libpng 1.6.32 [August 24, 2017]

Courtesy of @mrfixit3000 ( https://github.com/reicast/reicast-emulator/issues/1121#issuecomment-383257219 )
This commit is contained in:
TwistedUmbrella 2018-04-20 22:46:51 -04:00 committed by Ender's Games
parent 85d271a7b1
commit 66c3cb8a33
26 changed files with 2891 additions and 1779 deletions

View File

@ -1,9 +1,9 @@
/* arm_init.c - NEON optimised filter functions /* arm_init.c - NEON optimised filter functions
* *
* Copyright (c) 2014 Glenn Randers-Pehrson * Copyright (c) 2014,2016 Glenn Randers-Pehrson
* Written by Mans Rullgard, 2011. * Written by Mans Rullgard, 2011.
* Last changed in libpng 1.6.16 [December 22, 2014] * Last changed in libpng 1.6.22 [May 26, 2016]
* *
* This code is released under the libpng license. * This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer * For conditions of distribution and use, see the disclaimer
@ -66,6 +66,7 @@ png_init_filter_functions_neon(png_structp pp, unsigned int bpp)
* wrong order of the 'ON' and 'default' cases. UNSET now defaults to OFF, * wrong order of the 'ON' and 'default' cases. UNSET now defaults to OFF,
* as documented in png.h * as documented in png.h
*/ */
png_debug(1, "in png_init_filter_functions_neon");
#ifdef PNG_ARM_NEON_API_SUPPORTED #ifdef PNG_ARM_NEON_API_SUPPORTED
switch ((pp->options >> PNG_ARM_NEON) & 3) switch ((pp->options >> PNG_ARM_NEON) & 3)
{ {

View File

@ -1,9 +1,9 @@
/* filter_neon.S - NEON optimised filter functions /* 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. * 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. * This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer * For conditions of distribution and use, see the disclaimer
@ -16,7 +16,7 @@
#define PNG_VERSION_INFO_ONLY #define PNG_VERSION_INFO_ONLY
#include "../pngpriv.h" #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 */ .section .note.GNU-stack,"",%progbits /* mark stack as non-executable */
#endif #endif

View File

@ -1,11 +1,11 @@
/* filter_neon_intrinsics.c - NEON optimised filter functions /* filter_neon_intrinsics.c - NEON optimised filter functions
* *
* Copyright (c) 2014 Glenn Randers-Pehrson * Copyright (c) 2014,2016 Glenn Randers-Pehrson
* Written by James Yu <james.yu at linaro.org>, October 2013. * Written by James Yu <james.yu at linaro.org>, October 2013.
* Based on filter_neon.S, written by Mans Rullgard, 2011. * Based on filter_neon.S, written by Mans Rullgard, 2011.
* *
* Last changed in libpng 1.6.16 [December 22, 2014] * Last changed in libpng 1.6.22 [May 26, 2016]
* *
* This code is released under the libpng license. * This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer * For conditions of distribution and use, see the disclaimer
@ -47,6 +47,8 @@ png_read_filter_row_up_neon(png_row_infop row_info, png_bytep row,
png_bytep rp_stop = row + row_info->rowbytes; png_bytep rp_stop = row + row_info->rowbytes;
png_const_bytep pp = prev_row; png_const_bytep pp = prev_row;
png_debug(1, "in png_read_filter_row_up_neon");
for (; rp < rp_stop; rp += 16, pp += 16) for (; rp < rp_stop; rp += 16, pp += 16)
{ {
uint8x16_t qrp, qpp; uint8x16_t qrp, qpp;
@ -72,6 +74,8 @@ png_read_filter_row_sub3_neon(png_row_infop row_info, png_bytep row,
uint8x8x4_t vdest; uint8x8x4_t vdest;
vdest.val[3] = vdup_n_u8(0); vdest.val[3] = vdup_n_u8(0);
png_debug(1, "in png_read_filter_row_sub3_neon");
for (; rp < rp_stop;) for (; rp < rp_stop;)
{ {
uint8x8_t vtmp1, vtmp2; uint8x8_t vtmp1, vtmp2;
@ -113,6 +117,8 @@ png_read_filter_row_sub4_neon(png_row_infop row_info, png_bytep row,
uint8x8x4_t vdest; uint8x8x4_t vdest;
vdest.val[3] = vdup_n_u8(0); vdest.val[3] = vdup_n_u8(0);
png_debug(1, "in png_read_filter_row_sub4_neon");
for (; rp < rp_stop; rp += 16) for (; rp < rp_stop; rp += 16)
{ {
uint32x2x4_t vtmp = vld4_u32(png_ptr(uint32_t,rp)); uint32x2x4_t vtmp = vld4_u32(png_ptr(uint32_t,rp));
@ -148,6 +154,8 @@ png_read_filter_row_avg3_neon(png_row_infop row_info, png_bytep row,
vrpt = png_ptr(uint8x8x2_t,&vtmp); vrpt = png_ptr(uint8x8x2_t,&vtmp);
vrp = *vrpt; vrp = *vrpt;
png_debug(1, "in png_read_filter_row_avg3_neon");
for (; rp < rp_stop; pp += 12) for (; rp < rp_stop; pp += 12)
{ {
uint8x8_t vtmp1, vtmp2, vtmp3; uint8x8_t vtmp1, vtmp2, vtmp3;
@ -207,6 +215,8 @@ png_read_filter_row_avg4_neon(png_row_infop row_info, png_bytep row,
uint8x8x4_t vdest; uint8x8x4_t vdest;
vdest.val[3] = vdup_n_u8(0); vdest.val[3] = vdup_n_u8(0);
png_debug(1, "in png_read_filter_row_avg4_neon");
for (; rp < rp_stop; rp += 16, pp += 16) for (; rp < rp_stop; rp += 16, pp += 16)
{ {
uint32x2x4_t vtmp; uint32x2x4_t vtmp;
@ -280,6 +290,8 @@ png_read_filter_row_paeth3_neon(png_row_infop row_info, png_bytep row,
vrpt = png_ptr(uint8x8x2_t,&vtmp); vrpt = png_ptr(uint8x8x2_t,&vtmp);
vrp = *vrpt; vrp = *vrpt;
png_debug(1, "in png_read_filter_row_paeth3_neon");
for (; rp < rp_stop; pp += 12) for (; rp < rp_stop; pp += 12)
{ {
uint8x8x2_t *vppt; uint8x8x2_t *vppt;
@ -339,6 +351,8 @@ png_read_filter_row_paeth4_neon(png_row_infop row_info, png_bytep row,
uint8x8x4_t vdest; uint8x8x4_t vdest;
vdest.val[3] = vdup_n_u8(0); vdest.val[3] = vdup_n_u8(0);
png_debug(1, "in png_read_filter_row_paeth4_neon");
for (; rp < rp_stop; rp += 16, pp += 16) for (; rp < rp_stop; rp += 16, pp += 16)
{ {
uint32x2x4_t vtmp; uint32x2x4_t vtmp;

View File

@ -2,13 +2,13 @@
/* config.h.in. Generated from configure.ac by autoheader. */ /* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <dlfcn.h> header file. */ /* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 0 #define HAVE_DLFCN_H 1
/* Define to 1 if you have the `feenableexcept' function. */ /* Define to 1 if you have the `feenableexcept' function. */
#define HAVE_FEENABLEEXCEPT 1 #define HAVE_FEENABLEEXCEPT 1
/* Define to 1 if you have the <inttypes.h> header file. */ /* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 0 #define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `m' library (-lm). */ /* Define to 1 if you have the `m' library (-lm). */
#define HAVE_LIBM 1 #define HAVE_LIBM 1
@ -17,7 +17,7 @@
#define HAVE_LIBZ 1 #define HAVE_LIBZ 1
/* Define to 1 if you have the <memory.h> header file. */ /* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 0 #define HAVE_MEMORY_H 1
/* Define to 1 if you have the `memset' function. */ /* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1 #define HAVE_MEMSET 1
@ -59,7 +59,7 @@
#define PACKAGE_NAME "libpng" #define PACKAGE_NAME "libpng"
/* Define to the full name and version of this package. */ /* Define to the full name and version of this package. */
#define PACKAGE_STRING "libpng 1.6.18" #define PACKAGE_STRING "libpng 1.6.32"
/* Define to the one symbol short name of this package. */ /* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "libpng" #define PACKAGE_TARNAME "libpng"
@ -68,7 +68,7 @@
#define PACKAGE_URL "" #define PACKAGE_URL ""
/* Define to the version of this package. */ /* Define to the version of this package. */
#define PACKAGE_VERSION "1.6.18" #define PACKAGE_VERSION "1.6.32"
/* Turn on ARM Neon optimizations at run-time */ /* Turn on ARM Neon optimizations at run-time */
/* #undef PNG_ARM_NEON_API_SUPPORTED */ /* #undef PNG_ARM_NEON_API_SUPPORTED */
@ -77,7 +77,28 @@
/* #undef PNG_ARM_NEON_CHECK_SUPPORTED */ /* #undef PNG_ARM_NEON_CHECK_SUPPORTED */
/* Enable ARM Neon optimizations */ /* Enable ARM Neon optimizations */
/* #undef PNG_ARM_NEON_OPT */ #define PNG_ARM_NEON_OPT 2
/* Enable Intel SSE optimizations */
#define PNG_INTEL_SSE_OPT 0
/* Turn on MIPS MSA optimizations at run-time */
/* #undef PNG_MIPS_MSA_API_SUPPORTED */
/* Check for MIPS MSA support at run-time */
/* #undef PNG_MIPS_MSA_CHECK_SUPPORTED */
/* Enable MIPS MSA optimizations */
/* #undef PNG_MIPS_MSA_OPT */
/* Turn on POWERPC VSX optimizations at run-time */
/* #undef PNG_POWERPC_VSX_API_SUPPORTED */
/* Check for POWERPC VSX support at run-time */
/* #undef PNG_POWERPC_VSX_CHECK_SUPPORTED */
/* Enable POWERPC VSX optimizations */
/* #undef PNG_POWERPC_VSX_OPT */
/* Define to 1 if you have the ANSI C header files. */ /* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1 #define STDC_HEADERS 1
@ -86,7 +107,7 @@
/* #undef TM_IN_SYS_TIME */ /* #undef TM_IN_SYS_TIME */
/* Version number of package */ /* Version number of package */
#define VERSION "1.6.18" #define VERSION "1.6.32"
/* Define to empty if `const' does not conform to ANSI C. */ /* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */ /* #undef const */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,9 @@
/* pngconf.h - machine configurable file for libpng /* pngconf.h - machine configurable file for libpng
* *
* libpng version 1.6.18, July 23, 2015 * libpng version 1.6.32, August 24, 2017
* *
* Copyright (c) 1998-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.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@ -63,7 +63,7 @@
*/ */
#define PNG_CONST const /* backward compatibility only */ #define PNG_CONST const /* backward compatibility only */
/* This controls optimization of the reading of 16 and 32 bit values /* This controls optimization of the reading of 16-bit and 32-bit values
* from PNG files. It can be set on a per-app-file basis - it * from PNG files. It can be set on a per-app-file basis - it
* just changes whether a macro is used when the function is called. * just changes whether a macro is used when the function is called.
* The library builder sets the default; if read functions are not * The library builder sets the default; if read functions are not
@ -188,27 +188,27 @@
* compatible with GCC or Visual C because of different calling conventions. * compatible with GCC or Visual C because of different calling conventions.
*/ */
# if PNG_API_RULE == 2 # if PNG_API_RULE == 2
/* If this line results in an error, either because __watcall is not /* If this line results in an error, either because __watcall is not
* understood or because of a redefine just below you cannot use *this* * 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 of the library with the compiler you are using. *This* build was
* build using Watcom and applications must also be built using Watcom! * build using Watcom and applications must also be built using Watcom!
*/ */
# define PNGCAPI __watcall # define PNGCAPI __watcall
# endif # endif
# if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800)) # if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800))
# define PNGCAPI __cdecl # define PNGCAPI __cdecl
# if PNG_API_RULE == 1 # if PNG_API_RULE == 1
/* If this line results in an error __stdcall is not understood and /* If this line results in an error __stdcall is not understood and
* PNG_API_RULE should not have been set to '1'. * PNG_API_RULE should not have been set to '1'.
*/ */
# define PNGAPI __stdcall # define PNGAPI __stdcall
# endif # endif
# else # else
/* An older compiler, or one not detected (erroneously) above, /* An older compiler, or one not detected (erroneously) above,
* if necessary override on the command line to get the correct * if necessary override on the command line to get the correct
* variants for the compiler. * variants for the compiler.
*/ */
# ifndef PNGCAPI # ifndef PNGCAPI
# define PNGCAPI _cdecl # define PNGCAPI _cdecl
# endif # endif
@ -225,10 +225,10 @@
# if (defined(_MSC_VER) && _MSC_VER < 800) ||\ # if (defined(_MSC_VER) && _MSC_VER < 800) ||\
(defined(__BORLANDC__) && __BORLANDC__ < 0x500) (defined(__BORLANDC__) && __BORLANDC__ < 0x500)
/* older Borland and MSC /* older Borland and MSC
* compilers used '__export' and required this to be after * compilers used '__export' and required this to be after
* the type. * the type.
*/ */
# ifndef PNG_EXPORT_TYPE # ifndef PNG_EXPORT_TYPE
# define PNG_EXPORT_TYPE(type) type PNG_IMPEXP # define PNG_EXPORT_TYPE(type) type PNG_IMPEXP
# endif # endif
@ -244,9 +244,9 @@
# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__) # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
# define PNGAPI _System # define PNGAPI _System
# else /* !Windows/x86 && !OS/2 */ # else /* !Windows/x86 && !OS/2 */
/* Use the defaults, or define PNG*API on the command line (but /* Use the defaults, or define PNG*API on the command line (but
* this will have to be done for every compile!) * this will have to be done for every compile!)
*/ */
# endif /* other system, !OS/2 */ # endif /* other system, !OS/2 */
#endif /* !Windows/x86 */ #endif /* !Windows/x86 */
@ -267,7 +267,7 @@
*/ */
#ifndef PNG_IMPEXP #ifndef PNG_IMPEXP
# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT) # 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 # define PNG_IMPEXP PNG_DLL_IMPORT
# endif # endif
@ -340,7 +340,7 @@
* less efficient code. * less efficient code.
*/ */
# if defined(__clang__) && defined(__has_attribute) # 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__) # if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__)
# define PNG_USE_RESULT __attribute__((__warn_unused_result__)) # define PNG_USE_RESULT __attribute__((__warn_unused_result__))
# endif # endif
@ -480,7 +480,7 @@
#if CHAR_BIT == 8 && UCHAR_MAX == 255 #if CHAR_BIT == 8 && UCHAR_MAX == 255
typedef unsigned char png_byte; typedef unsigned char png_byte;
#else #else
# error "libpng requires 8 bit bytes" # error "libpng requires 8-bit bytes"
#endif #endif
#if INT_MIN == -32768 && INT_MAX == 32767 #if INT_MIN == -32768 && INT_MAX == 32767
@ -488,7 +488,7 @@
#elif SHRT_MIN == -32768 && SHRT_MAX == 32767 #elif SHRT_MIN == -32768 && SHRT_MAX == 32767
typedef short png_int_16; typedef short png_int_16;
#else #else
# error "libpng requires a signed 16 bit type" # error "libpng requires a signed 16-bit type"
#endif #endif
#if UINT_MAX == 65535 #if UINT_MAX == 65535
@ -496,7 +496,7 @@
#elif USHRT_MAX == 65535 #elif USHRT_MAX == 65535
typedef unsigned short png_uint_16; typedef unsigned short png_uint_16;
#else #else
# error "libpng requires an unsigned 16 bit type" # error "libpng requires an unsigned 16-bit type"
#endif #endif
#if INT_MIN < -2147483646 && INT_MAX > 2147483646 #if INT_MIN < -2147483646 && INT_MAX > 2147483646
@ -504,15 +504,15 @@
#elif LONG_MIN < -2147483646 && LONG_MAX > 2147483646 #elif LONG_MIN < -2147483646 && LONG_MAX > 2147483646
typedef long int png_int_32; typedef long int png_int_32;
#else #else
# error "libpng requires a signed 32 bit (or more) type" # error "libpng requires a signed 32-bit (or more) type"
#endif #endif
#if UINT_MAX > 4294967294 #if UINT_MAX > 4294967294U
typedef unsigned int png_uint_32; typedef unsigned int png_uint_32;
#elif ULONG_MAX > 4294967294 #elif ULONG_MAX > 4294967294U
typedef unsigned long int png_uint_32; typedef unsigned long int png_uint_32;
#else #else
# error "libpng requires an unsigned 32 bit (or more) type" # error "libpng requires an unsigned 32-bit (or more) type"
#endif #endif
/* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however, /* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however,

View File

@ -2,7 +2,7 @@
/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c /* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
* *
* Last changed in libpng 1.6.8 [December 19, 2013] * Last changed in libpng 1.6.8 [December 19, 2013]
* Copyright (c) 1998-2013 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2013 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *

View File

@ -1,8 +1,8 @@
/* pngerror.c - stub functions for i/o and memory allocation /* pngerror.c - stub functions for i/o and memory allocation
* *
* Last changed in libpng 1.6.15 [November 20, 2014] * Last changed in libpng 1.6.31 [July 27, 2017]
* Copyright (c) 1998-2014 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (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 #ifdef PNG_WARNINGS_SUPPORTED
static void /* PRIVATE */ static void /* PRIVATE */
png_default_warning PNGARG((png_const_structrp png_ptr, png_default_warning PNGARG((png_const_structrp png_ptr,
png_const_charp warning_message)); png_const_charp warning_message));
#endif /* WARNINGS */ #endif /* WARNINGS */
/* This function is called whenever there is a fatal error. This function /* This function is called whenever there is a fatal error. This function
@ -37,14 +37,14 @@ png_default_warning PNGARG((png_const_structrp png_ptr,
#ifdef PNG_ERROR_TEXT_SUPPORTED #ifdef PNG_ERROR_TEXT_SUPPORTED
PNG_FUNCTION(void,PNGAPI PNG_FUNCTION(void,PNGAPI
png_error,(png_const_structrp png_ptr, png_const_charp error_message), png_error,(png_const_structrp png_ptr, png_const_charp error_message),
PNG_NORETURN) PNG_NORETURN)
{ {
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
char msg[16]; char msg[16];
if (png_ptr != NULL) if (png_ptr != NULL)
{ {
if ((png_ptr->flags & if ((png_ptr->flags &
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)
{ {
if (*error_message == PNG_LITERAL_SHARP) if (*error_message == PNG_LITERAL_SHARP)
{ {
@ -65,18 +65,18 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
else else
error_message += offset; error_message += offset;
}
else
{
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
{
msg[0] = '0';
msg[1] = '\0';
error_message = msg;
} }
}
} else
{
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
{
msg[0] = '0';
msg[1] = '\0';
error_message = msg;
}
}
}
} }
#endif #endif
if (png_ptr != NULL && png_ptr->error_fn != NULL) if (png_ptr != NULL && png_ptr->error_fn != NULL)
@ -110,7 +110,7 @@ png_err,(png_const_structrp png_ptr),PNG_NORETURN)
*/ */
size_t size_t
png_safecat(png_charp buffer, size_t bufsize, size_t pos, png_safecat(png_charp buffer, size_t bufsize, size_t pos,
png_const_charp string) png_const_charp string)
{ {
if (buffer != NULL && pos < bufsize) if (buffer != NULL && pos < bufsize)
{ {
@ -131,7 +131,7 @@ png_safecat(png_charp buffer, size_t bufsize, size_t pos,
*/ */
png_charp png_charp
png_format_number(png_const_charp start, png_charp end, int format, 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 count = 0; /* number of digits output */
int mincount = 1; /* minimum number required */ 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: case PNG_NUMBER_FORMAT_02u:
/* Expects at least 2 digits. */ /* Expects at least 2 digits. */
mincount = 2; mincount = 2;
/* FALL THROUGH */ /* FALLTHROUGH */
case PNG_NUMBER_FORMAT_u: case PNG_NUMBER_FORMAT_u:
*--end = digits[number % 10]; *--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: case PNG_NUMBER_FORMAT_02x:
/* This format expects at least two digits */ /* This format expects at least two digits */
mincount = 2; mincount = 2;
/* FALL THROUGH */ /* FALLTHROUGH */
case PNG_NUMBER_FORMAT_x: case PNG_NUMBER_FORMAT_x:
*--end = digits[number & 0xf]; *--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) if (png_ptr != NULL && png_ptr->warning_fn != NULL)
(*(png_ptr->warning_fn))(png_constcast(png_structrp,png_ptr), (*(png_ptr->warning_fn))(png_constcast(png_structrp,png_ptr),
warning_message + offset); warning_message + offset);
else else
png_default_warning(png_ptr, warning_message + offset); 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 void
png_warning_parameter(png_warning_parameters p, int number, 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) if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT)
(void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string); (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 void
png_warning_parameter_unsigned(png_warning_parameters p, int number, int format, 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]; char buffer[PNG_NUMBER_BUFFER_SIZE];
png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value)); 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 void
png_warning_parameter_signed(png_warning_parameters p, int number, int format, 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_alloc_size_t u;
png_charp str; png_charp str;
@ -282,7 +282,7 @@ png_warning_parameter_signed(png_warning_parameters p, int number, int format,
void void
png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p, 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, /* The internal buffer is just 192 bytes - enough for all our messages,
* overflow doesn't happen because this code checks! If someone figures * 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 */ void /* PRIVATE */
png_app_warning(png_const_structrp png_ptr, png_const_charp error_message) png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
{ {
if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0) if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)
png_warning(png_ptr, error_message); png_warning(png_ptr, error_message);
else else
png_error(png_ptr, error_message); png_error(png_ptr, error_message);
# ifndef PNG_ERROR_TEXT_SUPPORTED # ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message) PNG_UNUSED(error_message)
@ -404,10 +404,10 @@ png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
void /* PRIVATE */ void /* PRIVATE */
png_app_error(png_const_structrp png_ptr, png_const_charp error_message) png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
{ {
if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0) if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0)
png_warning(png_ptr, error_message); png_warning(png_ptr, error_message);
else else
png_error(png_ptr, error_message); png_error(png_ptr, error_message);
# ifndef PNG_ERROR_TEXT_SUPPORTED # ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message) 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) #if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
PNG_FUNCTION(void,PNGAPI PNG_FUNCTION(void,PNGAPI
png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message), png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message),
PNG_NORETURN) PNG_NORETURN)
{ {
char msg[18+PNG_MAX_ERROR_TEXT]; char msg[18+PNG_MAX_ERROR_TEXT];
if (png_ptr == NULL) 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 "fixed point overflow in "
# define fixed_message_ln ((sizeof fixed_message)-1) # define fixed_message_ln ((sizeof fixed_message)-1)
int iin; unsigned int iin;
char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT]; char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
memcpy(msg, fixed_message, fixed_message_ln); memcpy(msg, fixed_message, fixed_message_ln);
iin = 0; iin = 0;
@ -620,7 +620,7 @@ png_set_longjmp_fn(png_structrp png_ptr, png_longjmp_ptr longjmp_fn,
else else
{ {
png_ptr->jmp_buf_ptr = png_voidcast(jmp_buf *, 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) if (png_ptr->jmp_buf_ptr == NULL)
return NULL; /* new NULL return on OOM */ return NULL; /* new NULL return on OOM */
@ -709,7 +709,7 @@ png_free_jmpbuf(png_structrp png_ptr)
*/ */
static PNG_FUNCTION(void /* PRIVATE */, static PNG_FUNCTION(void /* PRIVATE */,
png_default_error,(png_const_structrp png_ptr, png_const_charp error_message), png_default_error,(png_const_structrp png_ptr, png_const_charp error_message),
PNG_NORETURN) PNG_NORETURN)
{ {
#ifdef PNG_CONSOLE_IO_SUPPORTED #ifdef PNG_CONSOLE_IO_SUPPORTED
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
@ -768,7 +768,7 @@ png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN)
/* If control reaches this point, png_longjmp() must not return. The only /* If control reaches this point, png_longjmp() must not return. The only
* choice is to terminate the whole process (or maybe the thread); to do * choice is to terminate the whole process (or maybe the thread); to do
* this the ANSI-C abort() function is used unless a different method is * this the ANSI-C abort() function is used unless a different method is
* implemented by overriding the default configuration setting for * implemented by overriding the default configuration setting for
* PNG_ABORT(). * PNG_ABORT().
*/ */
@ -883,7 +883,7 @@ png_set_strip_error_numbers(png_structrp png_ptr, png_uint_32 strip_mode)
*/ */
PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI
png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message), 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; const png_const_structrp png_ptr = png_nonconst_ptr;
png_imagep image = png_voidcast(png_imagep, png_ptr->error_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: */ /* Missing longjmp buffer, the following is to help debugging: */
{ {
size_t pos = png_safecat(image->message, (sizeof image->message), 0, size_t pos = png_safecat(image->message, (sizeof image->message), 0,
"bad longjmp: "); "bad longjmp: ");
png_safecat(image->message, (sizeof image->message), pos, png_safecat(image->message, (sizeof image->message), pos,
error_message); error_message);
} }

View File

@ -1,8 +1,8 @@
/* pngget.c - retrieval of values from info struct /* pngget.c - retrieval of values from info struct
* *
* Last changed in libpng 1.6.17 [March 26, 2015] * Last changed in libpng 1.6.32 [August 24, 2017]
* Copyright (c) 1998-2015 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (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; png_fixed_point result;
if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127, if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
5000) != 0) 5000) != 0)
return result; return (png_uint_32)result;
/* Overflow. */ /* Overflow. */
return 0; return 0;
@ -456,11 +456,11 @@ png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
return (retval); return (retval);
} }
#endif /* pHYs */ #endif /* pHYs */
#endif /* INCH_CONVERSIONS */ #endif /* INCH_CONVERSIONS */
/* png_get_channels really belongs in here, too, but it's been around longer */ /* png_get_channels really belongs in here, too, but it's been around longer */
#endif /* EASY_ACCESS */ #endif /* EASY_ACCESS */
png_byte PNGAPI png_byte PNGAPI
@ -486,7 +486,7 @@ png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
#ifdef PNG_bKGD_SUPPORTED #ifdef PNG_bKGD_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr, 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 && if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_bKGD) != 0 && (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) if (white_x != NULL)
*white_x = png_float(png_ptr, *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) if (white_y != NULL)
*white_y = png_float(png_ptr, *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) if (red_x != NULL)
*red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx, *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
"cHRM red X"); "cHRM red X");
if (red_y != NULL) if (red_y != NULL)
*red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy, *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
"cHRM red Y"); "cHRM red Y");
if (green_x != NULL) if (green_x != NULL)
*green_x = png_float(png_ptr, *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) if (green_y != NULL)
*green_y = png_float(png_ptr, *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) if (blue_x != NULL)
*blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex, *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
"cHRM blue X"); "cHRM blue X");
if (blue_y != NULL) if (blue_y != NULL)
*blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey, *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
"cHRM blue Y"); "cHRM blue Y");
return (PNG_INFO_cHRM); 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_uint_32 PNGAPI
png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr, 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 *red_X, double *red_Y, double *red_Z, double *green_X,
double *green_Y, double *green_Z, double *blue_X, double *blue_Y, double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
double *blue_Z) double *blue_Z)
{ {
if (png_ptr != NULL && info_ptr != NULL && 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)"); png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
if (red_X != NULL) if (red_X != NULL)
*red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X, *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
"cHRM red X"); "cHRM red X");
if (red_Y != NULL) if (red_Y != NULL)
*red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y, *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
"cHRM red Y"); "cHRM red Y");
if (red_Z != NULL) if (red_Z != NULL)
*red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z, *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
"cHRM red Z"); "cHRM red Z");
if (green_X != NULL) if (green_X != NULL)
*green_X = png_float(png_ptr, *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) if (green_Y != NULL)
*green_Y = png_float(png_ptr, *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) if (green_Z != NULL)
*green_Z = png_float(png_ptr, *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) if (blue_X != NULL)
*blue_X = png_float(png_ptr, *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) if (blue_Y != NULL)
*blue_Y = png_float(png_ptr, *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) if (blue_Z != NULL)
*blue_Z = png_float(png_ptr, *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); 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"); png_debug1(1, "in %s retrieval function", "gAMA");
if (png_ptr != NULL && info_ptr != NULL && if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 && (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
file_gamma != NULL) file_gamma != NULL)
{ {
*file_gamma = info_ptr->colorspace.gamma; *file_gamma = info_ptr->colorspace.gamma;
return (PNG_INFO_gAMA); 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 != NULL)
{ {
*file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma, *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
"png_get_gAMA"); "png_get_gAMA");
return (PNG_INFO_gAMA); return (PNG_INFO_gAMA);
} }
@ -773,6 +773,35 @@ png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
} }
#endif #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 #ifdef PNG_hIST_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr, 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"); *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
*height = png_fixed(png_ptr, atof(info_ptr->scal_s_height), *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
"sCAL height"); "sCAL height");
return (PNG_INFO_sCAL); return (PNG_INFO_sCAL);
} }
@ -1142,19 +1171,19 @@ png_get_compression_buffer_size(png_const_structrp png_ptr)
return 0; return 0;
#ifdef PNG_WRITE_SUPPORTED #ifdef PNG_WRITE_SUPPORTED
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
#endif #endif
{ {
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
return png_ptr->IDAT_read_size; return png_ptr->IDAT_read_size;
#else #else
return PNG_IDAT_READ_SIZE; return PNG_IDAT_READ_SIZE;
#endif #endif
} }
#ifdef PNG_WRITE_SUPPORTED #ifdef PNG_WRITE_SUPPORTED
else else
return png_ptr->zbuffer_size; return png_ptr->zbuffer_size;
#endif #endif
} }

