[libpng16] Changed remaining "if (!x)" to "if (x == 0)" and "if (x)" to

"if (x !== 0)"
This commit is contained in:
Glenn Randers-Pehrson 2014-10-31 20:48:55 -05:00
parent 6b9a20e7f9
commit 5d713fe123
16 changed files with 880 additions and 795 deletions

View File

@ -1,4 +1,4 @@
Libpng 1.6.15beta02 - October 29, 2014
Libpng 1.6.15beta02 - November 1, 2014
This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version.
@ -30,7 +30,8 @@ Version 1.6.15beta01 [October 29, 2014]
Simplified png_free_data().
Added missing "ptr = NULL" after some instances of png_free().
Version 1.6.15beta02 [October 29, 2014]
Version 1.6.15beta02 [November 1, 2014]
Changed remaining "if (!x)" to "if (x == 0)" and "if (x)" to "if (x !== 0)"
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

View File

@ -5038,7 +5038,8 @@ Version 1.6.15beta01 [October 29, 2014]
Simplified png_free_data().
Added missing "ptr = NULL" after some instances of png_free().
Version 1.6.15beta02 [October 29, 2014]
Version 1.6.15beta02 [November 1, 2014]
Changed remaining "if (!x)" to "if (x == 0)" and "if (x)" to "if (x !== 0)"
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

View File

@ -2,7 +2,7 @@
#if 0 /* in case someone actually tries to compile this */
/* example.c - an example of using libpng
* Last changed in libpng 1.6.11 [June 5, 2014]
* Last changed in libpng 1.6.15 [(PENDING RELEASE)]
* Maintained 1998-2014 Glenn Randers-Pehrson
* Maintained 1996, 1997 Andreas Dilger)
* Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -52,7 +52,7 @@ int main(int argc, const char **argv)
image.version = PNG_IMAGE_VERSION;
/* The first argument is the file to read: */
if (png_image_begin_read_from_file(&image, argv[1]))
if (png_image_begin_read_from_file(&image, argv[1]) != 0)
{
png_bytep buffer;
@ -97,7 +97,7 @@ int main(int argc, const char **argv)
*/
if (buffer != NULL &&
png_image_finish_read(&image, NULL/*background*/, buffer,
0/*row_stride*/, NULL/*colormap*/))
0/*row_stride*/, NULL/*colormap*/) != 0)
{
/* Now write the image out to the second argument. In the write
* call 'convert_to_8bit' allows 16-bit data to be squashed down to
@ -105,7 +105,7 @@ int main(int argc, const char **argv)
* to the 8-bit format.
*/
if (png_image_write_to_file(&image, argv[2], 0/*convert_to_8bit*/,
buffer, 0/*row_stride*/, NULL/*colormap*/))
buffer, 0/*row_stride*/, NULL/*colormap*/) != 0)
{
/* The image has been written successfully. */
exit(0);
@ -405,7 +405,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
/* Expand paletted or RGB images with transparency to full alpha channels
* so the data will be available as RGBA quartets.
*/
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) != 0)
png_set_tRNS_to_alpha(png_ptr);
/* Set the background color to draw transparent and alpha images over.
@ -417,7 +417,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
png_color_16 my_background, *image_background;
if (png_get_bKGD(png_ptr, info_ptr, &image_background))
if (png_get_bKGD(png_ptr, info_ptr, &image_background) != 0)
png_set_background(png_ptr, image_background,
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
else
@ -454,12 +454,12 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
int intent;
if (png_get_sRGB(png_ptr, info_ptr, &intent))
if (png_get_sRGB(png_ptr, info_ptr, &intent) != 0)
png_set_gamma(png_ptr, screen_gamma, PNG_DEFAULT_sRGB);
else
{
double image_gamma;
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma))
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma) != 0)
png_set_gamma(png_ptr, screen_gamma, image_gamma);
else
png_set_gamma(png_ptr, screen_gamma, 0.45455);
@ -469,7 +469,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
/* Quantize RGB files down to 8 bit palette or reduce palettes
* to the number of colors available on your screen.
*/
if (color_type & PNG_COLOR_MASK_COLOR)
if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
{
int num_palette;
png_colorp palette;
@ -484,7 +484,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
MAX_SCREEN_COLORS, NULL, 0);
}
/* This reduces the image to the palette supplied in the file */
else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette))
else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette) != 0)
{
png_uint_16p histogram = NULL;
@ -503,7 +503,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
* [0,65535] to the original [0,7] or [0,31], or whatever range the
* colors were originally in:
*/
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT) != 0)
{
png_color_8p sig_bit_p;
@ -512,7 +512,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
}
/* Flip the RGB pixels to BGR (or RGBA to BGRA) */
if (color_type & PNG_COLOR_MASK_COLOR)
if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
png_set_bgr(png_ptr);
/* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */

298
png.c
View File

