Can some one help me to read PGM/PPM Images in C/C++. I am sure there
should be a library or a simple routine to read the pixels of an Image
and return a 2D array of pixel values...
It is so easy that you don't need a library routine.
First look up the format on wotsit.org. Basically it consists of width,
height, and raw pixel data, though there might be a few comments or colour
channel data in there.
I cannot remember offhand whether the width and height is big-endian or
little endian. Whichever, it may not match your machine. So write functions
that will read and write 16 and 32 bit integers in big or little endian
format, using the shift and AND and OR operators to construct the integer
portably.
Once you've done this, write a routine to load the header information, then
call malloc(), and then call fgetc() iteratively to read the pixel data.
The function should look something like this
unsigned char *readppm(const char *fname, int *width, int *height)
return NULL on any error, such as the file not being openable or there not
being enoguh memory.