[CHG] libpng updated to version 1.5.7

This commit is contained in:
Crayon2000 2011-12-19 20:23:19 +00:00
parent b168b38222
commit df330a0699
14 changed files with 489 additions and 215 deletions

View file

@ -1,7 +1,7 @@
/* png.c - location for general purpose libpng functions /* png.c - location for general purpose libpng functions
* *
* Last changed in libpng 1.5.6 [November 3, 2011] * Last changed in libpng 1.5.7 [December 15, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -14,7 +14,7 @@
#include "pngpriv.h" #include "pngpriv.h"
/* Generate a compiler error if there is an old png.h in the search path. */ /* Generate a compiler error if there is an old png.h in the search path. */
typedef png_libpng_version_1_5_6 Your_png_h_is_not_version_1_5_6; typedef png_libpng_version_1_5_7 Your_png_h_is_not_version_1_5_7;
/* Tells libpng that we have already handled the first "num_bytes" bytes /* Tells libpng that we have already handled the first "num_bytes" bytes
* of the PNG file signature. If the PNG data is embedded into another * of the PNG file signature. If the PNG data is embedded into another
@ -599,9 +599,19 @@ png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime)
if (png_ptr == NULL) if (png_ptr == NULL)
return (NULL); return (NULL);
if (ptime->year > 9999 /* RFC1123 limitation */ ||
ptime->month == 0 || ptime->month > 12 ||
ptime->day == 0 || ptime->day > 31 ||
ptime->hour > 23 || ptime->minute > 59 ||
ptime->second > 60)
{
png_warning(png_ptr, "Ignoring invalid time value");
return (NULL);
}
{ {
size_t pos = 0; size_t pos = 0;
char number_buf[5]; /* enough for a four digit year */ char number_buf[5]; /* enough for a four-digit year */
# define APPEND_STRING(string)\ # define APPEND_STRING(string)\
pos = png_safecat(png_ptr->time_buffer, sizeof png_ptr->time_buffer,\ pos = png_safecat(png_ptr->time_buffer, sizeof png_ptr->time_buffer,\
@ -612,17 +622,17 @@ png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime)
if (pos < (sizeof png_ptr->time_buffer)-1)\ if (pos < (sizeof png_ptr->time_buffer)-1)\
png_ptr->time_buffer[pos++] = (ch) png_ptr->time_buffer[pos++] = (ch)
APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day % 32); APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day);
APPEND(' '); APPEND(' ');
APPEND_STRING(short_months[(ptime->month - 1) % 12]); APPEND_STRING(short_months[(ptime->month - 1)]);
APPEND(' '); APPEND(' ');
APPEND_NUMBER(PNG_NUMBER_FORMAT_u, ptime->year); APPEND_NUMBER(PNG_NUMBER_FORMAT_u, ptime->year);
APPEND(' '); APPEND(' ');
APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->hour % 24); APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->hour);
APPEND(':'); APPEND(':');
APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->minute % 60); APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->minute);
APPEND(':'); APPEND(':');
APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->second % 61); APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->second);
APPEND_STRING(" +0000"); /* This reliably terminates the buffer */ APPEND_STRING(" +0000"); /* This reliably terminates the buffer */
# undef APPEND # undef APPEND
@ -645,13 +655,13 @@ png_get_copyright(png_const_structp png_ptr)
#else #else
# ifdef __STDC__ # ifdef __STDC__
return PNG_STRING_NEWLINE \ return PNG_STRING_NEWLINE \
"libpng version 1.5.6 - November 3, 2011" PNG_STRING_NEWLINE \ "libpng version 1.5.7 - December 15, 2011" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE; PNG_STRING_NEWLINE;
# else # else
return "libpng version 1.5.6 - November 3, 2011\ return "libpng version 1.5.7 - December 15, 2011\
Copyright (c) 1998-2011 Glenn Randers-Pehrson\ Copyright (c) 1998-2011 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@ -2164,9 +2174,9 @@ png_64bit_product (long v1, long v2, unsigned long *hi_product,
static png_uint_32 static png_uint_32
png_8bit_l2[128] = png_8bit_l2[128] =
{ {
# if PNG_DO_BC # ifdef PNG_DO_BC
for (i=128;i<256;++i) { .5 - l(i/255)/l(2)*65536*65536; } for (i=128;i<256;++i) { .5 - l(i/255)/l(2)*65536*65536; }
# endif # else
4270715492U, 4222494797U, 4174646467U, 4127164793U, 4080044201U, 4033279239U, 4270715492U, 4222494797U, 4174646467U, 4127164793U, 4080044201U, 4033279239U,
3986864580U, 3940795015U, 3895065449U, 3849670902U, 3804606499U, 3759867474U, 3986864580U, 3940795015U, 3895065449U, 3849670902U, 3804606499U, 3759867474U,
3715449162U, 3671346997U, 3627556511U, 3584073329U, 3540893168U, 3498011834U, 3715449162U, 3671346997U, 3627556511U, 3584073329U, 3540893168U, 3498011834U,
@ -2189,6 +2199,8 @@ png_8bit_l2[128] =
324227938U, 298676034U, 273229066U, 247886176U, 222646516U, 197509248U, 324227938U, 298676034U, 273229066U, 247886176U, 222646516U, 197509248U,
172473545U, 147538590U, 122703574U, 97967701U, 73330182U, 48790236U, 172473545U, 147538590U, 122703574U, 97967701U, 73330182U, 48790236U,
24347096U, 0U 24347096U, 0U
# endif
#if 0 #if 0
/* The following are the values for 16-bit tables - these work fine for the /* The following are the values for 16-bit tables - these work fine for the
* 8-bit conversions but produce very slightly larger errors in the 16-bit * 8-bit conversions but produce very slightly larger errors in the 16-bit
@ -2323,7 +2335,7 @@ png_log16bit(png_uint_32 x)
* integer bits (the top 4) simply determine a shift. * integer bits (the top 4) simply determine a shift.
* *
* The worst case is the 16-bit distinction between 65535 and 65534, this * The worst case is the 16-bit distinction between 65535 and 65534, this
* requires perhaps spurious accuracty in the decoding of the logarithm to * requires perhaps spurious accuracy in the decoding of the logarithm to
* distinguish log2(65535/65534.5) - 10^-5 or 17 bits. There is little chance * distinguish log2(65535/65534.5) - 10^-5 or 17 bits. There is little chance
* of getting this accuracy in practice. * of getting this accuracy in practice.
* *
@ -2334,17 +2346,18 @@ png_log16bit(png_uint_32 x)
static png_uint_32 static png_uint_32
png_32bit_exp[16] = png_32bit_exp[16] =
{ {
# if PNG_DO_BC # ifdef PNG_DO_BC
for (i=0;i<16;++i) { .5 + e(-i/16*l(2))*2^32; } for (i=0;i<16;++i) { .5 + e(-i/16*l(2))*2^32; }
# endif # else
/* NOTE: the first entry is deliberately set to the maximum 32-bit value. */ /* NOTE: the first entry is deliberately set to the maximum 32-bit value. */
4294967295U, 4112874773U, 3938502376U, 3771522796U, 3611622603U, 3458501653U, 4294967295U, 4112874773U, 3938502376U, 3771522796U, 3611622603U, 3458501653U,
3311872529U, 3171459999U, 3037000500U, 2908241642U, 2784941738U, 2666869345U, 3311872529U, 3171459999U, 3037000500U, 2908241642U, 2784941738U, 2666869345U,
2553802834U, 2445529972U, 2341847524U, 2242560872U 2553802834U, 2445529972U, 2341847524U, 2242560872U
# endif
}; };
/* Adjustment table; provided to explain the numbers in the code below. */ /* Adjustment table; provided to explain the numbers in the code below. */
#if PNG_DO_BC #ifdef PNG_DO_BC
for (i=11;i>=0;--i){ print i, " ", (1 - e(-(2^i)/65536*l(2))) * 2^(32-i), "\n"} for (i=11;i>=0;--i){ print i, " ", (1 - e(-(2^i)/65536*l(2))) * 2^(32-i), "\n"}
11 44937.64284865548751208448 11 44937.64284865548751208448
10 45180.98734845585101160448 10 45180.98734845585101160448
@ -2507,7 +2520,7 @@ png_gamma_significant(png_fixed_point gamma_val)
} }
/* Internal function to build a single 16-bit table - the table consists of /* Internal function to build a single 16-bit table - the table consists of
* 'num' 256 entry subtables, where 'num' is determined by 'shift' - the amount * 'num' 256-entry subtables, where 'num' is determined by 'shift' - the amount
* to shift the input values right (or 16-number_of_signifiant_bits). * to shift the input values right (or 16-number_of_signifiant_bits).
* *
* The caller is responsible for ensuring that the table gets cleaned up on * The caller is responsible for ensuring that the table gets cleaned up on
@ -2594,9 +2607,9 @@ png_build_16to8_table(png_structp png_ptr, png_uint_16pp *ptable,
png_uint_16pp table = *ptable = png_uint_16pp table = *ptable =
(png_uint_16pp)png_calloc(png_ptr, num * png_sizeof(png_uint_16p)); (png_uint_16pp)png_calloc(png_ptr, num * png_sizeof(png_uint_16p));
/* 'num' is the number of tables and also the number of low bits of low /* 'num' is the number of tables and also the number of low bits of the
* bits of the input 16-bit value used to select a table. Each table is * input 16-bit value used to select a table. Each table is itself indexed
* itself index by the high 8 bits of the value. * by the high 8 bits of the value.
*/ */
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
table[i] = (png_uint_16p)png_malloc(png_ptr, table[i] = (png_uint_16p)png_malloc(png_ptr,
@ -2647,7 +2660,7 @@ png_build_16to8_table(png_structp png_ptr, png_uint_16pp *ptable,
/* Build a single 8-bit table: same as the 16-bit case but much simpler (and /* Build a single 8-bit table: same as the 16-bit case but much simpler (and
* typically much faster). Note that libpng currently does no sBIT processing * typically much faster). Note that libpng currently does no sBIT processing
* (apparently contrary to the spec) so a 256 entry table is always generated. * (apparently contrary to the spec) so a 256-entry table is always generated.
*/ */
static void static void
png_build_8bit_table(png_structp png_ptr, png_bytepp ptable, png_build_8bit_table(png_structp png_ptr, png_bytepp ptable,
@ -2783,7 +2796,7 @@ png_build_gamma_table(png_structp png_ptr, int bit_depth)
* Where 'iv' is the input color value and 'ov' is the output value - * Where 'iv' is the input color value and 'ov' is the output value -
* pow(iv, gamma). * pow(iv, gamma).
* *
* Thus the gamma table consists of up to 256 256 entry tables. The table * Thus the gamma table consists of up to 256 256-entry tables. The table
* is selected by the (8-gamma_shift) most significant of the low 8 bits of * is selected by the (8-gamma_shift) most significant of the low 8 bits of
* the color value then indexed by the upper 8 bits: * the color value then indexed by the upper 8 bits:
* *

View file

@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library /* png.h - header file for PNG reference library
* *
* libpng version 1.5.6 - November 3, 2011 * libpng version 1.5.7 - December 15, 2011
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -11,7 +11,7 @@
* Authors and maintainers: * Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.5.6 - November 3, 2011: Glenn * libpng versions 0.97, January 1998, through 1.5.7 - December 15, 2011: Glenn
* See also "Contributing Authors", below. * See also "Contributing Authors", below.
* *
* Note about libpng version numbers: * Note about libpng version numbers:
@ -163,6 +163,9 @@
* 1.5.6beta01-07 15 10506 15.so.15.6[.0] * 1.5.6beta01-07 15 10506 15.so.15.6[.0]
* 1.5.6rc01-03 15 10506 15.so.15.6[.0] * 1.5.6rc01-03 15 10506 15.so.15.6[.0]
* 1.5.6 15 10506 15.so.15.6[.0] * 1.5.6 15 10506 15.so.15.6[.0]
* 1.5.7beta01-05 15 10507 15.so.15.7[.0]
* 1.5.7rc01-03 15 10507 15.so.15.7[.0]
* 1.5.7 15 10507 15.so.15.7[.0]
* *
* Henceforth the source version will match the shared-library major * Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be * and minor numbers; the shared-library major version number will be
@ -194,7 +197,7 @@
* *
* This code is released under the libpng license. * This code is released under the libpng license.
* *
* libpng versions 1.2.6, August 15, 2004, through 1.5.6, November 3, 2011, are * libpng versions 1.2.6, August 15, 2004, through 1.5.7, December 15, 2011, are
* Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are * Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are
* distributed according to the same disclaimer and license as libpng-1.2.5 * distributed according to the same disclaimer and license as libpng-1.2.5
* with the following individual added to the list of Contributing Authors: * with the following individual added to the list of Contributing Authors:
@ -306,13 +309,13 @@
* Y2K compliance in libpng: * Y2K compliance in libpng:
* ========================= * =========================
* *
* November 3, 2011 * December 15, 2011
* *
* Since the PNG Development group is an ad-hoc body, we can't make * Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration. * an official declaration.
* *
* This is your unofficial assurance that libpng from version 0.71 and * This is your unofficial assurance that libpng from version 0.71 and
* upward through 1.5.6 are Y2K compliant. It is my belief that * upward through 1.5.7 are Y2K compliant. It is my belief that
* earlier versions were also Y2K compliant. * earlier versions were also Y2K compliant.
* *
* Libpng only has two year fields. One is a 2-byte unsigned integer * Libpng only has two year fields. One is a 2-byte unsigned integer
@ -364,12 +367,15 @@
* describes how to use libpng, and the file example.c summarizes it * describes how to use libpng, and the file example.c summarizes it
* with some code on which to build. This file is useful for looking * with some code on which to build. This file is useful for looking
* at the actual function definitions and structure components. * at the actual function definitions and structure components.
*
* If you just need to read a PNG file and don't want to read the documentation
* skip to the end of this file and read the section entitled 'simplified API'.
*/ */
/* Version information for png.h - this should match the version in png.c */ /* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.5.6" #define PNG_LIBPNG_VER_STRING "1.5.7"
#define PNG_HEADER_VERSION_STRING \ #define PNG_HEADER_VERSION_STRING \
" libpng version 1.5.6 - November 3, 2011\n" " libpng version 1.5.7 - December 15, 2011\n"
#define PNG_LIBPNG_VER_SONUM 15 #define PNG_LIBPNG_VER_SONUM 15
#define PNG_LIBPNG_VER_DLLNUM 15 #define PNG_LIBPNG_VER_DLLNUM 15
@ -377,7 +383,8 @@
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1 #define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 5 #define PNG_LIBPNG_VER_MINOR 5
#define PNG_LIBPNG_VER_RELEASE 6 #define PNG_LIBPNG_VER_RELEASE 7
/* This should match the numeric part of the final component of /* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero: * PNG_LIBPNG_VER_STRING, omitting any leading zero:
*/ */
@ -407,7 +414,7 @@
* version 1.0.0 was mis-numbered 100 instead of 10000). From * version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release
*/ */
#define PNG_LIBPNG_VER 10506 /* 1.5.6 */ #define PNG_LIBPNG_VER 10507 /* 1.5.7 */
/* Library configuration: these options cannot be changed after /* Library configuration: these options cannot be changed after
* the library has been built. * the library has been built.
@ -529,7 +536,7 @@ extern "C" {
/* This triggers a compiler error in png.c, if png.c and png.h /* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number. * do not agree upon the version number.
*/ */
typedef char* png_libpng_version_1_5_6; typedef char* png_libpng_version_1_5_7;
/* Three color definitions. The order of the red, green, and blue, (and the /* Three color definitions. The order of the red, green, and blue, (and the
* exact size) is not important, although the size of the fields need to * exact size) is not important, although the size of the fields need to
@ -604,11 +611,20 @@ typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
#ifdef PNG_TEXT_SUPPORTED #ifdef PNG_TEXT_SUPPORTED
/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file, /* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file,
* and whether that contents is compressed or not. The "key" field * and whether that contents is compressed or not. The "key" field
* points to a regular zero-terminated C string. The "text", "lang", and * points to a regular zero-terminated C string. The "text" fields can be a
* "lang_key" fields can be regular C strings, empty strings, or NULL pointers. * regular C string, an empty string, or a NULL pointer.
* However, the structure returned by png_get_text() will always contain * However, the structure returned by png_get_text() will always contain
* regular zero-terminated C strings (possibly empty), never NULL pointers, * the "text" field as a regular zero-terminated C string (possibly
* so they can be safely used in printf() and other string-handling functions. * empty), never a NULL pointer, so it can be safely used in printf() and
* other string-handling functions. Note that the "itxt_length", "lang", and
* "lang_key" members of the structure only exist when the library is built
* with iTXt chunk support. Prior to libpng-1.4.0 the library was built by
* default without iTXt support. Also note that when iTXt *is* supported,
* the "lang" and "lang_key" fields contain NULL pointers when the
* "compression" field contains * PNG_TEXT_COMPRESSION_NONE or
* PNG_TEXT_COMPRESSION_zTXt. Note that the "compression value" is not the
* same as what appears in the PNG tEXt/zTXt/iTXt chunk's "compression flag"
* which is always 0 or 1, or its "compression method" which is always 0.
*/ */
typedef struct png_text_struct typedef struct png_text_struct
{ {
@ -1123,6 +1139,11 @@ PNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structp png_ptr));
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
/* Reduce RGB to grayscale. */ /* Reduce RGB to grayscale. */
#define PNG_ERROR_ACTION_NONE 1
#define PNG_ERROR_ACTION_WARN 2
#define PNG_ERROR_ACTION_ERROR 3
#define PNG_RGB_TO_GRAY_DEFAULT (-1)/*for red/green coefficients*/
PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structp png_ptr, PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structp png_ptr,
int error_action, double red, double green)); int error_action, double red, double green));
PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structp png_ptr, PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structp png_ptr,

