mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[libpng15] Multiple transform bug fixes plus a work-round for double gamma
correction.
This commit is contained in:
committed by
Glenn Randers-Pehrson
parent
36f5884359
commit
18c5cfafeb
50
pngrtran.c
50
pngrtran.c
@@ -1465,6 +1465,28 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
}
|
||||
#endif /* PNG_READ_BACKGROUND_SUPPORTED && PNG_READ_EXPAND_16_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
|
||||
(defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \
|
||||
defined(PNG_READ_STRIP_16_TO_8_SUPPORTED))
|
||||
if ((png_ptr->transformations & (PNG_16_TO_8|PNG_SCALE_16_TO_8)) &&
|
||||
(png_ptr->transformations & PNG_COMPOSE) &&
|
||||
!(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
|
||||
png_ptr->bit_depth == 16)
|
||||
{
|
||||
/* On the other hand, if a 16-bit file is to be reduced to 8-bits per
|
||||
* component this will also happen after PNG_COMPOSE and so the background
|
||||
* color must be pre-expanded here.
|
||||
*
|
||||
* TODO: fix this too.
|
||||
*/
|
||||
png_ptr->background.red = (png_uint_16)(png_ptr->background.red * 257);
|
||||
png_ptr->background.green =
|
||||
(png_uint_16)(png_ptr->background.green * 257);
|
||||
png_ptr->background.blue = (png_uint_16)(png_ptr->background.blue * 257);
|
||||
png_ptr->background.gray = (png_uint_16)(png_ptr->background.gray * 257);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* NOTE: below 'PNG_READ_ALPHA_MODE_SUPPORTED' is presumed to also enable the
|
||||
* background support (see the comments in scripts/pnglibconf.dfa), this
|
||||
* allows pre-multiplication of the alpha channel to be implemented as
|
||||
@@ -1512,6 +1534,16 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
#ifdef PNG_READ_BACKGROUND_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_COMPOSE)
|
||||
{
|
||||
/* Issue a warning about this combination: because RGB_TO_GRAY is
|
||||
* optimized to do the gamma transform if present yet do_background has
|
||||
* to do the same thing if both options are set a
|
||||
* double-gamma-correction happens. This is true in all versions of
|
||||
* libpng to date.
|
||||
*/
|
||||
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
|
||||
png_warning(png_ptr,
|
||||
"libpng does not support gamma+background+rgb_to_gray");
|
||||
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
/* We don't get to here unless there is a tRNS chunk with non-opaque
|
||||
@@ -1726,7 +1758,13 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
else
|
||||
/* Transformation does not include PNG_BACKGROUND */
|
||||
#endif /* PNG_READ_BACKGROUND_SUPPORTED */
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
/* RGB_TO_GRAY needs to have non-gamma-corrected values! */
|
||||
&& ((png_ptr->transformations & PNG_EXPAND) == 0 ||
|
||||
(png_ptr->transformations & PNG_RGB_TO_GRAY) == 0)
|
||||
#endif
|
||||
)
|
||||
{
|
||||
png_colorp palette = png_ptr->palette;
|
||||
int num_palette = png_ptr->num_palette;
|
||||
@@ -2165,12 +2203,22 @@ png_do_read_transformations(png_structp png_ptr, png_row_infop row_info)
|
||||
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_GAMMA) &&
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
/* Because RGB_TO_GRAY does the gamma transform. */
|
||||
!(png_ptr->transformations & PNG_RGB_TO_GRAY) &&
|
||||
#endif
|
||||
#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\
|
||||
(defined PNG_READ_ALPHA_MODE_SUPPORTED)
|
||||
/* Because PNG_COMPOSE does the gamma transform if there is something to
|
||||
* do (if there is an alpha channel or transparency.)
|
||||
*/
|
||||
!((png_ptr->transformations & PNG_COMPOSE) &&
|
||||
((png_ptr->num_trans != 0) ||
|
||||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
|
||||
#endif
|
||||
/* Because png_init_read_transformations transforms the palette, unless
|
||||
* RGB_TO_GRAY will do the transform.
|
||||
*/
|
||||
(png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
|
||||
png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user