From 40b2603687bb0bc9828306fd2183f35706d32b8e Mon Sep 17 00:00:00 2001 From: John Bowler Date: Thu, 22 Dec 2011 08:09:15 -0600 Subject: [PATCH] [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. --- png.c | 88 ++++++------ png.h | 378 ++++++++++++++++++++++++---------------------------- pngconf.h | 2 +- pngerror.c | 42 +++--- pngmem.c | 20 +-- pngpread.c | 2 +- pngpriv.h | 30 ++--- pngread.c | 8 ++ pngrutil.c | 4 +- pngset.c | 6 +- pngstruct.h | 10 +- pngtest.c | 23 ++-- pngwio.c | 3 +- 13 files changed, 305 insertions(+), 311 deletions(-) diff --git a/png.c b/png.c index b1fb74a2b..12953ead7 100644 --- a/png.c +++ b/png.c @@ -92,7 +92,7 @@ png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED) void /* PRIVATE */ 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 @@ -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. */ 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; @@ -365,7 +365,7 @@ png_create_info_struct,(png_structp png_ptr),PNG_ALLOCATED) * it). */ 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; @@ -427,7 +427,7 @@ png_info_init_3,(png_infopp ptr_ptr, png_size_t png_info_struct_size), } 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) { png_debug(1, "in png_data_freer"); @@ -447,7 +447,7 @@ png_data_freer(png_structp png_ptr, png_infop info_ptr, } 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) { 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, #endif #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 (num != -1) @@ -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 */ 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->valid &= ~PNG_INFO_PLTE; info_ptr->num_palette = 0; @@ -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. */ 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_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); } #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ @@ -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. */ png_voidp PNGAPI -png_get_io_ptr(png_structp png_ptr) +png_get_io_ptr(png_const_structp png_ptr) { if (png_ptr == NULL) return (NULL); @@ -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 * a "Creation Time" or other text-based time string. */ -png_const_charp PNGAPI -png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime) +int PNGAPI +png_convert_to_rfc1123_buffer(char out[29], png_const_timep ptime) { static PNG_CONST char short_months[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - if (png_ptr == NULL) - return (NULL); + if (out == NULL) + return 0; if (ptime->year > 9999 /* RFC1123 limitation */ || ptime->month == 0 || ptime->month > 12 || ptime->day == 0 || ptime->day > 31 || ptime->hour > 23 || ptime->minute > 59 || ptime->second > 60) - { - png_warning(png_ptr, "Ignoring invalid time value"); - return (NULL); - } + return 0; { size_t pos = 0; char number_buf[5]; /* enough for a four-digit year */ -# define APPEND_STRING(string)\ - pos = png_safecat(png_ptr->time_buffer, sizeof png_ptr->time_buffer,\ - pos, (string)) +# define APPEND_STRING(string) pos = png_safecat(out, 29, pos, (string)) # define APPEND_NUMBER(format, value)\ APPEND_STRING(PNG_FORMAT_NUMBER(number_buf, format, (value))) -# define APPEND(ch)\ - if (pos < (sizeof png_ptr->time_buffer)-1)\ - png_ptr->time_buffer[pos++] = (ch) +# define APPEND(ch) if (pos < 28) out[pos++] = (ch) APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day); APPEND(' '); @@ -760,8 +738,30 @@ png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime) # 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 /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ @@ -775,13 +775,13 @@ png_get_copyright(png_const_structp png_ptr) #else # ifdef __STDC__ 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) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ PNG_STRING_NEWLINE; # 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) 1996-1997 Andreas Dilger\ 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) 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)) { @@ -1286,7 +1286,7 @@ int png_XYZ_from_xy_checked(png_structp png_ptr, png_XYZ *XYZ, png_xy xy) #endif 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, int color_type, int interlace_type, int compression_type, int filter_type) @@ -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) && \ !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) 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); @@ -2147,7 +2147,7 @@ png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, * result. */ 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_fixed_point result; diff --git a/png.h b/png.h index 922a82e5a..4beaf1bf0 100644 --- a/png.h +++ b/png.h @@ -1,7 +1,7 @@ /* png.h - header file for PNG reference library * - * libpng version 1.6.0beta03 - December 21, 2011 + * libpng version 1.6.0beta03 - December 22, 2011 * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -11,7 +11,7 @@ * Authors and maintainers: * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.6.0beta03 - December 21, 2011: Glenn + * libpng versions 0.97, January 1998, through 1.6.0beta03 - December 22, 2011: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -198,7 +198,7 @@ * * This code is released under the libpng license. * - * libpng versions 1.2.6, August 15, 2004, through 1.6.0beta03, December 21, 2011, are + * libpng versions 1.2.6, August 15, 2004, through 1.6.0beta03, December 22, 2011, are * Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are * distributed according to the same disclaimer and license as libpng-1.2.5 * with the following individual added to the list of Contributing Authors: @@ -310,7 +310,7 @@ * Y2K compliance in libpng: * ========================= * - * December 21, 2011 + * December 22, 2011 * * Since the PNG Development group is an ad-hoc body, we can't make * an official declaration. @@ -376,7 +376,7 @@ /* Version information for png.h - this should match the version in png.c */ #define PNG_LIBPNG_VER_STRING "1.6.0beta03" #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.6.0beta03 - December 21, 2011\n" + " libpng version 1.6.0beta03 - December 22, 2011\n" #define PNG_LIBPNG_VER_SONUM 16 #define PNG_LIBPNG_VER_DLLNUM 16 @@ -677,9 +677,8 @@ typedef struct png_unknown_chunk_t /* libpng-using applications should NOT directly modify this byte. */ png_byte location; /* mode of operation at read time */ } - - png_unknown_chunk; + typedef png_unknown_chunk * png_unknown_chunkp; typedef const png_unknown_chunk * png_const_unknown_chunkp; typedef png_unknown_chunk * * png_unknown_chunkpp; @@ -1021,7 +1020,7 @@ PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structp png_ptr, * will use it; otherwise it will call PNG_ABORT(). This function was * added in libpng-1.5.0. */ -PNG_EXPORTA(9, void, png_longjmp, (png_structp png_ptr, int val), +PNG_EXPORTA(9, void, png_longjmp, (png_const_structp png_ptr, int val), PNG_NORETURN); #ifdef PNG_READ_SUPPORTED @@ -1062,9 +1061,13 @@ PNG_EXPORT(16, void, png_write_chunk_data, (png_structp png_ptr, PNG_EXPORT(17, void, png_write_chunk_end, (png_structp png_ptr)); /* Allocate and initialize the info structure */ -PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_structp png_ptr), +PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_const_structp png_ptr), PNG_ALLOCATED); +/* DEPRECATED: this function allowed init structures to be created using the + * default allocation method (typically malloc). Use is deprecated in 1.6.0 and + * the API will be removed in the future. + */ PNG_EXPORTA(19, void, png_info_init_3, (png_infopp info_ptr, png_size_t png_info_struct_size), PNG_DEPRECATED); @@ -1081,8 +1084,15 @@ PNG_EXPORT(22, void, png_read_info, #endif #ifdef PNG_TIME_RFC1123_SUPPORTED -PNG_EXPORT(23, png_const_charp, png_convert_to_rfc1123, - (png_structp png_ptr, + /* Convert to a US string format: there is no localization support in this + * routine. The original implementation used a 29 character buffer in + * png_struct, this will be removed in future versions. + */ +#if PNG_LIBPNG_VER < 10700 +PNG_EXPORTA(23, png_const_charp, png_convert_to_rfc1123, (png_structp png_ptr, + png_const_timep ptime),PNG_DEPRECATED); +#endif +PNG_EXPORT(241, int, png_convert_to_rfc1123_buffer, (char out[29], png_const_timep ptime)); #endif @@ -1092,8 +1102,7 @@ PNG_EXPORT(24, void, png_convert_from_struct_tm, (png_timep ptime, const struct tm * ttime)); /* Convert from time_t to png_time. Uses gmtime() */ -PNG_EXPORT(25, void, png_convert_from_time_t, - (png_timep ptime, time_t ttime)); +PNG_EXPORT(25, void, png_convert_from_time_t, (png_timep ptime, time_t ttime)); #endif /* PNG_CONVERT_tIME_SUPPORTED */ #ifdef PNG_READ_EXPAND_SUPPORTED @@ -1373,9 +1382,8 @@ PNG_EXPORT(39, void, png_set_filler, (png_structp png_ptr, png_uint_32 filler, # define PNG_FILLER_BEFORE 0 # define PNG_FILLER_AFTER 1 /* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */ -PNG_EXPORT(40, void, png_set_add_alpha, - (png_structp png_ptr, png_uint_32 filler, - int flags)); +PNG_EXPORT(40, void, png_set_add_alpha, (png_structp png_ptr, + png_uint_32 filler, int flags)); #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */ #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) @@ -1451,8 +1459,7 @@ PNG_EXPORT(48, void, png_set_strip_16, (png_structp png_ptr)); /* Turn on quantizing, and reduce the palette to the number of colors * available. */ -PNG_EXPORT(49, void, png_set_quantize, - (png_structp png_ptr, png_colorp palette, +PNG_EXPORT(49, void, png_set_quantize, (png_structp png_ptr, png_colorp palette, int num_palette, int maximum_colors, png_const_uint_16p histogram, int full_quantize)); #endif @@ -1474,9 +1481,8 @@ PNG_EXPORT(49, void, png_set_quantize, * API (floating point or fixed.) Notice, however, that the 'file_gamma' value * is the inverse of a 'screen gamma' value. */ -PNG_FP_EXPORT(50, void, png_set_gamma, - (png_structp png_ptr, double screen_gamma, - double override_file_gamma)); +PNG_FP_EXPORT(50, void, png_set_gamma, (png_structp png_ptr, + double screen_gamma, double override_file_gamma)); PNG_FIXED_EXPORT(208, void, png_set_gamma_fixed, (png_structp png_ptr, png_fixed_point screen_gamma, png_fixed_point override_file_gamma)); #endif @@ -1492,8 +1498,8 @@ PNG_EXPORT(52, void, png_write_flush, (png_structp png_ptr)); PNG_EXPORT(53, void, png_start_read_image, (png_structp png_ptr)); /* Optional call to update the users info structure */ -PNG_EXPORT(54, void, png_read_update_info, - (png_structp png_ptr, png_infop info_ptr)); +PNG_EXPORT(54, void, png_read_update_info, (png_structp png_ptr, + png_infop info_ptr)); #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read one or more rows of image data. */ @@ -1513,8 +1519,7 @@ PNG_EXPORT(57, void, png_read_image, (png_structp png_ptr, png_bytepp image)); #endif /* Write a row of image data */ -PNG_EXPORT(58, void, png_write_row, - (png_structp png_ptr, png_const_bytep row)); +PNG_EXPORT(58, void, png_write_row, (png_structp png_ptr, png_const_bytep row)); /* Write a few rows of image data: (*row) is not written; however, the type * is declared as writeable to maintain compatibility with previous versions @@ -1525,12 +1530,10 @@ PNG_EXPORT(59, void, png_write_rows, (png_structp png_ptr, png_bytepp row, png_uint_32 num_rows)); /* Write the image data */ -PNG_EXPORT(60, void, png_write_image, - (png_structp png_ptr, png_bytepp image)); +PNG_EXPORT(60, void, png_write_image, (png_structp png_ptr, png_bytepp image)); /* Write the end of the PNG file. */ -PNG_EXPORT(61, void, png_write_end, - (png_structp png_ptr, png_infop info_ptr)); +PNG_EXPORT(61, void, png_write_end, (png_structp png_ptr, png_infop info_ptr)); #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read the end of the PNG file. */ @@ -1538,7 +1541,7 @@ PNG_EXPORT(62, void, png_read_end, (png_structp png_ptr, png_infop info_ptr)); #endif /* Free any memory associated with the png_info_struct */ -PNG_EXPORT(63, void, png_destroy_info_struct, (png_structp png_ptr, +PNG_EXPORT(63, void, png_destroy_info_struct, (png_const_structp png_ptr, png_infopp info_ptr_ptr)); /* Free any memory associated with the png_struct and the png_info_structs */ @@ -1550,8 +1553,8 @@ PNG_EXPORT(65, void, png_destroy_write_struct, (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)); /* Set the libpng method of handling chunk CRC errors */ -PNG_EXPORT(66, void, png_set_crc_action, - (png_structp png_ptr, int crit_action, int ancil_action)); +PNG_EXPORT(66, void, png_set_crc_action, (png_structp png_ptr, int crit_action, + int ancil_action)); /* Values for png_set_crc_action() say how to handle CRC errors in * ancillary and critical chunks, and whether to use the data contained @@ -1580,8 +1583,8 @@ PNG_EXPORT(66, void, png_set_crc_action, /* Set the filtering method(s) used by libpng. Currently, the only valid * value for "method" is 0. */ -PNG_EXPORT(67, void, png_set_filter, - (png_structp png_ptr, int method, int filters)); +PNG_EXPORT(67, void, png_set_filter, (png_structp png_ptr, int method, + int filters)); /* Flags for png_set_filter() to say which filters to use. The flags * are chosen so that they don't conflict with real filter types @@ -1640,9 +1643,9 @@ PNG_FP_EXPORT(68, void, png_set_filter_heuristics, (png_structp png_ptr, int heuristic_method, int num_weights, png_const_doublep filter_weights, png_const_doublep filter_costs)); PNG_FIXED_EXPORT(209, void, png_set_filter_heuristics_fixed, - (png_structp png_ptr, - int heuristic_method, int num_weights, png_const_fixed_point_p - filter_weights, png_const_fixed_point_p filter_costs)); + (png_structp png_ptr, int heuristic_method, int num_weights, + png_const_fixed_point_p filter_weights, + png_const_fixed_point_p filter_costs)); #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ /* Heuristic used for row filter selection. These defines should NOT be @@ -1661,8 +1664,8 @@ PNG_FIXED_EXPORT(209, void, png_set_filter_heuristics_fixed, * for PNG images, and do considerably fewer caclulations. In the future, * these values may not correspond directly to the zlib compression levels. */ -PNG_EXPORT(69, void, png_set_compression_level, - (png_structp png_ptr, int level)); +PNG_EXPORT(69, void, png_set_compression_level, (png_structp png_ptr, + int level)); PNG_EXPORT(70, void, png_set_compression_mem_level, (png_structp png_ptr, int mem_level)); @@ -1682,8 +1685,8 @@ PNG_EXPORT(73, void, png_set_compression_method, (png_structp png_ptr, #ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED /* Also set zlib parameters for compressing non-IDAT chunks */ -PNG_EXPORT(222, void, png_set_text_compression_level, - (png_structp png_ptr, int level)); +PNG_EXPORT(222, void, png_set_text_compression_level, (png_structp png_ptr, + int level)); PNG_EXPORT(223, void, png_set_text_compression_mem_level, (png_structp png_ptr, int mem_level)); @@ -1694,8 +1697,8 @@ PNG_EXPORT(224, void, png_set_text_compression_strategy, (png_structp png_ptr, /* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a * smaller value of window_bits if it can do so safely. */ -PNG_EXPORT(225, void, png_set_text_compression_window_bits, (png_structp - png_ptr, int window_bits)); +PNG_EXPORT(225, void, png_set_text_compression_window_bits, + (png_structp png_ptr, int window_bits)); PNG_EXPORT(226, void, png_set_text_compression_method, (png_structp png_ptr, int method)); @@ -1723,9 +1726,8 @@ PNG_EXPORT(74, void, png_init_io, (png_structp png_ptr, png_FILE_p fp)); * default function will be used. */ -PNG_EXPORT(75, void, png_set_error_fn, - (png_structp png_ptr, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warning_fn)); +PNG_EXPORT(75, void, png_set_error_fn, (png_structp png_ptr, + png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn)); /* Return the user pointer associated with the error functions */ PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structp png_ptr)); @@ -1748,7 +1750,7 @@ PNG_EXPORT(78, void, png_set_read_fn, (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn)); /* Return the user pointer associated with the I/O functions */ -PNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_structp png_ptr)); +PNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_const_structp png_ptr)); PNG_EXPORT(80, void, png_set_read_status_fn, (png_structp png_ptr, png_read_status_ptr read_row_fn)); @@ -1817,8 +1819,7 @@ PNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structp png_ptr, PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, (png_const_structp png_ptr)); /* Function to be called when data becomes available */ -PNG_EXPORT(92, void, png_process_data, - (png_structp png_ptr, png_infop info_ptr, +PNG_EXPORT(92, void, png_process_data, (png_structp png_ptr, png_infop info_ptr, png_bytep buffer, png_size_t buffer_size)); /* A function which may be called *only* within png_process_data to stop the @@ -1844,34 +1845,34 @@ PNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structp)); * stores its own version of the new data internally and ignores the passed * in value. */ -PNG_EXPORT(93, void, png_progressive_combine_row, (png_structp png_ptr, +PNG_EXPORT(93, void, png_progressive_combine_row, (png_const_structp png_ptr, png_bytep old_row, png_const_bytep new_row)); #endif /* PNG_READ_INTERLACING_SUPPORTED */ #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ -PNG_EXPORTA(94, png_voidp, png_malloc, - (png_structp png_ptr, png_alloc_size_t size), - PNG_ALLOCATED); +PNG_EXPORTA(94, png_voidp, png_malloc, (png_const_structp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED); /* Added at libpng version 1.4.0 */ -PNG_EXPORTA(95, png_voidp, png_calloc, - (png_structp png_ptr, png_alloc_size_t size), - PNG_ALLOCATED); +PNG_EXPORTA(95, png_voidp, png_calloc, (png_const_structp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED); /* Added at libpng version 1.2.4 */ -PNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_structp png_ptr, +PNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_const_structp png_ptr, png_alloc_size_t size), PNG_ALLOCATED); /* Frees a pointer allocated by png_malloc() */ -PNG_EXPORT(97, void, png_free, (png_structp png_ptr, png_voidp ptr)); +PNG_EXPORT(97, void, png_free, (png_const_structp png_ptr, png_voidp ptr)); /* Free data that was allocated internally */ -PNG_EXPORT(98, void, png_free_data, - (png_structp png_ptr, png_infop info_ptr, png_uint_32 free_me, int num)); +PNG_EXPORT(98, void, png_free_data, (png_const_structp png_ptr, + png_infop info_ptr, png_uint_32 free_me, int num)); /* Reassign responsibility for freeing existing data, whether allocated - * by libpng or by the application */ -PNG_EXPORT(99, void, png_data_freer, - (png_structp png_ptr, png_infop info_ptr, int freer, png_uint_32 mask)); + * by libpng or by the application; this works on the png_info structure passed + * in, it does not change the state for other png_info structures. + */ +PNG_EXPORT(99, void, png_data_freer, (png_const_structp png_ptr, + png_infop info_ptr, int freer, png_uint_32 mask)); /* Assignments for png_data_freer */ #define PNG_DESTROY_WILL_FREE_DATA 1 @@ -1893,34 +1894,33 @@ PNG_EXPORT(99, void, png_data_freer, #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */ #ifdef PNG_USER_MEM_SUPPORTED -PNG_EXPORTA(100, png_voidp, png_malloc_default, (png_structp png_ptr, +PNG_EXPORTA(100, png_voidp, png_malloc_default, (png_const_structp png_ptr, png_alloc_size_t size), PNG_ALLOCATED PNG_DEPRECATED); -PNG_EXPORTA(101, void, png_free_default, (png_structp png_ptr, png_voidp ptr), - PNG_DEPRECATED); +PNG_EXPORTA(101, void, png_free_default, (png_const_structp png_ptr, + png_voidp ptr), PNG_DEPRECATED); #endif #ifdef PNG_ERROR_TEXT_SUPPORTED /* Fatal error in PNG image of libpng - can't continue */ -PNG_EXPORTA(102, void, png_error, - (png_structp png_ptr, png_const_charp error_message), - PNG_NORETURN); +PNG_EXPORTA(102, void, png_error, (png_const_structp png_ptr, + png_const_charp error_message), PNG_NORETURN); /* The same, but the chunk name is prepended to the error string. */ -PNG_EXPORTA(103, void, png_chunk_error, (png_structp png_ptr, +PNG_EXPORTA(103, void, png_chunk_error, (png_const_structp png_ptr, png_const_charp error_message), PNG_NORETURN); #else /* Fatal error in PNG image of libpng - can't continue */ -PNG_EXPORTA(104, void, png_err, (png_structp png_ptr), PNG_NORETURN); +PNG_EXPORTA(104, void, png_err, (png_const_structp png_ptr), PNG_NORETURN); #endif #ifdef PNG_WARNINGS_SUPPORTED /* Non-fatal error in libpng. Can continue, but may have a problem. */ -PNG_EXPORT(105, void, png_warning, (png_structp png_ptr, +PNG_EXPORT(105, void, png_warning, (png_const_structp png_ptr, png_const_charp warning_message)); /* Non-fatal error in libpng, chunk name is prepended to message. */ -PNG_EXPORT(106, void, png_chunk_warning, (png_structp png_ptr, +PNG_EXPORT(106, void, png_chunk_warning, (png_const_structp png_ptr, png_const_charp warning_message)); #endif @@ -1928,12 +1928,12 @@ PNG_EXPORT(106, void, png_chunk_warning, (png_structp png_ptr, /* Benign error in libpng. Can continue, but may have a problem. * User can choose whether to handle as a fatal error or as a warning. */ # undef png_benign_error -PNG_EXPORT(107, void, png_benign_error, (png_structp png_ptr, +PNG_EXPORT(107, void, png_benign_error, (png_const_structp png_ptr, png_const_charp warning_message)); /* Same, chunk name is prepended to message. */ # undef png_chunk_benign_error -PNG_EXPORT(108, void, png_chunk_benign_error, (png_structp png_ptr, +PNG_EXPORT(108, void, png_chunk_benign_error, (png_const_structp png_ptr, png_const_charp warning_message)); PNG_EXPORT(109, void, png_set_benign_errors, @@ -1961,9 +1961,8 @@ PNG_EXPORT(109, void, png_set_benign_errors, * png_info_struct. */ /* Returns "flag" if chunk data is valid in info_ptr. */ -PNG_EXPORT(110, png_uint_32, png_get_valid, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_32 flag)); +PNG_EXPORT(110, png_uint_32, png_get_valid, (png_const_structp png_ptr, + png_const_infop info_ptr, png_uint_32 flag)); /* Returns number of bytes needed to hold a transformed row. */ PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structp png_ptr, @@ -1973,18 +1972,19 @@ PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structp png_ptr, /* Returns row_pointers, which is an array of pointers to scanlines that was * returned from png_read_png(). */ -PNG_EXPORT(112, png_bytepp, png_get_rows, - (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(112, png_bytepp, png_get_rows, (png_const_structp png_ptr, + png_const_infop info_ptr)); + /* Set row_pointers, which is an array of pointers to scanlines for use * by png_write_png(). */ -PNG_EXPORT(113, void, png_set_rows, (png_structp png_ptr, - png_infop info_ptr, png_bytepp row_pointers)); +PNG_EXPORT(113, void, png_set_rows, (png_structp png_ptr, png_infop info_ptr, + png_bytepp row_pointers)); #endif /* Returns number of color channels in image. */ -PNG_EXPORT(114, png_byte, png_get_channels, - (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(114, png_byte, png_get_channels, (png_const_structp png_ptr, + png_const_infop info_ptr)); #ifdef PNG_EASY_ACCESS_SUPPORTED /* Returns image width in pixels. */ @@ -1996,8 +1996,8 @@ PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structp png_ptr, png_const_infop info_ptr)); /* Returns image bit_depth. */ -PNG_EXPORT(117, png_byte, png_get_bit_depth, - (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(117, png_byte, png_get_bit_depth, (png_const_structp png_ptr, + png_const_infop info_ptr)); /* Returns image color_type. */ PNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structp png_ptr, @@ -2030,10 +2030,10 @@ PNG_FIXED_EXPORT(210, png_fixed_point, png_get_pixel_aspect_ratio_fixed, (png_const_structp png_ptr, png_const_infop info_ptr)); /* Returns image x, y offset in pixels or microns, from oFFs chunk data. */ -PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels, - (png_const_structp png_ptr, png_const_infop info_ptr)); -PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels, - (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels, (png_const_structp png_ptr, + png_const_infop info_ptr)); +PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels, (png_const_structp png_ptr, + png_const_infop info_ptr)); PNG_EXPORT(128, png_int_32, png_get_x_offset_microns, (png_const_structp png_ptr, png_const_infop info_ptr)); PNG_EXPORT(129, png_int_32, png_get_y_offset_microns, @@ -2042,13 +2042,12 @@ PNG_EXPORT(129, png_int_32, png_get_y_offset_microns, #endif /* PNG_EASY_ACCESS_SUPPORTED */ /* Returns pointer to signature string read from PNG header */ -PNG_EXPORT(130, png_const_bytep, png_get_signature, - (png_const_structp png_ptr, png_infop info_ptr)); +PNG_EXPORT(130, png_const_bytep, png_get_signature, (png_const_structp png_ptr, + png_infop info_ptr)); #ifdef PNG_bKGD_SUPPORTED -PNG_EXPORT(131, png_uint_32, png_get_bKGD, - (png_const_structp png_ptr, png_infop info_ptr, - png_color_16p *background)); +PNG_EXPORT(131, png_uint_32, png_get_bKGD, (png_const_structp png_ptr, + png_infop info_ptr, png_color_16p *background)); #endif #ifdef PNG_bKGD_SUPPORTED @@ -2061,21 +2060,20 @@ PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structp png_ptr, png_const_infop info_ptr, double *white_x, double *white_y, double *red_x, double *red_y, double *green_x, double *green_y, double *blue_x, double *blue_y)); -PNG_FP_EXPORT(230, png_uint_32, png_get_cHRM_XYZ, (png_structp png_ptr, +PNG_FP_EXPORT(230, png_uint_32, png_get_cHRM_XYZ, (png_const_structp png_ptr, png_const_infop info_ptr, double *red_X, double *red_Y, double *red_Z, double *green_X, double *green_Y, double *green_Z, double *blue_X, double *blue_Y, double *blue_Z)); #ifdef PNG_FIXED_POINT_SUPPORTED /* Otherwise not implemented */ PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed, - (png_const_structp png_ptr, - png_const_infop info_ptr, png_fixed_point *int_white_x, - png_fixed_point *int_white_y, png_fixed_point *int_red_x, - png_fixed_point *int_red_y, png_fixed_point *int_green_x, - png_fixed_point *int_green_y, png_fixed_point *int_blue_x, - png_fixed_point *int_blue_y)); + (png_const_structp png_ptr, png_const_infop info_ptr, + png_fixed_point *int_white_x, png_fixed_point *int_white_y, + png_fixed_point *int_red_x, png_fixed_point *int_red_y, + png_fixed_point *int_green_x, png_fixed_point *int_green_y, + png_fixed_point *int_blue_x, png_fixed_point *int_blue_y)); #endif PNG_FIXED_EXPORT(231, png_uint_32, png_get_cHRM_XYZ_fixed, - (png_structp png_ptr, png_const_infop info_ptr, + (png_const_structp png_ptr, png_const_infop info_ptr, png_fixed_point *int_red_X, png_fixed_point *int_red_Y, png_fixed_point *int_red_Z, png_fixed_point *int_green_X, png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, @@ -2084,8 +2082,7 @@ PNG_FIXED_EXPORT(231, png_uint_32, png_get_cHRM_XYZ_fixed, #endif #ifdef PNG_cHRM_SUPPORTED -PNG_FP_EXPORT(135, void, png_set_cHRM, - (png_structp png_ptr, png_infop info_ptr, +PNG_FP_EXPORT(135, void, png_set_cHRM, (png_structp png_ptr, png_infop info_ptr, double white_x, double white_y, double red_x, double red_y, double green_x, double green_y, double blue_x, double blue_y)); PNG_FP_EXPORT(232, void, png_set_cHRM_XYZ, (png_structp png_ptr, @@ -2107,9 +2104,8 @@ PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_structp png_ptr, #endif #ifdef PNG_gAMA_SUPPORTED -PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, - (png_const_structp png_ptr, png_const_infop info_ptr, - double *file_gamma)); +PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, (png_const_structp png_ptr, + png_const_infop info_ptr, double *file_gamma)); PNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed, (png_const_structp png_ptr, png_const_infop info_ptr, png_fixed_point *int_file_gamma)); @@ -2123,82 +2119,73 @@ PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_structp png_ptr, #endif #ifdef PNG_hIST_SUPPORTED -PNG_EXPORT(141, png_uint_32, png_get_hIST, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_16p *hist)); +PNG_EXPORT(141, png_uint_32, png_get_hIST, (png_const_structp png_ptr, + png_const_infop info_ptr, png_uint_16p *hist)); #endif #ifdef PNG_hIST_SUPPORTED -PNG_EXPORT(142, void, png_set_hIST, (png_structp png_ptr, - png_infop info_ptr, png_const_uint_16p hist)); +PNG_EXPORT(142, void, png_set_hIST, (png_structp png_ptr, png_infop info_ptr, + png_const_uint_16p hist)); #endif -PNG_EXPORT(143, png_uint_32, png_get_IHDR, - (png_structp png_ptr, png_infop info_ptr, - png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, - int *interlace_method, int *compression_method, int *filter_method)); +PNG_EXPORT(143, png_uint_32, png_get_IHDR, (png_const_structp png_ptr, + png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, + int *bit_depth, int *color_type, int *interlace_method, + int *compression_method, int *filter_method)); -PNG_EXPORT(144, void, png_set_IHDR, - (png_structp png_ptr, png_infop info_ptr, +PNG_EXPORT(144, void, png_set_IHDR, (png_structp png_ptr, png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_method, int compression_method, int filter_method)); #ifdef PNG_oFFs_SUPPORTED -PNG_EXPORT(145, png_uint_32, png_get_oFFs, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)); +PNG_EXPORT(145, png_uint_32, png_get_oFFs, (png_const_structp png_ptr, + png_const_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, + int *unit_type)); #endif #ifdef PNG_oFFs_SUPPORTED -PNG_EXPORT(146, void, png_set_oFFs, - (png_structp png_ptr, png_infop info_ptr, +PNG_EXPORT(146, void, png_set_oFFs, (png_structp png_ptr, png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y, int unit_type)); #endif #ifdef PNG_pCAL_SUPPORTED -PNG_EXPORT(147, png_uint_32, png_get_pCAL, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, - int *nparams, - png_charp *units, png_charpp *params)); +PNG_EXPORT(147, png_uint_32, png_get_pCAL, (png_const_structp png_ptr, + png_const_infop info_ptr, png_charp *purpose, png_int_32 *X0, + png_int_32 *X1, int *type, int *nparams, png_charp *units, + png_charpp *params)); #endif #ifdef PNG_pCAL_SUPPORTED -PNG_EXPORT(148, void, png_set_pCAL, (png_structp png_ptr, - png_infop info_ptr, +PNG_EXPORT(148, void, png_set_pCAL, (png_structp png_ptr, png_infop info_ptr, png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_const_charp units, png_charpp params)); #endif #ifdef PNG_pHYs_SUPPORTED -PNG_EXPORT(149, png_uint_32, png_get_pHYs, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); +PNG_EXPORT(149, png_uint_32, png_get_pHYs, (png_const_structp png_ptr, + png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, + int *unit_type)); #endif #ifdef PNG_pHYs_SUPPORTED -PNG_EXPORT(150, void, png_set_pHYs, - (png_structp png_ptr, png_infop info_ptr, +PNG_EXPORT(150, void, png_set_pHYs, (png_structp png_ptr, png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type)); #endif -PNG_EXPORT(151, png_uint_32, png_get_PLTE, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_colorp *palette, int *num_palette)); +PNG_EXPORT(151, png_uint_32, png_get_PLTE, (png_const_structp png_ptr, + png_const_infop info_ptr, png_colorp *palette, int *num_palette)); -PNG_EXPORT(152, void, png_set_PLTE, - (png_structp png_ptr, png_infop info_ptr, +PNG_EXPORT(152, void, png_set_PLTE, (png_structp png_ptr, png_infop info_ptr, png_const_colorp palette, int num_palette)); #ifdef PNG_sBIT_SUPPORTED -PNG_EXPORT(153, png_uint_32, png_get_sBIT, - (png_const_structp png_ptr, png_infop info_ptr, - png_color_8p *sig_bit)); +PNG_EXPORT(153, png_uint_32, png_get_sBIT, (png_const_structp png_ptr, + png_infop info_ptr, png_color_8p *sig_bit)); #endif #ifdef PNG_sBIT_SUPPORTED -PNG_EXPORT(154, void, png_set_sBIT, - (png_structp png_ptr, png_infop info_ptr, png_const_color_8p sig_bit)); +PNG_EXPORT(154, void, png_set_sBIT, (png_structp png_ptr, png_infop info_ptr, + png_const_color_8p sig_bit)); #endif #ifdef PNG_sRGB_SUPPORTED @@ -2207,43 +2194,38 @@ PNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structp png_ptr, #endif #ifdef PNG_sRGB_SUPPORTED -PNG_EXPORT(156, void, png_set_sRGB, - (png_structp png_ptr, png_infop info_ptr, int srgb_intent)); +PNG_EXPORT(156, void, png_set_sRGB, (png_structp png_ptr, png_infop info_ptr, + int srgb_intent)); PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_structp png_ptr, png_infop info_ptr, int srgb_intent)); #endif #ifdef PNG_iCCP_SUPPORTED -PNG_EXPORT(158, png_uint_32, png_get_iCCP, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_charpp name, int *compression_type, png_bytepp profile, - png_uint_32 *proflen)); +PNG_EXPORT(158, png_uint_32, png_get_iCCP, (png_const_structp png_ptr, + png_const_infop info_ptr, png_charpp name, int *compression_type, + png_bytepp profile, png_uint_32 *proflen)); #endif #ifdef PNG_iCCP_SUPPORTED -PNG_EXPORT(159, void, png_set_iCCP, - (png_structp png_ptr, png_infop info_ptr, +PNG_EXPORT(159, void, png_set_iCCP, (png_structp png_ptr, png_infop info_ptr, png_const_charp name, int compression_type, png_const_bytep profile, png_uint_32 proflen)); #endif #ifdef PNG_sPLT_SUPPORTED -PNG_EXPORT(160, png_uint_32, png_get_sPLT, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_sPLT_tpp entries)); +PNG_EXPORT(160, png_uint_32, png_get_sPLT, (png_const_structp png_ptr, + png_const_infop info_ptr, png_sPLT_tpp entries)); #endif #ifdef PNG_sPLT_SUPPORTED -PNG_EXPORT(161, void, png_set_sPLT, - (png_structp png_ptr, png_infop info_ptr, +PNG_EXPORT(161, void, png_set_sPLT, (png_structp png_ptr, png_infop info_ptr, png_const_sPLT_tp entries, int nentries)); #endif #ifdef PNG_TEXT_SUPPORTED /* png_get_text also returns the number of text chunks in *num_text */ -PNG_EXPORT(162, png_uint_32, png_get_text, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_textp *text_ptr, int *num_text)); +PNG_EXPORT(162, png_uint_32, png_get_text, (png_const_structp png_ptr, + png_const_infop info_ptr, png_textp *text_ptr, int *num_text)); #endif /* Note while png_set_text() will accept a structure whose text, @@ -2254,38 +2236,35 @@ PNG_EXPORT(162, png_uint_32, png_get_text, */ #ifdef PNG_TEXT_SUPPORTED -PNG_EXPORT(163, void, png_set_text, - (png_structp png_ptr, png_infop info_ptr, +PNG_EXPORT(163, void, png_set_text, (png_structp png_ptr, png_infop info_ptr, png_const_textp text_ptr, int num_text)); #endif #ifdef PNG_tIME_SUPPORTED -PNG_EXPORT(164, png_uint_32, png_get_tIME, - (png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time)); +PNG_EXPORT(164, png_uint_32, png_get_tIME, (png_const_structp png_ptr, + png_infop info_ptr, png_timep *mod_time)); #endif #ifdef PNG_tIME_SUPPORTED -PNG_EXPORT(165, void, png_set_tIME, - (png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time)); +PNG_EXPORT(165, void, png_set_tIME, (png_structp png_ptr, png_infop info_ptr, + png_const_timep mod_time)); #endif #ifdef PNG_tRNS_SUPPORTED -PNG_EXPORT(166, png_uint_32, png_get_tRNS, - (png_const_structp png_ptr, png_infop info_ptr, - png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)); +PNG_EXPORT(166, png_uint_32, png_get_tRNS, (png_const_structp png_ptr, + png_infop info_ptr, png_bytep *trans_alpha, int *num_trans, + png_color_16p *trans_color)); #endif #ifdef PNG_tRNS_SUPPORTED -PNG_EXPORT(167, void, png_set_tRNS, - (png_structp png_ptr, png_infop info_ptr, +PNG_EXPORT(167, void, png_set_tRNS, (png_structp png_ptr, png_infop info_ptr, png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color)); #endif #ifdef PNG_sCAL_SUPPORTED -PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, - (png_const_structp png_ptr, png_const_infop info_ptr, - int *unit, double *width, double *height)); +PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, (png_const_structp png_ptr, + png_const_infop info_ptr, int *unit, double *width, double *height)); #ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED /* NOTE: this API is currently implemented using floating point arithmetic, * consequently it can only be used on systems with floating point support. @@ -2293,22 +2272,19 @@ PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, * is highly recommended that png_get_sCAL_s be used instead. */ PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed, - (png_structp png_ptr, png_const_infop info_ptr, int *unit, - png_fixed_point *width, - png_fixed_point *height)); + (png_const_structp png_ptr, png_const_infop info_ptr, int *unit, + png_fixed_point *width, png_fixed_point *height)); #endif PNG_EXPORT(169, png_uint_32, png_get_sCAL_s, - (png_const_structp png_ptr, png_const_infop info_ptr, - int *unit, png_charpp swidth, png_charpp sheight)); + (png_const_structp png_ptr, png_const_infop info_ptr, int *unit, + png_charpp swidth, png_charpp sheight)); -PNG_FP_EXPORT(170, void, png_set_sCAL, - (png_structp png_ptr, png_infop info_ptr, +PNG_FP_EXPORT(170, void, png_set_sCAL, (png_structp png_ptr, png_infop info_ptr, int unit, double width, double height)); PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_structp png_ptr, png_infop info_ptr, int unit, png_fixed_point width, png_fixed_point height)); -PNG_EXPORT(171, void, png_set_sCAL_s, - (png_structp png_ptr, png_infop info_ptr, +PNG_EXPORT(171, void, png_set_sCAL_s, (png_structp png_ptr, png_infop info_ptr, int unit, png_const_charp swidth, png_const_charp sheight)); #endif /* PNG_sCAL_SUPPORTED */ @@ -2324,9 +2300,8 @@ PNG_EXPORT(171, void, png_set_sCAL_s, = 2: PNG_HANDLE_CHUNK_IF_SAFE: keep only if safe-to-copy = 3: PNG_HANDLE_CHUNK_ALWAYS: keep even if unsafe-to-copy */ -PNG_EXPORT(172, void, png_set_keep_unknown_chunks, - (png_structp png_ptr, int keep, - png_const_bytep chunk_list, int num_chunks)); +PNG_EXPORT(172, void, png_set_keep_unknown_chunks, (png_structp png_ptr, + int keep, png_const_bytep chunk_list, int num_chunks)); /* The handling code is returned; the result is therefore true (non-zero) if * special handling is required, false for the default handling. @@ -2338,8 +2313,8 @@ PNG_EXPORT(173, int, png_handle_as_unknown, (png_structp png_ptr, PNG_EXPORT(174, void, png_set_unknown_chunks, (png_structp png_ptr, png_infop info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)); -PNG_EXPORT(175, void, png_set_unknown_chunk_location, - (png_structp png_ptr, png_infop info_ptr, int chunk, int location)); +PNG_EXPORT(175, void, png_set_unknown_chunk_location, (png_structp png_ptr, + png_infop info_ptr, int chunk, int location)); PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structp png_ptr, png_const_infop info_ptr, png_unknown_chunkpp entries)); #endif @@ -2348,8 +2323,8 @@ PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structp png_ptr, * If you need to turn it off for a chunk that your application has freed, * you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK); */ -PNG_EXPORT(177, void, png_set_invalid, - (png_structp png_ptr, png_infop info_ptr, int mask)); +PNG_EXPORT(177, void, png_set_invalid, (png_const_structp png_ptr, + png_infop info_ptr, int mask)); #ifdef PNG_INFO_IMAGE_SUPPORTED /* The "params" pointer is currently not used and is for future expansion. */ @@ -2383,8 +2358,7 @@ PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structp png_ptr, * messages before passing them to the error or warning handler. */ #ifdef PNG_ERROR_NUMBERS_SUPPORTED -PNG_EXPORT(185, void, png_set_strip_error_numbers, - (png_structp png_ptr, +PNG_EXPORT(185, void, png_set_strip_error_numbers, (png_structp png_ptr, png_uint_32 strip_mode)); #endif @@ -2422,14 +2396,14 @@ PNG_FP_EXPORT(196, float, png_get_x_offset_inches, (png_const_structp png_ptr, png_const_infop info_ptr)); #ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ PNG_FIXED_EXPORT(211, png_fixed_point, png_get_x_offset_inches_fixed, - (png_structp png_ptr, png_const_infop info_ptr)); + (png_const_structp png_ptr, png_const_infop info_ptr)); #endif PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structp png_ptr, png_const_infop info_ptr)); #ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ PNG_FIXED_EXPORT(212, png_fixed_point, png_get_y_offset_inches_fixed, - (png_structp png_ptr, png_const_infop info_ptr)); + (png_const_structp png_ptr, png_const_infop info_ptr)); #endif # ifdef PNG_pHYs_SUPPORTED @@ -2441,10 +2415,12 @@ PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structp png_ptr, /* Added in libpng-1.4.0 */ #ifdef PNG_IO_STATE_SUPPORTED -PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_structp png_ptr)); +PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_const_structp png_ptr)); + +/* Removed from libpng 1.6; use png_get_io_chunk_type. */ +PNG_REMOVED(200, png_const_bytep, png_get_io_chunk_name, (png_structp png_ptr), + PNG_DEPRECATED) -PNG_EXPORTA(200, png_const_bytep, png_get_io_chunk_name, - (png_structp png_ptr), PNG_DEPRECATED); PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type, (png_const_structp png_ptr)); @@ -2570,7 +2546,7 @@ PNG_EXPORT(202, png_uint_16, png_get_uint_16, (png_const_bytep buf)); PNG_EXPORT(203, png_int_32, png_get_int_32, (png_const_bytep buf)); #endif -PNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_structp png_ptr, +PNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_const_structp png_ptr, png_const_bytep buf)); /* No png_get_int_16 -- may be added if there's a real need for it. */ @@ -2915,7 +2891,7 @@ PNG_EXPORT(240, int, png_image_write_to_stdio, (png_imagep image, FILE *file, * scripts/symbols.def as well. */ #ifdef PNG_EXPORT_LAST_ORDINAL - PNG_EXPORT_LAST_ORDINAL(240); + PNG_EXPORT_LAST_ORDINAL(241); #endif #ifdef __cplusplus diff --git a/pngconf.h b/pngconf.h index 7929158dd..426d42a7d 100644 --- a/pngconf.h +++ b/pngconf.h @@ -1,7 +1,7 @@ /* 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 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/pngerror.c b/pngerror.c index 0b0c518b4..8e28e9e0e 100644 --- a/pngerror.c +++ b/pngerror.c @@ -20,12 +20,12 @@ #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); #ifdef PNG_WARNINGS_SUPPORTED 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)); #endif /* PNG_WARNINGS_SUPPORTED */ @@ -36,7 +36,8 @@ png_default_warning PNGARG((png_structp png_ptr, */ #ifdef PNG_ERROR_TEXT_SUPPORTED 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 char msg[16]; @@ -79,7 +80,7 @@ png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN) } #endif 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, 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) } #else 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 * 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, * png_set_error_fn() to replace the warning function at run-time. */ 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; if (png_ptr != NULL) @@ -230,7 +231,8 @@ png_warning(png_structp png_ptr, png_const_charp warning_message) } } 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 png_default_warning(png_ptr, warning_message + offset); } @@ -278,7 +280,7 @@ png_warning_parameter_signed(png_warning_parameters p, int number, int format, } 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) { /* 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, #ifdef PNG_BENIGN_ERRORS_SUPPORTED 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) png_warning(png_ptr, error_message); @@ -371,7 +373,7 @@ static PNG_CONST char png_digit[16] = { #define PNG_MAX_ERROR_TEXT 64 #if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED) 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) { 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 #if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) 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) { char msg[18+PNG_MAX_ERROR_TEXT]; @@ -434,7 +436,7 @@ png_chunk_error,(png_structp png_ptr, png_const_charp error_message), #ifdef PNG_WARNINGS_SUPPORTED 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]; if (png_ptr == NULL) @@ -451,7 +453,7 @@ png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) #ifdef PNG_READ_SUPPORTED #ifdef PNG_BENIGN_ERRORS_SUPPORTED 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) png_chunk_warning(png_ptr, 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_FLOATING_POINT_SUPPORTED 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_ln ((sizeof fixed_message)-1) @@ -603,7 +605,7 @@ png_free_jmpbuf(png_structp png_ptr) * error function pointer in png_set_error_fn(). */ 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) { #ifdef PNG_CONSOLE_IO_SUPPORTED @@ -650,7 +652,7 @@ png_default_error,(png_structp png_ptr, png_const_charp error_message), } 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 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) * not used, but it is passed in case it may be useful. */ 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_ERROR_NUMBERS_SUPPORTED @@ -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: */ 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) { + const png_const_structp png_ptr = png_nonconst_ptr; png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr); /* 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), #ifdef PNG_WARNINGS_SUPPORTED 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); /* A warning is only logged if there is no prior warning or error. */ diff --git a/pngmem.c b/pngmem.c index 7f0620176..ca905d97b 100644 --- a/pngmem.c +++ b/pngmem.c @@ -47,7 +47,7 @@ png_destroy_png_struct(png_structp png_ptr) * have the ability to do that. */ 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; @@ -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.) */ 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 * 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) { #ifdef PNG_USER_MEM_SUPPORTED 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 #endif @@ -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. */ 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; @@ -116,7 +117,7 @@ png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) #ifdef PNG_USER_MEM_SUPPORTED 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_voidp ret; @@ -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_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) { @@ -158,21 +160,21 @@ png_malloc_warn,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) * without taking any action. */ 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) return; #ifdef PNG_USER_MEM_SUPPORTED 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 png_free_default(png_ptr, ptr); } 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) return; diff --git a/pngpread.c b/pngpread.c index df45a436e..9f3805a01 100644 --- a/pngpread.c +++ b/pngpread.c @@ -1805,7 +1805,7 @@ png_push_have_row(png_structp png_ptr, png_bytep row) #ifdef PNG_READ_INTERLACING_SUPPORTED 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) { if (png_ptr == NULL) diff --git a/pngpriv.h b/pngpriv.h index 3e8c5e1c4..5afbb7077 100644 --- a/pngpriv.h +++ b/pngpriv.h @@ -240,8 +240,10 @@ typedef const png_uint_16p * png_const_uint_16pp; */ #ifdef __cplusplus # define png_voidcast(type, value) static_cast(value) +# define png_constcast(type, value) const_cast(value) #else # define png_voidcast(type, value) (value) +# define png_constcast(type, value) ((type)(value)) #endif /* __cplusplus */ #ifndef PNG_EXTERN @@ -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 ?\ ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0)) #else -PNG_EXTERN png_fixed_point png_fixed PNGARG((png_structp png_ptr, double fp, - png_const_charp text)); +PNG_EXTERN png_fixed_point png_fixed PNGARG((png_const_structp png_ptr, + double fp, png_const_charp text)); #endif #endif @@ -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 * 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_alloc_size_t size)),PNG_ALLOCATED); +PNG_EXTERN PNG_FUNCTION(png_voidp,png_malloc_base, + 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 * 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, png_malloc_ptr malloc_fn, png_free_ptr free_fn)),PNG_ALLOCATED); /* 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)); /* 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)); /* Free an allocated jmp_buf (always succeeds) */ @@ -960,8 +958,8 @@ PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr)); #ifndef PNG_USE_COMPILE_TIME_MASKS # define PNG_USE_COMPILE_TIME_MASKS 1 #endif -PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row, - int display)); +PNG_EXTERN void png_combine_row PNGARG((png_const_structp png_ptr, + png_bytep row, int display)); #ifdef PNG_READ_INTERLACING_SUPPORTED /* Expand an interlaced row: the 'row_info' describes the pass data that has @@ -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_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)); #endif /* 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, int color_type, int interlace_type, int compression_type, int filter_type)); #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); #endif @@ -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, 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); /* 'message' follows the X/Open approach of using @1, @2 to insert * 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, #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED) /* 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)); #endif diff --git a/pngread.c b/pngread.c index 758799fdf..1b84441d0 100644 --- a/pngread.c +++ b/pngread.c @@ -920,6 +920,14 @@ png_read_destroy(png_structp png_ptr) #endif /* PNG_TEXT_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 * callbacks are still set at this point. They are required to complete the * destruction of the png_struct itself. diff --git a/pngrutil.c b/pngrutil.c index 7a7d36ee5..293caaa6a 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -21,7 +21,7 @@ #define png_strtod(p,a,b) strtod(a,b) 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); @@ -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. */ 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; png_const_bytep sp = png_ptr->row_buf + 1; diff --git a/pngset.c b/pngset.c index af5511b36..5035cafc6 100644 --- a/pngset.c +++ b/pngset.c @@ -1024,9 +1024,9 @@ png_set_unknown_chunks(png_structp png_ptr, if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0) 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_sizeof(png_unknown_chunk)); + png_sizeof(png_unknown_chunk))); if (np == NULL) { @@ -1223,7 +1223,7 @@ png_set_compression_buffer_size(png_structp png_ptr, png_size_t size) } 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) info_ptr->valid &= ~mask; diff --git a/pngstruct.h b/pngstruct.h index da7ad0c6e..5b90d62d0 100644 --- a/pngstruct.h +++ b/pngstruct.h @@ -140,8 +140,10 @@ struct png_struct_def /* pixel depth used for the row buffers */ png_byte transformed_pixel_depth; /* pixel depth after read/write transforms */ +#if PNG_LIBPNG_VER < 10600 png_byte io_chunk_string[5]; /* string name of chunk */ +#endif #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) png_uint_16 filler; /* filler bytes for pixel expansion */ @@ -250,9 +252,11 @@ struct png_struct_def png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */ #endif +#if PNG_LIBPNG_VER < 10700 #ifdef PNG_TIME_RFC1123_SUPPORTED char time_buffer[29]; /* String to hold RFC 1123 time text */ #endif +#endif /* New members added in libpng-1.0.6 */ @@ -338,9 +342,13 @@ struct png_struct_def /* New member added in libpng-1.0.25 and 1.2.17 */ #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; #endif +#endif /* New member added in libpng-1.2.26 */ png_size_t old_big_row_buf_size; diff --git a/pngtest.c b/pngtest.c index 9476dd4bd..32d4c6829 100644 --- a/pngtest.c +++ b/pngtest.c @@ -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); #ifdef PNG_TIME_RFC1123_SUPPORTED - /* We have to use memcpy instead of "=" because the string - * pointed to by png_convert_to_rfc1123() gets free'ed before - * we use it. - */ - memcpy(tIME_string, png_convert_to_rfc1123(read_ptr, mod_time), - png_sizeof(tIME_string)); + if (png_convert_to_rfc1123_buffer(tIME_string, mod_time)) + tIME_string[png_sizeof(tIME_string) - 1] = '\0'; + + else + strcpy(tIME_string, "*** invalid time ***"); - tIME_string[png_sizeof(tIME_string) - 1] = '\0'; tIME_chunk_present++; #endif /* PNG_TIME_RFC1123_SUPPORTED */ } @@ -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); #ifdef PNG_TIME_RFC1123_SUPPORTED - /* We have to use memcpy instead of "=" because the string - pointed to by png_convert_to_rfc1123() gets free'ed before - we use it */ - memcpy(tIME_string, png_convert_to_rfc1123(read_ptr, mod_time), - png_sizeof(tIME_string)); + if (png_convert_to_rfc1123_buffer(tIME_string, mod_time)) + tIME_string[png_sizeof(tIME_string) - 1] = '\0'; + + else + strcpy(tIME_string, "*** invalid time ***"); - tIME_string[png_sizeof(tIME_string) - 1] = '\0'; tIME_chunk_present++; #endif /* PNG_TIME_RFC1123_SUPPORTED */ } diff --git a/pngwio.c b/pngwio.c index 8c1cab34f..65ac85669 100644 --- a/pngwio.c +++ b/pngwio.c @@ -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! */ 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 png_error(png_ptr, "Call to NULL write function");