View file

@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng /* pngconf.h - machine configurable file for libpng
* *
* libpng version 1.5.6 - November 3, 2011 * libpng version 1.5.7 - December 15, 2011
* *
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@ -369,7 +369,7 @@
# define PNG_NORETURN __declspec(noreturn) # define PNG_NORETURN __declspec(noreturn)
# endif # endif
# ifndef PNG_ALLOCATED # ifndef PNG_ALLOCATED
# if defined(_MSC_VER) && (_MSC_VER >= 1300) # if (_MSC_VER >= 1400)
# define PNG_ALLOCATED __declspec(restrict) # define PNG_ALLOCATED __declspec(restrict)
# endif # endif
# endif # endif

View file

@ -1,7 +1,7 @@
/* pngerror.c - stub functions for i/o and memory allocation /* pngerror.c - stub functions for i/o and memory allocation
* *
* Last changed in libpng 1.5.6 [November 3, 2011] * Last changed in libpng 1.5.7 [December 15, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)

View file

@ -1,7 +1,7 @@
/* pngget.c - retrieval of values from info struct /* pngget.c - retrieval of values from info struct
* *
* Last changed in libpng 1.5.6 [November 3, 2011] * Last changed in libpng 1.5.7 [December 15, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -682,15 +682,16 @@ png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr,
png_debug1(1, "in %s retrieval function", "iCCP"); png_debug1(1, "in %s retrieval function", "iCCP");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
&& name != NULL && profile != NULL && proflen != NULL) && name != NULL && compression_type != NULL && profile != NULL &&
proflen != NULL)
{ {
*name = info_ptr->iccp_name; *name = info_ptr->iccp_name;
*profile = info_ptr->iccp_profile; *profile = info_ptr->iccp_profile;
/* Compression_type is a dummy so the API won't have to change /* Compression_type is a dummy so the API won't have to change
* if we introduce multiple compression types later. * if we introduce multiple compression types later.
*/ */
*proflen = (int)info_ptr->iccp_proflen; *proflen = info_ptr->iccp_proflen;
*compression_type = (int)info_ptr->iccp_compression; *compression_type = info_ptr->iccp_compression;
return (PNG_INFO_iCCP); return (PNG_INFO_iCCP);
} }

