[libpng16] Corrected simplified API default gamma for color-mapped output, added

a flag to change default. In 1.6.0 when the simplified API was used
to produce color-mapped output from an input image with no gamma
information the gamma assumed for the input could be different from
that assumed for non-color-mapped output.  In particular 16-bit depth
input files were assumed to be sRGB encoded, whereas in the 'direct'
case they were assumed to have linear data.  This was an error.  The
fix makes the simplified API treat all input files the same way and
adds a new flag to the png_image::flags member to allow the
application/user to specify that 16-bit files contain sRGB data
rather than the default linear.
Fixed bugs in the pngpixel and makepng test programs.
This commit is contained in:
John Bowler
2013-03-06 22:23:40 -06:00
committed by Glenn Randers-Pehrson
parent f46106fa04
commit 2e92b4dfa0
7 changed files with 91 additions and 14 deletions

View File

@@ -2004,6 +2004,28 @@ png_image_read_colormap(png_voidp argument)
else
back_b = back_r = back_g = 255;
/* Default the input file gamma if required - this is necessary because
* libpng assumes that if no gamma information is present the data is in the
* output format, but the simplified API deduces the gamma from the input
* format.
*/
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) == 0)
{
/* Do this directly, not using the png_colorspace functions, to ensure
* that it happens even if the colorspace is invalid (though probably if
* it is the setting will be ignored) Note that the same thing can be
* achieved at the application interface with png_set_gAMA.
*/
if (png_ptr->bit_depth == 16 &&
(image->flags & PNG_IMAGE_FLAG_16BIT_sRGB) == 0)
png_ptr->colorspace.gamma = PNG_GAMMA_LINEAR;
else
png_ptr->colorspace.gamma = PNG_GAMMA_sRGB_INVERSE;
png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
}
/* Decide what to do based on the PNG color type of the input data. The
* utility function png_create_colormap_entry deals with most aspects of the
* output transformations; this code works out how to produce bytes of
@@ -3547,7 +3569,8 @@ png_image_read_direct(png_voidp argument)
{
png_fixed_point input_gamma_default;
if (base_format & PNG_FORMAT_FLAG_LINEAR)
if ((base_format & PNG_FORMAT_FLAG_LINEAR) &&
(image->flags & PNG_IMAGE_FLAG_16BIT_sRGB) == 0)
input_gamma_default = PNG_GAMMA_LINEAR;
else
input_gamma_default = PNG_DEFAULT_sRGB;