[libpng16] Fixed some indentation to comply with our coding style.

This commit is contained in:
Glenn Randers-Pehrson 2016-07-13 14:43:42 -05:00
parent 1b9f4817c8
commit 192e92d681
12 changed files with 407 additions and 400 deletions

View File

@ -1,4 +1,4 @@
Libpng 1.6.24beta05 - July 8, 2016 Libpng 1.6.24beta05 - July 13, 2016
This is not intended to be a public release. It will be replaced This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version. within a few weeks by a public version or by another test version.
@ -82,7 +82,8 @@ Version 1.6.24beta04 [July 8, 2016]
filter is a candidate for selection. This trades off code size (added filter is a candidate for selection. This trades off code size (added
private png_setup_*_row_only() functions) for speed. private png_setup_*_row_only() functions) for speed.
Version 1.6.24beta05 [July 8, 2016] Version 1.6.24beta05 [July 13, 2016]
Fixed some indentation to comply with our coding style.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit

View File

@ -5653,7 +5653,8 @@ Version 1.6.24beta04 [July 8, 2016]
filter is a candidate for selection. This trades off code size (added filter is a candidate for selection. This trades off code size (added
private png_setup_*_row_only() functions) for speed. private png_setup_*_row_only() functions) for speed.
Version 1.6.24beta05 [July 8, 2016] Version 1.6.24beta05 [July 13, 2016]
Fixed some indentation to comply with our coding style.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit

View File

@ -375,7 +375,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
* low byte. * low byte.
*/ */
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
png_set_scale_16(png_ptr); png_set_scale_16(png_ptr);
#else #else
png_set_strip_16(png_ptr); png_set_strip_16(png_ptr);
#endif #endif
@ -383,12 +383,12 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
/* Strip alpha bytes from the input data without combining with the /* Strip alpha bytes from the input data without combining with the
* background (not recommended). * background (not recommended).
*/ */
png_set_strip_alpha(png_ptr); png_set_strip_alpha(png_ptr);
/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
* byte into separate bytes (useful for paletted and grayscale images). * byte into separate bytes (useful for paletted and grayscale images).
*/ */
png_set_packing(png_ptr); png_set_packing(png_ptr);
/* Change the order of packed pixels to least significant bit first /* Change the order of packed pixels to least significant bit first
* (not useful if you are using png_set_packing). */ * (not useful if you are using png_set_packing). */
@ -988,11 +988,11 @@ void write_png(char *file_name /* , ... other image information ... */)
png_bytep row_pointers[height]; png_bytep row_pointers[height];
if (height > PNG_UINT_32_MAX/(sizeof (png_bytep))) if (height > PNG_UINT_32_MAX/(sizeof (png_bytep)))
png_error (png_ptr, "Image is too tall to process in memory"); png_error (png_ptr, "Image is too tall to process in memory");
/* Set up pointers into your "image" byte array */ /* Set up pointers into your "image" byte array */
for (k = 0; k < height; k++) for (k = 0; k < height; k++)
row_pointers[k] = image + k*width*bytes_per_pixel; row_pointers[k] = image + k*width*bytes_per_pixel;
/* One of the following output methods is REQUIRED */ /* One of the following output methods is REQUIRED */

216
png.c
View File