View File

@ -2,7 +2,7 @@
/* pnginfo.h - header file for PNG reference library /* pnginfo.h - header file for PNG reference library
* *
* Last changed in libpng 1.6.1 [March 28, 2013] * Last changed in libpng 1.6.1 [March 28, 2013]
* Copyright (c) 1998-2013 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2013 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@ -185,6 +185,14 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */ png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
#endif #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 #ifdef PNG_hIST_SUPPORTED
/* The hIST chunk contains the relative frequency or importance of the /* The hIST chunk contains the relative frequency or importance of the
* various palette entries, so that a viewer can intelligently select a * various palette entries, so that a viewer can intelligently select a
@ -223,7 +231,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
/* Storage for unknown chunks that the library doesn't recognize. */ /* Storage for unknown chunks that the library doesn't recognize. */
png_unknown_chunkp unknown_chunks; png_unknown_chunkp unknown_chunks;
/* The type of this field is limited by the type of /* The type of this field is limited by the type of
* png_struct::user_chunk_cache_max, else overflow can occur. * png_struct::user_chunk_cache_max, else overflow can occur.
*/ */
int unknown_chunks_num; int unknown_chunks_num;

View File

@ -1,10 +1,8 @@
/* libpng 1.6.18 STANDARD API DEFINITION */
/* pnglibconf.h - library build configuration */ /* pnglibconf.h - library build configuration */
/* Libpng version 1.6.18 - July 23, 2015 */ /* libpng version 1.6.32, August 24, 2017 */
/* Copyright (c) 1998-2014 Glenn Randers-Pehrson */ /* Copyright (c) 1998-2017 Glenn Randers-Pehrson */
/* This code is released under the libpng license. */ /* This code is released under the libpng license. */
/* For conditions of distribution and use, see the disclaimer */ /* For conditions of distribution and use, see the disclaimer */
@ -44,6 +42,8 @@
#define PNG_IO_STATE_SUPPORTED #define PNG_IO_STATE_SUPPORTED
#define PNG_MNG_FEATURES_SUPPORTED #define PNG_MNG_FEATURES_SUPPORTED
#define PNG_POINTER_INDEXING_SUPPORTED #define PNG_POINTER_INDEXING_SUPPORTED
/*#undef PNG_POWERPC_VSX_API_SUPPORTED*/
/*#undef PNG_POWERPC_VSX_CHECK_SUPPORTED*/
#define PNG_PROGRESSIVE_READ_SUPPORTED #define PNG_PROGRESSIVE_READ_SUPPORTED
#define PNG_READ_16BIT_SUPPORTED #define PNG_READ_16BIT_SUPPORTED
#define PNG_READ_ALPHA_MODE_SUPPORTED #define PNG_READ_ALPHA_MODE_SUPPORTED
@ -82,6 +82,7 @@
#define PNG_READ_USER_TRANSFORM_SUPPORTED #define PNG_READ_USER_TRANSFORM_SUPPORTED
#define PNG_READ_bKGD_SUPPORTED #define PNG_READ_bKGD_SUPPORTED
#define PNG_READ_cHRM_SUPPORTED #define PNG_READ_cHRM_SUPPORTED
#define PNG_READ_eXIf_SUPPORTED
#define PNG_READ_gAMA_SUPPORTED #define PNG_READ_gAMA_SUPPORTED
#define PNG_READ_hIST_SUPPORTED #define PNG_READ_hIST_SUPPORTED
#define PNG_READ_iCCP_SUPPORTED #define PNG_READ_iCCP_SUPPORTED
@ -109,6 +110,7 @@
#define PNG_SIMPLIFIED_READ_SUPPORTED #define PNG_SIMPLIFIED_READ_SUPPORTED
#define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED #define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
#define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED #define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
#define PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
#define PNG_SIMPLIFIED_WRITE_SUPPORTED #define PNG_SIMPLIFIED_WRITE_SUPPORTED
#define PNG_STDIO_SUPPORTED #define PNG_STDIO_SUPPORTED
#define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED #define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
@ -150,6 +152,7 @@
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED #define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
#define PNG_WRITE_bKGD_SUPPORTED #define PNG_WRITE_bKGD_SUPPORTED
#define PNG_WRITE_cHRM_SUPPORTED #define PNG_WRITE_cHRM_SUPPORTED
#define PNG_WRITE_eXIf_SUPPORTED
#define PNG_WRITE_gAMA_SUPPORTED #define PNG_WRITE_gAMA_SUPPORTED
#define PNG_WRITE_hIST_SUPPORTED #define PNG_WRITE_hIST_SUPPORTED
#define PNG_WRITE_iCCP_SUPPORTED #define PNG_WRITE_iCCP_SUPPORTED
@ -167,6 +170,7 @@
#define PNG_WRITE_zTXt_SUPPORTED #define PNG_WRITE_zTXt_SUPPORTED
#define PNG_bKGD_SUPPORTED #define PNG_bKGD_SUPPORTED
#define PNG_cHRM_SUPPORTED #define PNG_cHRM_SUPPORTED
#define PNG_eXIf_SUPPORTED
#define PNG_gAMA_SUPPORTED #define PNG_gAMA_SUPPORTED
#define PNG_hIST_SUPPORTED #define PNG_hIST_SUPPORTED
#define PNG_iCCP_SUPPORTED #define PNG_iCCP_SUPPORTED
@ -185,7 +189,7 @@
/* end of options */ /* end of options */
/* settings */ /* settings */
#define PNG_API_RULE 0 #define PNG_API_RULE 0
#define PNG_COST_SHIFT 3 #define PNG_ARM_NEON_OPT 2
#define PNG_DEFAULT_READ_MACROS 1 #define PNG_DEFAULT_READ_MACROS 1
#define PNG_GAMMA_THRESHOLD_FIXED 5000 #define PNG_GAMMA_THRESHOLD_FIXED 5000
#define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE #define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE
@ -204,9 +208,8 @@
#define PNG_USER_CHUNK_MALLOC_MAX 8000000 #define PNG_USER_CHUNK_MALLOC_MAX 8000000
#define PNG_USER_HEIGHT_MAX 1000000 #define PNG_USER_HEIGHT_MAX 1000000
#define PNG_USER_WIDTH_MAX 1000000 #define PNG_USER_WIDTH_MAX 1000000
#define PNG_WEIGHT_SHIFT 8
#define PNG_ZBUF_SIZE 8192 #define PNG_ZBUF_SIZE 8192
#define PNG_ZLIB_VERNUM 0 /* unknown */ #define PNG_ZLIB_VERNUM 0x12b0
#define PNG_Z_DEFAULT_COMPRESSION (-1) #define PNG_Z_DEFAULT_COMPRESSION (-1)
#define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0 #define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0
#define PNG_Z_DEFAULT_STRATEGY 1 #define PNG_Z_DEFAULT_STRATEGY 1

View File

