So I’m working on a class that is supposed to read in a pgm/ppm file and eventually modify it. However, I’m still working on reading in the data. My current objective is to create storage space for the binary data. Below is my code for a function that is supposed to do that:
uchar* pxm::newimg(int nrows, int ncols, int bpp)
{
uchar *newimage = new uchar[nrows * ncols * bpp];
//uchar defined as binary data previously
return newimage;
}
I then use this in my “read” function as:
img = newimg(nrows, ncols, bpp); //img declared in private section of class
ws(myfile); //reads the newline
myfile.read((char *) img[0], nrows * ncols * bpp);
//nrows, ncols, and bpp private member variables in class
myfile.close();
Unfortunately, while this code compiles, it produces a segmentation fault when run. I am fairly certain my issue is in the newimg function, as I have done checks to ensure that I am reading in the file properly and setting nrows, ncols, and bpp, as well as the magicid properly. Thus I presume I am not properly initializing the array data structure. If anyone has any suggestions it would be appreciated.
Thanks,
Zeta
p.s
If you need more details on my code, request it and I’ll add more to the post.
(char *) img[0]should beimg, or(char *) img.