@ -172,10 +172,10 @@ png_calculate_crc(png_structrp png_ptr, png_const_bytep ptr, png_size_t length)
int int
png_user_version_check(png_structrp png_ptr, png_const_charp user_png_ver) png_user_version_check(png_structrp png_ptr, png_const_charp user_png_ver)
{ {
/* Libpng versions 1.0.0 and later are binary compatible if the version /* Libpng versions 1.0.0 and later are binary compatible if the version
* string matches through the second '.'; we must recompile any * string matches through the second '.'; we must recompile any
* applications that use any older library version. * applications that use any older library version.
*/ */
if (user_png_ver != NULL) if (user_png_ver != NULL)
{ {
@ -775,14 +775,14 @@ png_get_copyright(png_const_structrp png_ptr)
#else #else
# ifdef __STDC__ # ifdef __STDC__
return PNG_STRING_NEWLINE \ return PNG_STRING_NEWLINE \
"libpng version 1.6.24beta05 - July 8, 2016" PNG_STRING_NEWLINE \ "libpng version 1.6.24beta05 - July 13, 2016" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson" \ "Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson" \
PNG_STRING_NEWLINE \ 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.6.24beta05 - July 8, 2016\ return "libpng version 1.6.24beta05 - July 13, 2016\
Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\ Copyright (c) 1998-2002,2004,2006-2016 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.";
@ -2468,7 +2468,7 @@ png_colorspace_set_rgb_coefficients(png_structrp png_ptr)
static int /* PRIVATE */ static int /* PRIVATE */
png_gt(size_t a, size_t b) png_gt(size_t a, size_t b)
{ {
return a > b; return a > b;
} }
#else #else
# define png_gt(a,b) ((a) > (b)) # define png_gt(a,b) ((a) > (b))
@ -4086,131 +4086,133 @@ png_destroy_gamma_table(png_structrp png_ptr)
void /* PRIVATE */ void /* PRIVATE */
png_build_gamma_table(png_structrp png_ptr, int bit_depth) png_build_gamma_table(png_structrp png_ptr, int bit_depth)
{ {
png_debug(1, "in png_build_gamma_table"); png_debug(1, "in png_build_gamma_table");
/* Remove any existing table; this copes with multiple calls to /* Remove any existing table; this copes with multiple calls to
* png_read_update_info. The warning is because building the gamma tables * png_read_update_info. The warning is because building the gamma tables
* multiple times is a performance hit - it's harmless but the ability to call * multiple times is a performance hit - it's harmless but the ability to
* png_read_update_info() multiple times is new in 1.5.6 so it seems sensible * call png_read_update_info() multiple times is new in 1.5.6 so it seems
* to warn if the app introduces such a hit. * sensible to warn if the app introduces such a hit.
*/ */
if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL) if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL)
{ {
png_warning(png_ptr, "gamma table being rebuilt"); png_warning(png_ptr, "gamma table being rebuilt");
png_destroy_gamma_table(png_ptr); png_destroy_gamma_table(png_ptr);
} }
if (bit_depth <= 8) if (bit_depth <= 8)
{ {
png_build_8bit_table(png_ptr, &png_ptr->gamma_table, png_build_8bit_table(png_ptr, &png_ptr->gamma_table,
png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma, png_ptr->screen_gamma > 0 ?
png_ptr->screen_gamma) : PNG_FP_1); png_reciprocal2(png_ptr->colorspace.gamma,
png_ptr->screen_gamma) : PNG_FP_1);
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0) if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0)
{ {
png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1, png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1,
png_reciprocal(png_ptr->colorspace.gamma)); png_reciprocal(png_ptr->colorspace.gamma));
png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1, png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1,
png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) : png_ptr->screen_gamma > 0 ?
png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */); png_reciprocal(png_ptr->screen_gamma) :
} png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */);
}
#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
} }
#ifdef PNG_16BIT_SUPPORTED #ifdef PNG_16BIT_SUPPORTED
else else
{ {
png_byte shift, sig_bit; png_byte shift, sig_bit;
if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
{ {
sig_bit = png_ptr->sig_bit.red; sig_bit = png_ptr->sig_bit.red;
if (png_ptr->sig_bit.green > sig_bit) if (png_ptr->sig_bit.green > sig_bit)
sig_bit = png_ptr->sig_bit.green; sig_bit = png_ptr->sig_bit.green;
if (png_ptr->sig_bit.blue > sig_bit) if (png_ptr->sig_bit.blue > sig_bit)
sig_bit = png_ptr->sig_bit.blue; sig_bit = png_ptr->sig_bit.blue;
} }
else else
sig_bit = png_ptr->sig_bit.gray; sig_bit = png_ptr->sig_bit.gray;
/* 16-bit gamma code uses this equation: /* 16-bit gamma code uses this equation:
* *
* ov = table[(iv & 0xff) >> gamma_shift][iv >> 8] * ov = table[(iv & 0xff) >> gamma_shift][iv >> 8]
* *
* 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
* the color value then indexed by the upper 8 bits: * of the color value then indexed by the upper 8 bits:
* *
* table[low bits][high 8 bits] * table[low bits][high 8 bits]
* *
* So the table 'n' corresponds to all those 'iv' of: * So the table 'n' corresponds to all those 'iv' of:
* *
* <all high 8-bit values><n << gamma_shift>..<(n+1 << gamma_shift)-1> * <all high 8-bit values><n << gamma_shift>..<(n+1 << gamma_shift)-1>
* *
*/ */
if (sig_bit > 0 && sig_bit < 16U) if (sig_bit > 0 && sig_bit < 16U)
/* shift == insignificant bits */ /* shift == insignificant bits */
shift = (png_byte)((16U - sig_bit) & 0xff); shift = (png_byte)((16U - sig_bit) & 0xff);
else else
shift = 0; /* keep all 16 bits */ shift = 0; /* keep all 16 bits */
if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0) if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0)
{ {
/* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively /* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively
* the significant bits in the *input* when the output will * the significant bits in the *input* when the output will
* eventually be 8 bits. By default it is 11. * eventually be 8 bits. By default it is 11.
*/ */
if (shift < (16U - PNG_MAX_GAMMA_8)) if (shift < (16U - PNG_MAX_GAMMA_8))
shift = (16U - PNG_MAX_GAMMA_8); shift = (16U - PNG_MAX_GAMMA_8);
} }
if (shift > 8U) if (shift > 8U)
shift = 8U; /* Guarantees at least one table! */ shift = 8U; /* Guarantees at least one table! */
png_ptr->gamma_shift = shift; png_ptr->gamma_shift = shift;
/* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now
* PNG_COMPOSE). This effectively smashed the background calculation for * PNG_COMPOSE). This effectively smashed the background calculation for
* 16-bit output because the 8-bit table assumes the result will be reduced * 16-bit output because the 8-bit table assumes the result will be
* to 8 bits. * reduced to 8 bits.
*/ */
if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0) if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0)
png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift, png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift,
png_ptr->screen_gamma > 0 ? png_product2(png_ptr->colorspace.gamma, png_ptr->screen_gamma > 0 ? png_product2(png_ptr->colorspace.gamma,
png_ptr->screen_gamma) : PNG_FP_1); png_ptr->screen_gamma) : PNG_FP_1);
else else
png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift, png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift,
png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma, png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma,
png_ptr->screen_gamma) : PNG_FP_1); png_ptr->screen_gamma) : PNG_FP_1);
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0) if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0)
{ {
png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift, png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift,
png_reciprocal(png_ptr->colorspace.gamma)); png_reciprocal(png_ptr->colorspace.gamma));
/* Notice that the '16 from 1' table should be full precision, however /* Notice that the '16 from 1' table should be full precision, however
* the lookup on this table still uses gamma_shift, so it can't be. * the lookup on this table still uses gamma_shift, so it can't be.
* TODO: fix this. * TODO: fix this.
*/ */
png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift, png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift,
png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) : png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) :
png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */); png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */);
} }
#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
} }
#endif /* 16BIT */ #endif /* 16BIT */
} }
#endif /* READ_GAMMA */ #endif /* READ_GAMMA */