@ -1,8 +1,8 @@
/* pngmem.c - stub functions for memory allocation /* pngmem.c - stub functions for memory allocation
* *
* Last changed in libpng 1.6.15 [November 20, 2014] * Last changed in libpng 1.6.26 [October 20, 2016]
* Copyright (c) 1998-2014 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@ -66,7 +66,7 @@ png_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
*/ */
PNG_FUNCTION(png_voidp /* PRIVATE */, PNG_FUNCTION(png_voidp /* PRIVATE */,
png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size), 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 /* 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 * allocators have also been removed in 1.6.0, so any 16-bit system now has
@ -107,9 +107,9 @@ png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
*/ */
static png_voidp static png_voidp
png_malloc_array_checked(png_const_structrp png_ptr, int nelements, 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) if (req <= PNG_SIZE_MAX/element_size)
return png_malloc_base(png_ptr, req * element_size); return png_malloc_base(png_ptr, req * element_size);
@ -120,7 +120,7 @@ png_malloc_array_checked(png_const_structrp png_ptr, int nelements,
PNG_FUNCTION(png_voidp /* PRIVATE */, PNG_FUNCTION(png_voidp /* PRIVATE */,
png_malloc_array,(png_const_structrp png_ptr, int nelements, 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) if (nelements <= 0 || element_size == 0)
png_error(png_ptr, "internal error: array alloc"); png_error(png_ptr, "internal error: array alloc");
@ -130,7 +130,7 @@ png_malloc_array,(png_const_structrp png_ptr, int nelements,
PNG_FUNCTION(png_voidp /* PRIVATE */, PNG_FUNCTION(png_voidp /* PRIVATE */,
png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array, 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: */ /* These are internal errors: */
if (add_elements <= 0 || element_size == 0 || old_elements < 0 || if (add_elements <= 0 || element_size == 0 || old_elements < 0 ||
@ -143,7 +143,7 @@ png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
if (add_elements <= INT_MAX - old_elements) if (add_elements <= INT_MAX - old_elements)
{ {
png_voidp new_array = png_malloc_array_checked(png_ptr, 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) if (new_array != NULL)
{ {
@ -154,7 +154,7 @@ png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
memcpy(new_array, old_array, element_size*(unsigned)old_elements); memcpy(new_array, old_array, element_size*(unsigned)old_elements);
memset((char*)new_array + element_size*(unsigned)old_elements, 0, memset((char*)new_array + element_size*(unsigned)old_elements, 0,
element_size*(unsigned)add_elements); element_size*(unsigned)add_elements);
return new_array; return new_array;
} }
@ -187,7 +187,7 @@ png_malloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
PNG_FUNCTION(png_voidp,PNGAPI PNG_FUNCTION(png_voidp,PNGAPI
png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size), png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size),
PNG_ALLOCATED PNG_DEPRECATED) PNG_ALLOCATED PNG_DEPRECATED)
{ {
png_voidp ret; png_voidp ret;
@ -210,7 +210,7 @@ png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size),
*/ */
PNG_FUNCTION(png_voidp,PNGAPI PNG_FUNCTION(png_voidp,PNGAPI
png_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size), png_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size),
PNG_ALLOCATED) PNG_ALLOCATED)
{ {
if (png_ptr != NULL) if (png_ptr != NULL)
{ {

View File

@ -1,8 +1,8 @@
/* pngpread.c - read a png file in push mode /* pngpread.c - read a png file in push mode
* *
* Last changed in libpng 1.6.18 [July 23, 2015] * Last changed in libpng 1.6.32 [August 24, 2017]
* Copyright (c) 1998-2015 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (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_uint_32 PNGAPI
png_process_data_skip(png_structrp png_ptr) png_process_data_skip(png_structrp png_ptr)
{ {
/* TODO: Deprecate and remove this API. /* TODO: Deprecate and remove this API.
* Somewhere the implementation of this seems to have been lost, * Somewhere the implementation of this seems to have been lost,
* or abandoned. It was only to support some internal back-door access * or abandoned. It was only to support some internal back-door access
* to png_struct) in libpng-1.4.x. * to png_struct) in libpng-1.4.x.
*/ */
png_app_warning(png_ptr, png_app_warning(png_ptr,
"png_process_data_skip is not implemented in any current version of libpng"); "png_process_data_skip is not implemented in any current version of libpng");
return 0; return 0;
@ -133,7 +133,7 @@ png_process_some_data(png_structrp png_ptr, png_inforp info_ptr)
void /* PRIVATE */ void /* PRIVATE */
png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr) png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr)
{ {
png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */ png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */
num_to_check = 8 - num_checked; num_to_check = 8 - num_checked;
if (png_ptr->buffer_size < num_to_check) if (png_ptr->buffer_size < num_to_check)
@ -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_crc_read(png_ptr, chunk_tag, 4);
png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
png_check_chunk_name(png_ptr, png_ptr->chunk_name); 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; png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
} }
@ -210,12 +211,14 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
(png_ptr->mode & PNG_HAVE_PLTE) == 0) (png_ptr->mode & PNG_HAVE_PLTE) == 0)
png_error(png_ptr, "Missing PLTE before IDAT"); png_error(png_ptr, "Missing PLTE before IDAT");
png_ptr->mode |= PNG_HAVE_IDAT;
png_ptr->process_mode = PNG_READ_IDAT_MODE; png_ptr->process_mode = PNG_READ_IDAT_MODE;
if ((png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) == 0) if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
if (png_ptr->push_length == 0) if ((png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) == 0)
return; if (png_ptr->push_length == 0)
return;
png_ptr->mode |= PNG_HAVE_IDAT;
if ((png_ptr->mode & PNG_AFTER_IDAT) != 0) if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)
png_benign_error(png_ptr, "Too many IDATs found"); png_benign_error(png_ptr, "Too many IDATs found");
@ -408,7 +411,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
{ {
PNG_PUSH_SAVE_BUFFER_IF_FULL PNG_PUSH_SAVE_BUFFER_IF_FULL
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, 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; png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
@ -499,7 +502,10 @@ png_push_save_buffer(png_structrp png_ptr)
png_error(png_ptr, "Insufficient memory for save_buffer"); 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_free(png_ptr, old_buffer);
png_ptr->save_buffer_max = new_max; png_ptr->save_buffer_max = new_max;
} }
@ -516,7 +522,7 @@ png_push_save_buffer(png_structrp png_ptr)
void /* PRIVATE */ void /* PRIVATE */
png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer, 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 = buffer;
png_ptr->current_buffer_size = buffer_length; png_ptr->current_buffer_size = buffer_length;
@ -563,7 +569,7 @@ png_push_read_IDAT(png_structrp png_ptr)
* are of different types and we don't know which variable has the fewest * are of different types and we don't know which variable has the fewest
* bits. Carefully select the smaller and cast it to the type of the * bits. Carefully select the smaller and cast it to the type of the
* larger - this cannot overflow. Do not cast in the following test - it * larger - this cannot overflow. Do not cast in the following test - it
* will break on either 16 or 64 bit platforms. * will break on either 16-bit or 64-bit platforms.
*/ */
if (idat_size < save_size) if (idat_size < save_size)
save_size = (png_size_t)idat_size; save_size = (png_size_t)idat_size;
@ -619,7 +625,7 @@ png_push_read_IDAT(png_structrp png_ptr)
void /* PRIVATE */ void /* PRIVATE */
png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer, 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. */ /* The caller checks for a non-zero buffer length. */
if (!(buffer_length > 0) || buffer == NULL) if (!(buffer_length > 0) || buffer == NULL)
@ -662,7 +668,7 @@ png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
* change the current behavior (see comments in inflate.c * change the current behavior (see comments in inflate.c
* for why this doesn't happen at present with zlib 1.2.5). * for why this doesn't happen at present with zlib 1.2.5).
*/ */
ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH); ret = PNG_INFLATE(png_ptr, Z_SYNC_FLUSH);
/* Check for any failure before proceeding. */ /* Check for any failure before proceeding. */
if (ret != Z_OK && ret != Z_STREAM_END) if (ret != Z_OK && ret != Z_STREAM_END)
@ -679,7 +685,12 @@ png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
png_warning(png_ptr, "Truncated compressed data in IDAT"); png_warning(png_ptr, "Truncated compressed data in IDAT");
else 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 */ /* Skip the check on unprocessed input */
return; return;
@ -777,7 +788,7 @@ png_push_process_row(png_structrp png_ptr)
{ {
if (png_ptr->pass < 6) if (png_ptr->pass < 6)
png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,
png_ptr->transformations); png_ptr->transformations);
switch (png_ptr->pass) switch (png_ptr->pass)
{ {
@ -1039,7 +1050,7 @@ png_push_have_row(png_structrp png_ptr, png_bytep row)
{ {
if (png_ptr->row_fn != NULL) if (png_ptr->row_fn != NULL)
(*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number, (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
(int)png_ptr->pass); (int)png_ptr->pass);
} }
#ifdef PNG_READ_INTERLACING_SUPPORTED #ifdef PNG_READ_INTERLACING_SUPPORTED

View File

@ -1,8 +1,8 @@
/* pngpriv.h - private declarations for use inside libpng /* pngpriv.h - private declarations for use inside libpng
* *
* Last changed in libpng 1.6.18 [July 23, 2015] * Last changed in libpng 1.6.32 [August 24, 2017]
* Copyright (c) 1998-2015 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (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 * Windows/Visual Studio) there is no effect; the OS specific tests below are
* still required (as of 2011-05-02.) * 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 #ifndef PNG_VERSION_INFO_ONLY
/* Standard library headers not required by png.h: */ /* Standard library headers not required by png.h: */
@ -182,6 +184,84 @@
# endif # endif
#endif /* PNG_ARM_NEON_OPT > 0 */ #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
* 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
#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 /* 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 * different preprocessor settings to those required for a simple library? If
* so PNG_BUILD_DLL must be set. * so PNG_BUILD_DLL must be set.
@ -374,25 +454,6 @@
# define png_fixed_error(s1,s2) png_err(s1) # define png_fixed_error(s1,s2) png_err(s1)
#endif #endif
/* 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
* const is not cast away.
*/
#ifdef __cplusplus
# define png_voidcast(type, value) static_cast<type>(value)
# define png_constcast(type, value) const_cast<type>(value)
# define png_aligncast(type, value) \
static_cast<type>(static_cast<void*>(value))
# define png_aligncastconst(type, value) \
static_cast<type>(static_cast<const void*>(value))
#else
# define png_voidcast(type, value) (value)
# define png_constcast(type, value) ((type)(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 /* Some fixed point APIs are still required even if not exported because
* they get used by the corresponding floating point APIs. This magic * they get used by the corresponding floating point APIs. This magic
* deals with this: * deals with this:
@ -407,6 +468,35 @@
/* Other defines specific to compilers can go here. Try to keep /* Other defines specific to compilers can go here. Try to keep
* them inside an appropriate ifdef/endif pair for portability. * 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
* const is not cast away.
*/
#ifdef __cplusplus
# define png_voidcast(type, value) static_cast<type>(value)
# define png_constcast(type, value) const_cast<type>(value)
# define png_aligncast(type, value) \
static_cast<type>(static_cast<void*>(value))
# define png_aligncastconst(type, value) \
static_cast<type>(static_cast<const void*>(value))
#else
# define png_voidcast(type, value) (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 */
#if defined(PNG_FLOATING_POINT_SUPPORTED) ||\ #if defined(PNG_FLOATING_POINT_SUPPORTED) ||\
defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
/* png.c requires the following ANSI-C constants if the conversion of /* png.c requires the following ANSI-C constants if the conversion of
@ -420,10 +510,10 @@
# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \ # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC) defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
/* We need to check that <math.h> hasn't already been included earlier /* 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 * as it seems it doesn't agree with <fp.h>, yet we should really use
* <fp.h> if possible. * <fp.h> if possible.
*/ */
# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
# include <fp.h> # include <fp.h>
# endif # endif
@ -431,9 +521,9 @@
# include <math.h> # include <math.h>
# endif # endif
# if defined(_AMIGA) && defined(__SASC) && defined(_M68881) # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
/* Amiga SAS/C: We must include builtin FPU functions when compiling using /* Amiga SAS/C: We must include builtin FPU functions when compiling using
* MATH=68881 * MATH=68881
*/ */
# include <m68881.h> # include <m68881.h>
# endif # endif
#endif #endif
@ -504,7 +594,8 @@
/* This implicitly assumes alignment is always to a power of 2. */ /* This implicitly assumes alignment is always to a power of 2. */
#ifdef png_alignof #ifdef png_alignof
# define png_isaligned(ptr, type)\ # 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 #else
# define png_isaligned(ptr, type) 0 # define png_isaligned(ptr, type) 0
#endif #endif
@ -521,96 +612,92 @@
* are defined in png.h because they need to be visible to applications * are defined in png.h because they need to be visible to applications
* that call png_set_unknown_chunk(). * that call png_set_unknown_chunk().
*/ */
/* #define PNG_HAVE_IHDR 0x01 (defined in png.h) */ /* #define PNG_HAVE_IHDR 0x01U (defined in png.h) */
/* #define PNG_HAVE_PLTE 0x02 (defined in png.h) */ /* #define PNG_HAVE_PLTE 0x02U (defined in png.h) */
#define PNG_HAVE_IDAT 0x04 #define PNG_HAVE_IDAT 0x04U
/* #define PNG_AFTER_IDAT 0x08 (defined in png.h) */ /* #define PNG_AFTER_IDAT 0x08U (defined in png.h) */
#define PNG_HAVE_IEND 0x10 #define PNG_HAVE_IEND 0x10U
/* 0x20 (unused) */ /* 0x20U (unused) */
/* 0x40 (unused) */ /* 0x40U (unused) */
/* 0x80 (unused) */ /* 0x80U (unused) */
#define PNG_HAVE_CHUNK_HEADER 0x100 #define PNG_HAVE_CHUNK_HEADER 0x100U
#define PNG_WROTE_tIME 0x200 #define PNG_WROTE_tIME 0x200U
#define PNG_WROTE_INFO_BEFORE_PLTE 0x400 #define PNG_WROTE_INFO_BEFORE_PLTE 0x400U
#define PNG_BACKGROUND_IS_GRAY 0x800 #define PNG_BACKGROUND_IS_GRAY 0x800U
#define PNG_HAVE_PNG_SIGNATURE 0x1000 #define PNG_HAVE_PNG_SIGNATURE 0x1000U
#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */ #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000U /* Have another chunk after IDAT */
/* 0x4000 (unused) */ /* 0x4000U (unused) */
#define PNG_IS_READ_STRUCT 0x8000 /* Else is a write struct */ #define PNG_IS_READ_STRUCT 0x8000U /* Else is a write struct */
/* Flags for the transformations the PNG library does on the image data */ /* Flags for the transformations the PNG library does on the image data */
#define PNG_BGR 0x0001 #define PNG_BGR 0x0001U
#define PNG_INTERLACE 0x0002 #define PNG_INTERLACE 0x0002U
#define PNG_PACK 0x0004 #define PNG_PACK 0x0004U
#define PNG_SHIFT 0x0008 #define PNG_SHIFT 0x0008U
#define PNG_SWAP_BYTES 0x0010 #define PNG_SWAP_BYTES 0x0010U
#define PNG_INVERT_MONO 0x0020 #define PNG_INVERT_MONO 0x0020U
#define PNG_QUANTIZE 0x0040 #define PNG_QUANTIZE 0x0040U
#define PNG_COMPOSE 0x0080 /* Was PNG_BACKGROUND */ #define PNG_COMPOSE 0x0080U /* Was PNG_BACKGROUND */
#define PNG_BACKGROUND_EXPAND 0x0100 #define PNG_BACKGROUND_EXPAND 0x0100U
#define PNG_EXPAND_16 0x0200 /* Added to libpng 1.5.2 */ #define PNG_EXPAND_16 0x0200U /* Added to libpng 1.5.2 */
#define PNG_16_TO_8 0x0400 /* Becomes 'chop' in 1.5.4 */ #define PNG_16_TO_8 0x0400U /* Becomes 'chop' in 1.5.4 */
#define PNG_RGBA 0x0800 #define PNG_RGBA 0x0800U
#define PNG_EXPAND 0x1000 #define PNG_EXPAND 0x1000U
#define PNG_GAMMA 0x2000 #define PNG_GAMMA 0x2000U
#define PNG_GRAY_TO_RGB 0x4000 #define PNG_GRAY_TO_RGB 0x4000U
#define PNG_FILLER 0x8000 #define PNG_FILLER 0x8000U
#define PNG_PACKSWAP 0x10000 #define PNG_PACKSWAP 0x10000U
#define PNG_SWAP_ALPHA 0x20000 #define PNG_SWAP_ALPHA 0x20000U
#define PNG_STRIP_ALPHA 0x40000 #define PNG_STRIP_ALPHA 0x40000U
#define PNG_INVERT_ALPHA 0x80000 #define PNG_INVERT_ALPHA 0x80000U
#define PNG_USER_TRANSFORM 0x100000 #define PNG_USER_TRANSFORM 0x100000U
#define PNG_RGB_TO_GRAY_ERR 0x200000 #define PNG_RGB_TO_GRAY_ERR 0x200000U
#define PNG_RGB_TO_GRAY_WARN 0x400000 #define PNG_RGB_TO_GRAY_WARN 0x400000U
#define PNG_RGB_TO_GRAY 0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */ #define PNG_RGB_TO_GRAY 0x600000U /* two bits, RGB_TO_GRAY_ERR|WARN */
#define PNG_ENCODE_ALPHA 0x800000 /* Added to libpng-1.5.4 */ #define PNG_ENCODE_ALPHA 0x800000U /* Added to libpng-1.5.4 */
#define PNG_ADD_ALPHA 0x1000000 /* Added to libpng-1.2.7 */ #define PNG_ADD_ALPHA 0x1000000U /* Added to libpng-1.2.7 */
#define PNG_EXPAND_tRNS 0x2000000 /* Added to libpng-1.2.9 */ #define PNG_EXPAND_tRNS 0x2000000U /* Added to libpng-1.2.9 */
#define PNG_SCALE_16_TO_8 0x4000000 /* Added to libpng-1.5.4 */ #define PNG_SCALE_16_TO_8 0x4000000U /* Added to libpng-1.5.4 */
/* 0x8000000 unused */ /* 0x8000000U unused */
/* 0x10000000 unused */ /* 0x10000000U unused */
/* 0x20000000 unused */ /* 0x20000000U unused */
/* 0x40000000 unused */ /* 0x40000000U unused */
/* Flags for png_create_struct */ /* Flags for png_create_struct */
#define PNG_STRUCT_PNG 0x0001 #define PNG_STRUCT_PNG 0x0001U
#define PNG_STRUCT_INFO 0x0002 #define PNG_STRUCT_INFO 0x0002U
/* Scaling factor for filter heuristic weighting calculations */
#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
/* Flags for the png_ptr->flags rather than declaring a byte for each one */ /* Flags for the png_ptr->flags rather than declaring a byte for each one */
#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001 #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001U
#define PNG_FLAG_ZSTREAM_INITIALIZED 0x0002 /* Added to libpng-1.6.0 */ #define PNG_FLAG_ZSTREAM_INITIALIZED 0x0002U /* Added to libpng-1.6.0 */
/* 0x0004 unused */ /* 0x0004U unused */
#define PNG_FLAG_ZSTREAM_ENDED 0x0008 /* Added to libpng-1.6.0 */ #define PNG_FLAG_ZSTREAM_ENDED 0x0008U /* Added to libpng-1.6.0 */
/* 0x0010 unused */ /* 0x0010U unused */
/* 0x0020 unused */ /* 0x0020U unused */
#define PNG_FLAG_ROW_INIT 0x0040 #define PNG_FLAG_ROW_INIT 0x0040U
#define PNG_FLAG_FILLER_AFTER 0x0080 #define PNG_FLAG_FILLER_AFTER 0x0080U
#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100 #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100U
#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200 #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200U
#define PNG_FLAG_CRC_CRITICAL_USE 0x0400 #define PNG_FLAG_CRC_CRITICAL_USE 0x0400U
#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800 #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800U
#define PNG_FLAG_ASSUME_sRGB 0x1000 /* Added to libpng-1.5.4 */ #define PNG_FLAG_ASSUME_sRGB 0x1000U /* Added to libpng-1.5.4 */
#define PNG_FLAG_OPTIMIZE_ALPHA 0x2000 /* Added to libpng-1.5.4 */ #define PNG_FLAG_OPTIMIZE_ALPHA 0x2000U /* Added to libpng-1.5.4 */
#define PNG_FLAG_DETECT_UNINITIALIZED 0x4000 /* Added to libpng-1.5.4 */ #define PNG_FLAG_DETECT_UNINITIALIZED 0x4000U /* Added to libpng-1.5.4 */
/* #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000 */ /* #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000U */
/* #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000 */ /* #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000U */
#define PNG_FLAG_LIBRARY_MISMATCH 0x20000 #define PNG_FLAG_LIBRARY_MISMATCH 0x20000U
#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000 #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000U
#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000 #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000U
#define PNG_FLAG_BENIGN_ERRORS_WARN 0x100000 /* Added to libpng-1.4.0 */ #define PNG_FLAG_BENIGN_ERRORS_WARN 0x100000U /* Added to libpng-1.4.0 */
#define PNG_FLAG_APP_WARNINGS_WARN 0x200000 /* Added to libpng-1.6.0 */ #define PNG_FLAG_APP_WARNINGS_WARN 0x200000U /* Added to libpng-1.6.0 */
#define PNG_FLAG_APP_ERRORS_WARN 0x400000 /* Added to libpng-1.6.0 */ #define PNG_FLAG_APP_ERRORS_WARN 0x400000U /* Added to libpng-1.6.0 */
/* 0x800000 unused */ /* 0x800000U unused */
/* 0x1000000 unused */ /* 0x1000000U unused */
/* 0x2000000 unused */ /* 0x2000000U unused */
/* 0x4000000 unused */ /* 0x4000000U unused */
/* 0x8000000 unused */ /* 0x8000000U unused */
/* 0x10000000 unused */ /* 0x10000000U unused */
/* 0x20000000 unused */ /* 0x20000000U unused */
/* 0x40000000 unused */ /* 0x40000000U unused */
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
PNG_FLAG_CRC_ANCILLARY_NOWARN) PNG_FLAG_CRC_ANCILLARY_NOWARN)
@ -644,6 +731,24 @@
((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \ ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \
(( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 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 /* PNG_OUT_OF_RANGE returns true if value is outside the range
* ideal-delta..ideal+delta. Each argument is evaluated twice. * ideal-delta..ideal+delta. Each argument is evaluated twice.
* "ideal" and "delta" should be constants, normally simple * "ideal" and "delta" should be constants, normally simple
@ -669,7 +774,7 @@
/* The fixed point conversion performs range checking and evaluates /* The fixed point conversion performs range checking and evaluates
* its argument multiple times, so must be used with care. The * its argument multiple times, so must be used with care. The
* range checking uses the PNG specification values for a signed * range checking uses the PNG specification values for a signed
* 32 bit fixed point value except that the values are deliberately * 32-bit fixed point value except that the values are deliberately
* rounded-to-zero to an integral value - 21474 (21474.83 is roughly * rounded-to-zero to an integral value - 21474 (21474.83 is roughly
* (2^31-1) * 100000). 's' is a string that describes the value being * (2^31-1) * 100000). 's' is a string that describes the value being
* converted. * converted.
@ -737,6 +842,7 @@
#define png_PLTE PNG_U32( 80, 76, 84, 69) #define png_PLTE PNG_U32( 80, 76, 84, 69)
#define png_bKGD PNG_U32( 98, 75, 71, 68) #define png_bKGD PNG_U32( 98, 75, 71, 68)
#define png_cHRM PNG_U32( 99, 72, 82, 77) #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_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */
#define png_gAMA PNG_U32(103, 65, 77, 65) #define png_gAMA PNG_U32(103, 65, 77, 65)
#define png_gIFg PNG_U32(103, 73, 70, 103) #define png_gIFg PNG_U32(103, 73, 70, 103)
@ -816,7 +922,7 @@
*/ */
#endif #endif
/* This is used for 16 bit gamma tables -- only the top level pointers are /* This is used for 16-bit gamma tables -- only the top level pointers are
* const; this could be changed: * const; this could be changed:
*/ */
typedef const png_uint_16p * png_const_uint_16pp; typedef const png_uint_16p * png_const_uint_16pp;
@ -1029,7 +1135,7 @@ PNG_INTERNAL_FUNCTION(void,png_write_sBIT,(png_structrp png_ptr,
#ifdef PNG_WRITE_cHRM_SUPPORTED #ifdef PNG_WRITE_cHRM_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_write_cHRM_fixed,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_write_cHRM_fixed,(png_structrp png_ptr,
const png_xy *xy), PNG_EMPTY); const png_xy *xy), PNG_EMPTY);
/* The xy value must have been previously validated */ /* The xy value must have been previously validated */
#endif #endif
#ifdef PNG_WRITE_sRGB_SUPPORTED #ifdef PNG_WRITE_sRGB_SUPPORTED
@ -1037,6 +1143,11 @@ PNG_INTERNAL_FUNCTION(void,png_write_sRGB,(png_structrp png_ptr,
int intent),PNG_EMPTY); int intent),PNG_EMPTY);
#endif #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 #ifdef PNG_WRITE_iCCP_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_write_iCCP,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_write_iCCP,(png_structrp png_ptr,
png_const_charp name, png_const_bytep profile), PNG_EMPTY); png_const_charp name, png_const_bytep profile), PNG_EMPTY);
@ -1178,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 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); 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_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_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_neon,(png_row_infop PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_neon,(png_row_infop
@ -1192,6 +1304,56 @@ 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); 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 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); 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
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);
#endif
/* Choose the best filter to use and filter the row data */ /* Choose the best filter to use and filter the row data */
PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr,
@ -1219,6 +1381,14 @@ PNG_INTERNAL_FUNCTION(void,png_read_finish_row,(png_structrp png_ptr),
/* Initialize the row buffers, etc. */ /* Initialize the row buffers, etc. */
PNG_INTERNAL_FUNCTION(void,png_read_start_row,(png_structrp png_ptr),PNG_EMPTY); PNG_INTERNAL_FUNCTION(void,png_read_start_row,(png_structrp png_ptr),PNG_EMPTY);
#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)
#else /* Zlib < 1.2.4 */
# define PNG_INFLATE(pp, flush) inflate(&(pp)->zstream, flush)
#endif /* Zlib < 1.2.4 */
#ifdef PNG_READ_TRANSFORMS_SUPPORTED #ifdef PNG_READ_TRANSFORMS_SUPPORTED
/* Optional call to update the users info structure */ /* Optional call to update the users info structure */
PNG_INTERNAL_FUNCTION(void,png_read_transform_info,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_read_transform_info,(png_structrp png_ptr,
@ -1277,6 +1447,11 @@ PNG_INTERNAL_FUNCTION(void,png_handle_cHRM,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
#endif #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 #ifdef PNG_READ_gAMA_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_gAMA,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_handle_gAMA,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
@ -1352,8 +1527,11 @@ PNG_INTERNAL_FUNCTION(void,png_handle_zTXt,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
#endif #endif
PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_const_structrp png_ptr,
png_uint_32 chunk_name),PNG_EMPTY); 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_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY); png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY);
@ -1409,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_INTERNAL_FUNCTION(void,png_push_have_end,(png_structrp png_ptr,
png_inforp info_ptr),PNG_EMPTY); png_inforp info_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_have_row,(png_structrp png_ptr, 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_INTERNAL_FUNCTION(void,png_push_read_end,(png_structrp png_ptr,
png_inforp info_ptr),PNG_EMPTY); png_inforp info_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_process_some_data,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_process_some_data,(png_structrp png_ptr,
@ -1448,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_INTERNAL_FUNCTION(void,png_colorspace_sync_info,(png_const_structrp png_ptr,
png_inforp info_ptr), PNG_EMPTY); 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_INTERNAL_FUNCTION(void,png_colorspace_sync,(png_const_structrp png_ptr,
png_inforp info_ptr), PNG_EMPTY); png_inforp info_ptr), PNG_EMPTY);
/* Copy the png_struct colorspace to the info_struct and call the above to /* 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. * synchronize the flags. Checks for NULL info_ptr and does nothing.
*/ */
#endif #endif
/* Added at libpng version 1.4.0 */ /* Added at libpng version 1.4.0 */
@ -1488,9 +1666,11 @@ PNG_INTERNAL_FUNCTION(int,png_colorspace_set_ICC,(png_const_structrp png_ptr,
/* The 'name' is used for information only */ /* The 'name' is used for information only */
/* Routines for checking parts of an ICC profile. */ /* 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_INTERNAL_FUNCTION(int,png_icc_check_length,(png_const_structrp png_ptr,
png_colorspacerp colorspace, png_const_charp name, png_colorspacerp colorspace, png_const_charp name,
png_uint_32 profile_length), PNG_EMPTY); png_uint_32 profile_length), PNG_EMPTY);
#endif /* READ_iCCP */
PNG_INTERNAL_FUNCTION(int,png_icc_check_header,(png_const_structrp png_ptr, PNG_INTERNAL_FUNCTION(int,png_icc_check_header,(png_const_structrp png_ptr,
png_colorspacerp colorspace, png_const_charp name, png_colorspacerp colorspace, png_const_charp name,
png_uint_32 profile_length, png_uint_32 profile_length,
@ -1909,10 +2089,25 @@ PNG_INTERNAL_FUNCTION(void, PNG_FILTER_OPTIMIZATIONS, (png_structp png_ptr,
* the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in * the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in
* CFLAGS in place of CPPFLAGS *and* uses symbol prefixing. * 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_INTERNAL_FUNCTION(void, png_init_filter_functions_neon,
(png_structp png_ptr, unsigned int bpp), PNG_EMPTY); (png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
#endif #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);
/* Maintainer: Put new private prototypes here ^ */ /* Maintainer: Put new private prototypes here ^ */
#include "pngdebug.h" #include "pngdebug.h"

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
/* pngrio.c - functions for data input /* pngrio.c - functions for data input
* *
* Last changed in libpng 1.6.17 [March 26, 2015] * Last changed in libpng 1.6.24 [August 4, 2016]
* Copyright (c) 1998-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.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@ -26,7 +26,7 @@
* reads from a file pointer. Note that this routine sometimes gets called * reads from a file pointer. Note that this routine sometimes gets called
* with very small lengths, so you should implement some kind of simple * with very small lengths, so you should implement some kind of simple
* buffering if you are using unbuffered reads. This should never be asked * buffering if you are using unbuffered reads. This should never be asked
* to read more than 64K on a 16 bit machine. * to read more than 64K on a 16-bit machine.
*/ */
void /* PRIVATE */ void /* PRIVATE */
png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length) png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length)
@ -85,7 +85,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
*/ */
void PNGAPI void PNGAPI
png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr, 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) if (png_ptr == NULL)
return; return;

View File

@ -1,8 +1,8 @@
/* pngrtran.c - transforms the data in a row for PNG readers /* pngrtran.c - transforms the data in a row for PNG readers
* *
* Last changed in libpng 1.6.18 [July 23, 2015] * Last changed in libpng 1.6.31 [July 27, 2017]
* Copyright (c) 1998-2015 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@ -48,7 +48,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 */ case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */
png_warning(png_ptr, 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_ERROR_QUIT: /* Error/quit */
case PNG_CRC_DEFAULT: case PNG_CRC_DEFAULT:
@ -101,7 +102,7 @@ png_rtran_ok(png_structrp png_ptr, int need_IHDR)
{ {
if ((png_ptr->flags & PNG_FLAG_ROW_INIT) != 0) if ((png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)
png_app_error(png_ptr, 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) else if (need_IHDR && (png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_app_error(png_ptr, "invalid before the PNG header has been read"); png_app_error(png_ptr, "invalid before the PNG header has been read");
@ -159,7 +160,7 @@ png_set_background(png_structrp png_ptr,
png_set_background_fixed(png_ptr, background_color, background_gamma_code, png_set_background_fixed(png_ptr, background_color, background_gamma_code,
need_expand, png_fixed(png_ptr, background_gamma, "png_set_background")); need_expand, png_fixed(png_ptr, background_gamma, "png_set_background"));
} }
# endif /* FLOATING_POINT */ # endif /* FLOATING_POINT */
#endif /* READ_BACKGROUND */ #endif /* READ_BACKGROUND */
/* Scale 16-bit depth files to 8-bit depth. If both of these are set then the /* Scale 16-bit depth files to 8-bit depth. If both of these are set then the
@ -209,7 +210,7 @@ png_set_strip_alpha(png_structrp png_ptr)
#if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED) #if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
static png_fixed_point static png_fixed_point
translate_gamma_flags(png_structrp png_ptr, png_fixed_point output_gamma, 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 /* 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 * flag is that it is pretty near impossible to work out what the correct
@ -273,7 +274,7 @@ convert_gamma_value(png_structrp png_ptr, double output_gamma)
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED #ifdef PNG_READ_ALPHA_MODE_SUPPORTED
void PNGFAPI void PNGFAPI
png_set_alpha_mode_fixed(png_structrp png_ptr, int mode, png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
png_fixed_point output_gamma) png_fixed_point output_gamma)
{ {
int compose = 0; int compose = 0;
png_fixed_point file_gamma; png_fixed_point file_gamma;
@ -289,9 +290,12 @@ png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
* is expected to be 1 or greater, but this range test allows for some * is expected to be 1 or greater, but this range test allows for some
* viewing correction values. The intent is to weed out users of this API * viewing correction values. The intent is to weed out users of this API
* who use the inverse of the gamma value accidentally! Since some of these * who use the inverse of the gamma value accidentally! Since some of these
* values are reasonable this may have to be changed. * values are reasonable this may have to be changed:
*
* 1.6.x: changed from 0.07..3 to 0.01..100 (to accomodate the optimal 16-bit
* gamma of 36, and its reciprocal.)
*/ */
if (output_gamma < 70000 || output_gamma > 300000) if (output_gamma < 1000 || output_gamma > 10000000)
png_error(png_ptr, "output gamma out of expected range"); png_error(png_ptr, "output gamma out of expected range");
/* The default file gamma is the inverse of the output gamma; the output /* The default file gamma is the inverse of the output gamma; the output
@ -374,7 +378,7 @@ png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
if ((png_ptr->transformations & PNG_COMPOSE) != 0) if ((png_ptr->transformations & PNG_COMPOSE) != 0)
png_error(png_ptr, 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; png_ptr->transformations |= PNG_COMPOSE;
} }
@ -385,7 +389,7 @@ void PNGAPI
png_set_alpha_mode(png_structrp png_ptr, int mode, double output_gamma) 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, png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr,
output_gamma)); output_gamma));
} }
# endif # endif
#endif #endif
@ -426,7 +430,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
int i; int i;
png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr, png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * (sizeof (png_byte)))); (png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte))));
for (i = 0; i < num_palette; i++) for (i = 0; i < num_palette; i++)
png_ptr->quantize_index[i] = (png_byte)i; png_ptr->quantize_index[i] = (png_byte)i;
} }
@ -443,7 +447,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
/* Initialize an array to sort colors */ /* Initialize an array to sort colors */
png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr, png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * (sizeof (png_byte)))); (png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte))));
/* Initialize the quantize_sort array */ /* Initialize the quantize_sort array */
for (i = 0; i < num_palette; i++) for (i = 0; i < num_palette; i++)
@ -577,9 +581,9 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
/* Initialize palette index arrays */ /* Initialize palette index arrays */
png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr, png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * (sizeof (png_byte)))); (png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte))));
png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr, png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * (sizeof (png_byte)))); (png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte))));
/* Initialize the sort array */ /* Initialize the sort array */
for (i = 0; i < num_palette; i++) for (i = 0; i < num_palette; i++)
@ -799,7 +803,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
#ifdef PNG_READ_GAMMA_SUPPORTED #ifdef PNG_READ_GAMMA_SUPPORTED
void PNGFAPI void PNGFAPI
png_set_gamma_fixed(png_structrp png_ptr, png_fixed_point scrn_gamma, 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"); png_debug(1, "in png_set_gamma_fixed");
@ -841,7 +845,7 @@ void PNGAPI
png_set_gamma(png_structrp png_ptr, double scrn_gamma, double file_gamma) 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), 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 /* FLOATING_POINT */
#endif /* READ_GAMMA */ #endif /* READ_GAMMA */
@ -976,7 +980,6 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
default: default:
png_error(png_ptr, "invalid error action to rgb_to_gray"); png_error(png_ptr, "invalid error action to rgb_to_gray");
break;
} }
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
@ -988,7 +991,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
* that it just worked and get a memory overwrite. * that it just worked and get a memory overwrite.
*/ */
png_error(png_ptr, 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; */ /* png_ptr->transformations &= ~PNG_RGB_TO_GRAY; */
} }
@ -1015,7 +1018,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
{ {
if (red >= 0 && green >= 0) if (red >= 0 && green >= 0)
png_app_warning(png_ptr, 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 /* 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 * values which are close to the sRGB/HDTV/ITU-Rec 709 values. See
@ -1024,7 +1027,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
* something has already provided a default. * something has already provided a default.
*/ */
if (png_ptr->rgb_to_gray_red_coeff == 0 && 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_red_coeff = 6968;
png_ptr->rgb_to_gray_green_coeff = 23434; png_ptr->rgb_to_gray_green_coeff = 23434;
@ -1041,10 +1044,10 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
void PNGAPI void PNGAPI
png_set_rgb_to_gray(png_structrp png_ptr, int error_action, double red, 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_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")); png_fixed(png_ptr, green, "rgb to gray green coefficient"));
} }
#endif /* FLOATING POINT */ #endif /* FLOATING POINT */
@ -1251,7 +1254,7 @@ png_init_rgb_transformations(png_structrp png_ptr)
default: default:
case 8: case 8:
/* FALL THROUGH (Already 8 bits) */ /* FALLTHROUGH */ /* (Already 8 bits) */
case 16: case 16:
/* Already a full 16 bits */ /* Already a full 16 bits */
@ -1301,7 +1304,7 @@ png_init_read_transformations(png_structrp png_ptr)
{ {
if (png_ptr->screen_gamma != 0) /* screen set too */ if (png_ptr->screen_gamma != 0) /* screen set too */
gamma_correction = png_gamma_threshold(png_ptr->colorspace.gamma, gamma_correction = png_gamma_threshold(png_ptr->colorspace.gamma,
png_ptr->screen_gamma); png_ptr->screen_gamma);
else else
/* Assume the output matches the input; a long time default behavior /* Assume the output matches the input; a long time default behavior
@ -1582,7 +1585,7 @@ png_init_read_transformations(png_structrp png_ptr)
*/ */
if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0) if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
png_warning(png_ptr, 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) if ((png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) != 0)
{ {
@ -1618,13 +1621,13 @@ png_init_read_transformations(png_structrp png_ptr)
case PNG_BACKGROUND_GAMMA_FILE: case PNG_BACKGROUND_GAMMA_FILE:
g = png_reciprocal(png_ptr->colorspace.gamma); g = png_reciprocal(png_ptr->colorspace.gamma);
gs = png_reciprocal2(png_ptr->colorspace.gamma, gs = png_reciprocal2(png_ptr->colorspace.gamma,
png_ptr->screen_gamma); png_ptr->screen_gamma);
break; break;
case PNG_BACKGROUND_GAMMA_UNIQUE: case PNG_BACKGROUND_GAMMA_UNIQUE:
g = png_reciprocal(png_ptr->background_gamma); g = png_reciprocal(png_ptr->background_gamma);
gs = png_reciprocal2(png_ptr->background_gamma, gs = png_reciprocal2(png_ptr->background_gamma,
png_ptr->screen_gamma); png_ptr->screen_gamma);
break; break;
default: default:
g = PNG_FP_1; /* back_1 */ g = PNG_FP_1; /* back_1 */
@ -1652,11 +1655,11 @@ png_init_read_transformations(png_structrp png_ptr)
if (png_gamma_significant(g) != 0) if (png_gamma_significant(g) != 0)
{ {
back_1.red = png_gamma_8bit_correct(png_ptr->background.red, back_1.red = png_gamma_8bit_correct(png_ptr->background.red,
g); g);
back_1.green = png_gamma_8bit_correct( 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, back_1.blue = png_gamma_8bit_correct(png_ptr->background.blue,
g); g);
} }
else else
@ -1727,7 +1730,7 @@ png_init_read_transformations(png_structrp png_ptr)
case PNG_BACKGROUND_GAMMA_FILE: case PNG_BACKGROUND_GAMMA_FILE:
g = png_reciprocal(png_ptr->colorspace.gamma); g = png_reciprocal(png_ptr->colorspace.gamma);
gs = png_reciprocal2(png_ptr->colorspace.gamma, gs = png_reciprocal2(png_ptr->colorspace.gamma,
png_ptr->screen_gamma); png_ptr->screen_gamma);
break; break;
case PNG_BACKGROUND_GAMMA_UNIQUE: case PNG_BACKGROUND_GAMMA_UNIQUE:
@ -1913,7 +1916,7 @@ png_init_read_transformations(png_structrp png_ptr)
png_ptr->palette[i].blue = (png_byte)component; png_ptr->palette[i].blue = (png_byte)component;
} }
} }
#endif /* READ_SHIFT */ #endif /* READ_SHIFT */
} }
/* Modify the info structure to reflect the transformations. The /* Modify the info structure to reflect the transformations. The
@ -1997,7 +2000,7 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
# endif # endif
# else # else
/* No 16 bit support: force chopping 16-bit input down to 8, in this case /* No 16-bit support: force chopping 16-bit input down to 8, in this case
* the app program can chose if both APIs are available by setting the * the app program can chose if both APIs are available by setting the
* correct scaling to use. * correct scaling to use.
*/ */
@ -2098,10 +2101,10 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
defined(PNG_READ_USER_TRANSFORM_SUPPORTED) defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0) if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
{ {
if (info_ptr->bit_depth < png_ptr->user_transform_depth) if (png_ptr->user_transform_depth != 0)
info_ptr->bit_depth = png_ptr->user_transform_depth; info_ptr->bit_depth = png_ptr->user_transform_depth;
if (info_ptr->channels < png_ptr->user_transform_channels) if (png_ptr->user_transform_channels != 0)
info_ptr->channels = png_ptr->user_transform_channels; info_ptr->channels = png_ptr->user_transform_channels;
} }
#endif #endif
@ -2148,7 +2151,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 sp = row + (png_size_t)((row_width - 1) >> 3);
png_bytep dp = row + (png_size_t)row_width - 1; 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++) for (i = 0; i < row_width; i++)
{ {
*dp = (png_byte)((*sp >> shift) & 0x01); *dp = (png_byte)((*sp >> shift) & 0x01);
@ -2172,7 +2175,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 sp = row + (png_size_t)((row_width - 1) >> 2);
png_bytep dp = row + (png_size_t)row_width - 1; 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++) for (i = 0; i < row_width; i++)
{ {
*dp = (png_byte)((*sp >> shift) & 0x03); *dp = (png_byte)((*sp >> shift) & 0x03);
@ -2195,7 +2198,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 sp = row + (png_size_t)((row_width - 1) >> 1);
png_bytep dp = row + (png_size_t)row_width - 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++) for (i = 0; i < row_width; i++)
{ {
*dp = (png_byte)((*sp >> shift) & 0x0f); *dp = (png_byte)((*sp >> shift) & 0x0f);
@ -2382,8 +2385,8 @@ png_do_scale_16_to_8(png_row_infop row_info, png_bytep row)
while (sp < ep) while (sp < ep)
{ {
/* The input is an array of 16 bit components, these must be scaled to /* The input is an array of 16-bit components, these must be scaled to
* 8 bits each. For a 16 bit value V the required value (from the PNG * 8 bits each. For a 16-bit value V the required value (from the PNG
* specification) is: * specification) is:
* *
* (V * 255) / 65535 * (V * 255) / 65535
@ -2404,7 +2407,7 @@ png_do_scale_16_to_8(png_row_infop row_info, png_bytep row)
* *
* The approximate differs from the exact answer only when (vlo-vhi) is * The approximate differs from the exact answer only when (vlo-vhi) is
* 128; it then gives a correction of +1 when the exact correction is * 128; it then gives a correction of +1 when the exact correction is
* 0. This gives 128 errors. The exact answer (correct for all 16 bit * 0. This gives 128 errors. The exact answer (correct for all 16-bit
* input values) is: * input values) is:
* *
* error = (vlo-vhi+128)*65535 >> 24; * error = (vlo-vhi+128)*65535 >> 24;
@ -2932,7 +2935,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 * 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 * <http://www.inforamp.net/~poynton/> (THIS LINK IS DEAD June 2008 but
* versions dated 1998 through November 2002 have been archived at * 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 ) * ~poynton/notes/colour_and_gamma/ColorFAQ.txt )
* Charles Poynton poynton at poynton.com * Charles Poynton poynton at poynton.com
* *
@ -3148,9 +3151,9 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
if (red != green || red != blue) if (red != green || red != blue)
rgb_error |= 1; rgb_error |= 1;
/* From 1.5.5 in the 16 bit case do the accurate conversion even /* From 1.5.5 in the 16-bit case do the accurate conversion even
* in the 'fast' case - this is because this is where the code * in the 'fast' case - this is because this is where the code
* ends up when handling linear 16 bit data. * ends up when handling linear 16-bit data.
*/ */
gray16 = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >> gray16 = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >>
15); 15);
@ -3221,7 +3224,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
== png_ptr->trans_color.gray) == png_ptr->trans_color.gray)
{ {
unsigned int tmp = *sp & (0x7f7f >> (7 - shift)); 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); *sp = (png_byte)(tmp & 0xff);
} }
@ -3250,7 +3254,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
== png_ptr->trans_color.gray) == png_ptr->trans_color.gray)
{ {
unsigned int tmp = *sp & (0x3f3f >> (6 - shift)); 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); *sp = (png_byte)(tmp & 0xff);
} }
@ -3260,7 +3265,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
unsigned int g = (gamma_table [p | (p << 2) | unsigned int g = (gamma_table [p | (p << 2) |
(p << 4) | (p << 6)] >> 6) & 0x03; (p << 4) | (p << 6)] >> 6) & 0x03;
unsigned int tmp = *sp & (0x3f3f >> (6 - shift)); unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
tmp |= g << shift; tmp |= (unsigned int)(g << shift);
*sp = (png_byte)(tmp & 0xff); *sp = (png_byte)(tmp & 0xff);
} }
@ -3286,7 +3291,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
== png_ptr->trans_color.gray) == png_ptr->trans_color.gray)
{ {
unsigned int tmp = *sp & (0x3f3f >> (6 - shift)); 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); *sp = (png_byte)(tmp & 0xff);
} }
@ -3315,8 +3321,9 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
if ((png_uint_16)((*sp >> shift) & 0x0f) if ((png_uint_16)((*sp >> shift) & 0x0f)
== png_ptr->trans_color.gray) == png_ptr->trans_color.gray)
{ {
unsigned int tmp = *sp & (0xf0f >> (4 - shift)); 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); *sp = (png_byte)(tmp & 0xff);
} }
@ -3325,8 +3332,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
unsigned int p = (*sp >> shift) & 0x0f; unsigned int p = (*sp >> shift) & 0x0f;
unsigned int g = (gamma_table[p | (p << 4)] >> 4) & unsigned int g = (gamma_table[p | (p << 4)] >> 4) &
0x0f; 0x0f;
unsigned int tmp = *sp & (0xf0f >> (4 - shift)); unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
tmp |= g << shift; tmp |= (unsigned int)(g << shift);
*sp = (png_byte)(tmp & 0xff); *sp = (png_byte)(tmp & 0xff);
} }
@ -3351,8 +3358,9 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
if ((png_uint_16)((*sp >> shift) & 0x0f) if ((png_uint_16)((*sp >> shift) & 0x0f)
== png_ptr->trans_color.gray) == png_ptr->trans_color.gray)
{ {
unsigned int tmp = *sp & (0xf0f >> (4 - shift)); 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); *sp = (png_byte)(tmp & 0xff);
} }
@ -4193,7 +4201,7 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
*/ */
static void static void
png_do_expand_palette(png_row_infop row_info, png_bytep row, 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_const_colorp palette, png_const_bytep trans_alpha, int num_trans)
{ {
int shift, value; int shift, value;
png_bytep sp, dp; png_bytep sp, dp;
@ -4295,7 +4303,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
if (num_trans > 0) if (num_trans > 0)
{ {
sp = row + (png_size_t)row_width - 1; 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;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
@ -4456,7 +4464,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
{ {
gray = gray & 0xff; gray = gray & 0xff;
sp = row + (png_size_t)row_width - 1; 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++) for (i = 0; i < row_width; i++)
{ {
@ -4500,7 +4508,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
row_info->channels = 2; row_info->channels = 2;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1); row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
row_width); row_width);
} }
} }
else if (row_info->color_type == PNG_COLOR_TYPE_RGB && else if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
@ -4512,7 +4520,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
png_byte green = (png_byte)(trans_color->green & 0xff); png_byte green = (png_byte)(trans_color->green & 0xff);
png_byte blue = (png_byte)(trans_color->blue & 0xff); png_byte blue = (png_byte)(trans_color->blue & 0xff);
sp = row + (png_size_t)row_info->rowbytes - 1; 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++) for (i = 0; i < row_width; i++)
{ {
if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue) if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
@ -4535,7 +4543,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
png_byte green_low = (png_byte)(trans_color->green & 0xff); png_byte green_low = (png_byte)(trans_color->green & 0xff);
png_byte blue_low = (png_byte)(trans_color->blue & 0xff); png_byte blue_low = (png_byte)(trans_color->blue & 0xff);
sp = row + row_info->rowbytes - 1; 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++) for (i = 0; i < row_width; i++)
{ {
if (*(sp - 5) == red_high && if (*(sp - 5) == red_high &&
@ -4594,7 +4602,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 *sp = row + row_info->rowbytes; /* source, last byte + 1 */
png_byte *dp = sp + row_info->rowbytes; /* destination, end + 1 */ png_byte *dp = sp + row_info->rowbytes; /* destination, end + 1 */
while (dp > sp) while (dp > sp)
dp[-2] = dp[-1] = *--sp, dp -= 2; {
dp[-2] = dp[-1] = *--sp; dp -= 2;
}
row_info->rowbytes *= 2; row_info->rowbytes *= 2;
row_info->bit_depth = 16; row_info->bit_depth = 16;
@ -4760,7 +4770,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_RGB_ALPHA ||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
png_do_strip_channel(row_info, png_ptr->row_buf + 1, 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 #endif
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
/* pngset.c - storage of image information into info struct /* pngset.c - storage of image information into info struct
* *
* Last changed in libpng 1.6.18 [July 23, 2015] * Last changed in libpng 1.6.32 [August 24, 2017]
* Copyright (c) 1998-2015 Glenn Randers-Pehrson * Copyright (c) 1998-2017 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (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) double green_x, double green_y, double blue_x, double blue_y)
{ {
png_set_cHRM_fixed(png_ptr, info_ptr, png_set_cHRM_fixed(png_ptr, info_ptr,
png_fixed(png_ptr, white_x, "cHRM White X"), png_fixed(png_ptr, white_x, "cHRM White X"),
png_fixed(png_ptr, white_y, "cHRM White Y"), png_fixed(png_ptr, white_y, "cHRM White Y"),
png_fixed(png_ptr, red_x, "cHRM Red X"), png_fixed(png_ptr, red_x, "cHRM Red X"),
png_fixed(png_ptr, red_y, "cHRM Red Y"), png_fixed(png_ptr, red_y, "cHRM Red Y"),
png_fixed(png_ptr, green_x, "cHRM Green X"), png_fixed(png_ptr, green_x, "cHRM Green X"),
png_fixed(png_ptr, green_y, "cHRM Green Y"), png_fixed(png_ptr, green_y, "cHRM Green Y"),
png_fixed(png_ptr, blue_x, "cHRM Blue X"), png_fixed(png_ptr, blue_x, "cHRM Blue X"),
png_fixed(png_ptr, blue_y, "cHRM Blue Y")); png_fixed(png_ptr, blue_y, "cHRM Blue Y"));
} }
void PNGAPI 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) double blue_X, double blue_Y, double blue_Z)
{ {
png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, png_set_cHRM_XYZ_fixed(png_ptr, info_ptr,
png_fixed(png_ptr, red_X, "cHRM Red X"), png_fixed(png_ptr, red_X, "cHRM Red X"),
png_fixed(png_ptr, red_Y, "cHRM Red Y"), png_fixed(png_ptr, red_Y, "cHRM Red Y"),
png_fixed(png_ptr, red_Z, "cHRM Red Z"), png_fixed(png_ptr, red_Z, "cHRM Red Z"),
png_fixed(png_ptr, green_X, "cHRM Red X"), png_fixed(png_ptr, green_X, "cHRM Green X"),
png_fixed(png_ptr, green_Y, "cHRM Red Y"), png_fixed(png_ptr, green_Y, "cHRM Green Y"),
png_fixed(png_ptr, green_Z, "cHRM Red Z"), png_fixed(png_ptr, green_Z, "cHRM Green Z"),
png_fixed(png_ptr, blue_X, "cHRM Red X"), png_fixed(png_ptr, blue_X, "cHRM Blue X"),
png_fixed(png_ptr, blue_Y, "cHRM Red Y"), png_fixed(png_ptr, blue_Y, "cHRM Blue Y"),
png_fixed(png_ptr, blue_Z, "cHRM Red Z")); png_fixed(png_ptr, blue_Z, "cHRM Blue Z"));
} }
# endif /* FLOATING_POINT */ # endif /* FLOATING_POINT */
#endif /* cHRM */ #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 #ifdef PNG_gAMA_SUPPORTED
void PNGFAPI void PNGFAPI
png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr, png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
@ -283,17 +330,29 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
/* Check that the type matches the specification. */ /* Check that the type matches the specification. */
if (type < 0 || type > 3) 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) 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] */ /* Validate params[nparams] */
for (i=0; i<nparams; ++i) for (i=0; i<nparams; ++i)
{ {
if (params[i] == NULL || if (params[i] == NULL ||
!png_check_fp_string(params[i], strlen(params[i]))) !png_check_fp_string(params[i], strlen(params[i])))
png_error(png_ptr, "Invalid format for pCAL parameter"); {
png_chunk_report(png_ptr, "Invalid format for pCAL parameter",
PNG_CHUNK_WRITE_ERROR);
return;
}
} }
info_ptr->pcal_purpose = png_voidcast(png_charp, info_ptr->pcal_purpose = png_voidcast(png_charp,
@ -301,8 +360,8 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
if (info_ptr->pcal_purpose == NULL) 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; return;
} }
@ -316,10 +375,10 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
length = strlen(units) + 1; length = strlen(units) + 1;
png_debug1(3, "allocating units for info (%lu bytes)", png_debug1(3, "allocating units for info (%lu bytes)",
(unsigned long)length); (unsigned long)length);
info_ptr->pcal_units = png_voidcast(png_charp, 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) if (info_ptr->pcal_units == NULL)
{ {
@ -331,7 +390,7 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
memcpy(info_ptr->pcal_units, units, length); memcpy(info_ptr->pcal_units, units, length);
info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr, 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) if (info_ptr->pcal_params == NULL)
{ {
@ -340,7 +399,8 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
return; 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++) for (i = 0; i < nparams; i++)
{ {
@ -398,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); png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw);
info_ptr->scal_s_width = png_voidcast(png_charp, 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) if (info_ptr->scal_s_width == NULL)
{ {
@ -414,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); png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh);
info_ptr->scal_s_height = png_voidcast(png_charp, 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) if (info_ptr->scal_s_height == NULL)
{ {
@ -453,9 +513,9 @@ png_set_sCAL(png_const_structrp png_ptr, png_inforp info_ptr, int unit,
char sheight[PNG_sCAL_MAX_DIGITS+1]; char sheight[PNG_sCAL_MAX_DIGITS+1];
png_ascii_from_fp(png_ptr, swidth, (sizeof swidth), width, 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_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); png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
} }
@ -513,12 +573,17 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
png_const_colorp palette, int num_palette) png_const_colorp palette, int num_palette)
{ {
png_uint_32 max_palette_length;
png_debug1(1, "in %s storage function", "PLTE"); png_debug1(1, "in %s storage function", "PLTE");
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH) max_palette_length = (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ?
(1 << info_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH;
if (num_palette < 0 || num_palette > (int) max_palette_length)
{ {
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
png_error(png_ptr, "Invalid palette length"); png_error(png_ptr, "Invalid palette length");
@ -551,14 +616,15 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
/* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
* of num_palette entries, in case of an invalid PNG file that has * of num_palette entries, in case of an invalid PNG file or incorrect
* too-large sample values. * call to png_set_PLTE() with too-large sample values.
*/ */
png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr, png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr,
PNG_MAX_PALETTE_LENGTH * (sizeof (png_color)))); PNG_MAX_PALETTE_LENGTH * (sizeof (png_color))));
if (num_palette > 0) 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->palette = png_ptr->palette;
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
@ -643,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, 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); png_colorspace_sync_info(png_ptr, info_ptr);
@ -668,7 +734,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
memcpy(new_iccp_name, name, length); memcpy(new_iccp_name, name, length);
new_iccp_profile = png_voidcast(png_bytep, new_iccp_profile = png_voidcast(png_bytep,
png_malloc_warn(png_ptr, proflen)); png_malloc_warn(png_ptr, proflen));
if (new_iccp_profile == NULL) if (new_iccp_profile == NULL)
{ {
@ -709,7 +775,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
{ {
int i; int i;
png_debug1(1, "in %lx storage function", png_ptr == NULL ? 0xabadca11 : png_debug1(1, "in %lx storage function", png_ptr == NULL ? 0xabadca11U :
(unsigned long)png_ptr->chunk_name); (unsigned long)png_ptr->chunk_name);
if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL)
@ -743,14 +809,14 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
* the overflow checks. * the overflow checks.
*/ */
new_text = png_voidcast(png_textp,png_realloc_array(png_ptr, new_text = png_voidcast(png_textp,png_realloc_array(png_ptr,
info_ptr->text, old_num_text, max_text-old_num_text, info_ptr->text, old_num_text, max_text-old_num_text,
sizeof *new_text)); sizeof *new_text));
} }
if (new_text == NULL) if (new_text == NULL)
{ {
png_chunk_report(png_ptr, "too many text chunks", png_chunk_report(png_ptr, "too many text chunks",
PNG_CHUNK_WRITE_ERROR); PNG_CHUNK_WRITE_ERROR);
return 1; return 1;
} }
@ -778,7 +844,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST) text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)
{ {
png_chunk_report(png_ptr, "text compression mode is out of range", png_chunk_report(png_ptr, "text compression mode is out of range",
PNG_CHUNK_WRITE_ERROR); PNG_CHUNK_WRITE_ERROR);
continue; continue;
} }
@ -810,7 +876,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
# else /* iTXt */ # else /* iTXt */
{ {
png_chunk_report(png_ptr, "iTXt chunk not supported", png_chunk_report(png_ptr, "iTXt chunk not supported",
PNG_CHUNK_WRITE_ERROR); PNG_CHUNK_WRITE_ERROR);
continue; continue;
} }
# endif # endif
@ -839,7 +905,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
if (textp->key == NULL) if (textp->key == NULL)
{ {
png_chunk_report(png_ptr, "text chunk: out of memory", png_chunk_report(png_ptr, "text chunk: out of memory",
PNG_CHUNK_WRITE_ERROR); PNG_CHUNK_WRITE_ERROR);
return 1; return 1;
} }
@ -947,12 +1013,14 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
/* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
png_ptr->trans_alpha = info_ptr->trans_alpha = png_voidcast(png_bytep,
png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH));
if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
{
/* 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));
memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans); memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
}
png_ptr->trans_alpha = info_ptr->trans_alpha;
} }
if (trans_color != NULL) if (trans_color != NULL)
@ -969,7 +1037,7 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
trans_color->green > sample_max || trans_color->green > sample_max ||
trans_color->blue > sample_max))) trans_color->blue > sample_max)))
png_warning(png_ptr, 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 #endif
@ -1011,8 +1079,8 @@ png_set_sPLT(png_const_structrp png_ptr,
* overflows. Notice that the parameters are (int) and (size_t) * overflows. Notice that the parameters are (int) and (size_t)
*/ */
np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr, np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr,
info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries, info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries,
sizeof *np)); sizeof *np));
if (np == NULL) if (np == NULL)
{ {
@ -1073,7 +1141,7 @@ png_set_sPLT(png_const_structrp png_ptr,
* checked it when doing the allocation. * checked it when doing the allocation.
*/ */
memcpy(np->entries, entries->entries, 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 /* Note that 'continue' skips the advance of the out pointer and out
* count, so an invalid entry is not added. * count, so an invalid entry is not added.
@ -1081,8 +1149,9 @@ png_set_sPLT(png_const_structrp png_ptr,
info_ptr->valid |= PNG_INFO_sPLT; info_ptr->valid |= PNG_INFO_sPLT;
++(info_ptr->splt_palettes_num); ++(info_ptr->splt_palettes_num);
++np; ++np;
++entries;
} }
while (++entries, --nentries); while (--nentries);
if (nentries > 0) if (nentries > 0)
png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR); png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR);
@ -1103,10 +1172,10 @@ check_location(png_const_structrp png_ptr, int location)
{ {
/* Write struct, so unknown chunks come from the app */ /* Write struct, so unknown chunks come from the app */
png_app_warning(png_ptr, 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 */ /* Use the old behavior */
location = (png_byte)(png_ptr->mode & 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 /* This need not be an internal error - if the app calls
@ -1129,7 +1198,7 @@ check_location(png_const_structrp png_ptr, int location)
void PNGAPI void PNGAPI
png_set_unknown_chunks(png_const_structrp png_ptr, 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; png_unknown_chunkp np;
@ -1168,13 +1237,13 @@ png_set_unknown_chunks(png_const_structrp png_ptr,
* appropriate to read or write. * appropriate to read or write.
*/ */
np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr, np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr,
info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns, info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns,
sizeof *np)); sizeof *np));
if (np == NULL) if (np == NULL)
{ {
png_chunk_report(png_ptr, "too many unknown chunks", png_chunk_report(png_ptr, "too many unknown chunks",
PNG_CHUNK_WRITE_ERROR); PNG_CHUNK_WRITE_ERROR);
return; return;
} }
@ -1203,12 +1272,12 @@ png_set_unknown_chunks(png_const_structrp png_ptr,
else else
{ {
np->data = png_voidcast(png_bytep, np->data = png_voidcast(png_bytep,
png_malloc_base(png_ptr, unknowns->size)); png_malloc_base(png_ptr, unknowns->size));
if (np->data == NULL) if (np->data == NULL)
{ {
png_chunk_report(png_ptr, "unknown chunk: out of memory", 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 */ /* But just skip storing the unknown chunk */
continue; continue;
} }
@ -1242,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"); png_app_error(png_ptr, "invalid unknown chunk location");
/* Fake out the pre 1.6.0 behavior: */ /* 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; location = PNG_AFTER_IDAT;
else else
@ -1333,6 +1402,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
static PNG_CONST png_byte chunks_to_ignore[] = { static PNG_CONST png_byte chunks_to_ignore[] = {
98, 75, 71, 68, '\0', /* bKGD */ 98, 75, 71, 68, '\0', /* bKGD */
99, 72, 82, 77, '\0', /* cHRM */ 99, 72, 82, 77, '\0', /* cHRM */
101, 88, 73, 102, '\0', /* eXIf */
103, 65, 77, 65, '\0', /* gAMA */ 103, 65, 77, 65, '\0', /* gAMA */
104, 73, 83, 84, '\0', /* hIST */ 104, 73, 83, 84, '\0', /* hIST */
105, 67, 67, 80, '\0', /* iCCP */ 105, 67, 67, 80, '\0', /* iCCP */
@ -1366,7 +1436,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
return; return;
} }
num_chunks = num_chunks_in; num_chunks = (unsigned int)num_chunks_in;
} }
old_num_chunks = png_ptr->num_chunk_list; old_num_chunks = png_ptr->num_chunk_list;
@ -1415,7 +1485,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
for (i=0; i<num_chunks; ++i) for (i=0; i<num_chunks; ++i)
{ {
old_num_chunks = add_one_chunk(new_list, old_num_chunks, 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. */ /* Now remove any spurious 'default' entries. */
@ -1495,60 +1565,60 @@ png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr,
void PNGAPI void PNGAPI
png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size) png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
{ {
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
if (size == 0 || size > PNG_UINT_31_MAX) if (size == 0 || size > PNG_UINT_31_MAX)
png_error(png_ptr, "invalid compression buffer size"); png_error(png_ptr, "invalid compression buffer size");
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED # ifdef PNG_SEQUENTIAL_READ_SUPPORTED
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
{ {
png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */ png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */
return; return;
} }
# endif # endif
# ifdef PNG_WRITE_SUPPORTED # 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__ #ifndef __COVERITY__
/* Some compilers complain that this is always false. However, it /* Some compilers complain that this is always false. However, it
* can be true when integer overflow happens. * can be true when integer overflow happens.
*/ */
if (size > ZLIB_IO_MAX) if (size > ZLIB_IO_MAX)
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Compression buffer size limited to system maximum"); "Compression buffer size limited to system maximum");
size = ZLIB_IO_MAX; /* must fit */ size = ZLIB_IO_MAX; /* must fit */
} }
#endif #endif
if (size < 6) if (size < 6)
{ {
/* Deflate will potentially go into an infinite loop on a SYNC_FLUSH /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH
* if this is permitted. * if this is permitted.
*/ */
png_warning(png_ptr, png_warning(png_ptr,
"Compression buffer size cannot be reduced below 6"); "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 # endif
} }
@ -1556,7 +1626,7 @@ void PNGAPI
png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask) png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
info_ptr->valid &= ~mask; info_ptr->valid &= (unsigned int)(~mask);
} }
@ -1568,7 +1638,7 @@ png_set_user_limits (png_structrp png_ptr, png_uint_32 user_width_max,
{ {
/* Images with dimensions larger than these limits will be /* Images with dimensions larger than these limits will be
* rejected by png_set_IHDR(). To accept any PNG datastream * rejected by png_set_IHDR(). To accept any PNG datastream
* regardless of dimensions, set both limits to 0x7ffffffL. * regardless of dimensions, set both limits to 0x7fffffff.
*/ */
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
@ -1639,4 +1709,94 @@ png_set_check_for_invalid_index(png_structrp png_ptr, int allowed)
png_ptr->num_palette_max = -1; png_ptr->num_palette_max = -1;
} }
#endif #endif
#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) || \
defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification,
* and if invalid, correct the keyword rather than discarding the entire
* chunk. The PNG 1.0 specification requires keywords 1-79 characters in
* length, forbids leading or trailing whitespace, multiple internal spaces,
* and the non-break space (0x80) from ISO 8859-1. Returns keyword length.
*
* The 'new_key' buffer must be 80 characters in size (for the keyword plus a
* trailing '\0'). If this routine returns 0 then there was no keyword, or a
* valid one could not be generated, and the caller must png_error.
*/
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;
png_debug(1, "in png_check_keyword");
if (key == NULL)
{
*new_key = 0;
return 0;
}
while (*key && key_len < 79)
{
png_byte ch = (png_byte)*key++;
if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/))
{
*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;
/* If the character was not a space then it is invalid. */
if (ch != 32)
bad_character = ch;
}
else if (bad_character == 0)
bad_character = ch; /* just skip it, record the first error */
}
if (key_len > 0 && space != 0) /* trailing space */
{
--key_len; --new_key;
if (bad_character == 0)
bad_character = 32;
}
/* Terminate the keyword */
*new_key = 0;
if (key_len == 0)
return 0;
#ifdef PNG_WARNINGS_SUPPORTED
/* Try to only output one warning per keyword: */
if (*key != 0) /* keyword too long */
png_warning(png_ptr, "keyword truncated");
else if (bad_character != 0)
{
PNG_WARNING_PARAMETERS(p)
png_warning_parameter(p, 1, orig_key);
png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_02x, bad_character);
png_formatted_warning(png_ptr, p, "keyword \"@1\": bad character '0x@2'");
}
#else /* !WARNINGS */
PNG_UNUSED(png_ptr)
#endif /* !WARNINGS */
return key_len;
}
#endif /* TEXT || pCAL || iCCP || sPLT */
#endif /* READ || WRITE */ #endif /* READ || WRITE */

View File

@ -1,8 +1,8 @@
/* pngstruct.h - header file for PNG reference library /* pngstruct.h - header file for PNG reference library
* *
* Last changed in libpng 1.6.18 [July 23, 2015] * Last changed in libpng 1.6.32 [August 24, 2017]
* Copyright (c) 1998-2015 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@ -27,7 +27,7 @@
/* We must ensure that zlib uses 'const' in declarations. */ /* We must ensure that zlib uses 'const' in declarations. */
# define ZLIB_CONST # define ZLIB_CONST
#endif #endif
#include "../zlib/zlib.h" #include "zlib.h"
#ifdef const #ifdef const
/* zlib.h sometimes #defines const to nothing, undo this. */ /* zlib.h sometimes #defines const to nothing, undo this. */
# undef const # undef const
@ -249,7 +249,7 @@ struct png_struct_def
png_byte filter; /* file filter type (always 0) */ png_byte filter; /* file filter type (always 0) */
png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
png_byte pass; /* current interlace pass (0 - 6) */ 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 color_type; /* color type of file */
png_byte bit_depth; /* bit depth of file */ png_byte bit_depth; /* bit depth of file */
png_byte usr_bit_depth; /* bit depth of users row: write only */ png_byte usr_bit_depth; /* bit depth of users row: write only */
@ -263,6 +263,9 @@ struct png_struct_def
/* pixel depth used for the row buffers */ /* pixel depth used for the row buffers */
png_byte transformed_pixel_depth; png_byte transformed_pixel_depth;
/* pixel depth after read/write transforms */ /* pixel depth after read/write transforms */
#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) #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
png_uint_16 filler; /* filler bytes for pixel expansion */ png_uint_16 filler; /* filler bytes for pixel expansion */
#endif #endif
@ -350,7 +353,7 @@ struct png_struct_def
/* Options */ /* Options */
#ifdef PNG_SET_OPTION_SUPPORTED #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 #endif
#if PNG_LIBPNG_VER < 10700 #if PNG_LIBPNG_VER < 10700

