Feb 28, 2015 at 11:44pm UTC
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 Feb 28, 2015 at 11:45pm UTC