133
png.h
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.6.24beta05, July 8, 2016 * libpng version 1.6.24beta05, July 13, 2016
* *
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@ -12,7 +12,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.89, June 1996, through 0.96, May 1997: Andreas Dilger * libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.6.24beta05, July 8, 2016: * libpng versions 0.97, January 1998, through 1.6.24beta05, July 13, 2016:
* Glenn Randers-Pehrson. * Glenn Randers-Pehrson.
* See also "Contributing Authors", below. * See also "Contributing Authors", below.
*/ */
@ -29,7 +29,7 @@
* files that are distributed with libpng have other copyright owners and * files that are distributed with libpng have other copyright owners and
* are released under other open source licenses. * are released under other open source licenses.
* *
* libpng versions 1.0.7, July 1, 2000 through 1.6.24beta05, July 8, 2016 are * libpng versions 1.0.7, July 1, 2000 through 1.6.24beta05, July 13, 2016 are
* Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are * Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are
* derived from libpng-1.0.6, and are distributed according to the same * derived from libpng-1.0.6, and are distributed according to the same
* disclaimer and license as libpng-1.0.6 with the following individuals * disclaimer and license as libpng-1.0.6 with the following individuals
@ -245,7 +245,7 @@
* Y2K compliance in libpng: * Y2K compliance in libpng:
* ========================= * =========================
* *
* July 8, 2016 * July 13, 2016
* *
* 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.
@ -314,8 +314,7 @@
/* 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.6.24beta05" #define PNG_LIBPNG_VER_STRING "1.6.24beta05"
#define PNG_HEADER_VERSION_STRING \ #define PNG_HEADER_VERSION_STRING " libpng version 1.6.24beta05 - July 13, 2016\n"
" libpng version 1.6.24beta05 - July 8, 2016\n"
#define PNG_LIBPNG_VER_SONUM 16 #define PNG_LIBPNG_VER_SONUM 16
#define PNG_LIBPNG_VER_DLLNUM 16 #define PNG_LIBPNG_VER_DLLNUM 16
@ -360,14 +359,14 @@
* the library has been built. * the library has been built.
*/ */
#ifndef PNGLCONF_H #ifndef PNGLCONF_H
/* If pnglibconf.h is missing, you can /* If pnglibconf.h is missing, you can
* copy scripts/pnglibconf.h.prebuilt to pnglibconf.h * copy scripts/pnglibconf.h.prebuilt to pnglibconf.h
*/ */
# include "pnglibconf.h" # include "pnglibconf.h"
#endif #endif
#ifndef PNG_VERSION_INFO_ONLY #ifndef PNG_VERSION_INFO_ONLY
/* Machine specific configuration. */ /* Machine specific configuration. */
# include "pngconf.h" # include "pngconf.h"
#endif #endif
@ -657,17 +656,17 @@ typedef png_time * * png_timepp;
*/ */
typedef struct png_unknown_chunk_t typedef struct png_unknown_chunk_t
{ {
png_byte name[5]; /* Textual chunk name with '\0' terminator */ png_byte name[5]; /* Textual chunk name with '\0' terminator */
png_byte *data; /* Data, should not be modified on read! */ png_byte *data; /* Data, should not be modified on read! */
png_size_t size; png_size_t size;
/* On write 'location' must be set using the flag values listed below. /* On write 'location' must be set using the flag values listed below.
* Notice that on read it is set by libpng however the values stored have * Notice that on read it is set by libpng however the values stored have
* more bits set than are listed below. Always treat the value as a * more bits set than are listed below. Always treat the value as a
* bitmask. On write set only one bit - setting multiple bits may cause the * bitmask. On write set only one bit - setting multiple bits may cause the
* chunk to be written in multiple places. * chunk to be written in multiple places.
*/ */
png_byte location; /* mode of operation at read time */ png_byte location; /* mode of operation at read time */
} }
png_unknown_chunk; png_unknown_chunk;
@ -2532,33 +2531,37 @@ PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type,
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */ /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
# define png_composite(composite, fg, alpha, bg) \ # define png_composite(composite, fg, alpha, bg) \
{ png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \ { \
* (png_uint_16)(alpha) \ png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \
+ (png_uint_16)(bg)*(png_uint_16)(255 \ * (png_uint_16)(alpha) \
- (png_uint_16)(alpha)) + 128); \ + (png_uint_16)(bg)*(png_uint_16)(255 \
(composite) = (png_byte)(((temp + (temp >> 8)) >> 8) & 0xff); } - (png_uint_16)(alpha)) + 128); \
(composite) = (png_byte)(((temp + (temp >> 8)) >> 8) & 0xff); \
}
# define png_composite_16(composite, fg, alpha, bg) \ # define png_composite_16(composite, fg, alpha, bg) \
{ png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \ { \
* (png_uint_32)(alpha) \ png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \
+ (png_uint_32)(bg)*(65535 \ * (png_uint_32)(alpha) \
- (png_uint_32)(alpha)) + 32768); \ + (png_uint_32)(bg)*(65535 \
(composite) = (png_uint_16)(0xffff & ((temp + (temp >> 16)) >> 16)); } - (png_uint_32)(alpha)) + 32768); \
(composite) = (png_uint_16)(0xffff & ((temp + (temp >> 16)) >> 16)); \
}
#else /* Standard method using integer division */ #else /* Standard method using integer division */
# define png_composite(composite, fg, alpha, bg) \ # define png_composite(composite, fg, alpha, bg) \
(composite) = \ (composite) = \
(png_byte)(0xff & (((png_uint_16)(fg) * (png_uint_16)(alpha) + \ (png_byte)(0xff & (((png_uint_16)(fg) * (png_uint_16)(alpha) + \
(png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \ (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
127) / 255)) 127) / 255))
# define png_composite_16(composite, fg, alpha, bg) \ # define png_composite_16(composite, fg, alpha, bg) \
(composite) = \ (composite) = \
(png_uint_16)(0xffff & (((png_uint_32)(fg) * (png_uint_32)(alpha) + \ (png_uint_16)(0xffff & (((png_uint_32)(fg) * (png_uint_32)(alpha) + \
(png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) + \ (png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) + \
32767) / 65535)) 32767) / 65535))
#endif /* READ_COMPOSITE_NODIV */ #endif /* READ_COMPOSITE_NODIV */
#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED #ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
@ -2594,38 +2597,38 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i));
* format for negative values, which is almost certainly true. * format for negative values, which is almost certainly true.
*/ */
# define PNG_get_uint_32(buf) \ # define PNG_get_uint_32(buf) \
(((png_uint_32)(*(buf)) << 24) + \ (((png_uint_32)(*(buf)) << 24) + \
((png_uint_32)(*((buf) + 1)) << 16) + \ ((png_uint_32)(*((buf) + 1)) << 16) + \
((png_uint_32)(*((buf) + 2)) << 8) + \ ((png_uint_32)(*((buf) + 2)) << 8) + \
((png_uint_32)(*((buf) + 3)))) ((png_uint_32)(*((buf) + 3))))
/* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the /* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
* function) incorrectly returned a value of type png_uint_32. * function) incorrectly returned a value of type png_uint_32.
*/ */
# define PNG_get_uint_16(buf) \ # define PNG_get_uint_16(buf) \
((png_uint_16) \ ((png_uint_16) \
(((unsigned int)(*(buf)) << 8) + \ (((unsigned int)(*(buf)) << 8) + \
((unsigned int)(*((buf) + 1))))) ((unsigned int)(*((buf) + 1)))))
# define PNG_get_int_32(buf) \ # define PNG_get_int_32(buf) \
((png_int_32)((*(buf) & 0x80) \ ((png_int_32)((*(buf) & 0x80) \
? -((png_int_32)(((png_get_uint_32(buf)^0xffffffffU)+1U)&0x7fffffffU)) \ ? -((png_int_32)(((png_get_uint_32(buf)^0xffffffffU)+1U)&0x7fffffffU)) \
: (png_int_32)png_get_uint_32(buf))) : (png_int_32)png_get_uint_32(buf)))
/* If PNG_PREFIX is defined the same thing as below happens in pnglibconf.h, /* If PNG_PREFIX is defined the same thing as below happens in pnglibconf.h,
* but defining a macro name prefixed with PNG_PREFIX. * but defining a macro name prefixed with PNG_PREFIX.
*/ */
# ifndef PNG_PREFIX # ifndef PNG_PREFIX
# define png_get_uint_32(buf) PNG_get_uint_32(buf) # define png_get_uint_32(buf) PNG_get_uint_32(buf)
# define png_get_uint_16(buf) PNG_get_uint_16(buf) # define png_get_uint_16(buf) PNG_get_uint_16(buf)
# define png_get_int_32(buf) PNG_get_int_32(buf) # define png_get_int_32(buf) PNG_get_int_32(buf)
# endif # endif
#else #else
# ifdef PNG_PREFIX # ifdef PNG_PREFIX
/* No macros; revert to the (redefined) function */ /* No macros; revert to the (redefined) function */
# define PNG_get_uint_32 (png_get_uint_32) # define PNG_get_uint_32 (png_get_uint_32)
# define PNG_get_uint_16 (png_get_uint_16) # define PNG_get_uint_16 (png_get_uint_16)
# define PNG_get_int_32 (png_get_int_32) # define PNG_get_int_32 (png_get_int_32)
# endif # endif
#endif #endif
@ -3173,9 +3176,9 @@ PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory,
#define PNG_IMAGE_PNG_SIZE_MAX_(image, image_size)\ #define PNG_IMAGE_PNG_SIZE_MAX_(image, image_size)\
((8U/*sig*/+25U/*IHDR*/+16U/*gAMA*/+44U/*cHRM*/+12U/*IEND*/+\ ((8U/*sig*/+25U/*IHDR*/+16U/*gAMA*/+44U/*cHRM*/+12U/*IEND*/+\
(((image).format&PNG_FORMAT_FLAG_COLORMAP)?/*colormap: PLTE, tRNS*/\ (((image).format&PNG_FORMAT_FLAG_COLORMAP)?/*colormap: PLTE, tRNS*/\
12U+3U*(image).colormap_entries/*PLTE data*/+\ 12U+3U*(image).colormap_entries/*PLTE data*/+\
(((image).format&PNG_FORMAT_FLAG_ALPHA)?\ (((image).format&PNG_FORMAT_FLAG_ALPHA)?\
12U/*tRNS*/+(image).colormap_entries:0U):0U)+\ 12U/*tRNS*/+(image).colormap_entries:0U):0U)+\
12U)+(12U*((image_size)/PNG_ZBUF_SIZE))/*IDAT*/+(image_size)) 12U)+(12U*((image_size)/PNG_ZBUF_SIZE))/*IDAT*/+(image_size))
/* A helper for the following macro; if your compiler cannot handle the /* A helper for the following macro; if your compiler cannot handle the
* following macro use this one with the result of * following macro use this one with the result of

View File

@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng /* pngconf.h - machine configurable file for libpng
* *
* libpng version 1.6.24beta05, July 8, 2016 * libpng version 1.6.24beta05, July 13, 2016
* *
* Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@ -188,27 +188,27 @@
* compatible with GCC or Visual C because of different calling conventions. * compatible with GCC or Visual C because of different calling conventions.
*/ */
# if PNG_API_RULE == 2 # if PNG_API_RULE == 2
/* If this line results in an error, either because __watcall is not /* If this line results in an error, either because __watcall is not
* understood or because of a redefine just below you cannot use *this* * understood or because of a redefine just below you cannot use *this*
* build of the library with the compiler you are using. *This* build was * build of the library with the compiler you are using. *This* build was
* build using Watcom and applications must also be built using Watcom! * build using Watcom and applications must also be built using Watcom!
*/ */
# define PNGCAPI __watcall # define PNGCAPI __watcall
# endif # endif
# if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800)) # if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800))
# define PNGCAPI __cdecl # define PNGCAPI __cdecl
# if PNG_API_RULE == 1 # if PNG_API_RULE == 1
/* If this line results in an error __stdcall is not understood and /* If this line results in an error __stdcall is not understood and
* PNG_API_RULE should not have been set to '1'. * PNG_API_RULE should not have been set to '1'.
*/ */
# define PNGAPI __stdcall # define PNGAPI __stdcall
# endif # endif
# else # else
/* An older compiler, or one not detected (erroneously) above, /* An older compiler, or one not detected (erroneously) above,
* if necessary override on the command line to get the correct * if necessary override on the command line to get the correct
* variants for the compiler. * variants for the compiler.
*/ */
# ifndef PNGCAPI # ifndef PNGCAPI
# define PNGCAPI _cdecl # define PNGCAPI _cdecl
# endif # endif
@ -225,10 +225,10 @@
# if (defined(_MSC_VER) && _MSC_VER < 800) ||\ # if (defined(_MSC_VER) && _MSC_VER < 800) ||\
(defined(__BORLANDC__) && __BORLANDC__ < 0x500) (defined(__BORLANDC__) && __BORLANDC__ < 0x500)
/* older Borland and MSC /* older Borland and MSC
* compilers used '__export' and required this to be after * compilers used '__export' and required this to be after
* the type. * the type.
*/ */
# ifndef PNG_EXPORT_TYPE # ifndef PNG_EXPORT_TYPE
# define PNG_EXPORT_TYPE(type) type PNG_IMPEXP # define PNG_EXPORT_TYPE(type) type PNG_IMPEXP
# endif # endif
@ -244,9 +244,9 @@
# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__) # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
# define PNGAPI _System # define PNGAPI _System
# else /* !Windows/x86 && !OS/2 */ # else /* !Windows/x86 && !OS/2 */
/* Use the defaults, or define PNG*API on the command line (but /* Use the defaults, or define PNG*API on the command line (but
* this will have to be done for every compile!) * this will have to be done for every compile!)
*/ */
# endif /* other system, !OS/2 */ # endif /* other system, !OS/2 */
#endif /* !Windows/x86 */ #endif /* !Windows/x86 */
@ -267,7 +267,7 @@
*/ */
#ifndef PNG_IMPEXP #ifndef PNG_IMPEXP
# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT) # if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT)
/* This forces use of a DLL, disallowing static linking */ /* This forces use of a DLL, disallowing static linking */
# define PNG_IMPEXP PNG_DLL_IMPORT # define PNG_IMPEXP PNG_DLL_IMPORT
# endif # endif
@ -340,7 +340,7 @@
* less efficient code. * less efficient code.
*/ */
# if defined(__clang__) && defined(__has_attribute) # if defined(__clang__) && defined(__has_attribute)
/* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */ /* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */
# if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__) # if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__)
# define PNG_USE_RESULT __attribute__((__warn_unused_result__)) # define PNG_USE_RESULT __attribute__((__warn_unused_result__))
# endif # endif

