[CHG] libpng updated to version 1.2.42

This commit is contained in:
Crayon2000 2010-01-06 17:42:22 +00:00
parent de118ab6f2
commit 6847fba41f
20 changed files with 28599 additions and 28075 deletions

View file

@ -1,8 +1,8 @@
/* png.c - location for general purpose libpng functions /* png.c - location for general purpose libpng functions
* *
* Last changed in libpng 1.2.39 [August 13, 2009] * Last changed in libpng 1.2.42 [January 3, 2010]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2010 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.)
* *
@ -13,13 +13,15 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_EXTERN #define PNG_NO_EXTERN
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.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 version_1_2_40 Your_png_h_is_not_version_1_2_40; typedef version_1_2_42 Your_png_h_is_not_version_1_2_42;
/* Version information for C files. This had better match the version /* Version information for C files. This had better match the version
* string defined in png.h. */ * string defined in png.h.
*/
#ifdef PNG_USE_GLOBAL_ARRAYS #ifdef PNG_USE_GLOBAL_ARRAYS
/* png_libpng_ver was changed to a function in version 1.0.5c */ /* png_libpng_ver was changed to a function in version 1.0.5c */
@ -95,9 +97,11 @@ PNG_CONST int FARDATA png_pass_dsp_mask[]
void PNGAPI void PNGAPI
png_set_sig_bytes(png_structp png_ptr, int num_bytes) png_set_sig_bytes(png_structp png_ptr, int num_bytes)
{ {
png_debug(1, "in png_set_sig_bytes");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_debug(1, "in png_set_sig_bytes");
if (num_bytes > 8) if (num_bytes > 8)
png_error(png_ptr, "Too many bytes for PNG signature."); png_error(png_ptr, "Too many bytes for PNG signature.");
@ -246,8 +250,10 @@ png_create_info_struct(png_structp png_ptr)
png_infop info_ptr; png_infop info_ptr;
png_debug(1, "in png_create_info_struct"); png_debug(1, "in png_create_info_struct");
if (png_ptr == NULL) if (png_ptr == NULL)
return (NULL); return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
png_ptr->malloc_fn, png_ptr->mem_ptr); png_ptr->malloc_fn, png_ptr->mem_ptr);
@ -269,10 +275,12 @@ void PNGAPI
png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
{ {
png_infop info_ptr = NULL; png_infop info_ptr = NULL;
png_debug(1, "in png_destroy_info_struct");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_debug(1, "in png_destroy_info_struct");
if (info_ptr_ptr != NULL) if (info_ptr_ptr != NULL)
info_ptr = *info_ptr_ptr; info_ptr = *info_ptr_ptr;
@ -309,11 +317,11 @@ png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
{ {
png_infop info_ptr = *ptr_ptr; png_infop info_ptr = *ptr_ptr;
png_debug(1, "in png_info_init_3");
if (info_ptr == NULL) if (info_ptr == NULL)
return; return;
png_debug(1, "in png_info_init_3");
if (png_sizeof(png_info) > png_info_struct_size) if (png_sizeof(png_info) > png_info_struct_size)
{ {
png_destroy_struct(info_ptr); png_destroy_struct(info_ptr);
@ -331,8 +339,10 @@ png_data_freer(png_structp png_ptr, png_infop info_ptr,
int freer, png_uint_32 mask) int freer, png_uint_32 mask)
{ {
png_debug(1, "in png_data_freer"); png_debug(1, "in png_data_freer");
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
if (freer == PNG_DESTROY_WILL_FREE_DATA) if (freer == PNG_DESTROY_WILL_FREE_DATA)
info_ptr->free_me |= mask; info_ptr->free_me |= mask;
else if (freer == PNG_USER_WILL_FREE_DATA) else if (freer == PNG_USER_WILL_FREE_DATA)
@ -348,10 +358,11 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
int num) int num)
{ {
png_debug(1, "in png_free_data"); png_debug(1, "in png_free_data");
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
#if defined(PNG_TEXT_SUPPORTED) #ifdef PNG_TEXT_SUPPORTED
/* Free text item num or (if num == -1) all text items */ /* Free text item num or (if num == -1) all text items */
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_TEXT) & info_ptr->free_me) if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
@ -379,7 +390,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
} }
#endif #endif
#if defined(PNG_tRNS_SUPPORTED) #ifdef PNG_tRNS_SUPPORTED
/* Free any tRNS entry */ /* Free any tRNS entry */
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
@ -396,7 +407,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
} }
#endif #endif
#if defined(PNG_sCAL_SUPPORTED) #ifdef PNG_sCAL_SUPPORTED
/* Free any sCAL entry */ /* Free any sCAL entry */
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
@ -414,7 +425,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
} }
#endif #endif
#if defined(PNG_pCAL_SUPPORTED) #ifdef PNG_pCAL_SUPPORTED
/* Free any pCAL entry */ /* Free any pCAL entry */
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_PCAL) & info_ptr->free_me) if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
@ -432,7 +443,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
for (i = 0; i < (int)info_ptr->pcal_nparams; i++) for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
{ {
png_free(png_ptr, info_ptr->pcal_params[i]); png_free(png_ptr, info_ptr->pcal_params[i]);
info_ptr->pcal_params[i]=NULL; info_ptr->pcal_params[i] = NULL;
} }
png_free(png_ptr, info_ptr->pcal_params); png_free(png_ptr, info_ptr->pcal_params);
info_ptr->pcal_params = NULL; info_ptr->pcal_params = NULL;
@ -441,7 +452,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
} }
#endif #endif
#if defined(PNG_iCCP_SUPPORTED) #ifdef PNG_iCCP_SUPPORTED
/* Free any iCCP entry */ /* Free any iCCP entry */
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_ICCP) & info_ptr->free_me) if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
@ -457,7 +468,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
} }
#endif #endif
#if defined(PNG_sPLT_SUPPORTED) #ifdef PNG_sPLT_SUPPORTED
/* Free a given sPLT entry, or (if num == -1) all sPLT entries */ /* Free a given sPLT entry, or (if num == -1) all sPLT entries */
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
@ -492,7 +503,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
} }
#endif #endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
if (png_ptr->unknown_chunk.data) if (png_ptr->unknown_chunk.data)
{ {
png_free(png_ptr, png_ptr->unknown_chunk.data); png_free(png_ptr, png_ptr->unknown_chunk.data);
@ -530,7 +541,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
} }
#endif #endif
#if defined(PNG_hIST_SUPPORTED) #ifdef PNG_hIST_SUPPORTED
/* Free any hIST entry */ /* Free any hIST entry */
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_HIST) & info_ptr->free_me) if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
@ -563,7 +574,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
info_ptr->num_palette = 0; info_ptr->num_palette = 0;
} }
#if defined(PNG_INFO_IMAGE_SUPPORTED) #ifdef PNG_INFO_IMAGE_SUPPORTED
/* Free any image bits attached to the info structure */ /* Free any image bits attached to the info structure */
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
@ -577,10 +588,10 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
for (row = 0; row < (int)info_ptr->height; row++) for (row = 0; row < (int)info_ptr->height; row++)
{ {
png_free(png_ptr, info_ptr->row_pointers[row]); png_free(png_ptr, info_ptr->row_pointers[row]);
info_ptr->row_pointers[row]=NULL; info_ptr->row_pointers[row] = NULL;
} }
png_free(png_ptr, info_ptr->row_pointers); png_free(png_ptr, info_ptr->row_pointers);
info_ptr->row_pointers=NULL; info_ptr->row_pointers = NULL;
} }
info_ptr->valid &= ~PNG_INFO_IDAT; info_ptr->valid &= ~PNG_INFO_IDAT;
} }
@ -605,11 +616,11 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
#if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
if (png_ptr->num_chunk_list) if (png_ptr->num_chunk_list)
{ {
png_free(png_ptr, png_ptr->chunk_list); png_free(png_ptr, png_ptr->chunk_list);
png_ptr->chunk_list=NULL; png_ptr->chunk_list = NULL;
png_ptr->num_chunk_list = 0; png_ptr->num_chunk_list = 0;
} }
#endif #endif
@ -631,7 +642,7 @@ png_get_io_ptr(png_structp png_ptr)
} }
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#if !defined(PNG_NO_STDIO) #ifdef PNG_STDIO_SUPPORTED
/* Initialize the default input/output functions for the PNG file. If you /* Initialize the default input/output functions for the PNG file. If you
* use your own read or write routines, you can call either png_set_read_fn() * use your own read or write routines, you can call either png_set_read_fn()
* or png_set_write_fn() instead of png_init_io(). If you have defined * or png_set_write_fn() instead of png_init_io(). If you have defined
@ -642,13 +653,15 @@ void PNGAPI
png_init_io(png_structp png_ptr, png_FILE_p fp) png_init_io(png_structp png_ptr, png_FILE_p fp)
{ {
png_debug(1, "in png_init_io"); png_debug(1, "in png_init_io");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->io_ptr = (png_voidp)fp; png_ptr->io_ptr = (png_voidp)fp;
} }
#endif #endif
#if defined(PNG_TIME_RFC1123_SUPPORTED) #ifdef PNG_TIME_RFC1123_SUPPORTED
/* Convert the supplied time into an RFC 1123 string suitable for use in /* Convert the supplied time into an RFC 1123 string suitable for use in
* a "Creation Time" or other text-based time string. * a "Creation Time" or other text-based time string.
*/ */
@ -667,7 +680,7 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
png_sizeof(char))); png_sizeof(char)));
} }
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
{ {
wchar_t time_buf[29]; wchar_t time_buf[29];
wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"), wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
@ -705,10 +718,23 @@ png_charp PNGAPI
png_get_copyright(png_structp png_ptr) png_get_copyright(png_structp png_ptr)
{ {
png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */
return ((png_charp) "\n libpng version 1.2.40 - September 10, 2009\n\ #ifdef PNG_STRING_COPYRIGHT
Copyright (c) 1998-2009 Glenn Randers-Pehrson\n\ return PNG_STRING_COPYRIGHT
Copyright (c) 1996-1997 Andreas Dilger\n\ #else
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n"); #ifdef __STDC__
return ((png_charp) PNG_STRING_NEWLINE \
"libpng version 1.2.42 - January 3, 2010" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2010 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE);
#else
return ((png_charp) "libpng version 1.2.42 - January 3, 2010\
Copyright (c) 1998-2010 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.");
#endif
#endif
} }
/* The following return the library version as a short string in the /* The following return the library version as a short string in the
@ -740,11 +766,15 @@ png_get_header_version(png_structp png_ptr)
{ {
/* Returns longer string containing both version and date */ /* Returns longer string containing both version and date */
png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */
#ifdef __STDC__
return ((png_charp) PNG_HEADER_VERSION_STRING return ((png_charp) PNG_HEADER_VERSION_STRING
#ifndef PNG_READ_SUPPORTED #ifndef PNG_READ_SUPPORTED
" (NO READ SUPPORT)" " (NO READ SUPPORT)"
#endif #endif
"\n"); PNG_STRING_NEWLINE);
#else
return ((png_charp) PNG_HEADER_VERSION_STRING);
#endif
} }
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
@ -785,7 +815,7 @@ png_access_version_number(void)
#if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
#if !defined(PNG_1_0_X) #ifndef PNG_1_0_X
/* This function was added to libpng 1.2.0 */ /* This function was added to libpng 1.2.0 */
int PNGAPI int PNGAPI
png_mmx_support(void) png_mmx_support(void)
@ -810,8 +840,8 @@ png_convert_size(size_t size)
#endif /* PNG_SIZE_T */ #endif /* PNG_SIZE_T */
/* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */ /* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */
#if defined(PNG_cHRM_SUPPORTED) #ifdef PNG_cHRM_SUPPORTED
#if !defined(PNG_NO_CHECK_cHRM) #ifdef PNG_CHECK_cHRM_SUPPORTED
/* /*
* Multiply two 32-bit numbers, V1 and V2, using 32-bit * Multiply two 32-bit numbers, V1 and V2, using 32-bit
@ -863,6 +893,7 @@ png_check_cHRM_fixed(png_structp png_ptr,
unsigned long xy_hi,xy_lo,yx_hi,yx_lo; unsigned long xy_hi,xy_lo,yx_hi,yx_lo;
png_debug(1, "in function png_check_cHRM_fixed"); png_debug(1, "in function png_check_cHRM_fixed");
if (png_ptr == NULL) if (png_ptr == NULL)
return 0; return 0;
@ -921,6 +952,148 @@ png_check_cHRM_fixed(png_structp png_ptr,
return ret; return ret;
} }
#endif /* NO_PNG_CHECK_cHRM */ #endif /* PNG_CHECK_cHRM_SUPPORTED */
#endif /* PNG_cHRM_SUPPORTED */ #endif /* PNG_cHRM_SUPPORTED */
void /* PRIVATE */
png_check_IHDR(png_structp png_ptr,
png_uint_32 width, png_uint_32 height, int bit_depth,
int color_type, int interlace_type, int compression_type,
int filter_type)
{
int error = 0;
/* Check for width and height valid values */
if (width == 0)
{
png_warning(png_ptr, "Image width is zero in IHDR");
error = 1;
}
if (height == 0)
{
png_warning(png_ptr, "Image height is zero in IHDR");
error = 1;
}
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
if (width > png_ptr->user_width_max || width > PNG_USER_WIDTH_MAX)
#else
if (width > PNG_USER_WIDTH_MAX)
#endif
{
png_warning(png_ptr, "Image width exceeds user limit in IHDR");
error = 1;
}
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
if (height > png_ptr->user_height_max || height > PNG_USER_HEIGHT_MAX)
#else
if (height > PNG_USER_HEIGHT_MAX)
#endif
{
png_warning(png_ptr, "Image height exceeds user limit in IHDR");
error = 1;
}
if (width > PNG_UINT_31_MAX)
{
png_warning(png_ptr, "Invalid image width in IHDR");
error = 1;
}
if ( height > PNG_UINT_31_MAX)
{
png_warning(png_ptr, "Invalid image height in IHDR");
error = 1;
}
if ( width > (PNG_UINT_32_MAX
>> 3) /* 8-byte RGBA pixels */
- 64 /* bigrowbuf hack */
- 1 /* filter byte */
- 7*8 /* rounding of width to multiple of 8 pixels */
- 8) /* extra max_pixel_depth pad */
png_warning(png_ptr, "Width is too large for libpng to process pixels");
/* Check other values */
if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
bit_depth != 8 && bit_depth != 16)
{
png_warning(png_ptr, "Invalid bit depth in IHDR");
error = 1;
}
if (color_type < 0 || color_type == 1 ||
color_type == 5 || color_type > 6)
{
png_warning(png_ptr, "Invalid color type in IHDR");
error = 1;
}
if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
((color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
{
png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR");
error = 1;
}
if (interlace_type >= PNG_INTERLACE_LAST)
{
png_warning(png_ptr, "Unknown interlace method in IHDR");
error = 1;
}
if (compression_type != PNG_COMPRESSION_TYPE_BASE)
{
png_warning(png_ptr, "Unknown compression method in IHDR");
error = 1;
}
#ifdef PNG_MNG_FEATURES_SUPPORTED
/* Accept filter_method 64 (intrapixel differencing) only if
* 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
* 2. Libpng did not read a PNG signature (this filter_method is only
* used in PNG datastreams that are embedded in MNG datastreams) and
* 3. The application called png_permit_mng_features with a mask that
* included PNG_FLAG_MNG_FILTER_64 and
* 4. The filter_method is 64 and
* 5. The color_type is RGB or RGBA
*/
if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) &&
png_ptr->mng_features_permitted)
png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
if (filter_type != PNG_FILTER_TYPE_BASE)
{
if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) &&
(color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
{
png_warning(png_ptr, "Unknown filter method in IHDR");
error = 1;
}
if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE)
{
png_warning(png_ptr, "Invalid filter method in IHDR");
error = 1;
}
}
#else
if (filter_type != PNG_FILTER_TYPE_BASE)
{
png_warning(png_ptr, "Unknown filter method in IHDR");
error = 1;
}
#endif
if (error == 1)
png_error(png_ptr, "Invalid IHDR data");
}
#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,8 @@
/* pngconf.h - machine configurable file for libpng /* pngconf.h - machine configurable file for libpng
* *
* libpng version 1.2.40 - September 10, 2009 * libpng version 1.2.42 - January 3, 2010
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2010 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.)
* *
@ -115,8 +115,33 @@
# define PNG_WRITE_SUPPORTED # define PNG_WRITE_SUPPORTED
#endif #endif
/* Enabled in 1.2.41. */
#ifdef PNG_ALLOW_BENIGN_ERRORS
# define png_benign_error png_warning
# define png_chunk_benign_error png_chunk_warning
#else
# ifndef PNG_BENIGN_ERRORS_SUPPORTED
# define png_benign_error png_error
# define png_chunk_benign_error png_chunk_error
# endif
#endif
/* Added in libpng-1.2.41 */
#if !defined(PNG_NO_WARNINGS) && !defined(PNG_WARNINGS_SUPPORTED)
# define PNG_WARNINGS_SUPPORTED
#endif
#if !defined(PNG_NO_ERROR_TEXT) && !defined(PNG_ERROR_TEXT_SUPPORTED)
# define PNG_ERROR_TEXT_SUPPORTED
#endif
#if !defined(PNG_NO_CHECK_cHRM) && !defined(PNG_CHECK_cHRM_SUPPORTED)
# define PNG_CHECK_cHRM_SUPPORTED
#endif
/* Enabled by default in 1.2.0. You can disable this if you don't need to /* Enabled by default in 1.2.0. You can disable this if you don't need to
support PNGs that are embedded in MNG datastreams */ * support PNGs that are embedded in MNG datastreams
*/
#if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES) #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
# ifndef PNG_MNG_FEATURES_SUPPORTED # ifndef PNG_MNG_FEATURES_SUPPORTED
# define PNG_MNG_FEATURES_SUPPORTED # define PNG_MNG_FEATURES_SUPPORTED
@ -174,44 +199,44 @@
* PNG_BUILD_DLL and PNG_STATIC because those change some defaults * PNG_BUILD_DLL and PNG_STATIC because those change some defaults
* such as CONSOLE_IO and whether GLOBAL_ARRAYS are allowed. * such as CONSOLE_IO and whether GLOBAL_ARRAYS are allowed.
*/ */
#if defined(__CYGWIN__) #ifdef __CYGWIN__
# if defined(ALL_STATIC) # ifdef ALL_STATIC
# if defined(PNG_BUILD_DLL) # ifdef PNG_BUILD_DLL
# undef PNG_BUILD_DLL # undef PNG_BUILD_DLL
# endif # endif
# if defined(PNG_USE_DLL) # ifdef PNG_USE_DLL
# undef PNG_USE_DLL # undef PNG_USE_DLL
# endif # endif
# if defined(PNG_DLL) # ifdef PNG_DLL
# undef PNG_DLL # undef PNG_DLL
# endif # endif
# if !defined(PNG_STATIC) # ifndef PNG_STATIC
# define PNG_STATIC # define PNG_STATIC
# endif # endif
# else # else
# if defined (PNG_BUILD_DLL) # ifdef PNG_BUILD_DLL
# if defined(PNG_STATIC) # ifdef PNG_STATIC
# undef PNG_STATIC # undef PNG_STATIC
# endif # endif
# if defined(PNG_USE_DLL) # ifdef PNG_USE_DLL
# undef PNG_USE_DLL # undef PNG_USE_DLL
# endif # endif
# if !defined(PNG_DLL) # ifndef PNG_DLL
# define PNG_DLL # define PNG_DLL
# endif # endif
# else # else
# if defined(PNG_STATIC) # ifdef PNG_STATIC
# if defined(PNG_USE_DLL) # ifdef PNG_USE_DLL
# undef PNG_USE_DLL # undef PNG_USE_DLL
# endif # endif
# if defined(PNG_DLL) # ifdef PNG_DLL
# undef PNG_DLL # undef PNG_DLL
# endif # endif
# else # else
# if !defined(PNG_USE_DLL) # ifndef PNG_USE_DLL
# define PNG_USE_DLL # define PNG_USE_DLL
# endif # endif
# if !defined(PNG_DLL) # ifndef PNG_DLL
# define PNG_DLL # define PNG_DLL
# endif # endif
# endif # endif
@ -232,7 +257,11 @@
* #define PNG_NO_STDIO * #define PNG_NO_STDIO
*/ */
#if defined(_WIN32_WCE) #if !defined(PNG_NO_STDIO) && !defined(PNG_STDIO_SUPPORTED)
# define PNG_STDIO_SUPPORTED
#endif
#ifdef _WIN32_WCE
# include <windows.h> # include <windows.h>
/* Console I/O functions are not supported on WindowsCE */ /* Console I/O functions are not supported on WindowsCE */
# define PNG_NO_CONSOLE_IO # define PNG_NO_CONSOLE_IO
@ -261,12 +290,16 @@
# endif # endif
# endif # endif
# else # else
# if !defined(_WIN32_WCE) # ifndef _WIN32_WCE
/* "stdio.h" functions are not supported on WindowsCE */ /* "stdio.h" functions are not supported on WindowsCE */
# include <stdio.h> # include <stdio.h>
# endif # endif
# endif # endif
#if !(defined PNG_NO_CONSOLE_IO) && !defined(PNG_CONSOLE_IO_SUPPORTED)
# define PNG_CONSOLE_IO_SUPPORTED
#endif
/* This macro protects us against machines that don't have function /* This macro protects us against machines that don't have function
* prototypes (ie K&R style headers). If your compiler does not handle * prototypes (ie K&R style headers). If your compiler does not handle
* function prototypes, define this macro and use the included ansi2knr. * function prototypes, define this macro and use the included ansi2knr.
@ -378,8 +411,8 @@
* them inside an appropriate ifdef/endif pair for portability. * them inside an appropriate ifdef/endif pair for portability.
*/ */
#if defined(PNG_FLOATING_POINT_SUPPORTED) #ifdef PNG_FLOATING_POINT_SUPPORTED
# if defined(MACOS) # ifdef MACOS
/* 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.
@ -589,18 +622,22 @@
# ifndef PNG_NO_READ_BACKGROUND # ifndef PNG_NO_READ_BACKGROUND
# define PNG_READ_BACKGROUND_SUPPORTED # define PNG_READ_BACKGROUND_SUPPORTED
# endif # endif
#ifndef PNG_1_0_X
# ifndef PNG_NO_READ_16_TO_8 # ifndef PNG_NO_READ_16_TO_8
# define PNG_READ_16_TO_8_SUPPORTED # define PNG_READ_16_TO_8_SUPPORTED
# endif # endif
#endif
# ifndef PNG_NO_READ_FILLER # ifndef PNG_NO_READ_FILLER
# define PNG_READ_FILLER_SUPPORTED # define PNG_READ_FILLER_SUPPORTED
# endif # endif
# ifndef PNG_NO_READ_GAMMA # ifndef PNG_NO_READ_GAMMA
# define PNG_READ_GAMMA_SUPPORTED # define PNG_READ_GAMMA_SUPPORTED
# endif # endif
#ifndef PNG_1_0_X
# ifndef PNG_NO_READ_GRAY_TO_RGB # ifndef PNG_NO_READ_GRAY_TO_RGB
# define PNG_READ_GRAY_TO_RGB_SUPPORTED # define PNG_READ_GRAY_TO_RGB_SUPPORTED
# endif # endif
#endif
# ifndef PNG_NO_READ_SWAP_ALPHA # ifndef PNG_NO_READ_SWAP_ALPHA
# define PNG_READ_SWAP_ALPHA_SUPPORTED # define PNG_READ_SWAP_ALPHA_SUPPORTED
# endif # endif
@ -618,11 +655,20 @@
# endif # endif
#endif /* PNG_READ_TRANSFORMS_SUPPORTED */ #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
/* PNG_PROGRESSIVE_READ_NOT_SUPPORTED is deprecated. */
#if !defined(PNG_NO_PROGRESSIVE_READ) && \ #if !defined(PNG_NO_PROGRESSIVE_READ) && \
!defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */ !defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */
# define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */ # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
#endif /* about interlacing capability! You'll */ #endif /* about interlacing capability! You'll */
/* still have interlacing unless you change the following line: */ /* still have interlacing unless you change the following define: */
#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */
/* PNG_NO_SEQUENTIAL_READ_SUPPORTED is deprecated. */
#if !defined(PNG_NO_SEQUENTIAL_READ) && \
!defined(PNG_SEQUENTIAL_READ_SUPPORTED) && \
!defined(PNG_NO_SEQUENTIAL_READ_SUPPORTED)
# define PNG_SEQUENTIAL_READ_SUPPORTED
#endif
#define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */ #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
@ -674,9 +720,11 @@
# ifndef PNG_NO_WRITE_SWAP_ALPHA # ifndef PNG_NO_WRITE_SWAP_ALPHA
# define PNG_WRITE_SWAP_ALPHA_SUPPORTED # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
# endif # endif
#ifndef PNG_1_0_X
# ifndef PNG_NO_WRITE_INVERT_ALPHA # ifndef PNG_NO_WRITE_INVERT_ALPHA
# define PNG_WRITE_INVERT_ALPHA_SUPPORTED # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
# endif # endif
#endif
# ifndef PNG_NO_WRITE_USER_TRANSFORM # ifndef PNG_NO_WRITE_USER_TRANSFORM
# define PNG_WRITE_USER_TRANSFORM_SUPPORTED # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
# endif # endif
@ -768,7 +816,7 @@
# endif # endif
# endif # endif
# if defined(__APPLE__) # ifdef __APPLE__
# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
# define PNG_NO_MMX_CODE # define PNG_NO_MMX_CODE
# endif # endif
@ -787,19 +835,20 @@
#endif #endif
/* end of obsolete code to be removed from libpng-1.4.0 */ /* end of obsolete code to be removed from libpng-1.4.0 */
#if !defined(PNG_1_0_X) /* Added at libpng-1.2.0 */
#ifndef PNG_1_0_X
#if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED) #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
# define PNG_USER_MEM_SUPPORTED # define PNG_USER_MEM_SUPPORTED
#endif #endif
#endif /* PNG_1_0_X */ #endif /* PNG_1_0_X */
/* Added at libpng-1.2.6 */ /* Added at libpng-1.2.6 */
#if !defined(PNG_1_0_X) #ifndef PNG_1_0_X
#ifndef PNG_SET_USER_LIMITS_SUPPORTED # ifndef PNG_SET_USER_LIMITS_SUPPORTED
#if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED) # ifndef PNG_NO_SET_USER_LIMITS
# define PNG_SET_USER_LIMITS_SUPPORTED # define PNG_SET_USER_LIMITS_SUPPORTED
#endif # endif
#endif # endif
#endif /* PNG_1_0_X */ #endif /* PNG_1_0_X */
/* Added at libpng-1.0.16 and 1.2.6. To accept all valid PNGS no matter /* Added at libpng-1.0.16 and 1.2.6. To accept all valid PNGS no matter
@ -812,7 +861,24 @@
# define PNG_USER_HEIGHT_MAX 1000000L # define PNG_USER_HEIGHT_MAX 1000000L
#endif #endif
/* Added at libpng-1.2.34 and 1.4.0 */ #ifndef PNG_1_0_X
/* Added at libpng-1.2.41 */
#ifndef PNG_USER_CHUNK_CACHE_MAX
# define PNG_USER_CHUNK_CACHE_MAX 0x7fffffffL
#endif
#endif
#ifndef PNG_LITERAL_SHARP
# define PNG_LITERAL_SHARP 0x23
#endif
#ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET
# define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b
#endif
#ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET
# define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d
#endif
/* Added at libpng-1.2.34 */
#ifndef PNG_STRING_NEWLINE #ifndef PNG_STRING_NEWLINE
#define PNG_STRING_NEWLINE "\n" #define PNG_STRING_NEWLINE "\n"
#endif #endif
@ -841,6 +907,11 @@
#define PNG_NO_POINTER_INDEXING #define PNG_NO_POINTER_INDEXING
*/ */
#if !defined(PNG_NO_POINTER_INDEXING) && \
!defined(PNG_POINTER_INDEXING_SUPPORTED)
# define PNG_POINTER_INDEXING_SUPPORTED
#endif
/* These functions are turned off by default, as they will be phased out. */ /* These functions are turned off by default, as they will be phased out. */
/* /*
#define PNG_USELESS_TESTS_SUPPORTED #define PNG_USELESS_TESTS_SUPPORTED
@ -1099,8 +1170,23 @@
# endif # endif
#endif #endif
#ifdef PNG_WRITE_tIME_SUPPORTED
# ifndef PNG_NO_CONVERT_tIME
# ifndef _WIN32_WCE
/* The "tm" structure is not supported on WindowsCE */
# ifndef PNG_CONVERT_tIME_SUPPORTED
# define PNG_CONVERT_tIME_SUPPORTED
# endif
# endif
# endif
#endif
#endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */ #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
#if !defined(PNG_NO_WRITE_FILTER) && !defined(PNG_WRITE_FILTER_SUPPORTED)
# define PNG_WRITE_FILTER_SUPPORTED
#endif
#ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
# define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
# ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
@ -1123,12 +1209,10 @@
# define PNG_INFO_IMAGE_SUPPORTED # define PNG_INFO_IMAGE_SUPPORTED
#endif #endif
/* need the time information for reading tIME chunks */ /* Need the time information for converting tIME chunks */
#if defined(PNG_tIME_SUPPORTED) #ifdef PNG_CONVERT_tIME_SUPPORTED
# if !defined(_WIN32_WCE)
/* "time.h" functions are not supported on WindowsCE */ /* "time.h" functions are not supported on WindowsCE */
# include <time.h> # include <time.h>
# endif
#endif #endif
/* Some typedefs to get us started. These should be safe on most of the /* Some typedefs to get us started. These should be safe on most of the
@ -1197,8 +1281,8 @@ typedef unsigned char png_byte;
*/ */
/* MSC Medium model */ /* MSC Medium model */
#if defined(FAR) #ifdef FAR
# if defined(M_I86MM) # ifdef M_I86MM
# define USE_FAR_KEYWORD # define USE_FAR_KEYWORD
# define FARDATA FAR # define FARDATA FAR
# include <dos.h> # include <dos.h>
@ -1231,7 +1315,7 @@ typedef char FAR * png_charp;
typedef png_fixed_point FAR * png_fixed_point_p; typedef png_fixed_point FAR * png_fixed_point_p;
#ifndef PNG_NO_STDIO #ifndef PNG_NO_STDIO
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
typedef HANDLE png_FILE_p; typedef HANDLE png_FILE_p;
#else #else
typedef FILE * png_FILE_p; typedef FILE * png_FILE_p;
@ -1295,17 +1379,17 @@ typedef z_stream FAR * png_zstreamp;
* When building a static lib, default to no GLOBAL ARRAYS, but allow * When building a static lib, default to no GLOBAL ARRAYS, but allow
* command-line override * command-line override
*/ */
#if defined(__CYGWIN__) #ifdef __CYGWIN__
# if !defined(PNG_STATIC) # ifndef PNG_STATIC
# if defined(PNG_USE_GLOBAL_ARRAYS) # ifdef PNG_USE_GLOBAL_ARRAYS
# undef PNG_USE_GLOBAL_ARRAYS # undef PNG_USE_GLOBAL_ARRAYS
# endif # endif
# if !defined(PNG_USE_LOCAL_ARRAYS) # ifndef PNG_USE_LOCAL_ARRAYS
# define PNG_USE_LOCAL_ARRAYS # define PNG_USE_LOCAL_ARRAYS
# endif # endif
# else # else
# if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS) # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
# if defined(PNG_USE_GLOBAL_ARRAYS) # ifdef PNG_USE_GLOBAL_ARRAYS
# undef PNG_USE_GLOBAL_ARRAYS # undef PNG_USE_GLOBAL_ARRAYS
# endif # endif
# endif # endif
@ -1328,7 +1412,7 @@ typedef z_stream FAR * png_zstreamp;
# endif # endif
#endif #endif
#if defined(__CYGWIN__) #ifdef __CYGWIN__
# undef PNGAPI # undef PNGAPI
# define PNGAPI __cdecl # define PNGAPI __cdecl
# undef PNG_IMPEXP # undef PNG_IMPEXP
@ -1369,7 +1453,7 @@ typedef z_stream FAR * png_zstreamp;
# define PNG_IMPEXP # define PNG_IMPEXP
# endif # endif
# if !defined(PNG_IMPEXP) # ifndef PNG_IMPEXP
# define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
# define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
@ -1380,7 +1464,7 @@ typedef z_stream FAR * png_zstreamp;
# define PNG_EXPORT PNG_EXPORT_TYPE1 # define PNG_EXPORT PNG_EXPORT_TYPE1
# else # else
# define PNG_EXPORT PNG_EXPORT_TYPE2 # define PNG_EXPORT PNG_EXPORT_TYPE2
# if defined(PNG_BUILD_DLL) # ifdef PNG_BUILD_DLL
# define PNG_IMPEXP __export # define PNG_IMPEXP __export
# else # else
# define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
@ -1390,8 +1474,8 @@ typedef z_stream FAR * png_zstreamp;
# endif # endif
# endif # endif
# if !defined(PNG_IMPEXP) # ifndef PNG_IMPEXP
# if defined(PNG_BUILD_DLL) # ifdef PNG_BUILD_DLL
# define PNG_IMPEXP __declspec(dllexport) # define PNG_IMPEXP __declspec(dllexport)
# else # else
# define PNG_IMPEXP __declspec(dllimport) # define PNG_IMPEXP __declspec(dllimport)
@ -1437,6 +1521,70 @@ typedef z_stream FAR * png_zstreamp;
# endif # endif
#endif #endif
#ifdef PNG_PEDANTIC_WARNINGS
# ifndef PNG_PEDANTIC_WARNINGS_SUPPORTED
# define PNG_PEDANTIC_WARNINGS_SUPPORTED
# endif
#endif
#ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED
/* Support for compiler specific function attributes. These are used
* so that where compiler support is available incorrect use of API
* functions in png.h will generate compiler warnings. Added at libpng
* version 1.2.41.
*/
# ifdef __GNUC__
# ifndef PNG_USE_RESULT
# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
# endif
# ifndef PNG_NORETURN
# define PNG_NORETURN __attribute__((__noreturn__))
# endif
# ifndef PNG_ALLOCATED
# define PNG_ALLOCATED __attribute__((__malloc__))
# endif
/* This specifically protects structure members that should only be
* accessed from within the library, therefore should be empty during
* a library build.
*/
# ifndef PNG_DEPRECATED
# define PNG_DEPRECATED __attribute__((__deprecated__))
# endif
# ifndef PNG_DEPSTRUCT
# define PNG_DEPSTRUCT __attribute__((__deprecated__))
# endif
# ifndef PNG_PRIVATE
# if 0 /* Doesn't work so we use deprecated instead*/
# define PNG_PRIVATE \
__attribute__((warning("This function is not exported by libpng.")))
# else
# define PNG_PRIVATE \
__attribute__((__deprecated__))
# endif
# endif /* PNG_PRIVATE */
# endif /* __GNUC__ */
#endif /* PNG_PEDANTIC_WARNINGS */
#ifndef PNG_DEPRECATED
# define PNG_DEPRECATED /* Use of this function is deprecated */
#endif
#ifndef PNG_USE_RESULT
# define PNG_USE_RESULT /* The result of this function must be checked */
#endif
#ifndef PNG_NORETURN
# define PNG_NORETURN /* This function does not return */
#endif
#ifndef PNG_ALLOCATED
# define PNG_ALLOCATED /* The result of the function is new memory */
#endif
#ifndef PNG_DEPSTRUCT
# define PNG_DEPSTRUCT /* Access to this struct member is deprecated */
#endif
#ifndef PNG_PRIVATE
# define PNG_PRIVATE /* This is a private libpng function */
#endif
/* User may want to use these so they are not in PNG_INTERNAL. Any library /* User may want to use these so they are not in PNG_INTERNAL. Any library
* functions that are passed far data must be model independent. * functions that are passed far data must be model independent.
*/ */
@ -1452,8 +1600,8 @@ typedef z_stream FAR * png_zstreamp;
(LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED) (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
#endif #endif
#if defined(USE_FAR_KEYWORD) /* memory model independent fns */ #ifdef USE_FAR_KEYWORD /* memory model independent fns */
/* use this to make far-to-near assignments */ /* Use this to make far-to-near assignments */
# define CHECK 1 # define CHECK 1
# define NOCHECK 0 # define NOCHECK 0
# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
@ -1463,7 +1611,7 @@ typedef z_stream FAR * png_zstreamp;
# define png_memcmp _fmemcmp /* SJT: added */ # define png_memcmp _fmemcmp /* SJT: added */
# define png_memcpy _fmemcpy # define png_memcpy _fmemcpy
# define png_memset _fmemset # define png_memset _fmemset
#else /* use the usual functions */ #else /* Use the usual functions */
# define CVT_PTR(ptr) (ptr) # define CVT_PTR(ptr) (ptr)
# define CVT_PTR_NOCHECK(ptr) (ptr) # define CVT_PTR_NOCHECK(ptr) (ptr)
# ifndef PNG_NO_SNPRINTF # ifndef PNG_NO_SNPRINTF
@ -1481,7 +1629,8 @@ typedef z_stream FAR * png_zstreamp;
* sprintf instead of snprintf exposes your application to accidental * sprintf instead of snprintf exposes your application to accidental
* or malevolent buffer overflows. If you don't have snprintf() * or malevolent buffer overflows. If you don't have snprintf()
* as a general rule you should provide one (you can get one from * as a general rule you should provide one (you can get one from
* Portable OpenSSH). */ * Portable OpenSSH).
*/
# define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1) # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
# define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2) # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
# define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \ # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \

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.2.37 [June 4, 2009] * Last changed in libpng 1.2.41 [December 3, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 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.)
@ -17,24 +17,25 @@
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
static void /* PRIVATE */ static void /* PRIVATE */
png_default_error PNGARG((png_structp png_ptr, png_default_error PNGARG((png_structp png_ptr,
png_const_charp error_message)); png_const_charp error_message)) PNG_NORETURN;
#ifndef PNG_NO_WARNINGS #ifdef PNG_WARNINGS_SUPPORTED
static void /* PRIVATE */ static void /* PRIVATE */
png_default_warning PNGARG((png_structp png_ptr, png_default_warning PNGARG((png_structp png_ptr,
png_const_charp warning_message)); png_const_charp warning_message));
#endif /* PNG_NO_WARNINGS */ #endif /* PNG_WARNINGS_SUPPORTED */
/* This function is called whenever there is a fatal error. This function /* This function is called whenever there is a fatal error. This function
* should not be changed. If there is a need to handle errors differently, * should not be changed. If there is a need to handle errors differently,
* you should supply a replacement error function and use png_set_error_fn() * you should supply a replacement error function and use png_set_error_fn()
* to replace the error function at run-time. * to replace the error function at run-time.
*/ */
#ifndef PNG_NO_ERROR_TEXT #ifdef PNG_ERROR_TEXT_SUPPORTED
void PNGAPI void PNGAPI
png_error(png_structp png_ptr, png_const_charp error_message) png_error(png_structp png_ptr, png_const_charp error_message)
{ {
@ -45,7 +46,7 @@ png_error(png_structp png_ptr, png_const_charp error_message)
if (png_ptr->flags& if (png_ptr->flags&
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
{ {
if (*error_message == '#') if (*error_message == PNG_LITERAL_SHARP)
{ {
/* Strip "#nnnn " from beginning of error message. */ /* Strip "#nnnn " from beginning of error message. */
int offset; int offset;
@ -93,9 +94,9 @@ png_err(png_structp png_ptr)
use the default handler, which will not return. */ use the default handler, which will not return. */
png_default_error(png_ptr, '\0'); png_default_error(png_ptr, '\0');
} }
#endif /* PNG_NO_ERROR_TEXT */ #endif /* PNG_ERROR_TEXT_SUPPORTED */
#ifndef PNG_NO_WARNINGS #ifdef PNG_WARNINGS_SUPPORTED
/* This function is called whenever there is a non-fatal error. This function /* This function is called whenever there is a non-fatal error. This function
* should not be changed. If there is a need to handle warnings differently, * should not be changed. If there is a need to handle warnings differently,
* you should supply a replacement warning function and use * you should supply a replacement warning function and use
@ -112,7 +113,7 @@ png_warning(png_structp png_ptr, png_const_charp warning_message)
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
#endif #endif
{ {
if (*warning_message == '#') if (*warning_message == PNG_LITERAL_SHARP)
{ {
for (offset = 1; offset < 15; offset++) for (offset = 1; offset < 15; offset++)
if (warning_message[offset] == ' ') if (warning_message[offset] == ' ')
@ -125,8 +126,18 @@ png_warning(png_structp png_ptr, png_const_charp warning_message)
else else
png_default_warning(png_ptr, warning_message + offset); png_default_warning(png_ptr, warning_message + offset);
} }
#endif /* PNG_NO_WARNINGS */ #endif /* PNG_WARNINGS_SUPPORTED */
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
void PNGAPI
png_benign_error(png_structp png_ptr, png_const_charp error_message)
{
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
png_warning(png_ptr, error_message);
else
png_error(png_ptr, error_message);
}
#endif
/* These utilities are used internally to build an error message that relates /* These utilities are used internally to build an error message that relates
* to the current chunk. The chunk name comes from png_ptr->chunk_name, * to the current chunk. The chunk name comes from png_ptr->chunk_name,
@ -141,8 +152,7 @@ static PNG_CONST char png_digit[16] = {
}; };
#define PNG_MAX_ERROR_TEXT 64 #define PNG_MAX_ERROR_TEXT 64
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
#if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
static void /* PRIVATE */ static void /* PRIVATE */
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
error_message) error_message)
@ -154,10 +164,10 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
int c = png_ptr->chunk_name[iin++]; int c = png_ptr->chunk_name[iin++];
if (isnonalpha(c)) if (isnonalpha(c))
{ {
buffer[iout++] = '['; buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
buffer[iout++] = png_digit[(c & 0xf0) >> 4]; buffer[iout++] = png_digit[(c & 0xf0) >> 4];
buffer[iout++] = png_digit[c & 0x0f]; buffer[iout++] = png_digit[c & 0x0f];
buffer[iout++] = ']'; buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET;
} }
else else
{ {
@ -190,9 +200,9 @@ png_chunk_error(png_structp png_ptr, png_const_charp error_message)
} }
} }
#endif /* PNG_READ_SUPPORTED */ #endif /* PNG_READ_SUPPORTED */
#endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */ #endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */
#ifndef PNG_NO_WARNINGS #ifdef PNG_WARNINGS_SUPPORTED
void PNGAPI void PNGAPI
png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
{ {
@ -205,8 +215,20 @@ png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
png_warning(png_ptr, msg); png_warning(png_ptr, msg);
} }
} }
#endif /* PNG_NO_WARNINGS */ #endif /* PNG_WARNINGS_SUPPORTED */
#ifdef PNG_READ_SUPPORTED
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
void PNGAPI
png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message)
{
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
png_chunk_warning(png_ptr, error_message);
else
png_chunk_error(png_ptr, error_message);
}
#endif
#endif /* PNG_READ_SUPPORTED */
/* This is the default error handling function. Note that replacements for /* This is the default error handling function. Note that replacements for
* this function MUST NOT RETURN, or the program will likely crash. This * this function MUST NOT RETURN, or the program will likely crash. This
@ -216,9 +238,9 @@ png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
static void /* PRIVATE */ static void /* PRIVATE */
png_default_error(png_structp png_ptr, png_const_charp error_message) png_default_error(png_structp png_ptr, png_const_charp error_message)
{ {
#ifndef PNG_NO_CONSOLE_IO #ifdef PNG_CONSOLE_IO_SUPPORTED
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (*error_message == '#') if (*error_message == PNG_LITERAL_SHARP)
{ {
/* Strip "#nnnn " from beginning of error message. */ /* Strip "#nnnn " from beginning of error message. */
int offset; int offset;
@ -258,21 +280,21 @@ png_default_error(png_structp png_ptr, png_const_charp error_message)
{ {
jmp_buf jmpbuf; jmp_buf jmpbuf;
png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf)); png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
longjmp(jmpbuf, 1); longjmp(jmpbuf,1);
} }
# else # else
longjmp(png_ptr->jmpbuf, 1); longjmp(png_ptr->jmpbuf, 1);
# endif # endif
} }
#else
PNG_ABORT();
#endif #endif
#ifdef PNG_NO_CONSOLE_IO /* Here if not setjmp support or if png_ptr is null. */
PNG_ABORT();
#ifndef PNG_CONSOLE_IO_SUPPORTED
error_message = error_message; /* Make compiler happy */ error_message = error_message; /* Make compiler happy */
#endif #endif
} }
#ifndef PNG_NO_WARNINGS #ifdef PNG_WARNINGS_SUPPORTED
/* This function is called when there is a warning, but the library thinks /* This function is called when there is a warning, but the library thinks
* it can continue anyway. Replacement functions don't have to do anything * it can continue anyway. Replacement functions don't have to do anything
* here if you don't want them to. In the default configuration, png_ptr is * here if you don't want them to. In the default configuration, png_ptr is
@ -281,9 +303,9 @@ png_default_error(png_structp png_ptr, png_const_charp error_message)
static void /* PRIVATE */ static void /* PRIVATE */
png_default_warning(png_structp png_ptr, png_const_charp warning_message) png_default_warning(png_structp png_ptr, png_const_charp warning_message)
{ {
#ifndef PNG_NO_CONSOLE_IO #ifdef PNG_CONSOLE_IO_SUPPORTED
# ifdef PNG_ERROR_NUMBERS_SUPPORTED # ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (*warning_message == '#') if (*warning_message == PNG_LITERAL_SHARP)
{ {
int offset; int offset;
char warning_number[16]; char warning_number[16];
@ -318,7 +340,7 @@ png_default_warning(png_structp png_ptr, png_const_charp warning_message)
#endif #endif
png_ptr = png_ptr; /* Make compiler happy */ png_ptr = png_ptr; /* Make compiler happy */
} }
#endif /* PNG_NO_WARNINGS */ #endif /* PNG_WARNINGS_SUPPORTED */
/* This function is called when the application wants to use another method /* This function is called when the application wants to use another method
* of handling errors and warnings. Note that the error function MUST NOT * of handling errors and warnings. Note that the error function MUST NOT

View file

@ -17,9 +17,9 @@ int PNGAPI
png_dummy_mmx_support(void) png_dummy_mmx_support(void)
{ {
int result; int result;
#if defined(PNG_MMX_CODE_SUPPORTED) // superfluous, but what the heck #ifdef PNG_MMX_CODE_SUPPORTED // superfluous, but what the heck
__asm__ __volatile__ ( __asm__ __volatile__ (
#if defined(__x86_64__) #ifdef __x86_64__
"pushq %%rbx \n\t" // rbx gets clobbered by CPUID instruction "pushq %%rbx \n\t" // rbx gets clobbered by CPUID instruction
"pushq %%rcx \n\t" // so does rcx... "pushq %%rcx \n\t" // so does rcx...
"pushq %%rdx \n\t" // ...and rdx (but rcx & rdx safe on Linux) "pushq %%rdx \n\t" // ...and rdx (but rcx & rdx safe on Linux)
@ -71,7 +71,7 @@ png_dummy_mmx_support(void)
"0: \n\t" // .NOT_SUPPORTED: target label for jump instructions "0: \n\t" // .NOT_SUPPORTED: target label for jump instructions
"movl $0, %%eax \n\t" // set return value to 0 "movl $0, %%eax \n\t" // set return value to 0
"1: \n\t" // .RETURN: target label for jump instructions "1: \n\t" // .RETURN: target label for jump instructions
#if defined(__x86_64__) #ifdef __x86_64__
"popq %%rdx \n\t" // restore rdx "popq %%rdx \n\t" // restore rdx
"popq %%rcx \n\t" // restore rcx "popq %%rcx \n\t" // restore rcx
"popq %%rbx \n\t" // restore rbx "popq %%rbx \n\t" // restore rbx

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.2.37 [June 4, 2009] * Last changed in libpng 1.2.41 [December 3, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 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.)
@ -13,6 +13,7 @@
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
@ -36,7 +37,7 @@ png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
return(0); return(0);
} }
#if defined(PNG_INFO_IMAGE_SUPPORTED) #ifdef PNG_INFO_IMAGE_SUPPORTED
png_bytepp PNGAPI png_bytepp PNGAPI
png_get_rows(png_structp png_ptr, png_infop info_ptr) png_get_rows(png_structp png_ptr, png_infop info_ptr)
{ {
@ -117,7 +118,7 @@ png_uint_32 PNGAPI
png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_pHYs_SUPPORTED) #ifdef PNG_pHYs_SUPPORTED
if (info_ptr->valid & PNG_INFO_pHYs) if (info_ptr->valid & PNG_INFO_pHYs)
{ {
png_debug1(1, "in %s retrieval function", "png_get_x_pixels_per_meter"); png_debug1(1, "in %s retrieval function", "png_get_x_pixels_per_meter");
@ -138,7 +139,7 @@ png_uint_32 PNGAPI
png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_pHYs_SUPPORTED) #ifdef PNG_pHYs_SUPPORTED
if (info_ptr->valid & PNG_INFO_pHYs) if (info_ptr->valid & PNG_INFO_pHYs)
{ {
png_debug1(1, "in %s retrieval function", "png_get_y_pixels_per_meter"); png_debug1(1, "in %s retrieval function", "png_get_y_pixels_per_meter");
@ -159,7 +160,7 @@ png_uint_32 PNGAPI
png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_pHYs_SUPPORTED) #ifdef PNG_pHYs_SUPPORTED
if (info_ptr->valid & PNG_INFO_pHYs) if (info_ptr->valid & PNG_INFO_pHYs)
{ {
png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter"); png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
@ -182,13 +183,15 @@ float PNGAPI
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_pHYs_SUPPORTED) #ifdef PNG_pHYs_SUPPORTED
if (info_ptr->valid & PNG_INFO_pHYs) if (info_ptr->valid & PNG_INFO_pHYs)
{ {
png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio"); png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
if (info_ptr->x_pixels_per_unit == 0) if (info_ptr->x_pixels_per_unit == 0)
return ((float)0.0); return ((float)0.0);
else else
return ((float)((float)info_ptr->y_pixels_per_unit return ((float)((float)info_ptr->y_pixels_per_unit
/(float)info_ptr->x_pixels_per_unit)); /(float)info_ptr->x_pixels_per_unit));
@ -204,7 +207,7 @@ png_int_32 PNGAPI
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_oFFs_SUPPORTED) #ifdef PNG_oFFs_SUPPORTED
if (info_ptr->valid & PNG_INFO_oFFs) if (info_ptr->valid & PNG_INFO_oFFs)
{ {
@ -227,7 +230,7 @@ png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_oFFs_SUPPORTED) #ifdef PNG_oFFs_SUPPORTED
if (info_ptr->valid & PNG_INFO_oFFs) if (info_ptr->valid & PNG_INFO_oFFs)
{ {
png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
@ -249,7 +252,7 @@ png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_oFFs_SUPPORTED) #ifdef PNG_oFFs_SUPPORTED
if (info_ptr->valid & PNG_INFO_oFFs) if (info_ptr->valid & PNG_INFO_oFFs)
{ {
png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
@ -271,7 +274,7 @@ png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_oFFs_SUPPORTED) #ifdef PNG_oFFs_SUPPORTED
if (info_ptr->valid & PNG_INFO_oFFs) if (info_ptr->valid & PNG_INFO_oFFs)
{ {
png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
@ -324,7 +327,7 @@ png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
*.00003937); *.00003937);
} }
#if defined(PNG_pHYs_SUPPORTED) #ifdef PNG_pHYs_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
@ -334,6 +337,7 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
{ {
png_debug1(1, "in %s retrieval function", "pHYs"); png_debug1(1, "in %s retrieval function", "pHYs");
if (res_x != NULL) if (res_x != NULL)
{ {
*res_x = info_ptr->x_pixels_per_unit; *res_x = info_ptr->x_pixels_per_unit;
@ -382,7 +386,7 @@ png_get_signature(png_structp png_ptr, png_infop info_ptr)
return (NULL); return (NULL);
} }
#if defined(PNG_bKGD_SUPPORTED) #ifdef PNG_bKGD_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_bKGD(png_structp png_ptr, png_infop info_ptr, png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
png_color_16p *background) png_color_16p *background)
@ -391,6 +395,7 @@ png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
&& background != NULL) && background != NULL)
{ {
png_debug1(1, "in %s retrieval function", "bKGD"); png_debug1(1, "in %s retrieval function", "bKGD");
*background = &(info_ptr->background); *background = &(info_ptr->background);
return (PNG_INFO_bKGD); return (PNG_INFO_bKGD);
} }
@ -398,7 +403,7 @@ png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_cHRM_SUPPORTED) #ifdef PNG_cHRM_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_cHRM(png_structp png_ptr, png_infop info_ptr, png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
@ -408,6 +413,7 @@ png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
{ {
png_debug1(1, "in %s retrieval function", "cHRM"); png_debug1(1, "in %s retrieval function", "cHRM");
if (white_x != NULL) if (white_x != NULL)
*white_x = (double)info_ptr->x_white; *white_x = (double)info_ptr->x_white;
if (white_y != NULL) if (white_y != NULL)
@ -436,9 +442,10 @@ png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
png_fixed_point *blue_x, png_fixed_point *blue_y) png_fixed_point *blue_x, png_fixed_point *blue_y)
{ {
png_debug1(1, "in %s retrieval function", "cHRM");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
{ {
png_debug1(1, "in %s retrieval function", "cHRM");
if (white_x != NULL) if (white_x != NULL)
*white_x = info_ptr->int_x_white; *white_x = info_ptr->int_x_white;
if (white_y != NULL) if (white_y != NULL)
@ -462,15 +469,16 @@ png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
#endif #endif
#endif #endif
#if defined(PNG_gAMA_SUPPORTED) #ifdef PNG_gAMA_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
{ {
png_debug1(1, "in %s retrieval function", "gAMA");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
&& file_gamma != NULL) && file_gamma != NULL)
{ {
png_debug1(1, "in %s retrieval function", "gAMA");
*file_gamma = (double)info_ptr->gamma; *file_gamma = (double)info_ptr->gamma;
return (PNG_INFO_gAMA); return (PNG_INFO_gAMA);
} }
@ -482,10 +490,11 @@ png_uint_32 PNGAPI
png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
png_fixed_point *int_file_gamma) png_fixed_point *int_file_gamma)
{ {
png_debug1(1, "in %s retrieval function", "gAMA");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
&& int_file_gamma != NULL) && int_file_gamma != NULL)
{ {
png_debug1(1, "in %s retrieval function", "gAMA");
*int_file_gamma = info_ptr->int_gamma; *int_file_gamma = info_ptr->int_gamma;
return (PNG_INFO_gAMA); return (PNG_INFO_gAMA);
} }
@ -494,14 +503,15 @@ png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
#endif #endif
#endif #endif
#if defined(PNG_sRGB_SUPPORTED) #ifdef PNG_sRGB_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
{ {
png_debug1(1, "in %s retrieval function", "sRGB");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
&& file_srgb_intent != NULL) && file_srgb_intent != NULL)
{ {
png_debug1(1, "in %s retrieval function", "sRGB");
*file_srgb_intent = (int)info_ptr->srgb_intent; *file_srgb_intent = (int)info_ptr->srgb_intent;
return (PNG_INFO_sRGB); return (PNG_INFO_sRGB);
} }
@ -509,16 +519,17 @@ png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
} }
#endif #endif
#if defined(PNG_iCCP_SUPPORTED) #ifdef PNG_iCCP_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_iCCP(png_structp png_ptr, png_infop info_ptr, png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
png_charpp name, int *compression_type, png_charpp name, int *compression_type,
png_charpp profile, png_uint_32 *proflen) png_charpp profile, png_uint_32 *proflen)
{ {
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 && profile != NULL && proflen != NULL)
{ {
png_debug1(1, "in %s retrieval function", "iCCP");
*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
@ -532,7 +543,7 @@ png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_sPLT_SUPPORTED) #ifdef PNG_sPLT_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_sPLT(png_structp png_ptr, png_infop info_ptr, png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
png_sPLT_tpp spalettes) png_sPLT_tpp spalettes)
@ -546,14 +557,15 @@ png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_hIST_SUPPORTED) #ifdef PNG_hIST_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
{ {
png_debug1(1, "in %s retrieval function", "hIST");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
&& hist != NULL) && hist != NULL)
{ {
png_debug1(1, "in %s retrieval function", "hIST");
*hist = info_ptr->hist; *hist = info_ptr->hist;
return (PNG_INFO_hIST); return (PNG_INFO_hIST);
} }
@ -568,21 +580,17 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
int *filter_type) int *filter_type)
{ {
if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
bit_depth != NULL && color_type != NULL)
{
png_debug1(1, "in %s retrieval function", "IHDR"); png_debug1(1, "in %s retrieval function", "IHDR");
if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
height == NULL || bit_depth == NULL || color_type == NULL)
return (0);
*width = info_ptr->width; *width = info_ptr->width;
*height = info_ptr->height; *height = info_ptr->height;
*bit_depth = info_ptr->bit_depth; *bit_depth = info_ptr->bit_depth;
if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
png_error(png_ptr, "Invalid bit depth");
*color_type = info_ptr->color_type; *color_type = info_ptr->color_type;
if (info_ptr->color_type > 6)
png_error(png_ptr, "Invalid color type");
if (compression_type != NULL) if (compression_type != NULL)
*compression_type = info_ptr->compression_type; *compression_type = info_ptr->compression_type;
@ -592,38 +600,28 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
if (interlace_type != NULL) if (interlace_type != NULL)
*interlace_type = info_ptr->interlace_type; *interlace_type = info_ptr->interlace_type;
/* Check for potential overflow of rowbytes */ /* This is redundant if we can be sure that the info_ptr values were all
if (*width == 0 || *width > PNG_UINT_31_MAX) * assigned in png_set_IHDR(). We do the check anyhow in case an
png_error(png_ptr, "Invalid image width"); * application has ignored our advice not to mess with the members
* of info_ptr directly.
if (*height == 0 || *height > PNG_UINT_31_MAX) */
png_error(png_ptr, "Invalid image height"); png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
if (info_ptr->width > (PNG_UINT_32_MAX info_ptr->compression_type, info_ptr->filter_type);
>> 3) /* 8-byte RGBA pixels */
- 64 /* bigrowbuf hack */
- 1 /* filter byte */
- 7*8 /* rounding of width to multiple of 8 pixels */
- 8) /* extra max_pixel_depth pad */
{
png_warning(png_ptr,
"Width too large for libpng to process image data.");
}
return (1); return (1);
}
return (0);
} }
#if defined(PNG_oFFs_SUPPORTED) #ifdef PNG_oFFs_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_oFFs(png_structp png_ptr, png_infop info_ptr, png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
{ {
png_debug1(1, "in %s retrieval function", "oFFs");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
&& offset_x != NULL && offset_y != NULL && unit_type != NULL) && offset_x != NULL && offset_y != NULL && unit_type != NULL)
{ {
png_debug1(1, "in %s retrieval function", "oFFs");
*offset_x = info_ptr->x_offset; *offset_x = info_ptr->x_offset;
*offset_y = info_ptr->y_offset; *offset_y = info_ptr->y_offset;
*unit_type = (int)info_ptr->offset_unit_type; *unit_type = (int)info_ptr->offset_unit_type;
@ -633,17 +631,18 @@ png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_pCAL_SUPPORTED) #ifdef PNG_pCAL_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_pCAL(png_structp png_ptr, png_infop info_ptr, png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
png_charp *units, png_charpp *params) png_charp *units, png_charpp *params)
{ {
png_debug1(1, "in %s retrieval function", "pCAL");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
&& purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
nparams != NULL && units != NULL && params != NULL) nparams != NULL && units != NULL && params != NULL)
{ {
png_debug1(1, "in %s retrieval function", "pCAL");
*purpose = info_ptr->pcal_purpose; *purpose = info_ptr->pcal_purpose;
*X0 = info_ptr->pcal_X0; *X0 = info_ptr->pcal_X0;
*X1 = info_ptr->pcal_X1; *X1 = info_ptr->pcal_X1;
@ -657,7 +656,7 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_sCAL_SUPPORTED) #ifdef PNG_sCAL_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_sCAL(png_structp png_ptr, png_infop info_ptr, png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
@ -693,18 +692,18 @@ png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
#endif #endif
#endif #endif
#if defined(PNG_pHYs_SUPPORTED) #ifdef PNG_pHYs_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_pHYs(png_structp png_ptr, png_infop info_ptr, png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{ {
png_uint_32 retval = 0; png_uint_32 retval = 0;
png_debug1(1, "in %s retrieval function", "pHYs");
if (png_ptr != NULL && info_ptr != NULL && if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_pHYs)) (info_ptr->valid & PNG_INFO_pHYs))
{ {
png_debug1(1, "in %s retrieval function", "pHYs");
if (res_x != NULL) if (res_x != NULL)
{ {
*res_x = info_ptr->x_pixels_per_unit; *res_x = info_ptr->x_pixels_per_unit;
@ -731,10 +730,11 @@ png_uint_32 PNGAPI
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
int *num_palette) int *num_palette)
{ {
png_debug1(1, "in %s retrieval function", "PLTE");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
&& palette != NULL) && palette != NULL)
{ {
png_debug1(1, "in %s retrieval function", "PLTE");
*palette = info_ptr->palette; *palette = info_ptr->palette;
*num_palette = info_ptr->num_palette; *num_palette = info_ptr->num_palette;
png_debug1(3, "num_palette = %d", *num_palette); png_debug1(3, "num_palette = %d", *num_palette);
@ -743,14 +743,15 @@ png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
return (0); return (0);
} }
#if defined(PNG_sBIT_SUPPORTED) #ifdef PNG_sBIT_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
{ {
png_debug1(1, "in %s retrieval function", "sBIT");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
&& sig_bit != NULL) && sig_bit != NULL)
{ {
png_debug1(1, "in %s retrieval function", "sBIT");
*sig_bit = &(info_ptr->sig_bit); *sig_bit = &(info_ptr->sig_bit);
return (PNG_INFO_sBIT); return (PNG_INFO_sBIT);
} }
@ -758,7 +759,7 @@ png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
} }
#endif #endif
#if defined(PNG_TEXT_SUPPORTED) #ifdef PNG_TEXT_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
int *num_text) int *num_text)
@ -783,14 +784,15 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
} }
#endif #endif
#if defined(PNG_tIME_SUPPORTED) #ifdef PNG_tIME_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
{ {
png_debug1(1, "in %s retrieval function", "tIME");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
&& mod_time != NULL) && mod_time != NULL)
{ {
png_debug1(1, "in %s retrieval function", "tIME");
*mod_time = &(info_ptr->mod_time); *mod_time = &(info_ptr->mod_time);
return (PNG_INFO_tIME); return (PNG_INFO_tIME);
} }
@ -798,7 +800,7 @@ png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
} }
#endif #endif
#if defined(PNG_tRNS_SUPPORTED) #ifdef PNG_tRNS_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_tRNS(png_structp png_ptr, png_infop info_ptr, png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
png_bytep *trans, int *num_trans, png_color_16p *trans_values) png_bytep *trans, int *num_trans, png_color_16p *trans_values)
@ -807,6 +809,7 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
{ {
png_debug1(1, "in %s retrieval function", "tRNS"); png_debug1(1, "in %s retrieval function", "tRNS");
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{ {
if (trans != NULL) if (trans != NULL)
@ -839,7 +842,7 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
png_unknown_chunkpp unknowns) png_unknown_chunkpp unknowns)
@ -853,7 +856,7 @@ png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
png_byte PNGAPI png_byte PNGAPI
png_get_rgb_to_gray_status (png_structp png_ptr) png_get_rgb_to_gray_status (png_structp png_ptr)
{ {
@ -861,7 +864,7 @@ png_get_rgb_to_gray_status (png_structp png_ptr)
} }
#endif #endif
#if defined(PNG_USER_CHUNKS_SUPPORTED) #ifdef PNG_USER_CHUNKS_SUPPORTED
png_voidp PNGAPI png_voidp PNGAPI
png_get_user_chunk_ptr(png_structp png_ptr) png_get_user_chunk_ptr(png_structp png_ptr)
{ {
@ -939,5 +942,4 @@ png_get_user_height_max (png_structp png_ptr)
} }
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */

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.2.37 [June 4, 2009] * Last changed in libpng 1.2.41 [December 3, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 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.)
@ -18,6 +18,7 @@
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
@ -114,6 +115,16 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
* result, we would be truncating potentially larger memory requests * result, we would be truncating potentially larger memory requests
* (which should cause a fatal error) and introducing major problems. * (which should cause a fatal error) and introducing major problems.
*/ */
png_voidp PNGAPI
png_calloc(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
ret = (png_malloc(png_ptr, size));
if (ret != NULL)
png_memset(ret,0,(png_size_t)size);
return (ret);
}
png_voidp PNGAPI png_voidp PNGAPI
png_malloc(png_structp png_ptr, png_uint_32 size) png_malloc(png_structp png_ptr, png_uint_32 size)
@ -431,6 +442,16 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
* have the ability to do that. * have the ability to do that.
*/ */
png_voidp PNGAPI
png_calloc(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
ret = (png_malloc(png_ptr, size));
if (ret != NULL)
png_memset(ret,0,(png_size_t)size);
return (ret);
}
png_voidp PNGAPI png_voidp PNGAPI
png_malloc(png_structp png_ptr, png_uint_32 size) png_malloc(png_structp png_ptr, png_uint_32 size)
@ -538,7 +559,7 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
#endif /* Not Borland DOS special memory handler */ #endif /* Not Borland DOS special memory handler */
#if defined(PNG_1_0_X) #ifdef PNG_1_0_X
# define png_malloc_warn png_malloc # define png_malloc_warn png_malloc
#else #else
/* This function was added at libpng version 1.2.3. The png_malloc_warn() /* This function was added at libpng version 1.2.3. The png_malloc_warn()

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.2.38 [July 16, 2009] * Last changed in libpng 1.2.42 [January 3, 2010]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -12,6 +12,7 @@
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
@ -70,7 +71,7 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr)
break; break;
} }
#if defined(PNG_READ_tEXt_SUPPORTED) #ifdef PNG_READ_tEXt_SUPPORTED
case PNG_READ_tEXt_MODE: case PNG_READ_tEXt_MODE:
{ {
png_push_read_tEXt(png_ptr, info_ptr); png_push_read_tEXt(png_ptr, info_ptr);
@ -78,7 +79,7 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_zTXt_SUPPORTED) #ifdef PNG_READ_zTXt_SUPPORTED
case PNG_READ_zTXt_MODE: case PNG_READ_zTXt_MODE:
{ {
png_push_read_zTXt(png_ptr, info_ptr); png_push_read_zTXt(png_ptr, info_ptr);
@ -86,7 +87,7 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_iTXt_SUPPORTED) #ifdef PNG_READ_iTXt_SUPPORTED
case PNG_READ_iTXt_MODE: case PNG_READ_iTXt_MODE:
{ {
png_push_read_iTXt(png_ptr, info_ptr); png_push_read_iTXt(png_ptr, info_ptr);
@ -154,58 +155,59 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
PNG_CONST PNG_IDAT; PNG_CONST PNG_IDAT;
PNG_CONST PNG_IEND; PNG_CONST PNG_IEND;
PNG_CONST PNG_PLTE; PNG_CONST PNG_PLTE;
#if defined(PNG_READ_bKGD_SUPPORTED) #ifdef PNG_READ_bKGD_SUPPORTED
PNG_CONST PNG_bKGD; PNG_CONST PNG_bKGD;
#endif #endif
#if defined(PNG_READ_cHRM_SUPPORTED) #ifdef PNG_READ_cHRM_SUPPORTED
PNG_CONST PNG_cHRM; PNG_CONST PNG_cHRM;
#endif #endif
#if defined(PNG_READ_gAMA_SUPPORTED) #ifdef PNG_READ_gAMA_SUPPORTED
PNG_CONST PNG_gAMA; PNG_CONST PNG_gAMA;
#endif #endif
#if defined(PNG_READ_hIST_SUPPORTED) #ifdef PNG_READ_hIST_SUPPORTED
PNG_CONST PNG_hIST; PNG_CONST PNG_hIST;
#endif #endif
#if defined(PNG_READ_iCCP_SUPPORTED) #ifdef PNG_READ_iCCP_SUPPORTED
PNG_CONST PNG_iCCP; PNG_CONST PNG_iCCP;
#endif #endif
#if defined(PNG_READ_iTXt_SUPPORTED) #ifdef PNG_READ_iTXt_SUPPORTED
PNG_CONST PNG_iTXt; PNG_CONST PNG_iTXt;
#endif #endif
#if defined(PNG_READ_oFFs_SUPPORTED) #ifdef PNG_READ_oFFs_SUPPORTED
PNG_CONST PNG_oFFs; PNG_CONST PNG_oFFs;
#endif #endif
#if defined(PNG_READ_pCAL_SUPPORTED) #ifdef PNG_READ_pCAL_SUPPORTED
PNG_CONST PNG_pCAL; PNG_CONST PNG_pCAL;
#endif #endif
#if defined(PNG_READ_pHYs_SUPPORTED) #ifdef PNG_READ_pHYs_SUPPORTED
PNG_CONST PNG_pHYs; PNG_CONST PNG_pHYs;
#endif #endif
#if defined(PNG_READ_sBIT_SUPPORTED) #ifdef PNG_READ_sBIT_SUPPORTED
PNG_CONST PNG_sBIT; PNG_CONST PNG_sBIT;
#endif #endif
#if defined(PNG_READ_sCAL_SUPPORTED) #ifdef PNG_READ_sCAL_SUPPORTED
PNG_CONST PNG_sCAL; PNG_CONST PNG_sCAL;
#endif #endif
#if defined(PNG_READ_sRGB_SUPPORTED) #ifdef PNG_READ_sRGB_SUPPORTED
PNG_CONST PNG_sRGB; PNG_CONST PNG_sRGB;
#endif #endif
#if defined(PNG_READ_sPLT_SUPPORTED) #ifdef PNG_READ_sPLT_SUPPORTED
PNG_CONST PNG_sPLT; PNG_CONST PNG_sPLT;
#endif #endif
#if defined(PNG_READ_tEXt_SUPPORTED) #ifdef PNG_READ_tEXt_SUPPORTED
PNG_CONST PNG_tEXt; PNG_CONST PNG_tEXt;
#endif #endif
#if defined(PNG_READ_tIME_SUPPORTED) #ifdef PNG_READ_tIME_SUPPORTED
PNG_CONST PNG_tIME; PNG_CONST PNG_tIME;
#endif #endif
#if defined(PNG_READ_tRNS_SUPPORTED) #ifdef PNG_READ_tRNS_SUPPORTED
PNG_CONST PNG_tRNS; PNG_CONST PNG_tRNS;
#endif #endif
#if defined(PNG_READ_zTXt_SUPPORTED) #ifdef PNG_READ_zTXt_SUPPORTED
PNG_CONST PNG_zTXt; PNG_CONST PNG_zTXt;
#endif #endif
#endif /* PNG_USE_LOCAL_ARRAYS */ #endif /* PNG_USE_LOCAL_ARRAYS */
/* First we make sure we have enough data for the 4 byte chunk name /* First we make sure we have enough data for the 4 byte chunk name
* and the 4 byte chunk length before proceeding with decoding the * and the 4 byte chunk length before proceeding with decoding the
* chunk data. To fully decode each of these chunks, we also make * chunk data. To fully decode each of these chunks, we also make
@ -334,7 +336,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
return; return;
} }
#if defined(PNG_READ_gAMA_SUPPORTED) #ifdef PNG_READ_gAMA_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -347,7 +349,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_sBIT_SUPPORTED) #ifdef PNG_READ_sBIT_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -360,7 +362,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_cHRM_SUPPORTED) #ifdef PNG_READ_cHRM_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -373,7 +375,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_sRGB_SUPPORTED) #ifdef PNG_READ_sRGB_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -386,7 +388,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_iCCP_SUPPORTED) #ifdef PNG_READ_iCCP_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -399,7 +401,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_sPLT_SUPPORTED) #ifdef PNG_READ_sPLT_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -412,7 +414,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_tRNS_SUPPORTED) #ifdef PNG_READ_tRNS_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -425,7 +427,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_bKGD_SUPPORTED) #ifdef PNG_READ_bKGD_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -438,7 +440,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_hIST_SUPPORTED) #ifdef PNG_READ_hIST_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -451,7 +453,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_pHYs_SUPPORTED) #ifdef PNG_READ_pHYs_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -464,7 +466,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_oFFs_SUPPORTED) #ifdef PNG_READ_oFFs_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -477,7 +479,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_pCAL_SUPPORTED) #ifdef PNG_READ_pCAL_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -490,7 +492,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_sCAL_SUPPORTED) #ifdef PNG_READ_sCAL_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -503,7 +505,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_tIME_SUPPORTED) #ifdef PNG_READ_tIME_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -516,7 +518,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_tEXt_SUPPORTED) #ifdef PNG_READ_tEXt_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -529,7 +531,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_zTXt_SUPPORTED) #ifdef PNG_READ_zTXt_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -542,7 +544,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_iTXt_SUPPORTED) #ifdef PNG_READ_iTXt_SUPPORTED
else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
{ {
if (png_ptr->push_length + 4 > png_ptr->buffer_size) if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -859,7 +861,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
if (!(png_ptr->zstream.avail_out)) if (!(png_ptr->zstream.avail_out))
{ {
if (( if ((
#if defined(PNG_READ_INTERLACING_SUPPORTED) #ifdef PNG_READ_INTERLACING_SUPPORTED
png_ptr->interlaced && png_ptr->pass > 6) || png_ptr->interlaced && png_ptr->pass > 6) ||
(!png_ptr->interlaced && (!png_ptr->interlaced &&
#endif #endif
@ -902,7 +904,7 @@ png_push_process_row(png_structp png_ptr)
if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
png_do_read_transformations(png_ptr); png_do_read_transformations(png_ptr);
#if defined(PNG_READ_INTERLACING_SUPPORTED) #ifdef PNG_READ_INTERLACING_SUPPORTED
/* Blow up interlaced rows to full size */ /* Blow up interlaced rows to full size */
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
{ {
@ -1114,7 +1116,7 @@ png_read_push_finish_row(png_structp png_ptr)
if (png_ptr->row_number < png_ptr->num_rows) if (png_ptr->row_number < png_ptr->num_rows)
return; return;
#if defined(PNG_READ_INTERLACING_SUPPORTED) #ifdef PNG_READ_INTERLACING_SUPPORTED
if (png_ptr->interlaced) if (png_ptr->interlaced)
{ {
png_ptr->row_number = 0; png_ptr->row_number = 0;
@ -1155,7 +1157,7 @@ png_read_push_finish_row(png_structp png_ptr)
#endif /* PNG_READ_INTERLACING_SUPPORTED */ #endif /* PNG_READ_INTERLACING_SUPPORTED */
} }
#if defined(PNG_READ_tEXt_SUPPORTED) #ifdef PNG_READ_tEXt_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
length) length)
@ -1218,7 +1220,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
png_push_crc_finish(png_ptr); png_push_crc_finish(png_ptr);
#if defined(PNG_MAX_MALLOC_64K) #ifdef PNG_MAX_MALLOC_64K
if (png_ptr->skip_length) if (png_ptr->skip_length)
return; return;
#endif #endif
@ -1253,7 +1255,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_zTXt_SUPPORTED) #ifdef PNG_READ_zTXt_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
length) length)
@ -1454,7 +1456,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_iTXt_SUPPORTED) #ifdef PNG_READ_iTXt_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
length) length)
@ -1521,7 +1523,7 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
png_push_crc_finish(png_ptr); png_push_crc_finish(png_ptr);
#if defined(PNG_MAX_MALLOC_64K) #ifdef PNG_MAX_MALLOC_64K
if (png_ptr->skip_length) if (png_ptr->skip_length)
return; return;
#endif #endif
@ -1587,10 +1589,10 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
if (!(png_ptr->chunk_name[0] & 0x20)) if (!(png_ptr->chunk_name[0] & 0x20))
{ {
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
PNG_HANDLE_CHUNK_ALWAYS PNG_HANDLE_CHUNK_ALWAYS
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
&& png_ptr->read_user_chunk_fn == NULL && png_ptr->read_user_chunk_fn == NULL
#endif #endif
) )
@ -1600,7 +1602,7 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
info_ptr = info_ptr; /* To quiet some compiler warnings */ info_ptr = info_ptr; /* To quiet some compiler warnings */
} }
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
{ {
#ifdef PNG_MAX_MALLOC_64K #ifdef PNG_MAX_MALLOC_64K
@ -1629,7 +1631,7 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
} }
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
if (png_ptr->read_user_chunk_fn != NULL) if (png_ptr->read_user_chunk_fn != NULL)
{ {
/* Callback to user unknown chunk handler */ /* Callback to user unknown chunk handler */
@ -1694,6 +1696,7 @@ png_progressive_combine_row (png_structp png_ptr,
PNG_CONST int FARDATA png_pass_dsp_mask[7] = PNG_CONST int FARDATA png_pass_dsp_mask[7] =
{0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
#endif #endif
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;

View file

@ -1,7 +1,7 @@
/* pngread.c - read a PNG file /* pngread.c - read a PNG file
* *
* Last changed in libpng 1.2.37 [June 4, 2009] * Last changed in libpng 1.2.41 [December 3, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 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.)
@ -15,8 +15,10 @@
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) #ifdef PNG_READ_SUPPORTED
/* Create a PNG structure for reading, and allocate any memory needed. */ /* Create a PNG structure for reading, and allocate any memory needed. */
png_structp PNGAPI png_structp PNGAPI
@ -51,6 +53,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
int i; int i;
png_debug(1, "in png_create_read_struct"); png_debug(1, "in png_create_read_struct");
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
@ -62,8 +65,8 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
/* Added at libpng-1.2.6 */ /* Added at libpng-1.2.6 */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED #ifdef PNG_SET_USER_LIMITS_SUPPORTED
png_ptr->user_width_max=PNG_USER_WIDTH_MAX; png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
#endif #endif
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
@ -86,7 +89,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
#endif #endif
#endif #endif /* PNG_SETJMP_SUPPORTED */
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
@ -118,7 +121,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
(user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
(user_png_ver[0] == '0' && user_png_ver[2] < '9')) (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
{ {
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
char msg[80]; char msg[80];
if (user_png_ver) if (user_png_ver)
{ {
@ -152,20 +155,23 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
{ {
case Z_OK: /* Do nothing */ break; case Z_OK: /* Do nothing */ break;
case Z_MEM_ERROR: case Z_MEM_ERROR:
case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break; case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error");
case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break; break;
case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error");
break;
default: png_error(png_ptr, "Unknown zlib error"); default: png_error(png_ptr, "Unknown zlib error");
} }
png_ptr->zstream.next_out = png_ptr->zbuf; png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL); png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
/* Applications that neglect to set up their own setjmp() and then encounter /* Applications that neglect to set up their own setjmp() and then
a png_error() will longjmp here. Since the jmpbuf is then meaningless we encounter a png_error() will longjmp here. Since the jmpbuf is
abort instead of returning. */ then meaningless we abort instead of returning. */
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf)) if (setjmp(jmpbuf))
PNG_ABORT(); PNG_ABORT();
@ -174,14 +180,16 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
if (setjmp(png_ptr->jmpbuf)) if (setjmp(png_ptr->jmpbuf))
PNG_ABORT(); PNG_ABORT();
#endif #endif
#endif #endif /* PNG_SETJMP_SUPPORTED */
return (png_ptr); return (png_ptr);
} }
#if defined(PNG_1_0_X) || defined(PNG_1_2_X) #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
/* Initialize PNG structure for reading, and allocate any memory needed. /* Initialize PNG structure for reading, and allocate any memory needed.
This interface is deprecated in favour of the png_create_read_struct(), * This interface is deprecated in favour of the png_create_read_struct(),
and it will disappear as of libpng-1.3.0. */ * and it will disappear as of libpng-1.3.0.
*/
#undef png_read_init #undef png_read_init
void PNGAPI void PNGAPI
png_read_init(png_structp png_ptr) png_read_init(png_structp png_ptr)
@ -197,7 +205,7 @@ png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
/* We only come here via pre-1.0.12-compiled applications */ /* We only come here via pre-1.0.12-compiled applications */
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
if (png_sizeof(png_struct) > png_struct_size || if (png_sizeof(png_struct) > png_struct_size ||
png_sizeof(png_info) > png_info_size) png_sizeof(png_info) > png_info_size)
{ {
@ -292,12 +300,13 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
/* Added at libpng-1.2.6 */ /* Added at libpng-1.2.6 */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED #ifdef PNG_SET_USER_LIMITS_SUPPORTED
png_ptr->user_width_max=PNG_USER_WIDTH_MAX; png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
#endif #endif
/* Initialize zbuf - compression buffer */ /* Initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE; png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zstream.zalloc = png_zalloc;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size); (png_uint_32)png_ptr->zbuf_size);
png_ptr->zstream.zalloc = png_zalloc; png_ptr->zstream.zalloc = png_zalloc;
@ -307,9 +316,8 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
switch (inflateInit(&png_ptr->zstream)) switch (inflateInit(&png_ptr->zstream))
{ {
case Z_OK: /* Do nothing */ break; case Z_OK: /* Do nothing */ break;
case Z_MEM_ERROR: case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break; case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
default: png_error(png_ptr, "Unknown zlib error"); default: png_error(png_ptr, "Unknown zlib error");
} }
@ -319,7 +327,7 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL); png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
} }
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
/* Read the information before the actual image data. This has been /* Read the information before the actual image data. This has been
* changed in v0.90 to allow reading a file that already has the magic * changed in v0.90 to allow reading a file that already has the magic
* bytes read from the stream. You can tell libpng how many bytes have * bytes read from the stream. You can tell libpng how many bytes have
@ -331,9 +339,11 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
void PNGAPI void PNGAPI
png_read_info(png_structp png_ptr, png_infop info_ptr) png_read_info(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_read_info");
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
png_debug(1, "in png_read_info");
/* If we haven't checked all of the PNG signature bytes, do so now. */ /* If we haven't checked all of the PNG signature bytes, do so now. */
if (png_ptr->sig_bytes < 8) if (png_ptr->sig_bytes < 8)
{ {
@ -362,55 +372,55 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
PNG_CONST PNG_IDAT; PNG_CONST PNG_IDAT;
PNG_CONST PNG_IEND; PNG_CONST PNG_IEND;
PNG_CONST PNG_PLTE; PNG_CONST PNG_PLTE;
#if defined(PNG_READ_bKGD_SUPPORTED) #ifdef PNG_READ_bKGD_SUPPORTED
PNG_CONST PNG_bKGD; PNG_CONST PNG_bKGD;
#endif #endif
#if defined(PNG_READ_cHRM_SUPPORTED) #ifdef PNG_READ_cHRM_SUPPORTED
PNG_CONST PNG_cHRM; PNG_CONST PNG_cHRM;
#endif #endif
#if defined(PNG_READ_gAMA_SUPPORTED) #ifdef PNG_READ_gAMA_SUPPORTED
PNG_CONST PNG_gAMA; PNG_CONST PNG_gAMA;
#endif #endif
#if defined(PNG_READ_hIST_SUPPORTED) #ifdef PNG_READ_hIST_SUPPORTED
PNG_CONST PNG_hIST; PNG_CONST PNG_hIST;
#endif #endif
#if defined(PNG_READ_iCCP_SUPPORTED) #ifdef PNG_READ_iCCP_SUPPORTED
PNG_CONST PNG_iCCP; PNG_CONST PNG_iCCP;
#endif #endif
#if defined(PNG_READ_iTXt_SUPPORTED) #ifdef PNG_READ_iTXt_SUPPORTED
PNG_CONST PNG_iTXt; PNG_CONST PNG_iTXt;
#endif #endif
#if defined(PNG_READ_oFFs_SUPPORTED) #ifdef PNG_READ_oFFs_SUPPORTED
PNG_CONST PNG_oFFs; PNG_CONST PNG_oFFs;
#endif #endif
#if defined(PNG_READ_pCAL_SUPPORTED) #ifdef PNG_READ_pCAL_SUPPORTED
PNG_CONST PNG_pCAL; PNG_CONST PNG_pCAL;
#endif #endif
#if defined(PNG_READ_pHYs_SUPPORTED) #ifdef PNG_READ_pHYs_SUPPORTED
PNG_CONST PNG_pHYs; PNG_CONST PNG_pHYs;
#endif #endif
#if defined(PNG_READ_sBIT_SUPPORTED) #ifdef PNG_READ_sBIT_SUPPORTED
PNG_CONST PNG_sBIT; PNG_CONST PNG_sBIT;
#endif #endif
#if defined(PNG_READ_sCAL_SUPPORTED) #ifdef PNG_READ_sCAL_SUPPORTED
PNG_CONST PNG_sCAL; PNG_CONST PNG_sCAL;
#endif #endif
#if defined(PNG_READ_sPLT_SUPPORTED) #ifdef PNG_READ_sPLT_SUPPORTED
PNG_CONST PNG_sPLT; PNG_CONST PNG_sPLT;
#endif #endif
#if defined(PNG_READ_sRGB_SUPPORTED) #ifdef PNG_READ_sRGB_SUPPORTED
PNG_CONST PNG_sRGB; PNG_CONST PNG_sRGB;
#endif #endif
#if defined(PNG_READ_tEXt_SUPPORTED) #ifdef PNG_READ_tEXt_SUPPORTED
PNG_CONST PNG_tEXt; PNG_CONST PNG_tEXt;
#endif #endif
#if defined(PNG_READ_tIME_SUPPORTED) #ifdef PNG_READ_tIME_SUPPORTED
PNG_CONST PNG_tIME; PNG_CONST PNG_tIME;
#endif #endif
#if defined(PNG_READ_tRNS_SUPPORTED) #ifdef PNG_READ_tRNS_SUPPORTED
PNG_CONST PNG_tRNS; PNG_CONST PNG_tRNS;
#endif #endif
#if defined(PNG_READ_zTXt_SUPPORTED) #ifdef PNG_READ_zTXt_SUPPORTED
PNG_CONST PNG_zTXt; PNG_CONST PNG_zTXt;
#endif #endif
#endif /* PNG_USE_LOCAL_ARRAYS */ #endif /* PNG_USE_LOCAL_ARRAYS */
@ -461,71 +471,71 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
png_ptr->mode |= PNG_HAVE_IDAT; png_ptr->mode |= PNG_HAVE_IDAT;
break; break;
} }
#if defined(PNG_READ_bKGD_SUPPORTED) #ifdef PNG_READ_bKGD_SUPPORTED
else if (!png_memcmp(chunk_name, png_bKGD, 4)) else if (!png_memcmp(chunk_name, png_bKGD, 4))
png_handle_bKGD(png_ptr, info_ptr, length); png_handle_bKGD(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_cHRM_SUPPORTED) #ifdef PNG_READ_cHRM_SUPPORTED
else if (!png_memcmp(chunk_name, png_cHRM, 4)) else if (!png_memcmp(chunk_name, png_cHRM, 4))
png_handle_cHRM(png_ptr, info_ptr, length); png_handle_cHRM(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_gAMA_SUPPORTED) #ifdef PNG_READ_gAMA_SUPPORTED
else if (!png_memcmp(chunk_name, png_gAMA, 4)) else if (!png_memcmp(chunk_name, png_gAMA, 4))
png_handle_gAMA(png_ptr, info_ptr, length); png_handle_gAMA(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_hIST_SUPPORTED) #ifdef PNG_READ_hIST_SUPPORTED
else if (!png_memcmp(chunk_name, png_hIST, 4)) else if (!png_memcmp(chunk_name, png_hIST, 4))
png_handle_hIST(png_ptr, info_ptr, length); png_handle_hIST(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_oFFs_SUPPORTED) #ifdef PNG_READ_oFFs_SUPPORTED
else if (!png_memcmp(chunk_name, png_oFFs, 4)) else if (!png_memcmp(chunk_name, png_oFFs, 4))
png_handle_oFFs(png_ptr, info_ptr, length); png_handle_oFFs(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_pCAL_SUPPORTED) #ifdef PNG_READ_pCAL_SUPPORTED
else if (!png_memcmp(chunk_name, png_pCAL, 4)) else if (!png_memcmp(chunk_name, png_pCAL, 4))
png_handle_pCAL(png_ptr, info_ptr, length); png_handle_pCAL(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sCAL_SUPPORTED) #ifdef PNG_READ_sCAL_SUPPORTED
else if (!png_memcmp(chunk_name, png_sCAL, 4)) else if (!png_memcmp(chunk_name, png_sCAL, 4))
png_handle_sCAL(png_ptr, info_ptr, length); png_handle_sCAL(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_pHYs_SUPPORTED) #ifdef PNG_READ_pHYs_SUPPORTED
else if (!png_memcmp(chunk_name, png_pHYs, 4)) else if (!png_memcmp(chunk_name, png_pHYs, 4))
png_handle_pHYs(png_ptr, info_ptr, length); png_handle_pHYs(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sBIT_SUPPORTED) #ifdef PNG_READ_sBIT_SUPPORTED
else if (!png_memcmp(chunk_name, png_sBIT, 4)) else if (!png_memcmp(chunk_name, png_sBIT, 4))
png_handle_sBIT(png_ptr, info_ptr, length); png_handle_sBIT(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sRGB_SUPPORTED) #ifdef PNG_READ_sRGB_SUPPORTED
else if (!png_memcmp(chunk_name, png_sRGB, 4)) else if (!png_memcmp(chunk_name, png_sRGB, 4))
png_handle_sRGB(png_ptr, info_ptr, length); png_handle_sRGB(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_iCCP_SUPPORTED) #ifdef PNG_READ_iCCP_SUPPORTED
else if (!png_memcmp(chunk_name, png_iCCP, 4)) else if (!png_memcmp(chunk_name, png_iCCP, 4))
png_handle_iCCP(png_ptr, info_ptr, length); png_handle_iCCP(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sPLT_SUPPORTED) #ifdef PNG_READ_sPLT_SUPPORTED
else if (!png_memcmp(chunk_name, png_sPLT, 4)) else if (!png_memcmp(chunk_name, png_sPLT, 4))
png_handle_sPLT(png_ptr, info_ptr, length); png_handle_sPLT(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_tEXt_SUPPORTED) #ifdef PNG_READ_tEXt_SUPPORTED
else if (!png_memcmp(chunk_name, png_tEXt, 4)) else if (!png_memcmp(chunk_name, png_tEXt, 4))
png_handle_tEXt(png_ptr, info_ptr, length); png_handle_tEXt(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_tIME_SUPPORTED) #ifdef PNG_READ_tIME_SUPPORTED
else if (!png_memcmp(chunk_name, png_tIME, 4)) else if (!png_memcmp(chunk_name, png_tIME, 4))
png_handle_tIME(png_ptr, info_ptr, length); png_handle_tIME(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_tRNS_SUPPORTED) #ifdef PNG_READ_tRNS_SUPPORTED
else if (!png_memcmp(chunk_name, png_tRNS, 4)) else if (!png_memcmp(chunk_name, png_tRNS, 4))
png_handle_tRNS(png_ptr, info_ptr, length); png_handle_tRNS(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_zTXt_SUPPORTED) #ifdef PNG_READ_zTXt_SUPPORTED
else if (!png_memcmp(chunk_name, png_zTXt, 4)) else if (!png_memcmp(chunk_name, png_zTXt, 4))
png_handle_zTXt(png_ptr, info_ptr, length); png_handle_zTXt(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_iTXt_SUPPORTED) #ifdef PNG_READ_iTXt_SUPPORTED
else if (!png_memcmp(chunk_name, png_iTXt, 4)) else if (!png_memcmp(chunk_name, png_iTXt, 4))
png_handle_iTXt(png_ptr, info_ptr, length); png_handle_iTXt(png_ptr, info_ptr, length);
#endif #endif
@ -533,13 +543,14 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
png_handle_unknown(png_ptr, info_ptr, length); png_handle_unknown(png_ptr, info_ptr, length);
} }
} }
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
/* Optional call to update the users info_ptr structure */ /* Optional call to update the users info_ptr structure */
void PNGAPI void PNGAPI
png_read_update_info(png_structp png_ptr, png_infop info_ptr) png_read_update_info(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_read_update_info"); png_debug(1, "in png_read_update_info");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
@ -547,10 +558,11 @@ png_read_update_info(png_structp png_ptr, png_infop info_ptr)
else else
png_warning(png_ptr, png_warning(png_ptr,
"Ignoring extra png_read_update_info() call; row buffer not reallocated"); "Ignoring extra png_read_update_info() call; row buffer not reallocated");
png_read_transform_info(png_ptr, info_ptr); png_read_transform_info(png_ptr, info_ptr);
} }
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
/* Initialize palette, background, etc, after transformations /* Initialize palette, background, etc, after transformations
* are set, but before any reading takes place. This allows * are set, but before any reading takes place. This allows
* the user to obtain a gamma-corrected palette, for example. * the user to obtain a gamma-corrected palette, for example.
@ -560,28 +572,30 @@ void PNGAPI
png_start_read_image(png_structp png_ptr) png_start_read_image(png_structp png_ptr)
{ {
png_debug(1, "in png_start_read_image"); png_debug(1, "in png_start_read_image");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr); png_read_start_row(png_ptr);
} }
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
void PNGAPI void PNGAPI
png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
{ {
#ifdef PNG_USE_LOCAL_ARRAYS
PNG_CONST PNG_IDAT; PNG_CONST PNG_IDAT;
PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
0xff}; 0xff};
PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
#endif
int ret; int ret;
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_debug2(1, "in png_read_row (row %lu, pass %d)", png_debug2(1, "in png_read_row (row %lu, pass %d)",
png_ptr->row_number, png_ptr->pass); png_ptr->row_number, png_ptr->pass);
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr); png_read_start_row(png_ptr);
if (png_ptr->row_number == 0 && png_ptr->pass == 0) if (png_ptr->row_number == 0 && png_ptr->pass == 0)
@ -617,7 +631,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
#endif #endif
} }
#if defined(PNG_READ_INTERLACING_SUPPORTED) #ifdef PNG_READ_INTERLACING_SUPPORTED
/* If interlaced and we do not need a new row, combine row and return */ /* If interlaced and we do not need a new row, combine row and return */
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
{ {
@ -751,7 +765,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
png_ptr->rowbytes + 1); png_ptr->rowbytes + 1);
#if defined(PNG_MNG_FEATURES_SUPPORTED) #ifdef PNG_MNG_FEATURES_SUPPORTED
if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
{ {
@ -764,7 +778,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
png_do_read_transformations(png_ptr); png_do_read_transformations(png_ptr);
#if defined(PNG_READ_INTERLACING_SUPPORTED) #ifdef PNG_READ_INTERLACING_SUPPORTED
/* Blow up interlaced rows to full size */ /* Blow up interlaced rows to full size */
if (png_ptr->interlaced && if (png_ptr->interlaced &&
(png_ptr->transformations & PNG_INTERLACE)) (png_ptr->transformations & PNG_INTERLACE))
@ -796,9 +810,9 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
if (png_ptr->read_row_fn != NULL) if (png_ptr->read_row_fn != NULL)
(*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
} }
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
/* Read one or more rows of image data. If the image is interlaced, /* Read one or more rows of image data. If the image is interlaced,
* and png_set_interlace_handling() has been called, the rows need to * and png_set_interlace_handling() has been called, the rows need to
* contain the contents of the rows from the previous pass. If the * contain the contents of the rows from the previous pass. If the
@ -832,6 +846,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
png_bytepp dp; png_bytepp dp;
png_debug(1, "in png_read_rows"); png_debug(1, "in png_read_rows");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
rp = row; rp = row;
@ -859,9 +874,9 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
dp++; dp++;
} }
} }
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
/* Read the entire image. If the image has an alpha channel or a tRNS /* Read the entire image. If the image has an alpha channel or a tRNS
* chunk, and you have called png_handle_alpha()[*], you will need to * chunk, and you have called png_handle_alpha()[*], you will need to
* initialize the image to the current image that PNG will be overlaying. * initialize the image to the current image that PNG will be overlaying.
@ -882,6 +897,7 @@ png_read_image(png_structp png_ptr, png_bytepp image)
png_bytepp rp; png_bytepp rp;
png_debug(1, "in png_read_image"); png_debug(1, "in png_read_image");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
@ -908,9 +924,9 @@ png_read_image(png_structp png_ptr, png_bytepp image)
} }
} }
} }
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
/* Read the end of the PNG file. Will not read past the end of the /* Read the end of the PNG file. Will not read past the end of the
* file, will verify the end is accurate, and will read any comments * file, will verify the end is accurate, and will read any comments
* or time information at the end of the file, if info is not NULL. * or time information at the end of the file, if info is not NULL.
@ -919,6 +935,7 @@ void PNGAPI
png_read_end(png_structp png_ptr, png_infop info_ptr) png_read_end(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_read_end"); png_debug(1, "in png_read_end");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
@ -930,55 +947,55 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
PNG_CONST PNG_IDAT; PNG_CONST PNG_IDAT;
PNG_CONST PNG_IEND; PNG_CONST PNG_IEND;
PNG_CONST PNG_PLTE; PNG_CONST PNG_PLTE;
#if defined(PNG_READ_bKGD_SUPPORTED) #ifdef PNG_READ_bKGD_SUPPORTED
PNG_CONST PNG_bKGD; PNG_CONST PNG_bKGD;
#endif #endif
#if defined(PNG_READ_cHRM_SUPPORTED) #ifdef PNG_READ_cHRM_SUPPORTED
PNG_CONST PNG_cHRM; PNG_CONST PNG_cHRM;
#endif #endif
#if defined(PNG_READ_gAMA_SUPPORTED) #ifdef PNG_READ_gAMA_SUPPORTED
PNG_CONST PNG_gAMA; PNG_CONST PNG_gAMA;
#endif #endif
#if defined(PNG_READ_hIST_SUPPORTED) #ifdef PNG_READ_hIST_SUPPORTED
PNG_CONST PNG_hIST; PNG_CONST PNG_hIST;
#endif #endif
#if defined(PNG_READ_iCCP_SUPPORTED) #ifdef PNG_READ_iCCP_SUPPORTED
PNG_CONST PNG_iCCP; PNG_CONST PNG_iCCP;
#endif #endif
#if defined(PNG_READ_iTXt_SUPPORTED) #ifdef PNG_READ_iTXt_SUPPORTED
PNG_CONST PNG_iTXt; PNG_CONST PNG_iTXt;
#endif #endif
#if defined(PNG_READ_oFFs_SUPPORTED) #ifdef PNG_READ_oFFs_SUPPORTED
PNG_CONST PNG_oFFs; PNG_CONST PNG_oFFs;
#endif #endif
#if defined(PNG_READ_pCAL_SUPPORTED) #ifdef PNG_READ_pCAL_SUPPORTED
PNG_CONST PNG_pCAL; PNG_CONST PNG_pCAL;
#endif #endif
#if defined(PNG_READ_pHYs_SUPPORTED) #ifdef PNG_READ_pHYs_SUPPORTED
PNG_CONST PNG_pHYs; PNG_CONST PNG_pHYs;
#endif #endif
#if defined(PNG_READ_sBIT_SUPPORTED) #ifdef PNG_READ_sBIT_SUPPORTED
PNG_CONST PNG_sBIT; PNG_CONST PNG_sBIT;
#endif #endif
#if defined(PNG_READ_sCAL_SUPPORTED) #ifdef PNG_READ_sCAL_SUPPORTED
PNG_CONST PNG_sCAL; PNG_CONST PNG_sCAL;
#endif #endif
#if defined(PNG_READ_sPLT_SUPPORTED) #ifdef PNG_READ_sPLT_SUPPORTED
PNG_CONST PNG_sPLT; PNG_CONST PNG_sPLT;
#endif #endif
#if defined(PNG_READ_sRGB_SUPPORTED) #ifdef PNG_READ_sRGB_SUPPORTED
PNG_CONST PNG_sRGB; PNG_CONST PNG_sRGB;
#endif #endif
#if defined(PNG_READ_tEXt_SUPPORTED) #ifdef PNG_READ_tEXt_SUPPORTED
PNG_CONST PNG_tEXt; PNG_CONST PNG_tEXt;
#endif #endif
#if defined(PNG_READ_tIME_SUPPORTED) #ifdef PNG_READ_tIME_SUPPORTED
PNG_CONST PNG_tIME; PNG_CONST PNG_tIME;
#endif #endif
#if defined(PNG_READ_tRNS_SUPPORTED) #ifdef PNG_READ_tRNS_SUPPORTED
PNG_CONST PNG_tRNS; PNG_CONST PNG_tRNS;
#endif #endif
#if defined(PNG_READ_zTXt_SUPPORTED) #ifdef PNG_READ_zTXt_SUPPORTED
PNG_CONST PNG_zTXt; PNG_CONST PNG_zTXt;
#endif #endif
#endif /* PNG_USE_LOCAL_ARRAYS */ #endif /* PNG_USE_LOCAL_ARRAYS */
@ -1013,71 +1030,71 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
} }
else if (!png_memcmp(chunk_name, png_PLTE, 4)) else if (!png_memcmp(chunk_name, png_PLTE, 4))
png_handle_PLTE(png_ptr, info_ptr, length); png_handle_PLTE(png_ptr, info_ptr, length);
#if defined(PNG_READ_bKGD_SUPPORTED) #ifdef PNG_READ_bKGD_SUPPORTED
else if (!png_memcmp(chunk_name, png_bKGD, 4)) else if (!png_memcmp(chunk_name, png_bKGD, 4))
png_handle_bKGD(png_ptr, info_ptr, length); png_handle_bKGD(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_cHRM_SUPPORTED) #ifdef PNG_READ_cHRM_SUPPORTED
else if (!png_memcmp(chunk_name, png_cHRM, 4)) else if (!png_memcmp(chunk_name, png_cHRM, 4))
png_handle_cHRM(png_ptr, info_ptr, length); png_handle_cHRM(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_gAMA_SUPPORTED) #ifdef PNG_READ_gAMA_SUPPORTED
else if (!png_memcmp(chunk_name, png_gAMA, 4)) else if (!png_memcmp(chunk_name, png_gAMA, 4))
png_handle_gAMA(png_ptr, info_ptr, length); png_handle_gAMA(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_hIST_SUPPORTED) #ifdef PNG_READ_hIST_SUPPORTED
else if (!png_memcmp(chunk_name, png_hIST, 4)) else if (!png_memcmp(chunk_name, png_hIST, 4))
png_handle_hIST(png_ptr, info_ptr, length); png_handle_hIST(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_oFFs_SUPPORTED) #ifdef PNG_READ_oFFs_SUPPORTED
else if (!png_memcmp(chunk_name, png_oFFs, 4)) else if (!png_memcmp(chunk_name, png_oFFs, 4))
png_handle_oFFs(png_ptr, info_ptr, length); png_handle_oFFs(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_pCAL_SUPPORTED) #ifdef PNG_READ_pCAL_SUPPORTED
else if (!png_memcmp(chunk_name, png_pCAL, 4)) else if (!png_memcmp(chunk_name, png_pCAL, 4))
png_handle_pCAL(png_ptr, info_ptr, length); png_handle_pCAL(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sCAL_SUPPORTED) #ifdef PNG_READ_sCAL_SUPPORTED
else if (!png_memcmp(chunk_name, png_sCAL, 4)) else if (!png_memcmp(chunk_name, png_sCAL, 4))
png_handle_sCAL(png_ptr, info_ptr, length); png_handle_sCAL(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_pHYs_SUPPORTED) #ifdef PNG_READ_pHYs_SUPPORTED
else if (!png_memcmp(chunk_name, png_pHYs, 4)) else if (!png_memcmp(chunk_name, png_pHYs, 4))
png_handle_pHYs(png_ptr, info_ptr, length); png_handle_pHYs(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sBIT_SUPPORTED) #ifdef PNG_READ_sBIT_SUPPORTED
else if (!png_memcmp(chunk_name, png_sBIT, 4)) else if (!png_memcmp(chunk_name, png_sBIT, 4))
png_handle_sBIT(png_ptr, info_ptr, length); png_handle_sBIT(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sRGB_SUPPORTED) #ifdef PNG_READ_sRGB_SUPPORTED
else if (!png_memcmp(chunk_name, png_sRGB, 4)) else if (!png_memcmp(chunk_name, png_sRGB, 4))
png_handle_sRGB(png_ptr, info_ptr, length); png_handle_sRGB(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_iCCP_SUPPORTED) #ifdef PNG_READ_iCCP_SUPPORTED
else if (!png_memcmp(chunk_name, png_iCCP, 4)) else if (!png_memcmp(chunk_name, png_iCCP, 4))
png_handle_iCCP(png_ptr, info_ptr, length); png_handle_iCCP(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sPLT_SUPPORTED) #ifdef PNG_READ_sPLT_SUPPORTED
else if (!png_memcmp(chunk_name, png_sPLT, 4)) else if (!png_memcmp(chunk_name, png_sPLT, 4))
png_handle_sPLT(png_ptr, info_ptr, length); png_handle_sPLT(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_tEXt_SUPPORTED) #ifdef PNG_READ_tEXt_SUPPORTED
else if (!png_memcmp(chunk_name, png_tEXt, 4)) else if (!png_memcmp(chunk_name, png_tEXt, 4))
png_handle_tEXt(png_ptr, info_ptr, length); png_handle_tEXt(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_tIME_SUPPORTED) #ifdef PNG_READ_tIME_SUPPORTED
else if (!png_memcmp(chunk_name, png_tIME, 4)) else if (!png_memcmp(chunk_name, png_tIME, 4))
png_handle_tIME(png_ptr, info_ptr, length); png_handle_tIME(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_tRNS_SUPPORTED) #ifdef PNG_READ_tRNS_SUPPORTED
else if (!png_memcmp(chunk_name, png_tRNS, 4)) else if (!png_memcmp(chunk_name, png_tRNS, 4))
png_handle_tRNS(png_ptr, info_ptr, length); png_handle_tRNS(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_zTXt_SUPPORTED) #ifdef PNG_READ_zTXt_SUPPORTED
else if (!png_memcmp(chunk_name, png_zTXt, 4)) else if (!png_memcmp(chunk_name, png_zTXt, 4))
png_handle_zTXt(png_ptr, info_ptr, length); png_handle_zTXt(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_iTXt_SUPPORTED) #ifdef PNG_READ_iTXt_SUPPORTED
else if (!png_memcmp(chunk_name, png_iTXt, 4)) else if (!png_memcmp(chunk_name, png_iTXt, 4))
png_handle_iTXt(png_ptr, info_ptr, length); png_handle_iTXt(png_ptr, info_ptr, length);
#endif #endif
@ -1085,7 +1102,7 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
png_handle_unknown(png_ptr, info_ptr, length); png_handle_unknown(png_ptr, info_ptr, length);
} while (!(png_ptr->mode & PNG_HAVE_IEND)); } while (!(png_ptr->mode & PNG_HAVE_IEND));
} }
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
/* Free all memory used by the read */ /* Free all memory used by the read */
void PNGAPI void PNGAPI
@ -1100,6 +1117,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
#endif #endif
png_debug(1, "in png_destroy_read_struct"); png_debug(1, "in png_destroy_read_struct");
if (png_ptr_ptr != NULL) if (png_ptr_ptr != NULL)
png_ptr = *png_ptr_ptr; png_ptr = *png_ptr_ptr;
if (png_ptr == NULL) if (png_ptr == NULL)
@ -1120,7 +1138,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
if (info_ptr != NULL) if (info_ptr != NULL)
{ {
#if defined(PNG_TEXT_SUPPORTED) #ifdef PNG_TEXT_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1); png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
#endif #endif
@ -1135,7 +1153,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
if (end_info_ptr != NULL) if (end_info_ptr != NULL)
{ {
#if defined(PNG_READ_TEXT_SUPPORTED) #ifdef PNG_READ_TEXT_SUPPORTED
png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1); png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
#endif #endif
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
@ -1174,6 +1192,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
#endif #endif
png_debug(1, "in png_read_destroy"); png_debug(1, "in png_read_destroy");
if (info_ptr != NULL) if (info_ptr != NULL)
png_info_destroy(png_ptr, info_ptr); png_info_destroy(png_ptr, info_ptr);
@ -1184,14 +1203,14 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->big_row_buf); png_free(png_ptr, png_ptr->big_row_buf);
png_free(png_ptr, png_ptr->prev_row); png_free(png_ptr, png_ptr->prev_row);
png_free(png_ptr, png_ptr->chunkdata); png_free(png_ptr, png_ptr->chunkdata);
#if defined(PNG_READ_DITHER_SUPPORTED) #ifdef PNG_READ_DITHER_SUPPORTED
png_free(png_ptr, png_ptr->palette_lookup); png_free(png_ptr, png_ptr->palette_lookup);
png_free(png_ptr, png_ptr->dither_index); png_free(png_ptr, png_ptr->dither_index);
#endif #endif
#if defined(PNG_READ_GAMMA_SUPPORTED) #ifdef PNG_READ_GAMMA_SUPPORTED
png_free(png_ptr, png_ptr->gamma_table); png_free(png_ptr, png_ptr->gamma_table);
#endif #endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED) #ifdef PNG_READ_BACKGROUND_SUPPORTED
png_free(png_ptr, png_ptr->gamma_from_1); png_free(png_ptr, png_ptr->gamma_from_1);
png_free(png_ptr, png_ptr->gamma_to_1); png_free(png_ptr, png_ptr->gamma_to_1);
#endif #endif
@ -1216,7 +1235,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
#endif #endif
#endif #endif
#if defined(PNG_READ_hIST_SUPPORTED) #ifdef PNG_READ_hIST_SUPPORTED
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
if (png_ptr->free_me & PNG_FREE_HIST) if (png_ptr->free_me & PNG_FREE_HIST)
png_free(png_ptr, png_ptr->hist); png_free(png_ptr, png_ptr->hist);
@ -1227,7 +1246,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_ptr->flags &= ~PNG_FLAG_FREE_HIST; png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
#endif #endif
#endif #endif
#if defined(PNG_READ_GAMMA_SUPPORTED) #ifdef PNG_READ_GAMMA_SUPPORTED
if (png_ptr->gamma_16_table != NULL) if (png_ptr->gamma_16_table != NULL)
{ {
int i; int i;
@ -1238,7 +1257,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
} }
png_free(png_ptr, png_ptr->gamma_16_table); png_free(png_ptr, png_ptr->gamma_16_table);
} }
#if defined(PNG_READ_BACKGROUND_SUPPORTED) #ifdef PNG_READ_BACKGROUND_SUPPORTED
if (png_ptr->gamma_16_from_1 != NULL) if (png_ptr->gamma_16_from_1 != NULL)
{ {
int i; int i;
@ -1261,7 +1280,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
} }
#endif #endif
#endif #endif
#if defined(PNG_TIME_RFC1123_SUPPORTED) #ifdef PNG_TIME_RFC1123_SUPPORTED
png_free(png_ptr, png_ptr->time_buffer); png_free(png_ptr, png_ptr->time_buffer);
#endif #endif
@ -1314,8 +1333,8 @@ png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
} }
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
#if defined(PNG_INFO_IMAGE_SUPPORTED) #ifdef PNG_INFO_IMAGE_SUPPORTED
void PNGAPI void PNGAPI
png_read_png(png_structp png_ptr, png_infop info_ptr, png_read_png(png_structp png_ptr, png_infop info_ptr,
int transforms, int transforms,
@ -1325,7 +1344,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
/* Invert the alpha channel from opacity to transparency /* Invert the alpha channel from opacity to transparency
*/ */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA) if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
@ -1341,14 +1360,14 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
/* -------------- image transformations start here ------------------- */ /* -------------- image transformations start here ------------------- */
#if defined(PNG_READ_16_TO_8_SUPPORTED) #ifdef PNG_READ_16_TO_8_SUPPORTED
/* Tell libpng to strip 16 bit/color files down to 8 bits per color. /* Tell libpng to strip 16 bit/color files down to 8 bits per color.
*/ */
if (transforms & PNG_TRANSFORM_STRIP_16) if (transforms & PNG_TRANSFORM_STRIP_16)
png_set_strip_16(png_ptr); png_set_strip_16(png_ptr);
#endif #endif
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
/* Strip alpha bytes from the input data without combining with /* Strip alpha bytes from the input data without combining with
* the background (not recommended). * the background (not recommended).
*/ */
@ -1364,7 +1383,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
png_set_packing(png_ptr); png_set_packing(png_ptr);
#endif #endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED) #ifdef PNG_READ_PACKSWAP_SUPPORTED
/* 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).
*/ */
@ -1372,7 +1391,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
png_set_packswap(png_ptr); png_set_packswap(png_ptr);
#endif #endif
#if defined(PNG_READ_EXPAND_SUPPORTED) #ifdef PNG_READ_EXPAND_SUPPORTED
/* Expand paletted colors into true RGB triplets /* Expand paletted colors into true RGB triplets
* Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
* Expand paletted or RGB images with transparency to full alpha * Expand paletted or RGB images with transparency to full alpha
@ -1388,14 +1407,14 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
/* We don't handle background color or gamma transformation or dithering. /* We don't handle background color or gamma transformation or dithering.
*/ */
#if defined(PNG_READ_INVERT_SUPPORTED) #ifdef PNG_READ_INVERT_SUPPORTED
/* Invert monochrome files to have 0 as white and 1 as black /* Invert monochrome files to have 0 as white and 1 as black
*/ */
if (transforms & PNG_TRANSFORM_INVERT_MONO) if (transforms & PNG_TRANSFORM_INVERT_MONO)
png_set_invert_mono(png_ptr); png_set_invert_mono(png_ptr);
#endif #endif
#if defined(PNG_READ_SHIFT_SUPPORTED) #ifdef PNG_READ_SHIFT_SUPPORTED
/* If you want to shift the pixel values from the range [0,255] or /* If you want to shift the pixel values from the range [0,255] or
* [0,65535] to the original [0,7] or [0,31], or whatever range the * [0,65535] to the original [0,7] or [0,31], or whatever range the
* colors were originally in: * colors were originally in:
@ -1410,27 +1429,43 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_READ_BGR_SUPPORTED) #ifdef PNG_READ_BGR_SUPPORTED
/* Flip the RGB pixels to BGR (or RGBA to BGRA) /* Flip the RGB pixels to BGR (or RGBA to BGRA)
*/ */
if (transforms & PNG_TRANSFORM_BGR) if (transforms & PNG_TRANSFORM_BGR)
png_set_bgr(png_ptr); png_set_bgr(png_ptr);
#endif #endif
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
/* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
*/ */
if (transforms & PNG_TRANSFORM_SWAP_ALPHA) if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
png_set_swap_alpha(png_ptr); png_set_swap_alpha(png_ptr);
#endif #endif
#if defined(PNG_READ_SWAP_SUPPORTED) #ifdef PNG_READ_SWAP_SUPPORTED
/* Swap bytes of 16 bit files to least significant byte first /* Swap bytes of 16 bit files to least significant byte first
*/ */
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
png_set_swap(png_ptr); png_set_swap(png_ptr);
#endif #endif
/* Added at libpng-1.2.41 */
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
/* Invert the alpha channel from opacity to transparency
*/
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
png_set_invert_alpha(png_ptr);
#endif
/* Added at libpng-1.2.41 */
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
/* Expand grayscale image to RGB
*/
if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
png_set_gray_to_rgb(png_ptr);
#endif
/* We don't handle adding filler bytes */ /* We don't handle adding filler bytes */
/* Optional call to gamma correct and add the background to the palette /* Optional call to gamma correct and add the background to the palette
@ -1450,9 +1485,11 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
info_ptr->height * png_sizeof(png_bytep)); info_ptr->height * png_sizeof(png_bytep));
png_memset(info_ptr->row_pointers, 0, info_ptr->height png_memset(info_ptr->row_pointers, 0, info_ptr->height
* png_sizeof(png_bytep)); * png_sizeof(png_bytep));
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_ROWS; info_ptr->free_me |= PNG_FREE_ROWS;
#endif #endif
for (row = 0; row < (int)info_ptr->height; row++) for (row = 0; row < (int)info_ptr->height; row++)
info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
png_get_rowbytes(png_ptr, info_ptr)); png_get_rowbytes(png_ptr, info_ptr));
@ -1469,5 +1506,5 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
} }
#endif /* PNG_INFO_IMAGE_SUPPORTED */ #endif /* PNG_INFO_IMAGE_SUPPORTED */
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
#endif /* PNG_READ_SUPPORTED */ #endif /* PNG_READ_SUPPORTED */

View file

@ -1,7 +1,7 @@
/* pngrio.c - functions for data input /* pngrio.c - functions for data input
* *
* Last changed in libpng 1.2.37 [June 4, 2009] * Last changed in libpng 1.2.41 [December 3, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 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.)
@ -19,8 +19,9 @@
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) #ifdef PNG_READ_SUPPORTED
/* Read the data from whatever input you are using. The default routine /* Read the data from whatever input you are using. The default routine
* reads from a file pointer. Note that this routine sometimes gets called * reads from a file pointer. Note that this routine sometimes gets called
@ -32,13 +33,14 @@ void /* PRIVATE */
png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
png_debug1(4, "reading %d bytes", (int)length); png_debug1(4, "reading %d bytes", (int)length);
if (png_ptr->read_data_fn != NULL) if (png_ptr->read_data_fn != NULL)
(*(png_ptr->read_data_fn))(png_ptr, data, length); (*(png_ptr->read_data_fn))(png_ptr, data, length);
else else
png_error(png_ptr, "Call to NULL read function"); png_error(png_ptr, "Call to NULL read function");
} }
#if !defined(PNG_NO_STDIO) #ifdef PNG_STDIO_SUPPORTED
/* This is the function that does the actual reading of data. If you are /* This is the function that does the actual reading of data. If you are
* not reading from a standard C stream, you should create a replacement * not reading from a standard C stream, you should create a replacement
* read_data function and use it at run time with png_set_read_fn(), rather * read_data function and use it at run time with png_set_read_fn(), rather
@ -55,7 +57,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
/* fread() returns 0 on error, so it is OK to store this in a png_size_t /* fread() returns 0 on error, so it is OK to store this in a png_size_t
* instead of an int, which is what fread() actually returns. * instead of an int, which is what fread() actually returns.
*/ */
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
check = 0; check = 0;
#else #else
@ -89,7 +91,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
if ((png_bytep)n_data == data) if ((png_bytep)n_data == data)
{ {
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
check = 0; check = 0;
#else #else
@ -105,7 +107,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
do do
{ {
read = MIN(NEAR_BUF_SIZE, remaining); read = MIN(NEAR_BUF_SIZE, remaining);
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) ) if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
err = 0; err = 0;
#else #else
@ -151,7 +153,7 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
return; return;
png_ptr->io_ptr = io_ptr; png_ptr->io_ptr = io_ptr;
#if !defined(PNG_NO_STDIO) #ifdef PNG_STDIO_SUPPORTED
if (read_data_fn != NULL) if (read_data_fn != NULL)
png_ptr->read_data_fn = read_data_fn; png_ptr->read_data_fn = read_data_fn;
else else
@ -170,7 +172,7 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
"same structure. Resetting write_data_fn to NULL."); "same structure. Resetting write_data_fn to NULL.");
} }
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #ifdef PNG_WRITE_FLUSH_SUPPORTED
png_ptr->output_flush_fn = NULL; png_ptr->output_flush_fn = NULL;
#endif #endif
} }

