diff options
author | George Hazan <george.hazan@gmail.com> | 2014-12-18 11:45:07 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-12-18 11:45:07 +0000 |
commit | c554ec47dca508a085c4206aea5cc5cadc1311fb (patch) | |
tree | 6f00b5382e5d13fb72e4174017c8a344b4436902 /plugins/AdvaImg/src/LibPNG/png.c | |
parent | 040c8cd3bba9c42d5db076c6e612638a9c32a932 (diff) |
libpng updated to 1.6.15
git-svn-id: http://svn.miranda-ng.org/main/trunk@11507 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/AdvaImg/src/LibPNG/png.c')
-rw-r--r-- | plugins/AdvaImg/src/LibPNG/png.c | 595 |
1 files changed, 340 insertions, 255 deletions
diff --git a/plugins/AdvaImg/src/LibPNG/png.c b/plugins/AdvaImg/src/LibPNG/png.c index 7a67bd3026..f0f0f94c5c 100644 --- a/plugins/AdvaImg/src/LibPNG/png.c +++ b/plugins/AdvaImg/src/LibPNG/png.c @@ -1,7 +1,7 @@ /* png.c - location for general purpose libpng functions
*
- * Last changed in libpng 1.6.9 [February 6, 2014]
+ * Last changed in libpng 1.6.15 [November 20, 2014]
* Copyright (c) 1998-2014 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@@ -14,7 +14,7 @@ #include "pngpriv.h"
/* Generate a compiler error if there is an old png.h in the search path. */
-typedef png_libpng_version_1_6_10 Your_png_h_is_not_version_1_6_10;
+typedef png_libpng_version_1_6_15 Your_png_h_is_not_version_1_6_15;
/* Tells libpng that we have already handled the first "num_bytes" bytes
* of the PNG file signature. If the PNG data is embedded into another
@@ -65,7 +65,7 @@ png_sig_cmp(png_const_bytep sig, png_size_t start, png_size_t num_to_check) return ((int)(memcmp(&sig[start], &png_signature[start], num_to_check)));
}
-#endif /* PNG_READ_SUPPORTED */
+#endif /* READ */
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
/* Function to allocate memory for zlib */
@@ -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 */
@@ -165,53 +165,51 @@ png_calculate_crc(png_structrp png_ptr, png_const_bytep ptr, png_size_t length) int
png_user_version_check(png_structrp png_ptr, png_const_charp user_png_ver)
{
- if (user_png_ver)
+ /* Libpng versions 1.0.0 and later are binary compatible if the version
+ * string matches through the second '.'; we must recompile any
+ * applications that use any older library version.
+ */
+
+ if (user_png_ver != NULL)
{
- int i = 0;
+ int i = -1;
+ int found_dots = 0;
do
{
- if (user_png_ver[i] != png_libpng_ver[i])
+ i++;
+ if (user_png_ver[i] != PNG_LIBPNG_VER_STRING[i])
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
- } while (png_libpng_ver[i++]);
+ if (user_png_ver[i] == '.')
+ found_dots++;
+ } while (found_dots < 2 && user_png_ver[i] != 0 &&
+ PNG_LIBPNG_VER_STRING[i] != 0);
}
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.
- * For versions after libpng 1.0, we will be compatible, so we need
- * only check the first and third digits (note that when we reach version
- * 1.10 we will need to check the fourth symbol, namely user_png_ver[3]).
- */
- if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
- (user_png_ver[0] == '1' && (user_png_ver[2] != png_libpng_ver[2] ||
- user_png_ver[3] != png_libpng_ver[3])) ||
- (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
- {
#ifdef PNG_WARNINGS_SUPPORTED
- size_t pos = 0;
- char m[128];
+ size_t pos = 0;
+ char m[128];
- pos = png_safecat(m, (sizeof m), pos,
- "Application built with libpng-");
- pos = png_safecat(m, (sizeof m), pos, user_png_ver);
- pos = png_safecat(m, (sizeof m), pos, " but running with ");
- pos = png_safecat(m, (sizeof m), pos, png_libpng_ver);
- PNG_UNUSED(pos)
+ pos = png_safecat(m, (sizeof m), pos,
+ "Application built with libpng-");
+ pos = png_safecat(m, (sizeof m), pos, user_png_ver);
+ pos = png_safecat(m, (sizeof m), pos, " but running with ");
+ pos = png_safecat(m, (sizeof m), pos, PNG_LIBPNG_VER_STRING);
+ PNG_UNUSED(pos)
- png_warning(png_ptr, m);
+ png_warning(png_ptr, m);
#endif
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
- png_ptr->flags = 0;
+ png_ptr->flags = 0;
#endif
- return 0;
- }
+ return 0;
}
/* Success return. */
@@ -289,7 +287,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,32 +449,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)
{
png_free(png_ptr, info_ptr->trans_alpha);
info_ptr->trans_alpha = NULL;
@@ -486,7 +484,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);
@@ -498,20 +496,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;
}
@@ -521,7 +519,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);
@@ -533,26 +531,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;
@@ -564,25 +564,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;
@@ -594,7 +592,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;
@@ -603,7 +601,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;
@@ -613,16 +611,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;
}
@@ -635,7 +631,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask, info_ptr->free_me &= ~mask;
}
-#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
+#endif /* READ || WRITE */
/* This function returns a pointer to the io_ptr associated with the user
* functions. The application should free any memory associated with this
@@ -750,7 +746,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
@@ -760,9 +756,9 @@ png_convert_to_rfc1123(png_structrp png_ptr, png_const_timep ptime) return NULL;
}
# endif
-# endif /* PNG_TIME_RFC1123_SUPPORTED */
+# endif /* TIME_RFC1123 */
-#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
+#endif /* READ || WRITE */
png_const_charp PNGAPI
png_get_copyright(png_const_structrp png_ptr)
@@ -773,13 +769,13 @@ png_get_copyright(png_const_structrp png_ptr) #else
# ifdef __STDC__
return PNG_STRING_NEWLINE \
- "libpng version 1.6.10 - March 6, 2014" PNG_STRING_NEWLINE \
+ "libpng version 1.6.15 - November 20, 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.10 - March 6, 2014\
+ return "libpng version 1.6.15 - November 20, 2014\
Copyright (c) 1998-2014 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@@ -904,7 +900,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);
@@ -941,7 +937,7 @@ png_reset_zstream(png_structrp png_ptr) /* WARNING: this resets the window bits to the maximum! */
return (inflateReset(&png_ptr->zstream));
}
-#endif /* PNG_READ_SUPPORTED */
+#endif /* READ */
/* This function was added to libpng-1.0.7 */
png_uint_32 PNGAPI
@@ -1046,8 +1042,8 @@ png_colorspace_check_gamma(png_const_structrp png_ptr, png_fixed_point gtest;
if ((colorspace->flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
- (!png_muldiv(>est, colorspace->gamma, PNG_FP_1, gAMA) ||
- png_gamma_significant(gtest)))
+ (png_muldiv(>est, 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
@@ -1102,12 +1098,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;
@@ -1131,7 +1128,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|
@@ -1152,20 +1149,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
@@ -1198,22 +1195,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;
@@ -1221,8 +1224,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;
}
@@ -1425,16 +1430,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
@@ -1442,16 +1447,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;
@@ -1459,29 +1464,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*/
@@ -1503,24 +1513,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;
@@ -1530,14 +1551,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
@@ -1558,13 +1581,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) return result;
+ if (result != 0)
+ return result;
result = png_xy_from_XYZ(&xy_test, XYZ);
- if (result) 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 */
@@ -1581,10 +1606,12 @@ png_colorspace_check_XYZ(png_xy *xy, png_XYZ *XYZ) png_XYZ XYZtemp;
result = png_XYZ_normalize(XYZ);
- if (result) return result;
+ if (result != 0)
+ return result;
result = png_xy_from_XYZ(xy, XYZ);
- if (result) return result;
+ if (result != 0)
+ return result;
XYZtemp = *XYZ;
return png_colorspace_check_xy(&XYZtemp, xy);
@@ -1605,19 +1632,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");
@@ -1625,7 +1654,7 @@ png_colorspace_set_xy_and_XYZ(png_const_structrp png_ptr, }
/* Only overwrite with preferred values */
- if (!preferred)
+ if (preferred == 0)
return 1; /* ok, but no change */
}
@@ -1636,7 +1665,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
@@ -1764,7 +1793,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);
@@ -1825,7 +1854,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
@@ -1906,10 +1935,6 @@ png_icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace, return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
"too short");
- if (profile_length & 3)
- return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
- "invalid length");
-
return 1;
}
@@ -1930,6 +1955,11 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace, return png_icc_profile_error(png_ptr, colorspace, name, temp,
"length does not match profile");
+ temp = (png_uint_32) (*(profile+8));
+ if (temp > 3 && (profile_length & 3))
+ return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
+ "invalid length");
+
temp = png_get_uint_32(profile+128); /* tag count: 12 bytes/tag */
if (temp > 357913930 || /* (2^32-4-132)/12: maximum possible tag count */
profile_length < 132+12*temp) /* truncated tag table */
@@ -2003,13 +2033,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;
@@ -2044,7 +2074,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace, "invalid embedded Abstract ICC profile");
case 0x6C696E6B: /* 'link' */
- /* DeviceLink profiles cannnot be interpreted in a non-device specific
+ /* DeviceLink profiles cannot be interpreted in a non-device specific
* fashion, if an app uses the AToB0Tag in the profile the results are
* undefined unless the result is sent to the intended device,
* therefore a DeviceLink profile should not be found embedded in a
@@ -2055,7 +2085,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace, case 0x6E6D636C: /* 'nmcl' */
/* A NamedColor profile is also device specific, however it doesn't
- * contain an AToB0 tag that is open to misintrepretation. Almost
+ * contain an AToB0 tag that is open to misinterpretation. Almost
* certainly it will fail the tests below.
*/
(void)png_icc_profile_error(png_ptr, NULL, name, temp,
@@ -2136,7 +2166,7 @@ png_icc_check_tag_table(png_const_structrp png_ptr, png_colorspacerp colorspace, return 1; /* success, maybe with warnings */
}
-#ifdef PNG_sRGB_SUPPORTED
+#if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0
/* Information about the known ICC sRGB profiles */
static const struct
{
@@ -2210,6 +2240,7 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr, * by sRGB (but maybe defined by a later ICC specification) the read of
* the profile will fail at that point.
*/
+
png_uint_32 length = 0;
png_uint_32 intent = 0x10000; /* invalid */
#if PNG_sRGB_PROFILE_CHECKS > 1
@@ -2217,6 +2248,13 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr, #endif
unsigned int i;
+#ifdef PNG_SET_OPTION_SUPPORTED
+ /* First see if PNG_SKIP_sRGB_CHECK_PROFILE has been set to "on" */
+ if (((png_ptr->options >> PNG_SKIP_sRGB_CHECK_PROFILE) & 3) ==
+ PNG_OPTION_ON)
+ return 0;
+#endif
+
for (i=0; i < (sizeof png_sRGB_checks) / (sizeof png_sRGB_checks[0]); ++i)
{
if (png_get_uint_32(profile+84) == png_sRGB_checks[i].md5[0] &&
@@ -2229,7 +2267,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
@@ -2269,7 +2307,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
@@ -2284,28 +2322,28 @@ 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",
+ png_chunk_report(png_ptr, "out-of-date sRGB profile with"
+ " no signature",
PNG_CHUNK_WARNING);
}
return 1+png_sRGB_checks[i].is_broken;
}
}
- }
# if PNG_sRGB_PROFILE_CHECKS > 0
/* The signature matched, but the profile had been changed in some
* way. This probably indicates a data error or uninformed hacking.
* Fall through to "no match".
*/
- png_chunk_report(png_ptr,
- "Not recognizing known sRGB profile that has been edited",
+ png_chunk_report(png_ptr, "Not recognizing known sRGB profile that"
+ " has been edited",
PNG_CHUNK_WARNING);
break;
# endif
+ }
}
}
@@ -2321,25 +2359,27 @@ 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));
}
-#endif /* PNG_READ_sRGB_SUPPORTED */
+#endif /* READ_sRGB */
int /* PRIVATE */
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 */
@@ -2358,7 +2398,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
@@ -2435,44 +2475,45 @@ png_check_IHDR(png_const_structrp png_ptr, png_warning(png_ptr, "Image width is zero in IHDR");
error = 1;
}
-
- if (height == 0)
+ else if (width > PNG_UINT_31_MAX)
{
- png_warning(png_ptr, "Image height is zero in IHDR");
+ png_warning(png_ptr, "Invalid image width in IHDR");
error = 1;
}
-
-# ifdef PNG_SET_USER_LIMITS_SUPPORTED
- if (width > png_ptr->user_width_max)
-
-# else
- if (width > PNG_USER_WIDTH_MAX)
-# endif
+ else
{
- png_warning(png_ptr, "Image width exceeds user limit in IHDR");
- error = 1;
+# ifdef PNG_SET_USER_LIMITS_SUPPORTED
+ if (width > png_ptr->user_width_max)
+# else
+ if (width > PNG_USER_WIDTH_MAX)
+# endif
+ {
+ png_warning(png_ptr, "Image width exceeds user limit in IHDR");
+ error = 1;
+ }
}
-# ifdef PNG_SET_USER_LIMITS_SUPPORTED
- if (height > png_ptr->user_height_max)
-# else
- if (height > PNG_USER_HEIGHT_MAX)
-# endif
+ if (height == 0)
{
- png_warning(png_ptr, "Image height exceeds user limit in IHDR");
+ png_warning(png_ptr, "Image height is zero in IHDR");
error = 1;
}
-
- if (width > PNG_UINT_31_MAX)
+ else if (height > PNG_UINT_31_MAX)
{
- png_warning(png_ptr, "Invalid image width in IHDR");
+ png_warning(png_ptr, "Invalid image height in IHDR");
error = 1;
}
-
- if (height > PNG_UINT_31_MAX)
+ else
{
- png_warning(png_ptr, "Invalid image height in IHDR");
- error = 1;
+# ifdef PNG_SET_USER_LIMITS_SUPPORTED
+ if (height > png_ptr->user_height_max)
+# else
+ if (height > PNG_USER_HEIGHT_MAX)
+# endif
+ {
+ png_warning(png_ptr, "Image height exceeds user limit in IHDR");
+ error = 1;
+ }
}
/* Check other values */
@@ -2521,13 +2562,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 ||
@@ -2537,7 +2578,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;
@@ -2597,7 +2638,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);
@@ -2605,10 +2646,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
@@ -2617,7 +2658,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);
@@ -2655,7 +2696,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);
@@ -2698,13 +2739,13 @@ 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 */;
return 0; /* i.e. fail */
}
-#endif /* pCAL or sCAL */
+#endif /* pCAL || sCAL */
#ifdef PNG_sCAL_SUPPORTED
# ifdef PNG_FLOATING_POINT_SUPPORTED
@@ -2738,7 +2779,7 @@ png_pow10(int power) }
while (power > 0);
- if (recip) d = 1/d;
+ if (recip != 0) d = 1/d;
}
/* else power is 0 and d is 1 */
@@ -2952,8 +2993,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;
@@ -3261,11 +3303,12 @@ png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, if (s00 >= (D >> 1))
++result;
- if (negative)
+ if (negative != 0)
result = -result;
/* Check for overflow. */
- if ((negative && result <= 0) || (!negative && result >= 0))
+ if ((negative != 0 && result <= 0) ||
+ (negative == 0 && result >= 0))
{
*res = result;
return 1;
@@ -3289,7 +3332,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");
@@ -3310,7 +3353,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
@@ -3329,7 +3372,7 @@ png_gamma_significant(png_fixed_point gamma_val) #endif
#ifdef PNG_READ_GAMMA_SUPPORTED
-# ifdef PNG_16BIT_SUPPORTED
+#if defined(PNG_16BIT_SUPPORTED) || !defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
/* A local convenience routine. */
static png_fixed_point
png_product2(png_fixed_point a, png_fixed_point b)
@@ -3345,13 +3388,13 @@ 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
return 0; /* overflow */
}
-# endif /* 16BIT */
+#endif /* 16BIT || !FLOATING_ARITHMETIC */
/* The inverse of the above. */
png_fixed_point
@@ -3503,6 +3546,7 @@ png_log8bit(unsigned int x) * Zero (257): 0
* End (258): 23499
*/
+#ifdef PNG_16BIT_SUPPORTED
static png_int_32
png_log16bit(png_uint_32 x)
{
@@ -3553,14 +3597,15 @@ png_log16bit(png_uint_32 x) /* Safe, because the result can't have more than 20 bits: */
return (png_int_32)((lg2 + 2048) >> 12);
}
+#endif /* 16BIT */
/* The 'exp()' case must invert the above, taking a 20-bit fixed point
* logarithmic value and returning a 16 or 8-bit number as appropriate. In
* each case only the low 16 bits are relevant - the fraction - since the
* integer bits (the top 4) simply determine a shift.
*
- * The worst case is the 16-bit distinction between 65535 and 65534, this
- * requires perhaps spurious accuracty in the decoding of the logarithm to
+ * The worst case is the 16-bit distinction between 65535 and 65534. This
+ * requires perhaps spurious accuracy in the decoding of the logarithm to
* distinguish log2(65535/65534.5) - 10^-5 or 17 bits. There is little chance
* of getting this accuracy in practice.
*
@@ -3648,7 +3693,7 @@ png_exp8bit(png_fixed_point lg2) /* Get a 32-bit value: */
png_uint_32 x = png_exp(lg2);
- /* Convert the 32-bit value to 0..255 by multiplying by 256-1, note that the
+ /* Convert the 32-bit value to 0..255 by multiplying by 256-1. Note that the
* second, rounding, step can't overflow because of the first, subtraction,
* step.
*/
@@ -3676,13 +3721,37 @@ png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val) if (value > 0 && value < 255)
{
# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
- double r = floor(255*pow(value/255.,gamma_val*.00001)+.5);
+ /* 'value' is unsigned, ANSI-C90 requires the compiler to correctly
+ * convert this to a floating point value. This includes values that
+ * would overflow if 'value' were to be converted to 'int'.
+ *
+ * Apparently GCC, however, does an intermediate conversion to (int)
+ * on some (ARM) but not all (x86) platforms, possibly because of
+ * hardware FP limitations. (E.g. if the hardware conversion always
+ * assumes the integer register contains a signed value.) This results
+ * in ANSI-C undefined behavior for large values.
+ *
+ * Other implementations on the same machine might actually be ANSI-C90
+ * conformant and therefore compile spurious extra code for the large
+ * values.
+ *
+ * We can be reasonably sure that an unsigned to float conversion
+ * won't be faster than an int to float one. Therefore this code
+ * assumes responsibility for the undefined behavior, which it knows
+ * can't happen because of the check above.
+ *
+ * Note the argument to this routine is an (unsigned int) because, on
+ * 16-bit platforms, it is assigned a value which might be out of
+ * range for an (int); that would result in undefined behavior in the
+ * caller if the *argument* ('value') were to be declared (int).
+ */
+ double r = floor(255*pow((int)/*SAFE*/value/255.,gamma_val*.00001)+.5);
return (png_byte)r;
# else
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. */
@@ -3700,13 +3769,19 @@ png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val) if (value > 0 && value < 65535)
{
# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
- double r = floor(65535*pow(value/65535.,gamma_val*.00001)+.5);
+ /* The same (unsigned int)->(double) constraints apply here as above,
+ * however in this case the (unsigned int) to (int) conversion can
+ * overflow on an ANSI-C90 compliant system so the cast needs to ensure
+ * that this is not possible.
+ */
+ double r = floor(65535*pow((png_int_32)value/65535.,
+ gamma_val*.00001)+.5);
return (png_uint_16)r;
# else
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. */
@@ -3754,6 +3829,12 @@ png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable, {
/* Various values derived from 'shift': */
PNG_CONST unsigned int num = 1U << (8U - shift);
+#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
+ /* CSE the division and work round wacky GCC warnings (see the comments
+ * in png_gamma_8bit_correct for where these come from.)
+ */
+ PNG_CONST double fmax = 1./(((png_int_32)1 << (16U - shift))-1);
+#endif
PNG_CONST unsigned int max = (1U << (16U - shift))-1U;
PNG_CONST unsigned int max_by_2 = 1U << (15U-shift);
unsigned int i;
@@ -3769,7 +3850,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
@@ -3785,10 +3866,13 @@ png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable, png_uint_32 ig = (j << (8-shift)) + i;
# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
/* Inline the 'max' scaling operation: */
- double d = floor(65535*pow(ig/(double)max, gamma_val*.00001)+.5);
+ /* See png_gamma_8bit_correct for why the cast to (int) is
+ * required here.
+ */
+ double d = floor(65535.*pow(ig*fmax, gamma_val*.00001)+.5);
sub_table[j] = (png_uint_16)d;
# else
- if (shift)
+ if (shift != 0)
ig = (ig * 65535U + max_by_2)/max;
sub_table[j] = png_gamma_16bit_correct(ig, gamma_val);
@@ -3804,7 +3888,7 @@ png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable, {
png_uint_32 ig = (j << (8-shift)) + i;
- if (shift)
+ if (shift != 0)
ig = (ig * 65535U + max_by_2)/max;
sub_table[j] = (png_uint_16)ig;
@@ -3830,7 +3914,7 @@ png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable, /* 'num' is the number of tables and also the number of low bits of low
* bits of the input 16-bit value used to select a table. Each table is
- * itself index by the high 8 bits of the value.
+ * itself indexed by the high 8 bits of the value.
*/
for (i = 0; i < num; i++)
table[i] = (png_uint_16p)png_malloc(png_ptr,
@@ -3882,7 +3966,7 @@ png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable, /* Build a single 8-bit table: same as the 16-bit case but much simpler (and
* typically much faster). Note that libpng currently does no sBIT processing
- * (apparently contrary to the spec) so a 256 entry table is always generated.
+ * (apparently contrary to the spec) so a 256-entry table is always generated.
*/
static void
png_build_8bit_table(png_structrp png_ptr, png_bytepp ptable,
@@ -3891,11 +3975,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
@@ -3987,7 +4073,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));
@@ -4003,7 +4089,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;
@@ -4023,7 +4109,7 @@ png_build_gamma_table(png_structrp png_ptr, int bit_depth) * Where 'iv' is the input color value and 'ov' is the output value -
* pow(iv, gamma).
*
- * Thus the gamma table consists of up to 256 256 entry tables. The table
+ * Thus the gamma table consists of up to 256 256-entry tables. The table
* is selected by the (8-gamma_shift) most significant of the low 8 bits of
* the color value then indexed by the upper 8 bits:
*
@@ -4040,7 +4126,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
@@ -4060,7 +4146,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);
@@ -4073,7 +4159,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));
@@ -4092,7 +4178,7 @@ png_build_gamma_table(png_structrp png_ptr, int bit_depth) }
#endif /* READ_GAMMA */
-/* HARDWARE OPTION SUPPORT */
+/* HARDWARE OR SOFTWARE OPTION SUPPORT */
#ifdef PNG_SET_OPTION_SUPPORTED
int PNGAPI
png_set_option(png_structrp png_ptr, int option, int onoff)
@@ -4131,7 +4217,7 @@ png_set_option(png_structrp png_ptr, int option, int onoff) *
* error: -0.513727 - 0.607759, 308 (0.469978%) of readings inexact
*
- * In all cases the inexact readings are off by one.
+ * In all cases the inexact readings are only off by one.
*/
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
@@ -4171,8 +4257,7 @@ const png_uint_16 png_sRGB_table[256] = 57105,57646,58190,58737,59287,59840,60396,60955,
61517,62082,62650,63221,63795,64372,64952,65535
};
-
-#endif /* simplified read only */
+#endif /* SIMPLIFIED_READ */
/* The base/delta tables are required for both read and write (but currently
* only the simplified versions.)
@@ -4300,7 +4385,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;
@@ -4324,7 +4409,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);
@@ -4372,4 +4457,4 @@ png_image_error(png_imagep image, png_const_charp error_message) }
#endif /* SIMPLIFIED READ/WRITE */
-#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
+#endif /* READ || WRITE */
|