View File

@ -65,18 +65,18 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
else else
error_message += offset; error_message += offset;
}
else
{
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
{
msg[0] = '0';
msg[1] = '\0';
error_message = msg;
} }
}
} else
{
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
{
msg[0] = '0';
msg[1] = '\0';
error_message = msg;
}
}
}
} }
#endif #endif
if (png_ptr != NULL && png_ptr->error_fn != NULL) if (png_ptr != NULL && png_ptr->error_fn != NULL)
@ -391,10 +391,10 @@ png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
void /* PRIVATE */ void /* PRIVATE */
png_app_warning(png_const_structrp png_ptr, png_const_charp error_message) png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
{ {
if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0) if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)
png_warning(png_ptr, error_message); png_warning(png_ptr, error_message);
else else
png_error(png_ptr, error_message); png_error(png_ptr, error_message);
# ifndef PNG_ERROR_TEXT_SUPPORTED # ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message) PNG_UNUSED(error_message)
@ -404,10 +404,10 @@ png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
void /* PRIVATE */ void /* PRIVATE */
png_app_error(png_const_structrp png_ptr, png_const_charp error_message) png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
{ {
if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0) if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0)
png_warning(png_ptr, error_message); png_warning(png_ptr, error_message);
else else
png_error(png_ptr, error_message); png_error(png_ptr, error_message);
# ifndef PNG_ERROR_TEXT_SUPPORTED # ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message) PNG_UNUSED(error_message)

View File

@ -420,10 +420,10 @@
# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \ # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC) defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
/* We need to check that <math.h> hasn't already been included earlier /* We need to check that <math.h> hasn't already been included earlier
* as it seems it doesn't agree with <fp.h>, yet we should really use * as it seems it doesn't agree with <fp.h>, yet we should really use
* <fp.h> if possible. * <fp.h> if possible.
*/ */
# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
# include <fp.h> # include <fp.h>
# endif # endif
@ -431,9 +431,9 @@
# include <math.h> # include <math.h>
# endif # endif
# if defined(_AMIGA) && defined(__SASC) && defined(_M68881) # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
/* Amiga SAS/C: We must include builtin FPU functions when compiling using /* Amiga SAS/C: We must include builtin FPU functions when compiling using
* MATH=68881 * MATH=68881
*/ */
# include <m68881.h> # include <m68881.h>
# endif # endif
#endif #endif
@ -1025,7 +1025,7 @@ PNG_INTERNAL_FUNCTION(void,png_write_sBIT,(png_structrp png_ptr,
#ifdef PNG_WRITE_cHRM_SUPPORTED #ifdef PNG_WRITE_cHRM_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_write_cHRM_fixed,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_write_cHRM_fixed,(png_structrp png_ptr,
const png_xy *xy), PNG_EMPTY); const png_xy *xy), PNG_EMPTY);
/* The xy value must have been previously validated */ /* The xy value must have been previously validated */
#endif #endif
#ifdef PNG_WRITE_sRGB_SUPPORTED #ifdef PNG_WRITE_sRGB_SUPPORTED
@ -1413,7 +1413,7 @@ PNG_INTERNAL_FUNCTION(void,png_push_have_info,(png_structrp png_ptr,
PNG_INTERNAL_FUNCTION(void,png_push_have_end,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_push_have_end,(png_structrp png_ptr,
png_inforp info_ptr),PNG_EMPTY); png_inforp info_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_have_row,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_push_have_row,(png_structrp png_ptr,
png_bytep row),PNG_EMPTY); png_bytep row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_read_end,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_push_read_end,(png_structrp png_ptr,
png_inforp info_ptr),PNG_EMPTY); png_inforp info_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_process_some_data,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_process_some_data,(png_structrp png_ptr,
@ -1452,13 +1452,13 @@ PNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr,
PNG_INTERNAL_FUNCTION(void,png_colorspace_sync_info,(png_const_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_colorspace_sync_info,(png_const_structrp png_ptr,
png_inforp info_ptr), PNG_EMPTY); png_inforp info_ptr), PNG_EMPTY);
/* Synchronize the info 'valid' flags with the colorspace */ /* Synchronize the info 'valid' flags with the colorspace */
PNG_INTERNAL_FUNCTION(void,png_colorspace_sync,(png_const_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_colorspace_sync,(png_const_structrp png_ptr,
png_inforp info_ptr), PNG_EMPTY); png_inforp info_ptr), PNG_EMPTY);
/* Copy the png_struct colorspace to the info_struct and call the above to /* Copy the png_struct colorspace to the info_struct and call the above to
* synchronize the flags. Checks for NULL info_ptr and does nothing. * synchronize the flags. Checks for NULL info_ptr and does nothing.
*/ */
#endif #endif
/* Added at libpng version 1.4.0 */ /* Added at libpng version 1.4.0 */

View File

@ -779,8 +779,8 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED #ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
/* Report invalid palette index; added at libng-1.5.10 */ /* Report invalid palette index; added at libng-1.5.10 */
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
png_ptr->num_palette_max > png_ptr->num_palette) png_ptr->num_palette_max > png_ptr->num_palette)
png_benign_error(png_ptr, "Read palette index exceeding num_palette"); png_benign_error(png_ptr, "Read palette index exceeding num_palette");
#endif #endif
do do
@ -1629,7 +1629,7 @@ png_image_skip_unused_chunks(png_structrp png_ptr)
/* But do not ignore image data handling chunks */ /* But do not ignore image data handling chunks */
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_AS_DEFAULT, png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_AS_DEFAULT,
chunks_to_process, (int)/*SAFE*/(sizeof chunks_to_process)/5); chunks_to_process, (int)/*SAFE*/(sizeof chunks_to_process)/5);
} }
} }
# define PNG_SKIP_CHUNKS(p) png_image_skip_unused_chunks(p) # define PNG_SKIP_CHUNKS(p) png_image_skip_unused_chunks(p)

View File

@ -2465,8 +2465,8 @@ png_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if (buffer == NULL) if (buffer == NULL)
{ {
png_chunk_benign_error(png_ptr, "out of memory"); png_chunk_benign_error(png_ptr, "out of memory");
return; return;
} }
png_crc_read(png_ptr, buffer, length); png_crc_read(png_ptr, buffer, length);
@ -4447,42 +4447,42 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if (row_bytes + 48 > png_ptr->old_big_row_buf_size) 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_row_buf);
png_free(png_ptr, png_ptr->big_prev_row); png_free(png_ptr, png_ptr->big_prev_row);
if (png_ptr->interlaced != 0) if (png_ptr->interlaced != 0)
png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr, png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
row_bytes + 48); row_bytes + 48);
else else
png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48); 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 #ifdef PNG_ALIGNED_MEMORY_SUPPORTED
/* Use 16-byte aligned memory for row_buf with at least 16 bytes /* Use 16-byte aligned memory for row_buf with at least 16 bytes
* of padding before and after row_buf; treat prev_row similarly. * 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 * 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 * 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 * was incorrect; the filter byte was aligned, which had the exact
* opposite effect of that intended. * opposite effect of that intended.
*/ */
{ {
png_bytep temp = png_ptr->big_row_buf + 32; png_bytep temp = png_ptr->big_row_buf + 32;
int extra = (int)((temp - (png_bytep)0) & 0x0f); int extra = (int)((temp - (png_bytep)0) & 0x0f);
png_ptr->row_buf = temp - extra - 1/*filter byte*/; png_ptr->row_buf = temp - extra - 1/*filter byte*/;
temp = png_ptr->big_prev_row + 32; temp = png_ptr->big_prev_row + 32;
extra = (int)((temp - (png_bytep)0) & 0x0f); extra = (int)((temp - (png_bytep)0) & 0x0f);
png_ptr->prev_row = temp - extra - 1/*filter byte*/; png_ptr->prev_row = temp - extra - 1/*filter byte*/;
} }
#else #else
/* Use 31 bytes of padding before and 17 bytes after row_buf. */ /* Use 31 bytes of padding before and 17 bytes after row_buf. */
png_ptr->row_buf = png_ptr->big_row_buf + 31; png_ptr->row_buf = png_ptr->big_row_buf + 31;
png_ptr->prev_row = png_ptr->big_prev_row + 31; png_ptr->prev_row = png_ptr->big_prev_row + 31;
#endif #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 #ifdef PNG_MAX_MALLOC_64K

