提交 40b26036 编写于 作者: J John Bowler 提交者: Glenn Randers-Pehrson

[libpng16] Start-up code size improvements, error handler flexibility. These

changes alter how the tricky allocation of the initial png_struct and png_info
structures are handled. png_info is now handled in pretty much the same
way as everything else, except that the allocations handle NULL return
silently.  png_struct is changed in a similar way on allocation and on
deallocation a 'safety' error handler is put in place (which should never
be required).  The error handler itself is changed to permit mismatches
in the application and libpng error buffer size; however, this means a
silent change to the API to return the jmp_buf if the size doesn't match
the size from the libpng compilation; libpng now allocates the memory and
this may fail.  Overall these changes result in slight code size
reductions; however, this is a reduction in code that is always executed
so is particularly valuable.  Overall on a 64-bit system the libpng DLL
decreases in code size by 1733 bytes.  pngerror.o increases in size by
about 465 bytes because of the new functionality.
上级 ad41b883
...@@ -92,7 +92,7 @@ png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED) ...@@ -92,7 +92,7 @@ png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED)
void /* PRIVATE */ void /* PRIVATE */
png_zfree(voidpf png_ptr, voidpf ptr) png_zfree(voidpf png_ptr, voidpf ptr)
{ {
png_free((png_structp)png_ptr, (png_voidp)ptr); png_free(png_voidcast(png_const_structp,png_ptr), ptr);
} }
/* Reset the CRC variable to 32 bits of 1's. Care must be taken /* Reset the CRC variable to 32 bits of 1's. Care must be taken
...@@ -333,7 +333,7 @@ png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr, ...@@ -333,7 +333,7 @@ png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
/* Allocate the memory for an info_struct for the application. */ /* Allocate the memory for an info_struct for the application. */
PNG_FUNCTION(png_infop,PNGAPI PNG_FUNCTION(png_infop,PNGAPI
png_create_info_struct,(png_structp png_ptr),PNG_ALLOCATED) png_create_info_struct,(png_const_structp png_ptr),PNG_ALLOCATED)
{ {
png_infop info_ptr; png_infop info_ptr;
...@@ -365,7 +365,7 @@ png_create_info_struct,(png_structp png_ptr),PNG_ALLOCATED) ...@@ -365,7 +365,7 @@ png_create_info_struct,(png_structp png_ptr),PNG_ALLOCATED)
* it). * it).
*/ */
void PNGAPI void PNGAPI
png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) png_destroy_info_struct(png_const_structp png_ptr, png_infopp info_ptr_ptr)
{ {
png_infop info_ptr = NULL; png_infop info_ptr = NULL;
...@@ -427,7 +427,7 @@ png_info_init_3,(png_infopp ptr_ptr, png_size_t png_info_struct_size), ...@@ -427,7 +427,7 @@ png_info_init_3,(png_infopp ptr_ptr, png_size_t png_info_struct_size),
} }
void PNGAPI void PNGAPI
png_data_freer(png_structp png_ptr, png_infop info_ptr, png_data_freer(png_const_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");
...@@ -447,7 +447,7 @@ png_data_freer(png_structp png_ptr, png_infop info_ptr, ...@@ -447,7 +447,7 @@ png_data_freer(png_structp png_ptr, png_infop info_ptr,
} }
void PNGAPI void PNGAPI
png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, png_free_data(png_const_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");
...@@ -570,12 +570,6 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, ...@@ -570,12 +570,6 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
#endif #endif
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
if (png_ptr->unknown_chunk.data)
{
png_free(png_ptr, png_ptr->unknown_chunk.data);
png_ptr->unknown_chunk.data = NULL;
}
if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
{ {
if (num != -1) if (num != -1)
...@@ -617,7 +611,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, ...@@ -617,7 +611,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
/* Free any PLTE entry that was internally allocated */ /* Free any PLTE entry that was internally allocated */
if ((mask & PNG_FREE_PLTE) & info_ptr->free_me) if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
{ {
png_zfree(png_ptr, info_ptr->palette); png_free(png_ptr, info_ptr->palette);
info_ptr->palette = NULL; info_ptr->palette = NULL;
info_ptr->valid &= ~PNG_INFO_PLTE; info_ptr->valid &= ~PNG_INFO_PLTE;
info_ptr->num_palette = 0; info_ptr->num_palette = 0;
...@@ -653,21 +647,12 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, ...@@ -653,21 +647,12 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
* that png_free() checks for NULL pointers for us. * that png_free() checks for NULL pointers for us.
*/ */
void /* PRIVATE */ void /* PRIVATE */
png_info_destroy(png_structp png_ptr, png_infop info_ptr) png_info_destroy(png_const_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_info_destroy"); png_debug(1, "in png_info_destroy");
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
if (png_ptr->num_chunk_list)
{
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->chunk_list = NULL;
png_ptr->num_chunk_list = 0;
}
#endif
png_memset(info_ptr, 0, sizeof *info_ptr); png_memset(info_ptr, 0, sizeof *info_ptr);
} }
#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
...@@ -677,7 +662,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr) ...@@ -677,7 +662,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
* pointer before png_write_destroy() or png_read_destroy() are called. * pointer before png_write_destroy() or png_read_destroy() are called.
*/ */
png_voidp PNGAPI png_voidp PNGAPI
png_get_io_ptr(png_structp png_ptr) png_get_io_ptr(png_const_structp png_ptr)
{ {
if (png_ptr == NULL) if (png_ptr == NULL)
return (NULL); return (NULL);
...@@ -709,38 +694,31 @@ png_init_io(png_structp png_ptr, png_FILE_p fp) ...@@ -709,38 +694,31 @@ png_init_io(png_structp png_ptr, png_FILE_p fp)
/* 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.
*/ */
png_const_charp PNGAPI int PNGAPI
png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime) png_convert_to_rfc1123_buffer(char out[29], png_const_timep ptime)
{ {
static PNG_CONST char short_months[12][4] = static PNG_CONST char short_months[12][4] =
{"Jan", "Feb", "Mar", "Apr", "May", "Jun", {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
if (png_ptr == NULL) if (out == NULL)
return (NULL); return 0;
if (ptime->year > 9999 /* RFC1123 limitation */ || if (ptime->year > 9999 /* RFC1123 limitation */ ||
ptime->month == 0 || ptime->month > 12 || ptime->month == 0 || ptime->month > 12 ||
ptime->day == 0 || ptime->day > 31 || ptime->day == 0 || ptime->day > 31 ||
ptime->hour > 23 || ptime->minute > 59 || ptime->hour > 23 || ptime->minute > 59 ||
ptime->second > 60) ptime->second > 60)
{ return 0;
png_warning(png_ptr, "Ignoring invalid time value");
return (NULL);
}
{ {
size_t pos = 0; size_t pos = 0;
char number_buf[5]; /* enough for a four-digit year */ char number_buf[5]; /* enough for a four-digit year */
# define APPEND_STRING(string)\ # define APPEND_STRING(string) pos = png_safecat(out, 29, pos, (string))
pos = png_safecat(png_ptr->time_buffer, sizeof png_ptr->time_buffer,\
pos, (string))
# define APPEND_NUMBER(format, value)\ # define APPEND_NUMBER(format, value)\
APPEND_STRING(PNG_FORMAT_NUMBER(number_buf, format, (value))) APPEND_STRING(PNG_FORMAT_NUMBER(number_buf, format, (value)))
# define APPEND(ch)\ # define APPEND(ch) if (pos < 28) out[pos++] = (ch)
if (pos < (sizeof png_ptr->time_buffer)-1)\
png_ptr->time_buffer[pos++] = (ch)
APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day); APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day);
APPEND(' '); APPEND(' ');
...@@ -760,8 +738,30 @@ png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime) ...@@ -760,8 +738,30 @@ png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime)
# undef APPEND_STRING # undef APPEND_STRING
} }
return png_ptr->time_buffer; return 1;
}
# if PNG_LIBPNG_VER < 10700
/* Original API that uses a private buffer in png_struct.
* TODO: deprecate this, it causes png_struct to carry a spurious temporary
* buffer (png_struct::time_buffer), better to have the caller pass this in.
*/
png_const_charp PNGAPI
png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime)
{
if (png_ptr != NULL)
{
/* The only failure above if png_ptr != NULL is from an invalid ptime */
if (!png_convert_to_rfc1123_buffer(png_ptr->time_buffer, ptime))
png_warning(png_ptr, "Ignoring invalid time value");
else
return png_ptr->time_buffer;
}
return NULL;
} }
# endif
# endif /* PNG_TIME_RFC1123_SUPPORTED */ # endif /* PNG_TIME_RFC1123_SUPPORTED */
#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
...@@ -775,13 +775,13 @@ png_get_copyright(png_const_structp png_ptr) ...@@ -775,13 +775,13 @@ png_get_copyright(png_const_structp png_ptr)
#else #else
# ifdef __STDC__ # ifdef __STDC__
return PNG_STRING_NEWLINE \ return PNG_STRING_NEWLINE \
"libpng version 1.6.0beta03 - December 21, 2011" PNG_STRING_NEWLINE \ "libpng version 1.6.0beta03 - December 22, 2011" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE; PNG_STRING_NEWLINE;
# else # else
return "libpng version 1.6.0beta03 - December 21, 2011\ return "libpng version 1.6.0beta03 - December 22, 2011\
Copyright (c) 1998-2011 Glenn Randers-Pehrson\ Copyright (c) 1998-2011 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
...@@ -1256,7 +1256,7 @@ int png_XYZ_from_xy(png_XYZ *XYZ, png_xy xy) ...@@ -1256,7 +1256,7 @@ int png_XYZ_from_xy(png_XYZ *XYZ, png_xy xy)
return 0; /*success*/ return 0; /*success*/
} }
int png_XYZ_from_xy_checked(png_structp png_ptr, png_XYZ *XYZ, png_xy xy) int png_XYZ_from_xy_checked(png_const_structp png_ptr, png_XYZ *XYZ, png_xy xy)
{ {
switch (png_XYZ_from_xy(XYZ, xy)) switch (png_XYZ_from_xy(XYZ, xy))
{ {
...@@ -1286,7 +1286,7 @@ int png_XYZ_from_xy_checked(png_structp png_ptr, png_XYZ *XYZ, png_xy xy) ...@@ -1286,7 +1286,7 @@ int png_XYZ_from_xy_checked(png_structp png_ptr, png_XYZ *XYZ, png_xy xy)
#endif #endif
void /* PRIVATE */ void /* PRIVATE */
png_check_IHDR(png_structp png_ptr, png_check_IHDR(png_const_structp png_ptr,
png_uint_32 width, png_uint_32 height, int bit_depth, png_uint_32 width, png_uint_32 height, int bit_depth,
int color_type, int interlace_type, int compression_type, int color_type, int interlace_type, int compression_type,
int filter_type) int filter_type)
...@@ -2008,7 +2008,7 @@ png_ascii_from_fixed(png_structp png_ptr, png_charp ascii, png_size_t size, ...@@ -2008,7 +2008,7 @@ png_ascii_from_fixed(png_structp png_ptr, png_charp ascii, png_size_t size,
#if defined(PNG_FLOATING_POINT_SUPPORTED) && \ #if defined(PNG_FLOATING_POINT_SUPPORTED) && \
!defined(PNG_FIXED_POINT_MACRO_SUPPORTED) !defined(PNG_FIXED_POINT_MACRO_SUPPORTED)
png_fixed_point png_fixed_point
png_fixed(png_structp png_ptr, double fp, png_const_charp text) png_fixed(png_const_structp png_ptr, double fp, png_const_charp text)
{ {
double r = floor(100000 * fp + .5); double r = floor(100000 * fp + .5);
...@@ -2147,7 +2147,7 @@ png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, ...@@ -2147,7 +2147,7 @@ png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times,
* result. * result.
*/ */
png_fixed_point png_fixed_point
png_muldiv_warn(png_structp png_ptr, png_fixed_point a, png_int_32 times, png_muldiv_warn(png_const_structp png_ptr, png_fixed_point a, png_int_32 times,
png_int_32 divisor) png_int_32 divisor)
{ {
png_fixed_point result; png_fixed_point result;
......
此差异已折叠。
/* pngconf.h - machine configurable file for libpng /* pngconf.h - machine configurable file for libpng
* *
* libpng version 1.6.0beta03 - December 21, 2011 * libpng version 1.6.0beta03 - December 22, 2011
* *
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
......
...@@ -20,12 +20,12 @@ ...@@ -20,12 +20,12 @@
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
static PNG_FUNCTION(void, png_default_error,PNGARG((png_structp png_ptr, static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structp png_ptr,
png_const_charp error_message)),PNG_NORETURN); png_const_charp error_message)),PNG_NORETURN);
#ifdef PNG_WARNINGS_SUPPORTED #ifdef PNG_WARNINGS_SUPPORTED
static void /* PRIVATE */ static void /* PRIVATE */
png_default_warning PNGARG((png_structp png_ptr, png_default_warning PNGARG((png_const_structp png_ptr,
png_const_charp warning_message)); png_const_charp warning_message));
#endif /* PNG_WARNINGS_SUPPORTED */ #endif /* PNG_WARNINGS_SUPPORTED */
...@@ -36,7 +36,8 @@ png_default_warning PNGARG((png_structp png_ptr, ...@@ -36,7 +36,8 @@ png_default_warning PNGARG((png_structp png_ptr,
*/ */
#ifdef PNG_ERROR_TEXT_SUPPORTED #ifdef PNG_ERROR_TEXT_SUPPORTED
PNG_FUNCTION(void,PNGAPI PNG_FUNCTION(void,PNGAPI
png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN) png_error,(png_const_structp png_ptr, png_const_charp error_message),
PNG_NORETURN)
{ {
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
char msg[16]; char msg[16];
...@@ -79,7 +80,7 @@ png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN) ...@@ -79,7 +80,7 @@ png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN)
} }
#endif #endif
if (png_ptr != NULL && png_ptr->error_fn != NULL) if (png_ptr != NULL && png_ptr->error_fn != NULL)
(*(png_ptr->error_fn))(png_ptr, error_message); (*(png_ptr->error_fn))(png_constcast(png_structp,png_ptr), error_message);
/* If the custom handler doesn't exist, or if it returns, /* If the custom handler doesn't exist, or if it returns,
use the default handler, which will not return. */ use the default handler, which will not return. */
...@@ -87,7 +88,7 @@ png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN) ...@@ -87,7 +88,7 @@ png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN)
} }
#else #else
PNG_FUNCTION(void,PNGAPI PNG_FUNCTION(void,PNGAPI
png_err,(png_structp png_ptr),PNG_NORETURN) png_err,(png_const_structp png_ptr),PNG_NORETURN)
{ {
/* Prior to 1.5.2 the error_fn received a NULL pointer, expressed /* Prior to 1.5.2 the error_fn received a NULL pointer, expressed
* erroneously as '\0', instead of the empty string "". This was * erroneously as '\0', instead of the empty string "". This was
...@@ -211,7 +212,7 @@ png_format_number(png_const_charp start, png_charp end, int format, ...@@ -211,7 +212,7 @@ png_format_number(png_const_charp start, png_charp end, int format,
* png_set_error_fn() to replace the warning function at run-time. * png_set_error_fn() to replace the warning function at run-time.
*/ */
void PNGAPI void PNGAPI
png_warning(png_structp png_ptr, png_const_charp warning_message) png_warning(png_const_structp png_ptr, png_const_charp warning_message)
{ {
int offset = 0; int offset = 0;
if (png_ptr != NULL) if (png_ptr != NULL)
...@@ -230,7 +231,8 @@ png_warning(png_structp png_ptr, png_const_charp warning_message) ...@@ -230,7 +231,8 @@ png_warning(png_structp png_ptr, png_const_charp warning_message)
} }
} }
if (png_ptr != NULL && png_ptr->warning_fn != NULL) if (png_ptr != NULL && png_ptr->warning_fn != NULL)
(*(png_ptr->warning_fn))(png_ptr, warning_message + offset); (*(png_ptr->warning_fn))(png_constcast(png_structp,png_ptr),
warning_message + offset);
else else
png_default_warning(png_ptr, warning_message + offset); png_default_warning(png_ptr, warning_message + offset);
} }
...@@ -278,7 +280,7 @@ png_warning_parameter_signed(png_warning_parameters p, int number, int format, ...@@ -278,7 +280,7 @@ png_warning_parameter_signed(png_warning_parameters p, int number, int format,
} }
void void
png_formatted_warning(png_structp png_ptr, png_warning_parameters p, png_formatted_warning(png_const_structp png_ptr, png_warning_parameters p,
png_const_charp message) png_const_charp message)
{ {
/* The internal buffer is just 128 bytes - enough for all our messages, /* The internal buffer is just 128 bytes - enough for all our messages,
...@@ -347,7 +349,7 @@ png_formatted_warning(png_structp png_ptr, png_warning_parameters p, ...@@ -347,7 +349,7 @@ png_formatted_warning(png_structp png_ptr, png_warning_parameters p,
#ifdef PNG_BENIGN_ERRORS_SUPPORTED #ifdef PNG_BENIGN_ERRORS_SUPPORTED
void PNGAPI void PNGAPI
png_benign_error(png_structp png_ptr, png_const_charp error_message) png_benign_error(png_const_structp png_ptr, png_const_charp error_message)
{ {
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
png_warning(png_ptr, error_message); png_warning(png_ptr, error_message);
...@@ -371,7 +373,7 @@ static PNG_CONST char png_digit[16] = { ...@@ -371,7 +373,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_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
static void /* PRIVATE */ static void /* PRIVATE */
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp png_format_buffer(png_const_structp png_ptr, png_charp buffer, png_const_charp
error_message) error_message)
{ {
png_uint_32 chunk_name = png_ptr->chunk_name; png_uint_32 chunk_name = png_ptr->chunk_name;
...@@ -417,7 +419,7 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp ...@@ -417,7 +419,7 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) #if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
PNG_FUNCTION(void,PNGAPI PNG_FUNCTION(void,PNGAPI
png_chunk_error,(png_structp png_ptr, png_const_charp error_message), png_chunk_error,(png_const_structp png_ptr, png_const_charp error_message),
PNG_NORETURN) PNG_NORETURN)
{ {
char msg[18+PNG_MAX_ERROR_TEXT]; char msg[18+PNG_MAX_ERROR_TEXT];
...@@ -434,7 +436,7 @@ png_chunk_error,(png_structp png_ptr, png_const_charp error_message), ...@@ -434,7 +436,7 @@ png_chunk_error,(png_structp png_ptr, png_const_charp error_message),
#ifdef PNG_WARNINGS_SUPPORTED #ifdef PNG_WARNINGS_SUPPORTED
void PNGAPI void PNGAPI
png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) png_chunk_warning(png_const_structp png_ptr, png_const_charp warning_message)
{ {
char msg[18+PNG_MAX_ERROR_TEXT]; char msg[18+PNG_MAX_ERROR_TEXT];
if (png_ptr == NULL) if (png_ptr == NULL)
...@@ -451,7 +453,7 @@ png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) ...@@ -451,7 +453,7 @@ png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
#ifdef PNG_READ_SUPPORTED #ifdef PNG_READ_SUPPORTED
#ifdef PNG_BENIGN_ERRORS_SUPPORTED #ifdef PNG_BENIGN_ERRORS_SUPPORTED
void PNGAPI void PNGAPI
png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message) png_chunk_benign_error(png_const_structp png_ptr, png_const_charp error_message)
{ {
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
png_chunk_warning(png_ptr, error_message); png_chunk_warning(png_ptr, error_message);
...@@ -465,7 +467,7 @@ png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message) ...@@ -465,7 +467,7 @@ png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message)
#ifdef PNG_ERROR_TEXT_SUPPORTED #ifdef PNG_ERROR_TEXT_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
PNG_FUNCTION(void, PNG_FUNCTION(void,
png_fixed_error,(png_structp png_ptr, png_const_charp name),PNG_NORETURN) png_fixed_error,(png_const_structp png_ptr, png_const_charp name),PNG_NORETURN)
{ {
# define fixed_message "fixed point overflow in " # define fixed_message "fixed point overflow in "
# define fixed_message_ln ((sizeof fixed_message)-1) # define fixed_message_ln ((sizeof fixed_message)-1)
...@@ -603,7 +605,7 @@ png_free_jmpbuf(png_structp png_ptr) ...@@ -603,7 +605,7 @@ png_free_jmpbuf(png_structp png_ptr)
* error function pointer in png_set_error_fn(). * error function pointer in png_set_error_fn().
*/ */
static PNG_FUNCTION(void /* PRIVATE */, static PNG_FUNCTION(void /* PRIVATE */,
png_default_error,(png_structp png_ptr, png_const_charp error_message), png_default_error,(png_const_structp png_ptr, png_const_charp error_message),
PNG_NORETURN) PNG_NORETURN)
{ {
#ifdef PNG_CONSOLE_IO_SUPPORTED #ifdef PNG_CONSOLE_IO_SUPPORTED
...@@ -650,7 +652,7 @@ png_default_error,(png_structp png_ptr, png_const_charp error_message), ...@@ -650,7 +652,7 @@ png_default_error,(png_structp png_ptr, png_const_charp error_message),
} }
PNG_FUNCTION(void,PNGAPI PNG_FUNCTION(void,PNGAPI
png_longjmp,(png_structp png_ptr, int val),PNG_NORETURN) png_longjmp,(png_const_structp png_ptr, int val),PNG_NORETURN)
{ {
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
if (png_ptr && png_ptr->longjmp_fn && png_ptr->jmp_buf_ptr) if (png_ptr && png_ptr->longjmp_fn && png_ptr->jmp_buf_ptr)
...@@ -668,7 +670,7 @@ png_longjmp,(png_structp png_ptr, int val),PNG_NORETURN) ...@@ -668,7 +670,7 @@ png_longjmp,(png_structp png_ptr, int val),PNG_NORETURN)
* not used, but it is passed in case it may be useful. * not used, but it is passed in case it may be useful.
*/ */
static void /* PRIVATE */ static void /* PRIVATE */
png_default_warning(png_structp png_ptr, png_const_charp warning_message) png_default_warning(png_const_structp png_ptr, png_const_charp warning_message)
{ {
#ifdef PNG_CONSOLE_IO_SUPPORTED #ifdef PNG_CONSOLE_IO_SUPPORTED
# ifdef PNG_ERROR_NUMBERS_SUPPORTED # ifdef PNG_ERROR_NUMBERS_SUPPORTED
...@@ -768,9 +770,10 @@ png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode) ...@@ -768,9 +770,10 @@ png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
* way to handle the error return here: * way to handle the error return here:
*/ */
PNG_FUNCTION(void /* PRIVATE */, PNG_FUNCTION(void /* PRIVATE */,
png_safe_error,(png_structp png_ptr, png_const_charp error_message), png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message),
PNG_NORETURN) PNG_NORETURN)
{ {
const png_const_structp png_ptr = png_nonconst_ptr;
png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr); png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
/* An error is always logged here, overwriting anything (typically a warning) /* An error is always logged here, overwriting anything (typically a warning)
...@@ -802,8 +805,9 @@ png_safe_error,(png_structp png_ptr, png_const_charp error_message), ...@@ -802,8 +805,9 @@ png_safe_error,(png_structp png_ptr, png_const_charp error_message),
#ifdef PNG_WARNINGS_SUPPORTED #ifdef PNG_WARNINGS_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_safe_warning(png_structp png_ptr, png_const_charp warning_message) png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message)
{ {
const png_const_structp png_ptr = png_nonconst_ptr;
png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr); png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
/* A warning is only logged if there is no prior warning or error. */ /* A warning is only logged if there is no prior warning or error. */
......
...@@ -47,7 +47,7 @@ png_destroy_png_struct(png_structp png_ptr) ...@@ -47,7 +47,7 @@ png_destroy_png_struct(png_structp png_ptr)
* have the ability to do that. * have the ability to do that.
*/ */
PNG_FUNCTION(png_voidp,PNGAPI PNG_FUNCTION(png_voidp,PNGAPI
png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) png_calloc,(png_const_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
{ {
png_voidp ret; png_voidp ret;
...@@ -65,7 +65,8 @@ png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) ...@@ -65,7 +65,8 @@ png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
* if the allocation cannot be done (for any reason.) * if the allocation cannot be done (for any reason.)
*/ */
PNG_FUNCTION(png_voidp /* PRIVATE */, PNG_FUNCTION(png_voidp /* PRIVATE */,
png_malloc_base,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) png_malloc_base,(png_const_structp png_ptr, png_alloc_size_t size),
PNG_ALLOCATED)
{ {
/* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS /* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS
* allocators have also been removed in 1.6.0, so any 16-bit system now has * allocators have also been removed in 1.6.0, so any 16-bit system now has
...@@ -83,7 +84,7 @@ png_malloc_base,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) ...@@ -83,7 +84,7 @@ png_malloc_base,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
{ {
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
if (png_ptr != NULL && png_ptr->malloc_fn != NULL) if (png_ptr != NULL && png_ptr->malloc_fn != NULL)
return png_ptr->malloc_fn(png_ptr, size); return png_ptr->malloc_fn(png_constcast(png_structp,png_ptr), size);
else else
#endif #endif
...@@ -99,7 +100,7 @@ png_malloc_base,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) ...@@ -99,7 +100,7 @@ png_malloc_base,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
* function png_malloc_default is also provided. * function png_malloc_default is also provided.
*/ */
PNG_FUNCTION(png_voidp,PNGAPI PNG_FUNCTION(png_voidp,PNGAPI
png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) png_malloc,(png_const_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
{ {
png_voidp ret; png_voidp ret;
...@@ -116,7 +117,7 @@ png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) ...@@ -116,7 +117,7 @@ png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
PNG_FUNCTION(png_voidp,PNGAPI PNG_FUNCTION(png_voidp,PNGAPI
png_malloc_default,(png_structp png_ptr, png_alloc_size_t size), png_malloc_default,(png_const_structp png_ptr, png_alloc_size_t size),
PNG_ALLOCATED PNG_DEPRECATED) PNG_ALLOCATED PNG_DEPRECATED)
{ {
png_voidp ret; png_voidp ret;
...@@ -139,7 +140,8 @@ png_malloc_default,(png_structp png_ptr, png_alloc_size_t size), ...@@ -139,7 +140,8 @@ png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),
* png_error, if it fails to allocate the requested memory. * png_error, if it fails to allocate the requested memory.
*/ */
PNG_FUNCTION(png_voidp,PNGAPI PNG_FUNCTION(png_voidp,PNGAPI
png_malloc_warn,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) png_malloc_warn,(png_const_structp png_ptr, png_alloc_size_t size),
PNG_ALLOCATED)
{ {
if (png_ptr != NULL) if (png_ptr != NULL)
{ {
...@@ -158,21 +160,21 @@ png_malloc_warn,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) ...@@ -158,21 +160,21 @@ png_malloc_warn,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
* without taking any action. * without taking any action.
*/ */
void PNGAPI void PNGAPI
png_free(png_structp png_ptr, png_voidp ptr) png_free(png_const_structp png_ptr, png_voidp ptr)
{ {
if (png_ptr == NULL || ptr == NULL) if (png_ptr == NULL || ptr == NULL)
return; return;
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
if (png_ptr->free_fn != NULL) if (png_ptr->free_fn != NULL)
png_ptr->free_fn(png_ptr, ptr); png_ptr->free_fn(png_constcast(png_structp,png_ptr), ptr);
else else
png_free_default(png_ptr, ptr); png_free_default(png_ptr, ptr);
} }
PNG_FUNCTION(void,PNGAPI PNG_FUNCTION(void,PNGAPI
png_free_default,(png_structp png_ptr, png_voidp ptr),PNG_DEPRECATED) png_free_default,(png_const_structp png_ptr, png_voidp ptr),PNG_DEPRECATED)
{ {
if (png_ptr == NULL || ptr == NULL) if (png_ptr == NULL || ptr == NULL)
return; return;
......
...@@ -1805,7 +1805,7 @@ png_push_have_row(png_structp png_ptr, png_bytep row) ...@@ -1805,7 +1805,7 @@ png_push_have_row(png_structp png_ptr, png_bytep row)
#ifdef PNG_READ_INTERLACING_SUPPORTED #ifdef PNG_READ_INTERLACING_SUPPORTED
void PNGAPI void PNGAPI
png_progressive_combine_row (png_structp png_ptr, png_bytep old_row, png_progressive_combine_row(png_const_structp png_ptr, png_bytep old_row,
png_const_bytep new_row) png_const_bytep new_row)
{ {
if (png_ptr == NULL) if (png_ptr == NULL)
......
...@@ -240,8 +240,10 @@ typedef const png_uint_16p * png_const_uint_16pp; ...@@ -240,8 +240,10 @@ typedef const png_uint_16p * png_const_uint_16pp;
*/ */
#ifdef __cplusplus #ifdef __cplusplus
# define png_voidcast(type, value) static_cast<type>(value) # define png_voidcast(type, value) static_cast<type>(value)
# define png_constcast(type, value) const_cast<type>(value)
#else #else
# define png_voidcast(type, value) (value) # define png_voidcast(type, value) (value)
# define png_constcast(type, value) ((type)(value))
#endif /* __cplusplus */ #endif /* __cplusplus */
#ifndef PNG_EXTERN #ifndef PNG_EXTERN
...@@ -596,8 +598,8 @@ extern /*PRIVATE*/ PNG_CONST_DATA png_byte png_sRGB_delta[512]; ...@@ -596,8 +598,8 @@ extern /*PRIVATE*/ PNG_CONST_DATA png_byte png_sRGB_delta[512];
#define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\ #define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\
((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0)) ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0))
#else #else
PNG_EXTERN png_fixed_point png_fixed PNGARG((png_structp png_ptr, double fp, PNG_EXTERN png_fixed_point png_fixed PNGARG((png_const_structp png_ptr,
png_const_charp text)); double fp, png_const_charp text));
#endif #endif
#endif #endif
...@@ -691,8 +693,8 @@ PNG_EXTERN int png_user_version_check PNGARG((png_structp png_ptr, ...@@ -691,8 +693,8 @@ PNG_EXTERN int png_user_version_check PNGARG((png_structp png_ptr,
* does, however, call the application provided allocator and that could call * does, however, call the application provided allocator and that could call
* png_error (although that would be a bug in the application implementation.) * png_error (although that would be a bug in the application implementation.)
*/ */
PNG_EXTERN PNG_FUNCTION(png_voidp,png_malloc_base,PNGARG((png_structp png_ptr, PNG_EXTERN PNG_FUNCTION(png_voidp,png_malloc_base,
png_alloc_size_t size)),PNG_ALLOCATED); PNGARG((png_const_structp png_ptr, png_alloc_size_t size)),PNG_ALLOCATED);
/* Magic to create a struct when there is no struct to call the user supplied /* Magic to create a struct when there is no struct to call the user supplied
* memory allocators. Because error handling has not been set up the memory * memory allocators. Because error handling has not been set up the memory
...@@ -706,14 +708,10 @@ PNG_EXTERN PNG_FUNCTION(png_structp,png_create_png_struct, ...@@ -706,14 +708,10 @@ PNG_EXTERN PNG_FUNCTION(png_structp,png_create_png_struct,
png_malloc_ptr malloc_fn, png_free_ptr free_fn)),PNG_ALLOCATED); png_malloc_ptr malloc_fn, png_free_ptr free_fn)),PNG_ALLOCATED);
/* Free memory from internal libpng struct */ /* Free memory from internal libpng struct */
#if 0 /* no longer used */
PNG_EXTERN void png_destroy_struct_2 PNGARG((png_structp png_ptr,
png_voidp struct_ptr));
#endif
PNG_EXTERN void png_destroy_png_struct PNGARG((png_structp png_ptr)); PNG_EXTERN void png_destroy_png_struct PNGARG((png_structp png_ptr));
/* Free any memory that info_ptr points to and reset struct. */ /* Free any memory that info_ptr points to and reset struct. */
PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, PNG_EXTERN void png_info_destroy PNGARG((png_const_structp png_ptr,
png_infop info_ptr)); png_infop info_ptr));
/* Free an allocated jmp_buf (always succeeds) */ /* Free an allocated jmp_buf (always succeeds) */
...@@ -960,8 +958,8 @@ PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr)); ...@@ -960,8 +958,8 @@ PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
#ifndef PNG_USE_COMPILE_TIME_MASKS #ifndef PNG_USE_COMPILE_TIME_MASKS
# define PNG_USE_COMPILE_TIME_MASKS 1 # define PNG_USE_COMPILE_TIME_MASKS 1
#endif #endif
PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row, PNG_EXTERN void png_combine_row PNGARG((png_const_structp png_ptr,
int display)); png_bytep row, int display));
#ifdef PNG_READ_INTERLACING_SUPPORTED #ifdef PNG_READ_INTERLACING_SUPPORTED
/* Expand an interlaced row: the 'row_info' describes the pass data that has /* Expand an interlaced row: the 'row_info' describes the pass data that has
...@@ -1378,18 +1376,18 @@ typedef struct png_XYZ ...@@ -1378,18 +1376,18 @@ typedef struct png_XYZ
*/ */
PNG_EXTERN int png_xy_from_XYZ PNGARG((png_xy *xy, png_XYZ XYZ)); PNG_EXTERN int png_xy_from_XYZ PNGARG((png_xy *xy, png_XYZ XYZ));
PNG_EXTERN int png_XYZ_from_xy PNGARG((png_XYZ *XYZ, png_xy xy)); PNG_EXTERN int png_XYZ_from_xy PNGARG((png_XYZ *XYZ, png_xy xy));
PNG_EXTERN int png_XYZ_from_xy_checked PNGARG((png_structp png_ptr, PNG_EXTERN int png_XYZ_from_xy_checked PNGARG((png_const_structp png_ptr,
png_XYZ *XYZ, png_xy xy)); png_XYZ *XYZ, png_xy xy));
#endif #endif
/* Added at libpng version 1.4.0 */ /* Added at libpng version 1.4.0 */
PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr, PNG_EXTERN void png_check_IHDR PNGARG((png_const_structp png_ptr,
png_uint_32 width, png_uint_32 height, int bit_depth, png_uint_32 width, png_uint_32 height, int bit_depth,
int color_type, int interlace_type, int compression_type, int color_type, int interlace_type, int compression_type,
int filter_type)); int filter_type));
#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr, PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_const_structp png_ptr,
png_const_charp name),PNG_NORETURN); png_const_charp name),PNG_NORETURN);
#endif #endif
...@@ -1455,7 +1453,7 @@ PNG_EXTERN void png_warning_parameter_unsigned(png_warning_parameters p, ...@@ -1455,7 +1453,7 @@ PNG_EXTERN void png_warning_parameter_unsigned(png_warning_parameters p,
PNG_EXTERN void png_warning_parameter_signed(png_warning_parameters p, PNG_EXTERN void png_warning_parameter_signed(png_warning_parameters p,
int number, int format, png_int_32 value); int number, int format, png_int_32 value);
PNG_EXTERN void png_formatted_warning(png_structp png_ptr, PNG_EXTERN void png_formatted_warning(png_const_structp png_ptr,
png_warning_parameters p, png_const_charp message); png_warning_parameters p, png_const_charp message);
/* 'message' follows the X/Open approach of using @1, @2 to insert /* 'message' follows the X/Open approach of using @1, @2 to insert
* parameters previously supplied using the above functions. Errors in * parameters previously supplied using the above functions. Errors in
...@@ -1600,7 +1598,7 @@ PNG_EXTERN int png_muldiv PNGARG((png_fixed_point_p res, png_fixed_point a, ...@@ -1600,7 +1598,7 @@ PNG_EXTERN int png_muldiv PNGARG((png_fixed_point_p res, png_fixed_point a,
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED) #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
/* Same deal, but issue a warning on overflow and return 0. */ /* Same deal, but issue a warning on overflow and return 0. */
PNG_EXTERN png_fixed_point png_muldiv_warn PNGARG((png_structp png_ptr, PNG_EXTERN png_fixed_point png_muldiv_warn PNGARG((png_const_structp png_ptr,
png_fixed_point a, png_int_32 multiplied_by, png_int_32 divided_by)); png_fixed_point a, png_int_32 multiplied_by, png_int_32 divided_by));
#endif #endif
......
...@@ -920,6 +920,14 @@ png_read_destroy(png_structp png_ptr) ...@@ -920,6 +920,14 @@ png_read_destroy(png_structp png_ptr)
#endif /* PNG_TEXT_SUPPORTED */ #endif /* PNG_TEXT_SUPPORTED */
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
png_free(png_ptr, png_ptr->unknown_chunk.data);
#endif
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
png_free(png_ptr, png_ptr->chunk_list);
#endif
/* NOTE: the 'setjmp' buffer may still be allocated and the memory and error /* NOTE: the 'setjmp' buffer may still be allocated and the memory and error
* callbacks are still set at this point. They are required to complete the * callbacks are still set at this point. They are required to complete the
* destruction of the png_struct itself. * destruction of the png_struct itself.
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#define png_strtod(p,a,b) strtod(a,b) #define png_strtod(p,a,b) strtod(a,b)
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_uint_31(png_structp png_ptr, png_const_bytep buf) png_get_uint_31(png_const_structp png_ptr, png_const_bytep buf)
{ {
png_uint_32 uval = png_get_uint_32(buf); png_uint_32 uval = png_get_uint_32(buf);
...@@ -2783,7 +2783,7 @@ png_check_chunk_name(png_structp png_ptr, png_uint_32 chunk_name) ...@@ -2783,7 +2783,7 @@ png_check_chunk_name(png_structp png_ptr, png_uint_32 chunk_name)
* 'display' is false only those pixels present in the pass are filled in. * 'display' is false only those pixels present in the pass are filled in.
*/ */
void /* PRIVATE */ void /* PRIVATE */
png_combine_row(png_structp png_ptr, png_bytep dp, int display) png_combine_row(png_const_structp png_ptr, png_bytep dp, int display)
{ {
unsigned int pixel_depth = png_ptr->transformed_pixel_depth; unsigned int pixel_depth = png_ptr->transformed_pixel_depth;
png_const_bytep sp = png_ptr->row_buf + 1; png_const_bytep sp = png_ptr->row_buf + 1;
......
...@@ -1024,9 +1024,9 @@ png_set_unknown_chunks(png_structp png_ptr, ...@@ -1024,9 +1024,9 @@ png_set_unknown_chunks(png_structp png_ptr,
if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0) if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
return; return;
np = (png_unknown_chunkp)png_malloc_warn(png_ptr, np = png_voidcast(png_unknown_chunkp, png_malloc_warn(png_ptr,
(png_size_t)(info_ptr->unknown_chunks_num + num_unknowns) * (png_size_t)(info_ptr->unknown_chunks_num + num_unknowns) *
png_sizeof(png_unknown_chunk)); png_sizeof(png_unknown_chunk)));
if (np == NULL) if (np == NULL)
{ {
...@@ -1223,7 +1223,7 @@ png_set_compression_buffer_size(png_structp png_ptr, png_size_t size) ...@@ -1223,7 +1223,7 @@ png_set_compression_buffer_size(png_structp png_ptr, png_size_t size)
} }
void PNGAPI void PNGAPI
png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) png_set_invalid(png_const_structp png_ptr, png_infop info_ptr, int mask)
{ {
if (png_ptr && info_ptr) if (png_ptr && info_ptr)
info_ptr->valid &= ~mask; info_ptr->valid &= ~mask;
......
...@@ -140,8 +140,10 @@ struct png_struct_def ...@@ -140,8 +140,10 @@ struct png_struct_def
/* pixel depth used for the row buffers */ /* pixel depth used for the row buffers */
png_byte transformed_pixel_depth; png_byte transformed_pixel_depth;
/* pixel depth after read/write transforms */ /* pixel depth after read/write transforms */
#if PNG_LIBPNG_VER < 10600
png_byte io_chunk_string[5]; png_byte io_chunk_string[5];
/* string name of chunk */ /* string name of chunk */
#endif
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
png_uint_16 filler; /* filler bytes for pixel expansion */ png_uint_16 filler; /* filler bytes for pixel expansion */
...@@ -250,9 +252,11 @@ struct png_struct_def ...@@ -250,9 +252,11 @@ struct png_struct_def
png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */ png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
#endif #endif
#if PNG_LIBPNG_VER < 10700
#ifdef PNG_TIME_RFC1123_SUPPORTED #ifdef PNG_TIME_RFC1123_SUPPORTED
char time_buffer[29]; /* String to hold RFC 1123 time text */ char time_buffer[29]; /* String to hold RFC 1123 time text */
#endif #endif
#endif
/* New members added in libpng-1.0.6 */ /* New members added in libpng-1.0.6 */
...@@ -338,9 +342,13 @@ struct png_struct_def ...@@ -338,9 +342,13 @@ struct png_struct_def
/* New member added in libpng-1.0.25 and 1.2.17 */ /* New member added in libpng-1.0.25 and 1.2.17 */
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
/* Storage for unknown chunk that the library doesn't recognize. */ /* Temporary storage for unknown chunk that the library doesn't recognize,
* used while reading the chunk.
*/
#ifdef PNG_READ_SUPPORTED
png_unknown_chunk unknown_chunk; png_unknown_chunk unknown_chunk;
#endif #endif
#endif
/* New member added in libpng-1.2.26 */ /* New member added in libpng-1.2.26 */
png_size_t old_big_row_buf_size; png_size_t old_big_row_buf_size;
......
...@@ -1036,14 +1036,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) ...@@ -1036,14 +1036,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{ {
png_set_tIME(write_ptr, write_info_ptr, mod_time); png_set_tIME(write_ptr, write_info_ptr, mod_time);
#ifdef PNG_TIME_RFC1123_SUPPORTED #ifdef PNG_TIME_RFC1123_SUPPORTED
/* We have to use memcpy instead of "=" because the string if (png_convert_to_rfc1123_buffer(tIME_string, mod_time))
* pointed to by png_convert_to_rfc1123() gets free'ed before tIME_string[png_sizeof(tIME_string) - 1] = '\0';
* we use it.
*/ else
memcpy(tIME_string, png_convert_to_rfc1123(read_ptr, mod_time), strcpy(tIME_string, "*** invalid time ***");
png_sizeof(tIME_string));
tIME_string[png_sizeof(tIME_string) - 1] = '\0';
tIME_chunk_present++; tIME_chunk_present++;
#endif /* PNG_TIME_RFC1123_SUPPORTED */ #endif /* PNG_TIME_RFC1123_SUPPORTED */
} }
...@@ -1231,13 +1229,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) ...@@ -1231,13 +1229,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{ {
png_set_tIME(write_ptr, write_end_info_ptr, mod_time); png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
#ifdef PNG_TIME_RFC1123_SUPPORTED #ifdef PNG_TIME_RFC1123_SUPPORTED
/* We have to use memcpy instead of "=" because the string if (png_convert_to_rfc1123_buffer(tIME_string, mod_time))
pointed to by png_convert_to_rfc1123() gets free'ed before tIME_string[png_sizeof(tIME_string) - 1] = '\0';
we use it */
memcpy(tIME_string, png_convert_to_rfc1123(read_ptr, mod_time), else
png_sizeof(tIME_string)); strcpy(tIME_string, "*** invalid time ***");
tIME_string[png_sizeof(tIME_string) - 1] = '\0';
tIME_chunk_present++; tIME_chunk_present++;
#endif /* PNG_TIME_RFC1123_SUPPORTED */ #endif /* PNG_TIME_RFC1123_SUPPORTED */
} }
......
...@@ -34,7 +34,8 @@ png_write_data(png_structp png_ptr, png_const_bytep data, png_size_t length) ...@@ -34,7 +34,8 @@ png_write_data(png_structp png_ptr, png_const_bytep data, png_size_t length)
{ {
/* NOTE: write_data_fn must not change the buffer! */ /* NOTE: write_data_fn must not change the buffer! */
if (png_ptr->write_data_fn != NULL ) if (png_ptr->write_data_fn != NULL )
(*(png_ptr->write_data_fn))(png_ptr, (png_bytep)data, length); (*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data),
length);
else else
png_error(png_ptr, "Call to NULL write function"); png_error(png_ptr, "Call to NULL write function");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册