Changeset 44 for cafu/trunk/ExtLibs/libpng/pngrutil.c
- Timestamp:
- 02/15/10 11:56:43 (2 years ago)
- Files:
-
- 1 modified
-
cafu/trunk/ExtLibs/libpng/pngrutil.c (modified) (67 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cafu/trunk/ExtLibs/libpng/pngrutil.c
r11 r44 2 2 /* pngrutil.c - utilities to read a PNG file 3 3 * 4 * Last changed in libpng 1.2. 38 [July 16, 2009]4 * Last changed in libpng 1.2.41 [December 3, 2009] 5 5 * Copyright (c) 1998-2009 Glenn Randers-Pehrson 6 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) … … 16 16 17 17 #define PNG_INTERNAL 18 #define PNG_NO_PEDANTIC_WARNINGS 18 19 #include "png.h" 19 #if defined(PNG_READ_SUPPORTED)20 #ifdef PNG_READ_SUPPORTED 20 21 21 22 #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500) … … 24 25 25 26 #ifdef PNG_FLOATING_POINT_SUPPORTED 26 # if defined(WIN32_WCE_OLD)27 # ifdef WIN32_WCE_OLD 27 28 /* The strtod() function is not supported on WindowsCE */ 28 29 __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr) … … 229 230 png_size_t prefix_size, png_size_t *newlength) 230 231 { 231 static PNG_CONST char msg[] = "Error decoding compressed text";232 static PNG_CONST char msg[] = "Error decoding compressed chunk"; 232 233 png_charp text; 233 234 png_size_t text_size; … … 303 304 304 305 tmp = text; 305 text = (png_charp)png_malloc_warn(png_ptr,306 (png_uint_32)(text_size +307 png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));306 text = (png_charp)png_malloc_warn(png_ptr, 307 (png_uint_32)(text_size + 308 png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1)); 308 309 if (text == NULL) 309 310 { … … 332 333 if (ret != Z_STREAM_END) 333 334 { 334 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)335 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 335 336 char umsg[52]; 336 337 … … 379 380 else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ 380 381 { 381 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)382 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 382 383 char umsg[50]; 383 384 … … 431 432 png_ptr->interlaced = (png_byte)interlace_type; 432 433 png_ptr->color_type = (png_byte)color_type; 433 #if defined(PNG_MNG_FEATURES_SUPPORTED)434 #ifdef PNG_MNG_FEATURES_SUPPORTED 434 435 png_ptr->filter_type = (png_byte)filter_type; 435 436 #endif … … 474 475 png_color palette[PNG_MAX_PALETTE_LENGTH]; 475 476 int num, i; 476 #if ndef PNG_NO_POINTER_INDEXING477 #ifdef PNG_POINTER_INDEXING_SUPPORTED 477 478 png_colorp pal_ptr; 478 479 #endif … … 502 503 return; 503 504 } 504 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)505 #ifndef PNG_READ_OPT_PLTE_SUPPORTED 505 506 if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) 506 507 { … … 527 528 num = (int)length / 3; 528 529 529 #if ndef PNG_NO_POINTER_INDEXING530 #ifdef PNG_POINTER_INDEXING_SUPPORTED 530 531 for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) 531 532 { … … 555 556 * we will act as though it is. 556 557 */ 557 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)558 #ifndef PNG_READ_OPT_PLTE_SUPPORTED 558 559 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 559 560 #endif … … 561 562 png_crc_finish(png_ptr, 0); 562 563 } 563 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)564 #ifndef PNG_READ_OPT_PLTE_SUPPORTED 564 565 else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */ 565 566 { … … 590 591 png_set_PLTE(png_ptr, info_ptr, palette, num); 591 592 592 #if defined(PNG_READ_tRNS_SUPPORTED)593 #ifdef PNG_READ_tRNS_SUPPORTED 593 594 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 594 595 { … … 632 633 } 633 634 634 #if defined(PNG_READ_gAMA_SUPPORTED)635 #ifdef PNG_READ_gAMA_SUPPORTED 635 636 void /* PRIVATE */ 636 637 png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 657 658 658 659 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) 659 #if defined(PNG_READ_sRGB_SUPPORTED)660 #ifdef PNG_READ_sRGB_SUPPORTED 660 661 && !(info_ptr->valid & PNG_INFO_sRGB) 661 662 #endif … … 687 688 } 688 689 689 #if defined(PNG_READ_sRGB_SUPPORTED)690 #ifdef PNG_READ_sRGB_SUPPORTED 690 691 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) 691 692 if (PNG_OUT_OF_RANGE(igamma, 45500L, 500)) … … 693 694 png_warning(png_ptr, 694 695 "Ignoring incorrect gAMA value when sRGB is also present"); 695 #if ndef PNG_NO_CONSOLE_IO696 #ifdef PNG_CONSOLE_IO_SUPPORTED 696 697 fprintf(stderr, "gamma = (%d/100000)", (int)igamma); 697 698 #endif … … 713 714 #endif 714 715 715 #if defined(PNG_READ_sBIT_SUPPORTED)716 #ifdef PNG_READ_sBIT_SUPPORTED 716 717 void /* PRIVATE */ 717 718 png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 779 780 #endif 780 781 781 #if defined(PNG_READ_cHRM_SUPPORTED)782 #ifdef PNG_READ_cHRM_SUPPORTED 782 783 void /* PRIVATE */ 783 784 png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 807 808 808 809 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM) 809 #if defined(PNG_READ_sRGB_SUPPORTED)810 #ifdef PNG_READ_sRGB_SUPPORTED 810 811 && !(info_ptr->valid & PNG_INFO_sRGB) 811 812 #endif … … 859 860 #endif 860 861 861 #if defined(PNG_READ_sRGB_SUPPORTED)862 #ifdef PNG_READ_sRGB_SUPPORTED 862 863 if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB)) 863 864 { … … 873 874 png_warning(png_ptr, 874 875 "Ignoring incorrect cHRM value when sRGB is also present"); 875 #if ndef PNG_NO_CONSOLE_IO876 #ifdef PNG_CONSOLE_IO_SUPPORTED 876 877 #ifdef PNG_FLOATING_POINT_SUPPORTED 877 878 fprintf(stderr, "wx=%f, wy=%f, rx=%f, ry=%f\n", … … 885 886 int_x_green, int_y_green, int_x_blue, int_y_blue); 886 887 #endif 887 #endif /* PNG_ NO_CONSOLE_IO*/888 #endif /* PNG_CONSOLE_IO_SUPPORTED */ 888 889 } 889 890 return; … … 903 904 #endif 904 905 905 #if defined(PNG_READ_sRGB_SUPPORTED)906 #ifdef PNG_READ_sRGB_SUPPORTED 906 907 void /* PRIVATE */ 907 908 png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 965 966 png_warning(png_ptr, 966 967 "Ignoring incorrect gAMA value when sRGB is also present"); 967 #if ndef PNG_NO_CONSOLE_IO968 #ifdef PNG_CONSOLE_IO_SUPPORTED 968 969 # ifdef PNG_FIXED_POINT_SUPPORTED 969 970 fprintf(stderr, "incorrect gamma=(%d/100000)\n", … … 1001 1002 #endif /* PNG_READ_sRGB_SUPPORTED */ 1002 1003 1003 #if defined(PNG_READ_iCCP_SUPPORTED)1004 #ifdef PNG_READ_iCCP_SUPPORTED 1004 1005 void /* PRIVATE */ 1005 1006 png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 1121 1122 #endif /* PNG_READ_iCCP_SUPPORTED */ 1122 1123 1123 #if defined(PNG_READ_sPLT_SUPPORTED)1124 #ifdef PNG_READ_sPLT_SUPPORTED 1124 1125 void /* PRIVATE */ 1125 1126 png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 1128 1129 png_bytep entry_start; 1129 1130 png_sPLT_t new_palette; 1130 #ifdef PNG_ NO_POINTER_INDEXING1131 #ifdef PNG_POINTER_INDEXING_SUPPORTED 1131 1132 png_sPLT_entryp pp; 1132 1133 #endif … … 1136 1137 1137 1138 png_debug(1, "in png_handle_sPLT"); 1138 1139 1139 1140 1140 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 1211 1211 } 1212 1212 1213 #if ndef PNG_NO_POINTER_INDEXING1213 #ifdef PNG_POINTER_INDEXING_SUPPORTED 1214 1214 for (i = 0; i < new_palette.nentries; i++) 1215 1215 { 1216 p ng_sPLT_entryp pp = new_palette.entries + i;1216 pp = new_palette.entries + i; 1217 1217 1218 1218 if (new_palette.depth == 8) … … 1266 1266 #endif /* PNG_READ_sPLT_SUPPORTED */ 1267 1267 1268 #if defined(PNG_READ_tRNS_SUPPORTED)1268 #ifdef PNG_READ_tRNS_SUPPORTED 1269 1269 void /* PRIVATE */ 1270 1270 png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 1361 1361 #endif 1362 1362 1363 #if defined(PNG_READ_bKGD_SUPPORTED)1363 #ifdef PNG_READ_bKGD_SUPPORTED 1364 1364 void /* PRIVATE */ 1365 1365 png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 1450 1450 #endif 1451 1451 1452 #if defined(PNG_READ_hIST_SUPPORTED)1452 #ifdef PNG_READ_hIST_SUPPORTED 1453 1453 void /* PRIVATE */ 1454 1454 png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 1504 1504 #endif 1505 1505 1506 #if defined(PNG_READ_pHYs_SUPPORTED)1506 #ifdef PNG_READ_pHYs_SUPPORTED 1507 1507 void /* PRIVATE */ 1508 1508 png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 1547 1547 #endif 1548 1548 1549 #if defined(PNG_READ_oFFs_SUPPORTED)1549 #ifdef PNG_READ_oFFs_SUPPORTED 1550 1550 void /* PRIVATE */ 1551 1551 png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 1590 1590 #endif 1591 1591 1592 #if defined(PNG_READ_pCAL_SUPPORTED)1592 #ifdef PNG_READ_pCAL_SUPPORTED 1593 1593 /* Read the pCAL chunk (described in the PNG Extensions document) */ 1594 1594 void /* PRIVATE */ … … 1724 1724 #endif 1725 1725 1726 #if defined(PNG_READ_sCAL_SUPPORTED)1726 #ifdef PNG_READ_sCAL_SUPPORTED 1727 1727 /* Read the sCAL chunk */ 1728 1728 void /* PRIVATE */ … … 1867 1867 #endif 1868 1868 1869 #if defined(PNG_READ_tIME_SUPPORTED)1869 #ifdef PNG_READ_tIME_SUPPORTED 1870 1870 void /* PRIVATE */ 1871 1871 png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 1910 1910 #endif 1911 1911 1912 #if defined(PNG_READ_tEXt_SUPPORTED)1912 #ifdef PNG_READ_tEXt_SUPPORTED 1913 1913 /* Note: this does not properly handle chunks that are > 64K under DOS */ 1914 1914 void /* PRIVATE */ … … 1924 1924 png_debug(1, "in png_handle_tEXt"); 1925 1925 1926 1927 1926 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 1928 1927 png_error(png_ptr, "Missing IHDR before tEXt"); … … 1997 1996 #endif 1998 1997 1999 #if defined(PNG_READ_zTXt_SUPPORTED)1998 #ifdef PNG_READ_zTXt_SUPPORTED 2000 1999 /* Note: this does not correctly handle chunks that are > 64K under DOS */ 2001 2000 void /* PRIVATE */ … … 2009 2008 2010 2009 png_debug(1, "in png_handle_zTXt"); 2011 2012 2010 2013 2011 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 2101 2099 #endif 2102 2100 2103 #if defined(PNG_READ_iTXt_SUPPORTED)2101 #ifdef PNG_READ_iTXt_SUPPORTED 2104 2102 /* Note: this does not correctly handle chunks that are > 64K under DOS */ 2105 2103 void /* PRIVATE */ … … 2114 2112 2115 2113 png_debug(1, "in png_handle_iTXt"); 2116 2117 2114 2118 2115 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 2243 2240 png_debug(1, "in png_handle_unknown"); 2244 2241 2245 2246 2242 if (png_ptr->mode & PNG_HAVE_IDAT) 2247 2243 { … … 2255 2251 if (!(png_ptr->chunk_name[0] & 0x20)) 2256 2252 { 2257 #if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)2253 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED 2258 2254 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != 2259 2255 PNG_HANDLE_CHUNK_ALWAYS 2260 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)2256 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED 2261 2257 && png_ptr->read_user_chunk_fn == NULL 2262 2258 #endif … … 2266 2262 } 2267 2263 2268 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)2264 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED 2269 2265 if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) 2270 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)2266 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED 2271 2267 || (png_ptr->read_user_chunk_fn != NULL) 2272 2268 #endif … … 2293 2289 png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); 2294 2290 } 2295 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)2291 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED 2296 2292 if (png_ptr->read_user_chunk_fn != NULL) 2297 2293 { … … 2305 2301 { 2306 2302 if (!(png_ptr->chunk_name[0] & 0x20)) 2307 #if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)2303 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED 2308 2304 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != 2309 2305 PNG_HANDLE_CHUNK_ALWAYS) … … 2326 2322 png_crc_finish(png_ptr, skip); 2327 2323 2328 #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)2324 #ifndef PNG_READ_USER_CHUNKS_SUPPORTED 2329 2325 info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */ 2330 2326 #endif … … 2384 2380 png_uint_32 row_width = png_ptr->width; 2385 2381 2386 #if defined(PNG_READ_PACKSWAP_SUPPORTED)2382 #ifdef PNG_READ_PACKSWAP_SUPPORTED 2387 2383 if (png_ptr->transformations & PNG_PACKSWAP) 2388 2384 { … … 2439 2435 int value; 2440 2436 2441 #if defined(PNG_READ_PACKSWAP_SUPPORTED)2437 #ifdef PNG_READ_PACKSWAP_SUPPORTED 2442 2438 if (png_ptr->transformations & PNG_PACKSWAP) 2443 2439 { … … 2491 2487 int value; 2492 2488 2493 #if defined(PNG_READ_PACKSWAP_SUPPORTED)2489 #ifdef PNG_READ_PACKSWAP_SUPPORTED 2494 2490 if (png_ptr->transformations & PNG_PACKSWAP) 2495 2491 { … … 2574 2570 int pass = png_ptr->pass; 2575 2571 png_uint_32 transformations = png_ptr->transformations; 2576 #ifdef PNG_USE_LOCAL_ARRAYS2577 2572 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 2578 2573 /* Offset to next interlace block */ 2579 2574 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 2580 #endif2581 2575 2582 2576 png_debug(1, "in png_do_read_interlace"); … … 2600 2594 int j; 2601 2595 2602 #if defined(PNG_READ_PACKSWAP_SUPPORTED)2596 #ifdef PNG_READ_PACKSWAP_SUPPORTED 2603 2597 if (transformations & PNG_PACKSWAP) 2604 2598 { … … 2653 2647 png_uint_32 i; 2654 2648 2655 #if defined(PNG_READ_PACKSWAP_SUPPORTED)2649 #ifdef PNG_READ_PACKSWAP_SUPPORTED 2656 2650 if (transformations & PNG_PACKSWAP) 2657 2651 { … … 2709 2703 int jstop = png_pass_inc[pass]; 2710 2704 2711 #if defined(PNG_READ_PACKSWAP_SUPPORTED)2705 #ifdef PNG_READ_PACKSWAP_SUPPORTED 2712 2706 if (transformations & PNG_PACKSWAP) 2713 2707 { … … 2783 2777 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width); 2784 2778 } 2785 #if !defined(PNG_READ_PACKSWAP_SUPPORTED)2779 #ifndef PNG_READ_PACKSWAP_SUPPORTED 2786 2780 transformations = transformations; /* Silence compiler warning */ 2787 2781 #endif … … 2912 2906 } 2913 2907 2914 #if ndef PNG_NO_SEQUENTIAL_READ_SUPPORTED2908 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED 2915 2909 void /* PRIVATE */ 2916 2910 png_read_finish_row(png_structp png_ptr) 2917 2911 { 2918 #ifdef PNG_USE_LOCAL_ARRAYS2919 2912 #ifdef PNG_READ_INTERLACING_SUPPORTED 2920 2913 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ … … 2932 2925 PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 2933 2926 #endif /* PNG_READ_INTERLACING_SUPPORTED */ 2934 #endif2935 2927 2936 2928 png_debug(1, "in png_read_finish_row"); … … 3044 3036 png_ptr->mode |= PNG_AFTER_IDAT; 3045 3037 } 3046 #endif /* PNG_ NO_SEQUENTIAL_READ_SUPPORTED */3038 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ 3047 3039 3048 3040 void /* PRIVATE */ 3049 3041 png_read_start_row(png_structp png_ptr) 3050 3042 { 3051 #ifdef PNG_USE_LOCAL_ARRAYS3052 3043 #ifdef PNG_READ_INTERLACING_SUPPORTED 3053 3044 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ … … 3064 3055 /* Offset to next interlace block in the y direction */ 3065 3056 PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 3066 #endif3067 3057 #endif 3068 3058 … … 3099 3089 max_pixel_depth = png_ptr->pixel_depth; 3100 3090 3101 #if defined(PNG_READ_PACK_SUPPORTED)3091 #ifdef PNG_READ_PACK_SUPPORTED 3102 3092 if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8) 3103 3093 max_pixel_depth = 8; 3104 3094 #endif 3105 3095 3106 #if defined(PNG_READ_EXPAND_SUPPORTED)3096 #ifdef PNG_READ_EXPAND_SUPPORTED 3107 3097 if (png_ptr->transformations & PNG_EXPAND) 3108 3098 { … … 3132 3122 #endif 3133 3123 3134 #if defined(PNG_READ_FILLER_SUPPORTED)3124 #ifdef PNG_READ_FILLER_SUPPORTED 3135 3125 if (png_ptr->transformations & (PNG_FILLER)) 3136 3126 { … … 3154 3144 #endif 3155 3145 3156 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)3146 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED 3157 3147 if (png_ptr->transformations & PNG_GRAY_TO_RGB) 3158 3148 { 3159 3149 if ( 3160 #if defined(PNG_READ_EXPAND_SUPPORTED)3150 #ifdef PNG_READ_EXPAND_SUPPORTED 3161 3151 (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) || 3162 3152 #endif 3163 #if defined(PNG_READ_FILLER_SUPPORTED)3153 #ifdef PNG_READ_FILLER_SUPPORTED 3164 3154 (png_ptr->transformations & (PNG_FILLER)) || 3165 3155 #endif … … 3216 3206 { 3217 3207 png_free(png_ptr, png_ptr->big_row_buf); 3218 png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 64);3219 3208 if (png_ptr->interlaced) 3220 png_memset(png_ptr->big_row_buf, 0, row_bytes + 64); 3209 png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr, 3210 row_bytes + 64); 3211 else 3212 png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, 3213 row_bytes + 64); 3214 png_ptr->old_big_row_buf_size = row_bytes + 64; 3215 3216 /* Use 32 bytes of padding before and after row_buf. */ 3221 3217 png_ptr->row_buf = png_ptr->big_row_buf + 32; 3222 3218 png_ptr->old_big_row_buf_size = row_bytes + 64;
