summaryrefslogtreecommitdiff
path: root/third_party/libpng16
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libpng16')
-rw-r--r--third_party/libpng16/0003-check-errors-in-set-pcal.patch47
-rw-r--r--third_party/libpng16/0004-invalid-icc.patch81
-rw-r--r--third_party/libpng16/LICENSE135
-rw-r--r--third_party/libpng16/README.pdfium8
-rw-r--r--third_party/libpng16/arm/filter_neon.S6
-rw-r--r--third_party/libpng16/arm/palette_neon_intrinsics.c137
-rw-r--r--third_party/libpng16/contrib/intel/INSTALL158
-rw-r--r--third_party/libpng16/contrib/intel/intel_sse.patch164
-rw-r--r--third_party/libpng16/intel/filter_sse2_intrinsics.c (renamed from third_party/libpng16/contrib/intel/filter_sse2_intrinsics.c)123
-rw-r--r--third_party/libpng16/intel/intel_init.c (renamed from third_party/libpng16/contrib/intel/intel_init.c)11
-rw-r--r--third_party/libpng16/png.c627
-rw-r--r--third_party/libpng16/png.h213
-rw-r--r--third_party/libpng16/pngconf.h50
-rw-r--r--third_party/libpng16/pngerror.c72
-rw-r--r--third_party/libpng16/pngget.c87
-rw-r--r--third_party/libpng16/pnginfo.h8
-rw-r--r--third_party/libpng16/pnglibconf.h138
-rw-r--r--third_party/libpng16/pngmem.c22
-rw-r--r--third_party/libpng16/pngpread.c37
-rw-r--r--third_party/libpng16/pngprefix.h447
-rw-r--r--third_party/libpng16/pngpriv.h390
-rw-r--r--third_party/libpng16/pngread.c347
-rw-r--r--third_party/libpng16/pngrio.c6
-rw-r--r--third_party/libpng16/pngrtran.c159
-rw-r--r--third_party/libpng16/pngrutil.c538
-rw-r--r--third_party/libpng16/pngset.c252
-rw-r--r--third_party/libpng16/pngstruct.h14
-rw-r--r--third_party/libpng16/pngtrans.c51
-rw-r--r--third_party/libpng16/pngwio.c6
-rw-r--r--third_party/libpng16/pngwrite.c173
-rw-r--r--third_party/libpng16/pngwtran.c10
31 files changed, 2723 insertions, 1794 deletions
diff --git a/third_party/libpng16/0003-check-errors-in-set-pcal.patch b/third_party/libpng16/0003-check-errors-in-set-pcal.patch
deleted file mode 100644
index 58e27ba623..0000000000
--- a/third_party/libpng16/0003-check-errors-in-set-pcal.patch
+++ /dev/null
@@ -1,47 +0,0 @@
-diff --git a/pngset.c b/pngset.c
-index cccd9cd..83d6ce2 100644
---- a/pngset.c
-+++ b/pngset.c
-@@ -283,17 +283,29 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforpinfo_ptr,
-
- /* Check that the type matches the specification. */
- if (type < 0 || type > 3)
-- png_error(png_ptr, "Invalid pCAL equation type");
-+ {
-+ png_chunk_report(png_ptr, "Invalid pCAL equation type",
-+ PNG_CHUNK_WRITE_ERROR);
-+ return;
-+ }
-
- if (nparams < 0 || nparams > 255)
-- png_error(png_ptr, "Invalid pCAL parameter count");
-+ {
-+ png_chunk_report(png_ptr, "Invalid pCAL parameter count",
-+ PNG_CHUNK_WRITE_ERROR);
-+ return;
-+ }
-
- /* Validate params[nparams] */
- for (i=0; i<nparams; ++i)
- {
- if (params[i] == NULL ||
- !png_check_fp_string(params[i], strlen(params[i])))
-- png_error(png_ptr, "Invalid format for pCAL parameter");
-+ {
-+ png_chunk_report(png_ptr, "Invalid format for pCAL parameter",
-+ PNG_CHUNK_WRITE_ERROR);
-+ return;
-+ }
- }
-
- info_ptr->pcal_purpose = png_voidcast(png_charp,
-@@ -301,8 +313,8 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforpinfo_ptr,
-
- if (info_ptr->pcal_purpose == NULL)
- {
-- png_warning(png_ptr, "Insufficient memory for pCAL purpose");
--
-+ png_chunk_report(png_ptr, "Insufficient memory for pCAL purpose",
-+ PNG_CHUNK_WRITE_ERROR);
- return;
- }
diff --git a/third_party/libpng16/0004-invalid-icc.patch b/third_party/libpng16/0004-invalid-icc.patch
deleted file mode 100644
index 0052c8e0f7..0000000000
--- a/third_party/libpng16/0004-invalid-icc.patch
+++ /dev/null
@@ -1,81 +0,0 @@
-diff --git a/png.c b/png.c
-index 35e14f63d..01d8d9bae 100644
---- a/png.c
-+++ b/png.c
-@@ -1931,8 +1931,8 @@ png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
- static const png_byte D50_nCIEXYZ[12] =
- { 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d };
-
--int /* PRIVATE */
--png_icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace,
-+static int /* bool */
-+icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace,
- png_const_charp name, png_uint_32 profile_length)
- {
- if (profile_length < 132)
-@@ -1942,6 +1942,40 @@ png_icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace,
- return 1;
- }
-
-+#ifdef PNG_READ_iCCP_SUPPORTED
-+int /* PRIVATE */
-+png_icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace,
-+ png_const_charp name, png_uint_32 profile_length)
-+{
-+ if (!icc_check_length(png_ptr, colorspace, name, profile_length))
-+ return 0;
-+
-+ /* This needs to be here because the 'normal' check is in
-+ * png_decompress_chunk, yet this happens after the attempt to
-+ * png_malloc_base the required data. We only need this on read; on write
-+ * the caller supplies the profile buffer so libpng doesn't allocate it. See
-+ * the call to icc_check_length below (the write case).
-+ */
-+# ifdef PNG_SET_USER_LIMITS_SUPPORTED
-+ else if (png_ptr->user_chunk_malloc_max > 0 &&
-+ png_ptr->user_chunk_malloc_max < profile_length)
-+ return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
-+ "exceeds application limits");
-+# elif PNG_USER_CHUNK_MALLOC_MAX > 0
-+ else if (PNG_USER_CHUNK_MALLOC_MAX < profile_length)
-+ return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
-+ "exceeds libpng limits");
-+# else /* !SET_USER_LIMITS */
-+ /* This will get compiled out on all 32-bit and better systems. */
-+ else if (PNG_SIZE_MAX < profile_length)
-+ return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
-+ "exceeds system limits");
-+# endif /* !SET_USER_LIMITS */
-+
-+ return 1;
-+}
-+#endif /* READ_iCCP */
-+
- int /* PRIVATE */
- png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
- png_const_charp name, png_uint_32 profile_length,
-@@ -2379,7 +2413,7 @@ png_colorspace_set_ICC(png_const_structrp png_ptr, png_colorspacerp colorspace,
- if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)
- return 0;
-
-- if (png_icc_check_length(png_ptr, colorspace, name, profile_length) != 0 &&
-+ if (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,
-diff --git a/pngpriv.h b/pngpriv.h
-index 9ea023fea..633671352 100644
---- a/pngpriv.h
-+++ b/pngpriv.h
-@@ -1541,9 +1541,11 @@ PNG_INTERNAL_FUNCTION(int,png_colorspace_set_ICC,(png_const_structrp png_ptr,
- /* The 'name' is used for information only */
-
- /* Routines for checking parts of an ICC profile. */
-+#ifdef PNG_READ_iCCP_SUPPORTED
- PNG_INTERNAL_FUNCTION(int,png_icc_check_length,(png_const_structrp png_ptr,
- png_colorspacerp colorspace, png_const_charp name,
- png_uint_32 profile_length), PNG_EMPTY);
-+#endif /* READ_iCCP */
- PNG_INTERNAL_FUNCTION(int,png_icc_check_header,(png_const_structrp png_ptr,
- png_colorspacerp colorspace, png_const_charp name,
- png_uint_32 profile_length,
diff --git a/third_party/libpng16/LICENSE b/third_party/libpng16/LICENSE
new file mode 100644
index 0000000000..c1d22b1f4e
--- /dev/null
+++ b/third_party/libpng16/LICENSE
@@ -0,0 +1,135 @@
+
+This copy of the libpng notices is provided for your convenience. In case of
+any discrepancy between this copy and the notices in the file png.h that is
+included in the libpng distribution, the latter shall prevail.
+
+COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
+
+If you modify libpng you may insert additional notices immediately following
+this sentence.
+
+Using custom versions of pnglibconf.h and pngprefix.h for Chrome.
+
+This code is released under the libpng license.
+
+libpng versions 1.0.7, July 1, 2000 through 1.6.34, September 29, 2017 are
+Copyright (c) 2000-2002, 2004, 2006-2017 Glenn Randers-Pehrson, are
+derived from libpng-1.0.6, and are distributed according to the same
+disclaimer and license as libpng-1.0.6 with the following individuals
+added to the list of Contributing Authors:
+
+ Simon-Pierre Cadieux
+ Eric S. Raymond
+ Mans Rullgard
+ Cosmin Truta
+ Gilles Vollant
+ James Yu
+ Mandar Sahastrabuddhe
+ Google Inc.
+ Vadim Barkov
+
+and with the following additions to the disclaimer:
+
+ There is no warranty against interference with your enjoyment of the
+ library or against infringement. There is no warranty that our
+ efforts or the library will fulfill any of your particular purposes
+ or needs. This library is provided with all faults, and the entire
+ risk of satisfactory quality, performance, accuracy, and effort is with
+ the user.
+
+Some files in the "contrib" directory and some configure-generated
+files that are distributed with libpng have other copyright owners and
+are released under other open source licenses.
+
+libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
+Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
+libpng-0.96, and are distributed according to the same disclaimer and
+license as libpng-0.96, with the following individuals added to the list
+of Contributing Authors:
+
+ Tom Lane
+ Glenn Randers-Pehrson
+ Willem van Schaik
+
+libpng versions 0.89, June 1996, through 0.96, May 1997, are
+Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
+and are distributed according to the same disclaimer and license as
+libpng-0.88, with the following individuals added to the list of
+Contributing Authors:
+
+ John Bowler
+ Kevin Bracey
+ Sam Bushell
+ Magnus Holmgren
+ Greg Roelofs
+ Tom Tanner
+
+Some files in the "scripts" directory have other copyright owners
+but are released under this license.
+
+libpng versions 0.5, May 1995, through 0.88, January 1996, are
+Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
+
+For the purposes of this copyright and license, "Contributing Authors"
+is defined as the following set of individuals:
+
+ Andreas Dilger
+ Dave Martindale
+ Guy Eric Schalnat
+ Paul Schmidt
+ Tim Wegner
+
+The PNG Reference Library is supplied "AS IS". The Contributing Authors
+and Group 42, Inc. disclaim all warranties, expressed or implied,
+including, without limitation, the warranties of merchantability and of
+fitness for any purpose. The Contributing Authors and Group 42, Inc.
+assume no liability for direct, indirect, incidental, special, exemplary,
+or consequential damages, which may result from the use of the PNG
+Reference Library, even if advised of the possibility of such damage.
+
+Permission is hereby granted to use, copy, modify, and distribute this
+source code, or portions hereof, for any purpose, without fee, subject
+to the following restrictions:
+
+ 1. The origin of this source code must not be misrepresented.
+
+ 2. Altered versions must be plainly marked as such and must not
+ be misrepresented as being the original source.
+
+ 3. This Copyright notice may not be removed or altered from any
+ source or altered source distribution.
+
+The Contributing Authors and Group 42, Inc. specifically permit, without
+fee, and encourage the use of this source code as a component to
+supporting the PNG file format in commercial products. If you use this
+source code in a product, acknowledgment is not required but would be
+appreciated.
+
+END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.
+
+TRADEMARK:
+
+The name "libpng" has not been registered by the Copyright owner
+as a trademark in any jurisdiction. However, because libpng has
+been distributed and maintained world-wide, continually since 1995,
+the Copyright owner claims "common-law trademark protection" in any
+jurisdiction where common-law trademark is recognized.
+
+OSI CERTIFICATION:
+
+Libpng is OSI Certified Open Source Software. OSI Certified Open Source is
+a certification mark of the Open Source Initiative. OSI has not addressed
+the additional disclaimers inserted at version 1.0.7.
+
+EXPORT CONTROL:
+
+The Copyright owner believes that the Export Control Classification
+Number (ECCN) for libpng is EAR99, which means not subject to export
+controls or International Traffic in Arms Regulations (ITAR) because
+it is open source, publicly available software, that does not contain
+any encryption software. See the EAR, paragraphs 734.3(b)(3) and
+734.7(b).
+
+Glenn Randers-Pehrson
+glennrp at users.sourceforge.net
+September 29, 2017
diff --git a/third_party/libpng16/README.pdfium b/third_party/libpng16/README.pdfium
index faa59590c8..21ce2fdf13 100644
--- a/third_party/libpng16/README.pdfium
+++ b/third_party/libpng16/README.pdfium
@@ -1,6 +1,6 @@
Name: libpng
URL: http://libpng.org/
-Version: 1.6.22
+Version: 1.6.34
Security Critical: yes
License: libpng license
License Android Compatible: yes
@@ -10,12 +10,10 @@ PNG library.
Local Modifications:
-Local changes in Chromium's copy of libpng as of https://crrev.com/404379 - see
-README.chromium.
+Local changes in Chromium's copy of libpng as of
+e87a02987101e2dbe319a4aba6b52470f7624b4a - see README.chromium.
pnglibconf.h: a copy of libpng's scripts/pnglibconf.h.prebuilt.
pngprefix.h: manually-created redefinitions to avoid conflicts with Chromium.
0000-build-config.patch: Local build configuration changes.
0002-static-png-gt.patch: Unconditionally use static png_gt() in png.c to avoid compilation warning.
-0003-check-errors-in-set-pcal.patch: Backported github.com/glennrp/libpng/pull/135
-0004-invalid-icc.patch: Fix for large allocation for invalid ICC https://github.com/glennrp/libpng/commit/92a7c79db2c962d04006b35e2603ba9d5ce75541
diff --git a/third_party/libpng16/arm/filter_neon.S b/third_party/libpng16/arm/filter_neon.S
index 3b061d6bbf..000764cd21 100644
--- a/third_party/libpng16/arm/filter_neon.S
+++ b/third_party/libpng16/arm/filter_neon.S
@@ -1,9 +1,9 @@
/* filter_neon.S - NEON optimised filter functions
*
- * Copyright (c) 2014 Glenn Randers-Pehrson
+ * Copyright (c) 2014,2017 Glenn Randers-Pehrson
* Written by Mans Rullgard, 2011.
- * Last changed in libpng 1.6.16 [December 22, 2014]
+ * Last changed in libpng 1.6.31 [July 27, 2017]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@@ -16,7 +16,7 @@
#define PNG_VERSION_INFO_ONLY
#include "../pngpriv.h"
-#if defined(__linux__) && defined(__ELF__)
+#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits /* mark stack as non-executable */
#endif
diff --git a/third_party/libpng16/arm/palette_neon_intrinsics.c b/third_party/libpng16/arm/palette_neon_intrinsics.c
new file mode 100644
index 0000000000..703b9ff250
--- /dev/null
+++ b/third_party/libpng16/arm/palette_neon_intrinsics.c
@@ -0,0 +1,137 @@
+/* palette_neon_intrinsics.c - NEON optimised palette expansion functions
+ *
+ * Copyright (c) 2017 The Chromium Authors. All rights reserved.
+ * Written by Richard Townsend <Richard.Townsend@arm.com>, February 2017.
+ *
+ * This code is released under the libpng license.
+ * For conditions of distribution and use, see the disclaimer
+ * and license in png.h
+ */
+
+#include "../pngpriv.h"
+
+#if PNG_ARM_NEON_IMPLEMENTATION == 1
+
+#include <arm_neon.h>
+
+/* Build an RGBA palette from the RGB and separate alpha palettes. */
+void
+png_riffle_palette_rgba(png_structrp png_ptr, png_row_infop row_info)
+{
+ png_const_colorp palette = png_ptr->palette;
+ png_bytep riffled_palette = png_ptr->riffled_palette;
+ png_const_bytep trans_alpha = png_ptr->trans_alpha;
+ int num_trans = png_ptr->num_trans;
+
+ if (row_info->bit_depth != 8) {
+ png_error(png_ptr, "bit_depth must be 8 for png_riffle_palette_rgba");
+ return;
+ }
+
+ /* Initially black, opaque. */
+ uint8x16x4_t w = {{
+ vdupq_n_u8(0x00),
+ vdupq_n_u8(0x00),
+ vdupq_n_u8(0x00),
+ vdupq_n_u8(0xff),
+ }};
+
+ int i;
+ /* First, riffle the RGB colours into a RGBA palette, the A value is
+ * set to opaque for now. */
+ for (i = 0; i < (1 << row_info->bit_depth); i += 16) {
+ uint8x16x3_t v = vld3q_u8((png_const_bytep)(palette + i));
+ w.val[0] = v.val[0];
+ w.val[1] = v.val[1];
+ w.val[2] = v.val[2];
+ vst4q_u8(riffled_palette + (i << 2), w);
+ }
+
+ /* Fix up the missing transparency values. */
+ for (i = 0; i < num_trans; i++) {
+ riffled_palette[(i << 2) + 3] = trans_alpha[i];
+ }
+}
+
+
+/* Expands a palettized row into RGBA. */
+int
+png_do_expand_palette_neon_rgba(png_structrp png_ptr, png_row_infop row_info,
+ png_const_bytep row, const png_bytepp ssp, const png_bytepp ddp)
+{
+
+ png_uint_32 row_width = row_info->width;
+ const png_uint_32 *riffled_palette = (const png_uint_32*)png_ptr->riffled_palette;
+ const png_int_32 pixels_per_chunk = 4;
+
+ if (row_width < pixels_per_chunk) {
+ return 0;
+ }
+
+ /* This function originally gets the last byte of the output row.
+ The NEON part writes forward from a given position, so we have
+ to seek this back by 4 pixels x 4 bytes. */
+ *ddp = *ddp - ((pixels_per_chunk * sizeof(png_uint_32)) - 1);
+
+ int i;
+ for (i = 0; i < row_width; i += pixels_per_chunk) {
+ uint32x4_t cur;
+ png_bytep sp = *ssp - i, dp = *ddp - (i << 2);
+ cur = vld1q_dup_u32 (riffled_palette + *(sp - 3));
+ cur = vld1q_lane_u32(riffled_palette + *(sp - 2), cur, 1);
+ cur = vld1q_lane_u32(riffled_palette + *(sp - 1), cur, 2);
+ cur = vld1q_lane_u32(riffled_palette + *(sp - 0), cur, 3);
+ vst1q_u32((void *)dp, cur);
+ }
+ if (i != row_width) {
+ i -= pixels_per_chunk; /* Remove the amount that wasn't processed. */
+ }
+
+ /* Decrement output pointers. */
+ *ssp = *ssp - i;
+ *ddp = *ddp - (i << 2);
+ return i;
+}
+
+/* Expands a palettized row into RGB format. */
+int
+png_do_expand_palette_neon_rgb(png_structrp png_ptr, png_row_infop row_info,
+ png_const_bytep row, const png_bytepp ssp, const png_bytepp ddp)
+{
+ png_uint_32 row_width = row_info->width;
+ png_const_bytep palette = (png_const_bytep)png_ptr->palette;
+ const png_uint_32 pixels_per_chunk = 8;
+
+ if (row_width <= pixels_per_chunk) {
+ return 0;
+ }
+
+ /* Seeking this back by 8 pixels x 3 bytes. */
+ *ddp = *ddp - ((pixels_per_chunk * sizeof(png_color)) - 1);
+
+ int i;
+ for (i = 0; i < row_width; i += pixels_per_chunk) {
+ uint8x8x3_t cur;
+ png_bytep sp = *ssp - i, dp = *ddp - ((i << 1) + i);
+ cur = vld3_dup_u8(palette + sizeof(png_color) * (*(sp - 7)));
+ cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 6)), cur, 1);
+ cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 5)), cur, 2);
+ cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 4)), cur, 3);
+ cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 3)), cur, 4);
+ cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 2)), cur, 5);
+ cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 1)), cur, 6);
+ cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 0)), cur, 7);
+ vst3_u8((void *)dp, cur);
+ }
+
+ if (i != row_width) {
+ i -= pixels_per_chunk; /* Remove the amount that wasn't processed. */
+ }
+
+ /* Decrement output pointers. */
+ *ssp = *ssp - i;
+ *ddp = *ddp - ((i << 1) + i);
+ return i;
+}
+
+#endif /* PNG_ARM_NEON_IMPLEMENTATION */
diff --git a/third_party/libpng16/contrib/intel/INSTALL b/third_party/libpng16/contrib/intel/INSTALL
deleted file mode 100644
index cd5cdd94eb..0000000000
--- a/third_party/libpng16/contrib/intel/INSTALL
+++ /dev/null
@@ -1,158 +0,0 @@
-Enabling SSE support
-
-Copyright (c) 2016 Google, Inc.
-Written by Mike Klein, Matt Sarett
-
-This INSTALL file written by Glenn Randers-Pehrson, 2016.
-
-If you have moved intel_init.c and filter_sse2_intrinsics.c to a different
-directory, be sure to update the '#include "../../pngpriv.h"' line in both
-files if necessary to point to the correct relative location of pngpriv.h
-with respect to the new location of those files.
-
-To enable SSE support in libpng, follow the instructions in I, II, or III,
-below:
-
-I. Using patched "configure" scripts:
-
-First, apply intel_sse.patch in your build directory.
-
- patch -i contrib/intel/intel_sse.patch -p1
-
-Then, if you are not building in a new GIT clone, e.g., in a tar
-distribution, remove any existing pre-built configure scripts:
-
- ./configure --enable-maintainer-mode
- make maintainer-clean
- ./autogen.sh --maintainer --clean
-
-Finally, configure libpng with -DPNG_INTEL_SSE in CPPFLAGS:
-
- ./autogen.sh --maintainer
- CPPFLAGS="-DPNG_INTEL_SSE" ./configure [options]
- make CPPFLAGS="-DPNG_INTEL_SSE" [options]
- make
-
-II. Using a custom makefile:
-
-If you are using a custom makefile makefile, you will have to update it
-manually to include contrib/intel/*.o in the dependencies, and to define
-PNG_INTEL_SSE.
-
-III. Using manually updated "configure" scripts:
-
-If you prefer, manually edit pngpriv.h, configure.ac, and Makefile.am,
-following the instructions below, then follow the instructions in
-section II of INSTALL in the main libpng directory, then configure libpng
-with -DPNG_INTEL_SSE in CPPFLAGS.
-
-1. Add the following code to configure.ac under HOST SPECIFIC OPTIONS
-directly beneath the section for ARM:
-
------------------cut----------------
-# INTEL
-# =====
-#
-# INTEL SSE (SIMD) support.
-
-AC_ARG_ENABLE([intel-sse],
- AS_HELP_STRING([[[--enable-intel-sse]]],
- [Enable Intel SSE optimizations: =no/off, yes/on:]
- [no/off: disable the optimizations;]
- [yes/on: enable the optimizations.]
- [If not specified: determined by the compiler.]),
- [case "$enableval" in
- no|off)
- # disable the default enabling:
- AC_DEFINE([PNG_INTEL_SSE_OPT], [0],
- [Disable Intel SSE optimizations])
- # Prevent inclusion of the assembler files below:
- enable_intel_sse=no;;
- yes|on)
- AC_DEFINE([PNG_INTEL_SSE_OPT], [1],
- [Enable Intel SSE optimizations]);;
- *)
- AC_MSG_ERROR([--enable-intel-sse=${enable_intel_sse}: invalid value])
- esac])
-
-# Add Intel specific files to all builds where the host_cpu is Intel ('x86*')
-# or where Intel optimizations were explicitly requested (this allows a
-# fallback if a future host CPU does not match 'x86*')
-AM_CONDITIONAL([PNG_INTEL_SSE],
- [test "$enable_intel_sse" != 'no' &&
- case "$host_cpu" in
- i?86|x86_64) :;;
- *) test "$enable_intel_sse" != '';;
- esac])
------------------cut----------------
-
-2. Add the following code to Makefile.am under HOST SPECIFIC OPTIONS
-directly beneath the "if PNG_ARM_NEON ... endif" statement:
-
------------------cut----------------
-if PNG_INTEL_SSE
-libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += contrib/intel/intel_init.c\
- contrib/intel/filter_sse2_intrinsics.c
-endif
------------------cut----------------
-
-3. Add the following lines to pngpriv.h, following the PNG_ARM_NEON_OPT
-code:
-
------------------cut----------------
-#ifndef PNG_INTEL_SSE_OPT
-# ifdef PNG_INTEL_SSE
- /* Only check for SSE if the build configuration has been modified to
- * enable SSE optimizations. This means that these optimizations will
- * be off by default. See contrib/intel for more details.
- */
-# if defined(__SSE4_1__) || defined(__AVX__) || defined(__SSSE3__) || \
- defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \
- (defined(_M_IX86_FP) && _M_IX86_FP >= 2)
-# define PNG_INTEL_SSE_OPT 1
-# endif
-# endif
-#endif
-
-#if PNG_INTEL_SSE_OPT > 0
-# ifndef PNG_INTEL_SSE_IMPLEMENTATION
-# if defined(__SSE4_1__) || defined(__AVX__)
- /* We are not actually using AVX, but checking for AVX is the best
- way we can detect SSE4.1 and SSSE3 on MSVC.
- */
-# define PNG_INTEL_SSE_IMPLEMENTATION 3
-# elif defined(__SSSE3__)
-# define PNG_INTEL_SSE_IMPLEMENTATION 2
-# elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \
- (defined(_M_IX86_FP) && _M_IX86_FP >= 2)
-# define PNG_INTEL_SSE_IMPLEMENTATION 1
-# else
-# define PNG_INTEL_SSE_IMPLEMENTATION 0
-# endif
-# endif
-
-# if PNG_INTEL_SSE_IMPLEMENTATION > 0
-# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_sse2
-# endif
-#endif
-
------------------cut----------------
-
-4. Add the following lines to pngpriv.h, following the prototype for
-png_read_filter_row_paeth4_neon:
-
------------------cut----------------
-PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_sse2,(png_row_infop
- row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_sse2,(png_row_infop
- row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_sse2,(png_row_infop
- row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_sse2,(png_row_infop
- row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_sse2,(png_row_infop
- row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_sse2,(png_row_infop
- row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-
------------------cut----------------
diff --git a/third_party/libpng16/contrib/intel/intel_sse.patch b/third_party/libpng16/contrib/intel/intel_sse.patch
deleted file mode 100644
index d9d02bb8fc..0000000000
--- a/third_party/libpng16/contrib/intel/intel_sse.patch
+++ /dev/null
@@ -1,164 +0,0 @@
-diff --git libpng-1.6.22-orig/configure.ac libpng-1.6.22/configure.ac
---- libpng-1.6.22-orig/configure.ac 2016-05-25 18:59:10.000000000 -0400
-+++ libpng-1.6.22/configure.ac 2016-05-25 19:48:10.631751170 -0400
-@@ -341,16 +341,50 @@ AC_ARG_ENABLE([arm-neon],
-
- AM_CONDITIONAL([PNG_ARM_NEON],
- [test "$enable_arm_neon" != 'no' &&
- case "$host_cpu" in
- arm*|aarch64*) :;;
- *) test "$enable_arm_neon" != '';;
- esac])
-
-+# INTEL
-+# =====
-+#
-+# INTEL SSE (SIMD) support.
-+
-+AC_ARG_ENABLE([intel-sse],
-+ AS_HELP_STRING([[[--enable-intel-sse]]],
-+ [Enable Intel SSE optimizations: =no/off, yes/on:]
-+ [no/off: disable the optimizations;]
-+ [yes/on: enable the optimizations.]
-+ [If not specified: determined by the compiler.]),
-+ [case "$enableval" in
-+ no|off)
-+ # disable the default enabling:
-+ AC_DEFINE([PNG_INTEL_SSE_OPT], [0],
-+ [Disable Intel SSE optimizations])
-+ # Prevent inclusion of the assembler files below:
-+ enable_intel_sse=no;;
-+ yes|on)
-+ AC_DEFINE([PNG_INTEL_SSE_OPT], [1],
-+ [Enable Intel SSE optimizations]);;
-+ *)
-+ AC_MSG_ERROR([--enable-intel-sse=${enable_intel_sse}: invalid value])
-+ esac])
-+
-+# Add Intel specific files to all builds where the host_cpu is Intel ('x86*')
-+# or where Intel optimizations were explicitly requested (this allows a
-+# fallback if a future host CPU does not match 'x86*')
-+AM_CONDITIONAL([PNG_INTEL_SSE],
-+ [test "$enable_intel_sse" != 'no' &&
-+ case "$host_cpu" in
-+ i?86|x86_64) :;;
-+ *) test "$enable_intel_sse" != '';;
-+ esac])
- AC_MSG_NOTICE([[Extra options for compiler: $PNG_COPTS]])
-
- # Config files, substituting as above
- AC_CONFIG_FILES([Makefile libpng.pc:libpng.pc.in])
- AC_CONFIG_FILES([libpng-config:libpng-config.in],
- [chmod +x libpng-config])
-
- AC_OUTPUT
-diff --git libpng-1.6.22-orig/Makefile.am libpng-1.6.22/Makefile.am
---- libpng-1.6.22-orig/Makefile.am 2016-05-17 18:15:12.000000000 -0400
-+++ libpng-1.6.22/Makefile.am 2016-05-25 19:48:10.631751170 -0400
-@@ -89,16 +89,20 @@ libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SO
- pngset.c pngtrans.c pngwio.c pngwrite.c pngwtran.c pngwutil.c\
- png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h pngusr.dfa
-
- if PNG_ARM_NEON
- libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += arm/arm_init.c\
- arm/filter_neon.S arm/filter_neon_intrinsics.c
- endif
-
-+if PNG_INTEL_SSE
-+libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += contrib/intel/intel_init.c\
-+ contrib/intel/filter_sse2_intrinsics.c
-+endif
- nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = pnglibconf.h
-
- libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS = -no-undefined -export-dynamic \
- -version-number @PNGLIB_MAJOR@@PNGLIB_MINOR@:@PNGLIB_RELEASE@:0
-
- if HAVE_LD_VERSION_SCRIPT
- # Versioned symbols and restricted exports
- if HAVE_SOLARIS_LD
-diff --git libpng-1.6.22-orig/pngpriv.h libpng-1.6.22/pngpriv.h
---- libpng-1.6.22-orig/pngpriv.h 2016-05-25 18:59:10.000000000 -0400
-+++ libpng-1.6.22/pngpriv.h 2016-05-25 19:48:10.635751171 -0400
-@@ -177,16 +177,52 @@
- # endif /* !PNG_ARM_NEON_IMPLEMENTATION */
-
- # ifndef PNG_ARM_NEON_IMPLEMENTATION
- /* Use the intrinsics code by default. */
- # define PNG_ARM_NEON_IMPLEMENTATION 1
- # endif
- #endif /* PNG_ARM_NEON_OPT > 0 */
-
-+#ifndef PNG_INTEL_SSE_OPT
-+# ifdef PNG_INTEL_SSE
-+ /* Only check for SSE if the build configuration has been modified to
-+ * enable SSE optimizations. This means that these optimizations will
-+ * be off by default. See contrib/intel for more details.
-+ */
-+# if defined(__SSE4_1__) || defined(__AVX__) || defined(__SSSE3__) || \
-+ defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \
-+ (defined(_M_IX86_FP) && _M_IX86_FP >= 2)
-+# define PNG_INTEL_SSE_OPT 1
-+# endif
-+# endif
-+#endif
-+
-+#if PNG_INTEL_SSE_OPT > 0
-+# ifndef PNG_INTEL_SSE_IMPLEMENTATION
-+# if defined(__SSE4_1__) || defined(__AVX__)
-+ /* We are not actually using AVX, but checking for AVX is the best
-+ way we can detect SSE4.1 and SSSE3 on MSVC.
-+ */
-+# define PNG_INTEL_SSE_IMPLEMENTATION 3
-+# elif defined(__SSSE3__)
-+# define PNG_INTEL_SSE_IMPLEMENTATION 2
-+# elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \
-+ (defined(_M_IX86_FP) && _M_IX86_FP >= 2)
-+# define PNG_INTEL_SSE_IMPLEMENTATION 1
-+# else
-+# define PNG_INTEL_SSE_IMPLEMENTATION 0
-+# endif
-+# endif
-+
-+# if PNG_INTEL_SSE_IMPLEMENTATION > 0
-+# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_sse2
-+# endif
-+#endif
-+
- /* Is this a build of a DLL where compilation of the object modules requires
- * different preprocessor settings to those required for a simple library? If
- * so PNG_BUILD_DLL must be set.
- *
- * If libpng is used inside a DLL but that DLL does not export the libpng APIs
- * PNG_BUILD_DLL must not be set. To avoid the code below kicking in build a
- * static library of libpng then link the DLL against that.
- */
-@@ -1184,16 +1220,29 @@ PNG_INTERNAL_FUNCTION(void,png_read_filt
- row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
- PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_neon,(png_row_infop
- row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
- PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,(png_row_infop
- row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
- PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,(png_row_infop
- row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-
-+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_sse2,(png_row_infop
-+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_sse2,(png_row_infop
-+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_sse2,(png_row_infop
-+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_sse2,(png_row_infop
-+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_sse2,(png_row_infop
-+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_sse2,(png_row_infop
-+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
-+
- /* Choose the best filter to use and filter the row data */
- PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr,
- png_row_infop row_info),PNG_EMPTY);
-
- #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
- PNG_INTERNAL_FUNCTION(void,png_read_IDAT_data,(png_structrp png_ptr,
- png_bytep output, png_alloc_size_t avail_out),PNG_EMPTY);
- /* Read 'avail_out' bytes of data from the IDAT stream. If the output buffer
diff --git a/third_party/libpng16/contrib/intel/filter_sse2_intrinsics.c b/third_party/libpng16/intel/filter_sse2_intrinsics.c
index aea3f86af5..7a7d426960 100644
--- a/third_party/libpng16/contrib/intel/filter_sse2_intrinsics.c
+++ b/third_party/libpng16/intel/filter_sse2_intrinsics.c
@@ -1,19 +1,18 @@
/* filter_sse2_intrinsics.c - SSE2 optimized filter functions
*
- * Copyright (c) 2016 Google, Inc.
+ * Copyright (c) 2016-2017 Glenn Randers-Pehrson
* Written by Mike Klein and Matt Sarett
- * Derived from arm/filter_neon_intrinsics.c, which was
- * Copyright (c) 2014,2016 Glenn Randers-Pehrson
+ * Derived from arm/filter_neon_intrinsics.c
*
- * Last changed in libpng 1.6.22 [May 26, 2016]
+ * Last changed in libpng 1.6.31 [July 27, 2017]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*/
-#include "../../pngpriv.h"
+#include "../pngpriv.h"
#ifdef PNG_READ_SUPPORTED
@@ -41,7 +40,7 @@ static __m128i load3(const void* p) {
/* We'll load 2 bytes, then 1 byte,
* then mask them together, and finally load into SSE.
*/
- const png_uint_16* p01 = p;
+ const png_uint_16* p01 = (png_const_uint_16p)p;
const png_byte* p2 = (const png_byte*)(p01+1);
png_uint_32 v012 = (png_uint_32)(*p01)
@@ -54,12 +53,15 @@ static void store3(void* p, __m128i v) {
* its bottom two bytes, then its third byte.
*/
png_uint_32 v012;
+ png_uint_16* p01;
+ png_byte* p2;
+
store4(&v012, v);
- png_uint_16* p01 = p;
- png_byte* p2 = (png_byte*)(p01+1);
- *p01 = v012;
- *p2 = v012 >> 16;
+ p01 = (png_uint_16p)p;
+ p2 = (png_byte*)(p01+1);
+ *p01 = (png_uint_16)v012;
+ *p2 = (png_byte)(v012 >> 16);
}
void png_read_filter_row_sub3_sse2(png_row_infop row_info, png_bytep row,
@@ -69,10 +71,13 @@ void png_read_filter_row_sub3_sse2(png_row_infop row_info, png_bytep row,
* There is no pixel to the left of the first pixel. It's encoded directly.
* That works with our main loop if we just say that left pixel was zero.
*/
- png_debug(1, "in png_read_filter_row_sub3_sse2");
+ png_size_t rb;
+
__m128i a, d = _mm_setzero_si128();
- int rb = row_info->rowbytes;
+ png_debug(1, "in png_read_filter_row_sub3_sse2");
+
+ rb = row_info->rowbytes;
while (rb >= 4) {
a = d; d = load4(row);
d = _mm_add_epi8(d, a);
@@ -89,6 +94,7 @@ void png_read_filter_row_sub3_sse2(png_row_infop row_info, png_bytep row,
row += 3;
rb -= 3;
}
+ PNG_UNUSED(prev)
}
void png_read_filter_row_sub4_sse2(png_row_infop row_info, png_bytep row,
@@ -98,11 +104,14 @@ void png_read_filter_row_sub4_sse2(png_row_infop row_info, png_bytep row,
* There is no pixel to the left of the first pixel. It's encoded directly.
* That works with our main loop if we just say that left pixel was zero.
*/
- png_debug(1, "in png_read_filter_row_sub4_sse2");
+ png_size_t rb;
+
__m128i a, d = _mm_setzero_si128();
- int rb = row_info->rowbytes;
- while (rb > 0) {
+ png_debug(1, "in png_read_filter_row_sub4_sse2");
+
+ rb = row_info->rowbytes+4;
+ while (rb > 4) {
a = d; d = load4(row);
d = _mm_add_epi8(d, a);
store4(row, d);
@@ -110,6 +119,7 @@ void png_read_filter_row_sub4_sse2(png_row_infop row_info, png_bytep row,
row += 4;
rb -= 4;
}
+ PNG_UNUSED(prev)
}
void png_read_filter_row_avg3_sse2(png_row_infop row_info, png_bytep row,
@@ -120,18 +130,23 @@ void png_read_filter_row_avg3_sse2(png_row_infop row_info, png_bytep row,
* predicted to be half of the pixel above it. So again, this works
* perfectly with our loop if we make sure a starts at zero.
*/
- png_debug(1, "in png_read_filter_row_avg3_sse2");
+
+ png_size_t rb;
+
const __m128i zero = _mm_setzero_si128();
+
__m128i b;
__m128i a, d = zero;
- int rb = row_info->rowbytes;
+ png_debug(1, "in png_read_filter_row_avg3_sse2");
+ rb = row_info->rowbytes;
while (rb >= 4) {
+ __m128i avg;
b = load4(prev);
a = d; d = load4(row );
/* PNG requires a truncating average, so we can't just use _mm_avg_epu8 */
- __m128i avg = _mm_avg_epu8(a,b);
+ avg = _mm_avg_epu8(a,b);
/* ...but we can fix it up by subtracting off 1 if it rounded up. */
avg = _mm_sub_epi8(avg, _mm_and_si128(_mm_xor_si128(a,b),
_mm_set1_epi8(1)));
@@ -143,11 +158,12 @@ void png_read_filter_row_avg3_sse2(png_row_infop row_info, png_bytep row,
rb -= 3;
}
if (rb > 0) {
+ __m128i avg;
b = load3(prev);
a = d; d = load3(row );
/* PNG requires a truncating average, so we can't just use _mm_avg_epu8 */
- __m128i avg = _mm_avg_epu8(a,b);
+ avg = _mm_avg_epu8(a,b);
/* ...but we can fix it up by subtracting off 1 if it rounded up. */
avg = _mm_sub_epi8(avg, _mm_and_si128(_mm_xor_si128(a,b),
_mm_set1_epi8(1)));
@@ -169,18 +185,21 @@ void png_read_filter_row_avg4_sse2(png_row_infop row_info, png_bytep row,
* predicted to be half of the pixel above it. So again, this works
* perfectly with our loop if we make sure a starts at zero.
*/
- png_debug(1, "in png_read_filter_row_avg4_sse2");
+ png_size_t rb;
const __m128i zero = _mm_setzero_si128();
__m128i b;
__m128i a, d = zero;
- int rb = row_info->rowbytes;
- while (rb > 0) {
+ png_debug(1, "in png_read_filter_row_avg4_sse2");
+
+ rb = row_info->rowbytes+4;
+ while (rb > 4) {
+ __m128i avg;
b = load4(prev);
a = d; d = load4(row );
/* PNG requires a truncating average, so we can't just use _mm_avg_epu8 */
- __m128i avg = _mm_avg_epu8(a,b);
+ avg = _mm_avg_epu8(a,b);
/* ...but we can fix it up by subtracting off 1 if it rounded up. */
avg = _mm_sub_epi8(avg, _mm_and_si128(_mm_xor_si128(a,b),
_mm_set1_epi8(1)));
@@ -208,7 +227,7 @@ static __m128i abs_i16(__m128i x) {
x = _mm_xor_si128(x, is_negative);
/* +1 to negative lanes, else +0. */
- x = _mm_add_epi16(x, _mm_srli_epi16(is_negative, 15));
+ x = _mm_sub_epi16(x, is_negative);
return x;
#endif
}
@@ -238,38 +257,42 @@ void png_read_filter_row_paeth3_sse2(png_row_infop row_info, png_bytep row,
* Here we zero b and d, which become c and a respectively at the start of
* the loop.
*/
- png_debug(1, "in png_read_filter_row_paeth3_sse2");
+ png_size_t rb;
const __m128i zero = _mm_setzero_si128();
__m128i c, b = zero,
a, d = zero;
- int rb = row_info->rowbytes;
+ png_debug(1, "in png_read_filter_row_paeth3_sse2");
+
+ rb = row_info->rowbytes;
while (rb >= 4) {
/* It's easiest to do this math (particularly, deal with pc) with 16-bit
* intermediates.
*/
+ __m128i pa,pb,pc,smallest,nearest;
c = b; b = _mm_unpacklo_epi8(load4(prev), zero);
a = d; d = _mm_unpacklo_epi8(load4(row ), zero);
/* (p-a) == (a+b-c - a) == (b-c) */
- __m128i pa = _mm_sub_epi16(b,c);
+
+ pa = _mm_sub_epi16(b,c);
/* (p-b) == (a+b-c - b) == (a-c) */
- __m128i pb = _mm_sub_epi16(a,c);
+ pb = _mm_sub_epi16(a,c);
/* (p-c) == (a+b-c - c) == (a+b-c-c) == (b-c)+(a-c) */
- __m128i pc = _mm_add_epi16(pa,pb);
+ pc = _mm_add_epi16(pa,pb);
pa = abs_i16(pa); /* |p-a| */
pb = abs_i16(pb); /* |p-b| */
pc = abs_i16(pc); /* |p-c| */
- __m128i smallest = _mm_min_epi16(pc, _mm_min_epi16(pa, pb));
+ smallest = _mm_min_epi16(pc, _mm_min_epi16(pa, pb));
/* Paeth breaks ties favoring a over b over c. */
- __m128i nearest = if_then_else(_mm_cmpeq_epi16(smallest, pa), a,
- if_then_else(_mm_cmpeq_epi16(smallest, pb), b,
- c));
+ nearest = if_then_else(_mm_cmpeq_epi16(smallest, pa), a,
+ if_then_else(_mm_cmpeq_epi16(smallest, pb), b,
+ c));
/* Note `_epi8`: we need addition to wrap modulo 255. */
d = _mm_add_epi8(d, nearest);
@@ -283,28 +306,29 @@ void png_read_filter_row_paeth3_sse2(png_row_infop row_info, png_bytep row,
/* It's easiest to do this math (particularly, deal with pc) with 16-bit
* intermediates.
*/
+ __m128i pa,pb,pc,smallest,nearest;
c = b; b = _mm_unpacklo_epi8(load3(prev), zero);
a = d; d = _mm_unpacklo_epi8(load3(row ), zero);
/* (p-a) == (a+b-c - a) == (b-c) */
- __m128i pa = _mm_sub_epi16(b,c);
+ pa = _mm_sub_epi16(b,c);
/* (p-b) == (a+b-c - b) == (a-c) */
- __m128i pb = _mm_sub_epi16(a,c);
+ pb = _mm_sub_epi16(a,c);
/* (p-c) == (a+b-c - c) == (a+b-c-c) == (b-c)+(a-c) */
- __m128i pc = _mm_add_epi16(pa,pb);
+ pc = _mm_add_epi16(pa,pb);
pa = abs_i16(pa); /* |p-a| */
pb = abs_i16(pb); /* |p-b| */
pc = abs_i16(pc); /* |p-c| */
- __m128i smallest = _mm_min_epi16(pc, _mm_min_epi16(pa, pb));
+ smallest = _mm_min_epi16(pc, _mm_min_epi16(pa, pb));
/* Paeth breaks ties favoring a over b over c. */
- __m128i nearest = if_then_else(_mm_cmpeq_epi16(smallest, pa), a,
- if_then_else(_mm_cmpeq_epi16(smallest, pb), b,
- c));
+ nearest = if_then_else(_mm_cmpeq_epi16(smallest, pa), a,
+ if_then_else(_mm_cmpeq_epi16(smallest, pb), b,
+ c));
/* Note `_epi8`: we need addition to wrap modulo 255. */
d = _mm_add_epi8(d, nearest);
@@ -332,13 +356,16 @@ void png_read_filter_row_paeth4_sse2(png_row_infop row_info, png_bytep row,
* Here we zero b and d, which become c and a respectively at the start of
* the loop.
*/
- png_debug(1, "in png_read_filter_row_paeth4_sse2");
+ png_size_t rb;
const __m128i zero = _mm_setzero_si128();
+ __m128i pa,pb,pc,smallest,nearest;
__m128i c, b = zero,
a, d = zero;
- int rb = row_info->rowbytes;
- while (rb > 0) {
+ png_debug(1, "in png_read_filter_row_paeth4_sse2");
+
+ rb = row_info->rowbytes+4;
+ while (rb > 4) {
/* It's easiest to do this math (particularly, deal with pc) with 16-bit
* intermediates.
*/
@@ -346,22 +373,22 @@ void png_read_filter_row_paeth4_sse2(png_row_infop row_info, png_bytep row,
a = d; d = _mm_unpacklo_epi8(load4(row ), zero);
/* (p-a) == (a+b-c - a) == (b-c) */
- __m128i pa = _mm_sub_epi16(b,c);
+ pa = _mm_sub_epi16(b,c);
/* (p-b) == (a+b-c - b) == (a-c) */
- __m128i pb = _mm_sub_epi16(a,c);
+ pb = _mm_sub_epi16(a,c);
/* (p-c) == (a+b-c - c) == (a+b-c-c) == (b-c)+(a-c) */
- __m128i pc = _mm_add_epi16(pa,pb);
+ pc = _mm_add_epi16(pa,pb);
pa = abs_i16(pa); /* |p-a| */
pb = abs_i16(pb); /* |p-b| */
pc = abs_i16(pc); /* |p-c| */
- __m128i smallest = _mm_min_epi16(pc, _mm_min_epi16(pa, pb));
+ smallest = _mm_min_epi16(pc, _mm_min_epi16(pa, pb));
/* Paeth breaks ties favoring a over b over c. */
- __m128i nearest = if_then_else(_mm_cmpeq_epi16(smallest, pa), a,
+ nearest = if_then_else(_mm_cmpeq_epi16(smallest, pa), a,
if_then_else(_mm_cmpeq_epi16(smallest, pb), b,
c));
diff --git a/third_party/libpng16/contrib/intel/intel_init.c b/third_party/libpng16/intel/intel_init.c
index 328e90e9af..8f08baf8c5 100644
--- a/third_party/libpng16/contrib/intel/intel_init.c
+++ b/third_party/libpng16/intel/intel_init.c
@@ -1,19 +1,18 @@
/* intel_init.c - SSE2 optimized filter functions
*
- * Copyright (c) 2016 Google, Inc.
- * Written by Mike Klein and Matt Sarett
- * Derived from arm/arm_init.c, which was
- * Copyright (c) 2014,2016 Glenn Randers-Pehrson
+ * Copyright (c) 2016-2017 Glenn Randers-Pehrson
+ * Written by Mike Klein and Matt Sarett, Google, Inc.
+ * Derived from arm/arm_init.c
*
- * Last changed in libpng 1.6.22 [May 26, 2016]
+ * Last changed in libpng 1.6.29 [March 16, 2017]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*/
-#include "../../pngpriv.h"
+#include "../pngpriv.h"
#ifdef PNG_READ_SUPPORTED
#if PNG_INTEL_SSE_IMPLEMENTATION > 0
diff --git a/third_party/libpng16/png.c b/third_party/libpng16/png.c
index 01d8d9bae6..22dcef260e 100644
--- a/third_party/libpng16/png.c
+++ b/third_party/libpng16/png.c
@@ -1,8 +1,8 @@
/* png.c - location for general purpose libpng functions
*
- * Last changed in libpng 1.6.19 [November 12, 2015]
- * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.33 [September 28, 2017]
+ * Copyright (c) 1998-2002,2004,2006-2017 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,27 @@
#include "pngpriv.h"
/* Generate a compiler error if there is an old png.h in the search path. */
-typedef png_libpng_version_1_6_22 Your_png_h_is_not_version_1_6_22;
+typedef png_libpng_version_1_6_34 Your_png_h_is_not_version_1_6_34;
+
+#ifdef __GNUC__
+/* The version tests may need to be added to, but the problem warning has
+ * consistently been fixed in GCC versions which obtain wide-spread release.
+ * The problem is that many versions of GCC rearrange comparison expressions in
+ * the optimizer in such a way that the results of the comparison will change
+ * if signed integer overflow occurs. Such comparisons are not permitted in
+ * ANSI C90, however GCC isn't clever enough to work out that that do not occur
+ * below in png_ascii_from_fp and png_muldiv, so it produces a warning with
+ * -Wextra. Unfortunately this is highly dependent on the optimizer and the
+ * machine architecture so the warning comes and goes unpredictably and is
+ * impossible to "fix", even were that a good idea.
+ */
+#if __GNUC__ == 7 && __GNUC_MINOR__ == 1
+#define GCC_STRICT_OVERFLOW 1
+#endif /* GNU 7.1.x */
+#endif /* GNU */
+#ifndef GCC_STRICT_OVERFLOW
+#define GCC_STRICT_OVERFLOW 0
+#endif
/* 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
@@ -85,7 +105,7 @@ png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED)
if (items >= (~(png_alloc_size_t)0)/size)
{
png_warning (png_voidcast(png_structrp, png_ptr),
- "Potential overflow in png_zalloc()");
+ "Potential overflow in png_zalloc()");
return NULL;
}
@@ -172,10 +192,10 @@ 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)
{
- /* 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.
- */
+ /* 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)
{
@@ -297,7 +317,7 @@ png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
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)));
+ png_malloc_warn(&create_struct, (sizeof *png_ptr)));
if (png_ptr != NULL)
{
@@ -346,7 +366,7 @@ png_create_info_struct,(png_const_structrp png_ptr),PNG_ALLOCATED)
* has always been done in 'example.c'.
*/
info_ptr = png_voidcast(png_inforp, png_malloc_base(png_ptr,
- (sizeof *info_ptr)));
+ (sizeof *info_ptr)));
if (info_ptr != NULL)
memset(info_ptr, 0, (sizeof *info_ptr));
@@ -402,7 +422,7 @@ png_destroy_info_struct(png_const_structrp png_ptr, png_infopp info_ptr_ptr)
*/
PNG_FUNCTION(void,PNGAPI
png_info_init_3,(png_infopp ptr_ptr, png_size_t png_info_struct_size),
- PNG_DEPRECATED)
+ PNG_DEPRECATED)
{
png_inforp info_ptr = *ptr_ptr;
@@ -417,7 +437,7 @@ png_info_init_3,(png_infopp ptr_ptr, png_size_t png_info_struct_size),
/* The following line is why this API should not be used: */
free(info_ptr);
info_ptr = png_voidcast(png_inforp, png_malloc_base(NULL,
- (sizeof *info_ptr)));
+ (sizeof *info_ptr)));
if (info_ptr == NULL)
return;
*ptr_ptr = info_ptr;
@@ -430,7 +450,7 @@ png_info_init_3,(png_infopp ptr_ptr, png_size_t png_info_struct_size),
/* The following API is not called internally */
void PNGAPI
png_data_freer(png_const_structrp png_ptr, png_inforp info_ptr,
- int freer, png_uint_32 mask)
+ int freer, png_uint_32 mask)
{
png_debug(1, "in png_data_freer");
@@ -449,7 +469,7 @@ png_data_freer(png_const_structrp png_ptr, png_inforp info_ptr,
void PNGAPI
png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
- int num)
+ int num)
{
png_debug(1, "in png_free_data");
@@ -458,7 +478,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#ifdef PNG_TEXT_SUPPORTED
/* Free text item num or (if num == -1) all text items */
- if (info_ptr->text != 0 &&
+ if (info_ptr->text != NULL &&
((mask & PNG_FREE_TEXT) & info_ptr->free_me) != 0)
{
if (num != -1)
@@ -477,6 +497,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
png_free(png_ptr, info_ptr->text);
info_ptr->text = NULL;
info_ptr->num_text = 0;
+ info_ptr->max_text = 0;
}
}
#endif
@@ -541,7 +562,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#ifdef PNG_sPLT_SUPPORTED
/* Free a given sPLT entry, or (if num == -1) all sPLT entries */
- if (info_ptr->splt_palettes != 0 &&
+ if (info_ptr->splt_palettes != NULL &&
((mask & PNG_FREE_SPLT) & info_ptr->free_me) != 0)
{
if (num != -1)
@@ -571,7 +592,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
#endif
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
- if (info_ptr->unknown_chunks != 0 &&
+ if (info_ptr->unknown_chunks != NULL &&
((mask & PNG_FREE_UNKN) & info_ptr->free_me) != 0)
{
if (num != -1)
@@ -594,6 +615,26 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
}
#endif
+#ifdef PNG_eXIf_SUPPORTED
+ /* Free any eXIf entry */
+ if (((mask & PNG_FREE_EXIF) & info_ptr->free_me) != 0)
+ {
+# ifdef PNG_READ_eXIf_SUPPORTED
+ if (info_ptr->eXIf_buf)
+ {
+ png_free(png_ptr, info_ptr->eXIf_buf);
+ info_ptr->eXIf_buf = NULL;
+ }
+# endif
+ if (info_ptr->exif)
+ {
+ png_free(png_ptr, info_ptr->exif);
+ info_ptr->exif = NULL;
+ }
+ info_ptr->valid &= ~PNG_INFO_eXIf;
+ }
+#endif
+
#ifdef PNG_hIST_SUPPORTED
/* Free any hIST entry */
if (((mask & PNG_FREE_HIST) & info_ptr->free_me) != 0)
@@ -617,7 +658,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
/* Free any image bits attached to the info structure */
if (((mask & PNG_FREE_ROWS) & info_ptr->free_me) != 0)
{
- if (info_ptr->row_pointers != 0)
+ if (info_ptr->row_pointers != NULL)
{
png_uint_32 row;
for (row = 0; row < info_ptr->height; row++)
@@ -684,7 +725,7 @@ png_init_io(png_structrp png_ptr, png_FILE_p fp)
void PNGAPI
png_save_int_32(png_bytep buf, png_int_32 i)
{
- png_save_uint_32(buf, i);
+ png_save_uint_32(buf, (png_uint_32)i);
}
# endif
@@ -775,15 +816,15 @@ png_get_copyright(png_const_structrp png_ptr)
#else
# ifdef __STDC__
return PNG_STRING_NEWLINE \
- "libpng version 1.6.22 - May 26, 2016" PNG_STRING_NEWLINE \
- "Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson" \
+ "libpng version 1.6.34 - September 29, 2017" PNG_STRING_NEWLINE \
+ "Copyright (c) 1998-2002,2004,2006-2017 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.22 - May 26, 2016\
- Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\
+ return "libpng version 1.6.34 - September 29, 2017\
+ Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
# endif
@@ -1033,7 +1074,7 @@ png_zstream_error(png_structrp png_ptr, int ret)
#ifdef PNG_GAMMA_SUPPORTED /* always set if COLORSPACE */
static int
png_colorspace_check_gamma(png_const_structrp png_ptr,
- png_colorspacerp colorspace, png_fixed_point gAMA, int from)
+ png_colorspacerp colorspace, png_fixed_point gAMA, int from)
/* This is called to check a new gamma value against an existing one. The
* routine returns false if the new gamma value should not be written.
*
@@ -1047,7 +1088,7 @@ png_colorspace_check_gamma(png_const_structrp png_ptr,
png_fixed_point gtest;
if ((colorspace->flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
- (png_muldiv(&gtest, colorspace->gamma, PNG_FP_1, gAMA) == 0 ||
+ (png_muldiv(&gtest, colorspace->gamma, PNG_FP_1, gAMA) == 0 ||
png_gamma_significant(gtest) != 0))
{
/* Either this is an sRGB image, in which case the calculated gamma
@@ -1059,7 +1100,7 @@ png_colorspace_check_gamma(png_const_structrp png_ptr,
if ((colorspace->flags & PNG_COLORSPACE_FROM_sRGB) != 0 || from == 2)
{
png_chunk_report(png_ptr, "gamma value does not match sRGB",
- PNG_CHUNK_ERROR);
+ PNG_CHUNK_ERROR);
/* Do not overwrite an sRGB value */
return from == 2;
}
@@ -1067,7 +1108,7 @@ png_colorspace_check_gamma(png_const_structrp png_ptr,
else /* sRGB tag not involved */
{
png_chunk_report(png_ptr, "gamma value does not match libpng estimate",
- PNG_CHUNK_WARNING);
+ PNG_CHUNK_WARNING);
return from == 1;
}
}
@@ -1077,7 +1118,7 @@ png_colorspace_check_gamma(png_const_structrp png_ptr,
void /* PRIVATE */
png_colorspace_set_gamma(png_const_structrp png_ptr,
- png_colorspacerp colorspace, png_fixed_point gAMA)
+ 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 asymetrical it is
@@ -1635,8 +1676,8 @@ static const png_xy sRGB_xy = /* From ITU-R BT.709-3 */
static int
png_colorspace_set_xy_and_XYZ(png_const_structrp png_ptr,
- png_colorspacerp colorspace, const png_xy *xy, const png_XYZ *XYZ,
- int preferred)
+ png_colorspacerp colorspace, const png_xy *xy, const png_XYZ *XYZ,
+ int preferred)
{
if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)
return 0;
@@ -1683,7 +1724,7 @@ png_colorspace_set_xy_and_XYZ(png_const_structrp png_ptr,
int /* PRIVATE */
png_colorspace_set_chromaticities(png_const_structrp png_ptr,
- png_colorspacerp colorspace, const png_xy *xy, int preferred)
+ png_colorspacerp colorspace, const png_xy *xy, int preferred)
{
/* We must check the end points to ensure they are reasonable - in the past
* color management systems have crashed as a result of getting bogus
@@ -1697,7 +1738,7 @@ png_colorspace_set_chromaticities(png_const_structrp png_ptr,
{
case 0: /* success */
return png_colorspace_set_xy_and_XYZ(png_ptr, colorspace, xy, &XYZ,
- preferred);
+ preferred);
case 1:
/* We can't invert the chromaticities so we can't produce value XYZ
@@ -1720,7 +1761,7 @@ png_colorspace_set_chromaticities(png_const_structrp png_ptr,
int /* PRIVATE */
png_colorspace_set_endpoints(png_const_structrp png_ptr,
- png_colorspacerp colorspace, const png_XYZ *XYZ_in, int preferred)
+ png_colorspacerp colorspace, const png_XYZ *XYZ_in, int preferred)
{
png_XYZ XYZ = *XYZ_in;
png_xy xy;
@@ -1729,7 +1770,7 @@ png_colorspace_set_endpoints(png_const_structrp png_ptr,
{
case 0:
return png_colorspace_set_xy_and_XYZ(png_ptr, colorspace, &xy, &XYZ,
- preferred);
+ preferred);
case 1:
/* End points are invalid. */
@@ -1786,7 +1827,7 @@ is_ICC_signature(png_alloc_size_t it)
static int
png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace,
- png_const_charp name, png_alloc_size_t value, png_const_charp reason)
+ png_const_charp name, png_alloc_size_t value, png_const_charp reason)
{
size_t pos;
char message[196]; /* see below for calculation */
@@ -1811,8 +1852,8 @@ png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace,
char number[PNG_NUMBER_BUFFER_SIZE]; /* +24 = 114*/
pos = png_safecat(message, (sizeof message), pos,
- png_format_number(number, number+(sizeof number),
- PNG_NUMBER_FORMAT_x, value));
+ png_format_number(number, number+(sizeof number),
+ PNG_NUMBER_FORMAT_x, value));
pos = png_safecat(message, (sizeof message), pos, "h: "); /*+2 = 116*/
}
# endif
@@ -1826,7 +1867,7 @@ png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace,
* application errors the PNG won't be written.)
*/
png_chunk_report(png_ptr, message,
- (colorspace != NULL) ? PNG_CHUNK_ERROR : PNG_CHUNK_WRITE_ERROR);
+ (colorspace != NULL) ? PNG_CHUNK_ERROR : PNG_CHUNK_WRITE_ERROR);
return 0;
}
@@ -1835,7 +1876,7 @@ png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace,
#ifdef PNG_sRGB_SUPPORTED
int /* PRIVATE */
png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
- int intent)
+ int intent)
{
/* sRGB sets known gamma, end points and (from the chunk) intent. */
/* IMPORTANT: these are not necessarily the values found in an ICC profile
@@ -1872,12 +1913,12 @@ png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
*/
if (intent < 0 || intent >= PNG_sRGB_INTENT_LAST)
return png_icc_profile_error(png_ptr, colorspace, "sRGB",
- (unsigned)intent, "invalid sRGB rendering intent");
+ (png_alloc_size_t)intent, "invalid sRGB rendering intent");
if ((colorspace->flags & PNG_COLORSPACE_HAVE_INTENT) != 0 &&
- colorspace->rendering_intent != intent)
+ colorspace->rendering_intent != intent)
return png_icc_profile_error(png_ptr, colorspace, "sRGB",
- (unsigned)intent, "inconsistent rendering intents");
+ (png_alloc_size_t)intent, "inconsistent rendering intents");
if ((colorspace->flags & PNG_COLORSPACE_FROM_sRGB) != 0)
{
@@ -1889,8 +1930,8 @@ png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
* warn but overwrite the value with the correct one.
*/
if ((colorspace->flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0 &&
- !png_colorspace_endpoints_match(&sRGB_xy, &colorspace->end_points_xy,
- 100))
+ !png_colorspace_endpoints_match(&sRGB_xy, &colorspace->end_points_xy,
+ 100))
png_chunk_report(png_ptr, "cHRM chunk does not match sRGB",
PNG_CHUNK_ERROR);
@@ -1898,7 +1939,7 @@ png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
* returns true when the 'from' argument corresponds to sRGB (2).
*/
(void)png_colorspace_check_gamma(png_ptr, colorspace, PNG_GAMMA_sRGB_INVERSE,
- 2/*from sRGB*/);
+ 2/*from sRGB*/);
/* intent: bugs in GCC force 'int' to be used as the parameter type. */
colorspace->rendering_intent = (png_uint_16)intent;
@@ -1933,12 +1974,11 @@ static const png_byte D50_nCIEXYZ[12] =
static int /* bool */
icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace,
- png_const_charp name, png_uint_32 profile_length)
+ png_const_charp name, png_uint_32 profile_length)
{
if (profile_length < 132)
return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
- "too short");
-
+ "too short");
return 1;
}
@@ -1978,8 +2018,8 @@ png_icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace,
int /* PRIVATE */
png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
- png_const_charp name, png_uint_32 profile_length,
- png_const_bytep profile/* first 132 bytes only */, int color_type)
+ png_const_charp name, png_uint_32 profile_length,
+ png_const_bytep profile/* first 132 bytes only */, int color_type)
{
png_uint_32 temp;
@@ -1991,18 +2031,18 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
temp = png_get_uint_32(profile);
if (temp != profile_length)
return png_icc_profile_error(png_ptr, colorspace, name, temp,
- "length does not match profile");
+ "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");
+ "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 */
return png_icc_profile_error(png_ptr, colorspace, name, temp,
- "tag count too large");
+ "tag count too large");
/* The 'intent' must be valid or we can't store it, ICC limits the intent to
* 16 bits.
@@ -2010,14 +2050,14 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
temp = png_get_uint_32(profile+64);
if (temp >= 0xffff) /* The ICC limit */
return png_icc_profile_error(png_ptr, colorspace, name, temp,
- "invalid rendering intent");
+ "invalid rendering intent");
/* This is just a warning because the profile may be valid in future
* versions.
*/
if (temp >= PNG_sRGB_INTENT_LAST)
(void)png_icc_profile_error(png_ptr, NULL, name, temp,
- "intent outside defined range");
+ "intent outside defined range");
/* At this point the tag table can't be checked because it hasn't necessarily
* been loaded; however, various header fields can be checked. These checks
@@ -2034,7 +2074,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
temp = png_get_uint_32(profile+36); /* signature 'ascp' */
if (temp != 0x61637370)
return png_icc_profile_error(png_ptr, colorspace, name, temp,
- "invalid signature");
+ "invalid signature");
/* Currently the PCS illuminant/adopted white point (the computational
* white point) are required to be D50,
@@ -2045,7 +2085,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
*/
if (memcmp(profile+68, D50_nCIEXYZ, 12) != 0)
(void)png_icc_profile_error(png_ptr, NULL, name, 0/*no tag value*/,
- "PCS illuminant is not D50");
+ "PCS illuminant is not D50");
/* The PNG spec requires this:
* "If the iCCP chunk is present, the image samples conform to the colour
@@ -2073,18 +2113,18 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
case 0x52474220: /* 'RGB ' */
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");
+ "RGB color space not permitted on grayscale PNG");
break;
case 0x47524159: /* 'GRAY' */
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");
+ "Gray color space not permitted on RGB PNG");
break;
default:
return png_icc_profile_error(png_ptr, colorspace, name, temp,
- "invalid ICC profile color space");
+ "invalid ICC profile color space");
}
/* It is up to the application to check that the profile class matches the
@@ -2109,7 +2149,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
case 0x61627374: /* 'abst' */
/* May not be embedded in an image */
return png_icc_profile_error(png_ptr, colorspace, name, temp,
- "invalid embedded Abstract ICC profile");
+ "invalid embedded Abstract ICC profile");
case 0x6c696e6b: /* 'link' */
/* DeviceLink profiles cannot be interpreted in a non-device specific
@@ -2119,7 +2159,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
* PNG.
*/
return png_icc_profile_error(png_ptr, colorspace, name, temp,
- "unexpected DeviceLink ICC profile class");
+ "unexpected DeviceLink ICC profile class");
case 0x6e6d636c: /* 'nmcl' */
/* A NamedColor profile is also device specific, however it doesn't
@@ -2127,7 +2167,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
* certainly it will fail the tests below.
*/
(void)png_icc_profile_error(png_ptr, NULL, name, temp,
- "unexpected NamedColor ICC profile class");
+ "unexpected NamedColor ICC profile class");
break;
default:
@@ -2137,7 +2177,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
* understood profiles.
*/
(void)png_icc_profile_error(png_ptr, NULL, name, temp,
- "unrecognized ICC profile class");
+ "unrecognized ICC profile class");
break;
}
@@ -2153,7 +2193,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
default:
return png_icc_profile_error(png_ptr, colorspace, name, temp,
- "unexpected ICC PCS encoding");
+ "unexpected ICC PCS encoding");
}
return 1;
@@ -2161,8 +2201,8 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
int /* PRIVATE */
png_icc_check_tag_table(png_const_structrp png_ptr, png_colorspacerp colorspace,
- png_const_charp name, png_uint_32 profile_length,
- png_const_bytep profile /* header plus whole tag table */)
+ png_const_charp name, png_uint_32 profile_length,
+ png_const_bytep profile /* header plus whole tag table */)
{
png_uint_32 tag_count = png_get_uint_32(profile+128);
png_uint_32 itag;
@@ -2183,22 +2223,23 @@ png_icc_check_tag_table(png_const_structrp png_ptr, png_colorspacerp colorspace,
* being in range. All defined tag types have an 8 byte header - a 4 byte
* type signature then 0.
*/
+
+ /* This is a hard error; potentially it can cause read outside the
+ * profile.
+ */
+ if (tag_start > profile_length || tag_length > profile_length - tag_start)
+ return png_icc_profile_error(png_ptr, colorspace, name, tag_id,
+ "ICC profile tag outside profile");
+
if ((tag_start & 3) != 0)
{
- /* CNHP730S.icc shipped with Microsoft Windows 64 violates this, it is
+ /* CNHP730S.icc shipped with Microsoft Windows 64 violates this; it is
* only a warning here because libpng does not care about the
* alignment.
*/
(void)png_icc_profile_error(png_ptr, NULL, name, tag_id,
- "ICC profile tag start not a multiple of 4");
+ "ICC profile tag start not a multiple of 4");
}
-
- /* This is a hard error; potentially it can cause read outside the
- * profile.
- */
- if (tag_start > profile_length || tag_length > profile_length - tag_start)
- return png_icc_profile_error(png_ptr, colorspace, name, tag_id,
- "ICC profile tag outside profile");
}
return 1; /* success, maybe with warnings */
@@ -2226,22 +2267,22 @@ static const struct
*/
/* adler32, crc32, MD5[4], intent, date, length, file-name */
PNG_ICC_CHECKSUM(0x0a3fd9f6, 0x3b8772b9,
- PNG_MD5(0x29f83dde, 0xaff255ae, 0x7842fae4, 0xca83390d), 0, 0,
- "2009/03/27 21:36:31", 3048, "sRGB_IEC61966-2-1_black_scaled.icc")
+ PNG_MD5(0x29f83dde, 0xaff255ae, 0x7842fae4, 0xca83390d), 0, 0,
+ "2009/03/27 21:36:31", 3048, "sRGB_IEC61966-2-1_black_scaled.icc")
/* ICC sRGB v2 perceptual no black-compensation: */
PNG_ICC_CHECKSUM(0x4909e5e1, 0x427ebb21,
- PNG_MD5(0xc95bd637, 0xe95d8a3b, 0x0df38f99, 0xc1320389), 1, 0,
- "2009/03/27 21:37:45", 3052, "sRGB_IEC61966-2-1_no_black_scaling.icc")
+ PNG_MD5(0xc95bd637, 0xe95d8a3b, 0x0df38f99, 0xc1320389), 1, 0,
+ "2009/03/27 21:37:45", 3052, "sRGB_IEC61966-2-1_no_black_scaling.icc")
PNG_ICC_CHECKSUM(0xfd2144a1, 0x306fd8ae,
- PNG_MD5(0xfc663378, 0x37e2886b, 0xfd72e983, 0x8228f1b8), 0, 0,
- "2009/08/10 17:28:01", 60988, "sRGB_v4_ICC_preference_displayclass.icc")
+ PNG_MD5(0xfc663378, 0x37e2886b, 0xfd72e983, 0x8228f1b8), 0, 0,
+ "2009/08/10 17:28:01", 60988, "sRGB_v4_ICC_preference_displayclass.icc")
/* ICC sRGB v4 perceptual */
PNG_ICC_CHECKSUM(0x209c35d2, 0xbbef7812,
- PNG_MD5(0x34562abf, 0x994ccd06, 0x6d2c5721, 0xd0d68c5d), 0, 0,
- "2007/07/25 00:05:37", 60960, "sRGB_v4_ICC_preference.icc")
+ PNG_MD5(0x34562abf, 0x994ccd06, 0x6d2c5721, 0xd0d68c5d), 0, 0,
+ "2007/07/25 00:05:37", 60960, "sRGB_v4_ICC_preference.icc")
/* The following profiles have no known MD5 checksum. If there is a match
* on the (empty) MD5 the other fields are used to attempt a match and
@@ -2249,8 +2290,8 @@ static const struct
* which suggests that they were also made by Hewlett Packard.
*/
PNG_ICC_CHECKSUM(0xa054d762, 0x5d5129ce,
- PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 0,
- "2004/07/21 18:57:42", 3024, "sRGB_IEC61966-2-1_noBPC.icc")
+ PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 0,
+ "2004/07/21 18:57:42", 3024, "sRGB_IEC61966-2-1_noBPC.icc")
/* This is a 'mntr' (display) profile with a mediaWhitePointTag that does not
* match the D50 PCS illuminant in the header (it is in fact the D65 values,
@@ -2260,17 +2301,17 @@ static const struct
* chromaticAdaptationTag.
*/
PNG_ICC_CHECKSUM(0xf784f3fb, 0x182ea552,
- PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 0, 1/*broken*/,
- "1998/02/09 06:49:00", 3144, "HP-Microsoft sRGB v2 perceptual")
+ PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 0, 1/*broken*/,
+ "1998/02/09 06:49:00", 3144, "HP-Microsoft sRGB v2 perceptual")
PNG_ICC_CHECKSUM(0x0398f3fc, 0xf29e526d,
- PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 1/*broken*/,
- "1998/02/09 06:49:00", 3144, "HP-Microsoft sRGB v2 media-relative")
+ PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 1/*broken*/,
+ "1998/02/09 06:49:00", 3144, "HP-Microsoft sRGB v2 media-relative")
};
static int
png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,
- png_const_bytep profile, uLong adler)
+ png_const_bytep profile, uLong adler)
{
/* The quick check is to verify just the MD5 signature and trust the
* rest of the data. Because the profile has already been verified for
@@ -2354,7 +2395,7 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,
* which is made irrelevant by this error.
*/
png_chunk_report(png_ptr, "known incorrect sRGB profile",
- PNG_CHUNK_ERROR);
+ PNG_CHUNK_ERROR);
}
/* Warn that this being done; this isn't even an error since
@@ -2364,8 +2405,8 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,
else if (png_sRGB_checks[i].have_md5 == 0)
{
png_chunk_report(png_ptr,
- "out-of-date sRGB profile with no signature",
- PNG_CHUNK_WARNING);
+ "out-of-date sRGB profile with no signature",
+ PNG_CHUNK_WARNING);
}
return 1+png_sRGB_checks[i].is_broken;
@@ -2388,38 +2429,36 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,
return 0; /* no match */
}
-#endif /* PNG_sRGB_PROFILE_CHECKS >= 0 */
void /* PRIVATE */
png_icc_set_sRGB(png_const_structrp png_ptr,
- png_colorspacerp colorspace, png_const_bytep profile, uLong adler)
+ png_colorspacerp colorspace, png_const_bytep profile, uLong adler)
{
/* Is this profile one of the known ICC sRGB profiles? If it is, just set
* the sRGB information.
*/
-#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_sRGB_PROFILE_CHECKS >= 0 */
#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)
+ png_const_charp name, png_uint_32 profile_length, png_const_bytep profile,
+ int color_type)
{
if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)
return 0;
if (icc_check_length(png_ptr, colorspace, name, profile_length) != 0 &&
png_icc_check_header(png_ptr, colorspace, name, profile_length, profile,
- color_type) != 0 &&
+ color_type) != 0 &&
png_icc_check_tag_table(png_ptr, colorspace, name, profile_length,
- profile) != 0)
+ profile) != 0)
{
-# ifdef PNG_sRGB_SUPPORTED
+# if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0
/* If no sRGB support, don't try storing sRGB information */
png_icc_set_sRGB(png_ptr, colorspace, profile, 0);
# endif
@@ -2478,7 +2517,7 @@ png_colorspace_set_rgb_coefficients(png_structrp png_ptr)
/* Check for an internal error. */
if (r+g+b != 32768)
png_error(png_ptr,
- "internal error handling cHRM coefficients");
+ "internal error handling cHRM coefficients");
else
{
@@ -2505,7 +2544,7 @@ png_colorspace_set_rgb_coefficients(png_structrp png_ptr)
static int /* PRIVATE */
png_gt(size_t a, size_t b)
{
- return a > b;
+ return a > b;
}
#else
# define png_gt(a,b) ((a) > (b))
@@ -2513,9 +2552,9 @@ png_gt(size_t a, size_t b)
void /* PRIVATE */
png_check_IHDR(png_const_structrp png_ptr,
- png_uint_32 width, png_uint_32 height, int bit_depth,
- int color_type, int interlace_type, int compression_type,
- int filter_type)
+ png_uint_32 width, png_uint_32 height, int bit_depth,
+ int color_type, int interlace_type, int compression_type,
+ int filter_type)
{
int error = 0;
@@ -2532,7 +2571,7 @@ png_check_IHDR(png_const_structrp png_ptr,
error = 1;
}
- if (png_gt(((width + 7) & (~7)),
+ if (png_gt(((width + 7) & (~7U)),
((PNG_SIZE_MAX
- 48 /* big_row_buf hack */
- 1) /* filter byte */
@@ -2678,7 +2717,7 @@ png_check_IHDR(png_const_structrp png_ptr,
int /* PRIVATE */
png_check_fp_number(png_const_charp string, png_size_t size, int *statep,
- png_size_tp whereami)
+ png_size_tp whereami)
{
int state = *statep;
png_size_t i = *whereami;
@@ -2834,7 +2873,7 @@ png_pow10(int power)
if (power < 0)
{
if (power < DBL_MIN_10_EXP) return 0;
- recip = 1, power = -power;
+ recip = 1; power = -power;
}
if (power > 0)
@@ -2859,6 +2898,14 @@ png_pow10(int power)
/* Function to format a floating point value in ASCII with a given
* precision.
*/
+#if GCC_STRICT_OVERFLOW
+#pragma GCC diagnostic push
+/* The problem arises below with exp_b10, which can never overflow because it
+ * comes, originally, from frexp and is therefore limited to a range which is
+ * typically +/-710 (log2(DBL_MAX)/log2(DBL_MIN)).
+ */
+#pragma GCC diagnostic warning "-Wstrict-overflow=2"
+#endif /* GCC_STRICT_OVERFLOW */
void /* PRIVATE */
png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
double fp, unsigned int precision)
@@ -2912,7 +2959,9 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
double test = png_pow10(exp_b10+1);
if (test <= DBL_MAX)
- ++exp_b10, base = test;
+ {
+ ++exp_b10; base = test;
+ }
else
break;
@@ -2926,7 +2975,10 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
* test on DBL_MAX above.
*/
fp /= base;
- while (fp >= 1) fp /= 10, ++exp_b10;
+ while (fp >= 1)
+ {
+ fp /= 10; ++exp_b10;
+ }
/* Because of the code above fp may, at this point, be
* less than .1, this is ok because the code below can
@@ -2943,7 +2995,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
*/
if (exp_b10 < 0 && exp_b10 > -3) /* PLUS 3 TOTAL 4 */
{
- czero = -exp_b10; /* PLUS 2 digits: TOTAL 3 */
+ czero = 0U-exp_b10; /* PLUS 2 digits: TOTAL 3 */
exp_b10 = 0; /* Dot added below before first output. */
}
else
@@ -2977,7 +3029,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
/* Rounding up to 10, handle that here. */
if (czero > 0)
{
- --czero, d = 1;
+ --czero; d = 1;
if (cdigits == 0) --clead;
}
else
@@ -2991,7 +3043,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
else if (ch == 46)
{
- ch = *--ascii, ++size;
+ ch = *--ascii; ++size;
/* Advance exp_b10 to '1', so that the
* decimal point happens after the
* previous digit.
@@ -3018,7 +3070,9 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
int ch = *--ascii;
if (ch == 46)
- ++size, exp_b10 = 1;
+ {
+ ++size; exp_b10 = 1;
+ }
/* Else lost a leading zero, so 'exp_b10' is
* still ok at (-1)
@@ -3054,21 +3108,26 @@ 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;
+ if (exp_b10 == 0)
+ {
+ *ascii++ = 46; --size;
+ }
/* PLUS 1: TOTAL 4 */
--exp_b10;
}
- *ascii++ = 48, --czero;
+ *ascii++ = 48; --czero;
}
if (exp_b10 != (-1))
{
if (exp_b10 == 0)
- *ascii++ = 46, --size; /* counted above */
+ {
+ *ascii++ = 46; --size; /* counted above */
+ }
--exp_b10;
}
- *ascii++ = (char)(48 + (int)d), ++cdigits;
+ *ascii++ = (char)(48 + (int)d); ++cdigits;
}
}
while (cdigits+czero < precision+clead && fp > DBL_MIN);
@@ -3077,7 +3136,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
/* 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
+ * this point exp_b10==(-1) is effectively a flag - it got
* to '-1' because of the decrement after outputting
* the decimal point above (the exponent required is
* *not* -1!)
@@ -3091,7 +3150,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
* zeros were *not* output, so this doesn't increase
* the output count.
*/
- while (--exp_b10 >= 0) *ascii++ = 48;
+ while (exp_b10-- > 0) *ascii++ = 48;
*ascii = 0;
@@ -3109,7 +3168,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
*/
size -= cdigits;
- *ascii++ = 69, --size; /* 'E': PLUS 1 TOTAL 2+precision */
+ *ascii++ = 69; --size; /* 'E': PLUS 1 TOTAL 2+precision */
/* The following use of an unsigned temporary avoids ambiguities in
* the signed arithmetic on exp_b10 and permits GCC at least to do
@@ -3120,12 +3179,12 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
if (exp_b10 < 0)
{
- *ascii++ = 45, --size; /* '-': PLUS 1 TOTAL 3+precision */
- uexp_b10 = -exp_b10;
+ *ascii++ = 45; --size; /* '-': PLUS 1 TOTAL 3+precision */
+ uexp_b10 = 0U-exp_b10;
}
else
- uexp_b10 = exp_b10;
+ uexp_b10 = 0U+exp_b10;
cdigits = 0;
@@ -3168,6 +3227,9 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
/* Here on buffer too small. */
png_error(png_ptr, "ASCII conversion buffer too small");
}
+#if GCC_STRICT_OVERFLOW
+#pragma GCC diagnostic pop
+#endif /* GCC_STRICT_OVERFLOW */
# endif /* FLOATING_POINT */
@@ -3187,9 +3249,11 @@ png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii,
/* Avoid overflow here on the minimum integer. */
if (fp < 0)
- *ascii++ = 45, num = -fp;
+ {
+ *ascii++ = 45; num = (png_uint_32)(-fp);
+ }
else
- num = fp;
+ num = (png_uint_32)fp;
if (num <= 0x80000000) /* else overflowed */
{
@@ -3225,7 +3289,10 @@ png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii,
* then ndigits digits to first:
*/
i = 5;
- while (ndigits < i) *ascii++ = 48, --i;
+ while (ndigits < i)
+ {
+ *ascii++ = 48; --i;
+ }
while (ndigits >= first) *ascii++ = digits[--ndigits];
/* Don't output the trailing zeros! */
}
@@ -3276,6 +3343,15 @@ png_fixed(png_const_structrp png_ptr, double fp, png_const_charp text)
* the nearest .00001). Overflow and divide by zero are signalled in
* the result, a boolean - true on success, false on overflow.
*/
+#if GCC_STRICT_OVERFLOW /* from above */
+/* It is not obvious which comparison below gets optimized in such a way that
+ * signed overflow would change the result; looking through the code does not
+ * reveal any tests which have the form GCC complains about, so presumably the
+ * optimizer is moving an add or subtract into the 'if' somewhere.
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic warning "-Wstrict-overflow=2"
+#endif /* GCC_STRICT_OVERFLOW */
int
png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times,
png_int_32 divisor)
@@ -3390,6 +3466,9 @@ png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times,
return 0;
}
+#if GCC_STRICT_OVERFLOW
+#pragma GCC diagnostic pop
+#endif /* GCC_STRICT_OVERFLOW */
#endif /* READ_GAMMA || INCH_CONVERSIONS */
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
@@ -3683,7 +3762,7 @@ png_log16bit(png_uint_32 x)
* of getting this accuracy in practice.
*
* To deal with this the following exp() function works out the exponent of the
- * frational part of the logarithm by using an accurate 32-bit value from the
+ * fractional part of the logarithm by using an accurate 32-bit value from the
* top four fractional bits then multiplying in the remaining bits.
*/
static const png_uint_32
@@ -3841,25 +3920,25 @@ png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val)
{
if (value > 0 && value < 65535)
{
-# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
- /* 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) != 0)
- return png_exp16bit(res);
-
- /* Overflow. */
- value = 0;
-# endif
+# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
+ /* 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) != 0)
+ return png_exp16bit(res);
+
+ /* Overflow. */
+ value = 0;
+# endif
}
return (png_uint_16)value;
@@ -3898,7 +3977,7 @@ png_gamma_correct(png_structrp png_ptr, unsigned int value,
*/
static void
png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable,
- PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
+ PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
{
/* Various values derived from 'shift': */
PNG_CONST unsigned int num = 1U << (8U - shift);
@@ -3975,7 +4054,7 @@ png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable,
*/
static void
png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable,
- PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
+ PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
{
PNG_CONST unsigned int num = 1U << (8U - shift);
PNG_CONST unsigned int max = (1U << (16U - shift))-1U;
@@ -4043,7 +4122,7 @@ png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable,
*/
static void
png_build_8bit_table(png_structrp png_ptr, png_bytepp ptable,
- PNG_CONST png_fixed_point gamma_val)
+ PNG_CONST png_fixed_point gamma_val)
{
unsigned int i;
png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256);
@@ -4123,131 +4202,133 @@ png_destroy_gamma_table(png_structrp png_ptr)
void /* PRIVATE */
png_build_gamma_table(png_structrp png_ptr, int bit_depth)
{
- png_debug(1, "in png_build_gamma_table");
-
- /* Remove any existing table; this copes with multiple calls to
- * png_read_update_info. The warning is because building the gamma tables
- * multiple times is a performance hit - it's harmless but the ability to call
- * png_read_update_info() multiple times is new in 1.5.6 so it seems sensible
- * to warn if the app introduces such a hit.
- */
- if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL)
- {
- png_warning(png_ptr, "gamma table being rebuilt");
- png_destroy_gamma_table(png_ptr);
- }
-
- if (bit_depth <= 8)
- {
- png_build_8bit_table(png_ptr, &png_ptr->gamma_table,
- png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma,
- png_ptr->screen_gamma) : PNG_FP_1);
+ png_debug(1, "in png_build_gamma_table");
+
+ /* Remove any existing table; this copes with multiple calls to
+ * png_read_update_info. The warning is because building the gamma tables
+ * multiple times is a performance hit - it's harmless but the ability to
+ * call png_read_update_info() multiple times is new in 1.5.6 so it seems
+ * sensible to warn if the app introduces such a hit.
+ */
+ if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL)
+ {
+ png_warning(png_ptr, "gamma table being rebuilt");
+ png_destroy_gamma_table(png_ptr);
+ }
+
+ if (bit_depth <= 8)
+ {
+ png_build_8bit_table(png_ptr, &png_ptr->gamma_table,
+ png_ptr->screen_gamma > 0 ?
+ png_reciprocal2(png_ptr->colorspace.gamma,
+ png_ptr->screen_gamma) : PNG_FP_1);
#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)) != 0)
- {
- png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1,
- png_reciprocal(png_ptr->colorspace.gamma));
-
- png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1,
- png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) :
- png_ptr->colorspace.gamma/* Probably doing 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));
+
+ png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1,
+ png_ptr->screen_gamma > 0 ?
+ png_reciprocal(png_ptr->screen_gamma) :
+ png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */);
+ }
#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
- }
+ }
#ifdef PNG_16BIT_SUPPORTED
- else
- {
- png_byte shift, sig_bit;
-
- if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
- {
- sig_bit = png_ptr->sig_bit.red;
-
- if (png_ptr->sig_bit.green > sig_bit)
- sig_bit = png_ptr->sig_bit.green;
-
- if (png_ptr->sig_bit.blue > sig_bit)
- sig_bit = png_ptr->sig_bit.blue;
- }
- else
- sig_bit = png_ptr->sig_bit.gray;
-
- /* 16-bit gamma code uses this equation:
- *
- * ov = table[(iv & 0xff) >> gamma_shift][iv >> 8]
- *
- * 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
- * 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:
- *
- * table[low bits][high 8 bits]
- *
- * So the table 'n' corresponds to all those 'iv' of:
- *
- * <all high 8-bit values><n << gamma_shift>..<(n+1 << gamma_shift)-1>
- *
- */
- if (sig_bit > 0 && sig_bit < 16U)
- /* 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)) != 0)
- {
- /* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively
- * the significant bits in the *input* when the output will
- * eventually be 8 bits. By default it is 11.
- */
- if (shift < (16U - PNG_MAX_GAMMA_8))
- shift = (16U - PNG_MAX_GAMMA_8);
- }
-
- if (shift > 8U)
- shift = 8U; /* Guarantees at least one table! */
-
- png_ptr->gamma_shift = shift;
-
- /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now
- * PNG_COMPOSE). This effectively smashed the background calculation for
- * 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)) != 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);
-
- else
- png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift,
- png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma,
- png_ptr->screen_gamma) : PNG_FP_1);
+ else
+ {
+ png_byte shift, sig_bit;
+
+ if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
+ {
+ sig_bit = png_ptr->sig_bit.red;
+
+ if (png_ptr->sig_bit.green > sig_bit)
+ sig_bit = png_ptr->sig_bit.green;
+
+ if (png_ptr->sig_bit.blue > sig_bit)
+ sig_bit = png_ptr->sig_bit.blue;
+ }
+ else
+ sig_bit = png_ptr->sig_bit.gray;
+
+ /* 16-bit gamma code uses this equation:
+ *
+ * ov = table[(iv & 0xff) >> gamma_shift][iv >> 8]
+ *
+ * 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
+ * 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:
+ *
+ * table[low bits][high 8 bits]
+ *
+ * So the table 'n' corresponds to all those 'iv' of:
+ *
+ * <all high 8-bit values><n << gamma_shift>..<(n+1 << gamma_shift)-1>
+ *
+ */
+ if (sig_bit > 0 && sig_bit < 16U)
+ /* 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)) != 0)
+ {
+ /* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively
+ * the significant bits in the *input* when the output will
+ * eventually be 8 bits. By default it is 11.
+ */
+ if (shift < (16U - PNG_MAX_GAMMA_8))
+ shift = (16U - PNG_MAX_GAMMA_8);
+ }
+
+ if (shift > 8U)
+ shift = 8U; /* Guarantees at least one table! */
+
+ png_ptr->gamma_shift = shift;
+
+ /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now
+ * PNG_COMPOSE). This effectively smashed the background calculation for
+ * 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)) != 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);
+
+ else
+ png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift,
+ png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma,
+ png_ptr->screen_gamma) : PNG_FP_1);
#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)) != 0)
- {
- png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift,
- png_reciprocal(png_ptr->colorspace.gamma));
-
- /* Notice that the '16 from 1' table should be full precision, however
- * the lookup on this table still uses gamma_shift, so it can't be.
- * TODO: fix this.
- */
- png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift,
- png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) :
- png_ptr->colorspace.gamma/* Probably doing 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));
+
+ /* Notice that the '16 from 1' table should be full precision, however
+ * the lookup on this table still uses gamma_shift, so it can't be.
+ * TODO: fix this.
+ */
+ png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift,
+ png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) :
+ png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */);
+ }
#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
- }
+ }
#endif /* 16BIT */
}
#endif /* READ_GAMMA */
@@ -4260,13 +4341,13 @@ png_set_option(png_structrp png_ptr, int option, int onoff)
if (png_ptr != NULL && option >= 0 && option < PNG_OPTION_NEXT &&
(option & 1) == 0)
{
- int mask = 3 << option;
- int setting = (2 + (onoff != 0)) << option;
- int current = png_ptr->options;
+ png_uint_32 mask = 3U << option;
+ png_uint_32 setting = (2U + (onoff != 0)) << option;
+ png_uint_32 current = png_ptr->options;
- png_ptr->options = (png_byte)(((current & ~mask) | setting) & 0xff);
+ png_ptr->options = (png_uint_32)(((current & ~mask) | setting) & 0xff);
- return (current & mask) >> option;
+ return (int)(current & mask) >> option;
}
return PNG_OPTION_INVALID;
@@ -4278,7 +4359,7 @@ png_set_option(png_structrp png_ptr, int option, int onoff)
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
/* sRGB conversion tables; these are machine generated with the code in
* contrib/tools/makesRGB.c. The actual sRGB transfer curve defined in the
- * specification (see the article at http://en.wikipedia.org/wiki/SRGB)
+ * specification (see the article at https://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 inverse (linear to sRGB) table has accuracies as follows:
diff --git a/third_party/libpng16/png.h b/third_party/libpng16/png.h
index 08c039df0b..4c873f5c22 100644
--- a/third_party/libpng16/png.h
+++ b/third_party/libpng16/png.h
@@ -1,9 +1,9 @@
/* png.h - header file for PNG reference library
*
- * libpng version 1.6.22, May 26, 2016
+ * libpng version 1.6.34, September 29, 2017
*
- * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2002,2004,2006-2017 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.)
*
@@ -12,7 +12,7 @@
* Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger
- * libpng versions 0.97, January 1998, through 1.6.22, May 26, 2016:
+ * libpng versions 0.97, January 1998, through 1.6.34, September 29, 2017:
* Glenn Randers-Pehrson.
* See also "Contributing Authors", below.
*/
@@ -25,12 +25,8 @@
*
* This code is released under the libpng license.
*
- * Some files in the "contrib" directory and some configure-generated
- * files that are distributed with libpng have other copyright owners and
- * are released under other open source licenses.
- *
- * libpng versions 1.0.7, July 1, 2000 through 1.6.22, May 26, 2016 are
- * Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are
+ * libpng versions 1.0.7, July 1, 2000 through 1.6.34, September 29, 2017 are
+ * Copyright (c) 2000-2002, 2004, 2006-2017 Glenn Randers-Pehrson, are
* derived from libpng-1.0.6, and are distributed according to the same
* disclaimer and license as libpng-1.0.6 with the following individuals
* added to the list of Contributing Authors:
@@ -41,6 +37,9 @@
* Cosmin Truta
* Gilles Vollant
* James Yu
+ * Mandar Sahastrabuddhe
+ * Google Inc.
+ * Vadim Barkov
*
* and with the following additions to the disclaimer:
*
@@ -51,10 +50,10 @@
* risk of satisfactory quality, performance, accuracy, and effort is with
* the user.
*
- * Some files in the "contrib" directory have other copyright owners and
+ * Some files in the "contrib" directory and some configure-generated
+ * files that are distributed with libpng have other copyright owners and
* are released under other open source licenses.
*
- *
* libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
* Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
* libpng-0.96, and are distributed according to the same disclaimer and
@@ -65,9 +64,6 @@
* Glenn Randers-Pehrson
* Willem van Schaik
*
- * Some files in the "scripts" directory have different copyright owners
- * but are also released under this license.
- *
* libpng versions 0.89, June 1996, through 0.96, May 1997, are
* Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
* and are distributed according to the same disclaimer and license as
@@ -213,11 +209,11 @@
* ...
* 1.0.19 10 10019 10.so.0.19[.0]
* ...
- * 1.2.56 13 10256 12.so.0.56[.0]
+ * 1.2.59 13 10257 12.so.0.59[.0]
* ...
- * 1.5.27 15 10527 15.so.15.27[.0]
+ * 1.5.30 15 10527 15.so.15.30[.0]
* ...
- * 1.6.22 16 10622 16.so.16.22[.0]
+ * 1.6.34 16 10633 16.so.16.34[.0]
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
@@ -238,20 +234,20 @@
*
* See libpng.txt or libpng.3 for more information. The PNG specification
* is available as a W3C Recommendation and as an ISO Specification,
- * <http://www.w3.org/TR/2003/REC-PNG-20031110/
+ * <https://www.w3.org/TR/2003/REC-PNG-20031110/
*/
/*
* Y2K compliance in libpng:
* =========================
*
- * May 26, 2016
+ * September 29, 2017
*
* Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration.
*
* This is your unofficial assurance that libpng from version 0.71 and
- * upward through 1.6.22 are Y2K compliant. It is my belief that
+ * upward through 1.6.34 are Y2K compliant. It is my belief that
* earlier versions were also Y2K compliant.
*
* Libpng only has two year fields. One is a 2-byte unsigned integer
@@ -313,9 +309,8 @@
*/
/* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.6.22"
-#define PNG_HEADER_VERSION_STRING \
- " libpng version 1.6.22 - May 26, 2016\n"
+#define PNG_LIBPNG_VER_STRING "1.6.34"
+#define PNG_HEADER_VERSION_STRING " libpng version 1.6.34 - September 29, 2017\n"
#define PNG_LIBPNG_VER_SONUM 16
#define PNG_LIBPNG_VER_DLLNUM 16
@@ -323,7 +318,7 @@
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 6
-#define PNG_LIBPNG_VER_RELEASE 22
+#define PNG_LIBPNG_VER_RELEASE 34
/* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero:
@@ -354,20 +349,20 @@
* version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release
*/
-#define PNG_LIBPNG_VER 10622 /* 1.6.22 */
+#define PNG_LIBPNG_VER 10634 /* 1.6.34 */
/* Library configuration: these options cannot be changed after
* the library has been built.
*/
#ifndef PNGLCONF_H
- /* If pnglibconf.h is missing, you can
- * copy scripts/pnglibconf.h.prebuilt to pnglibconf.h
- */
+/* If pnglibconf.h is missing, you can
+ * copy scripts/pnglibconf.h.prebuilt to pnglibconf.h
+ */
# include "pnglibconf.h"
#endif
#ifndef PNG_VERSION_INFO_ONLY
- /* Machine specific configuration. */
+/* Machine specific configuration. */
# include "pngconf.h"
#endif
@@ -464,7 +459,7 @@ extern "C" {
/* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number.
*/
-typedef char* png_libpng_version_1_6_22;
+typedef char* png_libpng_version_1_6_34;
/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info.
*
@@ -657,17 +652,17 @@ typedef png_time * * png_timepp;
*/
typedef struct png_unknown_chunk_t
{
- png_byte name[5]; /* Textual chunk name with '\0' terminator */
- png_byte *data; /* Data, should not be modified on read! */
- png_size_t size;
-
- /* On write 'location' must be set using the flag values listed below.
- * Notice that on read it is set by libpng however the values stored have
- * more bits set than are listed below. Always treat the value as a
- * bitmask. On write set only one bit - setting multiple bits may cause the
- * chunk to be written in multiple places.
- */
- png_byte location; /* mode of operation at read time */
+ png_byte name[5]; /* Textual chunk name with '\0' terminator */
+ png_byte *data; /* Data, should not be modified on read! */
+ png_size_t size;
+
+ /* On write 'location' must be set using the flag values listed below.
+ * Notice that on read it is set by libpng however the values stored have
+ * more bits set than are listed below. Always treat the value as a
+ * bitmask. On write set only one bit - setting multiple bits may cause the
+ * chunk to be written in multiple places.
+ */
+ png_byte location; /* mode of operation at read time */
}
png_unknown_chunk;
@@ -781,6 +776,7 @@ typedef png_unknown_chunk * * png_unknown_chunkpp;
#define PNG_INFO_sPLT 0x2000U /* ESR, 1.0.6 */
#define PNG_INFO_sCAL 0x4000U /* ESR, 1.0.6 */
#define PNG_INFO_IDAT 0x8000U /* ESR, 1.0.6 */
+#define PNG_INFO_eXIf 0x10000U /* GR-P, 1.6.31 */
/* This is used for the transformation routines, as some of them
* change these values for the row. It also should enable using
@@ -1793,7 +1789,8 @@ PNG_EXPORT(99, void, png_data_freer, (png_const_structrp png_ptr,
#define PNG_FREE_PLTE 0x1000U
#define PNG_FREE_TRNS 0x2000U
#define PNG_FREE_TEXT 0x4000U
-#define PNG_FREE_ALL 0x7fffU
+#define PNG_FREE_EXIF 0x8000U /* Added at libpng-1.6.31 */
+#define PNG_FREE_ALL 0xffffU
#define PNG_FREE_MUL 0x4220U /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
#ifdef PNG_USER_MEM_SUPPORTED
@@ -2012,6 +2009,18 @@ PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_const_structrp png_ptr,
png_fixed_point int_blue_Z))
#endif
+#ifdef PNG_eXIf_SUPPORTED
+PNG_EXPORT(246, png_uint_32, png_get_eXIf, (png_const_structrp png_ptr,
+ png_inforp info_ptr, png_bytep *exif));
+PNG_EXPORT(247, void, png_set_eXIf, (png_const_structrp png_ptr,
+ png_inforp info_ptr, const png_bytep exif));
+
+PNG_EXPORT(248, png_uint_32, png_get_eXIf_1, (png_const_structrp png_ptr,
+ png_const_inforp info_ptr, png_uint_32 *num_exif, png_bytep *exif));
+PNG_EXPORT(249, void, png_set_eXIf_1, (png_const_structrp png_ptr,
+ png_inforp info_ptr, const png_uint_32 num_exif, const png_bytep exif));
+#endif
+
#ifdef PNG_gAMA_SUPPORTED
PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, (png_const_structrp png_ptr,
png_const_inforp info_ptr, double *file_gamma))
@@ -2030,9 +2039,6 @@ PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_const_structrp png_ptr,
#ifdef PNG_hIST_SUPPORTED
PNG_EXPORT(141, png_uint_32, png_get_hIST, (png_const_structrp png_ptr,
png_inforp info_ptr, png_uint_16p *hist));
-#endif
-
-#ifdef PNG_hIST_SUPPORTED
PNG_EXPORT(142, void, png_set_hIST, (png_const_structrp png_ptr,
png_inforp info_ptr, png_const_uint_16p hist));
#endif
@@ -2300,8 +2306,10 @@ PNG_EXPORT(171, void, png_set_sCAL_s, (png_const_structrp png_ptr,
* except for the IHDR, PLTE, tRNS, IDAT, and IEND chunks (which continue to
* be processed by libpng.
*/
+#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
PNG_EXPORT(172, void, png_set_keep_unknown_chunks, (png_structrp png_ptr,
int keep, png_const_bytep chunk_list, int num_chunks));
+#endif /* HANDLE_AS_UNKNOWN */
/* The "keep" PNG_HANDLE_CHUNK_ parameter for the specified chunk is returned;
* the result is therefore true (non-zero) if special handling is required,
@@ -2309,7 +2317,7 @@ PNG_EXPORT(172, void, png_set_keep_unknown_chunks, (png_structrp png_ptr,
*/
PNG_EXPORT(173, int, png_handle_as_unknown, (png_const_structrp png_ptr,
png_const_bytep chunk_name));
-#endif
+#endif /* SET_UNKNOWN_CHUNKS */
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
PNG_EXPORT(174, void, png_set_unknown_chunks, (png_const_structrp png_ptr,
@@ -2530,33 +2538,37 @@ PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type,
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
-# define png_composite(composite, fg, alpha, bg) \
- { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \
- * (png_uint_16)(alpha) \
- + (png_uint_16)(bg)*(png_uint_16)(255 \
- - (png_uint_16)(alpha)) + 128); \
- (composite) = (png_byte)(((temp + (temp >> 8)) >> 8) & 0xff); }
-
-# define png_composite_16(composite, fg, alpha, bg) \
- { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \
- * (png_uint_32)(alpha) \
- + (png_uint_32)(bg)*(65535 \
- - (png_uint_32)(alpha)) + 32768); \
- (composite) = (png_uint_16)(0xffff & ((temp + (temp >> 16)) >> 16)); }
+# define png_composite(composite, fg, alpha, bg) \
+ { \
+ png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \
+ * (png_uint_16)(alpha) \
+ + (png_uint_16)(bg)*(png_uint_16)(255 \
+ - (png_uint_16)(alpha)) + 128); \
+ (composite) = (png_byte)(((temp + (temp >> 8)) >> 8) & 0xff); \
+ }
+
+# define png_composite_16(composite, fg, alpha, bg) \
+ { \
+ png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \
+ * (png_uint_32)(alpha) \
+ + (png_uint_32)(bg)*(65535 \
+ - (png_uint_32)(alpha)) + 32768); \
+ (composite) = (png_uint_16)(0xffff & ((temp + (temp >> 16)) >> 16)); \
+ }
#else /* Standard method using integer division */
-# define png_composite(composite, fg, alpha, bg) \
- (composite) = \
- (png_byte)(0xff & (((png_uint_16)(fg) * (png_uint_16)(alpha) + \
- (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
- 127) / 255))
-
-# define png_composite_16(composite, fg, alpha, bg) \
- (composite) = \
- (png_uint_16)(0xffff & (((png_uint_32)(fg) * (png_uint_32)(alpha) + \
- (png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) + \
- 32767) / 65535))
+# define png_composite(composite, fg, alpha, bg) \
+ (composite) = \
+ (png_byte)(0xff & (((png_uint_16)(fg) * (png_uint_16)(alpha) + \
+ (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
+ 127) / 255))
+
+# define png_composite_16(composite, fg, alpha, bg) \
+ (composite) = \
+ (png_uint_16)(0xffff & (((png_uint_32)(fg) * (png_uint_32)(alpha) + \
+ (png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) + \
+ 32767) / 65535))
#endif /* READ_COMPOSITE_NODIV */
#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
@@ -2592,38 +2604,38 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i));
* format for negative values, which is almost certainly true.
*/
# define PNG_get_uint_32(buf) \
- (((png_uint_32)(*(buf)) << 24) + \
- ((png_uint_32)(*((buf) + 1)) << 16) + \
- ((png_uint_32)(*((buf) + 2)) << 8) + \
- ((png_uint_32)(*((buf) + 3))))
+ (((png_uint_32)(*(buf)) << 24) + \
+ ((png_uint_32)(*((buf) + 1)) << 16) + \
+ ((png_uint_32)(*((buf) + 2)) << 8) + \
+ ((png_uint_32)(*((buf) + 3))))
/* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
* function) incorrectly returned a value of type png_uint_32.
*/
# define PNG_get_uint_16(buf) \
- ((png_uint_16) \
- (((unsigned int)(*(buf)) << 8) + \
- ((unsigned int)(*((buf) + 1)))))
+ ((png_uint_16) \
+ (((unsigned int)(*(buf)) << 8) + \
+ ((unsigned int)(*((buf) + 1)))))
# define PNG_get_int_32(buf) \
- ((png_int_32)((*(buf) & 0x80) \
- ? -((png_int_32)(((png_get_uint_32(buf)^0xffffffffU)+1U)&0x7fffffffU)) \
- : (png_int_32)png_get_uint_32(buf)))
+ ((png_int_32)((*(buf) & 0x80) \
+ ? -((png_int_32)(((png_get_uint_32(buf)^0xffffffffU)+1U)&0x7fffffffU)) \
+ : (png_int_32)png_get_uint_32(buf)))
- /* If PNG_PREFIX is defined the same thing as below happens in pnglibconf.h,
- * but defining a macro name prefixed with PNG_PREFIX.
- */
+/* If PNG_PREFIX is defined the same thing as below happens in pnglibconf.h,
+ * but defining a macro name prefixed with PNG_PREFIX.
+ */
# ifndef PNG_PREFIX
-# define png_get_uint_32(buf) PNG_get_uint_32(buf)
-# define png_get_uint_16(buf) PNG_get_uint_16(buf)
-# define png_get_int_32(buf) PNG_get_int_32(buf)
+# define png_get_uint_32(buf) PNG_get_uint_32(buf)
+# define png_get_uint_16(buf) PNG_get_uint_16(buf)
+# define png_get_int_32(buf) PNG_get_int_32(buf)
# endif
#else
# ifdef PNG_PREFIX
- /* No macros; revert to the (redefined) function */
-# define PNG_get_uint_32 (png_get_uint_32)
-# define PNG_get_uint_16 (png_get_uint_16)
-# define PNG_get_int_32 (png_get_int_32)
+ /* No macros; revert to the (redefined) function */
+# define PNG_get_uint_32 (png_get_uint_32)
+# define PNG_get_uint_16 (png_get_uint_16)
+# define PNG_get_int_32 (png_get_int_32)
# endif
#endif
@@ -2752,7 +2764,7 @@ typedef struct
*
* When the simplified API needs to convert between sRGB and linear colorspaces,
* the actual sRGB transfer curve defined in the sRGB specification (see the
- * article at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
+ * article at https://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
* approximation used elsewhere in libpng.
*
* When an alpha channel is present it is expected to denote pixel coverage
@@ -2807,6 +2819,8 @@ typedef struct
# define PNG_FORMAT_FLAG_AFIRST 0x20U /* alpha channel comes first */
#endif
+#define PNG_FORMAT_FLAG_ASSOCIATED_ALPHA 0x40U /* alpha channel is associated */
+
/* Commonly used formats have predefined macros.
*
* First the single byte (sRGB) formats:
@@ -3171,9 +3185,9 @@ PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory,
#define PNG_IMAGE_PNG_SIZE_MAX_(image, image_size)\
((8U/*sig*/+25U/*IHDR*/+16U/*gAMA*/+44U/*cHRM*/+12U/*IEND*/+\
(((image).format&PNG_FORMAT_FLAG_COLORMAP)?/*colormap: PLTE, tRNS*/\
- 12U+3U*(image).colormap_entries/*PLTE data*/+\
- (((image).format&PNG_FORMAT_FLAG_ALPHA)?\
- 12U/*tRNS*/+(image).colormap_entries:0U):0U)+\
+ 12U+3U*(image).colormap_entries/*PLTE data*/+\
+ (((image).format&PNG_FORMAT_FLAG_ALPHA)?\
+ 12U/*tRNS*/+(image).colormap_entries:0U):0U)+\
12U)+(12U*((image_size)/PNG_ZBUF_SIZE))/*IDAT*/+(image_size))
/* A helper for the following macro; if your compiler cannot handle the
* following macro use this one with the result of
@@ -3221,7 +3235,14 @@ PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory,
#endif
#define PNG_MAXIMUM_INFLATE_WINDOW 2 /* SOFTWARE: force maximum window */
#define PNG_SKIP_sRGB_CHECK_PROFILE 4 /* SOFTWARE: Check ICC profile for sRGB */
-#define PNG_OPTION_NEXT 6 /* Next option - numbers must be even */
+#ifdef PNG_MIPS_MSA_API_SUPPORTED
+# define PNG_MIPS_MSA 6 /* HARDWARE: MIPS Msa SIMD instructions supported */
+#endif
+#define PNG_IGNORE_ADLER32 8
+#ifdef PNG_POWERPC_VSX_API_SUPPORTED
+# define PNG_POWERPC_VSX 10 /* HARDWARE: PowerPC VSX SIMD instructions supported */
+#endif
+#define PNG_OPTION_NEXT 12 /* Next option - numbers must be even */
/* Return values: NOTE: there are four values and 'off' is *not* zero */
#define PNG_OPTION_UNSET 0 /* Unset - defaults to off */
@@ -3245,7 +3266,7 @@ PNG_EXPORT(244, int, png_set_option, (png_structrp png_ptr, int option,
* one to use is one more than this.)
*/
#ifdef PNG_EXPORT_LAST_ORDINAL
- PNG_EXPORT_LAST_ORDINAL(245);
+ PNG_EXPORT_LAST_ORDINAL(249);
#endif
#ifdef __cplusplus
diff --git a/third_party/libpng16/pngconf.h b/third_party/libpng16/pngconf.h
index 0cabe4b385..d13b13e57a 100644
--- a/third_party/libpng16/pngconf.h
+++ b/third_party/libpng16/pngconf.h
@@ -1,9 +1,9 @@
/* pngconf.h - machine configurable file for libpng
*
- * libpng version 1.6.22, May 26, 2016
+ * libpng version 1.6.34, September 29, 2017
*
- * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2002,2004,2006-2016 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.)
*
@@ -188,27 +188,27 @@
* compatible with GCC or Visual C because of different calling conventions.
*/
# if PNG_API_RULE == 2
- /* If this line results in an error, either because __watcall is not
- * understood or because of a redefine just below you cannot use *this*
- * build of the library with the compiler you are using. *This* build was
- * build using Watcom and applications must also be built using Watcom!
- */
+ /* If this line results in an error, either because __watcall is not
+ * understood or because of a redefine just below you cannot use *this*
+ * build of the library with the compiler you are using. *This* build was
+ * build using Watcom and applications must also be built using Watcom!
+ */
# define PNGCAPI __watcall
# endif
# if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800))
# define PNGCAPI __cdecl
# if PNG_API_RULE == 1
- /* If this line results in an error __stdcall is not understood and
- * PNG_API_RULE should not have been set to '1'.
- */
+ /* If this line results in an error __stdcall is not understood and
+ * PNG_API_RULE should not have been set to '1'.
+ */
# define PNGAPI __stdcall
# endif
# else
- /* An older compiler, or one not detected (erroneously) above,
- * if necessary override on the command line to get the correct
- * variants for the compiler.
- */
+ /* An older compiler, or one not detected (erroneously) above,
+ * if necessary override on the command line to get the correct
+ * variants for the compiler.
+ */
# ifndef PNGCAPI
# define PNGCAPI _cdecl
# endif
@@ -225,10 +225,10 @@
# if (defined(_MSC_VER) && _MSC_VER < 800) ||\
(defined(__BORLANDC__) && __BORLANDC__ < 0x500)
- /* older Borland and MSC
- * compilers used '__export' and required this to be after
- * the type.
- */
+ /* older Borland and MSC
+ * compilers used '__export' and required this to be after
+ * the type.
+ */
# ifndef PNG_EXPORT_TYPE
# define PNG_EXPORT_TYPE(type) type PNG_IMPEXP
# endif
@@ -244,9 +244,9 @@
# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
# define PNGAPI _System
# else /* !Windows/x86 && !OS/2 */
- /* Use the defaults, or define PNG*API on the command line (but
- * this will have to be done for every compile!)
- */
+ /* Use the defaults, or define PNG*API on the command line (but
+ * this will have to be done for every compile!)
+ */
# endif /* other system, !OS/2 */
#endif /* !Windows/x86 */
@@ -267,7 +267,7 @@
*/
#ifndef PNG_IMPEXP
# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT)
- /* This forces use of a DLL, disallowing static linking */
+ /* This forces use of a DLL, disallowing static linking */
# define PNG_IMPEXP PNG_DLL_IMPORT
# endif
@@ -340,7 +340,7 @@
* less efficient code.
*/
# if defined(__clang__) && defined(__has_attribute)
- /* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */
+ /* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */
# if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__)
# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
# endif
@@ -507,9 +507,9 @@
# error "libpng requires a signed 32-bit (or more) type"
#endif
-#if UINT_MAX > 4294967294
+#if UINT_MAX > 4294967294U
typedef unsigned int png_uint_32;
-#elif ULONG_MAX > 4294967294
+#elif ULONG_MAX > 4294967294U
typedef unsigned long int png_uint_32;
#else
# error "libpng requires an unsigned 32-bit (or more) type"
diff --git a/third_party/libpng16/pngerror.c b/third_party/libpng16/pngerror.c
index 3fc8092fa6..ad48bfb986 100644
--- a/third_party/libpng16/pngerror.c
+++ b/third_party/libpng16/pngerror.c
@@ -1,8 +1,8 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
- * Last changed in libpng 1.6.15 [November 20, 2014]
- * Copyright (c) 1998-2002,2004,2006-2014 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.31 [July 27, 2017]
+ * Copyright (c) 1998-2002,2004,2006-2017 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.)
*
@@ -26,7 +26,7 @@ static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr,
#ifdef PNG_WARNINGS_SUPPORTED
static void /* PRIVATE */
png_default_warning PNGARG((png_const_structrp png_ptr,
- png_const_charp warning_message));
+ png_const_charp warning_message));
#endif /* WARNINGS */
/* This function is called whenever there is a fatal error. This function
@@ -37,7 +37,7 @@ png_default_warning PNGARG((png_const_structrp png_ptr,
#ifdef PNG_ERROR_TEXT_SUPPORTED
PNG_FUNCTION(void,PNGAPI
png_error,(png_const_structrp png_ptr, png_const_charp error_message),
- PNG_NORETURN)
+ PNG_NORETURN)
{
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
char msg[16];
@@ -65,18 +65,18 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
else
error_message += offset;
- }
+ }
- else
- {
- if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
+ else
{
- msg[0] = '0';
- msg[1] = '\0';
- error_message = msg;
+ if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
+ {
+ msg[0] = '0';
+ msg[1] = '\0';
+ error_message = msg;
+ }
}
- }
- }
+ }
}
#endif
if (png_ptr != NULL && png_ptr->error_fn != NULL)
@@ -110,7 +110,7 @@ png_err,(png_const_structrp png_ptr),PNG_NORETURN)
*/
size_t
png_safecat(png_charp buffer, size_t bufsize, size_t pos,
- png_const_charp string)
+ png_const_charp string)
{
if (buffer != NULL && pos < bufsize)
{
@@ -131,7 +131,7 @@ png_safecat(png_charp buffer, size_t bufsize, size_t pos,
*/
png_charp
png_format_number(png_const_charp start, png_charp end, int format,
- png_alloc_size_t number)
+ png_alloc_size_t number)
{
int count = 0; /* number of digits output */
int mincount = 1; /* minimum number required */
@@ -163,7 +163,7 @@ png_format_number(png_const_charp start, png_charp end, int format,
case PNG_NUMBER_FORMAT_02u:
/* Expects at least 2 digits. */
mincount = 2;
- /* FALL THROUGH */
+ /* FALLTHROUGH */
case PNG_NUMBER_FORMAT_u:
*--end = digits[number % 10];
@@ -173,7 +173,7 @@ png_format_number(png_const_charp start, png_charp end, int format,
case PNG_NUMBER_FORMAT_02x:
/* This format expects at least two digits */
mincount = 2;
- /* FALL THROUGH */
+ /* FALLTHROUGH */
case PNG_NUMBER_FORMAT_x:
*--end = digits[number & 0xf];
@@ -233,7 +233,7 @@ png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
}
if (png_ptr != NULL && png_ptr->warning_fn != NULL)
(*(png_ptr->warning_fn))(png_constcast(png_structrp,png_ptr),
- warning_message + offset);
+ warning_message + offset);
else
png_default_warning(png_ptr, warning_message + offset);
}
@@ -245,7 +245,7 @@ png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
*/
void
png_warning_parameter(png_warning_parameters p, int number,
- png_const_charp string)
+ png_const_charp string)
{
if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT)
(void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string);
@@ -253,7 +253,7 @@ png_warning_parameter(png_warning_parameters p, int number,
void
png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
- png_alloc_size_t value)
+ png_alloc_size_t value)
{
char buffer[PNG_NUMBER_BUFFER_SIZE];
png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value));
@@ -261,7 +261,7 @@ png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
void
png_warning_parameter_signed(png_warning_parameters p, int number, int format,
- png_int_32 value)
+ png_int_32 value)
{
png_alloc_size_t u;
png_charp str;
@@ -282,7 +282,7 @@ png_warning_parameter_signed(png_warning_parameters p, int number, int format,
void
png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p,
- png_const_charp message)
+ png_const_charp message)
{
/* The internal buffer is just 192 bytes - enough for all our messages,
* overflow doesn't happen because this code checks! If someone figures
@@ -391,10 +391,10 @@ png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
void /* PRIVATE */
png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
{
- if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)
- png_warning(png_ptr, error_message);
- else
- png_error(png_ptr, error_message);
+ if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)
+ png_warning(png_ptr, error_message);
+ else
+ png_error(png_ptr, error_message);
# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message)
@@ -404,10 +404,10 @@ png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
void /* PRIVATE */
png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
{
- if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0)
- png_warning(png_ptr, error_message);
- else
- png_error(png_ptr, error_message);
+ if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0)
+ png_warning(png_ptr, error_message);
+ else
+ png_error(png_ptr, error_message);
# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message)
@@ -478,7 +478,7 @@ png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
PNG_FUNCTION(void,PNGAPI
png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message),
- PNG_NORETURN)
+ PNG_NORETURN)
{
char msg[18+PNG_MAX_ERROR_TEXT];
if (png_ptr == NULL)
@@ -573,7 +573,7 @@ png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN)
{
# define fixed_message "fixed point overflow in "
# define fixed_message_ln ((sizeof fixed_message)-1)
- int iin;
+ unsigned int iin;
char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
memcpy(msg, fixed_message, fixed_message_ln);
iin = 0;
@@ -620,7 +620,7 @@ png_set_longjmp_fn(png_structrp png_ptr, png_longjmp_ptr longjmp_fn,
else
{
png_ptr->jmp_buf_ptr = png_voidcast(jmp_buf *,
- png_malloc_warn(png_ptr, jmp_buf_size));
+ png_malloc_warn(png_ptr, jmp_buf_size));
if (png_ptr->jmp_buf_ptr == NULL)
return NULL; /* new NULL return on OOM */
@@ -709,7 +709,7 @@ png_free_jmpbuf(png_structrp png_ptr)
*/
static PNG_FUNCTION(void /* PRIVATE */,
png_default_error,(png_const_structrp png_ptr, png_const_charp error_message),
- PNG_NORETURN)
+ PNG_NORETURN)
{
#ifdef PNG_CONSOLE_IO_SUPPORTED
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
@@ -883,7 +883,7 @@ png_set_strip_error_numbers(png_structrp png_ptr, png_uint_32 strip_mode)
*/
PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI
png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
- PNG_NORETURN)
+ PNG_NORETURN)
{
const png_const_structrp png_ptr = png_nonconst_ptr;
png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
@@ -906,7 +906,7 @@ png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
/* Missing longjmp buffer, the following is to help debugging: */
{
size_t pos = png_safecat(image->message, (sizeof image->message), 0,
- "bad longjmp: ");
+ "bad longjmp: ");
png_safecat(image->message, (sizeof image->message), pos,
error_message);
}
diff --git a/third_party/libpng16/pngget.c b/third_party/libpng16/pngget.c
index 14fc7be520..26e9fb1c35 100644
--- a/third_party/libpng16/pngget.c
+++ b/third_party/libpng16/pngget.c
@@ -1,8 +1,8 @@
/* pngget.c - retrieval of values from info struct
*
- * Last changed in libpng 1.6.17 [March 26, 2015]
- * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.32 [August 24, 2017]
+ * Copyright (c) 1998-2002,2004,2006-2017 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.)
*
@@ -338,7 +338,7 @@ ppi_from_ppm(png_uint_32 ppm)
png_fixed_point result;
if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
5000) != 0)
- return result;
+ return (png_uint_32)result;
/* Overflow. */
return 0;
@@ -486,7 +486,7 @@ png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
#ifdef PNG_bKGD_SUPPORTED
png_uint_32 PNGAPI
png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
- png_color_16p *background)
+ png_color_16p *background)
{
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_bKGD) != 0 &&
@@ -526,28 +526,28 @@ png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
if (white_x != NULL)
*white_x = png_float(png_ptr,
- info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
+ info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
if (white_y != NULL)
*white_y = png_float(png_ptr,
- info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
+ info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
if (red_x != NULL)
*red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
- "cHRM red X");
+ "cHRM red X");
if (red_y != NULL)
*red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
- "cHRM red Y");
+ "cHRM red Y");
if (green_x != NULL)
*green_x = png_float(png_ptr,
- info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
+ info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
if (green_y != NULL)
*green_y = png_float(png_ptr,
- info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
+ info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
if (blue_x != NULL)
*blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
- "cHRM blue X");
+ "cHRM blue X");
if (blue_y != NULL)
*blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
- "cHRM blue Y");
+ "cHRM blue Y");
return (PNG_INFO_cHRM);
}
@@ -556,42 +556,42 @@ png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_uint_32 PNGAPI
png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
- double *red_X, double *red_Y, double *red_Z, double *green_X,
- double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
- double *blue_Z)
+ double *red_X, double *red_Y, double *red_Z, double *green_X,
+ double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
+ double *blue_Z)
{
if (png_ptr != NULL && info_ptr != NULL &&
- (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
+ (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
{
png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
if (red_X != NULL)
*red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
- "cHRM red X");
+ "cHRM red X");
if (red_Y != NULL)
*red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
- "cHRM red Y");
+ "cHRM red Y");
if (red_Z != NULL)
*red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
- "cHRM red Z");
+ "cHRM red Z");
if (green_X != NULL)
*green_X = png_float(png_ptr,
- info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
+ info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
if (green_Y != NULL)
*green_Y = png_float(png_ptr,
- info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
+ info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
if (green_Z != NULL)
*green_Z = png_float(png_ptr,
- info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
+ info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
if (blue_X != NULL)
*blue_X = png_float(png_ptr,
- info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
+ info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
if (blue_Y != NULL)
*blue_Y = png_float(png_ptr,
- info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
+ info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
if (blue_Z != NULL)
*blue_Z = png_float(png_ptr,
- info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
+ info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
return (PNG_INFO_cHRM);
}
@@ -681,8 +681,8 @@ png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_debug1(1, "in %s retrieval function", "gAMA");
if (png_ptr != NULL && info_ptr != NULL &&
- (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
- file_gamma != NULL)
+ (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
+ file_gamma != NULL)
{
*file_gamma = info_ptr->colorspace.gamma;
return (PNG_INFO_gAMA);
@@ -704,7 +704,7 @@ png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
file_gamma != NULL)
{
*file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
- "png_get_gAMA");
+ "png_get_gAMA");
return (PNG_INFO_gAMA);
}
@@ -773,6 +773,35 @@ png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
}
#endif
+#ifdef PNG_eXIf_SUPPORTED
+png_uint_32 PNGAPI
+png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
+ png_bytep *exif)
+{
+ png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1");
+ PNG_UNUSED(info_ptr)
+ PNG_UNUSED(exif)
+ return 0;
+}
+
+png_uint_32 PNGAPI
+png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr,
+ png_uint_32 *num_exif, png_bytep *exif)
+{
+ png_debug1(1, "in %s retrieval function", "eXIf");
+
+ if (png_ptr != NULL && info_ptr != NULL &&
+ (info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL)
+ {
+ *num_exif = info_ptr->num_exif;
+ *exif = info_ptr->exif;
+ return (PNG_INFO_eXIf);
+ }
+
+ return (0);
+}
+#endif
+
#ifdef PNG_hIST_SUPPORTED
png_uint_32 PNGAPI
png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
@@ -901,7 +930,7 @@ png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
*/
*width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
*height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
- "sCAL height");
+ "sCAL height");
return (PNG_INFO_sCAL);
}
diff --git a/third_party/libpng16/pnginfo.h b/third_party/libpng16/pnginfo.h
index 361ed8be70..d5f6149dbd 100644
--- a/third_party/libpng16/pnginfo.h
+++ b/third_party/libpng16/pnginfo.h
@@ -185,6 +185,14 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
#endif
+#ifdef PNG_eXIf_SUPPORTED
+ int num_exif; /* Added at libpng-1.6.31 */
+ png_bytep exif;
+# ifdef PNG_READ_eXIf_SUPPORTED
+ png_bytep eXIf_buf; /* Added at libpng-1.6.32 */
+# endif
+#endif
+
#ifdef PNG_hIST_SUPPORTED
/* The hIST chunk contains the relative frequency or importance of the
* various palette entries, so that a viewer can intelligently select a
diff --git a/third_party/libpng16/pnglibconf.h b/third_party/libpng16/pnglibconf.h
index adf4238ff7..308c606537 100644
--- a/third_party/libpng16/pnglibconf.h
+++ b/third_party/libpng16/pnglibconf.h
@@ -1,8 +1,8 @@
-/* libpng 1.6.20 STANDARD API DEFINITION */
+/* libpng 1.6.22 CUSTOM API DEFINITION */
/* pnglibconf.h - library build configuration */
-/* Libpng version 1.6.20 - December 3, 2015 */
+/* Libpng version 1.6.22 - May 29, 2016 */
/* Copyright (c) 1998-2015 Glenn Randers-Pehrson */
@@ -11,11 +11,12 @@
/* and license in png.h */
/* pnglibconf.h */
-/* Machine generated file: DO NOT EDIT */
/* Derived from: scripts/pnglibconf.dfa */
#ifndef PNGLCONF_H
#define PNGLCONF_H
-/* options */
+
+/* default options */
+/* These are PNG options that match the default in scripts/pnglibconf.dfa */
#define PNG_16BIT_SUPPORTED
#define PNG_ALIGNED_MEMORY_SUPPORTED
/*#undef PNG_ARM_NEON_API_SUPPORTED*/
@@ -23,11 +24,7 @@
#define PNG_BENIGN_ERRORS_SUPPORTED
#define PNG_BENIGN_READ_ERRORS_SUPPORTED
/*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/
-#define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
-#define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
#define PNG_COLORSPACE_SUPPORTED
-#define PNG_CONSOLE_IO_SUPPORTED
-#define PNG_CONVERT_tIME_SUPPORTED
#define PNG_EASY_ACCESS_SUPPORTED
/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/
#define PNG_ERROR_TEXT_SUPPORTED
@@ -37,12 +34,8 @@
#define PNG_FORMAT_AFIRST_SUPPORTED
#define PNG_FORMAT_BGR_SUPPORTED
#define PNG_GAMMA_SUPPORTED
-#define PNG_GET_PALETTE_MAX_SUPPORTED
#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
-#define PNG_INCH_CONVERSIONS_SUPPORTED
#define PNG_INFO_IMAGE_SUPPORTED
-#define PNG_IO_STATE_SUPPORTED
-#define PNG_MNG_FEATURES_SUPPORTED
#define PNG_POINTER_INDEXING_SUPPORTED
#define PNG_PROGRESSIVE_READ_SUPPORTED
#define PNG_READ_16BIT_SUPPORTED
@@ -50,23 +43,17 @@
#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
#define PNG_READ_BACKGROUND_SUPPORTED
#define PNG_READ_BGR_SUPPORTED
-#define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
#define PNG_READ_COMPOSITE_NODIV_SUPPORTED
#define PNG_READ_COMPRESSED_TEXT_SUPPORTED
#define PNG_READ_EXPAND_16_SUPPORTED
#define PNG_READ_EXPAND_SUPPORTED
#define PNG_READ_FILLER_SUPPORTED
#define PNG_READ_GAMMA_SUPPORTED
-#define PNG_READ_GET_PALETTE_MAX_SUPPORTED
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
#define PNG_READ_INTERLACING_SUPPORTED
#define PNG_READ_INT_FUNCTIONS_SUPPORTED
-#define PNG_READ_INVERT_ALPHA_SUPPORTED
-#define PNG_READ_INVERT_SUPPORTED
-#define PNG_READ_OPT_PLTE_SUPPORTED
#define PNG_READ_PACKSWAP_SUPPORTED
#define PNG_READ_PACK_SUPPORTED
-#define PNG_READ_QUANTIZE_SUPPORTED
#define PNG_READ_RGB_TO_GRAY_SUPPORTED
#define PNG_READ_SCALE_16_TO_8_SUPPORTED
#define PNG_READ_SHIFT_SUPPORTED
@@ -80,28 +67,17 @@
#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_READ_USER_CHUNKS_SUPPORTED
#define PNG_READ_USER_TRANSFORM_SUPPORTED
-#define PNG_READ_bKGD_SUPPORTED
#define PNG_READ_cHRM_SUPPORTED
#define PNG_READ_gAMA_SUPPORTED
-#define PNG_READ_hIST_SUPPORTED
#define PNG_READ_iCCP_SUPPORTED
-#define PNG_READ_iTXt_SUPPORTED
-#define PNG_READ_oFFs_SUPPORTED
-#define PNG_READ_pCAL_SUPPORTED
-#define PNG_READ_pHYs_SUPPORTED
-#define PNG_READ_sBIT_SUPPORTED
-#define PNG_READ_sCAL_SUPPORTED
-#define PNG_READ_sPLT_SUPPORTED
#define PNG_READ_sRGB_SUPPORTED
#define PNG_READ_tEXt_SUPPORTED
-#define PNG_READ_tIME_SUPPORTED
#define PNG_READ_tRNS_SUPPORTED
#define PNG_READ_zTXt_SUPPORTED
#define PNG_SAVE_INT_32_SUPPORTED
#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_SEQUENTIAL_READ_SUPPORTED
#define PNG_SETJMP_SUPPORTED
-#define PNG_SET_OPTION_SUPPORTED
#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_SET_USER_LIMITS_SUPPORTED
#define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
@@ -109,11 +85,11 @@
#define PNG_SIMPLIFIED_READ_SUPPORTED
#define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
#define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
+#define PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
#define PNG_SIMPLIFIED_WRITE_SUPPORTED
#define PNG_STDIO_SUPPORTED
#define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_TEXT_SUPPORTED
-#define PNG_TIME_RFC1123_SUPPORTED
#define PNG_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_USER_CHUNKS_SUPPORTED
#define PNG_USER_LIMITS_SUPPORTED
@@ -124,19 +100,14 @@
#define PNG_WRITE_16BIT_SUPPORTED
#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
#define PNG_WRITE_BGR_SUPPORTED
-#define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
#define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
#define PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED
#define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
#define PNG_WRITE_FILLER_SUPPORTED
#define PNG_WRITE_FILTER_SUPPORTED
#define PNG_WRITE_FLUSH_SUPPORTED
-#define PNG_WRITE_GET_PALETTE_MAX_SUPPORTED
#define PNG_WRITE_INTERLACING_SUPPORTED
#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED
-#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
-#define PNG_WRITE_INVERT_SUPPORTED
-#define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
#define PNG_WRITE_PACKSWAP_SUPPORTED
#define PNG_WRITE_PACK_SUPPORTED
#define PNG_WRITE_SHIFT_SUPPORTED
@@ -148,42 +119,79 @@
#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_WRITE_USER_TRANSFORM_SUPPORTED
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
-#define PNG_WRITE_bKGD_SUPPORTED
#define PNG_WRITE_cHRM_SUPPORTED
#define PNG_WRITE_gAMA_SUPPORTED
-#define PNG_WRITE_hIST_SUPPORTED
#define PNG_WRITE_iCCP_SUPPORTED
-#define PNG_WRITE_iTXt_SUPPORTED
-#define PNG_WRITE_oFFs_SUPPORTED
-#define PNG_WRITE_pCAL_SUPPORTED
-#define PNG_WRITE_pHYs_SUPPORTED
-#define PNG_WRITE_sBIT_SUPPORTED
-#define PNG_WRITE_sCAL_SUPPORTED
-#define PNG_WRITE_sPLT_SUPPORTED
#define PNG_WRITE_sRGB_SUPPORTED
#define PNG_WRITE_tEXt_SUPPORTED
-#define PNG_WRITE_tIME_SUPPORTED
#define PNG_WRITE_tRNS_SUPPORTED
#define PNG_WRITE_zTXt_SUPPORTED
-#define PNG_bKGD_SUPPORTED
#define PNG_cHRM_SUPPORTED
#define PNG_gAMA_SUPPORTED
-#define PNG_hIST_SUPPORTED
#define PNG_iCCP_SUPPORTED
-#define PNG_iTXt_SUPPORTED
-#define PNG_oFFs_SUPPORTED
-#define PNG_pCAL_SUPPORTED
-#define PNG_pHYs_SUPPORTED
#define PNG_sBIT_SUPPORTED
-#define PNG_sCAL_SUPPORTED
-#define PNG_sPLT_SUPPORTED
#define PNG_sRGB_SUPPORTED
#define PNG_tEXt_SUPPORTED
-#define PNG_tIME_SUPPORTED
#define PNG_tRNS_SUPPORTED
#define PNG_zTXt_SUPPORTED
/* end of options */
-/* settings */
+
+/* chromium options */
+/* These are PNG options that chromium chooses to explicitly disable */
+/*#undef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED*/
+/*#undef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED*/
+/*#undef PNG_CONSOLE_IO_SUPPORTED*/
+/*#undef PNG_CONVERT_tIME_SUPPORTED*/
+/*#undef PNG_GET_PALETTE_MAX_SUPPORTED*/
+/*#undef PNG_INCH_CONVERSIONS_SUPPORTED*/
+/*#undef PNG_IO_STATE_SUPPORTED*/
+/*#undef PNG_MNG_FEATURES_SUPPORTED*/
+/*#undef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED*/
+/*#undef PNG_READ_GET_PALETTE_MAX_SUPPORTED*/
+/*#undef PNG_READ_INVERT_ALPHA_SUPPORTED*/
+/*#undef PNG_READ_INVERT_SUPPORTED*/
+/*#undef PNG_READ_OPT_PLTE_SUPPORTED*/
+/*#undef PNG_READ_QUANTIZE_SUPPORTED*/
+/*#undef PNG_READ_bKGD_SUPPORTED*/
+/*#undef PNG_READ_hIST_SUPPORTED*/
+/*#undef PNG_READ_iTXt_SUPPORTED*/
+/*#undef PNG_READ_oFFs_SUPPORTED*/
+/*#undef PNG_READ_pCAL_SUPPORTED*/
+/*#undef PNG_READ_pHYs_SUPPORTED*/
+/*#undef PNG_READ_sBIT_SUPPORTED*/
+/*#undef PNG_READ_sCAL_SUPPORTED*/
+/*#undef PNG_READ_sPLT_SUPPORTED*/
+/*#undef PNG_READ_tIME_SUPPORTED*/
+/*#undef PNG_SET_OPTION_SUPPORTED*/
+/*#undef PNG_TIME_RFC1123_SUPPORTED*/
+/*#undef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED*/
+/*#undef PNG_WRITE_GET_PALETTE_MAX_SUPPORTED*/
+/*#undef PNG_WRITE_INVERT_ALPHA_SUPPORTED*/
+/*#undef PNG_WRITE_INVERT_SUPPORTED*/
+/*#undef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED*/
+/*#undef PNG_WRITE_bKGD_SUPPORTED*/
+/*#undef PNG_WRITE_hIST_SUPPORTED*/
+/*#undef PNG_WRITE_iTXt_SUPPORTED*/
+/*#undef PNG_WRITE_oFFs_SUPPORTED*/
+/*#undef PNG_WRITE_pCAL_SUPPORTED*/
+/*#undef PNG_WRITE_pHYs_SUPPORTED*/
+/*#undef PNG_WRITE_sBIT_SUPPORTED*/
+/*#undef PNG_WRITE_sCAL_SUPPORTED*/
+/*#undef PNG_WRITE_sPLT_SUPPORTED*/
+/*#undef PNG_WRITE_tIME_SUPPORTED*/
+/*#undef PNG_bKGD_SUPPORTED*/
+/*#undef PNG_hIST_SUPPORTED*/
+/*#undef PNG_iTXt_SUPPORTED*/
+/*#undef PNG_oFFs_SUPPORTED*/
+/*#undef PNG_pCAL_SUPPORTED*/
+/*#undef PNG_pHYs_SUPPORTED*/
+/*#undef PNG_sCAL_SUPPORTED*/
+/*#undef PNG_sPLT_SUPPORTED*/
+/*#undef PNG_tIME_SUPPORTED*/
+/* end of chromium options */
+
+/* default settings */
+/* These are PNG settings that match the default in scripts/pnglibconf.dfa */
#define PNG_API_RULE 0
#define PNG_DEFAULT_READ_MACROS 1
#define PNG_GAMMA_THRESHOLD_FIXED 5000
@@ -199,8 +207,6 @@
#define PNG_QUANTIZE_RED_BITS 5
#define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1)
#define PNG_TEXT_Z_DEFAULT_STRATEGY 0
-#define PNG_USER_CHUNK_CACHE_MAX 1000
-#define PNG_USER_CHUNK_MALLOC_MAX 8000000
#define PNG_USER_HEIGHT_MAX 1000000
#define PNG_USER_WIDTH_MAX 1000000
#define PNG_ZBUF_SIZE 8192
@@ -210,5 +216,21 @@
#define PNG_Z_DEFAULT_STRATEGY 1
#define PNG_sCAL_PRECISION 5
#define PNG_sRGB_PROFILE_CHECKS 2
-/* end of settings */
+/* end of default settings */
+
+/* chromium settings */
+/* These are PNG setting that chromium has modified */
+/* crbug.com/117369 */
+#define PNG_USER_CHUNK_CACHE_MAX 128
+#define PNG_USER_CHUNK_MALLOC_MAX 4000000L
+/* end of chromium settings */
+
+/* pdfium prefixing */
+/*
+ * This is necessary to build multiple copies of libpng. We need this while pdfium builds
+ * its own copy of libpng.
+ */
+#include "pngprefix.h"
+/* end of pdfium prefixing */
+
#endif /* PNGLCONF_H */
diff --git a/third_party/libpng16/pngmem.c b/third_party/libpng16/pngmem.c
index cf815a6f88..0a2f685e4f 100644
--- a/third_party/libpng16/pngmem.c
+++ b/third_party/libpng16/pngmem.c
@@ -1,8 +1,8 @@
/* pngmem.c - stub functions for memory allocation
*
- * Last changed in libpng 1.6.15 [November 20, 2014]
- * Copyright (c) 1998-2002,2004,2006-2014 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.26 [October 20, 2016]
+ * Copyright (c) 1998-2002,2004,2006-2014,2016 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.)
*
@@ -69,7 +69,7 @@ png_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
*/
PNG_FUNCTION(png_voidp /* PRIVATE */,
png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
- PNG_ALLOCATED)
+ PNG_ALLOCATED)
{
/* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS
* allocators have also been removed in 1.6.0, so any 16-bit system now has
@@ -110,9 +110,9 @@ png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
*/
static png_voidp
png_malloc_array_checked(png_const_structrp png_ptr, int nelements,
- size_t element_size)
+ size_t element_size)
{
- png_alloc_size_t req = nelements; /* known to be > 0 */
+ png_alloc_size_t req = (png_alloc_size_t)nelements; /* known to be > 0 */
if (req <= PNG_SIZE_MAX/element_size)
return png_malloc_base(png_ptr, req * element_size);
@@ -123,7 +123,7 @@ png_malloc_array_checked(png_const_structrp png_ptr, int nelements,
PNG_FUNCTION(png_voidp /* PRIVATE */,
png_malloc_array,(png_const_structrp png_ptr, int nelements,
- size_t element_size),PNG_ALLOCATED)
+ size_t element_size),PNG_ALLOCATED)
{
if (nelements <= 0 || element_size == 0)
png_error(png_ptr, "internal error: array alloc");
@@ -133,7 +133,7 @@ png_malloc_array,(png_const_structrp png_ptr, int nelements,
PNG_FUNCTION(png_voidp /* PRIVATE */,
png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
- int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED)
+ int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED)
{
/* These are internal errors: */
if (add_elements <= 0 || element_size == 0 || old_elements < 0 ||
@@ -146,7 +146,7 @@ png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
if (add_elements <= INT_MAX - old_elements)
{
png_voidp new_array = png_malloc_array_checked(png_ptr,
- old_elements+add_elements, element_size);
+ old_elements+add_elements, element_size);
if (new_array != NULL)
{
@@ -157,7 +157,7 @@ png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
memcpy(new_array, old_array, element_size*(unsigned)old_elements);
memset((char*)new_array + element_size*(unsigned)old_elements, 0,
- element_size*(unsigned)add_elements);
+ element_size*(unsigned)add_elements);
return new_array;
}
@@ -190,7 +190,7 @@ png_malloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
#ifdef PNG_USER_MEM_SUPPORTED
PNG_FUNCTION(png_voidp,PNGAPI
png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size),
- PNG_ALLOCATED PNG_DEPRECATED)
+ PNG_ALLOCATED PNG_DEPRECATED)
{
png_voidp ret;
@@ -213,7 +213,7 @@ png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size),
*/
PNG_FUNCTION(png_voidp,PNGAPI
png_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size),
- PNG_ALLOCATED)
+ PNG_ALLOCATED)
{
if (png_ptr != NULL)
{
diff --git a/third_party/libpng16/pngpread.c b/third_party/libpng16/pngpread.c
index a16fcbef3a..fbe361dc34 100644
--- a/third_party/libpng16/pngpread.c
+++ b/third_party/libpng16/pngpread.c
@@ -1,8 +1,8 @@
/* pngpread.c - read a png file in push mode
*
- * Last changed in libpng 1.6.18 [July 23, 2015]
- * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.32 [August 24, 2017]
+ * Copyright (c) 1998-2002,2004,2006-2017 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.)
*
@@ -77,11 +77,11 @@ png_process_data_pause(png_structrp png_ptr, int save)
png_uint_32 PNGAPI
png_process_data_skip(png_structrp png_ptr)
{
- /* TODO: Deprecate and remove this API.
- * Somewhere the implementation of this seems to have been lost,
- * or abandoned. It was only to support some internal back-door access
- * to png_struct) in libpng-1.4.x.
- */
+/* TODO: Deprecate and remove this API.
+ * Somewhere the implementation of this seems to have been lost,
+ * or abandoned. It was only to support some internal back-door access
+ * to png_struct) in libpng-1.4.x.
+ */
png_app_warning(png_ptr,
"png_process_data_skip is not implemented in any current version of libpng");
return 0;
@@ -189,6 +189,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
png_crc_read(png_ptr, chunk_tag, 4);
png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
+ png_check_chunk_length(png_ptr, png_ptr->push_length);
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
}
@@ -410,7 +411,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
{
PNG_PUSH_SAVE_BUFFER_IF_FULL
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length,
- PNG_HANDLE_CHUNK_AS_DEFAULT);
+ PNG_HANDLE_CHUNK_AS_DEFAULT);
}
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
@@ -501,7 +502,10 @@ png_push_save_buffer(png_structrp png_ptr)
png_error(png_ptr, "Insufficient memory for save_buffer");
}
- memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
+ if (old_buffer)
+ memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
+ else if (png_ptr->save_buffer_size)
+ png_error(png_ptr, "save_buffer error");
png_free(png_ptr, old_buffer);
png_ptr->save_buffer_max = new_max;
}
@@ -518,7 +522,7 @@ png_push_save_buffer(png_structrp png_ptr)
void /* PRIVATE */
png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer,
- png_size_t buffer_length)
+ png_size_t buffer_length)
{
png_ptr->current_buffer = buffer;
png_ptr->current_buffer_size = buffer_length;
@@ -621,7 +625,7 @@ png_push_read_IDAT(png_structrp png_ptr)
void /* PRIVATE */
png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
- png_size_t buffer_length)
+ png_size_t buffer_length)
{
/* The caller checks for a non-zero buffer length. */
if (!(buffer_length > 0) || buffer == NULL)
@@ -681,7 +685,12 @@ png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
png_warning(png_ptr, "Truncated compressed data in IDAT");
else
- png_error(png_ptr, "Decompression error in IDAT");
+ {
+ if (ret == Z_DATA_ERROR)
+ png_benign_error(png_ptr, "IDAT: ADLER32 checksum mismatch");
+ else
+ png_error(png_ptr, "Decompression error in IDAT");
+ }
/* Skip the check on unprocessed input */
return;
@@ -779,7 +788,7 @@ png_push_process_row(png_structrp png_ptr)
{
if (png_ptr->pass < 6)
png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,
- png_ptr->transformations);
+ png_ptr->transformations);
switch (png_ptr->pass)
{
@@ -1041,7 +1050,7 @@ png_push_have_row(png_structrp png_ptr, png_bytep row)
{
if (png_ptr->row_fn != NULL)
(*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
- (int)png_ptr->pass);
+ (int)png_ptr->pass);
}
#ifdef PNG_READ_INTERLACING_SUPPORTED
diff --git a/third_party/libpng16/pngprefix.h b/third_party/libpng16/pngprefix.h
index 8eab668297..979484334d 100644
--- a/third_party/libpng16/pngprefix.h
+++ b/third_party/libpng16/pngprefix.h
@@ -9,9 +9,450 @@
// when this version of libpng and chromium's version of it are
// both simultaneously present.
-#define png_get_uint_32 PDFIUM_png_get_uint_32
-#define png_get_uint_16 PDFIUM_png_get_uint_16
+#define png_access_version_number PDFIUM_png_access_version_number
+#define png_app_error PDFIUM_png_app_error
+#define png_app_warning PDFIUM_png_app_warning
+#define png_ascii_from_fixed PDFIUM_png_ascii_from_fixed
+#define png_ascii_from_fp PDFIUM_png_ascii_from_fp
+#define png_benign_error PDFIUM_png_benign_error
+#define png_build_gamma_table PDFIUM_png_build_gamma_table
+#define png_build_grayscale_palette PDFIUM_png_build_grayscale_palette
+#define png_calculate_crc PDFIUM_png_calculate_crc
+#define png_calloc PDFIUM_png_calloc
+#define png_check_IHDR PDFIUM_png_check_IHDR
+#define png_check_chunk_length PDFIUM_png_check_chunk_length
+#define png_check_chunk_name PDFIUM_png_check_chunk_name
+#define png_check_fp_number PDFIUM_png_check_fp_number
+#define png_check_fp_string PDFIUM_png_check_fp_string
+#define png_check_keyword PDFIUM_png_check_keyword
+#define png_chunk_benign_error PDFIUM_png_chunk_benign_error
+#define png_chunk_error PDFIUM_png_chunk_error
+#define png_chunk_report PDFIUM_png_chunk_report
+#define png_chunk_unknown_handling PDFIUM_png_chunk_unknown_handling
+#define png_chunk_warning PDFIUM_png_chunk_warning
+#define png_colorspace_set_ICC PDFIUM_png_colorspace_set_ICC
+#define png_colorspace_set_chromaticities PDFIUM_png_colorspace_set_chromaticities
+#define png_colorspace_set_endpoints PDFIUM_png_colorspace_set_endpoints
+#define png_colorspace_set_gamma PDFIUM_png_colorspace_set_gamma
+#define png_colorspace_set_rgb_coefficients PDFIUM_png_colorspace_set_rgb_coefficients
+#define png_colorspace_set_sRGB PDFIUM_png_colorspace_set_sRGB
+#define png_colorspace_sync PDFIUM_png_colorspace_sync
+#define png_colorspace_sync_info PDFIUM_png_colorspace_sync_info
+#define png_combine_row PDFIUM_png_combine_row
+#define png_compress_IDAT PDFIUM_png_compress_IDAT
+#define png_convert_from_struct_tm PDFIUM_png_convert_from_struct_tm
+#define png_convert_from_time_t PDFIUM_png_convert_from_time_t
+#define png_convert_to_rfc1123 PDFIUM_png_convert_to_rfc1123
+#define png_convert_to_rfc1123_buffer PDFIUM_png_convert_to_rfc1123_buffer
+#define png_crc_error PDFIUM_png_crc_error
+#define png_crc_finish PDFIUM_png_crc_finish
+#define png_crc_read PDFIUM_png_crc_read
+#define png_create_info_struct PDFIUM_png_create_info_struct
+#define png_create_png_struct PDFIUM_png_create_png_struct
+#define png_create_read_struct PDFIUM_png_create_read_struct
+#define png_create_read_struct_2 PDFIUM_png_create_read_struct_2
+#define png_create_write_struct PDFIUM_png_create_write_struct
+#define png_create_write_struct_2 PDFIUM_png_create_write_struct_2
+#define png_data_freer PDFIUM_png_data_freer
+#define png_default_flush PDFIUM_png_default_flush
+#define png_default_read_data PDFIUM_png_default_read_data
+#define png_default_write_data PDFIUM_png_default_write_data
+#define png_destroy_gamma_table PDFIUM_png_destroy_gamma_table
+#define png_destroy_info_struct PDFIUM_png_destroy_info_struct
+#define png_destroy_png_struct PDFIUM_png_destroy_png_struct
+#define png_destroy_read_struct PDFIUM_png_destroy_read_struct
+#define png_destroy_write_struct PDFIUM_png_destroy_write_struct
+#define png_do_bgr PDFIUM_png_do_bgr
+#define png_do_check_palette_indexes PDFIUM_png_do_check_palette_indexes
+#define png_do_chop PDFIUM_png_do_chop
+#define png_do_compose PDFIUM_png_do_compose
+#define png_do_encode_alpha PDFIUM_png_do_encode_alpha
+#define png_do_expand PDFIUM_png_do_expand
+#define png_do_expand_16 PDFIUM_png_do_expand_16
+#define png_do_expand_palette PDFIUM_png_do_expand_palette
+#define png_do_gamma PDFIUM_png_do_gamma
+#define png_do_gray_to_rgb PDFIUM_png_do_gray_to_rgb
+#define png_do_invert PDFIUM_png_do_invert
+#define png_do_pack PDFIUM_png_do_pack
+#define png_do_packswap PDFIUM_png_do_packswap
+#define png_do_quantize PDFIUM_png_do_quantize
+#define png_do_read_filler PDFIUM_png_do_read_filler
+#define png_do_read_interlace PDFIUM_png_do_read_interlace
+#define png_do_read_intrapixel PDFIUM_png_do_read_intrapixel
+#define png_do_read_invert_alpha PDFIUM_png_do_read_invert_alpha
+#define png_do_read_swap_alpha PDFIUM_png_do_read_swap_alpha
+#define png_do_read_transformations PDFIUM_png_do_read_transformations
+#define png_do_rgb_to_gray PDFIUM_png_do_rgb_to_gray
+#define png_do_scale_16_to_8 PDFIUM_png_do_scale_16_to_8
+#define png_do_shift PDFIUM_png_do_shift
+#define png_do_strip_channel PDFIUM_png_do_strip_channel
+#define png_do_swap PDFIUM_png_do_swap
+#define png_do_unpack PDFIUM_png_do_unpack
+#define png_do_unshift PDFIUM_png_do_unshift
+#define png_do_write_interlace PDFIUM_png_do_write_interlace
+#define png_do_write_intrapixel PDFIUM_png_do_write_intrapixel
+#define png_do_write_invert_alpha PDFIUM_png_do_write_invert_alpha
+#define png_do_write_swap_alpha PDFIUM_png_do_write_swap_alpha
+#define png_do_write_transformations PDFIUM_png_do_write_transformations
+#define png_error PDFIUM_png_error
+#define png_fixed PDFIUM_png_fixed
+#define png_fixed_error PDFIUM_png_fixed_error
+#define png_flush PDFIUM_png_flush
+#define png_format_number PDFIUM_png_format_number
+#define png_formatted_warning PDFIUM_png_formatted_warning
+#define png_free PDFIUM_png_free
+#define png_free_buffer_list PDFIUM_png_free_buffer_list
+#define png_free_data PDFIUM_png_free_data
+#define png_free_default PDFIUM_png_free_default
+#define png_free_jmpbuf PDFIUM_png_free_jmpbuf
+#define png_gamma_16bit_correct PDFIUM_png_gamma_16bit_correct
+#define png_gamma_8bit_correct PDFIUM_png_gamma_8bit_correct
+#define png_gamma_correct PDFIUM_png_gamma_correct
+#define png_gamma_significant PDFIUM_png_gamma_significant
+#define png_get_IHDR PDFIUM_png_get_IHDR
+#define png_get_PLTE PDFIUM_png_get_PLTE
+#define png_get_bKGD PDFIUM_png_get_bKGD
+#define png_get_bit_depth PDFIUM_png_get_bit_depth
+#define png_get_cHRM PDFIUM_png_get_cHRM
+#define png_get_cHRM_XYZ PDFIUM_png_get_cHRM_XYZ
+#define png_get_cHRM_XYZ_fixed PDFIUM_png_get_cHRM_XYZ_fixed
+#define png_get_cHRM_fixed PDFIUM_png_get_cHRM_fixed
+#define png_get_channels PDFIUM_png_get_channels
+#define png_get_chunk_cache_max PDFIUM_png_get_chunk_cache_max
+#define png_get_chunk_malloc_max PDFIUM_png_get_chunk_malloc_max
+#define png_get_color_type PDFIUM_png_get_color_type
+#define png_get_compression_buffer_size PDFIUM_png_get_compression_buffer_size
+#define png_get_compression_type PDFIUM_png_get_compression_type
+#define png_get_copyright PDFIUM_png_get_copyright
+#define png_get_current_pass_number PDFIUM_png_get_current_pass_number
+#define png_get_current_row_number PDFIUM_png_get_current_row_number
+#define png_get_eXIf PDFIUM_png_get_eXIf
+#define png_get_eXIf_1 PDFIUM_png_get_eXIf_1
+#define png_get_error_ptr PDFIUM_png_get_error_ptr
+#define png_get_filter_type PDFIUM_png_get_filter_type
+#define png_get_gAMA PDFIUM_png_get_gAMA
+#define png_get_gAMA_fixed PDFIUM_png_get_gAMA_fixed
+#define png_get_hIST PDFIUM_png_get_hIST
+#define png_get_header_ver PDFIUM_png_get_header_ver
+#define png_get_header_version PDFIUM_png_get_header_version
+#define png_get_iCCP PDFIUM_png_get_iCCP
+#define png_get_image_height PDFIUM_png_get_image_height
+#define png_get_image_width PDFIUM_png_get_image_width
#define png_get_int_32 PDFIUM_png_get_int_32
-#define png_get_int_16 PDFIUM_png_get_int_16
+#define png_get_interlace_type PDFIUM_png_get_interlace_type
+#define png_get_io_chunk_type PDFIUM_png_get_io_chunk_type
+#define png_get_io_ptr PDFIUM_png_get_io_ptr
+#define png_get_io_state PDFIUM_png_get_io_state
+#define png_get_libpng_ver PDFIUM_png_get_libpng_ver
+#define png_get_mem_ptr PDFIUM_png_get_mem_ptr
+#define png_get_oFFs PDFIUM_png_get_oFFs
+#define png_get_pCAL PDFIUM_png_get_pCAL
+#define png_get_pHYs PDFIUM_png_get_pHYs
+#define png_get_pHYs_dpi PDFIUM_png_get_pHYs_dpi
+#define png_get_palette_max PDFIUM_png_get_palette_max
+#define png_get_pixel_aspect_ratio PDFIUM_png_get_pixel_aspect_ratio
+#define png_get_pixel_aspect_ratio_fixed PDFIUM_png_get_pixel_aspect_ratio_fixed
+#define png_get_pixels_per_inch PDFIUM_png_get_pixels_per_inch
+#define png_get_pixels_per_meter PDFIUM_png_get_pixels_per_meter
+#define png_get_progressive_ptr PDFIUM_png_get_progressive_ptr
+#define png_get_rgb_to_gray_status PDFIUM_png_get_rgb_to_gray_status
+#define png_get_rowbytes PDFIUM_png_get_rowbytes
+#define png_get_rows PDFIUM_png_get_rows
+#define png_get_sBIT PDFIUM_png_get_sBIT
+#define png_get_sCAL PDFIUM_png_get_sCAL
+#define png_get_sCAL_fixed PDFIUM_png_get_sCAL_fixed
+#define png_get_sCAL_s PDFIUM_png_get_sCAL_s
+#define png_get_sPLT PDFIUM_png_get_sPLT
+#define png_get_sRGB PDFIUM_png_get_sRGB
+#define png_get_signature PDFIUM_png_get_signature
+#define png_get_tIME PDFIUM_png_get_tIME
+#define png_get_tRNS PDFIUM_png_get_tRNS
+#define png_get_text PDFIUM_png_get_text
+#define png_get_uint_16 PDFIUM_png_get_uint_16
+#define png_get_uint_31 PDFIUM_png_get_uint_31
+#define png_get_uint_32 PDFIUM_png_get_uint_32
+#define png_get_unknown_chunks PDFIUM_png_get_unknown_chunks
+#define png_get_user_chunk_ptr PDFIUM_png_get_user_chunk_ptr
+#define png_get_user_height_max PDFIUM_png_get_user_height_max
+#define png_get_user_transform_ptr PDFIUM_png_get_user_transform_ptr
+#define png_get_user_width_max PDFIUM_png_get_user_width_max
+#define png_get_valid PDFIUM_png_get_valid
+#define png_get_x_offset_inches PDFIUM_png_get_x_offset_inches
+#define png_get_x_offset_inches_fixed PDFIUM_png_get_x_offset_inches_fixed
+#define png_get_x_offset_microns PDFIUM_png_get_x_offset_microns
+#define png_get_x_offset_pixels PDFIUM_png_get_x_offset_pixels
+#define png_get_x_pixels_per_inch PDFIUM_png_get_x_pixels_per_inch
+#define png_get_x_pixels_per_meter PDFIUM_png_get_x_pixels_per_meter
+#define png_get_y_offset_inches PDFIUM_png_get_y_offset_inches
+#define png_get_y_offset_inches_fixed PDFIUM_png_get_y_offset_inches_fixed
+#define png_get_y_offset_microns PDFIUM_png_get_y_offset_microns
+#define png_get_y_offset_pixels PDFIUM_png_get_y_offset_pixels
+#define png_get_y_pixels_per_inch PDFIUM_png_get_y_pixels_per_inch
+#define png_get_y_pixels_per_meter PDFIUM_png_get_y_pixels_per_meter
+#define png_handle_IEND PDFIUM_png_handle_IEND
+#define png_handle_IHDR PDFIUM_png_handle_IHDR
+#define png_handle_PLTE PDFIUM_png_handle_PLTE
+#define png_handle_as_unknown PDFIUM_png_handle_as_unknown
+#define png_handle_bKGD PDFIUM_png_handle_bKGD
+#define png_handle_cHRM PDFIUM_png_handle_cHRM
+#define png_handle_gAMA PDFIUM_png_handle_gAMA
+#define png_handle_hIST PDFIUM_png_handle_hIST
+#define png_handle_iCCP PDFIUM_png_handle_iCCP
+#define png_handle_iTXt PDFIUM_png_handle_iTXt
+#define png_handle_oFFs PDFIUM_png_handle_oFFs
+#define png_handle_pCAL PDFIUM_png_handle_pCAL
+#define png_handle_pHYs PDFIUM_png_handle_pHYs
+#define png_handle_sBIT PDFIUM_png_handle_sBIT
+#define png_handle_sCAL PDFIUM_png_handle_sCAL
+#define png_handle_sPLT PDFIUM_png_handle_sPLT
+#define png_handle_sRGB PDFIUM_png_handle_sRGB
+#define png_handle_tEXt PDFIUM_png_handle_tEXt
+#define png_handle_tIME PDFIUM_png_handle_tIME
+#define png_handle_tRNS PDFIUM_png_handle_tRNS
+#define png_handle_unknown PDFIUM_png_handle_unknown
+#define png_handle_zTXt PDFIUM_png_handle_zTXt
+#define png_icc_check_header PDFIUM_png_icc_check_header
+#define png_icc_check_length PDFIUM_png_icc_check_length
+#define png_icc_check_tag_table PDFIUM_png_icc_check_tag_table
+#define png_icc_set_sRGB PDFIUM_png_icc_set_sRGB
+#define png_image_begin_read_from_file PDFIUM_png_image_begin_read_from_file
+#define png_image_begin_read_from_memory PDFIUM_png_image_begin_read_from_memory
+#define png_image_begin_read_from_stdio PDFIUM_png_image_begin_read_from_stdio
+#define png_image_error PDFIUM_png_image_error
+#define png_image_finish_read PDFIUM_png_image_finish_read
+#define png_image_free PDFIUM_png_image_free
+#define png_image_write_to_file PDFIUM_png_image_write_to_file
+#define png_image_write_to_memory PDFIUM_png_image_write_to_memory
+#define png_image_write_to_stdio PDFIUM_png_image_write_to_stdio
+#define png_info_init_3 PDFIUM_png_info_init_3
+#define png_init_filter_functions_neon PDFIUM_png_init_filter_functions_neon
+#define png_init_filter_functions_sse2 PDFIUM_png_init_filter_functions_sse2
+#define png_init_io PDFIUM_png_init_io
+#define png_init_read_transformations PDFIUM_png_init_read_transformations
+#define png_longjmp PDFIUM_png_longjmp
+#define png_malloc PDFIUM_png_malloc
+#define png_malloc_array PDFIUM_png_malloc_array
+#define png_malloc_base PDFIUM_png_malloc_base
+#define png_malloc_default PDFIUM_png_malloc_default
+#define png_malloc_warn PDFIUM_png_malloc_warn
+#define png_muldiv PDFIUM_png_muldiv
+#define png_muldiv_warn PDFIUM_png_muldiv_warn
+#define png_permit_mng_features PDFIUM_png_permit_mng_features
+#define png_process_IDAT_data PDFIUM_png_process_IDAT_data
+#define png_process_data PDFIUM_png_process_data
+#define png_process_data_pause PDFIUM_png_process_data_pause
+#define png_process_data_skip PDFIUM_png_process_data_skip
+#define png_process_some_data PDFIUM_png_process_some_data
+#define png_progressive_combine_row PDFIUM_png_progressive_combine_row
+#define png_push_check_crc PDFIUM_png_push_check_crc
+#define png_push_crc_finish PDFIUM_png_push_crc_finish
+#define png_push_crc_skip PDFIUM_png_push_crc_skip
+#define png_push_fill_buffer PDFIUM_png_push_fill_buffer
+#define png_push_handle_iTXt PDFIUM_png_push_handle_iTXt
+#define png_push_handle_tEXt PDFIUM_png_push_handle_tEXt
+#define png_push_handle_unknown PDFIUM_png_push_handle_unknown
+#define png_push_handle_zTXt PDFIUM_png_push_handle_zTXt
+#define png_push_have_end PDFIUM_png_push_have_end
+#define png_push_have_info PDFIUM_png_push_have_info
+#define png_push_have_row PDFIUM_png_push_have_row
+#define png_push_process_row PDFIUM_png_push_process_row
+#define png_push_read_IDAT PDFIUM_png_push_read_IDAT
+#define png_push_read_chunk PDFIUM_png_push_read_chunk
+#define png_push_read_end PDFIUM_png_push_read_end
+#define png_push_read_iTXt PDFIUM_png_push_read_iTXt
+#define png_push_read_sig PDFIUM_png_push_read_sig
+#define png_push_read_tEXt PDFIUM_png_push_read_tEXt
+#define png_push_read_zTXt PDFIUM_png_push_read_zTXt
+#define png_push_restore_buffer PDFIUM_png_push_restore_buffer
+#define png_push_save_buffer PDFIUM_png_push_save_buffer
+#define png_read_IDAT_data PDFIUM_png_read_IDAT_data
+#define png_read_chunk_header PDFIUM_png_read_chunk_header
+#define png_read_data PDFIUM_png_read_data
+#define png_read_end PDFIUM_png_read_end
+#define png_read_filter_row PDFIUM_png_read_filter_row
+#define png_read_filter_row_avg3_neon PDFIUM_png_read_filter_row_avg3_neon
+#define png_read_filter_row_avg3_sse2 PDFIUM_png_read_filter_row_avg3_sse2
+#define png_read_filter_row_avg4_neon PDFIUM_png_read_filter_row_avg4_neon
+#define png_read_filter_row_avg4_sse2 PDFIUM_png_read_filter_row_avg4_sse2
+#define png_read_filter_row_paeth3_neon PDFIUM_png_read_filter_row_paeth3_neon
+#define png_read_filter_row_paeth3_sse2 PDFIUM_png_read_filter_row_paeth3_sse2
+#define png_read_filter_row_paeth4_neon PDFIUM_png_read_filter_row_paeth4_neon
+#define png_read_filter_row_paeth4_sse2 PDFIUM_png_read_filter_row_paeth4_sse2
+#define png_read_filter_row_sub3_neon PDFIUM_png_read_filter_row_sub3_neon
+#define png_read_filter_row_sub3_sse2 PDFIUM_png_read_filter_row_sub3_sse2
+#define png_read_filter_row_sub4_neon PDFIUM_png_read_filter_row_sub4_neon
+#define png_read_filter_row_sub4_sse2 PDFIUM_png_read_filter_row_sub4_sse2
+#define png_read_filter_row_up_neon PDFIUM_png_read_filter_row_up_neon
+#define png_read_finish_IDAT PDFIUM_png_read_finish_IDAT
+#define png_read_finish_row PDFIUM_png_read_finish_row
+#define png_read_image PDFIUM_png_read_image
+#define png_read_info PDFIUM_png_read_info
+#define png_read_png PDFIUM_png_read_png
+#define png_read_push_finish_row PDFIUM_png_read_push_finish_row
+#define png_read_row PDFIUM_png_read_row
+#define png_read_rows PDFIUM_png_read_rows
+#define png_read_sig PDFIUM_png_read_sig
+#define png_read_start_row PDFIUM_png_read_start_row
+#define png_read_transform_info PDFIUM_png_read_transform_info
+#define png_read_update_info PDFIUM_png_read_update_info
+#define png_realloc_array PDFIUM_png_realloc_array
+#define png_reciprocal PDFIUM_png_reciprocal
+#define png_reciprocal2 PDFIUM_png_reciprocal2
+#define png_reset_crc PDFIUM_png_reset_crc
+#define png_reset_zstream PDFIUM_png_reset_zstream
+#define png_sRGB_base PDFIUM_png_sRGB_base
+#define png_sRGB_delta PDFIUM_png_sRGB_delta
+#define png_sRGB_table PDFIUM_png_sRGB_table
+#define png_safe_error PDFIUM_png_safe_error
+#define png_safe_execute PDFIUM_png_safe_execute
+#define png_safe_warning PDFIUM_png_safe_warning
+#define png_safecat PDFIUM_png_safecat
+#define png_save_int_32 PDFIUM_png_save_int_32
+#define png_save_uint_16 PDFIUM_png_save_uint_16
+#define png_save_uint_32 PDFIUM_png_save_uint_32
+#define png_set_IHDR PDFIUM_png_set_IHDR
+#define png_set_PLTE PDFIUM_png_set_PLTE
+#define png_set_add_alpha PDFIUM_png_set_add_alpha
+#define png_set_alpha_mode PDFIUM_png_set_alpha_mode
+#define png_set_alpha_mode_fixed PDFIUM_png_set_alpha_mode_fixed
+#define png_set_bKGD PDFIUM_png_set_bKGD
+#define png_set_background PDFIUM_png_set_background
+#define png_set_background_fixed PDFIUM_png_set_background_fixed
+#define png_set_benign_errors PDFIUM_png_set_benign_errors
+#define png_set_bgr PDFIUM_png_set_bgr
+#define png_set_cHRM PDFIUM_png_set_cHRM
+#define png_set_cHRM_XYZ PDFIUM_png_set_cHRM_XYZ
+#define png_set_cHRM_XYZ_fixed PDFIUM_png_set_cHRM_XYZ_fixed
+#define png_set_cHRM_fixed PDFIUM_png_set_cHRM_fixed
+#define png_set_check_for_invalid_index PDFIUM_png_set_check_for_invalid_index
+#define png_set_chunk_cache_max PDFIUM_png_set_chunk_cache_max
+#define png_set_chunk_malloc_max PDFIUM_png_set_chunk_malloc_max
+#define png_set_compression_buffer_size PDFIUM_png_set_compression_buffer_size
+#define png_set_compression_level PDFIUM_png_set_compression_level
+#define png_set_compression_mem_level PDFIUM_png_set_compression_mem_level
+#define png_set_compression_method PDFIUM_png_set_compression_method
+#define png_set_compression_strategy PDFIUM_png_set_compression_strategy
+#define png_set_compression_window_bits PDFIUM_png_set_compression_window_bits
+#define png_set_crc_action PDFIUM_png_set_crc_action
+#define png_set_eXIf PDFIUM_png_set_eXIf
+#define png_set_eXIf_1 PDFIUM_png_set_eXIf_1
+#define png_set_error_fn PDFIUM_png_set_error_fn
+#define png_set_expand PDFIUM_png_set_expand
+#define png_set_expand_16 PDFIUM_png_set_expand_16
+#define png_set_expand_gray_1_2_4_to_8 PDFIUM_png_set_expand_gray_1_2_4_to_8
+#define png_set_filler PDFIUM_png_set_filler
+#define png_set_filter PDFIUM_png_set_filter
+#define png_set_filter_heuristics PDFIUM_png_set_filter_heuristics
+#define png_set_filter_heuristics_fixed PDFIUM_png_set_filter_heuristics_fixed
+#define png_set_flush PDFIUM_png_set_flush
+#define png_set_gAMA PDFIUM_png_set_gAMA
+#define png_set_gAMA_fixed PDFIUM_png_set_gAMA_fixed
+#define png_set_gamma PDFIUM_png_set_gamma
+#define png_set_gamma_fixed PDFIUM_png_set_gamma_fixed
+#define png_set_gray_to_rgb PDFIUM_png_set_gray_to_rgb
+#define png_set_hIST PDFIUM_png_set_hIST
+#define png_set_iCCP PDFIUM_png_set_iCCP
+#define png_set_interlace_handling PDFIUM_png_set_interlace_handling
+#define png_set_invalid PDFIUM_png_set_invalid
+#define png_set_invert_alpha PDFIUM_png_set_invert_alpha
+#define png_set_invert_mono PDFIUM_png_set_invert_mono
+#define png_set_keep_unknown_chunks PDFIUM_png_set_keep_unknown_chunks
+#define png_set_longjmp_fn PDFIUM_png_set_longjmp_fn
+#define png_set_mem_fn PDFIUM_png_set_mem_fn
+#define png_set_oFFs PDFIUM_png_set_oFFs
+#define png_set_option PDFIUM_png_set_option
+#define png_set_pCAL PDFIUM_png_set_pCAL
+#define png_set_pHYs PDFIUM_png_set_pHYs
+#define png_set_packing PDFIUM_png_set_packing
+#define png_set_packswap PDFIUM_png_set_packswap
+#define png_set_palette_to_rgb PDFIUM_png_set_palette_to_rgb
+#define png_set_progressive_read_fn PDFIUM_png_set_progressive_read_fn
+#define png_set_quantize PDFIUM_png_set_quantize
+#define png_set_read_fn PDFIUM_png_set_read_fn
+#define png_set_read_status_fn PDFIUM_png_set_read_status_fn
+#define png_set_read_user_chunk_fn PDFIUM_png_set_read_user_chunk_fn
+#define png_set_read_user_transform_fn PDFIUM_png_set_read_user_transform_fn
+#define png_set_rgb_to_gray PDFIUM_png_set_rgb_to_gray
+#define png_set_rgb_to_gray_fixed PDFIUM_png_set_rgb_to_gray_fixed
+#define png_set_rows PDFIUM_png_set_rows
+#define png_set_sBIT PDFIUM_png_set_sBIT
+#define png_set_sCAL PDFIUM_png_set_sCAL
+#define png_set_sCAL_fixed PDFIUM_png_set_sCAL_fixed
+#define png_set_sCAL_s PDFIUM_png_set_sCAL_s
+#define png_set_sPLT PDFIUM_png_set_sPLT
+#define png_set_sRGB PDFIUM_png_set_sRGB
+#define png_set_sRGB_gAMA_and_cHRM PDFIUM_png_set_sRGB_gAMA_and_cHRM
+#define png_set_scale_16 PDFIUM_png_set_scale_16
+#define png_set_shift PDFIUM_png_set_shift
+#define png_set_sig_bytes PDFIUM_png_set_sig_bytes
+#define png_set_strip_16 PDFIUM_png_set_strip_16
+#define png_set_strip_alpha PDFIUM_png_set_strip_alpha
+#define png_set_swap PDFIUM_png_set_swap
+#define png_set_swap_alpha PDFIUM_png_set_swap_alpha
+#define png_set_tIME PDFIUM_png_set_tIME
+#define png_set_tRNS PDFIUM_png_set_tRNS
+#define png_set_tRNS_to_alpha PDFIUM_png_set_tRNS_to_alpha
+#define png_set_text PDFIUM_png_set_text
+#define png_set_text_2 PDFIUM_png_set_text_2
+#define png_set_text_compression_level PDFIUM_png_set_text_compression_level
+#define png_set_text_compression_mem_level PDFIUM_png_set_text_compression_mem_level
+#define png_set_text_compression_method PDFIUM_png_set_text_compression_method
+#define png_set_text_compression_strategy PDFIUM_png_set_text_compression_strategy
+#define png_set_text_compression_window_bits PDFIUM_png_set_text_compression_window_bits
+#define png_set_unknown_chunk_location PDFIUM_png_set_unknown_chunk_location
+#define png_set_unknown_chunks PDFIUM_png_set_unknown_chunks
+#define png_set_user_limits PDFIUM_png_set_user_limits
+#define png_set_user_transform_info PDFIUM_png_set_user_transform_info
+#define png_set_write_fn PDFIUM_png_set_write_fn
+#define png_set_write_status_fn PDFIUM_png_set_write_status_fn
+#define png_set_write_user_transform_fn PDFIUM_png_set_write_user_transform_fn
+#define png_sig_cmp PDFIUM_png_sig_cmp
+#define png_start_read_image PDFIUM_png_start_read_image
+#define png_user_version_check PDFIUM_png_user_version_check
+#define png_warning PDFIUM_png_warning
+#define png_warning_parameter PDFIUM_png_warning_parameter
+#define png_warning_parameter_signed PDFIUM_png_warning_parameter_signed
+#define png_warning_parameter_unsigned PDFIUM_png_warning_parameter_unsigned
+#define png_write_IEND PDFIUM_png_write_IEND
+#define png_write_IHDR PDFIUM_png_write_IHDR
+#define png_write_PLTE PDFIUM_png_write_PLTE
+#define png_write_bKGD PDFIUM_png_write_bKGD
+#define png_write_cHRM_fixed PDFIUM_png_write_cHRM_fixed
+#define png_write_chunk PDFIUM_png_write_chunk
+#define png_write_chunk_data PDFIUM_png_write_chunk_data
+#define png_write_chunk_end PDFIUM_png_write_chunk_end
+#define png_write_chunk_start PDFIUM_png_write_chunk_start
+#define png_write_data PDFIUM_png_write_data
+#define png_write_end PDFIUM_png_write_end
+#define png_write_find_filter PDFIUM_png_write_find_filter
+#define png_write_finish_row PDFIUM_png_write_finish_row
+#define png_write_flush PDFIUM_png_write_flush
+#define png_write_gAMA_fixed PDFIUM_png_write_gAMA_fixed
+#define png_write_hIST PDFIUM_png_write_hIST
+#define png_write_iCCP PDFIUM_png_write_iCCP
+#define png_write_iTXt PDFIUM_png_write_iTXt
+#define png_write_image PDFIUM_png_write_image
+#define png_write_info PDFIUM_png_write_info
+#define png_write_info_before_PLTE PDFIUM_png_write_info_before_PLTE
+#define png_write_oFFs PDFIUM_png_write_oFFs
+#define png_write_pCAL PDFIUM_png_write_pCAL
+#define png_write_pHYs PDFIUM_png_write_pHYs
+#define png_write_png PDFIUM_png_write_png
+#define png_write_row PDFIUM_png_write_row
+#define png_write_rows PDFIUM_png_write_rows
+#define png_write_sBIT PDFIUM_png_write_sBIT
+#define png_write_sCAL_s PDFIUM_png_write_sCAL_s
+#define png_write_sPLT PDFIUM_png_write_sPLT
+#define png_write_sRGB PDFIUM_png_write_sRGB
+#define png_write_sig PDFIUM_png_write_sig
+#define png_write_start_row PDFIUM_png_write_start_row
+#define png_write_tEXt PDFIUM_png_write_tEXt
+#define png_write_tIME PDFIUM_png_write_tIME
+#define png_write_tRNS PDFIUM_png_write_tRNS
+#define png_write_zTXt PDFIUM_png_write_zTXt
+#define png_zalloc PDFIUM_png_zalloc
+#define png_zfree PDFIUM_png_zfree
+#define png_zlib_inflate PDFIUM_png_zlib_inflate
+#define png_zstream_error PDFIUM_png_zstream_error
#endif // PNGPREFIX_H
diff --git a/third_party/libpng16/pngpriv.h b/third_party/libpng16/pngpriv.h
index 6336713526..5652525b2b 100644
--- a/third_party/libpng16/pngpriv.h
+++ b/third_party/libpng16/pngpriv.h
@@ -1,8 +1,8 @@
/* pngpriv.h - private declarations for use inside libpng
*
- * Last changed in libpng 1.6.22 [May 26, 2016]
- * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.32 [August 24, 2017]
+ * Copyright (c) 1998-2002,2004,2006-2017 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.)
*
@@ -35,7 +35,9 @@
* Windows/Visual Studio) there is no effect; the OS specific tests below are
* still required (as of 2011-05-02.)
*/
-#define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */
+#ifndef _POSIX_SOURCE
+# define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */
+#endif
#ifndef PNG_VERSION_INFO_ONLY
/* Standard library headers not required by png.h: */
@@ -182,6 +184,22 @@
# endif
#endif /* PNG_ARM_NEON_OPT > 0 */
+#ifndef PNG_MIPS_MSA_OPT
+# if defined(__mips_msa) && (__mips_isa_rev >= 5) && defined(PNG_ALIGNED_MEMORY_SUPPORTED)
+# define PNG_MIPS_MSA_OPT 2
+# else
+# define PNG_MIPS_MSA_OPT 0
+# endif
+#endif
+
+#ifndef PNG_POWERPC_VSX_OPT
+# if defined(__PPC64__) && defined(__ALTIVEC__) && defined(__VSX__)
+# define PNG_POWERPC_VSX_OPT 2
+# else
+# define PNG_POWERPC_VSX_OPT 0
+# endif
+#endif
+
#ifndef PNG_INTEL_SSE_OPT
# ifdef PNG_INTEL_SSE
/* Only check for SSE if the build configuration has been modified to
@@ -218,6 +236,32 @@
# endif
#endif
+#if PNG_MIPS_MSA_OPT > 0
+# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_msa
+# ifndef PNG_MIPS_MSA_IMPLEMENTATION
+# if defined(__mips_msa)
+# if defined(__clang__)
+# elif defined(__GNUC__)
+# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
+# define PNG_MIPS_MSA_IMPLEMENTATION 2
+# endif /* no GNUC support */
+# endif /* __GNUC__ */
+# else /* !defined __mips_msa */
+# define PNG_MIPS_MSA_IMPLEMENTATION 2
+# endif /* __mips_msa */
+# endif /* !PNG_MIPS_MSA_IMPLEMENTATION */
+
+# ifndef PNG_MIPS_MSA_IMPLEMENTATION
+# define PNG_MIPS_MSA_IMPLEMENTATION 1
+# endif
+#endif /* PNG_MIPS_MSA_OPT > 0 */
+
+#if PNG_POWERPC_VSX_OPT > 0
+# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_vsx
+# define PNG_POWERPC_VSX_IMPLEMENTATION 1
+#endif
+
+
/* Is this a build of a DLL where compilation of the object modules requires
* different preprocessor settings to those required for a simple library? If
* so PNG_BUILD_DLL must be set.
@@ -410,6 +454,21 @@
# define png_fixed_error(s1,s2) png_err(s1)
#endif
+/* Some fixed point APIs are still required even if not exported because
+ * they get used by the corresponding floating point APIs. This magic
+ * deals with this:
+ */
+#ifdef PNG_FIXED_POINT_SUPPORTED
+# define PNGFAPI PNGAPI
+#else
+# define PNGFAPI /* PRIVATE */
+#endif
+
+#ifndef PNG_VERSION_INFO_ONLY
+/* Other defines specific to compilers can go here. Try to keep
+ * them inside an appropriate ifdef/endif pair for portability.
+ */
+
/* C allows up-casts from (void*) to any pointer and (const void*) to any
* pointer to a const object. C++ regards this as a type error and requires an
* explicit, static, cast and provides the static_cast<> rune to ensure that
@@ -424,25 +483,20 @@
static_cast<type>(static_cast<const void*>(value))
#else
# define png_voidcast(type, value) (value)
-# define png_constcast(type, value) ((type)(value))
+# ifdef _WIN64
+# ifdef __GNUC__
+ typedef unsigned long long png_ptruint;
+# else
+ typedef unsigned __int64 png_ptruint;
+# endif
+# else
+ typedef unsigned long png_ptruint;
+# endif
+# define png_constcast(type, value) ((type)(png_ptruint)(const void*)(value))
# define png_aligncast(type, value) ((void*)(value))
# define png_aligncastconst(type, value) ((const void*)(value))
#endif /* __cplusplus */
-/* Some fixed point APIs are still required even if not exported because
- * they get used by the corresponding floating point APIs. This magic
- * deals with this:
- */
-#ifdef PNG_FIXED_POINT_SUPPORTED
-# define PNGFAPI PNGAPI
-#else
-# define PNGFAPI /* PRIVATE */
-#endif
-
-#ifndef PNG_VERSION_INFO_ONLY
-/* Other defines specific to compilers can go here. Try to keep
- * them inside an appropriate ifdef/endif pair for portability.
- */
#if defined(PNG_FLOATING_POINT_SUPPORTED) ||\
defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
/* png.c requires the following ANSI-C constants if the conversion of
@@ -456,10 +510,10 @@
# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
- /* We need to check that <math.h> hasn't already been included earlier
- * as it seems it doesn't agree with <fp.h>, yet we should really use
- * <fp.h> if possible.
- */
+ /* We need to check that <math.h> hasn't already been included earlier
+ * as it seems it doesn't agree with <fp.h>, yet we should really use
+ * <fp.h> if possible.
+ */
# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
# include <fp.h>
# endif
@@ -467,9 +521,9 @@
# include <math.h>
# endif
# if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
- /* Amiga SAS/C: We must include builtin FPU functions when compiling using
- * MATH=68881
- */
+ /* Amiga SAS/C: We must include builtin FPU functions when compiling using
+ * MATH=68881
+ */
# include <m68881.h>
# endif
#endif
@@ -540,7 +594,8 @@
/* This implicitly assumes alignment is always to a power of 2. */
#ifdef png_alignof
# define png_isaligned(ptr, type)\
- ((((const char*)ptr-(const char*)0) & (png_alignof(type)-1)) == 0)
+ (((type)((const char*)ptr-(const char*)0) & \
+ (type)(png_alignof(type)-1)) == 0)
#else
# define png_isaligned(ptr, type) 0
#endif
@@ -557,92 +612,92 @@
* are defined in png.h because they need to be visible to applications
* that call png_set_unknown_chunk().
*/
-/* #define PNG_HAVE_IHDR 0x01 (defined in png.h) */
-/* #define PNG_HAVE_PLTE 0x02 (defined in png.h) */
-#define PNG_HAVE_IDAT 0x04
-/* #define PNG_AFTER_IDAT 0x08 (defined in png.h) */
-#define PNG_HAVE_IEND 0x10
- /* 0x20 (unused) */
- /* 0x40 (unused) */
- /* 0x80 (unused) */
-#define PNG_HAVE_CHUNK_HEADER 0x100
-#define PNG_WROTE_tIME 0x200
-#define PNG_WROTE_INFO_BEFORE_PLTE 0x400
-#define PNG_BACKGROUND_IS_GRAY 0x800
-#define PNG_HAVE_PNG_SIGNATURE 0x1000
-#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
- /* 0x4000 (unused) */
-#define PNG_IS_READ_STRUCT 0x8000 /* Else is a write struct */
+/* #define PNG_HAVE_IHDR 0x01U (defined in png.h) */
+/* #define PNG_HAVE_PLTE 0x02U (defined in png.h) */
+#define PNG_HAVE_IDAT 0x04U
+/* #define PNG_AFTER_IDAT 0x08U (defined in png.h) */
+#define PNG_HAVE_IEND 0x10U
+ /* 0x20U (unused) */
+ /* 0x40U (unused) */
+ /* 0x80U (unused) */
+#define PNG_HAVE_CHUNK_HEADER 0x100U
+#define PNG_WROTE_tIME 0x200U
+#define PNG_WROTE_INFO_BEFORE_PLTE 0x400U
+#define PNG_BACKGROUND_IS_GRAY 0x800U
+#define PNG_HAVE_PNG_SIGNATURE 0x1000U
+#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000U /* Have another chunk after IDAT */
+ /* 0x4000U (unused) */
+#define PNG_IS_READ_STRUCT 0x8000U /* Else is a write struct */
/* Flags for the transformations the PNG library does on the image data */
-#define PNG_BGR 0x0001
-#define PNG_INTERLACE 0x0002
-#define PNG_PACK 0x0004
-#define PNG_SHIFT 0x0008
-#define PNG_SWAP_BYTES 0x0010
-#define PNG_INVERT_MONO 0x0020
-#define PNG_QUANTIZE 0x0040
-#define PNG_COMPOSE 0x0080 /* Was PNG_BACKGROUND */
-#define PNG_BACKGROUND_EXPAND 0x0100
-#define PNG_EXPAND_16 0x0200 /* Added to libpng 1.5.2 */
-#define PNG_16_TO_8 0x0400 /* Becomes 'chop' in 1.5.4 */
-#define PNG_RGBA 0x0800
-#define PNG_EXPAND 0x1000
-#define PNG_GAMMA 0x2000
-#define PNG_GRAY_TO_RGB 0x4000
-#define PNG_FILLER 0x8000
-#define PNG_PACKSWAP 0x10000
-#define PNG_SWAP_ALPHA 0x20000
-#define PNG_STRIP_ALPHA 0x40000
-#define PNG_INVERT_ALPHA 0x80000
-#define PNG_USER_TRANSFORM 0x100000
-#define PNG_RGB_TO_GRAY_ERR 0x200000
-#define PNG_RGB_TO_GRAY_WARN 0x400000
-#define PNG_RGB_TO_GRAY 0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */
-#define PNG_ENCODE_ALPHA 0x800000 /* Added to libpng-1.5.4 */
-#define PNG_ADD_ALPHA 0x1000000 /* Added to libpng-1.2.7 */
-#define PNG_EXPAND_tRNS 0x2000000 /* Added to libpng-1.2.9 */
-#define PNG_SCALE_16_TO_8 0x4000000 /* Added to libpng-1.5.4 */
- /* 0x8000000 unused */
- /* 0x10000000 unused */
- /* 0x20000000 unused */
- /* 0x40000000 unused */
+#define PNG_BGR 0x0001U
+#define PNG_INTERLACE 0x0002U
+#define PNG_PACK 0x0004U
+#define PNG_SHIFT 0x0008U
+#define PNG_SWAP_BYTES 0x0010U
+#define PNG_INVERT_MONO 0x0020U
+#define PNG_QUANTIZE 0x0040U
+#define PNG_COMPOSE 0x0080U /* Was PNG_BACKGROUND */
+#define PNG_BACKGROUND_EXPAND 0x0100U
+#define PNG_EXPAND_16 0x0200U /* Added to libpng 1.5.2 */
+#define PNG_16_TO_8 0x0400U /* Becomes 'chop' in 1.5.4 */
+#define PNG_RGBA 0x0800U
+#define PNG_EXPAND 0x1000U
+#define PNG_GAMMA 0x2000U
+#define PNG_GRAY_TO_RGB 0x4000U
+#define PNG_FILLER 0x8000U
+#define PNG_PACKSWAP 0x10000U
+#define PNG_SWAP_ALPHA 0x20000U
+#define PNG_STRIP_ALPHA 0x40000U
+#define PNG_INVERT_ALPHA 0x80000U
+#define PNG_USER_TRANSFORM 0x100000U
+#define PNG_RGB_TO_GRAY_ERR 0x200000U
+#define PNG_RGB_TO_GRAY_WARN 0x400000U
+#define PNG_RGB_TO_GRAY 0x600000U /* two bits, RGB_TO_GRAY_ERR|WARN */
+#define PNG_ENCODE_ALPHA 0x800000U /* Added to libpng-1.5.4 */
+#define PNG_ADD_ALPHA 0x1000000U /* Added to libpng-1.2.7 */
+#define PNG_EXPAND_tRNS 0x2000000U /* Added to libpng-1.2.9 */
+#define PNG_SCALE_16_TO_8 0x4000000U /* Added to libpng-1.5.4 */
+ /* 0x8000000U unused */
+ /* 0x10000000U unused */
+ /* 0x20000000U unused */
+ /* 0x40000000U unused */
/* Flags for png_create_struct */
-#define PNG_STRUCT_PNG 0x0001
-#define PNG_STRUCT_INFO 0x0002
+#define PNG_STRUCT_PNG 0x0001U
+#define PNG_STRUCT_INFO 0x0002U
/* Flags for the png_ptr->flags rather than declaring a byte for each one */
-#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
-#define PNG_FLAG_ZSTREAM_INITIALIZED 0x0002 /* Added to libpng-1.6.0 */
- /* 0x0004 unused */
-#define PNG_FLAG_ZSTREAM_ENDED 0x0008 /* Added to libpng-1.6.0 */
- /* 0x0010 unused */
- /* 0x0020 unused */
-#define PNG_FLAG_ROW_INIT 0x0040
-#define PNG_FLAG_FILLER_AFTER 0x0080
-#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
-#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
-#define PNG_FLAG_CRC_CRITICAL_USE 0x0400
-#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
-#define PNG_FLAG_ASSUME_sRGB 0x1000 /* Added to libpng-1.5.4 */
-#define PNG_FLAG_OPTIMIZE_ALPHA 0x2000 /* Added to libpng-1.5.4 */
-#define PNG_FLAG_DETECT_UNINITIALIZED 0x4000 /* Added to libpng-1.5.4 */
-/* #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000 */
-/* #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000 */
-#define PNG_FLAG_LIBRARY_MISMATCH 0x20000
-#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000
-#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000
-#define PNG_FLAG_BENIGN_ERRORS_WARN 0x100000 /* Added to libpng-1.4.0 */
-#define PNG_FLAG_APP_WARNINGS_WARN 0x200000 /* Added to libpng-1.6.0 */
-#define PNG_FLAG_APP_ERRORS_WARN 0x400000 /* Added to libpng-1.6.0 */
- /* 0x800000 unused */
- /* 0x1000000 unused */
- /* 0x2000000 unused */
- /* 0x4000000 unused */
- /* 0x8000000 unused */
- /* 0x10000000 unused */
- /* 0x20000000 unused */
- /* 0x40000000 unused */
+#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001U
+#define PNG_FLAG_ZSTREAM_INITIALIZED 0x0002U /* Added to libpng-1.6.0 */
+ /* 0x0004U unused */
+#define PNG_FLAG_ZSTREAM_ENDED 0x0008U /* Added to libpng-1.6.0 */
+ /* 0x0010U unused */
+ /* 0x0020U unused */
+#define PNG_FLAG_ROW_INIT 0x0040U
+#define PNG_FLAG_FILLER_AFTER 0x0080U
+#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100U
+#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200U
+#define PNG_FLAG_CRC_CRITICAL_USE 0x0400U
+#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800U
+#define PNG_FLAG_ASSUME_sRGB 0x1000U /* Added to libpng-1.5.4 */
+#define PNG_FLAG_OPTIMIZE_ALPHA 0x2000U /* Added to libpng-1.5.4 */
+#define PNG_FLAG_DETECT_UNINITIALIZED 0x4000U /* Added to libpng-1.5.4 */
+/* #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000U */
+/* #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000U */
+#define PNG_FLAG_LIBRARY_MISMATCH 0x20000U
+#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000U
+#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000U
+#define PNG_FLAG_BENIGN_ERRORS_WARN 0x100000U /* Added to libpng-1.4.0 */
+#define PNG_FLAG_APP_WARNINGS_WARN 0x200000U /* Added to libpng-1.6.0 */
+#define PNG_FLAG_APP_ERRORS_WARN 0x400000U /* Added to libpng-1.6.0 */
+ /* 0x800000U unused */
+ /* 0x1000000U unused */
+ /* 0x2000000U unused */
+ /* 0x4000000U unused */
+ /* 0x8000000U unused */
+ /* 0x10000000U unused */
+ /* 0x20000000U unused */
+ /* 0x40000000U unused */
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
PNG_FLAG_CRC_ANCILLARY_NOWARN)
@@ -676,6 +731,24 @@
((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \
(( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) )
+/* This returns the number of trailing bits in the last byte of a row, 0 if the
+ * last byte is completely full of pixels. It is, in principle, (pixel_bits x
+ * width) % 8, but that would overflow for large 'width'. The second macro is
+ * the same except that it returns the number of unused bits in the last byte;
+ * (8-TRAILBITS), but 0 when TRAILBITS is 0.
+ *
+ * NOTE: these macros are intended to be self-evidently correct and never
+ * overflow on the assumption that pixel_bits is in the range 0..255. The
+ * arguments are evaluated only once and they can be signed (e.g. as a result of
+ * the integral promotions). The result of the expression always has type
+ * (png_uint_32), however the compiler always knows it is in the range 0..7.
+ */
+#define PNG_TRAILBITS(pixel_bits, width) \
+ (((pixel_bits) * ((width) % (png_uint_32)8)) % 8)
+
+#define PNG_PADBITS(pixel_bits, width) \
+ ((8 - PNG_TRAILBITS(pixel_bits, width)) % 8)
+
/* PNG_OUT_OF_RANGE returns true if value is outside the range
* ideal-delta..ideal+delta. Each argument is evaluated twice.
* "ideal" and "delta" should be constants, normally simple
@@ -769,6 +842,7 @@
#define png_PLTE PNG_U32( 80, 76, 84, 69)
#define png_bKGD PNG_U32( 98, 75, 71, 68)
#define png_cHRM PNG_U32( 99, 72, 82, 77)
+#define png_eXIf PNG_U32(101, 88, 73, 102) /* registered July 2017 */
#define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */
#define png_gAMA PNG_U32(103, 65, 77, 65)
#define png_gIFg PNG_U32(103, 73, 70, 103)
@@ -1061,7 +1135,7 @@ PNG_INTERNAL_FUNCTION(void,png_write_sBIT,(png_structrp png_ptr,
#ifdef PNG_WRITE_cHRM_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_write_cHRM_fixed,(png_structrp png_ptr,
const png_xy *xy), PNG_EMPTY);
- /* The xy value must have been previously validated */
+ /* The xy value must have been previously validated */
#endif
#ifdef PNG_WRITE_sRGB_SUPPORTED
@@ -1069,6 +1143,11 @@ PNG_INTERNAL_FUNCTION(void,png_write_sRGB,(png_structrp png_ptr,
int intent),PNG_EMPTY);
#endif
+#ifdef PNG_WRITE_eXIf_SUPPORTED
+PNG_INTERNAL_FUNCTION(void,png_write_eXIf,(png_structrp png_ptr,
+ png_bytep exif, int num_exif),PNG_EMPTY);
+#endif
+
#ifdef PNG_WRITE_iCCP_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_write_iCCP,(png_structrp png_ptr,
png_const_charp name, png_const_bytep profile), PNG_EMPTY);
@@ -1210,6 +1289,7 @@ PNG_INTERNAL_FUNCTION(void,png_do_write_interlace,(png_row_infop row_info,
PNG_INTERNAL_FUNCTION(void,png_read_filter_row,(png_structrp pp, png_row_infop
row_info, png_bytep row, png_const_bytep prev_row, int filter),PNG_EMPTY);
+#if PNG_ARM_NEON_OPT > 0
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_neon,(png_row_infop row_info,
png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_neon,(png_row_infop
@@ -1224,7 +1304,43 @@ PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+#endif
+
+#if PNG_MIPS_MSA_OPT > 0
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_msa,(png_row_infop row_info,
+ png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_msa,(png_row_infop
+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_msa,(png_row_infop
+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_msa,(png_row_infop
+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_msa,(png_row_infop
+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_msa,(png_row_infop
+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_msa,(png_row_infop
+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+#endif
+#if PNG_POWERPC_VSX_OPT > 0
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_vsx,(png_row_infop row_info,
+ png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_vsx,(png_row_infop
+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_vsx,(png_row_infop
+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_vsx,(png_row_infop
+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_vsx,(png_row_infop
+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_vsx,(png_row_infop
+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_vsx,(png_row_infop
+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+#endif
+
+#if PNG_INTEL_SSE_IMPLEMENTATION > 0
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_sse2,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_sse2,(png_row_infop
@@ -1237,6 +1353,7 @@ PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_sse2,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_sse2,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
+#endif
/* Choose the best filter to use and filter the row data */
PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr,
@@ -1264,7 +1381,7 @@ PNG_INTERNAL_FUNCTION(void,png_read_finish_row,(png_structrp png_ptr),
/* Initialize the row buffers, etc. */
PNG_INTERNAL_FUNCTION(void,png_read_start_row,(png_structrp png_ptr),PNG_EMPTY);
-#if PNG_ZLIB_VERNUM >= 0x1240
+#if ZLIB_VERNUM >= 0x1240
PNG_INTERNAL_FUNCTION(int,png_zlib_inflate,(png_structrp png_ptr, int flush),
PNG_EMPTY);
# define PNG_INFLATE(pp, flush) png_zlib_inflate(pp, flush)
@@ -1330,6 +1447,11 @@ PNG_INTERNAL_FUNCTION(void,png_handle_cHRM,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
#endif
+#ifdef PNG_READ_eXIf_SUPPORTED
+PNG_INTERNAL_FUNCTION(void,png_handle_eXIf,(png_structrp png_ptr,
+ png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
+#endif
+
#ifdef PNG_READ_gAMA_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_gAMA,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
@@ -1405,8 +1527,11 @@ PNG_INTERNAL_FUNCTION(void,png_handle_zTXt,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
#endif
-PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_structrp png_ptr,
- png_uint_32 chunk_name),PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_const_structrp png_ptr,
+ const png_uint_32 chunk_name),PNG_EMPTY);
+
+PNG_INTERNAL_FUNCTION(void,png_check_chunk_length,(png_const_structrp png_ptr,
+ const png_uint_32 chunk_length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY);
@@ -1462,7 +1587,7 @@ PNG_INTERNAL_FUNCTION(void,png_push_have_info,(png_structrp png_ptr,
PNG_INTERNAL_FUNCTION(void,png_push_have_end,(png_structrp png_ptr,
png_inforp info_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_have_row,(png_structrp png_ptr,
- png_bytep row),PNG_EMPTY);
+ png_bytep row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_read_end,(png_structrp png_ptr,
png_inforp info_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_process_some_data,(png_structrp png_ptr,
@@ -1501,13 +1626,13 @@ PNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr,
PNG_INTERNAL_FUNCTION(void,png_colorspace_sync_info,(png_const_structrp png_ptr,
png_inforp info_ptr), PNG_EMPTY);
- /* Synchronize the info 'valid' flags with the colorspace */
+ /* Synchronize the info 'valid' flags with the colorspace */
PNG_INTERNAL_FUNCTION(void,png_colorspace_sync,(png_const_structrp png_ptr,
png_inforp info_ptr), PNG_EMPTY);
- /* Copy the png_struct colorspace to the info_struct and call the above to
- * synchronize the flags. Checks for NULL info_ptr and does nothing.
- */
+ /* Copy the png_struct colorspace to the info_struct and call the above to
+ * synchronize the flags. Checks for NULL info_ptr and does nothing.
+ */
#endif
/* Added at libpng version 1.4.0 */
@@ -1964,15 +2089,48 @@ PNG_INTERNAL_FUNCTION(void, PNG_FILTER_OPTIMIZATIONS, (png_structp png_ptr,
* the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in
* CFLAGS in place of CPPFLAGS *and* uses symbol prefixing.
*/
+# if PNG_ARM_NEON_OPT > 0
PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon,
(png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
+#endif
+
+#if PNG_MIPS_MSA_OPT > 0
+PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_msa,
+ (png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
+#endif
+
+# if PNG_INTEL_SSE_IMPLEMENTATION > 0
PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_sse2,
(png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
+# endif
#endif
PNG_INTERNAL_FUNCTION(png_uint_32, png_check_keyword, (png_structrp png_ptr,
png_const_charp key, png_bytep new_key), PNG_EMPTY);
+#if PNG_ARM_NEON_IMPLEMENTATION == 1
+PNG_INTERNAL_FUNCTION(void,
+ png_riffle_palette_rgba,
+ (png_structrp, png_row_infop),
+ PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(int,
+ png_do_expand_palette_neon_rgba,
+ (png_structrp,
+ png_row_infop,
+ png_const_bytep,
+ const png_bytepp,
+ const png_bytepp),
+ PNG_EMPTY);
+PNG_INTERNAL_FUNCTION(int,
+ png_do_expand_palette_neon_rgb,
+ (png_structrp,
+ png_row_infop,
+ png_const_bytep,
+ const png_bytepp,
+ const png_bytepp),
+ PNG_EMPTY);
+#endif
+
/* Maintainer: Put new private prototypes here ^ */
#include "pngdebug.h"
diff --git a/third_party/libpng16/pngread.c b/third_party/libpng16/pngread.c
index 0572c208cc..da32e9ad9c 100644
--- a/third_party/libpng16/pngread.c
+++ b/third_party/libpng16/pngread.c
@@ -1,8 +1,8 @@
/* pngread.c - read a PNG file
*
- * Last changed in libpng 1.6.17 [March 26, 2015]
- * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.33 [September 28, 2017]
+ * Copyright (c) 1998-2002,2004,2006-2017 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.)
*
@@ -28,10 +28,10 @@ png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
{
#ifndef PNG_USER_MEM_SUPPORTED
png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr,
- error_fn, warn_fn, NULL, NULL, NULL);
+ error_fn, warn_fn, NULL, NULL, NULL);
#else
return png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
- warn_fn, NULL, NULL, NULL);
+ warn_fn, NULL, NULL, NULL);
}
/* Alternate create PNG structure for reading, and allocate any memory
@@ -43,7 +43,7 @@ png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED)
{
png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr,
- error_fn, warn_fn, mem_ptr, malloc_fn, free_fn);
+ error_fn, warn_fn, mem_ptr, malloc_fn, free_fn);
#endif /* USER_MEM */
if (png_ptr != NULL)
@@ -175,6 +175,11 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
png_handle_cHRM(png_ptr, info_ptr, length);
#endif
+#ifdef PNG_READ_eXIf_SUPPORTED
+ else if (chunk_name == png_eXIf)
+ png_handle_eXIf(png_ptr, info_ptr, length);
+#endif
+
#ifdef PNG_READ_gAMA_SUPPORTED
else if (chunk_name == png_gAMA)
png_handle_gAMA(png_ptr, info_ptr, length);
@@ -252,7 +257,7 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
else
png_handle_unknown(png_ptr, info_ptr, length,
- PNG_HANDLE_CHUNK_AS_DEFAULT);
+ PNG_HANDLE_CHUNK_AS_DEFAULT);
}
}
#endif /* SEQUENTIAL_READ */
@@ -279,7 +284,7 @@ png_read_update_info(png_structrp png_ptr, png_inforp info_ptr)
/* New in 1.6.0 this avoids the bug of doing the initializations twice */
else
png_app_error(png_ptr,
- "png_read_update_info/png_start_read_image: duplicate call");
+ "png_read_update_info/png_start_read_image: duplicate call");
}
}
@@ -302,7 +307,7 @@ png_start_read_image(png_structrp png_ptr)
/* New in 1.6.0 this avoids the bug of doing the initializations twice */
else
png_app_error(png_ptr,
- "png_start_read_image/png_read_update_info: duplicate call");
+ "png_start_read_image/png_read_update_info: duplicate call");
}
}
#endif /* SEQUENTIAL_READ */
@@ -359,9 +364,9 @@ png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
- png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
- png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
- png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
+ png_uint_32 s0 = (png_uint_32)(*(rp ) << 8) | *(rp + 1);
+ png_uint_32 s1 = (png_uint_32)(*(rp + 2) << 8) | *(rp + 3);
+ png_uint_32 s2 = (png_uint_32)(*(rp + 4) << 8) | *(rp + 5);
png_uint_32 red = (s0 + s1 + 65536) & 0xffff;
png_uint_32 blue = (s2 + s1 + 65536) & 0xffff;
*(rp ) = (png_byte)((red >> 8) & 0xff);
@@ -534,13 +539,14 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
png_error(png_ptr, "Invalid attempt to read row data");
/* Fill the row with IDAT data: */
+ png_ptr->row_buf[0]=255; /* to force error if no data was found */
png_read_IDAT_data(png_ptr, png_ptr->row_buf, row_info.rowbytes + 1);
if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE)
{
if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST)
png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1,
- png_ptr->prev_row + 1, png_ptr->row_buf[0]);
+ png_ptr->prev_row + 1, png_ptr->row_buf[0]);
else
png_error(png_ptr, "bad adaptive filter value");
}
@@ -584,7 +590,7 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
{
if (png_ptr->pass < 6)
png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,
- png_ptr->transformations);
+ png_ptr->transformations);
if (dsp_row != NULL)
png_combine_row(png_ptr, dsp_row, 1/*display*/);
@@ -719,7 +725,7 @@ png_read_image(png_structrp png_ptr, png_bytepp image)
* but the caller should do it!
*/
png_warning(png_ptr, "Interlace handling should be turned on when "
- "using png_read_image");
+ "using png_read_image");
/* Make sure this is set correctly */
png_ptr->num_rows = png_ptr->height;
}
@@ -779,8 +785,8 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
/* Report invalid palette index; added at libng-1.5.10 */
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
- png_ptr->num_palette_max > png_ptr->num_palette)
- png_benign_error(png_ptr, "Read palette index exceeding num_palette");
+ png_ptr->num_palette_max > png_ptr->num_palette)
+ png_benign_error(png_ptr, "Read palette index exceeding num_palette");
#endif
do
@@ -842,6 +848,11 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
png_handle_cHRM(png_ptr, info_ptr, length);
#endif
+#ifdef PNG_READ_eXIf_SUPPORTED
+ else if (chunk_name == png_eXIf)
+ png_handle_eXIf(png_ptr, info_ptr, length);
+#endif
+
#ifdef PNG_READ_gAMA_SUPPORTED
else if (chunk_name == png_gAMA)
png_handle_gAMA(png_ptr, info_ptr, length);
@@ -919,7 +930,7 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
else
png_handle_unknown(png_ptr, info_ptr, length,
- PNG_HANDLE_CHUNK_AS_DEFAULT);
+ PNG_HANDLE_CHUNK_AS_DEFAULT);
} while ((png_ptr->mode & PNG_HAVE_IEND) == 0);
}
#endif /* SEQUENTIAL_READ */
@@ -1030,8 +1041,7 @@ png_set_read_status_fn(png_structrp png_ptr, png_read_status_ptr read_row_fn)
#ifdef PNG_INFO_IMAGE_SUPPORTED
void PNGAPI
png_read_png(png_structrp png_ptr, png_inforp info_ptr,
- int transforms,
- voidp params)
+ int transforms, voidp params)
{
if (png_ptr == NULL || info_ptr == NULL)
return;
@@ -1307,7 +1317,7 @@ png_image_read_init(png_imagep image)
if (info_ptr != NULL)
{
png_controlp control = png_voidcast(png_controlp,
- png_malloc_warn(png_ptr, (sizeof *control)));
+ png_malloc_warn(png_ptr, (sizeof *control)));
if (control != NULL)
{
@@ -1394,7 +1404,9 @@ png_image_read_header(png_voidp argument)
png_structrp png_ptr = image->opaque->png_ptr;
png_inforp info_ptr = image->opaque->info_ptr;
+#ifdef PNG_BENIGN_ERRORS_SUPPORTED
png_set_benign_errors(png_ptr, 1/*warn*/);
+#endif
png_read_info(png_ptr, info_ptr);
/* Do this the fast way; just read directly out of png_struct. */
@@ -1432,7 +1444,7 @@ png_image_read_header(png_voidp argument)
break;
case PNG_COLOR_TYPE_PALETTE:
- cmap_entries = png_ptr->num_palette;
+ cmap_entries = (png_uint_32)png_ptr->num_palette;
break;
default:
@@ -1470,12 +1482,12 @@ png_image_begin_read_from_stdio(png_imagep image, FILE* file)
else
return png_image_error(image,
- "png_image_begin_read_from_stdio: invalid argument");
+ "png_image_begin_read_from_stdio: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
- "png_image_begin_read_from_stdio: incorrect PNG_IMAGE_VERSION");
+ "png_image_begin_read_from_stdio: incorrect PNG_IMAGE_VERSION");
return 0;
}
@@ -1508,12 +1520,12 @@ png_image_begin_read_from_file(png_imagep image, const char *file_name)
else
return png_image_error(image,
- "png_image_begin_read_from_file: invalid argument");
+ "png_image_begin_read_from_file: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
- "png_image_begin_read_from_file: incorrect PNG_IMAGE_VERSION");
+ "png_image_begin_read_from_file: incorrect PNG_IMAGE_VERSION");
return 0;
}
@@ -1550,7 +1562,7 @@ png_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need)
}
int PNGAPI png_image_begin_read_from_memory(png_imagep image,
- png_const_voidp memory, png_size_t size)
+ png_const_voidp memory, png_size_t size)
{
if (image != NULL && image->version == PNG_IMAGE_VERSION)
{
@@ -1573,12 +1585,12 @@ int PNGAPI png_image_begin_read_from_memory(png_imagep image,
else
return png_image_error(image,
- "png_image_begin_read_from_memory: invalid argument");
+ "png_image_begin_read_from_memory: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
- "png_image_begin_read_from_memory: incorrect PNG_IMAGE_VERSION");
+ "png_image_begin_read_from_memory: incorrect PNG_IMAGE_VERSION");
return 0;
}
@@ -1624,12 +1636,12 @@ png_image_skip_unused_chunks(png_structrp png_ptr)
* IHDR, PLTE, tRNS, IDAT, and IEND chunks.
*/
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_NEVER,
- NULL, -1);
+ NULL, -1);
/* But do not ignore image data handling chunks */
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_AS_DEFAULT,
- chunks_to_process, (int)/*SAFE*/(sizeof chunks_to_process)/5);
- }
+ chunks_to_process, (int)/*SAFE*/(sizeof chunks_to_process)/5);
+ }
}
# define PNG_SKIP_CHUNKS(p) png_image_skip_unused_chunks(p)
@@ -1696,7 +1708,7 @@ decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding)
#ifdef __GNUC__
default:
png_error(display->image->opaque->png_ptr,
- "unexpected encoding (internal error)");
+ "unexpected encoding (internal error)");
#endif
}
@@ -1705,8 +1717,8 @@ decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding)
static png_uint_32
png_colormap_compose(png_image_read_control *display,
- png_uint_32 foreground, int foreground_encoding, png_uint_32 alpha,
- png_uint_32 background, int encoding)
+ png_uint_32 foreground, int foreground_encoding, png_uint_32 alpha,
+ png_uint_32 background, int encoding)
{
/* The file value is composed on the background, the background has the given
* encoding and so does the result, the file is encoded with P_FILE and the
@@ -1742,14 +1754,14 @@ png_colormap_compose(png_image_read_control *display,
*/
static void
png_create_colormap_entry(png_image_read_control *display,
- png_uint_32 ip, png_uint_32 red, png_uint_32 green, png_uint_32 blue,
- png_uint_32 alpha, int encoding)
+ png_uint_32 ip, png_uint_32 red, png_uint_32 green, png_uint_32 blue,
+ png_uint_32 alpha, int encoding)
{
png_imagep image = display->image;
const int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) != 0 ?
- P_LINEAR : P_sRGB;
+ P_LINEAR : P_sRGB;
const int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 &&
- (red != green || green != blue);
+ (red != green || green != blue);
if (ip > 255)
png_error(image->opaque->png_ptr, "color-map index out of range");
@@ -1882,7 +1894,7 @@ png_create_colormap_entry(png_image_read_control *display,
{
case 4:
entry[afirst ? 0 : 3] = (png_uint_16)alpha;
- /* FALL THROUGH */
+ /* FALLTHROUGH */
case 3:
if (alpha < 65535)
@@ -1904,7 +1916,7 @@ png_create_colormap_entry(png_image_read_control *display,
case 2:
entry[1 ^ afirst] = (png_uint_16)alpha;
- /* FALL THROUGH */
+ /* FALLTHROUGH */
case 1:
if (alpha < 65535)
@@ -1933,6 +1945,7 @@ png_create_colormap_entry(png_image_read_control *display,
{
case 4:
entry[afirst ? 0 : 3] = (png_byte)alpha;
+ /* FALLTHROUGH */
case 3:
entry[afirst + (2 ^ bgr)] = (png_byte)blue;
entry[afirst + 1] = (png_byte)green;
@@ -1941,6 +1954,7 @@ png_create_colormap_entry(png_image_read_control *display,
case 2:
entry[1 ^ afirst] = (png_byte)alpha;
+ /* FALLTHROUGH */
case 1:
entry[afirst] = (png_byte)green;
break;
@@ -1967,7 +1981,7 @@ make_gray_file_colormap(png_image_read_control *display)
for (i=0; i<256; ++i)
png_create_colormap_entry(display, i, i, i, i, 255, P_FILE);
- return i;
+ return (int)i;
}
static int
@@ -1978,7 +1992,7 @@ make_gray_colormap(png_image_read_control *display)
for (i=0; i<256; ++i)
png_create_colormap_entry(display, i, i, i, i, 255, P_sRGB);
- return i;
+ return (int)i;
}
#define PNG_GRAY_COLORMAP_ENTRIES 256
@@ -2029,10 +2043,10 @@ make_ga_colormap(png_image_read_control *display)
for (g=0; g<6; ++g)
png_create_colormap_entry(display, i++, g*51, g*51, g*51, a*51,
- P_sRGB);
+ P_sRGB);
}
- return i;
+ return (int)i;
}
#define PNG_GA_COLORMAP_ENTRIES 256
@@ -2053,11 +2067,11 @@ make_rgb_colormap(png_image_read_control *display)
for (b=0; b<6; ++b)
png_create_colormap_entry(display, i++, r*51, g*51, b*51, 255,
- P_sRGB);
+ P_sRGB);
}
}
- return i;
+ return (int)i;
}
#define PNG_RGB_COLORMAP_ENTRIES 216
@@ -2105,7 +2119,7 @@ png_image_read_colormap(png_voidp argument)
else if (display->background == NULL /* no way to remove it */)
png_error(png_ptr,
- "a background color must be supplied to remove alpha/transparency");
+ "background color must be supplied to remove alpha/transparency");
/* Get a copy of the background color (this avoids repeating the checks
* below.) The encoding is 8-bit sRGB or 16-bit linear, depending on the
@@ -2200,7 +2214,7 @@ png_image_read_colormap(png_voidp argument)
*/
if (i != trans)
png_create_colormap_entry(display, i, val, val, val, 255,
- P_FILE/*8-bit with file gamma*/);
+ P_FILE/*8-bit with file gamma*/);
/* Else this entry is transparent. The colors don't matter if
* there is an alpha channel (back_alpha == 0), but it does no
@@ -2212,7 +2226,7 @@ png_image_read_colormap(png_voidp argument)
*/
else
png_create_colormap_entry(display, i, back_r, back_g, back_b,
- back_alpha, output_encoding);
+ back_alpha, output_encoding);
}
/* We need libpng to preserve the original encoding. */
@@ -2250,7 +2264,7 @@ png_image_read_colormap(png_voidp argument)
if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries)
png_error(png_ptr, "gray[16] color-map: too few entries");
- cmap_entries = make_gray_colormap(display);
+ cmap_entries = (unsigned int)make_gray_colormap(display);
if (png_ptr->num_trans > 0)
{
@@ -2277,7 +2291,7 @@ png_image_read_colormap(png_voidp argument)
* matches.
*/
png_create_colormap_entry(display, gray, back_g, back_g,
- back_g, 65535, P_LINEAR);
+ back_g, 65535, P_LINEAR);
}
/* The background passed to libpng, however, must be the
@@ -2291,8 +2305,8 @@ png_image_read_colormap(png_voidp argument)
* doesn't.
*/
png_set_background_fixed(png_ptr, &c,
- PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
- 0/*gamma: not used*/);
+ PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
+ 0/*gamma: not used*/);
output_processing = PNG_CMAP_NONE;
break;
@@ -2322,7 +2336,7 @@ png_image_read_colormap(png_voidp argument)
* background color at full precision.
*/
png_create_colormap_entry(display, 254, back_r, back_g, back_b,
- back_alpha, output_encoding);
+ back_alpha, output_encoding);
}
else
@@ -2348,7 +2362,7 @@ png_image_read_colormap(png_voidp argument)
if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries)
png_error(png_ptr, "gray+alpha color-map: too few entries");
- cmap_entries = make_ga_colormap(display);
+ cmap_entries = (unsigned int)make_ga_colormap(display);
background_index = PNG_CMAP_GA_BACKGROUND;
output_processing = PNG_CMAP_GA;
@@ -2382,7 +2396,7 @@ png_image_read_colormap(png_voidp argument)
if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries)
png_error(png_ptr, "gray-alpha color-map: too few entries");
- cmap_entries = make_gray_colormap(display);
+ cmap_entries = (unsigned int)make_gray_colormap(display);
if (output_encoding == P_LINEAR)
{
@@ -2390,7 +2404,7 @@ png_image_read_colormap(png_voidp argument)
/* And make sure the corresponding palette entry matches. */
png_create_colormap_entry(display, gray, back_g, back_g,
- back_g, 65535, P_LINEAR);
+ back_g, 65535, P_LINEAR);
}
/* The background passed to libpng, however, must be the sRGB
@@ -2400,8 +2414,8 @@ png_image_read_colormap(png_voidp argument)
c.gray = c.red = c.green = c.blue = (png_uint_16)gray;
png_set_background_fixed(png_ptr, &c,
- PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
- 0/*gamma: not used*/);
+ PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
+ 0/*gamma: not used*/);
output_processing = PNG_CMAP_NONE;
}
@@ -2421,7 +2435,7 @@ png_image_read_colormap(png_voidp argument)
{
png_uint_32 gray = (i * 256 + 115) / 231;
png_create_colormap_entry(display, i++, gray, gray, gray,
- 255, P_sRGB);
+ 255, P_sRGB);
}
/* NOTE: this preserves the full precision of the application
@@ -2430,13 +2444,13 @@ png_image_read_colormap(png_voidp argument)
background_index = i;
png_create_colormap_entry(display, i++, back_r, back_g, back_b,
#ifdef __COVERITY__
- /* Coverity claims that output_encoding cannot be 2 (P_LINEAR)
- * here.
- */ 255U,
+ /* Coverity claims that output_encoding
+ * cannot be 2 (P_LINEAR) here.
+ */ 255U,
#else
- output_encoding == P_LINEAR ? 65535U : 255U,
+ output_encoding == P_LINEAR ? 65535U : 255U,
#endif
- output_encoding);
+ output_encoding);
/* For non-opaque input composite on the sRGB background - this
* requires inverting the encoding for each component. The input
@@ -2474,9 +2488,9 @@ png_image_read_colormap(png_voidp argument)
png_uint_32 gray = png_sRGB_table[g*51] * alpha;
png_create_colormap_entry(display, i++,
- PNG_sRGB_FROM_LINEAR(gray + back_rx),
- PNG_sRGB_FROM_LINEAR(gray + back_gx),
- PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, P_sRGB);
+ PNG_sRGB_FROM_LINEAR(gray + back_rx),
+ PNG_sRGB_FROM_LINEAR(gray + back_gx),
+ PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, P_sRGB);
}
}
@@ -2502,7 +2516,7 @@ png_image_read_colormap(png_voidp argument)
* png_set_tRNS_to_alpha before png_set_background_fixed.
*/
png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, -1,
- -1);
+ -1);
data_encoding = P_sRGB;
/* The output will now be one or two 8-bit gray or gray+alpha
@@ -2521,7 +2535,7 @@ png_image_read_colormap(png_voidp argument)
if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries)
png_error(png_ptr, "rgb[ga] color-map: too few entries");
- cmap_entries = make_ga_colormap(display);
+ cmap_entries = (unsigned int)make_ga_colormap(display);
background_index = PNG_CMAP_GA_BACKGROUND;
output_processing = PNG_CMAP_GA;
}
@@ -2547,12 +2561,12 @@ png_image_read_colormap(png_voidp argument)
png_ptr->num_trans > 0) &&
png_gamma_not_sRGB(png_ptr->colorspace.gamma) != 0)
{
- cmap_entries = make_gray_file_colormap(display);
+ cmap_entries = (unsigned int)make_gray_file_colormap(display);
data_encoding = P_FILE;
}
else
- cmap_entries = make_gray_colormap(display);
+ cmap_entries = (unsigned int)make_gray_colormap(display);
/* But if the input has alpha or transparency it must be removed
*/
@@ -2578,13 +2592,13 @@ png_image_read_colormap(png_voidp argument)
gray = png_sRGB_table[gray]; /* now P_LINEAR */
gray = PNG_DIV257(png_gamma_16bit_correct(gray,
- png_ptr->colorspace.gamma)); /* now P_FILE */
+ png_ptr->colorspace.gamma)); /* now P_FILE */
/* And make sure the corresponding palette entry contains
* exactly the required sRGB value.
*/
png_create_colormap_entry(display, gray, back_g, back_g,
- back_g, 0/*unused*/, output_encoding);
+ back_g, 0/*unused*/, output_encoding);
}
else if (output_encoding == P_LINEAR)
@@ -2609,8 +2623,8 @@ png_image_read_colormap(png_voidp argument)
*/
expand_tRNS = 1;
png_set_background_fixed(png_ptr, &c,
- PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
- 0/*gamma: not used*/);
+ PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
+ 0/*gamma: not used*/);
}
output_processing = PNG_CMAP_NONE;
@@ -2640,11 +2654,11 @@ png_image_read_colormap(png_voidp argument)
if (PNG_RGB_COLORMAP_ENTRIES+1+27 > image->colormap_entries)
png_error(png_ptr, "rgb+alpha color-map: too few entries");
- cmap_entries = make_rgb_colormap(display);
+ cmap_entries = (unsigned int)make_rgb_colormap(display);
/* Add a transparent entry. */
png_create_colormap_entry(display, cmap_entries, 255, 255,
- 255, 0, P_sRGB);
+ 255, 0, P_sRGB);
/* This is stored as the background index for the processing
* algorithm.
@@ -2665,7 +2679,7 @@ png_image_read_colormap(png_voidp argument)
*/
for (b=0; b<256; b = (b << 1) | 0x7f)
png_create_colormap_entry(display, cmap_entries++,
- r, g, b, 128, P_sRGB);
+ r, g, b, 128, P_sRGB);
}
}
@@ -2689,10 +2703,10 @@ png_image_read_colormap(png_voidp argument)
if (PNG_RGB_COLORMAP_ENTRIES+1+27 > image->colormap_entries)
png_error(png_ptr, "rgb-alpha color-map: too few entries");
- cmap_entries = make_rgb_colormap(display);
+ cmap_entries = (unsigned int)make_rgb_colormap(display);
png_create_colormap_entry(display, cmap_entries, back_r,
- back_g, back_b, 0/*unused*/, output_encoding);
+ back_g, back_b, 0/*unused*/, output_encoding);
if (output_encoding == P_LINEAR)
{
@@ -2714,9 +2728,9 @@ png_image_read_colormap(png_voidp argument)
* index.
*/
if (memcmp((png_const_bytep)display->colormap +
- sample_size * cmap_entries,
- (png_const_bytep)display->colormap +
- sample_size * PNG_RGB_INDEX(r,g,b),
+ sample_size * cmap_entries,
+ (png_const_bytep)display->colormap +
+ sample_size * PNG_RGB_INDEX(r,g,b),
sample_size) != 0)
{
/* The background color must be added. */
@@ -2734,13 +2748,13 @@ png_image_read_colormap(png_voidp argument)
*/
for (b=0; b<256; b = (b << 1) | 0x7f)
png_create_colormap_entry(display, cmap_entries++,
- png_colormap_compose(display, r, P_sRGB, 128,
- back_r, output_encoding),
- png_colormap_compose(display, g, P_sRGB, 128,
- back_g, output_encoding),
- png_colormap_compose(display, b, P_sRGB, 128,
- back_b, output_encoding),
- 0/*unused*/, output_encoding);
+ png_colormap_compose(display, r, P_sRGB, 128,
+ back_r, output_encoding),
+ png_colormap_compose(display, g, P_sRGB, 128,
+ back_g, output_encoding),
+ png_colormap_compose(display, b, P_sRGB, 128,
+ back_b, output_encoding),
+ 0/*unused*/, output_encoding);
}
}
@@ -2758,8 +2772,8 @@ png_image_read_colormap(png_voidp argument)
c.blue = (png_uint_16)back_b;
png_set_background_fixed(png_ptr, &c,
- PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
- 0/*gamma: not used*/);
+ PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
+ 0/*gamma: not used*/);
output_processing = PNG_CMAP_RGB;
}
@@ -2774,7 +2788,7 @@ png_image_read_colormap(png_voidp argument)
if (PNG_RGB_COLORMAP_ENTRIES > image->colormap_entries)
png_error(png_ptr, "rgb color-map: too few entries");
- cmap_entries = make_rgb_colormap(display);
+ cmap_entries = (unsigned int)make_rgb_colormap(display);
output_processing = PNG_CMAP_RGB;
}
}
@@ -2798,11 +2812,11 @@ png_image_read_colormap(png_voidp argument)
output_processing = PNG_CMAP_NONE;
data_encoding = P_FILE; /* Don't change from color-map indices */
- cmap_entries = png_ptr->num_palette;
+ cmap_entries = (unsigned int)png_ptr->num_palette;
if (cmap_entries > 256)
cmap_entries = 256;
- if (cmap_entries > image->colormap_entries)
+ if (cmap_entries > (unsigned int)image->colormap_entries)
png_error(png_ptr, "palette color-map: too few entries");
for (i=0; i < cmap_entries; ++i)
@@ -2811,7 +2825,7 @@ png_image_read_colormap(png_voidp argument)
{
if (trans[i] == 0)
png_create_colormap_entry(display, i, back_r, back_g,
- back_b, 0, output_encoding);
+ back_b, 0, output_encoding);
else
{
@@ -2819,22 +2833,22 @@ png_image_read_colormap(png_voidp argument)
* on the sRGB color in 'back'.
*/
png_create_colormap_entry(display, i,
- png_colormap_compose(display, colormap[i].red, P_FILE,
- trans[i], back_r, output_encoding),
- png_colormap_compose(display, colormap[i].green, P_FILE,
- trans[i], back_g, output_encoding),
- png_colormap_compose(display, colormap[i].blue, P_FILE,
- trans[i], back_b, output_encoding),
- output_encoding == P_LINEAR ? trans[i] * 257U :
- trans[i],
- output_encoding);
+ png_colormap_compose(display, colormap[i].red,
+ P_FILE, trans[i], back_r, output_encoding),
+ png_colormap_compose(display, colormap[i].green,
+ P_FILE, trans[i], back_g, output_encoding),
+ png_colormap_compose(display, colormap[i].blue,
+ P_FILE, trans[i], back_b, output_encoding),
+ output_encoding == P_LINEAR ? trans[i] * 257U :
+ trans[i],
+ output_encoding);
}
}
else
png_create_colormap_entry(display, i, colormap[i].red,
- colormap[i].green, colormap[i].blue,
- i < num_trans ? trans[i] : 255U, P_FILE/*8-bit*/);
+ colormap[i].green, colormap[i].blue,
+ i < num_trans ? trans[i] : 255U, P_FILE/*8-bit*/);
}
/* The PNG data may have indices packed in fewer than 8 bits, it
@@ -2860,7 +2874,7 @@ png_image_read_colormap(png_voidp argument)
case P_sRGB:
/* Change to 8-bit sRGB */
png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB);
- /* FALL THROUGH */
+ /* FALLTHROUGH */
case P_FILE:
if (png_ptr->bit_depth > 8)
@@ -2914,7 +2928,7 @@ png_image_read_colormap(png_voidp argument)
png_error(png_ptr, "bad background index (internal error)");
}
- display->colormap_processing = output_processing;
+ display->colormap_processing = (int)output_processing;
return 1/*ok*/;
}
@@ -2924,7 +2938,7 @@ static int
png_image_read_and_map(png_voidp argument)
{
png_image_read_control *display = png_voidcast(png_image_read_control*,
- argument);
+ argument);
png_imagep image = display->image;
png_structrp png_ptr = image->opaque->png_ptr;
int passes;
@@ -3061,7 +3075,7 @@ png_image_read_and_map(png_voidp argument)
if (alpha >= 196)
*outrow = PNG_RGB_INDEX(inrow[0], inrow[1],
- inrow[2]);
+ inrow[2]);
else if (alpha < 64)
*outrow = PNG_CMAP_RGB_ALPHA_BACKGROUND;
@@ -3113,7 +3127,7 @@ static int
png_image_read_colormapped(png_voidp argument)
{
png_image_read_control *display = png_voidcast(png_image_read_control*,
- argument);
+ argument);
png_imagep image = display->image;
png_controlp control = image->opaque;
png_structrp png_ptr = control->png_ptr;
@@ -3178,8 +3192,7 @@ png_image_read_colormapped(png_voidp argument)
image->colormap_entries == 244 /* 216 + 1 + 27 */)
break;
- /* goto bad_output; */
- /* FALL THROUGH */
+ goto bad_output;
default:
bad_output:
@@ -3223,14 +3236,14 @@ png_image_read_colormapped(png_voidp argument)
else
{
- png_alloc_size_t row_bytes = display->row_bytes;
+ png_alloc_size_t row_bytes = (png_alloc_size_t)display->row_bytes;
while (--passes >= 0)
{
png_uint_32 y = image->height;
png_bytep row = png_voidcast(png_bytep, display->first_row);
- while (y-- > 0)
+ for (; y > 0; --y)
{
png_read_row(png_ptr, row, NULL);
row += row_bytes;
@@ -3246,7 +3259,7 @@ static int
png_image_read_composite(png_voidp argument)
{
png_image_read_control *display = png_voidcast(png_image_read_control*,
- argument);
+ argument);
png_imagep image = display->image;
png_structrp png_ptr = image->opaque->png_ptr;
int passes;
@@ -3373,7 +3386,7 @@ static int
png_image_read_background(png_voidp argument)
{
png_image_read_control *display = png_voidcast(png_image_read_control*,
- argument);
+ argument);
png_imagep image = display->image;
png_structrp png_ptr = image->opaque->png_ptr;
png_inforp info_ptr = image->opaque->info_ptr;
@@ -3433,8 +3446,7 @@ png_image_read_background(png_voidp argument)
for (pass = 0; pass < passes; ++pass)
{
- png_bytep row = png_voidcast(png_bytep,
- display->first_row);
+ png_bytep row = png_voidcast(png_bytep, display->first_row);
unsigned int startx, stepx, stepy;
png_uint_32 y;
@@ -3462,7 +3474,7 @@ png_image_read_background(png_voidp argument)
for (; y<height; y += stepy)
{
png_bytep inrow = png_voidcast(png_bytep,
- display->local_row);
+ display->local_row);
png_bytep outrow = first_row + y * step_row;
png_const_bytep end_row = outrow + width;
@@ -3507,7 +3519,7 @@ png_image_read_background(png_voidp argument)
for (; y<height; y += stepy)
{
png_bytep inrow = png_voidcast(png_bytep,
- display->local_row);
+ display->local_row);
png_bytep outrow = first_row + y * step_row;
png_const_bytep end_row = outrow + width;
@@ -3554,13 +3566,14 @@ png_image_read_background(png_voidp argument)
*/
{
png_uint_16p first_row = png_voidcast(png_uint_16p,
- display->first_row);
+ display->first_row);
/* The division by two is safe because the caller passed in a
* stride which was multiplied by 2 (below) to get row_bytes.
*/
ptrdiff_t step_row = display->row_bytes / 2;
- int preserve_alpha = (image->format & PNG_FORMAT_FLAG_ALPHA) != 0;
- unsigned int outchannels = 1+preserve_alpha;
+ unsigned int preserve_alpha = (image->format &
+ PNG_FORMAT_FLAG_ALPHA) != 0;
+ unsigned int outchannels = 1U+preserve_alpha;
int swap_alpha = 0;
# ifdef PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
@@ -3604,7 +3617,7 @@ png_image_read_background(png_voidp argument)
/* Read the row, which is packed: */
png_read_row(png_ptr, png_voidcast(png_bytep,
- display->local_row), NULL);
+ display->local_row), NULL);
inrow = png_voidcast(png_const_uint_16p, display->local_row);
/* Now do the pre-multiplication on each pixel in this row.
@@ -3653,7 +3666,7 @@ static int
png_image_read_direct(png_voidp argument)
{
png_image_read_control *display = png_voidcast(png_image_read_control*,
- argument);
+ argument);
png_imagep image = display->image;
png_structrp png_ptr = image->opaque->png_ptr;
png_inforp info_ptr = image->opaque->info_ptr;
@@ -3704,7 +3717,7 @@ png_image_read_direct(png_voidp argument)
do_local_background = 1/*maybe*/;
png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE,
- PNG_RGB_TO_GRAY_DEFAULT, PNG_RGB_TO_GRAY_DEFAULT);
+ PNG_RGB_TO_GRAY_DEFAULT, PNG_RGB_TO_GRAY_DEFAULT);
}
change &= ~PNG_FORMAT_FLAG_COLOR;
@@ -3746,7 +3759,13 @@ png_image_read_direct(png_voidp argument)
mode = PNG_ALPHA_PNG;
output_gamma = PNG_DEFAULT_sRGB;
}
-
+
+ if ((change & PNG_FORMAT_FLAG_ASSOCIATED_ALPHA) != 0)
+ {
+ mode = PNG_ALPHA_OPTIMIZED;
+ change &= ~PNG_FORMAT_FLAG_ASSOCIATED_ALPHA;
+ }
+
/* If 'do_local_background' is set check for the presence of gamma
* correction; this is part of the work-round for the libpng bug
* described above.
@@ -3763,7 +3782,7 @@ png_image_read_direct(png_voidp argument)
* final value.
*/
if (png_muldiv(&gtest, output_gamma, png_ptr->colorspace.gamma,
- PNG_FP_1) != 0 && png_gamma_significant(gtest) == 0)
+ PNG_FP_1) != 0 && png_gamma_significant(gtest) == 0)
do_local_background = 0;
else if (mode == PNG_ALPHA_STANDARD)
@@ -3826,8 +3845,8 @@ png_image_read_direct(png_voidp argument)
* pixels.
*/
png_set_background_fixed(png_ptr, &c,
- PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
- 0/*gamma: not used*/);
+ PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
+ 0/*gamma: not used*/);
}
else /* compose on row: implemented below. */
@@ -3972,6 +3991,10 @@ png_image_read_direct(png_voidp argument)
else if (do_local_compose != 0) /* internal error */
png_error(png_ptr, "png_image_read: alpha channel lost");
+ if ((format & PNG_FORMAT_FLAG_ASSOCIATED_ALPHA) != 0) {
+ info_format |= PNG_FORMAT_FLAG_ASSOCIATED_ALPHA;
+ }
+
if (info_ptr->bit_depth == 16)
info_format |= PNG_FORMAT_FLAG_LINEAR;
@@ -4057,14 +4080,14 @@ png_image_read_direct(png_voidp argument)
else
{
- png_alloc_size_t row_bytes = display->row_bytes;
+ png_alloc_size_t row_bytes = (png_alloc_size_t)display->row_bytes;
while (--passes >= 0)
{
png_uint_32 y = image->height;
png_bytep row = png_voidcast(png_bytep, display->first_row);
- while (y-- > 0)
+ for (; y > 0; --y)
{
png_read_row(png_ptr, row, NULL);
row += row_bytes;
@@ -4077,7 +4100,7 @@ png_image_read_direct(png_voidp argument)
int PNGAPI
png_image_finish_read(png_imagep image, png_const_colorp background,
- void *buffer, png_int_32 row_stride, void *colormap)
+ void *buffer, png_int_32 row_stride, void *colormap)
{
if (image != NULL && image->version == PNG_IMAGE_VERSION)
{
@@ -4087,7 +4110,13 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
*/
const unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format);
- if (image->width <= 0x7FFFFFFFU/channels) /* no overflow */
+ /* The following checks just the 'row_stride' calculation to ensure it
+ * fits in a signed 32-bit value. Because channels/components can be
+ * either 1 or 2 bytes in size the length of a row can still overflow 32
+ * bits; this is just to verify that the 'row_stride' argument can be
+ * represented.
+ */
+ if (image->width <= 0x7fffffffU/channels) /* no overflow */
{
png_uint_32 check;
const png_uint_32 png_row_stride = image->width * channels;
@@ -4096,18 +4125,35 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
row_stride = (png_int_32)/*SAFE*/png_row_stride;
if (row_stride < 0)
- check = -row_stride;
+ check = (png_uint_32)(-row_stride);
else
- check = row_stride;
+ check = (png_uint_32)row_stride;
+ /* This verifies 'check', the absolute value of the actual stride
+ * passed in and detects overflow in the application calculation (i.e.
+ * if the app did actually pass in a non-zero 'row_stride'.
+ */
if (image->opaque != NULL && buffer != NULL && check >= png_row_stride)
{
/* Now check for overflow of the image buffer calculation; this
* limits the whole image size to 32 bits for API compatibility with
* the current, 32-bit, PNG_IMAGE_BUFFER_SIZE macro.
+ *
+ * The PNG_IMAGE_BUFFER_SIZE macro is:
+ *
+ * (PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)*height*(row_stride))
+ *
+ * And the component size is always 1 or 2, so make sure that the
+ * number of *bytes* that the application is saying are available
+ * does actually fit into a 32-bit number.
+ *
+ * NOTE: this will be changed in 1.7 because PNG_IMAGE_BUFFER_SIZE
+ * will be changed to use png_alloc_size_t; bigger images can be
+ * accomodated on 64-bit systems.
*/
- if (image->height <= 0xFFFFFFFF/png_row_stride)
+ if (image->height <=
+ 0xffffffffU/PNG_IMAGE_PIXEL_COMPONENT_SIZE(image->format)/check)
{
if ((image->format & PNG_FORMAT_FLAG_COLORMAP) == 0 ||
(image->colormap_entries > 0 && colormap != NULL))
@@ -4127,15 +4173,16 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
* all the setup has already been done.
*/
if ((image->format & PNG_FORMAT_FLAG_COLORMAP) != 0)
- result = png_safe_execute(image,
- png_image_read_colormap, &display) &&
- png_safe_execute(image,
- png_image_read_colormapped, &display);
+ result =
+ png_safe_execute(image,
+ png_image_read_colormap, &display) &&
+ png_safe_execute(image,
+ png_image_read_colormapped, &display);
else
result =
png_safe_execute(image,
- png_image_read_direct, &display);
+ png_image_read_direct, &display);
png_image_free(image);
return result;
@@ -4143,27 +4190,27 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
else
return png_image_error(image,
- "png_image_finish_read[color-map]: no color-map");
+ "png_image_finish_read[color-map]: no color-map");
}
else
return png_image_error(image,
- "png_image_finish_read: image too large");
+ "png_image_finish_read: image too large");
}
else
return png_image_error(image,
- "png_image_finish_read: invalid argument");
+ "png_image_finish_read: invalid argument");
}
else
return png_image_error(image,
- "png_image_finish_read: row_stride too large");
+ "png_image_finish_read: row_stride too large");
}
else if (image != NULL)
return png_image_error(image,
- "png_image_finish_read: damaged PNG_IMAGE_VERSION");
+ "png_image_finish_read: damaged PNG_IMAGE_VERSION");
return 0;
}
diff --git a/third_party/libpng16/pngrio.c b/third_party/libpng16/pngrio.c
index 5101d54a62..7e26e855ca 100644
--- a/third_party/libpng16/pngrio.c
+++ b/third_party/libpng16/pngrio.c
@@ -1,8 +1,8 @@
/* pngrio.c - functions for data input
*
- * Last changed in libpng 1.6.17 [March 26, 2015]
- * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.24 [August 4, 2016]
+ * Copyright (c) 1998-2002,2004,2006-2016 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.)
*
@@ -85,7 +85,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
*/
void PNGAPI
png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
- png_rw_ptr read_data_fn)
+ png_rw_ptr read_data_fn)
{
if (png_ptr == NULL)
return;
diff --git a/third_party/libpng16/pngrtran.c b/third_party/libpng16/pngrtran.c
index 3138147aff..9dd82c929b 100644
--- a/third_party/libpng16/pngrtran.c
+++ b/third_party/libpng16/pngrtran.c
@@ -1,8 +1,8 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
- * Last changed in libpng 1.6.22 [May 26, 2016]
- * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.33 [September 28, 2017]
+ * Copyright (c) 1998-2002,2004,2006-2017 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.)
*
@@ -18,6 +18,13 @@
#include "pngpriv.h"
+#ifdef PNG_ARM_NEON_IMPLEMENTATION
+#if PNG_ARM_NEON_IMPLEMENTATION == 1
+#define PNG_ARM_NEON_INTRINSICS_AVAILABLE
+#include <arm_neon.h>
+#endif
+#endif
+
#ifdef PNG_READ_SUPPORTED
/* Set the action on getting a CRC error for an ancillary or critical chunk. */
@@ -48,7 +55,8 @@ png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action)
case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */
png_warning(png_ptr,
- "Can't discard critical data on CRC error");
+ "Can't discard critical data on CRC error");
+ /* FALLTHROUGH */
case PNG_CRC_ERROR_QUIT: /* Error/quit */
case PNG_CRC_DEFAULT:
@@ -101,7 +109,7 @@ png_rtran_ok(png_structrp png_ptr, int need_IHDR)
{
if ((png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)
png_app_error(png_ptr,
- "invalid after png_start_read_image or png_read_update_info");
+ "invalid after png_start_read_image or png_read_update_info");
else if (need_IHDR && (png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_app_error(png_ptr, "invalid before the PNG header has been read");
@@ -209,7 +217,7 @@ png_set_strip_alpha(png_structrp png_ptr)
#if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
static png_fixed_point
translate_gamma_flags(png_structrp png_ptr, png_fixed_point output_gamma,
- int is_screen)
+ int is_screen)
{
/* Check for flag values. The main reason for having the old Mac value as a
* flag is that it is pretty near impossible to work out what the correct
@@ -273,7 +281,7 @@ convert_gamma_value(png_structrp png_ptr, double output_gamma)
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
void PNGFAPI
png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
- png_fixed_point output_gamma)
+ png_fixed_point output_gamma)
{
int compose = 0;
png_fixed_point file_gamma;
@@ -377,7 +385,7 @@ png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
if ((png_ptr->transformations & PNG_COMPOSE) != 0)
png_error(png_ptr,
- "conflicting calls to set alpha mode and background");
+ "conflicting calls to set alpha mode and background");
png_ptr->transformations |= PNG_COMPOSE;
}
@@ -388,7 +396,7 @@ void PNGAPI
png_set_alpha_mode(png_structrp png_ptr, int mode, double output_gamma)
{
png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr,
- output_gamma));
+ output_gamma));
}
# endif
#endif
@@ -429,7 +437,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
int i;
png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,
- (png_uint_32)(num_palette * (sizeof (png_byte))));
+ (png_alloc_size_t)((png_uint_32)num_palette * (sizeof (png_byte))));
for (i = 0; i < num_palette; i++)
png_ptr->quantize_index[i] = (png_byte)i;
}
@@ -446,7 +454,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
/* Initialize an array to sort colors */
png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,
- (png_uint_32)(num_palette * (sizeof (png_byte))));
+ (png_alloc_size_t)((png_uint_32)num_palette * (sizeof (png_byte))));
/* Initialize the quantize_sort array */
for (i = 0; i < num_palette; i++)
@@ -580,9 +588,11 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
/* Initialize palette index arrays */
png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
- (png_uint_32)(num_palette * (sizeof (png_byte))));
+ (png_alloc_size_t)((png_uint_32)num_palette *
+ (sizeof (png_byte))));
png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
- (png_uint_32)(num_palette * (sizeof (png_byte))));
+ (png_alloc_size_t)((png_uint_32)num_palette *
+ (sizeof (png_byte))));
/* Initialize the sort array */
for (i = 0; i < num_palette; i++)
@@ -591,7 +601,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
png_ptr->palette_to_index[i] = (png_byte)i;
}
- hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 *
+ hash = (png_dsortpp)png_calloc(png_ptr, (png_alloc_size_t)(769 *
(sizeof (png_dsortp))));
num_new_palette = num_palette;
@@ -622,7 +632,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
{
t = (png_dsortp)png_malloc_warn(png_ptr,
- (png_uint_32)(sizeof (png_dsort)));
+ (png_alloc_size_t)(sizeof (png_dsort)));
if (t == NULL)
break;
@@ -747,9 +757,9 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
png_size_t num_entries = ((png_size_t)1 << total_bits);
png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr,
- (png_uint_32)(num_entries * (sizeof (png_byte))));
+ (png_alloc_size_t)(num_entries * (sizeof (png_byte))));
- distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
+ distance = (png_bytep)png_malloc(png_ptr, (png_alloc_size_t)(num_entries *
(sizeof (png_byte))));
memset(distance, 0xff, num_entries * (sizeof (png_byte)));
@@ -802,7 +812,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
#ifdef PNG_READ_GAMMA_SUPPORTED
void PNGFAPI
png_set_gamma_fixed(png_structrp png_ptr, png_fixed_point scrn_gamma,
- png_fixed_point file_gamma)
+ png_fixed_point file_gamma)
{
png_debug(1, "in png_set_gamma_fixed");
@@ -844,7 +854,7 @@ void PNGAPI
png_set_gamma(png_structrp png_ptr, double scrn_gamma, double file_gamma)
{
png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma),
- convert_gamma_value(png_ptr, file_gamma));
+ convert_gamma_value(png_ptr, file_gamma));
}
# endif /* FLOATING_POINT */
#endif /* READ_GAMMA */
@@ -990,7 +1000,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
* that it just worked and get a memory overwrite.
*/
png_error(png_ptr,
- "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
+ "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
/* png_ptr->transformations &= ~PNG_RGB_TO_GRAY; */
}
@@ -1017,7 +1027,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
{
if (red >= 0 && green >= 0)
png_app_warning(png_ptr,
- "ignoring out of range rgb_to_gray coefficients");
+ "ignoring out of range rgb_to_gray coefficients");
/* Use the defaults, from the cHRM chunk if set, else the historical
* values which are close to the sRGB/HDTV/ITU-Rec 709 values. See
@@ -1026,7 +1036,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
* something has already provided a default.
*/
if (png_ptr->rgb_to_gray_red_coeff == 0 &&
- png_ptr->rgb_to_gray_green_coeff == 0)
+ png_ptr->rgb_to_gray_green_coeff == 0)
{
png_ptr->rgb_to_gray_red_coeff = 6968;
png_ptr->rgb_to_gray_green_coeff = 23434;
@@ -1043,10 +1053,10 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
void PNGAPI
png_set_rgb_to_gray(png_structrp png_ptr, int error_action, double red,
- double green)
+ double green)
{
png_set_rgb_to_gray_fixed(png_ptr, error_action,
- png_fixed(png_ptr, red, "rgb to gray red coefficient"),
+ png_fixed(png_ptr, red, "rgb to gray red coefficient"),
png_fixed(png_ptr, green, "rgb to gray green coefficient"));
}
#endif /* FLOATING POINT */
@@ -1253,7 +1263,7 @@ png_init_rgb_transformations(png_structrp png_ptr)
default:
case 8:
- /* FALL THROUGH (Already 8 bits) */
+ /* FALLTHROUGH */ /* (Already 8 bits) */
case 16:
/* Already a full 16 bits */
@@ -1303,7 +1313,7 @@ png_init_read_transformations(png_structrp png_ptr)
{
if (png_ptr->screen_gamma != 0) /* screen set too */
gamma_correction = png_gamma_threshold(png_ptr->colorspace.gamma,
- png_ptr->screen_gamma);
+ png_ptr->screen_gamma);
else
/* Assume the output matches the input; a long time default behavior
@@ -1584,7 +1594,7 @@ png_init_read_transformations(png_structrp png_ptr)
*/
if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
png_warning(png_ptr,
- "libpng does not support gamma+background+rgb_to_gray");
+ "libpng does not support gamma+background+rgb_to_gray");
if ((png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) != 0)
{
@@ -1620,13 +1630,13 @@ png_init_read_transformations(png_structrp png_ptr)
case PNG_BACKGROUND_GAMMA_FILE:
g = png_reciprocal(png_ptr->colorspace.gamma);
gs = png_reciprocal2(png_ptr->colorspace.gamma,
- png_ptr->screen_gamma);
+ png_ptr->screen_gamma);
break;
case PNG_BACKGROUND_GAMMA_UNIQUE:
g = png_reciprocal(png_ptr->background_gamma);
gs = png_reciprocal2(png_ptr->background_gamma,
- png_ptr->screen_gamma);
+ png_ptr->screen_gamma);
break;
default:
g = PNG_FP_1; /* back_1 */
@@ -1654,11 +1664,11 @@ png_init_read_transformations(png_structrp png_ptr)
if (png_gamma_significant(g) != 0)
{
back_1.red = png_gamma_8bit_correct(png_ptr->background.red,
- g);
+ g);
back_1.green = png_gamma_8bit_correct(
- png_ptr->background.green, g);
+ png_ptr->background.green, g);
back_1.blue = png_gamma_8bit_correct(png_ptr->background.blue,
- g);
+ g);
}
else
@@ -1729,7 +1739,7 @@ png_init_read_transformations(png_structrp png_ptr)
case PNG_BACKGROUND_GAMMA_FILE:
g = png_reciprocal(png_ptr->colorspace.gamma);
gs = png_reciprocal2(png_ptr->colorspace.gamma,
- png_ptr->screen_gamma);
+ png_ptr->screen_gamma);
break;
case PNG_BACKGROUND_GAMMA_UNIQUE:
@@ -2150,7 +2160,7 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
{
png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
png_bytep dp = row + (png_size_t)row_width - 1;
- png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
+ png_uint_32 shift = 7U - ((row_width + 7U) & 0x07);
for (i = 0; i < row_width; i++)
{
*dp = (png_byte)((*sp >> shift) & 0x01);
@@ -2174,7 +2184,7 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
png_bytep dp = row + (png_size_t)row_width - 1;
- png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
+ png_uint_32 shift = ((3U - ((row_width + 3U) & 0x03)) << 1);
for (i = 0; i < row_width; i++)
{
*dp = (png_byte)((*sp >> shift) & 0x03);
@@ -2197,7 +2207,7 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
{
png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
png_bytep dp = row + (png_size_t)row_width - 1;
- png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
+ png_uint_32 shift = ((1U - ((row_width + 1U) & 0x01)) << 2);
for (i = 0; i < row_width; i++)
{
*dp = (png_byte)((*sp >> shift) & 0x0f);
@@ -2934,7 +2944,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
* using the equation given in Poynton's ColorFAQ of 1998-01-04 at
* <http://www.inforamp.net/~poynton/> (THIS LINK IS DEAD June 2008 but
* versions dated 1998 through November 2002 have been archived at
- * http://web.archive.org/web/20000816232553/http://www.inforamp.net/
+ * https://web.archive.org/web/20000816232553/www.inforamp.net/
* ~poynton/notes/colour_and_gamma/ColorFAQ.txt )
* Charles Poynton poynton at poynton.com
*
@@ -3223,7 +3233,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
== png_ptr->trans_color.gray)
{
unsigned int tmp = *sp & (0x7f7f >> (7 - shift));
- tmp |= png_ptr->background.gray << shift;
+ tmp |=
+ (unsigned int)(png_ptr->background.gray << shift);
*sp = (png_byte)(tmp & 0xff);
}
@@ -3252,7 +3263,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
== png_ptr->trans_color.gray)
{
unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
- tmp |= png_ptr->background.gray << shift;
+ tmp |=
+ (unsigned int)png_ptr->background.gray << shift;
*sp = (png_byte)(tmp & 0xff);
}
@@ -3262,7 +3274,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
unsigned int g = (gamma_table [p | (p << 2) |
(p << 4) | (p << 6)] >> 6) & 0x03;
unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
- tmp |= g << shift;
+ tmp |= (unsigned int)(g << shift);
*sp = (png_byte)(tmp & 0xff);
}
@@ -3288,7 +3300,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
== png_ptr->trans_color.gray)
{
unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
- tmp |= png_ptr->background.gray << shift;
+ tmp |=
+ (unsigned int)png_ptr->background.gray << shift;
*sp = (png_byte)(tmp & 0xff);
}
@@ -3318,7 +3331,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
== png_ptr->trans_color.gray)
{
unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
- tmp |= png_ptr->background.gray << shift;
+ tmp |=
+ (unsigned int)(png_ptr->background.gray << shift);
*sp = (png_byte)(tmp & 0xff);
}
@@ -3328,7 +3342,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
unsigned int g = (gamma_table[p | (p << 4)] >> 4) &
0x0f;
unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
- tmp |= g << shift;
+ tmp |= (unsigned int)(g << shift);
*sp = (png_byte)(tmp & 0xff);
}
@@ -3354,7 +3368,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
== png_ptr->trans_color.gray)
{
unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
- tmp |= png_ptr->background.gray << shift;
+ tmp |=
+ (unsigned int)(png_ptr->background.gray << shift);
*sp = (png_byte)(tmp & 0xff);
}
@@ -4194,8 +4209,9 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
* upon whether you supply trans and num_trans.
*/
static void
-png_do_expand_palette(png_row_infop row_info, png_bytep row,
- png_const_colorp palette, png_const_bytep trans_alpha, int num_trans)
+png_do_expand_palette(png_structrp png_ptr, png_row_infop row_info,
+ png_bytep row, png_const_colorp palette, png_const_bytep trans_alpha,
+ int num_trans)
{
int shift, value;
png_bytep sp, dp;
@@ -4297,16 +4313,24 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
if (num_trans > 0)
{
sp = row + (png_size_t)row_width - 1;
- dp = row + (png_size_t)(row_width << 2) - 1;
+ dp = row + ((png_size_t)row_width << 2) - 1;
+
+ i = 0;
+#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
+ if (png_ptr->riffled_palette != NULL) {
+ /* The RGBA optimization works with png_ptr->bit_depth == 8
+ but sometimes row_info->bit_depth has been changed to 8.
+ In these cases, the palette hasn't been riffled. */
+ i = png_do_expand_palette_neon_rgba(png_ptr, row_info, row, &sp, &dp);
+ }
+#endif
- for (i = 0; i < row_width; i++)
+ for (; i < row_width; i++)
{
if ((int)(*sp) >= num_trans)
*dp-- = 0xff;
-
else
*dp-- = trans_alpha[*sp];
-
*dp-- = palette[*sp].blue;
*dp-- = palette[*sp].green;
*dp-- = palette[*sp].red;
@@ -4323,8 +4347,12 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
{
sp = row + (png_size_t)row_width - 1;
dp = row + (png_size_t)(row_width * 3) - 1;
+ i = 0;
+#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
+ i = png_do_expand_palette_neon_rgb(png_ptr, row_info, row, &sp, &dp);
+#endif
- for (i = 0; i < row_width; i++)
+ for (; i < row_width; i++)
{
*dp-- = palette[*sp].blue;
*dp-- = palette[*sp].green;
@@ -4458,7 +4486,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
{
gray = gray & 0xff;
sp = row + (png_size_t)row_width - 1;
- dp = row + (png_size_t)(row_width << 1) - 1;
+ dp = row + ((png_size_t)row_width << 1) - 1;
for (i = 0; i < row_width; i++)
{
@@ -4502,7 +4530,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
row_info->channels = 2;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
- row_width);
+ row_width);
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
@@ -4514,7 +4542,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
png_byte green = (png_byte)(trans_color->green & 0xff);
png_byte blue = (png_byte)(trans_color->blue & 0xff);
sp = row + (png_size_t)row_info->rowbytes - 1;
- dp = row + (png_size_t)(row_width << 2) - 1;
+ dp = row + ((png_size_t)row_width << 2) - 1;
for (i = 0; i < row_width; i++)
{
if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
@@ -4537,7 +4565,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
png_byte green_low = (png_byte)(trans_color->green & 0xff);
png_byte blue_low = (png_byte)(trans_color->blue & 0xff);
sp = row + row_info->rowbytes - 1;
- dp = row + (png_size_t)(row_width << 3) - 1;
+ dp = row + ((png_size_t)row_width << 3) - 1;
for (i = 0; i < row_width; i++)
{
if (*(sp - 5) == red_high &&
@@ -4596,7 +4624,9 @@ png_do_expand_16(png_row_infop row_info, png_bytep row)
png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */
png_byte *dp = sp + row_info->rowbytes; /* destination, end + 1 */
while (dp > sp)
- dp[-2] = dp[-1] = *--sp, dp -= 2;
+ {
+ dp[-2] = dp[-1] = *--sp; dp -= 2;
+ }
row_info->rowbytes *= 2;
row_info->bit_depth = 16;
@@ -4738,8 +4768,21 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
{
if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
{
- png_do_expand_palette(row_info, png_ptr->row_buf + 1,
- png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
+#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
+ if ((png_ptr->num_trans > 0) && (png_ptr->bit_depth == 8)) {
+ /* Allocate space for the decompressed full palette. */
+ if (png_ptr->riffled_palette == NULL) {
+ png_ptr->riffled_palette = png_malloc(png_ptr, 256*4);
+ if (png_ptr->riffled_palette == NULL) {
+ png_error(png_ptr, "NULL row buffer");
+ }
+ /* Build the RGBA palette. */
+ png_riffle_palette_rgba(png_ptr, row_info);
+ }
+ }
+#endif
+ png_do_expand_palette(png_ptr, row_info, png_ptr->row_buf + 1,
+ png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
}
else
@@ -4762,7 +4805,7 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
(row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
- 0 /* at_start == false, because SWAP_ALPHA happens later */);
+ 0 /* at_start == false, because SWAP_ALPHA happens later */);
#endif
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
diff --git a/third_party/libpng16/pngrutil.c b/third_party/libpng16/pngrutil.c
index c9747fc27d..2210ffc75b 100644
--- a/third_party/libpng16/pngrutil.c
+++ b/third_party/libpng16/pngrutil.c
@@ -1,8 +1,8 @@
/* pngrutil.c - utilities to read a PNG file
*
- * Last changed in libpng 1.6.20 [December 3, 2014]
- * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.33 [September 28, 2017]
+ * Copyright (c) 1998-2002,2004,2006-2017 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.)
*
@@ -86,11 +86,11 @@ png_get_int_32)(png_const_bytep buf)
{
png_uint_32 uval = png_get_uint_32(buf);
if ((uval & 0x80000000) == 0) /* non-negative */
- return uval;
+ return (png_int_32)uval;
uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */
if ((uval & 0x80000000) == 0) /* no overflow */
- return -(png_int_32)uval;
+ return -(png_int_32)uval;
/* The following has to be safe; this function only gets called on PNG data
* and if we get here that data is invalid. 0 is the most safe value and
* if not then an attacker would surely just generate a PNG with 0 instead.
@@ -181,6 +181,9 @@ png_read_chunk_header(png_structrp png_ptr)
/* Check to see if chunk name is valid. */
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
+ /* Check for too-large chunk length */
+ png_check_chunk_length(png_ptr, length);
+
#ifdef PNG_IO_STATE_SUPPORTED
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA;
#endif
@@ -311,6 +314,7 @@ png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn)
if (buffer != NULL)
{
+ memset(buffer, 0, new_size); /* just in case */
png_ptr->read_buffer = buffer;
png_ptr->read_buffer_size = new_size;
}
@@ -370,11 +374,10 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
*/
{
int ret; /* zlib return code */
-#if PNG_ZLIB_VERNUM >= 0x1240
+#if ZLIB_VERNUM >= 0x1240
+ int window_bits = 0;
# if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW)
- int window_bits;
-
if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) ==
PNG_OPTION_ON)
{
@@ -384,13 +387,11 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
else
{
- window_bits = 0;
png_ptr->zstream_start = 1;
}
-# else
-# define window_bits 0
# endif
-#endif
+
+#endif /* ZLIB_VERNUM >= 0x1240 */
/* Set this for safety, just in case the previous owner left pointers to
* memory allocations.
@@ -402,25 +403,32 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)
{
-#if PNG_ZLIB_VERNUM < 0x1240
- ret = inflateReset(&png_ptr->zstream);
-#else
+#if ZLIB_VERNUM >= 0x1240
ret = inflateReset2(&png_ptr->zstream, window_bits);
+#else
+ ret = inflateReset(&png_ptr->zstream);
#endif
}
else
{
-#if PNG_ZLIB_VERNUM < 0x1240
- ret = inflateInit(&png_ptr->zstream);
-#else
+#if ZLIB_VERNUM >= 0x1240
ret = inflateInit2(&png_ptr->zstream, window_bits);
+#else
+ ret = inflateInit(&png_ptr->zstream);
#endif
if (ret == Z_OK)
png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;
}
+#if ZLIB_VERNUM >= 0x1290 && \
+ defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_IGNORE_ADLER32)
+ if (((png_ptr->options >> PNG_IGNORE_ADLER32) & 3) == PNG_OPTION_ON)
+ /* Turn off validation of the ADLER32 checksum in IDAT chunks */
+ ret = inflateValidate(&png_ptr->zstream, 0);
+#endif
+
if (ret == Z_OK)
png_ptr->zowner = owner;
@@ -435,7 +443,7 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
#endif
}
-#if PNG_ZLIB_VERNUM >= 0x1240
+#if ZLIB_VERNUM >= 0x1240
/* Handle the start of the inflate stream if we called inflateInit2(strm,0);
* in this case some zlib versions skip validation of the CINFO field and, in
* certain circumstances, libpng may end up displaying an invalid image, in
@@ -461,6 +469,7 @@ png_zlib_inflate(png_structrp png_ptr, int flush)
#endif /* Zlib >= 1.2.4 */
#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED
+#if defined(PNG_READ_zTXt_SUPPORTED) || defined (PNG_READ_iTXt_SUPPORTED)
/* png_inflate now returns zlib error codes including Z_OK and Z_STREAM_END to
* allow the caller to do multiple calls if required. If the 'finish' flag is
* set Z_FINISH will be passed to the final inflate() call and Z_STREAM_END must
@@ -599,9 +608,9 @@ png_inflate(png_structrp png_ptr, png_uint_32 owner, int finish,
*/
static int
png_decompress_chunk(png_structrp png_ptr,
- png_uint_32 chunklength, png_uint_32 prefix_size,
- png_alloc_size_t *newlength /* must be initialized to the maximum! */,
- int terminate /*add a '\0' to the end of the uncompressed data*/)
+ png_uint_32 chunklength, png_uint_32 prefix_size,
+ png_alloc_size_t *newlength /* must be initialized to the maximum! */,
+ int terminate /*add a '\0' to the end of the uncompressed data*/)
{
/* TODO: implement different limits for different types of chunk.
*
@@ -638,8 +647,8 @@ png_decompress_chunk(png_structrp png_ptr,
png_uint_32 lzsize = chunklength - prefix_size;
ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
- /* input: */ png_ptr->read_buffer + prefix_size, &lzsize,
- /* output: */ NULL, newlength);
+ /* input: */ png_ptr->read_buffer + prefix_size, &lzsize,
+ /* output: */ NULL, newlength);
if (ret == Z_STREAM_END)
{
@@ -659,15 +668,17 @@ png_decompress_chunk(png_structrp png_ptr,
*/
png_alloc_size_t new_size = *newlength;
png_alloc_size_t buffer_size = prefix_size + new_size +
- (terminate != 0);
+ (terminate != 0);
png_bytep text = png_voidcast(png_bytep, png_malloc_base(png_ptr,
- buffer_size));
+ buffer_size));
if (text != NULL)
{
+ memset(text, 0, buffer_size);
+
ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
- png_ptr->read_buffer + prefix_size, &lzsize,
- text + prefix_size, newlength);
+ png_ptr->read_buffer + prefix_size, &lzsize,
+ text + prefix_size, newlength);
if (ret == Z_STREAM_END)
{
@@ -712,7 +723,7 @@ png_decompress_chunk(png_structrp png_ptr,
* the extra space may otherwise be used as a Trojan Horse.
*/
if (ret == Z_STREAM_END &&
- chunklength - prefix_size != lzsize)
+ chunklength - prefix_size != lzsize)
png_chunk_benign_error(png_ptr, "extra compressed data");
}
@@ -728,9 +739,7 @@ png_decompress_chunk(png_structrp png_ptr,
{
/* inflateReset failed, store the error message */
png_zstream_error(png_ptr, ret);
-
- if (ret == Z_STREAM_END)
- ret = PNG_UNEXPECTED_ZLIB_RETURN;
+ ret = PNG_UNEXPECTED_ZLIB_RETURN;
}
}
@@ -754,6 +763,7 @@ png_decompress_chunk(png_structrp png_ptr,
return Z_MEM_ERROR;
}
}
+#endif /* READ_zTXt || READ_iTXt */
#endif /* READ_COMPRESSED_TEXT */
#ifdef PNG_READ_iCCP_SUPPORTED
@@ -762,8 +772,8 @@ png_decompress_chunk(png_structrp png_ptr,
*/
static int
png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,
- png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size,
- int finish)
+ png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size,
+ int finish)
{
if (png_ptr->zowner == png_ptr->chunk_name)
{
@@ -802,8 +812,8 @@ png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,
* the available output is produced; this allows reading of truncated
* streams.
*/
- ret = PNG_INFLATE(png_ptr,
- *chunk_bytes > 0 ? Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH));
+ ret = PNG_INFLATE(png_ptr, *chunk_bytes > 0 ?
+ Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH));
}
while (ret == Z_OK && (*out_size > 0 || png_ptr->zstream.avail_out > 0));
@@ -821,7 +831,7 @@ png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,
return Z_STREAM_ERROR;
}
}
-#endif
+#endif /* READ_iCCP */
/* Read and check the IDHR chunk */
@@ -1009,7 +1019,7 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
#endif
{
- png_crc_finish(png_ptr, (int) length - num * 3);
+ png_crc_finish(png_ptr, (png_uint_32) (length - (unsigned int)num * 3));
}
#ifndef PNG_READ_OPT_PLTE_SUPPORTED
@@ -1292,7 +1302,7 @@ png_handle_cHRM(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
(void)png_colorspace_set_chromaticities(png_ptr, &png_ptr->colorspace, &xy,
- 1/*prefer cHRM values*/);
+ 1/*prefer cHRM values*/);
png_colorspace_sync(png_ptr, info_ptr);
}
#endif
@@ -1371,11 +1381,13 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
* chunk is just ignored, so does not invalidate the color space. An
* alternative is to set the 'invalid' flags at the start of this routine
* and only clear them in they were not set before and all the tests pass.
- * The minimum 'deflate' stream is assumed to be just the 2 byte header and
- * 4 byte checksum. The keyword must be at least one character and there is
- * a terminator (0) byte and the compression method.
*/
- if (length < 9)
+
+ /* The keyword must be at least one character and there is a
+ * terminator (0) byte and the compression method byte, and the
+ * 'zlib' datastream is at least 11 bytes.
+ */
+ if (length < 14)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "too short");
@@ -1407,6 +1419,16 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, (png_bytep)keyword, read_length);
length -= read_length;
+ /* The minimum 'zlib' stream is assumed to be just the 2 byte header,
+ * 5 bytes minimum 'deflate' stream, and the 4 byte checksum.
+ */
+ if (length < 11)
+ {
+ png_crc_finish(png_ptr, length);
+ png_chunk_benign_error(png_ptr, "too short");
+ return;
+ }
+
keyword_length = 0;
while (keyword_length < 80 && keyword_length < read_length &&
keyword[keyword_length] != 0)
@@ -1425,15 +1447,15 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK)
{
- Byte profile_header[132];
+ Byte profile_header[132]={0};
Byte local_buffer[PNG_INFLATE_BUF_SIZE];
png_alloc_size_t size = (sizeof profile_header);
png_ptr->zstream.next_in = (Bytef*)keyword + (keyword_length+2);
png_ptr->zstream.avail_in = read_length;
(void)png_inflate_read(png_ptr, local_buffer,
- (sizeof local_buffer), &length, profile_header, &size,
- 0/*finish: don't, because the output is too small*/);
+ (sizeof local_buffer), &length, profile_header, &size,
+ 0/*finish: don't, because the output is too small*/);
if (size == 0)
{
@@ -1443,35 +1465,35 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_get_uint_32(profile_header);
if (png_icc_check_length(png_ptr, &png_ptr->colorspace,
- keyword, profile_length) != 0)
+ keyword, profile_length) != 0)
{
/* The length is apparently ok, so we can check the 132
* byte header.
*/
if (png_icc_check_header(png_ptr, &png_ptr->colorspace,
- keyword, profile_length, profile_header,
- png_ptr->color_type) != 0)
+ keyword, profile_length, profile_header,
+ png_ptr->color_type) != 0)
{
/* Now read the tag table; a variable size buffer is
* needed at this point, allocate one for the whole
* profile. The header check has already validated
- * that none of these stuff will overflow.
+ * that none of this stuff will overflow.
*/
const png_uint_32 tag_count = png_get_uint_32(
- profile_header+128);
+ profile_header+128);
png_bytep profile = png_read_buffer(png_ptr,
- profile_length, 2/*silent*/);
+ profile_length, 2/*silent*/);
if (profile != NULL)
{
memcpy(profile, profile_header,
- (sizeof profile_header));
+ (sizeof profile_header));
size = 12 * tag_count;
(void)png_inflate_read(png_ptr, local_buffer,
- (sizeof local_buffer), &length,
- profile + (sizeof profile_header), &size, 0);
+ (sizeof local_buffer), &length,
+ profile + (sizeof profile_header), &size, 0);
/* Still expect a buffer error because we expect
* there to be some tag data!
@@ -1479,22 +1501,22 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if (size == 0)
{
if (png_icc_check_tag_table(png_ptr,
- &png_ptr->colorspace, keyword, profile_length,
- profile) != 0)
+ &png_ptr->colorspace, keyword, profile_length,
+ profile) != 0)
{
/* The profile has been validated for basic
* security issues, so read the whole thing in.
*/
size = profile_length - (sizeof profile_header)
- - 12 * tag_count;
+ - 12 * tag_count;
(void)png_inflate_read(png_ptr, local_buffer,
- (sizeof local_buffer), &length,
- profile + (sizeof profile_header) +
- 12 * tag_count, &size, 1/*finish*/);
+ (sizeof local_buffer), &length,
+ profile + (sizeof profile_header) +
+ 12 * tag_count, &size, 1/*finish*/);
if (length > 0 && !(png_ptr->flags &
- PNG_FLAG_BENIGN_ERRORS_WARN))
+ PNG_FLAG_BENIGN_ERRORS_WARN))
errmsg = "extra compressed data";
/* But otherwise allow extra data: */
@@ -1506,34 +1528,34 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
* keep going.
*/
png_chunk_warning(png_ptr,
- "extra compressed data");
+ "extra compressed data");
}
png_crc_finish(png_ptr, length);
finished = 1;
-# ifdef PNG_sRGB_SUPPORTED
+# if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0
/* Check for a match against sRGB */
png_icc_set_sRGB(png_ptr,
- &png_ptr->colorspace, profile,
- png_ptr->zstream.adler);
-# endif
+ &png_ptr->colorspace, profile,
+ png_ptr->zstream.adler);
+# endif
/* Steal the profile for info_ptr. */
if (info_ptr != NULL)
{
png_free_data(png_ptr, info_ptr,
- PNG_FREE_ICCP, 0);
+ PNG_FREE_ICCP, 0);
info_ptr->iccp_name = png_voidcast(char*,
- png_malloc_base(png_ptr,
- keyword_length+1));
+ png_malloc_base(png_ptr,
+ keyword_length+1));
if (info_ptr->iccp_name != NULL)
{
memcpy(info_ptr->iccp_name, keyword,
- keyword_length+1);
+ keyword_length+1);
info_ptr->iccp_proflen =
- profile_length;
+ profile_length;
info_ptr->iccp_profile = profile;
png_ptr->read_buffer = NULL; /*steal*/
info_ptr->free_me |= PNG_FREE_ICCP;
@@ -1562,19 +1584,11 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
return;
}
}
-
- else if (size > 0)
- errmsg = "truncated";
-
-#ifndef __COVERITY__
- else
+ if (errmsg == NULL)
errmsg = png_ptr->zstream.msg;
-#endif
}
-
/* else png_icc_check_tag_table output an error */
}
-
else /* profile truncated */
errmsg = png_ptr->zstream.msg;
}
@@ -1715,13 +1729,13 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
data_length = length - (png_uint_32)(entry_start - buffer);
/* Integrity-check the data length */
- if ((data_length % entry_size) != 0)
+ if ((data_length % (unsigned int)entry_size) != 0)
{
png_warning(png_ptr, "sPLT chunk has bad length");
return;
}
- dl = (png_int_32)(data_length / entry_size);
+ dl = (png_uint_32)(data_length / (unsigned int)entry_size);
max_dl = PNG_SIZE_MAX / (sizeof (png_sPLT_entry));
if (dl > max_dl)
@@ -1730,10 +1744,10 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
return;
}
- new_palette.nentries = (png_int_32)(data_length / entry_size);
+ new_palette.nentries = (png_int_32)(data_length / (unsigned int)entry_size);
- new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
- png_ptr, new_palette.nentries * (sizeof (png_sPLT_entry)));
+ new_palette.entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
+ (png_alloc_size_t) new_palette.nentries * (sizeof (png_sPLT_entry)));
if (new_palette.entries == NULL)
{
@@ -2003,6 +2017,69 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
#endif
+#ifdef PNG_READ_eXIf_SUPPORTED
+void /* PRIVATE */
+png_handle_eXIf(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
+{
+ unsigned int i;
+
+ png_debug(1, "in png_handle_eXIf");
+
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
+ png_chunk_error(png_ptr, "missing IHDR");
+
+ if (length < 2)
+ {
+ png_crc_finish(png_ptr, length);
+ png_chunk_benign_error(png_ptr, "too short");
+ return;
+ }
+
+ else if (info_ptr == NULL || (info_ptr->valid & PNG_INFO_eXIf) != 0)
+ {
+ png_crc_finish(png_ptr, length);
+ png_chunk_benign_error(png_ptr, "duplicate");
+ return;
+ }
+
+ info_ptr->free_me |= PNG_FREE_EXIF;
+
+ info_ptr->eXIf_buf = png_voidcast(png_bytep,
+ png_malloc_warn(png_ptr, length));
+
+ if (info_ptr->eXIf_buf == NULL)
+ {
+ png_crc_finish(png_ptr, length);
+ png_chunk_benign_error(png_ptr, "out of memory");
+ return;
+ }
+
+ for (i = 0; i < length; i++)
+ {
+ png_byte buf[1];
+ png_crc_read(png_ptr, buf, 1);
+ info_ptr->eXIf_buf[i] = buf[0];
+ if (i == 1 && buf[0] != 'M' && buf[0] != 'I'
+ && info_ptr->eXIf_buf[0] != buf[0])
+ {
+ png_crc_finish(png_ptr, length);
+ png_chunk_benign_error(png_ptr, "incorrect byte-order specifier");
+ png_free(png_ptr, info_ptr->eXIf_buf);
+ info_ptr->eXIf_buf = NULL;
+ return;
+ }
+ }
+
+ if (png_crc_finish(png_ptr, 0) != 0)
+ return;
+
+ png_set_eXIf_1(png_ptr, info_ptr, length, info_ptr->eXIf_buf);
+
+ png_free(png_ptr, info_ptr->eXIf_buf);
+ info_ptr->eXIf_buf = NULL;
+}
+#endif
+
#ifdef PNG_READ_hIST_SUPPORTED
void /* PRIVATE */
png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
@@ -2270,7 +2347,7 @@ png_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
png_set_pCAL(png_ptr, info_ptr, (png_charp)buffer, X0, X1, type, nparams,
- (png_charp)units, params);
+ (png_charp)units, params);
png_free(png_ptr, params);
}
@@ -2313,7 +2390,7 @@ png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)",
- length + 1);
+ length + 1);
buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/);
@@ -2365,7 +2442,7 @@ png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
else
/* This is the (only) success case. */
png_set_sCAL_s(png_ptr, info_ptr, buffer[0],
- (png_charp)buffer+1, (png_charp)buffer+heighti);
+ (png_charp)buffer+1, (png_charp)buffer+heighti);
}
}
#endif
@@ -2465,8 +2542,8 @@ png_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if (buffer == NULL)
{
- png_chunk_benign_error(png_ptr, "out of memory");
- return;
+ png_chunk_benign_error(png_ptr, "out of memory");
+ return;
}
png_crc_read(png_ptr, buffer, length);
@@ -2531,6 +2608,9 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
png_ptr->mode |= PNG_AFTER_IDAT;
+ /* Note, "length" is sufficient here; we won't be adding
+ * a null terminator later.
+ */
buffer = png_read_buffer(png_ptr, length, 2/*silent*/);
if (buffer == NULL)
@@ -2573,27 +2653,32 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
* and text chunks.
*/
if (png_decompress_chunk(png_ptr, length, keyword_length+2,
- &uncompressed_length, 1/*terminate*/) == Z_STREAM_END)
+ &uncompressed_length, 1/*terminate*/) == Z_STREAM_END)
{
png_text text;
- /* It worked; png_ptr->read_buffer now looks like a tEXt chunk except
- * for the extra compression type byte and the fact that it isn't
- * necessarily '\0' terminated.
- */
- buffer = png_ptr->read_buffer;
- buffer[uncompressed_length+(keyword_length+2)] = 0;
-
- text.compression = PNG_TEXT_COMPRESSION_zTXt;
- text.key = (png_charp)buffer;
- text.text = (png_charp)(buffer + keyword_length+2);
- text.text_length = uncompressed_length;
- text.itxt_length = 0;
- text.lang = NULL;
- text.lang_key = NULL;
-
- if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)
- errmsg = "insufficient memory";
+ if (png_ptr->read_buffer == NULL)
+ errmsg="Read failure in png_handle_zTXt";
+ else
+ {
+ /* It worked; png_ptr->read_buffer now looks like a tEXt chunk
+ * except for the extra compression type byte and the fact that
+ * it isn't necessarily '\0' terminated.
+ */
+ buffer = png_ptr->read_buffer;
+ buffer[uncompressed_length+(keyword_length+2)] = 0;
+
+ text.compression = PNG_TEXT_COMPRESSION_zTXt;
+ text.key = (png_charp)buffer;
+ text.text = (png_charp)(buffer + keyword_length+2);
+ text.text_length = uncompressed_length;
+ text.itxt_length = 0;
+ text.lang = NULL;
+ text.lang_key = NULL;
+
+ if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)
+ errmsg = "insufficient memory";
+ }
}
else
@@ -2713,7 +2798,7 @@ png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
* iCCP and text chunks.
*/
if (png_decompress_chunk(png_ptr, length, prefix_length,
- &uncompressed_length, 1/*terminate*/) == Z_STREAM_END)
+ &uncompressed_length, 1/*terminate*/) == Z_STREAM_END)
buffer = png_ptr->read_buffer;
else
@@ -2793,7 +2878,7 @@ png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
{
/* Do a 'warn' here - it is handled below. */
png_ptr->unknown_chunk.data = png_voidcast(png_bytep,
- png_malloc_warn(png_ptr, length));
+ png_malloc_warn(png_ptr, length));
}
}
@@ -2818,7 +2903,7 @@ png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
/* Handle an unknown, or known but disabled, chunk */
void /* PRIVATE */
png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
- png_uint_32 length, int keep)
+ png_uint_32 length, int keep)
{
int handled = 0; /* the chunk was handled */
@@ -2856,7 +2941,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
{
/* Callback to user unknown chunk handler */
int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr,
- &png_ptr->unknown_chunk);
+ &png_ptr->unknown_chunk);
/* ret is:
* negative: An error occurred; png_chunk_error will be called.
@@ -2890,9 +2975,9 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
{
png_chunk_warning(png_ptr, "Saving unknown chunk:");
png_app_warning(png_ptr,
- "forcing save of an unhandled chunk;"
- " please call png_set_keep_unknown_chunks");
- /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */
+ "forcing save of an unhandled chunk;"
+ " please call png_set_keep_unknown_chunks");
+ /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */
}
# endif
keep = PNG_HANDLE_CHUNK_IF_SAFE;
@@ -2969,7 +3054,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
case 2:
png_ptr->user_chunk_cache_max = 1;
png_chunk_benign_error(png_ptr, "no space in chunk cache");
- /* FALL THROUGH */
+ /* FALLTHROUGH */
case 1:
/* NOTE: prior to 1.6.0 this case resulted in an unknown critical
* chunk being skipped, now there will be a hard error below.
@@ -2978,14 +3063,14 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
default: /* not at limit */
--(png_ptr->user_chunk_cache_max);
- /* FALL THROUGH */
+ /* FALLTHROUGH */
case 0: /* no limit */
# endif /* USER_LIMITS */
/* Here when the limit isn't reached or when limits are compiled
* out; store the chunk.
*/
png_set_unknown_chunks(png_ptr, info_ptr,
- &png_ptr->unknown_chunk, 1);
+ &png_ptr->unknown_chunk, 1);
handled = 1;
# ifdef PNG_USER_LIMITS_SUPPORTED
break;
@@ -3029,20 +3114,58 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
*/
void /* PRIVATE */
-png_check_chunk_name(png_structrp png_ptr, png_uint_32 chunk_name)
+png_check_chunk_name(png_const_structrp png_ptr, const png_uint_32 chunk_name)
{
int i;
+ png_uint_32 cn=chunk_name;
png_debug(1, "in png_check_chunk_name");
for (i=1; i<=4; ++i)
{
- int c = chunk_name & 0xff;
+ int c = cn & 0xff;
if (c < 65 || c > 122 || (c > 90 && c < 97))
png_chunk_error(png_ptr, "invalid chunk type");
- chunk_name >>= 8;
+ cn >>= 8;
+ }
+}
+
+void /* PRIVATE */
+png_check_chunk_length(png_const_structrp png_ptr, const png_uint_32 length)
+{
+ png_alloc_size_t limit = PNG_UINT_31_MAX;
+
+# ifdef PNG_SET_USER_LIMITS_SUPPORTED
+ if (png_ptr->user_chunk_malloc_max > 0 &&
+ png_ptr->user_chunk_malloc_max < limit)
+ limit = png_ptr->user_chunk_malloc_max;
+# elif PNG_USER_CHUNK_MALLOC_MAX > 0
+ if (PNG_USER_CHUNK_MALLOC_MAX < limit)
+ limit = PNG_USER_CHUNK_MALLOC_MAX;
+# endif
+ if (png_ptr->chunk_name == png_IDAT)
+ {
+ png_alloc_size_t idat_limit = PNG_UINT_31_MAX;
+ size_t row_factor =
+ (png_ptr->width * png_ptr->channels * (png_ptr->bit_depth > 8? 2: 1)
+ + 1 + (png_ptr->interlaced? 6: 0));
+ if (png_ptr->height > PNG_UINT_32_MAX/row_factor)
+ idat_limit=PNG_UINT_31_MAX;
+ else
+ idat_limit = png_ptr->height * row_factor;
+ row_factor = row_factor > 32566? 32566 : row_factor;
+ idat_limit += 6 + 5*(idat_limit/row_factor+1); /* zlib+deflate overhead */
+ idat_limit=idat_limit < PNG_UINT_31_MAX? idat_limit : PNG_UINT_31_MAX;
+ limit = limit < idat_limit? idat_limit : limit;
+ }
+
+ if (length > limit)
+ {
+ png_debug2(0," length = %lu, limit = %lu",
+ (unsigned long)length,(unsigned long)limit);
+ png_benign_error(png_ptr, "chunk data is too large");
}
}
@@ -3097,7 +3220,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
# ifdef PNG_READ_PACKSWAP_SUPPORTED
if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
/* little-endian byte */
- end_mask = 0xff << end_mask;
+ end_mask = (unsigned int)(0xff << end_mask);
else /* big-endian byte */
# endif
@@ -3371,7 +3494,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
*/
do
{
- dp[0] = sp[0], dp[1] = sp[1];
+ dp[0] = sp[0]; dp[1] = sp[1];
if (row_width <= bytes_to_jump)
return;
@@ -3392,7 +3515,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
*/
for (;;)
{
- dp[0] = sp[0], dp[1] = sp[1], dp[2] = sp[2];
+ dp[0] = sp[0]; dp[1] = sp[1]; dp[2] = sp[2];
if (row_width <= bytes_to_jump)
return;
@@ -3418,8 +3541,8 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
/* Everything is aligned for png_uint_16 copies, but try for
* png_uint_32 first.
*/
- if (png_isaligned(dp, png_uint_32) != 0 &&
- png_isaligned(sp, png_uint_32) != 0 &&
+ if (png_isaligned(dp, png_uint_32) &&
+ png_isaligned(sp, png_uint_32) &&
bytes_to_copy % (sizeof (png_uint_32)) == 0 &&
bytes_to_jump % (sizeof (png_uint_32)) == 0)
{
@@ -3539,11 +3662,11 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
#ifdef PNG_READ_INTERLACING_SUPPORTED
void /* PRIVATE */
png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
- png_uint_32 transformations /* Because these may affect the byte layout */)
+ png_uint_32 transformations /* Because these may affect the byte layout */)
{
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* Offset to next interlace block */
- static PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
+ static PNG_CONST unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
png_debug(1, "in png_do_read_interlace");
if (row != NULL && row_info != NULL)
@@ -3558,9 +3681,10 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
{
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
- int sshift, dshift;
- int s_start, s_end, s_inc;
- int jstop = png_pass_inc[pass];
+ unsigned int sshift, dshift;
+ unsigned int s_start, s_end;
+ int s_inc;
+ int jstop = (int)png_pass_inc[pass];
png_byte v;
png_uint_32 i;
int j;
@@ -3568,8 +3692,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
#ifdef PNG_READ_PACKSWAP_SUPPORTED
if ((transformations & PNG_PACKSWAP) != 0)
{
- sshift = (int)((row_info->width + 7) & 0x07);
- dshift = (int)((final_width + 7) & 0x07);
+ sshift = ((row_info->width + 7) & 0x07);
+ dshift = ((final_width + 7) & 0x07);
s_start = 7;
s_end = 0;
s_inc = -1;
@@ -3578,8 +3702,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
else
#endif
{
- sshift = 7 - (int)((row_info->width + 7) & 0x07);
- dshift = 7 - (int)((final_width + 7) & 0x07);
+ sshift = 7 - ((row_info->width + 7) & 0x07);
+ dshift = 7 - ((final_width + 7) & 0x07);
s_start = 0;
s_end = 7;
s_inc = 1;
@@ -3591,7 +3715,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
for (j = 0; j < jstop; j++)
{
unsigned int tmp = *dp & (0x7f7f >> (7 - dshift));
- tmp |= v << dshift;
+ tmp |= (unsigned int)(v << dshift);
*dp = (png_byte)(tmp & 0xff);
if (dshift == s_end)
@@ -3601,7 +3725,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
}
else
- dshift += s_inc;
+ dshift = (unsigned int)((int)dshift + s_inc);
}
if (sshift == s_end)
@@ -3611,7 +3735,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
}
else
- sshift += s_inc;
+ sshift = (unsigned int)((int)sshift + s_inc);
}
break;
}
@@ -3620,16 +3744,17 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
{
png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
- int sshift, dshift;
- int s_start, s_end, s_inc;
- int jstop = png_pass_inc[pass];
+ unsigned int sshift, dshift;
+ unsigned int s_start, s_end;
+ int s_inc;
+ int jstop = (int)png_pass_inc[pass];
png_uint_32 i;
#ifdef PNG_READ_PACKSWAP_SUPPORTED
if ((transformations & PNG_PACKSWAP) != 0)
{
- sshift = (int)(((row_info->width + 3) & 0x03) << 1);
- dshift = (int)(((final_width + 3) & 0x03) << 1);
+ sshift = (((row_info->width + 3) & 0x03) << 1);
+ dshift = (((final_width + 3) & 0x03) << 1);
s_start = 6;
s_end = 0;
s_inc = -2;
@@ -3638,8 +3763,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
else
#endif
{
- sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
- dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
+ sshift = ((3 - ((row_info->width + 3) & 0x03)) << 1);
+ dshift = ((3 - ((final_width + 3) & 0x03)) << 1);
s_start = 0;
s_end = 6;
s_inc = 2;
@@ -3654,7 +3779,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
for (j = 0; j < jstop; j++)
{
unsigned int tmp = *dp & (0x3f3f >> (6 - dshift));
- tmp |= v << dshift;
+ tmp |= (unsigned int)(v << dshift);
*dp = (png_byte)(tmp & 0xff);
if (dshift == s_end)
@@ -3664,7 +3789,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
}
else
- dshift += s_inc;
+ dshift = (unsigned int)((int)dshift + s_inc);
}
if (sshift == s_end)
@@ -3674,7 +3799,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
}
else
- sshift += s_inc;
+ sshift = (unsigned int)((int)sshift + s_inc);
}
break;
}
@@ -3683,16 +3808,17 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
{
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
- int sshift, dshift;
- int s_start, s_end, s_inc;
+ unsigned int sshift, dshift;
+ unsigned int s_start, s_end;
+ int s_inc;
png_uint_32 i;
- int jstop = png_pass_inc[pass];
+ int jstop = (int)png_pass_inc[pass];
#ifdef PNG_READ_PACKSWAP_SUPPORTED
if ((transformations & PNG_PACKSWAP) != 0)
{
- sshift = (int)(((row_info->width + 1) & 0x01) << 2);
- dshift = (int)(((final_width + 1) & 0x01) << 2);
+ sshift = (((row_info->width + 1) & 0x01) << 2);
+ dshift = (((final_width + 1) & 0x01) << 2);
s_start = 4;
s_end = 0;
s_inc = -4;
@@ -3701,8 +3827,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
else
#endif
{
- sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
- dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
+ sshift = ((1 - ((row_info->width + 1) & 0x01)) << 2);
+ dshift = ((1 - ((final_width + 1) & 0x01)) << 2);
s_start = 0;
s_end = 4;
s_inc = 4;
@@ -3716,7 +3842,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
for (j = 0; j < jstop; j++)
{
unsigned int tmp = *dp & (0xf0f >> (4 - dshift));
- tmp |= v << dshift;
+ tmp |= (unsigned int)(v << dshift);
*dp = (png_byte)(tmp & 0xff);
if (dshift == s_end)
@@ -3726,7 +3852,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
}
else
- dshift += s_inc;
+ dshift = (unsigned int)((int)dshift + s_inc);
}
if (sshift == s_end)
@@ -3736,7 +3862,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
}
else
- sshift += s_inc;
+ sshift = (unsigned int)((int)sshift + s_inc);
}
break;
}
@@ -3750,7 +3876,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
- int jstop = png_pass_inc[pass];
+ int jstop = (int)png_pass_inc[pass];
png_uint_32 i;
for (i = 0; i < row_info->width; i++)
@@ -3783,7 +3909,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
static void
png_read_filter_row_sub(png_row_infop row_info, png_bytep row,
- png_const_bytep prev_row)
+ png_const_bytep prev_row)
{
png_size_t i;
png_size_t istop = row_info->rowbytes;
@@ -3801,7 +3927,7 @@ png_read_filter_row_sub(png_row_infop row_info, png_bytep row,
static void
png_read_filter_row_up(png_row_infop row_info, png_bytep row,
- png_const_bytep prev_row)
+ png_const_bytep prev_row)
{
png_size_t i;
png_size_t istop = row_info->rowbytes;
@@ -3817,7 +3943,7 @@ png_read_filter_row_up(png_row_infop row_info, png_bytep row,
static void
png_read_filter_row_avg(png_row_infop row_info, png_bytep row,
- png_const_bytep prev_row)
+ png_const_bytep prev_row)
{
png_size_t i;
png_bytep rp = row;
@@ -3844,7 +3970,7 @@ png_read_filter_row_avg(png_row_infop row_info, png_bytep row,
static void
png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,
- png_const_bytep prev_row)
+ png_const_bytep prev_row)
{
png_bytep rp_end = row + row_info->rowbytes;
int a, c;
@@ -3878,7 +4004,10 @@ png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,
/* Find the best predictor, the least of pa, pb, pc favoring the earlier
* ones in the case of a tie.
*/
- if (pb < pa) pa = pb, a = b;
+ if (pb < pa)
+ {
+ pa = pb; a = b;
+ }
if (pc < pa) a = c;
/* Calculate the current pixel in a, and move the previous row pixel to c
@@ -3892,9 +4021,9 @@ png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,
static void
png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
- png_const_bytep prev_row)
+ png_const_bytep prev_row)
{
- int bpp = (row_info->pixel_depth + 7) >> 3;
+ unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
png_bytep rp_end = row + bpp;
/* Process the first pixel in the row completely (this is the same as 'up'
@@ -3907,7 +4036,7 @@ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
}
/* Remainder */
- rp_end += row_info->rowbytes - bpp;
+ rp_end = rp_end + (row_info->rowbytes - bpp);
while (row < rp_end)
{
@@ -3930,7 +4059,10 @@ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif
- if (pb < pa) pa = pb, a = b;
+ if (pb < pa)
+ {
+ pa = pb; a = b;
+ }
if (pc < pa) a = c;
a += *row;
@@ -3977,7 +4109,7 @@ png_init_filter_functions(png_structrp pp)
void /* PRIVATE */
png_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row,
- png_const_bytep prev_row, int filter)
+ png_const_bytep prev_row, int filter)
{
/* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define
* PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic
@@ -3995,7 +4127,7 @@ png_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row,
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
void /* PRIVATE */
png_read_IDAT_data(png_structrp png_ptr, png_bytep output,
- png_alloc_size_t avail_out)
+ png_alloc_size_t avail_out)
{
/* Loop reading IDATs and decompressing the result into output[avail_out] */
png_ptr->zstream.next_out = output;
@@ -4252,7 +4384,7 @@ png_read_start_row(png_structrp png_ptr)
/* Offset to next interlace block in the y direction */
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
- int max_pixel_depth;
+ unsigned int max_pixel_depth;
png_size_t row_bytes;
png_debug(1, "in png_read_start_row");
@@ -4281,7 +4413,7 @@ png_read_start_row(png_structrp png_ptr)
png_ptr->iwidth = png_ptr->width;
}
- max_pixel_depth = png_ptr->pixel_depth;
+ max_pixel_depth = (unsigned int)png_ptr->pixel_depth;
/* WARNING: * png_read_transform_info (pngrtran.c) performs a simpler set of
* calculations to calculate the final pixel depth, then
@@ -4416,7 +4548,7 @@ png_read_start_row(png_structrp png_ptr)
defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
{
- int user_pixel_depth = png_ptr->user_transform_depth *
+ unsigned int user_pixel_depth = png_ptr->user_transform_depth *
png_ptr->user_transform_channels;
if (user_pixel_depth > max_pixel_depth)
@@ -4438,7 +4570,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
* for safety's sake
*/
row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +
- 1 + ((max_pixel_depth + 7) >> 3);
+ 1 + ((max_pixel_depth + 7) >> 3U);
#ifdef PNG_MAX_MALLOC_64K
if (row_bytes > (png_uint_32)65536L)
@@ -4447,42 +4579,42 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
{
- png_free(png_ptr, png_ptr->big_row_buf);
- png_free(png_ptr, png_ptr->big_prev_row);
+ png_free(png_ptr, png_ptr->big_row_buf);
+ png_free(png_ptr, png_ptr->big_prev_row);
- if (png_ptr->interlaced != 0)
- png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
- row_bytes + 48);
+ if (png_ptr->interlaced != 0)
+ png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
+ row_bytes + 48);
- else
- png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
+ else
+ png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
- png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
+ png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
#ifdef PNG_ALIGNED_MEMORY_SUPPORTED
- /* Use 16-byte aligned memory for row_buf with at least 16 bytes
- * of padding before and after row_buf; treat prev_row similarly.
- * NOTE: the alignment is to the start of the pixels, one beyond the start
- * of the buffer, because of the filter byte. Prior to libpng 1.5.6 this
- * was incorrect; the filter byte was aligned, which had the exact
- * opposite effect of that intended.
- */
- {
- png_bytep temp = png_ptr->big_row_buf + 32;
- int extra = (int)((temp - (png_bytep)0) & 0x0f);
- png_ptr->row_buf = temp - extra - 1/*filter byte*/;
-
- temp = png_ptr->big_prev_row + 32;
- extra = (int)((temp - (png_bytep)0) & 0x0f);
- png_ptr->prev_row = temp - extra - 1/*filter byte*/;
- }
+ /* Use 16-byte aligned memory for row_buf with at least 16 bytes
+ * of padding before and after row_buf; treat prev_row similarly.
+ * NOTE: the alignment is to the start of the pixels, one beyond the start
+ * of the buffer, because of the filter byte. Prior to libpng 1.5.6 this
+ * was incorrect; the filter byte was aligned, which had the exact
+ * opposite effect of that intended.
+ */
+ {
+ png_bytep temp = png_ptr->big_row_buf + 32;
+ int extra = (int)((temp - (png_bytep)0) & 0x0f);
+ png_ptr->row_buf = temp - extra - 1/*filter byte*/;
+
+ temp = png_ptr->big_prev_row + 32;
+ extra = (int)((temp - (png_bytep)0) & 0x0f);
+ png_ptr->prev_row = temp - extra - 1/*filter byte*/;
+ }
#else
- /* Use 31 bytes of padding before and 17 bytes after row_buf. */
- png_ptr->row_buf = png_ptr->big_row_buf + 31;
- png_ptr->prev_row = png_ptr->big_prev_row + 31;
+ /* Use 31 bytes of padding before and 17 bytes after row_buf. */
+ png_ptr->row_buf = png_ptr->big_row_buf + 31;
+ png_ptr->prev_row = png_ptr->big_prev_row + 31;
#endif
- png_ptr->old_big_row_buf_size = row_bytes + 48;
+ png_ptr->old_big_row_buf_size = row_bytes + 48;
}
#ifdef PNG_MAX_MALLOC_64K
@@ -4507,7 +4639,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
* does not, so free the read buffer now regardless; the sequential reader
* reallocates it on demand.
*/
- if (png_ptr->read_buffer != 0)
+ if (png_ptr->read_buffer != NULL)
{
png_bytep buffer = png_ptr->read_buffer;
diff --git a/third_party/libpng16/pngset.c b/third_party/libpng16/pngset.c
index 1c51270cc5..6f3a1ee11e 100644
--- a/third_party/libpng16/pngset.c
+++ b/third_party/libpng16/pngset.c
@@ -1,8 +1,8 @@
/* pngset.c - storage of image information into info struct
*
- * Last changed in libpng 1.6.21 [January 15, 2016]
- * Copyright (c) 1998-2015 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.32 [August 24, 2017]
+ * Copyright (c) 1998-2017 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.)
*
@@ -104,14 +104,14 @@ png_set_cHRM(png_const_structrp png_ptr, png_inforp info_ptr,
double green_x, double green_y, double blue_x, double blue_y)
{
png_set_cHRM_fixed(png_ptr, info_ptr,
- png_fixed(png_ptr, white_x, "cHRM White X"),
- png_fixed(png_ptr, white_y, "cHRM White Y"),
- png_fixed(png_ptr, red_x, "cHRM Red X"),
- png_fixed(png_ptr, red_y, "cHRM Red Y"),
- png_fixed(png_ptr, green_x, "cHRM Green X"),
- png_fixed(png_ptr, green_y, "cHRM Green Y"),
- png_fixed(png_ptr, blue_x, "cHRM Blue X"),
- png_fixed(png_ptr, blue_y, "cHRM Blue Y"));
+ png_fixed(png_ptr, white_x, "cHRM White X"),
+ png_fixed(png_ptr, white_y, "cHRM White Y"),
+ png_fixed(png_ptr, red_x, "cHRM Red X"),
+ png_fixed(png_ptr, red_y, "cHRM Red Y"),
+ png_fixed(png_ptr, green_x, "cHRM Green X"),
+ png_fixed(png_ptr, green_y, "cHRM Green Y"),
+ png_fixed(png_ptr, blue_x, "cHRM Blue X"),
+ png_fixed(png_ptr, blue_y, "cHRM Blue Y"));
}
void PNGAPI
@@ -120,20 +120,67 @@ png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X,
double blue_X, double blue_Y, double blue_Z)
{
png_set_cHRM_XYZ_fixed(png_ptr, info_ptr,
- png_fixed(png_ptr, red_X, "cHRM Red X"),
- png_fixed(png_ptr, red_Y, "cHRM Red Y"),
- png_fixed(png_ptr, red_Z, "cHRM Red Z"),
- png_fixed(png_ptr, green_X, "cHRM Green X"),
- png_fixed(png_ptr, green_Y, "cHRM Green Y"),
- png_fixed(png_ptr, green_Z, "cHRM Green Z"),
- png_fixed(png_ptr, blue_X, "cHRM Blue X"),
- png_fixed(png_ptr, blue_Y, "cHRM Blue Y"),
- png_fixed(png_ptr, blue_Z, "cHRM Blue Z"));
+ png_fixed(png_ptr, red_X, "cHRM Red X"),
+ png_fixed(png_ptr, red_Y, "cHRM Red Y"),
+ png_fixed(png_ptr, red_Z, "cHRM Red Z"),
+ png_fixed(png_ptr, green_X, "cHRM Green X"),
+ png_fixed(png_ptr, green_Y, "cHRM Green Y"),
+ png_fixed(png_ptr, green_Z, "cHRM Green Z"),
+ png_fixed(png_ptr, blue_X, "cHRM Blue X"),
+ png_fixed(png_ptr, blue_Y, "cHRM Blue Y"),
+ png_fixed(png_ptr, blue_Z, "cHRM Blue Z"));
}
# endif /* FLOATING_POINT */
#endif /* cHRM */
+#ifdef PNG_eXIf_SUPPORTED
+void PNGAPI
+png_set_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
+ const png_bytep eXIf_buf)
+{
+ png_warning(png_ptr, "png_set_eXIf does not work; use png_set_eXIf_1");
+ PNG_UNUSED(info_ptr)
+ PNG_UNUSED(eXIf_buf)
+}
+
+void PNGAPI
+png_set_eXIf_1(png_const_structrp png_ptr, png_inforp info_ptr,
+ const png_uint_32 num_exif, const png_bytep eXIf_buf)
+{
+ int i;
+
+ png_debug1(1, "in %s storage function", "eXIf");
+
+ if (png_ptr == NULL || info_ptr == NULL)
+ return;
+
+ if (info_ptr->exif)
+ {
+ png_free(png_ptr, info_ptr->exif);
+ info_ptr->exif = NULL;
+ }
+
+ info_ptr->num_exif = num_exif;
+
+ info_ptr->exif = png_voidcast(png_bytep, png_malloc_warn(png_ptr,
+ info_ptr->num_exif));
+
+ if (info_ptr->exif == NULL)
+ {
+ png_warning(png_ptr, "Insufficient memory for eXIf chunk data");
+ return;
+ }
+
+ info_ptr->free_me |= PNG_FREE_EXIF;
+
+ for (i = 0; i < (int) info_ptr->num_exif; i++)
+ info_ptr->exif[i] = eXIf_buf[i];
+
+ info_ptr->valid |= PNG_INFO_eXIf;
+}
+#endif /* eXIf */
+
#ifdef PNG_gAMA_SUPPORTED
void PNGFAPI
png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
@@ -328,10 +375,10 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
length = strlen(units) + 1;
png_debug1(3, "allocating units for info (%lu bytes)",
- (unsigned long)length);
+ (unsigned long)length);
info_ptr->pcal_units = png_voidcast(png_charp,
- png_malloc_warn(png_ptr, length));
+ png_malloc_warn(png_ptr, length));
if (info_ptr->pcal_units == NULL)
{
@@ -343,7 +390,7 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
memcpy(info_ptr->pcal_units, units, length);
info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,
- (png_size_t)((nparams + 1) * (sizeof (png_charp)))));
+ (png_size_t)(((unsigned int)nparams + 1) * (sizeof (png_charp)))));
if (info_ptr->pcal_params == NULL)
{
@@ -352,7 +399,8 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
return;
}
- memset(info_ptr->pcal_params, 0, (nparams + 1) * (sizeof (png_charp)));
+ memset(info_ptr->pcal_params, 0, ((unsigned int)nparams + 1) *
+ (sizeof (png_charp)));
for (i = 0; i < nparams; i++)
{
@@ -410,7 +458,7 @@ png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,
png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw);
info_ptr->scal_s_width = png_voidcast(png_charp,
- png_malloc_warn(png_ptr, lengthw));
+ png_malloc_warn(png_ptr, lengthw));
if (info_ptr->scal_s_width == NULL)
{
@@ -426,7 +474,7 @@ png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,
png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh);
info_ptr->scal_s_height = png_voidcast(png_charp,
- png_malloc_warn(png_ptr, lengthh));
+ png_malloc_warn(png_ptr, lengthh));
if (info_ptr->scal_s_height == NULL)
{
@@ -465,9 +513,9 @@ png_set_sCAL(png_const_structrp png_ptr, png_inforp info_ptr, int unit,
char sheight[PNG_sCAL_MAX_DIGITS+1];
png_ascii_from_fp(png_ptr, swidth, (sizeof swidth), width,
- PNG_sCAL_PRECISION);
+ PNG_sCAL_PRECISION);
png_ascii_from_fp(png_ptr, sheight, (sizeof sheight), height,
- PNG_sCAL_PRECISION);
+ PNG_sCAL_PRECISION);
png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
}
@@ -575,7 +623,8 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
PNG_MAX_PALETTE_LENGTH * (sizeof (png_color))));
if (num_palette > 0)
- memcpy(png_ptr->palette, palette, num_palette * (sizeof (png_color)));
+ memcpy(png_ptr->palette, palette, (unsigned int)num_palette *
+ (sizeof (png_color)));
info_ptr->palette = png_ptr->palette;
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
@@ -660,7 +709,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
*/
{
int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name,
- proflen, profile, info_ptr->color_type);
+ proflen, profile, info_ptr->color_type);
png_colorspace_sync_info(png_ptr, info_ptr);
@@ -685,7 +734,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
memcpy(new_iccp_name, name, length);
new_iccp_profile = png_voidcast(png_bytep,
- png_malloc_warn(png_ptr, proflen));
+ png_malloc_warn(png_ptr, proflen));
if (new_iccp_profile == NULL)
{
@@ -760,14 +809,14 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
* the overflow checks.
*/
new_text = png_voidcast(png_textp,png_realloc_array(png_ptr,
- info_ptr->text, old_num_text, max_text-old_num_text,
- sizeof *new_text));
+ info_ptr->text, old_num_text, max_text-old_num_text,
+ sizeof *new_text));
}
if (new_text == NULL)
{
png_chunk_report(png_ptr, "too many text chunks",
- PNG_CHUNK_WRITE_ERROR);
+ PNG_CHUNK_WRITE_ERROR);
return 1;
}
@@ -795,7 +844,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)
{
png_chunk_report(png_ptr, "text compression mode is out of range",
- PNG_CHUNK_WRITE_ERROR);
+ PNG_CHUNK_WRITE_ERROR);
continue;
}
@@ -827,7 +876,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
# else /* iTXt */
{
png_chunk_report(png_ptr, "iTXt chunk not supported",
- PNG_CHUNK_WRITE_ERROR);
+ PNG_CHUNK_WRITE_ERROR);
continue;
}
# endif
@@ -856,7 +905,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
if (textp->key == NULL)
{
png_chunk_report(png_ptr, "text chunk: out of memory",
- PNG_CHUNK_WRITE_ERROR);
+ PNG_CHUNK_WRITE_ERROR);
return 1;
}
@@ -968,8 +1017,7 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
{
/* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
info_ptr->trans_alpha = png_voidcast(png_bytep,
- png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH));
-
+ png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH));
memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
}
png_ptr->trans_alpha = info_ptr->trans_alpha;
@@ -989,7 +1037,7 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
trans_color->green > sample_max ||
trans_color->blue > sample_max)))
png_warning(png_ptr,
- "tRNS chunk has out-of-range samples for bit_depth");
+ "tRNS chunk has out-of-range samples for bit_depth");
}
#endif
@@ -1031,8 +1079,8 @@ png_set_sPLT(png_const_structrp png_ptr,
* overflows. Notice that the parameters are (int) and (size_t)
*/
np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr,
- info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries,
- sizeof *np));
+ info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries,
+ sizeof *np));
if (np == NULL)
{
@@ -1093,7 +1141,7 @@ png_set_sPLT(png_const_structrp png_ptr,
* checked it when doing the allocation.
*/
memcpy(np->entries, entries->entries,
- entries->nentries * sizeof (png_sPLT_entry));
+ (unsigned int)entries->nentries * sizeof (png_sPLT_entry));
/* Note that 'continue' skips the advance of the out pointer and out
* count, so an invalid entry is not added.
@@ -1101,8 +1149,9 @@ png_set_sPLT(png_const_structrp png_ptr,
info_ptr->valid |= PNG_INFO_sPLT;
++(info_ptr->splt_palettes_num);
++np;
+ ++entries;
}
- while (++entries, --nentries);
+ while (--nentries);
if (nentries > 0)
png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR);
@@ -1123,10 +1172,10 @@ check_location(png_const_structrp png_ptr, int location)
{
/* Write struct, so unknown chunks come from the app */
png_app_warning(png_ptr,
- "png_set_unknown_chunks now expects a valid location");
+ "png_set_unknown_chunks now expects a valid location");
/* Use the old behavior */
location = (png_byte)(png_ptr->mode &
- (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));
+ (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));
}
/* This need not be an internal error - if the app calls
@@ -1149,7 +1198,7 @@ check_location(png_const_structrp png_ptr, int location)
void PNGAPI
png_set_unknown_chunks(png_const_structrp png_ptr,
- png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
+ png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
{
png_unknown_chunkp np;
@@ -1188,13 +1237,13 @@ png_set_unknown_chunks(png_const_structrp png_ptr,
* appropriate to read or write.
*/
np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr,
- info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns,
- sizeof *np));
+ info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns,
+ sizeof *np));
if (np == NULL)
{
png_chunk_report(png_ptr, "too many unknown chunks",
- PNG_CHUNK_WRITE_ERROR);
+ PNG_CHUNK_WRITE_ERROR);
return;
}
@@ -1223,12 +1272,12 @@ png_set_unknown_chunks(png_const_structrp png_ptr,
else
{
np->data = png_voidcast(png_bytep,
- png_malloc_base(png_ptr, unknowns->size));
+ png_malloc_base(png_ptr, unknowns->size));
if (np->data == NULL)
{
png_chunk_report(png_ptr, "unknown chunk: out of memory",
- PNG_CHUNK_WRITE_ERROR);
+ PNG_CHUNK_WRITE_ERROR);
/* But just skip storing the unknown chunk */
continue;
}
@@ -1262,7 +1311,7 @@ png_set_unknown_chunk_location(png_const_structrp png_ptr, png_inforp info_ptr,
{
png_app_error(png_ptr, "invalid unknown chunk location");
/* Fake out the pre 1.6.0 behavior: */
- if ((location & PNG_HAVE_IDAT) != 0) /* undocumented! */
+ if (((unsigned int)location & PNG_HAVE_IDAT) != 0) /* undocumented! */
location = PNG_AFTER_IDAT;
else
@@ -1353,6 +1402,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
static PNG_CONST png_byte chunks_to_ignore[] = {
98, 75, 71, 68, '\0', /* bKGD */
99, 72, 82, 77, '\0', /* cHRM */
+ 101, 88, 73, 102, '\0', /* eXIf */
103, 65, 77, 65, '\0', /* gAMA */
104, 73, 83, 84, '\0', /* hIST */
105, 67, 67, 80, '\0', /* iCCP */
@@ -1386,7 +1436,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
return;
}
- num_chunks = num_chunks_in;
+ num_chunks = (unsigned int)num_chunks_in;
}
old_num_chunks = png_ptr->num_chunk_list;
@@ -1435,7 +1485,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
for (i=0; i<num_chunks; ++i)
{
old_num_chunks = add_one_chunk(new_list, old_num_chunks,
- chunk_list+5*i, keep);
+ chunk_list+5*i, keep);
}
/* Now remove any spurious 'default' entries. */
@@ -1515,60 +1565,60 @@ png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr,
void PNGAPI
png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
{
- if (png_ptr == NULL)
- return;
+ if (png_ptr == NULL)
+ return;
- if (size == 0 || size > PNG_UINT_31_MAX)
- png_error(png_ptr, "invalid compression buffer size");
+ if (size == 0 || size > PNG_UINT_31_MAX)
+ png_error(png_ptr, "invalid compression buffer size");
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
- if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
- {
- png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */
- return;
- }
+ if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
+ {
+ png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */
+ return;
+ }
# endif
# ifdef PNG_WRITE_SUPPORTED
- if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
+ if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
+ {
+ if (png_ptr->zowner != 0)
{
- if (png_ptr->zowner != 0)
- {
- png_warning(png_ptr,
- "Compression buffer size cannot be changed because it is in use");
+ png_warning(png_ptr,
+ "Compression buffer size cannot be changed because it is in use");
- return;
- }
+ return;
+ }
#ifndef __COVERITY__
- /* Some compilers complain that this is always false. However, it
- * can be true when integer overflow happens.
- */
- if (size > ZLIB_IO_MAX)
- {
- png_warning(png_ptr,
- "Compression buffer size limited to system maximum");
- size = ZLIB_IO_MAX; /* must fit */
- }
+ /* Some compilers complain that this is always false. However, it
+ * can be true when integer overflow happens.
+ */
+ if (size > ZLIB_IO_MAX)
+ {
+ png_warning(png_ptr,
+ "Compression buffer size limited to system maximum");
+ size = ZLIB_IO_MAX; /* must fit */
+ }
#endif
- if (size < 6)
- {
- /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH
- * if this is permitted.
- */
- png_warning(png_ptr,
- "Compression buffer size cannot be reduced below 6");
+ if (size < 6)
+ {
+ /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH
+ * if this is permitted.
+ */
+ png_warning(png_ptr,
+ "Compression buffer size cannot be reduced below 6");
- return;
- }
+ return;
+ }
- if (png_ptr->zbuffer_size != size)
- {
- png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
- png_ptr->zbuffer_size = (uInt)size;
- }
+ if (png_ptr->zbuffer_size != size)
+ {
+ png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
+ png_ptr->zbuffer_size = (uInt)size;
}
+ }
# endif
}
@@ -1576,7 +1626,7 @@ void PNGAPI
png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask)
{
if (png_ptr != NULL && info_ptr != NULL)
- info_ptr->valid &= ~mask;
+ info_ptr->valid &= (unsigned int)(~mask);
}
@@ -1675,7 +1725,9 @@ png_set_check_for_invalid_index(png_structrp png_ptr, int allowed)
png_uint_32 /* PRIVATE */
png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
{
+#ifdef PNG_WARNINGS_SUPPORTED
png_const_charp orig_key = key;
+#endif
png_uint_32 key_len = 0;
int bad_character = 0;
int space = 1;
@@ -1693,14 +1745,16 @@ png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
png_byte ch = (png_byte)*key++;
if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/))
- *new_key++ = ch, ++key_len, space = 0;
+ {
+ *new_key++ = ch; ++key_len; space = 0;
+ }
else if (space == 0)
{
/* A space or an invalid character when one wasn't seen immediately
* before; output just a space.
*/
- *new_key++ = 32, ++key_len, space = 1;
+ *new_key++ = 32; ++key_len; space = 1;
/* If the character was not a space then it is invalid. */
if (ch != 32)
@@ -1713,7 +1767,7 @@ png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
if (key_len > 0 && space != 0) /* trailing space */
{
- --key_len, --new_key;
+ --key_len; --new_key;
if (bad_character == 0)
bad_character = 32;
}
@@ -1738,7 +1792,9 @@ png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
png_formatted_warning(png_ptr, p, "keyword \"@1\": bad character '0x@2'");
}
-#endif /* WARNINGS */
+#else /* !WARNINGS */
+ PNG_UNUSED(png_ptr)
+#endif /* !WARNINGS */
return key_len;
}
diff --git a/third_party/libpng16/pngstruct.h b/third_party/libpng16/pngstruct.h
index c1f35edef5..aac88df02d 100644
--- a/third_party/libpng16/pngstruct.h
+++ b/third_party/libpng16/pngstruct.h
@@ -1,8 +1,8 @@
/* pngstruct.h - header file for PNG reference library
*
- * Last changed in libpng 1.6.18 [July 23, 2015]
- * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.32 [August 24, 2017]
+ * Copyright (c) 1998-2002,2004,2006-2017 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.)
*
@@ -228,6 +228,10 @@ struct png_struct_def
* big_row_buf; while writing it is separately
* allocated.
*/
+#ifdef PNG_READ_EXPAND_SUPPORTED
+ /* Buffer to accelerate palette transformations. */
+ png_bytep riffled_palette;
+#endif
#ifdef PNG_WRITE_FILTER_SUPPORTED
png_bytep try_row; /* buffer to save trial row when filtering */
png_bytep tst_row; /* buffer to save best trial row when filtering */
@@ -249,7 +253,7 @@ struct png_struct_def
png_byte filter; /* file filter type (always 0) */
png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
png_byte pass; /* current interlace pass (0 - 6) */
- png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
+ png_byte do_filter; /* row filter flags (see PNG_FILTER_ in png.h ) */
png_byte color_type; /* color type of file */
png_byte bit_depth; /* bit depth of file */
png_byte usr_bit_depth; /* bit depth of users row: write only */
@@ -263,7 +267,7 @@ struct png_struct_def
/* pixel depth used for the row buffers */
png_byte transformed_pixel_depth;
/* pixel depth after read/write transforms */
-#if PNG_ZLIB_VERNUM >= 0x1240
+#if ZLIB_VERNUM >= 0x1240
png_byte zstream_start; /* at start of an input zlib stream */
#endif /* Zlib >= 1.2.4 */
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
@@ -353,7 +357,7 @@ struct png_struct_def
/* Options */
#ifdef PNG_SET_OPTION_SUPPORTED
- png_byte options; /* On/off state (up to 4 options) */
+ png_uint_32 options; /* On/off state (up to 16 options) */
#endif
#if PNG_LIBPNG_VER < 10700
diff --git a/third_party/libpng16/pngtrans.c b/third_party/libpng16/pngtrans.c
index 7f8cc455d3..6882f0fd7b 100644
--- a/third_party/libpng16/pngtrans.c
+++ b/third_party/libpng16/pngtrans.c
@@ -1,8 +1,8 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
- * Last changed in libpng 1.6.18 [July 23, 2015]
- * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.33 [September 28, 2017]
+ * Copyright (c) 1998-2002,2004,2006-2017 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.)
*
@@ -172,13 +172,14 @@ png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
* size!
*/
png_app_error(png_ptr,
- "png_set_filler is invalid for low bit depth gray output");
+ "png_set_filler is invalid for"
+ " low bit depth gray output");
return;
}
default:
png_app_error(png_ptr,
- "png_set_filler: inappropriate color type");
+ "png_set_filler: inappropriate color type");
return;
}
# else
@@ -513,11 +514,15 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
if (at_start != 0) /* Skip initial filler */
++sp;
else /* Skip initial channel and, for sp, the filler */
- sp += 2, ++dp;
+ {
+ sp += 2; ++dp;
+ }
/* For a 1 pixel wide image there is nothing to do */
while (sp < ep)
- *dp++ = *sp, sp += 2;
+ {
+ *dp++ = *sp; sp += 2;
+ }
row_info->pixel_depth = 8;
}
@@ -527,10 +532,14 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
if (at_start != 0) /* Skip initial filler */
sp += 2;
else /* Skip initial channel and, for sp, the filler */
- sp += 4, dp += 2;
+ {
+ sp += 4; dp += 2;
+ }
while (sp < ep)
- *dp++ = *sp++, *dp++ = *sp, sp += 3;
+ {
+ *dp++ = *sp++; *dp++ = *sp; sp += 3;
+ }
row_info->pixel_depth = 16;
}
@@ -553,11 +562,15 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
if (at_start != 0) /* Skip initial filler */
++sp;
else /* Skip initial channels and, for sp, the filler */
- sp += 4, dp += 3;
+ {
+ sp += 4; dp += 3;
+ }
/* Note that the loop adds 3 to dp and 4 to sp each time. */
while (sp < ep)
- *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2;
+ {
+ *dp++ = *sp++; *dp++ = *sp++; *dp++ = *sp; sp += 2;
+ }
row_info->pixel_depth = 24;
}
@@ -567,14 +580,16 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
if (at_start != 0) /* Skip initial filler */
sp += 2;
else /* Skip initial channels and, for sp, the filler */
- sp += 8, dp += 6;
+ {
+ sp += 8; dp += 6;
+ }
while (sp < ep)
{
/* Copy 6 bytes, skip 2 */
- *dp++ = *sp++, *dp++ = *sp++;
- *dp++ = *sp++, *dp++ = *sp++;
- *dp++ = *sp++, *dp++ = *sp, sp += 3;
+ *dp++ = *sp++; *dp++ = *sp++;
+ *dp++ = *sp++; *dp++ = *sp++;
+ *dp++ = *sp++; *dp++ = *sp; sp += 3;
}
row_info->pixel_depth = 48;
@@ -594,7 +609,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
return; /* The filler channel has gone already */
/* Fix the rowbytes value. */
- row_info->rowbytes = dp-row;
+ row_info->rowbytes = (png_size_t)(dp-row);
}
#endif
@@ -692,8 +707,8 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
* and this calculation is used because it avoids warnings that other
* forms produced on either GCC or MSVC.
*/
- int padding = (-row_info->pixel_depth * row_info->width) & 7;
- png_bytep rp = png_ptr->row_buf + row_info->rowbytes;
+ int padding = PNG_PADBITS(row_info->pixel_depth, row_info->width);
+ png_bytep rp = png_ptr->row_buf + row_info->rowbytes - 1;
switch (row_info->bit_depth)
{
@@ -797,7 +812,7 @@ png_set_user_transform_info(png_structrp png_ptr, png_voidp
(png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)
{
png_app_error(png_ptr,
- "info change after png_start_read_image or png_read_update_info");
+ "info change after png_start_read_image or png_read_update_info");
return;
}
#endif
diff --git a/third_party/libpng16/pngwio.c b/third_party/libpng16/pngwio.c
index 586c03b721..37c7c3a7f0 100644
--- a/third_party/libpng16/pngwio.c
+++ b/third_party/libpng16/pngwio.c
@@ -1,8 +1,8 @@
/* pngwio.c - functions for data output
*
- * Last changed in libpng 1.6.15 [November 20, 2014]
- * Copyright (c) 1998-2002,2004,2006-2014 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.24 [August 4, 2016]
+ * Copyright (c) 1998-2002,2004,2006-2014,2016 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.)
*
@@ -35,7 +35,7 @@ png_write_data(png_structrp png_ptr, png_const_bytep data, png_size_t length)
/* NOTE: write_data_fn must not change the buffer! */
if (png_ptr->write_data_fn != NULL )
(*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data),
- length);
+ length);
else
png_error(png_ptr, "Call to NULL write function");
diff --git a/third_party/libpng16/pngwrite.c b/third_party/libpng16/pngwrite.c
index 181a899438..e25e5dcfdc 100644
--- a/third_party/libpng16/pngwrite.c
+++ b/third_party/libpng16/pngwrite.c
@@ -1,8 +1,8 @@
/* pngwrite.c - general routines to write a PNG file
*
- * Last changed in libpng 1.6.19 [November 12, 2015]
- * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.32 [August 24, 2017]
+ * Copyright (c) 1998-2002,2004,2006-2017 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.)
*
@@ -22,7 +22,7 @@
/* Write out all the unknown chunks for the current given location */
static void
write_unknown_chunks(png_structrp png_ptr, png_const_inforp info_ptr,
- unsigned int where)
+ unsigned int where)
{
if (info_ptr->unknown_chunks_num != 0)
{
@@ -148,11 +148,11 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
# ifdef PNG_WRITE_sRGB_SUPPORTED
if ((info_ptr->valid & PNG_INFO_sRGB) != 0)
png_app_warning(png_ptr,
- "profile matches sRGB but writing iCCP instead");
+ "profile matches sRGB but writing iCCP instead");
# endif
png_write_iCCP(png_ptr, info_ptr->iccp_name,
- info_ptr->iccp_profile);
+ info_ptr->iccp_profile);
}
# ifdef PNG_WRITE_sRGB_SUPPORTED
else
@@ -237,6 +237,11 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)
png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
#endif
+#ifdef PNG_WRITE_eXIf_SUPPORTED
+ if ((info_ptr->valid & PNG_INFO_eXIf) != 0)
+ png_write_eXIf(png_ptr, info_ptr->exif, info_ptr->num_exif);
+#endif
+
#ifdef PNG_WRITE_hIST_SUPPORTED
if ((info_ptr->valid & PNG_INFO_hIST) != 0)
png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
@@ -383,7 +388,7 @@ png_write_end(png_structrp png_ptr, png_inforp info_ptr)
for (i = 0; i < info_ptr->num_text; i++)
{
png_debug2(2, "Writing trailer text chunk %d, type %d", i,
- info_ptr->text[i].compression);
+ info_ptr->text[i].compression);
/* An internationalized chunk? */
if (info_ptr->text[i].compression > 0)
{
@@ -432,6 +437,12 @@ png_write_end(png_structrp png_ptr, png_inforp info_ptr)
}
}
#endif
+
+#ifdef PNG_WRITE_eXIf_SUPPORTED
+ if ((info_ptr->valid & PNG_INFO_eXIf) != 0)
+ png_write_eXIf(png_ptr, info_ptr->exif, info_ptr->num_exif);
+#endif
+
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
write_unknown_chunks(png_ptr, info_ptr, PNG_AFTER_IDAT);
#endif
@@ -666,9 +677,9 @@ png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
- png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
- png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
- png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
+ png_uint_32 s0 = (png_uint_32)(*(rp ) << 8) | *(rp + 1);
+ png_uint_32 s1 = (png_uint_32)(*(rp + 2) << 8) | *(rp + 3);
+ png_uint_32 s2 = (png_uint_32)(*(rp + 4) << 8) | *(rp + 5);
png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL);
png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
*(rp ) = (png_byte)(red >> 8);
@@ -693,7 +704,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
return;
png_debug2(1, "in png_write_row (row %u, pass %d)",
- png_ptr->row_number, png_ptr->pass);
+ png_ptr->row_number, png_ptr->pass);
/* Initialize transformations and other stuff if first time */
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
@@ -901,7 +912,7 @@ png_set_flush(png_structrp png_ptr, int nrows)
if (png_ptr == NULL)
return;
- png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
+ png_ptr->flush_dist = (nrows < 0 ? 0 : (png_uint_32)nrows);
}
/* Flush the current output buffers now */
@@ -937,6 +948,10 @@ png_write_destroy(png_structrp png_ptr)
png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
png_free(png_ptr, png_ptr->row_buf);
png_ptr->row_buf = NULL;
+#ifdef PNG_READ_EXPANDED_SUPPORTED
+ png_free(png_ptr, png_ptr->riffled_palette);
+ png_ptr->riffled_palette = NULL;
+#endif
#ifdef PNG_WRITE_FILTER_SUPPORTED
png_free(png_ptr, png_ptr->prev_row);
png_free(png_ptr, png_ptr->try_row);
@@ -1007,8 +1022,8 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
case 5:
case 6:
case 7: png_app_error(png_ptr, "Unknown row filter for method 0");
- /* FALL THROUGH */
#endif /* WRITE_FILTER */
+ /* FALLTHROUGH */
case PNG_FILTER_VALUE_NONE:
png_ptr->do_filter = PNG_FILTER_NONE; break;
@@ -1069,7 +1084,7 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
* is not available so the filter can't be used. Just warn here.
*/
png_app_warning(png_ptr,
- "png_set_filter: UP/AVG/PAETH cannot be added after start");
+ "png_set_filter: UP/AVG/PAETH cannot be added after start");
filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH);
}
@@ -1095,13 +1110,13 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
if (png_ptr->try_row == NULL)
png_ptr->try_row = png_voidcast(png_bytep,
- png_malloc(png_ptr, buf_size));
+ png_malloc(png_ptr, buf_size));
if (num_filters > 1)
{
if (png_ptr->tst_row == NULL)
png_ptr->tst_row = png_voidcast(png_bytep,
- png_malloc(png_ptr, buf_size));
+ png_malloc(png_ptr, buf_size));
}
}
png_ptr->do_filter = (png_byte)filters;
@@ -1525,7 +1540,8 @@ png_write_image_16bit(png_voidp argument)
display->first_row);
png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row);
png_uint_16p row_end;
- const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1;
+ const unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ?
+ 3 : 1;
int aindex = 0;
png_uint_32 y = image->height;
@@ -1539,9 +1555,9 @@ png_write_image_16bit(png_voidp argument)
++output_row;
}
else
- aindex = channels;
+ aindex = (int)channels;
# else
- aindex = channels;
+ aindex = (int)channels;
# endif
}
@@ -1554,7 +1570,7 @@ png_write_image_16bit(png_voidp argument)
*/
row_end = output_row + image->width * (channels+1);
- while (y-- > 0)
+ for (; y > 0; --y)
{
png_const_uint_16p in_ptr = input_row;
png_uint_16p out_ptr = output_row;
@@ -1575,7 +1591,7 @@ png_write_image_16bit(png_voidp argument)
if (alpha > 0 && alpha < 65535)
reciprocal = ((0xffff<<15)+(alpha>>1))/alpha;
- c = channels;
+ c = (int)channels;
do /* always at least one channel */
{
png_uint_16 component = *in_ptr++;
@@ -1610,7 +1626,7 @@ png_write_image_16bit(png_voidp argument)
}
png_write_row(png_ptr, png_voidcast(png_const_bytep, display->local_row));
- input_row += display->row_bytes/(sizeof (png_uint_16));
+ input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16));
}
return 1;
@@ -1628,7 +1644,7 @@ png_write_image_16bit(png_voidp argument)
static png_byte
png_unpremultiply(png_uint_32 component, png_uint_32 alpha,
- png_uint_32 reciprocal/*from the above macro*/)
+ png_uint_32 reciprocal/*from the above macro*/)
{
/* The following gives 1.0 for an alpha of 0, which is fine, otherwise if 0/0
* is represented as some other value there is more likely to be a
@@ -1683,7 +1699,8 @@ png_write_image_8bit(png_voidp argument)
display->first_row);
png_bytep output_row = png_voidcast(png_bytep, display->local_row);
png_uint_32 y = image->height;
- const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1;
+ const unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ?
+ 3 : 1;
if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0)
{
@@ -1700,12 +1717,12 @@ png_write_image_8bit(png_voidp argument)
else
# endif
- aindex = channels;
+ aindex = (int)channels;
/* Use row_end in place of a loop counter: */
row_end = output_row + image->width * (channels+1);
- while (y-- > 0)
+ for (; y > 0; --y)
{
png_const_uint_16p in_ptr = input_row;
png_bytep out_ptr = output_row;
@@ -1723,7 +1740,7 @@ png_write_image_8bit(png_voidp argument)
if (alphabyte > 0 && alphabyte < 255)
reciprocal = UNP_RECIPROCAL(alpha);
- c = channels;
+ c = (int)channels;
do /* always at least one channel */
*out_ptr++ = png_unpremultiply(*in_ptr++, alpha, reciprocal);
while (--c > 0);
@@ -1735,7 +1752,7 @@ png_write_image_8bit(png_voidp argument)
png_write_row(png_ptr, png_voidcast(png_const_bytep,
display->local_row));
- input_row += display->row_bytes/(sizeof (png_uint_16));
+ input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16));
} /* while y */
}
@@ -1746,7 +1763,7 @@ png_write_image_8bit(png_voidp argument)
*/
png_bytep row_end = output_row + image->width * channels;
- while (y-- > 0)
+ for (; y > 0; --y)
{
png_const_uint_16p in_ptr = input_row;
png_bytep out_ptr = output_row;
@@ -1760,7 +1777,7 @@ png_write_image_8bit(png_voidp argument)
}
png_write_row(png_ptr, output_row);
- input_row += display->row_bytes/(sizeof (png_uint_16));
+ input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16));
}
}
@@ -1777,7 +1794,7 @@ png_image_set_PLTE(png_image_write_control *display)
/* NOTE: the caller must check for cmap != NULL and entries != 0 */
const png_uint_32 format = image->format;
- const int channels = PNG_IMAGE_SAMPLE_CHANNELS(format);
+ const unsigned int channels = PNG_IMAGE_SAMPLE_CHANNELS(format);
# if defined(PNG_FORMAT_BGR_SUPPORTED) &&\
defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED)
@@ -1809,7 +1826,7 @@ png_image_set_PLTE(png_image_write_control *display)
{
png_const_uint_16p entry = png_voidcast(png_const_uint_16p, cmap);
- entry += i * channels;
+ entry += (unsigned int)i * channels;
if ((channels & 1) != 0) /* no alpha */
{
@@ -1848,16 +1865,16 @@ png_image_set_PLTE(png_image_write_control *display)
if (channels >= 3) /* RGB */
{
palette[i].blue = png_unpremultiply(entry[afirst + (2 ^ bgr)],
- alpha, reciprocal);
+ alpha, reciprocal);
palette[i].green = png_unpremultiply(entry[afirst + 1], alpha,
- reciprocal);
+ reciprocal);
palette[i].red = png_unpremultiply(entry[afirst + bgr], alpha,
- reciprocal);
+ reciprocal);
}
else /* gray */
palette[i].blue = palette[i].red = palette[i].green =
- png_unpremultiply(entry[afirst], alpha, reciprocal);
+ png_unpremultiply(entry[afirst], alpha, reciprocal);
}
}
@@ -1865,7 +1882,7 @@ png_image_set_PLTE(png_image_write_control *display)
{
png_const_bytep entry = png_voidcast(png_const_bytep, cmap);
- entry += i * channels;
+ entry += (unsigned int)i * channels;
switch (channels)
{
@@ -1873,7 +1890,7 @@ png_image_set_PLTE(png_image_write_control *display)
tRNS[i] = entry[afirst ? 0 : 3];
if (tRNS[i] < 255)
num_trans = i+1;
- /* FALL THROUGH */
+ /* FALLTHROUGH */
case 3:
palette[i].blue = entry[afirst + (2 ^ bgr)];
palette[i].green = entry[afirst + 1];
@@ -1884,7 +1901,7 @@ png_image_set_PLTE(png_image_write_control *display)
tRNS[i] = entry[1 ^ afirst];
if (tRNS[i] < 255)
num_trans = i+1;
- /* FALL THROUGH */
+ /* FALLTHROUGH */
case 1:
palette[i].blue = palette[i].red = palette[i].green =
entry[afirst];
@@ -1904,20 +1921,20 @@ png_image_set_PLTE(png_image_write_control *display)
# endif
png_set_PLTE(image->opaque->png_ptr, image->opaque->info_ptr, palette,
- entries);
+ entries);
if (num_trans > 0)
png_set_tRNS(image->opaque->png_ptr, image->opaque->info_ptr, tRNS,
- num_trans, NULL);
+ num_trans, NULL);
- image->colormap_entries = entries;
+ image->colormap_entries = (png_uint_32)entries;
}
static int
png_image_write_main(png_voidp argument)
{
png_image_write_control *display = png_voidcast(png_image_write_control*,
- argument);
+ argument);
png_imagep image = display->image;
png_structrp png_ptr = image->opaque->png_ptr;
png_inforp info_ptr = image->opaque->info_ptr;
@@ -1927,7 +1944,7 @@ png_image_write_main(png_voidp argument)
int colormap = (format & PNG_FORMAT_FLAG_COLORMAP);
int linear = !colormap && (format & PNG_FORMAT_FLAG_LINEAR); /* input */
int alpha = !colormap && (format & PNG_FORMAT_FLAG_ALPHA);
- int write_16bit = linear && !colormap && (display->convert_to_8bit == 0);
+ int write_16bit = linear && (display->convert_to_8bit == 0);
# ifdef PNG_BENIGN_ERRORS_SUPPORTED
/* Make sure we error out on any bad situation */
@@ -1940,7 +1957,7 @@ png_image_write_main(png_voidp argument)
{
const unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format);
- if (image->width <= 0x7FFFFFFFU/channels) /* no overflow */
+ if (image->width <= 0x7fffffffU/channels) /* no overflow */
{
png_uint_32 check;
const png_uint_32 png_row_stride = image->width * channels;
@@ -1949,10 +1966,10 @@ png_image_write_main(png_voidp argument)
display->row_stride = (png_int_32)/*SAFE*/png_row_stride;
if (display->row_stride < 0)
- check = -display->row_stride;
+ check = (png_uint_32)(-display->row_stride);
else
- check = display->row_stride;
+ check = (png_uint_32)display->row_stride;
if (check >= png_row_stride)
{
@@ -1960,7 +1977,7 @@ png_image_write_main(png_voidp argument)
* limits the whole image size to 32 bits for API compatibility with
* the current, 32-bit, PNG_IMAGE_BUFFER_SIZE macro.
*/
- if (image->height > 0xFFFFFFFF/png_row_stride)
+ if (image->height > 0xffffffffU/png_row_stride)
png_error(image->opaque->png_ptr, "memory image too large");
}
@@ -1980,24 +1997,24 @@ png_image_write_main(png_voidp argument)
png_uint_32 entries = image->colormap_entries;
png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
- entries > 16 ? 8 : (entries > 4 ? 4 : (entries > 2 ? 2 : 1)),
- PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+ entries > 16 ? 8 : (entries > 4 ? 4 : (entries > 2 ? 2 : 1)),
+ PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_image_set_PLTE(display);
}
else
png_error(image->opaque->png_ptr,
- "no color-map for color-mapped image");
+ "no color-map for color-mapped image");
}
else
png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
- write_16bit ? 16 : 8,
- ((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) +
- ((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0),
- PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+ write_16bit ? 16 : 8,
+ ((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) +
+ ((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0),
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
/* Counter-intuitively the data transformations must be called *after*
* png_write_info, not before as in the read code, but the 'set' functions
@@ -2012,11 +2029,11 @@ png_image_write_main(png_voidp argument)
if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0)
png_set_cHRM_fixed(png_ptr, info_ptr,
- /* color x y */
- /* white */ 31270, 32900,
- /* red */ 64000, 33000,
- /* green */ 30000, 60000,
- /* blue */ 15000, 6000
+ /* color x y */
+ /* white */ 31270, 32900,
+ /* red */ 64000, 33000,
+ /* green */ 30000, 60000,
+ /* blue */ 15000, 6000
);
}
@@ -2110,7 +2127,7 @@ png_image_write_main(png_voidp argument)
(colormap == 0 && display->convert_to_8bit != 0))
{
png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr,
- png_get_rowbytes(png_ptr, info_ptr)));
+ png_get_rowbytes(png_ptr, info_ptr)));
int result;
display->local_row = row;
@@ -2136,7 +2153,7 @@ png_image_write_main(png_voidp argument)
ptrdiff_t row_bytes = display->row_bytes;
png_uint_32 y = image->height;
- while (y-- > 0)
+ for (; y > 0; --y)
{
png_write_row(png_ptr, row);
row += row_bytes;
@@ -2150,10 +2167,10 @@ png_image_write_main(png_voidp argument)
static void (PNGCBAPI
image_memory_write)(png_structp png_ptr, png_bytep/*const*/ data,
- png_size_t size)
+ png_size_t size)
{
png_image_write_control *display = png_voidcast(png_image_write_control*,
- png_ptr->io_ptr/*backdoor: png_get_io_ptr(png_ptr)*/);
+ png_ptr->io_ptr/*backdoor: png_get_io_ptr(png_ptr)*/);
const png_alloc_size_t ob = display->output_bytes;
/* Check for overflow; this should never happen: */
@@ -2184,22 +2201,22 @@ static int
png_image_write_memory(png_voidp argument)
{
png_image_write_control *display = png_voidcast(png_image_write_control*,
- argument);
+ argument);
/* The rest of the memory-specific init and write_main in an error protected
* environment. This case needs to use callbacks for the write operations
* since libpng has no built in support for writing to memory.
*/
png_set_write_fn(display->image->opaque->png_ptr, display/*io_ptr*/,
- image_memory_write, image_memory_flush);
+ image_memory_write, image_memory_flush);
return png_image_write_main(display);
}
int PNGAPI
png_image_write_to_memory(png_imagep image, void *memory,
- png_alloc_size_t * PNG_RESTRICT memory_bytes, int convert_to_8bit,
- const void *buffer, png_int_32 row_stride, const void *colormap)
+ png_alloc_size_t * PNG_RESTRICT memory_bytes, int convert_to_8bit,
+ const void *buffer, png_int_32 row_stride, const void *colormap)
{
/* Write the image to the given buffer, or count the bytes if it is NULL */
if (image != NULL && image->version == PNG_IMAGE_VERSION)
@@ -2251,12 +2268,12 @@ png_image_write_to_memory(png_imagep image, void *memory,
else
return png_image_error(image,
- "png_image_write_to_memory: invalid argument");
+ "png_image_write_to_memory: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
- "png_image_write_to_memory: incorrect PNG_IMAGE_VERSION");
+ "png_image_write_to_memory: incorrect PNG_IMAGE_VERSION");
else
return 0;
@@ -2265,7 +2282,7 @@ png_image_write_to_memory(png_imagep image, void *memory,
#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
int PNGAPI
png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
- const void *buffer, png_int_32 row_stride, const void *colormap)
+ const void *buffer, png_int_32 row_stride, const void *colormap)
{
/* Write the image to the given (FILE*). */
if (image != NULL && image->version == PNG_IMAGE_VERSION)
@@ -2301,12 +2318,12 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
else
return png_image_error(image,
- "png_image_write_to_stdio: invalid argument");
+ "png_image_write_to_stdio: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
- "png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION");
+ "png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION");
else
return 0;
@@ -2314,8 +2331,8 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
int PNGAPI
png_image_write_to_file(png_imagep image, const char *file_name,
- int convert_to_8bit, const void *buffer, png_int_32 row_stride,
- const void *colormap)
+ int convert_to_8bit, const void *buffer, png_int_32 row_stride,
+ const void *colormap)
{
/* Write the image to the named file. */
if (image != NULL && image->version == PNG_IMAGE_VERSION)
@@ -2327,7 +2344,7 @@ png_image_write_to_file(png_imagep image, const char *file_name,
if (fp != NULL)
{
if (png_image_write_to_stdio(image, fp, convert_to_8bit, buffer,
- row_stride, colormap) != 0)
+ row_stride, colormap) != 0)
{
int error; /* from fflush/fclose */
@@ -2368,12 +2385,12 @@ png_image_write_to_file(png_imagep image, const char *file_name,
else
return png_image_error(image,
- "png_image_write_to_file: invalid argument");
+ "png_image_write_to_file: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
- "png_image_write_to_file: incorrect PNG_IMAGE_VERSION");
+ "png_image_write_to_file: incorrect PNG_IMAGE_VERSION");
else
return 0;
diff --git a/third_party/libpng16/pngwtran.c b/third_party/libpng16/pngwtran.c
index 038a2ef5dc..377b43e5ca 100644
--- a/third_party/libpng16/pngwtran.c
+++ b/third_party/libpng16/pngwtran.c
@@ -1,8 +1,8 @@
/* pngwtran.c - transforms the data in a row for PNG writers
*
- * Last changed in libpng 1.6.18 [July 23, 2015]
- * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.26 [October 20, 2016]
+ * Copyright (c) 1998-2002,2004,2006-2016 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.)
*
@@ -177,7 +177,7 @@ png_do_shift(png_row_infop row_info, png_bytep row,
if (row_info->color_type != PNG_COLOR_TYPE_PALETTE)
{
int shift_start[4], shift_dec[4];
- int channels = 0;
+ unsigned int channels = 0;
if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
{
@@ -525,7 +525,7 @@ png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
#ifdef PNG_WRITE_FILLER_SUPPORTED
if ((png_ptr->transformations & PNG_FILLER) != 0)
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
- !(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
+ !(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
#endif
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
@@ -549,7 +549,7 @@ png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
#ifdef PNG_WRITE_SHIFT_SUPPORTED
if ((png_ptr->transformations & PNG_SHIFT) != 0)
png_do_shift(row_info, png_ptr->row_buf + 1,
- &(png_ptr->shift));
+ &(png_ptr->shift));
#endif
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED