mirror of https://github.com/stella-emu/stella.git
Updated libpng to latest release.
This commit is contained in:
parent
8d805eb4f3
commit
26f4aa91a6
542
src/libpng/png.c
542
src/libpng/png.c
File diff suppressed because it is too large
Load Diff
753
src/libpng/png.h
753
src/libpng/png.h
File diff suppressed because it is too large
Load Diff
|
@ -1,9 +1,9 @@
|
|||
|
||||
/* pngconf.h - machine configurable file for libpng
|
||||
*
|
||||
* libpng version 1.6.18, July 23, 2015
|
||||
* libpng version 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.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -63,7 +63,7 @@
|
|||
*/
|
||||
#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
|
||||
* just changes whether a macro is used when the function is called.
|
||||
* 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.
|
||||
*/
|
||||
# if PNG_API_RULE == 2
|
||||
/* If this line results in an error, either because __watcall is not
|
||||
* understood or because of a redefine just below you cannot use *this*
|
||||
* build of the library with the compiler you are using. *This* build was
|
||||
* build using Watcom and applications must also be built using Watcom!
|
||||
*/
|
||||
/* If this line results in an error, either because __watcall is not
|
||||
* understood or because of a redefine just below you cannot use *this*
|
||||
* build of the library with the compiler you are using. *This* build was
|
||||
* build using Watcom and applications must also be built using Watcom!
|
||||
*/
|
||||
# define PNGCAPI __watcall
|
||||
# endif
|
||||
|
||||
# if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800))
|
||||
# define PNGCAPI __cdecl
|
||||
# if PNG_API_RULE == 1
|
||||
/* If this line results in an error __stdcall is not understood and
|
||||
* PNG_API_RULE should not have been set to '1'.
|
||||
*/
|
||||
/* If this line results in an error __stdcall is not understood and
|
||||
* PNG_API_RULE should not have been set to '1'.
|
||||
*/
|
||||
# define PNGAPI __stdcall
|
||||
# endif
|
||||
# else
|
||||
/* An older compiler, or one not detected (erroneously) above,
|
||||
* if necessary override on the command line to get the correct
|
||||
* variants for the compiler.
|
||||
*/
|
||||
/* An older compiler, or one not detected (erroneously) above,
|
||||
* if necessary override on the command line to get the correct
|
||||
* variants for the compiler.
|
||||
*/
|
||||
# ifndef PNGCAPI
|
||||
# define PNGCAPI _cdecl
|
||||
# endif
|
||||
|
@ -225,10 +225,10 @@
|
|||
|
||||
# if (defined(_MSC_VER) && _MSC_VER < 800) ||\
|
||||
(defined(__BORLANDC__) && __BORLANDC__ < 0x500)
|
||||
/* older Borland and MSC
|
||||
* compilers used '__export' and required this to be after
|
||||
* the type.
|
||||
*/
|
||||
/* older Borland and MSC
|
||||
* compilers used '__export' and required this to be after
|
||||
* the type.
|
||||
*/
|
||||
# ifndef PNG_EXPORT_TYPE
|
||||
# define PNG_EXPORT_TYPE(type) type PNG_IMPEXP
|
||||
# endif
|
||||
|
@ -244,9 +244,9 @@
|
|||
# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
|
||||
# define PNGAPI _System
|
||||
# else /* !Windows/x86 && !OS/2 */
|
||||
/* Use the defaults, or define PNG*API on the command line (but
|
||||
* this will have to be done for every compile!)
|
||||
*/
|
||||
/* Use the defaults, or define PNG*API on the command line (but
|
||||
* this will have to be done for every compile!)
|
||||
*/
|
||||
# endif /* other system, !OS/2 */
|
||||
#endif /* !Windows/x86 */
|
||||
|
||||
|
@ -267,7 +267,7 @@
|
|||
*/
|
||||
#ifndef PNG_IMPEXP
|
||||
# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT)
|
||||
/* This forces use of a DLL, disallowing static linking */
|
||||
/* This forces use of a DLL, disallowing static linking */
|
||||
# define PNG_IMPEXP PNG_DLL_IMPORT
|
||||
# endif
|
||||
|
||||
|
@ -340,7 +340,7 @@
|
|||
* less efficient code.
|
||||
*/
|
||||
# if defined(__clang__) && defined(__has_attribute)
|
||||
/* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */
|
||||
/* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */
|
||||
# if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__)
|
||||
# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
|
||||
# endif
|
||||
|
@ -480,7 +480,7 @@
|
|||
#if CHAR_BIT == 8 && UCHAR_MAX == 255
|
||||
typedef unsigned char png_byte;
|
||||
#else
|
||||
# error "libpng requires 8 bit bytes"
|
||||
# error "libpng requires 8-bit bytes"
|
||||
#endif
|
||||
|
||||
#if INT_MIN == -32768 && INT_MAX == 32767
|
||||
|
@ -488,7 +488,7 @@
|
|||
#elif SHRT_MIN == -32768 && SHRT_MAX == 32767
|
||||
typedef short png_int_16;
|
||||
#else
|
||||
# error "libpng requires a signed 16 bit type"
|
||||
# error "libpng requires a signed 16-bit type"
|
||||
#endif
|
||||
|
||||
#if UINT_MAX == 65535
|
||||
|
@ -496,7 +496,7 @@
|
|||
#elif USHRT_MAX == 65535
|
||||
typedef unsigned short png_uint_16;
|
||||
#else
|
||||
# error "libpng requires an unsigned 16 bit type"
|
||||
# error "libpng requires an unsigned 16-bit type"
|
||||
#endif
|
||||
|
||||
#if INT_MIN < -2147483646 && INT_MAX > 2147483646
|
||||
|
@ -504,15 +504,15 @@
|
|||
#elif LONG_MIN < -2147483646 && LONG_MAX > 2147483646
|
||||
typedef long int png_int_32;
|
||||
#else
|
||||
# error "libpng requires a signed 32 bit (or more) type"
|
||||
# error "libpng requires a signed 32-bit (or more) type"
|
||||
#endif
|
||||
|
||||
#if UINT_MAX > 4294967294
|
||||
#if UINT_MAX > 4294967294U
|
||||
typedef unsigned int png_uint_32;
|
||||
#elif ULONG_MAX > 4294967294
|
||||
#elif ULONG_MAX > 4294967294U
|
||||
typedef unsigned long int png_uint_32;
|
||||
#else
|
||||
# error "libpng requires an unsigned 32 bit (or more) type"
|
||||
# error "libpng requires an unsigned 32-bit (or more) type"
|
||||
#endif
|
||||
|
||||
/* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
|
||||
*
|
||||
* 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.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
*
|
||||
* Last changed in libpng 1.6.15 [November 20, 2014]
|
||||
* Copyright (c) 1998-2014 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.26 [October 20, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -26,7 +26,7 @@ static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr,
|
|||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
static void /* PRIVATE */
|
||||
png_default_warning PNGARG((png_const_structrp png_ptr,
|
||||
png_const_charp warning_message));
|
||||
png_const_charp warning_message));
|
||||
#endif /* WARNINGS */
|
||||
|
||||
/* This function is called whenever there is a fatal error. This function
|
||||
|
@ -37,14 +37,14 @@ png_default_warning PNGARG((png_const_structrp png_ptr,
|
|||
#ifdef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_FUNCTION(void,PNGAPI
|
||||
png_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
PNG_NORETURN)
|
||||
{
|
||||
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
char msg[16];
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -65,18 +65,18 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
|||
|
||||
else
|
||||
error_message += offset;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
|
||||
{
|
||||
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
|
||||
if (png_ptr != NULL && png_ptr->error_fn != NULL)
|
||||
|
@ -110,7 +110,7 @@ png_err,(png_const_structrp png_ptr),PNG_NORETURN)
|
|||
*/
|
||||
size_t
|
||||
png_safecat(png_charp buffer, size_t bufsize, size_t pos,
|
||||
png_const_charp string)
|
||||
png_const_charp string)
|
||||
{
|
||||
if (buffer != NULL && pos < bufsize)
|
||||
{
|
||||
|
@ -131,7 +131,7 @@ png_safecat(png_charp buffer, size_t bufsize, size_t pos,
|
|||
*/
|
||||
png_charp
|
||||
png_format_number(png_const_charp start, png_charp end, int format,
|
||||
png_alloc_size_t number)
|
||||
png_alloc_size_t number)
|
||||
{
|
||||
int count = 0; /* number of digits output */
|
||||
int mincount = 1; /* minimum number required */
|
||||
|
@ -233,7 +233,7 @@ png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
|||
}
|
||||
if (png_ptr != NULL && png_ptr->warning_fn != NULL)
|
||||
(*(png_ptr->warning_fn))(png_constcast(png_structrp,png_ptr),
|
||||
warning_message + offset);
|
||||
warning_message + offset);
|
||||
else
|
||||
png_default_warning(png_ptr, warning_message + offset);
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
|||
*/
|
||||
void
|
||||
png_warning_parameter(png_warning_parameters p, int number,
|
||||
png_const_charp string)
|
||||
png_const_charp string)
|
||||
{
|
||||
if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT)
|
||||
(void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string);
|
||||
|
@ -253,7 +253,7 @@ png_warning_parameter(png_warning_parameters p, int number,
|
|||
|
||||
void
|
||||
png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
|
||||
png_alloc_size_t value)
|
||||
png_alloc_size_t value)
|
||||
{
|
||||
char buffer[PNG_NUMBER_BUFFER_SIZE];
|
||||
png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value));
|
||||
|
@ -261,7 +261,7 @@ png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
|
|||
|
||||
void
|
||||
png_warning_parameter_signed(png_warning_parameters p, int number, int format,
|
||||
png_int_32 value)
|
||||
png_int_32 value)
|
||||
{
|
||||
png_alloc_size_t u;
|
||||
png_charp str;
|
||||
|
@ -282,7 +282,7 @@ png_warning_parameter_signed(png_warning_parameters p, int number, int format,
|
|||
|
||||
void
|
||||
png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p,
|
||||
png_const_charp message)
|
||||
png_const_charp message)
|
||||
{
|
||||
/* The internal buffer is just 192 bytes - enough for all our messages,
|
||||
* overflow doesn't happen because this code checks! If someone figures
|
||||
|
@ -391,10 +391,10 @@ png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
|
|||
void /* PRIVATE */
|
||||
png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)
|
||||
png_warning(png_ptr, error_message);
|
||||
else
|
||||
png_error(png_ptr, error_message);
|
||||
if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)
|
||||
png_warning(png_ptr, error_message);
|
||||
else
|
||||
png_error(png_ptr, error_message);
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(error_message)
|
||||
|
@ -404,10 +404,10 @@ png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
|
|||
void /* PRIVATE */
|
||||
png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0)
|
||||
png_warning(png_ptr, error_message);
|
||||
else
|
||||
png_error(png_ptr, error_message);
|
||||
if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0)
|
||||
png_warning(png_ptr, error_message);
|
||||
else
|
||||
png_error(png_ptr, error_message);
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(error_message)
|
||||
|
@ -478,7 +478,7 @@ png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
|
|||
#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
|
||||
PNG_FUNCTION(void,PNGAPI
|
||||
png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
PNG_NORETURN)
|
||||
{
|
||||
char msg[18+PNG_MAX_ERROR_TEXT];
|
||||
if (png_ptr == NULL)
|
||||
|
@ -573,7 +573,7 @@ png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN)
|
|||
{
|
||||
# define fixed_message "fixed point overflow in "
|
||||
# define fixed_message_ln ((sizeof fixed_message)-1)
|
||||
int iin;
|
||||
unsigned int iin;
|
||||
char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
|
||||
memcpy(msg, fixed_message, fixed_message_ln);
|
||||
iin = 0;
|
||||
|
@ -620,7 +620,7 @@ png_set_longjmp_fn(png_structrp png_ptr, png_longjmp_ptr longjmp_fn,
|
|||
else
|
||||
{
|
||||
png_ptr->jmp_buf_ptr = png_voidcast(jmp_buf *,
|
||||
png_malloc_warn(png_ptr, jmp_buf_size));
|
||||
png_malloc_warn(png_ptr, jmp_buf_size));
|
||||
|
||||
if (png_ptr->jmp_buf_ptr == NULL)
|
||||
return NULL; /* new NULL return on OOM */
|
||||
|
@ -709,7 +709,7 @@ png_free_jmpbuf(png_structrp png_ptr)
|
|||
*/
|
||||
static PNG_FUNCTION(void /* PRIVATE */,
|
||||
png_default_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
PNG_NORETURN)
|
||||
{
|
||||
#ifdef PNG_CONSOLE_IO_SUPPORTED
|
||||
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
|
@ -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
|
||||
* 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
|
||||
* 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_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
PNG_NORETURN)
|
||||
{
|
||||
const png_const_structrp png_ptr = png_nonconst_ptr;
|
||||
png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
|
||||
|
@ -906,7 +906,7 @@ png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
|
|||
/* Missing longjmp buffer, the following is to help debugging: */
|
||||
{
|
||||
size_t pos = png_safecat(image->message, (sizeof image->message), 0,
|
||||
"bad longjmp: ");
|
||||
"bad longjmp: ");
|
||||
png_safecat(image->message, (sizeof image->message), pos,
|
||||
error_message);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
*
|
||||
* Last changed in libpng 1.6.17 [March 26, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.26 [October 20, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -338,7 +338,7 @@ ppi_from_ppm(png_uint_32 ppm)
|
|||
png_fixed_point result;
|
||||
if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
|
||||
5000) != 0)
|
||||
return result;
|
||||
return (png_uint_32)result;
|
||||
|
||||
/* Overflow. */
|
||||
return 0;
|
||||
|
@ -456,11 +456,11 @@ png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
|||
return (retval);
|
||||
}
|
||||
#endif /* pHYs */
|
||||
#endif /* INCH_CONVERSIONS */
|
||||
#endif /* INCH_CONVERSIONS */
|
||||
|
||||
/* png_get_channels really belongs in here, too, but it's been around longer */
|
||||
|
||||
#endif /* EASY_ACCESS */
|
||||
#endif /* EASY_ACCESS */
|
||||
|
||||
|
||||
png_byte PNGAPI
|
||||
|
@ -486,7 +486,7 @@ png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
|||
#ifdef PNG_bKGD_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_color_16p *background)
|
||||
png_color_16p *background)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_bKGD) != 0 &&
|
||||
|
@ -526,28 +526,28 @@ png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
|||
|
||||
if (white_x != NULL)
|
||||
*white_x = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
|
||||
info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
|
||||
if (white_y != NULL)
|
||||
*white_y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
|
||||
info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
|
||||
if (red_x != NULL)
|
||||
*red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
|
||||
"cHRM red X");
|
||||
"cHRM red X");
|
||||
if (red_y != NULL)
|
||||
*red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
|
||||
"cHRM red Y");
|
||||
"cHRM red Y");
|
||||
if (green_x != NULL)
|
||||
*green_x = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
|
||||
info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
|
||||
if (green_y != NULL)
|
||||
*green_y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
|
||||
info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
|
||||
if (blue_x != NULL)
|
||||
*blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
|
||||
"cHRM blue X");
|
||||
"cHRM blue X");
|
||||
if (blue_y != NULL)
|
||||
*blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
|
||||
"cHRM blue Y");
|
||||
"cHRM blue Y");
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
|
||||
|
@ -556,42 +556,42 @@ png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
|||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
double *red_X, double *red_Y, double *red_Z, double *green_X,
|
||||
double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
|
||||
double *blue_Z)
|
||||
double *red_X, double *red_Y, double *red_Z, double *green_X,
|
||||
double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
|
||||
double *blue_Z)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
|
||||
|
||||
if (red_X != NULL)
|
||||
*red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
|
||||
"cHRM red X");
|
||||
"cHRM red X");
|
||||
if (red_Y != NULL)
|
||||
*red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
|
||||
"cHRM red Y");
|
||||
"cHRM red Y");
|
||||
if (red_Z != NULL)
|
||||
*red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
|
||||
"cHRM red Z");
|
||||
"cHRM red Z");
|
||||
if (green_X != NULL)
|
||||
*green_X = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
|
||||
info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
|
||||
if (green_Y != NULL)
|
||||
*green_Y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
|
||||
info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
|
||||
if (green_Z != NULL)
|
||||
*green_Z = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
|
||||
info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
|
||||
if (blue_X != NULL)
|
||||
*blue_X = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
|
||||
info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
|
||||
if (blue_Y != NULL)
|
||||
*blue_Y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
|
||||
if (blue_Z != NULL)
|
||||
*blue_Z = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
|
||||
|
@ -681,8 +681,8 @@ png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
|||
png_debug1(1, "in %s retrieval function", "gAMA");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
|
||||
file_gamma != NULL)
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
|
||||
file_gamma != NULL)
|
||||
{
|
||||
*file_gamma = info_ptr->colorspace.gamma;
|
||||
return (PNG_INFO_gAMA);
|
||||
|
@ -704,7 +704,7 @@ png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
|||
file_gamma != NULL)
|
||||
{
|
||||
*file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
|
||||
"png_get_gAMA");
|
||||
"png_get_gAMA");
|
||||
return (PNG_INFO_gAMA);
|
||||
}
|
||||
|
||||
|
@ -901,7 +901,7 @@ png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
|||
*/
|
||||
*width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
|
||||
*height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
|
||||
"sCAL height");
|
||||
"sCAL height");
|
||||
return (PNG_INFO_sCAL);
|
||||
}
|
||||
|
||||
|
@ -1142,19 +1142,19 @@ png_get_compression_buffer_size(png_const_structrp png_ptr)
|
|||
return 0;
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
|
||||
#endif
|
||||
{
|
||||
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||
return png_ptr->IDAT_read_size;
|
||||
return png_ptr->IDAT_read_size;
|
||||
#else
|
||||
return PNG_IDAT_READ_SIZE;
|
||||
return PNG_IDAT_READ_SIZE;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
else
|
||||
return png_ptr->zbuffer_size;
|
||||
else
|
||||
return png_ptr->zbuffer_size;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/* pnginfo.h - header file for PNG reference library
|
||||
*
|
||||
* 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.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -223,7 +223,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
|
|||
/* Storage for unknown chunks that the library doesn't recognize. */
|
||||
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.
|
||||
*/
|
||||
int unknown_chunks_num;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
*
|
||||
* Last changed in libpng 1.6.15 [November 20, 2014]
|
||||
* Copyright (c) 1998-2014 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.26 [October 20, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -66,7 +66,7 @@ png_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
|
|||
*/
|
||||
PNG_FUNCTION(png_voidp /* PRIVATE */,
|
||||
png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
PNG_ALLOCATED)
|
||||
PNG_ALLOCATED)
|
||||
{
|
||||
/* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS
|
||||
* allocators have also been removed in 1.6.0, so any 16-bit system now has
|
||||
|
@ -107,9 +107,9 @@ png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
|
|||
*/
|
||||
static png_voidp
|
||||
png_malloc_array_checked(png_const_structrp png_ptr, int nelements,
|
||||
size_t element_size)
|
||||
size_t element_size)
|
||||
{
|
||||
png_alloc_size_t req = nelements; /* known to be > 0 */
|
||||
png_alloc_size_t req = (png_alloc_size_t)nelements; /* known to be > 0 */
|
||||
|
||||
if (req <= PNG_SIZE_MAX/element_size)
|
||||
return png_malloc_base(png_ptr, req * element_size);
|
||||
|
@ -120,7 +120,7 @@ png_malloc_array_checked(png_const_structrp png_ptr, int nelements,
|
|||
|
||||
PNG_FUNCTION(png_voidp /* PRIVATE */,
|
||||
png_malloc_array,(png_const_structrp png_ptr, int nelements,
|
||||
size_t element_size),PNG_ALLOCATED)
|
||||
size_t element_size),PNG_ALLOCATED)
|
||||
{
|
||||
if (nelements <= 0 || element_size == 0)
|
||||
png_error(png_ptr, "internal error: array alloc");
|
||||
|
@ -130,7 +130,7 @@ png_malloc_array,(png_const_structrp png_ptr, int nelements,
|
|||
|
||||
PNG_FUNCTION(png_voidp /* PRIVATE */,
|
||||
png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
|
||||
int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED)
|
||||
int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED)
|
||||
{
|
||||
/* These are internal errors: */
|
||||
if (add_elements <= 0 || element_size == 0 || old_elements < 0 ||
|
||||
|
@ -143,7 +143,7 @@ png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
|
|||
if (add_elements <= INT_MAX - old_elements)
|
||||
{
|
||||
png_voidp new_array = png_malloc_array_checked(png_ptr,
|
||||
old_elements+add_elements, element_size);
|
||||
old_elements+add_elements, element_size);
|
||||
|
||||
if (new_array != NULL)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
memset((char*)new_array + element_size*(unsigned)old_elements, 0,
|
||||
element_size*(unsigned)add_elements);
|
||||
element_size*(unsigned)add_elements);
|
||||
|
||||
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
|
||||
PNG_FUNCTION(png_voidp,PNGAPI
|
||||
png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
PNG_ALLOCATED PNG_DEPRECATED)
|
||||
PNG_ALLOCATED PNG_DEPRECATED)
|
||||
{
|
||||
png_voidp ret;
|
||||
|
||||
|
@ -210,7 +210,7 @@ png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size),
|
|||
*/
|
||||
PNG_FUNCTION(png_voidp,PNGAPI
|
||||
png_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
PNG_ALLOCATED)
|
||||
PNG_ALLOCATED)
|
||||
{
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngpread.c - read a png file in push mode
|
||||
*
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.24 [August 4, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -77,11 +77,11 @@ png_process_data_pause(png_structrp png_ptr, int save)
|
|||
png_uint_32 PNGAPI
|
||||
png_process_data_skip(png_structrp png_ptr)
|
||||
{
|
||||
/* TODO: Deprecate and remove this API.
|
||||
* Somewhere the implementation of this seems to have been lost,
|
||||
* or abandoned. It was only to support some internal back-door access
|
||||
* to png_struct) in libpng-1.4.x.
|
||||
*/
|
||||
/* TODO: Deprecate and remove this API.
|
||||
* Somewhere the implementation of this seems to have been lost,
|
||||
* or abandoned. It was only to support some internal back-door access
|
||||
* to png_struct) in libpng-1.4.x.
|
||||
*/
|
||||
png_app_warning(png_ptr,
|
||||
"png_process_data_skip is not implemented in any current version of libpng");
|
||||
return 0;
|
||||
|
@ -133,7 +133,7 @@ png_process_some_data(png_structrp png_ptr, png_inforp info_ptr)
|
|||
void /* PRIVATE */
|
||||
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;
|
||||
|
||||
if (png_ptr->buffer_size < num_to_check)
|
||||
|
@ -210,12 +210,14 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
|||
(png_ptr->mode & PNG_HAVE_PLTE) == 0)
|
||||
png_error(png_ptr, "Missing PLTE before IDAT");
|
||||
|
||||
png_ptr->mode |= PNG_HAVE_IDAT;
|
||||
png_ptr->process_mode = PNG_READ_IDAT_MODE;
|
||||
|
||||
if ((png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) == 0)
|
||||
if (png_ptr->push_length == 0)
|
||||
return;
|
||||
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
||||
if ((png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) == 0)
|
||||
if (png_ptr->push_length == 0)
|
||||
return;
|
||||
|
||||
png_ptr->mode |= PNG_HAVE_IDAT;
|
||||
|
||||
if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)
|
||||
png_benign_error(png_ptr, "Too many IDATs found");
|
||||
|
@ -408,7 +410,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
|||
{
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length,
|
||||
PNG_HANDLE_CHUNK_AS_DEFAULT);
|
||||
PNG_HANDLE_CHUNK_AS_DEFAULT);
|
||||
}
|
||||
|
||||
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
|
||||
|
@ -499,7 +501,10 @@ png_push_save_buffer(png_structrp png_ptr)
|
|||
png_error(png_ptr, "Insufficient memory for save_buffer");
|
||||
}
|
||||
|
||||
memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
|
||||
if (old_buffer)
|
||||
memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
|
||||
else if (png_ptr->save_buffer_size)
|
||||
png_error(png_ptr, "save_buffer error");
|
||||
png_free(png_ptr, old_buffer);
|
||||
png_ptr->save_buffer_max = new_max;
|
||||
}
|
||||
|
@ -516,7 +521,7 @@ png_push_save_buffer(png_structrp png_ptr)
|
|||
|
||||
void /* PRIVATE */
|
||||
png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer,
|
||||
png_size_t buffer_length)
|
||||
png_size_t buffer_length)
|
||||
{
|
||||
png_ptr->current_buffer = buffer;
|
||||
png_ptr->current_buffer_size = buffer_length;
|
||||
|
@ -563,7 +568,7 @@ png_push_read_IDAT(png_structrp png_ptr)
|
|||
* 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
|
||||
* 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)
|
||||
save_size = (png_size_t)idat_size;
|
||||
|
@ -619,7 +624,7 @@ png_push_read_IDAT(png_structrp png_ptr)
|
|||
|
||||
void /* PRIVATE */
|
||||
png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
|
||||
png_size_t buffer_length)
|
||||
png_size_t buffer_length)
|
||||
{
|
||||
/* The caller checks for a non-zero buffer length. */
|
||||
if (!(buffer_length > 0) || buffer == NULL)
|
||||
|
@ -662,7 +667,7 @@ png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
|
|||
* change the current behavior (see comments in inflate.c
|
||||
* 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. */
|
||||
if (ret != Z_OK && ret != Z_STREAM_END)
|
||||
|
@ -679,7 +684,12 @@ png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
|
|||
png_warning(png_ptr, "Truncated compressed data in IDAT");
|
||||
|
||||
else
|
||||
png_error(png_ptr, "Decompression error in IDAT");
|
||||
{
|
||||
if (ret == Z_DATA_ERROR)
|
||||
png_benign_error(png_ptr, "IDAT: ADLER32 checksum mismatch");
|
||||
else
|
||||
png_error(png_ptr, "Decompression error in IDAT");
|
||||
}
|
||||
|
||||
/* Skip the check on unprocessed input */
|
||||
return;
|
||||
|
@ -777,7 +787,7 @@ png_push_process_row(png_structrp png_ptr)
|
|||
{
|
||||
if (png_ptr->pass < 6)
|
||||
png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,
|
||||
png_ptr->transformations);
|
||||
png_ptr->transformations);
|
||||
|
||||
switch (png_ptr->pass)
|
||||
{
|
||||
|
@ -1039,7 +1049,7 @@ png_push_have_row(png_structrp png_ptr, png_bytep row)
|
|||
{
|
||||
if (png_ptr->row_fn != NULL)
|
||||
(*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
|
||||
(int)png_ptr->pass);
|
||||
(int)png_ptr->pass);
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngpriv.h - private declarations for use inside libpng
|
||||
*
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.26 [October 20, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -182,6 +182,35 @@
|
|||
# endif
|
||||
#endif /* PNG_ARM_NEON_OPT > 0 */
|
||||
|
||||
#ifndef PNG_MIPS_MSA_OPT
|
||||
# if defined(__mips_msa) && (__mips_isa_rev >= 5) && defined(PNG_ALIGNED_MEMORY_SUPPORTED)
|
||||
# define PNG_MIPS_MSA_OPT 2
|
||||
# else
|
||||
# define PNG_MIPS_MSA_OPT 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#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 */
|
||||
|
||||
|
||||
/* Is this a build of a DLL where compilation of the object modules requires
|
||||
* different preprocessor settings to those required for a simple library? If
|
||||
* so PNG_BUILD_DLL must be set.
|
||||
|
@ -420,10 +449,10 @@
|
|||
|
||||
# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
|
||||
defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
|
||||
/* We need to check that <math.h> hasn't already been included earlier
|
||||
* as it seems it doesn't agree with <fp.h>, yet we should really use
|
||||
* <fp.h> if possible.
|
||||
*/
|
||||
/* We need to check that <math.h> hasn't already been included earlier
|
||||
* as it seems it doesn't agree with <fp.h>, yet we should really use
|
||||
* <fp.h> if possible.
|
||||
*/
|
||||
# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
|
||||
# include <fp.h>
|
||||
# endif
|
||||
|
@ -431,9 +460,9 @@
|
|||
# include <math.h>
|
||||
# endif
|
||||
# if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
|
||||
/* Amiga SAS/C: We must include builtin FPU functions when compiling using
|
||||
* MATH=68881
|
||||
*/
|
||||
/* Amiga SAS/C: We must include builtin FPU functions when compiling using
|
||||
* MATH=68881
|
||||
*/
|
||||
# include <m68881.h>
|
||||
# endif
|
||||
#endif
|
||||
|
@ -504,7 +533,8 @@
|
|||
/* This implicitly assumes alignment is always to a power of 2. */
|
||||
#ifdef png_alignof
|
||||
# define png_isaligned(ptr, type)\
|
||||
((((const char*)ptr-(const char*)0) & (png_alignof(type)-1)) == 0)
|
||||
(((type)((const char*)ptr-(const char*)0) & \
|
||||
(type)(png_alignof(type)-1)) == 0)
|
||||
#else
|
||||
# define png_isaligned(ptr, type) 0
|
||||
#endif
|
||||
|
@ -521,96 +551,92 @@
|
|||
* are defined in png.h because they need to be visible to applications
|
||||
* that call png_set_unknown_chunk().
|
||||
*/
|
||||
/* #define PNG_HAVE_IHDR 0x01 (defined in png.h) */
|
||||
/* #define PNG_HAVE_PLTE 0x02 (defined in png.h) */
|
||||
#define PNG_HAVE_IDAT 0x04
|
||||
/* #define PNG_AFTER_IDAT 0x08 (defined in png.h) */
|
||||
#define PNG_HAVE_IEND 0x10
|
||||
/* 0x20 (unused) */
|
||||
/* 0x40 (unused) */
|
||||
/* 0x80 (unused) */
|
||||
#define PNG_HAVE_CHUNK_HEADER 0x100
|
||||
#define PNG_WROTE_tIME 0x200
|
||||
#define PNG_WROTE_INFO_BEFORE_PLTE 0x400
|
||||
#define PNG_BACKGROUND_IS_GRAY 0x800
|
||||
#define PNG_HAVE_PNG_SIGNATURE 0x1000
|
||||
#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
|
||||
/* 0x4000 (unused) */
|
||||
#define PNG_IS_READ_STRUCT 0x8000 /* Else is a write struct */
|
||||
/* #define PNG_HAVE_IHDR 0x01U (defined in png.h) */
|
||||
/* #define PNG_HAVE_PLTE 0x02U (defined in png.h) */
|
||||
#define PNG_HAVE_IDAT 0x04U
|
||||
/* #define PNG_AFTER_IDAT 0x08U (defined in png.h) */
|
||||
#define PNG_HAVE_IEND 0x10U
|
||||
/* 0x20U (unused) */
|
||||
/* 0x40U (unused) */
|
||||
/* 0x80U (unused) */
|
||||
#define PNG_HAVE_CHUNK_HEADER 0x100U
|
||||
#define PNG_WROTE_tIME 0x200U
|
||||
#define PNG_WROTE_INFO_BEFORE_PLTE 0x400U
|
||||
#define PNG_BACKGROUND_IS_GRAY 0x800U
|
||||
#define PNG_HAVE_PNG_SIGNATURE 0x1000U
|
||||
#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000U /* Have another chunk after IDAT */
|
||||
/* 0x4000U (unused) */
|
||||
#define PNG_IS_READ_STRUCT 0x8000U /* Else is a write struct */
|
||||
|
||||
/* Flags for the transformations the PNG library does on the image data */
|
||||
#define PNG_BGR 0x0001
|
||||
#define PNG_INTERLACE 0x0002
|
||||
#define PNG_PACK 0x0004
|
||||
#define PNG_SHIFT 0x0008
|
||||
#define PNG_SWAP_BYTES 0x0010
|
||||
#define PNG_INVERT_MONO 0x0020
|
||||
#define PNG_QUANTIZE 0x0040
|
||||
#define PNG_COMPOSE 0x0080 /* Was PNG_BACKGROUND */
|
||||
#define PNG_BACKGROUND_EXPAND 0x0100
|
||||
#define PNG_EXPAND_16 0x0200 /* Added to libpng 1.5.2 */
|
||||
#define PNG_16_TO_8 0x0400 /* Becomes 'chop' in 1.5.4 */
|
||||
#define PNG_RGBA 0x0800
|
||||
#define PNG_EXPAND 0x1000
|
||||
#define PNG_GAMMA 0x2000
|
||||
#define PNG_GRAY_TO_RGB 0x4000
|
||||
#define PNG_FILLER 0x8000
|
||||
#define PNG_PACKSWAP 0x10000
|
||||
#define PNG_SWAP_ALPHA 0x20000
|
||||
#define PNG_STRIP_ALPHA 0x40000
|
||||
#define PNG_INVERT_ALPHA 0x80000
|
||||
#define PNG_USER_TRANSFORM 0x100000
|
||||
#define PNG_RGB_TO_GRAY_ERR 0x200000
|
||||
#define PNG_RGB_TO_GRAY_WARN 0x400000
|
||||
#define PNG_RGB_TO_GRAY 0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */
|
||||
#define PNG_ENCODE_ALPHA 0x800000 /* Added to libpng-1.5.4 */
|
||||
#define PNG_ADD_ALPHA 0x1000000 /* Added to libpng-1.2.7 */
|
||||
#define PNG_EXPAND_tRNS 0x2000000 /* Added to libpng-1.2.9 */
|
||||
#define PNG_SCALE_16_TO_8 0x4000000 /* Added to libpng-1.5.4 */
|
||||
/* 0x8000000 unused */
|
||||
/* 0x10000000 unused */
|
||||
/* 0x20000000 unused */
|
||||
/* 0x40000000 unused */
|
||||
#define PNG_BGR 0x0001U
|
||||
#define PNG_INTERLACE 0x0002U
|
||||
#define PNG_PACK 0x0004U
|
||||
#define PNG_SHIFT 0x0008U
|
||||
#define PNG_SWAP_BYTES 0x0010U
|
||||
#define PNG_INVERT_MONO 0x0020U
|
||||
#define PNG_QUANTIZE 0x0040U
|
||||
#define PNG_COMPOSE 0x0080U /* Was PNG_BACKGROUND */
|
||||
#define PNG_BACKGROUND_EXPAND 0x0100U
|
||||
#define PNG_EXPAND_16 0x0200U /* Added to libpng 1.5.2 */
|
||||
#define PNG_16_TO_8 0x0400U /* Becomes 'chop' in 1.5.4 */
|
||||
#define PNG_RGBA 0x0800U
|
||||
#define PNG_EXPAND 0x1000U
|
||||
#define PNG_GAMMA 0x2000U
|
||||
#define PNG_GRAY_TO_RGB 0x4000U
|
||||
#define PNG_FILLER 0x8000U
|
||||
#define PNG_PACKSWAP 0x10000U
|
||||
#define PNG_SWAP_ALPHA 0x20000U
|
||||
#define PNG_STRIP_ALPHA 0x40000U
|
||||
#define PNG_INVERT_ALPHA 0x80000U
|
||||
#define PNG_USER_TRANSFORM 0x100000U
|
||||
#define PNG_RGB_TO_GRAY_ERR 0x200000U
|
||||
#define PNG_RGB_TO_GRAY_WARN 0x400000U
|
||||
#define PNG_RGB_TO_GRAY 0x600000U /* two bits, RGB_TO_GRAY_ERR|WARN */
|
||||
#define PNG_ENCODE_ALPHA 0x800000U /* Added to libpng-1.5.4 */
|
||||
#define PNG_ADD_ALPHA 0x1000000U /* Added to libpng-1.2.7 */
|
||||
#define PNG_EXPAND_tRNS 0x2000000U /* Added to libpng-1.2.9 */
|
||||
#define PNG_SCALE_16_TO_8 0x4000000U /* Added to libpng-1.5.4 */
|
||||
/* 0x8000000U unused */
|
||||
/* 0x10000000U unused */
|
||||
/* 0x20000000U unused */
|
||||
/* 0x40000000U unused */
|
||||
/* Flags for png_create_struct */
|
||||
#define PNG_STRUCT_PNG 0x0001
|
||||
#define PNG_STRUCT_INFO 0x0002
|
||||
|
||||
/* Scaling factor for filter heuristic weighting calculations */
|
||||
#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
|
||||
#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
|
||||
#define PNG_STRUCT_PNG 0x0001U
|
||||
#define PNG_STRUCT_INFO 0x0002U
|
||||
|
||||
/* Flags for the png_ptr->flags rather than declaring a byte for each one */
|
||||
#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
|
||||
#define PNG_FLAG_ZSTREAM_INITIALIZED 0x0002 /* Added to libpng-1.6.0 */
|
||||
/* 0x0004 unused */
|
||||
#define PNG_FLAG_ZSTREAM_ENDED 0x0008 /* Added to libpng-1.6.0 */
|
||||
/* 0x0010 unused */
|
||||
/* 0x0020 unused */
|
||||
#define PNG_FLAG_ROW_INIT 0x0040
|
||||
#define PNG_FLAG_FILLER_AFTER 0x0080
|
||||
#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
|
||||
#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
|
||||
#define PNG_FLAG_CRC_CRITICAL_USE 0x0400
|
||||
#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
|
||||
#define PNG_FLAG_ASSUME_sRGB 0x1000 /* Added to libpng-1.5.4 */
|
||||
#define PNG_FLAG_OPTIMIZE_ALPHA 0x2000 /* Added to libpng-1.5.4 */
|
||||
#define PNG_FLAG_DETECT_UNINITIALIZED 0x4000 /* Added to libpng-1.5.4 */
|
||||
/* #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000 */
|
||||
/* #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000 */
|
||||
#define PNG_FLAG_LIBRARY_MISMATCH 0x20000
|
||||
#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000
|
||||
#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000
|
||||
#define PNG_FLAG_BENIGN_ERRORS_WARN 0x100000 /* Added to libpng-1.4.0 */
|
||||
#define PNG_FLAG_APP_WARNINGS_WARN 0x200000 /* Added to libpng-1.6.0 */
|
||||
#define PNG_FLAG_APP_ERRORS_WARN 0x400000 /* Added to libpng-1.6.0 */
|
||||
/* 0x800000 unused */
|
||||
/* 0x1000000 unused */
|
||||
/* 0x2000000 unused */
|
||||
/* 0x4000000 unused */
|
||||
/* 0x8000000 unused */
|
||||
/* 0x10000000 unused */
|
||||
/* 0x20000000 unused */
|
||||
/* 0x40000000 unused */
|
||||
#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001U
|
||||
#define PNG_FLAG_ZSTREAM_INITIALIZED 0x0002U /* Added to libpng-1.6.0 */
|
||||
/* 0x0004U unused */
|
||||
#define PNG_FLAG_ZSTREAM_ENDED 0x0008U /* Added to libpng-1.6.0 */
|
||||
/* 0x0010U unused */
|
||||
/* 0x0020U unused */
|
||||
#define PNG_FLAG_ROW_INIT 0x0040U
|
||||
#define PNG_FLAG_FILLER_AFTER 0x0080U
|
||||
#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100U
|
||||
#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200U
|
||||
#define PNG_FLAG_CRC_CRITICAL_USE 0x0400U
|
||||
#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800U
|
||||
#define PNG_FLAG_ASSUME_sRGB 0x1000U /* Added to libpng-1.5.4 */
|
||||
#define PNG_FLAG_OPTIMIZE_ALPHA 0x2000U /* Added to libpng-1.5.4 */
|
||||
#define PNG_FLAG_DETECT_UNINITIALIZED 0x4000U /* Added to libpng-1.5.4 */
|
||||
/* #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000U */
|
||||
/* #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000U */
|
||||
#define PNG_FLAG_LIBRARY_MISMATCH 0x20000U
|
||||
#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000U
|
||||
#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000U
|
||||
#define PNG_FLAG_BENIGN_ERRORS_WARN 0x100000U /* Added to libpng-1.4.0 */
|
||||
#define PNG_FLAG_APP_WARNINGS_WARN 0x200000U /* Added to libpng-1.6.0 */
|
||||
#define PNG_FLAG_APP_ERRORS_WARN 0x400000U /* Added to libpng-1.6.0 */
|
||||
/* 0x800000U unused */
|
||||
/* 0x1000000U unused */
|
||||
/* 0x2000000U unused */
|
||||
/* 0x4000000U unused */
|
||||
/* 0x8000000U unused */
|
||||
/* 0x10000000U unused */
|
||||
/* 0x20000000U unused */
|
||||
/* 0x40000000U unused */
|
||||
|
||||
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
|
||||
PNG_FLAG_CRC_ANCILLARY_NOWARN)
|
||||
|
@ -644,6 +670,24 @@
|
|||
((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \
|
||||
(( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) )
|
||||
|
||||
/* This returns the number of trailing bits in the last byte of a row, 0 if the
|
||||
* last byte is completely full of pixels. It is, in principle, (pixel_bits x
|
||||
* width) % 8, but that would overflow for large 'width'. The second macro is
|
||||
* the same except that it returns the number of unused bits in the last byte;
|
||||
* (8-TRAILBITS), but 0 when TRAILBITS is 0.
|
||||
*
|
||||
* NOTE: these macros are intended to be self-evidently correct and never
|
||||
* overflow on the assumption that pixel_bits is in the range 0..255. The
|
||||
* arguments are evaluated only once and they can be signed (e.g. as a result of
|
||||
* the integral promotions). The result of the expression always has type
|
||||
* (png_uint_32), however the compiler always knows it is in the range 0..7.
|
||||
*/
|
||||
#define PNG_TRAILBITS(pixel_bits, width) \
|
||||
(((pixel_bits) * ((width) % (png_uint_32)8)) % 8)
|
||||
|
||||
#define PNG_PADBITS(pixel_bits, width) \
|
||||
((8 - PNG_TRAILBITS(pixel_bits, width)) % 8)
|
||||
|
||||
/* PNG_OUT_OF_RANGE returns true if value is outside the range
|
||||
* ideal-delta..ideal+delta. Each argument is evaluated twice.
|
||||
* "ideal" and "delta" should be constants, normally simple
|
||||
|
@ -669,7 +713,7 @@
|
|||
/* The fixed point conversion performs range checking and evaluates
|
||||
* its argument multiple times, so must be used with care. The
|
||||
* 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
|
||||
* (2^31-1) * 100000). 's' is a string that describes the value being
|
||||
* converted.
|
||||
|
@ -798,7 +842,6 @@
|
|||
#include "pngstruct.h"
|
||||
#include "pnginfo.h"
|
||||
|
||||
#if 0 // Added by SA
|
||||
/* Validate the include paths - the include path used to generate pnglibconf.h
|
||||
* must match that used in the build, or we must be using pnglibconf.h.prebuilt:
|
||||
*/
|
||||
|
@ -816,9 +859,8 @@
|
|||
* directives must be in CPPFLAGS.
|
||||
*/
|
||||
#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:
|
||||
*/
|
||||
typedef const png_uint_16p * png_const_uint_16pp;
|
||||
|
@ -1031,7 +1073,7 @@ PNG_INTERNAL_FUNCTION(void,png_write_sBIT,(png_structrp png_ptr,
|
|||
#ifdef PNG_WRITE_cHRM_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_write_cHRM_fixed,(png_structrp png_ptr,
|
||||
const png_xy *xy), PNG_EMPTY);
|
||||
/* The xy value must have been previously validated */
|
||||
/* The xy value must have been previously validated */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_sRGB_SUPPORTED
|
||||
|
@ -1180,6 +1222,7 @@ PNG_INTERNAL_FUNCTION(void,png_do_write_interlace,(png_row_infop row_info,
|
|||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row,(png_structrp pp, png_row_infop
|
||||
row_info, png_bytep row, png_const_bytep prev_row, int filter),PNG_EMPTY);
|
||||
|
||||
#if PNG_ARM_NEON_OPT > 0
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_neon,(png_row_infop row_info,
|
||||
png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_neon,(png_row_infop
|
||||
|
@ -1194,6 +1237,24 @@ PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,(png_row_infop
|
|||
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,(png_row_infop
|
||||
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#if PNG_MIPS_MSA_OPT > 0
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_msa,(png_row_infop row_info,
|
||||
png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_msa,(png_row_infop
|
||||
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_msa,(png_row_infop
|
||||
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_msa,(png_row_infop
|
||||
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_msa,(png_row_infop
|
||||
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_msa,(png_row_infop
|
||||
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_msa,(png_row_infop
|
||||
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
/* Choose the best filter to use and filter the row data */
|
||||
PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr,
|
||||
|
@ -1221,6 +1282,14 @@ PNG_INTERNAL_FUNCTION(void,png_read_finish_row,(png_structrp png_ptr),
|
|||
/* Initialize the row buffers, etc. */
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_start_row,(png_structrp png_ptr),PNG_EMPTY);
|
||||
|
||||
#if 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
|
||||
/* Optional call to update the users info structure */
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_transform_info,(png_structrp png_ptr,
|
||||
|
@ -1411,7 +1480,7 @@ PNG_INTERNAL_FUNCTION(void,png_push_have_info,(png_structrp png_ptr,
|
|||
PNG_INTERNAL_FUNCTION(void,png_push_have_end,(png_structrp png_ptr,
|
||||
png_inforp info_ptr),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_push_have_row,(png_structrp png_ptr,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
png_bytep row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_push_read_end,(png_structrp png_ptr,
|
||||
png_inforp info_ptr),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_process_some_data,(png_structrp png_ptr,
|
||||
|
@ -1450,13 +1519,13 @@ PNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr,
|
|||
|
||||
PNG_INTERNAL_FUNCTION(void,png_colorspace_sync_info,(png_const_structrp png_ptr,
|
||||
png_inforp info_ptr), PNG_EMPTY);
|
||||
/* Synchronize the info 'valid' flags with the colorspace */
|
||||
/* Synchronize the info 'valid' flags with the colorspace */
|
||||
|
||||
PNG_INTERNAL_FUNCTION(void,png_colorspace_sync,(png_const_structrp png_ptr,
|
||||
png_inforp info_ptr), PNG_EMPTY);
|
||||
/* Copy the png_struct colorspace to the info_struct and call the above to
|
||||
* synchronize the flags. Checks for NULL info_ptr and does nothing.
|
||||
*/
|
||||
/* Copy the png_struct colorspace to the info_struct and call the above to
|
||||
* synchronize the flags. Checks for NULL info_ptr and does nothing.
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* Added at libpng version 1.4.0 */
|
||||
|
@ -1490,9 +1559,11 @@ PNG_INTERNAL_FUNCTION(int,png_colorspace_set_ICC,(png_const_structrp png_ptr,
|
|||
/* The 'name' is used for information only */
|
||||
|
||||
/* Routines for checking parts of an ICC profile. */
|
||||
#ifdef PNG_READ_iCCP_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(int,png_icc_check_length,(png_const_structrp png_ptr,
|
||||
png_colorspacerp colorspace, png_const_charp name,
|
||||
png_uint_32 profile_length), PNG_EMPTY);
|
||||
#endif /* READ_iCCP */
|
||||
PNG_INTERNAL_FUNCTION(int,png_icc_check_header,(png_const_structrp png_ptr,
|
||||
png_colorspacerp colorspace, png_const_charp name,
|
||||
png_uint_32 profile_length,
|
||||
|
@ -1911,10 +1982,20 @@ PNG_INTERNAL_FUNCTION(void, PNG_FILTER_OPTIMIZATIONS, (png_structp png_ptr,
|
|||
* the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in
|
||||
* CFLAGS in place of CPPFLAGS *and* uses symbol prefixing.
|
||||
*/
|
||||
# if PNG_ARM_NEON_OPT > 0
|
||||
PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon,
|
||||
(png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#if PNG_MIPS_MSA_OPT > 0
|
||||
PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_msa,
|
||||
(png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
|
||||
#endif
|
||||
#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 ^ */
|
||||
|
||||
#include "pngdebug.h"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngrio.c - functions for data input
|
||||
*
|
||||
* Last changed in libpng 1.6.17 [March 26, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.24 [August 4, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -26,7 +26,7 @@
|
|||
* reads from a file pointer. Note that this routine sometimes gets called
|
||||
* with very small lengths, so you should implement some kind of simple
|
||||
* 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 */
|
||||
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
|
||||
png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
|
||||
png_rw_ptr read_data_fn)
|
||||
png_rw_ptr read_data_fn)
|
||||
{
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngrtran.c - transforms the data in a row for PNG readers
|
||||
*
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.24 [August 4, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -48,7 +48,7 @@ png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action)
|
|||
|
||||
case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */
|
||||
png_warning(png_ptr,
|
||||
"Can't discard critical data on CRC error");
|
||||
"Can't discard critical data on CRC error");
|
||||
case PNG_CRC_ERROR_QUIT: /* Error/quit */
|
||||
|
||||
case PNG_CRC_DEFAULT:
|
||||
|
@ -101,7 +101,7 @@ png_rtran_ok(png_structrp png_ptr, int need_IHDR)
|
|||
{
|
||||
if ((png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)
|
||||
png_app_error(png_ptr,
|
||||
"invalid after png_start_read_image or png_read_update_info");
|
||||
"invalid after png_start_read_image or png_read_update_info");
|
||||
|
||||
else if (need_IHDR && (png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
||||
png_app_error(png_ptr, "invalid before the PNG header has been read");
|
||||
|
@ -159,7 +159,7 @@ png_set_background(png_structrp png_ptr,
|
|||
png_set_background_fixed(png_ptr, background_color, background_gamma_code,
|
||||
need_expand, png_fixed(png_ptr, background_gamma, "png_set_background"));
|
||||
}
|
||||
# endif /* FLOATING_POINT */
|
||||
# endif /* FLOATING_POINT */
|
||||
#endif /* READ_BACKGROUND */
|
||||
|
||||
/* Scale 16-bit depth files to 8-bit depth. If both of these are set then the
|
||||
|
@ -209,7 +209,7 @@ png_set_strip_alpha(png_structrp png_ptr)
|
|||
#if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
static png_fixed_point
|
||||
translate_gamma_flags(png_structrp png_ptr, png_fixed_point output_gamma,
|
||||
int is_screen)
|
||||
int is_screen)
|
||||
{
|
||||
/* Check for flag values. The main reason for having the old Mac value as a
|
||||
* flag is that it is pretty near impossible to work out what the correct
|
||||
|
@ -273,7 +273,7 @@ convert_gamma_value(png_structrp png_ptr, double output_gamma)
|
|||
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
|
||||
void PNGFAPI
|
||||
png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
|
||||
png_fixed_point output_gamma)
|
||||
png_fixed_point output_gamma)
|
||||
{
|
||||
int compose = 0;
|
||||
png_fixed_point file_gamma;
|
||||
|
@ -289,9 +289,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
|
||||
* 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
|
||||
* 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");
|
||||
|
||||
/* The default file gamma is the inverse of the output gamma; the output
|
||||
|
@ -374,7 +377,7 @@ png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
|
|||
|
||||
if ((png_ptr->transformations & PNG_COMPOSE) != 0)
|
||||
png_error(png_ptr,
|
||||
"conflicting calls to set alpha mode and background");
|
||||
"conflicting calls to set alpha mode and background");
|
||||
|
||||
png_ptr->transformations |= PNG_COMPOSE;
|
||||
}
|
||||
|
@ -385,7 +388,7 @@ void PNGAPI
|
|||
png_set_alpha_mode(png_structrp png_ptr, int mode, double output_gamma)
|
||||
{
|
||||
png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr,
|
||||
output_gamma));
|
||||
output_gamma));
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
@ -426,7 +429,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
|
|||
int i;
|
||||
|
||||
png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)(num_palette * (sizeof (png_byte))));
|
||||
(png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte))));
|
||||
for (i = 0; i < num_palette; i++)
|
||||
png_ptr->quantize_index[i] = (png_byte)i;
|
||||
}
|
||||
|
@ -443,7 +446,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
|
|||
|
||||
/* Initialize an array to sort colors */
|
||||
png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)(num_palette * (sizeof (png_byte))));
|
||||
(png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte))));
|
||||
|
||||
/* Initialize the quantize_sort array */
|
||||
for (i = 0; i < num_palette; i++)
|
||||
|
@ -577,9 +580,9 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
|
|||
|
||||
/* Initialize palette index arrays */
|
||||
png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)(num_palette * (sizeof (png_byte))));
|
||||
(png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte))));
|
||||
png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)(num_palette * (sizeof (png_byte))));
|
||||
(png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte))));
|
||||
|
||||
/* Initialize the sort array */
|
||||
for (i = 0; i < num_palette; i++)
|
||||
|
@ -799,7 +802,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
|
|||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
void PNGFAPI
|
||||
png_set_gamma_fixed(png_structrp png_ptr, png_fixed_point scrn_gamma,
|
||||
png_fixed_point file_gamma)
|
||||
png_fixed_point file_gamma)
|
||||
{
|
||||
png_debug(1, "in png_set_gamma_fixed");
|
||||
|
||||
|
@ -841,7 +844,7 @@ void PNGAPI
|
|||
png_set_gamma(png_structrp png_ptr, double scrn_gamma, double file_gamma)
|
||||
{
|
||||
png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma),
|
||||
convert_gamma_value(png_ptr, file_gamma));
|
||||
convert_gamma_value(png_ptr, file_gamma));
|
||||
}
|
||||
# endif /* FLOATING_POINT */
|
||||
#endif /* READ_GAMMA */
|
||||
|
@ -976,7 +979,6 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
|
|||
|
||||
default:
|
||||
png_error(png_ptr, "invalid error action to rgb_to_gray");
|
||||
break;
|
||||
}
|
||||
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
|
@ -988,7 +990,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
|
|||
* that it just worked and get a memory overwrite.
|
||||
*/
|
||||
png_error(png_ptr,
|
||||
"Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
|
||||
"Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
|
||||
|
||||
/* png_ptr->transformations &= ~PNG_RGB_TO_GRAY; */
|
||||
}
|
||||
|
@ -1015,7 +1017,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
|
|||
{
|
||||
if (red >= 0 && green >= 0)
|
||||
png_app_warning(png_ptr,
|
||||
"ignoring out of range rgb_to_gray coefficients");
|
||||
"ignoring out of range rgb_to_gray coefficients");
|
||||
|
||||
/* Use the defaults, from the cHRM chunk if set, else the historical
|
||||
* values which are close to the sRGB/HDTV/ITU-Rec 709 values. See
|
||||
|
@ -1024,7 +1026,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
|
|||
* something has already provided a default.
|
||||
*/
|
||||
if (png_ptr->rgb_to_gray_red_coeff == 0 &&
|
||||
png_ptr->rgb_to_gray_green_coeff == 0)
|
||||
png_ptr->rgb_to_gray_green_coeff == 0)
|
||||
{
|
||||
png_ptr->rgb_to_gray_red_coeff = 6968;
|
||||
png_ptr->rgb_to_gray_green_coeff = 23434;
|
||||
|
@ -1041,10 +1043,10 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
|
|||
|
||||
void PNGAPI
|
||||
png_set_rgb_to_gray(png_structrp png_ptr, int error_action, double red,
|
||||
double green)
|
||||
double green)
|
||||
{
|
||||
png_set_rgb_to_gray_fixed(png_ptr, error_action,
|
||||
png_fixed(png_ptr, red, "rgb to gray red coefficient"),
|
||||
png_fixed(png_ptr, red, "rgb to gray red coefficient"),
|
||||
png_fixed(png_ptr, green, "rgb to gray green coefficient"));
|
||||
}
|
||||
#endif /* FLOATING POINT */
|
||||
|
@ -1301,7 +1303,7 @@ png_init_read_transformations(png_structrp png_ptr)
|
|||
{
|
||||
if (png_ptr->screen_gamma != 0) /* screen set too */
|
||||
gamma_correction = png_gamma_threshold(png_ptr->colorspace.gamma,
|
||||
png_ptr->screen_gamma);
|
||||
png_ptr->screen_gamma);
|
||||
|
||||
else
|
||||
/* Assume the output matches the input; a long time default behavior
|
||||
|
@ -1582,7 +1584,7 @@ png_init_read_transformations(png_structrp png_ptr)
|
|||
*/
|
||||
if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
|
||||
png_warning(png_ptr,
|
||||
"libpng does not support gamma+background+rgb_to_gray");
|
||||
"libpng does not support gamma+background+rgb_to_gray");
|
||||
|
||||
if ((png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) != 0)
|
||||
{
|
||||
|
@ -1618,13 +1620,13 @@ png_init_read_transformations(png_structrp png_ptr)
|
|||
case PNG_BACKGROUND_GAMMA_FILE:
|
||||
g = png_reciprocal(png_ptr->colorspace.gamma);
|
||||
gs = png_reciprocal2(png_ptr->colorspace.gamma,
|
||||
png_ptr->screen_gamma);
|
||||
png_ptr->screen_gamma);
|
||||
break;
|
||||
|
||||
case PNG_BACKGROUND_GAMMA_UNIQUE:
|
||||
g = png_reciprocal(png_ptr->background_gamma);
|
||||
gs = png_reciprocal2(png_ptr->background_gamma,
|
||||
png_ptr->screen_gamma);
|
||||
png_ptr->screen_gamma);
|
||||
break;
|
||||
default:
|
||||
g = PNG_FP_1; /* back_1 */
|
||||
|
@ -1652,11 +1654,11 @@ png_init_read_transformations(png_structrp png_ptr)
|
|||
if (png_gamma_significant(g) != 0)
|
||||
{
|
||||
back_1.red = png_gamma_8bit_correct(png_ptr->background.red,
|
||||
g);
|
||||
g);
|
||||
back_1.green = png_gamma_8bit_correct(
|
||||
png_ptr->background.green, g);
|
||||
png_ptr->background.green, g);
|
||||
back_1.blue = png_gamma_8bit_correct(png_ptr->background.blue,
|
||||
g);
|
||||
g);
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -1727,7 +1729,7 @@ png_init_read_transformations(png_structrp png_ptr)
|
|||
case PNG_BACKGROUND_GAMMA_FILE:
|
||||
g = png_reciprocal(png_ptr->colorspace.gamma);
|
||||
gs = png_reciprocal2(png_ptr->colorspace.gamma,
|
||||
png_ptr->screen_gamma);
|
||||
png_ptr->screen_gamma);
|
||||
break;
|
||||
|
||||
case PNG_BACKGROUND_GAMMA_UNIQUE:
|
||||
|
@ -1913,7 +1915,7 @@ png_init_read_transformations(png_structrp png_ptr)
|
|||
png_ptr->palette[i].blue = (png_byte)component;
|
||||
}
|
||||
}
|
||||
#endif /* READ_SHIFT */
|
||||
#endif /* READ_SHIFT */
|
||||
}
|
||||
|
||||
/* Modify the info structure to reflect the transformations. The
|
||||
|
@ -1997,7 +1999,7 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
|
|||
# endif
|
||||
|
||||
# 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
|
||||
* correct scaling to use.
|
||||
*/
|
||||
|
@ -2098,10 +2100,10 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
|
|||
defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
|
||||
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;
|
||||
|
||||
if (info_ptr->channels < png_ptr->user_transform_channels)
|
||||
if (png_ptr->user_transform_channels != 0)
|
||||
info_ptr->channels = png_ptr->user_transform_channels;
|
||||
}
|
||||
#endif
|
||||
|
@ -2148,7 +2150,7 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
|
|||
{
|
||||
png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
|
||||
png_bytep dp = row + (png_size_t)row_width - 1;
|
||||
png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
|
||||
png_uint_32 shift = 7U - ((row_width + 7U) & 0x07);
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
*dp = (png_byte)((*sp >> shift) & 0x01);
|
||||
|
@ -2172,7 +2174,7 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
|
|||
|
||||
png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
|
||||
png_bytep dp = row + (png_size_t)row_width - 1;
|
||||
png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
|
||||
png_uint_32 shift = ((3U - ((row_width + 3U) & 0x03)) << 1);
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
*dp = (png_byte)((*sp >> shift) & 0x03);
|
||||
|
@ -2195,7 +2197,7 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
|
|||
{
|
||||
png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
|
||||
png_bytep dp = row + (png_size_t)row_width - 1;
|
||||
png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
|
||||
png_uint_32 shift = ((1U - ((row_width + 1U) & 0x01)) << 2);
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
*dp = (png_byte)((*sp >> shift) & 0x0f);
|
||||
|
@ -2382,8 +2384,8 @@ png_do_scale_16_to_8(png_row_infop row_info, png_bytep row)
|
|||
|
||||
while (sp < ep)
|
||||
{
|
||||
/* 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
|
||||
/* 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
|
||||
* specification) is:
|
||||
*
|
||||
* (V * 255) / 65535
|
||||
|
@ -2404,7 +2406,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
|
||||
* 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:
|
||||
*
|
||||
* error = (vlo-vhi+128)*65535 >> 24;
|
||||
|
@ -3148,9 +3150,9 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
|
|||
if (red != green || red != blue)
|
||||
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
|
||||
* 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) >>
|
||||
15);
|
||||
|
@ -3221,7 +3223,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
|||
== png_ptr->trans_color.gray)
|
||||
{
|
||||
unsigned int tmp = *sp & (0x7f7f >> (7 - shift));
|
||||
tmp |= png_ptr->background.gray << shift;
|
||||
tmp |=
|
||||
(unsigned int)(png_ptr->background.gray << shift);
|
||||
*sp = (png_byte)(tmp & 0xff);
|
||||
}
|
||||
|
||||
|
@ -3250,7 +3253,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
|||
== png_ptr->trans_color.gray)
|
||||
{
|
||||
unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
|
||||
tmp |= png_ptr->background.gray << shift;
|
||||
tmp |=
|
||||
(unsigned int)png_ptr->background.gray << shift;
|
||||
*sp = (png_byte)(tmp & 0xff);
|
||||
}
|
||||
|
||||
|
@ -3260,7 +3264,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
|||
unsigned int g = (gamma_table [p | (p << 2) |
|
||||
(p << 4) | (p << 6)] >> 6) & 0x03;
|
||||
unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
|
||||
tmp |= g << shift;
|
||||
tmp |= (unsigned int)(g << shift);
|
||||
*sp = (png_byte)(tmp & 0xff);
|
||||
}
|
||||
|
||||
|
@ -3286,7 +3290,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
|||
== png_ptr->trans_color.gray)
|
||||
{
|
||||
unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
|
||||
tmp |= png_ptr->background.gray << shift;
|
||||
tmp |=
|
||||
(unsigned int)png_ptr->background.gray << shift;
|
||||
*sp = (png_byte)(tmp & 0xff);
|
||||
}
|
||||
|
||||
|
@ -3315,8 +3320,9 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
|||
if ((png_uint_16)((*sp >> shift) & 0x0f)
|
||||
== png_ptr->trans_color.gray)
|
||||
{
|
||||
unsigned int tmp = *sp & (0xf0f >> (4 - shift));
|
||||
tmp |= png_ptr->background.gray << shift;
|
||||
unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
|
||||
tmp |=
|
||||
(unsigned int)(png_ptr->background.gray << shift);
|
||||
*sp = (png_byte)(tmp & 0xff);
|
||||
}
|
||||
|
||||
|
@ -3325,8 +3331,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
|||
unsigned int p = (*sp >> shift) & 0x0f;
|
||||
unsigned int g = (gamma_table[p | (p << 4)] >> 4) &
|
||||
0x0f;
|
||||
unsigned int tmp = *sp & (0xf0f >> (4 - shift));
|
||||
tmp |= g << shift;
|
||||
unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
|
||||
tmp |= (unsigned int)(g << shift);
|
||||
*sp = (png_byte)(tmp & 0xff);
|
||||
}
|
||||
|
||||
|
@ -3351,8 +3357,9 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
|||
if ((png_uint_16)((*sp >> shift) & 0x0f)
|
||||
== png_ptr->trans_color.gray)
|
||||
{
|
||||
unsigned int tmp = *sp & (0xf0f >> (4 - shift));
|
||||
tmp |= png_ptr->background.gray << shift;
|
||||
unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
|
||||
tmp |=
|
||||
(unsigned int)(png_ptr->background.gray << shift);
|
||||
*sp = (png_byte)(tmp & 0xff);
|
||||
}
|
||||
|
||||
|
@ -4193,7 +4200,7 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
|||
*/
|
||||
static void
|
||||
png_do_expand_palette(png_row_infop row_info, png_bytep row,
|
||||
png_const_colorp palette, png_const_bytep trans_alpha, int num_trans)
|
||||
png_const_colorp palette, png_const_bytep trans_alpha, int num_trans)
|
||||
{
|
||||
int shift, value;
|
||||
png_bytep sp, dp;
|
||||
|
@ -4500,7 +4507,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
|
|||
row_info->channels = 2;
|
||||
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
|
||||
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
|
||||
row_width);
|
||||
row_width);
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
|
||||
|
@ -4760,7 +4767,7 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
|
|||
(row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
|
||||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
|
||||
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
|
||||
0 /* at_start == false, because SWAP_ALPHA happens later */);
|
||||
0 /* at_start == false, because SWAP_ALPHA happens later */);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngrutil.c - utilities to read a PNG file
|
||||
*
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.26 [October 20, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -86,10 +86,16 @@ png_get_int_32)(png_const_bytep buf)
|
|||
{
|
||||
png_uint_32 uval = png_get_uint_32(buf);
|
||||
if ((uval & 0x80000000) == 0) /* non-negative */
|
||||
return uval;
|
||||
return (png_int_32)uval;
|
||||
|
||||
uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */
|
||||
return -(png_int_32)uval;
|
||||
if ((uval & 0x80000000) == 0) /* no overflow */
|
||||
return -(png_int_32)uval;
|
||||
/* The following has to be safe; this function only gets called on PNG data
|
||||
* and if we get here that data is invalid. 0 is the most safe value and
|
||||
* if not then an attacker would surely just generate a PNG with 0 instead.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */
|
||||
|
@ -98,7 +104,7 @@ png_get_uint_16)(png_const_bytep buf)
|
|||
{
|
||||
/* ANSI-C requires an int value to accomodate at least 16 bits so this
|
||||
* works and allows the compiler not to worry about possible narrowing
|
||||
* on 32 bit systems. (Pre-ANSI systems did not make integers smaller
|
||||
* on 32-bit systems. (Pre-ANSI systems did not make integers smaller
|
||||
* than 16 bits either.)
|
||||
*/
|
||||
unsigned int val =
|
||||
|
@ -364,21 +370,24 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
|
|||
*/
|
||||
{
|
||||
int ret; /* zlib return code */
|
||||
#if PNG_ZLIB_VERNUM >= 0x1240
|
||||
#if ZLIB_VERNUM >= 0x1240
|
||||
int window_bits = 0;
|
||||
|
||||
# if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW)
|
||||
int window_bits;
|
||||
|
||||
if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) ==
|
||||
PNG_OPTION_ON)
|
||||
{
|
||||
window_bits = 15;
|
||||
png_ptr->zstream_start = 0; /* fixed window size */
|
||||
}
|
||||
|
||||
else
|
||||
window_bits = 0;
|
||||
# else
|
||||
# define window_bits 0
|
||||
{
|
||||
png_ptr->zstream_start = 1;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* ZLIB_VERNUM >= 0x1240 */
|
||||
|
||||
/* Set this for safety, just in case the previous owner left pointers to
|
||||
* memory allocations.
|
||||
|
@ -390,25 +399,31 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
|
|||
|
||||
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)
|
||||
{
|
||||
#if PNG_ZLIB_VERNUM < 0x1240
|
||||
ret = inflateReset(&png_ptr->zstream);
|
||||
#else
|
||||
#if ZLIB_VERNUM >= 0x1240
|
||||
ret = inflateReset2(&png_ptr->zstream, window_bits);
|
||||
#else
|
||||
ret = inflateReset(&png_ptr->zstream);
|
||||
#endif
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
#if PNG_ZLIB_VERNUM < 0x1240
|
||||
ret = inflateInit(&png_ptr->zstream);
|
||||
#else
|
||||
#if ZLIB_VERNUM >= 0x1240
|
||||
ret = inflateInit2(&png_ptr->zstream, window_bits);
|
||||
#else
|
||||
ret = inflateInit(&png_ptr->zstream);
|
||||
#endif
|
||||
|
||||
if (ret == Z_OK)
|
||||
png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;
|
||||
}
|
||||
|
||||
#if ZLIB_VERNUM >= 0x1281
|
||||
/* Turn off validation of the ADLER32 checksum */
|
||||
if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0)
|
||||
ret = inflateValidate(&png_ptr->zstream, 0);
|
||||
#endif
|
||||
|
||||
if (ret == Z_OK)
|
||||
png_ptr->zowner = owner;
|
||||
|
||||
|
@ -423,7 +438,33 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
|
|||
#endif
|
||||
}
|
||||
|
||||
#if ZLIB_VERNUM >= 0x1240
|
||||
/* Handle the start of the inflate stream if we called inflateInit2(strm,0);
|
||||
* in this case some zlib versions skip validation of the CINFO field and, in
|
||||
* certain circumstances, libpng may end up displaying an invalid image, in
|
||||
* contrast to implementations that call zlib in the normal way (e.g. libpng
|
||||
* 1.5).
|
||||
*/
|
||||
int /* PRIVATE */
|
||||
png_zlib_inflate(png_structrp png_ptr, int flush)
|
||||
{
|
||||
if (png_ptr->zstream_start && png_ptr->zstream.avail_in > 0)
|
||||
{
|
||||
if ((*png_ptr->zstream.next_in >> 4) > 7)
|
||||
{
|
||||
png_ptr->zstream.msg = "invalid window size (libpng)";
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
|
||||
png_ptr->zstream_start = 0;
|
||||
}
|
||||
|
||||
return inflate(&png_ptr->zstream, flush);
|
||||
}
|
||||
#endif /* Zlib >= 1.2.4 */
|
||||
|
||||
#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED) || defined (PNG_READ_iTXt_SUPPORTED)
|
||||
/* png_inflate now returns zlib error codes including Z_OK and Z_STREAM_END to
|
||||
* allow the caller to do multiple calls if required. If the 'finish' flag is
|
||||
* set Z_FINISH will be passed to the final inflate() call and Z_STREAM_END must
|
||||
|
@ -516,7 +557,7 @@ png_inflate(png_structrp png_ptr, png_uint_32 owner, int finish,
|
|||
* the previous chunk of input data. Tell zlib if we have reached the
|
||||
* end of the output buffer.
|
||||
*/
|
||||
ret = inflate(&png_ptr->zstream, avail_out > 0 ? Z_NO_FLUSH :
|
||||
ret = PNG_INFLATE(png_ptr, avail_out > 0 ? Z_NO_FLUSH :
|
||||
(finish ? Z_FINISH : Z_SYNC_FLUSH));
|
||||
} while (ret == Z_OK);
|
||||
|
||||
|
@ -562,9 +603,9 @@ png_inflate(png_structrp png_ptr, png_uint_32 owner, int finish,
|
|||
*/
|
||||
static int
|
||||
png_decompress_chunk(png_structrp png_ptr,
|
||||
png_uint_32 chunklength, png_uint_32 prefix_size,
|
||||
png_alloc_size_t *newlength /* must be initialized to the maximum! */,
|
||||
int terminate /*add a '\0' to the end of the uncompressed data*/)
|
||||
png_uint_32 chunklength, png_uint_32 prefix_size,
|
||||
png_alloc_size_t *newlength /* must be initialized to the maximum! */,
|
||||
int terminate /*add a '\0' to the end of the uncompressed data*/)
|
||||
{
|
||||
/* TODO: implement different limits for different types of chunk.
|
||||
*
|
||||
|
@ -601,8 +642,8 @@ png_decompress_chunk(png_structrp png_ptr,
|
|||
png_uint_32 lzsize = chunklength - prefix_size;
|
||||
|
||||
ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
|
||||
/* input: */ png_ptr->read_buffer + prefix_size, &lzsize,
|
||||
/* output: */ NULL, newlength);
|
||||
/* input: */ png_ptr->read_buffer + prefix_size, &lzsize,
|
||||
/* output: */ NULL, newlength);
|
||||
|
||||
if (ret == Z_STREAM_END)
|
||||
{
|
||||
|
@ -622,15 +663,15 @@ png_decompress_chunk(png_structrp png_ptr,
|
|||
*/
|
||||
png_alloc_size_t new_size = *newlength;
|
||||
png_alloc_size_t buffer_size = prefix_size + new_size +
|
||||
(terminate != 0);
|
||||
(terminate != 0);
|
||||
png_bytep text = png_voidcast(png_bytep, png_malloc_base(png_ptr,
|
||||
buffer_size));
|
||||
buffer_size));
|
||||
|
||||
if (text != NULL)
|
||||
{
|
||||
ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
|
||||
png_ptr->read_buffer + prefix_size, &lzsize,
|
||||
text + prefix_size, newlength);
|
||||
png_ptr->read_buffer + prefix_size, &lzsize,
|
||||
text + prefix_size, newlength);
|
||||
|
||||
if (ret == Z_STREAM_END)
|
||||
{
|
||||
|
@ -717,6 +758,7 @@ png_decompress_chunk(png_structrp png_ptr,
|
|||
return Z_MEM_ERROR;
|
||||
}
|
||||
}
|
||||
#endif /* READ_zTXt || READ_iTXt */
|
||||
#endif /* READ_COMPRESSED_TEXT */
|
||||
|
||||
#ifdef PNG_READ_iCCP_SUPPORTED
|
||||
|
@ -725,8 +767,8 @@ png_decompress_chunk(png_structrp png_ptr,
|
|||
*/
|
||||
static int
|
||||
png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,
|
||||
png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size,
|
||||
int finish)
|
||||
png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size,
|
||||
int finish)
|
||||
{
|
||||
if (png_ptr->zowner == png_ptr->chunk_name)
|
||||
{
|
||||
|
@ -765,8 +807,8 @@ png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,
|
|||
* the available output is produced; this allows reading of truncated
|
||||
* streams.
|
||||
*/
|
||||
ret = inflate(&png_ptr->zstream,
|
||||
*chunk_bytes > 0 ? Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH));
|
||||
ret = PNG_INFLATE(png_ptr, *chunk_bytes > 0 ?
|
||||
Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH));
|
||||
}
|
||||
while (ret == Z_OK && (*out_size > 0 || png_ptr->zstream.avail_out > 0));
|
||||
|
||||
|
@ -866,7 +908,7 @@ void /* PRIVATE */
|
|||
png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
{
|
||||
png_color palette[PNG_MAX_PALETTE_LENGTH];
|
||||
int num, i;
|
||||
int max_palette_length, num, i;
|
||||
#ifdef PNG_POINTER_INDEXING_SUPPORTED
|
||||
png_colorp pal_ptr;
|
||||
#endif
|
||||
|
@ -927,6 +969,19 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
/* The cast is safe because 'length' is less than 3*PNG_MAX_PALETTE_LENGTH */
|
||||
num = (int)length / 3;
|
||||
|
||||
/* If the palette has 256 or fewer entries but is too large for the bit
|
||||
* depth, we don't issue an error, to preserve the behavior of previous
|
||||
* libpng versions. We silently truncate the unused extra palette entries
|
||||
* here.
|
||||
*/
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
max_palette_length = (1 << png_ptr->bit_depth);
|
||||
else
|
||||
max_palette_length = PNG_MAX_PALETTE_LENGTH;
|
||||
|
||||
if (num > max_palette_length)
|
||||
num = max_palette_length;
|
||||
|
||||
#ifdef PNG_POINTER_INDEXING_SUPPORTED
|
||||
for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
|
||||
{
|
||||
|
@ -959,7 +1014,7 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
#endif
|
||||
{
|
||||
png_crc_finish(png_ptr, 0);
|
||||
png_crc_finish(png_ptr, (png_uint_32) (length - (unsigned int)num * 3));
|
||||
}
|
||||
|
||||
#ifndef PNG_READ_OPT_PLTE_SUPPORTED
|
||||
|
@ -1242,7 +1297,7 @@ png_handle_cHRM(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
|
||||
png_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
|
||||
(void)png_colorspace_set_chromaticities(png_ptr, &png_ptr->colorspace, &xy,
|
||||
1/*prefer cHRM values*/);
|
||||
1/*prefer cHRM values*/);
|
||||
png_colorspace_sync(png_ptr, info_ptr);
|
||||
}
|
||||
#endif
|
||||
|
@ -1382,8 +1437,8 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
png_ptr->zstream.next_in = (Bytef*)keyword + (keyword_length+2);
|
||||
png_ptr->zstream.avail_in = read_length;
|
||||
(void)png_inflate_read(png_ptr, local_buffer,
|
||||
(sizeof local_buffer), &length, profile_header, &size,
|
||||
0/*finish: don't, because the output is too small*/);
|
||||
(sizeof local_buffer), &length, profile_header, &size,
|
||||
0/*finish: don't, because the output is too small*/);
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
|
@ -1393,14 +1448,14 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
png_get_uint_32(profile_header);
|
||||
|
||||
if (png_icc_check_length(png_ptr, &png_ptr->colorspace,
|
||||
keyword, profile_length) != 0)
|
||||
keyword, profile_length) != 0)
|
||||
{
|
||||
/* The length is apparently ok, so we can check the 132
|
||||
* byte header.
|
||||
*/
|
||||
if (png_icc_check_header(png_ptr, &png_ptr->colorspace,
|
||||
keyword, profile_length, profile_header,
|
||||
png_ptr->color_type) != 0)
|
||||
keyword, profile_length, profile_header,
|
||||
png_ptr->color_type) != 0)
|
||||
{
|
||||
/* Now read the tag table; a variable size buffer is
|
||||
* needed at this point, allocate one for the whole
|
||||
|
@ -1408,20 +1463,20 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
* that none of these stuff will overflow.
|
||||
*/
|
||||
const png_uint_32 tag_count = png_get_uint_32(
|
||||
profile_header+128);
|
||||
profile_header+128);
|
||||
png_bytep profile = png_read_buffer(png_ptr,
|
||||
profile_length, 2/*silent*/);
|
||||
profile_length, 2/*silent*/);
|
||||
|
||||
if (profile != NULL)
|
||||
{
|
||||
memcpy(profile, profile_header,
|
||||
(sizeof profile_header));
|
||||
(sizeof profile_header));
|
||||
|
||||
size = 12 * tag_count;
|
||||
|
||||
(void)png_inflate_read(png_ptr, local_buffer,
|
||||
(sizeof local_buffer), &length,
|
||||
profile + (sizeof profile_header), &size, 0);
|
||||
(sizeof local_buffer), &length,
|
||||
profile + (sizeof profile_header), &size, 0);
|
||||
|
||||
/* Still expect a buffer error because we expect
|
||||
* there to be some tag data!
|
||||
|
@ -1429,22 +1484,22 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
if (size == 0)
|
||||
{
|
||||
if (png_icc_check_tag_table(png_ptr,
|
||||
&png_ptr->colorspace, keyword, profile_length,
|
||||
profile) != 0)
|
||||
&png_ptr->colorspace, keyword, profile_length,
|
||||
profile) != 0)
|
||||
{
|
||||
/* The profile has been validated for basic
|
||||
* security issues, so read the whole thing in.
|
||||
*/
|
||||
size = profile_length - (sizeof profile_header)
|
||||
- 12 * tag_count;
|
||||
- 12 * tag_count;
|
||||
|
||||
(void)png_inflate_read(png_ptr, local_buffer,
|
||||
(sizeof local_buffer), &length,
|
||||
profile + (sizeof profile_header) +
|
||||
12 * tag_count, &size, 1/*finish*/);
|
||||
(sizeof local_buffer), &length,
|
||||
profile + (sizeof profile_header) +
|
||||
12 * tag_count, &size, 1/*finish*/);
|
||||
|
||||
if (length > 0 && !(png_ptr->flags &
|
||||
PNG_FLAG_BENIGN_ERRORS_WARN))
|
||||
PNG_FLAG_BENIGN_ERRORS_WARN))
|
||||
errmsg = "extra compressed data";
|
||||
|
||||
/* But otherwise allow extra data: */
|
||||
|
@ -1456,34 +1511,34 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
* keep going.
|
||||
*/
|
||||
png_chunk_warning(png_ptr,
|
||||
"extra compressed data");
|
||||
"extra compressed data");
|
||||
}
|
||||
|
||||
png_crc_finish(png_ptr, length);
|
||||
finished = 1;
|
||||
|
||||
# ifdef PNG_sRGB_SUPPORTED
|
||||
# if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0
|
||||
/* Check for a match against sRGB */
|
||||
png_icc_set_sRGB(png_ptr,
|
||||
&png_ptr->colorspace, profile,
|
||||
png_ptr->zstream.adler);
|
||||
# endif
|
||||
&png_ptr->colorspace, profile,
|
||||
png_ptr->zstream.adler);
|
||||
# endif
|
||||
|
||||
/* Steal the profile for info_ptr. */
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
png_free_data(png_ptr, info_ptr,
|
||||
PNG_FREE_ICCP, 0);
|
||||
PNG_FREE_ICCP, 0);
|
||||
|
||||
info_ptr->iccp_name = png_voidcast(char*,
|
||||
png_malloc_base(png_ptr,
|
||||
keyword_length+1));
|
||||
png_malloc_base(png_ptr,
|
||||
keyword_length+1));
|
||||
if (info_ptr->iccp_name != NULL)
|
||||
{
|
||||
memcpy(info_ptr->iccp_name, keyword,
|
||||
keyword_length+1);
|
||||
keyword_length+1);
|
||||
info_ptr->iccp_proflen =
|
||||
profile_length;
|
||||
profile_length;
|
||||
info_ptr->iccp_profile = profile;
|
||||
png_ptr->read_buffer = NULL; /*steal*/
|
||||
info_ptr->free_me |= PNG_FREE_ICCP;
|
||||
|
@ -1651,7 +1706,7 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
++entry_start;
|
||||
|
||||
/* A sample depth should follow the separator, and we should be on it */
|
||||
if (entry_start > buffer + length - 2)
|
||||
if (length < 2U || entry_start > buffer + (length - 2U))
|
||||
{
|
||||
png_warning(png_ptr, "malformed sPLT chunk");
|
||||
return;
|
||||
|
@ -1665,13 +1720,13 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
data_length = length - (png_uint_32)(entry_start - buffer);
|
||||
|
||||
/* Integrity-check the data length */
|
||||
if ((data_length % entry_size) != 0)
|
||||
if ((data_length % (unsigned int)entry_size) != 0)
|
||||
{
|
||||
png_warning(png_ptr, "sPLT chunk has bad length");
|
||||
return;
|
||||
}
|
||||
|
||||
dl = (png_int_32)(data_length / entry_size);
|
||||
dl = (png_uint_32)(data_length / (unsigned int)entry_size);
|
||||
max_dl = PNG_SIZE_MAX / (sizeof (png_sPLT_entry));
|
||||
|
||||
if (dl > max_dl)
|
||||
|
@ -1680,10 +1735,10 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
return;
|
||||
}
|
||||
|
||||
new_palette.nentries = (png_int_32)(data_length / entry_size);
|
||||
new_palette.nentries = (png_int_32)(data_length / (unsigned int)entry_size);
|
||||
|
||||
new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
|
||||
png_ptr, new_palette.nentries * (sizeof (png_sPLT_entry)));
|
||||
new_palette.entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
|
||||
(png_alloc_size_t) new_palette.nentries * (sizeof (png_sPLT_entry)));
|
||||
|
||||
if (new_palette.entries == NULL)
|
||||
{
|
||||
|
@ -1818,7 +1873,7 @@ png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
return;
|
||||
}
|
||||
|
||||
if (length > png_ptr->num_palette ||
|
||||
if (length > (unsigned int) png_ptr->num_palette ||
|
||||
length > (unsigned int) PNG_MAX_PALETTE_LENGTH ||
|
||||
length == 0)
|
||||
{
|
||||
|
@ -1982,7 +2037,8 @@ png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
|
||||
num = length / 2 ;
|
||||
|
||||
if (num != png_ptr->num_palette || num > (unsigned int) PNG_MAX_PALETTE_LENGTH)
|
||||
if (num != (unsigned int) png_ptr->num_palette ||
|
||||
num > (unsigned int) PNG_MAX_PALETTE_LENGTH)
|
||||
{
|
||||
png_crc_finish(png_ptr, length);
|
||||
png_chunk_benign_error(png_ptr, "invalid");
|
||||
|
@ -2154,7 +2210,7 @@ png_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
/* We need to have at least 12 bytes after the purpose string
|
||||
* in order to get the parameter information.
|
||||
*/
|
||||
if (endptr <= buf + 12)
|
||||
if (endptr - buf <= 12)
|
||||
{
|
||||
png_chunk_benign_error(png_ptr, "invalid");
|
||||
return;
|
||||
|
@ -2219,7 +2275,7 @@ png_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
}
|
||||
|
||||
png_set_pCAL(png_ptr, info_ptr, (png_charp)buffer, X0, X1, type, nparams,
|
||||
(png_charp)units, params);
|
||||
(png_charp)units, params);
|
||||
|
||||
png_free(png_ptr, params);
|
||||
}
|
||||
|
@ -2262,7 +2318,7 @@ png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
}
|
||||
|
||||
png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)",
|
||||
length + 1);
|
||||
length + 1);
|
||||
|
||||
buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/);
|
||||
|
||||
|
@ -2314,7 +2370,7 @@ png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
else
|
||||
/* This is the (only) success case. */
|
||||
png_set_sCAL_s(png_ptr, info_ptr, buffer[0],
|
||||
(png_charp)buffer+1, (png_charp)buffer+heighti);
|
||||
(png_charp)buffer+1, (png_charp)buffer+heighti);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -2414,8 +2470,8 @@ png_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
|
||||
if (buffer == NULL)
|
||||
{
|
||||
png_chunk_benign_error(png_ptr, "out of memory");
|
||||
return;
|
||||
png_chunk_benign_error(png_ptr, "out of memory");
|
||||
return;
|
||||
}
|
||||
|
||||
png_crc_read(png_ptr, buffer, length);
|
||||
|
@ -2522,7 +2578,7 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
* and text chunks.
|
||||
*/
|
||||
if (png_decompress_chunk(png_ptr, length, keyword_length+2,
|
||||
&uncompressed_length, 1/*terminate*/) == Z_STREAM_END)
|
||||
&uncompressed_length, 1/*terminate*/) == Z_STREAM_END)
|
||||
{
|
||||
png_text text;
|
||||
|
||||
|
@ -2662,7 +2718,7 @@ png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|||
* iCCP and text chunks.
|
||||
*/
|
||||
if (png_decompress_chunk(png_ptr, length, prefix_length,
|
||||
&uncompressed_length, 1/*terminate*/) == Z_STREAM_END)
|
||||
&uncompressed_length, 1/*terminate*/) == Z_STREAM_END)
|
||||
buffer = png_ptr->read_buffer;
|
||||
|
||||
else
|
||||
|
@ -2742,7 +2798,7 @@ png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
|
|||
{
|
||||
/* Do a 'warn' here - it is handled below. */
|
||||
png_ptr->unknown_chunk.data = png_voidcast(png_bytep,
|
||||
png_malloc_warn(png_ptr, length));
|
||||
png_malloc_warn(png_ptr, length));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2767,7 +2823,7 @@ png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
|
|||
/* Handle an unknown, or known but disabled, chunk */
|
||||
void /* PRIVATE */
|
||||
png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
||||
png_uint_32 length, int keep)
|
||||
png_uint_32 length, int keep)
|
||||
{
|
||||
int handled = 0; /* the chunk was handled */
|
||||
|
||||
|
@ -2805,7 +2861,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
|||
{
|
||||
/* Callback to user unknown chunk handler */
|
||||
int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr,
|
||||
&png_ptr->unknown_chunk);
|
||||
&png_ptr->unknown_chunk);
|
||||
|
||||
/* ret is:
|
||||
* negative: An error occurred; png_chunk_error will be called.
|
||||
|
@ -2839,9 +2895,9 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
|||
{
|
||||
png_chunk_warning(png_ptr, "Saving unknown chunk:");
|
||||
png_app_warning(png_ptr,
|
||||
"forcing save of an unhandled chunk;"
|
||||
" please call png_set_keep_unknown_chunks");
|
||||
/* with keep = PNG_HANDLE_CHUNK_IF_SAFE */
|
||||
"forcing save of an unhandled chunk;"
|
||||
" please call png_set_keep_unknown_chunks");
|
||||
/* with keep = PNG_HANDLE_CHUNK_IF_SAFE */
|
||||
}
|
||||
# endif
|
||||
keep = PNG_HANDLE_CHUNK_IF_SAFE;
|
||||
|
@ -2934,7 +2990,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
|||
* out; store the chunk.
|
||||
*/
|
||||
png_set_unknown_chunks(png_ptr, info_ptr,
|
||||
&png_ptr->unknown_chunk, 1);
|
||||
&png_ptr->unknown_chunk, 1);
|
||||
handled = 1;
|
||||
# ifdef PNG_USER_LIMITS_SUPPORTED
|
||||
break;
|
||||
|
@ -3046,7 +3102,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
|||
# ifdef PNG_READ_PACKSWAP_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
|
||||
/* little-endian byte */
|
||||
end_mask = 0xff << end_mask;
|
||||
end_mask = (unsigned int)(0xff << end_mask);
|
||||
|
||||
else /* big-endian byte */
|
||||
# endif
|
||||
|
@ -3367,8 +3423,8 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
|||
/* Everything is aligned for png_uint_16 copies, but try for
|
||||
* png_uint_32 first.
|
||||
*/
|
||||
if (png_isaligned(dp, png_uint_32) != 0 &&
|
||||
png_isaligned(sp, png_uint_32) != 0 &&
|
||||
if (png_isaligned(dp, png_uint_32) &&
|
||||
png_isaligned(sp, png_uint_32) &&
|
||||
bytes_to_copy % (sizeof (png_uint_32)) == 0 &&
|
||||
bytes_to_jump % (sizeof (png_uint_32)) == 0)
|
||||
{
|
||||
|
@ -3488,11 +3544,11 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
|||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
png_uint_32 transformations /* Because these may affect the byte layout */)
|
||||
png_uint_32 transformations /* Because these may affect the byte layout */)
|
||||
{
|
||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
/* Offset to next interlace block */
|
||||
static PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
static PNG_CONST unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
|
||||
png_debug(1, "in png_do_read_interlace");
|
||||
if (row != NULL && row_info != NULL)
|
||||
|
@ -3507,9 +3563,10 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
{
|
||||
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
|
||||
png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
|
||||
int sshift, dshift;
|
||||
int s_start, s_end, s_inc;
|
||||
int jstop = png_pass_inc[pass];
|
||||
unsigned int sshift, dshift;
|
||||
unsigned int s_start, s_end;
|
||||
int s_inc;
|
||||
int jstop = (int)png_pass_inc[pass];
|
||||
png_byte v;
|
||||
png_uint_32 i;
|
||||
int j;
|
||||
|
@ -3517,8 +3574,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
#ifdef PNG_READ_PACKSWAP_SUPPORTED
|
||||
if ((transformations & PNG_PACKSWAP) != 0)
|
||||
{
|
||||
sshift = (int)((row_info->width + 7) & 0x07);
|
||||
dshift = (int)((final_width + 7) & 0x07);
|
||||
sshift = ((row_info->width + 7) & 0x07);
|
||||
dshift = ((final_width + 7) & 0x07);
|
||||
s_start = 7;
|
||||
s_end = 0;
|
||||
s_inc = -1;
|
||||
|
@ -3527,8 +3584,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
else
|
||||
#endif
|
||||
{
|
||||
sshift = 7 - (int)((row_info->width + 7) & 0x07);
|
||||
dshift = 7 - (int)((final_width + 7) & 0x07);
|
||||
sshift = 7 - ((row_info->width + 7) & 0x07);
|
||||
dshift = 7 - ((final_width + 7) & 0x07);
|
||||
s_start = 0;
|
||||
s_end = 7;
|
||||
s_inc = 1;
|
||||
|
@ -3540,7 +3597,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
for (j = 0; j < jstop; j++)
|
||||
{
|
||||
unsigned int tmp = *dp & (0x7f7f >> (7 - dshift));
|
||||
tmp |= v << dshift;
|
||||
tmp |= (unsigned int)(v << dshift);
|
||||
*dp = (png_byte)(tmp & 0xff);
|
||||
|
||||
if (dshift == s_end)
|
||||
|
@ -3550,7 +3607,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
}
|
||||
|
||||
else
|
||||
dshift += s_inc;
|
||||
dshift = (unsigned int)((int)dshift + s_inc);
|
||||
}
|
||||
|
||||
if (sshift == s_end)
|
||||
|
@ -3560,7 +3617,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
}
|
||||
|
||||
else
|
||||
sshift += s_inc;
|
||||
sshift = (unsigned int)((int)sshift + s_inc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -3569,16 +3626,17 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
{
|
||||
png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
|
||||
png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
|
||||
int sshift, dshift;
|
||||
int s_start, s_end, s_inc;
|
||||
int jstop = png_pass_inc[pass];
|
||||
unsigned int sshift, dshift;
|
||||
unsigned int s_start, s_end;
|
||||
int s_inc;
|
||||
int jstop = (int)png_pass_inc[pass];
|
||||
png_uint_32 i;
|
||||
|
||||
#ifdef PNG_READ_PACKSWAP_SUPPORTED
|
||||
if ((transformations & PNG_PACKSWAP) != 0)
|
||||
{
|
||||
sshift = (int)(((row_info->width + 3) & 0x03) << 1);
|
||||
dshift = (int)(((final_width + 3) & 0x03) << 1);
|
||||
sshift = (((row_info->width + 3) & 0x03) << 1);
|
||||
dshift = (((final_width + 3) & 0x03) << 1);
|
||||
s_start = 6;
|
||||
s_end = 0;
|
||||
s_inc = -2;
|
||||
|
@ -3587,8 +3645,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
else
|
||||
#endif
|
||||
{
|
||||
sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
|
||||
dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
|
||||
sshift = ((3 - ((row_info->width + 3) & 0x03)) << 1);
|
||||
dshift = ((3 - ((final_width + 3) & 0x03)) << 1);
|
||||
s_start = 0;
|
||||
s_end = 6;
|
||||
s_inc = 2;
|
||||
|
@ -3603,7 +3661,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
for (j = 0; j < jstop; j++)
|
||||
{
|
||||
unsigned int tmp = *dp & (0x3f3f >> (6 - dshift));
|
||||
tmp |= v << dshift;
|
||||
tmp |= (unsigned int)(v << dshift);
|
||||
*dp = (png_byte)(tmp & 0xff);
|
||||
|
||||
if (dshift == s_end)
|
||||
|
@ -3613,7 +3671,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
}
|
||||
|
||||
else
|
||||
dshift += s_inc;
|
||||
dshift = (unsigned int)((int)dshift + s_inc);
|
||||
}
|
||||
|
||||
if (sshift == s_end)
|
||||
|
@ -3623,7 +3681,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
}
|
||||
|
||||
else
|
||||
sshift += s_inc;
|
||||
sshift = (unsigned int)((int)sshift + s_inc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -3632,16 +3690,17 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
{
|
||||
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
|
||||
png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
|
||||
int sshift, dshift;
|
||||
int s_start, s_end, s_inc;
|
||||
unsigned int sshift, dshift;
|
||||
unsigned int s_start, s_end;
|
||||
int s_inc;
|
||||
png_uint_32 i;
|
||||
int jstop = png_pass_inc[pass];
|
||||
int jstop = (int)png_pass_inc[pass];
|
||||
|
||||
#ifdef PNG_READ_PACKSWAP_SUPPORTED
|
||||
if ((transformations & PNG_PACKSWAP) != 0)
|
||||
{
|
||||
sshift = (int)(((row_info->width + 1) & 0x01) << 2);
|
||||
dshift = (int)(((final_width + 1) & 0x01) << 2);
|
||||
sshift = (((row_info->width + 1) & 0x01) << 2);
|
||||
dshift = (((final_width + 1) & 0x01) << 2);
|
||||
s_start = 4;
|
||||
s_end = 0;
|
||||
s_inc = -4;
|
||||
|
@ -3650,8 +3709,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
else
|
||||
#endif
|
||||
{
|
||||
sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
|
||||
dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
|
||||
sshift = ((1 - ((row_info->width + 1) & 0x01)) << 2);
|
||||
dshift = ((1 - ((final_width + 1) & 0x01)) << 2);
|
||||
s_start = 0;
|
||||
s_end = 4;
|
||||
s_inc = 4;
|
||||
|
@ -3665,7 +3724,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
for (j = 0; j < jstop; j++)
|
||||
{
|
||||
unsigned int tmp = *dp & (0xf0f >> (4 - dshift));
|
||||
tmp |= v << dshift;
|
||||
tmp |= (unsigned int)(v << dshift);
|
||||
*dp = (png_byte)(tmp & 0xff);
|
||||
|
||||
if (dshift == s_end)
|
||||
|
@ -3675,7 +3734,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
}
|
||||
|
||||
else
|
||||
dshift += s_inc;
|
||||
dshift = (unsigned int)((int)dshift + s_inc);
|
||||
}
|
||||
|
||||
if (sshift == s_end)
|
||||
|
@ -3685,7 +3744,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
}
|
||||
|
||||
else
|
||||
sshift += s_inc;
|
||||
sshift = (unsigned int)((int)sshift + s_inc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -3699,7 +3758,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
|
||||
png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
|
||||
|
||||
int jstop = png_pass_inc[pass];
|
||||
int jstop = (int)png_pass_inc[pass];
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0; i < row_info->width; i++)
|
||||
|
@ -3732,7 +3791,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|||
|
||||
static void
|
||||
png_read_filter_row_sub(png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row)
|
||||
png_const_bytep prev_row)
|
||||
{
|
||||
png_size_t i;
|
||||
png_size_t istop = row_info->rowbytes;
|
||||
|
@ -3750,7 +3809,7 @@ png_read_filter_row_sub(png_row_infop row_info, png_bytep row,
|
|||
|
||||
static void
|
||||
png_read_filter_row_up(png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row)
|
||||
png_const_bytep prev_row)
|
||||
{
|
||||
png_size_t i;
|
||||
png_size_t istop = row_info->rowbytes;
|
||||
|
@ -3766,7 +3825,7 @@ png_read_filter_row_up(png_row_infop row_info, png_bytep row,
|
|||
|
||||
static void
|
||||
png_read_filter_row_avg(png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row)
|
||||
png_const_bytep prev_row)
|
||||
{
|
||||
png_size_t i;
|
||||
png_bytep rp = row;
|
||||
|
@ -3793,7 +3852,7 @@ png_read_filter_row_avg(png_row_infop row_info, png_bytep row,
|
|||
|
||||
static void
|
||||
png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row)
|
||||
png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp_end = row + row_info->rowbytes;
|
||||
int a, c;
|
||||
|
@ -3841,9 +3900,9 @@ png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,
|
|||
|
||||
static void
|
||||
png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row)
|
||||
png_const_bytep prev_row)
|
||||
{
|
||||
int bpp = (row_info->pixel_depth + 7) >> 3;
|
||||
unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
|
||||
png_bytep rp_end = row + bpp;
|
||||
|
||||
/* Process the first pixel in the row completely (this is the same as 'up'
|
||||
|
@ -3856,7 +3915,7 @@ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
|
|||
}
|
||||
|
||||
/* Remainder */
|
||||
rp_end += row_info->rowbytes - bpp;
|
||||
rp_end = rp_end + (row_info->rowbytes - bpp);
|
||||
|
||||
while (row < rp_end)
|
||||
{
|
||||
|
@ -3926,7 +3985,7 @@ png_init_filter_functions(png_structrp pp)
|
|||
|
||||
void /* PRIVATE */
|
||||
png_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row, int filter)
|
||||
png_const_bytep prev_row, int filter)
|
||||
{
|
||||
/* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define
|
||||
* PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic
|
||||
|
@ -3944,7 +4003,7 @@ png_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row,
|
|||
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
png_read_IDAT_data(png_structrp png_ptr, png_bytep output,
|
||||
png_alloc_size_t avail_out)
|
||||
png_alloc_size_t avail_out)
|
||||
{
|
||||
/* Loop reading IDATs and decompressing the result into output[avail_out] */
|
||||
png_ptr->zstream.next_out = output;
|
||||
|
@ -4019,7 +4078,7 @@ png_read_IDAT_data(png_structrp png_ptr, png_bytep output,
|
|||
*
|
||||
* TODO: deal more elegantly with truncated IDAT lists.
|
||||
*/
|
||||
ret = inflate(&png_ptr->zstream, Z_NO_FLUSH);
|
||||
ret = PNG_INFLATE(png_ptr, Z_NO_FLUSH);
|
||||
|
||||
/* Take the unconsumed output back. */
|
||||
if (output != NULL)
|
||||
|
@ -4048,7 +4107,15 @@ png_read_IDAT_data(png_structrp png_ptr, png_bytep output,
|
|||
png_zstream_error(png_ptr, ret);
|
||||
|
||||
if (output != NULL)
|
||||
png_chunk_error(png_ptr, png_ptr->zstream.msg);
|
||||
{
|
||||
if(!strncmp(png_ptr->zstream.msg,"incorrect data check",20))
|
||||
{
|
||||
png_chunk_benign_error(png_ptr, "ADLER32 checksum mismatch");
|
||||
continue;
|
||||
}
|
||||
else
|
||||
png_chunk_error(png_ptr, png_ptr->zstream.msg);
|
||||
}
|
||||
|
||||
else /* checking */
|
||||
{
|
||||
|
@ -4201,7 +4268,7 @@ png_read_start_row(png_structrp png_ptr)
|
|||
/* Offset to next interlace block in the y direction */
|
||||
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||
|
||||
int max_pixel_depth;
|
||||
unsigned int max_pixel_depth;
|
||||
png_size_t row_bytes;
|
||||
|
||||
png_debug(1, "in png_read_start_row");
|
||||
|
@ -4230,7 +4297,7 @@ png_read_start_row(png_structrp png_ptr)
|
|||
png_ptr->iwidth = png_ptr->width;
|
||||
}
|
||||
|
||||
max_pixel_depth = png_ptr->pixel_depth;
|
||||
max_pixel_depth = (unsigned int)png_ptr->pixel_depth;
|
||||
|
||||
/* WARNING: * png_read_transform_info (pngrtran.c) performs a simpler set of
|
||||
* calculations to calculate the final pixel depth, then
|
||||
|
@ -4365,7 +4432,7 @@ png_read_start_row(png_structrp png_ptr)
|
|||
defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
||||
if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
|
||||
{
|
||||
int user_pixel_depth = png_ptr->user_transform_depth *
|
||||
unsigned int user_pixel_depth = png_ptr->user_transform_depth *
|
||||
png_ptr->user_transform_channels;
|
||||
|
||||
if (user_pixel_depth > max_pixel_depth)
|
||||
|
@ -4387,7 +4454,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
|||
* for safety's sake
|
||||
*/
|
||||
row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +
|
||||
1 + ((max_pixel_depth + 7) >> 3);
|
||||
1 + ((max_pixel_depth + 7) >> 3U);
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (row_bytes > (png_uint_32)65536L)
|
||||
|
@ -4396,42 +4463,42 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
|||
|
||||
if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
|
||||
{
|
||||
png_free(png_ptr, png_ptr->big_row_buf);
|
||||
png_free(png_ptr, png_ptr->big_prev_row);
|
||||
png_free(png_ptr, png_ptr->big_row_buf);
|
||||
png_free(png_ptr, png_ptr->big_prev_row);
|
||||
|
||||
if (png_ptr->interlaced != 0)
|
||||
png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
|
||||
row_bytes + 48);
|
||||
if (png_ptr->interlaced != 0)
|
||||
png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
|
||||
row_bytes + 48);
|
||||
|
||||
else
|
||||
png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
|
||||
else
|
||||
png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
|
||||
|
||||
png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
|
||||
png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
|
||||
|
||||
#ifdef PNG_ALIGNED_MEMORY_SUPPORTED
|
||||
/* Use 16-byte aligned memory for row_buf with at least 16 bytes
|
||||
* of padding before and after row_buf; treat prev_row similarly.
|
||||
* NOTE: the alignment is to the start of the pixels, one beyond the start
|
||||
* of the buffer, because of the filter byte. Prior to libpng 1.5.6 this
|
||||
* was incorrect; the filter byte was aligned, which had the exact
|
||||
* opposite effect of that intended.
|
||||
*/
|
||||
{
|
||||
png_bytep temp = png_ptr->big_row_buf + 32;
|
||||
int extra = (int)((temp - (png_bytep)0) & 0x0f);
|
||||
png_ptr->row_buf = temp - extra - 1/*filter byte*/;
|
||||
/* Use 16-byte aligned memory for row_buf with at least 16 bytes
|
||||
* of padding before and after row_buf; treat prev_row similarly.
|
||||
* NOTE: the alignment is to the start of the pixels, one beyond the start
|
||||
* of the buffer, because of the filter byte. Prior to libpng 1.5.6 this
|
||||
* was incorrect; the filter byte was aligned, which had the exact
|
||||
* opposite effect of that intended.
|
||||
*/
|
||||
{
|
||||
png_bytep temp = png_ptr->big_row_buf + 32;
|
||||
int extra = (int)((temp - (png_bytep)0) & 0x0f);
|
||||
png_ptr->row_buf = temp - extra - 1/*filter byte*/;
|
||||
|
||||
temp = png_ptr->big_prev_row + 32;
|
||||
extra = (int)((temp - (png_bytep)0) & 0x0f);
|
||||
png_ptr->prev_row = temp - extra - 1/*filter byte*/;
|
||||
}
|
||||
temp = png_ptr->big_prev_row + 32;
|
||||
extra = (int)((temp - (png_bytep)0) & 0x0f);
|
||||
png_ptr->prev_row = temp - extra - 1/*filter byte*/;
|
||||
}
|
||||
|
||||
#else
|
||||
/* Use 31 bytes of padding before and 17 bytes after row_buf. */
|
||||
png_ptr->row_buf = png_ptr->big_row_buf + 31;
|
||||
png_ptr->prev_row = png_ptr->big_prev_row + 31;
|
||||
/* Use 31 bytes of padding before and 17 bytes after row_buf. */
|
||||
png_ptr->row_buf = png_ptr->big_row_buf + 31;
|
||||
png_ptr->prev_row = png_ptr->big_prev_row + 31;
|
||||
#endif
|
||||
png_ptr->old_big_row_buf_size = row_bytes + 48;
|
||||
png_ptr->old_big_row_buf_size = row_bytes + 48;
|
||||
}
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
|
@ -4456,7 +4523,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
|||
* does not, so free the read buffer now regardless; the sequential reader
|
||||
* reallocates it on demand.
|
||||
*/
|
||||
if (png_ptr->read_buffer != 0)
|
||||
if (png_ptr->read_buffer != NULL)
|
||||
{
|
||||
png_bytep buffer = png_ptr->read_buffer;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngset.c - storage of image information into info struct
|
||||
*
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.26 [October 20, 2016]
|
||||
* Copyright (c) 1998-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -104,14 +104,14 @@ png_set_cHRM(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
double green_x, double green_y, double blue_x, double blue_y)
|
||||
{
|
||||
png_set_cHRM_fixed(png_ptr, info_ptr,
|
||||
png_fixed(png_ptr, white_x, "cHRM White X"),
|
||||
png_fixed(png_ptr, white_y, "cHRM White Y"),
|
||||
png_fixed(png_ptr, red_x, "cHRM Red X"),
|
||||
png_fixed(png_ptr, red_y, "cHRM Red Y"),
|
||||
png_fixed(png_ptr, green_x, "cHRM Green X"),
|
||||
png_fixed(png_ptr, green_y, "cHRM Green Y"),
|
||||
png_fixed(png_ptr, blue_x, "cHRM Blue X"),
|
||||
png_fixed(png_ptr, blue_y, "cHRM Blue Y"));
|
||||
png_fixed(png_ptr, white_x, "cHRM White X"),
|
||||
png_fixed(png_ptr, white_y, "cHRM White Y"),
|
||||
png_fixed(png_ptr, red_x, "cHRM Red X"),
|
||||
png_fixed(png_ptr, red_y, "cHRM Red Y"),
|
||||
png_fixed(png_ptr, green_x, "cHRM Green X"),
|
||||
png_fixed(png_ptr, green_y, "cHRM Green Y"),
|
||||
png_fixed(png_ptr, blue_x, "cHRM Blue X"),
|
||||
png_fixed(png_ptr, blue_y, "cHRM Blue Y"));
|
||||
}
|
||||
|
||||
void PNGAPI
|
||||
|
@ -120,15 +120,15 @@ png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X,
|
|||
double blue_X, double blue_Y, double blue_Z)
|
||||
{
|
||||
png_set_cHRM_XYZ_fixed(png_ptr, info_ptr,
|
||||
png_fixed(png_ptr, red_X, "cHRM Red X"),
|
||||
png_fixed(png_ptr, red_Y, "cHRM Red Y"),
|
||||
png_fixed(png_ptr, red_Z, "cHRM Red Z"),
|
||||
png_fixed(png_ptr, green_X, "cHRM Red X"),
|
||||
png_fixed(png_ptr, green_Y, "cHRM Red Y"),
|
||||
png_fixed(png_ptr, green_Z, "cHRM Red Z"),
|
||||
png_fixed(png_ptr, blue_X, "cHRM Red X"),
|
||||
png_fixed(png_ptr, blue_Y, "cHRM Red Y"),
|
||||
png_fixed(png_ptr, blue_Z, "cHRM Red Z"));
|
||||
png_fixed(png_ptr, red_X, "cHRM Red X"),
|
||||
png_fixed(png_ptr, red_Y, "cHRM Red Y"),
|
||||
png_fixed(png_ptr, red_Z, "cHRM Red Z"),
|
||||
png_fixed(png_ptr, green_X, "cHRM Green X"),
|
||||
png_fixed(png_ptr, green_Y, "cHRM Green Y"),
|
||||
png_fixed(png_ptr, green_Z, "cHRM Green Z"),
|
||||
png_fixed(png_ptr, blue_X, "cHRM Blue X"),
|
||||
png_fixed(png_ptr, blue_Y, "cHRM Blue Y"),
|
||||
png_fixed(png_ptr, blue_Z, "cHRM Blue Z"));
|
||||
}
|
||||
# endif /* FLOATING_POINT */
|
||||
|
||||
|
@ -283,17 +283,29 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
|
||||
/* Check that the type matches the specification. */
|
||||
if (type < 0 || type > 3)
|
||||
png_error(png_ptr, "Invalid pCAL equation type");
|
||||
{
|
||||
png_chunk_report(png_ptr, "Invalid pCAL equation type",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nparams < 0 || nparams > 255)
|
||||
png_error(png_ptr, "Invalid pCAL parameter count");
|
||||
{
|
||||
png_chunk_report(png_ptr, "Invalid pCAL parameter count",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Validate params[nparams] */
|
||||
for (i=0; i<nparams; ++i)
|
||||
{
|
||||
if (params[i] == NULL ||
|
||||
!png_check_fp_string(params[i], strlen(params[i])))
|
||||
png_error(png_ptr, "Invalid format for pCAL parameter");
|
||||
{
|
||||
png_chunk_report(png_ptr, "Invalid format for pCAL parameter",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
info_ptr->pcal_purpose = png_voidcast(png_charp,
|
||||
|
@ -301,8 +313,8 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
|
||||
if (info_ptr->pcal_purpose == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Insufficient memory for pCAL purpose");
|
||||
|
||||
png_chunk_report(png_ptr, "Insufficient memory for pCAL purpose",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -316,10 +328,10 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
|
||||
length = strlen(units) + 1;
|
||||
png_debug1(3, "allocating units for info (%lu bytes)",
|
||||
(unsigned long)length);
|
||||
(unsigned long)length);
|
||||
|
||||
info_ptr->pcal_units = png_voidcast(png_charp,
|
||||
png_malloc_warn(png_ptr, length));
|
||||
png_malloc_warn(png_ptr, length));
|
||||
|
||||
if (info_ptr->pcal_units == NULL)
|
||||
{
|
||||
|
@ -331,7 +343,7 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
memcpy(info_ptr->pcal_units, units, length);
|
||||
|
||||
info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,
|
||||
(png_size_t)((nparams + 1) * (sizeof (png_charp)))));
|
||||
(png_size_t)(((unsigned int)nparams + 1) * (sizeof (png_charp)))));
|
||||
|
||||
if (info_ptr->pcal_params == NULL)
|
||||
{
|
||||
|
@ -340,7 +352,8 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
return;
|
||||
}
|
||||
|
||||
memset(info_ptr->pcal_params, 0, (nparams + 1) * (sizeof (png_charp)));
|
||||
memset(info_ptr->pcal_params, 0, ((unsigned int)nparams + 1) *
|
||||
(sizeof (png_charp)));
|
||||
|
||||
for (i = 0; i < nparams; i++)
|
||||
{
|
||||
|
@ -398,7 +411,7 @@ png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw);
|
||||
|
||||
info_ptr->scal_s_width = png_voidcast(png_charp,
|
||||
png_malloc_warn(png_ptr, lengthw));
|
||||
png_malloc_warn(png_ptr, lengthw));
|
||||
|
||||
if (info_ptr->scal_s_width == NULL)
|
||||
{
|
||||
|
@ -414,7 +427,7 @@ png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh);
|
||||
|
||||
info_ptr->scal_s_height = png_voidcast(png_charp,
|
||||
png_malloc_warn(png_ptr, lengthh));
|
||||
png_malloc_warn(png_ptr, lengthh));
|
||||
|
||||
if (info_ptr->scal_s_height == NULL)
|
||||
{
|
||||
|
@ -453,9 +466,9 @@ png_set_sCAL(png_const_structrp png_ptr, png_inforp info_ptr, int unit,
|
|||
char sheight[PNG_sCAL_MAX_DIGITS+1];
|
||||
|
||||
png_ascii_from_fp(png_ptr, swidth, (sizeof swidth), width,
|
||||
PNG_sCAL_PRECISION);
|
||||
PNG_sCAL_PRECISION);
|
||||
png_ascii_from_fp(png_ptr, sheight, (sizeof sheight), height,
|
||||
PNG_sCAL_PRECISION);
|
||||
PNG_sCAL_PRECISION);
|
||||
|
||||
png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
|
||||
}
|
||||
|
@ -513,12 +526,17 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
|
|||
png_const_colorp palette, int num_palette)
|
||||
{
|
||||
|
||||
png_uint_32 max_palette_length;
|
||||
|
||||
png_debug1(1, "in %s storage function", "PLTE");
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
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)
|
||||
png_error(png_ptr, "Invalid palette length");
|
||||
|
@ -551,14 +569,15 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
|
|||
png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
|
||||
|
||||
/* 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
|
||||
* too-large sample values.
|
||||
* of num_palette entries, in case of an invalid PNG file or incorrect
|
||||
* call to png_set_PLTE() with too-large sample values.
|
||||
*/
|
||||
png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr,
|
||||
PNG_MAX_PALETTE_LENGTH * (sizeof (png_color))));
|
||||
|
||||
if (num_palette > 0)
|
||||
memcpy(png_ptr->palette, palette, num_palette * (sizeof (png_color)));
|
||||
memcpy(png_ptr->palette, palette, (unsigned int)num_palette *
|
||||
(sizeof (png_color)));
|
||||
info_ptr->palette = png_ptr->palette;
|
||||
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
|
||||
|
||||
|
@ -643,7 +662,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
*/
|
||||
{
|
||||
int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name,
|
||||
proflen, profile, info_ptr->color_type);
|
||||
proflen, profile, info_ptr->color_type);
|
||||
|
||||
png_colorspace_sync_info(png_ptr, info_ptr);
|
||||
|
||||
|
@ -668,7 +687,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
|
||||
memcpy(new_iccp_name, name, length);
|
||||
new_iccp_profile = png_voidcast(png_bytep,
|
||||
png_malloc_warn(png_ptr, proflen));
|
||||
png_malloc_warn(png_ptr, proflen));
|
||||
|
||||
if (new_iccp_profile == NULL)
|
||||
{
|
||||
|
@ -709,7 +728,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
{
|
||||
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);
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL)
|
||||
|
@ -743,14 +762,14 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
* the overflow checks.
|
||||
*/
|
||||
new_text = png_voidcast(png_textp,png_realloc_array(png_ptr,
|
||||
info_ptr->text, old_num_text, max_text-old_num_text,
|
||||
sizeof *new_text));
|
||||
info_ptr->text, old_num_text, max_text-old_num_text,
|
||||
sizeof *new_text));
|
||||
}
|
||||
|
||||
if (new_text == NULL)
|
||||
{
|
||||
png_chunk_report(png_ptr, "too many text chunks",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -778,7 +797,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)
|
||||
{
|
||||
png_chunk_report(png_ptr, "text compression mode is out of range",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -810,7 +829,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
# else /* iTXt */
|
||||
{
|
||||
png_chunk_report(png_ptr, "iTXt chunk not supported",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
continue;
|
||||
}
|
||||
# endif
|
||||
|
@ -839,7 +858,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
if (textp->key == NULL)
|
||||
{
|
||||
png_chunk_report(png_ptr, "text chunk: out of memory",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -947,12 +966,14 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
|
|||
|
||||
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)
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
png_ptr->trans_alpha = info_ptr->trans_alpha;
|
||||
}
|
||||
|
||||
if (trans_color != NULL)
|
||||
|
@ -969,7 +990,7 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
|
|||
trans_color->green > sample_max ||
|
||||
trans_color->blue > sample_max)))
|
||||
png_warning(png_ptr,
|
||||
"tRNS chunk has out-of-range samples for bit_depth");
|
||||
"tRNS chunk has out-of-range samples for bit_depth");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1011,8 +1032,8 @@ png_set_sPLT(png_const_structrp png_ptr,
|
|||
* overflows. Notice that the parameters are (int) and (size_t)
|
||||
*/
|
||||
np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr,
|
||||
info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries,
|
||||
sizeof *np));
|
||||
info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries,
|
||||
sizeof *np));
|
||||
|
||||
if (np == NULL)
|
||||
{
|
||||
|
@ -1073,7 +1094,7 @@ png_set_sPLT(png_const_structrp png_ptr,
|
|||
* checked it when doing the allocation.
|
||||
*/
|
||||
memcpy(np->entries, entries->entries,
|
||||
entries->nentries * sizeof (png_sPLT_entry));
|
||||
(unsigned int)entries->nentries * sizeof (png_sPLT_entry));
|
||||
|
||||
/* Note that 'continue' skips the advance of the out pointer and out
|
||||
* count, so an invalid entry is not added.
|
||||
|
@ -1103,10 +1124,10 @@ check_location(png_const_structrp png_ptr, int location)
|
|||
{
|
||||
/* Write struct, so unknown chunks come from the app */
|
||||
png_app_warning(png_ptr,
|
||||
"png_set_unknown_chunks now expects a valid location");
|
||||
"png_set_unknown_chunks now expects a valid location");
|
||||
/* Use the old behavior */
|
||||
location = (png_byte)(png_ptr->mode &
|
||||
(PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));
|
||||
(PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));
|
||||
}
|
||||
|
||||
/* This need not be an internal error - if the app calls
|
||||
|
@ -1129,7 +1150,7 @@ check_location(png_const_structrp png_ptr, int location)
|
|||
|
||||
void PNGAPI
|
||||
png_set_unknown_chunks(png_const_structrp png_ptr,
|
||||
png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
|
||||
png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
|
||||
{
|
||||
png_unknown_chunkp np;
|
||||
|
||||
|
@ -1168,13 +1189,13 @@ png_set_unknown_chunks(png_const_structrp png_ptr,
|
|||
* appropriate to read or write.
|
||||
*/
|
||||
np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr,
|
||||
info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns,
|
||||
sizeof *np));
|
||||
info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns,
|
||||
sizeof *np));
|
||||
|
||||
if (np == NULL)
|
||||
{
|
||||
png_chunk_report(png_ptr, "too many unknown chunks",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -1203,12 +1224,12 @@ png_set_unknown_chunks(png_const_structrp png_ptr,
|
|||
else
|
||||
{
|
||||
np->data = png_voidcast(png_bytep,
|
||||
png_malloc_base(png_ptr, unknowns->size));
|
||||
png_malloc_base(png_ptr, unknowns->size));
|
||||
|
||||
if (np->data == NULL)
|
||||
{
|
||||
png_chunk_report(png_ptr, "unknown chunk: out of memory",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
/* But just skip storing the unknown chunk */
|
||||
continue;
|
||||
}
|
||||
|
@ -1242,7 +1263,7 @@ png_set_unknown_chunk_location(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
{
|
||||
png_app_error(png_ptr, "invalid unknown chunk location");
|
||||
/* Fake out the pre 1.6.0 behavior: */
|
||||
if ((location & PNG_HAVE_IDAT) != 0) /* undocumented! */
|
||||
if (((unsigned int)location & PNG_HAVE_IDAT) != 0) /* undocumented! */
|
||||
location = PNG_AFTER_IDAT;
|
||||
|
||||
else
|
||||
|
@ -1366,7 +1387,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
|
|||
return;
|
||||
}
|
||||
|
||||
num_chunks = num_chunks_in;
|
||||
num_chunks = (unsigned int)num_chunks_in;
|
||||
}
|
||||
|
||||
old_num_chunks = png_ptr->num_chunk_list;
|
||||
|
@ -1415,7 +1436,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
|
|||
for (i=0; i<num_chunks; ++i)
|
||||
{
|
||||
old_num_chunks = add_one_chunk(new_list, old_num_chunks,
|
||||
chunk_list+5*i, keep);
|
||||
chunk_list+5*i, keep);
|
||||
}
|
||||
|
||||
/* Now remove any spurious 'default' entries. */
|
||||
|
@ -1495,60 +1516,60 @@ png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr,
|
|||
void PNGAPI
|
||||
png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
|
||||
{
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
if (size == 0 || size > PNG_UINT_31_MAX)
|
||||
png_error(png_ptr, "invalid compression buffer size");
|
||||
if (size == 0 || size > PNG_UINT_31_MAX)
|
||||
png_error(png_ptr, "invalid compression buffer size");
|
||||
|
||||
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
|
||||
{
|
||||
png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */
|
||||
return;
|
||||
}
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
|
||||
{
|
||||
png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
|
||||
{
|
||||
if (png_ptr->zowner != 0)
|
||||
{
|
||||
if (png_ptr->zowner != 0)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Compression buffer size cannot be changed because it is in use");
|
||||
png_warning(png_ptr,
|
||||
"Compression buffer size cannot be changed because it is in use");
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef __COVERITY__
|
||||
/* Some compilers complain that this is always false. However, it
|
||||
* can be true when integer overflow happens.
|
||||
*/
|
||||
if (size > ZLIB_IO_MAX)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Compression buffer size limited to system maximum");
|
||||
size = ZLIB_IO_MAX; /* must fit */
|
||||
}
|
||||
/* Some compilers complain that this is always false. However, it
|
||||
* can be true when integer overflow happens.
|
||||
*/
|
||||
if (size > ZLIB_IO_MAX)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Compression buffer size limited to system maximum");
|
||||
size = ZLIB_IO_MAX; /* must fit */
|
||||
}
|
||||
#endif
|
||||
|
||||
if (size < 6)
|
||||
{
|
||||
/* Deflate will potentially go into an infinite loop on a SYNC_FLUSH
|
||||
* if this is permitted.
|
||||
*/
|
||||
png_warning(png_ptr,
|
||||
"Compression buffer size cannot be reduced below 6");
|
||||
if (size < 6)
|
||||
{
|
||||
/* Deflate will potentially go into an infinite loop on a SYNC_FLUSH
|
||||
* if this is permitted.
|
||||
*/
|
||||
png_warning(png_ptr,
|
||||
"Compression buffer size cannot be reduced below 6");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (png_ptr->zbuffer_size != size)
|
||||
{
|
||||
png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
|
||||
png_ptr->zbuffer_size = (uInt)size;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (png_ptr->zbuffer_size != size)
|
||||
{
|
||||
png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
|
||||
png_ptr->zbuffer_size = (uInt)size;
|
||||
}
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
|
@ -1556,7 +1577,7 @@ void PNGAPI
|
|||
png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
info_ptr->valid &= ~mask;
|
||||
info_ptr->valid &= (unsigned int)(~mask);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1568,7 +1589,7 @@ png_set_user_limits (png_structrp png_ptr, png_uint_32 user_width_max,
|
|||
{
|
||||
/* Images with dimensions larger than these limits will be
|
||||
* 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)
|
||||
return;
|
||||
|
@ -1639,4 +1660,92 @@ png_set_check_for_invalid_index(png_structrp png_ptr, int allowed)
|
|||
png_ptr->num_palette_max = -1;
|
||||
}
|
||||
#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 */
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngstruct.h - header file for PNG reference library
|
||||
*
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.24 [August 4, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -249,7 +249,7 @@ struct png_struct_def
|
|||
png_byte filter; /* file filter type (always 0) */
|
||||
png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
|
||||
png_byte pass; /* current interlace pass (0 - 6) */
|
||||
png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
|
||||
png_byte do_filter; /* row filter flags (see PNG_FILTER_ in png.h ) */
|
||||
png_byte color_type; /* color type of file */
|
||||
png_byte bit_depth; /* bit depth of file */
|
||||
png_byte usr_bit_depth; /* bit depth of users row: write only */
|
||||
|
@ -263,6 +263,9 @@ struct png_struct_def
|
|||
/* pixel depth used for the row buffers */
|
||||
png_byte transformed_pixel_depth;
|
||||
/* 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)
|
||||
png_uint_16 filler; /* filler bytes for pixel expansion */
|
||||
#endif
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
|
||||
*
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.26 [October 20, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -30,7 +30,7 @@ png_set_bgr(png_structrp png_ptr)
|
|||
#endif
|
||||
|
||||
#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
|
||||
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!
|
||||
*/
|
||||
png_app_error(png_ptr,
|
||||
"png_set_filler is invalid for low bit depth gray output");
|
||||
"png_set_filler is invalid for"
|
||||
" low bit depth gray output");
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
png_app_error(png_ptr,
|
||||
"png_set_filler: inappropriate color type");
|
||||
"png_set_filler: inappropriate color type");
|
||||
return;
|
||||
}
|
||||
# else
|
||||
|
@ -313,7 +314,7 @@ png_do_invert(png_row_infop row_info, png_bytep row)
|
|||
|
||||
#ifdef PNG_16BIT_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 */
|
||||
png_do_swap(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
|
@ -594,7 +595,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
|
|||
return; /* The filler channel has gone already */
|
||||
|
||||
/* Fix the rowbytes value. */
|
||||
row_info->rowbytes = dp-row;
|
||||
row_info->rowbytes = (unsigned int)(dp-row);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -692,7 +693,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
|
||||
* 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;
|
||||
|
||||
switch (row_info->bit_depth)
|
||||
|
@ -797,7 +798,7 @@ png_set_user_transform_info(png_structrp png_ptr, png_voidp
|
|||
(png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)
|
||||
{
|
||||
png_app_error(png_ptr,
|
||||
"info change after png_start_read_image or png_read_update_info");
|
||||
"info change after png_start_read_image or png_read_update_info");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngwio.c - functions for data output
|
||||
*
|
||||
* Last changed in libpng 1.6.15 [November 20, 2014]
|
||||
* Copyright (c) 1998-2014 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.24 [August 4, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -26,7 +26,7 @@
|
|||
* writes to a file pointer. Note that this routine sometimes gets called
|
||||
* with very small lengths, so you should implement some kind of simple
|
||||
* 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 */
|
||||
|
@ -35,7 +35,7 @@ png_write_data(png_structrp png_ptr, png_const_bytep data, png_size_t length)
|
|||
/* NOTE: write_data_fn must not change the buffer! */
|
||||
if (png_ptr->write_data_fn != NULL )
|
||||
(*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data),
|
||||
length);
|
||||
length);
|
||||
|
||||
else
|
||||
png_error(png_ptr, "Call to NULL write function");
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngwrite.c - general routines to write a PNG file
|
||||
*
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.26 [October 20, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -12,9 +12,9 @@
|
|||
*/
|
||||
|
||||
#include "pngpriv.h"
|
||||
#if defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)
|
||||
#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
|
||||
# include <errno.h>
|
||||
#endif
|
||||
#endif /* SIMPLIFIED_WRITE_STDIO */
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
|||
/* Write out all the unknown chunks for the current given location */
|
||||
static void
|
||||
write_unknown_chunks(png_structrp png_ptr, png_const_inforp info_ptr,
|
||||
unsigned int where)
|
||||
unsigned int where)
|
||||
{
|
||||
if (info_ptr->unknown_chunks_num != 0)
|
||||
{
|
||||
|
@ -148,11 +148,11 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
|
|||
# ifdef PNG_WRITE_sRGB_SUPPORTED
|
||||
if ((info_ptr->valid & PNG_INFO_sRGB) != 0)
|
||||
png_app_warning(png_ptr,
|
||||
"profile matches sRGB but writing iCCP instead");
|
||||
"profile matches sRGB but writing iCCP instead");
|
||||
# endif
|
||||
|
||||
png_write_iCCP(png_ptr, info_ptr->iccp_name,
|
||||
info_ptr->iccp_profile);
|
||||
info_ptr->iccp_profile);
|
||||
}
|
||||
# ifdef PNG_WRITE_sRGB_SUPPORTED
|
||||
else
|
||||
|
@ -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_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");
|
||||
|
||||
#ifdef PNG_WRITE_tRNS_SUPPORTED
|
||||
|
@ -383,7 +383,7 @@ png_write_end(png_structrp png_ptr, png_inforp info_ptr)
|
|||
for (i = 0; i < info_ptr->num_text; i++)
|
||||
{
|
||||
png_debug2(2, "Writing trailer text chunk %d, type %d", i,
|
||||
info_ptr->text[i].compression);
|
||||
info_ptr->text[i].compression);
|
||||
/* An internationalized chunk? */
|
||||
if (info_ptr->text[i].compression > 0)
|
||||
{
|
||||
|
@ -666,9 +666,9 @@ png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
|
|||
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
|
||||
{
|
||||
png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
|
||||
png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
|
||||
png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
|
||||
png_uint_32 s0 = (png_uint_32)(*(rp ) << 8) | *(rp + 1);
|
||||
png_uint_32 s1 = (png_uint_32)(*(rp + 2) << 8) | *(rp + 3);
|
||||
png_uint_32 s2 = (png_uint_32)(*(rp + 4) << 8) | *(rp + 5);
|
||||
png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL);
|
||||
png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
|
||||
*(rp ) = (png_byte)(red >> 8);
|
||||
|
@ -693,7 +693,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
|
|||
return;
|
||||
|
||||
png_debug2(1, "in png_write_row (row %u, pass %d)",
|
||||
png_ptr->row_number, png_ptr->pass);
|
||||
png_ptr->row_number, png_ptr->pass);
|
||||
|
||||
/* Initialize transformations and other stuff if first time */
|
||||
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
|
||||
|
@ -901,7 +901,7 @@ png_set_flush(png_structrp png_ptr, int nrows)
|
|||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
|
||||
png_ptr->flush_dist = (nrows < 0 ? 0 : (png_uint_32)nrows);
|
||||
}
|
||||
|
||||
/* Flush the current output buffers now */
|
||||
|
@ -1069,7 +1069,7 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
|
|||
* is not available so the filter can't be used. Just warn here.
|
||||
*/
|
||||
png_app_warning(png_ptr,
|
||||
"png_set_filter: UP/AVG/PAETH cannot be added after start");
|
||||
"png_set_filter: UP/AVG/PAETH cannot be added after start");
|
||||
filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH);
|
||||
}
|
||||
|
||||
|
@ -1095,13 +1095,13 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
|
|||
|
||||
if (png_ptr->try_row == NULL)
|
||||
png_ptr->try_row = png_voidcast(png_bytep,
|
||||
png_malloc(png_ptr, buf_size));
|
||||
png_malloc(png_ptr, buf_size));
|
||||
|
||||
if (num_filters > 1)
|
||||
{
|
||||
if (png_ptr->tst_row == NULL)
|
||||
png_ptr->tst_row = png_voidcast(png_bytep,
|
||||
png_malloc(png_ptr, buf_size));
|
||||
png_malloc(png_ptr, buf_size));
|
||||
}
|
||||
}
|
||||
png_ptr->do_filter = (png_byte)filters;
|
||||
|
@ -1422,7 +1422,7 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
|
|||
png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported");
|
||||
#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)
|
||||
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
|
||||
png_set_packswap(png_ptr);
|
||||
|
@ -1452,7 +1452,6 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
|
|||
|
||||
|
||||
#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
|
||||
# ifdef PNG_STDIO_SUPPORTED /* currently required for png_image_write_* */
|
||||
/* Initialize the write structure - general purpose utility. */
|
||||
static int
|
||||
png_image_write_init(png_imagep image)
|
||||
|
@ -1504,6 +1503,10 @@ typedef struct
|
|||
png_const_voidp first_row;
|
||||
ptrdiff_t row_bytes;
|
||||
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;
|
||||
|
||||
/* Write png_uint_16 input to a 16-bit PNG; the png_ptr has already been set to
|
||||
|
@ -1522,7 +1525,8 @@ png_write_image_16bit(png_voidp argument)
|
|||
display->first_row);
|
||||
png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row);
|
||||
png_uint_16p row_end;
|
||||
const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1;
|
||||
const unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ?
|
||||
3 : 1;
|
||||
int aindex = 0;
|
||||
png_uint_32 y = image->height;
|
||||
|
||||
|
@ -1536,9 +1540,9 @@ png_write_image_16bit(png_voidp argument)
|
|||
++output_row;
|
||||
}
|
||||
else
|
||||
aindex = channels;
|
||||
aindex = (int)channels;
|
||||
# else
|
||||
aindex = channels;
|
||||
aindex = (int)channels;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
@ -1551,7 +1555,7 @@ png_write_image_16bit(png_voidp argument)
|
|||
*/
|
||||
row_end = output_row + image->width * (channels+1);
|
||||
|
||||
while (y-- > 0)
|
||||
for (; y > 0; --y)
|
||||
{
|
||||
png_const_uint_16p in_ptr = input_row;
|
||||
png_uint_16p out_ptr = output_row;
|
||||
|
@ -1572,7 +1576,7 @@ png_write_image_16bit(png_voidp argument)
|
|||
if (alpha > 0 && alpha < 65535)
|
||||
reciprocal = ((0xffff<<15)+(alpha>>1))/alpha;
|
||||
|
||||
c = channels;
|
||||
c = (int)channels;
|
||||
do /* always at least one channel */
|
||||
{
|
||||
png_uint_16 component = *in_ptr++;
|
||||
|
@ -1607,7 +1611,7 @@ png_write_image_16bit(png_voidp argument)
|
|||
}
|
||||
|
||||
png_write_row(png_ptr, png_voidcast(png_const_bytep, display->local_row));
|
||||
input_row += display->row_bytes/(sizeof (png_uint_16));
|
||||
input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16));
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -1625,7 +1629,7 @@ png_write_image_16bit(png_voidp argument)
|
|||
|
||||
static png_byte
|
||||
png_unpremultiply(png_uint_32 component, png_uint_32 alpha,
|
||||
png_uint_32 reciprocal/*from the above macro*/)
|
||||
png_uint_32 reciprocal/*from the above macro*/)
|
||||
{
|
||||
/* The following gives 1.0 for an alpha of 0, which is fine, otherwise if 0/0
|
||||
* is represented as some other value there is more likely to be a
|
||||
|
@ -1680,7 +1684,8 @@ png_write_image_8bit(png_voidp argument)
|
|||
display->first_row);
|
||||
png_bytep output_row = png_voidcast(png_bytep, display->local_row);
|
||||
png_uint_32 y = image->height;
|
||||
const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1;
|
||||
const unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ?
|
||||
3 : 1;
|
||||
|
||||
if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0)
|
||||
{
|
||||
|
@ -1697,12 +1702,12 @@ png_write_image_8bit(png_voidp argument)
|
|||
|
||||
else
|
||||
# endif
|
||||
aindex = channels;
|
||||
aindex = (int)channels;
|
||||
|
||||
/* Use row_end in place of a loop counter: */
|
||||
row_end = output_row + image->width * (channels+1);
|
||||
|
||||
while (y-- > 0)
|
||||
for (; y > 0; --y)
|
||||
{
|
||||
png_const_uint_16p in_ptr = input_row;
|
||||
png_bytep out_ptr = output_row;
|
||||
|
@ -1720,7 +1725,7 @@ png_write_image_8bit(png_voidp argument)
|
|||
if (alphabyte > 0 && alphabyte < 255)
|
||||
reciprocal = UNP_RECIPROCAL(alpha);
|
||||
|
||||
c = channels;
|
||||
c = (int)channels;
|
||||
do /* always at least one channel */
|
||||
*out_ptr++ = png_unpremultiply(*in_ptr++, alpha, reciprocal);
|
||||
while (--c > 0);
|
||||
|
@ -1732,7 +1737,7 @@ png_write_image_8bit(png_voidp argument)
|
|||
|
||||
png_write_row(png_ptr, png_voidcast(png_const_bytep,
|
||||
display->local_row));
|
||||
input_row += display->row_bytes/(sizeof (png_uint_16));
|
||||
input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16));
|
||||
} /* while y */
|
||||
}
|
||||
|
||||
|
@ -1743,7 +1748,7 @@ png_write_image_8bit(png_voidp argument)
|
|||
*/
|
||||
png_bytep row_end = output_row + image->width * channels;
|
||||
|
||||
while (y-- > 0)
|
||||
for (; y > 0; --y)
|
||||
{
|
||||
png_const_uint_16p in_ptr = input_row;
|
||||
png_bytep out_ptr = output_row;
|
||||
|
@ -1757,7 +1762,7 @@ png_write_image_8bit(png_voidp argument)
|
|||
}
|
||||
|
||||
png_write_row(png_ptr, output_row);
|
||||
input_row += display->row_bytes/(sizeof (png_uint_16));
|
||||
input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1774,7 +1779,7 @@ png_image_set_PLTE(png_image_write_control *display)
|
|||
|
||||
/* NOTE: the caller must check for cmap != NULL and entries != 0 */
|
||||
const png_uint_32 format = image->format;
|
||||
const int channels = PNG_IMAGE_SAMPLE_CHANNELS(format);
|
||||
const unsigned int channels = PNG_IMAGE_SAMPLE_CHANNELS(format);
|
||||
|
||||
# if defined(PNG_FORMAT_BGR_SUPPORTED) &&\
|
||||
defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED)
|
||||
|
@ -1806,7 +1811,7 @@ png_image_set_PLTE(png_image_write_control *display)
|
|||
{
|
||||
png_const_uint_16p entry = png_voidcast(png_const_uint_16p, cmap);
|
||||
|
||||
entry += i * channels;
|
||||
entry += (unsigned int)i * channels;
|
||||
|
||||
if ((channels & 1) != 0) /* no alpha */
|
||||
{
|
||||
|
@ -1845,16 +1850,16 @@ png_image_set_PLTE(png_image_write_control *display)
|
|||
if (channels >= 3) /* RGB */
|
||||
{
|
||||
palette[i].blue = png_unpremultiply(entry[afirst + (2 ^ bgr)],
|
||||
alpha, reciprocal);
|
||||
alpha, reciprocal);
|
||||
palette[i].green = png_unpremultiply(entry[afirst + 1], alpha,
|
||||
reciprocal);
|
||||
reciprocal);
|
||||
palette[i].red = png_unpremultiply(entry[afirst + bgr], alpha,
|
||||
reciprocal);
|
||||
reciprocal);
|
||||
}
|
||||
|
||||
else /* gray */
|
||||
palette[i].blue = palette[i].red = palette[i].green =
|
||||
png_unpremultiply(entry[afirst], alpha, reciprocal);
|
||||
png_unpremultiply(entry[afirst], alpha, reciprocal);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1862,7 +1867,7 @@ png_image_set_PLTE(png_image_write_control *display)
|
|||
{
|
||||
png_const_bytep entry = png_voidcast(png_const_bytep, cmap);
|
||||
|
||||
entry += i * channels;
|
||||
entry += (unsigned int)i * channels;
|
||||
|
||||
switch (channels)
|
||||
{
|
||||
|
@ -1901,20 +1906,20 @@ png_image_set_PLTE(png_image_write_control *display)
|
|||
# endif
|
||||
|
||||
png_set_PLTE(image->opaque->png_ptr, image->opaque->info_ptr, palette,
|
||||
entries);
|
||||
entries);
|
||||
|
||||
if (num_trans > 0)
|
||||
png_set_tRNS(image->opaque->png_ptr, image->opaque->info_ptr, tRNS,
|
||||
num_trans, NULL);
|
||||
num_trans, NULL);
|
||||
|
||||
image->colormap_entries = entries;
|
||||
image->colormap_entries = (png_uint_32)entries;
|
||||
}
|
||||
|
||||
static int
|
||||
png_image_write_main(png_voidp argument)
|
||||
{
|
||||
png_image_write_control *display = png_voidcast(png_image_write_control*,
|
||||
argument);
|
||||
argument);
|
||||
png_imagep image = display->image;
|
||||
png_structrp png_ptr = image->opaque->png_ptr;
|
||||
png_inforp info_ptr = image->opaque->info_ptr;
|
||||
|
@ -1931,9 +1936,43 @@ png_image_write_main(png_voidp argument)
|
|||
png_set_benign_errors(png_ptr, 0/*error*/);
|
||||
# endif
|
||||
|
||||
/* Default the 'row_stride' parameter if required. */
|
||||
if (display->row_stride == 0)
|
||||
display->row_stride = PNG_IMAGE_ROW_STRIDE(*image);
|
||||
/* Default the 'row_stride' parameter if required, also check the row stride
|
||||
* and total image size to ensure that they are within the system limits.
|
||||
*/
|
||||
{
|
||||
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. */
|
||||
if ((format & PNG_FORMAT_FLAG_COLORMAP) != 0)
|
||||
|
@ -1943,24 +1982,24 @@ png_image_write_main(png_voidp argument)
|
|||
png_uint_32 entries = image->colormap_entries;
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
|
||||
entries > 16 ? 8 : (entries > 4 ? 4 : (entries > 2 ? 2 : 1)),
|
||||
PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
entries > 16 ? 8 : (entries > 4 ? 4 : (entries > 2 ? 2 : 1)),
|
||||
PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
png_image_set_PLTE(display);
|
||||
}
|
||||
|
||||
else
|
||||
png_error(image->opaque->png_ptr,
|
||||
"no color-map for color-mapped image");
|
||||
"no color-map for color-mapped image");
|
||||
}
|
||||
|
||||
else
|
||||
png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
|
||||
write_16bit ? 16 : 8,
|
||||
((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) +
|
||||
((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0),
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
write_16bit ? 16 : 8,
|
||||
((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) +
|
||||
((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0),
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
/* Counter-intuitively the data transformations must be called *after*
|
||||
* png_write_info, not before as in the read code, but the 'set' functions
|
||||
|
@ -1975,11 +2014,11 @@ png_image_write_main(png_voidp argument)
|
|||
|
||||
if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0)
|
||||
png_set_cHRM_fixed(png_ptr, info_ptr,
|
||||
/* color x y */
|
||||
/* white */ 31270, 32900,
|
||||
/* red */ 64000, 33000,
|
||||
/* green */ 30000, 60000,
|
||||
/* blue */ 15000, 6000
|
||||
/* color x y */
|
||||
/* white */ 31270, 32900,
|
||||
/* red */ 64000, 33000,
|
||||
/* green */ 30000, 60000,
|
||||
/* blue */ 15000, 6000
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1998,7 +2037,7 @@ png_image_write_main(png_voidp argument)
|
|||
/* Now set up the data transformations (*after* the header is written),
|
||||
* 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)
|
||||
{
|
||||
|
@ -2073,7 +2112,7 @@ png_image_write_main(png_voidp argument)
|
|||
(colormap == 0 && display->convert_to_8bit != 0))
|
||||
{
|
||||
png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr,
|
||||
png_get_rowbytes(png_ptr, info_ptr)));
|
||||
png_get_rowbytes(png_ptr, info_ptr)));
|
||||
int result;
|
||||
|
||||
display->local_row = row;
|
||||
|
@ -2099,7 +2138,7 @@ png_image_write_main(png_voidp argument)
|
|||
ptrdiff_t row_bytes = display->row_bytes;
|
||||
png_uint_32 y = image->height;
|
||||
|
||||
while (y-- > 0)
|
||||
for (; y > 0; --y)
|
||||
{
|
||||
png_write_row(png_ptr, row);
|
||||
row += row_bytes;
|
||||
|
@ -2110,14 +2149,130 @@ png_image_write_main(png_voidp argument)
|
|||
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
|
||||
png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
|
||||
const void *buffer, png_int_32 row_stride, const void *colormap)
|
||||
const void *buffer, png_int_32 row_stride, const void *colormap)
|
||||
{
|
||||
/* Write the image to the given (FILE*). */
|
||||
if (image != NULL && image->version == PNG_IMAGE_VERSION)
|
||||
{
|
||||
if (file != NULL)
|
||||
if (file != NULL && buffer != NULL)
|
||||
{
|
||||
if (png_image_write_init(image) != 0)
|
||||
{
|
||||
|
@ -2148,12 +2303,12 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
|
|||
|
||||
else
|
||||
return png_image_error(image,
|
||||
"png_image_write_to_stdio: invalid argument");
|
||||
"png_image_write_to_stdio: invalid argument");
|
||||
}
|
||||
|
||||
else if (image != NULL)
|
||||
return png_image_error(image,
|
||||
"png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION");
|
||||
"png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION");
|
||||
|
||||
else
|
||||
return 0;
|
||||
|
@ -2161,20 +2316,20 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
|
|||
|
||||
int PNGAPI
|
||||
png_image_write_to_file(png_imagep image, const char *file_name,
|
||||
int convert_to_8bit, const void *buffer, png_int_32 row_stride,
|
||||
const void *colormap)
|
||||
int convert_to_8bit, const void *buffer, png_int_32 row_stride,
|
||||
const void *colormap)
|
||||
{
|
||||
/* Write the image to the named file. */
|
||||
if (image != NULL && image->version == PNG_IMAGE_VERSION)
|
||||
{
|
||||
if (file_name != NULL)
|
||||
if (file_name != NULL && buffer != NULL)
|
||||
{
|
||||
FILE *fp = fopen(file_name, "wb");
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
if (png_image_write_to_stdio(image, fp, convert_to_8bit, buffer,
|
||||
row_stride, colormap) != 0)
|
||||
row_stride, colormap) != 0)
|
||||
{
|
||||
int error; /* from fflush/fclose */
|
||||
|
||||
|
@ -2215,16 +2370,16 @@ png_image_write_to_file(png_imagep image, const char *file_name,
|
|||
|
||||
else
|
||||
return png_image_error(image,
|
||||
"png_image_write_to_file: invalid argument");
|
||||
"png_image_write_to_file: invalid argument");
|
||||
}
|
||||
|
||||
else if (image != NULL)
|
||||
return png_image_error(image,
|
||||
"png_image_write_to_file: incorrect PNG_IMAGE_VERSION");
|
||||
"png_image_write_to_file: incorrect PNG_IMAGE_VERSION");
|
||||
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
# endif /* STDIO */
|
||||
#endif /* SIMPLIFIED_WRITE_STDIO */
|
||||
#endif /* SIMPLIFIED_WRITE */
|
||||
#endif /* WRITE */
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
*
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.26 [October 20, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -177,7 +177,7 @@ png_do_shift(png_row_infop row_info, png_bytep row,
|
|||
if (row_info->color_type != PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
int shift_start[4], shift_dec[4];
|
||||
int channels = 0;
|
||||
unsigned int channels = 0;
|
||||
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
{
|
||||
|
@ -525,7 +525,7 @@ png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
|
|||
#ifdef PNG_WRITE_FILLER_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_FILLER) != 0)
|
||||
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
|
||||
!(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
|
||||
!(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
|
||||
|
@ -549,7 +549,7 @@ png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
|
|||
#ifdef PNG_WRITE_SHIFT_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_SHIFT) != 0)
|
||||
png_do_shift(row_info, png_ptr->row_buf + 1,
|
||||
&(png_ptr->shift));
|
||||
&(png_ptr->shift));
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/* pngwutil.c - utilities to write a PNG file
|
||||
*
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.26 [October 20, 2016]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
|
@ -23,10 +23,10 @@
|
|||
void PNGAPI
|
||||
png_save_uint_32(png_bytep buf, png_uint_32 i)
|
||||
{
|
||||
buf[0] = (png_byte)(i >> 24);
|
||||
buf[1] = (png_byte)(i >> 16);
|
||||
buf[2] = (png_byte)(i >> 8);
|
||||
buf[3] = (png_byte)(i );
|
||||
buf[0] = (png_byte)((i >> 24) & 0xffU);
|
||||
buf[1] = (png_byte)((i >> 16) & 0xffU);
|
||||
buf[2] = (png_byte)((i >> 8) & 0xffU);
|
||||
buf[3] = (png_byte)( i & 0xffU);
|
||||
}
|
||||
|
||||
/* 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
|
||||
png_save_uint_16(png_bytep buf, unsigned int i)
|
||||
{
|
||||
buf[0] = (png_byte)(i >> 8);
|
||||
buf[1] = (png_byte)(i );
|
||||
buf[0] = (png_byte)((i >> 8) & 0xffU);
|
||||
buf[1] = (png_byte)( i & 0xffU);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -59,7 +59,7 @@ png_write_sig(png_structrp png_ptr)
|
|||
|
||||
/* Write the rest of the 8 byte signature */
|
||||
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)
|
||||
png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
|
||||
|
@ -174,12 +174,12 @@ png_write_chunk_end(png_structrp png_ptr)
|
|||
*/
|
||||
static void
|
||||
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)
|
||||
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)
|
||||
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. */
|
||||
void PNGAPI
|
||||
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,
|
||||
length);
|
||||
length);
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
static int
|
||||
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)
|
||||
{
|
||||
|
@ -408,7 +408,7 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
|
|||
png_ptr->zstream.avail_out = 0;
|
||||
|
||||
/* 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)
|
||||
ret = deflateReset(&png_ptr->zstream);
|
||||
|
@ -416,7 +416,7 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
|
|||
else
|
||||
{
|
||||
ret = deflateInit2(&png_ptr->zstream, level, method, windowBits,
|
||||
memLevel, strategy);
|
||||
memLevel, strategy);
|
||||
|
||||
if (ret == Z_OK)
|
||||
png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;
|
||||
|
@ -477,7 +477,7 @@ typedef struct
|
|||
|
||||
static void
|
||||
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_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 */
|
||||
static int
|
||||
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;
|
||||
|
||||
|
@ -579,7 +579,7 @@ png_text_compress(png_structrp png_ptr, png_uint_32 chunk_name,
|
|||
|
||||
/* Compress the data */
|
||||
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
|
||||
* 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 */
|
||||
|
||||
#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
|
||||
* information. Note that the rest of this code depends upon this
|
||||
* information being correct.
|
||||
|
@ -922,17 +838,20 @@ void /* PRIVATE */
|
|||
png_write_PLTE(png_structrp png_ptr, png_const_colorp palette,
|
||||
png_uint_32 num_pal)
|
||||
{
|
||||
png_uint_32 i;
|
||||
png_uint_32 max_palette_length, i;
|
||||
png_const_colorp pal_ptr;
|
||||
png_byte buf[3];
|
||||
|
||||
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 ((
|
||||
#ifdef PNG_MNG_FEATURES_SUPPORTED
|
||||
(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 &&
|
||||
#endif
|
||||
num_pal == 0) || num_pal > 256)
|
||||
num_pal == 0) || num_pal > max_palette_length)
|
||||
{
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
|
@ -1006,7 +925,7 @@ png_write_PLTE(png_structrp png_ptr, png_const_colorp palette,
|
|||
*/
|
||||
void /* PRIVATE */
|
||||
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)
|
||||
{
|
||||
|
@ -1018,7 +937,7 @@ png_compress_IDAT(png_structrp png_ptr, png_const_bytep input,
|
|||
if (png_ptr->zbuffer_list == NULL)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1257,7 +1176,7 @@ png_write_sPLT(png_structrp png_ptr, png_const_sPLT_tp spalette)
|
|||
png_byte new_name[80];
|
||||
png_byte entrybuf[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;
|
||||
#ifndef PNG_POINTER_INDEXING_SUPPORTED
|
||||
int i;
|
||||
|
@ -1439,12 +1358,12 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,
|
|||
|
||||
/* Write the chunk out as it is */
|
||||
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)
|
||||
{
|
||||
/* One 16 bit value */
|
||||
/* One 16-bit value */
|
||||
if (tran->gray >= (1 << png_ptr->bit_depth))
|
||||
{
|
||||
png_app_warning(png_ptr,
|
||||
|
@ -1459,7 +1378,7 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,
|
|||
|
||||
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 + 2, tran->green);
|
||||
png_save_uint_16(buf + 4, tran->blue);
|
||||
|
@ -1470,7 +1389,7 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,
|
|||
#endif
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1522,7 +1441,8 @@ png_write_bKGD(png_structrp png_ptr, png_const_color_16p back, int color_type)
|
|||
#endif
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -1652,7 +1572,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 */
|
||||
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)
|
||||
png_error(png_ptr, png_ptr->zstream.msg);
|
||||
|
@ -1823,7 +1743,7 @@ png_write_pCAL(png_structrp png_ptr, png_charp purpose, png_int_32 X0,
|
|||
total_len = purpose_len + units_len + 10;
|
||||
|
||||
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
|
||||
* null terminator for the last parameter.
|
||||
|
@ -2022,7 +1942,7 @@ png_write_start_row(png_structrp png_ptr)
|
|||
*/
|
||||
if ((filters & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) != 0)
|
||||
png_ptr->prev_row = png_voidcast(png_bytep,
|
||||
png_calloc(png_ptr, buf_size));
|
||||
png_calloc(png_ptr, buf_size));
|
||||
#endif /* WRITE_FILTER */
|
||||
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
|
@ -2325,7 +2245,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
|||
*/
|
||||
static void /* PRIVATE */
|
||||
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
|
||||
static png_size_t /* PRIVATE */
|
||||
|
@ -2335,7 +2255,7 @@ png_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp,
|
|||
png_bytep rp, dp, lp;
|
||||
png_size_t i;
|
||||
png_size_t sum = 0;
|
||||
int v;
|
||||
unsigned int v;
|
||||
|
||||
png_ptr->try_row[0] = PNG_FILTER_VALUE_SUB;
|
||||
|
||||
|
@ -2343,14 +2263,22 @@ png_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp,
|
|||
i++, rp++, dp++)
|
||||
{
|
||||
v = *dp = *rp;
|
||||
#ifdef PNG_USE_ABS
|
||||
sum += 128 - abs((int)v - 128);
|
||||
#else
|
||||
sum += (v < 128) ? v : 256 - v;
|
||||
#endif
|
||||
}
|
||||
|
||||
for (lp = png_ptr->row_buf + 1; i < row_bytes;
|
||||
i++, rp++, lp++, dp++)
|
||||
{
|
||||
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;
|
||||
#endif
|
||||
|
||||
if (sum > lmins) /* We are already worse, don't continue. */
|
||||
break;
|
||||
|
@ -2359,6 +2287,28 @@ png_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp,
|
|||
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 */
|
||||
png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
|
||||
const png_size_t lmins)
|
||||
|
@ -2366,7 +2316,7 @@ png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
|
|||
png_bytep rp, dp, pp;
|
||||
png_size_t i;
|
||||
png_size_t sum = 0;
|
||||
int v;
|
||||
unsigned int v;
|
||||
|
||||
png_ptr->try_row[0] = PNG_FILTER_VALUE_UP;
|
||||
|
||||
|
@ -2375,7 +2325,11 @@ png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
|
|||
i++, rp++, pp++, dp++)
|
||||
{
|
||||
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;
|
||||
#endif
|
||||
|
||||
if (sum > lmins) /* We are already worse, don't continue. */
|
||||
break;
|
||||
|
@ -2383,24 +2337,43 @@ png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
|
|||
|
||||
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 */
|
||||
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_uint_32 i;
|
||||
png_size_t sum = 0;
|
||||
int v;
|
||||
unsigned int v;
|
||||
|
||||
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++)
|
||||
pp = png_ptr->prev_row + 1; i < bpp; i++)
|
||||
{
|
||||
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;
|
||||
#endif
|
||||
}
|
||||
|
||||
for (lp = png_ptr->row_buf + 1; i < row_bytes; i++)
|
||||
|
@ -2408,7 +2381,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))
|
||||
& 0xff);
|
||||
|
||||
#ifdef PNG_USE_ABS
|
||||
sum += 128 - abs((int)v - 128);
|
||||
#else
|
||||
sum += (v < 128) ? v : 256 - v;
|
||||
#endif
|
||||
|
||||
if (sum > lmins) /* We are already worse, don't continue. */
|
||||
break;
|
||||
|
@ -2416,6 +2393,27 @@ png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,
|
|||
|
||||
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 */
|
||||
png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
|
||||
|
@ -2424,7 +2422,7 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
|
|||
png_bytep rp, dp, pp, cp, lp;
|
||||
png_size_t i;
|
||||
png_size_t sum = 0;
|
||||
int v;
|
||||
unsigned int v;
|
||||
|
||||
png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH;
|
||||
|
||||
|
@ -2433,7 +2431,11 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
|
|||
{
|
||||
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;
|
||||
#endif
|
||||
}
|
||||
|
||||
for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes;
|
||||
|
@ -2462,7 +2464,11 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
|
|||
|
||||
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;
|
||||
#endif
|
||||
|
||||
if (sum > lmins) /* We are already worse, don't continue. */
|
||||
break;
|
||||
|
@ -2470,6 +2476,48 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
|
|||
|
||||
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 */
|
||||
|
||||
void /* PRIVATE */
|
||||
|
@ -2478,7 +2526,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||
#ifndef PNG_WRITE_FILTER_SUPPORTED
|
||||
png_write_filtered_row(png_ptr, png_ptr->row_buf, row_info->rowbytes+1);
|
||||
#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 best_row;
|
||||
png_uint_32 bpp;
|
||||
|
@ -2524,32 +2572,33 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||
*/
|
||||
best_row = png_ptr->row_buf;
|
||||
|
||||
|
||||
if ((filter_to_do & PNG_FILTER_NONE) != 0 && filter_to_do != PNG_FILTER_NONE)
|
||||
if (PNG_SIZE_MAX/128 <= row_bytes)
|
||||
{
|
||||
/* 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_size_t sum = 0;
|
||||
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++)
|
||||
{
|
||||
v = *rp;
|
||||
#ifdef PNG_USE_ABS
|
||||
sum += 128 - abs((int)v - 128);
|
||||
#else
|
||||
sum += (v < 128) ? v : 256 - v;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2560,7 +2609,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||
if (filter_to_do == PNG_FILTER_SUB)
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
@ -2569,7 +2618,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||
png_size_t sum;
|
||||
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)
|
||||
{
|
||||
|
@ -2586,7 +2635,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||
/* Up filter */
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -2595,7 +2644,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||
png_size_t sum;
|
||||
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)
|
||||
{
|
||||
|
@ -2612,7 +2661,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||
/* Avg filter */
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -2636,9 +2685,9 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
@ -2651,7 +2700,6 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||
|
||||
if (sum < mins)
|
||||
{
|
||||
mins = sum;
|
||||
best_row = png_ptr->try_row;
|
||||
if (png_ptr->tst_row != NULL)
|
||||
{
|
||||
|
@ -2671,7 +2719,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||
/* Do the actual writing of a previously filtered row. */
|
||||
static void
|
||||
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");
|
||||
|
||||
|
|
Loading…
Reference in New Issue