Open randy408 opened 5 years ago
More tests that produce similar errors: https://gist.github.com/randy408/5a0b8cf8bea56bb6ee82fce7958c1b91, files are from https://github.com/glennrp/libpng/tree/libpng16/contrib/testpngs.
There is a bad (horrible) bug in 1.6 and prior versions where at least one combination of transforms results in transforms being performed in the wrong order, e.g. gamma correction after 16->8.
This was fixed in my version of 1.7 (by completely rewriting the transform code) but major versions of libpng were required by the maintainer to be "binary" compatible with image transforms; so fixing a bug were the transform is bogus was not permitted without a major release (and even then with much screaming and yelling.)
That doesn't seem to be this case because the observed behaviour is inconsistent with tthe required behaviour that a pixel at one place gets transformed identically to a pixel at another.
There might be a problem in the particular transforms used:
png_set_gray_to_rgb(png_ptr);
png_set_filler(png_ptr, 0xFF, PNG_FILLER_AFTER);
/* png_set_palette_to_rgb() + png_set_tRNS_to_alpha() */
png_set_expand(png_ptr);
png_set_strip_16(png_ptr);
png_set_filler and png_set_tRNS_to_alpha cannot be used together; the result is undefined (do you get the filler or the alpha?)
Since this is a poorly defined combination of transforms (in the code PNG_FILLER|PNG_EXPAND_tRNS) it would not surprise me if it revealed a bug.
The basic rule is to check the properties of the input PNG and only apply transforms that make sense.
This is not a case which would be detected by any of the tests since it is asking for incompatible transforms.
I suggest using the simplified API, then you can blame me if it doesn't work :-)
This was first submitted on sourceforge but no one uses that site anymore.
libpng has a corner case with the last pixel of 16-bit grayscale images when they're decoded to 8-bit RGBA using gamma correction.
When basn0g16.png is decoded without gamma correction both pixels at 0,0 and 31,31 are decoded to RGBA 0 0 0 255. Using gamma correction it's 0 0 0 255 at 0,0 and 19 19 19 255 at 31,31.
The code below reads basn0g16.png and decodes it without gamma correction and prints the first and last pixel's RGBA values. If "g" is passed as an argument it will decode using gamma correction.
This is reproducible with libpng 1.6.37 libspng bug report