@ -115,7 +115,7 @@ png_calculate_crc(png_structrp png_ptr, png_const_bytep ptr, png_size_t length)
{
int need_crc = 1;
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0)
{
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
(PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
@ -124,7 +124,7 @@ png_calculate_crc(png_structrp png_ptr, png_const_bytep ptr, png_size_t length)
else /* critical */
{
if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0)
need_crc = 0;
}
@ -133,7 +133,7 @@ png_calculate_crc(png_structrp png_ptr, png_const_bytep ptr, png_size_t length)
* following cast is safe. 'uInt' may be no more than 16 bits, so it is
* necessary to perform a loop here.
*/
if (need_crc && length > 0)
if (need_crc != 0 && length > 0)
{
uLong crc = png_ptr->crc; /* Should never issue a warning */
@ -179,7 +179,7 @@ png_user_version_check(png_structrp png_ptr, png_const_charp user_png_ver)
else
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
if ((png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) != 0)
{
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
* we must recompile any applications that use any older library version.
@ -289,7 +289,7 @@ png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
# endif
/* Call the general version checker (shared with read and write code):
*/
if (png_user_version_check(&create_struct, user_png_ver))
if (png_user_version_check(&create_struct, user_png_ver) != 0)
{
png_structrp png_ptr = png_voidcast(png_structrp,
png_malloc_warn(&create_struct, (sizeof *png_ptr)));
@ -451,7 +451,8 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#ifdef PNG_TEXT_SUPPORTED
/* Free text item num or (if num == -1) all text items */
if (info_ptr->text && ((mask & PNG_FREE_TEXT) & info_ptr->free_me))
if (info_ptr->text != 0 &&
((mask & PNG_FREE_TEXT) & info_ptr->free_me) != 0)
{
if (num != -1)
{
@ -475,7 +476,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#ifdef PNG_tRNS_SUPPORTED
/* Free any tRNS entry */
if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
if (((mask & PNG_FREE_TRNS) & info_ptr->free_me) != 0)
{
png_free(png_ptr, info_ptr->trans_alpha);
info_ptr->trans_alpha = NULL;
@ -485,7 +486,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#ifdef PNG_sCAL_SUPPORTED
/* Free any sCAL entry */
if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
if (((mask & PNG_FREE_SCAL) & info_ptr->free_me) != 0)
{
png_free(png_ptr, info_ptr->scal_s_width);
png_free(png_ptr, info_ptr->scal_s_height);
@ -497,7 +498,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#ifdef PNG_pCAL_SUPPORTED
/* Free any pCAL entry */
if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
if (((mask & PNG_FREE_PCAL) & info_ptr->free_me) != 0)
{
png_free(png_ptr, info_ptr->pcal_purpose);
png_free(png_ptr, info_ptr->pcal_units);
@ -520,7 +521,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#ifdef PNG_iCCP_SUPPORTED
/* Free any profile entry */
if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
if (((mask & PNG_FREE_ICCP) & info_ptr->free_me) != 0)
{
png_free(png_ptr, info_ptr->iccp_name);
png_free(png_ptr, info_ptr->iccp_profile);
@ -532,7 +533,8 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#ifdef PNG_sPLT_SUPPORTED
/* Free a given sPLT entry, or (if num == -1) all sPLT entries */
if (info_ptr->splt_palettes && ((mask & PNG_FREE_SPLT) & info_ptr->free_me))
if (info_ptr->splt_palettes != 0 &&
((mask & PNG_FREE_SPLT) & info_ptr->free_me) != 0)
{
if (num != -1)
{
@ -544,7 +546,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
else
{
if (info_ptr->splt_palettes_num)
if (info_ptr->splt_palettes_num != 0)
{
int i;
@ -564,7 +566,8 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#endif
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
if (info_ptr->unknown_chunks && ((mask & PNG_FREE_UNKN) & info_ptr->free_me))
if (info_ptr->unknown_chunks != 0 &&
((mask & PNG_FREE_UNKN) & info_ptr->free_me) != 0)
{
if (num != -1)
{
@ -576,7 +579,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
{
int i;
if (info_ptr->unknown_chunks_num)
if (info_ptr->unknown_chunks_num != 0)
{
for (i = 0; i < info_ptr->unknown_chunks_num; i++)
png_free(png_ptr, info_ptr->unknown_chunks[i].data);
@ -591,7 +594,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#ifdef PNG_hIST_SUPPORTED
/* Free any hIST entry */
if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
if (((mask & PNG_FREE_HIST) & info_ptr->free_me) != 0)
{
png_free(png_ptr, info_ptr->hist);
info_ptr->hist = NULL;
@ -600,7 +603,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#endif
/* Free any PLTE entry that was internally allocated */
if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
if (((mask & PNG_FREE_PLTE) & info_ptr->free_me) != 0)
{
png_free(png_ptr, info_ptr->palette);
info_ptr->palette = NULL;
@ -610,9 +613,9 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#ifdef PNG_INFO_IMAGE_SUPPORTED
/* Free any image bits attached to the info structure */
if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
if (((mask & PNG_FREE_ROWS) & info_ptr->free_me) != 0)
{
if (info_ptr->row_pointers)
if (info_ptr->row_pointers != 0)
{
png_uint_32 row;
for (row = 0; row < info_ptr->height; row++)
@ -745,7 +748,7 @@ png_convert_to_rfc1123(png_structrp png_ptr, png_const_timep ptime)
if (png_ptr != NULL)
{
/* The only failure above if png_ptr != NULL is from an invalid ptime */
if (!png_convert_to_rfc1123_buffer(png_ptr->time_buffer, ptime))
if (png_convert_to_rfc1123_buffer(png_ptr->time_buffer, ptime) == 0)
png_warning(png_ptr, "Ignoring invalid time value");
else
@ -768,13 +771,13 @@ png_get_copyright(png_const_structrp png_ptr)
#else
# ifdef __STDC__
return PNG_STRING_NEWLINE \
"libpng version 1.6.15beta02 - October 29, 2014" PNG_STRING_NEWLINE \
"libpng version 1.6.15beta02 - November 1, 2014" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2014 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE;
# else
return "libpng version 1.6.15beta02 - October 29, 2014\
return "libpng version 1.6.15beta02 - November 1, 2014\
Copyright (c) 1998-2014 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@ -899,7 +902,7 @@ png_handle_as_unknown(png_const_structrp png_ptr, png_const_bytep chunk_name)
{
p -= 5;
if (!memcmp(chunk_name, p, 4))
if (memcmp(chunk_name, p, 4) == 0)
return p[4];
}
while (p > p_end);
@ -1041,8 +1044,8 @@ png_colorspace_check_gamma(png_const_structrp png_ptr,
png_fixed_point gtest;
if ((colorspace->flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
(!png_muldiv(&gtest, colorspace->gamma, PNG_FP_1, gAMA) ||
png_gamma_significant(gtest)))
(png_muldiv(&gtest, colorspace->gamma, PNG_FP_1, gAMA) == 0 ||
png_gamma_significant(gtest) != 0))
{
/* Either this is an sRGB image, in which case the calculated gamma
* approximation should match, or this is an image with a profile and the
@ -1097,12 +1100,13 @@ png_colorspace_set_gamma(png_const_structrp png_ptr,
# endif
/* Do nothing if the colorspace is already invalid */
else if (colorspace->flags & PNG_COLORSPACE_INVALID)
else if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)
return;
else
{
if (png_colorspace_check_gamma(png_ptr, colorspace, gAMA, 1/*from gAMA*/))
if (png_colorspace_check_gamma(png_ptr, colorspace, gAMA,
1/*from gAMA*/) != 0)
{
/* Store this gamma value. */
colorspace->gamma = gAMA;
@ -1126,7 +1130,7 @@ png_colorspace_set_gamma(png_const_structrp png_ptr,
void /* PRIVATE */
png_colorspace_sync_info(png_const_structrp png_ptr, png_inforp info_ptr)
{
if (info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID)
if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)
{
/* Everything is invalid */
info_ptr->valid &= ~(PNG_INFO_gAMA|PNG_INFO_cHRM|PNG_INFO_sRGB|
@ -1147,20 +1151,20 @@ png_colorspace_sync_info(png_const_structrp png_ptr, png_inforp info_ptr)
* it; this allows a PNG to contain a profile which matches sRGB and
* yet still have that profile retrievable by the application.
*/
if (info_ptr->colorspace.flags & PNG_COLORSPACE_MATCHES_sRGB)
if ((info_ptr->colorspace.flags & PNG_COLORSPACE_MATCHES_sRGB) != 0)
info_ptr->valid |= PNG_INFO_sRGB;
else
info_ptr->valid &= ~PNG_INFO_sRGB;
if (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS)
if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
info_ptr->valid |= PNG_INFO_cHRM;
else
info_ptr->valid &= ~PNG_INFO_cHRM;
# endif
if (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA)
if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0)
info_ptr->valid |= PNG_INFO_gAMA;
else
@ -1193,22 +1197,28 @@ png_xy_from_XYZ(png_xy *xy, const png_XYZ *XYZ)
png_int_32 d, dwhite, whiteX, whiteY;
d = XYZ->red_X + XYZ->red_Y + XYZ->red_Z;
if (!png_muldiv(&xy->redx, XYZ->red_X, PNG_FP_1, d)) return 1;
if (!png_muldiv(&xy->redy, XYZ->red_Y, PNG_FP_1, d)) return 1;
if (png_muldiv(&xy->redx, XYZ->red_X, PNG_FP_1, d) == 0)
return 1;
if (png_muldiv(&xy->redy, XYZ->red_Y, PNG_FP_1, d) == 0)
return 1;
dwhite = d;
whiteX = XYZ->red_X;
whiteY = XYZ->red_Y;
d = XYZ->green_X + XYZ->green_Y + XYZ->green_Z;
if (!png_muldiv(&xy->greenx, XYZ->green_X, PNG_FP_1, d)) return 1;
if (!png_muldiv(&xy->greeny, XYZ->green_Y, PNG_FP_1, d)) return 1;
if (png_muldiv(&xy->greenx, XYZ->green_X, PNG_FP_1, d) == 0)
return 1;
if (png_muldiv(&xy->greeny, XYZ->green_Y, PNG_FP_1, d) == 0)
return 1;
dwhite += d;
whiteX += XYZ->green_X;
whiteY += XYZ->green_Y;
d = XYZ->blue_X + XYZ->blue_Y + XYZ->blue_Z;
if (!png_muldiv(&xy->bluex, XYZ->blue_X, PNG_FP_1, d)) return 1;
if (!png_muldiv(&xy->bluey, XYZ->blue_Y, PNG_FP_1, d)) return 1;
if (png_muldiv(&xy->bluex, XYZ->blue_X, PNG_FP_1, d) == 0)
return 1;
if (png_muldiv(&xy->bluey, XYZ->blue_Y, PNG_FP_1, d) == 0)
return 1;
dwhite += d;
whiteX += XYZ->blue_X;
whiteY += XYZ->blue_Y;
@ -1216,8 +1226,10 @@ png_xy_from_XYZ(png_xy *xy, const png_XYZ *XYZ)
/* The reference white is simply the sum of the end-point (X,Y,Z) vectors,
* thus:
*/
if (!png_muldiv(&xy->whitex, whiteX, PNG_FP_1, dwhite)) return 1;
if (!png_muldiv(&xy->whitey, whiteY, PNG_FP_1, dwhite)) return 1;
if (png_muldiv(&xy->whitex, whiteX, PNG_FP_1, dwhite) == 0)
return 1;
if (png_muldiv(&xy->whitey, whiteY, PNG_FP_1, dwhite) == 0)
return 1;
return 0;
}
@ -1420,16 +1432,16 @@ png_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy)
/* By the argument, above overflow should be impossible here. The return
* value of 2 indicates an internal error to the caller.
*/
if (!png_muldiv(&left, xy->greenx-xy->bluex, xy->redy - xy->bluey, 7))
if (png_muldiv(&left, xy->greenx-xy->bluex, xy->redy - xy->bluey, 7) == 0)
return 2;
if (!png_muldiv(&right, xy->greeny-xy->bluey, xy->redx - xy->bluex, 7))
if (png_muldiv(&right, xy->greeny-xy->bluey, xy->redx - xy->bluex, 7) == 0)
return 2;
denominator = left - right;
/* Now find the red numerator. */
if (!png_muldiv(&left, xy->greenx-xy->bluex, xy->whitey-xy->bluey, 7))
if (png_muldiv(&left, xy->greenx-xy->bluex, xy->whitey-xy->bluey, 7) == 0)
return 2;
if (!png_muldiv(&right, xy->greeny-xy->bluey, xy->whitex-xy->bluex, 7))
if (png_muldiv(&right, xy->greeny-xy->bluey, xy->whitex-xy->bluex, 7) == 0)
return 2;
/* Overflow is possible here and it indicates an extreme set of PNG cHRM
@ -1437,16 +1449,16 @@ png_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy)
* scale value because this allows us to delay the multiplication of white-y
* into the denominator, which tends to produce a small number.
*/
if (!png_muldiv(&red_inverse, xy->whitey, denominator, left-right) ||
if (png_muldiv(&red_inverse, xy->whitey, denominator, left-right) == 0 ||
red_inverse <= xy->whitey /* r+g+b scales = white scale */)
return 1;
/* Similarly for green_inverse: */
if (!png_muldiv(&left, xy->redy-xy->bluey, xy->whitex-xy->bluex, 7))
if (png_muldiv(&left, xy->redy-xy->bluey, xy->whitex-xy->bluex, 7) == 0)
return 2;
if (!png_muldiv(&right, xy->redx-xy->bluex, xy->whitey-xy->bluey, 7))
if (png_muldiv(&right, xy->redx-xy->bluex, xy->whitey-xy->bluey, 7) == 0)
return 2;
if (!png_muldiv(&green_inverse, xy->whitey, denominator, left-right) ||
if (png_muldiv(&green_inverse, xy->whitey, denominator, left-right) == 0 ||
green_inverse <= xy->whitey)
return 1;
@ -1454,29 +1466,34 @@ png_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy)
* can still produce 0 for extreme cHRM values.
*/
blue_scale = png_reciprocal(xy->whitey) - png_reciprocal(red_inverse) -
png_reciprocal(green_inverse);
if (blue_scale <= 0) return 1;
png_reciprocal(green_inverse);
if (blue_scale <= 0)
return 1;
/* And fill in the png_XYZ: */
if (!png_muldiv(&XYZ->red_X, xy->redx, PNG_FP_1, red_inverse)) return 1;
if (!png_muldiv(&XYZ->red_Y, xy->redy, PNG_FP_1, red_inverse)) return 1;
if (!png_muldiv(&XYZ->red_Z, PNG_FP_1 - xy->redx - xy->redy, PNG_FP_1,
red_inverse))
if (png_muldiv(&XYZ->red_X, xy->redx, PNG_FP_1, red_inverse) == 0)
return 1;
if (png_muldiv(&XYZ->red_Y, xy->redy, PNG_FP_1, red_inverse) == 0)
return 1;
if (png_muldiv(&XYZ->red_Z, PNG_FP_1 - xy->redx - xy->redy, PNG_FP_1,
red_inverse) == 0)
return 1;
if (!png_muldiv(&XYZ->green_X, xy->greenx, PNG_FP_1, green_inverse))
if (png_muldiv(&XYZ->green_X, xy->greenx, PNG_FP_1, green_inverse) == 0)
return 1;
if (!png_muldiv(&XYZ->green_Y, xy->greeny, PNG_FP_1, green_inverse))
if (png_muldiv(&XYZ->green_Y, xy->greeny, PNG_FP_1, green_inverse) == 0)
return 1;
if (!png_muldiv(&XYZ->green_Z, PNG_FP_1 - xy->greenx - xy->greeny, PNG_FP_1,
green_inverse))
if (png_muldiv(&XYZ->green_Z, PNG_FP_1 - xy->greenx - xy->greeny, PNG_FP_1,
green_inverse) == 0)
return 1;
if (!png_muldiv(&XYZ->blue_X, xy->bluex, blue_scale, PNG_FP_1)) return 1;
if (!png_muldiv(&XYZ->blue_Y, xy->bluey, blue_scale, PNG_FP_1)) return 1;
if (!png_muldiv(&XYZ->blue_Z, PNG_FP_1 - xy->bluex - xy->bluey, blue_scale,
PNG_FP_1))
if (png_muldiv(&XYZ->blue_X, xy->bluex, blue_scale, PNG_FP_1) == 0)
return 1;
if (png_muldiv(&XYZ->blue_Y, xy->bluey, blue_scale, PNG_FP_1) == 0)
return 1;
if (png_muldiv(&XYZ->blue_Z, PNG_FP_1 - xy->bluex - xy->bluey, blue_scale,
PNG_FP_1) == 0)
return 1;
return 0; /*success*/
@ -1498,24 +1515,35 @@ png_XYZ_normalize(png_XYZ *XYZ)
* safe.
*/
Y = XYZ->red_Y;
if (0x7fffffff - Y < XYZ->green_X) return 1;
if (0x7fffffff - Y < XYZ->green_X)
return 1;
Y += XYZ->green_Y;
if (0x7fffffff - Y < XYZ->blue_X) return 1;
if (0x7fffffff - Y < XYZ->blue_X)
return 1;
Y += XYZ->blue_Y;
if (Y != PNG_FP_1)
{
if (!png_muldiv(&XYZ->red_X, XYZ->red_X, PNG_FP_1, Y)) return 1;
if (!png_muldiv(&XYZ->red_Y, XYZ->red_Y, PNG_FP_1, Y)) return 1;
if (!png_muldiv(&XYZ->red_Z, XYZ->red_Z, PNG_FP_1, Y)) return 1;
if (png_muldiv(&XYZ->red_X, XYZ->red_X, PNG_FP_1, Y) == 0)
return 1;
if (png_muldiv(&XYZ->red_Y, XYZ->red_Y, PNG_FP_1, Y) == 0)
return 1;
if (png_muldiv(&XYZ->red_Z, XYZ->red_Z, PNG_FP_1, Y) == 0)
return 1;
if (!png_muldiv(&XYZ->green_X, XYZ->green_X, PNG_FP_1, Y)) return 1;
if (!png_muldiv(&XYZ->green_Y, XYZ->green_Y, PNG_FP_1, Y)) return 1;
if (!png_muldiv(&XYZ->green_Z, XYZ->green_Z, PNG_FP_1, Y)) return 1;
if (png_muldiv(&XYZ->green_X, XYZ->green_X, PNG_FP_1, Y) == 0)
return 1;
if (png_muldiv(&XYZ->green_Y, XYZ->green_Y, PNG_FP_1, Y) == 0)
return 1;
if (png_muldiv(&XYZ->green_Z, XYZ->green_Z, PNG_FP_1, Y) == 0)
return 1;
if (!png_muldiv(&XYZ->blue_X, XYZ->blue_X, PNG_FP_1, Y)) return 1;
if (!png_muldiv(&XYZ->blue_Y, XYZ->blue_Y, PNG_FP_1, Y)) return 1;
if (!png_muldiv(&XYZ->blue_Z, XYZ->blue_Z, PNG_FP_1, Y)) return 1;
if (png_muldiv(&XYZ->blue_X, XYZ->blue_X, PNG_FP_1, Y) == 0)
return 1;
if (png_muldiv(&XYZ->blue_Y, XYZ->blue_Y, PNG_FP_1, Y) == 0)
return 1;
if (png_muldiv(&XYZ->blue_Z, XYZ->blue_Z, PNG_FP_1, Y) == 0)
return 1;
}
return 0;
@ -1525,14 +1553,16 @@ static int
png_colorspace_endpoints_match(const png_xy *xy1, const png_xy *xy2, int delta)
{
/* Allow an error of +/-0.01 (absolute value) on each chromaticity */
return !(PNG_OUT_OF_RANGE(xy1->whitex, xy2->whitex,delta) ||
PNG_OUT_OF_RANGE(xy1->whitey, xy2->whitey,delta) ||
PNG_OUT_OF_RANGE(xy1->redx, xy2->redx, delta) ||
PNG_OUT_OF_RANGE(xy1->redy, xy2->redy, delta) ||
PNG_OUT_OF_RANGE(xy1->greenx, xy2->greenx,delta) ||
PNG_OUT_OF_RANGE(xy1->greeny, xy2->greeny,delta) ||
PNG_OUT_OF_RANGE(xy1->bluex, xy2->bluex, delta) ||
PNG_OUT_OF_RANGE(xy1->bluey, xy2->bluey, delta));
if (PNG_OUT_OF_RANGE(xy1->whitex, xy2->whitex,delta) ||
PNG_OUT_OF_RANGE(xy1->whitey, xy2->whitey,delta) ||
PNG_OUT_OF_RANGE(xy1->redx, xy2->redx, delta) ||
PNG_OUT_OF_RANGE(xy1->redy, xy2->redy, delta) ||
PNG_OUT_OF_RANGE(xy1->greenx, xy2->greenx,delta) ||
PNG_OUT_OF_RANGE(xy1->greeny, xy2->greeny,delta) ||
PNG_OUT_OF_RANGE(xy1->bluex, xy2->bluex, delta) ||
PNG_OUT_OF_RANGE(xy1->bluey, xy2->bluey, delta))
return 0;
return 1;
}
/* Added in libpng-1.6.0, a different check for the validity of a set of cHRM
@ -1553,13 +1583,15 @@ png_colorspace_check_xy(png_XYZ *XYZ, const png_xy *xy)
/* As a side-effect this routine also returns the XYZ endpoints. */
result = png_XYZ_from_xy(XYZ, xy);
if (result != 0) return result;
if (result != 0)
return result;
result = png_xy_from_XYZ(&xy_test, XYZ);
if (result != 0) return result;
if (result != 0)
return result;
if (png_colorspace_endpoints_match(xy, &xy_test,
5/*actually, the math is pretty accurate*/))
5/*actually, the math is pretty accurate*/) != 0)
return 0;
/* Too much slip */
@ -1576,10 +1608,12 @@ png_colorspace_check_XYZ(png_xy *xy, png_XYZ *XYZ)
png_XYZ XYZtemp;
result = png_XYZ_normalize(XYZ);
if (result != 0) return result;
if (result != 0)
return result;
result = png_xy_from_XYZ(xy, XYZ);
if (result != 0) return result;
if (result != 0)
return result;
XYZtemp = *XYZ;
return png_colorspace_check_xy(&XYZtemp, xy);
@ -1612,7 +1646,8 @@ png_colorspace_set_xy_and_XYZ(png_const_structrp png_ptr,
/* The end points must be reasonably close to any we already have. The
* following allows an error of up to +/-.001
*/
if (!png_colorspace_endpoints_match(xy, &colorspace->end_points_xy, 100))
if (png_colorspace_endpoints_match(xy, &colorspace->end_points_xy,
100) == 0)
{
colorspace->flags |= PNG_COLORSPACE_INVALID;
png_benign_error(png_ptr, "inconsistent chromaticities");
@ -1631,7 +1666,7 @@ png_colorspace_set_xy_and_XYZ(png_const_structrp png_ptr,
/* The end points are normally quoted to two decimal digits, so allow +/-0.01
* on this test.
*/
if (png_colorspace_endpoints_match(xy, &sRGB_xy, 1000))
if (png_colorspace_endpoints_match(xy, &sRGB_xy, 1000) != 0)
colorspace->flags |= PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB;
else
@ -1759,7 +1794,7 @@ png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace,
pos = png_safecat(message, (sizeof message), 0, "profile '"); /* 9 chars */
pos = png_safecat(message, pos+79, pos, name); /* Truncate to 79 chars */
pos = png_safecat(message, (sizeof message), pos, "': "); /* +2 = 90 */
if (is_ICC_signature(value))
if (is_ICC_signature(value) != 0)
{
/* So 'value' is at most 4 bytes and the following cast is safe */
png_icc_tag_name(message+pos, (png_uint_32)value);
@ -1820,7 +1855,7 @@ png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
};
/* Do nothing if the colorspace is already invalidated. */
if (colorspace->flags & PNG_COLORSPACE_INVALID)
if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)
return 0;
/* Check the intent, then check for existing settings. It is valid for the
@ -1999,13 +2034,13 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
switch (temp)
{
case 0x52474220: /* 'RGB ' */
if (!(color_type & PNG_COLOR_MASK_COLOR))
if ((color_type & PNG_COLOR_MASK_COLOR) == 0)
return png_icc_profile_error(png_ptr, colorspace, name, temp,
"RGB color space not permitted on grayscale PNG");
break;
case 0x47524159: /* 'GRAY' */
if (color_type & PNG_COLOR_MASK_COLOR)
if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
return png_icc_profile_error(png_ptr, colorspace, name, temp,
"Gray color space not permitted on RGB PNG");
break;
@ -2233,7 +2268,7 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,
* are not used by default if there is an MD5!)
*/
# if PNG_sRGB_PROFILE_CHECKS == 0
if (png_sRGB_checks[i].have_md5)
if (png_sRGB_checks[i].have_md5 != 0)
return 1+png_sRGB_checks[i].is_broken;
# endif
@ -2273,7 +2308,7 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,
if (crc == png_sRGB_checks[i].crc)
# endif
{
if (png_sRGB_checks[i].is_broken)
if (png_sRGB_checks[i].is_broken != 0)
{
/* These profiles are known to have bad data that may cause
* problems if they are used, therefore attempt to
@ -2288,7 +2323,7 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,
* the profile is perfectly valid, but it would be nice if
* people used the up-to-date ones.
*/
else if (!png_sRGB_checks[i].have_md5)
else if (png_sRGB_checks[i].have_md5 == 0)
{
png_chunk_report(png_ptr, "out-of-date sRGB profile with"
" no signature",
@ -2326,7 +2361,7 @@ png_icc_set_sRGB(png_const_structrp png_ptr,
* the sRGB information.
*/
#if PNG_sRGB_PROFILE_CHECKS >= 0
if (png_compare_ICC_profile_with_sRGB(png_ptr, profile, adler))
if (png_compare_ICC_profile_with_sRGB(png_ptr, profile, adler) != 0)
#endif
(void)png_colorspace_set_sRGB(png_ptr, colorspace,
(int)/*already checked*/png_get_uint_32(profile+64));
@ -2338,14 +2373,14 @@ png_colorspace_set_ICC(png_const_structrp png_ptr, png_colorspacerp colorspace,
png_const_charp name, png_uint_32 profile_length, png_const_bytep profile,
int color_type)
{
if (colorspace->flags & PNG_COLORSPACE_INVALID)
if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)
return 0;
if (png_icc_check_length(png_ptr, colorspace, name, profile_length) &&
png_icc_check_header(png_ptr, colorspace, name, profile_length, profile,
color_type) &&
png_icc_check_tag_table(png_ptr, colorspace, name, profile_length,
profile))
if (png_icc_check_length(png_ptr, colorspace, name, profile_length) != 0 &&
png_icc_check_header(png_ptr, colorspace, name, profile_length, profile,
color_type) != 0 &&
png_icc_check_tag_table(png_ptr, colorspace, name, profile_length,
profile) != 0)
{
# ifdef PNG_sRGB_SUPPORTED
/* If no sRGB support, don't try storing sRGB information */
@ -2364,7 +2399,7 @@ void /* PRIVATE */
png_colorspace_set_rgb_coefficients(png_structrp png_ptr)
{
/* Set the rgb_to_gray coefficients from the colorspace. */
if (!png_ptr->rgb_to_gray_coefficients_set &&
if (png_ptr->rgb_to_gray_coefficients_set == 0 &&
(png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
{
/* png_set_background has not been called, get the coefficients from the Y
@ -2528,13 +2563,13 @@ png_check_IHDR(png_const_structrp png_ptr,
* 4. The filter_method is 64 and
* 5. The color_type is RGB or RGBA
*/
if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) &&
png_ptr->mng_features_permitted)
if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 &&
png_ptr->mng_features_permitted != 0)
png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
if (filter_type != PNG_FILTER_TYPE_BASE)
{
if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 &&
(filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) &&
(color_type == PNG_COLOR_TYPE_RGB ||
@ -2544,7 +2579,7 @@ png_check_IHDR(png_const_structrp png_ptr,
error = 1;
}
if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE)
if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0)
{
png_warning(png_ptr, "Invalid filter method in IHDR");
error = 1;
@ -2604,7 +2639,7 @@ png_check_fp_number(png_const_charp string, png_size_t size, int *statep,
switch ((state & PNG_FP_STATE) + (type & PNG_FP_SAW_ANY))
{
case PNG_FP_INTEGER + PNG_FP_SAW_SIGN:
if (state & PNG_FP_SAW_ANY)
if ((state & PNG_FP_SAW_ANY) != 0)
goto PNG_FP_End; /* not a part of the number */
png_fp_add(state, type);
@ -2612,10 +2647,10 @@ png_check_fp_number(png_const_charp string, png_size_t size, int *statep,
case PNG_FP_INTEGER + PNG_FP_SAW_DOT:
/* Ok as trailer, ok as lead of fraction. */
if (state & PNG_FP_SAW_DOT) /* two dots */
if ((state & PNG_FP_SAW_DOT) != 0) /* two dots */
goto PNG_FP_End;
else if (state & PNG_FP_SAW_DIGIT) /* trailing dot? */
else if ((state & PNG_FP_SAW_DIGIT) != 0) /* trailing dot? */
png_fp_add(state, type);
else
@ -2624,7 +2659,7 @@ png_check_fp_number(png_const_charp string, png_size_t size, int *statep,
break;
case PNG_FP_INTEGER + PNG_FP_SAW_DIGIT:
if (state & PNG_FP_SAW_DOT) /* delayed fraction */
if ((state & PNG_FP_SAW_DOT) != 0) /* delayed fraction */
png_fp_set(state, PNG_FP_FRACTION | PNG_FP_SAW_DOT);
png_fp_add(state, type | PNG_FP_WAS_VALID);
@ -2662,7 +2697,7 @@ png_check_fp_number(png_const_charp string, png_size_t size, int *statep,
break;
case PNG_FP_EXPONENT + PNG_FP_SAW_SIGN:
if (state & PNG_FP_SAW_ANY)
if ((state & PNG_FP_SAW_ANY) != 0)
goto PNG_FP_End; /* not a part of the number */
png_fp_add(state, PNG_FP_SAW_SIGN);
@ -2705,7 +2740,7 @@ png_check_fp_string(png_const_charp string, png_size_t size)
int state=0;
png_size_t char_index=0;
if (png_check_fp_number(string, size, &state, &char_index) &&
if (png_check_fp_number(string, size, &state, &char_index) != 0 &&
(char_index == size || string[char_index] == 0))
return state /* must be non-zero - see above */;
@ -2959,8 +2994,9 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
if (exp_b10 != (-1))
{
if (exp_b10 == 0) *ascii++ = 46, --size; /* counted
above */
if (exp_b10 == 0)
*ascii++ = 46, --size; /* counted above */
--exp_b10;
}
*ascii++ = (char)(48 + (int)d), ++cdigits;
@ -3297,7 +3333,7 @@ png_muldiv_warn(png_const_structrp png_ptr, png_fixed_point a, png_int_32 times,
{
png_fixed_point result;
if (png_muldiv(&result, a, times, divisor))
if (png_muldiv(&result, a, times, divisor) != 0)
return result;
png_warning(png_ptr, "fixed point overflow ignored");
@ -3318,7 +3354,7 @@ png_reciprocal(png_fixed_point a)
#else
png_fixed_point res;
if (png_muldiv(&res, 100000, 100000, a))
if (png_muldiv(&res, 100000, 100000, a) != 0)
return res;
#endif
@ -3353,7 +3389,7 @@ png_product2(png_fixed_point a, png_fixed_point b)
# else
png_fixed_point res;
if (png_muldiv(&res, a, b, 100000))
if (png_muldiv(&res, a, b, 100000) != 0)
return res;
# endif
@ -3690,7 +3726,7 @@ png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val)
png_int_32 lg2 = png_log8bit(value);
png_fixed_point res;
if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1))
if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1) != 0)
return png_exp8bit(res);
/* Overflow. */
@ -3714,7 +3750,7 @@ png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val)
png_int_32 lg2 = png_log16bit(value);
png_fixed_point res;
if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1))
if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1) != 0)
return png_exp16bit(res);
/* Overflow. */
@ -3777,7 +3813,7 @@ png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable,
/* The 'threshold' test is repeated here because it can arise for one of
* the 16-bit tables even if the others don't hit it.
*/
if (png_gamma_significant(gamma_val))
if (png_gamma_significant(gamma_val) != 0)
{
/* The old code would overflow at the end and this would cause the
* 'pow' function to return a result >1, resulting in an
@ -3899,11 +3935,13 @@ png_build_8bit_table(png_structrp png_ptr, png_bytepp ptable,
unsigned int i;
png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256);
if (png_gamma_significant(gamma_val)) for (i=0; i<256; i++)
table[i] = png_gamma_8bit_correct(i, gamma_val);
if (png_gamma_significant(gamma_val) != 0)
for (i=0; i<256; i++)
table[i] = png_gamma_8bit_correct(i, gamma_val);
else for (i=0; i<256; ++i)
table[i] = (png_byte)i;
else
for (i=0; i<256; ++i)
table[i] = (png_byte)i;
}
/* Used from png_read_destroy and below to release the memory used by the gamma
@ -3995,7 +4033,7 @@ png_build_gamma_table(png_structrp png_ptr, int bit_depth)
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
if (png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY))
if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0)
{
png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1,
png_reciprocal(png_ptr->colorspace.gamma));
@ -4011,7 +4049,7 @@ png_build_gamma_table(png_structrp png_ptr, int bit_depth)
{
png_byte shift, sig_bit;
if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
{
sig_bit = png_ptr->sig_bit.red;
@ -4048,7 +4086,7 @@ png_build_gamma_table(png_structrp png_ptr, int bit_depth)
else
shift = 0; /* keep all 16 bits */
if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8))
if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0)
{
/* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively
* the significant bits in the *input* when the output will
@ -4068,7 +4106,7 @@ png_build_gamma_table(png_structrp png_ptr, int bit_depth)
* 16-bit output because the 8-bit table assumes the result will be reduced
* to 8 bits.
*/
if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8))
if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0)
png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift,
png_ptr->screen_gamma > 0 ? png_product2(png_ptr->colorspace.gamma,
png_ptr->screen_gamma) : PNG_FP_1);
@ -4081,7 +4119,7 @@ png_build_gamma_table(png_structrp png_ptr, int bit_depth)
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
if (png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY))
if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0)
{
png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift,
png_reciprocal(png_ptr->colorspace.gamma));
@ -4307,7 +4345,7 @@ png_image_free_function(png_voidp argument)
/* First free any data held in the control structure. */
# ifdef PNG_STDIO_SUPPORTED
if (cp->owned_file)
if (cp->owned_file != 0)
{
FILE *fp = png_voidcast(FILE*, cp->png_ptr->io_ptr);
cp->owned_file = 0;
@ -4331,7 +4369,7 @@ png_image_free_function(png_voidp argument)
png_free(c.png_ptr, cp);
/* Then the structures, calling the correct API. */
if (c.for_write)
if (c.for_write != 0)
{
# ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
png_destroy_write_struct(&c.png_ptr, &c.info_ptr);

View File

@ -1,7 +1,7 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
* Last changed in libpng 1.6.13 [August 21, 2014]
* Last changed in libpng 1.6.15 [(PENDING RELEASE)]
* 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.)
@ -43,8 +43,8 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
char msg[16];
if (png_ptr != NULL)
{
if (png_ptr->flags&
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
if ((png_ptr->flags &
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0
{
if (*error_message == PNG_LITERAL_SHARP)
{
@ -54,7 +54,7 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
if (error_message[offset] == ' ')
break;
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
{
int i;
for (i = 0; i < offset - 1; i++)
@ -69,7 +69,7 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
else
{
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
{
msg[0] = '0';
msg[1] = '\0';
@ -152,7 +152,7 @@ png_format_number(png_const_charp start, png_charp end, int format,
case PNG_NUMBER_FORMAT_fixed:
/* Needs five digits (the fraction) */
mincount = 5;
if (output || number % 10 != 0)
if (output != 0 || number % 10 != 0)
{
*--end = digits[number % 10];
output = 1;
@ -189,7 +189,7 @@ png_format_number(png_const_charp start, png_charp end, int format,
++count;
/* Float a fixed number here: */
if (format == PNG_NUMBER_FORMAT_fixed) if (count == 5) if (end > start)
if ((format == PNG_NUMBER_FORMAT_fixed) && (count == 5) && (end > start))
{
/* End of the fraction, but maybe nothing was output? In that case
* drop the decimal point. If the number is a true zero handle that
@ -219,8 +219,8 @@ png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
if (png_ptr != NULL)
{
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (png_ptr->flags&
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
if ((png_ptr->flags &
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)
#endif
{
if (*warning_message == PNG_LITERAL_SHARP)
@ -361,7 +361,7 @@ png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p,
void PNGAPI
png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
{
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
{
# ifdef PNG_READ_SUPPORTED
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
@ -391,7 +391,7 @@ png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
void /* PRIVATE */
png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
{
if (png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN)
if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)
png_warning(png_ptr, error_message);
else
png_error(png_ptr, error_message);
@ -404,7 +404,7 @@ png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
void /* PRIVATE */
png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
{
if (png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN)
if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0)
png_warning(png_ptr, error_message);
else
png_error(png_ptr, error_message);
@ -442,7 +442,7 @@ png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
int c = (int)(chunk_name >> ishift) & 0xff;
ishift -= 8;
if (isnonalpha(c))
if (isnonalpha(c) != 0)
{
buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
@ -514,7 +514,7 @@ void PNGAPI
png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp
error_message)
{
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
png_chunk_warning(png_ptr, error_message);
else
@ -538,7 +538,7 @@ png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
* unconditionally does the right thing.
*/
# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
if (png_ptr->mode & PNG_IS_READ_STRUCT)
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
# endif
# ifdef PNG_READ_SUPPORTED
@ -552,7 +552,7 @@ png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
# endif
# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
else if (!(png_ptr->mode & PNG_IS_READ_STRUCT))
else if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
# endif
# ifdef PNG_WRITE_SUPPORTED
@ -577,11 +577,12 @@ png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN)
char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
memcpy(msg, fixed_message, fixed_message_ln);
iin = 0;
if (name != NULL) while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
{
msg[fixed_message_ln + iin] = name[iin];
++iin;
}
if (name != NULL)
while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
{
msg[fixed_message_ln + iin] = name[iin];
++iin;
}
msg[fixed_message_ln + iin] = 0;
png_error(png_ptr, msg);
}
@ -757,7 +758,8 @@ PNG_FUNCTION(void,PNGAPI
png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN)
{
#ifdef PNG_SETJMP_SUPPORTED
if (png_ptr && png_ptr->longjmp_fn && png_ptr->jmp_buf_ptr)
if (png_ptr != NULL && png_ptr->longjmp_fn != NULL &&
png_ptr->jmp_buf_ptr != NULL)
png_ptr->longjmp_fn(*png_ptr->jmp_buf_ptr, val);
#else
PNG_UNUSED(png_ptr)

106
pngget.c
View File

@ -1,7 +1,7 @@
/* pngget.c - retrieval of values from info struct
*
* Last changed in libpng 1.6.11 [June 5, 2014]
* Last changed in libpng 1.6.15 [(PENDING RELEASE)]
* 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.)
@ -116,7 +116,8 @@ png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
info_ptr)
{
#ifdef PNG_pHYs_SUPPORTED
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_pHYs) != 0)
{
png_debug1(1, "in %s retrieval function",
"png_get_x_pixels_per_meter");
@ -137,7 +138,8 @@ png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
info_ptr)
{
#ifdef PNG_pHYs_SUPPORTED
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_pHYs) != 0)
{
png_debug1(1, "in %s retrieval function",
"png_get_y_pixels_per_meter");
@ -157,7 +159,8 @@ png_uint_32 PNGAPI
png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
#ifdef PNG_pHYs_SUPPORTED
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_pHYs) != 0)
{
png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
@ -202,10 +205,11 @@ png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
png_const_inforp info_ptr)
{
#ifdef PNG_READ_pHYs_SUPPORTED
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
&& info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
&& info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
&& info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_pHYs) != 0 &&
info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 &&
info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX &&
info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
{
png_fixed_point res;
@ -215,7 +219,7 @@ png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
* range of 0..2^31-1; otherwise the cast might overflow.
*/
if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
(png_int_32)info_ptr->x_pixels_per_unit))
(png_int_32)info_ptr->x_pixels_per_unit) != 0)
return res;
}
#else
@ -231,7 +235,8 @@ png_int_32 PNGAPI
png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
#ifdef PNG_oFFs_SUPPORTED
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_oFFs) != 0)
{
png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
@ -250,7 +255,8 @@ png_int_32 PNGAPI
png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
#ifdef PNG_oFFs_SUPPORTED
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_oFFs) != 0)
{
png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
@ -269,7 +275,8 @@ png_int_32 PNGAPI
png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
#ifdef PNG_oFFs_SUPPORTED
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_oFFs) != 0)
{
png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
@ -288,7 +295,8 @@ png_int_32 PNGAPI
png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
#ifdef PNG_oFFs_SUPPORTED
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_oFFs) != 0)
{
png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
@ -328,7 +336,7 @@ ppi_from_ppm(png_uint_32 ppm)
*/
png_fixed_point result;
if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
5000))
5000) != 0)
return result;
/* Overflow. */
@ -414,7 +422,8 @@ png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
{
png_uint_32 retval = 0;
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_pHYs) != 0)
{
png_debug1(1, "in %s retrieval function", "pHYs");
@ -478,8 +487,9 @@ png_uint_32 PNGAPI
png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
png_color_16p *background)
{
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
&& background != NULL)
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_bKGD) != 0 &&
background != NULL)
{
png_debug1(1, "in %s retrieval function", "bKGD");
@ -509,7 +519,7 @@ png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
* consistent.
*/
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
{
png_debug1(1, "in %s retrieval function", "cHRM");
@ -550,7 +560,7 @@ png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
double *blue_Z)
{
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
{
png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
@ -598,7 +608,7 @@ png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_fixed_point *int_blue_Z)
{
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
{
png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
@ -635,7 +645,7 @@ png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_debug1(1, "in %s retrieval function", "cHRM");
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
{
if (white_x != NULL)
*white_x = info_ptr->colorspace.end_points_xy.whitex;
@ -670,7 +680,7 @@ png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_debug1(1, "in %s retrieval function", "gAMA");
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
file_gamma != NULL)
{
*file_gamma = info_ptr->colorspace.gamma;
@ -689,7 +699,7 @@ png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_debug1(1, "in %s retrieval function", "gAMA(float)");
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
file_gamma != NULL)
{
*file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
@ -709,8 +719,8 @@ png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
{
png_debug1(1, "in %s retrieval function", "sRGB");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
&& file_srgb_intent != NULL)
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL)
{
*file_srgb_intent = info_ptr->colorspace.rendering_intent;
return (PNG_INFO_sRGB);
@ -728,9 +738,10 @@ png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
{
png_debug1(1, "in %s retrieval function", "iCCP");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
&& name != NULL && compression_type != NULL && profile != NULL &&
proflen != NULL)
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_iCCP) != 0 &&
name != NULL && compression_type != NULL && profile != NULL &&
proflen != NULL)
{
*name = info_ptr->iccp_name;
*profile = info_ptr->iccp_profile;
@ -768,8 +779,8 @@ png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
{
png_debug1(1, "in %s retrieval function", "hIST");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
&& hist != NULL)
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
{
*hist = info_ptr->hist;
return (PNG_INFO_hIST);
@ -824,8 +835,9 @@ png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
{
png_debug1(1, "in %s retrieval function", "oFFs");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
&& offset_x != NULL && offset_y != NULL && unit_type != NULL)
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_oFFs) != 0 &&
offset_x != NULL && offset_y != NULL && unit_type != NULL)
{
*offset_x = info_ptr->x_offset;
*offset_y = info_ptr->y_offset;
@ -845,8 +857,9 @@ png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
{
png_debug1(1, "in %s retrieval function", "pCAL");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
&& purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_pCAL) != 0 &&
purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
nparams != NULL && units != NULL && params != NULL)
{
*purpose = info_ptr->pcal_purpose;
@ -872,7 +885,7 @@ png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
int *unit, png_fixed_point *width, png_fixed_point *height)
{
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_sCAL))
(info_ptr->valid & PNG_INFO_sCAL) != 0)
{
*unit = info_ptr->scal_unit;
/*TODO: make this work without FP support; the API is currently eliminated
@ -895,7 +908,7 @@ png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
int *unit, double *width, double *height)
{
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_sCAL))
(info_ptr->valid & PNG_INFO_sCAL) != 0)
{
*unit = info_ptr->scal_unit;
*width = atof(info_ptr->scal_s_width);
@ -911,7 +924,7 @@ png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
int *unit, png_charpp width, png_charpp height)
{
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_sCAL))
(info_ptr->valid & PNG_INFO_sCAL) != 0)
{
*unit = info_ptr->scal_unit;
*width = info_ptr->scal_s_width;
@ -933,7 +946,7 @@ png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_debug1(1, "in %s retrieval function", "pHYs");
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_pHYs))
(info_ptr->valid & PNG_INFO_pHYs) != 0)
{
if (res_x != NULL)
{
@ -964,8 +977,8 @@ png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
{
png_debug1(1, "in %s retrieval function", "PLTE");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
&& palette != NULL)
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
{
*palette = info_ptr->palette;
*num_palette = info_ptr->num_palette;
@ -983,8 +996,8 @@ png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
{
png_debug1(1, "in %s retrieval function", "sBIT");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
&& sig_bit != NULL)
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
{
*sig_bit = &(info_ptr->sig_bit);
return (PNG_INFO_sBIT);
@ -1027,8 +1040,8 @@ png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
{
png_debug1(1, "in %s retrieval function", "tIME");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
&& mod_time != NULL)
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
{
*mod_time = &(info_ptr->mod_time);
return (PNG_INFO_tIME);
@ -1044,7 +1057,8 @@ png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
{
png_uint_32 retval = 0;
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_tRNS) != 0)
{
png_debug1(1, "in %s retrieval function", "tRNS");
@ -1121,7 +1135,7 @@ png_get_compression_buffer_size(png_const_structrp png_ptr)
return 0;
# ifdef PNG_WRITE_SUPPORTED
if (png_ptr->mode & PNG_IS_READ_STRUCT)
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
# endif
{
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED

View File

@ -202,7 +202,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
* sure we have enough data in the buffer for the 4-byte CRC at the
* end of every chunk (except IDAT, which is handled separately).
*/
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0)
{
png_byte chunk_length[4];
png_byte chunk_tag[4];
@ -221,14 +221,14 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
if (chunk_name == png_IDAT)
{
if (png_ptr->mode & PNG_AFTER_IDAT)
if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)
png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
/* If we reach an IDAT chunk, this means we have read all of the
* header chunks, and we can start reading the image (or if this
* is called after the image has been read - we have an error).
*/
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_error(png_ptr, "Missing IHDR before IDAT");
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
@ -238,11 +238,11 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
png_ptr->mode |= PNG_HAVE_IDAT;
png_ptr->process_mode = PNG_READ_IDAT_MODE;
if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
if ((png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) == 0)
if (png_ptr->push_length == 0)
return;
if (png_ptr->mode & PNG_AFTER_IDAT)
if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)
png_benign_error(png_ptr, "Too many IDATs found");
}
@ -449,7 +449,7 @@ png_push_crc_skip(png_structrp png_ptr, png_uint_32 skip)
void /* PRIVATE */
png_push_crc_finish(png_structrp png_ptr)
{
if (png_ptr->skip_length && png_ptr->save_buffer_size)
if (png_ptr->skip_length != 0 && png_ptr->save_buffer_size != 0)
{
png_size_t save_size = png_ptr->save_buffer_size;
png_uint_32 skip_length = png_ptr->skip_length;
@ -473,7 +473,7 @@ png_push_crc_finish(png_structrp png_ptr)
png_ptr->save_buffer_size -= save_size;
png_ptr->save_buffer_ptr += save_size;
}
if (png_ptr->skip_length && png_ptr->current_buffer_size)
if (png_ptr->skip_length != 0 && png_ptr->current_buffer_size != 0)
{
png_size_t save_size = png_ptr->current_buffer_size;
png_uint_32 skip_length = png_ptr->skip_length;
@ -494,7 +494,7 @@ png_push_crc_finish(png_structrp png_ptr)
png_ptr->current_buffer_size -= save_size;
png_ptr->current_buffer_ptr += save_size;
}
if (!png_ptr->skip_length)
if (png_ptr->skip_length == 0)
{
PNG_PUSH_SAVE_BUFFER_IF_LT(4)
png_crc_finish(png_ptr, 0);
@ -511,7 +511,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
return;
ptr = buffer;
if (png_ptr->save_buffer_size)
if (png_ptr->save_buffer_size != 0)
{
png_size_t save_size;
@ -528,7 +528,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
png_ptr->save_buffer_size -= save_size;
png_ptr->save_buffer_ptr += save_size;
}
if (length && png_ptr->current_buffer_size)
if (length != 0 && png_ptr->current_buffer_size != 0)
{
png_size_t save_size;
@ -548,7 +548,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
void /* PRIVATE */
png_push_save_buffer(png_structrp png_ptr)
{
if (png_ptr->save_buffer_size)
if (png_ptr->save_buffer_size != 0)
{
if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
{
@ -617,7 +617,7 @@ png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer,
void /* PRIVATE */
png_push_read_IDAT(png_structrp png_ptr)
{
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0)
{
png_byte chunk_length[4];
png_byte chunk_tag[4];
@ -635,7 +635,7 @@ png_push_read_IDAT(png_structrp png_ptr)
{
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
if (!(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
png_error(png_ptr, "Not enough compressed data");
return;
@ -644,7 +644,7 @@ png_push_read_IDAT(png_structrp png_ptr)
png_ptr->idat_size = png_ptr->push_length;
}
if (png_ptr->idat_size && png_ptr->save_buffer_size)
if (png_ptr->idat_size != 0 && png_ptr->save_buffer_size != 0)
{
png_size_t save_size = png_ptr->save_buffer_size;
png_uint_32 idat_size = png_ptr->idat_size;
@ -671,7 +671,7 @@ png_push_read_IDAT(png_structrp png_ptr)
png_ptr->save_buffer_ptr += save_size;
}
if (png_ptr->idat_size && png_ptr->current_buffer_size)
if (png_ptr->idat_size != 0 && png_ptr->current_buffer_size != 0)
{
png_size_t save_size = png_ptr->current_buffer_size;
png_uint_32 idat_size = png_ptr->idat_size;
@ -696,7 +696,7 @@ png_push_read_IDAT(png_structrp png_ptr)
png_ptr->current_buffer_size -= save_size;
png_ptr->current_buffer_ptr += save_size;
}
if (!png_ptr->idat_size)
if (png_ptr->idat_size == 0)
{
PNG_PUSH_SAVE_BUFFER_IF_LT(4)
png_crc_finish(png_ptr, 0);
@ -843,7 +843,7 @@ png_push_process_row(png_structrp png_ptr)
memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
if (png_ptr->transformations)
if (png_ptr->transformations != 0)
png_do_read_transformations(png_ptr, &row_info);
#endif
@ -861,7 +861,8 @@ png_push_process_row(png_structrp png_ptr)
#ifdef PNG_READ_INTERLACING_SUPPORTED
/* Expand interlaced rows to full size */
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
if (png_ptr->interlaced != 0 &&
(png_ptr->transformations & PNG_INTERLACE) != 0)
{
if (png_ptr->pass < 6)
png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,
@ -1068,7 +1069,7 @@ png_read_push_finish_row(png_structrp png_ptr)
if (png_ptr->row_number < png_ptr->num_rows)
return;
if (png_ptr->interlaced)
if (png_ptr->interlaced != 0)
{
png_ptr->row_number = 0;
memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
@ -1092,7 +1093,7 @@ png_read_push_finish_row(png_structrp png_ptr)
png_pass_start[png_ptr->pass]) /
png_pass_inc[png_ptr->pass];
if (png_ptr->transformations & PNG_INTERLACE)
if ((png_ptr->transformations & PNG_INTERLACE) != 0)
break;
png_ptr->num_rows = (png_ptr->height +

140
pngread.c
View File

@ -113,14 +113,14 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
*/
if (chunk_name == png_IDAT)
{
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "Missing IHDR before IDAT");
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
!(png_ptr->mode & PNG_HAVE_PLTE))
(png_ptr->mode & PNG_HAVE_PLTE) == 0)
png_chunk_error(png_ptr, "Missing PLTE before IDAT");
else if (png_ptr->mode & PNG_AFTER_IDAT)
else if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)
png_chunk_benign_error(png_ptr, "Too many IDATs found");
png_ptr->mode |= PNG_HAVE_IDAT;
@ -385,7 +385,7 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
/* png_read_start_row sets the information (in particular iwidth) for this
* interlace pass.
*/
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0)
png_read_start_row(png_ptr);
/* 1.5.6: row_info moved out of png_struct to a local here. */
@ -516,7 +516,7 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
default:
case 6:
if (!(png_ptr->row_number & 1))
if ((png_ptr->row_number & 1) == 0)
{
png_read_finish_row(png_ptr);
return;
@ -526,7 +526,7 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
}
#endif
if (!(png_ptr->mode & PNG_HAVE_IDAT))
if ((png_ptr->mode & PNG_HAVE_IDAT) == 0)
png_error(png_ptr, "Invalid attempt to read row data");
/* Fill the row with IDAT data: */
@ -699,7 +699,7 @@ png_read_image(png_structrp png_ptr, png_bytepp image)
return;
#ifdef PNG_READ_INTERLACING_SUPPORTED
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0)
{
pass = png_set_interlace_handling(png_ptr);
/* And make sure transforms are initialized. */
@ -767,7 +767,7 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
* still be pending IDAT data and an owned zstream. Deal with this here.
*/
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
if (!png_chunk_unknown_handling(png_ptr, png_IDAT))
if (png_chunk_unknown_handling(png_ptr, png_IDAT) == 0)
#endif
png_read_finish_IDAT(png_ptr);
@ -797,7 +797,8 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
{
if (chunk_name == png_IDAT)
{
if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
if ((length > 0) ||
(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) != 0)
png_benign_error(png_ptr, "Too many IDATs found");
}
png_handle_unknown(png_ptr, info_ptr, length, keep);
@ -811,7 +812,8 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
/* Zero length IDATs are legal after the last IDAT has been
* read, but not after other chunks have been read.
*/
if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
if ((length > 0) ||
(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) != 0)
png_benign_error(png_ptr, "Too many IDATs found");
png_crc_finish(png_ptr, length);
@ -935,7 +937,7 @@ png_read_destroy(png_structrp png_ptr)
png_ptr->quantize_index = NULL;
#endif
if (png_ptr->free_me & PNG_FREE_PLTE)
if ((png_ptr->free_me & PNG_FREE_PLTE) != 0)
{
png_zfree(png_ptr, png_ptr->palette);
png_ptr->palette = NULL;
@ -944,7 +946,7 @@ png_read_destroy(png_structrp png_ptr)
#if defined(PNG_tRNS_SUPPORTED) || \
defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
if (png_ptr->free_me & PNG_FREE_TRNS)
if ((png_ptr->free_me & PNG_FREE_TRNS) != 0)
{
png_free(png_ptr, png_ptr->trans_alpha);
png_ptr->trans_alpha = NULL;
@ -1039,7 +1041,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
/* Tell libpng to strip 16-bit/color files down to 8 bits per color.
*/
if (transforms & PNG_TRANSFORM_SCALE_16)
if ((transforms & PNG_TRANSFORM_SCALE_16) != 0)
/* Added at libpng-1.5.4. "strip_16" produces the same result that it
* did in earlier versions, while "scale_16" is now more accurate.
*/
@ -1053,7 +1055,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
* latter by doing SCALE first. This is ok and allows apps not to check for
* which is supported to get the right answer.
*/
if (transforms & PNG_TRANSFORM_STRIP_16)
if ((transforms & PNG_TRANSFORM_STRIP_16) != 0)
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
png_set_strip_16(png_ptr);
#else
@ -1063,7 +1065,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
/* Strip alpha bytes from the input data without combining with
* the background (not recommended).
*/
if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
if ((transforms & PNG_TRANSFORM_STRIP_ALPHA) != 0)
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
png_set_strip_alpha(png_ptr);
#else
@ -1073,7 +1075,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
/* Extract multiple pixels with bit depths of 1, 2, or 4 from a single
* byte into separate bytes (useful for paletted and grayscale images).
*/
if (transforms & PNG_TRANSFORM_PACKING)
if ((transforms & PNG_TRANSFORM_PACKING) != 0)
#ifdef PNG_READ_PACK_SUPPORTED
png_set_packing(png_ptr);
#else
@ -1083,7 +1085,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
/* Change the order of packed pixels to least significant bit first
* (not useful if you are using png_set_packing).
*/
if (transforms & PNG_TRANSFORM_PACKSWAP)
if ((transforms & PNG_TRANSFORM_PACKSWAP) != 0)
#ifdef PNG_READ_PACKSWAP_SUPPORTED
png_set_packswap(png_ptr);
#else
@ -1095,7 +1097,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
* Expand paletted or RGB images with transparency to full alpha
* channels so the data will be available as RGBA quartets.
*/
if (transforms & PNG_TRANSFORM_EXPAND)
if ((transforms & PNG_TRANSFORM_EXPAND) != 0)
#ifdef PNG_READ_EXPAND_SUPPORTED
png_set_expand(png_ptr);
#else
@ -1107,7 +1109,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
/* Invert monochrome files to have 0 as white and 1 as black
*/
if (transforms & PNG_TRANSFORM_INVERT_MONO)
if ((transforms & PNG_TRANSFORM_INVERT_MONO) != 0)
#ifdef PNG_READ_INVERT_SUPPORTED
png_set_invert_mono(png_ptr);
#else
@ -1118,16 +1120,16 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
* [0,65535] to the original [0,7] or [0,31], or whatever range the
* colors were originally in:
*/
if (transforms & PNG_TRANSFORM_SHIFT)
if ((transforms & PNG_TRANSFORM_SHIFT) != 0)
#ifdef PNG_READ_SHIFT_SUPPORTED
if (info_ptr->valid & PNG_INFO_sBIT)
if ((info_ptr->valid & PNG_INFO_sBIT) != 0)
png_set_shift(png_ptr, &info_ptr->sig_bit);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_SHIFT not supported");
#endif
/* Flip the RGB pixels to BGR (or RGBA to BGRA) */
if (transforms & PNG_TRANSFORM_BGR)
if ((transforms & PNG_TRANSFORM_BGR) != 0)
#ifdef PNG_READ_BGR_SUPPORTED
png_set_bgr(png_ptr);
#else
@ -1135,7 +1137,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
#endif
/* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
if ((transforms & PNG_TRANSFORM_SWAP_ALPHA) != 0)
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
png_set_swap_alpha(png_ptr);
#else
@ -1143,7 +1145,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
#endif
/* Swap bytes of 16-bit files to least significant byte first */
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
if ((transforms & PNG_TRANSFORM_SWAP_ENDIAN) != 0)
#ifdef PNG_READ_SWAP_SUPPORTED
png_set_swap(png_ptr);
#else
@ -1152,7 +1154,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
/* Added at libpng-1.2.41 */
/* Invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
if ((transforms & PNG_TRANSFORM_INVERT_ALPHA) != 0)
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
png_set_invert_alpha(png_ptr);
#else
@ -1161,7 +1163,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
/* Added at libpng-1.2.41 */
/* Expand grayscale image to RGB */
if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
if ((transforms & PNG_TRANSFORM_GRAY_TO_RGB) != 0)
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
png_set_gray_to_rgb(png_ptr);
#else
@ -1169,7 +1171,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
#endif
/* Added at libpng-1.5.4 */
if (transforms & PNG_TRANSFORM_EXPAND_16)
if ((transforms & PNG_TRANSFORM_EXPAND_16) != 0)
#ifdef PNG_READ_EXPAND_16_SUPPORTED
png_set_expand_16(png_ptr);
#else
@ -1327,10 +1329,10 @@ png_image_format(png_structrp png_ptr)
{
png_uint_32 format = 0;
if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
format |= PNG_FORMAT_FLAG_COLOR;
if (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)
if ((png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)
format |= PNG_FORMAT_FLAG_ALPHA;
/* Use png_ptr here, not info_ptr, because by examination png_handle_tRNS
@ -1344,7 +1346,7 @@ png_image_format(png_structrp png_ptr)
if (png_ptr->bit_depth == 16)
format |= PNG_FORMAT_FLAG_LINEAR;
if (png_ptr->color_type & PNG_COLOR_MASK_PALETTE)
if ((png_ptr->color_type & PNG_COLOR_MASK_PALETTE) != 0)
format |= PNG_FORMAT_FLAG_COLORMAP;
return format;
@ -1444,7 +1446,7 @@ png_image_begin_read_from_stdio(png_imagep image, FILE* file)
{
if (file != NULL)
{
if (png_image_read_init(image))
if (png_image_read_init(image) != 0)
{
/* This is slightly evil, but png_init_io doesn't do anything other
* than this and we haven't changed the standard IO functions so
@ -1478,7 +1480,7 @@ png_image_begin_read_from_file(png_imagep image, const char *file_name)
if (fp != NULL)
{
if (png_image_read_init(image))
if (png_image_read_init(image) != 0)
{
image->opaque->png_ptr->io_ptr = fp;
image->opaque->owned_file = 1;
@ -1543,7 +1545,7 @@ int PNGAPI png_image_begin_read_from_memory(png_imagep image,
{
if (memory != NULL && size > 0)
{
if (png_image_read_init(image))
if (png_image_read_init(image) != 0)
{
/* Now set the IO functions to read from the memory buffer and
* store it into io_ptr. Again do this in-place to avoid calling a
@ -1635,9 +1637,9 @@ static void
set_file_encoding(png_image_read_control *display)
{
png_fixed_point g = display->image->opaque->png_ptr->colorspace.gamma;
if (png_gamma_significant(g))
if (png_gamma_significant(g) != 0)
{
if (png_gamma_not_sRGB(g))
if (png_gamma_not_sRGB(g) != 0)
{
display->file_encoding = P_FILE;
display->gamma_to_linear = png_reciprocal(g);
@ -1762,7 +1764,7 @@ png_create_colormap_entry(png_image_read_control *display,
green = png_gamma_16bit_correct(green*257, g);
blue = png_gamma_16bit_correct(blue*257, g);
if (convert_to_Y || output_encoding == P_LINEAR)
if (convert_to_Y != 0 || output_encoding == P_LINEAR)
{
alpha *= 257;
encoding = P_LINEAR;
@ -1789,7 +1791,8 @@ png_create_colormap_entry(png_image_read_control *display,
encoding = P_LINEAR;
}
else if (encoding == P_sRGB && (convert_to_Y || output_encoding == P_LINEAR))
else if (encoding == P_sRGB &&
(convert_to_Y != 0 || output_encoding == P_LINEAR))
{
/* The values are 8-bit sRGB values, but must be converted to 16-bit
* linear.
@ -2098,7 +2101,7 @@ png_image_read_colormap(png_voidp argument)
else
{
back_g = display->background->green;
if (output_format & PNG_FORMAT_FLAG_COLOR)
if ((output_format & PNG_FORMAT_FLAG_COLOR) != 0)
{
back_r = display->background->red;
back_b = display->background->blue;
@ -2240,7 +2243,7 @@ png_image_read_colormap(png_voidp argument)
{
unsigned int back_alpha;
if (output_format & PNG_FORMAT_FLAG_ALPHA)
if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0)
back_alpha = 0;
else
@ -2321,7 +2324,7 @@ png_image_read_colormap(png_voidp argument)
*/
data_encoding = P_sRGB;
if (output_format & PNG_FORMAT_FLAG_ALPHA)
if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0)
{
if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries)
png_error(png_ptr, "gray+alpha color-map: too few entries");
@ -2516,7 +2519,7 @@ png_image_read_colormap(png_voidp argument)
*/
if ((png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
png_ptr->num_trans > 0) &&
png_gamma_not_sRGB(png_ptr->colorspace.gamma))
png_gamma_not_sRGB(png_ptr->colorspace.gamma) != 0)
{
cmap_entries = make_gray_file_colormap(display);
data_encoding = P_FILE;
@ -2604,7 +2607,7 @@ png_image_read_colormap(png_voidp argument)
/* Is there alpha in the output too? If so all four channels are
* processed into a special RGB cube with alpha support.
*/
if (output_format & PNG_FORMAT_FLAG_ALPHA)
if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0)
{
png_uint_32 r;
@ -2778,7 +2781,7 @@ png_image_read_colormap(png_voidp argument)
for (i=0; i < cmap_entries; ++i)
{
if (do_background && i < num_trans && trans[i] < 255)
if (do_background != 0 && i < num_trans && trans[i] < 255)
{
if (trans[i] == 0)
png_create_colormap_entry(display, i, back_r, back_g,
@ -2823,8 +2826,8 @@ png_image_read_colormap(png_voidp argument)
}
/* Now deal with the output processing */
if (expand_tRNS && png_ptr->num_trans > 0 &&
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA) == 0)
if (expand_tRNS != 0 && png_ptr->num_trans > 0 &&
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA) == 0)
png_set_tRNS_to_alpha(png_ptr);
switch (data_encoding)
@ -3538,7 +3541,8 @@ png_image_read_background(png_voidp argument)
int swap_alpha = 0;
# ifdef PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
if (preserve_alpha && (image->format & PNG_FORMAT_FLAG_AFIRST))
if (preserve_alpha != 0 &&
(image->format & PNG_FORMAT_FLAG_AFIRST))
swap_alpha = 1;
# endif
@ -3647,10 +3651,10 @@ png_image_read_direct(png_voidp argument)
int mode; /* alpha mode */
/* Do this first so that we have a record if rgb to gray is happening. */
if (change & PNG_FORMAT_FLAG_COLOR)
if ((change & PNG_FORMAT_FLAG_COLOR) != 0)
{
/* gray<->color transformation required. */
if (format & PNG_FORMAT_FLAG_COLOR)
if ((format & PNG_FORMAT_FLAG_COLOR) != 0)
png_set_gray_to_rgb(png_ptr);
else
@ -3668,7 +3672,7 @@ png_image_read_direct(png_voidp argument)
* enormous change) 'do_local_background' is used to indicate that
* the problem exists.
*/
if (base_format & PNG_FORMAT_FLAG_ALPHA)
if ((base_format & PNG_FORMAT_FLAG_ALPHA) != 0)
do_local_background = 1/*maybe*/;
png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE,
@ -3683,8 +3687,8 @@ png_image_read_direct(png_voidp argument)
{
png_fixed_point input_gamma_default;
if ((base_format & PNG_FORMAT_FLAG_LINEAR) &&
(image->flags & PNG_IMAGE_FLAG_16BIT_sRGB) == 0)
if ((base_format & PNG_FORMAT_FLAG_LINEAR) != 0 &&
(image->flags & PNG_IMAGE_FLAG_16BIT_sRGB) == 0)
input_gamma_default = PNG_GAMMA_LINEAR;
else
input_gamma_default = PNG_DEFAULT_sRGB;
@ -3700,7 +3704,7 @@ png_image_read_direct(png_voidp argument)
/* If there *is* an alpha channel in the input it must be multiplied
* out; use PNG_ALPHA_STANDARD, otherwise just use PNG_ALPHA_PNG.
*/
if (base_format & PNG_FORMAT_FLAG_ALPHA)
if ((base_format & PNG_FORMAT_FLAG_ALPHA) != 0)
mode = PNG_ALPHA_STANDARD; /* associated alpha */
else
@ -3731,7 +3735,7 @@ png_image_read_direct(png_voidp argument)
* final value.
*/
if (png_muldiv(&gtest, output_gamma, png_ptr->colorspace.gamma,
PNG_FP_1) && !png_gamma_significant(gtest))
PNG_FP_1) != 0 && png_gamma_significant(gtest) == 0)
do_local_background = 0;
else if (mode == PNG_ALPHA_STANDARD)
@ -3744,9 +3748,9 @@ png_image_read_direct(png_voidp argument)
}
/* If the bit-depth changes then handle that here. */
if (change & PNG_FORMAT_FLAG_LINEAR)
if ((change & PNG_FORMAT_FLAG_LINEAR) != 0)
{
if (linear /*16-bit output*/)
if (linear != 0 /*16-bit output*/)
png_set_expand_16(png_ptr);
else /* 8-bit output */
@ -3756,13 +3760,13 @@ png_image_read_direct(png_voidp argument)
}
/* Now the background/alpha channel changes. */
if (change & PNG_FORMAT_FLAG_ALPHA)
if ((change & PNG_FORMAT_FLAG_ALPHA) != 0)
{
/* Removing an alpha channel requires composition for the 8-bit
* formats; for the 16-bit it is already done, above, by the
* pre-multiplication and the channel just needs to be stripped.
*/
if (base_format & PNG_FORMAT_FLAG_ALPHA)
if ((base_format & PNG_FORMAT_FLAG_ALPHA) != 0)
{
/* If RGB->gray is happening the alpha channel must be left and the
* operation completed locally.
@ -3827,7 +3831,7 @@ png_image_read_direct(png_voidp argument)
filler = 255;
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
if (format & PNG_FORMAT_FLAG_AFIRST)
if ((format & PNG_FORMAT_FLAG_AFIRST) != 0)
{
where = PNG_FILLER_BEFORE;
change &= ~PNG_FORMAT_FLAG_AFIRST;
@ -3851,12 +3855,12 @@ png_image_read_direct(png_voidp argument)
png_set_alpha_mode_fixed(png_ptr, mode, output_gamma);
# ifdef PNG_FORMAT_BGR_SUPPORTED
if (change & PNG_FORMAT_FLAG_BGR)
if ((change & PNG_FORMAT_FLAG_BGR) != 0)
{
/* Check only the output format; PNG is never BGR; don't do this if
* the output is gray, but fix up the 'format' value in that case.
*/
if (format & PNG_FORMAT_FLAG_COLOR)
if ((format & PNG_FORMAT_FLAG_COLOR) != 0)
png_set_bgr(png_ptr);
else
@ -3867,14 +3871,14 @@ png_image_read_direct(png_voidp argument)
# endif
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
if (change & PNG_FORMAT_FLAG_AFIRST)
if ((change & PNG_FORMAT_FLAG_AFIRST) != 0)
{
/* Only relevant if there is an alpha channel - it's particularly
* important to handle this correctly because do_local_compose may
* be set above and then libpng will keep the alpha channel for this
* code to remove.
*/
if (format & PNG_FORMAT_FLAG_ALPHA)
if ((format & PNG_FORMAT_FLAG_ALPHA) != 0)
{
/* Disable this if doing a local background,
* TODO: remove this when local background is no longer required.
@ -3897,7 +3901,7 @@ png_image_read_direct(png_voidp argument)
{
PNG_CONST png_uint_16 le = 0x0001;
if (*(png_const_bytep)&le)
if ((*(png_const_bytep) & le) != 0)
png_set_swap(png_ptr);
}
@ -3922,10 +3926,10 @@ png_image_read_direct(png_voidp argument)
{
png_uint_32 info_format = 0;
if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
info_format |= PNG_FORMAT_FLAG_COLOR;
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)
{
/* do_local_compose removes this channel below. */
if (do_local_compose == 0)
@ -3944,14 +3948,14 @@ png_image_read_direct(png_voidp argument)
info_format |= PNG_FORMAT_FLAG_LINEAR;
# ifdef PNG_FORMAT_BGR_SUPPORTED
if (png_ptr->transformations & PNG_BGR)
if ((png_ptr->transformations & PNG_BGR) != 0)
info_format |= PNG_FORMAT_FLAG_BGR;
# endif
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
if (do_local_background == 2)
{
if (format & PNG_FORMAT_FLAG_AFIRST)
if ((format & PNG_FORMAT_FLAG_AFIRST) != 0)
info_format |= PNG_FORMAT_FLAG_AFIRST;
}
@ -4080,7 +4084,7 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
/* Choose the correct 'end' routine; for the color-map case all the
* setup has already been done.
*/
if (image->format & PNG_FORMAT_FLAG_COLORMAP)
if ((image->format & PNG_FORMAT_FLAG_COLORMAP) != 0)
result =
png_safe_execute(image, png_image_read_colormap, &display) &&
png_safe_execute(image, png_image_read_colormapped, &display);

View File

@ -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 [(PENDING RELEASE)]
* 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.)
@ -98,7 +98,7 @@ 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 +127,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 +171,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 +185,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 +198,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 +279,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 +371,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 +415,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;
@ -802,7 +802,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. */
@ -855,7 +855,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 +885,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 +897,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,7 +909,7 @@ 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);
@ -925,7 +925,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 +938,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 +956,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)
@ -1153,8 +1153,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 +1165,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
@ -1220,9 +1220,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,7 +1260,7 @@ 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;
@ -1374,8 +1374,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 +1401,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 +1412,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 +1433,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)
@ -1481,10 +1481,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
@ -1508,10 +1508,10 @@ png_init_read_transformations(png_structrp png_ptr)
#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 +1554,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 +1579,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 +1631,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 +1648,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);
@ -1832,7 +1831,7 @@ png_init_read_transformations(png_structrp png_ptr)
#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;
@ -1870,8 +1869,8 @@ png_init_read_transformations(png_structrp png_ptr)
#endif /* PNG_READ_BACKGROUND_SUPPORTED */
#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;
@ -1926,7 +1925,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 +1947,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 +1965,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 +1986,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
@ -2022,23 +2021,23 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
}
#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 +2045,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 +2077,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 +2246,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 +2258,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 +2672,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 +2707,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 +2749,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 +2788,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 +2849,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 +2987,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 +3087,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 +3138,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 +3151,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)
@ -4127,7 +4128,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 +4354,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 +4498,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)
{
@ -4715,7 +4717,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 +4727,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 +4737,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 +4750,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 +4814,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)
@ -4846,22 +4848,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 +4872,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);
@ -4891,35 +4893,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,35 +4933,35 @@ 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 */
@ -4973,10 +4975,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 *

View File

@ -131,7 +131,7 @@ png_read_sig(png_structrp png_ptr, png_inforp info_ptr)
png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
png_ptr->sig_bytes = 8;
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check) != 0)
{
if (num_checked < 4 &&
png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
@ -217,9 +217,9 @@ png_crc_finish(png_structrp png_ptr, png_uint_32 skip)
png_crc_read(png_ptr, tmpbuf, len);
}
if (png_crc_error(png_ptr))
if (png_crc_error(png_ptr) != 0)
{
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) ?
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0 ?
!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) :
(png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))
{
@ -245,7 +245,7 @@ png_crc_error(png_structrp png_ptr)
png_uint_32 crc;
int need_crc = 1;
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0)
{
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
(PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
@ -254,7 +254,7 @@ png_crc_error(png_structrp png_ptr)
else /* critical */
{
if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0)
need_crc = 0;
}
@ -388,7 +388,7 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
png_ptr->zstream.next_out = NULL;
png_ptr->zstream.avail_out = 0;
if (png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED)
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)
{
#if PNG_ZLIB_VERNUM < 0x1240
ret = inflateReset(&png_ptr->zstream);
@ -798,7 +798,7 @@ png_handle_IHDR(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_IHDR");
if (png_ptr->mode & PNG_HAVE_IHDR)
if ((png_ptr->mode & PNG_HAVE_IHDR) != 0)
png_chunk_error(png_ptr, "out of place");
/* Check the length */
@ -874,7 +874,7 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_PLTE");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
/* Moved to before the 'after IDAT' check below because otherwise duplicate
@ -882,10 +882,10 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
* than one PLTE, the error is not treated as benign, so this check trumps
* the requirement that PLTE appears before IDAT.)
*/
else if (png_ptr->mode & PNG_HAVE_PLTE)
else if ((png_ptr->mode & PNG_HAVE_PLTE) != 0)
png_chunk_error(png_ptr, "duplicate");
else if (png_ptr->mode & PNG_HAVE_IDAT)
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
{
/* This is benign because the non-benign error happened before, when an
* IDAT was encountered in a color-mapped image with no PLTE.
@ -897,7 +897,7 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_ptr->mode |= PNG_HAVE_PLTE;
if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR))
if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "ignored in grayscale PNG");
@ -964,7 +964,7 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
#ifndef PNG_READ_OPT_PLTE_SUPPORTED
else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
else if (png_crc_error(png_ptr) != 0) /* Only if we have a CRC error */
{
/* If we don't want to use the data from an ancillary chunk,
* we have two options: an error abort, or a warning and we
@ -975,9 +975,9 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
* chunk type to determine whether to check the ancillary or the critical
* flags.
*/
if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE) == 0)
{
if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) != 0)
return;
else
@ -985,7 +985,7 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
/* Otherwise, we (optionally) emit a warning and use the chunk. */
else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
else if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0)
png_chunk_warning(png_ptr, "CRC error");
}
#endif
@ -1042,7 +1042,8 @@ png_handle_IEND(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
{
png_debug(1, "in png_handle_IEND");
if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0 ||
(png_ptr->mode & PNG_HAVE_IDAT) == 0)
png_chunk_error(png_ptr, "out of place");
png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
@ -1064,10 +1065,10 @@ png_handle_gAMA(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_gAMA");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if (png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE))
else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
@ -1083,7 +1084,7 @@ png_handle_gAMA(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buf, 4);
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
igamma = png_get_fixed_point(NULL, buf);
@ -1103,17 +1104,17 @@ png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_sBIT");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if (png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE))
else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
return;
}
if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "duplicate");
@ -1142,7 +1143,7 @@ png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
buf[0] = buf[1] = buf[2] = buf[3] = sample_depth;
png_crc_read(png_ptr, buf, truelen);
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
for (i=0; i<truelen; ++i)
@ -1152,7 +1153,7 @@ png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
return;
}
if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
{
png_ptr->sig_bit.red = buf[0];
png_ptr->sig_bit.green = buf[1];
@ -1182,10 +1183,10 @@ png_handle_cHRM(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_cHRM");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if (png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE))
else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
@ -1201,7 +1202,7 @@ png_handle_cHRM(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buf, 32);
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
xy.whitex = png_get_fixed_point(NULL, buf);
@ -1227,10 +1228,10 @@ png_handle_cHRM(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
/* If a colorspace error has already been output skip this chunk */
if (png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID)
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)
return;
if (png_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM)
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0)
{
png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID;
png_colorspace_sync(png_ptr, info_ptr);
@ -1253,10 +1254,10 @@ png_handle_sRGB(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_sRGB");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if (png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE))
else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
@ -1272,17 +1273,17 @@ png_handle_sRGB(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, &intent, 1);
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
/* If a colorspace error has already been output skip this chunk */
if (png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID)
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)
return;
/* Only one sRGB or iCCP chunk is allowed, use the HAVE_INTENT flag to detect
* this.
*/
if (png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_INTENT)
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_INTENT) != 0)
{
png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID;
png_colorspace_sync(png_ptr, info_ptr);
@ -1305,10 +1306,10 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_iCCP");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if (png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE))
else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
@ -1331,7 +1332,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
/* If a colorspace error has already been output skip this chunk */
if (png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID)
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)
{
png_crc_finish(png_ptr, length);
return;
@ -1391,14 +1392,14 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_get_uint_32(profile_header);
if (png_icc_check_length(png_ptr, &png_ptr->colorspace,
keyword, profile_length))
keyword, profile_length) != 0)
{
/* The length is apparently ok, so we can check the 132
* byte header.
*/
if (png_icc_check_header(png_ptr, &png_ptr->colorspace,
keyword, profile_length, profile_header,
png_ptr->color_type))
png_ptr->color_type) != 0)
{
/* Now read the tag table; a variable size buffer is
* needed at this point, allocate one for the whole
@ -1428,7 +1429,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
{
if (png_icc_check_tag_table(png_ptr,
&png_ptr->colorspace, keyword, profile_length,
profile))
profile) != 0)
{
/* The profile has been validated for basic
* security issues, so read the whole thing in.
@ -1602,10 +1603,10 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
#endif
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if (png_ptr->mode & PNG_HAVE_IDAT)
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
@ -1636,7 +1637,7 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
*/
png_crc_read(png_ptr, buffer, length);
if (png_crc_finish(png_ptr, skip))
if (png_crc_finish(png_ptr, skip) != 0)
return;
buffer[length] = 0;
@ -1661,7 +1662,7 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
data_length = length - (png_uint_32)(entry_start - buffer);
/* Integrity-check the data length */
if (data_length % entry_size)
if ((data_length % entry_size) != 0)
{
png_warning(png_ptr, "sPLT chunk has bad length");
return;
@ -1753,17 +1754,17 @@ png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_tRNS");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if (png_ptr->mode & PNG_HAVE_IDAT)
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
return;
}
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "duplicate");
@ -1806,7 +1807,7 @@ png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
if (!(png_ptr->mode & PNG_HAVE_PLTE))
if ((png_ptr->mode & PNG_HAVE_PLTE) == 0)
{
/* TODO: is this actually an error in the ISO spec? */
png_crc_finish(png_ptr, length);
@ -1833,7 +1834,7 @@ png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
return;
}
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
{
png_ptr->num_trans = 0;
return;
@ -1858,19 +1859,19 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_bKGD");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if ((png_ptr->mode & PNG_HAVE_IDAT) ||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
!(png_ptr->mode & PNG_HAVE_PLTE)))
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0 ||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
(png_ptr->mode & PNG_HAVE_PLTE) == 0))
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
return;
}
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "duplicate");
@ -1880,7 +1881,7 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
truelen = 1;
else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
truelen = 6;
else
@ -1895,7 +1896,7 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buf, truelen);
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
/* We convert the index value into RGB components so that we can allow
@ -1907,7 +1908,7 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
{
background.index = buf[0];
if (info_ptr && info_ptr->num_palette)
if (info_ptr != NULL && info_ptr->num_palette != 0)
{
if (buf[0] >= info_ptr->num_palette)
{
@ -1926,7 +1927,7 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
background.gray = 0;
}
else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) /* GRAY */
{
background.index = 0;
background.red =
@ -1957,17 +1958,18 @@ png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_hIST");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if ((png_ptr->mode & PNG_HAVE_IDAT) || !(png_ptr->mode & PNG_HAVE_PLTE))
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0 ||
(png_ptr->mode & PNG_HAVE_PLTE) == 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
return;
}
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "duplicate");
@ -1991,7 +1993,7 @@ png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
readbuf[i] = png_get_uint_16(buf);
}
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
png_set_hIST(png_ptr, info_ptr, readbuf);
@ -2008,17 +2010,17 @@ png_handle_pHYs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_pHYs");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if (png_ptr->mode & PNG_HAVE_IDAT)
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
return;
}
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "duplicate");
@ -2034,7 +2036,7 @@ png_handle_pHYs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buf, 9);
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
res_x = png_get_uint_32(buf);
@ -2054,17 +2056,17 @@ png_handle_oFFs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_oFFs");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if (png_ptr->mode & PNG_HAVE_IDAT)
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
return;
}
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "duplicate");
@ -2080,7 +2082,7 @@ png_handle_oFFs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buf, 9);
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
offset_x = png_get_int_32(buf);
@ -2103,17 +2105,17 @@ png_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_pCAL");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if (png_ptr->mode & PNG_HAVE_IDAT)
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
return;
}
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "duplicate");
@ -2134,7 +2136,7 @@ png_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buffer, length);
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
buffer[length] = 0; /* Null terminate the last string */
@ -2230,17 +2232,17 @@ png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_sCAL");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if (png_ptr->mode & PNG_HAVE_IDAT)
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of place");
return;
}
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "duplicate");
@ -2270,7 +2272,7 @@ png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buffer, length);
buffer[length] = 0; /* Null terminate the last string */
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
/* Validate the unit. */
@ -2286,11 +2288,11 @@ png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
i = 1;
state = 0;
if (!png_check_fp_number((png_const_charp)buffer, length, &state, &i) ||
if (png_check_fp_number((png_const_charp)buffer, length, &state, &i) == 0 ||
i >= length || buffer[i++] != 0)
png_chunk_benign_error(png_ptr, "bad width format");
else if (!PNG_FP_IS_POSITIVE(state))
else if (PNG_FP_IS_POSITIVE(state) == 0)
png_chunk_benign_error(png_ptr, "non-positive width");
else
@ -2298,11 +2300,11 @@ png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_size_t heighti = i;
state = 0;
if (!png_check_fp_number((png_const_charp)buffer, length, &state, &i) ||
i != length)
if (png_check_fp_number((png_const_charp)buffer, length,
&state, &i) == 0 || i != length)
png_chunk_benign_error(png_ptr, "bad height format");
else if (!PNG_FP_IS_POSITIVE(state))
else if (PNG_FP_IS_POSITIVE(state) == 0)
png_chunk_benign_error(png_ptr, "non-positive height");
else
@ -2322,17 +2324,17 @@ png_handle_tIME(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_tIME");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "duplicate");
return;
}
if (png_ptr->mode & PNG_HAVE_IDAT)
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
png_ptr->mode |= PNG_AFTER_IDAT;
if (length != 7)
@ -2344,7 +2346,7 @@ png_handle_tIME(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buf, 7);
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
mod_time.second = buf[6];
@ -2389,10 +2391,10 @@ png_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
#endif
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
if (png_ptr->mode & PNG_HAVE_IDAT)
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
png_ptr->mode |= PNG_AFTER_IDAT;
#ifdef PNG_MAX_MALLOC_64K
@ -2414,7 +2416,7 @@ png_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buffer, length);
if (png_crc_finish(png_ptr, skip))
if (png_crc_finish(png_ptr, skip) != 0)
return;
key = (png_charp)buffer;
@ -2434,7 +2436,7 @@ png_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
text_info.text = text;
text_info.text_length = strlen(text);
if (png_set_text_2(png_ptr, info_ptr, &text_info, 1))
if (png_set_text_2(png_ptr, info_ptr, &text_info, 1) != 0)
png_warning(png_ptr, "Insufficient memory to process text chunk");
}
#endif
@ -2468,10 +2470,10 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
#endif
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
if (png_ptr->mode & PNG_HAVE_IDAT)
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
png_ptr->mode |= PNG_AFTER_IDAT;
buffer = png_read_buffer(png_ptr, length, 2/*silent*/);
@ -2485,7 +2487,7 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buffer, length);
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
/* TODO: also check that the keyword contents match the spec! */
@ -2535,7 +2537,7 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
text.lang = NULL;
text.lang_key = NULL;
if (png_set_text_2(png_ptr, info_ptr, &text, 1))
if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)
errmsg = "insufficient memory";
}
@ -2577,10 +2579,10 @@ png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
#endif
if (!(png_ptr->mode & PNG_HAVE_IHDR))
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
if (png_ptr->mode & PNG_HAVE_IDAT)
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
png_ptr->mode |= PNG_AFTER_IDAT;
buffer = png_read_buffer(png_ptr, length+1, 1/*warn*/);
@ -2594,7 +2596,7 @@ png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buffer, length);
if (png_crc_finish(png_ptr, 0))
if (png_crc_finish(png_ptr, 0) != 0)
return;
/* First the keyword. */
@ -2685,7 +2687,7 @@ png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
text.text_length = 0;
text.itxt_length = uncompressed_length;
if (png_set_text_2(png_ptr, info_ptr, &text, 1))
if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)
errmsg = "insufficient memory";
}
}
@ -2713,7 +2715,7 @@ png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
# ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
if (png_ptr->user_chunk_malloc_max > 0 &&
png_ptr->user_chunk_malloc_max < limit)
png_ptr->user_chunk_malloc_max < limit)
limit = png_ptr->user_chunk_malloc_max;
# elif PNG_USER_CHUNK_MALLOC_MAX > 0
@ -2795,7 +2797,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
*/
if (png_ptr->read_user_chunk_fn != NULL)
{
if (png_cache_unknown_chunk(png_ptr, length))
if (png_cache_unknown_chunk(png_ptr, length) != 0)
{
/* Callback to user unknown chunk handler */
int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr,
@ -2872,7 +2874,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
(keep == PNG_HANDLE_CHUNK_IF_SAFE &&
PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
{
if (!png_cache_unknown_chunk(png_ptr, length))
if (png_cache_unknown_chunk(png_ptr, length) == 0)
keep = PNG_HANDLE_CHUNK_NEVER;
}
@ -3038,7 +3040,8 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
end_ptr = dp + PNG_ROWBYTES(pixel_depth, row_width) - 1;
end_byte = *end_ptr;
# ifdef PNG_READ_PACKSWAP_SUPPORTED
if (png_ptr->transformations & PNG_PACKSWAP) /* little-endian byte */
if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
/* little-endian byte */
end_mask = 0xff << end_mask;
else /* big-endian byte */
@ -3054,10 +3057,11 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
* pass.
*/
#ifdef PNG_READ_INTERLACING_SUPPORTED
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE) &&
pass < 6 && (display == 0 ||
/* The following copies everything for 'display' on passes 0, 2 and 4. */
(display == 1 && (pass & 1) != 0)))
if (png_ptr->interlaced != 0 &&
(png_ptr->transformations & PNG_INTERLACE) != 0 &&
pass < 6 && (display == 0 ||
/* The following copies everything for 'display' on passes 0, 2 and 4. */
(display == 1 && (pass & 1) != 0)))
{
/* Narrow images may have no bits in a pass; the caller should handle
* this, but this test is cheap:
@ -3200,7 +3204,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
png_uint_32 mask;
# ifdef PNG_READ_PACKSWAP_SUPPORTED
if (png_ptr->transformations & PNG_PACKSWAP)
if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
mask = MASK(pass, pixel_depth, display, 0);
else
@ -3351,24 +3355,24 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
* wide bytes_to_copy either - use the memcpy there.
*/
if (bytes_to_copy < 16 /*else use memcpy*/ &&
png_isaligned(dp, png_uint_16) &&
png_isaligned(sp, png_uint_16) &&
bytes_to_copy % (sizeof (png_uint_16)) == 0 &&
bytes_to_jump % (sizeof (png_uint_16)) == 0)
png_isaligned(dp, png_uint_16) &&
png_isaligned(sp, png_uint_16) &&
bytes_to_copy % (sizeof (png_uint_16)) == 0 &&
bytes_to_jump % (sizeof (png_uint_16)) == 0)
{
/* Everything is aligned for png_uint_16 copies, but try for
* png_uint_32 first.
*/
if (png_isaligned(dp, png_uint_32) &&
png_isaligned(sp, png_uint_32) &&
bytes_to_copy % (sizeof (png_uint_32)) == 0 &&
bytes_to_jump % (sizeof (png_uint_32)) == 0)
if (png_isaligned(dp, png_uint_32) != 0 &&
png_isaligned(sp, png_uint_32) != 0 &&
bytes_to_copy % (sizeof (png_uint_32)) == 0 &&
bytes_to_jump % (sizeof (png_uint_32)) == 0)
{
png_uint_32p dp32 = png_aligncast(png_uint_32p,dp);
png_const_uint_32p sp32 = png_aligncastconst(
png_const_uint_32p, sp);
png_const_uint_32p, sp);
size_t skip = (bytes_to_jump-bytes_to_copy) /
(sizeof (png_uint_32));
(sizeof (png_uint_32));
do
{
@ -3507,7 +3511,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
int j;
#ifdef PNG_READ_PACKSWAP_SUPPORTED
if (transformations & PNG_PACKSWAP)
if ((transformations & PNG_PACKSWAP) != 0)
{
sshift = (int)((row_info->width + 7) & 0x07);
dshift = (int)((final_width + 7) & 0x07);
@ -3567,7 +3571,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
png_uint_32 i;
#ifdef PNG_READ_PACKSWAP_SUPPORTED
if (transformations & PNG_PACKSWAP)
if ((transformations & PNG_PACKSWAP) != 0)
{
sshift = (int)(((row_info->width + 3) & 0x03) << 1);
dshift = (int)(((final_width + 3) & 0x03) << 1);
@ -3630,7 +3634,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
int jstop = png_pass_inc[pass];
#ifdef PNG_READ_PACKSWAP_SUPPORTED
if (transformations & PNG_PACKSWAP)
if ((transformations & PNG_PACKSWAP) != 0)
{
sshift = (int)(((row_info->width + 1) & 0x01) << 2);
dshift = (int)(((final_width + 1) & 0x01) << 2);
@ -4071,7 +4075,7 @@ png_read_finish_IDAT(png_structrp png_ptr)
* read it otherwise stray unread IDAT data or, more likely, an IDAT chunk
* may still remain to be consumed.
*/
if (!(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
{
/* The NULL causes png_read_IDAT_data to swallow any remaining bytes in
* the compressed stream, but the stream may be damaged too, so even after
@ -4083,7 +4087,7 @@ png_read_finish_IDAT(png_structrp png_ptr)
/* Now clear everything out for safety; the following may not have been
* done.
*/
if (!(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
{
png_ptr->mode |= PNG_AFTER_IDAT;
png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
@ -4133,7 +4137,7 @@ png_read_finish_row(png_structrp png_ptr)
if (png_ptr->row_number < png_ptr->num_rows)
return;
if (png_ptr->interlaced)
if (png_ptr->interlaced != 0)
{
png_ptr->row_number = 0;
@ -4154,7 +4158,7 @@ png_read_finish_row(png_structrp png_ptr)
png_pass_start[png_ptr->pass]) /
png_pass_inc[png_ptr->pass];
if (!(png_ptr->transformations & PNG_INTERLACE))
if ((png_ptr->transformations & PNG_INTERLACE) == 0)
{
png_ptr->num_rows = (png_ptr->height +
png_pass_yinc[png_ptr->pass] - 1 -
@ -4201,9 +4205,9 @@ png_read_start_row(png_structrp png_ptr)
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
png_init_read_transformations(png_ptr);
#endif
if (png_ptr->interlaced)
if (png_ptr->interlaced != 0)
{
if (!(png_ptr->transformations & PNG_INTERLACE))
if ((png_ptr->transformations & PNG_INTERLACE) == 0)
png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
png_pass_ystart[0]) / png_pass_yinc[0];
@ -4235,16 +4239,16 @@ png_read_start_row(png_structrp png_ptr)
* TODO: fix this.
*/
#ifdef PNG_READ_PACK_SUPPORTED
if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
if ((png_ptr->transformations & PNG_PACK) != 0 && png_ptr->bit_depth < 8)
max_pixel_depth = 8;
#endif
#ifdef PNG_READ_EXPAND_SUPPORTED
if (png_ptr->transformations & PNG_EXPAND)
if ((png_ptr->transformations & PNG_EXPAND) != 0)
{
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
if (png_ptr->num_trans)
if (png_ptr->num_trans != 0)
max_pixel_depth = 32;
else
@ -4256,13 +4260,13 @@ png_read_start_row(png_structrp png_ptr)
if (max_pixel_depth < 8)
max_pixel_depth = 8;
if (png_ptr->num_trans)
if (png_ptr->num_trans != 0)
max_pixel_depth *= 2;
}
else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
{
if (png_ptr->num_trans)
if (png_ptr->num_trans != 0)
{
max_pixel_depth *= 4;
max_pixel_depth /= 3;
@ -4272,13 +4276,13 @@ png_read_start_row(png_structrp png_ptr)
#endif
#ifdef PNG_READ_EXPAND_16_SUPPORTED
if (png_ptr->transformations & PNG_EXPAND_16)
if ((png_ptr->transformations & PNG_EXPAND_16) != 0)
{
# ifdef PNG_READ_EXPAND_SUPPORTED
/* In fact it is an error if it isn't supported, but checking is
* the safe way.
*/
if (png_ptr->transformations & PNG_EXPAND)
if ((png_ptr->transformations & PNG_EXPAND) != 0)
{
if (png_ptr->bit_depth < 16)
max_pixel_depth *= 2;
@ -4290,7 +4294,7 @@ png_read_start_row(png_structrp png_ptr)
#endif
#ifdef PNG_READ_FILLER_SUPPORTED
if (png_ptr->transformations & (PNG_FILLER))
if ((png_ptr->transformations & (PNG_FILLER)) != 0)
{
if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
{
@ -4314,14 +4318,15 @@ png_read_start_row(png_structrp png_ptr)
#endif
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
if (png_ptr->transformations & PNG_GRAY_TO_RGB)
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)
{
if (
#ifdef PNG_READ_EXPAND_SUPPORTED
(png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
(png_ptr->num_trans != 0 &&
(png_ptr->transformations & PNG_EXPAND) != 0) ||
#endif
#ifdef PNG_READ_FILLER_SUPPORTED
(png_ptr->transformations & (PNG_FILLER)) ||
(png_ptr->transformations & (PNG_FILLER)) != 0 ||
#endif
png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
@ -4354,7 +4359,7 @@ png_read_start_row(png_structrp png_ptr)
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if (png_ptr->transformations & PNG_USER_TRANSFORM)
if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
{
int user_pixel_depth = png_ptr->user_transform_depth *
png_ptr->user_transform_channels;
@ -4390,7 +4395,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
png_free(png_ptr, png_ptr->big_row_buf);
png_free(png_ptr, png_ptr->big_prev_row);
if (png_ptr->interlaced)
if (png_ptr->interlaced != 0)
png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
row_bytes + 48);
@ -4447,7 +4452,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
* does not, so free the read buffer now regardless; the sequential reader
* reallocates it on demand.
*/
if (png_ptr->read_buffer)
if (png_ptr->read_buffer != 0)
{
png_bytep buffer = png_ptr->read_buffer;

View File

@ -1,7 +1,7 @@
/* pngset.c - storage of image information into info struct
*
* Last changed in libpng 1.6.11 [June 5, 2014]
* Last changed in libpng 1.6.15 [(PENDING RELEASE)]
* 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.)
@ -59,7 +59,7 @@ png_set_cHRM_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
xy.whitey = white_y;
if (png_colorspace_set_chromaticities(png_ptr, &info_ptr->colorspace, &xy,
2/* override with app values*/))
2/* override with app values*/) != 0)
info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
png_colorspace_sync_info(png_ptr, info_ptr);
@ -90,7 +90,8 @@ png_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
XYZ.blue_Y = int_blue_Y;
XYZ.blue_Z = int_blue_Z;
if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace, &XYZ, 2))
if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace,
&XYZ, 2) != 0)
info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
png_colorspace_sync_info(png_ptr, info_ptr);
@ -227,13 +228,13 @@ png_set_IHDR(png_const_structrp png_ptr, png_inforp info_ptr,
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;
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)
info_ptr->channels++;
info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
@ -288,12 +289,14 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
/* Validate params[nparams] */
for (i=0; i<nparams; ++i)
{
if (params[i] == NULL ||
!png_check_fp_string(params[i], strlen(params[i])))
!png_check_fp_string(params[i], strlen(params[i])))
png_error(png_ptr, "Invalid format for pCAL parameter");
}
info_ptr->pcal_purpose = png_voidcast(png_charp,
png_malloc_warn(png_ptr, length));
png_malloc_warn(png_ptr, length));
if (info_ptr->pcal_purpose == NULL)
{
@ -594,7 +597,8 @@ png_set_sRGB_gAMA_and_cHRM(png_const_structrp png_ptr, png_inforp info_ptr,
if (png_ptr == NULL || info_ptr == NULL)
return;
if (png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, srgb_intent))
if (png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace,
srgb_intent) != 0)
{
/* This causes the gAMA and cHRM to be written too */
info_ptr->colorspace.flags |=
@ -891,7 +895,7 @@ png_set_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
png_debug1(1, "in %s storage function", "tIME");
if (png_ptr == NULL || info_ptr == NULL || mod_time == NULL ||
(png_ptr->mode & PNG_WROTE_tIME))
(png_ptr->mode & PNG_WROTE_tIME) != 0)
return;
if (mod_time->month == 0 || mod_time->month > 12 ||
@ -1077,7 +1081,7 @@ check_location(png_const_structrp png_ptr, int location)
* change; previously the app had to use the
* png_set_unknown_chunk_location API below for each chunk.
*/
if (location == 0 && !(png_ptr->mode & PNG_IS_READ_STRUCT))
if (location == 0 && (png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
{
/* Write struct, so unknown chunks come from the app */
png_app_warning(png_ptr,
@ -1123,7 +1127,7 @@ png_set_unknown_chunks(png_const_structrp png_ptr,
*/
# if !defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \
defined(PNG_READ_SUPPORTED)
if (png_ptr->mode & PNG_IS_READ_STRUCT)
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
{
png_app_error(png_ptr, "no unknown chunk support on read");
return;
@ -1131,7 +1135,7 @@ png_set_unknown_chunks(png_const_structrp png_ptr,
# endif
# if !defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \
defined(PNG_WRITE_SUPPORTED)
if (!(png_ptr->mode & PNG_IS_READ_STRUCT))
if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
{
png_app_error(png_ptr, "no unknown chunk support on write");
return;
@ -1217,7 +1221,7 @@ png_set_unknown_chunk_location(png_const_structrp png_ptr, png_inforp info_ptr,
{
png_app_error(png_ptr, "invalid unknown chunk location");
/* Fake out the pre 1.6.0 behavior: */
if ((location & PNG_HAVE_IDAT)) /* undocumented! */
if ((location & PNG_HAVE_IDAT) != 0) /* undocumented! */
location = PNG_AFTER_IDAT;
else
@ -1255,10 +1259,13 @@ add_one_chunk(png_bytep list, unsigned int count, png_const_bytep add, int keep)
/* Utility function: update the 'keep' state of a chunk if it is already in
* the list, otherwise add it to the list.
*/
for (i=0; i<count; ++i, list += 5) if (memcmp(list, add, 4) == 0)
for (i=0; i<count; ++i, list += 5)
{
list[4] = (png_byte)keep;
return count;
if (memcmp(list, add, 4) == 0)
{
list[4] = (png_byte)keep;
return count;
}
}
if (keep != PNG_HANDLE_CHUNK_AS_DEFAULT)
@ -1382,12 +1389,15 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
unsigned int i;
for (i=0; i<num_chunks; ++i)
{
old_num_chunks = add_one_chunk(new_list, old_num_chunks,
chunk_list+5*i, keep);
}
/* Now remove any spurious 'default' entries. */
num_chunks = 0;
for (i=0, inlist=outlist=new_list; i<old_num_chunks; ++i, inlist += 5)
{
if (inlist[4])
{
if (outlist != inlist)
@ -1395,6 +1405,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
outlist += 5;
++num_chunks;
}
}
/* This means the application has removed all the specialized handling. */
if (num_chunks == 0)
@ -1446,7 +1457,8 @@ png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr,
if (png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
if (info_ptr->row_pointers != NULL &&
(info_ptr->row_pointers != row_pointers))
png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
info_ptr->row_pointers = row_pointers;
@ -1466,7 +1478,7 @@ png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
png_error(png_ptr, "invalid compression buffer size");
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
if (png_ptr->mode & PNG_IS_READ_STRUCT)
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
{
png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */
return;
@ -1474,7 +1486,7 @@ png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
# endif
# ifdef PNG_WRITE_SUPPORTED
if (!(png_ptr->mode & PNG_IS_READ_STRUCT))
if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
{
if (png_ptr->zowner != 0)
{
@ -1512,7 +1524,7 @@ png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
void PNGAPI
png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask)
{
if (png_ptr && info_ptr)
if (png_ptr != NULL && info_ptr != NULL)
info_ptr->valid &= ~mask;
}

View File

@ -283,7 +283,8 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
png_uint_32 n, nstop;
int channel;
int color_channels = row_info->channels;
if (row_info->color_type > 3)color_channels--;
if (row_info->color_type > 3)
color_channels--;
for (n = 0, nstop=row_info->width; n<nstop; n++)
{
@ -643,7 +644,7 @@ set_location(png_structp png_ptr, struct user_chunk_data *data, int what)
{
int location;
if ((data->location[0] & what) || (data->location[1] & what))
if ((data->location[0] & what) != 0 || (data->location[1] & what) != 0)
return 0; /* already have one of these */
/* Find where we are (the code below zeroes info_ptr to indicate that the
@ -652,7 +653,7 @@ set_location(png_structp png_ptr, struct user_chunk_data *data, int what)
if (data->info_ptr == NULL) /* after IDAT */
location = what | after_IDAT;
else if (png_get_valid(png_ptr, data->info_ptr, PNG_INFO_PLTE))
else if (png_get_valid(png_ptr, data->info_ptr, PNG_INFO_PLTE) != 0)
location = what | before_IDAT;
else
@ -699,7 +700,7 @@ read_user_chunk_callback(png_struct *png_ptr, png_unknown_chunkp chunk)
if (chunk->data[0] != 0 && chunk->data[0] != 1)
return (-1); /* Invalid mode */
if (set_location(png_ptr, my_user_chunk_data, have_sTER))
if (set_location(png_ptr, my_user_chunk_data, have_sTER) != 0)
{
my_user_chunk_data->sTER_mode=chunk->data[0];
return (1);
@ -718,7 +719,7 @@ read_user_chunk_callback(png_struct *png_ptr, png_unknown_chunkp chunk)
if (chunk->size != 9)
return (-1); /* Error return */
if (!set_location(png_ptr, my_user_chunk_data, have_vpAg))
if (set_location(png_ptr, my_user_chunk_data, have_vpAg) == 0)
return (0); /* duplicate vpAg */
my_user_chunk_data->vpAg_width = png_get_uint_31(png_ptr, chunk->data);
@ -1049,7 +1050,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
int interlace_type, compression_type, filter_type;
if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,
&color_type, &interlace_type, &compression_type, &filter_type))
&color_type, &interlace_type, &compression_type, &filter_type) != 0)
{
png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
color_type, interlace_type, compression_type, filter_type);
@ -1082,7 +1083,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
blue_y;
if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y,
&red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y))
&red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0)
{
png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x,
red_y, green_x, green_y, blue_x, blue_y);
@ -1093,7 +1094,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
png_fixed_point gamma;
if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma))
if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma) != 0)
png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma);
}
#endif
@ -1105,7 +1106,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
blue_y;
if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
&red_y, &green_x, &green_y, &blue_x, &blue_y))
&red_y, &green_x, &green_y, &blue_x, &blue_y) != 0)
{
png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
red_y, green_x, green_y, blue_x, blue_y);
@ -1116,7 +1117,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
double gamma;
if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))
if (png_get_gAMA(read_ptr, read_info_ptr, &gamma) != 0)
png_set_gAMA(write_ptr, write_info_ptr, gamma);
}
#endif
@ -1130,7 +1131,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
int compression_type;
if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type,
&profile, &proflen))
&profile, &proflen) != 0)
{
png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,
profile, proflen);
@ -1141,7 +1142,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
int intent;
if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
if (png_get_sRGB(read_ptr, read_info_ptr, &intent) != 0)
png_set_sRGB(write_ptr, write_info_ptr, intent);
}
#endif
@ -1149,14 +1150,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_colorp palette;
int num_palette;
if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette) != 0)
png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
}
#ifdef PNG_bKGD_SUPPORTED
{
png_color_16p background;
if (png_get_bKGD(read_ptr, read_info_ptr, &background))
if (png_get_bKGD(read_ptr, read_info_ptr, &background) != 0)
{
png_set_bKGD(write_ptr, write_info_ptr, background);
}
@ -1166,7 +1167,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
png_uint_16p hist;
if (png_get_hIST(read_ptr, read_info_ptr, &hist))
if (png_get_hIST(read_ptr, read_info_ptr, &hist) != 0)
png_set_hIST(write_ptr, write_info_ptr, hist);
}
#endif
@ -1176,7 +1177,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
int unit_type;
if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y,
&unit_type))
&unit_type) != 0)
{
png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
}
@ -1190,7 +1191,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
int type, nparams;
if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,
&nparams, &units, &params))
&nparams, &units, &params) != 0)
{
png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,
nparams, units, params);
@ -1202,7 +1203,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_uint_32 res_x, res_y;
int unit_type;
if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type))
if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y,
&unit_type) != 0)
png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
}
#endif
@ -1210,7 +1212,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
png_color_8p sig_bit;
if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit))
if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit) != 0)
png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
}
#endif
@ -1222,7 +1224,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
double scal_width, scal_height;
if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width,
&scal_height))
&scal_height) != 0)
{
png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height);
}
@ -1234,7 +1236,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_charp scal_width, scal_height;
if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width,
&scal_height))
&scal_height) != 0)
{
png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width,
scal_height);
@ -1274,11 +1276,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
png_timep mod_time;
if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
if (png_get_tIME(read_ptr, read_info_ptr, &mod_time) != 0)
{
png_set_tIME(write_ptr, write_info_ptr, mod_time);
#ifdef PNG_TIME_RFC1123_SUPPORTED
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time))
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time) != 0)
tIME_string[(sizeof tIME_string) - 1] = '\0';
else
@ -1299,7 +1301,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_color_16p trans_color;
if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans,
&trans_color))
&trans_color) != 0)
{
int sample_max = (1 << bit_depth);
/* libpng doesn't reject a tRNS chunk with out-of-range samples */
@ -1457,11 +1459,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
png_timep mod_time;
if (png_get_tIME(read_ptr, end_info_ptr, &mod_time))
if (png_get_tIME(read_ptr, end_info_ptr, &mod_time) != 0)
{
png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
#ifdef PNG_TIME_RFC1123_SUPPORTED
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time))
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time) != 0)
tIME_string[(sizeof tIME_string) - 1] = '\0';
else
@ -1824,7 +1826,7 @@ main(int argc, char *argv[])
#endif
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
for (k = 0; k<256; k++)
if (filters_used[k])
if (filters_used[k] != 0)
fprintf(STDERR, " Filter %d was used %lu times\n",
k, (unsigned long)filters_used[k]);
#endif
@ -1915,7 +1917,7 @@ main(int argc, char *argv[])
#endif
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
for (k = 0; k<256; k++)
if (filters_used[k])
if (filters_used[k] != 0)
fprintf(STDERR, " Filter %d was used %lu times\n",
k, (unsigned long)filters_used[k]);
#endif