View File

@ -1,8 +1,8 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers) /* pngtrans.c - transforms the data in a row (used by both readers and writers)
* *
* Last changed in libpng 1.6.18 [July 23, 2015] * Last changed in libpng 1.6.30 [June 28, 2017]
* Copyright (c) 1998-2015 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@ -30,7 +30,7 @@ png_set_bgr(png_structrp png_ptr)
#endif #endif
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
/* Turn on 16 bit byte swapping */ /* Turn on 16-bit byte swapping */
void PNGAPI void PNGAPI
png_set_swap(png_structrp png_ptr) png_set_swap(png_structrp png_ptr)
{ {
@ -172,13 +172,14 @@ png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
* size! * size!
*/ */
png_app_error(png_ptr, 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; return;
} }
default: default:
png_app_error(png_ptr, png_app_error(png_ptr,
"png_set_filler: inappropriate color type"); "png_set_filler: inappropriate color type");
return; return;
} }
# else # else
@ -313,7 +314,7 @@ png_do_invert(png_row_infop row_info, png_bytep row)
#ifdef PNG_16BIT_SUPPORTED #ifdef PNG_16BIT_SUPPORTED
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
/* Swaps byte order on 16 bit depth images */ /* Swaps byte order on 16-bit depth images */
void /* PRIVATE */ void /* PRIVATE */
png_do_swap(png_row_infop row_info, png_bytep row) png_do_swap(png_row_infop row_info, png_bytep row)
{ {
@ -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 */ if (at_start != 0) /* Skip initial filler */
++sp; ++sp;
else /* Skip initial channel and, for sp, the filler */ 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 */ /* For a 1 pixel wide image there is nothing to do */
while (sp < ep) while (sp < ep)
*dp++ = *sp, sp += 2; {
*dp++ = *sp; sp += 2;
}
row_info->pixel_depth = 8; 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 */ if (at_start != 0) /* Skip initial filler */
sp += 2; sp += 2;
else /* Skip initial channel and, for sp, the filler */ else /* Skip initial channel and, for sp, the filler */
sp += 4, dp += 2; {
sp += 4; dp += 2;
}
while (sp < ep) while (sp < ep)
*dp++ = *sp++, *dp++ = *sp, sp += 3; {
*dp++ = *sp++; *dp++ = *sp; sp += 3;
}
row_info->pixel_depth = 16; 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 */ if (at_start != 0) /* Skip initial filler */
++sp; ++sp;
else /* Skip initial channels and, for sp, the filler */ 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. */ /* Note that the loop adds 3 to dp and 4 to sp each time. */
while (sp < ep) while (sp < ep)
*dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2; {
*dp++ = *sp++; *dp++ = *sp++; *dp++ = *sp; sp += 2;
}
row_info->pixel_depth = 24; 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 */ if (at_start != 0) /* Skip initial filler */
sp += 2; sp += 2;
else /* Skip initial channels and, for sp, the filler */ else /* Skip initial channels and, for sp, the filler */
sp += 8, dp += 6; {
sp += 8; dp += 6;
}
while (sp < ep) while (sp < ep)
{ {
/* Copy 6 bytes, skip 2 */ /* Copy 6 bytes, skip 2 */
*dp++ = *sp++, *dp++ = *sp++; *dp++ = *sp++; *dp++ = *sp++;
*dp++ = *sp++, *dp++ = *sp++; *dp++ = *sp++; *dp++ = *sp++;
*dp++ = *sp++, *dp++ = *sp, sp += 3; *dp++ = *sp++; *dp++ = *sp; sp += 3;
} }
row_info->pixel_depth = 48; 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 */ return; /* The filler channel has gone already */
/* Fix the rowbytes value. */ /* Fix the rowbytes value. */
row_info->rowbytes = dp-row; row_info->rowbytes = (unsigned int)(dp-row);
} }
#endif #endif
@ -692,7 +707,7 @@ 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 * and this calculation is used because it avoids warnings that other
* forms produced on either GCC or MSVC. * forms produced on either GCC or MSVC.
*/ */
int padding = (-row_info->pixel_depth * row_info->width) & 7; int padding = PNG_PADBITS(row_info->pixel_depth, row_info->width);
png_bytep rp = png_ptr->row_buf + row_info->rowbytes; png_bytep rp = png_ptr->row_buf + row_info->rowbytes;
switch (row_info->bit_depth) 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_ptr->flags & PNG_FLAG_ROW_INIT) != 0)
{ {
png_app_error(png_ptr, 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; return;
} }
#endif #endif

View File

@ -1,8 +1,8 @@
/* pngwio.c - functions for data output /* pngwio.c - functions for data output
* *
* Last changed in libpng 1.6.15 [November 20, 2014] * Last changed in libpng 1.6.24 [August 4, 2016]
* Copyright (c) 1998-2014 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@ -26,7 +26,7 @@
* writes to a file pointer. Note that this routine sometimes gets called * writes to a file pointer. Note that this routine sometimes gets called
* with very small lengths, so you should implement some kind of simple * with very small lengths, so you should implement some kind of simple
* buffering if you are using unbuffered writes. This should never be asked * buffering if you are using unbuffered writes. This should never be asked
* to write more than 64K on a 16 bit machine. * to write more than 64K on a 16-bit machine.
*/ */
void /* PRIVATE */ void /* PRIVATE */
@ -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! */ /* NOTE: write_data_fn must not change the buffer! */
if (png_ptr->write_data_fn != NULL ) if (png_ptr->write_data_fn != NULL )
(*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data), (*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data),
length); length);
else else
png_error(png_ptr, "Call to NULL write function"); png_error(png_ptr, "Call to NULL write function");