File diff suppressed because it is too large Load diff

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.2.38 [July 16, 2009] * Last changed in libpng 1.2.41 [December 3, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 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.)
@ -15,15 +15,16 @@
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) #ifdef PNG_READ_SUPPORTED
#if defined(_WIN32_WCE) && (_WIN32_WCE<0x500) #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
# define WIN32_WCE_OLD # define WIN32_WCE_OLD
#endif #endif
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
# if defined(WIN32_WCE_OLD) # ifdef WIN32_WCE_OLD
/* The strtod() function is not supported on WindowsCE */ /* The strtod() function is not supported on WindowsCE */
__inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr) __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
{ {
@ -228,7 +229,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
png_size_t chunklength, png_size_t chunklength,
png_size_t prefix_size, png_size_t *newlength) png_size_t prefix_size, png_size_t *newlength)
{ {
static PNG_CONST char msg[] = "Error decoding compressed text"; static PNG_CONST char msg[] = "Error decoding compressed chunk";
png_charp text; png_charp text;
png_size_t text_size; png_size_t text_size;
@ -331,7 +332,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
} }
if (ret != Z_STREAM_END) if (ret != Z_STREAM_END)
{ {
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
char umsg[52]; char umsg[52];
if (ret == Z_BUF_ERROR) if (ret == Z_BUF_ERROR)
@ -378,7 +379,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
} }
else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
{ {
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
char umsg[50]; char umsg[50];
png_snprintf(umsg, 50, "Unknown zTXt compression type %d", comp_type); png_snprintf(umsg, 50, "Unknown zTXt compression type %d", comp_type);
@ -430,7 +431,7 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_ptr->bit_depth = (png_byte)bit_depth; png_ptr->bit_depth = (png_byte)bit_depth;
png_ptr->interlaced = (png_byte)interlace_type; png_ptr->interlaced = (png_byte)interlace_type;
png_ptr->color_type = (png_byte)color_type; png_ptr->color_type = (png_byte)color_type;
#if defined(PNG_MNG_FEATURES_SUPPORTED) #ifdef PNG_MNG_FEATURES_SUPPORTED
png_ptr->filter_type = (png_byte)filter_type; png_ptr->filter_type = (png_byte)filter_type;
#endif #endif
png_ptr->compression_type = (png_byte)compression_type; png_ptr->compression_type = (png_byte)compression_type;
@ -473,7 +474,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
png_color palette[PNG_MAX_PALETTE_LENGTH]; png_color palette[PNG_MAX_PALETTE_LENGTH];
int num, i; int num, i;
#ifndef PNG_NO_POINTER_INDEXING #ifdef PNG_POINTER_INDEXING_SUPPORTED
png_colorp pal_ptr; png_colorp pal_ptr;
#endif #endif
@ -501,7 +502,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_finish(png_ptr, length); png_crc_finish(png_ptr, length);
return; return;
} }
#if !defined(PNG_READ_OPT_PLTE_SUPPORTED) #ifndef PNG_READ_OPT_PLTE_SUPPORTED
if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
{ {
png_crc_finish(png_ptr, length); png_crc_finish(png_ptr, length);
@ -526,7 +527,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
num = (int)length / 3; num = (int)length / 3;
#ifndef PNG_NO_POINTER_INDEXING #ifdef PNG_POINTER_INDEXING_SUPPORTED
for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
{ {
png_byte buf[3]; png_byte buf[3];
@ -554,13 +555,13 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
* have an RGB image, the PLTE can be considered ancillary, so * have an RGB image, the PLTE can be considered ancillary, so
* we will act as though it is. * we will act as though it is.
*/ */
#if !defined(PNG_READ_OPT_PLTE_SUPPORTED) #ifndef PNG_READ_OPT_PLTE_SUPPORTED
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
#endif #endif
{ {
png_crc_finish(png_ptr, 0); png_crc_finish(png_ptr, 0);
} }
#if !defined(PNG_READ_OPT_PLTE_SUPPORTED) #ifndef PNG_READ_OPT_PLTE_SUPPORTED
else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */ else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
{ {
/* If we don't want to use the data from an ancillary chunk, /* If we don't want to use the data from an ancillary chunk,
@ -589,7 +590,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_set_PLTE(png_ptr, info_ptr, palette, num); png_set_PLTE(png_ptr, info_ptr, palette, num);
#if defined(PNG_READ_tRNS_SUPPORTED) #ifdef PNG_READ_tRNS_SUPPORTED
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{ {
if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
@ -631,7 +632,7 @@ png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */ info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */
} }
#if defined(PNG_READ_gAMA_SUPPORTED) #ifdef PNG_READ_gAMA_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
@ -656,7 +657,7 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_warning(png_ptr, "Out of place gAMA chunk"); png_warning(png_ptr, "Out of place gAMA chunk");
if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
#if defined(PNG_READ_sRGB_SUPPORTED) #ifdef PNG_READ_sRGB_SUPPORTED
&& !(info_ptr->valid & PNG_INFO_sRGB) && !(info_ptr->valid & PNG_INFO_sRGB)
#endif #endif
) )
@ -686,13 +687,13 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
return; return;
} }
#if defined(PNG_READ_sRGB_SUPPORTED) #ifdef PNG_READ_sRGB_SUPPORTED
if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
if (PNG_OUT_OF_RANGE(igamma, 45500L, 500)) if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Ignoring incorrect gAMA value when sRGB is also present"); "Ignoring incorrect gAMA value when sRGB is also present");
#ifndef PNG_NO_CONSOLE_IO #ifdef PNG_CONSOLE_IO_SUPPORTED
fprintf(stderr, "gamma = (%d/100000)", (int)igamma); fprintf(stderr, "gamma = (%d/100000)", (int)igamma);
#endif #endif
return; return;
@ -712,7 +713,7 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_sBIT_SUPPORTED) #ifdef PNG_READ_sBIT_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
@ -778,7 +779,7 @@ png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_cHRM_SUPPORTED) #ifdef PNG_READ_cHRM_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
@ -806,7 +807,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_warning(png_ptr, "Missing PLTE before cHRM"); png_warning(png_ptr, "Missing PLTE before cHRM");
if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM) if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
#if defined(PNG_READ_sRGB_SUPPORTED) #ifdef PNG_READ_sRGB_SUPPORTED
&& !(info_ptr->valid & PNG_INFO_sRGB) && !(info_ptr->valid & PNG_INFO_sRGB)
#endif #endif
) )
@ -858,7 +859,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
blue_y = (float)int_y_blue / (float)100000.0; blue_y = (float)int_y_blue / (float)100000.0;
#endif #endif
#if defined(PNG_READ_sRGB_SUPPORTED) #ifdef PNG_READ_sRGB_SUPPORTED
if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB)) if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
{ {
if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) || if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
@ -872,7 +873,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Ignoring incorrect cHRM value when sRGB is also present"); "Ignoring incorrect cHRM value when sRGB is also present");
#ifndef PNG_NO_CONSOLE_IO #ifdef PNG_CONSOLE_IO_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
fprintf(stderr, "wx=%f, wy=%f, rx=%f, ry=%f\n", fprintf(stderr, "wx=%f, wy=%f, rx=%f, ry=%f\n",
white_x, white_y, red_x, red_y); white_x, white_y, red_x, red_y);
@ -884,7 +885,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
fprintf(stderr, "gx=%ld, gy=%ld, bx=%ld, by=%ld\n", fprintf(stderr, "gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
int_x_green, int_y_green, int_x_blue, int_y_blue); int_x_green, int_y_green, int_x_blue, int_y_blue);
#endif #endif
#endif /* PNG_NO_CONSOLE_IO */ #endif /* PNG_CONSOLE_IO_SUPPORTED */
} }
return; return;
} }
@ -902,7 +903,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_sRGB_SUPPORTED) #ifdef PNG_READ_sRGB_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
@ -964,7 +965,7 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Ignoring incorrect gAMA value when sRGB is also present"); "Ignoring incorrect gAMA value when sRGB is also present");
#ifndef PNG_NO_CONSOLE_IO #ifdef PNG_CONSOLE_IO_SUPPORTED
# ifdef PNG_FIXED_POINT_SUPPORTED # ifdef PNG_FIXED_POINT_SUPPORTED
fprintf(stderr, "incorrect gamma=(%d/100000)\n", fprintf(stderr, "incorrect gamma=(%d/100000)\n",
(int)png_ptr->int_gamma); (int)png_ptr->int_gamma);
@ -1000,7 +1001,7 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif /* PNG_READ_sRGB_SUPPORTED */ #endif /* PNG_READ_sRGB_SUPPORTED */
#if defined(PNG_READ_iCCP_SUPPORTED) #ifdef PNG_READ_iCCP_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Note: this does not properly handle chunks that are > 64K under DOS */ /* Note: this does not properly handle chunks that are > 64K under DOS */
@ -1120,14 +1121,14 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif /* PNG_READ_iCCP_SUPPORTED */ #endif /* PNG_READ_iCCP_SUPPORTED */
#if defined(PNG_READ_sPLT_SUPPORTED) #ifdef PNG_READ_sPLT_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Note: this does not properly handle chunks that are > 64K under DOS */ /* Note: this does not properly handle chunks that are > 64K under DOS */
{ {
png_bytep entry_start; png_bytep entry_start;
png_sPLT_t new_palette; png_sPLT_t new_palette;
#ifdef PNG_NO_POINTER_INDEXING #ifdef PNG_POINTER_INDEXING_SUPPORTED
png_sPLT_entryp pp; png_sPLT_entryp pp;
#endif #endif
int data_length, entry_size, i; int data_length, entry_size, i;
@ -1136,7 +1137,6 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_sPLT"); png_debug(1, "in png_handle_sPLT");
if (!(png_ptr->mode & PNG_HAVE_IHDR)) if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before sPLT"); png_error(png_ptr, "Missing IHDR before sPLT");
else if (png_ptr->mode & PNG_HAVE_IDAT) else if (png_ptr->mode & PNG_HAVE_IDAT)
@ -1210,10 +1210,10 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
return; return;
} }
#ifndef PNG_NO_POINTER_INDEXING #ifdef PNG_POINTER_INDEXING_SUPPORTED
for (i = 0; i < new_palette.nentries; i++) for (i = 0; i < new_palette.nentries; i++)
{ {
png_sPLT_entryp pp = new_palette.entries + i; pp = new_palette.entries + i;
if (new_palette.depth == 8) if (new_palette.depth == 8)
{ {
@ -1265,7 +1265,7 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif /* PNG_READ_sPLT_SUPPORTED */ #endif /* PNG_READ_sPLT_SUPPORTED */
#if defined(PNG_READ_tRNS_SUPPORTED) #ifdef PNG_READ_tRNS_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
@ -1360,7 +1360,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_bKGD_SUPPORTED) #ifdef PNG_READ_bKGD_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
@ -1449,7 +1449,7 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_hIST_SUPPORTED) #ifdef PNG_READ_hIST_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
@ -1503,7 +1503,7 @@ png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_pHYs_SUPPORTED) #ifdef PNG_READ_pHYs_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
@ -1546,7 +1546,7 @@ png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_oFFs_SUPPORTED) #ifdef PNG_READ_oFFs_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
@ -1589,7 +1589,7 @@ png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_pCAL_SUPPORTED) #ifdef PNG_READ_pCAL_SUPPORTED
/* Read the pCAL chunk (described in the PNG Extensions document) */ /* Read the pCAL chunk (described in the PNG Extensions document) */
void /* PRIVATE */ void /* PRIVATE */
png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
@ -1723,7 +1723,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_sCAL_SUPPORTED) #ifdef PNG_READ_sCAL_SUPPORTED
/* Read the sCAL chunk */ /* Read the sCAL chunk */
void /* PRIVATE */ void /* PRIVATE */
png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
@ -1866,7 +1866,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_tIME_SUPPORTED) #ifdef PNG_READ_tIME_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
@ -1909,7 +1909,7 @@ png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_tEXt_SUPPORTED) #ifdef PNG_READ_tEXt_SUPPORTED
/* Note: this does not properly handle chunks that are > 64K under DOS */ /* Note: this does not properly handle chunks that are > 64K under DOS */
void /* PRIVATE */ void /* PRIVATE */
png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
@ -1923,7 +1923,6 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_tEXt"); png_debug(1, "in png_handle_tEXt");
if (!(png_ptr->mode & PNG_HAVE_IHDR)) if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before tEXt"); png_error(png_ptr, "Missing IHDR before tEXt");
@ -1996,7 +1995,7 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_zTXt_SUPPORTED) #ifdef PNG_READ_zTXt_SUPPORTED
/* Note: this does not correctly handle chunks that are > 64K under DOS */ /* Note: this does not correctly handle chunks that are > 64K under DOS */
void /* PRIVATE */ void /* PRIVATE */
png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
@ -2009,7 +2008,6 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_zTXt"); png_debug(1, "in png_handle_zTXt");
if (!(png_ptr->mode & PNG_HAVE_IHDR)) if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before zTXt"); png_error(png_ptr, "Missing IHDR before zTXt");
@ -2100,7 +2098,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
#if defined(PNG_READ_iTXt_SUPPORTED) #ifdef PNG_READ_iTXt_SUPPORTED
/* Note: this does not correctly handle chunks that are > 64K under DOS */ /* Note: this does not correctly handle chunks that are > 64K under DOS */
void /* PRIVATE */ void /* PRIVATE */
png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
@ -2114,7 +2112,6 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_iTXt"); png_debug(1, "in png_handle_iTXt");
if (!(png_ptr->mode & PNG_HAVE_IHDR)) if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before iTXt"); png_error(png_ptr, "Missing IHDR before iTXt");
@ -2242,7 +2239,6 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_unknown"); png_debug(1, "in png_handle_unknown");
if (png_ptr->mode & PNG_HAVE_IDAT) if (png_ptr->mode & PNG_HAVE_IDAT)
{ {
#ifdef PNG_USE_LOCAL_ARRAYS #ifdef PNG_USE_LOCAL_ARRAYS
@ -2254,10 +2250,10 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (!(png_ptr->chunk_name[0] & 0x20)) if (!(png_ptr->chunk_name[0] & 0x20))
{ {
#if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
PNG_HANDLE_CHUNK_ALWAYS PNG_HANDLE_CHUNK_ALWAYS
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
&& png_ptr->read_user_chunk_fn == NULL && png_ptr->read_user_chunk_fn == NULL
#endif #endif
) )
@ -2265,9 +2261,9 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_chunk_error(png_ptr, "unknown critical chunk"); png_chunk_error(png_ptr, "unknown critical chunk");
} }
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|| (png_ptr->read_user_chunk_fn != NULL) || (png_ptr->read_user_chunk_fn != NULL)
#endif #endif
) )
@ -2292,7 +2288,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length); png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
} }
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
if (png_ptr->read_user_chunk_fn != NULL) if (png_ptr->read_user_chunk_fn != NULL)
{ {
/* Callback to user unknown chunk handler */ /* Callback to user unknown chunk handler */
@ -2304,7 +2300,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (ret == 0) if (ret == 0)
{ {
if (!(png_ptr->chunk_name[0] & 0x20)) if (!(png_ptr->chunk_name[0] & 0x20))
#if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
PNG_HANDLE_CHUNK_ALWAYS) PNG_HANDLE_CHUNK_ALWAYS)
#endif #endif
@ -2325,7 +2321,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_finish(png_ptr, skip); png_crc_finish(png_ptr, skip);
#if !defined(PNG_READ_USER_CHUNKS_SUPPORTED) #ifndef PNG_READ_USER_CHUNKS_SUPPORTED
info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */ info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */
#endif #endif
} }
@ -2383,7 +2379,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
png_uint_32 i; png_uint_32 i;
png_uint_32 row_width = png_ptr->width; png_uint_32 row_width = png_ptr->width;
#if defined(PNG_READ_PACKSWAP_SUPPORTED) #ifdef PNG_READ_PACKSWAP_SUPPORTED
if (png_ptr->transformations & PNG_PACKSWAP) if (png_ptr->transformations & PNG_PACKSWAP)
{ {
s_start = 0; s_start = 0;
@ -2438,7 +2434,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
png_uint_32 row_width = png_ptr->width; png_uint_32 row_width = png_ptr->width;
int value; int value;
#if defined(PNG_READ_PACKSWAP_SUPPORTED) #ifdef PNG_READ_PACKSWAP_SUPPORTED
if (png_ptr->transformations & PNG_PACKSWAP) if (png_ptr->transformations & PNG_PACKSWAP)
{ {
s_start = 0; s_start = 0;
@ -2490,7 +2486,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
png_uint_32 row_width = png_ptr->width; png_uint_32 row_width = png_ptr->width;
int value; int value;
#if defined(PNG_READ_PACKSWAP_SUPPORTED) #ifdef PNG_READ_PACKSWAP_SUPPORTED
if (png_ptr->transformations & PNG_PACKSWAP) if (png_ptr->transformations & PNG_PACKSWAP)
{ {
s_start = 0; s_start = 0;
@ -2573,11 +2569,9 @@ png_do_read_interlace(png_structp png_ptr)
png_bytep row = png_ptr->row_buf + 1; png_bytep row = png_ptr->row_buf + 1;
int pass = png_ptr->pass; int pass = png_ptr->pass;
png_uint_32 transformations = png_ptr->transformations; png_uint_32 transformations = png_ptr->transformations;
#ifdef PNG_USE_LOCAL_ARRAYS
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* Offset to next interlace block */ /* Offset to next interlace block */
PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
#endif
png_debug(1, "in png_do_read_interlace"); png_debug(1, "in png_do_read_interlace");
if (row != NULL && row_info != NULL) if (row != NULL && row_info != NULL)
@ -2599,7 +2593,7 @@ png_do_read_interlace(png_structp png_ptr)
png_uint_32 i; png_uint_32 i;
int j; int j;
#if defined(PNG_READ_PACKSWAP_SUPPORTED) #ifdef PNG_READ_PACKSWAP_SUPPORTED
if (transformations & PNG_PACKSWAP) if (transformations & PNG_PACKSWAP)
{ {
sshift = (int)((row_info->width + 7) & 0x07); sshift = (int)((row_info->width + 7) & 0x07);
@ -2652,7 +2646,7 @@ png_do_read_interlace(png_structp png_ptr)
int jstop = png_pass_inc[pass]; int jstop = png_pass_inc[pass];
png_uint_32 i; png_uint_32 i;
#if defined(PNG_READ_PACKSWAP_SUPPORTED) #ifdef PNG_READ_PACKSWAP_SUPPORTED
if (transformations & PNG_PACKSWAP) if (transformations & PNG_PACKSWAP)
{ {
sshift = (int)(((row_info->width + 3) & 0x03) << 1); sshift = (int)(((row_info->width + 3) & 0x03) << 1);
@ -2708,7 +2702,7 @@ png_do_read_interlace(png_structp png_ptr)
png_uint_32 i; png_uint_32 i;
int jstop = png_pass_inc[pass]; int jstop = png_pass_inc[pass];
#if defined(PNG_READ_PACKSWAP_SUPPORTED) #ifdef PNG_READ_PACKSWAP_SUPPORTED
if (transformations & PNG_PACKSWAP) if (transformations & PNG_PACKSWAP)
{ {
sshift = (int)(((row_info->width + 1) & 0x01) << 2); sshift = (int)(((row_info->width + 1) & 0x01) << 2);
@ -2782,7 +2776,7 @@ png_do_read_interlace(png_structp png_ptr)
row_info->width = final_width; row_info->width = final_width;
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width); row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width);
} }
#if !defined(PNG_READ_PACKSWAP_SUPPORTED) #ifndef PNG_READ_PACKSWAP_SUPPORTED
transformations = transformations; /* Silence compiler warning */ transformations = transformations; /* Silence compiler warning */
#endif #endif
} }
@ -2911,11 +2905,10 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
} }
} }
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_read_finish_row(png_structp png_ptr) png_read_finish_row(png_structp png_ptr)
{ {
#ifdef PNG_USE_LOCAL_ARRAYS
#ifdef PNG_READ_INTERLACING_SUPPORTED #ifdef PNG_READ_INTERLACING_SUPPORTED
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
@ -2931,7 +2924,6 @@ png_read_finish_row(png_structp png_ptr)
/* Offset to next interlace block in the y direction */ /* Offset to next interlace block in the y direction */
PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
#endif /* PNG_READ_INTERLACING_SUPPORTED */ #endif /* PNG_READ_INTERLACING_SUPPORTED */
#endif
png_debug(1, "in png_read_finish_row"); png_debug(1, "in png_read_finish_row");
png_ptr->row_number++; png_ptr->row_number++;
@ -3043,12 +3035,11 @@ png_read_finish_row(png_structp png_ptr)
png_ptr->mode |= PNG_AFTER_IDAT; png_ptr->mode |= PNG_AFTER_IDAT;
} }
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
void /* PRIVATE */ void /* PRIVATE */
png_read_start_row(png_structp png_ptr) png_read_start_row(png_structp png_ptr)
{ {
#ifdef PNG_USE_LOCAL_ARRAYS
#ifdef PNG_READ_INTERLACING_SUPPORTED #ifdef PNG_READ_INTERLACING_SUPPORTED
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
@ -3063,7 +3054,6 @@ png_read_start_row(png_structp png_ptr)
/* Offset to next interlace block in the y direction */ /* Offset to next interlace block in the y direction */
PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
#endif
#endif #endif
int max_pixel_depth; int max_pixel_depth;
@ -3098,12 +3088,12 @@ png_read_start_row(png_structp png_ptr)
} }
max_pixel_depth = png_ptr->pixel_depth; max_pixel_depth = png_ptr->pixel_depth;
#if defined(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;
#endif #endif
#if defined(PNG_READ_EXPAND_SUPPORTED) #ifdef PNG_READ_EXPAND_SUPPORTED
if (png_ptr->transformations & PNG_EXPAND) if (png_ptr->transformations & PNG_EXPAND)
{ {
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
@ -3131,7 +3121,7 @@ png_read_start_row(png_structp png_ptr)
} }
#endif #endif
#if defined(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_PALETTE)
@ -3153,14 +3143,14 @@ png_read_start_row(png_structp png_ptr)
} }
#endif #endif
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
if (png_ptr->transformations & PNG_GRAY_TO_RGB) if (png_ptr->transformations & PNG_GRAY_TO_RGB)
{ {
if ( if (
#if defined(PNG_READ_EXPAND_SUPPORTED) #ifdef PNG_READ_EXPAND_SUPPORTED
(png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) || (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
#endif #endif
#if defined(PNG_READ_FILLER_SUPPORTED) #ifdef PNG_READ_FILLER_SUPPORTED
(png_ptr->transformations & (PNG_FILLER)) || (png_ptr->transformations & (PNG_FILLER)) ||
#endif #endif
png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
@ -3215,9 +3205,15 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if (row_bytes + 64 > png_ptr->old_big_row_buf_size) if (row_bytes + 64 > 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_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 64);
if (png_ptr->interlaced) if (png_ptr->interlaced)
png_memset(png_ptr->big_row_buf, 0, row_bytes + 64); png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
row_bytes + 64);
else
png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr,
row_bytes + 64);
png_ptr->old_big_row_buf_size = row_bytes + 64;
/* Use 32 bytes of padding before and after row_buf. */
png_ptr->row_buf = png_ptr->big_row_buf + 32; png_ptr->row_buf = png_ptr->big_row_buf + 32;
png_ptr->old_big_row_buf_size = row_bytes + 64; png_ptr->old_big_row_buf_size = row_bytes + 64;
} }

View file

@ -1,8 +1,8 @@
/* pngset.c - storage of image information into info struct /* pngset.c - storage of image information into info struct
* *
* Last changed in libpng 1.2.40 [September 10, 2009] * Last changed in libpng 1.2.42 [January 3, 2010]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2010 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.)
* *
@ -17,10 +17,11 @@
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#if defined(PNG_bKGD_SUPPORTED) #ifdef PNG_bKGD_SUPPORTED
void PNGAPI void PNGAPI
png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background) png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
{ {
@ -34,7 +35,7 @@ png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
} }
#endif #endif
#if defined(PNG_cHRM_SUPPORTED) #ifdef PNG_cHRM_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
void PNGAPI void PNGAPI
png_set_cHRM(png_structp png_ptr, png_infop info_ptr, png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
@ -80,7 +81,7 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
#if !defined(PNG_NO_CHECK_cHRM) #ifdef PNG_CHECK_cHRM_SUPPORTED
if (png_check_cHRM_fixed(png_ptr, if (png_check_cHRM_fixed(png_ptr,
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y)) white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
#endif #endif
@ -109,7 +110,7 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
#endif /* PNG_FIXED_POINT_SUPPORTED */ #endif /* PNG_FIXED_POINT_SUPPORTED */
#endif /* PNG_cHRM_SUPPORTED */ #endif /* PNG_cHRM_SUPPORTED */
#if defined(PNG_gAMA_SUPPORTED) #ifdef PNG_gAMA_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
void PNGAPI void PNGAPI
png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
@ -176,7 +177,7 @@ png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
} }
#endif #endif
#if defined(PNG_hIST_SUPPORTED) #ifdef PNG_hIST_SUPPORTED
void PNGAPI void PNGAPI
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
{ {
@ -233,82 +234,18 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
/* Check for width and height valid values */
if (width == 0 || height == 0)
png_error(png_ptr, "Image width or height is zero in IHDR");
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
png_error(png_ptr, "image size exceeds user limits in IHDR");
#else
if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
png_error(png_ptr, "image size exceeds user limits in IHDR");
#endif
if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
png_error(png_ptr, "Invalid image size in IHDR");
if ( width > (PNG_UINT_32_MAX
>> 3) /* 8-byte RGBA pixels */
- 64 /* bigrowbuf hack */
- 1 /* filter byte */
- 7*8 /* rounding of width to multiple of 8 pixels */
- 8) /* extra max_pixel_depth pad */
png_warning(png_ptr, "Width is too large for libpng to process pixels");
/* Check other values */
if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
bit_depth != 8 && bit_depth != 16)
png_error(png_ptr, "Invalid bit depth in IHDR");
if (color_type < 0 || color_type == 1 ||
color_type == 5 || color_type > 6)
png_error(png_ptr, "Invalid color type in IHDR");
if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
((color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
if (interlace_type >= PNG_INTERLACE_LAST)
png_error(png_ptr, "Unknown interlace method in IHDR");
if (compression_type != PNG_COMPRESSION_TYPE_BASE)
png_error(png_ptr, "Unknown compression method in IHDR");
#if defined(PNG_MNG_FEATURES_SUPPORTED)
/* Accept filter_method 64 (intrapixel differencing) only if
* 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
* 2. Libpng did not read a PNG signature (this filter_method is only
* used in PNG datastreams that are embedded in MNG datastreams) and
* 3. The application called png_permit_mng_features with a mask that
* included PNG_FLAG_MNG_FILTER_64 and
* 4. The filter_method is 64 and
* 5. The color_type is RGB or RGBA
*/
if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
if (filter_type != PNG_FILTER_TYPE_BASE)
{
if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
(color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
png_error(png_ptr, "Unknown filter method in IHDR");
if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
png_warning(png_ptr, "Invalid filter method in IHDR");
}
#else
if (filter_type != PNG_FILTER_TYPE_BASE)
png_error(png_ptr, "Unknown filter method in IHDR");
#endif
info_ptr->width = width; info_ptr->width = width;
info_ptr->height = height; info_ptr->height = height;
info_ptr->bit_depth = (png_byte)bit_depth; info_ptr->bit_depth = (png_byte)bit_depth;
info_ptr->color_type =(png_byte) color_type; info_ptr->color_type = (png_byte)color_type;
info_ptr->compression_type = (png_byte)compression_type; info_ptr->compression_type = (png_byte)compression_type;
info_ptr->filter_type = (png_byte)filter_type; info_ptr->filter_type = (png_byte)filter_type;
info_ptr->interlace_type = (png_byte)interlace_type; info_ptr->interlace_type = (png_byte)interlace_type;
png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
info_ptr->compression_type, info_ptr->filter_type);
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
info_ptr->channels = 1; info_ptr->channels = 1;
else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
@ -331,7 +268,7 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
} }
#if defined(PNG_oFFs_SUPPORTED) #ifdef PNG_oFFs_SUPPORTED
void PNGAPI void PNGAPI
png_set_oFFs(png_structp png_ptr, png_infop info_ptr, png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
png_int_32 offset_x, png_int_32 offset_y, int unit_type) png_int_32 offset_x, png_int_32 offset_y, int unit_type)
@ -348,7 +285,7 @@ png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_pCAL_SUPPORTED) #ifdef PNG_pCAL_SUPPORTED
void PNGAPI void PNGAPI
png_set_pCAL(png_structp png_ptr, png_infop info_ptr, png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
@ -487,7 +424,7 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
#endif #endif
#endif #endif
#if defined(PNG_pHYs_SUPPORTED) #ifdef PNG_pHYs_SUPPORTED
void PNGAPI void PNGAPI
png_set_pHYs(png_structp png_ptr, png_infop info_ptr, png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 res_x, png_uint_32 res_y, int unit_type) png_uint_32 res_x, png_uint_32 res_y, int unit_type)
@ -525,8 +462,7 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
} }
} }
/* /* It may not actually be necessary to set png_ptr->palette here;
* It may not actually be necessary to set png_ptr->palette here;
* we do it for backward compatibility with the way the png_handle_tRNS * we do it for backward compatibility with the way the png_handle_tRNS
* function used to do the allocation. * function used to do the allocation.
*/ */
@ -538,10 +474,8 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
* of num_palette entries, in case of an invalid PNG file that has * of num_palette entries, in case of an invalid PNG file that has
* too-large sample values. * too-large sample values.
*/ */
png_ptr->palette = (png_colorp)png_malloc(png_ptr, png_ptr->palette = (png_colorp)png_calloc(png_ptr,
PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
png_sizeof(png_color));
png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color)); png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
info_ptr->palette = png_ptr->palette; info_ptr->palette = png_ptr->palette;
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
@ -555,7 +489,7 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
info_ptr->valid |= PNG_INFO_PLTE; info_ptr->valid |= PNG_INFO_PLTE;
} }
#if defined(PNG_sBIT_SUPPORTED) #ifdef PNG_sBIT_SUPPORTED
void PNGAPI void PNGAPI
png_set_sBIT(png_structp png_ptr, png_infop info_ptr, png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
png_color_8p sig_bit) png_color_8p sig_bit)
@ -570,7 +504,7 @@ png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_sRGB_SUPPORTED) #ifdef PNG_sRGB_SUPPORTED
void PNGAPI void PNGAPI
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent) png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
{ {
@ -587,7 +521,7 @@ void PNGAPI
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
int intent) int intent)
{ {
#if defined(PNG_gAMA_SUPPORTED) #ifdef PNG_gAMA_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
float file_gamma; float file_gamma;
#endif #endif
@ -595,7 +529,7 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
png_fixed_point int_file_gamma; png_fixed_point int_file_gamma;
#endif #endif
#endif #endif
#if defined(PNG_cHRM_SUPPORTED) #ifdef PNG_cHRM_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
#endif #endif
@ -609,7 +543,7 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
png_set_sRGB(png_ptr, info_ptr, intent); png_set_sRGB(png_ptr, info_ptr, intent);
#if defined(PNG_gAMA_SUPPORTED) #ifdef PNG_gAMA_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
file_gamma = (float).45455; file_gamma = (float).45455;
png_set_gAMA(png_ptr, info_ptr, file_gamma); png_set_gAMA(png_ptr, info_ptr, file_gamma);
@ -620,7 +554,7 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
#endif #endif
#endif #endif
#if defined(PNG_cHRM_SUPPORTED) #ifdef PNG_cHRM_SUPPORTED
int_white_x = 31270L; int_white_x = 31270L;
int_white_y = 32900L; int_white_y = 32900L;
int_red_x = 64000L; int_red_x = 64000L;
@ -641,12 +575,6 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
blue_y = (float).06; blue_y = (float).06;
#endif #endif
#if !defined(PNG_NO_CHECK_cHRM)
if (png_check_cHRM_fixed(png_ptr,
int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
int_green_y, int_blue_x, int_blue_y))
#endif
{
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
png_set_cHRM_fixed(png_ptr, info_ptr, png_set_cHRM_fixed(png_ptr, info_ptr,
int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
@ -656,13 +584,12 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
png_set_cHRM(png_ptr, info_ptr, png_set_cHRM(png_ptr, info_ptr,
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
#endif #endif
}
#endif /* cHRM */ #endif /* cHRM */
} }
#endif /* sRGB */ #endif /* sRGB */
#if defined(PNG_iCCP_SUPPORTED) #ifdef PNG_iCCP_SUPPORTED
void PNGAPI void PNGAPI
png_set_iCCP(png_structp png_ptr, png_infop info_ptr, png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
png_charp name, int compression_type, png_charp name, int compression_type,
@ -701,7 +628,8 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
info_ptr->iccp_name = new_iccp_name; info_ptr->iccp_name = new_iccp_name;
info_ptr->iccp_profile = new_iccp_profile; info_ptr->iccp_profile = new_iccp_profile;
/* Compression is always zero but is here so the API and info structure /* Compression is always zero but is here so the API and info structure
* does not have to change if we introduce multiple compression types */ * does not have to change if we introduce multiple compression types
*/
info_ptr->iccp_compression = (png_byte)compression_type; info_ptr->iccp_compression = (png_byte)compression_type;
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_ICCP; info_ptr->free_me |= PNG_FREE_ICCP;
@ -710,7 +638,7 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_TEXT_SUPPORTED) #ifdef PNG_TEXT_SUPPORTED
void PNGAPI void PNGAPI
png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
int num_text) int num_text)
@ -789,10 +717,12 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
lang_len = 0; lang_len = 0;
lang_key_len = 0; lang_key_len = 0;
} }
else else
#ifdef PNG_iTXt_SUPPORTED #ifdef PNG_iTXt_SUPPORTED
{ {
/* Set iTXt data */ /* Set iTXt data */
if (text_ptr[i].lang != NULL) if (text_ptr[i].lang != NULL)
lang_len = png_strlen(text_ptr[i].lang); lang_len = png_strlen(text_ptr[i].lang);
else else
@ -802,7 +732,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
else else
lang_key_len = 0; lang_key_len = 0;
} }
#else #else /* PNG_iTXt_SUPPORTED */
{ {
png_warning(png_ptr, "iTXt chunk not supported."); png_warning(png_ptr, "iTXt chunk not supported.");
continue; continue;
@ -819,6 +749,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
#endif #endif
textp->compression = PNG_TEXT_COMPRESSION_NONE; textp->compression = PNG_TEXT_COMPRESSION_NONE;
} }
else else
{ {
text_length = png_strlen(text_ptr[i].text); text_length = png_strlen(text_ptr[i].text);
@ -870,6 +801,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
} }
else else
#endif #endif
{ {
textp->text_length = text_length; textp->text_length = text_length;
#ifdef PNG_iTXt_SUPPORTED #ifdef PNG_iTXt_SUPPORTED
@ -883,7 +815,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
} }
#endif #endif
#if defined(PNG_tIME_SUPPORTED) #ifdef PNG_tIME_SUPPORTED
void PNGAPI void PNGAPI
png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
{ {
@ -898,7 +830,7 @@ png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
} }
#endif #endif
#if defined(PNG_tRNS_SUPPORTED) #ifdef PNG_tRNS_SUPPORTED
void PNGAPI void PNGAPI
png_set_tRNS(png_structp png_ptr, png_infop info_ptr, png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
png_bytep trans, int num_trans, png_color_16p trans_values) png_bytep trans, int num_trans, png_color_16p trans_values)
@ -910,8 +842,7 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
if (trans != NULL) if (trans != NULL)
{ {
/* /* It may not actually be necessary to set png_ptr->trans here;
* It may not actually be necessary to set png_ptr->trans here;
* we do it for backward compatibility with the way the png_handle_tRNS * we do it for backward compatibility with the way the png_handle_tRNS
* function used to do the allocation. * function used to do the allocation.
*/ */
@ -957,7 +888,7 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_sPLT_SUPPORTED) #ifdef PNG_sPLT_SUPPORTED
void PNGAPI void PNGAPI
png_set_sPLT(png_structp png_ptr, png_set_sPLT(png_structp png_ptr,
png_infop info_ptr, png_sPLT_tp entries, int nentries) png_infop info_ptr, png_sPLT_tp entries, int nentries)
@ -1029,7 +960,7 @@ png_set_sPLT(png_structp png_ptr,
} }
#endif /* PNG_sPLT_SUPPORTED */ #endif /* PNG_sPLT_SUPPORTED */
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
void PNGAPI void PNGAPI
png_set_unknown_chunks(png_structp png_ptr, png_set_unknown_chunks(png_structp png_ptr,
png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns) png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
@ -1053,15 +984,14 @@ png_set_unknown_chunks(png_structp png_ptr,
png_memcpy(np, info_ptr->unknown_chunks, png_memcpy(np, info_ptr->unknown_chunks,
info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk)); info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
png_free(png_ptr, info_ptr->unknown_chunks); png_free(png_ptr, info_ptr->unknown_chunks);
info_ptr->unknown_chunks=NULL; info_ptr->unknown_chunks = NULL;
for (i = 0; i < num_unknowns; i++) for (i = 0; i < num_unknowns; i++)
{ {
png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i; png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
png_unknown_chunkp from = unknowns + i; png_unknown_chunkp from = unknowns + i;
png_memcpy((png_charp)to->name, png_memcpy((png_charp)to->name, (png_charp)from->name,
(png_charp)from->name,
png_sizeof(from->name)); png_sizeof(from->name));
to->name[png_sizeof(to->name)-1] = '\0'; to->name[png_sizeof(to->name)-1] = '\0';
to->size = from->size; to->size = from->size;
@ -1121,7 +1051,7 @@ png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
#endif #endif
#endif #endif
#if defined(PNG_MNG_FEATURES_SUPPORTED) #ifdef PNG_MNG_FEATURES_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features) png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
{ {
@ -1135,7 +1065,7 @@ png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
} }
#endif #endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
void PNGAPI void PNGAPI
png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
chunk_list, int num_chunks) chunk_list, int num_chunks)
@ -1182,7 +1112,7 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
} }
#endif #endif
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
void PNGAPI void PNGAPI
png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
png_user_chunk_ptr read_user_chunk_fn) png_user_chunk_ptr read_user_chunk_fn)
@ -1197,7 +1127,7 @@ png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
} }
#endif #endif
#if defined(PNG_INFO_IMAGE_SUPPORTED) #ifdef PNG_INFO_IMAGE_SUPPORTED
void PNGAPI void PNGAPI
png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
{ {
@ -1281,5 +1211,18 @@ png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
} }
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
void PNGAPI
png_set_benign_errors(png_structp png_ptr, int allowed)
{
png_debug(1, "in png_set_benign_errors");
if (allowed)
png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
else
png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
}
#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
#endif /* ?PNG_1_0_X */ #endif /* ?PNG_1_0_X */
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */

View file

@ -1,7 +1,7 @@
/* pngtest.c - a simple test program to test libpng /* pngtest.c - a simple test program to test libpng
* *
* Last changed in libpng 1.2.37 [June 4, 2009] * Last changed in libpng 1.2.41 [December 3, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 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.)
@ -31,9 +31,10 @@
* of files at once by typing "pngtest -m file1.png file2.png ..." * of files at once by typing "pngtest -m file1.png file2.png ..."
*/ */
#define PNG_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
# if _WIN32_WCE < 211 # if _WIN32_WCE < 211
__error__ (f|w)printf functions are not supported on old WindowsCE.; __error__ (f|w)printf functions are not supported on old WindowsCE.;
# endif # endif
@ -54,8 +55,8 @@
# define FCLOSE(file) fclose(file) # define FCLOSE(file) fclose(file)
#endif #endif
#if defined(PNG_NO_STDIO) #ifndef PNG_STDIO_SUPPORTED
# if defined(_WIN32_WCE) # ifdef _WIN32_WCE
typedef HANDLE png_FILE_p; typedef HANDLE png_FILE_p;
# else # else
typedef FILE * png_FILE_p; typedef FILE * png_FILE_p;
@ -75,7 +76,7 @@
#define PNGTEST_TIMING #define PNGTEST_TIMING
*/ */
#ifdef PNG_NO_FLOATING_POINT_SUPPORTED #ifndef PNG_FLOATING_POINT_SUPPORTED
#undef PNGTEST_TIMING #undef PNGTEST_TIMING
#endif #endif
@ -84,7 +85,7 @@ static float t_start, t_stop, t_decode, t_encode, t_misc;
#include <time.h> #include <time.h>
#endif #endif
#if defined(PNG_TIME_RFC1123_SUPPORTED) #ifdef PNG_TIME_RFC1123_SUPPORTED
#define PNG_tIME_STRING_LENGTH 29 #define PNG_tIME_STRING_LENGTH 29
static int tIME_chunk_present = 0; static int tIME_chunk_present = 0;
static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present"; static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";
@ -162,7 +163,7 @@ write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
} }
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
/* Example of using user transform callback (we don't transform anything, /* Example of using user transform callback (we don't transform anything,
* but merely examine the row filters. We set this to 256 rather than * but merely examine the row filters. We set this to 256 rather than
* 5 in case illegal filter values are present.) * 5 in case illegal filter values are present.)
@ -184,7 +185,7 @@ count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
} }
#endif #endif
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
/* Example of using user transform callback (we don't transform anything, /* Example of using user transform callback (we don't transform anything,
* but merely count the zero samples) * but merely count the zero samples)
*/ */
@ -297,7 +298,7 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
static int wrote_question = 0; static int wrote_question = 0;
#if defined(PNG_NO_STDIO) #ifndef PNG_STDIO_SUPPORTED
/* START of code to validate stdio-free compilation */ /* START of code to validate stdio-free compilation */
/* These copies of the default read/write functions come from pngrio.c and /* These copies of the default read/write functions come from pngrio.c and
* pngwio.c. They allow "don't include stdio" testing of the library. * pngwio.c. They allow "don't include stdio" testing of the library.
@ -311,12 +312,17 @@ static int wrote_question = 0;
static void static void
pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
png_size_t check; png_size_t check = 0;
png_voidp io_ptr;
/* fread() returns 0 on error, so it is OK to store this in a png_size_t /* fread() returns 0 on error, so it is OK to store this in a png_size_t
* instead of an int, which is what fread() actually returns. * instead of an int, which is what fread() actually returns.
*/ */
READFILE((png_FILE_p)png_ptr->io_ptr, data, length, check); io_ptr = png_get_io_ptr(png_ptr);
if (io_ptr != NULL)
{
READFILE((png_FILE_p)io_ptr, data, length, check);
}
if (check != length) if (check != length)
{ {
@ -371,7 +377,7 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
} }
#endif /* USE_FAR_KEYWORD */ #endif /* USE_FAR_KEYWORD */
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #ifdef PNG_WRITE_FLUSH_SUPPORTED
static void static void
pngtest_flush(png_structp png_ptr) pngtest_flush(png_structp png_ptr)
{ {
@ -456,9 +462,12 @@ static void
pngtest_warning(png_structp png_ptr, png_const_charp message) pngtest_warning(png_structp png_ptr, png_const_charp message)
{ {
PNG_CONST char *name = "UNKNOWN (ERROR!)"; PNG_CONST char *name = "UNKNOWN (ERROR!)";
if (png_ptr != NULL && png_ptr->error_ptr != NULL) char *test;
name = png_ptr->error_ptr; test = png_get_error_ptr(png_ptr);
if (test == NULL)
fprintf(STDERR, "%s: libpng warning: %s\n", name, message); fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
else
fprintf(STDERR, "%s: libpng warning: %s\n", test, message);
} }
/* This is the default error handling function. Note that replacements for /* This is the default error handling function. Note that replacements for
@ -474,7 +483,7 @@ pngtest_error(png_structp png_ptr, png_const_charp message)
* actually OK in this case. * actually OK in this case.
*/ */
} }
#endif /* PNG_NO_STDIO */ #endif /* !PNG_STDIO_SUPPORTED */
/* END of code to validate stdio-free compilation */ /* END of code to validate stdio-free compilation */
/* START of code to validate memory allocation and deallocation */ /* START of code to validate memory allocation and deallocation */
@ -607,7 +616,7 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
/* Demonstration of user chunk support of the sTER and vpAg chunks */ /* Demonstration of user chunk support of the sTER and vpAg chunks */
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
/* (sTER is a public chunk not yet known by libpng. vpAg is a private /* (sTER is a public chunk not yet known by libpng. vpAg is a private
chunk used in ImageMagick to store "virtual page" size). */ chunk used in ImageMagick to store "virtual page" size). */
@ -701,14 +710,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif #endif
#endif #endif
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
TCHAR path[MAX_PATH]; TCHAR path[MAX_PATH];
#endif #endif
char inbuf[256], outbuf[256]; char inbuf[256], outbuf[256];
row_buf = NULL; row_buf = NULL;
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH);
if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
#else #else
@ -719,7 +728,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
return (1); return (1);
} }
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH);
if ((fpout = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL)) == INVALID_HANDLE_VALUE) if ((fpout = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL)) == INVALID_HANDLE_VALUE)
#else #else
@ -742,12 +751,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_create_read_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL, png_create_read_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
png_error_ptr_NULL, png_error_ptr_NULL); png_error_ptr_NULL, png_error_ptr_NULL);
#endif #endif
#if defined(PNG_NO_STDIO) #ifndef PNG_STDIO_SUPPORTED
png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error, png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error,
pngtest_warning); pngtest_warning);
#endif #endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
user_chunk_data[0] = 0; user_chunk_data[0] = 0;
user_chunk_data[1] = 0; user_chunk_data[1] = 0;
user_chunk_data[2] = 0; user_chunk_data[2] = 0;
@ -767,7 +776,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_create_write_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL, png_create_write_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
png_error_ptr_NULL, png_error_ptr_NULL); png_error_ptr_NULL, png_error_ptr_NULL);
#endif #endif
#if defined(PNG_NO_STDIO) #ifndef PNG_STDIO_SUPPORTED
png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error, png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error,
pngtest_warning); pngtest_warning);
#endif #endif
@ -829,7 +838,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif #endif
png_debug(0, "Initializing input and output streams"); png_debug(0, "Initializing input and output streams");
#if !defined(PNG_NO_STDIO) #ifdef PNG_STDIO_SUPPORTED
png_init_io(read_ptr, fpin); png_init_io(read_ptr, fpin);
# ifdef PNG_WRITE_SUPPORTED # ifdef PNG_WRITE_SUPPORTED
png_init_io(write_ptr, fpout); png_init_io(write_ptr, fpout);
@ -838,7 +847,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data); png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data);
# ifdef PNG_WRITE_SUPPORTED # ifdef PNG_WRITE_SUPPORTED
png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data, png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data,
# if defined(PNG_WRITE_FLUSH_SUPPORTED) # ifdef PNG_WRITE_FLUSH_SUPPORTED
pngtest_flush); pngtest_flush);
# else # else
NULL); NULL);
@ -860,7 +869,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_set_read_status_fn(read_ptr, png_read_status_ptr_NULL); png_set_read_status_fn(read_ptr, png_read_status_ptr_NULL);
} }
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
{ {
int i; int i;
for (i = 0; i<256; i++) for (i = 0; i<256; i++)
@ -868,19 +877,19 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_set_read_user_transform_fn(read_ptr, count_filters); png_set_read_user_transform_fn(read_ptr, count_filters);
} }
#endif #endif
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
zero_samples = 0; zero_samples = 0;
png_set_write_user_transform_fn(write_ptr, count_zero_samples); png_set_write_user_transform_fn(write_ptr, count_zero_samples);
#endif #endif
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
# ifndef PNG_HANDLE_CHUNK_ALWAYS # ifndef PNG_HANDLE_CHUNK_ALWAYS
# define PNG_HANDLE_CHUNK_ALWAYS 3 # define PNG_HANDLE_CHUNK_ALWAYS 3
# endif # endif
png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS,
png_bytep_NULL, 0); png_bytep_NULL, 0);
#endif #endif
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
# ifndef PNG_HANDLE_CHUNK_IF_SAFE # ifndef PNG_HANDLE_CHUNK_IF_SAFE
# define PNG_HANDLE_CHUNK_IF_SAFE 2 # define PNG_HANDLE_CHUNK_IF_SAFE 2
# endif # endif
@ -899,15 +908,15 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
&color_type, &interlace_type, &compression_type, &filter_type)) &color_type, &interlace_type, &compression_type, &filter_type))
{ {
png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth, png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
#if defined(PNG_WRITE_INTERLACING_SUPPORTED) #ifdef PNG_WRITE_INTERLACING_SUPPORTED
color_type, interlace_type, compression_type, filter_type); color_type, interlace_type, compression_type, filter_type);
#else #else
color_type, PNG_INTERLACE_NONE, compression_type, filter_type); color_type, PNG_INTERLACE_NONE, compression_type, filter_type);
#endif #endif
} }
} }
#if defined(PNG_FIXED_POINT_SUPPORTED) #ifdef PNG_FIXED_POINT_SUPPORTED
#if defined(PNG_cHRM_SUPPORTED) #ifdef PNG_cHRM_SUPPORTED
{ {
png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x, png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
blue_y; blue_y;
@ -919,7 +928,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#endif #endif
#if defined(PNG_gAMA_SUPPORTED) #ifdef PNG_gAMA_SUPPORTED
{ {
png_fixed_point gamma; png_fixed_point gamma;
@ -928,8 +937,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
#endif #endif
#else /* Use floating point versions */ #else /* Use floating point versions */
#if defined(PNG_FLOATING_POINT_SUPPORTED) #ifdef PNG_FLOATING_POINT_SUPPORTED
#if defined(PNG_cHRM_SUPPORTED) #ifdef PNG_cHRM_SUPPORTED
{ {
double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, double white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
blue_y; blue_y;
@ -941,7 +950,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#endif #endif
#if defined(PNG_gAMA_SUPPORTED) #ifdef PNG_gAMA_SUPPORTED
{ {
double gamma; double gamma;
@ -951,7 +960,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif #endif
#endif /* Floating point */ #endif /* Floating point */
#endif /* Fixed point */ #endif /* Fixed point */
#if defined(PNG_iCCP_SUPPORTED) #ifdef PNG_iCCP_SUPPORTED
{ {
png_charp name; png_charp name;
png_charp profile; png_charp profile;
@ -966,7 +975,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#endif #endif
#if defined(PNG_sRGB_SUPPORTED) #ifdef PNG_sRGB_SUPPORTED
{ {
int intent; int intent;
@ -981,7 +990,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette)) if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
} }
#if defined(PNG_bKGD_SUPPORTED) #ifdef PNG_bKGD_SUPPORTED
{ {
png_color_16p background; png_color_16p background;
@ -991,7 +1000,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#endif #endif
#if defined(PNG_hIST_SUPPORTED) #ifdef PNG_hIST_SUPPORTED
{ {
png_uint_16p hist; png_uint_16p hist;
@ -999,7 +1008,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_set_hIST(write_ptr, write_info_ptr, hist); png_set_hIST(write_ptr, write_info_ptr, hist);
} }
#endif #endif
#if defined(PNG_oFFs_SUPPORTED) #ifdef PNG_oFFs_SUPPORTED
{ {
png_int_32 offset_x, offset_y; png_int_32 offset_x, offset_y;
int unit_type; int unit_type;
@ -1011,7 +1020,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#endif #endif
#if defined(PNG_pCAL_SUPPORTED) #ifdef PNG_pCAL_SUPPORTED
{ {
png_charp purpose, units; png_charp purpose, units;
png_charpp params; png_charpp params;
@ -1026,7 +1035,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#endif #endif
#if defined(PNG_pHYs_SUPPORTED) #ifdef PNG_pHYs_SUPPORTED
{ {
png_uint_32 res_x, res_y; png_uint_32 res_x, res_y;
int unit_type; int unit_type;
@ -1035,7 +1044,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type); png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
} }
#endif #endif
#if defined(PNG_sBIT_SUPPORTED) #ifdef PNG_sBIT_SUPPORTED
{ {
png_color_8p sig_bit; png_color_8p sig_bit;
@ -1043,7 +1052,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_set_sBIT(write_ptr, write_info_ptr, sig_bit); png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
} }
#endif #endif
#if defined(PNG_sCAL_SUPPORTED) #ifdef PNG_sCAL_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
{ {
int unit; int unit;
@ -1070,7 +1079,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif #endif
#endif #endif
#endif #endif
#if defined(PNG_TEXT_SUPPORTED) #ifdef PNG_TEXT_SUPPORTED
{ {
png_textp text_ptr; png_textp text_ptr;
int num_text; int num_text;
@ -1082,14 +1091,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#endif #endif
#if defined(PNG_tIME_SUPPORTED) #ifdef PNG_tIME_SUPPORTED
{ {
png_timep mod_time; png_timep mod_time;
if (png_get_tIME(read_ptr, read_info_ptr, &mod_time)) if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
{ {
png_set_tIME(write_ptr, write_info_ptr, mod_time); png_set_tIME(write_ptr, write_info_ptr, mod_time);
#if defined(PNG_TIME_RFC1123_SUPPORTED) #ifdef PNG_TIME_RFC1123_SUPPORTED
/* We have to use png_memcpy instead of "=" because the string /* We have to use png_memcpy instead of "=" because the string
* pointed to by png_convert_to_rfc1123() gets free'ed before * pointed to by png_convert_to_rfc1123() gets free'ed before
* we use it. * we use it.
@ -1103,7 +1112,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#endif #endif
#if defined(PNG_tRNS_SUPPORTED) #ifdef PNG_tRNS_SUPPORTED
{ {
png_bytep trans; png_bytep trans;
int num_trans; int num_trans;
@ -1112,11 +1121,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans, if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans,
&trans_values)) &trans_values))
{ {
int sample_max = (1 << read_info_ptr->bit_depth); int sample_max = (1 << bit_depth);
/* libpng doesn't reject a tRNS chunk with out-of-range samples */ /* libpng doesn't reject a tRNS chunk with out-of-range samples */
if (!((read_info_ptr->color_type == PNG_COLOR_TYPE_GRAY && if (!((color_type == PNG_COLOR_TYPE_GRAY &&
(int)trans_values->gray > sample_max) || (int)trans_values->gray > sample_max) ||
(read_info_ptr->color_type == PNG_COLOR_TYPE_RGB && (color_type == PNG_COLOR_TYPE_RGB &&
((int)trans_values->red > sample_max || ((int)trans_values->red > sample_max ||
(int)trans_values->green > sample_max || (int)trans_values->green > sample_max ||
(int)trans_values->blue > sample_max)))) (int)trans_values->blue > sample_max))))
@ -1125,7 +1134,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#endif #endif
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
{ {
png_unknown_chunkp unknowns; png_unknown_chunkp unknowns;
int num_unknowns = (int)png_get_unknown_chunks(read_ptr, read_info_ptr, int num_unknowns = (int)png_get_unknown_chunks(read_ptr, read_info_ptr,
@ -1154,7 +1163,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
*/ */
png_write_info(write_ptr, write_info_ptr); png_write_info(write_ptr, write_info_ptr);
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
if (user_chunk_data[0] != 0) if (user_chunk_data[0] != 0)
{ {
png_byte png_sTER[5] = {115, 84, 69, 82, '\0'}; png_byte png_sTER[5] = {115, 84, 69, 82, '\0'};
@ -1248,17 +1257,17 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1); png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
#endif #endif
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1); png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
#endif #endif
png_debug(0, "Reading and writing end_info data"); png_debug(0, "Reading and writing end_info data");
png_read_end(read_ptr, end_info_ptr); png_read_end(read_ptr, end_info_ptr);
#if defined(PNG_TEXT_SUPPORTED) #ifdef PNG_TEXT_SUPPORTED
{ {
png_textp text_ptr; png_textp text_ptr;
int num_text; int num_text;
@ -1270,14 +1279,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#endif #endif
#if defined(PNG_tIME_SUPPORTED) #ifdef PNG_tIME_SUPPORTED
{ {
png_timep mod_time; png_timep mod_time;
if (png_get_tIME(read_ptr, end_info_ptr, &mod_time)) if (png_get_tIME(read_ptr, end_info_ptr, &mod_time))
{ {
png_set_tIME(write_ptr, write_end_info_ptr, mod_time); png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
#if defined(PNG_TIME_RFC1123_SUPPORTED) #ifdef PNG_TIME_RFC1123_SUPPORTED
/* We have to use png_memcpy instead of "=" because the string /* We have to use png_memcpy instead of "=" because the string
pointed to by png_convert_to_rfc1123() gets free'ed before pointed to by png_convert_to_rfc1123() gets free'ed before
we use it */ we use it */
@ -1290,7 +1299,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#endif #endif
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
{ {
png_unknown_chunkp unknowns; png_unknown_chunkp unknowns;
int num_unknowns; int num_unknowns;
@ -1346,7 +1355,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
FCLOSE(fpout); FCLOSE(fpout);
png_debug(0, "Opening files for comparison"); png_debug(0, "Opening files for comparison");
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH);
if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
#else #else
@ -1357,7 +1366,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
return (1); return (1);
} }
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH);
if ((fpout = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) if ((fpout = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
#else #else
@ -1527,7 +1536,7 @@ main(int argc, char *argv[])
#endif #endif
for (i=2; i<argc; ++i) for (i=2; i<argc; ++i)
{ {
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
int k; int k;
#endif #endif
int kerror; int kerror;
@ -1535,19 +1544,19 @@ main(int argc, char *argv[])
kerror = test_one_file(argv[i], outname); kerror = test_one_file(argv[i], outname);
if (kerror == 0) if (kerror == 0)
{ {
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
fprintf(STDERR, "\n PASS (%lu zero samples)\n", fprintf(STDERR, "\n PASS (%lu zero samples)\n",
(unsigned long)zero_samples); (unsigned long)zero_samples);
#else #else
fprintf(STDERR, " PASS\n"); fprintf(STDERR, " PASS\n");
#endif #endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
for (k = 0; k<256; k++) for (k = 0; k<256; k++)
if (filters_used[k]) if (filters_used[k])
fprintf(STDERR, " Filter %d was used %lu times\n", fprintf(STDERR, " Filter %d was used %lu times\n",
k, (unsigned long)filters_used[k]); k, (unsigned long)filters_used[k]);
#endif #endif
#if defined(PNG_TIME_RFC1123_SUPPORTED) #ifdef PNG_TIME_RFC1123_SUPPORTED
if (tIME_chunk_present != 0) if (tIME_chunk_present != 0)
fprintf(STDERR, " tIME = %s\n", tIME_string); fprintf(STDERR, " tIME = %s\n", tIME_string);
tIME_chunk_present = 0; tIME_chunk_present = 0;
@ -1607,23 +1616,23 @@ main(int argc, char *argv[])
{ {
if (verbose == 1 || i == 2) if (verbose == 1 || i == 2)
{ {
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
int k; int k;
#endif #endif
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
fprintf(STDERR, "\n PASS (%lu zero samples)\n", fprintf(STDERR, "\n PASS (%lu zero samples)\n",
(unsigned long)zero_samples); (unsigned long)zero_samples);
#else #else
fprintf(STDERR, " PASS\n"); fprintf(STDERR, " PASS\n");
#endif #endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
for (k = 0; k<256; k++) for (k = 0; k<256; k++)
if (filters_used[k]) if (filters_used[k])
fprintf(STDERR, " Filter %d was used %lu times\n", fprintf(STDERR, " Filter %d was used %lu times\n",
k, k,
(unsigned long)filters_used[k]); (unsigned long)filters_used[k]);
#endif #endif
#if defined(PNG_TIME_RFC1123_SUPPORTED) #ifdef PNG_TIME_RFC1123_SUPPORTED
if (tIME_chunk_present != 0) if (tIME_chunk_present != 0)
fprintf(STDERR, " tIME = %s\n", tIME_string); fprintf(STDERR, " tIME = %s\n", tIME_string);
#endif /* PNG_TIME_RFC1123_SUPPORTED */ #endif /* PNG_TIME_RFC1123_SUPPORTED */
@ -1689,4 +1698,4 @@ main(int argc, char *argv[])
} }
/* 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 version_1_2_40 your_png_h_is_not_version_1_2_40; typedef version_1_2_42 your_png_h_is_not_version_1_2_42;

View file

@ -1,7 +1,7 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers) /* pngtrans.c - transforms the data in a row (used by both readers and writers)
* *
* Last changed in libpng 1.2.36 [May 14, 2009] * Last changed in libpng 1.2.41 [December 3, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -12,6 +12,7 @@
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
@ -21,6 +22,7 @@ void PNGAPI
png_set_bgr(png_structp png_ptr) png_set_bgr(png_structp png_ptr)
{ {
png_debug(1, "in png_set_bgr"); png_debug(1, "in png_set_bgr");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->transformations |= PNG_BGR; png_ptr->transformations |= PNG_BGR;
@ -33,6 +35,7 @@ void PNGAPI
png_set_swap(png_structp png_ptr) png_set_swap(png_structp png_ptr)
{ {
png_debug(1, "in png_set_swap"); png_debug(1, "in png_set_swap");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
if (png_ptr->bit_depth == 16) if (png_ptr->bit_depth == 16)
@ -46,6 +49,7 @@ void PNGAPI
png_set_packing(png_structp png_ptr) png_set_packing(png_structp png_ptr)
{ {
png_debug(1, "in png_set_packing"); png_debug(1, "in png_set_packing");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
if (png_ptr->bit_depth < 8) if (png_ptr->bit_depth < 8)
@ -62,6 +66,7 @@ void PNGAPI
png_set_packswap(png_structp png_ptr) png_set_packswap(png_structp png_ptr)
{ {
png_debug(1, "in png_set_packswap"); png_debug(1, "in png_set_packswap");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
if (png_ptr->bit_depth < 8) if (png_ptr->bit_depth < 8)
@ -74,6 +79,7 @@ void PNGAPI
png_set_shift(png_structp png_ptr, png_color_8p true_bits) png_set_shift(png_structp png_ptr, png_color_8p true_bits)
{ {
png_debug(1, "in png_set_shift"); png_debug(1, "in png_set_shift");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->transformations |= PNG_SHIFT; png_ptr->transformations |= PNG_SHIFT;
@ -87,6 +93,7 @@ int PNGAPI
png_set_interlace_handling(png_structp png_ptr) png_set_interlace_handling(png_structp png_ptr)
{ {
png_debug(1, "in png_set_interlace handling"); png_debug(1, "in png_set_interlace handling");
if (png_ptr && png_ptr->interlaced) if (png_ptr && png_ptr->interlaced)
{ {
png_ptr->transformations |= PNG_INTERLACE; png_ptr->transformations |= PNG_INTERLACE;
@ -107,10 +114,15 @@ void PNGAPI
png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
{ {
png_debug(1, "in png_set_filler"); png_debug(1, "in png_set_filler");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->transformations |= PNG_FILLER; png_ptr->transformations |= PNG_FILLER;
#ifdef PNG_LEGACY_SUPPORTED
png_ptr->filler = (png_byte)filler; png_ptr->filler = (png_byte)filler;
#else
png_ptr->filler = (png_uint_16)filler;
#endif
if (filler_loc == PNG_FILLER_AFTER) if (filler_loc == PNG_FILLER_AFTER)
png_ptr->flags |= PNG_FLAG_FILLER_AFTER; png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
else else
@ -135,12 +147,13 @@ png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
} }
} }
#if !defined(PNG_1_0_X) #ifndef PNG_1_0_X
/* Added to libpng-1.2.7 */ /* Added to libpng-1.2.7 */
void PNGAPI void PNGAPI
png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
{ {
png_debug(1, "in png_set_add_alpha"); png_debug(1, "in png_set_add_alpha");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_set_filler(png_ptr, filler, filler_loc); png_set_filler(png_ptr, filler, filler_loc);
@ -156,6 +169,7 @@ void PNGAPI
png_set_swap_alpha(png_structp png_ptr) png_set_swap_alpha(png_structp png_ptr)
{ {
png_debug(1, "in png_set_swap_alpha"); png_debug(1, "in png_set_swap_alpha");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->transformations |= PNG_SWAP_ALPHA; png_ptr->transformations |= PNG_SWAP_ALPHA;
@ -168,6 +182,7 @@ void PNGAPI
png_set_invert_alpha(png_structp png_ptr) png_set_invert_alpha(png_structp png_ptr)
{ {
png_debug(1, "in png_set_invert_alpha"); png_debug(1, "in png_set_invert_alpha");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->transformations |= PNG_INVERT_ALPHA; png_ptr->transformations |= PNG_INVERT_ALPHA;
@ -179,6 +194,7 @@ void PNGAPI
png_set_invert_mono(png_structp png_ptr) png_set_invert_mono(png_structp png_ptr)
{ {
png_debug(1, "in png_set_invert_mono"); png_debug(1, "in png_set_invert_mono");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->transformations |= PNG_INVERT_MONO; png_ptr->transformations |= PNG_INVERT_MONO;
@ -189,10 +205,11 @@ void /* PRIVATE */
png_do_invert(png_row_infop row_info, png_bytep row) png_do_invert(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_invert"); png_debug(1, "in png_do_invert");
/* This test removed from libpng version 1.0.13 and 1.2.0: /* This test removed from libpng version 1.0.13 and 1.2.0:
* if (row_info->bit_depth == 1 && * if (row_info->bit_depth == 1 &&
*/ */
#if defined(PNG_USELESS_TESTS_SUPPORTED) #ifdef PNG_USELESS_TESTS_SUPPORTED
if (row == NULL || row_info == NULL) if (row == NULL || row_info == NULL)
return; return;
#endif #endif
@ -244,8 +261,9 @@ void /* PRIVATE */
png_do_swap(png_row_infop row_info, png_bytep row) png_do_swap(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_swap"); png_debug(1, "in png_do_swap");
if ( if (
#if defined(PNG_USELESS_TESTS_SUPPORTED) #ifdef PNG_USELESS_TESTS_SUPPORTED
row != NULL && row_info != NULL && row != NULL && row_info != NULL &&
#endif #endif
row_info->bit_depth == 16) row_info->bit_depth == 16)
@ -375,8 +393,9 @@ void /* PRIVATE */
png_do_packswap(png_row_infop row_info, png_bytep row) png_do_packswap(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_packswap"); png_debug(1, "in png_do_packswap");
if ( if (
#if defined(PNG_USELESS_TESTS_SUPPORTED) #ifdef PNG_USELESS_TESTS_SUPPORTED
row != NULL && row_info != NULL && row != NULL && row_info != NULL &&
#endif #endif
row_info->bit_depth < 8) row_info->bit_depth < 8)
@ -407,7 +426,8 @@ void /* PRIVATE */
png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags) png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
{ {
png_debug(1, "in png_do_strip_filler"); png_debug(1, "in png_do_strip_filler");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
#ifdef PNG_USELESS_TESTS_SUPPORTED
if (row != NULL && row_info != NULL) if (row != NULL && row_info != NULL)
#endif #endif
{ {
@ -565,8 +585,9 @@ void /* PRIVATE */
png_do_bgr(png_row_infop row_info, png_bytep row) png_do_bgr(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_bgr"); png_debug(1, "in png_do_bgr");
if ( if (
#if defined(PNG_USELESS_TESTS_SUPPORTED) #ifdef PNG_USELESS_TESTS_SUPPORTED
row != NULL && row_info != NULL && row != NULL && row_info != NULL &&
#endif #endif
(row_info->color_type & PNG_COLOR_MASK_COLOR)) (row_info->color_type & PNG_COLOR_MASK_COLOR))
@ -644,9 +665,10 @@ png_set_user_transform_info(png_structp png_ptr, png_voidp
user_transform_ptr, int user_transform_depth, int user_transform_channels) user_transform_ptr, int user_transform_depth, int user_transform_channels)
{ {
png_debug(1, "in png_set_user_transform_info"); png_debug(1, "in png_set_user_transform_info");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
png_ptr->user_transform_ptr = user_transform_ptr; png_ptr->user_transform_ptr = user_transform_ptr;
png_ptr->user_transform_depth = (png_byte)user_transform_depth; png_ptr->user_transform_depth = (png_byte)user_transform_depth;
png_ptr->user_transform_channels = (png_byte)user_transform_channels; png_ptr->user_transform_channels = (png_byte)user_transform_channels;
@ -668,7 +690,7 @@ png_get_user_transform_ptr(png_structp png_ptr)
{ {
if (png_ptr == NULL) if (png_ptr == NULL)
return (NULL); return (NULL);
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
return ((png_voidp)png_ptr->user_transform_ptr); return ((png_voidp)png_ptr->user_transform_ptr);
#else #else
return (NULL); return (NULL);

View file

@ -1,7 +1,7 @@
/* pngwio.c - functions for data output /* pngwio.c - functions for data output
* *
* Last changed in libpng 1.2.37 [June 4, 2009] * Last changed in libpng 1.2.41 [December 3, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 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.)
@ -19,6 +19,7 @@
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#ifdef PNG_WRITE_SUPPORTED #ifdef PNG_WRITE_SUPPORTED
@ -38,7 +39,7 @@ png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
png_error(png_ptr, "Call to NULL write function"); png_error(png_ptr, "Call to NULL write function");
} }
#if !defined(PNG_NO_STDIO) #ifdef PNG_STDIO_SUPPORTED
/* This is the function that does the actual writing of data. If you are /* This is the function that does the actual writing of data. If you are
* not writing to a standard C stream, you should create a replacement * not writing to a standard C stream, you should create a replacement
* write_data function and use it at run time with png_set_write_fn(), rather * write_data function and use it at run time with png_set_write_fn(), rather
@ -52,7 +53,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
check = 0; check = 0;
#else #else
@ -84,7 +85,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
if ((png_bytep)near_data == data) if ((png_bytep)near_data == data)
{ {
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
if ( !WriteFile(io_ptr, near_data, length, &check, NULL) ) if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
check = 0; check = 0;
#else #else
@ -101,7 +102,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
written = MIN(NEAR_BUF_SIZE, remaining); written = MIN(NEAR_BUF_SIZE, remaining);
png_memcpy(buf, data, written); /* Copy far buffer to near buffer */ png_memcpy(buf, data, written); /* Copy far buffer to near buffer */
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
if ( !WriteFile(io_ptr, buf, written, &err, NULL) ) if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
err = 0; err = 0;
#else #else
@ -129,7 +130,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
* to disk). After png_flush is called, there should be no data pending * to disk). After png_flush is called, there should be no data pending
* writing in any buffers. * writing in any buffers.
*/ */
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #ifdef PNG_WRITE_FLUSH_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_flush(png_structp png_ptr) png_flush(png_structp png_ptr)
{ {
@ -137,16 +138,16 @@ png_flush(png_structp png_ptr)
(*(png_ptr->output_flush_fn))(png_ptr); (*(png_ptr->output_flush_fn))(png_ptr);
} }
#if !defined(PNG_NO_STDIO) #ifdef PNG_STDIO_SUPPORTED
void PNGAPI void PNGAPI
png_default_flush(png_structp png_ptr) png_default_flush(png_structp png_ptr)
{ {
#if !defined(_WIN32_WCE) #ifndef _WIN32_WCE
png_FILE_p io_ptr; png_FILE_p io_ptr;
#endif #endif
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
#if !defined(_WIN32_WCE) #ifndef _WIN32_WCE
io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
fflush(io_ptr); fflush(io_ptr);
#endif #endif
@ -192,7 +193,7 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
png_ptr->io_ptr = io_ptr; png_ptr->io_ptr = io_ptr;
#if !defined(PNG_NO_STDIO) #ifdef PNG_STDIO_SUPPORTED
if (write_data_fn != NULL) if (write_data_fn != NULL)
png_ptr->write_data_fn = write_data_fn; png_ptr->write_data_fn = write_data_fn;
@ -202,8 +203,8 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
png_ptr->write_data_fn = write_data_fn; png_ptr->write_data_fn = write_data_fn;
#endif #endif
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #ifdef PNG_WRITE_FLUSH_SUPPORTED
#if !defined(PNG_NO_STDIO) #ifdef PNG_STDIO_SUPPORTED
if (output_flush_fn != NULL) if (output_flush_fn != NULL)
png_ptr->output_flush_fn = output_flush_fn; png_ptr->output_flush_fn = output_flush_fn;
@ -225,8 +226,8 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
} }
} }
#if defined(USE_FAR_KEYWORD) #ifdef USE_FAR_KEYWORD
#if defined(_MSC_VER) #ifdef _MSC_VER
void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check) void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
{ {
void *near_ptr; void *near_ptr;

View file

@ -1,8 +1,8 @@
/* pngwrite.c - general routines to write a PNG file /* pngwrite.c - general routines to write a PNG file
* *
* Last changed in libpng 1.2.37 [June 4, 2009] * Last changed in libpng 1.2.42 [January 3, 2010]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2010 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.)
* *
@ -13,6 +13,7 @@
/* Get internal access to png.h */ /* Get internal access to png.h */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#ifdef PNG_WRITE_SUPPORTED #ifdef PNG_WRITE_SUPPORTED
@ -29,23 +30,25 @@ void PNGAPI
png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_write_info_before_PLTE"); png_debug(1, "in png_write_info_before_PLTE");
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
{ {
png_write_sig(png_ptr); /* Write PNG signature */ /* Write PNG signature */
#if defined(PNG_MNG_FEATURES_SUPPORTED) png_write_sig(png_ptr);
#ifdef PNG_MNG_FEATURES_SUPPORTED
if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted)) if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
{ {
png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
png_ptr->mng_features_permitted=0; png_ptr->mng_features_permitted = 0;
} }
#endif #endif
/* Write IHDR information. */ /* Write IHDR information. */
png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
info_ptr->filter_type, info_ptr->filter_type,
#if defined(PNG_WRITE_INTERLACING_SUPPORTED) #ifdef PNG_WRITE_INTERLACING_SUPPORTED
info_ptr->interlace_type); info_ptr->interlace_type);
#else #else
0); 0);
@ -53,7 +56,7 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
/* The rest of these check to see if the valid field has the appropriate /* The rest of these check to see if the valid field has the appropriate
* flag set, and if it does, writes the chunk. * flag set, and if it does, writes the chunk.
*/ */
#if defined(PNG_WRITE_gAMA_SUPPORTED) #ifdef PNG_WRITE_gAMA_SUPPORTED
if (info_ptr->valid & PNG_INFO_gAMA) if (info_ptr->valid & PNG_INFO_gAMA)
{ {
# ifdef PNG_FLOATING_POINT_SUPPORTED # ifdef PNG_FLOATING_POINT_SUPPORTED
@ -65,20 +68,20 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
#endif #endif
} }
#endif #endif
#if defined(PNG_WRITE_sRGB_SUPPORTED) #ifdef PNG_WRITE_sRGB_SUPPORTED
if (info_ptr->valid & PNG_INFO_sRGB) if (info_ptr->valid & PNG_INFO_sRGB)
png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent); png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
#endif #endif
#if defined(PNG_WRITE_iCCP_SUPPORTED) #ifdef PNG_WRITE_iCCP_SUPPORTED
if (info_ptr->valid & PNG_INFO_iCCP) if (info_ptr->valid & PNG_INFO_iCCP)
png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE, png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
info_ptr->iccp_profile, (int)info_ptr->iccp_proflen); info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
#endif #endif
#if defined(PNG_WRITE_sBIT_SUPPORTED) #ifdef PNG_WRITE_sBIT_SUPPORTED
if (info_ptr->valid & PNG_INFO_sBIT) if (info_ptr->valid & PNG_INFO_sBIT)
png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
#endif #endif
#if defined(PNG_WRITE_cHRM_SUPPORTED) #ifdef PNG_WRITE_cHRM_SUPPORTED
if (info_ptr->valid & PNG_INFO_cHRM) if (info_ptr->valid & PNG_INFO_cHRM)
{ {
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
@ -98,7 +101,7 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
#endif #endif
} }
#endif #endif
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
if (info_ptr->unknown_chunks_num) if (info_ptr->unknown_chunks_num)
{ {
png_unknown_chunk *up; png_unknown_chunk *up;
@ -109,7 +112,7 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
up++) up++)
{ {
int keep=png_handle_as_unknown(png_ptr, up->name); int keep = png_handle_as_unknown(png_ptr, up->name);
if (keep != PNG_HANDLE_CHUNK_NEVER && if (keep != PNG_HANDLE_CHUNK_NEVER &&
up->location && !(up->location & PNG_HAVE_PLTE) && up->location && !(up->location & PNG_HAVE_PLTE) &&
!(up->location & PNG_HAVE_IDAT) && !(up->location & PNG_HAVE_IDAT) &&
@ -147,16 +150,16 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
png_error(png_ptr, "Valid palette required for paletted images"); png_error(png_ptr, "Valid palette required for paletted images");
#if defined(PNG_WRITE_tRNS_SUPPORTED) #ifdef PNG_WRITE_tRNS_SUPPORTED
if (info_ptr->valid & PNG_INFO_tRNS) if (info_ptr->valid & PNG_INFO_tRNS)
{ {
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
/* Invert the alpha channel (in tRNS) */ /* Invert the alpha channel (in tRNS) */
if ((png_ptr->transformations & PNG_INVERT_ALPHA) && if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{ {
int j; int j;
for (j=0; j<(int)info_ptr->num_trans; j++) for (j = 0; j<(int)info_ptr->num_trans; j++)
info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]); info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
} }
#endif #endif
@ -164,30 +167,30 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->num_trans, info_ptr->color_type); info_ptr->num_trans, info_ptr->color_type);
} }
#endif #endif
#if defined(PNG_WRITE_bKGD_SUPPORTED) #ifdef PNG_WRITE_bKGD_SUPPORTED
if (info_ptr->valid & PNG_INFO_bKGD) if (info_ptr->valid & PNG_INFO_bKGD)
png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type); png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
#endif #endif
#if defined(PNG_WRITE_hIST_SUPPORTED) #ifdef PNG_WRITE_hIST_SUPPORTED
if (info_ptr->valid & PNG_INFO_hIST) if (info_ptr->valid & PNG_INFO_hIST)
png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
#endif #endif
#if defined(PNG_WRITE_oFFs_SUPPORTED) #ifdef PNG_WRITE_oFFs_SUPPORTED
if (info_ptr->valid & PNG_INFO_oFFs) if (info_ptr->valid & PNG_INFO_oFFs)
png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset, png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
info_ptr->offset_unit_type); info_ptr->offset_unit_type);
#endif #endif
#if defined(PNG_WRITE_pCAL_SUPPORTED) #ifdef PNG_WRITE_pCAL_SUPPORTED
if (info_ptr->valid & PNG_INFO_pCAL) if (info_ptr->valid & PNG_INFO_pCAL)
png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0, png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams, info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
info_ptr->pcal_units, info_ptr->pcal_params); info_ptr->pcal_units, info_ptr->pcal_params);
#endif #endif
#if defined(PNG_sCAL_SUPPORTED) #ifdef PNG_sCAL_SUPPORTED
if (info_ptr->valid & PNG_INFO_sCAL) if (info_ptr->valid & PNG_INFO_sCAL)
#if defined(PNG_WRITE_sCAL_SUPPORTED) #ifdef PNG_WRITE_sCAL_SUPPORTED
#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)
png_write_sCAL(png_ptr, (int)info_ptr->scal_unit, png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
info_ptr->scal_pixel_width, info_ptr->scal_pixel_height); info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
#else /* !FLOATING_POINT */ #else /* !FLOATING_POINT */
@ -202,13 +205,13 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
#endif /* WRITE_sCAL */ #endif /* WRITE_sCAL */
#endif /* sCAL */ #endif /* sCAL */
#if defined(PNG_WRITE_pHYs_SUPPORTED) #ifdef PNG_WRITE_pHYs_SUPPORTED
if (info_ptr->valid & PNG_INFO_pHYs) if (info_ptr->valid & PNG_INFO_pHYs)
png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit, png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type); info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
#endif /* pHYs */ #endif /* pHYs */
#if defined(PNG_WRITE_tIME_SUPPORTED) #ifdef PNG_WRITE_tIME_SUPPORTED
if (info_ptr->valid & PNG_INFO_tIME) if (info_ptr->valid & PNG_INFO_tIME)
{ {
png_write_tIME(png_ptr, &(info_ptr->mod_time)); png_write_tIME(png_ptr, &(info_ptr->mod_time));
@ -216,13 +219,13 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
} }
#endif /* tIME */ #endif /* tIME */
#if defined(PNG_WRITE_sPLT_SUPPORTED) #ifdef PNG_WRITE_sPLT_SUPPORTED
if (info_ptr->valid & PNG_INFO_sPLT) if (info_ptr->valid & PNG_INFO_sPLT)
for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
png_write_sPLT(png_ptr, info_ptr->splt_palettes + i); png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
#endif /* sPLT */ #endif /* sPLT */
#if defined(PNG_WRITE_TEXT_SUPPORTED) #ifdef PNG_WRITE_TEXT_SUPPORTED
/* Check to see if we need to write text chunks */ /* Check to see if we need to write text chunks */
for (i = 0; i < info_ptr->num_text; i++) for (i = 0; i < info_ptr->num_text; i++)
{ {
@ -231,7 +234,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
/* An internationalized chunk? */ /* An internationalized chunk? */
if (info_ptr->text[i].compression > 0) if (info_ptr->text[i].compression > 0)
{ {
#if defined(PNG_WRITE_iTXt_SUPPORTED) #ifdef PNG_WRITE_iTXt_SUPPORTED
/* Write international chunk */ /* Write international chunk */
png_write_iTXt(png_ptr, png_write_iTXt(png_ptr,
info_ptr->text[i].compression, info_ptr->text[i].compression,
@ -248,7 +251,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
/* If we want a compressed text chunk */ /* If we want a compressed text chunk */
else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt) else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
{ {
#if defined(PNG_WRITE_zTXt_SUPPORTED) #ifdef PNG_WRITE_zTXt_SUPPORTED
/* Write compressed chunk */ /* Write compressed chunk */
png_write_zTXt(png_ptr, info_ptr->text[i].key, png_write_zTXt(png_ptr, info_ptr->text[i].key,
info_ptr->text[i].text, 0, info_ptr->text[i].text, 0,
@ -261,7 +264,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
} }
else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
{ {
#if defined(PNG_WRITE_tEXt_SUPPORTED) #ifdef PNG_WRITE_tEXt_SUPPORTED
/* Write uncompressed chunk */ /* Write uncompressed chunk */
png_write_tEXt(png_ptr, info_ptr->text[i].key, png_write_tEXt(png_ptr, info_ptr->text[i].key,
info_ptr->text[i].text, info_ptr->text[i].text,
@ -276,7 +279,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
} }
#endif /* tEXt */ #endif /* tEXt */
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
if (info_ptr->unknown_chunks_num) if (info_ptr->unknown_chunks_num)
{ {
png_unknown_chunk *up; png_unknown_chunk *up;
@ -287,7 +290,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
up++) up++)
{ {
int keep=png_handle_as_unknown(png_ptr, up->name); int keep = png_handle_as_unknown(png_ptr, up->name);
if (keep != PNG_HANDLE_CHUNK_NEVER && if (keep != PNG_HANDLE_CHUNK_NEVER &&
up->location && (up->location & PNG_HAVE_PLTE) && up->location && (up->location & PNG_HAVE_PLTE) &&
!(up->location & PNG_HAVE_IDAT) && !(up->location & PNG_HAVE_IDAT) &&
@ -310,6 +313,7 @@ void PNGAPI
png_write_end(png_structp png_ptr, png_infop info_ptr) png_write_end(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_write_end"); png_debug(1, "in png_write_end");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
if (!(png_ptr->mode & PNG_HAVE_IDAT)) if (!(png_ptr->mode & PNG_HAVE_IDAT))
@ -318,16 +322,16 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
/* See if user wants us to write information chunks */ /* See if user wants us to write information chunks */
if (info_ptr != NULL) if (info_ptr != NULL)
{ {
#if defined(PNG_WRITE_TEXT_SUPPORTED) #ifdef PNG_WRITE_TEXT_SUPPORTED
int i; /* Local index variable */ int i; /* local index variable */
#endif #endif
#if defined(PNG_WRITE_tIME_SUPPORTED) #ifdef PNG_WRITE_tIME_SUPPORTED
/* Check to see if user has supplied a time chunk */ /* Check to see if user has supplied a time chunk */
if ((info_ptr->valid & PNG_INFO_tIME) && if ((info_ptr->valid & PNG_INFO_tIME) &&
!(png_ptr->mode & PNG_WROTE_tIME)) !(png_ptr->mode & PNG_WROTE_tIME))
png_write_tIME(png_ptr, &(info_ptr->mod_time)); png_write_tIME(png_ptr, &(info_ptr->mod_time));
#endif #endif
#if defined(PNG_WRITE_TEXT_SUPPORTED) #ifdef PNG_WRITE_TEXT_SUPPORTED
/* Loop through comment chunks */ /* Loop through comment chunks */
for (i = 0; i < info_ptr->num_text; i++) for (i = 0; i < info_ptr->num_text; i++)
{ {
@ -336,7 +340,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
/* An internationalized chunk? */ /* An internationalized chunk? */
if (info_ptr->text[i].compression > 0) if (info_ptr->text[i].compression > 0)
{ {
#if defined(PNG_WRITE_iTXt_SUPPORTED) #ifdef PNG_WRITE_iTXt_SUPPORTED
/* Write international chunk */ /* Write international chunk */
png_write_iTXt(png_ptr, png_write_iTXt(png_ptr,
info_ptr->text[i].compression, info_ptr->text[i].compression,
@ -352,7 +356,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
} }
else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
{ {
#if defined(PNG_WRITE_zTXt_SUPPORTED) #ifdef PNG_WRITE_zTXt_SUPPORTED
/* Write compressed chunk */ /* Write compressed chunk */
png_write_zTXt(png_ptr, info_ptr->text[i].key, png_write_zTXt(png_ptr, info_ptr->text[i].key,
info_ptr->text[i].text, 0, info_ptr->text[i].text, 0,
@ -365,7 +369,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
} }
else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
{ {
#if defined(PNG_WRITE_tEXt_SUPPORTED) #ifdef PNG_WRITE_tEXt_SUPPORTED
/* Write uncompressed chunk */ /* Write uncompressed chunk */
png_write_tEXt(png_ptr, info_ptr->text[i].key, png_write_tEXt(png_ptr, info_ptr->text[i].key,
info_ptr->text[i].text, 0); info_ptr->text[i].text, 0);
@ -378,7 +382,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
} }
} }
#endif #endif
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
if (info_ptr->unknown_chunks_num) if (info_ptr->unknown_chunks_num)
{ {
png_unknown_chunk *up; png_unknown_chunk *up;
@ -389,7 +393,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
up++) up++)
{ {
int keep=png_handle_as_unknown(png_ptr, up->name); int keep = png_handle_as_unknown(png_ptr, up->name);
if (keep != PNG_HANDLE_CHUNK_NEVER && if (keep != PNG_HANDLE_CHUNK_NEVER &&
up->location && (up->location & PNG_AFTER_IDAT) && up->location && (up->location & PNG_AFTER_IDAT) &&
((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
@ -411,22 +415,22 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
* do not set png_ptr->output_flush_fn to crash. If your application * do not set png_ptr->output_flush_fn to crash. If your application
* experiences a problem, please try building libpng with * experiences a problem, please try building libpng with
* PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to
* png-mng-implement at lists.sf.net . This kludge will be removed * png-mng-implement at lists.sf.net .
* from libpng-1.4.0.
*/ */
#if defined(PNG_WRITE_FLUSH_SUPPORTED) && \ #ifdef PNG_WRITE_FLUSH_SUPPORTED
defined(PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED) # ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED
png_flush(png_ptr); png_flush(png_ptr);
# endif
#endif #endif
} }
#if defined(PNG_WRITE_tIME_SUPPORTED) #ifdef PNG_CONVERT_tIME_SUPPORTED
#if !defined(_WIN32_WCE) /* "tm" structure is not supported on WindowsCE */
/* "time.h" functions are not supported on WindowsCE */
void PNGAPI void PNGAPI
png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
{ {
png_debug(1, "in png_convert_from_struct_tm"); png_debug(1, "in png_convert_from_struct_tm");
ptime->year = (png_uint_16)(1900 + ttime->tm_year); ptime->year = (png_uint_16)(1900 + ttime->tm_year);
ptime->month = (png_byte)(ttime->tm_mon + 1); ptime->month = (png_byte)(ttime->tm_mon + 1);
ptime->day = (png_byte)ttime->tm_mday; ptime->day = (png_byte)ttime->tm_mday;
@ -441,11 +445,11 @@ png_convert_from_time_t(png_timep ptime, time_t ttime)
struct tm *tbuf; struct tm *tbuf;
png_debug(1, "in png_convert_from_time_t"); png_debug(1, "in png_convert_from_time_t");
tbuf = gmtime(&ttime); tbuf = gmtime(&ttime);
png_convert_from_struct_tm(ptime, tbuf); png_convert_from_struct_tm(ptime, tbuf);
} }
#endif #endif
#endif
/* Initialize png_ptr structure, and allocate any memory needed */ /* Initialize png_ptr structure, and allocate any memory needed */
png_structp PNGAPI png_structp PNGAPI
@ -474,7 +478,9 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#endif #endif
#endif #endif
int i; int i;
png_debug(1, "in png_create_write_struct"); png_debug(1, "in png_create_write_struct");
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
@ -486,8 +492,8 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
/* Added at libpng-1.2.6 */ /* Added at libpng-1.2.6 */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED #ifdef PNG_SET_USER_LIMITS_SUPPORTED
png_ptr->user_width_max=PNG_USER_WIDTH_MAX; png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
#endif #endif
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
@ -498,8 +504,13 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#endif #endif
{ {
png_free(png_ptr, png_ptr->zbuf); png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf=NULL; png_ptr->zbuf = NULL;
png_destroy_struct(png_ptr); #ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr,
(png_free_ptr)free_fn, (png_voidp)mem_ptr);
#else
png_destroy_struct((png_voidp)png_ptr);
#endif
return (NULL); return (NULL);
} }
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
@ -514,7 +525,7 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
if (user_png_ver) if (user_png_ver)
{ {
i=0; i = 0;
do do
{ {
if (user_png_ver[i] != png_libpng_ver[i]) if (user_png_ver[i] != png_libpng_ver[i])
@ -533,7 +544,7 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
(user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
(user_png_ver[0] == '0' && user_png_ver[2] < '9')) (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
{ {
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
char msg[80]; char msg[80];
if (user_png_ver) if (user_png_ver)
{ {
@ -548,7 +559,7 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_warning(png_ptr, msg); png_warning(png_ptr, msg);
#endif #endif
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0; png_ptr->flags = 0;
#endif #endif
png_error(png_ptr, png_error(png_ptr,
"Incompatible libpng version in application and library"); "Incompatible libpng version in application and library");
@ -563,15 +574,16 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
png_flush_ptr_NULL); png_flush_ptr_NULL);
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
1, png_doublep_NULL, png_doublep_NULL); 1, png_doublep_NULL, png_doublep_NULL);
#endif #endif
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
/* Applications that neglect to set up their own setjmp() and then encounter /* Applications that neglect to set up their own setjmp() and then
a png_error() will longjmp here. Since the jmpbuf is then meaningless we * encounter a png_error() will longjmp here. Since the jmpbuf is
abort instead of returning. */ * then meaningless we abort instead of returning.
*/
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf)) if (setjmp(jmpbuf))
PNG_ABORT(); PNG_ABORT();
@ -601,12 +613,12 @@ png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
{ {
/* We only come here via pre-1.0.12-compiled applications */ /* We only come here via pre-1.0.12-compiled applications */
if (png_ptr == NULL) return; if (png_ptr == NULL) return;
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
if (png_sizeof(png_struct) > png_struct_size || if (png_sizeof(png_struct) > png_struct_size ||
png_sizeof(png_info) > png_info_size) png_sizeof(png_info) > png_info_size)
{ {
char msg[80]; char msg[80];
png_ptr->warning_fn=NULL; png_ptr->warning_fn = NULL;
if (user_png_ver) if (user_png_ver)
{ {
png_snprintf(msg, 80, png_snprintf(msg, 80,
@ -622,18 +634,18 @@ png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
#endif #endif
if (png_sizeof(png_struct) > png_struct_size) if (png_sizeof(png_struct) > png_struct_size)
{ {
png_ptr->error_fn=NULL; png_ptr->error_fn = NULL;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0; png_ptr->flags = 0;
#endif #endif
png_error(png_ptr, png_error(png_ptr,
"The png struct allocated by the application for writing is too small."); "The png struct allocated by the application for writing is too small.");
} }
if (png_sizeof(png_info) > png_info_size) if (png_sizeof(png_info) > png_info_size)
{ {
png_ptr->error_fn=NULL; png_ptr->error_fn = NULL;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0; png_ptr->flags = 0;
#endif #endif
png_error(png_ptr, png_error(png_ptr,
"The info struct allocated by the application for writing is too small."); "The info struct allocated by the application for writing is too small.");
@ -647,9 +659,9 @@ void PNGAPI
png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size) png_size_t png_struct_size)
{ {
png_structp png_ptr=*ptr_ptr; png_structp png_ptr = *ptr_ptr;
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* To save current jump buffer */ jmp_buf tmp_jmp; /* to save current jump buffer */
#endif #endif
int i = 0; int i = 0;
@ -664,10 +676,9 @@ png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
#ifdef PNG_LEGACY_SUPPORTED #ifdef PNG_LEGACY_SUPPORTED
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
#else #else
png_ptr->warning_fn=NULL; png_ptr->warning_fn = NULL;
png_warning(png_ptr, png_warning(png_ptr,
"Application uses deprecated png_write_init() and should be recompiled."); "Application uses deprecated png_write_init() and should be recompiled.");
break;
#endif #endif
} }
} while (png_libpng_ver[i++]); } while (png_libpng_ver[i++]);
@ -691,8 +702,8 @@ png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
/* Added at libpng-1.2.6 */ /* Added at libpng-1.2.6 */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED #ifdef PNG_SET_USER_LIMITS_SUPPORTED
png_ptr->user_width_max=PNG_USER_WIDTH_MAX; png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
#endif #endif
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
@ -707,8 +718,7 @@ png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
png_ptr->zbuf_size = PNG_ZBUF_SIZE; png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size); (png_uint_32)png_ptr->zbuf_size);
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
1, png_doublep_NULL, png_doublep_NULL); 1, png_doublep_NULL, png_doublep_NULL);
#endif #endif
@ -723,8 +733,8 @@ void PNGAPI
png_write_rows(png_structp png_ptr, png_bytepp row, png_write_rows(png_structp png_ptr, png_bytepp row,
png_uint_32 num_rows) png_uint_32 num_rows)
{ {
png_uint_32 i; /* Row counter */ png_uint_32 i; /* row counter */
png_bytepp rp; /* Row pointer */ png_bytepp rp; /* row pointer */
png_debug(1, "in png_write_rows"); png_debug(1, "in png_write_rows");
@ -744,15 +754,16 @@ png_write_rows(png_structp png_ptr, png_bytepp row,
void PNGAPI void PNGAPI
png_write_image(png_structp png_ptr, png_bytepp image) png_write_image(png_structp png_ptr, png_bytepp image)
{ {
png_uint_32 i; /* Row index */ png_uint_32 i; /* row index */
int pass, num_pass; /* Pass variables */ int pass, num_pass; /* pass variables */
png_bytepp rp; /* Points to current row */ png_bytepp rp; /* points to current row */
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_debug(1, "in png_write_image"); png_debug(1, "in png_write_image");
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Initialize interlace handling. If image is not interlaced, /* Initialize interlace handling. If image is not interlaced,
* this will set pass to 1 * this will set pass to 1
*/ */
@ -777,6 +788,7 @@ png_write_row(png_structp png_ptr, png_bytep row)
{ {
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_debug2(1, "in png_write_row (row %ld, pass %d)", png_debug2(1, "in png_write_row (row %ld, pass %d)",
png_ptr->row_number, png_ptr->pass); png_ptr->row_number, png_ptr->pass);
@ -821,7 +833,7 @@ png_write_row(png_structp png_ptr, png_bytep row)
png_write_start_row(png_ptr); png_write_start_row(png_ptr);
} }
#if defined(PNG_WRITE_INTERLACING_SUPPORTED) #ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* If interlaced and not interested in row, return */ /* If interlaced and not interested in row, return */
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
{ {
@ -902,7 +914,7 @@ png_write_row(png_structp png_ptr, png_bytep row)
png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row, png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
png_ptr->row_info.rowbytes); png_ptr->row_info.rowbytes);
#if defined(PNG_WRITE_INTERLACING_SUPPORTED) #ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Handle interlacing */ /* Handle interlacing */
if (png_ptr->interlaced && png_ptr->pass < 6 && if (png_ptr->interlaced && png_ptr->pass < 6 &&
(png_ptr->transformations & PNG_INTERLACE)) (png_ptr->transformations & PNG_INTERLACE))
@ -922,7 +934,7 @@ png_write_row(png_structp png_ptr, png_bytep row)
if (png_ptr->transformations) if (png_ptr->transformations)
png_do_write_transformations(png_ptr); png_do_write_transformations(png_ptr);
#if defined(PNG_MNG_FEATURES_SUPPORTED) #ifdef PNG_MNG_FEATURES_SUPPORTED
/* Write filter_method 64 (intrapixel differencing) only if /* Write filter_method 64 (intrapixel differencing) only if
* 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
* 2. Libpng did not write a PNG signature (this filter_method is only * 2. Libpng did not write a PNG signature (this filter_method is only
@ -947,12 +959,13 @@ png_write_row(png_structp png_ptr, png_bytep row)
(*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
} }
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #ifdef PNG_WRITE_FLUSH_SUPPORTED
/* Set the automatic flush interval or 0 to turn flushing off */ /* Set the automatic flush interval or 0 to turn flushing off */
void PNGAPI void PNGAPI
png_set_flush(png_structp png_ptr, int nrows) png_set_flush(png_structp png_ptr, int nrows)
{ {
png_debug(1, "in png_set_flush"); png_debug(1, "in png_set_flush");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->flush_dist = (nrows < 0 ? 0 : nrows); png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
@ -965,6 +978,7 @@ png_write_flush(png_structp png_ptr)
int wrote_IDAT; int wrote_IDAT;
png_debug(1, "in png_write_flush"); png_debug(1, "in png_write_flush");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
/* We have already written out all of the data */ /* We have already written out all of the data */
@ -1025,6 +1039,7 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
#endif #endif
png_debug(1, "in png_destroy_write_struct"); png_debug(1, "in png_destroy_write_struct");
if (png_ptr_ptr != NULL) if (png_ptr_ptr != NULL)
{ {
png_ptr = *png_ptr_ptr; png_ptr = *png_ptr_ptr;
@ -1051,11 +1066,11 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
{ {
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
if (png_ptr->num_chunk_list) if (png_ptr->num_chunk_list)
{ {
png_free(png_ptr, png_ptr->chunk_list); png_free(png_ptr, png_ptr->chunk_list);
png_ptr->chunk_list=NULL; png_ptr->chunk_list = NULL;
png_ptr->num_chunk_list = 0; png_ptr->num_chunk_list = 0;
} }
#endif #endif
@ -1099,13 +1114,14 @@ png_write_destroy(png_structp png_ptr)
#endif #endif
png_debug(1, "in png_write_destroy"); png_debug(1, "in png_write_destroy");
/* Free any memory zlib uses */ /* Free any memory zlib uses */
deflateEnd(&png_ptr->zstream); deflateEnd(&png_ptr->zstream);
/* Free our memory. png_free checks NULL for us. */ /* Free our memory. png_free checks NULL for us. */
png_free(png_ptr, png_ptr->zbuf); png_free(png_ptr, png_ptr->zbuf);
png_free(png_ptr, png_ptr->row_buf); png_free(png_ptr, png_ptr->row_buf);
#ifndef PNG_NO_WRITE_FILTER #ifdef PNG_WRITE_FILTER_SUPPORTED
png_free(png_ptr, png_ptr->prev_row); png_free(png_ptr, png_ptr->prev_row);
png_free(png_ptr, png_ptr->sub_row); png_free(png_ptr, png_ptr->sub_row);
png_free(png_ptr, png_ptr->up_row); png_free(png_ptr, png_ptr->up_row);
@ -1113,11 +1129,11 @@ png_write_destroy(png_structp png_ptr)
png_free(png_ptr, png_ptr->paeth_row); png_free(png_ptr, png_ptr->paeth_row);
#endif #endif
#if defined(PNG_TIME_RFC1123_SUPPORTED) #ifdef PNG_TIME_RFC1123_SUPPORTED
png_free(png_ptr, png_ptr->time_buffer); png_free(png_ptr, png_ptr->time_buffer);
#endif #endif
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
png_free(png_ptr, png_ptr->prev_filters); png_free(png_ptr, png_ptr->prev_filters);
png_free(png_ptr, png_ptr->filter_weights); png_free(png_ptr, png_ptr->filter_weights);
png_free(png_ptr, png_ptr->inv_filter_weights); png_free(png_ptr, png_ptr->inv_filter_weights);
@ -1156,9 +1172,10 @@ void PNGAPI
png_set_filter(png_structp png_ptr, int method, int filters) png_set_filter(png_structp png_ptr, int method, int filters)
{ {
png_debug(1, "in png_set_filter"); png_debug(1, "in png_set_filter");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
#if defined(PNG_MNG_FEATURES_SUPPORTED) #ifdef PNG_MNG_FEATURES_SUPPORTED
if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(method == PNG_INTRAPIXEL_DIFFERENCING)) (method == PNG_INTRAPIXEL_DIFFERENCING))
method = PNG_FILTER_TYPE_BASE; method = PNG_FILTER_TYPE_BASE;
@ -1167,26 +1184,26 @@ png_set_filter(png_structp png_ptr, int method, int filters)
{ {
switch (filters & (PNG_ALL_FILTERS | 0x07)) switch (filters & (PNG_ALL_FILTERS | 0x07))
{ {
#ifndef PNG_NO_WRITE_FILTER #ifdef PNG_WRITE_FILTER_SUPPORTED
case 5: case 5:
case 6: case 6:
case 7: png_warning(png_ptr, "Unknown row filter for method 0"); case 7: png_warning(png_ptr, "Unknown row filter for method 0");
#endif /* PNG_NO_WRITE_FILTER */ #endif /* PNG_WRITE_FILTER_SUPPORTED */
case PNG_FILTER_VALUE_NONE: case PNG_FILTER_VALUE_NONE:
png_ptr->do_filter=PNG_FILTER_NONE; break; png_ptr->do_filter = PNG_FILTER_NONE; break;
#ifndef PNG_NO_WRITE_FILTER #ifdef PNG_WRITE_FILTER_SUPPORTED
case PNG_FILTER_VALUE_SUB: case PNG_FILTER_VALUE_SUB:
png_ptr->do_filter=PNG_FILTER_SUB; break; png_ptr->do_filter = PNG_FILTER_SUB; break;
case PNG_FILTER_VALUE_UP: case PNG_FILTER_VALUE_UP:
png_ptr->do_filter=PNG_FILTER_UP; break; png_ptr->do_filter = PNG_FILTER_UP; break;
case PNG_FILTER_VALUE_AVG: case PNG_FILTER_VALUE_AVG:
png_ptr->do_filter=PNG_FILTER_AVG; break; png_ptr->do_filter = PNG_FILTER_AVG; break;
case PNG_FILTER_VALUE_PAETH: case PNG_FILTER_VALUE_PAETH:
png_ptr->do_filter=PNG_FILTER_PAETH; break; png_ptr->do_filter = PNG_FILTER_PAETH; break;
default: png_ptr->do_filter = (png_byte)filters; break; default: png_ptr->do_filter = (png_byte)filters; break;
#else #else
default: png_warning(png_ptr, "Unknown row filter for method 0"); default: png_warning(png_ptr, "Unknown row filter for method 0");
#endif /* PNG_NO_WRITE_FILTER */ #endif /* PNG_WRITE_FILTER_SUPPORTED */
} }
/* If we have allocated the row_buf, this means we have already started /* If we have allocated the row_buf, this means we have already started
@ -1200,7 +1217,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
*/ */
if (png_ptr->row_buf != NULL) if (png_ptr->row_buf != NULL)
{ {
#ifndef PNG_NO_WRITE_FILTER #ifdef PNG_WRITE_FILTER_SUPPORTED
if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
{ {
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
@ -1255,7 +1272,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
} }
if (png_ptr->do_filter == PNG_NO_FILTERS) if (png_ptr->do_filter == PNG_NO_FILTERS)
#endif /* PNG_NO_WRITE_FILTER */ #endif /* PNG_WRITE_FILTER_SUPPORTED */
png_ptr->do_filter = PNG_FILTER_NONE; png_ptr->do_filter = PNG_FILTER_NONE;
} }
} }
@ -1270,7 +1287,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
* filtered data going to zlib more consistent, hopefully resulting in * filtered data going to zlib more consistent, hopefully resulting in
* better compression. * better compression.
*/ */
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */ #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* GRR 970116 */
void PNGAPI void PNGAPI
png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
int num_weights, png_doublep filter_weights, int num_weights, png_doublep filter_weights,
@ -1279,6 +1296,7 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
int i; int i;
png_debug(1, "in png_set_filter_heuristics"); png_debug(1, "in png_set_filter_heuristics");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST) if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
@ -1393,6 +1411,7 @@ void PNGAPI
png_set_compression_level(png_structp png_ptr, int level) png_set_compression_level(png_structp png_ptr, int level)
{ {
png_debug(1, "in png_set_compression_level"); png_debug(1, "in png_set_compression_level");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL; png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
@ -1403,6 +1422,7 @@ void PNGAPI
png_set_compression_mem_level(png_structp png_ptr, int mem_level) png_set_compression_mem_level(png_structp png_ptr, int mem_level)
{ {
png_debug(1, "in png_set_compression_mem_level"); png_debug(1, "in png_set_compression_mem_level");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL; png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
@ -1413,6 +1433,7 @@ void PNGAPI
png_set_compression_strategy(png_structp png_ptr, int strategy) png_set_compression_strategy(png_structp png_ptr, int strategy)
{ {
png_debug(1, "in png_set_compression_strategy"); png_debug(1, "in png_set_compression_strategy");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
@ -1433,7 +1454,7 @@ png_set_compression_window_bits(png_structp png_ptr, int window_bits)
if (window_bits == 8) if (window_bits == 8)
{ {
png_warning(png_ptr, "Compression window is being reset to 512"); png_warning(png_ptr, "Compression window is being reset to 512");
window_bits=9; window_bits = 9;
} }
#endif #endif
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS; png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
@ -1444,6 +1465,7 @@ void PNGAPI
png_set_compression_method(png_structp png_ptr, int method) png_set_compression_method(png_structp png_ptr, int method)
{ {
png_debug(1, "in png_set_compression_method"); png_debug(1, "in png_set_compression_method");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
if (method != 8) if (method != 8)
@ -1460,12 +1482,13 @@ png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
png_ptr->write_row_fn = write_row_fn; png_ptr->write_row_fn = write_row_fn;
} }
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
void PNGAPI void PNGAPI
png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
write_user_transform_fn) write_user_transform_fn)
{ {
png_debug(1, "in png_set_write_user_transform_fn"); png_debug(1, "in png_set_write_user_transform_fn");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->transformations |= PNG_USER_TRANSFORM; png_ptr->transformations |= PNG_USER_TRANSFORM;
@ -1474,31 +1497,26 @@ png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
#endif #endif
#if defined(PNG_INFO_IMAGE_SUPPORTED) #ifdef PNG_INFO_IMAGE_SUPPORTED
void PNGAPI void PNGAPI
png_write_png(png_structp png_ptr, png_infop info_ptr, png_write_png(png_structp png_ptr, png_infop info_ptr,
int transforms, voidp params) int transforms, voidp params)
{ {
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
/* Invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
png_set_invert_alpha(png_ptr);
#endif
/* Write the file header information. */ /* Write the file header information. */
png_write_info(png_ptr, info_ptr); png_write_info(png_ptr, info_ptr);
/* ------ these transformations don't touch the info structure ------- */ /* ------ these transformations don't touch the info structure ------- */
#if defined(PNG_WRITE_INVERT_SUPPORTED) #ifdef PNG_WRITE_INVERT_SUPPORTED
/* Invert monochrome pixels */ /* Invert monochrome pixels */
if (transforms & PNG_TRANSFORM_INVERT_MONO) if (transforms & PNG_TRANSFORM_INVERT_MONO)
png_set_invert_mono(png_ptr); png_set_invert_mono(png_ptr);
#endif #endif
#if defined(PNG_WRITE_SHIFT_SUPPORTED) #ifdef PNG_WRITE_SHIFT_SUPPORTED
/* Shift the pixels up to a legal bit depth and fill in /* Shift the pixels up to a legal bit depth and fill in
* as appropriate to correctly scale the image. * as appropriate to correctly scale the image.
*/ */
@ -1507,19 +1525,19 @@ png_write_png(png_structp png_ptr, png_infop info_ptr,
png_set_shift(png_ptr, &info_ptr->sig_bit); png_set_shift(png_ptr, &info_ptr->sig_bit);
#endif #endif
#if defined(PNG_WRITE_PACK_SUPPORTED) #ifdef PNG_WRITE_PACK_SUPPORTED
/* Pack pixels into bytes */ /* Pack pixels into bytes */
if (transforms & PNG_TRANSFORM_PACKING) if (transforms & PNG_TRANSFORM_PACKING)
png_set_packing(png_ptr); png_set_packing(png_ptr);
#endif #endif
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
/* Swap location of alpha bytes from ARGB to RGBA */ /* Swap location of alpha bytes from ARGB to RGBA */
if (transforms & PNG_TRANSFORM_SWAP_ALPHA) if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
png_set_swap_alpha(png_ptr); png_set_swap_alpha(png_ptr);
#endif #endif
#if defined(PNG_WRITE_FILLER_SUPPORTED) #ifdef PNG_WRITE_FILLER_SUPPORTED
/* Pack XRGB/RGBX/ARGB/RGBA into * RGB (4 channels -> 3 channels) */ /* Pack XRGB/RGBX/ARGB/RGBA into * RGB (4 channels -> 3 channels) */
if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER)
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
@ -1527,24 +1545,30 @@ png_write_png(png_structp png_ptr, png_infop info_ptr,
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
#endif #endif
#if defined(PNG_WRITE_BGR_SUPPORTED) #ifdef PNG_WRITE_BGR_SUPPORTED
/* Flip BGR pixels to RGB */ /* Flip BGR pixels to RGB */
if (transforms & PNG_TRANSFORM_BGR) if (transforms & PNG_TRANSFORM_BGR)
png_set_bgr(png_ptr); png_set_bgr(png_ptr);
#endif #endif
#if defined(PNG_WRITE_SWAP_SUPPORTED) #ifdef PNG_WRITE_SWAP_SUPPORTED
/* Swap bytes of 16-bit files to most significant byte first */ /* Swap bytes of 16-bit files to most significant byte first */
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
png_set_swap(png_ptr); png_set_swap(png_ptr);
#endif #endif
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) #ifdef PNG_WRITE_PACKSWAP_SUPPORTED
/* Swap bits of 1, 2, 4 bit packed pixel formats */ /* Swap bits of 1, 2, 4 bit packed pixel formats */
if (transforms & PNG_TRANSFORM_PACKSWAP) if (transforms & PNG_TRANSFORM_PACKSWAP)
png_set_packswap(png_ptr); png_set_packswap(png_ptr);
#endif #endif
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
/* Invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
png_set_invert_alpha(png_ptr);
#endif
/* ----------------------- end of transformations ------------------- */ /* ----------------------- end of transformations ------------------- */
/* Write the bits */ /* Write the bits */

View file

@ -1,7 +1,7 @@
/* pngwtran.c - transforms the data in a row for PNG writers /* pngwtran.c - transforms the data in a row for PNG writers
* *
* Last changed in libpng 1.2.37 [June 4, 2009] * Last changed in libpng 1.2.41 [December 3, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -12,6 +12,7 @@
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#ifdef PNG_WRITE_SUPPORTED #ifdef PNG_WRITE_SUPPORTED
@ -26,7 +27,7 @@ png_do_write_transformations(png_structp png_ptr)
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
if (png_ptr->transformations & PNG_USER_TRANSFORM) if (png_ptr->transformations & PNG_USER_TRANSFORM)
if (png_ptr->write_user_transform_fn != NULL) if (png_ptr->write_user_transform_fn != NULL)
(*(png_ptr->write_user_transform_fn)) /* User write transform function */ (*(png_ptr->write_user_transform_fn)) /* User write transform function */
@ -40,48 +41,48 @@ png_do_write_transformations(png_structp png_ptr)
/* png_byte pixel_depth; bits per pixel (depth*channels) */ /* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */ png_ptr->row_buf + 1); /* start of pixel data for row */
#endif #endif
#if defined(PNG_WRITE_FILLER_SUPPORTED) #ifdef PNG_WRITE_FILLER_SUPPORTED
if (png_ptr->transformations & PNG_FILLER) if (png_ptr->transformations & PNG_FILLER)
png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
png_ptr->flags); png_ptr->flags);
#endif #endif
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) #ifdef PNG_WRITE_PACKSWAP_SUPPORTED
if (png_ptr->transformations & PNG_PACKSWAP) if (png_ptr->transformations & PNG_PACKSWAP)
png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1); png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif #endif
#if defined(PNG_WRITE_PACK_SUPPORTED) #ifdef PNG_WRITE_PACK_SUPPORTED
if (png_ptr->transformations & PNG_PACK) if (png_ptr->transformations & PNG_PACK)
png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1, png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
(png_uint_32)png_ptr->bit_depth); (png_uint_32)png_ptr->bit_depth);
#endif #endif
#if defined(PNG_WRITE_SWAP_SUPPORTED) #ifdef PNG_WRITE_SWAP_SUPPORTED
if (png_ptr->transformations & PNG_SWAP_BYTES) if (png_ptr->transformations & PNG_SWAP_BYTES)
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif #endif
#if defined(PNG_WRITE_SHIFT_SUPPORTED) #ifdef PNG_WRITE_SHIFT_SUPPORTED
if (png_ptr->transformations & PNG_SHIFT) if (png_ptr->transformations & PNG_SHIFT)
png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1, png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
&(png_ptr->shift)); &(png_ptr->shift));
#endif #endif
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
if (png_ptr->transformations & PNG_SWAP_ALPHA) if (png_ptr->transformations & PNG_SWAP_ALPHA)
png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif #endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
if (png_ptr->transformations & PNG_INVERT_ALPHA) if (png_ptr->transformations & PNG_INVERT_ALPHA)
png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif #endif
#if defined(PNG_WRITE_BGR_SUPPORTED) #ifdef PNG_WRITE_BGR_SUPPORTED
if (png_ptr->transformations & PNG_BGR) if (png_ptr->transformations & PNG_BGR)
png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif #endif
#if defined(PNG_WRITE_INVERT_SUPPORTED) #ifdef PNG_WRITE_INVERT_SUPPORTED
if (png_ptr->transformations & PNG_INVERT_MONO) if (png_ptr->transformations & PNG_INVERT_MONO)
png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif #endif
} }
#if defined(PNG_WRITE_PACK_SUPPORTED) #ifdef PNG_WRITE_PACK_SUPPORTED
/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The /* Pack pixels into bytes. Pass the true bit depth in bit_depth. The
* row_info bit depth should be 8 (one pixel per byte). The channels * row_info bit depth should be 8 (one pixel per byte). The channels
* should be 1 (this only happens on grayscale and paletted images). * should be 1 (this only happens on grayscale and paletted images).
@ -90,8 +91,9 @@ void /* PRIVATE */
png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
{ {
png_debug(1, "in png_do_pack"); png_debug(1, "in png_do_pack");
if (row_info->bit_depth == 8 && if (row_info->bit_depth == 8 &&
#if defined(PNG_USELESS_TESTS_SUPPORTED) #ifdef PNG_USELESS_TESTS_SUPPORTED
row != NULL && row_info != NULL && row != NULL && row_info != NULL &&
#endif #endif
row_info->channels == 1) row_info->channels == 1)
@ -204,7 +206,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
} }
#endif #endif
#if defined(PNG_WRITE_SHIFT_SUPPORTED) #ifdef PNG_WRITE_SHIFT_SUPPORTED
/* Shift pixel values to take advantage of whole range. Pass the /* Shift pixel values to take advantage of whole range. Pass the
* true number of bits in bit_depth. The row should be packed * true number of bits in bit_depth. The row should be packed
* according to row_info->bit_depth. Thus, if you had a row of * according to row_info->bit_depth. Thus, if you had a row of
@ -216,7 +218,8 @@ void /* PRIVATE */
png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
{ {
png_debug(1, "in png_do_shift"); png_debug(1, "in png_do_shift");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
#ifdef PNG_USELESS_TESTS_SUPPORTED
if (row != NULL && row_info != NULL && if (row != NULL && row_info != NULL &&
#else #else
if ( if (
@ -335,12 +338,13 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
} }
#endif #endif
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_write_swap_alpha"); png_debug(1, "in png_do_write_swap_alpha");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
#ifdef PNG_USELESS_TESTS_SUPPORTED
if (row != NULL && row_info != NULL) if (row != NULL && row_info != NULL)
#endif #endif
{ {
@ -423,12 +427,13 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
} }
#endif #endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_write_invert_alpha"); png_debug(1, "in png_do_write_invert_alpha");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
#ifdef PNG_USELESS_TESTS_SUPPORTED
if (row != NULL && row_info != NULL) if (row != NULL && row_info != NULL)
#endif #endif
{ {
@ -512,14 +517,15 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
} }
#endif #endif
#if defined(PNG_MNG_FEATURES_SUPPORTED) #ifdef PNG_MNG_FEATURES_SUPPORTED
/* Undoes intrapixel differencing */ /* Undoes intrapixel differencing */
void /* PRIVATE */ void /* PRIVATE */
png_do_write_intrapixel(png_row_infop row_info, png_bytep row) png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_write_intrapixel"); png_debug(1, "in png_do_write_intrapixel");
if ( if (
#if defined(PNG_USELESS_TESTS_SUPPORTED) #ifdef PNG_USELESS_TESTS_SUPPORTED
row != NULL && row_info != NULL && row != NULL && row_info != NULL &&
#endif #endif
(row_info->color_type & PNG_COLOR_MASK_COLOR)) (row_info->color_type & PNG_COLOR_MASK_COLOR))

View file

@ -1,7 +1,7 @@
/* pngwutil.c - utilities to write a PNG file /* pngwutil.c - utilities to write a PNG file
* *
* Last changed in libpng 1.2.40 [September 10, 2009] * Last changed in libpng 1.2.41 [December 3, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -12,6 +12,7 @@
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h" #include "png.h"
#ifdef PNG_WRITE_SUPPORTED #ifdef PNG_WRITE_SUPPORTED
@ -58,7 +59,7 @@ png_save_uint_16(png_bytep buf, unsigned int i)
* we should call png_set_sig_bytes() to tell libpng how many of the * we should call png_set_sig_bytes() to tell libpng how many of the
* bytes have already been written. * bytes have already been written.
*/ */
void /* PRIVATE */ void PNGAPI
png_write_sig(png_structp png_ptr) png_write_sig(png_structp png_ptr)
{ {
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
@ -106,6 +107,7 @@ png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
/* Write the length and the chunk name */ /* Write the length and the chunk name */
png_save_uint_32(buf, length); png_save_uint_32(buf, length);
png_memcpy(buf + 4, chunk_name, 4); png_memcpy(buf + 4, chunk_name, 4);
@ -192,7 +194,7 @@ png_text_compress(png_structp png_ptr,
if (compression >= PNG_TEXT_COMPRESSION_LAST) if (compression >= PNG_TEXT_COMPRESSION_LAST)
{ {
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
char msg[50]; char msg[50];
png_snprintf(msg, 50, "Unknown compression type %d", compression); png_snprintf(msg, 50, "Unknown compression type %d", compression);
png_warning(png_ptr, msg); png_warning(png_ptr, msg);
@ -459,7 +461,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
* 5. The color_type is RGB or RGBA * 5. The color_type is RGB or RGBA
*/ */
if ( if (
#if defined(PNG_MNG_FEATURES_SUPPORTED) #ifdef PNG_MNG_FEATURES_SUPPORTED
!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
(color_type == PNG_COLOR_TYPE_RGB || (color_type == PNG_COLOR_TYPE_RGB ||
@ -487,7 +489,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
png_ptr->bit_depth = (png_byte)bit_depth; png_ptr->bit_depth = (png_byte)bit_depth;
png_ptr->color_type = (png_byte)color_type; png_ptr->color_type = (png_byte)color_type;
png_ptr->interlaced = (png_byte)interlace_type; png_ptr->interlaced = (png_byte)interlace_type;
#if defined(PNG_MNG_FEATURES_SUPPORTED) #ifdef PNG_MNG_FEATURES_SUPPORTED
png_ptr->filter_type = (png_byte)filter_type; png_ptr->filter_type = (png_byte)filter_type;
#endif #endif
png_ptr->compression_type = (png_byte)compression_type; png_ptr->compression_type = (png_byte)compression_type;
@ -579,7 +581,7 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
png_debug(1, "in png_write_PLTE"); png_debug(1, "in png_write_PLTE");
if (( if ((
#if defined(PNG_MNG_FEATURES_SUPPORTED) #ifdef PNG_MNG_FEATURES_SUPPORTED
!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
#endif #endif
num_pal == 0) || num_pal > 256) num_pal == 0) || num_pal > 256)
@ -607,7 +609,7 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
png_write_chunk_start(png_ptr, (png_bytep)png_PLTE, png_write_chunk_start(png_ptr, (png_bytep)png_PLTE,
(png_uint_32)(num_pal * 3)); (png_uint_32)(num_pal * 3));
#ifndef PNG_NO_POINTER_INDEXING #ifdef PNG_POINTER_INDEXING_SUPPORTED
for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
{ {
buf[0] = pal_ptr->red; buf[0] = pal_ptr->red;
@ -700,7 +702,7 @@ png_write_IEND(png_structp png_ptr)
png_ptr->mode |= PNG_HAVE_IEND; png_ptr->mode |= PNG_HAVE_IEND;
} }
#if defined(PNG_WRITE_gAMA_SUPPORTED) #ifdef PNG_WRITE_gAMA_SUPPORTED
/* Write a gAMA chunk */ /* Write a gAMA chunk */
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
@ -738,7 +740,7 @@ png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
#endif #endif
#endif #endif
#if defined(PNG_WRITE_sRGB_SUPPORTED) #ifdef PNG_WRITE_sRGB_SUPPORTED
/* Write a sRGB chunk */ /* Write a sRGB chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_sRGB(png_structp png_ptr, int srgb_intent) png_write_sRGB(png_structp png_ptr, int srgb_intent)
@ -758,7 +760,7 @@ png_write_sRGB(png_structp png_ptr, int srgb_intent)
} }
#endif #endif
#if defined(PNG_WRITE_iCCP_SUPPORTED) #ifdef PNG_WRITE_iCCP_SUPPORTED
/* Write an iCCP chunk */ /* Write an iCCP chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
@ -839,7 +841,7 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
} }
#endif #endif
#if defined(PNG_WRITE_sPLT_SUPPORTED) #ifdef PNG_WRITE_sPLT_SUPPORTED
/* Write a sPLT chunk */ /* Write a sPLT chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette) png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
@ -853,7 +855,7 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
int entry_size = (spalette->depth == 8 ? 6 : 10); int entry_size = (spalette->depth == 8 ? 6 : 10);
int palette_size = entry_size * spalette->nentries; int palette_size = entry_size * spalette->nentries;
png_sPLT_entryp ep; png_sPLT_entryp ep;
#ifdef PNG_NO_POINTER_INDEXING #ifndef PNG_POINTER_INDEXING_SUPPORTED
int i; int i;
#endif #endif
@ -870,7 +872,7 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1); png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1);
/* Loop through each palette entry, writing appropriately */ /* Loop through each palette entry, writing appropriately */
#ifndef PNG_NO_POINTER_INDEXING #ifdef PNG_POINTER_INDEXING_SUPPORTED
for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++) for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++)
{ {
if (spalette->depth == 8) if (spalette->depth == 8)
@ -920,7 +922,7 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
} }
#endif #endif
#if defined(PNG_WRITE_sBIT_SUPPORTED) #ifdef PNG_WRITE_sBIT_SUPPORTED
/* Write the sBIT chunk */ /* Write the sBIT chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type) png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
@ -977,7 +979,7 @@ png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
} }
#endif #endif
#if defined(PNG_WRITE_cHRM_SUPPORTED) #ifdef PNG_WRITE_cHRM_SUPPORTED
/* Write the cHRM chunk */ /* Write the cHRM chunk */
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
@ -1004,7 +1006,7 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
int_blue_x = (png_uint_32)(blue_x * 100000.0 + 0.5); int_blue_x = (png_uint_32)(blue_x * 100000.0 + 0.5);
int_blue_y = (png_uint_32)(blue_y * 100000.0 + 0.5); int_blue_y = (png_uint_32)(blue_y * 100000.0 + 0.5);
#if !defined(PNG_NO_CHECK_cHRM) #ifdef PNG_CHECK_cHRM_SUPPORTED
if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y, if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y,
int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y)) int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y))
#endif #endif
@ -1042,7 +1044,7 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
png_debug(1, "in png_write_cHRM"); png_debug(1, "in png_write_cHRM");
/* Each value is saved in 1/100,000ths */ /* Each value is saved in 1/100,000ths */
#if !defined(PNG_NO_CHECK_cHRM) #ifdef PNG_CHECK_cHRM_SUPPORTED
if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y, if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y,
green_x, green_y, blue_x, blue_y)) green_x, green_y, blue_x, blue_y))
#endif #endif
@ -1065,7 +1067,7 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
#endif #endif
#endif #endif
#if defined(PNG_WRITE_tRNS_SUPPORTED) #ifdef PNG_WRITE_tRNS_SUPPORTED
/* Write the tRNS chunk */ /* Write the tRNS chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran, png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
@ -1122,7 +1124,7 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
} }
#endif #endif
#if defined(PNG_WRITE_bKGD_SUPPORTED) #ifdef PNG_WRITE_bKGD_SUPPORTED
/* Write the background chunk */ /* Write the background chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type) png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
@ -1137,7 +1139,7 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
if (color_type == PNG_COLOR_TYPE_PALETTE) if (color_type == PNG_COLOR_TYPE_PALETTE)
{ {
if ( if (
#if defined(PNG_MNG_FEATURES_SUPPORTED) #ifdef PNG_MNG_FEATURES_SUPPORTED
(png_ptr->num_palette || (png_ptr->num_palette ||
(!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
#endif #endif
@ -1176,7 +1178,7 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
} }
#endif #endif
#if defined(PNG_WRITE_hIST_SUPPORTED) #ifdef PNG_WRITE_hIST_SUPPORTED
/* Write the histogram */ /* Write the histogram */
void /* PRIVATE */ void /* PRIVATE */
png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist) png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
@ -1253,7 +1255,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
if ((png_byte)*kp < 0x20 || if ((png_byte)*kp < 0x20 ||
((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1)) ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
{ {
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
char msg[40]; char msg[40];
png_snprintf(msg, 40, png_snprintf(msg, 40,
@ -1340,7 +1342,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
} }
#endif #endif
#if defined(PNG_WRITE_tEXt_SUPPORTED) #ifdef PNG_WRITE_tEXt_SUPPORTED
/* Write a tEXt chunk */ /* Write a tEXt chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text, png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
@ -1381,7 +1383,7 @@ png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
} }
#endif #endif
#if defined(PNG_WRITE_zTXt_SUPPORTED) #ifdef PNG_WRITE_zTXt_SUPPORTED
/* Write a compressed text chunk */ /* Write a compressed text chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text, png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
@ -1441,7 +1443,7 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
} }
#endif #endif
#if defined(PNG_WRITE_iTXt_SUPPORTED) #ifdef PNG_WRITE_iTXt_SUPPORTED
/* Write an iTXt chunk */ /* Write an iTXt chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_iTXt(png_structp png_ptr, int compression, png_charp key, png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
@ -1530,7 +1532,7 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
} }
#endif #endif
#if defined(PNG_WRITE_oFFs_SUPPORTED) #ifdef PNG_WRITE_oFFs_SUPPORTED
/* Write the oFFs chunk */ /* Write the oFFs chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
@ -1553,7 +1555,7 @@ png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9); png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9);
} }
#endif #endif
#if defined(PNG_WRITE_pCAL_SUPPORTED) #ifdef PNG_WRITE_pCAL_SUPPORTED
/* Write the pCAL chunk (described in the PNG extensions document) */ /* Write the pCAL chunk (described in the PNG extensions document) */
void /* PRIVATE */ void /* PRIVATE */
png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
@ -1616,9 +1618,9 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
} }
#endif #endif
#if defined(PNG_WRITE_sCAL_SUPPORTED) #ifdef PNG_WRITE_sCAL_SUPPORTED
/* Write the sCAL chunk */ /* Write the sCAL chunk */
#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)
void /* PRIVATE */ void /* PRIVATE */
png_write_sCAL(png_structp png_ptr, int unit, double width, double height) png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
{ {
@ -1631,7 +1633,7 @@ png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
png_debug(1, "in png_write_sCAL"); png_debug(1, "in png_write_sCAL");
buf[0] = (char)unit; buf[0] = (char)unit;
#if defined(_WIN32_WCE) #ifdef _WIN32_WCE
/* sprintf() function is not supported on WindowsCE */ /* sprintf() function is not supported on WindowsCE */
{ {
wchar_t wc_buf[32]; wchar_t wc_buf[32];
@ -1690,7 +1692,7 @@ png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
#endif #endif
#endif #endif
#if defined(PNG_WRITE_pHYs_SUPPORTED) #ifdef PNG_WRITE_pHYs_SUPPORTED
/* Write the pHYs chunk */ /* Write the pHYs chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
@ -1715,7 +1717,7 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
} }
#endif #endif
#if defined(PNG_WRITE_tIME_SUPPORTED) #ifdef PNG_WRITE_tIME_SUPPORTED
/* Write the tIME chunk. Use either png_convert_from_struct_tm() /* Write the tIME chunk. Use either png_convert_from_struct_tm()
* or png_convert_from_time_t(), or fill in the structure yourself. * or png_convert_from_time_t(), or fill in the structure yourself.
*/ */
@ -1753,7 +1755,6 @@ void /* PRIVATE */
png_write_start_row(png_structp png_ptr) png_write_start_row(png_structp png_ptr)
{ {
#ifdef PNG_WRITE_INTERLACING_SUPPORTED #ifdef PNG_WRITE_INTERLACING_SUPPORTED
#ifdef PNG_USE_LOCAL_ARRAYS
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* Start of interlace block */ /* Start of interlace block */
@ -1767,7 +1768,6 @@ png_write_start_row(png_structp png_ptr)
/* Offset to next interlace block in the y direction */ /* Offset to next interlace block in the y direction */
int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
#endif
#endif #endif
png_size_t buf_size; png_size_t buf_size;
@ -1782,7 +1782,7 @@ png_write_start_row(png_structp png_ptr)
(png_uint_32)buf_size); (png_uint_32)buf_size);
png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
#ifndef PNG_NO_WRITE_FILTER #ifdef PNG_WRITE_FILTER_SUPPORTED
/* Set up filtering buffer, if using this filter */ /* Set up filtering buffer, if using this filter */
if (png_ptr->do_filter & PNG_FILTER_SUB) if (png_ptr->do_filter & PNG_FILTER_SUB)
{ {
@ -1795,9 +1795,8 @@ png_write_start_row(png_structp png_ptr)
if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
{ {
/* Set up previous row buffer */ /* Set up previous row buffer */
png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, png_ptr->prev_row = (png_bytep)png_calloc(png_ptr,
(png_uint_32)buf_size); (png_uint_32)buf_size);
png_memset(png_ptr->prev_row, 0, buf_size);
if (png_ptr->do_filter & PNG_FILTER_UP) if (png_ptr->do_filter & PNG_FILTER_UP)
{ {
@ -1820,7 +1819,7 @@ png_write_start_row(png_structp png_ptr)
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
} }
} }
#endif /* PNG_NO_WRITE_FILTER */ #endif /* PNG_WRITE_FILTER_SUPPORTED */
#ifdef PNG_WRITE_INTERLACING_SUPPORTED #ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* If interlaced, we need to set up width and height of pass */ /* If interlaced, we need to set up width and height of pass */
@ -1854,7 +1853,6 @@ void /* PRIVATE */
png_write_finish_row(png_structp png_ptr) png_write_finish_row(png_structp png_ptr)
{ {
#ifdef PNG_WRITE_INTERLACING_SUPPORTED #ifdef PNG_WRITE_INTERLACING_SUPPORTED
#ifdef PNG_USE_LOCAL_ARRAYS
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* Start of interlace block */ /* Start of interlace block */
@ -1868,7 +1866,6 @@ png_write_finish_row(png_structp png_ptr)
/* Offset to next interlace block in the y direction */ /* Offset to next interlace block in the y direction */
int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
#endif
#endif #endif
int ret; int ret;
@ -1962,7 +1959,7 @@ png_write_finish_row(png_structp png_ptr)
png_ptr->zstream.data_type = Z_BINARY; png_ptr->zstream.data_type = Z_BINARY;
} }
#if defined(PNG_WRITE_INTERLACING_SUPPORTED) #ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Pick out the correct pixels for the interlace pass. /* Pick out the correct pixels for the interlace pass.
* The basic idea here is to go through the row with a source * The basic idea here is to go through the row with a source
* pointer and a destination pointer (sp and dp), and copy the * pointer and a destination pointer (sp and dp), and copy the
@ -1973,7 +1970,6 @@ png_write_finish_row(png_structp png_ptr)
void /* PRIVATE */ void /* PRIVATE */
png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
{ {
#ifdef PNG_USE_LOCAL_ARRAYS
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* Start of interlace block */ /* Start of interlace block */
@ -1981,12 +1977,11 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
/* Offset to next interlace block */ /* Offset to next interlace block */
int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
#endif
png_debug(1, "in png_do_write_interlace"); png_debug(1, "in png_do_write_interlace");
/* We don't have to do anything on the last pass (6) */ /* We don't have to do anything on the last pass (6) */
#if defined(PNG_USELESS_TESTS_SUPPORTED) #ifdef PNG_USELESS_TESTS_SUPPORTED
if (row != NULL && row_info != NULL && pass < 6) if (row != NULL && row_info != NULL && pass < 6)
#else #else
if (pass < 6) if (pass < 6)
@ -2146,7 +2141,7 @@ void /* PRIVATE */
png_write_find_filter(png_structp png_ptr, png_row_infop row_info) png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{ {
png_bytep best_row; png_bytep best_row;
#ifndef PNG_NO_WRITE_FILTER #ifdef PNG_WRITE_FILTER_SUPPORTED
png_bytep prev_row, row_buf; png_bytep prev_row, row_buf;
png_uint_32 mins, bpp; png_uint_32 mins, bpp;
png_byte filter_to_do = png_ptr->do_filter; png_byte filter_to_do = png_ptr->do_filter;
@ -2157,13 +2152,21 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
png_debug(1, "in png_write_find_filter"); png_debug(1, "in png_write_find_filter");
#ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS)
{
/* These will never be selected so we need not test them. */
filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH);
}
#endif
/* Find out how many bytes offset each pixel is */ /* Find out how many bytes offset each pixel is */
bpp = (row_info->pixel_depth + 7) >> 3; bpp = (row_info->pixel_depth + 7) >> 3;
prev_row = png_ptr->prev_row; prev_row = png_ptr->prev_row;
#endif #endif
best_row = png_ptr->row_buf; best_row = png_ptr->row_buf;
#ifndef PNG_NO_WRITE_FILTER #ifdef PNG_WRITE_FILTER_SUPPORTED
row_buf = best_row; row_buf = best_row;
mins = PNG_MAXSUM; mins = PNG_MAXSUM;
@ -2206,7 +2209,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sum += (v < 128) ? v : 256 - v; sum += (v < 128) ? v : 256 - v;
} }
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{ {
png_uint_32 sumhi, sumlo; png_uint_32 sumhi, sumlo;
@ -2270,7 +2273,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
png_uint_32 i; png_uint_32 i;
int v; int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
/* We temporarily increase the "minimum sum" by the factor we /* We temporarily increase the "minimum sum" by the factor we
* would reduce the sum of this filter, so that we can do the * would reduce the sum of this filter, so that we can do the
* early exit comparison without scaling the sum each time. * early exit comparison without scaling the sum each time.
@ -2323,7 +2326,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
break; break;
} }
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{ {
int j; int j;
@ -2384,7 +2387,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
int v; int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{ {
int j; int j;
@ -2426,7 +2429,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
break; break;
} }
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{ {
int j; int j;
@ -2489,7 +2492,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
png_uint_32 i; png_uint_32 i;
int v; int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{ {
int j; int j;
@ -2538,7 +2541,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
break; break;
} }
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{ {
int j; int j;
@ -2622,7 +2625,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
png_uint_32 i; png_uint_32 i;
int v; int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{ {
int j; int j;
@ -2703,7 +2706,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
break; break;
} }
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{ {
int j; int j;
@ -2739,13 +2742,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
best_row = png_ptr->paeth_row; best_row = png_ptr->paeth_row;
} }
} }
#endif /* PNG_NO_WRITE_FILTER */ #endif /* PNG_WRITE_FILTER_SUPPORTED */
/* Do the actual writing of the filtered row data from the chosen filter. */ /* Do the actual writing of the filtered row data from the chosen filter. */
png_write_filtered_row(png_ptr, best_row); png_write_filtered_row(png_ptr, best_row);
#ifndef PNG_NO_WRITE_FILTER #ifdef PNG_WRITE_FILTER_SUPPORTED
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
/* Save the type of filter we picked this time for future calculations */ /* Save the type of filter we picked this time for future calculations */
if (png_ptr->num_prev_filters > 0) if (png_ptr->num_prev_filters > 0)
{ {
@ -2757,7 +2760,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
png_ptr->prev_filters[j] = best_row[0]; png_ptr->prev_filters[j] = best_row[0];
} }
#endif #endif
#endif /* PNG_NO_WRITE_FILTER */ #endif /* PNG_WRITE_FILTER_SUPPORTED */
} }
@ -2812,7 +2815,7 @@ png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
/* Finish row - updates counters and flushes zlib if last row */ /* Finish row - updates counters and flushes zlib if last row */
png_write_finish_row(png_ptr); png_write_finish_row(png_ptr);
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #ifdef PNG_WRITE_FLUSH_SUPPORTED
png_ptr->flush_rows++; png_ptr->flush_rows++;
if (png_ptr->flush_dist > 0 && if (png_ptr->flush_dist > 0 &&