diff options
-rw-r--r-- | png.c | 208 | ||||
-rw-r--r-- | png.h | 1517 | ||||
-rw-r--r-- | pngconf.h | 657 | ||||
-rw-r--r-- | pngcrush.c | 9 | ||||
-rw-r--r-- | pngcrush.h | 2 | ||||
-rw-r--r-- | pngerror.c | 4 | ||||
-rw-r--r-- | pngget.c | 77 | ||||
-rw-r--r-- | pngmem.c | 76 | ||||
-rw-r--r-- | pngpread.c | 115 | ||||
-rw-r--r-- | pngpriv.h | 835 | ||||
-rw-r--r-- | pngread.c | 419 | ||||
-rw-r--r-- | pngrio.c | 28 | ||||
-rw-r--r-- | pngrtran.c | 360 | ||||
-rw-r--r-- | pngrutil.c | 157 | ||||
-rw-r--r-- | pngset.c | 241 | ||||
-rw-r--r-- | pngtest.c | 156 | ||||
-rw-r--r-- | pngtrans.c | 27 | ||||
-rw-r--r-- | pngwio.c | 25 | ||||
-rw-r--r-- | pngwrite.c | 266 | ||||
-rw-r--r-- | pngwtran.c | 20 | ||||
-rw-r--r-- | pngwutil.c | 124 |
21 files changed, 3551 insertions, 1772 deletions
@@ -1,7 +1,7 @@ /* png.c - location for general purpose libpng functions * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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,17 +11,81 @@ * and license in png.h */ +#define PNG_INTERNAL #define PNG_NO_EXTERN #include "png.h" -#include "pngpriv.h" /* Generate a compiler error if there is an old png.h in the search path. */ -typedef version_1_4_0rc01 Your_png_h_is_not_version_1_4_0rc01; +typedef version_1_2_41beta14 Your_png_h_is_not_version_1_2_41beta14; /* Version information for C files. This had better match the version * string defined in png.h. */ +#ifdef PNG_USE_GLOBAL_ARRAYS +/* png_libpng_ver was changed to a function in version 1.0.5c */ +PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING; + +#ifdef PNG_READ_SUPPORTED + +/* png_sig was changed to a function in version 1.0.5c */ +/* Place to hold the signature string for a PNG file. */ +PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; +#endif /* PNG_READ_SUPPORTED */ + +/* Invoke global declarations for constant strings for known chunk types */ +PNG_IHDR; +PNG_IDAT; +PNG_IEND; +PNG_PLTE; +PNG_bKGD; +PNG_cHRM; +PNG_gAMA; +PNG_hIST; +PNG_iCCP; +PNG_iTXt; +PNG_oFFs; +PNG_pCAL; +PNG_sCAL; +PNG_pHYs; +PNG_sBIT; +PNG_sPLT; +PNG_sRGB; +PNG_tEXt; +PNG_tIME; +PNG_tRNS; +PNG_zTXt; + +#ifdef PNG_READ_SUPPORTED +/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + +/* Start of interlace block */ +PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; + +/* Offset to next interlace block */ +PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; + +/* Start of interlace block in the y direction */ +PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; + +/* Offset to next interlace block in the y direction */ +PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; + +/* Height of interlace block. This is not currently used - if you need + * it, uncomment it here and in png.h +PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; +*/ + +/* Mask to determine which pixels are valid in a pass */ +PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; + +/* Mask to determine which pixels to overwrite while displaying */ +PNG_CONST int FARDATA png_pass_dsp_mask[] + = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; + +#endif /* PNG_READ_SUPPORTED */ +#endif /* PNG_USE_GLOBAL_ARRAYS */ + /* Tells libpng that we have already handled the first "num_bytes" bytes * of the PNG file signature. If the PNG data is embedded into another * stream we can set num_bytes = 8 so that libpng will not attempt to read @@ -38,7 +102,7 @@ png_set_sig_bytes(png_structp png_ptr, int num_bytes) return; if (num_bytes > 8) - png_error(png_ptr, "Too many bytes for PNG signature"); + png_error(png_ptr, "Too many bytes for PNG signature."); png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes); } @@ -69,17 +133,32 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check) return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check))); } +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* (Obsolete) function to check signature bytes. It does not allow one + * to check a partial signature. This function might be removed in the + * future - use png_sig_cmp(). Returns true (nonzero) if the file is PNG. + */ +int PNGAPI +png_check_sig(png_bytep sig, int num) +{ + return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num)); +} +#endif #endif /* PNG_READ_SUPPORTED */ #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) /* Function to allocate memory for zlib and clear it to 0. */ +#ifdef PNG_1_0_X +voidpf PNGAPI +#else voidpf /* PRIVATE */ +#endif png_zalloc(voidpf png_ptr, uInt items, uInt size) { png_voidp ptr; png_structp p=(png_structp)png_ptr; png_uint_32 save_flags=p->flags; - png_alloc_size_t num_bytes; + png_uint_32 num_bytes; if (png_ptr == NULL) return (NULL); @@ -88,17 +167,36 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size) png_warning (p, "Potential overflow in png_zalloc()"); return (NULL); } - num_bytes = (png_alloc_size_t)items * size; + num_bytes = (png_uint_32)items * size; p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes); p->flags=save_flags; +#if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO) + if (ptr == NULL) + return ((voidpf)ptr); + + if (num_bytes > (png_uint_32)0x8000L) + { + png_memset(ptr, 0, (png_size_t)0x8000L); + png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0, + (png_size_t)(num_bytes - (png_uint_32)0x8000L)); + } + else + { + png_memset(ptr, 0, (png_size_t)num_bytes); + } +#endif return ((voidpf)ptr); } /* Function to free memory for zlib */ +#ifdef PNG_1_0_X +void PNGAPI +#else void /* PRIVATE */ +#endif png_zfree(voidpf png_ptr, voidpf ptr) { png_free((png_structp)png_ptr, (png_voidp)ptr); @@ -203,6 +301,15 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) * and applications using it are urged to use png_create_info_struct() * instead. */ +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +#undef png_info_init +void PNGAPI +png_info_init(png_infop info_ptr) +{ + /* We only come here via pre-1.0.12-compiled applications */ + png_info_init_3(&info_ptr, 0); +} +#endif void PNGAPI png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) @@ -225,6 +332,7 @@ png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) png_memset(info_ptr, 0, png_sizeof(png_info)); } +#ifdef PNG_FREE_ME_SUPPORTED void PNGAPI png_data_freer(png_structp png_ptr, png_infop info_ptr, int freer, png_uint_32 mask) @@ -240,8 +348,9 @@ png_data_freer(png_structp png_ptr, png_infop info_ptr, info_ptr->free_me &= ~mask; else png_warning(png_ptr, - "Unknown freer parameter in png_data_freer"); + "Unknown freer parameter in png_data_freer."); } +#endif void PNGAPI png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, @@ -254,7 +363,11 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #ifdef PNG_TEXT_SUPPORTED /* Free text item num or (if num == -1) all text items */ +#ifdef PNG_FREE_ME_SUPPORTED if ((mask & PNG_FREE_TEXT) & info_ptr->free_me) +#else + if (mask & PNG_FREE_TEXT) +#endif { if (num != -1) { @@ -278,17 +391,28 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #ifdef PNG_tRNS_SUPPORTED /* Free any tRNS entry */ +#ifdef PNG_FREE_ME_SUPPORTED if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) +#else + if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS)) +#endif { - png_free(png_ptr, info_ptr->trans_alpha); - info_ptr->trans_alpha = NULL; + png_free(png_ptr, info_ptr->trans); + info_ptr->trans = NULL; info_ptr->valid &= ~PNG_INFO_tRNS; +#ifndef PNG_FREE_ME_SUPPORTED + png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; +#endif } #endif #ifdef PNG_sCAL_SUPPORTED /* Free any sCAL entry */ +#ifdef PNG_FREE_ME_SUPPORTED if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) +#else + if (mask & PNG_FREE_SCAL) +#endif { #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) png_free(png_ptr, info_ptr->scal_s_width); @@ -302,7 +426,11 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #ifdef PNG_pCAL_SUPPORTED /* Free any pCAL entry */ +#ifdef PNG_FREE_ME_SUPPORTED if ((mask & PNG_FREE_PCAL) & info_ptr->free_me) +#else + if (mask & PNG_FREE_PCAL) +#endif { png_free(png_ptr, info_ptr->pcal_purpose); png_free(png_ptr, info_ptr->pcal_units); @@ -325,7 +453,11 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #ifdef PNG_iCCP_SUPPORTED /* Free any iCCP entry */ +#ifdef PNG_FREE_ME_SUPPORTED if ((mask & PNG_FREE_ICCP) & info_ptr->free_me) +#else + if (mask & PNG_FREE_ICCP) +#endif { png_free(png_ptr, info_ptr->iccp_name); png_free(png_ptr, info_ptr->iccp_profile); @@ -337,7 +469,11 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #ifdef PNG_sPLT_SUPPORTED /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ +#ifdef PNG_FREE_ME_SUPPORTED if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) +#else + if (mask & PNG_FREE_SPLT) +#endif { if (num != -1) { @@ -373,7 +509,11 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, png_ptr->unknown_chunk.data = NULL; } +#ifdef PNG_FREE_ME_SUPPORTED if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) +#else + if (mask & PNG_FREE_UNKN) +#endif { if (num != -1) { @@ -402,26 +542,44 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #ifdef PNG_hIST_SUPPORTED /* Free any hIST entry */ +#ifdef PNG_FREE_ME_SUPPORTED if ((mask & PNG_FREE_HIST) & info_ptr->free_me) +#else + if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST)) +#endif { png_free(png_ptr, info_ptr->hist); info_ptr->hist = NULL; info_ptr->valid &= ~PNG_INFO_hIST; +#ifndef PNG_FREE_ME_SUPPORTED + png_ptr->flags &= ~PNG_FLAG_FREE_HIST; +#endif } #endif /* Free any PLTE entry that was internally allocated */ +#ifdef PNG_FREE_ME_SUPPORTED if ((mask & PNG_FREE_PLTE) & info_ptr->free_me) +#else + if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE)) +#endif { png_zfree(png_ptr, info_ptr->palette); info_ptr->palette = NULL; info_ptr->valid &= ~PNG_INFO_PLTE; +#ifndef PNG_FREE_ME_SUPPORTED + png_ptr->flags &= ~PNG_FLAG_FREE_PLTE; +#endif info_ptr->num_palette = 0; } #ifdef PNG_INFO_IMAGE_SUPPORTED /* Free any image bits attached to the info structure */ +#ifdef PNG_FREE_ME_SUPPORTED if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) +#else + if (mask & PNG_FREE_ROWS) +#endif { if (info_ptr->row_pointers) { @@ -429,17 +587,21 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, for (row = 0; row < (int)info_ptr->height; row++) { png_free(png_ptr, info_ptr->row_pointers[row]); + info_ptr->row_pointers[row]=NULL; } png_free(png_ptr, info_ptr->row_pointers); + info_ptr->row_pointers=NULL; } info_ptr->valid &= ~PNG_INFO_IDAT; } #endif +#ifdef PNG_FREE_ME_SUPPORTED if (num == -1) info_ptr->free_me &= ~mask; else info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL); +#endif } /* This is an internal routine to free any memory that the info struct is @@ -457,6 +619,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr) 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 @@ -516,6 +679,17 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) png_sizeof(char))); } +#ifdef _WIN32_WCE + { + wchar_t time_buf[29]; + wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"), + ptime->day % 32, short_months[(ptime->month - 1) % 12], + ptime->year, ptime->hour % 24, ptime->minute % 60, + ptime->second % 61); + WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29, + NULL, NULL); + } +#else #ifdef USE_FAR_KEYWORD { char near_time_buf[29]; @@ -532,6 +706,7 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) ptime->year, ptime->hour % 24, ptime->minute % 60, ptime->second % 61); #endif +#endif /* _WIN32_WCE */ return ((png_charp)png_ptr->time_buffer); } #endif /* PNG_TIME_RFC1123_SUPPORTED */ @@ -547,13 +722,13 @@ png_get_copyright(png_structp png_ptr) #else #ifdef __STDC__ return ((png_charp) PNG_STRING_NEWLINE \ - "libpng version x 1.4.0rc01 - October 21, 2009" PNG_STRING_NEWLINE \ + "libpng version 1.2.41beta14 - November 3, 2009" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2009 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ PNG_STRING_NEWLINE); #else - return ((png_charp) "libpng version 1.4.0rc01 - October 21, 2009\ + return ((png_charp) "libpng version 1.2.41beta14 - November 3, 2009\ Copyright (c) 1998-2009 Glenn Randers-Pehrson\ Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."); @@ -638,6 +813,17 @@ png_access_version_number(void) } +#if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#ifndef PNG_1_0_X +/* This function was added to libpng 1.2.0 */ +int PNGAPI +png_mmx_support(void) +{ + /* Obsolete, to be removed from libpng-1.4.0 */ + return -1; +} +#endif /* PNG_1_0_X */ +#endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */ #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #ifdef PNG_SIZE_T @@ -1,7 +1,6 @@ - /* png.h - header file for PNG reference library * - * libpng version 1.4.0rc01 - October 21, 2009 + * libpng version 1.2.41beta14 - November 3, 2009 * Copyright (c) 1998-2009 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 +10,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.4.0rc01 - October 21, 2009: Glenn + * libpng versions 0.97, January 1998, through 1.2.41beta14 - November 3, 2009: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -105,31 +104,148 @@ * 1.0.16 10 10016 10.so.0.1.0.16 * 1.2.6 13 10206 12.so.0.1.2.6 * 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2 - * 1.0.17rc1 10 10017 12.so.0.1.0.17rc1 + * 1.0.17rc1 10 10017 10.so.0.1.0.17rc1 * 1.2.7rc1 13 10207 12.so.0.1.2.7rc1 - * 1.0.17 10 10017 12.so.0.1.0.17 + * 1.0.17 10 10017 10.so.0.1.0.17 * 1.2.7 13 10207 12.so.0.1.2.7 * 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5 - * 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5 + * 1.0.18rc1-5 10 10018 10.so.0.1.0.18rc1-5 * 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5 - * 1.0.18 10 10018 12.so.0.1.0.18 + * 1.0.18 10 10018 10.so.0.1.0.18 * 1.2.8 13 10208 12.so.0.1.2.8 * 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3 * 1.2.9beta4-11 13 10209 12.so.0.9[.0] * 1.2.9rc1 13 10209 12.so.0.9[.0] * 1.2.9 13 10209 12.so.0.9[.0] - * 1.2.10beta1-7 13 10210 12.so.0.10[.0] - * 1.2.10rc1-2 13 10210 12.so.0.10[.0] + * 1.2.10beta1-8 13 10210 12.so.0.10[.0] + * 1.2.10rc1-3 13 10210 12.so.0.10[.0] * 1.2.10 13 10210 12.so.0.10[.0] - * 1.4.0beta1-5 14 10400 14.so.0.0[.0] * 1.2.11beta1-4 13 10211 12.so.0.11[.0] - * 1.4.0beta7-8 14 10400 14.so.0.0[.0] + * 1.0.19rc1-5 10 10019 10.so.0.19[.0] + * 1.2.11rc1-5 13 10211 12.so.0.11[.0] + * 1.0.19 10 10019 10.so.0.19[.0] * 1.2.11 13 10211 12.so.0.11[.0] + * 1.0.20 10 10020 10.so.0.20[.0] * 1.2.12 13 10212 12.so.0.12[.0] - * 1.4.0beta9-14 14 10400 14.so.0.0[.0] + * 1.2.13beta1 13 10213 12.so.0.13[.0] + * 1.0.21 10 10021 10.so.0.21[.0] * 1.2.13 13 10213 12.so.0.13[.0] - * 1.4.0beta15-36 14 10400 14.so.0.0[.0] - * 1.4.0beta37-87 14 10400 14.so.14.0[.0] + * 1.2.14beta1-2 13 10214 12.so.0.14[.0] + * 1.0.22rc1 10 10022 10.so.0.22[.0] + * 1.2.14rc1 13 10214 12.so.0.14[.0] + * 1.0.22 10 10022 10.so.0.22[.0] + * 1.2.14 13 10214 12.so.0.14[.0] + * 1.2.15beta1-6 13 10215 12.so.0.15[.0] + * 1.0.23rc1-5 10 10023 10.so.0.23[.0] + * 1.2.15rc1-5 13 10215 12.so.0.15[.0] + * 1.0.23 10 10023 10.so.0.23[.0] + * 1.2.15 13 10215 12.so.0.15[.0] + * 1.2.16beta1-2 13 10216 12.so.0.16[.0] + * 1.2.16rc1 13 10216 12.so.0.16[.0] + * 1.0.24 10 10024 10.so.0.24[.0] + * 1.2.16 13 10216 12.so.0.16[.0] + * 1.2.17beta1-2 13 10217 12.so.0.17[.0] + * 1.0.25rc1 10 10025 10.so.0.25[.0] + * 1.2.17rc1-3 13 10217 12.so.0.17[.0] + * 1.0.25 10 10025 10.so.0.25[.0] + * 1.2.17 13 10217 12.so.0.17[.0] + * 1.0.26 10 10026 10.so.0.26[.0] + * 1.2.18 13 10218 12.so.0.18[.0] + * 1.2.19beta1-31 13 10219 12.so.0.19[.0] + * 1.0.27rc1-6 10 10027 10.so.0.27[.0] + * 1.2.19rc1-6 13 10219 12.so.0.19[.0] + * 1.0.27 10 10027 10.so.0.27[.0] + * 1.2.19 13 10219 12.so.0.19[.0] + * 1.2.20beta01-04 13 10220 12.so.0.20[.0] + * 1.0.28rc1-6 10 10028 10.so.0.28[.0] + * 1.2.20rc1-6 13 10220 12.so.0.20[.0] + * 1.0.28 10 10028 10.so.0.28[.0] + * 1.2.20 13 10220 12.so.0.20[.0] + * 1.2.21beta1-2 13 10221 12.so.0.21[.0] + * 1.2.21rc1-3 13 10221 12.so.0.21[.0] + * 1.0.29 10 10029 10.so.0.29[.0] + * 1.2.21 13 10221 12.so.0.21[.0] + * 1.2.22beta1-4 13 10222 12.so.0.22[.0] + * 1.0.30rc1 10 10030 10.so.0.30[.0] + * 1.2.22rc1 13 10222 12.so.0.22[.0] + * 1.0.30 10 10030 10.so.0.30[.0] + * 1.2.22 13 10222 12.so.0.22[.0] + * 1.2.23beta01-05 13 10223 12.so.0.23[.0] + * 1.2.23rc01 13 10223 12.so.0.23[.0] + * 1.2.23 13 10223 12.so.0.23[.0] + * 1.2.24beta01-02 13 10224 12.so.0.24[.0] + * 1.2.24rc01 13 10224 12.so.0.24[.0] + * 1.2.24 13 10224 12.so.0.24[.0] + * 1.2.25beta01-06 13 10225 12.so.0.25[.0] + * 1.2.25rc01-02 13 10225 12.so.0.25[.0] + * 1.0.31 10 10031 10.so.0.31[.0] + * 1.2.25 13 10225 12.so.0.25[.0] + * 1.2.26beta01-06 13 10226 12.so.0.26[.0] + * 1.2.26rc01 13 10226 12.so.0.26[.0] + * 1.2.26 13 10226 12.so.0.26[.0] + * 1.0.32 10 10032 10.so.0.32[.0] + * 1.2.27beta01-06 13 10227 12.so.0.27[.0] + * 1.2.27rc01 13 10227 12.so.0.27[.0] + * 1.0.33 10 10033 10.so.0.33[.0] + * 1.2.27 13 10227 12.so.0.27[.0] + * 1.0.34 10 10034 10.so.0.34[.0] + * 1.2.28 13 10228 12.so.0.28[.0] + * 1.2.29beta01-03 13 10229 12.so.0.29[.0] + * 1.2.29rc01 13 10229 12.so.0.29[.0] + * 1.0.35 10 10035 10.so.0.35[.0] + * 1.2.29 13 10229 12.so.0.29[.0] + * 1.0.37 10 10037 10.so.0.37[.0] + * 1.2.30beta01-04 13 10230 12.so.0.30[.0] + * 1.0.38rc01-08 10 10038 10.so.0.38[.0] + * 1.2.30rc01-08 13 10230 12.so.0.30[.0] + * 1.0.38 10 10038 10.so.0.38[.0] + * 1.2.30 13 10230 12.so.0.30[.0] + * 1.0.39rc01-03 10 10039 10.so.0.39[.0] + * 1.2.31rc01-03 13 10231 12.so.0.31[.0] + * 1.0.39 10 10039 10.so.0.39[.0] + * 1.2.31 13 10231 12.so.0.31[.0] + * 1.2.32beta01-02 13 10232 12.so.0.32[.0] + * 1.0.40rc01 10 10040 10.so.0.40[.0] + * 1.2.32rc01 13 10232 12.so.0.32[.0] + * 1.0.40 10 10040 10.so.0.40[.0] + * 1.2.32 13 10232 12.so.0.32[.0] + * 1.2.33beta01-02 13 10233 12.so.0.33[.0] + * 1.2.33rc01-02 13 10233 12.so.0.33[.0] + * 1.0.41rc01 10 10041 10.so.0.41[.0] + * 1.2.33 13 10233 12.so.0.33[.0] + * 1.0.41 10 10041 10.so.0.41[.0] + * 1.2.34beta01-07 13 10234 12.so.0.34[.0] + * 1.0.42rc01 10 10042 10.so.0.42[.0] + * 1.2.34rc01 13 10234 12.so.0.34[.0] + * 1.0.42 10 10042 10.so.0.42[.0] + * 1.2.34 13 10234 12.so.0.34[.0] + * 1.2.35beta01-03 13 10235 12.so.0.35[.0] + * 1.0.43rc01-02 10 10043 10.so.0.43[.0] + * 1.2.35rc01-02 13 10235 12.so.0.35[.0] + * 1.0.43 10 10043 10.so.0.43[.0] + * 1.2.35 13 10235 12.so.0.35[.0] + * 1.2.36beta01-05 13 10236 12.so.0.36[.0] + * 1.2.36rc01 13 10236 12.so.0.36[.0] + * 1.0.44 10 10044 10.so.0.44[.0] + * 1.2.36 13 10236 12.so.0.36[.0] + * 1.2.37beta01-03 13 10237 12.so.0.37[.0] + * 1.2.37rc01 13 10237 12.so.0.37[.0] + * 1.2.37 13 10237 12.so.0.37[.0] + * 1.2.45 10 10045 12.so.0.45[.0] + * 1.0.46 10 10046 10.so.0.46[.0] + * 1.2.38beta01 13 10238 12.so.0.38[.0] + * 1.2.38rc01-03 13 10238 12.so.0.38[.0] + * 1.0.47 10 10047 10.so.0.47[.0] + * 1.2.38 13 10238 12.so.0.38[.0] + * 1.2.39beta01-05 13 10239 12.so.0.39[.0] + * 1.2.39rc01 13 10239 12.so.0.39[.0] + * 1.0.48 10 10048 10.so.0.48[.0] + * 1.2.39 13 10239 12.so.0.39[.0] + * 1.2.40beta01 13 10240 12.so.0.40[.0] + * 1.2.40rc01 13 10240 12.so.0.40[.0] + * 1.0.49 10 10049 10.so.0.49[.0] + * 1.2.40 13 10240 12.so.0.40[.0] + * 1.2.41beta01-14 13 10241 12.so.0.41[.0] * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be @@ -139,7 +255,7 @@ * to the source version x.y.z (leading zeros in y and z). Beta versions * were given the previous public release number plus a letter, until * version 1.0.6j; from then on they were given the upcoming public - * release number plus "betaNN" or "rcN". + * release number plus "betaNN" or "rcNN". * * Binary incompatibility exists only when applications make direct access * to the info_ptr or png_ptr members through png.h, and the compiled @@ -161,8 +277,8 @@ * * This code is released under the libpng license. * - * libpng versions 1.2.6, August 15, 2004, through 1.4.0rc01, October 21, 2009, are - * Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are + * libpng versions 1.2.6, August 15, 2004, through 1.2.41beta14, November 3, 2009, are + * Copyright (c) 2004, 2006-2009 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: * @@ -250,7 +366,7 @@ * A "png_get_copyright" function is available, for convenient use in "about" * boxes and the like: * - * printf("%s",png_get_copyright(NULL)); + * printf("%s",png_get_copyright(NULL)); * * Also, the PNG logo (in PNG format, of course) is supplied in the * files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). @@ -273,13 +389,13 @@ * Y2K compliance in libpng: * ========================= * - * July 1, 2008 + * November 3, 2009 * * Since the PNG Development group is an ad-hoc body, we can't make * an official declaration. * * This is your unofficial assurance that libpng from version 0.71 and - * upward through 1.4.0rc01 are Y2K compliant. It is my belief that earlier + * upward through 1.2.41beta14 are Y2K compliant. It is my belief that earlier * versions were also Y2K compliant. * * Libpng only has three year fields. One is a 2-byte unsigned integer @@ -335,22 +451,22 @@ */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.4.0rc01" +#define PNG_LIBPNG_VER_STRING "1.2.41beta14" #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.4.0rc01 - October 21, 2009\n" + " libpng version 1.2.41beta14 - November 3, 2009\n" -#define PNG_LIBPNG_VER_SONUM 14 -#define PNG_LIBPNG_VER_DLLNUM 14 +#define PNG_LIBPNG_VER_SONUM 0 +#define PNG_LIBPNG_VER_DLLNUM 13 /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ #define PNG_LIBPNG_VER_MAJOR 1 -#define PNG_LIBPNG_VER_MINOR 4 -#define PNG_LIBPNG_VER_RELEASE 0 +#define PNG_LIBPNG_VER_MINOR 2 +#define PNG_LIBPNG_VER_RELEASE 41 /* This should match the numeric part of the final component of * PNG_LIBPNG_VER_STRING, omitting any leading zero: */ -#define PNG_LIBPNG_VER_BUILD 01 +#define PNG_LIBPNG_VER_BUILD 14 /* Release Status */ #define PNG_LIBPNG_BUILD_ALPHA 1 @@ -375,24 +491,19 @@ * version 1.0.0 was mis-numbered 100 instead of 10000). From * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */ -#define PNG_LIBPNG_VER 10400 /* 1.4.0 */ +#define PNG_LIBPNG_VER 10241 /* 1.2.41 */ #ifndef PNG_VERSION_INFO_ONLY /* Include the compression library's header */ #include "zlib.h" #endif -#ifdef AIX -#define jmpbuf __jmpbuf -#endif - /* Include all user configurable info, including optional assembler routines */ #include "pngconf.h" /* - * Added at libpng-1.2.8 - * - * Ref MSDN: Private as priority over Special + * Added at libpng-1.2.8 */ +/* Ref MSDN: Private as priority over Special * VS_FF_PRIVATEBUILD File *was not* built using standard release * procedures. If this value is given, the StringFileInfo block must * contain a PrivateBuild string. @@ -428,12 +539,65 @@ extern "C" { * which applications aren't expected to use directly. */ +#ifndef PNG_NO_TYPECAST_NULL +#define int_p_NULL (int *)NULL +#define png_bytep_NULL (png_bytep)NULL +#define png_bytepp_NULL (png_bytepp)NULL +#define png_doublep_NULL (png_doublep)NULL +#define png_error_ptr_NULL (png_error_ptr)NULL +#define png_flush_ptr_NULL (png_flush_ptr)NULL +#define png_free_ptr_NULL (png_free_ptr)NULL +#define png_infopp_NULL (png_infopp)NULL +#define png_malloc_ptr_NULL (png_malloc_ptr)NULL +#define png_read_status_ptr_NULL (png_read_status_ptr)NULL +#define png_rw_ptr_NULL (png_rw_ptr)NULL +#define png_structp_NULL (png_structp)NULL +#define png_uint_16p_NULL (png_uint_16p)NULL +#define png_voidp_NULL (png_voidp)NULL +#define png_write_status_ptr_NULL (png_write_status_ptr)NULL +#else +#define int_p_NULL NULL +#define png_bytep_NULL NULL +#define png_bytepp_NULL NULL +#define png_doublep_NULL NULL +#define png_error_ptr_NULL NULL +#define png_flush_ptr_NULL NULL +#define png_free_ptr_NULL NULL +#define png_infopp_NULL NULL +#define png_malloc_ptr_NULL NULL +#define png_read_status_ptr_NULL NULL +#define png_rw_ptr_NULL NULL +#define png_structp_NULL NULL +#define png_uint_16p_NULL NULL +#define png_voidp_NULL NULL +#define png_write_status_ptr_NULL NULL +#endif + /* Variables declared in png.c - only it needs to define PNG_NO_EXTERN */ #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN) /* Version information for C files, stored in png.c. This had better match * the version above. */ +#ifdef PNG_USE_GLOBAL_ARRAYS +PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18]; + /* Need room for 99.99.99beta99z */ +#else #define png_libpng_ver png_get_header_ver(NULL) +#endif + +#ifdef PNG_USE_GLOBAL_ARRAYS +/* This was removed in version 1.0.5c */ +/* Structures to facilitate easy interlacing. See png.c for more details */ +PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7]; +PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7]; +PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7]; +PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7]; +PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7]; +PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7]; +/* This isn't currently used. If you need it, see png.c for more details. +PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_height[7]; +*/ +#endif #endif /* PNG_NO_EXTERN */ @@ -535,7 +699,8 @@ typedef png_text FAR * FAR * png_textpp; #endif /* Supported compression types for text in PNG files (tEXt, and zTXt). - * The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */ + * The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. + */ #define PNG_TEXT_COMPRESSION_NONE_WR -3 #define PNG_TEXT_COMPRESSION_zTXt_WR -2 #define PNG_TEXT_COMPRESSION_NONE -1 @@ -569,9 +734,10 @@ typedef png_time FAR * FAR * png_timepp; * up private chunks for output even though the library doesn't actually * know about their semantics. */ +#define PNG_CHUNK_NAME_LENGTH 5 typedef struct png_unknown_chunk_t { - png_byte name[5]; + png_byte name[PNG_CHUNK_NAME_LENGTH]; png_byte *data; png_size_t size; @@ -624,11 +790,11 @@ typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp; */ typedef struct png_info_struct { - /* the following are necessary for every PNG file */ + /* The following are necessary for every PNG file */ png_uint_32 width; /* width of image in pixels (from IHDR) */ png_uint_32 height; /* height of image in pixels (from IHDR) */ png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */ - png_size_t rowbytes; /* bytes needed to hold an untransformed row */ + png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */ png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */ png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */ png_uint_16 num_trans; /* number of transparent palette color (tRNS) */ @@ -707,8 +873,8 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) * single color specified that should be treated as fully transparent. * Data is valid if (valid & PNG_INFO_tRNS) is non-zero. */ - png_bytep trans_alpha; /* alpha values for paletted image */ - png_color_16 trans_color; /* transparent color for non-palette image */ + png_bytep trans; /* transparent values for paletted image */ + png_color_16 trans_values; /* transparent color for non-palette image */ #endif #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) @@ -793,7 +959,9 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) #endif /* New members added in libpng-1.0.6 */ +#ifdef PNG_FREE_ME_SUPPORTED png_uint_32 free_me; /* flags items libpng is responsible for freeing */ +#endif #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \ defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) @@ -866,6 +1034,10 @@ typedef png_info FAR * FAR * png_infopp; #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL) #define PNG_UINT_32_MAX ((png_uint_32)(-1)) #define PNG_SIZE_MAX ((png_size_t)(-1)) +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* PNG_MAX_UINT is deprecated; use PNG_UINT_31_MAX instead. */ +#define PNG_MAX_UINT PNG_UINT_31_MAX +#endif /* These describe the color_type field in png_info. */ /* color type masks */ @@ -962,7 +1134,7 @@ typedef png_info FAR * FAR * png_infopp; typedef struct png_row_info_struct { png_uint_32 width; /* width of row */ - png_size_t rowbytes; /* number of bytes in row */ + png_uint_32 rowbytes; /* number of bytes in row */ png_byte color_type; /* color type of row */ png_byte bit_depth; /* bit depth of row */ png_byte channels; /* number of channels (1, 2, 3, or 4) */ @@ -997,7 +1169,8 @@ typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep, #endif #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp, png_row_infop, png_bytep)); #endif @@ -1022,11 +1195,11 @@ typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp)); #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */ #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */ #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */ -#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* write only */ +#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* write only, deprecated */ /* Added to libpng-1.2.34 */ -#define PNG_TRANSFORM_STRIP_FILLER_BEFORE PNG_TRANSFORM_STRIP_FILLER -#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */ -/* Added to libpng-1.4.0 */ +#define PNG_TRANSFORM_STRIP_FILLER_BEFORE 0x0800 /* write only */ +#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */ +/* Added to libpng-1.2.41 */ #define PNG_TRANSFORM_GRAY_TO_RGB 0x2000 /* read only */ /* Flags for MNG supported features */ @@ -1034,7 +1207,7 @@ typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp)); #define PNG_FLAG_MNG_FILTER_64 0x04 #define PNG_ALL_MNG_FEATURES 0x05 -typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_alloc_size_t)); +typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t)); typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp)); /* The structure that holds the information to read and write PNG files. @@ -1091,16 +1264,18 @@ struct png_struct_def png_uint_32 height; /* height of image in pixels */ png_uint_32 num_rows; /* number of rows in current pass */ png_uint_32 usr_width; /* width of row at start of write */ - png_size_t rowbytes; /* size of row in bytes */ - png_size_t irowbytes; /* size of current interlaced row in bytes */ + png_uint_32 rowbytes; /* size of row in bytes */ + png_uint_32 irowbytes; /* size of current interlaced row in bytes */ png_uint_32 iwidth; /* width of current interlaced row in pixels */ png_uint_32 row_number; /* current row in interlace pass */ png_bytep prev_row; /* buffer to save previous (unfiltered) row */ png_bytep row_buf; /* buffer to save current (unfiltered) row */ +#ifndef PNG_NO_WRITE_FILTER png_bytep sub_row; /* buffer to save "sub" row when filtering */ png_bytep up_row; /* buffer to save "up" row when filtering */ png_bytep avg_row; /* buffer to save "avg" row when filtering */ png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */ +#endif png_row_info row_info; /* used for transformation routines */ png_uint_32 idat_size; /* current IDAT size for read */ @@ -1123,8 +1298,12 @@ struct png_struct_def png_byte sig_bytes; /* magic bytes read/written from start of file */ #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) +#ifdef PNG_LEGACY_SUPPORTED + png_byte filler; /* filler byte for pixel expansion */ +#else png_uint_16 filler; /* filler bytes for pixel expansion */ #endif +#endif #ifdef PNG_bKGD_SUPPORTED png_byte background_gamma_type; @@ -1170,8 +1349,8 @@ struct png_struct_def #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \ || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - png_bytep trans_alpha; /* alpha values for paletted files */ - png_color_16 trans_color; /* transparent color for non-paletted files */ + png_bytep trans; /* transparency values for paletted files */ + png_color_16 trans_values; /* transparency values for non-paletted files */ #endif png_read_status_ptr read_row_fn; /* called after each row is decoded */ @@ -1198,12 +1377,11 @@ struct png_struct_def png_size_t current_text_left; /* how much text left to read in input */ png_charp current_text; /* current text chunk buffer */ png_charp current_text_ptr; /* current location in current_text */ -# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */ - +# endif /* PNG_TEXT_SUPPORTED */ #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) -/* For the Borland special 64K segment handler */ +/* for the Borland special 64K segment handler */ png_bytepp offset_table_ptr; png_bytep offset_table; png_uint_16 offset_table_number; @@ -1236,7 +1414,9 @@ struct png_struct_def /* New members added in libpng-1.0.6 */ - png_uint_32 free_me; /* flags items libpng is responsible for freeing */ +#ifdef PNG_FREE_ME_SUPPORTED + png_uint_32 free_me; /* flags items libpng is responsible for freeing */ +#endif #ifdef PNG_USER_CHUNKS_SUPPORTED png_voidp user_chunk_ptr; @@ -1262,7 +1442,11 @@ struct png_struct_def defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) /* Changed from png_byte to png_uint_32 at version 1.2.0 */ +#ifdef PNG_1_0_X + png_byte mng_features_permitted; +#else png_uint_32 mng_features_permitted; +#endif /* PNG_1_0_X */ #endif /* New member added in libpng-1.0.7 */ @@ -1275,25 +1459,39 @@ struct png_struct_def png_byte filter_type; #endif +#ifdef PNG_1_0_X +/* New member added in libpng-1.0.10, ifdef'ed out in 1.2.0 */ + png_uint_32 row_buf_size; +#endif + /* New members added in libpng-1.2.0 */ +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +# ifndef PNG_1_0_X +# ifdef PNG_MMX_CODE_SUPPORTED + png_byte mmx_bitdepth_threshold; + png_uint_32 mmx_rowbytes_threshold; +# endif + png_uint_32 asm_flags; +# endif +#endif /* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ #ifdef PNG_USER_MEM_SUPPORTED - png_voidp mem_ptr; /* user supplied struct for mem functions */ - png_malloc_ptr malloc_fn; /* function for allocating memory */ - png_free_ptr free_fn; /* function for freeing memory */ + png_voidp mem_ptr; /* user supplied struct for mem functions */ + png_malloc_ptr malloc_fn; /* function for allocating memory */ + png_free_ptr free_fn; /* function for freeing memory */ #endif /* New member added in libpng-1.0.13 and 1.2.0 */ - png_bytep big_row_buf; /* buffer to save current (unfiltered) row */ + png_bytep big_row_buf; /* buffer to save current (unfiltered) row */ #ifdef PNG_READ_DITHER_SUPPORTED /* The following three members were added at version 1.0.14 and 1.2.4 */ - png_bytep dither_sort; /* working sort array */ - png_bytep index_to_palette; /* where the original index currently is */ - /* in the palette */ - png_bytep palette_to_index; /* which original index points to this */ - /* palette color */ + png_bytep dither_sort; /* working sort array */ + png_bytep index_to_palette; /* where the original index currently is */ + /* in the palette */ + png_bytep palette_to_index; /* which original index points to this */ + /* palette color */ #endif /* New members added in libpng-1.0.16 and 1.2.6 */ @@ -1302,10 +1500,6 @@ struct png_struct_def #ifdef PNG_SET_USER_LIMITS_SUPPORTED png_uint_32 user_width_max; png_uint_32 user_height_max; - /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown - * chunks that can be stored (0x7fffffff means unlimited). - */ - png_uint_32 user_chunk_cache_max; #endif /* New member added in libpng-1.0.25 and 1.2.17 */ @@ -1320,9 +1514,22 @@ struct png_struct_def /* New member added in libpng-1.2.30 */ png_charp chunkdata; /* buffer for reading chunk data */ -/* New member added in libpng-1.4.0 */ +/* New member added in libpng-1.2.41 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + /* Total number of sPLT, text, and unknown + * chunks that can be stored (0x7fffffff means unlimited). + */ + png_uint_32 user_chunk_cache_max; +#endif + +/* New member added in libpng-1.2.41 */ #ifdef PNG_IO_STATE_SUPPORTED - png_uint_32 io_state; + png_uint_32 io_state; +#endif + +/* New member added in libpng-1.2.41, will be removed from 1.4.0 */ +#ifdef PNG_iTXt_SUPPORTED + png_charp user_png_ver; /* libpng version used to build calling app */ #endif }; @@ -1330,7 +1537,7 @@ struct png_struct_def /* This triggers a compiler error in png.c, if png.c and png.h * do not agree upon the version number. */ -typedef png_structp version_1_4_0rc01; +typedef png_structp version_1_2_41beta14; typedef png_struct FAR * FAR * png_structpp; @@ -1360,7 +1567,7 @@ extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start, /* Simple signature checking function. This is the same as calling * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n). */ -#define png_check_sig(sig,n) !png_sig_cmp((sig), 0, (n)) +extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num)); /* Allocate and initialize png_ptr struct for reading, and any other memory. */ extern PNG_EXPORT(png_structp,png_create_read_struct) @@ -1373,13 +1580,13 @@ extern PNG_EXPORT(png_structp,png_create_write_struct) png_error_ptr error_fn, png_error_ptr warn_fn)); #ifdef PNG_WRITE_SUPPORTED -extern PNG_EXPORT(png_size_t,png_get_compression_buffer_size) +extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size) PNGARG((png_structp png_ptr)); #endif #ifdef PNG_WRITE_SUPPORTED extern PNG_EXPORT(void,png_set_compression_buffer_size) - PNGARG((png_structp png_ptr, png_size_t size)); + PNGARG((png_structp png_ptr, png_uint_32 size)); #endif /* Reset the compression stream */ @@ -1397,9 +1604,6 @@ extern PNG_EXPORT(png_structp,png_create_write_struct_2) png_malloc_ptr malloc_fn, png_free_ptr free_fn)); #endif -/* Write the PNG file signature. */ -extern PNG_EXPORT(void,png_write_sig) PNGARG((png_structp png_ptr)); - /* Write a PNG chunk - size, type, (optional) data, CRC. */ extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr, png_bytep chunk_name, png_bytep data, png_size_t length)); @@ -1419,6 +1623,14 @@ extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(png_infop,png_create_info_struct) PNGARG((png_structp png_ptr)); +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Initialize the info structure (old interface - DEPRECATED) */ +extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr)); +#undef png_info_init +#define png_info_init(info_ptr) png_info_init_3(&info_ptr,\ + png_sizeof(png_info)); +#endif + extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr, png_size_t png_info_struct_size)); @@ -1439,7 +1651,7 @@ extern PNG_EXPORT(png_charp,png_convert_to_rfc1123) PNGARG((png_structp png_ptr, png_timep ptime)); #endif -#ifdef PNG_WRITE_tIME_SUPPORTED +#ifdef PNG_CONVERT_tIME_SUPPORTED /* Convert from a struct tm to png_time */ extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime, struct tm FAR * ttime)); @@ -1447,15 +1659,21 @@ extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime, /* Convert from time_t to png_time. Uses gmtime() */ extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime, time_t ttime)); -#endif /* PNG_WRITE_tIME_SUPPORTED */ +#endif /* PNG_CONVERT_tIME_SUPPORTED */ #ifdef PNG_READ_EXPAND_SUPPORTED /* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */ extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr)); +#ifndef PNG_1_0_X extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp png_ptr)); +#endif extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr)); +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Deprecated */ +extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr)); +#endif #endif #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) @@ -1510,8 +1728,10 @@ extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr, #define PNG_FILLER_BEFORE 0 #define PNG_FILLER_AFTER 1 /* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */ +#ifndef PNG_1_0_X extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr, png_uint_32 filler, int flags)); +#endif #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */ #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) @@ -1579,6 +1799,15 @@ extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr, #endif #endif +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ + defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) +/* Permit or disallow empty PLTE (0: not permitted, 1: permitted) */ +/* Deprecated and will be removed. Use png_permit_mng_features() instead. */ +extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr, + int empty_plte_permitted)); +#endif +#endif #ifdef PNG_WRITE_FLUSH_SUPPORTED /* Set how many lines between output flushes - 0 for no flushing */ @@ -1594,20 +1823,20 @@ extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr, png_infop info_ptr)); -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED /* Read one or more rows of image data. */ extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr, png_bytepp row, png_bytepp display_row, png_uint_32 num_rows)); #endif -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED /* Read a row of data. */ extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr, png_bytep row, png_bytep display_row)); #endif -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED /* Read the whole image into memory at once. */ extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr, png_bytepp image)); @@ -1625,11 +1854,11 @@ extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr, extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr, png_bytepp image)); -/* Write the end of the PNG file. */ +/* Writes the end of the PNG file. */ extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr, png_infop info_ptr)); -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED /* Read the end of the PNG file. */ extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr, png_infop info_ptr)); @@ -1712,7 +1941,7 @@ extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method, #define PNG_FILTER_VALUE_PAETH 4 #define PNG_FILTER_VALUE_LAST 5 -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* EXPERIMENTAL */ +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */ /* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_ * defines, either the default (minimum-sum-of-absolute-differences), or * the experimental method (weighted-minimum-sum-of-absolute-differences). @@ -1840,18 +2069,21 @@ extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr, extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr)); #endif -#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp png_ptr, png_user_transform_ptr read_user_transform_fn)); #endif -#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED +#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp png_ptr, png_user_transform_ptr write_user_transform_fn)); #endif #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp png_ptr, png_voidp user_transform_ptr, int user_transform_depth, int user_transform_channels)); @@ -1892,25 +2124,41 @@ extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr, #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr, - png_alloc_size_t size)); -/* Added at libpng version 1.4.0 */ + png_uint_32 size)); +/* Added at libpng version 1.2.41 */ extern PNG_EXPORT(png_voidp,png_calloc) PNGARG((png_structp png_ptr, - png_alloc_size_t size)); + png_uint_32 size)); +#ifdef PNG_1_0_X +# define png_malloc_warn png_malloc +#else /* Added at libpng version 1.2.4 */ extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr, - png_alloc_size_t size)); + png_uint_32 size)); +#endif /* Frees a pointer allocated by png_malloc() */ extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr)); +#ifdef PNG_1_0_X +/* Function to allocate memory for zlib. */ +extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items, + uInt size)); + +/* Function to free memory for zlib */ +extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr)); +#endif + /* Free data that was allocated internally */ extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 free_me, int num)); +#ifdef PNG_FREE_ME_SUPPORTED /* Reassign responsibility for freeing existing data, whether allocated - * by libpng or by the application */ + * by libpng or by the application + */ extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr, png_infop info_ptr, int freer, png_uint_32 mask)); +#endif /* Assignments for png_data_freer */ #define PNG_DESTROY_WILL_FREE_DATA 1 #define PNG_SET_WILL_FREE_DATA 1 @@ -1932,16 +2180,23 @@ extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr, #ifdef PNG_USER_MEM_SUPPORTED extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr, - png_alloc_size_t size)); + png_uint_32 size)); extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr, png_voidp ptr)); #endif -#ifdef USE_FAR_KEYWORD /* memory model conversion function */ +extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr, + png_voidp s1, png_voidp s2, png_uint_32 size)); + +extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr, + png_voidp s1, int value, png_uint_32 size)); + +#if defined(USE_FAR_KEYWORD) /* memory model conversion function */ extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr, int check)); #endif /* USE_FAR_KEYWORD */ +#ifndef PNG_NO_ERROR_TEXT /* Fatal error in PNG image of libpng - can't continue */ extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr, png_const_charp error_message)); @@ -1949,28 +2204,22 @@ extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr, /* The same, but the chunk name is prepended to the error string. */ extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr, png_const_charp error_message)); +#else +/* Fatal error in PNG image of libpng - can't continue */ +extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr)); +#endif +#ifndef PNG_NO_WARNINGS /* Non-fatal error in libpng. Can continue, but may have a problem. */ extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr, png_const_charp warning_message)); +#ifdef PNG_READ_SUPPORTED /* Non-fatal error in libpng, chunk name is prepended to message. */ extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr, png_const_charp warning_message)); - -#ifdef PNG_BENIGN_ERRORS_SUPPORTED -/* 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. */ -extern PNG_EXPORT(void,png_benign_error) PNGARG((png_structp png_ptr, - png_const_charp warning_message)); - -/* Same, chunk name is prepended to message. */ -extern PNG_EXPORT(void,png_chunk_benign_error) PNGARG((png_structp png_ptr, - png_const_charp warning_message)); - -extern PNG_EXPORT(void,png_set_benign_errors) PNGARG((png_structp - png_ptr, int allowed)); -#endif +#endif /* PNG_READ_SUPPORTED */ +#endif /* PNG_NO_WARNINGS */ /* The png_set_<chunk> functions are for storing values in the png_info_struct. * Similarly, the png_get_<chunk> calls are used to read values from the @@ -1989,7 +2238,7 @@ extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)); /* Returns number of bytes needed to hold a transformed row. */ -extern PNG_EXPORT(png_size_t,png_get_rowbytes) PNGARG((png_structp png_ptr, +extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr, png_infop info_ptr)); #ifdef PNG_INFO_IMAGE_SUPPORTED @@ -2239,11 +2488,12 @@ extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, int *num_text)); #endif -/* Note while png_set_text() will accept a structure whose text, - * language, and translated keywords are NULL pointers, the structure - * returned by png_get_text will always contain regular - * zero-terminated C strings. They might be empty strings but - * they will never be NULL pointers. +/* + * Note while png_set_text() will accept a structure whose text, + * language, and translated keywords are NULL pointers, the structure + * returned by png_get_text will always contain regular + * zero-terminated C strings. They might be empty strings but + * they will never be NULL pointers. */ #ifdef PNG_TEXT_SUPPORTED @@ -2263,14 +2513,14 @@ extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr, #ifdef PNG_tRNS_SUPPORTED extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_bytep *trans_alpha, int *num_trans, - png_color_16p *trans_color)); + png_infop info_ptr, png_bytep *trans, int *num_trans, + png_color_16p *trans_values)); #endif #ifdef PNG_tRNS_SUPPORTED extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_bytep trans_alpha, int num_trans, - png_color_16p trans_color)); + png_infop info_ptr, png_bytep trans, int num_trans, + png_color_16p trans_values)); #endif #ifdef PNG_tRNS_SUPPORTED @@ -2372,8 +2622,8 @@ extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr, #endif /* PNG_DEBUG_FILE */ #if (PNG_DEBUG > 1) -/* Note: ["%s"m PNG_STRING_NEWLINE] probably does not work on - * non-ISO compilers +/* Note: ["%s"m PNG_STRING_NEWLINE] probably does not work on non-ISO + * compilers. */ # ifdef __STDC__ # ifndef png_debug @@ -2450,10 +2700,6 @@ extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr, #define png_debug2(l, m, p1, p2) #endif -#if 0 -extern PNG_EXPORT(png_bytep,png_sig_bytes) PNGARG((void)); -#endif - extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr)); @@ -2470,6 +2716,74 @@ extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp #define PNG_HANDLE_CHUNK_IF_SAFE 2 #define PNG_HANDLE_CHUNK_ALWAYS 3 +/* Added to version 1.2.0 */ +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +#ifdef PNG_MMX_CODE_SUPPORTED +#define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */ +#define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */ +#define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04 +#define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08 +#define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10 +#define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20 +#define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40 +#define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80 +#define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */ + +#define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \ + | PNG_ASM_FLAG_MMX_READ_INTERLACE \ + | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \ + | PNG_ASM_FLAG_MMX_READ_FILTER_UP \ + | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \ + | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ) +#define PNG_MMX_WRITE_FLAGS ( 0 ) + +#define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \ + | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \ + | PNG_MMX_READ_FLAGS \ + | PNG_MMX_WRITE_FLAGS ) + +#define PNG_SELECT_READ 1 +#define PNG_SELECT_WRITE 2 +#endif /* PNG_MMX_CODE_SUPPORTED */ + +#ifndef PNG_1_0_X +/* pngget.c */ +extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask) + PNGARG((int flag_select, int *compilerID)); + +/* pngget.c */ +extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask) + PNGARG((int flag_select)); + +/* pngget.c */ +extern PNG_EXPORT(png_uint_32,png_get_asm_flags) + PNGARG((png_structp png_ptr)); + +/* pngget.c */ +extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold) + PNGARG((png_structp png_ptr)); + +/* pngget.c */ +extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold) + PNGARG((png_structp png_ptr)); + +/* pngset.c */ +extern PNG_EXPORT(void,png_set_asm_flags) + PNGARG((png_structp png_ptr, png_uint_32 asm_flags)); + +/* pngset.c */ +extern PNG_EXPORT(void,png_set_mmx_thresholds) + PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold, + png_uint_32 mmx_rowbytes_threshold)); + +#endif /* PNG_1_0_X */ + +#ifndef PNG_1_0_X +/* png.c, pnggccrd.c, or pngvcrd.c */ +extern PNG_EXPORT(int,png_mmx_support) PNGARG((void)); +#endif /* PNG_1_0_X */ +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ + /* Strip the prepended error numbers ("#nnn ") from error and warning * messages before passing them to the error or warning handler. */ @@ -2478,7 +2792,7 @@ extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp png_ptr, png_uint_32 strip_mode)); #endif -/* Added in libpng-1.2.6 */ +/* Added at libpng-1.2.6 */ #ifdef PNG_SET_USER_LIMITS_SUPPORTED extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max)); @@ -2486,36 +2800,14 @@ extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp png_ptr)); -/* Added in libpng-1.4.0 */ +/* Added in libpng-1.2.41 */ extern PNG_EXPORT(void,png_set_chunk_cache_max) PNGARG((png_structp png_ptr, png_uint_32 user_chunk_cache_max)); extern PNG_EXPORT(png_uint_32,png_get_chunk_cache_max) PNGARG((png_structp png_ptr)); #endif -#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) -PNG_EXPORT(png_uint_32,png_get_pixels_per_inch) PNGARG((png_structp png_ptr, -png_infop info_ptr)); - -PNG_EXPORT(png_uint_32,png_get_x_pixels_per_inch) PNGARG((png_structp png_ptr, -png_infop info_ptr)); - -PNG_EXPORT(png_uint_32,png_get_y_pixels_per_inch) PNGARG((png_structp png_ptr, -png_infop info_ptr)); - -PNG_EXPORT(float,png_get_x_offset_inches) PNGARG((png_structp png_ptr, -png_infop info_ptr)); - -PNG_EXPORT(float,png_get_y_offset_inches) PNGARG((png_structp png_ptr, -png_infop info_ptr)); - -#ifdef PNG_pHYs_SUPPORTED -PNG_EXPORT(png_uint_32,png_get_pHYs_dpi) PNGARG((png_structp png_ptr, -png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); -#endif /* PNG_pHYs_SUPPORTED */ -#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ - -/* Added in libpng-1.4.0 */ +/* Added in libpng-1.2.41 */ #ifdef PNG_IO_STATE_SUPPORTED extern PNG_EXPORT(png_uint_32,png_get_io_state) PNGARG((png_structp png_ptr)); @@ -2523,19 +2815,19 @@ extern PNG_EXPORT(png_bytep,png_get_io_chunk_name) PNGARG((png_structp png_ptr)); /* The flags returned by png_get_io_state() are the following: */ -#define PNG_IO_NONE 0x0000 /* no I/O at this moment */ -#define PNG_IO_READING 0x0001 /* currently reading */ -#define PNG_IO_WRITING 0x0002 /* currently writing */ -#define PNG_IO_SIGNATURE 0x0010 /* currently at the file signature */ -#define PNG_IO_CHUNK_HDR 0x0020 /* currently at the chunk header */ -#define PNG_IO_CHUNK_DATA 0x0040 /* currently at the chunk data */ -#define PNG_IO_CHUNK_CRC 0x0080 /* currently at the chunk crc */ -#define PNG_IO_MASK_OP 0x000f /* current operation: reading/writing */ -#define PNG_IO_MASK_LOC 0x00f0 /* current location: sig/hdr/data/crc */ +#define PNG_IO_NONE 0x0000 /* no I/O at this moment */ +#define PNG_IO_READING 0x0001 /* currently reading */ +#define PNG_IO_WRITING 0x0002 /* currently writing */ +#define PNG_IO_SIGNATURE 0x0010 /* currently at the file signature */ +#define PNG_IO_CHUNK_HDR 0x0020 /* currently at the chunk header */ +#define PNG_IO_CHUNK_DATA 0x0040 /* currently at the chunk data */ +#define PNG_IO_CHUNK_CRC 0x0080 /* currently at the chunk crc */ +#define PNG_IO_MASK_OP 0x000f /* current operation: reading/writing */ +#define PNG_IO_MASK_LOC 0x00f0 /* current location: sig/hdr/data/crc */ #endif /* ?PNG_IO_STATE_SUPPORTED */ -/* Maintainer: Put new public prototypes here ^, in libpng.3, and project - * defs +/* Maintainer: Put new public prototypes here ^, in libpng.3, and in + * project defs */ #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED @@ -2579,39 +2871,29 @@ extern PNG_EXPORT(png_bytep,png_get_io_chunk_name) #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */ -#ifdef PNG_USE_READ_MACROS -/* Inline macros to do direct reads of bytes from the input buffer. - * The png_get_int_32() routine assumes we are using two's complement - * format for negative values, which is almost certainly true. - */ -/* We could make special-case BIG_ENDIAN macros that do direct reads here */ -# define png_get_uint_32(buf) \ - (((png_uint_32)(*(buf)) << 24) + \ - ((png_uint_32)(*((buf) + 1)) << 16) + \ - ((png_uint_32)(*((buf) + 2)) << 8) + \ - ((png_uint_32)(*((buf) + 3)))) -# define png_get_uint_16(buf) \ - (((png_uint_32)(*(buf)) << 8) + \ - ((png_uint_32)(*((buf) + 1)))) -#ifdef PNG_GET_INT_32_SUPPORTED -# define png_get_int_32(buf) \ - (((png_int_32)(*(buf)) << 24) + \ - ((png_int_32)(*((buf) + 1)) << 16) + \ - ((png_int_32)(*((buf) + 2)) << 8) + \ - ((png_int_32)(*((buf) + 3)))) -#endif +/* Inline macros to do direct reads of bytes from the input buffer. These + * require that you are using an architecture that uses PNG byte ordering + * (MSB first) and supports unaligned data storage. I think that PowerPC + * in big-endian mode and 680x0 are the only ones that will support this. + * The x86 line of processors definitely do not. The png_get_int_32() + * routine also assumes we are using two's complement format for negative + * values, which is almost certainly true. + */ +#ifdef PNG_READ_BIG_ENDIAN_SUPPORTED +# define png_get_uint_32(buf) ( *((png_uint_32p) (buf))) +# define png_get_uint_16(buf) ( *((png_uint_16p) (buf))) +# define png_get_int_32(buf) ( *((png_int_32p) (buf))) #else extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf)); extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf)); -#ifdef PNG_GET_INT_32_SUPPORTED extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf)); -#endif -#endif +#endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */ extern PNG_EXPORT(png_uint_32,png_get_uint_31) PNGARG((png_structp png_ptr, png_bytep buf)); /* No png_get_int_16 -- may be added if there's a real need for it. */ -/* Place a 32-bit number into a buffer in PNG byte order (big-endian). */ +/* Place a 32-bit number into a buffer in PNG byte order (big-endian). + */ extern PNG_EXPORT(void,png_save_uint_32) PNGARG((png_bytep buf, png_uint_32 i)); extern PNG_EXPORT(void,png_save_int_32) @@ -2627,16 +2909,873 @@ extern PNG_EXPORT(void,png_save_uint_16) /* ************************************************************************* */ -/* Various modes of operation. Note that after an init, mode is set to - * zero automatically when the structure is created. +/* These next functions are used internally in the code. They generally + * shouldn't be used unless you are writing code to add or replace some + * functionality in libpng. More information about most functions can + * be found in the files where the functions are located. + */ + + +/* Various modes of operation, that are visible to applications because + * they are used for unknown chunk location. */ #define PNG_HAVE_IHDR 0x01 #define PNG_HAVE_PLTE 0x02 #define PNG_HAVE_IDAT 0x04 #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */ #define PNG_HAVE_IEND 0x10 + +#ifdef PNG_INTERNAL + +/* More modes of operation. Note that after an init, mode is set to + * zero automatically when the structure is created. + */ #define PNG_HAVE_gAMA 0x20 #define PNG_HAVE_cHRM 0x40 +#define PNG_HAVE_sRGB 0x80 +#define PNG_HAVE_CHUNK_HEADER 0x100 +#define PNG_WROTE_tIME 0x200 +#define PNG_WROTE_INFO_BEFORE_PLTE 0x400 +#define PNG_BACKGROUND_IS_GRAY 0x800 +#define PNG_HAVE_PNG_SIGNATURE 0x1000 +#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */ + +/* Flags for the transformations the PNG library does on the image data */ +#define PNG_BGR 0x0001 +#define PNG_INTERLACE 0x0002 +#define PNG_PACK 0x0004 +#define PNG_SHIFT 0x0008 +#define PNG_SWAP_BYTES 0x0010 +#define PNG_INVERT_MONO 0x0020 +#define PNG_DITHER 0x0040 +#define PNG_BACKGROUND 0x0080 +#define PNG_BACKGROUND_EXPAND 0x0100 + /* 0x0200 unused */ +#define PNG_16_TO_8 0x0400 +#define PNG_RGBA 0x0800 +#define PNG_EXPAND 0x1000 +#define PNG_GAMMA 0x2000 +#define PNG_GRAY_TO_RGB 0x4000 +#define PNG_FILLER 0x8000L +#define PNG_PACKSWAP 0x10000L +#define PNG_SWAP_ALPHA 0x20000L +#define PNG_STRIP_ALPHA 0x40000L +#define PNG_INVERT_ALPHA 0x80000L +#define PNG_USER_TRANSFORM 0x100000L +#define PNG_RGB_TO_GRAY_ERR 0x200000L +#define PNG_RGB_TO_GRAY_WARN 0x400000L +#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */ + /* 0x800000L Unused */ +#define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */ +#define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */ +#define PNG_PREMULTIPLY_ALPHA 0x4000000L /* Added to libpng-1.2.41 */ + /* by volker */ + /* 0x8000000L unused */ + /* 0x10000000L unused */ + /* 0x20000000L unused */ + /* 0x40000000L unused */ + +/* Flags for png_create_struct */ +#define PNG_STRUCT_PNG 0x0001 +#define PNG_STRUCT_INFO 0x0002 + +/* Scaling factor for filter heuristic weighting calculations */ +#define PNG_WEIGHT_SHIFT 8 +#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT)) +#define PNG_COST_SHIFT 3 +#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT)) + +/* Flags for the png_ptr->flags rather than declaring a byte for each one */ +#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001 +#define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002 +#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004 +#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008 +#define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010 +#define PNG_FLAG_ZLIB_FINISHED 0x0020 +#define PNG_FLAG_ROW_INIT 0x0040 +#define PNG_FLAG_FILLER_AFTER 0x0080 +#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100 +#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200 +#define PNG_FLAG_CRC_CRITICAL_USE 0x0400 +#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800 +#define PNG_FLAG_FREE_PLTE 0x1000 +#define PNG_FLAG_FREE_TRNS 0x2000 +#define PNG_FLAG_FREE_HIST 0x4000 +#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L +#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L +#define PNG_FLAG_LIBRARY_MISMATCH 0x20000L +#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L +#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L +#define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L +#define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */ +#define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */ + /* 0x800000L unused */ + /* 0x1000000L unused */ + /* 0x2000000L unused */ + /* 0x4000000L unused */ + /* 0x8000000L unused */ + /* 0x10000000L unused */ + /* 0x20000000L unused */ + /* 0x40000000L unused */ + +#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ + PNG_FLAG_CRC_ANCILLARY_NOWARN) + +#define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \ + PNG_FLAG_CRC_CRITICAL_IGNORE) + +#define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \ + PNG_FLAG_CRC_CRITICAL_MASK) + +/* Save typing and make code easier to understand */ + +#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \ + abs((int)((c1).green) - (int)((c2).green)) + \ + abs((int)((c1).blue) - (int)((c2).blue))) + +/* Added to libpng-1.2.6 JB */ +#define PNG_ROWBYTES(pixel_bits, width) \ + ((pixel_bits) >= 8 ? \ + ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \ + (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) ) + +/* PNG_OUT_OF_RANGE returns true if value is outside the range + * ideal-delta..ideal+delta. Each argument is evaluated twice. + * "ideal" and "delta" should be constants, normally simple + * integers, "value" a variable. Added to libpng-1.2.6 JB + */ +#define PNG_OUT_OF_RANGE(value, ideal, delta) \ + ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) ) + +/* Variables declared in png.c - only it needs to define PNG_NO_EXTERN */ +#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN) +/* Place to hold the signature string for a PNG file. */ +#ifdef PNG_USE_GLOBAL_ARRAYS + PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8]; +#else +#endif +#endif /* PNG_NO_EXTERN */ + +/* Constant strings for known chunk types. If you need to add a chunk, + * define the name here, and add an invocation of the macro in png.c and + * wherever it's needed. + */ +#define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'} +#define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'} +#define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'} +#define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'} +#define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'} +#define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'} +#define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'} +#define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'} +#define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'} +#define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'} +#define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'} +#define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'} +#define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'} +#define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'} +#define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'} +#define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'} +#define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'} +#define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'} +#define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'} +#define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'} +#define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'} + +#ifdef PNG_USE_GLOBAL_ARRAYS +PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5]; +#endif /* PNG_USE_GLOBAL_ARRAYS */ + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Initialize png_ptr struct for reading, and allocate any other memory. + * (old interface - DEPRECATED - use png_create_read_struct instead). + */ +extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr)); +#undef png_read_init +#define png_read_init(png_ptr) png_read_init_3(&png_ptr, \ + PNG_LIBPNG_VER_STRING, png_sizeof(png_struct)); +#endif + +extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size)); +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t + png_info_size)); +#endif + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Initialize png_ptr struct for writing, and allocate any other memory. + * (old interface - DEPRECATED - use png_create_write_struct instead). + */ +extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr)); +#undef png_write_init +#define png_write_init(png_ptr) png_write_init_3(&png_ptr, \ + PNG_LIBPNG_VER_STRING, png_sizeof(png_struct)); +#endif + +extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size)); +extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t + png_info_size)); + +/* Allocate memory for an internal libpng struct */ +PNG_EXTERN png_voidp png_create_struct PNGARG((int type)); + +/* Free memory from internal libpng struct */ +PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr)); + +PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr + malloc_fn, png_voidp mem_ptr)); +PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr, + png_free_ptr free_fn, png_voidp mem_ptr)); + +/* Free any memory that info_ptr points to and reset struct. */ +PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, + png_infop info_ptr)); + +#ifndef PNG_1_0_X +/* Function to allocate memory for zlib. */ +PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size)); + +/* Function to free memory for zlib */ +PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr)); + +#ifdef PNG_SIZE_T +/* Function to convert a sizeof an item to png_sizeof item */ + PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size)); +#endif + +/* Next four functions are used internally as callbacks. PNGAPI is required + * but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3. + */ + +PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr, + png_bytep data, png_size_t length)); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t length)); +#endif + +PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr, + png_bytep data, png_size_t length)); + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +#ifdef PNG_STDIO_SUPPORTED +PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr)); +#endif +#endif +#else /* PNG_1_0_X */ +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t length)); +#endif +#endif /* PNG_1_0_X */ + +/* Reset the CRC variable */ +PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr)); + +/* Write the "data" buffer to whatever output you are using. */ +PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data, + png_size_t length)); + +/* Read data from whatever input you are using into the "data" buffer */ +PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data, + png_size_t length)); + +/* Read bytes into buf, and update png_ptr->crc */ +PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf, + png_size_t length)); + +/* Decompress data in a chunk that uses compression */ +#if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \ + defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) +PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr, + int comp_type, png_size_t chunklength, + png_size_t prefix_length, png_size_t *data_length)); +#endif + +/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */ +PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip)); + +/* Read the CRC from the file and compare it to the libpng calculated CRC */ +PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr)); + +/* Calculate the CRC over a section of data. Note that we are only + * passing a maximum of 64K on systems that have this as a memory limit, + * since this is the maximum buffer size we can specify. + */ +PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr, + png_size_t length)); + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +PNG_EXTERN void png_flush PNGARG((png_structp png_ptr)); +#endif + +/* Simple function to write the signature */ +PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr)); + +/* Write various chunks */ + +/* Write the IHDR chunk, and update the png_struct with the necessary + * information. + */ +PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width, + png_uint_32 height, + int bit_depth, int color_type, int compression_method, int filter_method, + int interlace_method)); + +PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette, + png_uint_32 num_pal)); + +PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data, + png_size_t length)); + +PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr)); + +#ifdef PNG_WRITE_gAMA_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma)); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point + file_gamma)); +#endif +#endif + +#ifdef PNG_WRITE_sBIT_SUPPORTED +PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit, + int color_type)); +#endif + +#ifdef PNG_WRITE_cHRM_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_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)); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_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 +#endif + +#ifdef PNG_WRITE_sRGB_SUPPORTED +PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr, + int intent)); +#endif + +#ifdef PNG_WRITE_iCCP_SUPPORTED +PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr, + png_charp name, int compression_type, + png_charp profile, int proflen)); + /* Note to maintainer: profile should be png_bytep */ +#endif + +#ifdef PNG_WRITE_sPLT_SUPPORTED +PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr, + png_sPLT_tp palette)); +#endif + +#ifdef PNG_WRITE_tRNS_SUPPORTED +PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans, + png_color_16p values, int number, int color_type)); +#endif + +#ifdef PNG_WRITE_bKGD_SUPPORTED +PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr, + png_color_16p values, int color_type)); +#endif + +#ifdef PNG_WRITE_hIST_SUPPORTED +PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist, + int num_hist)); +#endif + +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ + defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) +PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr, + png_charp key, png_charpp new_key)); +#endif + +#ifdef PNG_WRITE_tEXt_SUPPORTED +PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key, + png_charp text, png_size_t text_len)); +#endif + +#ifdef PNG_WRITE_zTXt_SUPPORTED +PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key, + png_charp text, png_size_t text_len, int compression)); +#endif + +#ifdef PNG_WRITE_iTXt_SUPPORTED +PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr, + int compression, png_charp key, png_charp lang, png_charp lang_key, + png_charp text)); +#endif + +#ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */ +PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr, + png_infop info_ptr, png_textp text_ptr, int num_text)); +#endif + +#ifdef PNG_WRITE_oFFs_SUPPORTED +PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr, + png_int_32 x_offset, png_int_32 y_offset, int unit_type)); +#endif + +#ifdef PNG_WRITE_pCAL_SUPPORTED +PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_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_WRITE_pHYs_SUPPORTED +PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr, + png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, + int unit_type)); +#endif + +#ifdef PNG_WRITE_tIME_SUPPORTED +PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr, + png_timep mod_time)); +#endif + +#ifdef PNG_WRITE_sCAL_SUPPORTED +#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) +PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr, + int unit, double width, double height)); +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr, + int unit, png_charp width, png_charp height)); +#endif +#endif +#endif + +/* Called when finished processing a row of data */ +PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr)); + +/* Internal use only. Called before first row of data */ +PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr)); + +#ifdef PNG_READ_GAMMA_SUPPORTED +PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr)); +#endif + +/* Combine a row of data, dealing with alpha, etc. if requested */ +PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row, + int mask)); + +#ifdef PNG_READ_INTERLACING_SUPPORTED +/* Expand an interlaced row */ +/* OLD pre-1.0.9 interface: +PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info, + png_bytep row, int pass, png_uint_32 transformations)); + */ +PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr)); +#endif + +/* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */ + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED +/* Grab pixels out of a row for an interlaced pass */ +PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info, + png_bytep row, int pass)); +#endif + +/* Unfilter a row */ +PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr, + png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter)); + +/* Choose the best filter to use and filter the row data */ +PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr, + png_row_infop row_info)); + +/* Write out the filtered row. */ +PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr, + png_bytep filtered_row)); +/* Finish a row while reading, dealing with interlacing passes, etc. */ +PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr)); + +/* Initialize the row buffers, etc. */ +PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr)); +/* Optional call to update the users info structure */ +PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr, + png_infop info_ptr)); + +/* These are the functions that do the transformations */ +#ifdef PNG_READ_FILLER_SUPPORTED +PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info, + png_bytep row, png_uint_32 filler, png_uint_32 flags)); +#endif + +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED +PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED +PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED +PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED +PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ + defined(PNG_READ_STRIP_ALPHA_SUPPORTED) +PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info, + png_bytep row, png_uint_32 flags)); +#endif + +#ifdef PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED +PNG_EXTERN void png_do_read_premultiply_alpha + PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED) +PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop + row_info, png_bytep row)); +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_READ_PACK_SUPPORTED +PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#ifdef PNG_READ_SHIFT_SUPPORTED +PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row, + png_color_8p sig_bits)); +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#ifdef PNG_READ_16_TO_8_SUPPORTED +PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#ifdef PNG_READ_DITHER_SUPPORTED +PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info, + png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup)); + +# ifdef PNG_CORRECT_PALETTE_SUPPORTED +PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr, + png_colorp palette, int num_palette)); +# endif +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#ifdef PNG_WRITE_PACK_SUPPORTED +PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info, + png_bytep row, png_uint_32 bit_depth)); +#endif + +#ifdef PNG_WRITE_SHIFT_SUPPORTED +PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row, + png_color_8p bit_depth)); +#endif + +#ifdef PNG_READ_BACKGROUND_SUPPORTED +#ifdef PNG_READ_GAMMA_SUPPORTED +PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row, + png_color_16p trans_values, png_color_16p background, + png_color_16p background_1, + png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, + png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1, + png_uint_16pp gamma_16_to_1, int gamma_shift)); +#else +PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row, + png_color_16p trans_values, png_color_16p background)); +#endif +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row, + png_bytep gamma_table, png_uint_16pp gamma_16_table, + int gamma_shift)); +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED +PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info, + png_bytep row, png_colorp palette, png_bytep trans, int num_trans)); +PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info, + png_bytep row, png_color_16p trans_value)); +#endif + +/* The following decodes the appropriate chunks, and does error correction, + * then calls the appropriate callback for the chunk if it is valid. + */ + +/* Decode the IHDR chunk */ +PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); + +#ifdef PNG_READ_bKGD_SUPPORTED +PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_cHRM_SUPPORTED +PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_gAMA_SUPPORTED +PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_hIST_SUPPORTED +PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_iCCP_SUPPORTED +extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif /* PNG_READ_iCCP_SUPPORTED */ + +#ifdef PNG_READ_iTXt_SUPPORTED +PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_oFFs_SUPPORTED +PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED +PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_pHYs_SUPPORTED +PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_sBIT_SUPPORTED +PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_sCAL_SUPPORTED +PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_sPLT_SUPPORTED +extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif /* PNG_READ_sPLT_SUPPORTED */ + +#ifdef PNG_READ_sRGB_SUPPORTED +PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_tEXt_SUPPORTED +PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_tIME_SUPPORTED +PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_tRNS_SUPPORTED +PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_zTXt_SUPPORTED +PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); + +PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr, + png_bytep chunk_name)); + +/* Handle the transformations for reading and writing */ +PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr)); + +PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr)); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr, + png_uint_32 length)); +PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t buffer_length)); +PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t buffer_length)); +PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); +PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row)); +PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr)); +#ifdef PNG_READ_tEXt_SUPPORTED +PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); +PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif +#ifdef PNG_READ_zTXt_SUPPORTED +PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); +PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif +#ifdef PNG_READ_iTXt_SUPPORTED +PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); +PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif + +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + +#ifdef PNG_MNG_FEATURES_SUPPORTED +PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info, + png_bytep row)); +PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +#ifdef PNG_MMX_CODE_SUPPORTED +/* png.c */ /* PRIVATE */ +PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr)); +#endif +#endif + +#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) +PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +#ifdef PNG_pHYs_SUPPORTED +PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr, +png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); +#endif /* PNG_pHYs_SUPPORTED */ +#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ + +/* Read the chunk header (length + type name) */ +PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr)); + +/* Added at libpng version 1.2.34 */ +#ifdef PNG_cHRM_SUPPORTED +PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_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 + +#ifdef PNG_cHRM_SUPPORTED +#ifdef PNG_CHECK_cHRM_SUPPORTED +/* Added at libpng version 1.2.34 */ +PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2, + unsigned long *hi_product, unsigned long *lo_product)); +#endif +#endif + +/* Added at libpng version 1.2.41 */ +PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_type, int compression_type, + int filter_type)); + +/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ + +#endif /* PNG_INTERNAL */ #ifdef __cplusplus } @@ -1,6 +1,12 @@ + /* pngconf.h - machine configurable file for libpng * + * libpng version 1.2.41beta14 - November 3, 2009 + * Copyright (c) 1998-2009 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.) + * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer * and license in png.h @@ -19,24 +25,11 @@ #ifndef PNGCONF_H #define PNGCONF_H -#include "pngcrush.h" +#define PNG_1_2_X -#ifndef PNG_NO_LIMITS_H -# include <limits.h> -#endif - -/* Added at libpng-1.2.9 */ - -/* config.h is created by and PNG_CONFIGURE_LIBPNG is set by the "configure" script. */ -#ifdef PNG_CONFIGURE_LIBPNG -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif -#endif +#include "pngcrush.h" /* - * Added at libpng-1.2.8 - * * PNG_USER_CONFIG has to be defined on the compiler command line. This * includes the resource compiler for Windows DLL configurations. */ @@ -44,10 +37,19 @@ # ifndef PNG_USER_PRIVATEBUILD # define PNG_USER_PRIVATEBUILD # endif -# include "pngusr.h" +#include "pngusr.h" +#endif + +/* PNG_CONFIGURE_LIBPNG is set by the "configure" script. */ +#ifdef PNG_CONFIGURE_LIBPNG +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #endif /* + * Added at libpng-1.2.8 + * * If you create a private DLL you need to define in "pngusr.h" the followings: * #define PNG_USER_PRIVATEBUILD <Describes by whom and why this version of * the DLL was built> @@ -67,21 +69,29 @@ */ #ifdef __STDC__ -# ifdef SPECIALBUILD -# pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\ - are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.") -# endif +#ifdef SPECIALBUILD +# pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\ + are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.") +#endif -# ifdef PRIVATEBUILD -# pragma message("PRIVATEBUILD is deprecated.\ - Use PNG_USER_PRIVATEBUILD instead.") -# define PNG_USER_PRIVATEBUILD PRIVATEBUILD -# endif +#ifdef PRIVATEBUILD +# pragma message("PRIVATEBUILD is deprecated.\ + Use PNG_USER_PRIVATEBUILD instead.") +# define PNG_USER_PRIVATEBUILD PRIVATEBUILD +#endif #endif /* __STDC__ */ +#ifndef PNG_VERSION_INFO_ONLY + /* End of material added to libpng-1.2.8 */ -#ifndef PNG_VERSION_INFO_ONLY +/* Added at libpng-1.2.19, removed at libpng-1.2.20 because it caused trouble + Restored at libpng-1.2.21 */ +#if !defined(PNG_NO_WARN_UNINITIALIZED_ROW) && \ + !defined(PNG_WARN_UNINITIALIZED_ROW) +# define PNG_WARN_UNINITIALIZED_ROW 1 +#endif +/* End of material added at libpng-1.2.19/1.2.21 */ /* This is the size of the compression buffer, and thus the size of * an IDAT chunk. Make this whatever size you feel is best for your @@ -112,7 +122,7 @@ # define PNG_WRITE_SUPPORTED #endif -/* Enabled in 1.4.0. */ +/* Enabled in 1.2.41. */ #ifdef PNG_ALLOW_BENIGN_ERRORS # define png_benign_error png_warning # define png_chunk_benign_error png_chunk_warning @@ -123,7 +133,7 @@ # endif #endif -/* Added at libpng version 1.4.0 */ +/* Added in libpng-1.2.41 */ #if !defined(PNG_NO_WARNINGS) && !defined(PNG_WARNINGS_SUPPORTED) # define PNG_WARNINGS_SUPPORTED #endif @@ -137,25 +147,20 @@ #endif /* Enabled by default in 1.2.0. You can disable this if you don't need to - support PNGs that are embedded in MNG datastreams */ -#ifndef PNG_NO_MNG_FEATURES + * support PNGs that are embedded in MNG datastreams + */ +#if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES) # ifndef PNG_MNG_FEATURES_SUPPORTED # define PNG_MNG_FEATURES_SUPPORTED # endif #endif -/* Added at libpng version 1.4.0 */ #ifndef PNG_NO_FLOATING_POINT_SUPPORTED # ifndef PNG_FLOATING_POINT_SUPPORTED # define PNG_FLOATING_POINT_SUPPORTED # endif #endif -/* Added at libpng-1.4.0beta49 for testing (this test is no longer used - in libpng and png_calloc() is always present) - */ -#define PNG_CALLOC_SUPPORTED - /* If you are running on a machine where you cannot allocate more * than 64K of memory at once, uncomment this. While libpng will not * normally need that much memory in a chunk (unless you load up a very @@ -199,7 +204,7 @@ * we don't need to worry about PNG_STATIC or ALL_STATIC when it comes * to __declspec() stuff. However, we DO need to worry about * PNG_BUILD_DLL and PNG_STATIC because those change some defaults - * such as CONSOLE_IO. + * such as CONSOLE_IO and whether GLOBAL_ARRAYS are allowed. */ #ifdef __CYGWIN__ # ifdef ALL_STATIC @@ -267,14 +272,18 @@ # include <windows.h> /* Console I/O functions are not supported on WindowsCE */ # define PNG_NO_CONSOLE_IO + /* abort() may not be supported on some/all Windows CE platforms */ +# define PNG_ABORT() exit(-1) # ifdef PNG_DEBUG # undef PNG_DEBUG # endif #endif #ifdef PNG_BUILD_DLL -# if !defined(PNG_CONSOLE_IO_SUPPORTED) && !defined(PNG_NO_CONSOLE_IO) -# define PNG_NO_CONSOLE_IO +# ifndef PNG_CONSOLE_IO_SUPPORTED +# ifndef PNG_NO_CONSOLE_IO +# define PNG_NO_CONSOLE_IO +# endif # endif #endif @@ -288,7 +297,10 @@ # endif # endif # else -# include <stdio.h> +# ifndef _WIN32_WCE +/* "stdio.h" functions are not supported on WindowsCE */ +# include <stdio.h> +# endif # endif #if !(defined PNG_NO_CONSOLE_IO) && !defined(PNG_CONSOLE_IO_SUPPORTED) @@ -310,10 +322,14 @@ #ifdef _NO_PROTO # define PNGARG(arglist) () +# ifndef PNG_TYPECAST_NULL +# define PNG_TYPECAST_NULL +# endif #else # define PNGARG(arglist) arglist #endif /* _NO_PROTO */ + #endif /* OF */ #endif /* PNGARG */ @@ -329,14 +345,12 @@ # endif #endif -/* Enough people need this for various reasons to include it here */ +/* enough people need this for various reasons to include it here */ #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE) # include <sys/types.h> #endif -/* PNG_SETJMP_NOT_SUPPORTED and PNG_NO_SETJMP_SUPPORTED are deprecated. */ -#if !defined(PNG_NO_SETJMP) && \ - !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED) +#if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED) # define PNG_SETJMP_SUPPORTED #endif @@ -367,15 +381,14 @@ # endif /* __linux__ */ # endif /* PNG_SKIP_SETJMP_CHECK */ - /* Include setjmp.h for error handling */ + /* include setjmp.h for error handling */ # include <setjmp.h> # ifdef __linux__ # ifdef PNG_SAVE_BSD_SOURCE -# ifdef _BSD_SOURCE -# undef _BSD_SOURCE +# ifndef _BSD_SOURCE +# define _BSD_SOURCE # endif -# define _BSD_SOURCE # undef PNG_SAVE_BSD_SOURCE # endif # endif /* __linux__ */ @@ -388,6 +401,59 @@ #endif /* Other defines for things like memory and the like can go here. */ +#ifdef PNG_INTERNAL + +#include <stdlib.h> + +/* The functions exported by PNG_EXTERN are PNG_INTERNAL functions, which + * aren't usually used outside the library (as far as I know), so it is + * debatable if they should be exported at all. In the future, when it is + * possible to have run-time registry of chunk-handling functions, some of + * these will be made available again. +#define PNG_EXTERN extern + */ +#define PNG_EXTERN + +/* Other defines specific to compilers can go here. Try to keep + * them inside an appropriate ifdef/endif pair for portability. + */ + +#ifdef PNG_FLOATING_POINT_SUPPORTED +# ifdef MACOS + /* We need to check that <math.h> hasn't already been included earlier + * as it seems it doesn't agree with <fp.h>, yet we should really use + * <fp.h> if possible. + */ +# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) +# include <fp.h> +# endif +# else +# include <math.h> +# endif +# if defined(_AMIGA) && defined(__SASC) && defined(_M68881) + /* Amiga SAS/C: We must include builtin FPU functions when compiling using + * MATH=68881 + */ +# include <m68881.h> +# endif +#endif + +/* Codewarrior on NT has linking problems without this. */ +#if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__) +# define PNG_ALWAYS_EXTERN +#endif + +/* This provides the non-ANSI (far) memory allocation routines. */ +#if defined(__TURBOC__) && defined(__MSDOS__) +# include <mem.h> +# include <alloc.h> +#endif + +/* I have no idea why is this necessary... */ +#if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \ + defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__)) +# include <malloc.h> +#endif /* This controls how fine the dithering gets. As this allocates * a largish chunk of memory (32K), those who are not as concerned @@ -421,6 +487,8 @@ # define PNG_GAMMA_THRESHOLD 0.05 #endif +#endif /* PNG_INTERNAL */ + /* The following uses const char * instead of char * for error * and warning message functions, so some compilers won't complain. * If you do not want to use const, define PNG_NO_CONST here. @@ -449,25 +517,64 @@ /* Any features you will not be using can be undef'ed here */ /* GR-P, 0.96a: Set "*TRANSFORMS_SUPPORTED as default but allow user - * to turn it off with PNG_NO_READ|WRITE_TRANSFORMS on the compile line, - * then pick and choose which ones to define without having to edit this - * file. It is safe to use the PNG_NO_READ|WRITE_TRANSFORMS + * to turn it off with "*TRANSFORMS_NOT_SUPPORTED" or *PNG_NO_*_TRANSFORMS + * on the compile line, then pick and choose which ones to define without + * having to edit this file. It is safe to use the *TRANSFORMS_NOT_SUPPORTED * if you only want to have a png-compliant reader/writer but don't need * any of the extra transformations. This saves about 80 kbytes in a * typical installation of the library. (PNG_NO_* form added in version - * 1.0.1c, for consistency; PNG_*_TRANSFORMS_NOT_SUPPORTED deprecated in - * 1.4.0) + * 1.0.1c, for consistency) */ +/* The size of the png_text structure changed in libpng-1.0.6 when + * iTXt support was added. iTXt support was turned off by default through + * libpng-1.2.x, to support old apps that malloc the png_text structure + * instead of calling png_set_text() and letting libpng malloc it. It + * was turned on by default in libpng-1.2.41. + */ + +/* The following support, added after version 1.0.0, can be turned off here en + * masse by defining PNG_LEGACY_SUPPORTED in case you need binary compatibility + * with old applications that require the length of png_struct and png_info + * to remain unchanged. + */ + +#ifdef PNG_LEGACY_SUPPORTED +# define PNG_NO_FREE_ME +# define PNG_NO_READ_UNKNOWN_CHUNKS +# define PNG_NO_WRITE_UNKNOWN_CHUNKS +# define PNG_NO_HANDLE_AS_UNKNOWN +# define PNG_NO_READ_USER_CHUNKS +# define PNG_NO_READ_iCCP +# define PNG_NO_WRITE_iCCP +# define PNG_NO_READ_iTXt +# define PNG_NO_WRITE_iTXt +# define PNG_NO_READ_sCAL +# define PNG_NO_WRITE_sCAL +# define PNG_NO_READ_sPLT +# define PNG_NO_WRITE_sPLT +# define PNG_NO_INFO_IMAGE +# define PNG_NO_READ_RGB_TO_GRAY +# define PNG_NO_READ_USER_TRANSFORM +# define PNG_NO_WRITE_USER_TRANSFORM +# define PNG_NO_USER_MEM +# define PNG_NO_READ_EMPTY_PLTE +# define PNG_NO_MNG_FEATURES +# define PNG_NO_FIXED_POINT_SUPPORTED +#endif + /* Ignore attempt to turn off both floating and fixed point support */ #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \ !defined(PNG_NO_FIXED_POINT_SUPPORTED) # define PNG_FIXED_POINT_SUPPORTED #endif +#ifndef PNG_NO_FREE_ME +# define PNG_FREE_ME_SUPPORTED +#endif + #ifdef PNG_READ_SUPPORTED -/* PNG_READ_TRANSFORMS_NOT_SUPPORTED is deprecated. */ #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \ !defined(PNG_NO_READ_TRANSFORMS) # define PNG_READ_TRANSFORMS_SUPPORTED @@ -495,35 +602,39 @@ # ifndef PNG_NO_READ_INVERT # define PNG_READ_INVERT_SUPPORTED # endif -#if 0 /* removed from libpng-1.4.0 */ # ifndef PNG_NO_READ_DITHER # define PNG_READ_DITHER_SUPPORTED # endif -#endif /* 0 */ # ifndef PNG_NO_READ_BACKGROUND # define PNG_READ_BACKGROUND_SUPPORTED # endif +#ifndef PNG_1_0_X # ifndef PNG_NO_READ_16_TO_8 # define PNG_READ_16_TO_8_SUPPORTED # endif +#endif # ifndef PNG_NO_READ_FILLER # define PNG_READ_FILLER_SUPPORTED # endif # ifndef PNG_NO_READ_GAMMA # define PNG_READ_GAMMA_SUPPORTED # endif +#ifndef PNG_1_0_X # ifndef PNG_NO_READ_GRAY_TO_RGB # define PNG_READ_GRAY_TO_RGB_SUPPORTED # endif +#endif # ifndef PNG_NO_READ_SWAP_ALPHA # define PNG_READ_SWAP_ALPHA_SUPPORTED # endif # ifndef PNG_NO_READ_INVERT_ALPHA # define PNG_READ_INVERT_ALPHA_SUPPORTED # endif +#ifndef PNG_1_0_X # ifndef PNG_NO_READ_PREMULTIPLY_ALPHA # define PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED # endif +#endif # ifndef PNG_NO_READ_STRIP_ALPHA # define PNG_READ_STRIP_ALPHA_SUPPORTED # endif @@ -541,7 +652,6 @@ # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */ #endif /* about interlacing capability! You'll */ /* still have interlacing unless you change the following define: */ - #define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */ /* PNG_NO_SEQUENTIAL_READ_SUPPORTED is deprecated. */ @@ -551,25 +661,27 @@ # define PNG_SEQUENTIAL_READ_SUPPORTED #endif +#define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */ + #ifndef PNG_NO_READ_COMPOSITE_NODIV # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */ -# define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */ +# define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */ # endif #endif -#if !defined(PNG_NO_GET_INT_32) || defined(PNG_READ_oFFS_SUPPORTED) || \ - defined(PNG_READ_pCAL_SUPPORTED) -# ifndef PNG_GET_INT_32_SUPPORTED -# define PNG_GET_INT_32_SUPPORTED -# endif +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Deprecated, will be removed from version 2.0.0. + Use PNG_MNG_FEATURES_SUPPORTED instead. */ +#ifndef PNG_NO_READ_EMPTY_PLTE +# define PNG_READ_EMPTY_PLTE_SUPPORTED +#endif #endif #endif /* PNG_READ_SUPPORTED */ #ifdef PNG_WRITE_SUPPORTED -/* PNG_WRITE_TRANSFORMS_NOT_SUPPORTED is deprecated. */ -#if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \ +# if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \ !defined(PNG_NO_WRITE_TRANSFORMS) # define PNG_WRITE_TRANSFORMS_SUPPORTED #endif @@ -599,9 +711,11 @@ # ifndef PNG_NO_WRITE_SWAP_ALPHA # define PNG_WRITE_SWAP_ALPHA_SUPPORTED # endif +#ifndef PNG_1_0_X # ifndef PNG_NO_WRITE_INVERT_ALPHA # define PNG_WRITE_INVERT_ALPHA_SUPPORTED # endif +#endif # ifndef PNG_NO_WRITE_USER_TRANSFORM # define PNG_WRITE_USER_TRANSFORM_SUPPORTED # endif @@ -609,10 +723,9 @@ #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \ !defined(PNG_WRITE_INTERLACING_SUPPORTED) - /* This is not required for PNG-compliant encoders, but can cause - * trouble if left undefined - */ -# define PNG_WRITE_INTERLACING_SUPPORTED +#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant + encoders, but can cause trouble + if left undefined */ #endif #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \ @@ -625,16 +738,21 @@ # define PNG_WRITE_FLUSH_SUPPORTED #endif -#if !defined(PNG_NO_SAVE_INT_32) || defined(PNG_WRITE_oFFS_SUPPORTED) || \ - defined(PNG_WRITE_pCAL_SUPPORTED) -# ifndef PNG_SAVE_INT_32_SUPPORTED -# define PNG_SAVE_INT_32_SUPPORTED -# endif +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Deprecated, see PNG_MNG_FEATURES_SUPPORTED, above */ +#ifndef PNG_NO_WRITE_EMPTY_PLTE +# define PNG_WRITE_EMPTY_PLTE_SUPPORTED +#endif #endif #endif /* PNG_WRITE_SUPPORTED */ #define PNG_NO_ERROR_NUMBERS +#ifndef PNG_1_0_X +# ifndef PNG_NO_ERROR_NUMBERS +# define PNG_ERROR_NUMBERS_SUPPORTED +# endif +#endif /* PNG_1_0_X */ #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) @@ -643,7 +761,7 @@ # endif #endif -#if defined(PNG_STDIO_SUPPORTED) && !defined(PNG_TIME_RFC1123_SUPPORTED) +#ifndef PNG_NO_STDIO # define PNG_TIME_RFC1123_SUPPORTED #endif @@ -667,19 +785,65 @@ # define PNG_EASY_ACCESS_SUPPORTED #endif +/* PNG_ASSEMBLER_CODE was enabled by default in version 1.2.0 + * and removed from version 1.2.20. The following will be removed + * from libpng-1.4.0 +*/ + +#if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE) +# ifndef PNG_OPTIMIZED_CODE_SUPPORTED +# define PNG_OPTIMIZED_CODE_SUPPORTED +# endif +#endif + +#if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE) +# ifndef PNG_ASSEMBLER_CODE_SUPPORTED +# define PNG_ASSEMBLER_CODE_SUPPORTED +# endif + +# if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4) + /* work around 64-bit gcc compiler bugs in gcc-3.x */ +# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) +# define PNG_NO_MMX_CODE +# endif +# endif + +# ifdef __APPLE__ +# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) +# define PNG_NO_MMX_CODE +# endif +# endif + +# if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh)) +# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) +# define PNG_NO_MMX_CODE +# endif +# endif + +# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) +# define PNG_MMX_CODE_SUPPORTED +# endif + +#endif +/* end of obsolete code to be removed from libpng-1.4.0 */ + /* Added at libpng-1.2.0 */ +#ifndef PNG_1_0_X #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED) # define PNG_USER_MEM_SUPPORTED #endif +#endif /* PNG_1_0_X */ /* Added at libpng-1.2.6 */ -#ifndef PNG_SET_USER_LIMITS_SUPPORTED -# ifndef PNG_NO_SET_USER_LIMITS -# define PNG_SET_USER_LIMITS_SUPPORTED +#ifndef PNG_1_0_X +# ifndef PNG_SET_USER_LIMITS_SUPPORTED +# ifndef PNG_NO_SET_USER_LIMITS +# define PNG_SET_USER_LIMITS_SUPPORTED +# endif # endif -#endif +#endif /* PNG_1_0_X */ -/* Added at libpng-1.0.16 and 1.2.6. To accept all valid PNGs no matter +/* Added at libpng-1.0.16 and 1.2.6. To accept all valid PNGS no matter * how large, set these limits to 0x7fffffffL */ #ifndef PNG_USER_WIDTH_MAX @@ -689,15 +853,19 @@ # define PNG_USER_HEIGHT_MAX 1000000L #endif -/* Added at libpng-1.4.0 */ +#ifndef PNG_1_0_X +/* Added at libpng-1.2.41 */ #ifndef PNG_USER_CHUNK_CACHE_MAX -# define PNG_USER_CHUNK_CACHE_MAX 0x7ffffffLL +# define PNG_USER_CHUNK_CACHE_MAX 0x7fffffffL +#endif #endif -/* Added at libpng-1.4.0 */ +/* Added at libpng-1.2.41 */ +#ifndef PNG_1_0_X #if !defined(PNG_NO_IO_STATE) && !defined(PNG_IO_STATE_SUPPORTED) # define PNG_IO_STATE_SUPPORTED #endif +#endif #ifndef PNG_LITERAL_SHARP # define PNG_LITERAL_SHARP 0x23 @@ -708,13 +876,15 @@ #ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET # define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d #endif + +/* Added at libpng-1.2.34 */ #ifndef PNG_STRING_NEWLINE #define PNG_STRING_NEWLINE "\n" #endif /* These are currently experimental features, define them if you want */ -/* Very little testing */ +/* very little testing */ /* #ifdef PNG_READ_SUPPORTED # ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED @@ -731,17 +901,21 @@ #endif */ -#if !defined(PNG_NO_USE_READ_MACROS) && !defined(PNG_USE_READ_MACROS) -# define PNG_USE_READ_MACROS -#endif - -/* Buggy compilers (e.g., gcc 2.7.2.2) need PNG_NO_POINTER_INDEXING */ +/* Buggy compilers (e.g., gcc 2.7.2.2) need this */ +/* +#define PNG_NO_POINTER_INDEXING +*/ #if !defined(PNG_NO_POINTER_INDEXING) && \ !defined(PNG_POINTER_INDEXING_SUPPORTED) # define PNG_POINTER_INDEXING_SUPPORTED #endif +/* These functions are turned off by default, as they will be phased out. */ +/* +#define PNG_USELESS_TESTS_SUPPORTED +#define PNG_CORRECT_PALETTE_SUPPORTED +*/ /* Any chunks you are not interested in, you can undef here. The * ones that allocate memory may be expecially important (hIST, @@ -749,21 +923,12 @@ * a bit smaller. */ -/* The size of the png_text structure changed in libpng-1.0.6 when - * iTXt support was added. iTXt support was turned off by default through - * libpng-1.2.x, to support old apps that malloc the png_text structure - * instead of calling png_set_text() and letting libpng malloc it. It - * was turned on by default in libpng-1.4.0. - */ - -/* PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED is deprecated. */ #if defined(PNG_READ_SUPPORTED) && \ !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ !defined(PNG_NO_READ_ANCILLARY_CHUNKS) # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED #endif -/* PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED is deprecated. */ #if defined(PNG_WRITE_SUPPORTED) && \ !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS) @@ -777,7 +942,6 @@ # define PNG_NO_READ_tEXt # define PNG_NO_READ_zTXt #endif - #ifndef PNG_NO_READ_bKGD # define PNG_READ_bKGD_SUPPORTED # define PNG_bKGD_SUPPORTED @@ -878,6 +1042,7 @@ # undef PNG_NO_HANDLE_AS_UNKNOWN # endif #endif + #ifndef PNG_NO_HANDLE_AS_UNKNOWN # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED @@ -1004,6 +1169,15 @@ # endif #endif +#ifndef PNG_NO_CONVERT_tIME +# ifndef _WIN32_WCE +/* The "tm" structure is not supported on WindowsCE */ +# ifndef PNG_CONVERT_tIME_SUPPORTED +# define PNG_CONVERT_tIME_SUPPORTED +# endif +# endif +#endif + #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */ #if !defined(PNG_NO_WRITE_FILTER) && !defined(PNG_WRITE_FILTER_SUPPORTED) @@ -1016,6 +1190,7 @@ # define PNG_UNKNOWN_CHUNKS_SUPPORTED # endif #endif + #ifndef PNG_NO_HANDLE_AS_UNKNOWN # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED @@ -1031,12 +1206,10 @@ # define PNG_INFO_IMAGE_SUPPORTED #endif -/* Need the time information for reading tIME chunks */ -#ifdef PNG_tIME_SUPPORTED -# ifndef _WIN32_WCE +/* Need the time information for converting tIME chunks */ +#ifdef PNG_CONVERT_tIME_SUPPORTED /* "time.h" functions are not supported on WindowsCE */ # include <time.h> -# endif #endif /* Some typedefs to get us started. These should be safe on most of the @@ -1044,29 +1217,28 @@ * numbers suggest (a png_uint_32 must be at least 32 bits long), but they * don't have to be exactly that size. Some compilers dislike passing * unsigned shorts as function parameters, so you may be better off using - * unsigned int for png_uint_16. + * unsigned int for png_uint_16. Likewise, for 64-bit systems, you may + * want to have unsigned int for png_uint_32 instead of unsigned long. */ -#if defined(INT_MAX) && (INT_MAX > 0x7ffffffeL) -typedef unsigned int png_uint_32; -typedef int png_int_32; -#else typedef unsigned long png_uint_32; typedef long png_int_32; -#endif typedef unsigned short png_uint_16; typedef short png_int_16; typedef unsigned char png_byte; -#ifdef PNG_NO_SIZE_T - typedef unsigned int png_size_t; +/* This is usually size_t. It is typedef'ed just in case you need it to + change (I'm not sure if you will or not, so I thought I'd be safe) */ +#ifdef PNG_SIZE_T + typedef PNG_SIZE_T png_size_t; +# define png_sizeof(x) png_convert_size(sizeof(x)) #else typedef size_t png_size_t; +# define png_sizeof(x) sizeof(x) #endif -#define png_sizeof(x) sizeof(x) /* The following is needed for medium model support. It cannot be in the - * pngpriv.h header. Needs modification for other compilers besides + * PNG_INTERNAL section. Needs modification for other compilers besides * MSC. Model independent support declares all arrays and pointers to be * large using the far keyword. The zlib version used must also support * model independent data. As of version zlib 1.0.4, the necessary changes @@ -1075,8 +1247,7 @@ typedef unsigned char png_byte; */ /* Separate compiler dependencies (problem here is that zlib.h always - * defines FAR. (SJT) - */ + defines FAR. (SJT) */ #ifdef __BORLANDC__ # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__) # define LDATA 1 @@ -1141,11 +1312,11 @@ typedef char FAR * png_charp; typedef png_fixed_point FAR * png_fixed_point_p; #ifndef PNG_NO_STDIO -# ifdef _WIN32_WCE +#ifdef _WIN32_WCE typedef HANDLE png_FILE_p; -# else +#else typedef FILE * png_FILE_p; -# endif +#endif #endif #ifdef PNG_FLOATING_POINT_SUPPORTED @@ -1168,7 +1339,20 @@ typedef double FAR * FAR * png_doublepp; /* Pointers to pointers to pointers; i.e., pointer to array */ typedef char FAR * FAR * FAR * png_charppp; -/* Define PNG_BUILD_DLL if the module being built is a Windows +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* SPC - Is this stuff deprecated? */ +/* It'll be removed as of libpng-1.4.0 - GR-P */ +/* libpng typedefs for types in zlib. If zlib changes + * or another compression library is used, then change these. + * Eliminates need to change all the source files. + */ +typedef charf * png_zcharp; +typedef charf * FAR * png_zcharpp; +typedef z_stream FAR * png_zstreamp; +#endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */ + +/* + * Define PNG_BUILD_DLL if the module being built is a Windows * LIBPNG DLL. * * Define PNG_USE_DLL if you want to *link* to the Windows LIBPNG DLL. @@ -1188,6 +1372,42 @@ typedef char FAR * FAR * FAR * png_charppp; #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL)) # define PNG_DLL #endif +/* If CYGWIN, then disallow GLOBAL ARRAYS unless building a static lib. + * When building a static lib, default to no GLOBAL ARRAYS, but allow + * command-line override + */ +#ifdef __CYGWIN__ +# ifndef PNG_STATIC +# ifdef PNG_USE_GLOBAL_ARRAYS +# undef PNG_USE_GLOBAL_ARRAYS +# endif +# ifndef PNG_USE_LOCAL_ARRAYS +# define PNG_USE_LOCAL_ARRAYS +# endif +# else +# if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS) +# ifdef PNG_USE_GLOBAL_ARRAYS +# undef PNG_USE_GLOBAL_ARRAYS +# endif +# endif +# endif +# if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS) +# define PNG_USE_LOCAL_ARRAYS +# endif +#endif + +/* Do not use global arrays (helps with building DLL's) + * They are no longer used in libpng itself, since version 1.0.5c, + * but might be required for some pre-1.0.5c applications. + */ +#if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS) +# if defined(PNG_NO_GLOBAL_ARRAYS) || \ + (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER) +# define PNG_USE_LOCAL_ARRAYS +# else +# define PNG_USE_GLOBAL_ARRAYS +# endif +#endif #ifdef __CYGWIN__ # undef PNGAPI @@ -1196,8 +1416,6 @@ typedef char FAR * FAR * FAR * png_charppp; # define PNG_IMPEXP #endif -#define PNG_USE_LOCAL_ARRAYS /* Not used in libpng, defined for legacy apps */ - /* If you define PNGAPI, e.g., with compiler option "-DPNGAPI=__stdcall", * you may get warnings regarding the linkage of png_zalloc and png_zfree. * Don't ignore those warnings; you must also reset the default calling @@ -1234,40 +1452,41 @@ typedef char FAR * FAR * FAR * png_charppp; # ifndef PNG_IMPEXP -# define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol -# define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol - - /* Borland/Microsoft */ -# if defined(_MSC_VER) || defined(__BORLANDC__) -# if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500) -# define PNG_EXPORT PNG_EXPORT_TYPE1 -# else -# define PNG_EXPORT PNG_EXPORT_TYPE2 -# ifdef PNG_BUILD_DLL -# define PNG_IMPEXP __export -# else -# define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in VC++ */ -# endif /* Exists in Borland C++ for - C++ classes (== huge) */ -# endif -# endif +# define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol +# define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol + + /* Borland/Microsoft */ +# if defined(_MSC_VER) || defined(__BORLANDC__) +# if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500) +# define PNG_EXPORT PNG_EXPORT_TYPE1 +# else +# define PNG_EXPORT PNG_EXPORT_TYPE2 +# ifdef PNG_BUILD_DLL +# define PNG_IMPEXP __export +# else +# define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in + VC++ */ +# endif /* Exists in Borland C++ for + C++ classes (== huge) */ +# endif +# endif -# ifndef PNG_IMPEXP -# ifdef PNG_BUILD_DLL -# define PNG_IMPEXP __declspec(dllexport) -# else -# define PNG_IMPEXP __declspec(dllimport) -# endif -# endif +# ifndef PNG_IMPEXP +# ifdef PNG_BUILD_DLL +# define PNG_IMPEXP __declspec(dllexport) +# else +# define PNG_IMPEXP __declspec(dllimport) +# endif +# endif # endif /* PNG_IMPEXP */ #else /* !(DLL || non-cygwin WINDOWS) */ # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__) -# ifndef PNGAPI -# define PNGAPI _System -# endif +# ifndef PNGAPI +# define PNGAPI _System +# endif # else -# if 0 /* ... other platforms, with other meanings */ -# endif +# if 0 /* ... other platforms, with other meanings */ +# endif # endif #endif @@ -1282,122 +1501,79 @@ typedef char FAR * FAR * FAR * png_charppp; # ifndef PNG_EXPORT # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END # endif +# ifdef PNG_USE_GLOBAL_ARRAYS +# ifndef PNG_EXPORT_VAR +# define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT +# endif +# endif #endif #ifndef PNG_EXPORT # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol #endif -/* Users may want to use these so they are not private. Any library - * functions that are passed far data must be model-independent. +#ifdef PNG_USE_GLOBAL_ARRAYS +# ifndef PNG_EXPORT_VAR +# define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type +# endif +#endif + +/* User may want to use these so they are not in PNG_INTERNAL. Any library + * functions that are passed far data must be model independent. */ +#ifndef PNG_ABORT +# define PNG_ABORT() abort() +#endif + #ifdef PNG_SETJMP_SUPPORTED # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) #else # define png_jmpbuf(png_ptr) \ - (LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP) -#endif - -/* memory model/platform independent fns */ -#ifndef PNG_ABORT -# ifdef _WINDOWS_ -# define PNG_ABORT() ExitProcess(0) -# else -# define PNG_ABORT() abort() -# endif + (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED) #endif -#ifdef USE_FAR_KEYWORD +#ifdef USE_FAR_KEYWORD /* memory model independent fns */ /* use this to make far-to-near assignments */ # define CHECK 1 # define NOCHECK 0 # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK)) -# define png_strcpy _fstrcpy -# define png_strncpy _fstrncpy /* Added to v 1.2.6 */ +# define png_snprintf _fsnprintf /* Added to v 1.2.19 */ # define png_strlen _fstrlen # define png_memcmp _fmemcmp /* SJT: added */ # define png_memcpy _fmemcpy # define png_memset _fmemset -# define png_sprintf sprintf -#else -# ifdef _WINDOWS_ /* favor Windows over C runtime fns */ -# define CVT_PTR(ptr) (ptr) -# define CVT_PTR_NOCHECK(ptr) (ptr) -# define png_strcpy lstrcpyA -# define png_strncpy lstrcpynA -# define png_strlen lstrlenA -# define png_memcmp memcmp -# define png_memcpy CopyMemory -# define png_memset memset -# define png_sprintf wsprintfA -# else -# define CVT_PTR(ptr) (ptr) -# define CVT_PTR_NOCHECK(ptr) (ptr) -# define png_strcpy strcpy -# define png_strncpy strncpy /* Added to v 1.2.6 */ -# define png_strlen strlen -# define png_memcmp memcmp /* SJT: added */ -# define png_memcpy memcpy -# define png_memset memset -# define png_sprintf sprintf -# ifndef PNG_NO_SNPRINTF -# ifdef _MSC_VER -# define png_snprintf _snprintf /* Added to v 1.2.19 */ -# define png_snprintf2 _snprintf -# define png_snprintf6 _snprintf -# else -# define png_snprintf snprintf /* Added to v 1.2.19 */ -# define png_snprintf2 snprintf -# define png_snprintf6 snprintf -# endif +#else /* use the usual functions */ +# define CVT_PTR(ptr) (ptr) +# define CVT_PTR_NOCHECK(ptr) (ptr) +# ifndef PNG_NO_SNPRINTF +# ifdef _MSC_VER +# define png_snprintf _snprintf /* Added to v 1.2.19 */ +# define png_snprintf2 _snprintf +# define png_snprintf6 _snprintf # else - /* You don't have or don't want to use snprintf(). Caution: Using - * sprintf instead of snprintf exposes your application to accidental - * or malevolent buffer overflows. If you don't have snprintf() - * as a general rule you should provide one (you can get one from - * Portable OpenSSH). - */ -# define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1) -# define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2) -# define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \ - sprintf(s1,fmt,x1,x2,x3,x4,x5,x6) +# define png_snprintf snprintf /* Added to v 1.2.19 */ +# define png_snprintf2 snprintf +# define png_snprintf6 snprintf # endif -# endif -#endif - -/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, - * and no smaller than png_uint_32. Casts from png_size_t or png_uint_32 - * to png_alloc_size_t are not necessary; in fact, it is recommended - * not to use them at all so that the compiler can complain when something - * turns out to be problematic. - * Casts in the other direction (from png_alloc_size_t to png_size_t or - * png_uint_32) should be explicitly applied; however, we do not expect - * to encounter practical situations that require such conversions. - */ -#if defined(__TURBOC__) && !defined(__FLAT__) -# define png_mem_alloc farmalloc -# define png_mem_free farfree - typedef unsigned long png_alloc_size_t; -#else -# if defined(_MSC_VER) && defined(MAXSEG_64K) -# define png_mem_alloc(s) halloc(s, 1) -# define png_mem_free hfree - typedef unsigned long png_alloc_size_t; # else -# if defined(_WINDOWS_) && (!defined(INT_MAX) || INT_MAX <= 0x7ffffffeL) -# define png_mem_alloc(s) HeapAlloc(GetProcessHeap(), 0, s) -# define png_mem_free(p) HeapFree(GetProcessHeap(), 0, p) - typedef DWORD png_alloc_size_t; -# else -# define png_mem_alloc malloc -# define png_mem_free free - typedef png_size_t png_alloc_size_t; -# endif -# endif -#endif -/* End of memory model/platform independent support */ + /* You don't have or don't want to use snprintf(). Caution: Using + * sprintf instead of snprintf exposes your application to accidental + * or malevolent buffer overflows. If you don't have snprintf() + * as a general rule you should provide one (you can get one from + * Portable OpenSSH). */ +# define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1) +# define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2) +# define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \ + sprintf(s1,fmt,x1,x2,x3,x4,x5,x6) +# endif +# define png_strlen strlen +# define png_memcmp memcmp /* SJT: added */ +# define png_memcpy memcpy +# define png_memset memset +#endif +/* End of memory model independent support */ /* Just a little check that someone hasn't tried to define something * contradictory. @@ -1407,7 +1583,6 @@ typedef char FAR * FAR * FAR * png_charppp; # define PNG_ZBUF_SIZE 65536L #endif - /* Added at libpng-1.2.8 */ #endif /* PNG_VERSION_INFO_ONLY */ diff --git a/pngcrush.c b/pngcrush.c index f26ef0f7b..ce34b85c3 100644 --- a/pngcrush.c +++ b/pngcrush.c @@ -57,7 +57,7 @@ * */ -#define PNGCRUSH_VERSION "1.7.3" +#define PNGCRUSH_VERSION "1.7.5" /* #define PNGCRUSH_COUNT_COLORS @@ -160,7 +160,9 @@ Change log: -Version 1.7.4 (built with libpng-1.4.0rc01 and zlib-1.2.3.2) +Version 1.7.5 (built with libpng-1.2.41beta14 and zlib-1.2.3.2) + +Version 1.7.4 (built with libpng-1.2.40rc01 and zlib-1.2.3.2) Use unmodified pngconf.h from libpng-1.2.41beta05 or later. Version 1.7.3 (built with libpng-1.2.40 and zlib-1.2.3.2) @@ -5241,14 +5243,11 @@ int main(int argc, char *argv[]) png_textp text_ptr; int num_text = 0; -P1("whoopee.\n"); - if (png_get_text (read_ptr, end_info_ptr, &text_ptr, &num_text) > 0 || text_inputs) { int ntext; -P1("again.\n"); #ifdef PNG_iTXt_SUPPORTED P1( "Handling %d tEXt/zTXt/iTXt chunks after IDAT\n", diff --git a/pngcrush.h b/pngcrush.h index e33ded094..9f89e2cb3 100644 --- a/pngcrush.h +++ b/pngcrush.h @@ -15,6 +15,8 @@ #include <malloc.h> */ +#define PNG_NO_GLOBAL_ARRAYS + #ifndef PNG_NO_ZALLOC_ZERO # define PNG_NO_ZALLOC_ZERO /* speeds it up a little */ #endif diff --git a/pngerror.c b/pngerror.c index d19623346..993a3bcb6 100644 --- a/pngerror.c +++ b/pngerror.c @@ -1,7 +1,7 @@ /* pngerror.c - stub functions for i/o and memory allocation * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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.) @@ -16,9 +16,9 @@ * at each function. */ +#define PNG_INTERNAL #include "png.h" #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) -#include "pngpriv.h" static void /* PRIVATE */ png_default_error PNGARG((png_structp png_ptr, @@ -1,7 +1,7 @@ /* pngget.c - retrieval of values from info struct * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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.) @@ -12,9 +12,9 @@ * */ +#define PNG_INTERNAL #include "png.h" #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) -#include "pngpriv.h" png_uint_32 PNGAPI png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) @@ -26,7 +26,7 @@ png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) return(0); } -png_size_t PNGAPI +png_uint_32 PNGAPI png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) @@ -802,7 +802,7 @@ png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) #ifdef PNG_tRNS_SUPPORTED png_uint_32 PNGAPI png_get_tRNS(png_structp png_ptr, png_infop info_ptr, - png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color) + png_bytep *trans, int *num_trans, png_color_16p *trans_values) { png_uint_32 retval = 0; if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) @@ -811,25 +811,25 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr, if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { - if (trans_alpha != NULL) + if (trans != NULL) { - *trans_alpha = info_ptr->trans_alpha; + *trans = info_ptr->trans; retval |= PNG_INFO_tRNS; } - if (trans_color != NULL) - *trans_color = &(info_ptr->trans_color); + if (trans_values != NULL) + *trans_values = &(info_ptr->trans_values); } else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ { - if (trans_color != NULL) + if (trans_values != NULL) { - *trans_color = &(info_ptr->trans_color); + *trans_values = &(info_ptr->trans_values); retval |= PNG_INFO_tRNS; } - if (trans_alpha != NULL) - *trans_alpha = NULL; + if (trans != NULL) + *trans = NULL; } if (num_trans != NULL) { @@ -872,13 +872,60 @@ png_get_user_chunk_ptr(png_structp png_ptr) #endif #ifdef PNG_WRITE_SUPPORTED -png_size_t PNGAPI +png_uint_32 PNGAPI png_get_compression_buffer_size(png_structp png_ptr) { - return (png_ptr ? png_ptr->zbuf_size : 0L); + return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L); } #endif +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +#ifndef PNG_1_0_X +/* This function was added to libpng 1.2.0 and should exist by default */ +png_uint_32 PNGAPI +png_get_asm_flags (png_structp png_ptr) +{ + /* Obsolete, to be removed from libpng-1.4.0 */ + return (png_ptr? 0L: 0L); +} + +/* This function was added to libpng 1.2.0 and should exist by default */ +png_uint_32 PNGAPI +png_get_asm_flagmask (int flag_select) +{ + /* Obsolete, to be removed from libpng-1.4.0 */ + flag_select=flag_select; + return 0L; +} + + /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */ +/* This function was added to libpng 1.2.0 */ +png_uint_32 PNGAPI +png_get_mmx_flagmask (int flag_select, int *compilerID) +{ + /* Obsolete, to be removed from libpng-1.4.0 */ + flag_select=flag_select; + *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */ + return 0L; +} + +/* This function was added to libpng 1.2.0 */ +png_byte PNGAPI +png_get_mmx_bitdepth_threshold (png_structp png_ptr) +{ + /* Obsolete, to be removed from libpng-1.4.0 */ + return (png_ptr? 0: 0); +} + +/* This function was added to libpng 1.2.0 */ +png_uint_32 PNGAPI +png_get_mmx_rowbytes_threshold (png_structp png_ptr) +{ + /* Obsolete, to be removed from libpng-1.4.0 */ + return (png_ptr? 0L: 0L); +} +#endif /* ?PNG_1_0_X */ +#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ #ifdef PNG_SET_USER_LIMITS_SUPPORTED /* These functions were added to libpng 1.2.6 */ @@ -892,7 +939,7 @@ png_get_user_height_max (png_structp png_ptr) { return (png_ptr? png_ptr->user_height_max : 0); } -/* This function was added to libpng 1.4.0 */ +/* This function was added to libpng 1.2.41 */ png_uint_32 PNGAPI png_get_chunk_cache_max (png_structp png_ptr) { @@ -1,7 +1,7 @@ /* pngmem.c - stub functions for memory allocation * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.37 [June 4, 2009] * Copyright (c) 1998-2009 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.) @@ -17,9 +17,9 @@ * identify the replacement functions. */ +#define PNG_INTERNAL #include "png.h" #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) -#include "pngpriv.h" /* Borland DOS special memory handler */ #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) @@ -31,7 +31,7 @@ png_voidp /* PRIVATE */ png_create_struct(int type) { #ifdef PNG_USER_MEM_SUPPORTED - return (png_create_struct_2(type, NULL, NULL)); + return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL)); } /* Alternate version of png_create_struct, for use with user-defined malloc. */ @@ -70,7 +70,7 @@ void /* PRIVATE */ png_destroy_struct(png_voidp struct_ptr) { #ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2(struct_ptr, NULL, NULL); + png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL); } /* Free memory allocated by a png_create_struct() call */ @@ -115,7 +115,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, * (which should cause a fatal error) and introducing major problems. */ png_voidp PNGAPI -png_calloc(png_structp png_ptr, png_alloc_size_t size) +png_calloc(png_structp png_ptr, png_uint_32 size) { png_voidp ret; @@ -126,7 +126,7 @@ png_calloc(png_structp png_ptr, png_alloc_size_t size) } png_voidp PNGAPI -png_malloc(png_structp png_ptr, png_alloc_size_t size) +png_malloc(png_structp png_ptr, png_uint_32 size) { png_voidp ret; @@ -139,12 +139,12 @@ png_malloc(png_structp png_ptr, png_alloc_size_t size) else ret = (png_malloc_default(png_ptr, size)); if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of memory"); + png_error(png_ptr, "Out of memory!"); return (ret); } png_voidp PNGAPI -png_malloc_default(png_structp png_ptr, png_alloc_size_t size) +png_malloc_default(png_structp png_ptr, png_uint_32 size) { png_voidp ret; #endif /* PNG_USER_MEM_SUPPORTED */ @@ -200,9 +200,9 @@ png_malloc_default(png_structp png_ptr, png_alloc_size_t size) { #ifndef PNG_USER_MEM_SUPPORTED if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out Of Memory"); /* Note "O" and "M" */ + png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */ else - png_warning(png_ptr, "Out Of Memory"); + png_warning(png_ptr, "Out Of Memory."); #endif return (NULL); } @@ -228,9 +228,9 @@ png_malloc_default(png_structp png_ptr, png_alloc_size_t size) { #ifndef PNG_USER_MEM_SUPPORTED if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out Of memory"); /* Note "O" and "M" */ + png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */ else - png_warning(png_ptr, "Out Of memory"); + png_warning(png_ptr, "Out Of memory."); #endif return (NULL); } @@ -257,9 +257,9 @@ png_malloc_default(png_structp png_ptr, png_alloc_size_t size) { #ifndef PNG_USER_MEM_SUPPORTED if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of Memory"); /* Note "o" and "M" */ + png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */ else - png_warning(png_ptr, "Out of Memory"); + png_warning(png_ptr, "Out of Memory."); #endif return (NULL); } @@ -273,9 +273,9 @@ png_malloc_default(png_structp png_ptr, png_alloc_size_t size) if (ret == NULL) { if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of memory"); /* Note "o" and "m" */ + png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */ else - png_warning(png_ptr, "Out of memory"); /* Note "o" and "m" */ + png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */ } #endif @@ -347,7 +347,7 @@ png_voidp /* PRIVATE */ png_create_struct(int type) { #ifdef PNG_USER_MEM_SUPPORTED - return (png_create_struct_2(type, NULL, NULL)); + return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL)); } /* Allocate memory for a png_struct or a png_info. The malloc and @@ -401,7 +401,7 @@ void /* PRIVATE */ png_destroy_struct(png_voidp struct_ptr) { #ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2(struct_ptr, NULL, NULL); + png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL); } /* Free memory allocated by a png_create_struct() call */ @@ -442,7 +442,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, */ png_voidp PNGAPI -png_calloc(png_structp png_ptr, png_alloc_size_t size) +png_calloc(png_structp png_ptr, png_uint_32 size) { png_voidp ret; @@ -453,7 +453,7 @@ png_calloc(png_structp png_ptr, png_alloc_size_t size) } png_voidp PNGAPI -png_malloc(png_structp png_ptr, png_alloc_size_t size) +png_malloc(png_structp png_ptr, png_uint_32 size) { png_voidp ret; @@ -466,12 +466,12 @@ png_malloc(png_structp png_ptr, png_alloc_size_t size) else ret = (png_malloc_default(png_ptr, size)); if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of Memory"); + png_error(png_ptr, "Out of Memory!"); return (ret); } png_voidp PNGAPI -png_malloc_default(png_structp png_ptr, png_alloc_size_t size) +png_malloc_default(png_structp png_ptr, png_uint_32 size) { png_voidp ret; #endif /* PNG_USER_MEM_SUPPORTED */ @@ -558,13 +558,16 @@ png_free_default(png_structp png_ptr, png_voidp ptr) #endif /* Not Borland DOS special memory handler */ +#ifdef PNG_1_0_X +# define png_malloc_warn png_malloc +#else /* This function was added at libpng version 1.2.3. The png_malloc_warn() * function will set up png_malloc() to issue a png_warning and return NULL * instead of issuing a png_error, if it fails to allocate the requested * memory. */ png_voidp PNGAPI -png_malloc_warn(png_structp png_ptr, png_alloc_size_t size) +png_malloc_warn(png_structp png_ptr, png_uint_32 size) { png_voidp ptr; png_uint_32 save_flags; @@ -577,7 +580,34 @@ png_malloc_warn(png_structp png_ptr, png_alloc_size_t size) png_ptr->flags=save_flags; return(ptr); } +#endif + +png_voidp PNGAPI +png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2, + png_uint_32 length) +{ + png_size_t size; + + size = (png_size_t)length; + if ((png_uint_32)size != length) + png_error(png_ptr, "Overflow in png_memcpy_check."); + + return(png_memcpy (s1, s2, size)); +} + +png_voidp PNGAPI +png_memset_check (png_structp png_ptr, png_voidp s1, int value, + png_uint_32 length) +{ + png_size_t size; + + size = (png_size_t)length; + if ((png_uint_32)size != length) + png_error(png_ptr, "Overflow in png_memset_check."); + return (png_memset (s1, value, size)); + +} #ifdef PNG_USER_MEM_SUPPORTED /* This function is called when the application wants to use another method diff --git a/pngpread.c b/pngpread.c index 3ac38f139..239c04d8a 100644 --- a/pngpread.c +++ b/pngpread.c @@ -1,7 +1,7 @@ /* pngpread.c - read a png file in push mode * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.38 [July 16, 2009] * Copyright (c) 1998-2009 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,9 +11,9 @@ * and license in png.h */ +#define PNG_INTERNAL #include "png.h" #ifdef PNG_PROGRESSIVE_READ_SUPPORTED -#include "pngpriv.h" /* Push model modes */ #define PNG_READ_SIG_MODE 0 @@ -149,61 +149,63 @@ png_push_read_sig(png_structp png_ptr, png_infop info_ptr) void /* PRIVATE */ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) { - PNG_IHDR; - PNG_IDAT; - PNG_IEND; - PNG_PLTE; +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST PNG_IHDR; + PNG_CONST PNG_IDAT; + PNG_CONST PNG_IEND; + PNG_CONST PNG_PLTE; #ifdef PNG_READ_bKGD_SUPPORTED - PNG_bKGD; + PNG_CONST PNG_bKGD; #endif #ifdef PNG_READ_cHRM_SUPPORTED - PNG_cHRM; + PNG_CONST PNG_cHRM; #endif #ifdef PNG_READ_gAMA_SUPPORTED - PNG_gAMA; + PNG_CONST PNG_gAMA; #endif #ifdef PNG_READ_hIST_SUPPORTED - PNG_hIST; + PNG_CONST PNG_hIST; #endif #ifdef PNG_READ_iCCP_SUPPORTED - PNG_iCCP; + PNG_CONST PNG_iCCP; #endif #ifdef PNG_READ_iTXt_SUPPORTED - PNG_iTXt; + PNG_CONST PNG_iTXt; #endif #ifdef PNG_READ_oFFs_SUPPORTED - PNG_oFFs; + PNG_CONST PNG_oFFs; #endif #ifdef PNG_READ_pCAL_SUPPORTED - PNG_pCAL; + PNG_CONST PNG_pCAL; #endif #ifdef PNG_READ_pHYs_SUPPORTED - PNG_pHYs; + PNG_CONST PNG_pHYs; #endif #ifdef PNG_READ_sBIT_SUPPORTED - PNG_sBIT; + PNG_CONST PNG_sBIT; #endif #ifdef PNG_READ_sCAL_SUPPORTED - PNG_sCAL; + PNG_CONST PNG_sCAL; #endif #ifdef PNG_READ_sRGB_SUPPORTED - PNG_sRGB; + PNG_CONST PNG_sRGB; #endif #ifdef PNG_READ_sPLT_SUPPORTED - PNG_sPLT; + PNG_CONST PNG_sPLT; #endif #ifdef PNG_READ_tEXt_SUPPORTED - PNG_tEXt; + PNG_CONST PNG_tEXt; #endif #ifdef PNG_READ_tIME_SUPPORTED - PNG_tIME; + PNG_CONST PNG_tIME; #endif #ifdef PNG_READ_tRNS_SUPPORTED - PNG_tRNS; + PNG_CONST PNG_tRNS; #endif #ifdef PNG_READ_zTXt_SUPPORTED - PNG_zTXt; + PNG_CONST PNG_zTXt; #endif +#endif /* PNG_USE_LOCAL_ARRAYS */ /* First we make sure we have enough data for the 4 byte chunk name * and the 4 byte chunk length before proceeding with decoding the @@ -321,7 +323,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) return; if (png_ptr->mode & PNG_AFTER_IDAT) - png_benign_error(png_ptr, "Too many IDATs found"); + png_error(png_ptr, "Too many IDAT's found"); } png_ptr->idat_size = png_ptr->push_length; @@ -698,7 +700,7 @@ png_push_save_buffer(png_structp png_ptr) new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; old_buffer = png_ptr->save_buffer; png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr, - (png_size_t)new_max); + (png_uint_32)new_max); png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); png_free(png_ptr, old_buffer); png_ptr->save_buffer_max = new_max; @@ -727,7 +729,9 @@ png_push_restore_buffer(png_structp png_ptr, png_bytep buffer, void /* PRIVATE */ png_push_read_IDAT(png_structp png_ptr) { - PNG_IDAT; +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST PNG_IDAT; +#endif if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) { png_byte chunk_length[4]; @@ -824,7 +828,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, int ret; if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length) - png_benign_error(png_ptr, "Extra compression data"); + png_error(png_ptr, "Extra compression data"); png_ptr->zstream.next_in = buffer; png_ptr->zstream.avail_in = (uInt)buffer_length; @@ -836,7 +840,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, if (ret == Z_STREAM_END) { if (png_ptr->zstream.avail_in) - png_benign_error(png_ptr, "Extra compressed data"); + png_error(png_ptr, "Extra compressed data"); if (!(png_ptr->zstream.avail_out)) { @@ -893,7 +897,8 @@ png_push_process_row(png_structp png_ptr) png_ptr->row_buf + 1, png_ptr->prev_row + 1, (int)(png_ptr->row_buf[0])); - png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1); + png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, + png_ptr->rowbytes + 1); if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) png_do_read_transformations(png_ptr); @@ -924,7 +929,7 @@ png_push_process_row(png_structp png_ptr) { for (i = 0; i < 4 && png_ptr->pass == 2; i++) { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, png_bytep_NULL); png_read_push_finish_row(png_ptr); } } @@ -933,14 +938,14 @@ png_push_process_row(png_structp png_ptr) { for (i = 0; i < 2 && png_ptr->pass == 4; i++) { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, png_bytep_NULL); png_read_push_finish_row(png_ptr); } } if (png_ptr->pass == 6 && png_ptr->height <= 4) { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, png_bytep_NULL); png_read_push_finish_row(png_ptr); } @@ -960,7 +965,7 @@ png_push_process_row(png_structp png_ptr) { for (i = 0; i < 4 && png_ptr->pass == 2; i++) { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, png_bytep_NULL); png_read_push_finish_row(png_ptr); } } @@ -980,7 +985,7 @@ png_push_process_row(png_structp png_ptr) for (i = 0; i < 4 && png_ptr->pass == 2; i++) { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, png_bytep_NULL); png_read_push_finish_row(png_ptr); } @@ -988,7 +993,7 @@ png_push_process_row(png_structp png_ptr) { for (i = 0; i < 2 && png_ptr->pass == 4; i++) { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, png_bytep_NULL); png_read_push_finish_row(png_ptr); } } @@ -1010,7 +1015,7 @@ png_push_process_row(png_structp png_ptr) { for (i = 0; i < 2 && png_ptr->pass == 4; i++) { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, png_bytep_NULL); png_read_push_finish_row(png_ptr); } } @@ -1030,13 +1035,13 @@ png_push_process_row(png_structp png_ptr) for (i = 0; i < 2 && png_ptr->pass == 4; i++) { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, png_bytep_NULL); png_read_push_finish_row(png_ptr); } if (png_ptr->pass == 6) /* Pass 5 might be empty */ { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, png_bytep_NULL); png_read_push_finish_row(png_ptr); } @@ -1055,7 +1060,7 @@ png_push_process_row(png_structp png_ptr) if (png_ptr->pass == 6) /* Skip top generated row */ { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, png_bytep_NULL); png_read_push_finish_row(png_ptr); } @@ -1069,7 +1074,7 @@ png_push_process_row(png_structp png_ptr) if (png_ptr->pass != 6) break; - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, png_bytep_NULL); png_read_push_finish_row(png_ptr); } } @@ -1085,6 +1090,7 @@ png_push_process_row(png_structp png_ptr) void /* PRIVATE */ png_read_push_finish_row(png_structp png_ptr) { +#ifdef PNG_USE_LOCAL_ARRAYS /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Start of interlace block */ @@ -1103,6 +1109,7 @@ png_read_push_finish_row(png_structp png_ptr) * it, uncomment it here and in png.h PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; */ +#endif png_ptr->row_number++; if (png_ptr->row_number < png_ptr->num_rows) @@ -1112,7 +1119,7 @@ png_read_push_finish_row(png_structp png_ptr) if (png_ptr->interlaced) { png_ptr->row_number = 0; - png_memset(png_ptr->prev_row, 0, + png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1); do { @@ -1172,7 +1179,7 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 #endif png_ptr->current_text = (png_charp)png_malloc(png_ptr, - (png_size_t)(length + 1)); + (png_uint_32)(length + 1)); png_ptr->current_text[length] = '\0'; png_ptr->current_text_ptr = png_ptr->current_text; png_ptr->current_text_size = (png_size_t)length; @@ -1226,7 +1233,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) text++; text_ptr = (png_textp)png_malloc(png_ptr, - png_sizeof(png_text)); + (png_uint_32)png_sizeof(png_text)); text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; text_ptr->key = key; #ifdef PNG_iTXt_SUPPORTED @@ -1242,7 +1249,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) png_ptr->current_text = NULL; if (ret) - png_warning(png_ptr, "Insufficient memory to store text chunk"); + png_warning(png_ptr, "Insufficient memory to store text chunk."); } } #endif @@ -1272,7 +1279,7 @@ png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 #endif png_ptr->current_text = (png_charp)png_malloc(png_ptr, - (png_size_t)(length + 1)); + (png_uint_32)(length + 1)); png_ptr->current_text[length] = '\0'; png_ptr->current_text_ptr = png_ptr->current_text; png_ptr->current_text_size = (png_size_t)length; @@ -1365,7 +1372,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) if (text == NULL) { text = (png_charp)png_malloc(png_ptr, - (png_ptr->zbuf_size + (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out + key_size + 1)); png_memcpy(text + key_size, png_ptr->zbuf, @@ -1384,7 +1391,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) tmp = text; text = (png_charp)png_malloc(png_ptr, text_size + - (png_ptr->zbuf_size + (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1)); png_memcpy(text, tmp, text_size); @@ -1428,7 +1435,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) text += key_size; text_ptr = (png_textp)png_malloc(png_ptr, - png_sizeof(png_text)); + (png_uint_32)png_sizeof(png_text)); text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt; text_ptr->key = key; #ifdef PNG_iTXt_SUPPORTED @@ -1443,7 +1450,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) png_free(png_ptr, text_ptr); if (ret) - png_warning(png_ptr, "Insufficient memory to store text chunk"); + png_warning(png_ptr, "Insufficient memory to store text chunk."); } } #endif @@ -1471,7 +1478,7 @@ png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 #endif png_ptr->current_text = (png_charp)png_malloc(png_ptr, - (png_size_t)(length + 1)); + (png_uint_32)(length + 1)); png_ptr->current_text[length] = '\0'; png_ptr->current_text_ptr = png_ptr->current_text; png_ptr->current_text_size = (png_size_t)length; @@ -1548,7 +1555,7 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr) text++; text_ptr = (png_textp)png_malloc(png_ptr, - png_sizeof(png_text)); + (png_uint_32)png_sizeof(png_text)); text_ptr->compression = comp_flag + 2; text_ptr->key = key; @@ -1564,7 +1571,7 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr) png_free(png_ptr, text_ptr); if (ret) - png_warning(png_ptr, "Insufficient memory to store iTXt chunk"); + png_warning(png_ptr, "Insufficient memory to store iTXt chunk."); } } #endif @@ -1619,7 +1626,7 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 else { png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, - (png_size_t)length); + (png_uint_32)length); png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); } @@ -1684,8 +1691,10 @@ void PNGAPI png_progressive_combine_row (png_structp png_ptr, png_bytep old_row, png_bytep new_row) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_CONST int FARDATA png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; +#endif if (png_ptr == NULL) return; @@ -1,841 +1,12 @@ /* pngpriv.h - private declarations for use inside libpng * - * libpng version 1.4.0rc01 - October 21, 2009 + * libpng version 1.2.41beta14 - November 3, 2009 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2009 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.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - */ - -/* The symbols declared in this file (including the functions declared - * as PNG_EXTERN) are PRIVATE. They are not part of the libpng public - * interface, and are not recommended for use by regular applications. - * Some of them may become public in the future; others may stay private, - * change in an incompatible way, or even disappear. - * Although the libpng users are not forbidden to include this header, - * they should be well aware of the issues that may arise from doing so. - */ - -#ifndef PNGPRIV_H -#define PNGPRIV_H - -#ifndef PNG_VERSION_INFO_ONLY - -#include <stdlib.h> - -/* The functions exported by PNG_EXTERN are internal functions, which - * aren't usually used outside the library (as far as I know), so it is - * debatable if they should be exported at all. In the future, when it - * is possible to have run-time registry of chunk-handling functions, - * some of these will be made available again. -#define PNG_EXTERN extern - */ -#define PNG_EXTERN - -/* Other defines specific to compilers can go here. Try to keep - * them inside an appropriate ifdef/endif pair for portability. - */ - -#ifdef PNG_FLOATING_POINT_SUPPORTED -# ifdef MACOS - /* We need to check that <math.h> hasn't already been included earlier - * as it seems it doesn't agree with <fp.h>, yet we should really use - * <fp.h> if possible. - */ -# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) -# include <fp.h> -# endif -# else -# include <math.h> -# endif -# if defined(_AMIGA) && defined(__SASC) && defined(_M68881) - /* Amiga SAS/C: We must include builtin FPU functions when compiling using - * MATH=68881 - */ -# include <m68881.h> -# endif -#endif - -/* Codewarrior on NT has linking problems without this. */ -#if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__) -# define PNG_ALWAYS_EXTERN -#endif - -/* This provides the non-ANSI (far) memory allocation routines. */ -#if defined(__TURBOC__) && defined(__MSDOS__) -# include <mem.h> -# include <alloc.h> -#endif - -#if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \ - defined(_WIN32) || defined(__WIN32__) -# include <windows.h> /* defines _WINDOWS_ macro */ -/* I have no idea why is this necessary... */ -# ifdef _MSC_VER -# include <malloc.h> -# endif -#endif - -/* Various modes of operation. Note that after an init, mode is set to - * zero automatically when the structure is created. - */ -#define PNG_HAVE_IHDR 0x01 -#define PNG_HAVE_PLTE 0x02 -#define PNG_HAVE_IDAT 0x04 -#define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */ -#define PNG_HAVE_IEND 0x10 -#define PNG_HAVE_gAMA 0x20 -#define PNG_HAVE_cHRM 0x40 -#define PNG_HAVE_sRGB 0x80 -#define PNG_HAVE_CHUNK_HEADER 0x100 -#define PNG_WROTE_tIME 0x200 -#define PNG_WROTE_INFO_BEFORE_PLTE 0x400 -#define PNG_BACKGROUND_IS_GRAY 0x800 -#define PNG_HAVE_PNG_SIGNATURE 0x1000 -#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */ - -/* Flags for the transformations the PNG library does on the image data */ -#define PNG_BGR 0x0001 -#define PNG_INTERLACE 0x0002 -#define PNG_PACK 0x0004 -#define PNG_SHIFT 0x0008 -#define PNG_SWAP_BYTES 0x0010 -#define PNG_INVERT_MONO 0x0020 -#define PNG_DITHER 0x0040 -#define PNG_BACKGROUND 0x0080 -#define PNG_BACKGROUND_EXPAND 0x0100 - /* 0x0200 unused */ -#define PNG_16_TO_8 0x0400 -#define PNG_RGBA 0x0800 -#define PNG_EXPAND 0x1000 -#define PNG_GAMMA 0x2000 -#define PNG_GRAY_TO_RGB 0x4000 -#define PNG_FILLER 0x8000L -#define PNG_PACKSWAP 0x10000L -#define PNG_SWAP_ALPHA 0x20000L -#define PNG_STRIP_ALPHA 0x40000L -#define PNG_INVERT_ALPHA 0x80000L -#define PNG_USER_TRANSFORM 0x100000L -#define PNG_RGB_TO_GRAY_ERR 0x200000L -#define PNG_RGB_TO_GRAY_WARN 0x400000L -#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */ - /* 0x800000L Unused */ -#define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */ -#define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */ -#define PNG_PREMULTIPLY_ALPHA 0x4000000L /* Added to libpng-1.4.0 */ - /* by volker */ - /* 0x8000000L unused */ - /* 0x10000000L unused */ - /* 0x20000000L unused */ - /* 0x40000000L unused */ - -/* Flags for png_create_struct */ -#define PNG_STRUCT_PNG 0x0001 -#define PNG_STRUCT_INFO 0x0002 - -/* Scaling factor for filter heuristic weighting calculations */ -#define PNG_WEIGHT_SHIFT 8 -#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT)) -#define PNG_COST_SHIFT 3 -#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT)) - -/* Flags for the png_ptr->flags rather than declaring a byte for each one */ -#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001 -#define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002 -#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004 -#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008 -#define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010 -#define PNG_FLAG_ZLIB_FINISHED 0x0020 -#define PNG_FLAG_ROW_INIT 0x0040 -#define PNG_FLAG_FILLER_AFTER 0x0080 -#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100 -#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200 -#define PNG_FLAG_CRC_CRITICAL_USE 0x0400 -#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800 - /* 0x1000 unused */ - /* 0x2000 unused */ - /* 0x4000 unused */ -#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L -#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L -#define PNG_FLAG_LIBRARY_MISMATCH 0x20000L -#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L -#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L -#define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L -#define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */ -#define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */ -#define PNG_FLAG_BENIGN_ERRORS_WARN 0x800000L /* Added to libpng-1.4.0 */ - /* 0x1000000L unused */ - /* 0x2000000L unused */ - /* 0x4000000L unused */ - /* 0x8000000L unused */ - /* 0x10000000L unused */ - /* 0x20000000L unused */ - /* 0x40000000L unused */ - -#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ - PNG_FLAG_CRC_ANCILLARY_NOWARN) - -#define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \ - PNG_FLAG_CRC_CRITICAL_IGNORE) - -#define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \ - PNG_FLAG_CRC_CRITICAL_MASK) - -/* Save typing and make code easier to understand */ - -#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \ - abs((int)((c1).green) - (int)((c2).green)) + \ - abs((int)((c1).blue) - (int)((c2).blue))) - -/* Added to libpng-1.2.6 JB */ -#define PNG_ROWBYTES(pixel_bits, width) \ - ((pixel_bits) >= 8 ? \ - ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \ - (( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) ) - -/* PNG_OUT_OF_RANGE returns true if value is outside the range - * ideal-delta..ideal+delta. Each argument is evaluated twice. - * "ideal" and "delta" should be constants, normally simple - * integers, "value" a variable. Added to libpng-1.2.6 JB - */ -#define PNG_OUT_OF_RANGE(value, ideal, delta) \ - ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) ) - -/* Constant strings for known chunk types. If you need to add a chunk, - * define the name here, and add an invocation of the macro wherever it's - * needed. - */ -#define PNG_IHDR PNG_CONST png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'} -#define PNG_IDAT PNG_CONST png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'} -#define PNG_IEND PNG_CONST png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'} -#define PNG_PLTE PNG_CONST png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'} -#define PNG_bKGD PNG_CONST png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'} -#define PNG_cHRM PNG_CONST png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'} -#define PNG_gAMA PNG_CONST png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'} -#define PNG_hIST PNG_CONST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'} -#define PNG_iCCP PNG_CONST png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'} -#define PNG_iTXt PNG_CONST png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'} -#define PNG_oFFs PNG_CONST png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'} -#define PNG_pCAL PNG_CONST png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'} -#define PNG_sCAL PNG_CONST png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'} -#define PNG_pHYs PNG_CONST png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'} -#define PNG_sBIT PNG_CONST png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'} -#define PNG_sPLT PNG_CONST png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'} -#define PNG_sRGB PNG_CONST png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'} -#define PNG_sTER PNG_CONST png_byte png_sTER[5] = {115, 84, 69, 82, '\0'} -#define PNG_tEXt PNG_CONST png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'} -#define PNG_tIME PNG_CONST png_byte png_tIME[5] = {116, 73, 77, 69, '\0'} -#define PNG_tRNS PNG_CONST png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'} -#define PNG_zTXt PNG_CONST png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'} - - -/* Inhibit C++ name-mangling for libpng functions but not for system calls. */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* These functions are used internally in the code. They generally - * shouldn't be used unless you are writing code to add or replace some - * functionality in libpng. More information about most functions can - * be found in the files where the functions are located. - */ - -/* Allocate memory for an internal libpng struct */ -PNG_EXTERN png_voidp png_create_struct PNGARG((int type)); - -/* Free memory from internal libpng struct */ -PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr)); - -PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr - malloc_fn, png_voidp mem_ptr)); -PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr, - png_free_ptr free_fn, png_voidp mem_ptr)); - -/* Free any memory that info_ptr points to and reset struct. */ -PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, - png_infop info_ptr)); - -/* Function to allocate memory for zlib. PNGAPI is disallowed. */ -PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size)); - -/* Function to free memory for zlib. PNGAPI is disallowed. */ -PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr)); - -/* Next four functions are used internally as callbacks. PNGAPI is required - * but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3. */ - -PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr, - png_bytep data, png_size_t length)); - -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr, - png_bytep buffer, png_size_t length)); -#endif - -PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr, - png_bytep data, png_size_t length)); - -#ifdef PNG_WRITE_FLUSH_SUPPORTED -#ifdef PNG_STDIO_SUPPORTED -PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr)); -#endif -#endif - -/* Reset the CRC variable */ -PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr)); - -/* Write the "data" buffer to whatever output you are using */ -PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data, - png_size_t length)); - -/* Read the chunk header (length + type name) */ -PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr)); - -/* Read data from whatever input you are using into the "data" buffer */ -PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data, - png_size_t length)); - -/* Read bytes into buf, and update png_ptr->crc */ -PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf, - png_size_t length)); - -/* Decompress data in a chunk that uses compression */ -#if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \ - defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) -PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr, - int comp_type, png_size_t chunklength, png_size_t prefix_length, - png_size_t *data_length)); -#endif - -/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */ -PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip)); - -/* Read the CRC from the file and compare it to the libpng calculated CRC */ -PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr)); - -/* Calculate the CRC over a section of data. Note that we are only - * passing a maximum of 64K on systems that have this as a memory limit, - * since this is the maximum buffer size we can specify. - */ -PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr, - png_size_t length)); - -#ifdef PNG_WRITE_FLUSH_SUPPORTED -PNG_EXTERN void png_flush PNGARG((png_structp png_ptr)); -#endif - -/* Write various chunks */ - -/* Write the IHDR chunk, and update the png_struct with the necessary - * information. - */ -PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width, - png_uint_32 height, - int bit_depth, int color_type, int compression_method, int filter_method, - int interlace_method)); - -PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette, - png_uint_32 num_pal)); - -PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data, - png_size_t length)); - -PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr)); - -#ifdef PNG_WRITE_gAMA_SUPPORTED -#ifdef PNG_FLOATING_POINT_SUPPORTED -PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma)); -#endif -#ifdef PNG_FIXED_POINT_SUPPORTED -PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point - file_gamma)); -#endif -#endif - -#ifdef PNG_WRITE_sBIT_SUPPORTED -PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit, - int color_type)); -#endif - -#ifdef PNG_WRITE_cHRM_SUPPORTED -#ifdef PNG_FLOATING_POINT_SUPPORTED -PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_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)); -#endif -PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_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 - -#ifdef PNG_WRITE_sRGB_SUPPORTED -PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr, - int intent)); -#endif - -#ifdef PNG_WRITE_iCCP_SUPPORTED -PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr, - png_charp name, int compression_type, - png_charp profile, int proflen)); - /* Note to maintainer: profile should be png_bytep */ -#endif - -#ifdef PNG_WRITE_sPLT_SUPPORTED -PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr, - png_sPLT_tp palette)); -#endif - -#ifdef PNG_WRITE_tRNS_SUPPORTED -PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans, - png_color_16p values, int number, int color_type)); -#endif - -#ifdef PNG_WRITE_bKGD_SUPPORTED -PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr, - png_color_16p values, int color_type)); -#endif - -#ifdef PNG_WRITE_hIST_SUPPORTED -PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist, - int num_hist)); -#endif - -#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ - defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) -PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr, - png_charp key, png_charpp new_key)); -#endif - -#ifdef PNG_WRITE_tEXt_SUPPORTED -PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key, - png_charp text, png_size_t text_len)); -#endif - -#ifdef PNG_WRITE_zTXt_SUPPORTED -PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key, - png_charp text, png_size_t text_len, int compression)); -#endif - -#ifdef PNG_WRITE_iTXt_SUPPORTED -PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr, - int compression, png_charp key, png_charp lang, png_charp lang_key, - png_charp text)); -#endif - -#ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */ -PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr, - png_infop info_ptr, png_textp text_ptr, int num_text)); -#endif - -#ifdef PNG_WRITE_oFFs_SUPPORTED -PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr, - png_int_32 x_offset, png_int_32 y_offset, int unit_type)); -#endif - -#ifdef PNG_WRITE_pCAL_SUPPORTED -PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_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_WRITE_pHYs_SUPPORTED -PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr, - png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, - int unit_type)); -#endif - -#ifdef PNG_WRITE_tIME_SUPPORTED -PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr, - png_timep mod_time)); -#endif - -#ifdef PNG_WRITE_sCAL_SUPPORTED -#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) -PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr, - int unit, double width, double height)); -#else -#ifdef PNG_FIXED_POINT_SUPPORTED -PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr, - int unit, png_charp width, png_charp height)); -#endif -#endif -#endif - -/* Called when finished processing a row of data */ -PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr)); - -/* Internal use only. Called before first row of data */ -PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr)); - -#ifdef PNG_READ_GAMMA_SUPPORTED -PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr)); -#endif - -/* Combine a row of data, dealing with alpha, etc. if requested */ -PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row, - int mask)); - -#ifdef PNG_READ_INTERLACING_SUPPORTED -/* Expand an interlaced row */ -/* OLD pre-1.0.9 interface: -PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info, - png_bytep row, int pass, png_uint_32 transformations)); - */ -PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr)); -#endif - -/* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */ - -#ifdef PNG_WRITE_INTERLACING_SUPPORTED -/* Grab pixels out of a row for an interlaced pass */ -PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info, - png_bytep row, int pass)); -#endif - -/* Unfilter a row */ -PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr, - png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter)); - -/* Choose the best filter to use and filter the row data */ -PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr, - png_row_infop row_info)); - -/* Write out the filtered row. */ -PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr, - png_bytep filtered_row)); -/* Finish a row while reading, dealing with interlacing passes, etc. */ -PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr)); - -/* Initialize the row buffers, etc. */ -PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr)); -/* Optional call to update the users info structure */ -PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr, - png_infop info_ptr)); - -/* These are the functions that do the transformations */ -#ifdef PNG_READ_FILLER_SUPPORTED -PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info, - png_bytep row, png_uint_32 filler, png_uint_32 flags)); -#endif - -#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED -PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED -PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED -PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED -PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ - defined(PNG_READ_STRIP_ALPHA_SUPPORTED) -PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info, - png_bytep row, png_uint_32 flags)); -#endif - -#ifdef PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED -PNG_EXTERN void png_do_read_premultiply_alpha - PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) -PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED) -PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED -PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop - row_info, png_bytep row)); -#endif - -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED -PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_PACK_SUPPORTED -PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#ifdef PNG_READ_SHIFT_SUPPORTED -PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row, - png_color_8p sig_bits)); -#endif - -#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) -PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#ifdef PNG_READ_16_TO_8_SUPPORTED -PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#ifdef PNG_READ_DITHER_SUPPORTED -PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info, - png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup)); - -# ifdef PNG_CORRECT_PALETTE_SUPPORTED -PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr, - png_colorp palette, int num_palette)); -# endif -#endif - -#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) -PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#ifdef PNG_WRITE_PACK_SUPPORTED -PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info, - png_bytep row, png_uint_32 bit_depth)); -#endif - -#ifdef PNG_WRITE_SHIFT_SUPPORTED -PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row, - png_color_8p bit_depth)); -#endif - -#ifdef PNG_READ_BACKGROUND_SUPPORTED -#ifdef PNG_READ_GAMMA_SUPPORTED -PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row, - png_color_16p trans_color, png_color_16p background, - png_color_16p background_1, - png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, - png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1, - png_uint_16pp gamma_16_to_1, int gamma_shift)); -#else -PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row, - png_color_16p trans_color, png_color_16p background)); -#endif -#endif - -#ifdef PNG_READ_GAMMA_SUPPORTED -PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row, - png_bytep gamma_table, png_uint_16pp gamma_16_table, - int gamma_shift)); -#endif - -#ifdef PNG_READ_EXPAND_SUPPORTED -PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info, - png_bytep row, png_colorp palette, png_bytep trans, int num_trans)); -PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info, - png_bytep row, png_color_16p trans_value)); -#endif - -/* The following decodes the appropriate chunks, and does error correction, - * then calls the appropriate callback for the chunk if it is valid. */ -/* Decode the IHDR chunk */ -PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); - -#ifdef PNG_READ_bKGD_SUPPORTED -PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_cHRM_SUPPORTED -PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_gAMA_SUPPORTED -PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_hIST_SUPPORTED -PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_iCCP_SUPPORTED -extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif /* PNG_READ_iCCP_SUPPORTED */ - -#ifdef PNG_READ_iTXt_SUPPORTED -PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_oFFs_SUPPORTED -PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_pCAL_SUPPORTED -PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_pHYs_SUPPORTED -PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_sBIT_SUPPORTED -PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_sCAL_SUPPORTED -PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_sPLT_SUPPORTED -extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif /* PNG_READ_sPLT_SUPPORTED */ - -#ifdef PNG_READ_sRGB_SUPPORTED -PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_tEXt_SUPPORTED -PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_tIME_SUPPORTED -PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_tRNS_SUPPORTED -PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_zTXt_SUPPORTED -PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); - -PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr, - png_bytep chunk_name)); - -/* Handle the transformations for reading and writing */ -PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr)); - -PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr)); - -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr, - png_uint_32 length)); -PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr, - png_bytep buffer, png_size_t buffer_length)); -PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr, - png_bytep buffer, png_size_t buffer_length)); -PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row)); -PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr)); -#ifdef PNG_READ_tEXt_SUPPORTED -PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr, - png_infop info_ptr)); -#endif -#ifdef PNG_READ_zTXt_SUPPORTED -PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr, - png_infop info_ptr)); -#endif -#ifdef PNG_READ_iTXt_SUPPORTED -PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr, - png_infop info_ptr)); -#endif - -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ - -#ifdef PNG_MNG_FEATURES_SUPPORTED -PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info, - png_bytep row)); -PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -/* Added at libpng version 1.4.0 */ -#ifdef PNG_cHRM_SUPPORTED -PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_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 - -#ifdef PNG_cHRM_SUPPORTED -#ifdef PNG_CHECK_cHRM_SUPPORTED -/* Added at libpng version 1.2.34 and 1.4.0 */ -PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2, - unsigned long *hi_product, unsigned long *lo_product)); -#endif -#endif - -/* Added at libpng version 1.4.0 */ -PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr, - png_uint_32 width, png_uint_32 height, int bit_depth, - int color_type, int interlace_type, int compression_type, - int filter_type)); - -/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ - -#ifdef __cplusplus -} -#endif - -#endif /* PNG_VERSION_INFO_ONLY */ -#endif /* PNGPRIV_H */ +/* This is a placeholder for a header file that is introduced in + * libpng-1.4.0 */ @@ -1,7 +1,7 @@ /* pngread.c - read a PNG file * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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.) @@ -14,9 +14,9 @@ * read a PNG file or stream. */ +#define PNG_INTERNAL #include "png.h" #ifdef PNG_READ_SUPPORTED -#include "pngpriv.h" /* Create a PNG structure for reading, and allocate any memory needed. */ @@ -27,7 +27,7 @@ png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, #ifdef PNG_USER_MEM_SUPPORTED return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn, - warn_fn, NULL, NULL, NULL)); + warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); } /* Alternate create PNG structure for reading, and allocate any memory needed. */ @@ -42,7 +42,6 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, volatile #endif png_structp png_ptr; - int png_cleanup_needed = 0; #ifdef PNG_SETJMP_SUPPORTED #ifdef USE_FAR_KEYWORD @@ -56,7 +55,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, #ifdef PNG_USER_MEM_SUPPORTED png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, - malloc_fn, mem_ptr); + (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); #else png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); #endif @@ -65,20 +64,32 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, /* Added at libpng-1.2.6 */ #ifdef PNG_SET_USER_LIMITS_SUPPORTED - png_ptr->user_width_max=PNG_USER_WIDTH_MAX; - png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; + png_ptr->user_width_max = PNG_USER_WIDTH_MAX; + png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; + /* Added at libpng-1.2.41 */ + png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; #endif #ifdef PNG_SETJMP_SUPPORTED -/* Applications that neglect to set up their own setjmp() and then - encounter a png_error() will longjmp here. Since the jmpbuf is - then meaningless we abort instead of returning. */ #ifdef USE_FAR_KEYWORD if (setjmp(jmpbuf)) #else if (setjmp(png_ptr->jmpbuf)) #endif - PNG_ABORT(); + { + png_free(png_ptr, png_ptr->zbuf); + png_ptr->zbuf = NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, + (png_free_ptr)free_fn, (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + return (NULL); + } +#ifdef USE_FAR_KEYWORD + png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); +#endif #endif /* PNG_SETJMP_SUPPORTED */ #ifdef PNG_USER_MEM_SUPPORTED @@ -107,6 +118,10 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, * For versions after libpng 1.0, we will be compatible, so we need * only check the first digit. */ +#ifdef PNG_iTXt_SUPPORTED + png_size_t length; +#endif + if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || (user_png_ver[0] == '0' && user_png_ver[2] < '9')) @@ -128,64 +143,216 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, #ifdef PNG_ERROR_NUMBERS_SUPPORTED png_ptr->flags = 0; #endif - png_warning(png_ptr, + png_error(png_ptr, "Incompatible libpng version in application and library"); - - png_cleanup_needed = 1; } + +#ifdef PNG_iTXt_SUPPORTED + /* Any library mismatch is trouble for png_set_read() in + * libpng-1.2.41 and later 1.2.x, so we store the caller's + * library version string. + */ + + length = (png_size_t)png_strlen(user_png_ver) + 1; + png_debug1(3, "allocating user_png_ver for png_ptr (%lu bytes)", + (unsigned long)length); + png_ptr->user_png_ver = (png_charp)png_malloc_warn(png_ptr, + (png_uint_32)length); + + if (png_ptr->user_png_ver == NULL) + png_warning(png_ptr, "Could not store png_ptr->user_png_ver"); + + else + png_memcpy(png_ptr->user_png_ver, user_png_ver, length); + +#endif /* PNG_iTXt_SUPPORTED */ } - if (!png_cleanup_needed) - { /* Initialize zbuf - compression buffer */ png_ptr->zbuf_size = PNG_ZBUF_SIZE; - png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, - png_ptr->zbuf_size); - if (png_ptr->zbuf == NULL) - png_cleanup_needed = 1; - } + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); png_ptr->zstream.zalloc = png_zalloc; png_ptr->zstream.zfree = png_zfree; png_ptr->zstream.opaque = (voidpf)png_ptr; - if (!png_cleanup_needed) - { switch (inflateInit(&png_ptr->zstream)) { case Z_OK: /* Do nothing */ break; case Z_MEM_ERROR: - case Z_STREAM_ERROR: png_warning(png_ptr, "zlib memory error"); - png_cleanup_needed = 1; break; - case Z_VERSION_ERROR: png_warning(png_ptr, "zlib version error"); - png_cleanup_needed = 1; break; - default: png_warning(png_ptr, "Unknown zlib error"); - png_cleanup_needed = 1; + case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); + break; + case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); + break; + default: png_error(png_ptr, "Unknown zlib error"); } + + + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + + png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL); + +#ifdef PNG_SETJMP_SUPPORTED +/* Applications that neglect to set up their own setjmp() and then + encounter a png_error() will longjmp here. Since the jmpbuf is + then meaningless we abort instead of returning. */ +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) + PNG_ABORT(); + png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); +#else + if (setjmp(png_ptr->jmpbuf)) + PNG_ABORT(); +#endif +#endif /* PNG_SETJMP_SUPPORTED */ + + return (png_ptr); +} + +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* Initialize PNG structure for reading, and allocate any memory needed. + * This interface is deprecated in favour of the png_create_read_struct(), + * and it will disappear as of libpng-1.3.0. + */ +#undef png_read_init +void PNGAPI +png_read_init(png_structp png_ptr) +{ + /* We only come here via pre-1.0.7-compiled applications */ + png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0); +} + +void PNGAPI +png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size, png_size_t png_info_size) +{ + /* We only come here via pre-1.0.12-compiled applications */ + if (png_ptr == NULL) + return; +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) + if (png_sizeof(png_struct) > png_struct_size || + png_sizeof(png_info) > png_info_size) + { + char msg[80]; + png_ptr->warning_fn = NULL; + if (user_png_ver) + { + png_snprintf(msg, 80, + "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + png_snprintf(msg, 80, + "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); + } +#endif + if (png_sizeof(png_struct) > png_struct_size) + { + png_ptr->error_fn = NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags = 0; +#endif + png_error(png_ptr, + "The png struct allocated by the application for reading is too small."); } + if (png_sizeof(png_info) > png_info_size) + { + png_ptr->error_fn = NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags = 0; +#endif + png_error(png_ptr, + "The info struct allocated by application for reading is too small."); + } + png_read_init_3(&png_ptr, user_png_ver, png_struct_size); +} +#endif /* PNG_1_0_X || PNG_1_2_X */ + +void PNGAPI +png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size) +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf tmp_jmp; /* to save current jump buffer */ +#endif + + int i = 0; + + png_structp png_ptr=*ptr_ptr; - if (png_cleanup_needed) + if (png_ptr == NULL) + return; + + do { - /* Clean up PNG structure and deallocate any memory. */ - png_free(png_ptr, png_ptr->zbuf); - png_ptr->zbuf = NULL; -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)png_ptr, - (png_free_ptr)free_fn, (png_voidp)mem_ptr); + if (user_png_ver[i] != png_libpng_ver[i]) + { +#ifdef PNG_LEGACY_SUPPORTED + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; #else - png_destroy_struct((png_voidp)png_ptr); + png_ptr->warning_fn = NULL; + png_warning(png_ptr, + "Application uses deprecated png_read_init() and should be recompiled."); + break; #endif - return (NULL); + } + } while (png_libpng_ver[i++]); + + png_debug(1, "in png_read_init_3"); + +#ifdef PNG_SETJMP_SUPPORTED + /* Save jump buffer and error functions */ + png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); +#endif + + if (png_sizeof(png_struct) > png_struct_size) + { + png_destroy_struct(png_ptr); + *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); + png_ptr = *ptr_ptr; } - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + /* Reset all variables to 0 */ + png_memset(png_ptr, 0, png_sizeof(png_struct)); + +#ifdef PNG_SETJMP_SUPPORTED + /* Restore jump buffer */ + png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); +#endif - png_set_read_fn(png_ptr, NULL, NULL); + /* Added at libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + png_ptr->user_width_max = PNG_USER_WIDTH_MAX; + png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; + /* Added at libpng-1.2.41 */ + png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; +#endif + + /* Initialize zbuf - compression buffer */ + png_ptr->zbuf_size = PNG_ZBUF_SIZE; + png_ptr->zstream.zalloc = png_zalloc; + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); + png_ptr->zstream.zalloc = png_zalloc; + png_ptr->zstream.zfree = png_zfree; + png_ptr->zstream.opaque = (voidpf)png_ptr; + switch (inflateInit(&png_ptr->zstream)) + { + case Z_OK: /* Do nothing */ break; + case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break; + case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break; + default: png_error(png_ptr, "Unknown zlib error"); + } - return (png_ptr); -} + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL); +} #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read the information before the actual image data. This has been @@ -231,61 +398,63 @@ png_read_info(png_structp png_ptr, png_infop info_ptr) for (;;) { - PNG_IHDR; - PNG_IDAT; - PNG_IEND; - PNG_PLTE; +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST PNG_IHDR; + PNG_CONST PNG_IDAT; + PNG_CONST PNG_IEND; + PNG_CONST PNG_PLTE; #ifdef PNG_READ_bKGD_SUPPORTED - PNG_bKGD; + PNG_CONST PNG_bKGD; #endif #ifdef PNG_READ_cHRM_SUPPORTED - PNG_cHRM; + PNG_CONST PNG_cHRM; #endif #ifdef PNG_READ_gAMA_SUPPORTED - PNG_gAMA; + PNG_CONST PNG_gAMA; #endif #ifdef PNG_READ_hIST_SUPPORTED - PNG_hIST; + PNG_CONST PNG_hIST; #endif #ifdef PNG_READ_iCCP_SUPPORTED - PNG_iCCP; + PNG_CONST PNG_iCCP; #endif #ifdef PNG_READ_iTXt_SUPPORTED - PNG_iTXt; + PNG_CONST PNG_iTXt; #endif #ifdef PNG_READ_oFFs_SUPPORTED - PNG_oFFs; + PNG_CONST PNG_oFFs; #endif #ifdef PNG_READ_pCAL_SUPPORTED - PNG_pCAL; + PNG_CONST PNG_pCAL; #endif #ifdef PNG_READ_pHYs_SUPPORTED - PNG_pHYs; + PNG_CONST PNG_pHYs; #endif #ifdef PNG_READ_sBIT_SUPPORTED - PNG_sBIT; + PNG_CONST PNG_sBIT; #endif #ifdef PNG_READ_sCAL_SUPPORTED - PNG_sCAL; + PNG_CONST PNG_sCAL; #endif #ifdef PNG_READ_sPLT_SUPPORTED - PNG_sPLT; + PNG_CONST PNG_sPLT; #endif #ifdef PNG_READ_sRGB_SUPPORTED - PNG_sRGB; + PNG_CONST PNG_sRGB; #endif #ifdef PNG_READ_tEXt_SUPPORTED - PNG_tEXt; + PNG_CONST PNG_tEXt; #endif #ifdef PNG_READ_tIME_SUPPORTED - PNG_tIME; + PNG_CONST PNG_tIME; #endif #ifdef PNG_READ_tRNS_SUPPORTED - PNG_tRNS; + PNG_CONST PNG_tRNS; #endif #ifdef PNG_READ_zTXt_SUPPORTED - PNG_zTXt; + PNG_CONST PNG_zTXt; #endif +#endif /* PNG_USE_LOCAL_ARRAYS */ png_uint_32 length = png_read_chunk_header(png_ptr); PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; @@ -445,7 +614,7 @@ png_start_read_image(png_structp png_ptr) void PNGAPI png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) { - PNG_IDAT; + PNG_CONST PNG_IDAT; PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; @@ -455,7 +624,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) return; png_debug2(1, "in png_read_row (row %lu, pass %d)", - (unsigned long) png_ptr->row_number, png_ptr->pass); + png_ptr->row_number, png_ptr->pass); if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) png_read_start_row(png_ptr); @@ -464,31 +633,31 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) /* Check for transforms that have been set but were defined out */ #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) if (png_ptr->transformations & PNG_INVERT_MONO) - png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined."); #endif #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) if (png_ptr->transformations & PNG_FILLER) - png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined."); #endif #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED) if (png_ptr->transformations & PNG_PACKSWAP) - png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined."); #endif #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED) if (png_ptr->transformations & PNG_PACK) - png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined."); #endif #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) if (png_ptr->transformations & PNG_SHIFT) - png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined."); #endif #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED) if (png_ptr->transformations & PNG_BGR) - png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined."); #endif #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) if (png_ptr->transformations & PNG_SWAP_BYTES) - png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined."); #endif } @@ -599,7 +768,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) { if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in || png_ptr->idat_size) - png_benign_error(png_ptr, "Extra compressed data"); + png_error(png_ptr, "Extra compressed data"); png_ptr->mode |= PNG_AFTER_IDAT; png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; break; @@ -623,7 +792,8 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) png_ptr->row_buf + 1, png_ptr->prev_row + 1, (int)(png_ptr->row_buf[0])); - png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1); + png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, + png_ptr->rowbytes + 1); #ifdef PNG_MNG_FEATURES_SUPPORTED if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && @@ -723,14 +893,14 @@ png_read_rows(png_structp png_ptr, png_bytepp row, for (i = 0; i < num_rows; i++) { png_bytep rptr = *rp; - png_read_row(png_ptr, rptr, NULL); + png_read_row(png_ptr, rptr, png_bytep_NULL); rp++; } else if (dp != NULL) for (i = 0; i < num_rows; i++) { png_bytep dptr = *dp; - png_read_row(png_ptr, NULL, dptr); + png_read_row(png_ptr, png_bytep_NULL, dptr); dp++; } } @@ -766,7 +936,7 @@ png_read_image(png_structp png_ptr, png_bytepp image) #else if (png_ptr->interlaced) png_error(png_ptr, - "Cannot read interlaced image -- interlace handler disabled"); + "Cannot read interlaced image -- interlace handler disabled."); pass = 1; #endif @@ -779,7 +949,7 @@ png_read_image(png_structp png_ptr, png_bytepp image) rp = image; for (i = 0; i < image_height; i++) { - png_read_row(png_ptr, *rp, NULL); + png_read_row(png_ptr, *rp, png_bytep_NULL); rp++; } } @@ -802,61 +972,63 @@ png_read_end(png_structp png_ptr, png_infop info_ptr) do { - PNG_IHDR; - PNG_IDAT; - PNG_IEND; - PNG_PLTE; +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST PNG_IHDR; + PNG_CONST PNG_IDAT; + PNG_CONST PNG_IEND; + PNG_CONST PNG_PLTE; #ifdef PNG_READ_bKGD_SUPPORTED - PNG_bKGD; + PNG_CONST PNG_bKGD; #endif #ifdef PNG_READ_cHRM_SUPPORTED - PNG_cHRM; + PNG_CONST PNG_cHRM; #endif #ifdef PNG_READ_gAMA_SUPPORTED - PNG_gAMA; + PNG_CONST PNG_gAMA; #endif #ifdef PNG_READ_hIST_SUPPORTED - PNG_hIST; + PNG_CONST PNG_hIST; #endif #ifdef PNG_READ_iCCP_SUPPORTED - PNG_iCCP; + PNG_CONST PNG_iCCP; #endif #ifdef PNG_READ_iTXt_SUPPORTED - PNG_iTXt; + PNG_CONST PNG_iTXt; #endif #ifdef PNG_READ_oFFs_SUPPORTED - PNG_oFFs; + PNG_CONST PNG_oFFs; #endif #ifdef PNG_READ_pCAL_SUPPORTED - PNG_pCAL; + PNG_CONST PNG_pCAL; #endif #ifdef PNG_READ_pHYs_SUPPORTED - PNG_pHYs; + PNG_CONST PNG_pHYs; #endif #ifdef PNG_READ_sBIT_SUPPORTED - PNG_sBIT; + PNG_CONST PNG_sBIT; #endif #ifdef PNG_READ_sCAL_SUPPORTED - PNG_sCAL; + PNG_CONST PNG_sCAL; #endif #ifdef PNG_READ_sPLT_SUPPORTED - PNG_sPLT; + PNG_CONST PNG_sPLT; #endif #ifdef PNG_READ_sRGB_SUPPORTED - PNG_sRGB; + PNG_CONST PNG_sRGB; #endif #ifdef PNG_READ_tEXt_SUPPORTED - PNG_tEXt; + PNG_CONST PNG_tEXt; #endif #ifdef PNG_READ_tIME_SUPPORTED - PNG_tIME; + PNG_CONST PNG_tIME; #endif #ifdef PNG_READ_tRNS_SUPPORTED - PNG_tRNS; + PNG_CONST PNG_tRNS; #endif #ifdef PNG_READ_zTXt_SUPPORTED - PNG_zTXt; + PNG_CONST PNG_zTXt; #endif +#endif /* PNG_USE_LOCAL_ARRAYS */ png_uint_32 length = png_read_chunk_header(png_ptr); PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; @@ -870,7 +1042,7 @@ png_read_end(png_structp png_ptr, png_infop info_ptr) if (!png_memcmp(chunk_name, png_IDAT, 4)) { if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) - png_benign_error(png_ptr, "Too many IDATs found"); + png_error(png_ptr, "Too many IDAT's found"); } png_handle_unknown(png_ptr, info_ptr, length); if (!png_memcmp(chunk_name, png_PLTE, 4)) @@ -883,7 +1055,7 @@ png_read_end(png_structp png_ptr, png_infop info_ptr) * read, but not after other chunks have been read. */ if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) - png_benign_error(png_ptr, "Too many IDATs found"); + png_error(png_ptr, "Too many IDAT's found"); png_crc_finish(png_ptr, length); } else if (!png_memcmp(chunk_name, png_PLTE, 4)) @@ -1072,19 +1244,37 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr png_free(png_ptr, png_ptr->gamma_from_1); png_free(png_ptr, png_ptr->gamma_to_1); #endif +#ifdef PNG_FREE_ME_SUPPORTED if (png_ptr->free_me & PNG_FREE_PLTE) png_zfree(png_ptr, png_ptr->palette); png_ptr->free_me &= ~PNG_FREE_PLTE; +#else + if (png_ptr->flags & PNG_FLAG_FREE_PLTE) + png_zfree(png_ptr, png_ptr->palette); + png_ptr->flags &= ~PNG_FLAG_FREE_PLTE; +#endif #if defined(PNG_tRNS_SUPPORTED) || \ defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) +#ifdef PNG_FREE_ME_SUPPORTED if (png_ptr->free_me & PNG_FREE_TRNS) - png_free(png_ptr, png_ptr->trans_alpha); + png_free(png_ptr, png_ptr->trans); png_ptr->free_me &= ~PNG_FREE_TRNS; +#else + if (png_ptr->flags & PNG_FLAG_FREE_TRNS) + png_free(png_ptr, png_ptr->trans); + png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; +#endif #endif #ifdef PNG_READ_hIST_SUPPORTED +#ifdef PNG_FREE_ME_SUPPORTED if (png_ptr->free_me & PNG_FREE_HIST) png_free(png_ptr, png_ptr->hist); png_ptr->free_me &= ~PNG_FREE_HIST; +#else + if (png_ptr->flags & PNG_FLAG_FREE_HIST) + png_free(png_ptr, png_ptr->hist); + png_ptr->flags &= ~PNG_FLAG_FREE_HIST; +#endif #endif #ifdef PNG_READ_GAMMA_SUPPORTED if (png_ptr->gamma_16_table != NULL) @@ -1135,6 +1325,11 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr #endif /* PNG_TEXT_SUPPORTED */ #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ +/* New member added in libpng-1.2.41, will be removed from 1.4.0 */ +#ifdef PNG_iTXt_SUPPORTED + png_free(png_ptr, png_ptr->user_png_ver); +#endif + /* Save the important info out of the png_struct, in case it is * being used again. */ @@ -1184,6 +1379,12 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, if (png_ptr == NULL) return; +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED + /* Invert the alpha channel from opacity to transparency + */ + if (transforms & PNG_TRANSFORM_INVERT_ALPHA) + png_set_invert_alpha(png_ptr); +#endif /* png_read_info() gives us all of the information from the * PNG file before the first IDAT (image data chunk). @@ -1284,6 +1485,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, png_set_swap(png_ptr); #endif +/* Added at libpng-1.2.41 */ #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED /* Invert the alpha channel from opacity to transparency */ @@ -1291,6 +1493,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, png_set_invert_alpha(png_ptr); #endif +/* Added at libpng-1.2.41 */ #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED /* Expand grayscale image to RGB */ @@ -1308,17 +1511,19 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, /* -------------- image transformations end here ------------------- */ +#ifdef PNG_FREE_ME_SUPPORTED png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); +#endif if (info_ptr->row_pointers == NULL) { - png_uint_32 iptr; - info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, info_ptr->height * png_sizeof(png_bytep)); - for (iptr=0; iptr<info_ptr->height; iptr++) - info_ptr->row_pointers[iptr] = NULL; + png_memset(info_ptr->row_pointers, 0, info_ptr->height + * png_sizeof(png_bytep)); +#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_ROWS; +#endif for (row = 0; row < (int)info_ptr->height; row++) info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, @@ -1,7 +1,7 @@ /* pngrio.c - functions for data input * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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.) @@ -18,9 +18,9 @@ * libpng use it at run time with png_set_read_fn(...). */ +#define PNG_INTERNAL #include "png.h" #ifdef PNG_READ_SUPPORTED -#include "pngpriv.h" /* Read the data from whatever input you are using. The default routine * reads from a file pointer. Note that this routine sometimes gets called @@ -56,7 +56,13 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) /* fread() returns 0 on error, so it is OK to store this in a png_size_t * instead of an int, which is what fread() actually returns. */ - check = fread(data, 1, length, (png_FILE_p)png_ptr->io_ptr); +#ifdef _WIN32_WCE + if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) + check = 0; +#else + check = (png_size_t)fread(data, (png_size_t)1, length, + (png_FILE_p)png_ptr->io_ptr); +#endif if (check != length) png_error(png_ptr, "Read Error"); @@ -73,7 +79,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) static void PNGAPI png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) { - png_size_t check; + int check; png_byte *n_data; png_FILE_p io_ptr; @@ -84,7 +90,12 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); if ((png_bytep)n_data == data) { +#ifdef _WIN32_WCE + if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) + check = 0; +#else check = fread(n_data, 1, length, io_ptr); +#endif } else { @@ -95,7 +106,12 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) do { read = MIN(NEAR_BUF_SIZE, remaining); - err = fread(buf, 1, read, io_ptr); +#ifdef _WIN32_WCE + if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) ) + err = 0; +#else + err = fread(buf, (png_size_t)1, read, io_ptr); +#endif png_memcpy(data, buf, read); /* copy far buffer to near buffer */ if (err != read) break; @@ -152,7 +168,7 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, png_warning(png_ptr, "It's an error to set both read_data_fn and write_data_fn in the "); png_warning(png_ptr, - "same structure. Resetting write_data_fn to NULL"); + "same structure. Resetting write_data_fn to NULL."); } #ifdef PNG_WRITE_FLUSH_SUPPORTED diff --git a/pngrtran.c b/pngrtran.c index 7cd0fa819..1241224a5 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -1,7 +1,7 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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.) @@ -16,9 +16,9 @@ * in pngtrans.c. */ +#define PNG_INTERNAL #include "png.h" #ifdef PNG_READ_SUPPORTED -#include "pngpriv.h" /* Set the action on getting a CRC error for an ancillary or critical chunk. */ void PNGAPI @@ -48,7 +48,7 @@ png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */ png_warning(png_ptr, - "Can't discard critical data on CRC error"); + "Can't discard critical data on CRC error."); case PNG_CRC_ERROR_QUIT: /* Error/quit */ case PNG_CRC_DEFAULT: @@ -624,6 +624,7 @@ png_set_palette_to_rgb(png_structp png_ptr) png_ptr->flags &= ~PNG_FLAG_ROW_INIT; } +#ifndef PNG_1_0_X /* Expand grayscale images of less than 8-bit depth to 8 bits. */ void PNGAPI png_set_expand_gray_1_2_4_to_8(png_structp png_ptr) @@ -636,7 +637,22 @@ png_set_expand_gray_1_2_4_to_8(png_structp png_ptr) png_ptr->transformations |= PNG_EXPAND; png_ptr->flags &= ~PNG_FLAG_ROW_INIT; } +#endif + +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* Expand grayscale images of less than 8-bit depth to 8 bits. */ +/* Deprecated as of libpng-1.2.9 */ +void PNGAPI +png_set_gray_1_2_4_to_8(png_structp png_ptr) +{ + png_debug(1, "in png_set_gray_1_2_4_to_8"); + + if (png_ptr == NULL) + return; + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); +} +#endif /* Expand tRNS chunks to alpha channels. */ @@ -704,7 +720,7 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, #else { png_warning(png_ptr, - "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED"); + "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED."); png_ptr->transformations &= ~PNG_RGB_TO_GRAY; } #endif @@ -735,6 +751,7 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, #endif #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) || \ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) void PNGAPI png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr @@ -749,6 +766,11 @@ png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr png_ptr->transformations |= PNG_USER_TRANSFORM; png_ptr->read_user_transform_fn = read_user_transform_fn; #endif +#ifdef PNG_LEGACY_SUPPORTED + if (read_user_transform_fn) + png_warning(png_ptr, + "This version of libpng does not support user transforms"); +#endif } #endif @@ -760,6 +782,9 @@ png_init_read_transformations(png_structp png_ptr) { png_debug(1, "in png_init_read_transformations"); +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (png_ptr != NULL) +#endif { #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \ || defined(PNG_READ_GAMMA_SUPPORTED) @@ -808,9 +833,9 @@ png_init_read_transformations(png_structp png_ptr) = png_ptr->background.blue = png_ptr->background.gray; if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) { - png_ptr->trans_color.gray *= (png_uint_16)0xff; - png_ptr->trans_color.red = png_ptr->trans_color.green - = png_ptr->trans_color.blue = png_ptr->trans_color.gray; + png_ptr->trans_values.gray *= (png_uint_16)0xff; + png_ptr->trans_values.red = png_ptr->trans_values.green + = png_ptr->trans_values.blue = png_ptr->trans_values.gray; } break; @@ -820,9 +845,9 @@ png_init_read_transformations(png_structp png_ptr) = png_ptr->background.blue = png_ptr->background.gray; if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) { - png_ptr->trans_color.gray *= (png_uint_16)0x55; - png_ptr->trans_color.red = png_ptr->trans_color.green - = png_ptr->trans_color.blue = png_ptr->trans_color.gray; + png_ptr->trans_values.gray *= (png_uint_16)0x55; + png_ptr->trans_values.red = png_ptr->trans_values.green + = png_ptr->trans_values.blue = png_ptr->trans_values.gray; } break; @@ -832,9 +857,9 @@ png_init_read_transformations(png_structp png_ptr) = png_ptr->background.blue = png_ptr->background.gray; if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) { - png_ptr->trans_color.gray *= (png_uint_16)0x11; - png_ptr->trans_color.red = png_ptr->trans_color.green - = png_ptr->trans_color.blue = png_ptr->trans_color.gray; + png_ptr->trans_values.gray *= (png_uint_16)0x11; + png_ptr->trans_values.red = png_ptr->trans_values.green + = png_ptr->trans_values.blue = png_ptr->trans_values.gray; } break; @@ -868,7 +893,7 @@ png_init_read_transformations(png_structp png_ptr) int i, istop; istop=(int)png_ptr->num_trans; for (i=0; i<istop; i++) - png_ptr->trans_alpha[i] = (png_byte)(255 - png_ptr->trans_alpha[i]); + png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]); } } #endif @@ -890,7 +915,7 @@ png_init_read_transformations(png_structp png_ptr) k=0; for (i=0; i<png_ptr->num_trans; i++) { - if (png_ptr->trans_alpha[i] != 0 && png_ptr->trans_alpha[i] != 0xff) + if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff) k=1; /* Partial transparency is present */ } if (k == 0) @@ -972,26 +997,26 @@ png_init_read_transformations(png_structp png_ptr) } for (i = 0; i < num_palette; i++) { - if (i < (int)png_ptr->num_trans && png_ptr->trans_alpha[i] != 0xff) + if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff) { - if (png_ptr->trans_alpha[i] == 0) + if (png_ptr->trans[i] == 0) { palette[i] = back; } - else /* if (png_ptr->trans_alpha[i] != 0xff) */ + else /* if (png_ptr->trans[i] != 0xff) */ { png_byte v, w; v = png_ptr->gamma_to_1[palette[i].red]; - png_composite(w, v, png_ptr->trans_alpha[i], back_1.red); + png_composite(w, v, png_ptr->trans[i], back_1.red); palette[i].red = png_ptr->gamma_from_1[w]; v = png_ptr->gamma_to_1[palette[i].green]; - png_composite(w, v, png_ptr->trans_alpha[i], back_1.green); + png_composite(w, v, png_ptr->trans[i], back_1.green); palette[i].green = png_ptr->gamma_from_1[w]; v = png_ptr->gamma_to_1[palette[i].blue]; - png_composite(w, v, png_ptr->trans_alpha[i], back_1.blue); + png_composite(w, v, png_ptr->trans[i], back_1.blue); palette[i].blue = png_ptr->gamma_from_1[w]; } } @@ -1111,19 +1136,19 @@ png_init_read_transformations(png_structp png_ptr) for (i = 0; i < istop; i++) { - if (png_ptr->trans_alpha[i] == 0) + if (png_ptr->trans[i] == 0) { palette[i] = back; } - else if (png_ptr->trans_alpha[i] != 0xff) + else if (png_ptr->trans[i] != 0xff) { /* The png_composite() macro is defined in png.h */ png_composite(palette[i].red, palette[i].red, - png_ptr->trans_alpha[i], back.red); + png_ptr->trans[i], back.red); png_composite(palette[i].green, palette[i].green, - png_ptr->trans_alpha[i], back.green); + png_ptr->trans[i], back.green); png_composite(palette[i].blue, palette[i].blue, - png_ptr->trans_alpha[i], back.blue); + png_ptr->trans[i], back.blue); } } @@ -1277,8 +1302,10 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr) { info_ptr->channels++; /* If adding a true alpha channel not just filler */ +#ifndef PNG_1_0_X if (png_ptr->transformations & PNG_ADD_ALPHA) info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; +#endif } #endif @@ -1345,14 +1372,14 @@ png_do_read_transformations(png_structp png_ptr) if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE) { png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1, - png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans); + png_ptr->palette, png_ptr->trans, png_ptr->num_trans); } else { if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS)) png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, - &(png_ptr->trans_color)); + &(png_ptr->trans_values)); else png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, NULL); @@ -1434,7 +1461,7 @@ png_do_read_transformations(png_structp png_ptr) ((png_ptr->num_trans != 0 ) || (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1, - &(png_ptr->trans_color), &(png_ptr->background) + &(png_ptr->trans_values), &(png_ptr->background) #ifdef PNG_READ_GAMMA_SUPPORTED , &(png_ptr->background_1), png_ptr->gamma_table, png_ptr->gamma_from_1, @@ -1569,7 +1596,11 @@ png_do_unpack(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_unpack"); +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL && row_info->bit_depth < 8) +#else if (row_info->bit_depth < 8) +#endif { png_uint_32 i; png_uint_32 row_width=row_info->width; @@ -1659,6 +1690,9 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits) png_debug(1, "in png_do_unshift"); if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && sig_bits != NULL && +#endif row_info->color_type != PNG_COLOR_TYPE_PALETTE) { int shift[4]; @@ -1765,7 +1799,11 @@ png_do_chop(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_chop"); +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL && row_info->bit_depth == 16) +#else if (row_info->bit_depth == 16) +#endif { png_bytep sp = row; png_bytep dp = row; @@ -1819,6 +1857,9 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_read_swap_alpha"); +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif { png_uint_32 row_width = row_info->width; if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) @@ -1909,6 +1950,9 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_read_invert_alpha"); +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif { png_uint_32 row_width = row_info->width; if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) @@ -2093,6 +2137,9 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, png_debug(1, "in png_do_read_filler"); if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif row_info->color_type == PNG_COLOR_TYPE_GRAY) { if (row_info->bit_depth == 8) @@ -2263,6 +2310,9 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) png_debug(1, "in png_do_gray_to_rgb"); if (row_info->bit_depth >= 8 && +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif !(row_info->color_type & PNG_COLOR_MASK_COLOR)) { if (row_info->color_type == PNG_COLOR_TYPE_GRAY) @@ -2367,6 +2417,9 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) png_debug(1, "in png_do_rgb_to_gray"); if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif (row_info->color_type & PNG_COLOR_MASK_COLOR)) { png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff; @@ -2641,6 +2694,188 @@ png_build_grayscale_palette(int bit_depth, png_colorp palette) } } +/* This function is currently unused. Do we really need it? */ +#if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED) +void /* PRIVATE */ +png_correct_palette(png_structp png_ptr, png_colorp palette, + int num_palette) +{ + png_debug(1, "in png_correct_palette"); + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ + defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) + if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND)) + { + png_color back, back_1; + + if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) + { + back.red = png_ptr->gamma_table[png_ptr->background.red]; + back.green = png_ptr->gamma_table[png_ptr->background.green]; + back.blue = png_ptr->gamma_table[png_ptr->background.blue]; + + back_1.red = png_ptr->gamma_to_1[png_ptr->background.red]; + back_1.green = png_ptr->gamma_to_1[png_ptr->background.green]; + back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue]; + } + else + { + double g; + + g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma); + + if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN || + fabs(g - 1.0) < PNG_GAMMA_THRESHOLD) + { + back.red = png_ptr->background.red; + back.green = png_ptr->background.green; + back.blue = png_ptr->background.blue; + } + else + { + back.red = + (png_byte)(pow((double)png_ptr->background.red/255, g) * + 255.0 + 0.5); + back.green = + (png_byte)(pow((double)png_ptr->background.green/255, g) * + 255.0 + 0.5); + back.blue = + (png_byte)(pow((double)png_ptr->background.blue/255, g) * + 255.0 + 0.5); + } + + g = 1.0 / png_ptr->background_gamma; + + back_1.red = + (png_byte)(pow((double)png_ptr->background.red/255, g) * + 255.0 + 0.5); + back_1.green = + (png_byte)(pow((double)png_ptr->background.green/255, g) * + 255.0 + 0.5); + back_1.blue = + (png_byte)(pow((double)png_ptr->background.blue/255, g) * + 255.0 + 0.5); + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_uint_32 i; + + for (i = 0; i < (png_uint_32)num_palette; i++) + { + if (i < png_ptr->num_trans && png_ptr->trans[i] == 0) + { + palette[i] = back; + } + else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff) + { + png_byte v, w; + + v = png_ptr->gamma_to_1[png_ptr->palette[i].red]; + png_composite(w, v, png_ptr->trans[i], back_1.red); + palette[i].red = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[png_ptr->palette[i].green]; + png_composite(w, v, png_ptr->trans[i], back_1.green); + palette[i].green = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[png_ptr->palette[i].blue]; + png_composite(w, v, png_ptr->trans[i], back_1.blue); + palette[i].blue = png_ptr->gamma_from_1[w]; + } + else + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } + } + else + { + int i; + + for (i = 0; i < num_palette; i++) + { + if (palette[i].red == (png_byte)png_ptr->trans_values.gray) + { + palette[i] = back; + } + else + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } + } + } + else +#endif +#ifdef PNG_READ_GAMMA_SUPPORTED + if (png_ptr->transformations & PNG_GAMMA) + { + int i; + + for (i = 0; i < num_palette; i++) + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } +#ifdef PNG_READ_BACKGROUND_SUPPORTED + else +#endif +#endif +#ifdef PNG_READ_BACKGROUND_SUPPORTED + if (png_ptr->transformations & PNG_BACKGROUND) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_color back; + + back.red = (png_byte)png_ptr->background.red; + back.green = (png_byte)png_ptr->background.green; + back.blue = (png_byte)png_ptr->background.blue; + + for (i = 0; i < (int)png_ptr->num_trans; i++) + { + if (png_ptr->trans[i] == 0) + { + palette[i].red = back.red; + palette[i].green = back.green; + palette[i].blue = back.blue; + } + else if (png_ptr->trans[i] != 0xff) + { + png_composite(palette[i].red, png_ptr->palette[i].red, + png_ptr->trans[i], back.red); + png_composite(palette[i].green, png_ptr->palette[i].green, + png_ptr->trans[i], back.green); + png_composite(palette[i].blue, png_ptr->palette[i].blue, + png_ptr->trans[i], back.blue); + } + } + } + else /* Assume grayscale palette (what else could it be?) */ + { + int i; + + for (i = 0; i < num_palette; i++) + { + if (i == (png_byte)png_ptr->trans_values.gray) + { + palette[i].red = (png_byte)png_ptr->background.red; + palette[i].green = (png_byte)png_ptr->background.green; + palette[i].blue = (png_byte)png_ptr->background.blue; + } + } + } + } +#endif +} +#endif #ifdef PNG_READ_BACKGROUND_SUPPORTED /* Replace any alpha or transparency with the supplied background color. @@ -2649,7 +2884,7 @@ png_build_grayscale_palette(int bit_depth, png_colorp palette) */ void /* PRIVATE */ png_do_background(png_row_infop row_info, png_bytep row, - png_color_16p trans_color, png_color_16p background + png_color_16p trans_values, png_color_16p background #ifdef PNG_READ_GAMMA_SUPPORTED , png_color_16p background_1, png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, @@ -2666,8 +2901,11 @@ png_do_background(png_row_infop row_info, png_bytep row, png_debug(1, "in png_do_background"); if (background != NULL && +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) || - (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_color))) + (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values))) { switch (row_info->color_type) { @@ -2682,7 +2920,7 @@ png_do_background(png_row_infop row_info, png_bytep row, for (i = 0; i < row_width; i++) { if ((png_uint_16)((*sp >> shift) & 0x01) - == trans_color->gray) + == trans_values->gray) { *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff); *sp |= (png_byte)(background->gray << shift); @@ -2708,7 +2946,7 @@ png_do_background(png_row_infop row_info, png_bytep row, for (i = 0; i < row_width; i++) { if ((png_uint_16)((*sp >> shift) & 0x03) - == trans_color->gray) + == trans_values->gray) { *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); *sp |= (png_byte)(background->gray << shift); @@ -2738,7 +2976,7 @@ png_do_background(png_row_infop row_info, png_bytep row, for (i = 0; i < row_width; i++) { if ((png_uint_16)((*sp >> shift) & 0x03) - == trans_color->gray) + == trans_values->gray) { *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); *sp |= (png_byte)(background->gray << shift); @@ -2765,7 +3003,7 @@ png_do_background(png_row_infop row_info, png_bytep row, for (i = 0; i < row_width; i++) { if ((png_uint_16)((*sp >> shift) & 0x0f) - == trans_color->gray) + == trans_values->gray) { *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); *sp |= (png_byte)(background->gray << shift); @@ -2795,7 +3033,7 @@ png_do_background(png_row_infop row_info, png_bytep row, for (i = 0; i < row_width; i++) { if ((png_uint_16)((*sp >> shift) & 0x0f) - == trans_color->gray) + == trans_values->gray) { *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); *sp |= (png_byte)(background->gray << shift); @@ -2820,7 +3058,7 @@ png_do_background(png_row_infop row_info, png_bytep row, sp = row; for (i = 0; i < row_width; i++, sp++) { - if (*sp == trans_color->gray) + if (*sp == trans_values->gray) { *sp = (png_byte)background->gray; } @@ -2836,7 +3074,7 @@ png_do_background(png_row_infop row_info, png_bytep row, sp = row; for (i = 0; i < row_width; i++, sp++) { - if (*sp == trans_color->gray) + if (*sp == trans_values->gray) { *sp = (png_byte)background->gray; } @@ -2856,7 +3094,7 @@ png_do_background(png_row_infop row_info, png_bytep row, png_uint_16 v; v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); - if (v == trans_color->gray) + if (v == trans_values->gray) { /* Background is already in screen gamma */ *sp = (png_byte)((background->gray >> 8) & 0xff); @@ -2879,7 +3117,7 @@ png_do_background(png_row_infop row_info, png_bytep row, png_uint_16 v; v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); - if (v == trans_color->gray) + if (v == trans_values->gray) { *sp = (png_byte)((background->gray >> 8) & 0xff); *(sp + 1) = (png_byte)(background->gray & 0xff); @@ -2902,9 +3140,9 @@ png_do_background(png_row_infop row_info, png_bytep row, sp = row; for (i = 0; i < row_width; i++, sp += 3) { - if (*sp == trans_color->red && - *(sp + 1) == trans_color->green && - *(sp + 2) == trans_color->blue) + if (*sp == trans_values->red && + *(sp + 1) == trans_values->green && + *(sp + 2) == trans_values->blue) { *sp = (png_byte)background->red; *(sp + 1) = (png_byte)background->green; @@ -2924,9 +3162,9 @@ png_do_background(png_row_infop row_info, png_bytep row, sp = row; for (i = 0; i < row_width; i++, sp += 3) { - if (*sp == trans_color->red && - *(sp + 1) == trans_color->green && - *(sp + 2) == trans_color->blue) + if (*sp == trans_values->red && + *(sp + 1) == trans_values->green && + *(sp + 2) == trans_values->blue) { *sp = (png_byte)background->red; *(sp + 1) = (png_byte)background->green; @@ -2946,8 +3184,8 @@ png_do_background(png_row_infop row_info, png_bytep row, png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5)); - if (r == trans_color->red && g == trans_color->green && - b == trans_color->blue) + if (r == trans_values->red && g == trans_values->green && + b == trans_values->blue) { /* Background is already in screen gamma */ *sp = (png_byte)((background->red >> 8) & 0xff); @@ -2981,8 +3219,8 @@ png_do_background(png_row_infop row_info, png_bytep row, png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5)); - if (r == trans_color->red && g == trans_color->green && - b == trans_color->blue) + if (r == trans_values->red && g == trans_values->green && + b == trans_values->blue) { *sp = (png_byte)((background->red >> 8) & 0xff); *(sp + 1) = (png_byte)(background->red & 0xff); @@ -3353,6 +3591,9 @@ png_do_gamma(png_row_infop row_info, png_bytep row, png_debug(1, "in png_do_gamma"); if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif ((row_info->bit_depth <= 8 && gamma_table != NULL) || (row_info->bit_depth == 16 && gamma_16_table != NULL))) { @@ -3529,7 +3770,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row, */ void /* PRIVATE */ png_do_expand_palette(png_row_infop row_info, png_bytep row, - png_colorp palette, png_bytep trans_alpha, int num_trans) + png_colorp palette, png_bytep trans, int num_trans) { int shift, value; png_bytep sp, dp; @@ -3539,6 +3780,9 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, png_debug(1, "in png_do_expand_palette"); if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif row_info->color_type == PNG_COLOR_TYPE_PALETTE) { if (row_info->bit_depth < 8) @@ -3621,7 +3865,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, { case 8: { - if (trans_alpha != NULL) + if (trans != NULL) { sp = row + (png_size_t)row_width - 1; dp = row + (png_size_t)(row_width << 2) - 1; @@ -3631,7 +3875,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, if ((int)(*sp) >= num_trans) *dp-- = 0xff; else - *dp-- = trans_alpha[*sp]; + *dp-- = trans[*sp]; *dp-- = palette[*sp].blue; *dp-- = palette[*sp].green; *dp-- = palette[*sp].red; @@ -3682,6 +3926,9 @@ png_do_expand(png_row_infop row_info, png_bytep row, png_debug(1, "in png_do_expand"); +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif { if (row_info->color_type == PNG_COLOR_TYPE_GRAY) { @@ -3891,6 +4138,9 @@ png_do_dither(png_row_infop row_info, png_bytep row, png_debug(1, "in png_do_dither"); +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif { if (row_info->color_type == PNG_COLOR_TYPE_RGB && palette_lookup && row_info->bit_depth == 8) @@ -3990,7 +4240,6 @@ static PNG_CONST int png_gamma_shift[] = * AND * { * the screen_gamma is known - * * OR * * RGB_to_gray transformation is being performed @@ -4236,6 +4485,9 @@ png_do_read_intrapixel(png_row_infop row_info, png_bytep row) png_debug(1, "in png_do_read_intrapixel"); if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif (row_info->color_type & PNG_COLOR_MASK_COLOR)) { int bytes_per_pixel; diff --git a/pngrutil.c b/pngrutil.c index 6e15f1fd1..0e83884ac 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -1,7 +1,7 @@ /* pngrutil.c - utilities to read a PNG file * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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.) @@ -14,20 +14,57 @@ * libpng itself during the course of reading an image. */ +#define PNG_INTERNAL #include "png.h" #ifdef PNG_READ_SUPPORTED -#include "pngpriv.h" +#if defined(_WIN32_WCE) && (_WIN32_WCE<0x500) +# define WIN32_WCE_OLD +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +# ifdef WIN32_WCE_OLD +/* The strtod() function is not supported on WindowsCE */ +__inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr) +{ + double result = 0; + int len; + wchar_t *str, *end; + + len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0); + str = (wchar_t *)png_malloc(png_ptr, len * png_sizeof(wchar_t)); + if ( NULL != str ) + { + MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len); + result = wcstod(str, &end); + len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL); + *endptr = (char *)nptr + (png_strlen(nptr) - len + 1); + png_free(png_ptr, str); + } + return result; +} +# else # define png_strtod(p,a,b) strtod(a,b) +# endif +#endif + png_uint_32 PNGAPI png_get_uint_31(png_structp png_ptr, png_bytep buf) { +#ifdef PNG_READ_BIG_ENDIAN_SUPPORTED png_uint_32 i = png_get_uint_32(buf); +#else + /* Avoid an extra function call by inlining the result. */ + png_uint_32 i = ((png_uint_32)(*buf) << 24) + + ((png_uint_32)(*(buf + 1)) << 16) + + ((png_uint_32)(*(buf + 2)) << 8) + + (png_uint_32)(*(buf + 3)); +#endif if (i > PNG_UINT_31_MAX) - png_error(png_ptr, "PNG unsigned integer out of range"); + png_error(png_ptr, "PNG unsigned integer out of range."); return (i); } -#ifndef PNG_USE_READ_MACROS +#ifndef PNG_READ_BIG_ENDIAN_SUPPORTED /* Grab an unsigned 32-bit integer from a buffer in big-endian format. */ png_uint_32 PNGAPI png_get_uint_32(png_bytep buf) @@ -64,7 +101,7 @@ png_get_uint_16(png_bytep buf) return (i); } -#endif /* PNG_USE_READ_MACROS */ +#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */ /* Read the chunk header (length + type name). * Put the type name into png_ptr->chunk_name, and return the length. @@ -150,8 +187,7 @@ png_crc_finish(png_structp png_ptr, png_uint_32 skip) } else { - png_chunk_benign_error(png_ptr, "CRC error"); - return (0); + png_chunk_error(png_ptr, "CRC error"); } return (1); } @@ -274,7 +310,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = NULL; png_error(png_ptr, - "Not enough memory to decompress chunk"); + "Not enough memory to decompress chunk."); } png_memcpy(text + prefix_size, png_ptr->zbuf, text_size - prefix_size); @@ -286,16 +322,30 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, png_charp tmp; tmp = text; - text = (png_charp)png_malloc_warn(png_ptr, - (png_size_t)(text_size + - png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1)); +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + if ((png_ptr->user_chunk_cache_max != 0) && + (--png_ptr->user_chunk_cache_max == 0)) + { + png_warning(png_ptr, "No space in chunk cache"); + text = NULL; + } + + else + { +#endif + text = (png_charp)png_malloc_warn(png_ptr, + (png_uint_32)(text_size + + png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1)); +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + } +#endif if (text == NULL) { png_free(png_ptr, tmp); png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = NULL; png_error(png_ptr, - "Not enough memory to decompress chunk"); + "Not enough memory to decompress chunk.."); } png_memcpy(text, tmp, text_size); png_free(png_ptr, tmp); @@ -315,7 +365,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, } if (ret != Z_STREAM_END) { -#ifdef PNG_STDIO_SUPPORTED +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) char umsg[52]; if (ret == Z_BUF_ERROR) @@ -346,7 +396,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, { png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = NULL; - png_error(png_ptr, "Not enough memory for text"); + png_error(png_ptr, "Not enough memory for text."); } png_memcpy(text, png_ptr->chunkdata, prefix_size); } @@ -362,7 +412,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, } else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ { -#ifdef PNG_STDIO_SUPPORTED +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) char umsg[50]; png_snprintf(umsg, 50, "Unknown zTXt compression type %d", comp_type); @@ -555,7 +605,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) { - png_chunk_benign_error(png_ptr, "CRC error"); + png_chunk_error(png_ptr, "CRC error"); } else { @@ -1093,7 +1143,7 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = NULL; - png_warning(png_ptr, "Ignoring truncated iCCP profile"); + png_warning(png_ptr, "Ignoring truncated iCCP profile."); return; } @@ -1302,7 +1352,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_read(png_ptr, buf, 2); png_ptr->num_trans = 1; - png_ptr->trans_color.gray = png_get_uint_16(buf); + png_ptr->trans_values.gray = png_get_uint_16(buf); } else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) { @@ -1316,9 +1366,9 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } png_crc_read(png_ptr, buf, (png_size_t)length); png_ptr->num_trans = 1; - png_ptr->trans_color.red = png_get_uint_16(buf); - png_ptr->trans_color.green = png_get_uint_16(buf + 2); - png_ptr->trans_color.blue = png_get_uint_16(buf + 4); + png_ptr->trans_values.red = png_get_uint_16(buf); + png_ptr->trans_values.green = png_get_uint_16(buf + 2); + png_ptr->trans_values.blue = png_get_uint_16(buf + 4); } else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { @@ -1357,7 +1407,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans, - &(png_ptr->trans_color)); + &(png_ptr->trans_values)); } #endif @@ -1625,7 +1675,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); if (png_ptr->chunkdata == NULL) { - png_warning(png_ptr, "No memory for pCAL purpose"); + png_warning(png_ptr, "No memory for pCAL purpose."); return; } slength = (png_size_t)length; @@ -1686,12 +1736,12 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_debug(3, "Allocating pCAL parameters array"); params = (png_charpp)png_malloc_warn(png_ptr, - (png_size_t)(nparams * png_sizeof(png_charp))); + (png_uint_32)(nparams * png_sizeof(png_charp))) ; if (params == NULL) { png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = NULL; - png_warning(png_ptr, "No memory for pCAL params"); + png_warning(png_ptr, "No memory for pCAL params."); return; } @@ -1794,7 +1844,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_warning(png_ptr, "Out of memory while processing sCAL chunk width"); return; } - png_memcpy(swidth, ep, png_strlen(ep)); + png_memcpy(swidth, ep, (png_size_t)png_strlen(ep)); #endif #endif @@ -1829,7 +1879,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_warning(png_ptr, "Out of memory while processing sCAL chunk height"); return; } - png_memcpy(sheight, ep, png_strlen(ep)); + png_memcpy(sheight, ep, (png_size_t)png_strlen(ep)); #endif #endif @@ -1961,7 +2011,7 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); if (png_ptr->chunkdata == NULL) { - png_warning(png_ptr, "No memory to process text chunk"); + png_warning(png_ptr, "No memory to process text chunk."); return; } slength = (png_size_t)length; @@ -1985,10 +2035,10 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) text++; text_ptr = (png_textp)png_malloc_warn(png_ptr, - png_sizeof(png_text)); + (png_uint_32)png_sizeof(png_text)); if (text_ptr == NULL) { - png_warning(png_ptr, "Not enough memory to process text chunk"); + png_warning(png_ptr, "Not enough memory to process text chunk."); png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = NULL; return; @@ -2009,7 +2059,7 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_ptr->chunkdata = NULL; png_free(png_ptr, text_ptr); if (ret) - png_warning(png_ptr, "Insufficient memory to process text chunk"); + png_warning(png_ptr, "Insufficient memory to process text chunk."); } #endif @@ -2064,7 +2114,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); if (png_ptr->chunkdata == NULL) { - png_warning(png_ptr, "Out of memory processing zTXt chunk"); + png_warning(png_ptr, "Out of memory processing zTXt chunk."); return; } slength = (png_size_t)length; @@ -2105,10 +2155,10 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) (png_size_t)length, prefix_len, &data_len); text_ptr = (png_textp)png_malloc_warn(png_ptr, - png_sizeof(png_text)); + (png_uint_32)png_sizeof(png_text)); if (text_ptr == NULL) { - png_warning(png_ptr, "Not enough memory to process zTXt chunk"); + png_warning(png_ptr, "Not enough memory to process zTXt chunk."); png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = NULL; return; @@ -2129,7 +2179,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = NULL; if (ret) - png_error(png_ptr, "Insufficient memory to store zTXt chunk"); + png_error(png_ptr, "Insufficient memory to store zTXt chunk."); } #endif @@ -2185,7 +2235,7 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); if (png_ptr->chunkdata == NULL) { - png_warning(png_ptr, "No memory to process iTXt chunk"); + png_warning(png_ptr, "No memory to process iTXt chunk."); return; } slength = (png_size_t)length; @@ -2253,10 +2303,10 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) else data_len = png_strlen(png_ptr->chunkdata + prefix_len); text_ptr = (png_textp)png_malloc_warn(png_ptr, - png_sizeof(png_text)); + (png_uint_32)png_sizeof(png_text)); if (text_ptr == NULL) { - png_warning(png_ptr, "Not enough memory to process iTXt chunk"); + png_warning(png_ptr, "Not enough memory to process iTXt chunk."); png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = NULL; return; @@ -2275,7 +2325,7 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = NULL; if (ret) - png_error(png_ptr, "Insufficient memory to store iTXt chunk"); + png_error(png_ptr, "Insufficient memory to store iTXt chunk."); } #endif @@ -2310,7 +2360,9 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if (png_ptr->mode & PNG_HAVE_IDAT) { - PNG_IDAT; +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST PNG_IDAT; +#endif if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* Not an IDAT */ png_ptr->mode |= PNG_AFTER_IDAT; } @@ -3001,7 +3053,7 @@ png_read_finish_row(png_structp png_ptr) if (png_ptr->interlaced) { png_ptr->row_number = 0; - png_memset(png_ptr->prev_row, 0, + png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1); do { @@ -3036,7 +3088,9 @@ png_read_finish_row(png_structp png_ptr) if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) { - PNG_IDAT; +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST PNG_IDAT; +#endif char extra; int ret; @@ -3083,7 +3137,7 @@ png_read_finish_row(png_structp png_ptr) if (!(png_ptr->zstream.avail_out)) { - png_warning(png_ptr, "Extra compressed data"); + png_warning(png_ptr, "Extra compressed data."); png_ptr->mode |= PNG_AFTER_IDAT; png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; break; @@ -3273,27 +3327,28 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) if (png_ptr->interlaced) png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr, row_bytes + 64); else - png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 64); + png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 64); png_ptr->row_buf = png_ptr->big_row_buf + 32; png_ptr->old_big_row_buf_size = row_bytes + 64; } #ifdef PNG_MAX_MALLOC_64K - if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L) + if ((png_uint_32)row_bytes + 1 > (png_uint_32)65536L) png_error(png_ptr, "This image requires a row greater than 64KB"); #endif - if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1)) - png_error(png_ptr, "Row has too many bytes to allocate in memory"); + if ((png_uint_32)row_bytes > (png_uint_32)(PNG_SIZE_MAX - 1)) + png_error(png_ptr, "Row has too many bytes to allocate in memory."); - if (png_ptr->rowbytes + 1 > png_ptr->old_prev_row_size) + if (row_bytes + 1 > png_ptr->old_prev_row_size) { png_free(png_ptr, png_ptr->prev_row); png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)( - png_ptr->rowbytes + 1)); - png_ptr->old_prev_row_size = png_ptr->rowbytes + 1; + row_bytes + 1)); + png_memset_check(png_ptr, png_ptr->prev_row, 0, row_bytes + 1); + png_ptr->old_prev_row_size = row_bytes + 1; } - png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); + png_ptr->rowbytes = row_bytes; png_debug1(3, "width = %lu,", png_ptr->width); png_debug1(3, "height = %lu,", png_ptr->height); @@ -1,7 +1,7 @@ /* pngset.c - storage of image information into info struct * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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.) @@ -16,9 +16,9 @@ * info struct and allows us to change the structure in the future. */ +#define PNG_INTERNAL #include "png.h" #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) -#include "pngpriv.h" #ifdef PNG_bKGD_SUPPORTED void PNGAPI @@ -191,19 +191,21 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) > PNG_MAX_PALETTE_LENGTH) { png_warning(png_ptr, - "Invalid palette size, hIST allocation skipped"); + "Invalid palette size, hIST allocation skipped."); return; } +#ifdef PNG_FREE_ME_SUPPORTED png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); +#endif /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in * version 1.2.1 */ png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr, - PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16)); + (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16))); if (png_ptr->hist == NULL) { - png_warning(png_ptr, "Insufficient memory for hIST chunk data"); + png_warning(png_ptr, "Insufficient memory for hIST chunk data."); return; } @@ -212,7 +214,11 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) info_ptr->hist = png_ptr->hist; info_ptr->valid |= PNG_INFO_hIST; +#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_HIST; +#else + png_ptr->flags |= PNG_FLAG_FREE_HIST; +#endif } #endif @@ -256,7 +262,7 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr, - 1 /* filter byte */ - 7*8 /* rounding of width to multiple of 8 pixels */ - 8) /* extra max_pixel_depth pad */ - info_ptr->rowbytes = 0; + info_ptr->rowbytes = (png_size_t)0; else info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); } @@ -284,7 +290,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_charp units, png_charpp params) { - png_size_t length; + png_uint_32 length; int i; png_debug1(1, "in %s storage function", "pCAL"); @@ -298,10 +304,10 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length); if (info_ptr->pcal_purpose == NULL) { - png_warning(png_ptr, "Insufficient memory for pCAL purpose"); + png_warning(png_ptr, "Insufficient memory for pCAL purpose."); return; } - png_memcpy(info_ptr->pcal_purpose, purpose, length); + png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length); png_debug(3, "storing X0, X1, type, and nparams in info"); info_ptr->pcal_X0 = X0; @@ -315,16 +321,16 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length); if (info_ptr->pcal_units == NULL) { - png_warning(png_ptr, "Insufficient memory for pCAL units"); + png_warning(png_ptr, "Insufficient memory for pCAL units."); return; } - png_memcpy(info_ptr->pcal_units, units, length); + png_memcpy(info_ptr->pcal_units, units, (png_size_t)length); info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr, - (png_size_t)((nparams + 1) * png_sizeof(png_charp))); + (png_uint_32)((nparams + 1) * png_sizeof(png_charp))); if (info_ptr->pcal_params == NULL) { - png_warning(png_ptr, "Insufficient memory for pCAL params"); + png_warning(png_ptr, "Insufficient memory for pCAL params."); return; } @@ -338,14 +344,16 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); if (info_ptr->pcal_params[i] == NULL) { - png_warning(png_ptr, "Insufficient memory for pCAL parameter"); + png_warning(png_ptr, "Insufficient memory for pCAL parameter."); return; } - png_memcpy(info_ptr->pcal_params[i], params[i], length); + png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length); } info_ptr->valid |= PNG_INFO_pCAL; +#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_PCAL; +#endif } #endif @@ -372,7 +380,7 @@ void PNGAPI png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, int unit, png_charp swidth, png_charp sheight) { - png_size_t length; + png_uint_32 length; png_debug1(1, "in %s storage function", "sCAL"); @@ -388,10 +396,10 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, if (info_ptr->scal_s_width == NULL) { png_warning(png_ptr, - "Memory allocation failed while processing sCAL"); + "Memory allocation failed while processing sCAL."); return; } - png_memcpy(info_ptr->scal_s_width, swidth, length); + png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length); length = png_strlen(sheight) + 1; png_debug1(3, "allocating unit for info (%u bytes)", @@ -402,12 +410,14 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, png_free (png_ptr, info_ptr->scal_s_width); info_ptr->scal_s_width = NULL; png_warning(png_ptr, - "Memory allocation failed while processing sCAL"); + "Memory allocation failed while processing sCAL."); return; } - png_memcpy(info_ptr->scal_s_height, sheight, length); + png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length); info_ptr->valid |= PNG_INFO_sCAL; +#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_SCAL; +#endif } #endif #endif @@ -456,7 +466,9 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr, * we do it for backward compatibility with the way the png_handle_tRNS * function used to do the allocation. */ +#ifdef PNG_FREE_ME_SUPPORTED png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); +#endif /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead * of num_palette entries, in case of an invalid PNG file that has @@ -468,7 +480,11 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr, info_ptr->palette = png_ptr->palette; info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; +#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_PLTE; +#else + png_ptr->flags |= PNG_FLAG_FREE_PLTE; +#endif info_ptr->valid |= PNG_INFO_PLTE; } @@ -592,7 +608,7 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr, new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length); if (new_iccp_name == NULL) { - png_warning(png_ptr, "Insufficient memory to process iCCP chunk"); + png_warning(png_ptr, "Insufficient memory to process iCCP chunk."); return; } png_memcpy(new_iccp_name, name, length); @@ -601,7 +617,7 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr, { png_free (png_ptr, new_iccp_name); png_warning(png_ptr, - "Insufficient memory to process iCCP profile"); + "Insufficient memory to process iCCP profile."); return; } png_memcpy(new_iccp_profile, profile, (png_size_t)proflen); @@ -614,7 +630,9 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr, /* Compression is always zero but is here so the API and info structure * does not have to change if we introduce multiple compression types */ info_ptr->iccp_compression = (png_byte)compression_type; +#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_ICCP; +#endif info_ptr->valid |= PNG_INFO_iCCP; } #endif @@ -635,6 +653,9 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, int num_text) { int i; +#ifdef PNG_iTXt_SUPPORTED + int caller_no_itxt = 0; +#endif png_debug1(1, "in %s storage function", ((png_ptr == NULL || png_ptr->chunk_name[0] == '\0') ? @@ -643,6 +664,45 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, if (png_ptr == NULL || info_ptr == NULL || num_text == 0) return(0); +#ifdef PNG_iTXt_SUPPORTED + /* If an earlier version of the library was used to build the + * application, it might be using a png_textp structure that + * does not contain the lang or lang_key elements. Even if you build + * this library with PNG_iTXt_SUPPORTED explicitly defined, + * and your older library was also built with PNG_iTXt_SUPPORTED + * defined, the complete png_textp structure probably has not existed + * all along and it's not safe to access them, due to a bug in + * pngconf.h from version 1.2.9 to 1.2.40. + */ + if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) + { + int j; + png_byte c[12]; + + j = 0; + for (j = 0; j < 12; j++) + c[j] = 0; + + for (j = 0; c[j] && j < 12; j++) + c[j] = png_ptr->user_png_ver[j]; + + if ((c[5] == '\0') /* 1.2.N */ || + (c[5] == 'b') /* 1.2.NbetaNN */ || + (c[5] == 'r') /* 1.2.NrcNN */ || + (c[4] == '1') /* 1.2.1x */ || + (c[4] == '2') /* 1.2.2x */ || + (c[4] == '3') /* 1.2.3x */ || + ((c[4] == '4') /* 1.2.4x */ && + (((c[5] == '0')) /* 1.2.40 */ || + ((c[5] == '1') /* 1.2.41x */ && + (((c[6] == 'b') /* 1.2.41betax */ && + ((c[10] == '0'))) /* 1.2.41beta0x */ || + ((c[10] == '1') /* 1.2.41beta1x */ && + (c[11] == '0'))))))) /* 1.2.41beta10 */ + caller_no_itxt = 1; + } +#endif /* PNG_iTXt_SUPPORTED */ + /* Make sure we have enough space in the "text" array in info_struct * to hold all of the incoming text_ptr objects. */ @@ -657,7 +717,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, info_ptr->max_text = info_ptr->num_text + num_text + 8; old_text = info_ptr->text; info_ptr->text = (png_textp)png_malloc_warn(png_ptr, - (png_size_t)(info_ptr->max_text * png_sizeof(png_text))); + (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); if (info_ptr->text == NULL) { png_free(png_ptr, old_text); @@ -672,10 +732,12 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, info_ptr->max_text = num_text + 8; info_ptr->num_text = 0; info_ptr->text = (png_textp)png_malloc_warn(png_ptr, - (png_size_t)(info_ptr->max_text * png_sizeof(png_text))); + (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); if (info_ptr->text == NULL) return(1); +#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_TEXT; +#endif } png_debug1(3, "allocated %d entries for info_ptr->text", info_ptr->max_text); @@ -696,10 +758,14 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, lang_len = 0; lang_key_len = 0; } + else #ifdef PNG_iTXt_SUPPORTED { /* Set iTXt data */ + + if (caller_no_itxt == 0) + { if (text_ptr[i].lang != NULL) lang_len = png_strlen(text_ptr[i].lang); else @@ -708,10 +774,19 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, lang_key_len = png_strlen(text_ptr[i].lang_key); else lang_key_len = 0; + } + + else /* Caller does not support iTXt */ + { + lang_len = 0; + lang_key_len = 0; + png_warning(png_ptr, + "iTXt lang and lang_key not available from application"); + } } -#else +#else /* PNG_iTXt_SUPPORTED */ { - png_warning(png_ptr, "iTXt chunk not supported"); + png_warning(png_ptr, "iTXt chunk not supported."); continue; } #endif @@ -726,6 +801,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, #endif textp->compression = PNG_TEXT_COMPRESSION_NONE; } + else { text_length = png_strlen(text_ptr[i].text); @@ -733,12 +809,12 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, } textp->key = (png_charp)png_malloc_warn(png_ptr, - (png_size_t) + (png_uint_32) (key_len + text_length + lang_len + lang_key_len + 4)); if (textp->key == NULL) return(1); png_debug2(2, "Allocated %lu bytes at %x in png_set_text", - (unsigned long)(png_uint_32) + (png_uint_32) (key_len + lang_len + lang_key_len + text_length + 4), (int)textp->key); @@ -777,6 +853,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, } else #endif + { textp->text_length = text_length; #ifdef PNG_iTXt_SUPPORTED @@ -808,42 +885,43 @@ png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) #ifdef PNG_tRNS_SUPPORTED void PNGAPI png_set_tRNS(png_structp png_ptr, png_infop info_ptr, - png_bytep trans_alpha, int num_trans, png_color_16p trans_color) + png_bytep trans, int num_trans, png_color_16p trans_values) { png_debug1(1, "in %s storage function", "tRNS"); if (png_ptr == NULL || info_ptr == NULL) return; - if (trans_alpha != NULL) + if (trans != NULL) { - /* - * It may not actually be necessary to set png_ptr->trans_alpha here; + /* It may not actually be necessary to set png_ptr->trans here; * we do it for backward compatibility with the way the png_handle_tRNS * function used to do the allocation. */ +#ifdef PNG_FREE_ME_SUPPORTED png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); +#endif /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ - png_ptr->trans_alpha = info_ptr->trans_alpha = (png_bytep)png_malloc(png_ptr, - (png_size_t)PNG_MAX_PALETTE_LENGTH); + png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr, + (png_uint_32)PNG_MAX_PALETTE_LENGTH); if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) - png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans); + png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans); } - if (trans_color != NULL) + if (trans_values != NULL) { int sample_max = (1 << info_ptr->bit_depth); if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY && - (int)trans_color->gray > sample_max) || + (int)trans_values->gray > sample_max) || (info_ptr->color_type == PNG_COLOR_TYPE_RGB && - ((int)trans_color->red > sample_max || - (int)trans_color->green > sample_max || - (int)trans_color->blue > sample_max))) + ((int)trans_values->red > sample_max || + (int)trans_values->green > sample_max || + (int)trans_values->blue > sample_max))) png_warning(png_ptr, "tRNS chunk has out-of-range samples for bit_depth"); - png_memcpy(&(info_ptr->trans_color), trans_color, + png_memcpy(&(info_ptr->trans_values), trans_values, png_sizeof(png_color_16)); if (num_trans == 0) num_trans = 1; @@ -853,7 +931,11 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr, if (num_trans != 0) { info_ptr->valid |= PNG_INFO_tRNS; +#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_TRNS; +#else + png_ptr->flags |= PNG_FLAG_FREE_TRNS; +#endif } } #endif @@ -878,10 +960,10 @@ png_set_sPLT(png_structp png_ptr, np = (png_sPLT_tp)png_malloc_warn(png_ptr, (info_ptr->splt_palettes_num + nentries) * - (png_size_t)png_sizeof(png_sPLT_t)); + (png_uint_32)png_sizeof(png_sPLT_t)); if (np == NULL) { - png_warning(png_ptr, "No memory for sPLT palettes"); + png_warning(png_ptr, "No memory for sPLT palettes."); return; } @@ -897,7 +979,7 @@ png_set_sPLT(png_structp png_ptr, png_uint_32 length; length = png_strlen(from->name) + 1; - to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length); + to->name = (png_charp)png_malloc_warn(png_ptr, length); if (to->name == NULL) { png_warning(png_ptr, @@ -906,7 +988,7 @@ png_set_sPLT(png_structp png_ptr, } png_memcpy(to->name, from->name, length); to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, - (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry))); + (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry))); if (to->entries == NULL) { png_warning(png_ptr, @@ -924,7 +1006,9 @@ png_set_sPLT(png_structp png_ptr, info_ptr->splt_palettes = np; info_ptr->splt_palettes_num += nentries; info_ptr->valid |= PNG_INFO_sPLT; +#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_SPLT; +#endif } #endif /* PNG_sPLT_SUPPORTED */ @@ -940,18 +1024,19 @@ png_set_unknown_chunks(png_structp png_ptr, return; np = (png_unknown_chunkp)png_malloc_warn(png_ptr, - (png_size_t)((info_ptr->unknown_chunks_num + num_unknowns) * + (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) * png_sizeof(png_unknown_chunk))); if (np == NULL) { png_warning(png_ptr, - "Out of memory while processing unknown chunk"); + "Out of memory while processing unknown chunk."); return; } png_memcpy(np, info_ptr->unknown_chunks, info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk)); png_free(png_ptr, info_ptr->unknown_chunks); + info_ptr->unknown_chunks=NULL; for (i = 0; i < num_unknowns; i++) { @@ -971,11 +1056,11 @@ png_set_unknown_chunks(png_structp png_ptr, else { to->data = (png_bytep)png_malloc_warn(png_ptr, - (png_size_t)from->size); + (png_uint_32)from->size); if (to->data == NULL) { png_warning(png_ptr, - "Out of memory while processing unknown chunk"); + "Out of memory while processing unknown chunk."); to->size = 0; } else @@ -985,7 +1070,9 @@ png_set_unknown_chunks(png_structp png_ptr, info_ptr->unknown_chunks = np; info_ptr->unknown_chunks_num += num_unknowns; +#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_UNKN; +#endif } void PNGAPI png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, @@ -997,6 +1084,25 @@ png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, } #endif +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ + defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) +void PNGAPI +png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted) +{ + /* This function is deprecated in favor of png_permit_mng_features() + and will be removed from libpng-1.3.0 */ + + png_debug(1, "in png_permit_empty_plte, DEPRECATED."); + + if (png_ptr == NULL) + return; + png_ptr->mng_features_permitted = (png_byte) + ((png_ptr->mng_features_permitted & (~PNG_FLAG_MNG_EMPTY_PLTE)) | + ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE))); +} +#endif +#endif #ifdef PNG_MNG_FEATURES_SUPPORTED png_uint_32 PNGAPI @@ -1038,7 +1144,7 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep return; old_num_chunks = png_ptr->num_chunk_list; new_list=(png_bytep)png_malloc(png_ptr, - (png_size_t) + (png_uint_32) (5*(num_chunks + old_num_chunks))); if (png_ptr->chunk_list != NULL) { @@ -1053,7 +1159,9 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep *p=(png_byte)keep; png_ptr->num_chunk_list = old_num_chunks + num_chunks; png_ptr->chunk_list = new_list; +#ifdef PNG_FREE_ME_SUPPORTED png_ptr->free_me |= PNG_FREE_LIST; +#endif } #endif @@ -1092,12 +1200,12 @@ png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) #ifdef PNG_WRITE_SUPPORTED void PNGAPI png_set_compression_buffer_size(png_structp png_ptr, - png_size_t size) + png_uint_32 size) { if (png_ptr == NULL) return; png_free(png_ptr, png_ptr->zbuf); - png_ptr->zbuf_size = size; + png_ptr->zbuf_size = (png_size_t)size; png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size); png_ptr->zstream.next_out = png_ptr->zbuf; png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; @@ -1112,6 +1220,32 @@ png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) } +#ifndef PNG_1_0_X +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +/* Function was added to libpng 1.2.0 and should always exist by default */ +void PNGAPI +png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags) +{ +/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ + if (png_ptr != NULL) + png_ptr->asm_flags = 0; + asm_flags = asm_flags; /* Quiet the compiler */ +} + +/* This function was added to libpng 1.2.0 */ +void PNGAPI +png_set_mmx_thresholds (png_structp png_ptr, + png_byte mmx_bitdepth_threshold, + png_uint_32 mmx_rowbytes_threshold) +{ +/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ + if (png_ptr == NULL) + return; + /* Quiet the compiler */ + mmx_bitdepth_threshold = mmx_bitdepth_threshold; + mmx_rowbytes_threshold = mmx_rowbytes_threshold; +} +#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ #ifdef PNG_SET_USER_LIMITS_SUPPORTED /* This function was added to libpng 1.2.6 */ @@ -1128,7 +1262,7 @@ png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, png_ptr->user_width_max = user_width_max; png_ptr->user_height_max = user_height_max; } -/* This function was added to libpng 1.4.0 */ +/* This function was added to libpng 1.2.41 */ void PNGAPI png_set_chunk_cache_max (png_structp png_ptr, png_uint_32 user_chunk_cache_max) @@ -1156,4 +1290,5 @@ png_set_benign_errors(png_structp png_ptr, int allowed) png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN; } #endif /* PNG_BENIGN_ERRORS_SUPPORTED */ +#endif /* ?PNG_1_0_X */ #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ @@ -1,7 +1,7 @@ /* pngtest.c - a simple test program to test libpng * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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.) @@ -32,14 +32,34 @@ */ #include "png.h" -#include "pngpriv.h" +#ifdef _WIN32_WCE +# if _WIN32_WCE < 211 + __error__ (f|w)printf functions are not supported on old WindowsCE.; +# endif +# include <windows.h> +# include <stdlib.h> +# define READFILE(file, data, length, check) \ + if (ReadFile(file, data, length, &check, NULL)) check = 0 +# define WRITEFILE(file, data, length, check)) \ + if (WriteFile(file, data, length, &check, NULL)) check = 0 +# define FCLOSE(file) CloseHandle(file) +#else # include <stdio.h> # include <stdlib.h> +# define READFILE(file, data, length, check) \ + check=(png_size_t)fread(data, (png_size_t)1, length, file) +# define WRITEFILE(file, data, length, check) \ + check=(png_size_t)fwrite(data, (png_size_t)1, length, file) # define FCLOSE(file) fclose(file) +#endif #ifndef PNG_STDIO_SUPPORTED +# ifdef _WIN32_WCE + typedef HANDLE png_FILE_p; +# else typedef FILE * png_FILE_p; +# endif #endif /* Makes pngtest verbose so we can find problems (needs to be before png.h) */ @@ -98,8 +118,14 @@ static int status_dots_requested = 0; static int status_dots = 1; void +#ifdef PNG_1_0_X +PNGAPI +#endif read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); void +#ifdef PNG_1_0_X +PNGAPI +#endif read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) { if (png_ptr == NULL || row_number > PNG_UINT_31_MAX) @@ -120,8 +146,14 @@ read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) } void +#ifdef PNG_1_0_X +PNGAPI +#endif write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); void +#ifdef PNG_1_0_X +PNGAPI +#endif write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) { if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) @@ -137,8 +169,14 @@ write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) */ static png_uint_32 filters_used[256]; void +#ifdef PNG_1_0_X +PNGAPI +#endif count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data); void +#ifdef PNG_1_0_X +PNGAPI +#endif count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data) { if (png_ptr != NULL && row_info != NULL) @@ -154,8 +192,14 @@ count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data) static png_uint_32 zero_samples; void +#ifdef PNG_1_0_X +PNGAPI +#endif count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data); void +#ifdef PNG_1_0_X +PNGAPI +#endif count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data) { png_bytep dp = data; @@ -272,7 +316,7 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) /* fread() returns 0 on error, so it is OK to store this in a png_size_t * instead of an int, which is what fread() actually returns. */ - check = fread(data, 1, length, (png_FILE_p)png_ptr->io_ptr); + READFILE((png_FILE_p)png_ptr->io_ptr, data, length, check); if (check != length) { @@ -291,7 +335,7 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) static void pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) { - png_size_t check; + int check; png_byte *n_data; png_FILE_p io_ptr; @@ -300,7 +344,7 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); if ((png_bytep)n_data == data) { - check = fread(n_data, 1, length, io_ptr); + READFILE(io_ptr, n_data, length, check); } else { @@ -311,7 +355,7 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) do { read = MIN(NEAR_BUF_SIZE, remaining); - err = fread(buf, 1, 1, io_ptr); + READFILE(io_ptr, buf, 1, err); png_memcpy(data, buf, read); /* Copy far buffer to near buffer */ if (err != read) break; @@ -345,9 +389,9 @@ pngtest_flush(png_structp png_ptr) static void pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { - png_size_t check; + png_uint_32 check; - check = fwrite(data, 1, length, (png_FILE_p)png_ptr->io_ptr); + WRITEFILE((png_FILE_p)png_ptr->io_ptr, data, length, check); if (check != length) { png_error(png_ptr, "Write Error"); @@ -365,7 +409,7 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) static void pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { - png_size_t check; + png_uint_32 check; png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ png_FILE_p io_ptr; @@ -374,7 +418,7 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); if ((png_bytep)near_data == data) { - check = fwrite(near_data, 1, length, io_ptr); + WRITEFILE(io_ptr, near_data, length, check); } else { @@ -386,7 +430,7 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { written = MIN(NEAR_BUF_SIZE, remaining); png_memcpy(buf, data, written); /* Copy far buffer to near buffer */ - err = fwrite(buf, 1, written, io_ptr); + WRITEFILE(io_ptr, buf, written, err); if (err != written) break; else @@ -447,7 +491,7 @@ pngtest_error(png_structp png_ptr, png_const_charp message) */ typedef struct memory_information { - png_alloc_size_t size; + png_uint_32 size; png_voidp pointer; struct memory_information FAR *next; } memory_information; @@ -459,12 +503,11 @@ static int maximum_allocation = 0; static int total_allocation = 0; static int num_allocations = 0; -png_voidp png_debug_malloc - PNGARG((png_structp png_ptr, png_alloc_size_t size)); +png_voidp png_debug_malloc PNGARG((png_structp png_ptr, png_uint_32 size)); void png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr)); png_voidp -png_debug_malloc(png_structp png_ptr, png_alloc_size_t size) +png_debug_malloc(png_structp png_ptr, png_uint_32 size) { /* png_malloc has already tested for NULL; png_create_struct calls @@ -481,23 +524,24 @@ png_debug_malloc(png_structp png_ptr, png_alloc_size_t size) memory_infop pinfo; png_set_mem_fn(png_ptr, NULL, NULL, NULL); pinfo = (memory_infop)png_malloc(png_ptr, - png_sizeof(*pinfo)); + (png_uint_32)png_sizeof(*pinfo)); pinfo->size = size; current_allocation += size; total_allocation += size; num_allocations ++; if (current_allocation > maximum_allocation) maximum_allocation = current_allocation; - pinfo->pointer = png_malloc(png_ptr, size); + pinfo->pointer = (png_voidp)png_malloc(png_ptr, size); /* Restore malloc_fn and free_fn */ png_set_mem_fn(png_ptr, - NULL, png_debug_malloc, png_debug_free); + png_voidp_NULL, (png_malloc_ptr)png_debug_malloc, + (png_free_ptr)png_debug_free); if (size != 0 && pinfo->pointer == NULL) { current_allocation -= size; total_allocation -= size; png_error(png_ptr, - "out of memory in pngtest->png_debug_malloc"); + "out of memory in pngtest->png_debug_malloc."); } pinfo->next = pinformation; pinformation = pinfo; @@ -657,17 +701,30 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) #endif #endif +#ifdef _WIN32_WCE + TCHAR path[MAX_PATH]; +#endif char inbuf[256], outbuf[256]; row_buf = NULL; +#ifdef _WIN32_WCE + MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH); + if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) +#else if ((fpin = fopen(inname, "rb")) == NULL) +#endif { fprintf(STDERR, "Could not find input file %s\n", inname); return (1); } +#ifdef _WIN32_WCE + MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH); + if ((fpout = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL)) == INVALID_HANDLE_VALUE) +#else if ((fpout = fopen(outname, "wb")) == NULL) +#endif { fprintf(STDERR, "Could not open output file %s\n", outname); FCLOSE(fpin); @@ -677,12 +734,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) png_debug(0, "Allocating read and write structures"); #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG read_ptr = - png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL, - NULL, NULL, NULL, + png_create_read_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL, + png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL, (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free); #else read_ptr = - png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + png_create_read_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL, + png_error_ptr_NULL, png_error_ptr_NULL); #endif #ifndef PNG_STDIO_SUPPORTED png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error, @@ -701,11 +759,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) #ifdef PNG_WRITE_SUPPORTED #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG write_ptr = - png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL, - NULL, NULL, NULL, png_debug_malloc, png_debug_free); + png_create_write_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL, + png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL, + (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free); #else write_ptr = - png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + png_create_write_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL, + png_error_ptr_NULL, png_error_ptr_NULL); #endif #ifndef PNG_STDIO_SUPPORTED png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error, @@ -795,9 +855,9 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) else { #ifdef PNG_WRITE_SUPPORTED - png_set_write_status_fn(write_ptr, NULL); + png_set_write_status_fn(write_ptr, png_write_status_ptr_NULL); #endif - png_set_read_status_fn(read_ptr, NULL); + png_set_read_status_fn(read_ptr, png_read_status_ptr_NULL); } #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED @@ -818,14 +878,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) # define PNG_HANDLE_CHUNK_ALWAYS 3 # endif png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS, - NULL, 0); + png_bytep_NULL, 0); #endif #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED # ifndef PNG_HANDLE_CHUNK_IF_SAFE # define PNG_HANDLE_CHUNK_IF_SAFE 2 # endif png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE, - NULL, 0); + png_bytep_NULL, 0); #endif png_debug(0, "Reading info struct"); @@ -1045,23 +1105,23 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) #endif #ifdef PNG_tRNS_SUPPORTED { - png_bytep trans_alpha; + png_bytep trans; int num_trans; - png_color_16p trans_color; + png_color_16p trans_values; - if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans, - &trans_color)) + if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans, + &trans_values)) { int sample_max = (1 << read_info_ptr->bit_depth); /* libpng doesn't reject a tRNS chunk with out-of-range samples */ if (!((read_info_ptr->color_type == PNG_COLOR_TYPE_GRAY && - (int)trans_color->gray > sample_max) || + (int)trans_values->gray > sample_max) || (read_info_ptr->color_type == PNG_COLOR_TYPE_RGB && - ((int)trans_color->red > sample_max || - (int)trans_color->green > sample_max || - (int)trans_color->blue > sample_max)))) - png_set_tRNS(write_ptr, write_info_ptr, trans_alpha, num_trans, - trans_color); + ((int)trans_values->red > sample_max || + (int)trans_values->green > sample_max || + (int)trans_values->blue > sample_max)))) + png_set_tRNS(write_ptr, write_info_ptr, trans, num_trans, + trans_values); } } #endif @@ -1164,7 +1224,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) png_debug2(0, "0x%08lx (%ld bytes)", (unsigned long)row_buf, png_get_rowbytes(read_ptr, read_info_ptr)); #endif /* !SINGLE_ROWBUF_ALLOC */ - png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1); + png_read_rows(read_ptr, (png_bytepp)&row_buf, png_bytepp_NULL, 1); #ifdef PNG_WRITE_SUPPORTED #ifdef PNGTEST_TIMING @@ -1286,13 +1346,23 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) FCLOSE(fpout); png_debug(0, "Opening files for comparison"); +#ifdef _WIN32_WCE + MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH); + if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) +#else if ((fpin = fopen(inname, "rb")) == NULL) +#endif { fprintf(STDERR, "Could not find file %s\n", inname); return (1); } +#ifdef _WIN32_WCE + MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH); + if ((fpout = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) +#else if ((fpout = fopen(outname, "rb")) == NULL) +#endif { fprintf(STDERR, "Could not find file %s\n", outname); FCLOSE(fpin); @@ -1303,8 +1373,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) { png_size_t num_in, num_out; - num_in = fread(inbuf, 1, 1, fpin); - num_out = fread(outbuf, 1, 1, fpout); + READFILE(fpin, inbuf, 1, num_in); + READFILE(fpout, outbuf, 1, num_out); if (num_in != num_out) { @@ -1619,4 +1689,4 @@ main(int argc, char *argv[]) } /* Generate a compiler error if there is an old png.h in the search path. */ -typedef version_1_4_0rc01 your_png_h_is_not_version_1_4_0rc01; +typedef version_1_2_41beta14 your_png_h_is_not_version_1_2_41beta14; diff --git a/pngtrans.c b/pngtrans.c index 470c1e915..5ef2a5396 100644 --- a/pngtrans.c +++ b/pngtrans.c @@ -1,7 +1,7 @@ /* pngtrans.c - transforms the data in a row (used by both readers and writers) * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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,9 +11,9 @@ * and license in png.h */ +#define PNG_INTERNAL #include "png.h" #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) -#include "pngpriv.h" #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) /* Turn on BGR-to-RGB mapping */ @@ -117,7 +117,11 @@ png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) if (png_ptr == NULL) return; png_ptr->transformations |= PNG_FILLER; +#ifdef PNG_LEGACY_SUPPORTED + png_ptr->filler = (png_byte)filler; +#else png_ptr->filler = (png_uint_16)filler; +#endif if (filler_loc == PNG_FILLER_AFTER) png_ptr->flags |= PNG_FLAG_FILLER_AFTER; else @@ -142,6 +146,7 @@ png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) } } +#ifndef PNG_1_0_X /* Added to libpng-1.2.7 */ void PNGAPI png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) @@ -153,6 +158,7 @@ png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) png_set_filler(png_ptr, filler, filler_loc); png_ptr->transformations |= PNG_ADD_ALPHA; } +#endif #endif @@ -202,6 +208,10 @@ png_do_invert(png_row_infop row_info, png_bytep row) /* This test removed from libpng version 1.0.13 and 1.2.0: * if (row_info->bit_depth == 1 && */ +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row == NULL || row_info == NULL) + return; +#endif if (row_info->color_type == PNG_COLOR_TYPE_GRAY) { png_bytep rp = row; @@ -252,6 +262,9 @@ png_do_swap(png_row_infop row_info, png_bytep row) png_debug(1, "in png_do_swap"); if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif row_info->bit_depth == 16) { png_bytep rp = row; @@ -381,6 +394,9 @@ png_do_packswap(png_row_infop row_info, png_bytep row) png_debug(1, "in png_do_packswap"); if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif row_info->bit_depth < 8) { png_bytep rp, end, table; @@ -410,6 +426,9 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags) { png_debug(1, "in png_do_strip_filler"); +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif { png_bytep sp=row; png_bytep dp=row; @@ -567,6 +586,9 @@ png_do_bgr(png_row_infop row_info, png_bytep row) png_debug(1, "in png_do_bgr"); if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif (row_info->color_type & PNG_COLOR_MASK_COLOR)) { png_uint_32 row_width = row_info->width; @@ -635,6 +657,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row) #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) || \ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) void PNGAPI png_set_user_transform_info(png_structp png_ptr, png_voidp @@ -1,7 +1,7 @@ /* pngwio.c - functions for data output * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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.) @@ -18,9 +18,9 @@ * them at run time with png_set_write_fn(...). */ +#define PNG_INTERNAL #include "png.h" #ifdef PNG_WRITE_SUPPORTED -#include "pngpriv.h" /* Write the data to whatever output you are using. The default routine * writes to a file pointer. Note that this routine sometimes gets called @@ -52,7 +52,12 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) if (png_ptr == NULL) return; +#ifdef _WIN32_WCE + if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) + check = 0; +#else check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); +#endif if (check != length) png_error(png_ptr, "Write Error"); } @@ -79,7 +84,12 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); if ((png_bytep)near_data == data) { +#ifdef _WIN32_WCE + if ( !WriteFile(io_ptr, near_data, length, &check, NULL) ) + check = 0; +#else check = fwrite(near_data, 1, length, io_ptr); +#endif } else { @@ -91,7 +101,12 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { written = MIN(NEAR_BUF_SIZE, remaining); png_memcpy(buf, data, written); /* Copy far buffer to near buffer */ +#ifdef _WIN32_WCE + if ( !WriteFile(io_ptr, buf, written, &err, NULL) ) + err = 0; +#else err = fwrite(buf, 1, written, io_ptr); +#endif if (err != written) break; @@ -126,11 +141,15 @@ png_flush(png_structp png_ptr) void PNGAPI png_default_flush(png_structp png_ptr) { +#ifndef _WIN32_WCE png_FILE_p io_ptr; +#endif if (png_ptr == NULL) return; +#ifndef _WIN32_WCE io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); fflush(io_ptr); +#endif } #endif #endif @@ -202,7 +221,7 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, png_warning(png_ptr, "Attempted to set both read_data_fn and write_data_fn in"); png_warning(png_ptr, - "the same structure. Resetting read_data_fn to NULL"); + "the same structure. Resetting read_data_fn to NULL."); } } diff --git a/pngwrite.c b/pngwrite.c index a4e7e532a..66f585596 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -1,7 +1,7 @@ /* pngwrite.c - general routines to write a PNG file * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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.) @@ -12,9 +12,9 @@ */ /* Get internal access to png.h */ +#define PNG_INTERNAL #include "png.h" #ifdef PNG_WRITE_SUPPORTED -#include "pngpriv.h" /* Writes all the PNG information. This is the suggested way to use the * library. If you have a new chunk to add, make a function to write it, @@ -159,10 +159,10 @@ png_write_info(png_structp png_ptr, png_infop info_ptr) { int j; for (j = 0; j<(int)info_ptr->num_trans; j++) - info_ptr->trans_alpha[j] = (png_byte)(255 - info_ptr->trans_alpha[j]); + info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]); } #endif - png_write_tRNS(png_ptr, info_ptr->trans_alpha, &(info_ptr->trans_color), + png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values), info_ptr->num_trans, info_ptr->color_type); } #endif @@ -200,7 +200,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr) #endif /* FLOATING_POINT */ #else /* !WRITE_sCAL */ png_warning(png_ptr, - "png_write_sCAL not supported; sCAL chunk not written"); + "png_write_sCAL not supported; sCAL chunk not written."); #endif /* WRITE_sCAL */ #endif /* sCAL */ @@ -412,16 +412,19 @@ png_write_end(png_structp png_ptr, png_infop info_ptr) /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03, * and restored again in libpng-1.2.30, may cause some applications that * do not set png_ptr->output_flush_fn to crash. If your application - * experiences a problem, please report the event to - * png-mng-implement at lists.sf.net . + * experiences a problem, please try building libpng with + * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to + * png-mng-implement at lists.sf.net . This kludge will be removed + * from libpng-1.4.0. */ -#ifdef PNG_WRITE_FLUSH_SUPPORTED +#if defined(PNG_WRITE_FLUSH_SUPPORTED) && \ + defined(PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED) png_flush(png_ptr); #endif } -#ifdef PNG_WRITE_tIME_SUPPORTED -/* "time.h" functions are not supported on WindowsCE */ +#ifdef PNG_CONVERT_tIME_SUPPORTED +/* "tm" structure is not supported on WindowsCE */ void PNGAPI png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) { @@ -447,7 +450,6 @@ png_convert_from_time_t(png_timep ptime, time_t ttime) } #endif - /* Initialize png_ptr structure, and allocate any memory needed */ png_structp PNGAPI png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, @@ -455,7 +457,7 @@ png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, { #ifdef PNG_USER_MEM_SUPPORTED return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, - warn_fn, NULL, NULL, NULL)); + warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); } /* Alternate initialize png_ptr structure, and allocate any memory needed */ @@ -465,7 +467,6 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn) { #endif /* PNG_USER_MEM_SUPPORTED */ - int png_cleanup_needed = 0; #ifdef PNG_SETJMP_SUPPORTED volatile #endif @@ -495,15 +496,25 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, #endif #ifdef PNG_SETJMP_SUPPORTED -/* Applications that neglect to set up their own setjmp() and then - encounter a png_error() will longjmp here. Since the jmpbuf is - then meaningless we abort instead of returning. */ #ifdef USE_FAR_KEYWORD if (setjmp(jmpbuf)) #else if (setjmp(png_ptr->jmpbuf)) #endif - PNG_ABORT(); + { + png_free(png_ptr, png_ptr->zbuf); + png_ptr->zbuf = NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, + (png_free_ptr)free_fn, (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + return (NULL); + } +#ifdef USE_FAR_KEYWORD + png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); +#endif #endif #ifdef PNG_USER_MEM_SUPPORTED @@ -523,6 +534,10 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) { +#ifdef PNG_iTXt_SUPPORTED + png_size_t length; +#endif + /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so * we must recompile any applications that use any older library version. * For versions after libpng 1.0, we will be compatible, so we need @@ -549,46 +564,190 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, #ifdef PNG_ERROR_NUMBERS_SUPPORTED png_ptr->flags = 0; #endif - png_warning(png_ptr, + png_error(png_ptr, "Incompatible libpng version in application and library"); - png_cleanup_needed = 1; } +#ifdef PNG_iTXt_SUPPORTED + + /* Any library mismatch is trouble for png_set_read() in + * libpng-1.2.41 and later 1.2.x, so we store the caller's + * library version string. + */ + + length = (png_size_t)png_strlen(user_png_ver) + 1; + png_debug1(3, "allocating user_png_ver for png_ptr (%lu bytes)", + (unsigned long)length); + png_ptr->user_png_ver = (png_charp)png_malloc_warn(png_ptr, + (png_uint_32)length); + + if (png_ptr->user_png_ver == NULL) + png_warning(png_ptr, "Could not store png_ptr->user_png_ver"); + + else + png_memcpy(png_ptr->user_png_ver, user_png_ver, length); + +#endif /* PNG_iTXt_SUPPORTED */ + } /* Initialize zbuf - compression buffer */ png_ptr->zbuf_size = PNG_ZBUF_SIZE; - if (!png_cleanup_needed) + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); + + png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, + png_flush_ptr_NULL); + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, + 1, png_doublep_NULL, png_doublep_NULL); +#endif + +#ifdef PNG_SETJMP_SUPPORTED + /* Applications that neglect to set up their own setjmp() and then + * encounter a png_error() will longjmp here. Since the jmpbuf is + * then meaningless we abort instead of returning. + */ +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) + PNG_ABORT(); + png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); +#else + if (setjmp(png_ptr->jmpbuf)) + PNG_ABORT(); +#endif +#endif + return (png_ptr); +} + +/* Initialize png_ptr structure, and allocate any memory needed */ +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* Deprecated. */ +#undef png_write_init +void PNGAPI +png_write_init(png_structp png_ptr) +{ + /* We only come here via pre-1.0.7-compiled applications */ + png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0); +} + +void PNGAPI +png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size, png_size_t png_info_size) +{ + /* We only come here via pre-1.0.12-compiled applications */ + if (png_ptr == NULL) return; +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) + if (png_sizeof(png_struct) > png_struct_size || + png_sizeof(png_info) > png_info_size) { - png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, - png_ptr->zbuf_size); - if (png_ptr->zbuf == NULL) - png_cleanup_needed = 1; + char msg[80]; + png_ptr->warning_fn = NULL; + if (user_png_ver) + { + png_snprintf(msg, 80, + "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + png_snprintf(msg, 80, + "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); } - if (png_cleanup_needed) +#endif + if (png_sizeof(png_struct) > png_struct_size) { - /* Clean up PNG structure and deallocate any memory. */ - png_free(png_ptr, png_ptr->zbuf); - png_ptr->zbuf = NULL; -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)png_ptr, - (png_free_ptr)free_fn, (png_voidp)mem_ptr); + png_ptr->error_fn = NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags = 0; +#endif + png_error(png_ptr, + "The png struct allocated by the application for writing is too small."); + } + if (png_sizeof(png_info) > png_info_size) + { + png_ptr->error_fn = NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags = 0; +#endif + png_error(png_ptr, + "The info struct allocated by the application for writing is too small."); + } + png_write_init_3(&png_ptr, user_png_ver, png_struct_size); +} +#endif /* PNG_1_0_X || PNG_1_2_X */ + + +void PNGAPI +png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size) +{ + png_structp png_ptr = *ptr_ptr; +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf tmp_jmp; /* to save current jump buffer */ +#endif + + int i = 0; + + if (png_ptr == NULL) + return; + + do + { + if (user_png_ver[i] != png_libpng_ver[i]) + { +#ifdef PNG_LEGACY_SUPPORTED + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; #else - png_destroy_struct((png_voidp)png_ptr); + png_ptr->warning_fn = NULL; + png_warning(png_ptr, + "Application uses deprecated png_write_init() and should be recompiled."); #endif - return (NULL); + } + } while (png_libpng_ver[i++]); + + png_debug(1, "in png_write_init_3"); + +#ifdef PNG_SETJMP_SUPPORTED + /* Save jump buffer and error functions */ + png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); +#endif + + if (png_sizeof(png_struct) > png_struct_size) + { + png_destroy_struct(png_ptr); + png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); + *ptr_ptr = png_ptr; } - png_set_write_fn(png_ptr, NULL, NULL, NULL); + /* Reset all variables to 0 */ + png_memset(png_ptr, 0, png_sizeof(png_struct)); + + /* Added at libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + png_ptr->user_width_max = PNG_USER_WIDTH_MAX; + png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; +#endif + +#ifdef PNG_SETJMP_SUPPORTED + /* Restore jump buffer */ + png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); +#endif + + png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, + png_flush_ptr_NULL); + /* Initialize zbuf - compression buffer */ + png_ptr->zbuf_size = PNG_ZBUF_SIZE; + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, - 1, NULL, NULL); + 1, png_doublep_NULL, png_doublep_NULL); #endif - - return (png_ptr); } - /* Write a few rows of image data. If the image is interlaced, * either you will have to write the 7 sub images, or, if you * have called png_set_interlace_handling(), you will have to @@ -663,36 +822,36 @@ png_write_row(png_structp png_ptr, png_bytep row) /* Make sure we wrote the header info */ if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) png_error(png_ptr, - "png_write_info was never called before png_write_row"); + "png_write_info was never called before png_write_row."); /* Check for transforms that have been set but were defined out */ #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) if (png_ptr->transformations & PNG_INVERT_MONO) - png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined."); #endif #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED) if (png_ptr->transformations & PNG_FILLER) - png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined."); #endif #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED) if (png_ptr->transformations & PNG_PACKSWAP) - png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined."); #endif #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED) if (png_ptr->transformations & PNG_PACK) - png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined."); #endif #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED) if (png_ptr->transformations & PNG_SHIFT) - png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined."); #endif #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED) if (png_ptr->transformations & PNG_BGR) - png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined."); #endif #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED) if (png_ptr->transformations & PNG_SWAP_BYTES) - png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined"); + png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined."); #endif png_write_start_row(png_ptr); @@ -776,7 +935,8 @@ png_write_row(png_structp png_ptr, png_bytep row) png_debug1(3, "row_info->rowbytes = %lu", png_ptr->row_info.rowbytes); /* Copy user's row into buffer, leaving room for filter byte. */ - png_memcpy(png_ptr->row_buf + 1, row, png_ptr->row_info.rowbytes); + png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row, + png_ptr->row_info.rowbytes); #ifdef PNG_WRITE_INTERLACING_SUPPORTED /* Handle interlacing */ @@ -934,6 +1094,7 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) 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 @@ -1016,6 +1177,11 @@ png_write_destroy(png_structp png_ptr) free_fn = png_ptr->free_fn; #endif +/* New member added in libpng-1.2.41, will be removed from 1.4.0 */ +#ifdef PNG_iTXt_SUPPORTED + png_free(png_ptr, png_ptr->user_png_ver); +#endif + png_memset(png_ptr, 0, png_sizeof(png_struct)); png_ptr->error_fn = error_fn; @@ -1432,12 +1598,6 @@ png_write_png(png_structp png_ptr, png_infop info_ptr, png_set_invert_alpha(png_ptr); #endif -#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED - /* Invert the alpha channel from opacity to transparency */ - if (transforms & PNG_TRANSFORM_INVERT_ALPHA) - png_set_invert_alpha(png_ptr); -#endif - /* ----------------------- end of transformations ------------------- */ /* Write the bits */ diff --git a/pngwtran.c b/pngwtran.c index 88ca5df1c..05048c009 100644 --- a/pngwtran.c +++ b/pngwtran.c @@ -1,7 +1,7 @@ /* pngwtran.c - transforms the data in a row for PNG writers * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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,9 +11,9 @@ * and license in png.h */ +#define PNG_INTERNAL #include "png.h" #ifdef PNG_WRITE_SUPPORTED -#include "pngpriv.h" /* Transform the data according to the user's wishes. The order of * transformations is significant. @@ -92,6 +92,9 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) png_debug(1, "in png_do_pack"); if (row_info->bit_depth == 8 && +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif row_info->channels == 1) { switch ((int)bit_depth) @@ -215,7 +218,11 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) { png_debug(1, "in png_do_shift"); +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL && +#else if ( +#endif row_info->color_type != PNG_COLOR_TYPE_PALETTE) { int shift_start[4], shift_dec[4]; @@ -336,6 +343,9 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_write_swap_alpha"); +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif { if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) { @@ -422,6 +432,9 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_write_invert_alpha"); +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif { if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) { @@ -511,6 +524,9 @@ png_do_write_intrapixel(png_row_infop row_info, png_bytep row) png_debug(1, "in png_do_write_intrapixel"); if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif (row_info->color_type & PNG_COLOR_MASK_COLOR)) { int bytes_per_pixel; diff --git a/pngwutil.c b/pngwutil.c index f0db36f84..741123ac6 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -1,7 +1,7 @@ /* pngwutil.c - utilities to write a PNG file * - * Last changed in libpng 1.4.0 [October 21, 2009] + * Last changed in libpng 1.2.41 [November 3, 2009] * Copyright (c) 1998-2009 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,9 +11,9 @@ * and license in png.h */ +#define PNG_INTERNAL #include "png.h" #ifdef PNG_WRITE_SUPPORTED -#include "pngpriv.h" /* Place a 32-bit number into a buffer in PNG byte order. We work * with unsigned numbers for convenience, although one supported @@ -28,7 +28,6 @@ png_save_uint_32(png_bytep buf, png_uint_32 i) buf[3] = (png_byte)(i & 0xff); } -#ifdef PNG_SAVE_INT_32_SUPPORTED /* The png_save_int_32 function assumes integers are stored in two's * complement format. If this isn't the case, then this routine needs to * be modified to write data in two's complement format. @@ -41,7 +40,6 @@ png_save_int_32(png_bytep buf, png_int_32 i) buf[2] = (png_byte)((i >> 8) & 0xff); buf[3] = (png_byte)(i & 0xff); } -#endif /* Place a 16-bit number into a buffer in PNG byte order. * The parameter is declared unsigned int, not png_uint_16, @@ -128,7 +126,7 @@ png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name, png_memcpy(png_ptr->chunk_name, chunk_name, 4); /* Reset the crc and run it over the chunk name */ png_reset_crc(png_ptr); - png_calculate_crc(png_ptr, chunk_name, 4); + png_calculate_crc(png_ptr, chunk_name, (png_size_t)4); #ifdef PNG_IO_STATE_SUPPORTED /* Inform the I/O callback that chunk data will (possibly) be written. @@ -220,7 +218,7 @@ png_text_compress(png_structp png_ptr, if (compression >= PNG_TEXT_COMPRESSION_LAST) { -#ifdef PNG_STDIO_SUPPORTED +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) char msg[50]; png_snprintf(msg, 50, "Unknown compression type %d", compression); png_warning(png_ptr, msg); @@ -279,7 +277,7 @@ png_text_compress(png_structp png_ptr, old_ptr = comp->output_ptr; comp->output_ptr = (png_charpp)png_malloc(png_ptr, - (png_alloc_size_t) + (png_uint_32) (comp->max_output_ptr * png_sizeof(png_charpp))); png_memcpy(comp->output_ptr, old_ptr, old_max * png_sizeof(png_charp)); @@ -287,14 +285,14 @@ png_text_compress(png_structp png_ptr, } else comp->output_ptr = (png_charpp)png_malloc(png_ptr, - (png_alloc_size_t) + (png_uint_32) (comp->max_output_ptr * png_sizeof(png_charp))); } /* Save the data */ comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr, - (png_alloc_size_t)png_ptr->zbuf_size); + (png_uint_32)png_ptr->zbuf_size); png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, png_ptr->zbuf_size); comp->num_output_ptr++; @@ -331,7 +329,7 @@ png_text_compress(png_structp png_ptr, old_ptr = comp->output_ptr; /* This could be optimized to realloc() */ comp->output_ptr = (png_charpp)png_malloc(png_ptr, - (png_alloc_size_t)(comp->max_output_ptr * + (png_uint_32)(comp->max_output_ptr * png_sizeof(png_charp))); png_memcpy(comp->output_ptr, old_ptr, old_max * png_sizeof(png_charp)); @@ -339,14 +337,14 @@ png_text_compress(png_structp png_ptr, } else comp->output_ptr = (png_charpp)png_malloc(png_ptr, - (png_alloc_size_t)(comp->max_output_ptr * + (png_uint_32)(comp->max_output_ptr * png_sizeof(png_charp))); } /* Save the data */ comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr, - (png_alloc_size_t)png_ptr->zbuf_size); + (png_uint_32)png_ptr->zbuf_size); png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, png_ptr->zbuf_size); comp->num_output_ptr++; @@ -394,9 +392,11 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp) png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i], (png_size_t)png_ptr->zbuf_size); png_free(png_ptr, comp->output_ptr[i]); + comp->output_ptr[i]=NULL; } if (comp->max_output_ptr != 0) png_free(png_ptr, comp->output_ptr); + comp->output_ptr=NULL; /* Write anything left in zbuf */ if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) png_write_chunk_data(png_ptr, png_ptr->zbuf, @@ -417,7 +417,9 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int compression_type, int filter_type, int interlace_type) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_IHDR; +#endif int ret; png_byte buf[13]; /* Buffer to store the IHDR info */ @@ -593,7 +595,9 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, void /* PRIVATE */ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_PLTE; +#endif png_uint_32 i; png_colorp pal_ptr; png_byte buf[3]; @@ -656,7 +660,9 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal) void /* PRIVATE */ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_IDAT; +#endif png_debug(1, "in png_write_IDAT"); @@ -709,11 +715,13 @@ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) void /* PRIVATE */ png_write_IEND(png_structp png_ptr) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_IEND; +#endif png_debug(1, "in png_write_IEND"); - png_write_chunk(png_ptr, (png_bytep)png_IEND, NULL, + png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL, (png_size_t)0); png_ptr->mode |= PNG_HAVE_IEND; } @@ -724,7 +732,9 @@ png_write_IEND(png_structp png_ptr) void /* PRIVATE */ png_write_gAMA(png_structp png_ptr, double file_gamma) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_gAMA; +#endif png_uint_32 igamma; png_byte buf[4]; @@ -740,7 +750,9 @@ png_write_gAMA(png_structp png_ptr, double file_gamma) void /* PRIVATE */ png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_gAMA; +#endif png_byte buf[4]; png_debug(1, "in png_write_gAMA"); @@ -757,7 +769,9 @@ png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma) void /* PRIVATE */ png_write_sRGB(png_structp png_ptr, int srgb_intent) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_sRGB; +#endif png_byte buf[1]; png_debug(1, "in png_write_sRGB"); @@ -776,7 +790,9 @@ void /* PRIVATE */ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, png_charp profile, int profile_len) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_iCCP; +#endif png_size_t name_len; png_charp new_name; compression_state comp; @@ -854,12 +870,14 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, void /* PRIVATE */ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_sPLT; +#endif png_size_t name_len; png_charp new_name; png_byte entrybuf[10]; - png_size_t entry_size = (spalette->depth == 8 ? 6 : 10); - png_size_t palette_size = entry_size * spalette->nentries; + int entry_size = (spalette->depth == 8 ? 6 : 10); + int palette_size = entry_size * spalette->nentries; png_sPLT_entryp ep; #ifndef PNG_POINTER_INDEXING_SUPPORTED int i; @@ -933,7 +951,9 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette) void /* PRIVATE */ png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_sBIT; +#endif png_byte buf[4]; png_size_t size; @@ -991,7 +1011,9 @@ png_write_cHRM(png_structp png_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) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_cHRM; +#endif png_byte buf[32]; png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, @@ -1038,7 +1060,9 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x, png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, png_fixed_point blue_y) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_cHRM; +#endif png_byte buf[32]; png_debug(1, "in png_write_cHRM"); @@ -1070,10 +1094,12 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x, #ifdef PNG_WRITE_tRNS_SUPPORTED /* Write the tRNS chunk */ void /* PRIVATE */ -png_write_tRNS(png_structp png_ptr, png_bytep trans_alpha, png_color_16p tran, +png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran, int num_trans, int color_type) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_tRNS; +#endif png_byte buf[6]; png_debug(1, "in png_write_tRNS"); @@ -1086,7 +1112,7 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans_alpha, png_color_16p tran, return; } /* Write the chunk out as it is */ - png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans_alpha, + png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans, (png_size_t)num_trans); } else if (color_type == PNG_COLOR_TYPE_GRAY) @@ -1127,7 +1153,9 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans_alpha, png_color_16p tran, void /* PRIVATE */ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_bKGD; +#endif png_byte buf[6]; png_debug(1, "in png_write_bKGD"); @@ -1179,7 +1207,9 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type) void /* PRIVATE */ png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_hIST; +#endif int i; png_byte buf[3]; @@ -1249,7 +1279,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key) if ((png_byte)*kp < 0x20 || ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1)) { -#ifdef PNG_STDIO_SUPPORTED +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) char msg[40]; png_snprintf(msg, 40, @@ -1321,6 +1351,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key) if (key_len == 0) { png_free(png_ptr, *new_key); + *new_key=NULL; png_warning(png_ptr, "Zero length keyword"); } @@ -1341,7 +1372,9 @@ void /* PRIVATE */ png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text, png_size_t text_len) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_tEXt; +#endif png_size_t key_len; png_charp new_key; @@ -1380,7 +1413,9 @@ void /* PRIVATE */ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text, png_size_t text_len, int compression) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_zTXt; +#endif png_size_t key_len; char buf[1]; png_charp new_key; @@ -1438,7 +1473,9 @@ void /* PRIVATE */ png_write_iTXt(png_structp png_ptr, int compression, png_charp key, png_charp lang, png_charp lang_key, png_charp text) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_iTXt; +#endif png_size_t lang_len, key_len, lang_key_len, text_len; png_charp new_lang; png_charp new_key = NULL; @@ -1525,7 +1562,9 @@ void /* PRIVATE */ png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, int unit_type) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_oFFs; +#endif png_byte buf[9]; png_debug(1, "in png_write_oFFs"); @@ -1546,7 +1585,9 @@ void /* PRIVATE */ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_charp units, png_charpp params) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_pCAL; +#endif png_size_t purpose_len, units_len, total_len; png_uint_32p params_len; png_byte buf[10]; @@ -1565,7 +1606,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, total_len = purpose_len + units_len + 10; params_len = (png_uint_32p)png_malloc(png_ptr, - (png_alloc_size_t)(nparams * png_sizeof(png_uint_32))); + (png_uint_32)(nparams * png_sizeof(png_uint_32))); /* Find the length of each parameter, making sure we don't count the null terminator for the last parameter. */ @@ -1607,17 +1648,36 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, void /* PRIVATE */ png_write_sCAL(png_structp png_ptr, int unit, double width, double height) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_sCAL; +#endif char buf[64]; png_size_t total_len; png_debug(1, "in png_write_sCAL"); buf[0] = (char)unit; +#ifdef _WIN32_WCE +/* sprintf() function is not supported on WindowsCE */ + { + wchar_t wc_buf[32]; + size_t wc_len; + swprintf(wc_buf, TEXT("%12.12e"), width); + wc_len = wcslen(wc_buf); + WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL); + total_len = wc_len + 2; + swprintf(wc_buf, TEXT("%12.12e"), height); + wc_len = wcslen(wc_buf); + WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len, + NULL, NULL); + total_len += wc_len; + } +#else png_snprintf(buf + 1, 63, "%12.12e", width); total_len = 1 + png_strlen(buf + 1) + 1; png_snprintf(buf + total_len, 64-total_len, "%12.12e", height); total_len += png_strlen(buf + total_len); +#endif png_debug1(3, "sCAL total length = %u", (unsigned int)total_len); png_write_chunk(png_ptr, (png_bytep)png_sCAL, (png_bytep)buf, total_len); @@ -1628,7 +1688,9 @@ void /* PRIVATE */ png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width, png_charp height) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_sCAL; +#endif png_byte buf[64]; png_size_t wlen, hlen, total_len; @@ -1661,7 +1723,9 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, int unit_type) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_pHYs; +#endif png_byte buf[9]; png_debug(1, "in png_write_pHYs"); @@ -1684,7 +1748,9 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, void /* PRIVATE */ png_write_tIME(png_structp png_ptr, png_timep mod_time) { +#ifdef PNG_USE_LOCAL_ARRAYS PNG_tIME; +#endif png_byte buf[7]; png_debug(1, "in png_write_tIME"); @@ -1737,7 +1803,7 @@ png_write_start_row(png_structp png_ptr) /* Set up row buffer */ png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, - (png_alloc_size_t)buf_size); + (png_uint_32)buf_size); png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; #ifdef PNG_WRITE_FILTER_SUPPORTED @@ -1745,35 +1811,35 @@ png_write_start_row(png_structp png_ptr) if (png_ptr->do_filter & PNG_FILTER_SUB) { png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, - (png_alloc_size_t)(png_ptr->rowbytes + 1)); + (png_uint_32)(png_ptr->rowbytes + 1)); png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; } /* We only need to keep the previous row if we are using one of these. */ if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) { - /* Set up previous row buffer */ - png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, - (png_alloc_size_t)buf_size); + /* Set up previous row buffer */ + png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, + (png_uint_32)buf_size); if (png_ptr->do_filter & PNG_FILTER_UP) { png_ptr->up_row = (png_bytep)png_malloc(png_ptr, - (png_size_t)(png_ptr->rowbytes + 1)); + (png_uint_32)(png_ptr->rowbytes + 1)); png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; } if (png_ptr->do_filter & PNG_FILTER_AVG) { png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, - (png_alloc_size_t)(png_ptr->rowbytes + 1)); + (png_uint_32)(png_ptr->rowbytes + 1)); png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; } if (png_ptr->do_filter & PNG_FILTER_PAETH) { png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, - (png_size_t)(png_ptr->rowbytes + 1)); + (png_uint_32)(png_ptr->rowbytes + 1)); png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; } } @@ -1939,7 +2005,11 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) png_debug(1, "in png_do_write_interlace"); /* We don't have to do anything on the last pass (6) */ +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL && pass < 6) +#else if (pass < 6) +#endif { /* Each pixel depth is handled separately */ switch (row_info->pixel_depth) |