View File

@ -1,7 +1,7 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
* Last changed in libpng 1.6.11 [June 5, 2014]
* Last changed in libpng 1.6.15 [(PENDING RELEASE)]
* 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.)
@ -100,7 +100,7 @@ png_set_interlace_handling(png_structrp png_ptr)
{
png_debug(1, "in png_set_interlace handling");
if (png_ptr && png_ptr->interlaced)
if (png_ptr != 0 && png_ptr->interlaced != 0)
{
png_ptr->transformations |= PNG_INTERLACE;
return (7);
@ -127,7 +127,7 @@ png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
/* In libpng 1.6 it is possible to determine whether this is a read or write
* operation and therefore to do more checking here for a valid call.
*/
if (png_ptr->mode & PNG_IS_READ_STRUCT)
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
{
# ifdef PNG_READ_FILLER_SUPPORTED
/* On read png_set_filler is always valid, regardless of the base PNG
@ -210,7 +210,7 @@ png_set_add_alpha(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
png_set_filler(png_ptr, filler, filler_loc);
/* The above may fail to do anything. */
if (png_ptr->transformations & PNG_FILLER)
if ((png_ptr->transformations & PNG_FILLER) != 0)
png_ptr->transformations |= PNG_ADD_ALPHA;
}
@ -605,7 +605,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_bgr");
if ((row_info->color_type & PNG_COLOR_MASK_COLOR))
if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
{
png_uint_32 row_width = row_info->width;
if (row_info->bit_depth == 8)

View File

@ -24,7 +24,7 @@ static void
write_unknown_chunks(png_structrp png_ptr, png_const_inforp info_ptr,
unsigned int where)
{
if (info_ptr->unknown_chunks_num)
if (info_ptr->unknown_chunks_num != 0)
{
png_const_unknown_chunkp up;
@ -33,7 +33,7 @@ write_unknown_chunks(png_structrp png_ptr, png_const_inforp info_ptr,
for (up = info_ptr->unknown_chunks;
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
++up)
if (up->location & where)
if ((up->location & where) != 0)
{
/* If per-chunk unknown chunk handling is enabled use it, otherwise
* just write the chunks the application has set.
@ -88,14 +88,14 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
if (png_ptr == NULL || info_ptr == NULL)
return;
if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
if ((png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE) == 0)
{
/* Write PNG signature */
png_write_sig(png_ptr);
#ifdef PNG_MNG_FEATURES_SUPPORTED
if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) && \
(png_ptr->mng_features_permitted))
if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 && \
png_ptr->mng_features_permitted != 0)
{
png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
png_ptr->mng_features_permitted = 0;
@ -129,9 +129,9 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
*/
#ifdef PNG_GAMMA_SUPPORTED
# ifdef PNG_WRITE_gAMA_SUPPORTED
if (!(info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_gAMA) &&
(info_ptr->valid & PNG_INFO_gAMA))
if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_gAMA) != 0 &&
(info_ptr->valid & PNG_INFO_gAMA) != 0)
png_write_gAMA_fixed(png_ptr, info_ptr->colorspace.gamma);
# endif
#endif
@ -141,11 +141,11 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
* and it matches one of the known sRGB ones issue a warning.
*/
# ifdef PNG_WRITE_iCCP_SUPPORTED
if (!(info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) &&
(info_ptr->valid & PNG_INFO_iCCP))
if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
(info_ptr->valid & PNG_INFO_iCCP) != 0)
{
# ifdef PNG_WRITE_sRGB_SUPPORTED
if (info_ptr->valid & PNG_INFO_sRGB)
if ((info_ptr->valid & PNG_INFO_sRGB) != 0)
png_app_warning(png_ptr,
"profile matches sRGB but writing iCCP instead");
# endif
@ -159,22 +159,22 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
# endif
# ifdef PNG_WRITE_sRGB_SUPPORTED
if (!(info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) &&
(info_ptr->valid & PNG_INFO_sRGB))
if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
(info_ptr->valid & PNG_INFO_sRGB) != 0)
png_write_sRGB(png_ptr, info_ptr->colorspace.rendering_intent);
# endif /* WRITE_sRGB */
#endif /* COLORSPACE */
#ifdef PNG_WRITE_sBIT_SUPPORTED
if (info_ptr->valid & PNG_INFO_sBIT)
if ((info_ptr->valid & PNG_INFO_sBIT) != 0)
png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
#endif
#ifdef PNG_COLORSPACE_SUPPORTED
# ifdef PNG_WRITE_cHRM_SUPPORTED
if (!(info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) &&
(info_ptr->valid & PNG_INFO_cHRM))
if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0 &&
(info_ptr->valid & PNG_INFO_cHRM) != 0)
png_write_cHRM_fixed(png_ptr, &info_ptr->colorspace.end_points_xy);
# endif
#endif
@ -201,19 +201,19 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)
png_write_info_before_PLTE(png_ptr, info_ptr);
if (info_ptr->valid & PNG_INFO_PLTE)
if ((info_ptr->valid & PNG_INFO_PLTE) != 0)
png_write_PLTE(png_ptr, info_ptr->palette,
(png_uint_32)info_ptr->num_palette);
else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
else if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) !=0)
png_error(png_ptr, "Valid palette required for paletted images");
#ifdef PNG_WRITE_tRNS_SUPPORTED
if (info_ptr->valid & PNG_INFO_tRNS)
if ((info_ptr->valid & PNG_INFO_tRNS) !=0)
{
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
/* Invert the alpha channel (in tRNS) */
if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0 &&
info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
int j;
@ -227,42 +227,42 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)
}
#endif
#ifdef PNG_WRITE_bKGD_SUPPORTED
if (info_ptr->valid & PNG_INFO_bKGD)
if ((info_ptr->valid & PNG_INFO_bKGD) != 0)
png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
#endif
#ifdef PNG_WRITE_hIST_SUPPORTED
if (info_ptr->valid & PNG_INFO_hIST)
if ((info_ptr->valid & PNG_INFO_hIST) != 0)
png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
#endif
#ifdef PNG_WRITE_oFFs_SUPPORTED
if (info_ptr->valid & PNG_INFO_oFFs)
if ((info_ptr->valid & PNG_INFO_oFFs) != 0)
png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
info_ptr->offset_unit_type);
#endif
#ifdef PNG_WRITE_pCAL_SUPPORTED
if (info_ptr->valid & PNG_INFO_pCAL)
if ((info_ptr->valid & PNG_INFO_pCAL) != 0)
png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
info_ptr->pcal_units, info_ptr->pcal_params);
#endif
#ifdef PNG_WRITE_sCAL_SUPPORTED
if (info_ptr->valid & PNG_INFO_sCAL)
if ((info_ptr->valid & PNG_INFO_sCAL) != 0)
png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
info_ptr->scal_s_width, info_ptr->scal_s_height);
#endif /* sCAL */
#ifdef PNG_WRITE_pHYs_SUPPORTED
if (info_ptr->valid & PNG_INFO_pHYs)
if ((info_ptr->valid & PNG_INFO_pHYs) != 0)
png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
#endif /* pHYs */
#ifdef PNG_WRITE_tIME_SUPPORTED
if (info_ptr->valid & PNG_INFO_tIME)
if ((info_ptr->valid & PNG_INFO_tIME) != 0)
{
png_write_tIME(png_ptr, &(info_ptr->mod_time));
png_ptr->mode |= PNG_WROTE_tIME;
@ -270,7 +270,7 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)
#endif /* tIME */
#ifdef PNG_WRITE_sPLT_SUPPORTED
if (info_ptr->valid & PNG_INFO_sPLT)
if ((info_ptr->valid & PNG_INFO_sPLT) != 0)
for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
#endif /* sPLT */
@ -351,7 +351,7 @@ png_write_end(png_structrp png_ptr, png_inforp info_ptr)
if (png_ptr == NULL)
return;
if (!(png_ptr->mode & PNG_HAVE_IDAT))
if ((png_ptr->mode & PNG_HAVE_IDAT) == 0)
png_error(png_ptr, "No IDATs written into file");
#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
@ -367,8 +367,8 @@ png_write_end(png_structrp png_ptr, png_inforp info_ptr)
#endif
#ifdef PNG_WRITE_tIME_SUPPORTED
/* Check to see if user has supplied a time chunk */
if ((info_ptr->valid & PNG_INFO_tIME) &&
!(png_ptr->mode & PNG_WROTE_tIME))
if ((info_ptr->valid & PNG_INFO_tIME) != 0 &&
(png_ptr->mode & PNG_WROTE_tIME) == 0)
png_write_tIME(png_ptr, &(info_ptr->mod_time));
#endif
@ -618,7 +618,7 @@ png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_write_intrapixel");
if ((row_info->color_type & PNG_COLOR_MASK_COLOR))
if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
{
int bytes_per_pixel;
png_uint_32 row_width = row_info->width;
@ -693,44 +693,44 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
{
/* Make sure we wrote the header info */
if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
if ((png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE) == 0)
png_error(png_ptr,
"png_write_info was never called before png_write_row");
/* Check for transforms that have been set but were defined out */
#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_MONO)
if ((png_ptr->transformations & PNG_INVERT_MONO) != 0)
png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined");
#endif
#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
if (png_ptr->transformations & PNG_FILLER)
if ((png_ptr->transformations & PNG_FILLER) != 0)
png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined");
#endif
#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \
defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
png_warning(png_ptr,
"PNG_WRITE_PACKSWAP_SUPPORTED is not defined");
#endif
#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
if (png_ptr->transformations & PNG_PACK)
if ((png_ptr->transformations & PNG_PACK) != 0)
png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined");
#endif
#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
if (png_ptr->transformations & PNG_SHIFT)
if ((png_ptr->transformations & PNG_SHIFT) != 0)
png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined");
#endif
#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
if (png_ptr->transformations & PNG_BGR)
if ((png_ptr->transformations & PNG_BGR) != 0)
png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined");
#endif
#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
if (png_ptr->transformations & PNG_SWAP_BYTES)
if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0)
png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined");
#endif
@ -739,12 +739,13 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* If interlaced and not interested in row, return */
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
if (png_ptr->interlaced != 0 &&
(png_ptr->transformations & PNG_INTERLACE) != 0)
{
switch (png_ptr->pass)
{
case 0:
if (png_ptr->row_number & 0x07)
if ((png_ptr->row_number & 0x07) != 0)
{
png_write_finish_row(png_ptr);
return;
@ -752,7 +753,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
break;
case 1:
if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
if ((png_ptr->row_number & 0x07) != 0 || png_ptr->width < 5)
{
png_write_finish_row(png_ptr);
return;
@ -768,7 +769,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
break;
case 3:
if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
if ((png_ptr->row_number & 0x03) != 0 || png_ptr->width < 3)
{
png_write_finish_row(png_ptr);
return;
@ -784,7 +785,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
break;
case 5:
if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
if ((png_ptr->row_number & 0x01) != 0 || png_ptr->width < 2)
{
png_write_finish_row(png_ptr);
return;
@ -792,7 +793,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
break;
case 6:
if (!(png_ptr->row_number & 0x01))
if ((png_ptr->row_number & 0x01) == 0)
{
png_write_finish_row(png_ptr);
return;
@ -826,7 +827,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Handle interlacing */
if (png_ptr->interlaced && png_ptr->pass < 6 &&
(png_ptr->transformations & PNG_INTERLACE))
(png_ptr->transformations & PNG_INTERLACE) != 0)
{
png_do_write_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass);
/* This should always get caught above, but still ... */
@ -840,7 +841,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
/* Handle other transformations */
if (png_ptr->transformations)
if (png_ptr->transformations != 0)
png_do_write_transformations(png_ptr, &row_info);
#endif
@ -861,7 +862,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
* 4. The filter_method is 64 and
* 5. The color_type is RGB or RGBA
*/
if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 &&
(png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
{
/* Intrapixel differencing */
@ -927,7 +928,7 @@ png_write_destroy(png_structrp png_ptr)
png_debug(1, "in png_write_destroy");
/* Free any memory zlib uses */
if (png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED)
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)
deflateEnd(&png_ptr->zstream);
/* Free our memory. png_free checks NULL for us. */
@ -1004,7 +1005,7 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
return;
#ifdef PNG_MNG_FEATURES_SUPPORTED
if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 &&
(method == PNG_INTRAPIXEL_DIFFERENCING))
method = PNG_FILTER_TYPE_BASE;
@ -1055,14 +1056,16 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
if (png_ptr->row_buf != NULL)
{
#ifdef PNG_WRITE_FILTER_SUPPORTED
if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
if ((png_ptr->do_filter & PNG_FILTER_SUB) != 0 &&
png_ptr->sub_row == NULL)
{
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1));
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
}
if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
if ((png_ptr->do_filter & PNG_FILTER_UP) != 0 &&
png_ptr->up_row == NULL)
{
if (png_ptr->prev_row == NULL)
{
@ -1079,7 +1082,8 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
}
}
if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
if ((png_ptr->do_filter & PNG_FILTER_AVG) != 0 &&
png_ptr->avg_row == NULL)
{
if (png_ptr->prev_row == NULL)
{
@ -1096,7 +1100,7 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
}
}
if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
if ((png_ptr->do_filter & PNG_FILTER_PAETH) != 0 &&
png_ptr->paeth_row == NULL)
{
if (png_ptr->prev_row == NULL)
@ -1257,7 +1261,7 @@ png_set_filter_heuristics(png_structrp png_ptr, int heuristic_method,
/* The internal API allocates all the arrays and ensures that the elements of
* those arrays are set to the default value.
*/
if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights))
if (png_init_filter_heuristics(png_ptr, heuristic_method, num_weights) == 0)
return;
/* If using the weighted method copy in the weights. */
@ -1312,7 +1316,7 @@ png_set_filter_heuristics_fixed(png_structrp png_ptr, int heuristic_method,
/* The internal API allocates all the arrays and ensures that the elements of
* those arrays are set to the default value.
*/
if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights))
if (png_init_filter_heuristics(png_ptr, heuristic_method, num_weights) == 0)
return;
/* If using the weighted method copy in the weights. */
@ -1571,7 +1575,7 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
/* ------ these transformations don't touch the info structure ------- */
/* Invert monochrome pixels */
if (transforms & PNG_TRANSFORM_INVERT_MONO)
if ((transforms & PNG_TRANSFORM_INVERT_MONO) != 0)
#ifdef PNG_WRITE_INVERT_SUPPORTED
png_set_invert_mono(png_ptr);
#else
@ -1581,16 +1585,16 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
/* Shift the pixels up to a legal bit depth and fill in
* as appropriate to correctly scale the image.
*/
if (transforms & PNG_TRANSFORM_SHIFT)
if ((transforms & PNG_TRANSFORM_SHIFT) != 0)
#ifdef PNG_WRITE_SHIFT_SUPPORTED
if (info_ptr->valid & PNG_INFO_sBIT)
if ((info_ptr->valid & PNG_INFO_sBIT) != 0)
png_set_shift(png_ptr, &info_ptr->sig_bit);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_SHIFT not supported");
#endif
/* Pack pixels into bytes */
if (transforms & PNG_TRANSFORM_PACKING)
if ((transforms & PNG_TRANSFORM_PACKING) != 0)
#ifdef PNG_WRITE_PACK_SUPPORTED
png_set_packing(png_ptr);
#else
@ -1598,7 +1602,7 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
#endif
/* Swap location of alpha bytes from ARGB to RGBA */
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
if ((transforms & PNG_TRANSFORM_SWAP_ALPHA) != 0)
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
png_set_swap_alpha(png_ptr);
#else
@ -1609,13 +1613,13 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
* RGB, note that the code expects the input color type to be G or RGB; no
* alpha channel.
*/
if (transforms &
(PNG_TRANSFORM_STRIP_FILLER_AFTER|PNG_TRANSFORM_STRIP_FILLER_BEFORE))
if (transforms & (PNG_TRANSFORM_STRIP_FILLER_AFTER|
PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0)
{
#ifdef PNG_WRITE_FILLER_SUPPORTED
if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER)
if ((transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) != 0)
{
if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0)
png_app_error(png_ptr,
"PNG_TRANSFORM_STRIP_FILLER: BEFORE+AFTER not supported");
@ -1623,7 +1627,7 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
}
else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
else if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0)
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_FILLER not supported");
@ -1631,7 +1635,7 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
}
/* Flip BGR pixels to RGB */
if (transforms & PNG_TRANSFORM_BGR)
if ((transforms & PNG_TRANSFORM_BGR) != 0)
#ifdef PNG_WRITE_BGR_SUPPORTED
png_set_bgr(png_ptr);
#else
@ -1639,7 +1643,7 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
#endif
/* Swap bytes of 16-bit files to most significant byte first */
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
if ((transforms & PNG_TRANSFORM_SWAP_ENDIAN) != 0)
#ifdef PNG_WRITE_SWAP_SUPPORTED
png_set_swap(png_ptr);
#else
@ -1647,7 +1651,7 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
#endif
/* Swap bits of 1, 2, 4 bit packed pixel formats */
if (transforms & PNG_TRANSFORM_PACKSWAP)
if ((transforms & PNG_TRANSFORM_PACKSWAP) != 0)
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
png_set_packswap(png_ptr);
#else
@ -1655,7 +1659,7 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
#endif
/* Invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
if ((transforms & PNG_TRANSFORM_INVERT_ALPHA) != 0)
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
png_set_invert_alpha(png_ptr);
#else
@ -1750,10 +1754,10 @@ png_write_image_16bit(png_voidp argument)
int aindex = 0;
png_uint_32 y = image->height;
if (image->format & PNG_FORMAT_FLAG_ALPHA)
if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0)
{
# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
if (image->format & PNG_FORMAT_FLAG_AFIRST)
if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0)
{
aindex = -1;
++input_row; /* To point to the first component */
@ -1905,13 +1909,13 @@ png_write_image_8bit(png_voidp argument)
png_uint_32 y = image->height;
const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) ? 3 : 1;
if (image->format & PNG_FORMAT_FLAG_ALPHA)
if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0)
{
png_bytep row_end;
int aindex;
# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
if (image->format & PNG_FORMAT_FLAG_AFIRST)
if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0)
{
aindex = -1;
++input_row; /* To point to the first component */
@ -2025,13 +2029,13 @@ png_image_set_PLTE(png_image_write_control *display)
/* This gets automatically converted to sRGB with reversal of the
* pre-multiplication if the color-map has an alpha channel.
*/
if (format & PNG_FORMAT_FLAG_LINEAR)
if ((format & PNG_FORMAT_FLAG_LINEAR) != 0)
{
png_const_uint_16p entry = png_voidcast(png_const_uint_16p, cmap);
entry += i * channels;
if (channels & 1) /* no alpha */
if ((channels & 1) != 0) /* no alpha */
{
if (channels >= 3) /* RGB */
{
@ -2143,12 +2147,11 @@ png_image_write_main(png_voidp argument)
png_inforp info_ptr = image->opaque->info_ptr;
png_uint_32 format = image->format;
int colormap = (format & PNG_FORMAT_FLAG_COLORMAP) != 0;
/* input */
int linear = (colormap == 0) && (format & PNG_FORMAT_FLAG_LINEAR) != 0;
int alpha = (colormap == 0) && (format & PNG_FORMAT_FLAG_ALPHA) != 0;
int write_16bit = (linear != 0 ) && (colormap == 0) &&
(display->convert_to_8bit == 0);
/* The following four ints are actually booleans */
int colormap = (format & PNG_FORMAT_FLAG_COLORMAP);
int linear = !colormap && (format & PNG_FORMAT_FLAG_LINEAR); /* input */
int alpha = !colormap && (format & PNG_FORMAT_FLAG_ALPHA);
int write_16bit = linear && !colormap && (display->convert_to_8bit == 0);
# ifdef PNG_BENIGN_ERRORS_SUPPORTED
/* Make sure we error out on any bad situation */
@ -2160,7 +2163,7 @@ png_image_write_main(png_voidp argument)
display->row_stride = PNG_IMAGE_ROW_STRIDE(*image);
/* Set the required transforms then write the rows in the correct order. */
if (format & PNG_FORMAT_FLAG_COLORMAP)
if ((format & PNG_FORMAT_FLAG_COLORMAP) != 0)
{
if (display->colormap != NULL && image->colormap_entries > 0)
{
@ -2197,7 +2200,7 @@ png_image_write_main(png_voidp argument)
/* The gamma here is 1.0 (linear) and the cHRM chunk matches sRGB. */
png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_LINEAR);
if (!(image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB))
if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0)
png_set_cHRM_fixed(png_ptr, info_ptr,
/* color x y */
/* white */ 31270, 32900,
@ -2207,7 +2210,7 @@ png_image_write_main(png_voidp argument)
);
}
else if (!(image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB))
else if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0)
png_set_sRGB(png_ptr, info_ptr, PNG_sRGB_INTENT_PERCEPTUAL);
/* Else writing an 8-bit file and the *colors* aren't sRGB, but the 8-bit
@ -2228,12 +2231,12 @@ png_image_write_main(png_voidp argument)
{
PNG_CONST png_uint_16 le = 0x0001;
if (*(png_const_bytep)&le)
if ((*(png_const_bytep) & le) != 0)
png_set_swap(png_ptr);
}
# ifdef PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
if (format & PNG_FORMAT_FLAG_BGR)
if ((format & PNG_FORMAT_FLAG_BGR) != 0)
{
if (colormap == 0 && (format & PNG_FORMAT_FLAG_COLOR) != 0)
png_set_bgr(png_ptr);
@ -2242,7 +2245,7 @@ png_image_write_main(png_voidp argument)
# endif
# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
if (format & PNG_FORMAT_FLAG_AFIRST)
if ((format & PNG_FORMAT_FLAG_AFIRST) != 0)
{
if (colormap == 0 && (format & PNG_FORMAT_FLAG_ALPHA) != 0)
png_set_swap_alpha(png_ptr);
@ -2253,7 +2256,7 @@ png_image_write_main(png_voidp argument)
/* If there are 16 or fewer color-map entries we wrote a lower bit depth
* above, but the application data is still byte packed.
*/
if (colormap && image->colormap_entries <= 16)
if (colormap != 0 && image->colormap_entries <= 16)
png_set_packing(png_ptr);
/* That should have handled all (both) the transforms. */
@ -2341,7 +2344,7 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
{
if (file != NULL)
{
if (png_image_write_init(image))
if (png_image_write_init(image) != 0)
{
png_image_write_control display;
int result;
@ -2396,7 +2399,7 @@ png_image_write_to_file(png_imagep image, const char *file_name,
if (fp != NULL)
{
if (png_image_write_to_stdio(image, fp, convert_to_8bit, buffer,
row_stride, colormap))
row_stride, colormap) != 0)
{
int error; /* from fflush/fclose */

View File

@ -177,7 +177,7 @@ png_do_shift(png_row_infop row_info, png_bytep row,
int shift_start[4], shift_dec[4];
int channels = 0;
if (row_info->color_type & PNG_COLOR_MASK_COLOR)
if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
{
shift_start[channels] = row_info->bit_depth - bit_depth->red;
shift_dec[channels] = bit_depth->red;
@ -199,7 +199,7 @@ png_do_shift(png_row_infop row_info, png_bytep row,
channels++;
}
if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)
{
shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
shift_dec[channels] = bit_depth->alpha;
@ -505,7 +505,7 @@ png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
return;
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
if (png_ptr->transformations & PNG_USER_TRANSFORM)
if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
if (png_ptr->write_user_transform_fn != NULL)
(*(png_ptr->write_user_transform_fn)) /* User write transform
function */
@ -521,50 +521,50 @@ png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
#endif
#ifdef PNG_WRITE_FILLER_SUPPORTED
if (png_ptr->transformations & PNG_FILLER)
if ((png_ptr->transformations & PNG_FILLER) != 0)
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
!(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
#endif
#ifdef PNG_WRITE_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_WRITE_PACK_SUPPORTED
if (png_ptr->transformations & PNG_PACK)
if ((png_ptr->transformations & PNG_PACK) != 0)
png_do_pack(row_info, png_ptr->row_buf + 1,
(png_uint_32)png_ptr->bit_depth);
#endif
#ifdef PNG_WRITE_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
#ifdef PNG_WRITE_SHIFT_SUPPORTED
if (png_ptr->transformations & PNG_SHIFT)
if ((png_ptr->transformations & PNG_SHIFT) != 0)
png_do_shift(row_info, png_ptr->row_buf + 1,
&(png_ptr->shift));
#endif
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
if (png_ptr->transformations & PNG_SWAP_ALPHA)
if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0)
png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
if (png_ptr->transformations & PNG_INVERT_ALPHA)
if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_WRITE_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_WRITE_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
}

View File

@ -1,7 +1,7 @@
/* pngwutil.c - utilities to write a PNG file
*
* Last changed in libpng 1.6.14 [October 23, 2014]
* Last changed in libpng 1.6.15 [(PENDING RELEASE)]
* 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.)
@ -211,7 +211,7 @@ png_image_size(png_structrp png_ptr)
if (png_ptr->rowbytes < 32768 && h < 32768)
{
if (png_ptr->interlaced)
if (png_ptr->interlaced != 0)
{
/* Interlacing makes the image larger because of the replication of
* both the filter byte and the padding to a byte boundary.
@ -286,8 +286,6 @@ optimize_cmf(png_bytep data, png_alloc_size_t data_size)
}
}
}
#else
# define optimize_cmf(dp,dl) ((void)0)
#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */
/* Initialize the compressor for the appropriate type of compression. */
@ -297,7 +295,7 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
{
if (png_ptr->zowner != 0)
{
# if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
char msg[64];
PNG_STRING_FROM_CHUNK(msg, owner);
@ -309,8 +307,8 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
* are minimal.
*/
(void)png_safecat(msg, (sizeof msg), 10, " using zstream");
# endif
# if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC
#endif
#if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC
png_warning(png_ptr, msg);
/* Attempt sane error recovery */
@ -321,9 +319,9 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
}
png_ptr->zowner = 0;
# else
#else
png_error(png_ptr, msg);
# endif
#endif
}
{
@ -336,7 +334,7 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
if (owner == png_IDAT)
{
if (png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY)
if ((png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY) != 0)
strategy = png_ptr->zlib_strategy;
else if (png_ptr->do_filter != PNG_FILTER_NONE)
@ -348,20 +346,20 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
else
{
# ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
level = png_ptr->zlib_text_level;
method = png_ptr->zlib_text_method;
windowBits = png_ptr->zlib_text_window_bits;
memLevel = png_ptr->zlib_text_mem_level;
strategy = png_ptr->zlib_text_strategy;
# else
#else
/* If customization is not supported the values all come from the
* IDAT values except for the strategy, which is fixed to the
* default. (This is the pre-1.6.0 behavior too, although it was
* implemented in a very different way.)
*/
strategy = Z_DEFAULT_STRATEGY;
# endif
#endif
}
/* Adjust 'windowBits' down if larger than 'data_size'; to stop this
@ -388,7 +386,7 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
}
/* Check against the previous initialized values, if any. */
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) &&
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0 &&
(png_ptr->zlib_set_level != level ||
png_ptr->zlib_set_method != method ||
png_ptr->zlib_set_window_bits != windowBits ||
@ -412,7 +410,7 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
/* Now initialize if required, setting the new parameters, otherwise just
* to a simple reset to the previous parameters.
*/
if (png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED)
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)
ret = deflateReset(&png_ptr->zstream);
else
@ -619,9 +617,10 @@ png_text_compress(png_structrp png_ptr, png_uint_32 chunk_name,
*/
if (ret == Z_STREAM_END && input_len == 0)
{
#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
/* Fix up the deflate header, if required */
optimize_cmf(comp->output, comp->input_len);
#endif
/* But Z_OK is returned, not Z_STREAM_END; this allows the claim
* function above to return Z_STREAM_END on an error (though it never
* does in the current versions of zlib.)
@ -717,7 +716,7 @@ png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
bad_character = ch; /* just skip it, record the first error */
}
if (key_len > 0 && space) /* trailing space */
if (key_len > 0 && space != 0) /* trailing space */
{
--key_len, --new_key;
if (bad_character == 0)
@ -732,7 +731,7 @@ png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
#ifdef PNG_WARNINGS_SUPPORTED
/* Try to only output one warning per keyword: */
if (*key) /* keyword too long */
if (*key != 0) /* keyword too long */
png_warning(png_ptr, "keyword truncated");
else if (bad_character != 0)
@ -931,7 +930,7 @@ png_write_PLTE(png_structrp png_ptr, png_const_colorp palette,
if ((
#ifdef PNG_MNG_FEATURES_SUPPORTED
!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 &&
#endif
num_pal == 0) || num_pal > 256)
{
@ -947,7 +946,7 @@ png_write_PLTE(png_structrp png_ptr, png_const_colorp palette,
}
}
if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)
{
png_warning(png_ptr,
"Ignoring request to write a PLTE chunk in grayscale PNG");
@ -1074,11 +1073,11 @@ png_compress_IDAT(png_structrp png_ptr, png_const_bytep input,
/* Write an IDAT containing the data then reset the buffer. The
* first IDAT may need deflate header optimization.
*/
# ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
if ((png_ptr->mode & PNG_HAVE_IDAT) == 0 &&
png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
optimize_cmf(data, png_image_size(png_ptr));
# endif
#endif
png_write_complete_chunk(png_ptr, png_IDAT, data, size);
png_ptr->mode |= PNG_HAVE_IDAT;
@ -1120,11 +1119,11 @@ png_compress_IDAT(png_structrp png_ptr, png_const_bytep input,
png_bytep data = png_ptr->zbuffer_list->output;
uInt size = png_ptr->zbuffer_size - png_ptr->zstream.avail_out;
# ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
optimize_cmf(data, png_image_size(png_ptr));
# endif
#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
if ((png_ptr->mode & PNG_HAVE_IDAT) == 0 &&
png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
optimize_cmf(data, png_image_size(png_ptr));
#endif
png_write_complete_chunk(png_ptr, png_IDAT, data, size);
png_ptr->zstream.avail_out = 0;
@ -1345,7 +1344,7 @@ png_write_sBIT(png_structrp png_ptr, png_const_color_8p sbit, int color_type)
png_debug(1, "in png_write_sBIT");
/* Make sure we don't depend upon the order of PNG_COLOR_8 */
if (color_type & PNG_COLOR_MASK_COLOR)
if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
{
png_byte maxbits;
@ -1378,7 +1377,7 @@ png_write_sBIT(png_structrp png_ptr, png_const_color_8p sbit, int color_type)
size = 1;
}
if (color_type & PNG_COLOR_MASK_ALPHA)
if ((color_type & PNG_COLOR_MASK_ALPHA) != 0)
{
if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
{
@ -1465,9 +1464,9 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,
png_save_uint_16(buf + 2, tran->green);
png_save_uint_16(buf + 4, tran->blue);
#ifdef PNG_WRITE_16BIT_SUPPORTED
if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]) != 0)
#else
if (buf[0] | buf[2] | buf[4])
if ((buf[0] | buf[2] | buf[4]) != 0)
#endif
{
png_app_warning(png_ptr,
@ -1498,8 +1497,8 @@ png_write_bKGD(png_structrp png_ptr, png_const_color_16p back, int color_type)
{
if (
#ifdef PNG_MNG_FEATURES_SUPPORTED
(png_ptr->num_palette ||
(!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
(png_ptr->num_palette != 0 ||
(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0) &&
#endif
back->index >= png_ptr->num_palette)
{
@ -1511,15 +1510,15 @@ png_write_bKGD(png_structrp png_ptr, png_const_color_16p back, int color_type)
png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
}
else if (color_type & PNG_COLOR_MASK_COLOR)
else if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
{
png_save_uint_16(buf, back->red);
png_save_uint_16(buf + 2, back->green);
png_save_uint_16(buf + 4, back->blue);
#ifdef PNG_WRITE_16BIT_SUPPORTED
if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]) != 0)
#else
if (buf[0] | buf[2] | buf[4])
if ((buf[0] | buf[2] | buf[4]) != 0)
#endif
{
png_warning(png_ptr,
@ -1986,12 +1985,13 @@ png_write_start_row(png_structrp png_ptr)
}
/* We only need to keep the previous row if we are using one of these. */
if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
if ((png_ptr->do_filter &
(PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) != 0)
{
/* Set up previous row buffer */
png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, buf_size);
if (png_ptr->do_filter & PNG_FILTER_UP)
if ((png_ptr->do_filter & PNG_FILTER_UP) != 0)
{
png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
@ -1999,7 +1999,7 @@ png_write_start_row(png_structrp png_ptr)
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
}
if (png_ptr->do_filter & PNG_FILTER_AVG)
if ((png_ptr->do_filter & PNG_FILTER_AVG) != 0)
{
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
@ -2007,7 +2007,7 @@ png_write_start_row(png_structrp png_ptr)
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
}
if (png_ptr->do_filter & PNG_FILTER_PAETH)
if ((png_ptr->do_filter & PNG_FILTER_PAETH) != 0)
{
png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
@ -2019,9 +2019,9 @@ png_write_start_row(png_structrp png_ptr)
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* If interlaced, we need to set up width and height of pass */
if (png_ptr->interlaced)
if (png_ptr->interlaced != 0)
{
if (!(png_ptr->transformations & PNG_INTERLACE))
if ((png_ptr->transformations & PNG_INTERLACE) == 0)
{
png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
png_pass_ystart[0]) / png_pass_yinc[0];
@ -2076,10 +2076,10 @@ png_write_finish_row(png_structrp png_ptr)
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* If interlaced, go to next pass */
if (png_ptr->interlaced)
if (png_ptr->interlaced != 0)
{
png_ptr->row_number = 0;
if (png_ptr->transformations & PNG_INTERLACE)
if ((png_ptr->transformations & PNG_INTERLACE) != 0)
{
png_ptr->pass++;
}
@ -2104,7 +2104,7 @@ png_write_finish_row(png_structrp png_ptr)
png_pass_ystart[png_ptr->pass]) /
png_pass_yinc[png_ptr->pass];
if (png_ptr->transformations & PNG_INTERLACE)
if ((png_ptr->transformations & PNG_INTERLACE) != 0)
break;
} while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
@ -2383,7 +2383,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
/* We don't need to test the 'no filter' case if this is the only filter
* that has been chosen, as it doesn't actually do anything to the data.
*/
if ((filter_to_do & PNG_FILTER_NONE) && filter_to_do != PNG_FILTER_NONE)
if ((filter_to_do & PNG_FILTER_NONE) != 0 && filter_to_do != PNG_FILTER_NONE)
{
png_bytep rp;
png_uint_32 sum = 0;
@ -2459,7 +2459,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
best_row = png_ptr->sub_row;
}
else if (filter_to_do & PNG_FILTER_SUB)
else if ((filter_to_do & PNG_FILTER_SUB) != 0)
{
png_bytep rp, dp, lp;
png_uint_32 sum = 0, lmins = mins;
@ -2580,7 +2580,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
best_row = png_ptr->up_row;
}
else if (filter_to_do & PNG_FILTER_UP)
else if ((filter_to_do & PNG_FILTER_UP) != 0)
{
png_bytep rp, dp, pp;
png_uint_32 sum = 0, lmins = mins;
@ -2694,7 +2694,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
best_row = png_ptr->avg_row;
}
else if (filter_to_do & PNG_FILTER_AVG)
else if ((filter_to_do & PNG_FILTER_AVG) != 0)
{
png_bytep rp, dp, pp, lp;
png_uint_32 sum = 0, lmins = mins;
@ -2796,7 +2796,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
}
/* Paeth filter */
if (filter_to_do == PNG_FILTER_PAETH)
if ((filter_to_do == PNG_FILTER_PAETH) != 0)
{
png_bytep rp, dp, pp, cp, lp;
png_size_t i;
@ -2835,7 +2835,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
best_row = png_ptr->paeth_row;
}
else if (filter_to_do & PNG_FILTER_PAETH)
else if ((filter_to_do & PNG_FILTER_PAETH) != 0)
{
png_bytep rp, dp, pp, cp, lp;
png_uint_32 sum = 0, lmins = mins;