PPM Image file Magic Number and MaxColorValue

Hi,

When reading a PPM Image file, how would I find the magic number and the max color value?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
int main()
{
        string imageFileName;
	ifstream image;

	imageFileName = "C:\\Users\\Desktop\\drink.ppm";
	image.open(imageFileName.c_str(), ifstream::binary);
    
        image.seekg(0, std::ios::end);
	int size = image.tellg();
	image.seekg(0, std::ios::beg);

	char * buffer = new char[size];

	image.getline(buffer, 20);
	image.getline(buffer, 20, ' ');
	int width = atoi(buffer);

	image.getline(buffer, 20);
	image.getline(buffer, 20, ' ');
	int height = atoi(buffer);


        //...
        return 0;
}


The code gives me seemingly logical integer values for size, width and height. But how would I find the max color value and so called "magic number" for this PPM image file?
Last edited on
All your questions are answered in the documentation: http://netpbm.sourceforge.net/doc/ppm.html
Topic archived. No new replies allowed.