Load and store *.pnm image file

I would like to write two functions to load and store binary (types P5 and P6) “*.pnm” image files but I am new in image processing, can anyone help me or give me some resources that I can use. Furthermore, The image structure should contain following:
type : an integer value specifying the image type. Values Gray = 0 and RGB = 1
width : an integer value specifying the width of the image.
height : an integer value specifying the width of the image.
data : a byte array of image data (stored in row major order).

For example following C++ code shows the headers of required functions.

struct Image {
int type; // an integer value specifying the image type. Values // Gray = 0 and RGB = 1 
int width; // an integer value specifying the width of the image.
int height; // an integer value specifying the height of the image. 
char* data; // an 8-bit array of image data (row major).

Image loadImage(string fileName); 
void storeImage(string fileName, Image img);

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you decided to use C++ then you may start with this document: http://www.cs.tufts.edu/comp/40/progs/pnmrdr.pdf
Then you should also look at this source code: http://web.eecs.utk.edu/~leparker/Courses/CS594-fall08/Homeworks/inputMap_v2.cc

To look at the PNM files structure and retrieve metadata you may start here: https://en.wikipedia.org/wiki/Netpbm_format and continue on the links at the bottom or here: http://www.imagemagick.org/script/formats.php

Above info should be sufficient for you to start programming.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Images and Photos

From novice to tech pro — start learning today.