View file

@ -1,7 +1,7 @@
/* pngmem.c - stub functions for memory allocation /* pngmem.c - stub functions for memory allocation
* *
* Last changed in libpng 1.5.4 [July 7, 2011] * Last changed in libpng 1.5.7 [December 15, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -56,9 +56,9 @@ png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr),
if (malloc_fn != NULL) if (malloc_fn != NULL)
{ {
png_struct dummy_struct; png_struct dummy_struct;
png_structp png_ptr = &dummy_struct; memset(&dummy_struct, 0, sizeof dummy_struct);
png_ptr->mem_ptr=mem_ptr; dummy_struct.mem_ptr=mem_ptr;
struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size); struct_ptr = (*(malloc_fn))(&dummy_struct, (png_alloc_size_t)size);
} }
else else
@ -90,9 +90,9 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
if (free_fn != NULL) if (free_fn != NULL)
{ {
png_struct dummy_struct; png_struct dummy_struct;
png_structp png_ptr = &dummy_struct; memset(&dummy_struct, 0, sizeof dummy_struct);
png_ptr->mem_ptr=mem_ptr; dummy_struct.mem_ptr=mem_ptr;
(*(free_fn))(png_ptr, struct_ptr); (*(free_fn))(&dummy_struct, struct_ptr);
return; return;
} }
@ -143,7 +143,7 @@ png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
# ifdef PNG_USER_MEM_SUPPORTED # ifdef PNG_USER_MEM_SUPPORTED
if (png_ptr->malloc_fn != NULL) if (png_ptr->malloc_fn != NULL)
ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size)); ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
else else
ret = (png_malloc_default(png_ptr, size)); ret = (png_malloc_default(png_ptr, size));

View file

@ -1,7 +1,7 @@
/* pngpread.c - read a png file in push mode /* pngpread.c - read a png file in push mode
* *
* Last changed in libpng 1.5.6 [November 3, 2011] * Last changed in libpng 1.5.7 [December 15, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -985,7 +985,7 @@ png_push_process_row(png_structp png_ptr)
if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE)
{ {
if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST)
png_read_filter_row(&row_info, png_ptr->row_buf + 1, png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1,
png_ptr->prev_row + 1, png_ptr->row_buf[0]); png_ptr->prev_row + 1, png_ptr->row_buf[0]);
else else
png_error(png_ptr, "bad adaptive filter value"); png_error(png_ptr, "bad adaptive filter value");

View file

@ -6,7 +6,7 @@
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
* Last changed in libpng 1.5.6 [November 3, 2011] * Last changed in libpng 1.5.7 [December 15, 2011]
* *
* This code is released under the libpng license. * This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer * For conditions of distribution and use, see the disclaimer
@ -196,6 +196,23 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
# define PNG_STATIC static # define PNG_STATIC static
#endif #endif
/* C99 restrict is used where possible, to do this 'restrict' is defined as
* empty if we can't be sure it is supported. configure builds have already
* done this work.
*/
#ifdef PNG_CONFIGURE_LIBPNG
# define PNG_RESTRICT restrict
#else
/* Modern compilers support restrict, but assume not for anything not
* recognized here:
*/
# if defined __GNUC__ || defined _MSC_VER || defined __WATCOMC__
# define PNG_RESTRICT restrict
# else
# define PNG_RESTRICT
# endif
#endif
/* If warnings or errors are turned off the code is disabled or redirected here. /* If warnings or errors are turned off the code is disabled or redirected here.
* From 1.5.4 functions have been added to allow very limited formatting of * From 1.5.4 functions have been added to allow very limited formatting of
* error and warning messages - this code will also be disabled here. * error and warning messages - this code will also be disabled here.
@ -217,15 +234,28 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
# define png_fixed_error(s1,s2) png_err(s1) # define png_fixed_error(s1,s2) png_err(s1)
#endif #endif
/* C allows up-casts from (void*) to any pointer and (const void*) to any
* pointer to a const object. C++ regards this as a type error and requires an
* explicit, static, cast and provides the static_cast<> rune to ensure that
* const is not cast away.
*/
#ifdef __cplusplus
# define png_voidcast(type, value) static_cast<type>(value)
#else
# define png_voidcast(type, value) (value)
#endif /* __cplusplus */
#ifndef PNG_EXTERN #ifndef PNG_EXTERN
/* The functions exported by PNG_EXTERN are internal functions, which /* The functions exported by PNG_EXTERN are internal functions, which
* aren't usually used outside the library (as far as I know), so it is * aren't usually used outside the library (as far as I know), so it is
* debatable if they should be exported at all. In the future, when it * debatable if they should be exported at all. In the future, when it
* is possible to have run-time registry of chunk-handling functions, * is possible to have run-time registry of chunk-handling functions,
* some of these might be made available again. * some of these might be made available again.
# define PNG_EXTERN extern *
* 1.5.7: turned the use of 'extern' back on, since it is localized to pngpriv.h
* it should be safe now (it is unclear why it was turned off.)
*/ */
# define PNG_EXTERN # define PNG_EXTERN extern
#endif #endif
/* Some fixed point APIs are still required even if not exported because /* Some fixed point APIs are still required even if not exported because
@ -922,9 +952,24 @@ PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
/* Unfilter a row: check the filter value before calling this, there is no point /* Unfilter a row: check the filter value before calling this, there is no point
* calling it for PNG_FILTER_VALUE_NONE. * calling it for PNG_FILTER_VALUE_NONE.
*/ */
PNG_EXTERN void png_read_filter_row PNGARG((png_row_infop row_info, PNG_EXTERN void png_read_filter_row PNGARG((png_structp pp, png_row_infop row_info,
png_bytep row, png_const_bytep prev_row, int filter)); png_bytep row, png_const_bytep prev_row, int filter));
PNG_EXTERN void png_read_filter_row_up_neon PNGARG((png_row_infop row_info,
png_bytep row, png_const_bytep prev_row));
PNG_EXTERN void png_read_filter_row_sub3_neon PNGARG((png_row_infop row_info,
png_bytep row, png_const_bytep prev_row));
PNG_EXTERN void png_read_filter_row_sub4_neon PNGARG((png_row_infop row_info,
png_bytep row, png_const_bytep prev_row));
PNG_EXTERN void png_read_filter_row_avg3_neon PNGARG((png_row_infop row_info,
png_bytep row, png_const_bytep prev_row));
PNG_EXTERN void png_read_filter_row_avg4_neon PNGARG((png_row_infop row_info,
png_bytep row, png_const_bytep prev_row));
PNG_EXTERN void png_read_filter_row_paeth3_neon PNGARG((png_row_infop row_info,
png_bytep row, png_const_bytep prev_row));
PNG_EXTERN void png_read_filter_row_paeth4_neon PNGARG((png_row_infop row_info,
png_bytep row, png_const_bytep prev_row));
/* Choose the best filter to use and filter the row data */ /* Choose the best filter to use and filter the row data */
PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr, PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
png_row_infop row_info)); png_row_infop row_info));
@ -1575,7 +1620,6 @@ PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr,
/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
#include "pngdebug.h" #include "pngdebug.h"
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -1,7 +1,7 @@
/* pngread.c - read a PNG file /* pngread.c - read a PNG file
* *
* Last changed in libpng 1.5.6 [November 3, 2011] * Last changed in libpng 1.5.7 [December 15, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -80,8 +80,9 @@ png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
/* Applications that neglect to set up their own setjmp() and then /* Applications that neglect to set up their own setjmp() and then
encounter a png_error() will longjmp here. Since the jmpbuf is * encounter a png_error() will longjmp here. Since the jmpbuf is
then meaningless we abort instead of returning. */ * then meaningless we abort instead of returning.
*/
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
if (setjmp(tmp_jmpbuf)) if (setjmp(tmp_jmpbuf))
#else #else
@ -578,7 +579,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE)
{ {
if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST)
png_read_filter_row(&row_info, png_ptr->row_buf + 1, png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1,
png_ptr->prev_row + 1, png_ptr->row_buf[0]); png_ptr->prev_row + 1, png_ptr->row_buf[0]);
else else
png_error(png_ptr, "bad adaptive filter value"); png_error(png_ptr, "bad adaptive filter value");