View File

@ -316,10 +316,10 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
length = strlen(units) + 1; length = strlen(units) + 1;
png_debug1(3, "allocating units for info (%lu bytes)", png_debug1(3, "allocating units for info (%lu bytes)",
(unsigned long)length); (unsigned long)length);
info_ptr->pcal_units = png_voidcast(png_charp, info_ptr->pcal_units = png_voidcast(png_charp,
png_malloc_warn(png_ptr, length)); png_malloc_warn(png_ptr, length));
if (info_ptr->pcal_units == NULL) if (info_ptr->pcal_units == NULL)
{ {
@ -1502,60 +1502,60 @@ png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr,
void PNGAPI void PNGAPI
png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size) png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
{ {
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
if (size == 0 || size > PNG_UINT_31_MAX) if (size == 0 || size > PNG_UINT_31_MAX)
png_error(png_ptr, "invalid compression buffer size"); png_error(png_ptr, "invalid compression buffer size");
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED # ifdef PNG_SEQUENTIAL_READ_SUPPORTED
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
{ {
png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */ png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */
return; return;
} }
# endif # endif
# ifdef PNG_WRITE_SUPPORTED # ifdef PNG_WRITE_SUPPORTED
if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0) if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
{
if (png_ptr->zowner != 0)
{ {
if (png_ptr->zowner != 0) png_warning(png_ptr,
{ "Compression buffer size cannot be changed because it is in use");
png_warning(png_ptr,
"Compression buffer size cannot be changed because it is in use");
return; return;
} }
#ifndef __COVERITY__ #ifndef __COVERITY__
/* Some compilers complain that this is always false. However, it /* Some compilers complain that this is always false. However, it
* can be true when integer overflow happens. * can be true when integer overflow happens.
*/ */
if (size > ZLIB_IO_MAX) if (size > ZLIB_IO_MAX)
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Compression buffer size limited to system maximum"); "Compression buffer size limited to system maximum");
size = ZLIB_IO_MAX; /* must fit */ size = ZLIB_IO_MAX; /* must fit */
} }
#endif #endif
if (size < 6) if (size < 6)
{ {
/* Deflate will potentially go into an infinite loop on a SYNC_FLUSH /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH
* if this is permitted. * if this is permitted.
*/ */
png_warning(png_ptr, png_warning(png_ptr,
"Compression buffer size cannot be reduced below 6"); "Compression buffer size cannot be reduced below 6");
return; return;
}
if (png_ptr->zbuffer_size != size)
{
png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
png_ptr->zbuffer_size = (uInt)size;
}
} }
if (png_ptr->zbuffer_size != size)
{
png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
png_ptr->zbuffer_size = (uInt)size;
}
}
# endif # endif
} }

184
pngtest.c
View File