View File

@ -1,8 +1,8 @@
/* pngwrite.c - general routines to write a PNG file /* pngwrite.c - general routines to write a PNG file
* *
* Last changed in libpng 1.6.18 [July 23, 2015] * Last changed in libpng 1.6.32 [August 24, 2017]
* Copyright (c) 1998-2015 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@ -12,9 +12,9 @@
*/ */
#include "pngpriv.h" #include "pngpriv.h"
#if defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) #ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
# include <errno.h> # include <errno.h>
#endif #endif /* SIMPLIFIED_WRITE_STDIO */
#ifdef PNG_WRITE_SUPPORTED #ifdef PNG_WRITE_SUPPORTED
@ -22,7 +22,7 @@
/* Write out all the unknown chunks for the current given location */ /* Write out all the unknown chunks for the current given location */
static void static void
write_unknown_chunks(png_structrp png_ptr, png_const_inforp info_ptr, 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) 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 # ifdef PNG_WRITE_sRGB_SUPPORTED
if ((info_ptr->valid & PNG_INFO_sRGB) != 0) if ((info_ptr->valid & PNG_INFO_sRGB) != 0)
png_app_warning(png_ptr, png_app_warning(png_ptr,
"profile matches sRGB but writing iCCP instead"); "profile matches sRGB but writing iCCP instead");
# endif # endif
png_write_iCCP(png_ptr, info_ptr->iccp_name, png_write_iCCP(png_ptr, info_ptr->iccp_name,
info_ptr->iccp_profile); info_ptr->iccp_profile);
} }
# ifdef PNG_WRITE_sRGB_SUPPORTED # ifdef PNG_WRITE_sRGB_SUPPORTED
else else
@ -206,7 +206,7 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)
png_write_PLTE(png_ptr, info_ptr->palette, png_write_PLTE(png_ptr, info_ptr->palette,
(png_uint_32)info_ptr->num_palette); (png_uint_32)info_ptr->num_palette);
else if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) !=0) else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
png_error(png_ptr, "Valid palette required for paletted images"); png_error(png_ptr, "Valid palette required for paletted images");
#ifdef PNG_WRITE_tRNS_SUPPORTED #ifdef PNG_WRITE_tRNS_SUPPORTED
@ -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); png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
#endif #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 #ifdef PNG_WRITE_hIST_SUPPORTED
if ((info_ptr->valid & PNG_INFO_hIST) != 0) if ((info_ptr->valid & PNG_INFO_hIST) != 0)
png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); 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++) for (i = 0; i < info_ptr->num_text; i++)
{ {
png_debug2(2, "Writing trailer text chunk %d, type %d", 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? */ /* An internationalized chunk? */
if (info_ptr->text[i].compression > 0) if (info_ptr->text[i].compression > 0)
{ {
@ -432,6 +437,12 @@ png_write_end(png_structrp png_ptr, png_inforp info_ptr)
} }
} }
#endif #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 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
write_unknown_chunks(png_ptr, info_ptr, PNG_AFTER_IDAT); write_unknown_chunks(png_ptr, info_ptr, PNG_AFTER_IDAT);
#endif #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) for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{ {
png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); png_uint_32 s0 = (png_uint_32)(*(rp ) << 8) | *(rp + 1);
png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); png_uint_32 s1 = (png_uint_32)(*(rp + 2) << 8) | *(rp + 3);
png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); 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 red = (png_uint_32)((s0 - s1) & 0xffffL);
png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL); png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
*(rp ) = (png_byte)(red >> 8); *(rp ) = (png_byte)(red >> 8);
@ -693,7 +704,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
return; return;
png_debug2(1, "in png_write_row (row %u, pass %d)", 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 */ /* Initialize transformations and other stuff if first time */
if (png_ptr->row_number == 0 && png_ptr->pass == 0) 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) if (png_ptr == NULL)
return; 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 */ /* Flush the current output buffers now */
@ -1007,8 +1018,8 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
case 5: case 5:
case 6: case 6:
case 7: png_app_error(png_ptr, "Unknown row filter for method 0"); case 7: png_app_error(png_ptr, "Unknown row filter for method 0");
/* FALL THROUGH */
#endif /* WRITE_FILTER */ #endif /* WRITE_FILTER */
/* FALLTHROUGH */
case PNG_FILTER_VALUE_NONE: case PNG_FILTER_VALUE_NONE:
png_ptr->do_filter = PNG_FILTER_NONE; break; png_ptr->do_filter = PNG_FILTER_NONE; break;
@ -1069,7 +1080,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. * is not available so the filter can't be used. Just warn here.
*/ */
png_app_warning(png_ptr, 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); filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH);
} }
@ -1095,13 +1106,13 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
if (png_ptr->try_row == NULL) if (png_ptr->try_row == NULL)
png_ptr->try_row = png_voidcast(png_bytep, 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 (num_filters > 1)
{ {
if (png_ptr->tst_row == NULL) if (png_ptr->tst_row == NULL)
png_ptr->tst_row = png_voidcast(png_bytep, 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; png_ptr->do_filter = (png_byte)filters;
@ -1422,7 +1433,7 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported"); png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported");
#endif #endif
/* Swap bits of 1, 2, 4 bit packed pixel formats */ /* Swap bits of 1-bit, 2-bit, 4-bit packed pixel formats */
if ((transforms & PNG_TRANSFORM_PACKSWAP) != 0) if ((transforms & PNG_TRANSFORM_PACKSWAP) != 0)
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED #ifdef PNG_WRITE_PACKSWAP_SUPPORTED
png_set_packswap(png_ptr); png_set_packswap(png_ptr);
@ -1452,7 +1463,6 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED #ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
# ifdef PNG_STDIO_SUPPORTED /* currently required for png_image_write_* */
/* Initialize the write structure - general purpose utility. */ /* Initialize the write structure - general purpose utility. */
static int static int
png_image_write_init(png_imagep image) png_image_write_init(png_imagep image)
@ -1504,6 +1514,10 @@ typedef struct
png_const_voidp first_row; png_const_voidp first_row;
ptrdiff_t row_bytes; ptrdiff_t row_bytes;
png_voidp local_row; png_voidp local_row;
/* Byte count for memory writing */
png_bytep memory;
png_alloc_size_t memory_bytes; /* not used for STDIO */
png_alloc_size_t output_bytes; /* running total */
} png_image_write_control; } png_image_write_control;
/* Write png_uint_16 input to a 16-bit PNG; the png_ptr has already been set to /* Write png_uint_16 input to a 16-bit PNG; the png_ptr has already been set to
@ -1522,7 +1536,8 @@ png_write_image_16bit(png_voidp argument)
display->first_row); display->first_row);
png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row); png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row);
png_uint_16p row_end; 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; int aindex = 0;
png_uint_32 y = image->height; png_uint_32 y = image->height;
@ -1536,9 +1551,9 @@ png_write_image_16bit(png_voidp argument)
++output_row; ++output_row;
} }
else else
aindex = channels; aindex = (int)channels;
# else # else
aindex = channels; aindex = (int)channels;
# endif # endif
} }
@ -1551,7 +1566,7 @@ png_write_image_16bit(png_voidp argument)
*/ */
row_end = output_row + image->width * (channels+1); row_end = output_row + image->width * (channels+1);
while (y-- > 0) for (; y > 0; --y)
{ {
png_const_uint_16p in_ptr = input_row; png_const_uint_16p in_ptr = input_row;
png_uint_16p out_ptr = output_row; png_uint_16p out_ptr = output_row;
@ -1572,7 +1587,7 @@ png_write_image_16bit(png_voidp argument)
if (alpha > 0 && alpha < 65535) if (alpha > 0 && alpha < 65535)
reciprocal = ((0xffff<<15)+(alpha>>1))/alpha; reciprocal = ((0xffff<<15)+(alpha>>1))/alpha;
c = channels; c = (int)channels;
do /* always at least one channel */ do /* always at least one channel */
{ {
png_uint_16 component = *in_ptr++; png_uint_16 component = *in_ptr++;
@ -1607,7 +1622,7 @@ png_write_image_16bit(png_voidp argument)
} }
png_write_row(png_ptr, png_voidcast(png_const_bytep, display->local_row)); 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; return 1;
@ -1625,7 +1640,7 @@ png_write_image_16bit(png_voidp argument)
static png_byte static png_byte
png_unpremultiply(png_uint_32 component, png_uint_32 alpha, 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 /* 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 * is represented as some other value there is more likely to be a
@ -1680,7 +1695,8 @@ png_write_image_8bit(png_voidp argument)
display->first_row); display->first_row);
png_bytep output_row = png_voidcast(png_bytep, display->local_row); png_bytep output_row = png_voidcast(png_bytep, display->local_row);
png_uint_32 y = image->height; 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) if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0)
{ {
@ -1697,12 +1713,12 @@ png_write_image_8bit(png_voidp argument)
else else
# endif # endif
aindex = channels; aindex = (int)channels;
/* Use row_end in place of a loop counter: */ /* Use row_end in place of a loop counter: */
row_end = output_row + image->width * (channels+1); row_end = output_row + image->width * (channels+1);
while (y-- > 0) for (; y > 0; --y)
{ {
png_const_uint_16p in_ptr = input_row; png_const_uint_16p in_ptr = input_row;
png_bytep out_ptr = output_row; png_bytep out_ptr = output_row;
@ -1720,7 +1736,7 @@ png_write_image_8bit(png_voidp argument)
if (alphabyte > 0 && alphabyte < 255) if (alphabyte > 0 && alphabyte < 255)
reciprocal = UNP_RECIPROCAL(alpha); reciprocal = UNP_RECIPROCAL(alpha);
c = channels; c = (int)channels;
do /* always at least one channel */ do /* always at least one channel */
*out_ptr++ = png_unpremultiply(*in_ptr++, alpha, reciprocal); *out_ptr++ = png_unpremultiply(*in_ptr++, alpha, reciprocal);
while (--c > 0); while (--c > 0);
@ -1732,7 +1748,7 @@ png_write_image_8bit(png_voidp argument)
png_write_row(png_ptr, png_voidcast(png_const_bytep, png_write_row(png_ptr, png_voidcast(png_const_bytep,
display->local_row)); 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 */ } /* while y */
} }
@ -1743,7 +1759,7 @@ png_write_image_8bit(png_voidp argument)
*/ */
png_bytep row_end = output_row + image->width * channels; 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_const_uint_16p in_ptr = input_row;
png_bytep out_ptr = output_row; png_bytep out_ptr = output_row;
@ -1757,7 +1773,7 @@ png_write_image_8bit(png_voidp argument)
} }
png_write_row(png_ptr, output_row); 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));
} }
} }
@ -1774,7 +1790,7 @@ png_image_set_PLTE(png_image_write_control *display)
/* NOTE: the caller must check for cmap != NULL and entries != 0 */ /* NOTE: the caller must check for cmap != NULL and entries != 0 */
const png_uint_32 format = image->format; 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) &&\ # if defined(PNG_FORMAT_BGR_SUPPORTED) &&\
defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED) defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED)
@ -1806,7 +1822,7 @@ png_image_set_PLTE(png_image_write_control *display)
{ {
png_const_uint_16p entry = png_voidcast(png_const_uint_16p, cmap); 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 */ if ((channels & 1) != 0) /* no alpha */
{ {
@ -1845,16 +1861,16 @@ png_image_set_PLTE(png_image_write_control *display)
if (channels >= 3) /* RGB */ if (channels >= 3) /* RGB */
{ {
palette[i].blue = png_unpremultiply(entry[afirst + (2 ^ bgr)], palette[i].blue = png_unpremultiply(entry[afirst + (2 ^ bgr)],
alpha, reciprocal); alpha, reciprocal);
palette[i].green = png_unpremultiply(entry[afirst + 1], alpha, palette[i].green = png_unpremultiply(entry[afirst + 1], alpha,
reciprocal); reciprocal);
palette[i].red = png_unpremultiply(entry[afirst + bgr], alpha, palette[i].red = png_unpremultiply(entry[afirst + bgr], alpha,
reciprocal); reciprocal);
} }
else /* gray */ else /* gray */
palette[i].blue = palette[i].red = palette[i].green = palette[i].blue = palette[i].red = palette[i].green =
png_unpremultiply(entry[afirst], alpha, reciprocal); png_unpremultiply(entry[afirst], alpha, reciprocal);
} }
} }
@ -1862,7 +1878,7 @@ png_image_set_PLTE(png_image_write_control *display)
{ {
png_const_bytep entry = png_voidcast(png_const_bytep, cmap); png_const_bytep entry = png_voidcast(png_const_bytep, cmap);
entry += i * channels; entry += (unsigned int)i * channels;
switch (channels) switch (channels)
{ {
@ -1870,7 +1886,7 @@ png_image_set_PLTE(png_image_write_control *display)
tRNS[i] = entry[afirst ? 0 : 3]; tRNS[i] = entry[afirst ? 0 : 3];
if (tRNS[i] < 255) if (tRNS[i] < 255)
num_trans = i+1; num_trans = i+1;
/* FALL THROUGH */ /* FALLTHROUGH */
case 3: case 3:
palette[i].blue = entry[afirst + (2 ^ bgr)]; palette[i].blue = entry[afirst + (2 ^ bgr)];
palette[i].green = entry[afirst + 1]; palette[i].green = entry[afirst + 1];
@ -1881,7 +1897,7 @@ png_image_set_PLTE(png_image_write_control *display)
tRNS[i] = entry[1 ^ afirst]; tRNS[i] = entry[1 ^ afirst];
if (tRNS[i] < 255) if (tRNS[i] < 255)
num_trans = i+1; num_trans = i+1;
/* FALL THROUGH */ /* FALLTHROUGH */
case 1: case 1:
palette[i].blue = palette[i].red = palette[i].green = palette[i].blue = palette[i].red = palette[i].green =
entry[afirst]; entry[afirst];
@ -1901,20 +1917,20 @@ png_image_set_PLTE(png_image_write_control *display)
# endif # endif
png_set_PLTE(image->opaque->png_ptr, image->opaque->info_ptr, palette, png_set_PLTE(image->opaque->png_ptr, image->opaque->info_ptr, palette,
entries); entries);
if (num_trans > 0) if (num_trans > 0)
png_set_tRNS(image->opaque->png_ptr, image->opaque->info_ptr, tRNS, 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 static int
png_image_write_main(png_voidp argument) png_image_write_main(png_voidp argument)
{ {
png_image_write_control *display = png_voidcast(png_image_write_control*, png_image_write_control *display = png_voidcast(png_image_write_control*,
argument); argument);
png_imagep image = display->image; png_imagep image = display->image;
png_structrp png_ptr = image->opaque->png_ptr; png_structrp png_ptr = image->opaque->png_ptr;
png_inforp info_ptr = image->opaque->info_ptr; png_inforp info_ptr = image->opaque->info_ptr;
@ -1931,9 +1947,43 @@ png_image_write_main(png_voidp argument)
png_set_benign_errors(png_ptr, 0/*error*/); png_set_benign_errors(png_ptr, 0/*error*/);
# endif # endif
/* Default the 'row_stride' parameter if required. */ /* Default the 'row_stride' parameter if required, also check the row stride
if (display->row_stride == 0) * and total image size to ensure that they are within the system limits.
display->row_stride = PNG_IMAGE_ROW_STRIDE(*image); */
{
const unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format);
if (image->width <= 0x7fffffffU/channels) /* no overflow */
{
png_uint_32 check;
const png_uint_32 png_row_stride = image->width * channels;
if (display->row_stride == 0)
display->row_stride = (png_int_32)/*SAFE*/png_row_stride;
if (display->row_stride < 0)
check = (png_uint_32)(-display->row_stride);
else
check = (png_uint_32)display->row_stride;
if (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.
*/
if (image->height > 0xffffffffU/png_row_stride)
png_error(image->opaque->png_ptr, "memory image too large");
}
else
png_error(image->opaque->png_ptr, "supplied row stride too small");
}
else
png_error(image->opaque->png_ptr, "image row stride too large");
}
/* Set the required transforms then write the rows in the correct order. */ /* Set the required transforms then write the rows in the correct order. */
if ((format & PNG_FORMAT_FLAG_COLORMAP) != 0) if ((format & PNG_FORMAT_FLAG_COLORMAP) != 0)
@ -1943,24 +1993,24 @@ png_image_write_main(png_voidp argument)
png_uint_32 entries = image->colormap_entries; png_uint_32 entries = image->colormap_entries;
png_set_IHDR(png_ptr, info_ptr, image->width, image->height, png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
entries > 16 ? 8 : (entries > 4 ? 4 : (entries > 2 ? 2 : 1)), entries > 16 ? 8 : (entries > 4 ? 4 : (entries > 2 ? 2 : 1)),
PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_image_set_PLTE(display); png_image_set_PLTE(display);
} }
else else
png_error(image->opaque->png_ptr, png_error(image->opaque->png_ptr,
"no color-map for color-mapped image"); "no color-map for color-mapped image");
} }
else else
png_set_IHDR(png_ptr, info_ptr, image->width, image->height, png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
write_16bit ? 16 : 8, write_16bit ? 16 : 8,
((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) + ((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) +
((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0), ((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0),
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
/* Counter-intuitively the data transformations must be called *after* /* Counter-intuitively the data transformations must be called *after*
* png_write_info, not before as in the read code, but the 'set' functions * png_write_info, not before as in the read code, but the 'set' functions
@ -1975,11 +2025,11 @@ png_image_write_main(png_voidp argument)
if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0) if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0)
png_set_cHRM_fixed(png_ptr, info_ptr, png_set_cHRM_fixed(png_ptr, info_ptr,
/* color x y */ /* color x y */
/* white */ 31270, 32900, /* white */ 31270, 32900,
/* red */ 64000, 33000, /* red */ 64000, 33000,
/* green */ 30000, 60000, /* green */ 30000, 60000,
/* blue */ 15000, 6000 /* blue */ 15000, 6000
); );
} }
@ -1998,7 +2048,7 @@ png_image_write_main(png_voidp argument)
/* Now set up the data transformations (*after* the header is written), /* Now set up the data transformations (*after* the header is written),
* remove the handled transformations from the 'format' flags for checking. * remove the handled transformations from the 'format' flags for checking.
* *
* First check for a little endian system if writing 16 bit files. * First check for a little endian system if writing 16-bit files.
*/ */
if (write_16bit != 0) if (write_16bit != 0)
{ {
@ -2073,7 +2123,7 @@ png_image_write_main(png_voidp argument)
(colormap == 0 && display->convert_to_8bit != 0)) (colormap == 0 && display->convert_to_8bit != 0))
{ {
png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr, 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; int result;
display->local_row = row; display->local_row = row;
@ -2099,7 +2149,7 @@ png_image_write_main(png_voidp argument)
ptrdiff_t row_bytes = display->row_bytes; ptrdiff_t row_bytes = display->row_bytes;
png_uint_32 y = image->height; png_uint_32 y = image->height;
while (y-- > 0) for (; y > 0; --y)
{ {
png_write_row(png_ptr, row); png_write_row(png_ptr, row);
row += row_bytes; row += row_bytes;
@ -2110,14 +2160,130 @@ png_image_write_main(png_voidp argument)
return 1; return 1;
} }
static void (PNGCBAPI
image_memory_write)(png_structp png_ptr, png_bytep/*const*/ data,
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)*/);
const png_alloc_size_t ob = display->output_bytes;
/* Check for overflow; this should never happen: */
if (size <= ((png_alloc_size_t)-1) - ob)
{
/* I don't think libpng ever does this, but just in case: */
if (size > 0)
{
if (display->memory_bytes >= ob+size) /* writing */
memcpy(display->memory+ob, data, size);
/* Always update the size: */
display->output_bytes = ob+size;
}
}
else
png_error(png_ptr, "png_image_write_to_memory: PNG too big");
}
static void (PNGCBAPI
image_memory_flush)(png_structp png_ptr)
{
PNG_UNUSED(png_ptr)
}
static int
png_image_write_memory(png_voidp argument)
{
png_image_write_control *display = png_voidcast(png_image_write_control*,
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);
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)
{
/* Write the image to the given buffer, or count the bytes if it is NULL */
if (image != NULL && image->version == PNG_IMAGE_VERSION)
{
if (memory_bytes != NULL && buffer != NULL)
{
/* This is to give the caller an easier error detection in the NULL
* case and guard against uninitialized variable problems:
*/
if (memory == NULL)
*memory_bytes = 0;
if (png_image_write_init(image) != 0)
{
png_image_write_control display;
int result;
memset(&display, 0, (sizeof display));
display.image = image;
display.buffer = buffer;
display.row_stride = row_stride;
display.colormap = colormap;
display.convert_to_8bit = convert_to_8bit;
display.memory = png_voidcast(png_bytep, memory);
display.memory_bytes = *memory_bytes;
display.output_bytes = 0;
result = png_safe_execute(image, png_image_write_memory, &display);
png_image_free(image);
/* write_memory returns true even if we ran out of buffer. */
if (result)
{
/* On out-of-buffer this function returns '0' but still updates
* memory_bytes:
*/
if (memory != NULL && display.output_bytes > *memory_bytes)
result = 0;
*memory_bytes = display.output_bytes;
}
return result;
}
else
return 0;
}
else
return png_image_error(image,
"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");
else
return 0;
}
#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
int PNGAPI int PNGAPI
png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit, 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*). */ /* Write the image to the given (FILE*). */
if (image != NULL && image->version == PNG_IMAGE_VERSION) if (image != NULL && image->version == PNG_IMAGE_VERSION)
{ {
if (file != NULL) if (file != NULL && buffer != NULL)
{ {
if (png_image_write_init(image) != 0) if (png_image_write_init(image) != 0)
{ {
@ -2148,12 +2314,12 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
else else
return png_image_error(image, return png_image_error(image,
"png_image_write_to_stdio: invalid argument"); "png_image_write_to_stdio: invalid argument");
} }
else if (image != NULL) else if (image != NULL)
return png_image_error(image, return png_image_error(image,
"png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION"); "png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION");
else else
return 0; return 0;
@ -2161,20 +2327,20 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
int PNGAPI int PNGAPI
png_image_write_to_file(png_imagep image, const char *file_name, png_image_write_to_file(png_imagep image, const char *file_name,
int convert_to_8bit, const void *buffer, png_int_32 row_stride, int convert_to_8bit, const void *buffer, png_int_32 row_stride,
const void *colormap) const void *colormap)
{ {
/* Write the image to the named file. */ /* Write the image to the named file. */
if (image != NULL && image->version == PNG_IMAGE_VERSION) if (image != NULL && image->version == PNG_IMAGE_VERSION)
{ {
if (file_name != NULL) if (file_name != NULL && buffer != NULL)
{ {
FILE *fp = fopen(file_name, "wb"); FILE *fp = fopen(file_name, "wb");
if (fp != NULL) if (fp != NULL)
{ {
if (png_image_write_to_stdio(image, fp, convert_to_8bit, buffer, 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 */ int error; /* from fflush/fclose */
@ -2215,16 +2381,16 @@ png_image_write_to_file(png_imagep image, const char *file_name,
else else
return png_image_error(image, return png_image_error(image,
"png_image_write_to_file: invalid argument"); "png_image_write_to_file: invalid argument");
} }
else if (image != NULL) else if (image != NULL)
return png_image_error(image, return png_image_error(image,
"png_image_write_to_file: incorrect PNG_IMAGE_VERSION"); "png_image_write_to_file: incorrect PNG_IMAGE_VERSION");
else else
return 0; return 0;
} }
# endif /* STDIO */ #endif /* SIMPLIFIED_WRITE_STDIO */
#endif /* SIMPLIFIED_WRITE */ #endif /* SIMPLIFIED_WRITE */
#endif /* WRITE */ #endif /* WRITE */

View File

@ -1,8 +1,8 @@
/* pngwtran.c - transforms the data in a row for PNG writers /* pngwtran.c - transforms the data in a row for PNG writers
* *
* Last changed in libpng 1.6.18 [July 23, 2015] * Last changed in libpng 1.6.26 [October 20, 2016]
* Copyright (c) 1998-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.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (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) if (row_info->color_type != PNG_COLOR_TYPE_PALETTE)
{ {
int shift_start[4], shift_dec[4]; int shift_start[4], shift_dec[4];
int channels = 0; unsigned int channels = 0;
if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 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 #ifdef PNG_WRITE_FILLER_SUPPORTED
if ((png_ptr->transformations & PNG_FILLER) != 0) if ((png_ptr->transformations & PNG_FILLER) != 0)
png_do_strip_channel(row_info, png_ptr->row_buf + 1, 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 #endif
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED #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 #ifdef PNG_WRITE_SHIFT_SUPPORTED
if ((png_ptr->transformations & PNG_SHIFT) != 0) if ((png_ptr->transformations & PNG_SHIFT) != 0)
png_do_shift(row_info, png_ptr->row_buf + 1, png_do_shift(row_info, png_ptr->row_buf + 1,
&(png_ptr->shift)); &(png_ptr->shift));
#endif #endif
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED

View File

@ -1,8 +1,8 @@
/* pngwutil.c - utilities to write a PNG file /* pngwutil.c - utilities to write a PNG file
* *
* Last changed in libpng 1.6.18 [July 23, 2015] * Last changed in libpng 1.6.32 [August 24, 2017]
* Copyright (c) 1998-2015 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@ -23,10 +23,10 @@
void PNGAPI void PNGAPI
png_save_uint_32(png_bytep buf, png_uint_32 i) png_save_uint_32(png_bytep buf, png_uint_32 i)
{ {
buf[0] = (png_byte)(i >> 24); buf[0] = (png_byte)((i >> 24) & 0xffU);
buf[1] = (png_byte)(i >> 16); buf[1] = (png_byte)((i >> 16) & 0xffU);
buf[2] = (png_byte)(i >> 8); buf[2] = (png_byte)((i >> 8) & 0xffU);
buf[3] = (png_byte)(i ); buf[3] = (png_byte)( i & 0xffU);
} }
/* Place a 16-bit number into a buffer in PNG byte order. /* Place a 16-bit number into a buffer in PNG byte order.
@ -36,8 +36,8 @@ png_save_uint_32(png_bytep buf, png_uint_32 i)
void PNGAPI void PNGAPI
png_save_uint_16(png_bytep buf, unsigned int i) png_save_uint_16(png_bytep buf, unsigned int i)
{ {
buf[0] = (png_byte)(i >> 8); buf[0] = (png_byte)((i >> 8) & 0xffU);
buf[1] = (png_byte)(i ); buf[1] = (png_byte)( i & 0xffU);
} }
#endif #endif
@ -59,7 +59,7 @@ png_write_sig(png_structrp png_ptr)
/* Write the rest of the 8 byte signature */ /* Write the rest of the 8 byte signature */
png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes], png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
(png_size_t)(8 - png_ptr->sig_bytes)); (png_size_t)(8 - png_ptr->sig_bytes));
if (png_ptr->sig_bytes < 3) if (png_ptr->sig_bytes < 3)
png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
@ -174,12 +174,12 @@ png_write_chunk_end(png_structrp png_ptr)
*/ */
static void static void
png_write_complete_chunk(png_structrp png_ptr, png_uint_32 chunk_name, png_write_complete_chunk(png_structrp png_ptr, png_uint_32 chunk_name,
png_const_bytep data, png_size_t length) png_const_bytep data, png_size_t length)
{ {
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
/* On 64 bit architectures 'length' may not fit in a png_uint_32. */ /* On 64-bit architectures 'length' may not fit in a png_uint_32. */
if (length > PNG_UINT_31_MAX) if (length > PNG_UINT_31_MAX)
png_error(png_ptr, "length exceeds PNG maximum"); png_error(png_ptr, "length exceeds PNG maximum");
@ -191,10 +191,10 @@ png_write_complete_chunk(png_structrp png_ptr, png_uint_32 chunk_name,
/* This is the API that calls the internal function above. */ /* This is the API that calls the internal function above. */
void PNGAPI void PNGAPI
png_write_chunk(png_structrp png_ptr, png_const_bytep chunk_string, png_write_chunk(png_structrp png_ptr, png_const_bytep chunk_string,
png_const_bytep data, png_size_t length) png_const_bytep data, png_size_t length)
{ {
png_write_complete_chunk(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), data, png_write_complete_chunk(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), data,
length); length);
} }
/* This is used below to find the size of an image to pass to png_deflate_claim, /* This is used below to find the size of an image to pass to png_deflate_claim,
@ -291,7 +291,7 @@ optimize_cmf(png_bytep data, png_alloc_size_t data_size)
/* Initialize the compressor for the appropriate type of compression. */ /* Initialize the compressor for the appropriate type of compression. */
static int static int
png_deflate_claim(png_structrp png_ptr, png_uint_32 owner, png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
png_alloc_size_t data_size) png_alloc_size_t data_size)
{ {
if (png_ptr->zowner != 0) if (png_ptr->zowner != 0)
{ {
@ -408,7 +408,7 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
png_ptr->zstream.avail_out = 0; png_ptr->zstream.avail_out = 0;
/* Now initialize if required, setting the new parameters, otherwise just /* Now initialize if required, setting the new parameters, otherwise just
* to a simple reset to the previous parameters. * do a simple reset to the previous parameters.
*/ */
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0) if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)
ret = deflateReset(&png_ptr->zstream); ret = deflateReset(&png_ptr->zstream);
@ -416,7 +416,7 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
else else
{ {
ret = deflateInit2(&png_ptr->zstream, level, method, windowBits, ret = deflateInit2(&png_ptr->zstream, level, method, windowBits,
memLevel, strategy); memLevel, strategy);
if (ret == Z_OK) if (ret == Z_OK)
png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED; png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;
@ -477,7 +477,7 @@ typedef struct
static void static void
png_text_compress_init(compression_state *comp, png_const_bytep input, png_text_compress_init(compression_state *comp, png_const_bytep input,
png_alloc_size_t input_len) png_alloc_size_t input_len)
{ {
comp->input = input; comp->input = input;
comp->input_len = input_len; comp->input_len = input_len;
@ -487,7 +487,7 @@ png_text_compress_init(compression_state *comp, png_const_bytep input,
/* Compress the data in the compression state input */ /* Compress the data in the compression state input */
static int static int
png_text_compress(png_structrp png_ptr, png_uint_32 chunk_name, png_text_compress(png_structrp png_ptr, png_uint_32 chunk_name,
compression_state *comp, png_uint_32 prefix_len) compression_state *comp, png_uint_32 prefix_len)
{ {
int ret; int ret;
@ -579,7 +579,7 @@ png_text_compress(png_structrp png_ptr, png_uint_32 chunk_name,
/* Compress the data */ /* Compress the data */
ret = deflate(&png_ptr->zstream, ret = deflate(&png_ptr->zstream,
input_len > 0 ? Z_NO_FLUSH : Z_FINISH); input_len > 0 ? Z_NO_FLUSH : Z_FINISH);
/* Claw back input data that was not consumed (because avail_in is /* Claw back input data that was not consumed (because avail_in is
* reset above every time round the loop). * reset above every time round the loop).
@ -665,90 +665,6 @@ png_write_compressed_data_out(png_structrp png_ptr, compression_state *comp)
} }
#endif /* WRITE_COMPRESSED_TEXT */ #endif /* WRITE_COMPRESSED_TEXT */
#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification,
* and if invalid, correct the keyword rather than discarding the entire
* chunk. The PNG 1.0 specification requires keywords 1-79 characters in
* length, forbids leading or trailing whitespace, multiple internal spaces,
* and the non-break space (0x80) from ISO 8859-1. Returns keyword length.
*
* The 'new_key' buffer must be 80 characters in size (for the keyword plus a
* trailing '\0'). If this routine returns 0 then there was no keyword, or a
* valid one could not be generated, and the caller must png_error.
*/
static png_uint_32
png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
{
png_const_charp orig_key = key;
png_uint_32 key_len = 0;
int bad_character = 0;
int space = 1;
png_debug(1, "in png_check_keyword");
if (key == NULL)
{
*new_key = 0;
return 0;
}
while (*key && key_len < 79)
{
png_byte ch = (png_byte)*key++;
if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/))
*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;
/* If the character was not a space then it is invalid. */
if (ch != 32)
bad_character = ch;
}
else if (bad_character == 0)
bad_character = ch; /* just skip it, record the first error */
}
if (key_len > 0 && space != 0) /* trailing space */
{
--key_len, --new_key;
if (bad_character == 0)
bad_character = 32;
}
/* Terminate the keyword */
*new_key = 0;
if (key_len == 0)
return 0;
#ifdef PNG_WARNINGS_SUPPORTED
/* Try to only output one warning per keyword: */
if (*key != 0) /* keyword too long */
png_warning(png_ptr, "keyword truncated");
else if (bad_character != 0)
{
PNG_WARNING_PARAMETERS(p)
png_warning_parameter(p, 1, orig_key);
png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_02x, bad_character);
png_formatted_warning(png_ptr, p, "keyword \"@1\": bad character '0x@2'");
}
#endif /* WARNINGS */
return key_len;
}
#endif /* WRITE_TEXT || WRITE_pCAL || WRITE_iCCP || WRITE_sPLT */
/* Write the IHDR chunk, and update the png_struct with the necessary /* Write the IHDR chunk, and update the png_struct with the necessary
* information. Note that the rest of this code depends upon this * information. Note that the rest of this code depends upon this
* information being correct. * information being correct.
@ -759,6 +675,7 @@ png_write_IHDR(png_structrp png_ptr, png_uint_32 width, png_uint_32 height,
int interlace_type) int interlace_type)
{ {
png_byte buf[13]; /* Buffer to store the IHDR info */ png_byte buf[13]; /* Buffer to store the IHDR info */
int is_invalid_depth;
png_debug(1, "in png_write_IHDR"); png_debug(1, "in png_write_IHDR");
@ -784,11 +701,11 @@ png_write_IHDR(png_structrp png_ptr, png_uint_32 width, png_uint_32 height,
break; break;
case PNG_COLOR_TYPE_RGB: case PNG_COLOR_TYPE_RGB:
is_invalid_depth = (bit_depth != 8);
#ifdef PNG_WRITE_16BIT_SUPPORTED #ifdef PNG_WRITE_16BIT_SUPPORTED
if (bit_depth != 8 && bit_depth != 16) is_invalid_depth = (is_invalid_depth && bit_depth != 16);
#else
if (bit_depth != 8)
#endif #endif
if (is_invalid_depth)
png_error(png_ptr, "Invalid bit depth for RGB image"); png_error(png_ptr, "Invalid bit depth for RGB image");
png_ptr->channels = 3; png_ptr->channels = 3;
@ -810,18 +727,22 @@ png_write_IHDR(png_structrp png_ptr, png_uint_32 width, png_uint_32 height,
break; break;
case PNG_COLOR_TYPE_GRAY_ALPHA: case PNG_COLOR_TYPE_GRAY_ALPHA:
if (bit_depth != 8 && bit_depth != 16) is_invalid_depth = (bit_depth != 8);
#ifdef PNG_WRITE_16BIT_SUPPORTED
is_invalid_depth = (is_invalid_depth && bit_depth != 16);
#endif
if (is_invalid_depth)
png_error(png_ptr, "Invalid bit depth for grayscale+alpha image"); png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
png_ptr->channels = 2; png_ptr->channels = 2;
break; break;
case PNG_COLOR_TYPE_RGB_ALPHA: case PNG_COLOR_TYPE_RGB_ALPHA:
is_invalid_depth = (bit_depth != 8);
#ifdef PNG_WRITE_16BIT_SUPPORTED #ifdef PNG_WRITE_16BIT_SUPPORTED
if (bit_depth != 8 && bit_depth != 16) is_invalid_depth = (is_invalid_depth && bit_depth != 16);
#else
if (bit_depth != 8)
#endif #endif
if (is_invalid_depth)
png_error(png_ptr, "Invalid bit depth for RGBA image"); png_error(png_ptr, "Invalid bit depth for RGBA image");
png_ptr->channels = 4; png_ptr->channels = 4;
@ -922,17 +843,20 @@ void /* PRIVATE */
png_write_PLTE(png_structrp png_ptr, png_const_colorp palette, png_write_PLTE(png_structrp png_ptr, png_const_colorp palette,
png_uint_32 num_pal) png_uint_32 num_pal)
{ {
png_uint_32 i; png_uint_32 max_palette_length, i;
png_const_colorp pal_ptr; png_const_colorp pal_ptr;
png_byte buf[3]; png_byte buf[3];
png_debug(1, "in png_write_PLTE"); png_debug(1, "in png_write_PLTE");
max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ?
(1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH;
if (( if ((
#ifdef PNG_MNG_FEATURES_SUPPORTED #ifdef PNG_MNG_FEATURES_SUPPORTED
(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 && (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 &&
#endif #endif
num_pal == 0) || num_pal > 256) num_pal == 0) || num_pal > max_palette_length)
{ {
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{ {
@ -1006,7 +930,7 @@ png_write_PLTE(png_structrp png_ptr, png_const_colorp palette,
*/ */
void /* PRIVATE */ void /* PRIVATE */
png_compress_IDAT(png_structrp png_ptr, png_const_bytep input, png_compress_IDAT(png_structrp png_ptr, png_const_bytep input,
png_alloc_size_t input_len, int flush) png_alloc_size_t input_len, int flush)
{ {
if (png_ptr->zowner != png_IDAT) if (png_ptr->zowner != png_IDAT)
{ {
@ -1018,7 +942,7 @@ png_compress_IDAT(png_structrp png_ptr, png_const_bytep input,
if (png_ptr->zbuffer_list == NULL) if (png_ptr->zbuffer_list == NULL)
{ {
png_ptr->zbuffer_list = png_voidcast(png_compression_bufferp, png_ptr->zbuffer_list = png_voidcast(png_compression_bufferp,
png_malloc(png_ptr, PNG_COMPRESSION_BUFFER_SIZE(png_ptr))); png_malloc(png_ptr, PNG_COMPRESSION_BUFFER_SIZE(png_ptr)));
png_ptr->zbuffer_list->next = NULL; png_ptr->zbuffer_list->next = NULL;
} }
@ -1079,7 +1003,8 @@ png_compress_IDAT(png_structrp png_ptr, png_const_bytep input,
optimize_cmf(data, png_image_size(png_ptr)); optimize_cmf(data, png_image_size(png_ptr));
#endif #endif
png_write_complete_chunk(png_ptr, png_IDAT, data, size); if (size > 0)
png_write_complete_chunk(png_ptr, png_IDAT, data, size);
png_ptr->mode |= PNG_HAVE_IDAT; png_ptr->mode |= PNG_HAVE_IDAT;
png_ptr->zstream.next_out = data; png_ptr->zstream.next_out = data;
@ -1125,7 +1050,8 @@ png_compress_IDAT(png_structrp png_ptr, png_const_bytep input,
optimize_cmf(data, png_image_size(png_ptr)); optimize_cmf(data, png_image_size(png_ptr));
#endif #endif
png_write_complete_chunk(png_ptr, png_IDAT, data, size); if (size > 0)
png_write_complete_chunk(png_ptr, png_IDAT, data, size);
png_ptr->zstream.avail_out = 0; png_ptr->zstream.avail_out = 0;
png_ptr->zstream.next_out = NULL; png_ptr->zstream.next_out = NULL;
png_ptr->mode |= PNG_HAVE_IDAT | PNG_AFTER_IDAT; png_ptr->mode |= PNG_HAVE_IDAT | PNG_AFTER_IDAT;
@ -1257,7 +1183,7 @@ png_write_sPLT(png_structrp png_ptr, png_const_sPLT_tp spalette)
png_byte new_name[80]; png_byte new_name[80];
png_byte entrybuf[10]; png_byte entrybuf[10];
png_size_t entry_size = (spalette->depth == 8 ? 6 : 10); png_size_t entry_size = (spalette->depth == 8 ? 6 : 10);
png_size_t palette_size = entry_size * spalette->nentries; png_size_t palette_size = entry_size * (png_size_t)spalette->nentries;
png_sPLT_entryp ep; png_sPLT_entryp ep;
#ifndef PNG_POINTER_INDEXING_SUPPORTED #ifndef PNG_POINTER_INDEXING_SUPPORTED
int i; int i;
@ -1439,12 +1365,12 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,
/* Write the chunk out as it is */ /* Write the chunk out as it is */
png_write_complete_chunk(png_ptr, png_tRNS, trans_alpha, png_write_complete_chunk(png_ptr, png_tRNS, trans_alpha,
(png_size_t)num_trans); (png_size_t)num_trans);
} }
else if (color_type == PNG_COLOR_TYPE_GRAY) else if (color_type == PNG_COLOR_TYPE_GRAY)
{ {
/* One 16 bit value */ /* One 16-bit value */
if (tran->gray >= (1 << png_ptr->bit_depth)) if (tran->gray >= (1 << png_ptr->bit_depth))
{ {
png_app_warning(png_ptr, png_app_warning(png_ptr,
@ -1459,7 +1385,7 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,
else if (color_type == PNG_COLOR_TYPE_RGB) else if (color_type == PNG_COLOR_TYPE_RGB)
{ {
/* Three 16 bit values */ /* Three 16-bit values */
png_save_uint_16(buf, tran->red); png_save_uint_16(buf, tran->red);
png_save_uint_16(buf + 2, tran->green); png_save_uint_16(buf + 2, tran->green);
png_save_uint_16(buf + 4, tran->blue); png_save_uint_16(buf + 4, tran->blue);
@ -1470,7 +1396,7 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,
#endif #endif
{ {
png_app_warning(png_ptr, png_app_warning(png_ptr,
"Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8"); "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
return; return;
} }
@ -1522,7 +1448,8 @@ png_write_bKGD(png_structrp png_ptr, png_const_color_16p back, int color_type)
#endif #endif
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8"); "Ignoring attempt to write 16-bit bKGD chunk "
"when bit_depth is 8");
return; return;
} }
@ -1546,6 +1473,28 @@ png_write_bKGD(png_structrp png_ptr, png_const_color_16p back, int color_type)
} }
#endif #endif
#ifdef PNG_WRITE_eXIf_SUPPORTED
/* Write the Exif data */
void /* PRIVATE */
png_write_eXIf(png_structrp png_ptr, png_bytep exif, int num_exif)
{
int i;
png_byte buf[1];
png_debug(1, "in png_write_eXIf");
png_write_chunk_header(png_ptr, png_eXIf, (png_uint_32)(num_exif));
for (i = 0; i < num_exif; i++)
{
buf[0] = exif[i];
png_write_chunk_data(png_ptr, buf, (png_size_t)1);
}
png_write_chunk_end(png_ptr);
}
#endif
#ifdef PNG_WRITE_hIST_SUPPORTED #ifdef PNG_WRITE_hIST_SUPPORTED
/* Write the histogram */ /* Write the histogram */
void /* PRIVATE */ void /* PRIVATE */
@ -1652,7 +1601,7 @@ png_write_zTXt(png_structrp png_ptr, png_const_charp key, png_const_charp text,
/* Compute the compressed data; do it now for the length */ /* Compute the compressed data; do it now for the length */
png_text_compress_init(&comp, (png_const_bytep)text, png_text_compress_init(&comp, (png_const_bytep)text,
text == NULL ? 0 : strlen(text)); text == NULL ? 0 : strlen(text));
if (png_text_compress(png_ptr, png_zTXt, &comp, key_len) != Z_OK) if (png_text_compress(png_ptr, png_zTXt, &comp, key_len) != Z_OK)
png_error(png_ptr, png_ptr->zstream.msg); png_error(png_ptr, png_ptr->zstream.msg);
@ -1823,7 +1772,7 @@ png_write_pCAL(png_structrp png_ptr, png_charp purpose, png_int_32 X0,
total_len = purpose_len + units_len + 10; total_len = purpose_len + units_len + 10;
params_len = (png_size_tp)png_malloc(png_ptr, params_len = (png_size_tp)png_malloc(png_ptr,
(png_alloc_size_t)(nparams * (sizeof (png_size_t)))); (png_alloc_size_t)((png_alloc_size_t)nparams * (sizeof (png_size_t))));
/* Find the length of each parameter, making sure we don't count the /* Find the length of each parameter, making sure we don't count the
* null terminator for the last parameter. * null terminator for the last parameter.
@ -2022,7 +1971,7 @@ png_write_start_row(png_structrp png_ptr)
*/ */
if ((filters & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) != 0) if ((filters & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) != 0)
png_ptr->prev_row = png_voidcast(png_bytep, png_ptr->prev_row = png_voidcast(png_bytep,
png_calloc(png_ptr, buf_size)); png_calloc(png_ptr, buf_size));
#endif /* WRITE_FILTER */ #endif /* WRITE_FILTER */
#ifdef PNG_WRITE_INTERLACING_SUPPORTED #ifdef PNG_WRITE_INTERLACING_SUPPORTED
@ -2325,7 +2274,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
*/ */
static void /* PRIVATE */ static void /* PRIVATE */
png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row, png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row,
png_size_t row_bytes); png_size_t row_bytes);
#ifdef PNG_WRITE_FILTER_SUPPORTED #ifdef PNG_WRITE_FILTER_SUPPORTED
static png_size_t /* PRIVATE */ static png_size_t /* PRIVATE */
@ -2335,7 +2284,7 @@ png_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp,
png_bytep rp, dp, lp; png_bytep rp, dp, lp;
png_size_t i; png_size_t i;
png_size_t sum = 0; png_size_t sum = 0;
int v; unsigned int v;
png_ptr->try_row[0] = PNG_FILTER_VALUE_SUB; png_ptr->try_row[0] = PNG_FILTER_VALUE_SUB;
@ -2343,14 +2292,22 @@ png_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp,
i++, rp++, dp++) i++, rp++, dp++)
{ {
v = *dp = *rp; v = *dp = *rp;
#ifdef PNG_USE_ABS
sum += 128 - abs((int)v - 128);
#else
sum += (v < 128) ? v : 256 - v; sum += (v < 128) ? v : 256 - v;
#endif
} }
for (lp = png_ptr->row_buf + 1; i < row_bytes; for (lp = png_ptr->row_buf + 1; i < row_bytes;
i++, rp++, lp++, dp++) i++, rp++, lp++, dp++)
{ {
v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
#ifdef PNG_USE_ABS
sum += 128 - abs((int)v - 128);
#else
sum += (v < 128) ? v : 256 - v; sum += (v < 128) ? v : 256 - v;
#endif
if (sum > lmins) /* We are already worse, don't continue. */ if (sum > lmins) /* We are already worse, don't continue. */
break; break;
@ -2359,6 +2316,28 @@ png_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp,
return (sum); return (sum);
} }
static void /* PRIVATE */
png_setup_sub_row_only(png_structrp png_ptr, const png_uint_32 bpp,
const png_size_t row_bytes)
{
png_bytep rp, dp, lp;
png_size_t i;
png_ptr->try_row[0] = PNG_FILTER_VALUE_SUB;
for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1; i < bpp;
i++, rp++, dp++)
{
*dp = *rp;
}
for (lp = png_ptr->row_buf + 1; i < row_bytes;
i++, rp++, lp++, dp++)
{
*dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
}
}
static png_size_t /* PRIVATE */ static png_size_t /* PRIVATE */
png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes, png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
const png_size_t lmins) const png_size_t lmins)
@ -2366,7 +2345,7 @@ png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
png_bytep rp, dp, pp; png_bytep rp, dp, pp;
png_size_t i; png_size_t i;
png_size_t sum = 0; png_size_t sum = 0;
int v; unsigned int v;
png_ptr->try_row[0] = PNG_FILTER_VALUE_UP; png_ptr->try_row[0] = PNG_FILTER_VALUE_UP;
@ -2375,7 +2354,11 @@ png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
i++, rp++, pp++, dp++) i++, rp++, pp++, dp++)
{ {
v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
#ifdef PNG_USE_ABS
sum += 128 - abs((int)v - 128);
#else
sum += (v < 128) ? v : 256 - v; sum += (v < 128) ? v : 256 - v;
#endif
if (sum > lmins) /* We are already worse, don't continue. */ if (sum > lmins) /* We are already worse, don't continue. */
break; break;
@ -2383,24 +2366,43 @@ png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
return (sum); return (sum);
} }
static void /* PRIVATE */
png_setup_up_row_only(png_structrp png_ptr, const png_size_t row_bytes)
{
png_bytep rp, dp, pp;
png_size_t i;
png_ptr->try_row[0] = PNG_FILTER_VALUE_UP;
for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,
pp = png_ptr->prev_row + 1; i < row_bytes;
i++, rp++, pp++, dp++)
{
*dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
}
}
static png_size_t /* PRIVATE */ static png_size_t /* PRIVATE */
png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp, png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,
const png_size_t row_bytes, const png_size_t lmins) const png_size_t row_bytes, const png_size_t lmins)
{ {
png_bytep rp, dp, pp, lp; png_bytep rp, dp, pp, lp;
png_uint_32 i; png_uint_32 i;
png_size_t sum = 0; png_size_t sum = 0;
int v; unsigned int v;
png_ptr->try_row[0] = PNG_FILTER_VALUE_AVG; png_ptr->try_row[0] = PNG_FILTER_VALUE_AVG;
for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,
pp = png_ptr->prev_row + 1; i < bpp; i++) pp = png_ptr->prev_row + 1; i < bpp; i++)
{ {
v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
#ifdef PNG_USE_ABS
sum += 128 - abs((int)v - 128);
#else
sum += (v < 128) ? v : 256 - v; sum += (v < 128) ? v : 256 - v;
#endif
} }
for (lp = png_ptr->row_buf + 1; i < row_bytes; i++) for (lp = png_ptr->row_buf + 1; i < row_bytes; i++)
@ -2408,7 +2410,11 @@ png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,
v = *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) v = *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
& 0xff); & 0xff);
#ifdef PNG_USE_ABS
sum += 128 - abs((int)v - 128);
#else
sum += (v < 128) ? v : 256 - v; sum += (v < 128) ? v : 256 - v;
#endif
if (sum > lmins) /* We are already worse, don't continue. */ if (sum > lmins) /* We are already worse, don't continue. */
break; break;
@ -2416,6 +2422,27 @@ png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,
return (sum); return (sum);
} }
static void /* PRIVATE */
png_setup_avg_row_only(png_structrp png_ptr, const png_uint_32 bpp,
const png_size_t row_bytes)
{
png_bytep rp, dp, pp, lp;
png_uint_32 i;
png_ptr->try_row[0] = PNG_FILTER_VALUE_AVG;
for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,
pp = png_ptr->prev_row + 1; i < bpp; i++)
{
*dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
}
for (lp = png_ptr->row_buf + 1; i < row_bytes; i++)
{
*dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
& 0xff);
}
}
static png_size_t /* PRIVATE */ static png_size_t /* PRIVATE */
png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp, png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
@ -2424,7 +2451,7 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
png_bytep rp, dp, pp, cp, lp; png_bytep rp, dp, pp, cp, lp;
png_size_t i; png_size_t i;
png_size_t sum = 0; png_size_t sum = 0;
int v; unsigned int v;
png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH; png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH;
@ -2433,7 +2460,11 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
{ {
v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
#ifdef PNG_USE_ABS
sum += 128 - abs((int)v - 128);
#else
sum += (v < 128) ? v : 256 - v; sum += (v < 128) ? v : 256 - v;
#endif
} }
for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes; for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes;
@ -2462,7 +2493,11 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
#ifdef PNG_USE_ABS
sum += 128 - abs((int)v - 128);
#else
sum += (v < 128) ? v : 256 - v; sum += (v < 128) ? v : 256 - v;
#endif
if (sum > lmins) /* We are already worse, don't continue. */ if (sum > lmins) /* We are already worse, don't continue. */
break; break;
@ -2470,6 +2505,48 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
return (sum); return (sum);
} }
static void /* PRIVATE */
png_setup_paeth_row_only(png_structrp png_ptr, const png_uint_32 bpp,
const png_size_t row_bytes)
{
png_bytep rp, dp, pp, cp, lp;
png_size_t i;
png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH;
for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,
pp = png_ptr->prev_row + 1; i < bpp; i++)
{
*dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
}
for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes;
i++)
{
int a, b, c, pa, pb, pc, p;
b = *pp++;
c = *cp++;
a = *lp++;
p = b - c;
pc = a - c;
#ifdef PNG_USE_ABS
pa = abs(p);
pb = abs(pc);
pc = abs(p + pc);
#else
pa = p < 0 ? -p : p;
pb = pc < 0 ? -pc : pc;
pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif
p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
*dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
}
}
#endif /* WRITE_FILTER */ #endif /* WRITE_FILTER */
void /* PRIVATE */ void /* PRIVATE */
@ -2478,7 +2555,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
#ifndef PNG_WRITE_FILTER_SUPPORTED #ifndef PNG_WRITE_FILTER_SUPPORTED
png_write_filtered_row(png_ptr, png_ptr->row_buf, row_info->rowbytes+1); png_write_filtered_row(png_ptr, png_ptr->row_buf, row_info->rowbytes+1);
#else #else
png_byte filter_to_do = png_ptr->do_filter; unsigned int filter_to_do = png_ptr->do_filter;
png_bytep row_buf; png_bytep row_buf;
png_bytep best_row; png_bytep best_row;
png_uint_32 bpp; png_uint_32 bpp;
@ -2524,32 +2601,33 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
*/ */
best_row = png_ptr->row_buf; best_row = png_ptr->row_buf;
if (PNG_SIZE_MAX/128 <= row_bytes)
if ((filter_to_do & PNG_FILTER_NONE) != 0 && filter_to_do != PNG_FILTER_NONE)
{ {
/* Overflow can occur in the calculation, just select the lowest set
* filter.
*/
filter_to_do &= 0U-filter_to_do;
}
else if ((filter_to_do & PNG_FILTER_NONE) != 0 &&
filter_to_do != PNG_FILTER_NONE)
{
/* Overflow not possible and multiple filters in the list, including the
* 'none' filter.
*/
png_bytep rp; png_bytep rp;
png_size_t sum = 0; png_size_t sum = 0;
png_size_t i; png_size_t i;
int v; unsigned int v;
if (PNG_SIZE_MAX/128 <= row_bytes)
{
for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
{
/* Check for overflow */
if (sum > PNG_SIZE_MAX/128 - 256)
break;
v = *rp;
sum += (v < 128) ? v : 256 - v;
}
}
else /* Overflow is not possible */
{ {
for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++) for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
{ {
v = *rp; v = *rp;
#ifdef PNG_USE_ABS
sum += 128 - abs((int)v - 128);
#else
sum += (v < 128) ? v : 256 - v; sum += (v < 128) ? v : 256 - v;
#endif
} }
} }
@ -2560,7 +2638,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
if (filter_to_do == PNG_FILTER_SUB) if (filter_to_do == PNG_FILTER_SUB)
/* It's the only filter so no testing is needed */ /* It's the only filter so no testing is needed */
{ {
(void) png_setup_sub_row(png_ptr, bpp, row_bytes, mins); png_setup_sub_row_only(png_ptr, bpp, row_bytes);
best_row = png_ptr->try_row; best_row = png_ptr->try_row;
} }
@ -2569,7 +2647,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
png_size_t sum; png_size_t sum;
png_size_t lmins = mins; png_size_t lmins = mins;
sum = png_setup_sub_row(png_ptr, bpp, row_bytes, lmins); sum = png_setup_sub_row(png_ptr, bpp, row_bytes, lmins);
if (sum < mins) if (sum < mins)
{ {
@ -2586,7 +2664,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
/* Up filter */ /* Up filter */
if (filter_to_do == PNG_FILTER_UP) if (filter_to_do == PNG_FILTER_UP)
{ {
(void) png_setup_up_row(png_ptr, row_bytes, mins); png_setup_up_row_only(png_ptr, row_bytes);
best_row = png_ptr->try_row; best_row = png_ptr->try_row;
} }
@ -2595,7 +2673,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
png_size_t sum; png_size_t sum;
png_size_t lmins = mins; png_size_t lmins = mins;
sum = png_setup_up_row(png_ptr, row_bytes, lmins); sum = png_setup_up_row(png_ptr, row_bytes, lmins);
if (sum < mins) if (sum < mins)
{ {
@ -2612,7 +2690,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
/* Avg filter */ /* Avg filter */
if (filter_to_do == PNG_FILTER_AVG) if (filter_to_do == PNG_FILTER_AVG)
{ {
(void) png_setup_avg_row(png_ptr, bpp, row_bytes, mins); png_setup_avg_row_only(png_ptr, bpp, row_bytes);
best_row = png_ptr->try_row; best_row = png_ptr->try_row;
} }
@ -2636,9 +2714,9 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
} }
/* Paeth filter */ /* Paeth filter */
if ((filter_to_do == PNG_FILTER_PAETH) != 0) if (filter_to_do == PNG_FILTER_PAETH)
{ {
(void) png_setup_paeth_row(png_ptr, bpp, row_bytes, mins); png_setup_paeth_row_only(png_ptr, bpp, row_bytes);
best_row = png_ptr->try_row; best_row = png_ptr->try_row;
} }
@ -2651,7 +2729,6 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
if (sum < mins) if (sum < mins)
{ {
mins = sum;
best_row = png_ptr->try_row; best_row = png_ptr->try_row;
if (png_ptr->tst_row != NULL) if (png_ptr->tst_row != NULL)
{ {
@ -2671,7 +2748,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
/* Do the actual writing of a previously filtered row. */ /* Do the actual writing of a previously filtered row. */
static void static void
png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row, png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row,
png_size_t full_row_length/*includes filter byte*/) png_size_t full_row_length/*includes filter byte*/)
{ {
png_debug(1, "in png_write_filtered_row"); png_debug(1, "in png_write_filtered_row");