View file

@ -1,7 +1,7 @@
/* pngrtran.c - transforms the data in a row for PNG readers /* pngrtran.c - transforms the data in a row for PNG readers
* *
* Last changed in libpng 1.5.6 [November 3, 2011] * Last changed in libpng 1.5.7 [December 15, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -936,15 +936,15 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
switch(error_action) switch(error_action)
{ {
case 1: case PNG_ERROR_ACTION_NONE:
png_ptr->transformations |= PNG_RGB_TO_GRAY; png_ptr->transformations |= PNG_RGB_TO_GRAY;
break; break;
case 2: case PNG_ERROR_ACTION_WARN:
png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN; png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
break; break;
case 3: case PNG_ERROR_ACTION_ERROR:
png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR; png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
break; break;
@ -1465,6 +1465,28 @@ png_init_read_transformations(png_structp png_ptr)
} }
#endif /* PNG_READ_BACKGROUND_SUPPORTED && PNG_READ_EXPAND_16_SUPPORTED */ #endif /* PNG_READ_BACKGROUND_SUPPORTED && PNG_READ_EXPAND_16_SUPPORTED */
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
(defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \
defined(PNG_READ_STRIP_16_TO_8_SUPPORTED))
if ((png_ptr->transformations & (PNG_16_TO_8|PNG_SCALE_16_TO_8)) &&
(png_ptr->transformations & PNG_COMPOSE) &&
!(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
png_ptr->bit_depth == 16)
{
/* On the other hand, if a 16-bit file is to be reduced to 8-bits per
* component this will also happen after PNG_COMPOSE and so the background
* color must be pre-expanded here.
*
* TODO: fix this too.
*/
png_ptr->background.red = (png_uint_16)(png_ptr->background.red * 257);
png_ptr->background.green =
(png_uint_16)(png_ptr->background.green * 257);
png_ptr->background.blue = (png_uint_16)(png_ptr->background.blue * 257);
png_ptr->background.gray = (png_uint_16)(png_ptr->background.gray * 257);
}
#endif
/* NOTE: below 'PNG_READ_ALPHA_MODE_SUPPORTED' is presumed to also enable the /* NOTE: below 'PNG_READ_ALPHA_MODE_SUPPORTED' is presumed to also enable the
* background support (see the comments in scripts/pnglibconf.dfa), this * background support (see the comments in scripts/pnglibconf.dfa), this
* allows pre-multiplication of the alpha channel to be implemented as * allows pre-multiplication of the alpha channel to be implemented as
@ -1512,6 +1534,16 @@ png_init_read_transformations(png_structp png_ptr)
#ifdef PNG_READ_BACKGROUND_SUPPORTED #ifdef PNG_READ_BACKGROUND_SUPPORTED
if (png_ptr->transformations & PNG_COMPOSE) if (png_ptr->transformations & PNG_COMPOSE)
{ {
/* Issue a warning about this combination: because RGB_TO_GRAY is
* optimized to do the gamma transform if present yet do_background has
* to do the same thing if both options are set a
* double-gamma-correction happens. This is true in all versions of
* libpng to date.
*/
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
png_warning(png_ptr,
"libpng does not support gamma+background+rgb_to_gray");
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{ {
/* We don't get to here unless there is a tRNS chunk with non-opaque /* We don't get to here unless there is a tRNS chunk with non-opaque
@ -1726,7 +1758,13 @@ png_init_read_transformations(png_structp png_ptr)
else else
/* Transformation does not include PNG_BACKGROUND */ /* Transformation does not include PNG_BACKGROUND */
#endif /* PNG_READ_BACKGROUND_SUPPORTED */ #endif /* PNG_READ_BACKGROUND_SUPPORTED */
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
/* RGB_TO_GRAY needs to have non-gamma-corrected values! */
&& ((png_ptr->transformations & PNG_EXPAND) == 0 ||
(png_ptr->transformations & PNG_RGB_TO_GRAY) == 0)
#endif
)
{ {
png_colorp palette = png_ptr->palette; png_colorp palette = png_ptr->palette;
int num_palette = png_ptr->num_palette; int num_palette = png_ptr->num_palette;
@ -1918,7 +1956,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->bit_depth = 8; info_ptr->bit_depth = 8;
# else # else
# if PNG_READ_SCALE_16_TO_8_SUPPORTED # ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
png_ptr->transformations |= PNG_SCALE_16_TO_8; png_ptr->transformations |= PNG_SCALE_16_TO_8;
info_ptr->bit_depth = 8; info_ptr->bit_depth = 8;
# else # else
@ -2165,12 +2203,22 @@ png_do_read_transformations(png_structp png_ptr, png_row_infop row_info)
#ifdef PNG_READ_GAMMA_SUPPORTED #ifdef PNG_READ_GAMMA_SUPPORTED
if ((png_ptr->transformations & PNG_GAMMA) && if ((png_ptr->transformations & PNG_GAMMA) &&
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
/* Because RGB_TO_GRAY does the gamma transform. */
!(png_ptr->transformations & PNG_RGB_TO_GRAY) &&
#endif
#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\ #if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\
(defined PNG_READ_ALPHA_MODE_SUPPORTED) (defined PNG_READ_ALPHA_MODE_SUPPORTED)
/* Because PNG_COMPOSE does the gamma transform if there is something to
* do (if there is an alpha channel or transparency.)
*/
!((png_ptr->transformations & PNG_COMPOSE) && !((png_ptr->transformations & PNG_COMPOSE) &&
((png_ptr->num_trans != 0) || ((png_ptr->num_trans != 0) ||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) && (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
#endif #endif
/* Because png_init_read_transformations transforms the palette, unless
* RGB_TO_GRAY will do the transform.
*/
(png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)) (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr); png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr);
#endif #endif
@ -2562,7 +2610,7 @@ png_do_scale_16_to_8(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth == 16) if (row_info->bit_depth == 16)
{ {
png_bytep sp = row; /* source */ png_bytep sp = row; /* source */
png_bytep dp = row; /* destinaton */ png_bytep dp = row; /* destination */
png_bytep ep = sp + row_info->rowbytes; /* end+1 */ png_bytep ep = sp + row_info->rowbytes; /* end+1 */
while (sp < ep) while (sp < ep)
@ -2623,7 +2671,7 @@ png_do_chop(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth == 16) if (row_info->bit_depth == 16)
{ {
png_bytep sp = row; /* source */ png_bytep sp = row; /* source */
png_bytep dp = row; /* destinaton */ png_bytep dp = row; /* destination */
png_bytep ep = sp + row_info->rowbytes; /* end+1 */ png_bytep ep = sp + row_info->rowbytes; /* end+1 */
while (sp < ep) while (sp < ep)
@ -3331,7 +3379,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
if (red != green || red != blue) if (red != green || red != blue)
rgb_error |= 1; rgb_error |= 1;
/* From 1.5.5 in the 16 bit case do the accurate convertion even /* From 1.5.5 in the 16 bit case do the accurate conversion even
* in the 'fast' case - this is because this is where the code * in the 'fast' case - this is because this is where the code
* ends up when handling linear 16 bit data. * ends up when handling linear 16 bit data.
*/ */

View file

@ -1,7 +1,7 @@
/* pngrutil.c - utilities to read a PNG file /* pngrutil.c - utilities to read a PNG file
* *
* Last changed in libpng 1.5.6 [November 3, 2011] * Last changed in libpng 1.5.7 [December 15, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -490,7 +490,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
{ {
PNG_WARNING_PARAMETERS(p) PNG_WARNING_PARAMETERS(p)
png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, comp_type); png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, comp_type);
png_formatted_warning(png_ptr, p, "Unknown zTXt compression type @1"); png_formatted_warning(png_ptr, p, "Unknown compression type @1");
/* The recovery is to simply drop the data. */ /* The recovery is to simply drop the data. */
} }
@ -2540,6 +2540,14 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
comp_type = *lang++; comp_type = *lang++;
} }
if (comp_type || (comp_flag && comp_flag != PNG_TEXT_COMPRESSION_zTXt))
{
png_warning(png_ptr, "Unknown iTXt compression type or method");
png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return;
}
for (lang_key = lang; *lang_key; lang_key++) for (lang_key = lang; *lang_key; lang_key++)
/* Empty loop */ ; /* Empty loop */ ;
@ -2767,18 +2775,13 @@ png_check_chunk_name(png_structp png_ptr, png_uint_32 chunk_name)
} }
} }
/* Combines the row recently read in with the existing pixels in the /* Combines the row recently read in with the existing pixels in the row. This
* row. This routine takes care of alpha and transparency if requested. * routine takes care of alpha and transparency if requested. This routine also
* This routine also handles the two methods of progressive display * handles the two methods of progressive display of interlaced images,
* of interlaced images, depending on the mask value. * depending on the 'display' value; if 'display' is true then the whole row
* The mask value describes which pixels are to be combined with * (dp) is filled from the start by replicating the available pixels. If
* the row. The pattern always repeats every 8 pixels, so just 8 * 'display' is false only those pixels present in the pass are filled in.
* bits are needed. A one indicates the pixel is to be combined,
* a zero indicates the pixel is to be skipped. This is in addition
* to any alpha or transparency value associated with the pixel. If
* you want all pixels to be combined, pass 0xff (255) in mask.
*/ */
void /* PRIVATE */ void /* PRIVATE */
png_combine_row(png_structp png_ptr, png_bytep dp, int display) png_combine_row(png_structp png_ptr, png_bytep dp, int display)
{ {
@ -2850,7 +2853,7 @@ png_combine_row(png_structp png_ptr, png_bytep dp, int display)
if (pixel_depth < 8) if (pixel_depth < 8)
{ {
/* For pixel depths up to 4-bpp the 8-pixel mask can be expanded to fit /* For pixel depths up to 4 bpp the 8-pixel mask can be expanded to fit
* into 32 bits, then a single loop over the bytes using the four byte * into 32 bits, then a single loop over the bytes using the four byte
* values in the 32-bit mask can be used. For the 'display' option the * values in the 32-bit mask can be used. For the 'display' option the
* expanded mask may also not require any masking within a byte. To * expanded mask may also not require any masking within a byte. To
@ -2859,7 +2862,7 @@ png_combine_row(png_structp png_ptr, png_bytep dp, int display)
* *
* The 'regular' case requires a mask for each of the first 6 passes, * The 'regular' case requires a mask for each of the first 6 passes,
* the 'display' case does a copy for the even passes in the range * the 'display' case does a copy for the even passes in the range
* 0..6. This has already been handled in the tst above. * 0..6. This has already been handled in the test above.
* *
* The masks are arranged as four bytes with the first byte to use in * The masks are arranged as four bytes with the first byte to use in
* the lowest bits (little-endian) regardless of the order (PACKSWAP or * the lowest bits (little-endian) regardless of the order (PACKSWAP or
@ -2867,7 +2870,7 @@ png_combine_row(png_structp png_ptr, png_bytep dp, int display)
* *
* NOTE: the whole of this logic depends on the caller of this function * NOTE: the whole of this logic depends on the caller of this function
* only calling it on rows appropriate to the pass. This function only * only calling it on rows appropriate to the pass. This function only
* understands the 'x' logic, the 'y' logic is handled by the caller. * understands the 'x' logic; the 'y' logic is handled by the caller.
* *
* The following defines allow generation of compile time constant bit * The following defines allow generation of compile time constant bit
* masks for each pixel depth and each possibility of swapped or not * masks for each pixel depth and each possibility of swapped or not
@ -2885,7 +2888,7 @@ png_combine_row(png_structp png_ptr, png_bytep dp, int display)
* the compiler even though it isn't used. Microsoft Visual C (various * the compiler even though it isn't used. Microsoft Visual C (various
* versions) and the Intel C compiler are known to do this. To avoid * versions) and the Intel C compiler are known to do this. To avoid
* this the following macros are used in 1.5.6. This is a temporary * this the following macros are used in 1.5.6. This is a temporary
* solution to avoid destablizing the code during the release process. * solution to avoid destabilizing the code during the release process.
*/ */
# if PNG_USE_COMPILE_TIME_MASKS # if PNG_USE_COMPILE_TIME_MASKS
# define PNG_LSR(x,s) ((x)>>((s) & 0x1f)) # define PNG_LSR(x,s) ((x)>>((s) & 0x1f))
@ -2930,7 +2933,7 @@ png_combine_row(png_structp png_ptr, png_bytep dp, int display)
#if PNG_USE_COMPILE_TIME_MASKS #if PNG_USE_COMPILE_TIME_MASKS
/* Utility macros to construct all the masks for a depth/swap /* Utility macros to construct all the masks for a depth/swap
* combination. The 's' parameter says whether the format is PNG * combination. The 's' parameter says whether the format is PNG
* (big endian bytes) or not. Only the three odd numbered passes are * (big endian bytes) or not. Only the three odd-numbered passes are
* required for the display/block algorithm. * required for the display/block algorithm.
*/ */
# define S_MASKS(d,s) { S_MASK(0,d,s), S_MASK(1,d,s), S_MASK(2,d,s),\ # define S_MASKS(d,s) { S_MASK(0,d,s), S_MASK(1,d,s), S_MASK(2,d,s),\
@ -2943,7 +2946,8 @@ png_combine_row(png_structp png_ptr, png_bytep dp, int display)
/* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and /* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and
* then pass: * then pass:
*/ */
static PNG_CONST png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] = { static PNG_CONST png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =
{
/* Little-endian byte masks for PACKSWAP */ /* Little-endian byte masks for PACKSWAP */
{ S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) }, { S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) },
/* Normal (big-endian byte) masks - PNG format */ /* Normal (big-endian byte) masks - PNG format */
@ -2953,7 +2957,8 @@ png_combine_row(png_structp png_ptr, png_bytep dp, int display)
/* display_mask has only three entries for the odd passes, so index by /* display_mask has only three entries for the odd passes, so index by
* pass>>1. * pass>>1.
*/ */
static PNG_CONST png_uint_32 display_mask[2][3][3] = { static PNG_CONST png_uint_32 display_mask[2][3][3] =
{
/* Little-endian byte masks for PACKSWAP */ /* Little-endian byte masks for PACKSWAP */
{ B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) }, { B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) },
/* Normal (big-endian byte) masks - PNG format */ /* Normal (big-endian byte) masks - PNG format */
@ -3129,7 +3134,7 @@ png_combine_row(png_structp png_ptr, png_bytep dp, int display)
/* Check for double byte alignment and, if possible, use a /* Check for double byte alignment and, if possible, use a
* 16-bit copy. Don't attempt this for narrow images - ones that * 16-bit copy. Don't attempt this for narrow images - ones that
* are less than an interlace panel wide. Don't attempt it for * are less than an interlace panel wide. Don't attempt it for
* wide bytes-to-copy either - use the png_memcpy there. * wide bytes_to_copy either - use the png_memcpy there.
*/ */
if (bytes_to_copy < 16 /*else use png_memcpy*/ && if (bytes_to_copy < 16 /*else use png_memcpy*/ &&
png_isaligned(dp, png_uint_16) && png_isaligned(dp, png_uint_16) &&
@ -3498,34 +3503,27 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
} }
#endif /* PNG_READ_INTERLACING_SUPPORTED */ #endif /* PNG_READ_INTERLACING_SUPPORTED */
/* 1.5.6: Changed to just take a png_row_info (not png_ptr) and to ignore bad static void
* adaptive filter bytes. png_read_filter_row_sub(png_row_infop row_info, png_bytep row,
*/ png_const_bytep prev_row)
void /* PRIVATE */
png_read_filter_row(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row, int filter)
{
switch (filter)
{
case PNG_FILTER_VALUE_NONE:
break;
case PNG_FILTER_VALUE_SUB:
{ {
png_size_t i; png_size_t i;
png_size_t istop = row_info->rowbytes; png_size_t istop = row_info->rowbytes;
unsigned int bpp = (row_info->pixel_depth + 7) >> 3; unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
png_bytep rp = row + bpp; png_bytep rp = row + bpp;
png_bytep lp = row;
PNG_UNUSED(prev_row)
for (i = bpp; i < istop; i++) for (i = bpp; i < istop; i++)
{ {
*rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff); *rp = (png_byte)(((int)(*rp) + (int)(*(rp-bpp))) & 0xff);
rp++; rp++;
} }
break;
} }
case PNG_FILTER_VALUE_UP:
static void
png_read_filter_row_up(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row)
{ {
png_size_t i; png_size_t i;
png_size_t istop = row_info->rowbytes; png_size_t istop = row_info->rowbytes;
@ -3537,14 +3535,15 @@ png_read_filter_row(png_row_infop row_info, png_bytep row,
*rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
rp++; rp++;
} }
break;
} }
case PNG_FILTER_VALUE_AVG:
static void
png_read_filter_row_avg(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row)
{ {
png_size_t i; png_size_t i;
png_bytep rp = row; png_bytep rp = row;
png_const_bytep pp = prev_row; png_const_bytep pp = prev_row;
png_bytep lp = row;
unsigned int bpp = (row_info->pixel_depth + 7) >> 3; unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
png_size_t istop = row_info->rowbytes - bpp; png_size_t istop = row_info->rowbytes - bpp;
@ -3559,35 +3558,31 @@ png_read_filter_row(png_row_infop row_info, png_bytep row,
for (i = 0; i < istop; i++) for (i = 0; i < istop; i++)
{ {
*rp = (png_byte)(((int)(*rp) + *rp = (png_byte)(((int)(*rp) +
(int)(*pp++ + *lp++) / 2 ) & 0xff); (int)(*pp++ + *(rp-bpp)) / 2 ) & 0xff);
rp++; rp++;
} }
break;
}
case PNG_FILTER_VALUE_PAETH:
{
png_size_t i;
png_bytep rp = row;
png_const_bytep pp = prev_row;
png_bytep lp = row;
png_const_bytep cp = prev_row;
unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
png_size_t istop=row_info->rowbytes - bpp;
for (i = 0; i < bpp; i++)
{
*rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
rp++;
} }
for (i = 0; i < istop; i++) /* Use leftover rp,pp */ static void
png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row)
{ {
int a, b, c, pa, pb, pc, p; png_bytep rp_end = row + row_info->rowbytes;
int a, c;
a = *lp++; /* First pixel/byte */
b = *pp++; c = *prev_row++;
c = *cp++; a = *row + c;
*row++ = (png_byte)a;
/* Remainder */
while (row < rp_end)
{
int b, pa, pb, pc, p;
a &= 0xff; /* From previous iteration or start */
b = *prev_row++;
p = b - c; p = b - c;
pc = a - c; pc = a - c;
@ -3602,28 +3597,158 @@ png_read_filter_row(png_row_infop row_info, png_bytep row,
pc = (p + pc) < 0 ? -(p + pc) : p + pc; pc = (p + pc) < 0 ? -(p + pc) : p + pc;
# endif # endif
/* /* Find the best predictor, the least of pa, pb, pc favoring the earlier
if (pa <= pb && pa <= pc) * ones in the case of a tie.
p = a;
else if (pb <= pc)
p = b;
else
p = c;
*/ */
if (pb < pa) pa = pb, a = b;
if (pc < pa) a = c;
p = (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c; /* Calculate the current pixel in a, and move the previous row pixel to c
* for the next time round the loop
*rp = (png_byte)(((int)(*rp) + p) & 0xff); */
rp++; c = b;
a += *row;
*row++ = (png_byte)a;
} }
}
static void
png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row)
{
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'
* because there is only one candidate predictor for the first row).
*/
while (row < rp_end)
{
int a = *row + *prev_row++;
*row++ = (png_byte)a;
}
/* Remainder */
rp_end += row_info->rowbytes - bpp;
while (row < rp_end)
{
int a, b, c, pa, pb, pc, p;
c = *(prev_row - bpp);
a = *(row - bpp);
b = *prev_row++;
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
if (pb < pa) pa = pb, a = b;
if (pc < pa) a = c;
c = b;
a += *row;
*row++ = (png_byte)a;
}
}
#ifdef PNG_ARM_NEON
#ifdef __linux__
#include <stdio.h>
#include <elf.h>
#include <asm/hwcap.h>
static int png_have_hwcap(unsigned cap)
{
FILE *f = fopen("/proc/self/auxv", "r");
Elf32_auxv_t aux;
int have_cap = 0;
if (!f)
return 0;
while (fread(&aux, sizeof(aux), 1, f) > 0)
{
if (aux.a_type == AT_HWCAP &&
aux.a_un.a_val & cap)
{
have_cap = 1;
break; break;
} }
default:
/* NOT REACHED */
break;
} }
fclose(f);
return have_cap;
}
#endif /* __linux__ */
static void
png_init_filter_functions_neon(png_structp pp, unsigned int bpp)
{
#ifdef __linux__
if (!png_have_hwcap(HWCAP_NEON))
return;
#endif
pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon;
if (bpp == 3)
{
pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon;
pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon;
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
png_read_filter_row_paeth3_neon;
}
else if (bpp == 4)
{
pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon;
pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon;
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
png_read_filter_row_paeth4_neon;
}
}
#endif /* PNG_ARM_NEON */
static void
png_init_filter_functions(png_structp pp)
{
unsigned int bpp = (pp->pixel_depth + 7) >> 3;
pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub;
pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up;
pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg;
if (bpp == 1)
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
png_read_filter_row_paeth_1byte_pixel;
else
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
png_read_filter_row_paeth_multibyte_pixel;
#ifdef PNG_ARM_NEON
png_init_filter_functions_neon(pp, bpp);
#endif
}
void /* PRIVATE */
png_read_filter_row(png_structp pp, png_row_infop row_info, png_bytep row,
png_const_bytep prev_row, int filter)
{
if (pp->read_filter[0] == NULL)
png_init_filter_functions(pp);
if (filter > PNG_FILTER_VALUE_NONE && filter < PNG_FILTER_VALUE_LAST)
pp->read_filter[filter-1](row_info, row, prev_row);
} }
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
@ -3811,6 +3936,16 @@ png_read_start_row(png_structp png_ptr)
max_pixel_depth = png_ptr->pixel_depth; max_pixel_depth = png_ptr->pixel_depth;
/* WARNING: * png_read_transform_info (pngrtran.c) performs a simpliar set of
* calculations to calculate the final pixel depth, then
* png_do_read_transforms actually does the transforms. This means that the
* code which effectively calculates this value is actually repeated in three
* separate places. They must all match. Innocent changes to the order of
* transformations can and will break libpng in a way that causes memory
* overwrites.
*
* TODO: fix this.
*/
#ifdef PNG_READ_PACK_SUPPORTED #ifdef PNG_READ_PACK_SUPPORTED
if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8) if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
max_pixel_depth = 8; max_pixel_depth = 8;
@ -3869,10 +4004,7 @@ png_read_start_row(png_structp png_ptr)
#ifdef PNG_READ_FILLER_SUPPORTED #ifdef PNG_READ_FILLER_SUPPORTED
if (png_ptr->transformations & (PNG_FILLER)) if (png_ptr->transformations & (PNG_FILLER))
{ {
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
max_pixel_depth = 32;
else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
{ {
if (max_pixel_depth <= 8) if (max_pixel_depth <= 8)
max_pixel_depth = 16; max_pixel_depth = 16;
@ -3881,7 +4013,8 @@ png_read_start_row(png_structp png_ptr)
max_pixel_depth = 32; max_pixel_depth = 32;
} }
else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB ||
png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{ {
if (max_pixel_depth <= 32) if (max_pixel_depth <= 32)
max_pixel_depth = 32; max_pixel_depth = 32;

View file

@ -1,7 +1,7 @@
/* pngset.c - storage of image information into info struct /* pngset.c - storage of image information into info struct
* *
* Last changed in libpng 1.5.6 [November 3, 2011] * Last changed in libpng 1.5.7 [December 15, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -864,6 +864,15 @@ png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time)
(png_ptr->mode & PNG_WROTE_tIME)) (png_ptr->mode & PNG_WROTE_tIME))
return; return;
if (mod_time->month == 0 || mod_time->month > 12 ||
mod_time->day == 0 || mod_time->day > 31 ||
mod_time->hour > 23 || mod_time->minute > 59 ||
mod_time->second > 60)
{
png_warning(png_ptr, "Ignoring invalid time value");
return;
}
png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time)); png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
info_ptr->valid |= PNG_INFO_tIME; info_ptr->valid |= PNG_INFO_tIME;
} }

View file

@ -353,5 +353,8 @@ struct png_struct_def
/* New member added in libpng-1.5.6 */ /* New member added in libpng-1.5.6 */
png_bytep big_prev_row; png_bytep big_prev_row;
void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info,
png_bytep row, png_const_bytep prev_row);
}; };
#endif /* PNGSTRUCT_H */ #endif /* PNGSTRUCT_H */

View file

@ -1,7 +1,7 @@
/* pngwrite.c - general routines to write a PNG file /* pngwrite.c - general routines to write a PNG file
* *
* Last changed in libpng 1.5.6 [November 3, 2011] * Last changed in libpng 1.5.7 [December 15, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -490,8 +490,9 @@ png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
/* Applications that neglect to set up their own setjmp() and then /* Applications that neglect to set up their own setjmp() and then
encounter a png_error() will longjmp here. Since the jmpbuf is * encounter a png_error() will longjmp here. Since the jmpbuf is
then meaningless we abort instead of returning. */ * then meaningless we abort instead of returning.
*/
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
if (setjmp(tmp_jmpbuf)) if (setjmp(tmp_jmpbuf))
#else #else