@ -139,13 +139,13 @@ static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";
static int static int
tIME_to_str(png_structp png_ptr, png_charp ts, png_const_timep t) tIME_to_str(png_structp png_ptr, png_charp ts, png_const_timep t)
{ {
png_const_charp str = png_convert_to_rfc1123(png_ptr, t); png_const_charp str = png_convert_to_rfc1123(png_ptr, t);
if (str == NULL) if (str == NULL)
return 0; return 0;
strcpy(ts, str); strcpy(ts, str);
return 1; return 1;
} }
#endif /* older libpng */ #endif /* older libpng */
#endif #endif
@ -249,95 +249,95 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
* png_byte pixel_depth bits per pixel (depth*channels) * png_byte pixel_depth bits per pixel (depth*channels)
*/ */
/* Counts the number of zero samples (or zero pixels if color_type is 3 */ /* Counts the number of zero samples (or zero pixels if color_type is 3 */
if (row_info->color_type == 0 || row_info->color_type == 3) if (row_info->color_type == 0 || row_info->color_type == 3)
{ {
int pos = 0; int pos = 0;
png_uint_32 n, nstop; png_uint_32 n, nstop;
for (n = 0, nstop=row_info->width; n<nstop; n++) for (n = 0, nstop=row_info->width; n<nstop; n++)
{ {
if (row_info->bit_depth == 1) if (row_info->bit_depth == 1)
{ {
if (((*dp << pos++ ) & 0x80) == 0) if (((*dp << pos++ ) & 0x80) == 0)
zero_samples++; zero_samples++;
if (pos == 8) if (pos == 8)
{ {
pos = 0; pos = 0;
dp++; dp++;
} }
} }
if (row_info->bit_depth == 2) if (row_info->bit_depth == 2)
{ {
if (((*dp << (pos+=2)) & 0xc0) == 0) if (((*dp << (pos+=2)) & 0xc0) == 0)
zero_samples++; zero_samples++;
if (pos == 8) if (pos == 8)
{ {
pos = 0; pos = 0;
dp++; dp++;
} }
} }
if (row_info->bit_depth == 4) if (row_info->bit_depth == 4)
{ {
if (((*dp << (pos+=4)) & 0xf0) == 0) if (((*dp << (pos+=4)) & 0xf0) == 0)
zero_samples++; zero_samples++;
if (pos == 8) if (pos == 8)
{ {
pos = 0; pos = 0;
dp++; dp++;
} }
} }
if (row_info->bit_depth == 8) if (row_info->bit_depth == 8)
if (*dp++ == 0) if (*dp++ == 0)
zero_samples++; zero_samples++;
if (row_info->bit_depth == 16) if (row_info->bit_depth == 16)
{ {
if ((*dp | *(dp+1)) == 0) if ((*dp | *(dp+1)) == 0)
zero_samples++; zero_samples++;
dp+=2; dp+=2;
} }
} }
} }
else /* Other color types */ else /* Other color types */
{ {
png_uint_32 n, nstop; png_uint_32 n, nstop;
int channel; int channel;
int color_channels = row_info->channels; int color_channels = row_info->channels;
if (row_info->color_type > 3) if (row_info->color_type > 3)
color_channels--; color_channels--;
for (n = 0, nstop=row_info->width; n<nstop; n++) for (n = 0, nstop=row_info->width; n<nstop; n++)
{ {
for (channel = 0; channel < color_channels; channel++) for (channel = 0; channel < color_channels; channel++)
{ {
if (row_info->bit_depth == 8) if (row_info->bit_depth == 8)
if (*dp++ == 0) if (*dp++ == 0)
zero_samples++; zero_samples++;
if (row_info->bit_depth == 16) if (row_info->bit_depth == 16)
{ {
if ((*dp | *(dp+1)) == 0) if ((*dp | *(dp+1)) == 0)
zero_samples++; zero_samples++;
dp+=2; dp+=2;
} }
} }
if (row_info->color_type > 3) if (row_info->color_type > 3)
{ {
dp++; dp++;
if (row_info->bit_depth == 16) if (row_info->bit_depth == 16)
dp++; dp++;
} }
} }
} }
} }
#endif /* WRITE_USER_TRANSFORM */ #endif /* WRITE_USER_TRANSFORM */
@ -935,7 +935,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
init_callback_info(read_info_ptr); init_callback_info(read_info_ptr);
png_set_read_user_chunk_fn(read_ptr, &user_chunk_data, png_set_read_user_chunk_fn(read_ptr, &user_chunk_data,
read_user_chunk_callback); read_user_chunk_callback);
#endif #endif
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
@ -1855,19 +1855,19 @@ main(int argc, char *argv[])
} }
if (multiple == 0 && argc == 3 + verbose) if (multiple == 0 && argc == 3 + verbose)
outname = argv[2 + verbose]; outname = argv[2 + verbose];
if ((multiple == 0 && argc > 3 + verbose) || if ((multiple == 0 && argc > 3 + verbose) ||
(multiple != 0 && argc < 2)) (multiple != 0 && argc < 2))
{ {
fprintf(STDERR, fprintf(STDERR,
"usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n", "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
argv[0], argv[0]); argv[0], argv[0]);
fprintf(STDERR, fprintf(STDERR,
" reads/writes one PNG file (without -m) or multiple files (-m)\n"); " reads/writes one PNG file (without -m) or multiple files (-m)\n");
fprintf(STDERR, fprintf(STDERR,
" with -m %s is used as a temporary file\n", outname); " with -m %s is used as a temporary file\n", outname);
exit(1); exit(1);
} }
if (multiple != 0) if (multiple != 0)