jbredeme / pixmap

Portable Pixmap Format (PPM) image reader/writer
0 stars 0 forks source link

Mysterious line feed #1

Open jbredeme opened 8 years ago

jbredeme commented 8 years ago

Encountering a line feed (10) that is causing the output ppm file to change colors when converting P6 to P3. Unable to currently isolate the source of the problem. I know it is not the product of the header being read/written because the problem does not persist in other format conversion operations. The problem appears to come from the fread function when reading the P6 file from source, which makes no sense. Here is what happens when I convert a P6 to P3 image file:

P3 640 400 255 10 <- line feed character 255...

jbredeme commented 8 years ago

Functionality Checklist

Conclusion problem lies in the fread of P6...

jbredeme commented 8 years ago

I have played around with different read and write modes when opening a file (rb or wb) in the write_p6_image function, if I change...

fpointer = fopen(filename, "wb"); - to - fpointer = fopen(filename, "w");

When I convert P6 to P6 I no longer get any color variation but the image is shifted right by a few pixels. And P6 to P3 the line feed is still present and the image is not shifted. Something is going on when with fread() on P6.

fwrite(image->image_data, sizeof(Pixel), image->width * image->height, fpointer);

jbredeme commented 8 years ago

Problem Solved

Line 138 advanced the file pointer by one character, looks like the fscanf function was not advancing past the line feed.