mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[master] Imported from libpng-1.6.15.tar
This commit is contained in:
337
pngrtran.c
337
pngrtran.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngrtran.c - transforms the data in a row for PNG readers
|
||||
*
|
||||
* Last changed in libpng 1.6.11 [June 5, 2014]
|
||||
* Last changed in libpng 1.6.15 [November 20, 2014]
|
||||
* Copyright (c) 1998-2014 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
@@ -91,14 +91,15 @@ png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action)
|
||||
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
|
||||
/* Is it OK to set a transformation now? Only if png_start_read_image or
|
||||
* png_read_update_info have not been called. It is not necessary for the IHDR
|
||||
* to have been read in all cases, the parameter allows for this check too.
|
||||
* to have been read in all cases; the need_IHDR parameter allows for this
|
||||
* check too.
|
||||
*/
|
||||
static int
|
||||
png_rtran_ok(png_structrp png_ptr, int need_IHDR)
|
||||
{
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_ROW_INIT)
|
||||
if ((png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)
|
||||
png_app_error(png_ptr,
|
||||
"invalid after png_start_read_image or png_read_update_info");
|
||||
|
||||
@@ -127,7 +128,7 @@ png_set_background_fixed(png_structrp png_ptr,
|
||||
{
|
||||
png_debug(1, "in png_set_background_fixed");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0) || background_color == NULL)
|
||||
if (png_rtran_ok(png_ptr, 0) == 0 || background_color == NULL)
|
||||
return;
|
||||
|
||||
if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
|
||||
@@ -171,7 +172,7 @@ png_set_scale_16(png_structrp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_scale_16");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0))
|
||||
if (png_rtran_ok(png_ptr, 0) == 0)
|
||||
return;
|
||||
|
||||
png_ptr->transformations |= PNG_SCALE_16_TO_8;
|
||||
@@ -185,7 +186,7 @@ png_set_strip_16(png_structrp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_strip_16");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0))
|
||||
if (png_rtran_ok(png_ptr, 0) == 0)
|
||||
return;
|
||||
|
||||
png_ptr->transformations |= PNG_16_TO_8;
|
||||
@@ -198,7 +199,7 @@ png_set_strip_alpha(png_structrp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_strip_alpha");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0))
|
||||
if (png_rtran_ok(png_ptr, 0) == 0)
|
||||
return;
|
||||
|
||||
png_ptr->transformations |= PNG_STRIP_ALPHA;
|
||||
@@ -279,7 +280,7 @@ png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
|
||||
|
||||
png_debug(1, "in png_set_alpha_mode");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0))
|
||||
if (png_rtran_ok(png_ptr, 0) == 0)
|
||||
return;
|
||||
|
||||
output_gamma = translate_gamma_flags(png_ptr, output_gamma, 1/*screen*/);
|
||||
@@ -371,7 +372,7 @@ png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
|
||||
png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_FILE;
|
||||
png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
|
||||
|
||||
if (png_ptr->transformations & PNG_COMPOSE)
|
||||
if ((png_ptr->transformations & PNG_COMPOSE) != 0)
|
||||
png_error(png_ptr,
|
||||
"conflicting calls to set alpha mode and background");
|
||||
|
||||
@@ -415,7 +416,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
|
||||
{
|
||||
png_debug(1, "in png_set_quantize");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0))
|
||||
if (png_rtran_ok(png_ptr, 0) == 0)
|
||||
return;
|
||||
|
||||
png_ptr->transformations |= PNG_QUANTIZE;
|
||||
@@ -793,7 +794,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
|
||||
png_free(png_ptr, distance);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_QUANTIZE_SUPPORTED */
|
||||
#endif /* READ_QUANTIZE */
|
||||
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
void PNGFAPI
|
||||
@@ -802,7 +803,7 @@ png_set_gamma_fixed(png_structrp png_ptr, png_fixed_point scrn_gamma,
|
||||
{
|
||||
png_debug(1, "in png_set_gamma_fixed");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0))
|
||||
if (png_rtran_ok(png_ptr, 0) == 0)
|
||||
return;
|
||||
|
||||
/* New in libpng-1.5.4 - reserve particular negative values as flags. */
|
||||
@@ -842,7 +843,7 @@ png_set_gamma(png_structrp png_ptr, double scrn_gamma, double file_gamma)
|
||||
png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma),
|
||||
convert_gamma_value(png_ptr, file_gamma));
|
||||
}
|
||||
# endif /* FLOATING_POINT_SUPPORTED */
|
||||
# endif /* FLOATING_POINT */
|
||||
#endif /* READ_GAMMA */
|
||||
|
||||
#ifdef PNG_READ_EXPAND_SUPPORTED
|
||||
@@ -855,7 +856,7 @@ png_set_expand(png_structrp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_expand");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0))
|
||||
if (png_rtran_ok(png_ptr, 0) == 0)
|
||||
return;
|
||||
|
||||
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
|
||||
@@ -885,7 +886,7 @@ png_set_palette_to_rgb(png_structrp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_palette_to_rgb");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0))
|
||||
if (png_rtran_ok(png_ptr, 0) == 0)
|
||||
return;
|
||||
|
||||
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
|
||||
@@ -897,7 +898,7 @@ png_set_expand_gray_1_2_4_to_8(png_structrp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_expand_gray_1_2_4_to_8");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0))
|
||||
if (png_rtran_ok(png_ptr, 0) == 0)
|
||||
return;
|
||||
|
||||
png_ptr->transformations |= PNG_EXPAND;
|
||||
@@ -909,12 +910,12 @@ png_set_tRNS_to_alpha(png_structrp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_tRNS_to_alpha");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0))
|
||||
if (png_rtran_ok(png_ptr, 0) == 0)
|
||||
return;
|
||||
|
||||
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
|
||||
}
|
||||
#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
|
||||
#endif /* READ_EXPAND */
|
||||
|
||||
#ifdef PNG_READ_EXPAND_16_SUPPORTED
|
||||
/* Expand to 16-bit channels, expand the tRNS chunk too (because otherwise
|
||||
@@ -925,7 +926,7 @@ png_set_expand_16(png_structrp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_expand_16");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0))
|
||||
if (png_rtran_ok(png_ptr, 0) == 0)
|
||||
return;
|
||||
|
||||
png_ptr->transformations |= (PNG_EXPAND_16 | PNG_EXPAND | PNG_EXPAND_tRNS);
|
||||
@@ -938,7 +939,7 @@ png_set_gray_to_rgb(png_structrp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_gray_to_rgb");
|
||||
|
||||
if (!png_rtran_ok(png_ptr, 0))
|
||||
if (png_rtran_ok(png_ptr, 0) == 0)
|
||||
return;
|
||||
|
||||
/* Because rgb must be 8 bits or more: */
|
||||
@@ -956,7 +957,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
|
||||
|
||||
/* Need the IHDR here because of the check on color_type below. */
|
||||
/* TODO: fix this */
|
||||
if (!png_rtran_ok(png_ptr, 1))
|
||||
if (png_rtran_ok(png_ptr, 1) == 0)
|
||||
return;
|
||||
|
||||
switch (error_action)
|
||||
@@ -998,7 +999,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
|
||||
png_uint_16 red_int, green_int;
|
||||
|
||||
/* NOTE: this calculation does not round, but this behavior is retained
|
||||
* for consistency, the inaccuracy is very small. The code here always
|
||||
* for consistency; the inaccuracy is very small. The code here always
|
||||
* overwrites the coefficients, regardless of whether they have been
|
||||
* defaulted or set already.
|
||||
*/
|
||||
@@ -1091,7 +1092,7 @@ png_gamma_threshold(png_fixed_point screen_gamma, png_fixed_point file_gamma)
|
||||
* the palette.
|
||||
*/
|
||||
|
||||
/*For the moment 'png_init_palette_transformations' and
|
||||
/* For the moment 'png_init_palette_transformations' and
|
||||
* 'png_init_rgb_transformations' only do some flag canceling optimizations.
|
||||
* The intent is that these two routines should have palette or rgb operations
|
||||
* extracted from 'png_init_read_transformations'.
|
||||
@@ -1153,8 +1154,8 @@ png_init_palette_transformations(png_structrp png_ptr)
|
||||
/* The following code cannot be entered in the alpha pre-multiplication case
|
||||
* because PNG_BACKGROUND_EXPAND is cancelled below.
|
||||
*/
|
||||
if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
|
||||
(png_ptr->transformations & PNG_EXPAND))
|
||||
if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 &&
|
||||
(png_ptr->transformations & PNG_EXPAND) != 0)
|
||||
{
|
||||
{
|
||||
png_ptr->background.red =
|
||||
@@ -1165,9 +1166,9 @@ png_init_palette_transformations(png_structrp png_ptr)
|
||||
png_ptr->palette[png_ptr->background.index].blue;
|
||||
|
||||
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA)
|
||||
if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
|
||||
{
|
||||
if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
|
||||
if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)
|
||||
{
|
||||
/* Invert the alpha channel (in tRNS) unless the pixels are
|
||||
* going to be expanded, in which case leave it for later
|
||||
@@ -1179,10 +1180,10 @@ png_init_palette_transformations(png_structrp png_ptr)
|
||||
png_ptr->trans_alpha[i]);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED */
|
||||
#endif /* READ_INVERT_ALPHA */
|
||||
}
|
||||
} /* background expand and (therefore) no alpha association. */
|
||||
#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */
|
||||
#endif /* READ_EXPAND && READ_BACKGROUND */
|
||||
}
|
||||
|
||||
static void /* PRIVATE */
|
||||
@@ -1220,9 +1221,9 @@ png_init_rgb_transformations(png_structrp png_ptr)
|
||||
/* The following code cannot be entered in the alpha pre-multiplication case
|
||||
* because PNG_BACKGROUND_EXPAND is cancelled below.
|
||||
*/
|
||||
if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
|
||||
(png_ptr->transformations & PNG_EXPAND) &&
|
||||
!(png_ptr->color_type & PNG_COLOR_MASK_COLOR))
|
||||
if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 &&
|
||||
(png_ptr->transformations & PNG_EXPAND) != 0 &&
|
||||
(png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)
|
||||
/* i.e., GRAY or GRAY_ALPHA */
|
||||
{
|
||||
{
|
||||
@@ -1260,14 +1261,14 @@ png_init_rgb_transformations(png_structrp png_ptr)
|
||||
png_ptr->background.red = png_ptr->background.green =
|
||||
png_ptr->background.blue = (png_uint_16)gray;
|
||||
|
||||
if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
|
||||
if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)
|
||||
{
|
||||
png_ptr->trans_color.red = png_ptr->trans_color.green =
|
||||
png_ptr->trans_color.blue = (png_uint_16)trans_gray;
|
||||
}
|
||||
}
|
||||
} /* background expand and (therefore) no alpha association. */
|
||||
#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */
|
||||
#endif /* READ_EXPAND && READ_BACKGROUND */
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
@@ -1345,7 +1346,7 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
#endif
|
||||
|
||||
/* Certain transformations have the effect of preventing other
|
||||
* transformations that happen afterward in png_do_read_transformations,
|
||||
* transformations that happen afterward in png_do_read_transformations;
|
||||
* resolve the interdependencies here. From the code of
|
||||
* png_do_read_transformations the order is:
|
||||
*
|
||||
@@ -1374,8 +1375,8 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
* 23) PNG_USER_TRANSFORM [must be last]
|
||||
*/
|
||||
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
|
||||
!(png_ptr->transformations & PNG_COMPOSE))
|
||||
if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&
|
||||
(png_ptr->transformations & PNG_COMPOSE) == 0)
|
||||
{
|
||||
/* Stripping the alpha channel happens immediately after the 'expand'
|
||||
* transformations, before all other transformation, so it cancels out
|
||||
@@ -1401,7 +1402,7 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
/* If the screen gamma is about 1.0 then the OPTIMIZE_ALPHA and ENCODE_ALPHA
|
||||
* settings will have no effect.
|
||||
*/
|
||||
if (!png_gamma_significant(png_ptr->screen_gamma))
|
||||
if (png_gamma_significant(png_ptr->screen_gamma) == 0)
|
||||
{
|
||||
png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
|
||||
png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
|
||||
@@ -1412,7 +1413,7 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
/* Make sure the coefficients for the rgb to gray conversion are set
|
||||
* appropriately.
|
||||
*/
|
||||
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
|
||||
if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
|
||||
png_colorspace_set_rgb_coefficients(png_ptr);
|
||||
#endif
|
||||
|
||||
@@ -1433,23 +1434,23 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
* png_set_background, along with the bit depth, then the code has a record
|
||||
* of exactly what color space the background is currently in.
|
||||
*/
|
||||
if (png_ptr->transformations & PNG_BACKGROUND_EXPAND)
|
||||
if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0)
|
||||
{
|
||||
/* PNG_BACKGROUND_EXPAND: the background is in the file color space, so if
|
||||
* the file was grayscale the background value is gray.
|
||||
*/
|
||||
if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR))
|
||||
if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)
|
||||
png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
|
||||
}
|
||||
|
||||
else if (png_ptr->transformations & PNG_COMPOSE)
|
||||
else if ((png_ptr->transformations & PNG_COMPOSE) != 0)
|
||||
{
|
||||
/* PNG_COMPOSE: png_set_background was called with need_expand false,
|
||||
* so the color is in the color space of the output or png_set_alpha_mode
|
||||
* was called and the color is black. Ignore RGB_TO_GRAY because that
|
||||
* happens before GRAY_TO_RGB.
|
||||
*/
|
||||
if (png_ptr->transformations & PNG_GRAY_TO_RGB)
|
||||
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)
|
||||
{
|
||||
if (png_ptr->background.red == png_ptr->background.green &&
|
||||
png_ptr->background.red == png_ptr->background.blue)
|
||||
@@ -1459,8 +1460,8 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */
|
||||
#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED */
|
||||
#endif /* READ_EXPAND && READ_BACKGROUND */
|
||||
#endif /* READ_GRAY_TO_RGB */
|
||||
|
||||
/* For indexed PNG data (PNG_COLOR_TYPE_PALETTE) many of the transformations
|
||||
* can be performed directly on the palette, and some (such as rgb to gray)
|
||||
@@ -1481,10 +1482,10 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
|
||||
defined(PNG_READ_EXPAND_16_SUPPORTED)
|
||||
if ((png_ptr->transformations & PNG_EXPAND_16) &&
|
||||
(png_ptr->transformations & PNG_COMPOSE) &&
|
||||
!(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
|
||||
png_ptr->bit_depth != 16)
|
||||
if ((png_ptr->transformations & PNG_EXPAND_16) != 0 &&
|
||||
(png_ptr->transformations & PNG_COMPOSE) != 0 &&
|
||||
(png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 &&
|
||||
png_ptr->bit_depth != 16)
|
||||
{
|
||||
/* TODO: fix this. Because the expand_16 operation is after the compose
|
||||
* handling the background color must be 8, not 16, bits deep, but the
|
||||
@@ -1503,15 +1504,15 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
CHOP(png_ptr->background.gray);
|
||||
# undef CHOP
|
||||
}
|
||||
#endif /* PNG_READ_BACKGROUND_SUPPORTED && PNG_READ_EXPAND_16_SUPPORTED */
|
||||
#endif /* READ_BACKGROUND && READ_EXPAND_16 */
|
||||
|
||||
#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)
|
||||
if ((png_ptr->transformations & (PNG_16_TO_8|PNG_SCALE_16_TO_8)) != 0 &&
|
||||
(png_ptr->transformations & PNG_COMPOSE) != 0 &&
|
||||
(png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 &&
|
||||
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
|
||||
@@ -1554,25 +1555,24 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
* file gamma - if it is not 1.0 both RGB_TO_GRAY and COMPOSE need the
|
||||
* tables.
|
||||
*/
|
||||
if ((png_ptr->transformations & PNG_GAMMA)
|
||||
|| ((png_ptr->transformations & PNG_RGB_TO_GRAY)
|
||||
&& (png_gamma_significant(png_ptr->colorspace.gamma) ||
|
||||
png_gamma_significant(png_ptr->screen_gamma)))
|
||||
|| ((png_ptr->transformations & PNG_COMPOSE)
|
||||
&& (png_gamma_significant(png_ptr->colorspace.gamma)
|
||||
|| png_gamma_significant(png_ptr->screen_gamma)
|
||||
if ((png_ptr->transformations & PNG_GAMMA) != 0 ||
|
||||
((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0 &&
|
||||
(png_gamma_significant(png_ptr->colorspace.gamma) != 0 ||
|
||||
png_gamma_significant(png_ptr->screen_gamma) != 0)) ||
|
||||
((png_ptr->transformations & PNG_COMPOSE) != 0 &&
|
||||
(png_gamma_significant(png_ptr->colorspace.gamma) != 0 ||
|
||||
png_gamma_significant(png_ptr->screen_gamma) != 0
|
||||
# ifdef PNG_READ_BACKGROUND_SUPPORTED
|
||||
|| (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE
|
||||
&& png_gamma_significant(png_ptr->background_gamma))
|
||||
|| (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE &&
|
||||
png_gamma_significant(png_ptr->background_gamma) != 0)
|
||||
# endif
|
||||
)) || ((png_ptr->transformations & PNG_ENCODE_ALPHA)
|
||||
&& png_gamma_significant(png_ptr->screen_gamma))
|
||||
)
|
||||
)) || ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 &&
|
||||
png_gamma_significant(png_ptr->screen_gamma) != 0))
|
||||
{
|
||||
png_build_gamma_table(png_ptr, png_ptr->bit_depth);
|
||||
|
||||
#ifdef PNG_READ_BACKGROUND_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_COMPOSE)
|
||||
if ((png_ptr->transformations & PNG_COMPOSE) != 0)
|
||||
{
|
||||
/* Issue a warning about this combination: because RGB_TO_GRAY is
|
||||
* optimized to do the gamma transform if present yet do_background has
|
||||
@@ -1580,11 +1580,11 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
* double-gamma-correction happens. This is true in all versions of
|
||||
* libpng to date.
|
||||
*/
|
||||
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
|
||||
if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
|
||||
png_warning(png_ptr,
|
||||
"libpng does not support gamma+background+rgb_to_gray");
|
||||
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
if ((png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) != 0)
|
||||
{
|
||||
/* We don't get to here unless there is a tRNS chunk with non-opaque
|
||||
* entries - see the checking code at the start of this function.
|
||||
@@ -1632,7 +1632,7 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
break;
|
||||
}
|
||||
|
||||
if (png_gamma_significant(gs))
|
||||
if (png_gamma_significant(gs) != 0)
|
||||
{
|
||||
back.red = png_gamma_8bit_correct(png_ptr->background.red,
|
||||
gs);
|
||||
@@ -1649,7 +1649,7 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
back.blue = (png_byte)png_ptr->background.blue;
|
||||
}
|
||||
|
||||
if (png_gamma_significant(g))
|
||||
if (png_gamma_significant(g) != 0)
|
||||
{
|
||||
back_1.red = png_gamma_8bit_correct(png_ptr->background.red,
|
||||
g);
|
||||
@@ -1798,7 +1798,7 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
|
||||
else
|
||||
/* Transformation does not include PNG_BACKGROUND */
|
||||
#endif /* PNG_READ_BACKGROUND_SUPPORTED */
|
||||
#endif /* READ_BACKGROUND */
|
||||
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! */
|
||||
@@ -1828,11 +1828,11 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
#ifdef PNG_READ_BACKGROUND_SUPPORTED
|
||||
else
|
||||
#endif
|
||||
#endif /* PNG_READ_GAMMA_SUPPORTED */
|
||||
#endif /* READ_GAMMA */
|
||||
|
||||
#ifdef PNG_READ_BACKGROUND_SUPPORTED
|
||||
/* No GAMMA transformation (see the hanging else 4 lines above) */
|
||||
if ((png_ptr->transformations & PNG_COMPOSE) &&
|
||||
if ((png_ptr->transformations & PNG_COMPOSE) != 0 &&
|
||||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
|
||||
{
|
||||
int i;
|
||||
@@ -1867,11 +1867,11 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
|
||||
png_ptr->transformations &= ~PNG_COMPOSE;
|
||||
}
|
||||
#endif /* PNG_READ_BACKGROUND_SUPPORTED */
|
||||
#endif /* READ_BACKGROUND */
|
||||
|
||||
#ifdef PNG_READ_SHIFT_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_SHIFT) &&
|
||||
!(png_ptr->transformations & PNG_EXPAND) &&
|
||||
if ((png_ptr->transformations & PNG_SHIFT) != 0 &&
|
||||
(png_ptr->transformations & PNG_EXPAND) == 0 &&
|
||||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
|
||||
{
|
||||
int i;
|
||||
@@ -1913,7 +1913,7 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
png_ptr->palette[i].blue = (png_byte)component;
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_SHIFT_SUPPORTED */
|
||||
#endif /* READ_SHIFT */
|
||||
}
|
||||
|
||||
/* Modify the info structure to reflect the transformations. The
|
||||
@@ -1926,7 +1926,7 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
|
||||
png_debug(1, "in png_read_transform_info");
|
||||
|
||||
#ifdef PNG_READ_EXPAND_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_EXPAND)
|
||||
if ((png_ptr->transformations & PNG_EXPAND) != 0)
|
||||
{
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
@@ -1948,9 +1948,9 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (png_ptr->num_trans)
|
||||
if (png_ptr->num_trans != 0)
|
||||
{
|
||||
if (png_ptr->transformations & PNG_EXPAND_tRNS)
|
||||
if ((png_ptr->transformations & PNG_EXPAND_tRNS) != 0)
|
||||
info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
|
||||
}
|
||||
if (info_ptr->bit_depth < 8)
|
||||
@@ -1966,7 +1966,7 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
|
||||
/* The following is almost certainly wrong unless the background value is in
|
||||
* the screen space!
|
||||
*/
|
||||
if (png_ptr->transformations & PNG_COMPOSE)
|
||||
if ((png_ptr->transformations & PNG_COMPOSE) != 0)
|
||||
info_ptr->background = png_ptr->background;
|
||||
#endif
|
||||
|
||||
@@ -1987,12 +1987,12 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
|
||||
{
|
||||
# ifdef PNG_READ_16BIT_SUPPORTED
|
||||
# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SCALE_16_TO_8)
|
||||
if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0)
|
||||
info_ptr->bit_depth = 8;
|
||||
# endif
|
||||
|
||||
# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_16_TO_8)
|
||||
if ((png_ptr->transformations & PNG_16_TO_8) != 0)
|
||||
info_ptr->bit_depth = 8;
|
||||
# endif
|
||||
|
||||
@@ -2018,27 +2018,27 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
|
||||
CONFIGURATION ERROR: you must enable at least one 16 to 8 method
|
||||
# endif
|
||||
# endif
|
||||
#endif /* !READ_16BIT_SUPPORTED */
|
||||
#endif /* !READ_16BIT */
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_GRAY_TO_RGB)
|
||||
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)
|
||||
info_ptr->color_type = (png_byte)(info_ptr->color_type |
|
||||
PNG_COLOR_MASK_COLOR);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
|
||||
if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
|
||||
info_ptr->color_type = (png_byte)(info_ptr->color_type &
|
||||
~PNG_COLOR_MASK_COLOR);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_QUANTIZE_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_QUANTIZE)
|
||||
if ((png_ptr->transformations & PNG_QUANTIZE) != 0)
|
||||
{
|
||||
if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
|
||||
(info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
|
||||
png_ptr->palette_lookup && info_ptr->bit_depth == 8)
|
||||
png_ptr->palette_lookup != 0 && info_ptr->bit_depth == 8)
|
||||
{
|
||||
info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
|
||||
}
|
||||
@@ -2046,29 +2046,31 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_EXPAND_16_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_EXPAND_16 && info_ptr->bit_depth == 8 &&
|
||||
info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
|
||||
if ((png_ptr->transformations & PNG_EXPAND_16) != 0 &&
|
||||
info_ptr->bit_depth == 8 &&
|
||||
info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
info_ptr->bit_depth = 16;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_PACK_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
|
||||
if ((png_ptr->transformations & PNG_PACK) != 0 &&
|
||||
(info_ptr->bit_depth < 8))
|
||||
info_ptr->bit_depth = 8;
|
||||
#endif
|
||||
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
info_ptr->channels = 1;
|
||||
|
||||
else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
|
||||
else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
info_ptr->channels = 3;
|
||||
|
||||
else
|
||||
info_ptr->channels = 1;
|
||||
|
||||
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_STRIP_ALPHA)
|
||||
if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0)
|
||||
{
|
||||
info_ptr->color_type = (png_byte)(info_ptr->color_type &
|
||||
~PNG_COLOR_MASK_ALPHA);
|
||||
@@ -2076,25 +2078,25 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
|
||||
if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)
|
||||
info_ptr->channels++;
|
||||
|
||||
#ifdef PNG_READ_FILLER_SUPPORTED
|
||||
/* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */
|
||||
if ((png_ptr->transformations & PNG_FILLER) &&
|
||||
((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
|
||||
(info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
|
||||
if ((png_ptr->transformations & PNG_FILLER) != 0 &&
|
||||
(info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
|
||||
info_ptr->color_type == PNG_COLOR_TYPE_GRAY))
|
||||
{
|
||||
info_ptr->channels++;
|
||||
/* If adding a true alpha channel not just filler */
|
||||
if (png_ptr->transformations & PNG_ADD_ALPHA)
|
||||
if ((png_ptr->transformations & PNG_ADD_ALPHA) != 0)
|
||||
info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
|
||||
defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_USER_TRANSFORM)
|
||||
if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
|
||||
{
|
||||
if (info_ptr->bit_depth < png_ptr->user_transform_depth)
|
||||
info_ptr->bit_depth = png_ptr->user_transform_depth;
|
||||
@@ -2245,7 +2247,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row,
|
||||
int channels = 0;
|
||||
int bit_depth = row_info->bit_depth;
|
||||
|
||||
if (color_type & PNG_COLOR_MASK_COLOR)
|
||||
if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
{
|
||||
shift[channels++] = bit_depth - sig_bits->red;
|
||||
shift[channels++] = bit_depth - sig_bits->green;
|
||||
@@ -2257,7 +2259,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row,
|
||||
shift[channels++] = bit_depth - sig_bits->gray;
|
||||
}
|
||||
|
||||
if (color_type & PNG_COLOR_MASK_ALPHA)
|
||||
if ((color_type & PNG_COLOR_MASK_ALPHA) != 0)
|
||||
{
|
||||
shift[channels++] = bit_depth - sig_bits->alpha;
|
||||
}
|
||||
@@ -2671,7 +2673,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
|
||||
{
|
||||
/* This changes the data from G to GX */
|
||||
png_bytep sp = row + (png_size_t)row_width;
|
||||
@@ -2706,7 +2708,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
|
||||
#ifdef PNG_READ_16BIT_SUPPORTED
|
||||
else if (row_info->bit_depth == 16)
|
||||
{
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
|
||||
{
|
||||
/* This changes the data from GG to GGXX */
|
||||
png_bytep sp = row + (png_size_t)row_width * 2;
|
||||
@@ -2748,7 +2750,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
|
||||
{
|
||||
/* This changes the data from RGB to RGBX */
|
||||
png_bytep sp = row + (png_size_t)row_width * 3;
|
||||
@@ -2787,7 +2789,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
|
||||
#ifdef PNG_READ_16BIT_SUPPORTED
|
||||
else if (row_info->bit_depth == 16)
|
||||
{
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
|
||||
{
|
||||
/* This changes the data from RRGGBB to RRGGBBXX */
|
||||
png_bytep sp = row + (png_size_t)row_width * 6;
|
||||
@@ -2848,7 +2850,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
|
||||
png_debug(1, "in png_do_gray_to_rgb");
|
||||
|
||||
if (row_info->bit_depth >= 8 &&
|
||||
!(row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
(row_info->color_type & PNG_COLOR_MASK_COLOR) == 0)
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
|
||||
{
|
||||
@@ -2986,8 +2988,8 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
|
||||
png_debug(1, "in png_do_rgb_to_gray");
|
||||
|
||||
if (!(row_info->color_type & PNG_COLOR_MASK_PALETTE) &&
|
||||
(row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_PALETTE) == 0 &&
|
||||
(row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
{
|
||||
PNG_CONST png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
|
||||
PNG_CONST png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
|
||||
@@ -3086,15 +3088,15 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_uint_16 red, green, blue, w;
|
||||
|
||||
red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
|
||||
green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
|
||||
blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
|
||||
red = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2;
|
||||
green = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2;
|
||||
blue = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2;
|
||||
|
||||
if (red == green && red == blue)
|
||||
{
|
||||
if (png_ptr->gamma_16_table != NULL)
|
||||
w = png_ptr->gamma_16_table[(red&0xff)
|
||||
>> png_ptr->gamma_shift][red>>8];
|
||||
w = png_ptr->gamma_16_table[(red & 0xff)
|
||||
>> png_ptr->gamma_shift][red >> 8];
|
||||
|
||||
else
|
||||
w = red;
|
||||
@@ -3137,9 +3139,9 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_uint_16 red, green, blue, gray16;
|
||||
|
||||
red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
|
||||
green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
|
||||
blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
|
||||
red = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2;
|
||||
green = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2;
|
||||
blue = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2;
|
||||
|
||||
if (red != green || red != blue)
|
||||
rgb_error |= 1;
|
||||
@@ -3150,7 +3152,7 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
*/
|
||||
gray16 = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >>
|
||||
15);
|
||||
*(dp++) = (png_byte)((gray16>>8) & 0xff);
|
||||
*(dp++) = (png_byte)((gray16 >> 8) & 0xff);
|
||||
*(dp++) = (png_byte)(gray16 & 0xff);
|
||||
|
||||
if (have_alpha != 0)
|
||||
@@ -3910,7 +3912,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_READ_ALPHA_MODE_SUPPORTED */
|
||||
#endif /* READ_BACKGROUND || READ_ALPHA_MODE */
|
||||
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
/* Gamma correct the image, avoiding the alpha channel. Make sure
|
||||
@@ -4127,7 +4129,7 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
|
||||
png_debug(1, "in png_do_encode_alpha");
|
||||
|
||||
if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
@@ -4353,7 +4355,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
|
||||
{
|
||||
unsigned int gray = trans_color ? trans_color->gray : 0;
|
||||
unsigned int gray = trans_color != NULL ? trans_color->gray : 0;
|
||||
|
||||
if (row_info->bit_depth < 8)
|
||||
{
|
||||
@@ -4497,7 +4499,8 @@ png_do_expand(png_row_infop row_info, png_bytep row,
|
||||
row_width);
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_color)
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
|
||||
trans_color != NULL)
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
@@ -4688,7 +4691,7 @@ png_do_quantize(png_row_infop row_info, png_bytep row,
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_QUANTIZE_SUPPORTED */
|
||||
#endif /* READ_QUANTIZE */
|
||||
|
||||
/* Transform the row. The order of transformations is significant,
|
||||
* and is very touchy. If you add a transformation, take care to
|
||||
@@ -4715,7 +4718,7 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
* demand, if necessary.
|
||||
*/
|
||||
if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 &&
|
||||
!(png_ptr->flags & PNG_FLAG_ROW_INIT))
|
||||
(png_ptr->flags & PNG_FLAG_ROW_INIT) == 0)
|
||||
{
|
||||
/* Application has failed to call either png_read_start_image() or
|
||||
* png_read_update_info() after setting transforms that expand pixels.
|
||||
@@ -4725,7 +4728,7 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_EXPAND_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_EXPAND)
|
||||
if ((png_ptr->transformations & PNG_EXPAND) != 0)
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
@@ -4735,8 +4738,8 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
|
||||
else
|
||||
{
|
||||
if (png_ptr->num_trans &&
|
||||
(png_ptr->transformations & PNG_EXPAND_tRNS))
|
||||
if (png_ptr->num_trans != 0 &&
|
||||
(png_ptr->transformations & PNG_EXPAND_tRNS) != 0)
|
||||
png_do_expand(row_info, png_ptr->row_buf + 1,
|
||||
&(png_ptr->trans_color));
|
||||
|
||||
@@ -4748,16 +4751,16 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
|
||||
!(png_ptr->transformations & PNG_COMPOSE) &&
|
||||
(row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
|
||||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
|
||||
if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&
|
||||
(png_ptr->transformations & PNG_COMPOSE) == 0 &&
|
||||
(row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
|
||||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
|
||||
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
|
||||
0 /* at_start == false, because SWAP_ALPHA happens later */);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
|
||||
if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
|
||||
{
|
||||
int rgb_error =
|
||||
png_do_rgb_to_gray(png_ptr, row_info,
|
||||
@@ -4812,22 +4815,22 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
/* If gray -> RGB, do so now only if background is non-gray; else do later
|
||||
* for performance reasons
|
||||
*/
|
||||
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
|
||||
!(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
|
||||
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 &&
|
||||
(png_ptr->mode & PNG_BACKGROUND_IS_GRAY) == 0)
|
||||
png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
|
||||
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_COMPOSE)
|
||||
if ((png_ptr->transformations & PNG_COMPOSE) != 0)
|
||||
png_do_compose(row_info, png_ptr->row_buf + 1, png_ptr);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_GAMMA) &&
|
||||
if ((png_ptr->transformations & PNG_GAMMA) != 0 &&
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
/* Because RGB_TO_GRAY does the gamma transform. */
|
||||
!(png_ptr->transformations & PNG_RGB_TO_GRAY) &&
|
||||
(png_ptr->transformations & PNG_RGB_TO_GRAY) == 0 &&
|
||||
#endif
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
|
||||
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
|
||||
@@ -4836,7 +4839,7 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
*/
|
||||
!((png_ptr->transformations & PNG_COMPOSE) &&
|
||||
((png_ptr->num_trans != 0) ||
|
||||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
|
||||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)) &&
|
||||
#endif
|
||||
/* Because png_init_read_transformations transforms the palette, unless
|
||||
* RGB_TO_GRAY will do the transform.
|
||||
@@ -4846,22 +4849,22 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
|
||||
(png_ptr->transformations & PNG_COMPOSE) &&
|
||||
(row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
|
||||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
|
||||
if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&
|
||||
(png_ptr->transformations & PNG_COMPOSE) != 0 &&
|
||||
(row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
|
||||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
|
||||
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
|
||||
0 /* at_start == false, because SWAP_ALPHA happens later */);
|
||||
0 /* at_start == false, because SWAP_ALPHA happens later */);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_ENCODE_ALPHA) &&
|
||||
(row_info->color_type & PNG_COLOR_MASK_ALPHA))
|
||||
if ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 &&
|
||||
(row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)
|
||||
png_do_encode_alpha(row_info, png_ptr->row_buf + 1, png_ptr);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SCALE_16_TO_8)
|
||||
if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0)
|
||||
png_do_scale_16_to_8(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
@@ -4870,12 +4873,12 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
* by putting the 'scale' option first if the app asks for scale (either by
|
||||
* calling the API or in a TRANSFORM flag) this is what happens.
|
||||
*/
|
||||
if (png_ptr->transformations & PNG_16_TO_8)
|
||||
if ((png_ptr->transformations & PNG_16_TO_8) != 0)
|
||||
png_do_chop(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_QUANTIZE_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_QUANTIZE)
|
||||
if ((png_ptr->transformations & PNG_QUANTIZE) != 0)
|
||||
{
|
||||
png_do_quantize(row_info, png_ptr->row_buf + 1,
|
||||
png_ptr->palette_lookup, png_ptr->quantize_index);
|
||||
@@ -4883,7 +4886,7 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
if (row_info->rowbytes == 0)
|
||||
png_error(png_ptr, "png_do_quantize returned rowbytes=0");
|
||||
}
|
||||
#endif /* PNG_READ_QUANTIZE_SUPPORTED */
|
||||
#endif /* READ_QUANTIZE */
|
||||
|
||||
#ifdef PNG_READ_EXPAND_16_SUPPORTED
|
||||
/* Do the expansion now, after all the arithmetic has been done. Notice
|
||||
@@ -4891,35 +4894,35 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
* is efficient (particularly true in the case of gamma correction, where
|
||||
* better accuracy results faster!)
|
||||
*/
|
||||
if (png_ptr->transformations & PNG_EXPAND_16)
|
||||
if ((png_ptr->transformations & PNG_EXPAND_16) != 0)
|
||||
png_do_expand_16(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
|
||||
/* NOTE: moved here in 1.5.4 (from much later in this list.) */
|
||||
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
|
||||
(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
|
||||
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 &&
|
||||
(png_ptr->mode & PNG_BACKGROUND_IS_GRAY) != 0)
|
||||
png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_INVERT_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_INVERT_MONO)
|
||||
if ((png_ptr->transformations & PNG_INVERT_MONO) != 0)
|
||||
png_do_invert(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA)
|
||||
if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
|
||||
png_do_read_invert_alpha(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_SHIFT_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SHIFT)
|
||||
if ((png_ptr->transformations & PNG_SHIFT) != 0)
|
||||
png_do_unshift(row_info, png_ptr->row_buf + 1,
|
||||
&(png_ptr->shift));
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_PACK_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_PACK)
|
||||
if ((png_ptr->transformations & PNG_PACK) != 0)
|
||||
png_do_unpack(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
@@ -4931,36 +4934,36 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_BGR_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_BGR)
|
||||
if ((png_ptr->transformations & PNG_BGR) != 0)
|
||||
png_do_bgr(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_PACKSWAP_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_PACKSWAP)
|
||||
if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
|
||||
png_do_packswap(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_FILLER_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_FILLER)
|
||||
if ((png_ptr->transformations & PNG_FILLER) != 0)
|
||||
png_do_read_filler(row_info, png_ptr->row_buf + 1,
|
||||
(png_uint_32)png_ptr->filler, png_ptr->flags);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SWAP_ALPHA)
|
||||
if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0)
|
||||
png_do_read_swap_alpha(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_16BIT_SUPPORTED
|
||||
#ifdef PNG_READ_SWAP_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0)
|
||||
png_do_swap(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_USER_TRANSFORM)
|
||||
{
|
||||
if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
|
||||
{
|
||||
if (png_ptr->read_user_transform_fn != NULL)
|
||||
(*(png_ptr->read_user_transform_fn)) /* User read transform function */
|
||||
(png_ptr, /* png_ptr */
|
||||
@@ -4973,10 +4976,10 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
/* png_byte pixel_depth; bits per pixel (depth*channels) */
|
||||
png_ptr->row_buf + 1); /* start of pixel data for row */
|
||||
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
|
||||
if (png_ptr->user_transform_depth)
|
||||
if (png_ptr->user_transform_depth != 0)
|
||||
row_info->bit_depth = png_ptr->user_transform_depth;
|
||||
|
||||
if (png_ptr->user_transform_channels)
|
||||
if (png_ptr->user_transform_channels != 0)
|
||||
row_info->channels = png_ptr->user_transform_channels;
|
||||
#endif
|
||||
row_info->pixel_depth = (png_byte)(row_info->bit_depth *
|
||||
@@ -4987,5 +4990,5 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
#endif /* READ_TRANSFORMS */
|
||||
#endif /* READ */
|
||||
|
||||
Reference in New Issue
Block a user