[libpng17] Ported cosmetic changes from libpng-1.6.15beta02.

This commit is contained in:
Glenn Randers-Pehrson
2014-11-01 13:57:38 -05:00
parent 859254054a
commit 7a4bfbdec1
18 changed files with 778 additions and 679 deletions

340
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.
@@ -288,7 +288,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)));
@@ -396,32 +396,32 @@ 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 ((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)
{
if (info_ptr->text && info_ptr->text[num].key)
{
png_free(png_ptr, info_ptr->text[num].key);
info_ptr->text[num].key = NULL;
}
png_free(png_ptr, info_ptr->text[num].key);
info_ptr->text[num].key = NULL;
}
else
{
int i;
for (i = 0; i < info_ptr->num_text; i++)
png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
png_free(png_ptr, info_ptr->text[i].key);
png_free(png_ptr, info_ptr->text);
info_ptr->text = NULL;
info_ptr->num_text=0;
info_ptr->num_text = 0;
}
}
#endif
#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)
{
info_ptr->valid &= ~PNG_INFO_tRNS;
png_free(png_ptr, info_ptr->trans_alpha);
@@ -432,7 +432,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);
@@ -444,20 +444,20 @@ 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);
info_ptr->pcal_purpose = NULL;
info_ptr->pcal_units = NULL;
if (info_ptr->pcal_params != NULL)
{
unsigned int i;
int i;
for (i = 0; i < info_ptr->pcal_nparams; i++)
{
png_free(png_ptr, info_ptr->pcal_params[i]);
info_ptr->pcal_params[i] = NULL;
}
png_free(png_ptr, info_ptr->pcal_params);
info_ptr->pcal_params = NULL;
}
@@ -467,7 +467,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);
@@ -479,26 +479,28 @@ 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 ((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)
{
if (info_ptr->splt_palettes)
{
png_free(png_ptr, info_ptr->splt_palettes[num].name);
png_free(png_ptr, info_ptr->splt_palettes[num].entries);
info_ptr->splt_palettes[num].name = NULL;
info_ptr->splt_palettes[num].entries = NULL;
}
png_free(png_ptr, info_ptr->splt_palettes[num].name);
png_free(png_ptr, info_ptr->splt_palettes[num].entries);
info_ptr->splt_palettes[num].name = NULL;
info_ptr->splt_palettes[num].entries = NULL;
}
else
{
if (info_ptr->splt_palettes_num)
if (info_ptr->splt_palettes_num != 0)
{
int i;
for (i = 0; i < info_ptr->splt_palettes_num; i++)
png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, (int)i);
{
png_free(png_ptr, info_ptr->splt_palettes[i].name);
png_free(png_ptr, info_ptr->splt_palettes[i].entries);
}
png_free(png_ptr, info_ptr->splt_palettes);
info_ptr->splt_palettes = NULL;
@@ -510,25 +512,23 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#endif
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
if ((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)
{
if (info_ptr->unknown_chunks)
{
png_free(png_ptr, info_ptr->unknown_chunks[num].data);
info_ptr->unknown_chunks[num].data = NULL;
}
png_free(png_ptr, info_ptr->unknown_chunks[num].data);
info_ptr->unknown_chunks[num].data = NULL;
}
else
{
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_data(png_ptr, info_ptr, PNG_FREE_UNKN, (int)i);
png_free(png_ptr, info_ptr->unknown_chunks[i].data);
png_free(png_ptr, info_ptr->unknown_chunks);
info_ptr->unknown_chunks = NULL;
@@ -540,7 +540,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;
@@ -549,7 +549,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;
@@ -559,16 +559,14 @@ 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++)
{
png_free(png_ptr, info_ptr->row_pointers[row]);
info_ptr->row_pointers[row] = NULL;
}
png_free(png_ptr, info_ptr->row_pointers);
info_ptr->row_pointers = NULL;
}
@@ -696,13 +694,13 @@ png_get_copyright(png_const_structrp png_ptr)
#else
# ifdef __STDC__
return PNG_STRING_NEWLINE \
"libpng version 1.7.0beta39 - October 26, 2014" PNG_STRING_NEWLINE \
"libpng version 1.7.0beta39 - 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.7.0beta39 - October 26, 2014\
return "libpng version 1.7.0beta39 - 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.";
@@ -827,7 +825,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);
@@ -954,8 +952,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
@@ -1010,12 +1008,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;
@@ -1039,7 +1038,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|
@@ -1060,20 +1059,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
@@ -1106,22 +1105,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;
@@ -1129,8 +1134,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;
}
@@ -1333,16 +1340,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
@@ -1350,16 +1357,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;
@@ -1367,29 +1374,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*/
@@ -1411,24 +1423,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;
@@ -1438,14 +1461,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
@@ -1466,13 +1491,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 */
@@ -1489,10 +1516,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);
@@ -1513,19 +1542,21 @@ png_colorspace_set_xy_and_XYZ(png_const_structrp png_ptr,
png_colorspacerp colorspace, const png_xy *xy, const png_XYZ *XYZ,
int preferred)
{
if (colorspace->flags & PNG_COLORSPACE_INVALID)
if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)
return 0;
/* The consistency check is performed on the chromaticities; this factors out
* variations because of the normalization (or not) of the end point Y
* values.
*/
if (preferred < 2 && (colorspace->flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
if (preferred < 2 &&
(colorspace->flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
{
/* 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");
@@ -1544,7 +1575,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
@@ -1671,7 +1702,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);
@@ -1732,7 +1763,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
@@ -1910,13 +1941,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;
@@ -2136,7 +2167,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
@@ -2176,7 +2207,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
@@ -2191,7 +2222,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",
@@ -2227,7 +2258,9 @@ png_icc_set_sRGB(png_const_structrp png_ptr,
/* Is this profile one of the known ICC sRGB profiles? If it is, just set
* the sRGB information.
*/
if (png_compare_ICC_profile_with_sRGB(png_ptr, profile, adler))
#if PNG_sRGB_PROFILE_CHECKS >= 0
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));
}
@@ -2238,14 +2271,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 */
@@ -2428,13 +2461,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 ||
@@ -2444,7 +2477,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;
@@ -2504,7 +2537,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);
@@ -2512,10 +2545,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
@@ -2524,7 +2557,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);
@@ -2562,7 +2595,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);
@@ -2605,7 +2638,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 */;
@@ -2859,8 +2892,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;
@@ -3205,7 +3239,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");
@@ -3226,7 +3260,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
@@ -3261,7 +3295,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
@@ -3596,7 +3630,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. */
@@ -3619,7 +3653,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. */
@@ -3934,7 +3968,7 @@ png_build_gamma_table(png_structrp png_ptr, png_fixed_point gamma_val,
hival = ((png_uint_16p)data.table)[size-1] = 65535;
}
if (png_gamma_significant(gamma_val))
if (png_gamma_significant(gamma_val) != 0)
write_gamma_table(&data, 0, 0, size-1, hival);
else /* gamma_val not significant */
@@ -4033,7 +4067,7 @@ png_build_gamma_tables(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)
{
/* This sets the accuracy of 8-bit composition and the 8-bit RGB to gray
* conversion - PNG_MAX_GAMMA_8 (the number of bits in the sixteen bit
@@ -4064,7 +4098,7 @@ png_build_gamma_tables(png_structrp png_ptr, int bit_depth)
table_type = PNG_GAMMA_TABLE_8_IN_16;
# endif
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;
@@ -4083,7 +4117,7 @@ png_build_gamma_tables(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
@@ -4105,7 +4139,7 @@ png_build_gamma_tables(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_ptr->gamma_16_to_1 = png_voidcast(png_uint_16p,
png_build_gamma_table(png_ptr,
@@ -4335,7 +4369,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;
@@ -4359,7 +4393,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);