DO NOT MERGE Update libpng to 1.6.20
BUG:23265085
Change-Id: I85199805636d771f3597b691b63bc0bf46084833
(cherry picked from commit bbe98b40cda082024b669fa508931042eed18f82)
diff --git a/png.c b/png.c
index 59e991b..c183e3f 100644
--- a/png.c
+++ b/png.c
@@ -1,8 +1,8 @@
/* png.c - location for general purpose libpng functions
*
- * Last changed in libpng 1.6.9 [February 6, 2014]
- * Copyright (c) 1998-2014 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.19 [November 12, 2015]
+ * Copyright (c) 1998-2015 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_20 Your_png_h_is_not_version_1_6_20;
/* 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
@@ -26,15 +26,20 @@
void PNGAPI
png_set_sig_bytes(png_structrp png_ptr, int num_bytes)
{
+ unsigned int nb = (unsigned int)num_bytes;
+
png_debug(1, "in png_set_sig_bytes");
if (png_ptr == NULL)
return;
- if (num_bytes > 8)
+ if (num_bytes < 0)
+ nb = 0;
+
+ if (nb > 8)
png_error(png_ptr, "Too many bytes for PNG signature");
- png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
+ png_ptr->sig_bytes = (png_byte)nb;
}
/* Checks whether the supplied bytes match the PNG signature. We allow
@@ -65,7 +70,7 @@
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 */
@@ -101,7 +106,7 @@
void /* PRIVATE */
png_reset_crc(png_structrp png_ptr)
{
- /* The cast is safe because the crc is a 32 bit value. */
+ /* The cast is safe because the crc is a 32-bit value. */
png_ptr->crc = (png_uint_32)crc32(0, Z_NULL, 0);
}
@@ -115,7 +120,7 @@
{
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,24 +129,26 @@
else /* critical */
{
- if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
+ if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0)
need_crc = 0;
}
/* 'uLong' is defined in zlib.h as unsigned long; this means that on some
- * systems it is a 64 bit value. crc32, however, returns 32 bits so the
+ * systems it is a 64-bit value. crc32, however, returns 32 bits so the
* 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 */
do
{
uInt safe_length = (uInt)length;
+#ifndef __COVERITY__
if (safe_length == 0)
safe_length = (uInt)-1; /* evil, but safe */
+#endif
crc = crc32(crc, ptr, safe_length);
@@ -165,53 +172,51 @@
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. */
@@ -243,15 +248,15 @@
create_struct.user_height_max = PNG_USER_HEIGHT_MAX;
# ifdef PNG_USER_CHUNK_CACHE_MAX
- /* Added at libpng-1.2.43 and 1.4.0 */
- create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX;
+ /* Added at libpng-1.2.43 and 1.4.0 */
+ create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX;
# endif
# ifdef PNG_USER_CHUNK_MALLOC_MAX
- /* Added at libpng-1.2.43 and 1.4.1, required only for read but exists
- * in png_struct regardless.
- */
- create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX;
+ /* Added at libpng-1.2.43 and 1.4.1, required only for read but exists
+ * in png_struct regardless.
+ */
+ create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX;
# endif
# endif
@@ -275,7 +280,9 @@
# ifdef PNG_SETJMP_SUPPORTED
if (!setjmp(create_jmp_buf))
+# endif
{
+# ifdef PNG_SETJMP_SUPPORTED
/* Temporarily fake out the longjmp information until we have
* successfully completed this function. This only works if we have
* setjmp() support compiled in, but it is safe - this stuff should
@@ -284,12 +291,10 @@
create_struct.jmp_buf_ptr = &create_jmp_buf;
create_struct.jmp_buf_size = 0; /*stack allocation*/
create_struct.longjmp_fn = longjmp;
-# else
- {
# 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)));
@@ -304,10 +309,10 @@
create_struct.zstream.opaque = png_ptr;
# ifdef PNG_SETJMP_SUPPORTED
- /* Eliminate the local error handling: */
- create_struct.jmp_buf_ptr = NULL;
- create_struct.jmp_buf_size = 0;
- create_struct.longjmp_fn = 0;
+ /* Eliminate the local error handling: */
+ create_struct.jmp_buf_ptr = NULL;
+ create_struct.jmp_buf_size = 0;
+ create_struct.longjmp_fn = 0;
# endif
*png_ptr = create_struct;
@@ -413,6 +418,8 @@
free(info_ptr);
info_ptr = png_voidcast(png_inforp, png_malloc_base(NULL,
(sizeof *info_ptr)));
+ if (info_ptr == NULL)
+ return;
*ptr_ptr = info_ptr;
}
@@ -451,42 +458,43 @@
#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);
info_ptr->trans_alpha = NULL;
- info_ptr->valid &= ~PNG_INFO_tRNS;
+ info_ptr->num_trans = 0;
}
#endif
#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 +506,20 @@
#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 +529,7 @@
#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,68 +541,62 @@
#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;
- }
- }
-
- else
- {
- if (info_ptr->splt_palettes_num)
- {
- 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);
- info_ptr->splt_palettes = NULL;
- info_ptr->splt_palettes_num = 0;
- }
- info_ptr->valid &= ~PNG_INFO_sPLT;
- }
- }
-#endif
-
-#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
- if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
- {
- 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->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
{
int i;
- if (info_ptr->unknown_chunks_num)
+ for (i = 0; i < info_ptr->splt_palettes_num; i++)
{
- 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);
- info_ptr->unknown_chunks = NULL;
- info_ptr->unknown_chunks_num = 0;
+ 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;
+ info_ptr->splt_palettes_num = 0;
+ info_ptr->valid &= ~PNG_INFO_sPLT;
+ }
+ }
+#endif
+
+#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
+ if (info_ptr->unknown_chunks != 0 &&
+ ((mask & PNG_FREE_UNKN) & info_ptr->free_me) != 0)
+ {
+ if (num != -1)
+ {
+ png_free(png_ptr, info_ptr->unknown_chunks[num].data);
+ info_ptr->unknown_chunks[num].data = NULL;
+ }
+
+ else
+ {
+ int i;
+
+ for (i = 0; i < info_ptr->unknown_chunks_num; i++)
+ png_free(png_ptr, info_ptr->unknown_chunks[i].data);
+
+ png_free(png_ptr, info_ptr->unknown_chunks);
+ info_ptr->unknown_chunks = NULL;
+ info_ptr->unknown_chunks_num = 0;
}
}
#endif
#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 +605,7 @@
#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 +615,14 @@
#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 +635,7 @@
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
@@ -670,22 +670,23 @@
}
# endif
-#ifdef PNG_SAVE_INT_32_SUPPORTED
-/* The png_save_int_32 function assumes integers are stored in two's
- * complement format. If this isn't the case, then this routine needs to
- * be modified to write data in two's complement format. Note that,
- * the following works correctly even if png_int_32 has more than 32 bits
- * (compare the more complex code required on read for sign extension.)
+# ifdef PNG_SAVE_INT_32_SUPPORTED
+/* PNG signed integers are saved in 32-bit 2's complement format. ANSI C-90
+ * defines a cast of a signed integer to an unsigned integer either to preserve
+ * the value, if it is positive, or to calculate:
+ *
+ * (UNSIGNED_MAX+1) + integer
+ *
+ * Where UNSIGNED_MAX is the appropriate maximum unsigned value, so when the
+ * negative integral value is added the result will be an unsigned value
+ * correspnding to the 2's complement representation.
*/
void PNGAPI
png_save_int_32(png_bytep buf, png_int_32 i)
{
- buf[0] = (png_byte)((i >> 24) & 0xff);
- buf[1] = (png_byte)((i >> 16) & 0xff);
- buf[2] = (png_byte)((i >> 8) & 0xff);
- buf[3] = (png_byte)(i & 0xff);
+ png_save_uint_32(buf, i);
}
-#endif
+# endif
# ifdef PNG_TIME_RFC1123_SUPPORTED
/* Convert the supplied time into an RFC 1123 string suitable for use in
@@ -729,6 +730,7 @@
APPEND(':');
APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->second);
APPEND_STRING(" +0000"); /* This reliably terminates the buffer */
+ PNG_UNUSED (pos)
# undef APPEND
# undef APPEND_NUMBER
@@ -738,7 +740,7 @@
return 1;
}
-# if PNG_LIBPNG_VER < 10700
+# if PNG_LIBPNG_VER < 10700
/* To do: remove the following from libpng-1.7 */
/* Original API that uses a private buffer in png_struct.
* Deprecated because it causes png_struct to carry a spurious temporary
@@ -750,7 +752,7 @@
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
@@ -759,10 +761,10 @@
return NULL;
}
-# endif
-# endif /* PNG_TIME_RFC1123_SUPPORTED */
+# endif /* LIBPNG_VER < 10700 */
+# 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,14 +775,14 @@
#else
# ifdef __STDC__
return PNG_STRING_NEWLINE \
- "libpng version 1.6.10 - March 6, 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;
+ "libpng version 1.6.20 - December 3, 2015" PNG_STRING_NEWLINE \
+ "Copyright (c) 1998-2015 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\
- Copyright (c) 1998-2014 Glenn Randers-Pehrson\
+ return "libpng version 1.6.20 - December 3, 2015\
+ Copyright (c) 1998-2015 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
# endif
@@ -818,9 +820,9 @@
#ifdef __STDC__
return PNG_HEADER_VERSION_STRING
# ifndef PNG_READ_SUPPORTED
- " (NO READ SUPPORT)"
+ " (NO READ SUPPORT)"
# endif
- PNG_STRING_NEWLINE;
+ PNG_STRING_NEWLINE;
#else
return PNG_HEADER_VERSION_STRING;
#endif
@@ -876,9 +878,9 @@
for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
{
- palette[i].red = (png_byte)v;
- palette[i].green = (png_byte)v;
- palette[i].blue = (png_byte)v;
+ palette[i].red = (png_byte)(v & 0xff);
+ palette[i].green = (png_byte)(v & 0xff);
+ palette[i].blue = (png_byte)(v & 0xff);
}
}
#endif
@@ -904,7 +906,7 @@
{
p -= 5;
- if (!memcmp(chunk_name, p, 4))
+ if (memcmp(chunk_name, p, 4) == 0)
return p[4];
}
while (p > p_end);
@@ -941,7 +943,7 @@
/* 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
@@ -951,8 +953,6 @@
return((png_uint_32)PNG_LIBPNG_VER);
}
-
-
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
/* Ensure that png_ptr->zstream.msg holds some appropriate error message string.
* If it doesn't 'ret' is used to set it to something appropriate, even in cases
@@ -1046,8 +1046,8 @@
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
@@ -1079,7 +1079,7 @@
png_colorspacerp colorspace, png_fixed_point gAMA)
{
/* Changed in libpng-1.5.4 to limit the values to ensure overflow can't
- * occur. Since the fixed point representation is assymetrical it is
+ * occur. Since the fixed point representation is asymetrical it is
* possible for 1/gamma to overflow the limit of 21474 and this means the
* gamma value must be at least 5/100000 and hence at most 20000.0. For
* safety the limits here are a little narrower. The values are 0.00016 to
@@ -1095,19 +1095,20 @@
errmsg = "gamma value out of range";
# ifdef PNG_READ_gAMA_SUPPORTED
- /* Allow the application to set the gamma value more than once */
- else if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
- (colorspace->flags & PNG_COLORSPACE_FROM_gAMA) != 0)
- errmsg = "duplicate";
+ /* Allow the application to set the gamma value more than once */
+ else if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
+ (colorspace->flags & PNG_COLORSPACE_FROM_gAMA) != 0)
+ errmsg = "duplicate";
# 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,41 +1132,41 @@
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|
PNG_INFO_iCCP);
# ifdef PNG_COLORSPACE_SUPPORTED
- /* Clean up the iCCP profile now if it won't be used. */
- png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, -1/*not used*/);
+ /* Clean up the iCCP profile now if it won't be used. */
+ png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, -1/*not used*/);
# else
- PNG_UNUSED(png_ptr)
+ PNG_UNUSED(png_ptr)
# endif
}
else
{
# ifdef PNG_COLORSPACE_SUPPORTED
- /* Leave the INFO_iCCP flag set if the pngset.c code has already set
- * 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)
- info_ptr->valid |= PNG_INFO_sRGB;
+ /* Leave the INFO_iCCP flag set if the pngset.c code has already set
+ * 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) != 0)
+ info_ptr->valid |= PNG_INFO_sRGB;
- else
- info_ptr->valid &= ~PNG_INFO_sRGB;
+ else
+ info_ptr->valid &= ~PNG_INFO_sRGB;
- if (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS)
- info_ptr->valid |= PNG_INFO_cHRM;
+ if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
+ info_ptr->valid |= PNG_INFO_cHRM;
- else
- 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
@@ -1184,7 +1185,7 @@
png_colorspace_sync_info(png_ptr, info_ptr);
}
#endif
-#endif
+#endif /* GAMMA */
#ifdef PNG_COLORSPACE_SUPPORTED
/* Added at libpng-1.5.5 to support read and write of true CIEXYZ values for
@@ -1198,22 +1199,28 @@
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 +1228,10 @@
/* 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;
}
@@ -1320,7 +1329,7 @@
* (1/white-y), so we can immediately see that as white-y approaches 0 the
* accuracy inherent in the cHRM chunk drops off substantially.
*
- * libpng arithmetic: a simple invertion of the above equations
+ * libpng arithmetic: a simple inversion of the above equations
* ------------------------------------------------------------
*
* white_scale = 1/white-y
@@ -1426,16 +1435,16 @@
/* 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
@@ -1443,16 +1452,16 @@
* 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;
@@ -1460,29 +1469,34 @@
* 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*/
@@ -1504,24 +1518,35 @@
* 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;
@@ -1531,14 +1556,16 @@
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
@@ -1559,13 +1586,15 @@
/* 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 */
@@ -1582,10 +1611,12 @@
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);
@@ -1606,19 +1637,21 @@
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");
@@ -1626,7 +1659,7 @@
}
/* Only overwrite with preferred values */
- if (!preferred)
+ if (preferred == 0)
return 1; /* ok, but no change */
}
@@ -1637,7 +1670,7 @@
/* 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
@@ -1679,7 +1712,6 @@
*/
colorspace->flags |= PNG_COLORSPACE_INVALID;
png_error(png_ptr, "internal error checking chromaticities");
- break;
}
return 0; /* failed */
@@ -1707,7 +1739,6 @@
default:
colorspace->flags |= PNG_COLORSPACE_INVALID;
png_error(png_ptr, "internal error checking chromaticities");
- break;
}
return 0; /* failed */
@@ -1765,7 +1796,7 @@
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);
@@ -1789,7 +1820,7 @@
PNG_UNUSED(pos)
/* This is recoverable, but make it unconditionally an app_error on write to
- * avoid writing invalid ICC profiles into PNG files. (I.e. we handle them
+ * avoid writing invalid ICC profiles into PNG files (i.e., we handle them
* on read, with a warning, but on write unless the app turns off
* application errors the PNG won't be written.)
*/
@@ -1808,7 +1839,7 @@
/* sRGB sets known gamma, end points and (from the chunk) intent. */
/* IMPORTANT: these are not necessarily the values found in an ICC profile
* because ICC profiles store values adapted to a D50 environment; it is
- * expected that the ICC profile mediaWhitePointTag will be D50, see the
+ * expected that the ICC profile mediaWhitePointTag will be D50; see the
* checks and code elsewhere to understand this better.
*
* These XYZ values, which are accurate to 5dp, produce rgb to gray
@@ -1826,7 +1857,7 @@
};
/* 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
@@ -1907,10 +1938,6 @@
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;
}
@@ -1931,6 +1958,11 @@
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 */
@@ -2004,13 +2036,13 @@
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;
@@ -2032,8 +2064,8 @@
temp = png_get_uint_32(profile+12); /* profile/device class */
switch (temp)
{
- case 0x73636E72: /* 'scnr' */
- case 0x6D6E7472: /* 'mntr' */
+ case 0x73636e72: /* 'scnr' */
+ case 0x6d6e7472: /* 'mntr' */
case 0x70727472: /* 'prtr' */
case 0x73706163: /* 'spac' */
/* All supported */
@@ -2044,8 +2076,8 @@
return png_icc_profile_error(png_ptr, colorspace, name, temp,
"invalid embedded Abstract ICC profile");
- case 0x6C696E6B: /* 'link' */
- /* DeviceLink profiles cannnot be interpreted in a non-device specific
+ case 0x6c696e6b: /* 'link' */
+ /* 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
@@ -2054,9 +2086,9 @@
return png_icc_profile_error(png_ptr, colorspace, name, temp,
"unexpected DeviceLink ICC profile class");
- case 0x6E6D636C: /* 'nmcl' */
+ 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,
@@ -2080,8 +2112,8 @@
temp = png_get_uint_32(profile+20);
switch (temp)
{
- case 0x58595A20: /* 'XYZ ' */
- case 0x4C616220: /* 'Lab ' */
+ case 0x58595a20: /* 'XYZ ' */
+ case 0x4c616220: /* 'Lab ' */
break;
default:
@@ -2138,6 +2170,7 @@
}
#ifdef PNG_sRGB_SUPPORTED
+#if PNG_sRGB_PROFILE_CHECKS >= 0
/* Information about the known ICC sRGB profiles */
static const struct
{
@@ -2211,6 +2244,7 @@
* 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
@@ -2218,6 +2252,13 @@
#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] &&
@@ -2230,7 +2271,7 @@
* 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
@@ -2242,8 +2283,8 @@
}
/* Length *and* intent must match */
- if (length == png_sRGB_checks[i].length &&
- intent == png_sRGB_checks[i].intent)
+ if (length == (png_uint_32) png_sRGB_checks[i].length &&
+ intent == (png_uint_32) png_sRGB_checks[i].intent)
{
/* Now calculate the adler32 if not done already. */
if (adler == 0)
@@ -2270,7 +2311,7 @@
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
@@ -2285,7 +2326,7 @@
* 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",
@@ -2295,7 +2336,6 @@
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
@@ -2303,18 +2343,18 @@
* Fall through to "no match".
*/
png_chunk_report(png_ptr,
- "Not recognizing known sRGB profile that has been edited",
+ "Not recognizing known sRGB profile that has been edited",
PNG_CHUNK_WARNING);
break;
# endif
+ }
}
}
return 0; /* no match */
}
-#endif
+#endif /* PNG_sRGB_PROFILE_CHECKS >= 0 */
-#ifdef PNG_sRGB_SUPPORTED
void /* PRIVATE */
png_icc_set_sRGB(png_const_structrp png_ptr,
png_colorspacerp colorspace, png_const_bytep profile, uLong adler)
@@ -2322,25 +2362,27 @@
/* 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 /* 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 */
@@ -2359,7 +2401,7 @@
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
@@ -2418,7 +2460,7 @@
png_error(png_ptr, "internal error handling cHRM->XYZ");
}
}
-#endif
+#endif /* READ_RGB_TO_GRAY */
#endif /* COLORSPACE */
@@ -2447,18 +2489,19 @@
png_warning(png_ptr, "Image width is zero in IHDR");
error = 1;
}
- else if (width > PNG_UINT_31_MAX)
+
+ if (width > PNG_UINT_31_MAX)
{
png_warning(png_ptr, "Invalid image width in IHDR");
error = 1;
}
- else if (png_gt(width,
- (PNG_SIZE_MAX >> 3) /* 8-byte RGBA pixels */
- - 48 /* big_row_buf hack */
- - 1 /* filter byte */
- - 7*8 /* rounding width to multiple of 8 pix */
- - 8)) /* extra max_pixel_depth pad */
+ if (png_gt(((width + 7) & (~7)),
+ ((PNG_SIZE_MAX
+ - 48 /* big_row_buf hack */
+ - 1) /* filter byte */
+ / 8) /* 8-byte RGBA pixels */
+ - 1)) /* extra max_pixel_depth pad */
{
/* The size of the row must be within the limits of this architecture.
* Because the read code can perform arbitrary transformations the
@@ -2471,15 +2514,15 @@
* extensive, therefore much more dangerous and much more difficult to
* write in a way that avoids compiler warnings.
*/
- png_warning(png_ptr, "Image width is too large for this architecture");
- error = 1;
+ png_warning(png_ptr, "Image width is too large for this architecture");
+ error = 1;
}
-# ifdef PNG_SET_USER_LIMITS_SUPPORTED
- else if (width > png_ptr->user_width_max)
-# else
- else if (width > PNG_USER_WIDTH_MAX)
-# endif
+#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;
@@ -2491,24 +2534,22 @@
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;
- }
-
-
if (height > PNG_UINT_31_MAX)
{
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 */
if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
bit_depth != 8 && bit_depth != 16)
@@ -2545,7 +2586,7 @@
error = 1;
}
-# ifdef PNG_MNG_FEATURES_SUPPORTED
+#ifdef PNG_MNG_FEATURES_SUPPORTED
/* Accept filter_method 64 (intrapixel differencing) only if
* 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
* 2. Libpng did not read a PNG signature (this filter_method is only
@@ -2555,13 +2596,13 @@
* 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 ||
@@ -2571,20 +2612,20 @@
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;
}
}
-# else
+#else
if (filter_type != PNG_FILTER_TYPE_BASE)
{
png_warning(png_ptr, "Unknown filter method in IHDR");
error = 1;
}
-# endif
+#endif
if (error == 1)
png_error(png_ptr, "Invalid IHDR data");
@@ -2631,7 +2672,7 @@
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);
@@ -2639,10 +2680,10 @@
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
@@ -2651,7 +2692,7 @@
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);
@@ -2689,7 +2730,7 @@
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);
@@ -2732,13 +2773,13 @@
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
@@ -2772,7 +2813,7 @@
}
while (power > 0);
- if (recip) d = 1/d;
+ if (recip != 0) d = 1/d;
}
/* else power is 0 and d is 1 */
@@ -2810,7 +2851,7 @@
if (fp >= DBL_MIN && fp <= DBL_MAX)
{
- int exp_b10; /* A base 10 exponent */
+ int exp_b10; /* A base 10 exponent */
double base; /* 10^exp_b10 */
/* First extract a base 10 exponent of the number,
@@ -2858,7 +2899,7 @@
*/
{
- int czero, clead, cdigits;
+ unsigned int czero, clead, cdigits;
char exponent[10];
/* Allow up to two leading zeros - this will not lengthen
@@ -2888,7 +2929,7 @@
* of the loop don't break the number into parts so
* that the final digit is rounded.
*/
- if (cdigits+czero-clead+1 < (int)precision)
+ if (cdigits+czero+1 < precision+clead)
fp = modf(fp, &d);
else
@@ -2986,21 +3027,22 @@
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;
}
}
- while (cdigits+czero-clead < (int)precision && fp > DBL_MIN);
+ while (cdigits+czero < precision+clead && fp > DBL_MIN);
/* The total output count (max) is now 4+precision */
/* Check for an exponent, if we don't need one we are
* done and just need to terminate the string. At
* this point exp_b10==(-1) is effectively if flag - it got
- * to '-1' because of the decrement after outputing
+ * to '-1' because of the decrement after outputting
* the decimal point above (the exponent required is
* *not* -1!)
*/
@@ -3008,7 +3050,7 @@
{
/* The following only happens if we didn't output the
* leading zeros above for negative exponent, so this
- * doest add to the digit requirement. Note that the
+ * doesn't add to the digit requirement. Note that the
* two zeros here can only be output if the two leading
* zeros were *not* output, so this doesn't increase
* the output count.
@@ -3061,7 +3103,7 @@
/* Need another size check here for the exponent digits, so
* this need not be considered above.
*/
- if ((int)size > cdigits)
+ if (size > cdigits)
{
while (cdigits > 0) *ascii++ = exponent[--cdigits];
@@ -3109,7 +3151,7 @@
/* Avoid overflow here on the minimum integer. */
if (fp < 0)
- *ascii++ = 45, --size, num = -fp;
+ *ascii++ = 45, num = -fp;
else
num = fp;
@@ -3165,7 +3207,7 @@
png_error(png_ptr, "ASCII conversion buffer too small");
}
# endif /* FIXED_POINT */
-#endif /* READ_SCAL */
+#endif /* SCAL */
#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
!defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \
@@ -3183,7 +3225,7 @@
png_fixed_error(png_ptr, text);
# ifndef PNG_ERROR_TEXT_SUPPORTED
- PNG_UNUSED(text)
+ PNG_UNUSED(text)
# endif
return (png_fixed_point)r;
@@ -3295,11 +3337,12 @@
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;
@@ -3323,7 +3366,7 @@
{
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");
@@ -3344,7 +3387,7 @@
#else
png_fixed_point res;
- if (png_muldiv(&res, 100000, 100000, a))
+ if (png_muldiv(&res, 100000, 100000, a) != 0)
return res;
#endif
@@ -3363,29 +3406,29 @@
#endif
#ifdef PNG_READ_GAMMA_SUPPORTED
-# ifdef PNG_16BIT_SUPPORTED
+#ifdef PNG_16BIT_SUPPORTED
/* A local convenience routine. */
static png_fixed_point
png_product2(png_fixed_point a, png_fixed_point b)
{
/* The required result is 1/a * 1/b; the following preserves accuracy. */
-# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
+#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
double r = a * 1E-5;
r *= b;
r = floor(r+.5);
if (r <= 2147483647. && r >= -2147483648.)
return (png_fixed_point)r;
-# else
+#else
png_fixed_point res;
- if (png_muldiv(&res, a, b, 100000))
+ if (png_muldiv(&res, a, b, 100000) != 0)
return res;
-# endif
+#endif
return 0; /* overflow */
}
-# endif /* 16BIT */
+#endif /* 16BIT */
/* The inverse of the above. */
png_fixed_point
@@ -3393,12 +3436,15 @@
{
/* The required result is 1/a * 1/b; the following preserves accuracy. */
#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
- double r = 1E15/a;
- r /= b;
- r = floor(r+.5);
+ if (a != 0 && b != 0)
+ {
+ double r = 1E15/a;
+ r /= b;
+ r = floor(r+.5);
- if (r <= 2147483647. && r >= -2147483648.)
- return (png_fixed_point)r;
+ if (r <= 2147483647. && r >= -2147483648.)
+ return (png_fixed_point)r;
+ }
#else
/* This may overflow because the range of png_fixed_point isn't symmetric,
* but this API is only used for the product of file and screen gamma so it
@@ -3537,6 +3583,7 @@
* Zero (257): 0
* End (258): 23499
*/
+#ifdef PNG_16BIT_SUPPORTED
static png_int_32
png_log16bit(png_uint_32 x)
{
@@ -3587,14 +3634,15 @@
/* 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.
*
@@ -3634,7 +3682,7 @@
if (x > 0 && x <= 0xfffff) /* Else overflow or zero (underflow) */
{
/* Obtain a 4-bit approximation */
- png_uint_32 e = png_32bit_exp[(x >> 12) & 0xf];
+ png_uint_32 e = png_32bit_exp[(x >> 12) & 0x0f];
/* Incorporate the low 12 bits - these decrease the returned value by
* multiplying by a number less than 1 if the bit is set. The multiplier
@@ -3682,12 +3730,12 @@
/* 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.
*/
x -= x >> 8;
- return (png_byte)((x + 0x7fffffU) >> 24);
+ return (png_byte)(((x + 0x7fffffU) >> 24) & 0xff);
}
#ifdef PNG_16BIT_SUPPORTED
@@ -3710,13 +3758,37 @@
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. */
@@ -3724,7 +3796,7 @@
# endif
}
- return (png_byte)value;
+ return (png_byte)(value & 0xff);
}
#ifdef PNG_16BIT_SUPPORTED
@@ -3734,13 +3806,19 @@
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. */
@@ -3788,6 +3866,12 @@
{
/* 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;
@@ -3803,7 +3887,7 @@
/* 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
@@ -3819,10 +3903,13 @@
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);
@@ -3838,7 +3925,7 @@
{
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;
@@ -3864,7 +3951,7 @@
/* '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,
@@ -3916,7 +4003,7 @@
/* 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,
@@ -3925,11 +4012,13 @@
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 & 0xff);
}
/* Used from png_read_destroy and below to release the memory used by the gamma
@@ -4021,7 +4110,7 @@
#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));
@@ -4037,7 +4126,7 @@
{
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;
@@ -4057,7 +4146,7 @@
* 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:
*
@@ -4069,12 +4158,13 @@
*
*/
if (sig_bit > 0 && sig_bit < 16U)
- shift = (png_byte)(16U - sig_bit); /* shift == insignificant bits */
+ /* shift == insignificant bits */
+ shift = (png_byte)((16U - sig_bit) & 0xff);
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
@@ -4094,7 +4184,7 @@
* 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);
@@ -4107,7 +4197,7 @@
#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));
@@ -4126,7 +4216,7 @@
}
#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)
@@ -4138,7 +4228,7 @@
int setting = (2 + (onoff != 0)) << option;
int current = png_ptr->options;
- png_ptr->options = (png_byte)((current & ~mask) | setting);
+ png_ptr->options = (png_byte)(((current & ~mask) | setting) & 0xff);
return (current & mask) >> option;
}
@@ -4154,7 +4244,7 @@
* contrib/tools/makesRGB.c. The actual sRGB transfer curve defined in the
* specification (see the article at http://en.wikipedia.org/wiki/SRGB)
* is used, not the gamma=1/2.2 approximation use elsewhere in libpng.
- * The sRGB to linear table is exact (to the nearest 16 bit linear fraction).
+ * The sRGB to linear table is exact (to the nearest 16-bit linear fraction).
* The inverse (linear to sRGB) table has accuracies as follows:
*
* For all possible (255*65535+1) input values:
@@ -4165,7 +4255,7 @@
*
* 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
@@ -4205,8 +4295,7 @@
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.)
@@ -4334,7 +4423,7 @@
/* 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;
@@ -4358,7 +4447,7 @@
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);
@@ -4406,4 +4495,4 @@
}
#endif /* SIMPLIFIED READ/WRITE */
-#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
+#endif /* READ || WRITE */