Changeset 846 for trunk/src/3rdparty/libpng/png.c
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/3rdparty/libpng/png.c
r561 r846 2 2 /* png.c - location for general purpose libpng functions 3 3 * 4 * Last changed in libpng 1. 2.39 [August 13, 2009]5 * Copyright (c) 1998-20 09Glenn Randers-Pehrson4 * Last changed in libpng 1.4.0 [January 3, 2010] 5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson 6 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 7 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) … … 12 12 */ 13 13 14 #define PNG_INTERNAL15 14 #define PNG_NO_EXTERN 15 #define PNG_NO_PEDANTIC_WARNINGS 16 16 #include "png.h" 17 #include "pngpriv.h" 17 18 18 19 /* Generate a compiler error if there is an old png.h in the search path. */ 19 typedef version_1_ 2_40 Your_png_h_is_not_version_1_2_40;20 typedef version_1_4_0 Your_png_h_is_not_version_1_4_0; 20 21 21 22 /* Version information for C files. This had better match the version 22 * string defined in png.h. */ 23 24 #ifdef PNG_USE_GLOBAL_ARRAYS 25 /* png_libpng_ver was changed to a function in version 1.0.5c */ 26 PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING; 27 28 #ifdef PNG_READ_SUPPORTED 29 30 /* png_sig was changed to a function in version 1.0.5c */ 31 /* Place to hold the signature string for a PNG file. */ 32 PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; 33 #endif /* PNG_READ_SUPPORTED */ 34 35 /* Invoke global declarations for constant strings for known chunk types */ 36 PNG_IHDR; 37 PNG_IDAT; 38 PNG_IEND; 39 PNG_PLTE; 40 PNG_bKGD; 41 PNG_cHRM; 42 PNG_gAMA; 43 PNG_hIST; 44 PNG_iCCP; 45 PNG_iTXt; 46 PNG_oFFs; 47 PNG_pCAL; 48 PNG_sCAL; 49 PNG_pHYs; 50 PNG_sBIT; 51 PNG_sPLT; 52 PNG_sRGB; 53 PNG_tEXt; 54 PNG_tIME; 55 PNG_tRNS; 56 PNG_zTXt; 57 58 #ifdef PNG_READ_SUPPORTED 59 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 60 61 /* Start of interlace block */ 62 PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; 63 64 /* Offset to next interlace block */ 65 PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; 66 67 /* Start of interlace block in the y direction */ 68 PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; 69 70 /* Offset to next interlace block in the y direction */ 71 PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; 72 73 /* Height of interlace block. This is not currently used - if you need 74 * it, uncomment it here and in png.h 75 PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; 76 */ 77 78 /* Mask to determine which pixels are valid in a pass */ 79 PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; 80 81 /* Mask to determine which pixels to overwrite while displaying */ 82 PNG_CONST int FARDATA png_pass_dsp_mask[] 83 = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; 84 85 #endif /* PNG_READ_SUPPORTED */ 86 #endif /* PNG_USE_GLOBAL_ARRAYS */ 23 * string defined in png.h. 24 */ 87 25 88 26 /* Tells libpng that we have already handled the first "num_bytes" bytes … … 96 34 png_set_sig_bytes(png_structp png_ptr, int num_bytes) 97 35 { 36 png_debug(1, "in png_set_sig_bytes"); 37 98 38 if (png_ptr == NULL) 99 39 return; 100 png_debug(1, "in png_set_sig_bytes"); 40 101 41 if (num_bytes > 8) 102 png_error(png_ptr, "Too many bytes for PNG signature .");42 png_error(png_ptr, "Too many bytes for PNG signature"); 103 43 104 44 png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes); … … 131 71 } 132 72 133 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)134 /* (Obsolete) function to check signature bytes. It does not allow one135 * to check a partial signature. This function might be removed in the136 * future - use png_sig_cmp(). Returns true (nonzero) if the file is PNG.137 */138 int PNGAPI139 png_check_sig(png_bytep sig, int num)140 {141 return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));142 }143 #endif144 73 #endif /* PNG_READ_SUPPORTED */ 145 74 146 75 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) 147 76 /* Function to allocate memory for zlib and clear it to 0. */ 148 #ifdef PNG_1_0_X149 voidpf PNGAPI150 #else151 77 voidpf /* PRIVATE */ 152 #endif153 78 png_zalloc(voidpf png_ptr, uInt items, uInt size) 154 79 { … … 156 81 png_structp p=(png_structp)png_ptr; 157 82 png_uint_32 save_flags=p->flags; 158 png_ uint_32num_bytes;83 png_alloc_size_t num_bytes; 159 84 160 85 if (png_ptr == NULL) … … 165 90 return (NULL); 166 91 } 167 num_bytes = (png_ uint_32)items * size;92 num_bytes = (png_alloc_size_t)items * size; 168 93 169 94 p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; … … 171 96 p->flags=save_flags; 172 97 173 #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)174 if (ptr == NULL)175 return ((voidpf)ptr);176 177 if (num_bytes > (png_uint_32)0x8000L)178 {179 png_memset(ptr, 0, (png_size_t)0x8000L);180 png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,181 (png_size_t)(num_bytes - (png_uint_32)0x8000L));182 }183 else184 {185 png_memset(ptr, 0, (png_size_t)num_bytes);186 }187 #endif188 98 return ((voidpf)ptr); 189 99 } 190 100 191 101 /* Function to free memory for zlib */ 192 #ifdef PNG_1_0_X193 void PNGAPI194 #else195 102 void /* PRIVATE */ 196 #endif197 103 png_zfree(voidpf png_ptr, voidpf ptr) 198 104 { … … 247 153 248 154 png_debug(1, "in png_create_info_struct"); 155 249 156 if (png_ptr == NULL) 250 157 return (NULL); 158 251 159 #ifdef PNG_USER_MEM_SUPPORTED 252 160 info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, … … 270 178 { 271 179 png_infop info_ptr = NULL; 180 181 png_debug(1, "in png_destroy_info_struct"); 182 272 183 if (png_ptr == NULL) 273 184 return; 274 185 275 png_debug(1, "in png_destroy_info_struct");276 186 if (info_ptr_ptr != NULL) 277 187 info_ptr = *info_ptr_ptr; … … 295 205 * instead. 296 206 */ 297 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)298 #undef png_info_init299 void PNGAPI300 png_info_init(png_infop info_ptr)301 {302 /* We only come here via pre-1.0.12-compiled applications */303 png_info_init_3(&info_ptr, 0);304 }305 #endif306 207 307 208 void PNGAPI … … 310 211 png_infop info_ptr = *ptr_ptr; 311 212 213 png_debug(1, "in png_info_init_3"); 214 312 215 if (info_ptr == NULL) 313 216 return; 314 315 png_debug(1, "in png_info_init_3");316 217 317 218 if (png_sizeof(png_info) > png_info_struct_size) … … 326 227 } 327 228 328 #ifdef PNG_FREE_ME_SUPPORTED329 229 void PNGAPI 330 230 png_data_freer(png_structp png_ptr, png_infop info_ptr, … … 332 232 { 333 233 png_debug(1, "in png_data_freer"); 234 334 235 if (png_ptr == NULL || info_ptr == NULL) 335 236 return; 237 336 238 if (freer == PNG_DESTROY_WILL_FREE_DATA) 337 239 info_ptr->free_me |= mask; … … 340 242 else 341 243 png_warning(png_ptr, 342 "Unknown freer parameter in png_data_freer."); 343 } 344 #endif 244 "Unknown freer parameter in png_data_freer"); 245 } 345 246 346 247 void PNGAPI … … 349 250 { 350 251 png_debug(1, "in png_free_data"); 252 351 253 if (png_ptr == NULL || info_ptr == NULL) 352 254 return; 353 255 354 #if defined(PNG_TEXT_SUPPORTED)256 #ifdef PNG_TEXT_SUPPORTED 355 257 /* Free text item num or (if num == -1) all text items */ 356 #ifdef PNG_FREE_ME_SUPPORTED357 258 if ((mask & PNG_FREE_TEXT) & info_ptr->free_me) 358 #else359 if (mask & PNG_FREE_TEXT)360 #endif361 259 { 362 260 if (num != -1) … … 380 278 #endif 381 279 382 #if defined(PNG_tRNS_SUPPORTED)280 #ifdef PNG_tRNS_SUPPORTED 383 281 /* Free any tRNS entry */ 384 #ifdef PNG_FREE_ME_SUPPORTED385 282 if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) 386 #else 387 if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS)) 388 #endif 389 { 390 png_free(png_ptr, info_ptr->trans); 391 info_ptr->trans = NULL; 283 { 284 png_free(png_ptr, info_ptr->trans_alpha); 285 info_ptr->trans_alpha = NULL; 392 286 info_ptr->valid &= ~PNG_INFO_tRNS; 393 #ifndef PNG_FREE_ME_SUPPORTED 394 png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; 395 #endif 396 } 397 #endif 398 399 #if defined(PNG_sCAL_SUPPORTED) 287 } 288 #endif 289 290 #ifdef PNG_sCAL_SUPPORTED 400 291 /* Free any sCAL entry */ 401 #ifdef PNG_FREE_ME_SUPPORTED402 292 if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) 403 #else404 if (mask & PNG_FREE_SCAL)405 #endif406 293 { 407 294 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) … … 415 302 #endif 416 303 417 #if defined(PNG_pCAL_SUPPORTED)304 #ifdef PNG_pCAL_SUPPORTED 418 305 /* Free any pCAL entry */ 419 #ifdef PNG_FREE_ME_SUPPORTED420 306 if ((mask & PNG_FREE_PCAL) & info_ptr->free_me) 421 #else422 if (mask & PNG_FREE_PCAL)423 #endif424 307 { 425 308 png_free(png_ptr, info_ptr->pcal_purpose); … … 433 316 { 434 317 png_free(png_ptr, info_ptr->pcal_params[i]); 435 info_ptr->pcal_params[i] =NULL;318 info_ptr->pcal_params[i] = NULL; 436 319 } 437 320 png_free(png_ptr, info_ptr->pcal_params); … … 442 325 #endif 443 326 444 #if defined(PNG_iCCP_SUPPORTED)327 #ifdef PNG_iCCP_SUPPORTED 445 328 /* Free any iCCP entry */ 446 #ifdef PNG_FREE_ME_SUPPORTED447 329 if ((mask & PNG_FREE_ICCP) & info_ptr->free_me) 448 #else449 if (mask & PNG_FREE_ICCP)450 #endif451 330 { 452 331 png_free(png_ptr, info_ptr->iccp_name); … … 458 337 #endif 459 338 460 #if defined(PNG_sPLT_SUPPORTED)339 #ifdef PNG_sPLT_SUPPORTED 461 340 /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ 462 #ifdef PNG_FREE_ME_SUPPORTED463 341 if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) 464 #else465 if (mask & PNG_FREE_SPLT)466 #endif467 342 { 468 343 if (num != -1) … … 493 368 #endif 494 369 495 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)370 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED 496 371 if (png_ptr->unknown_chunk.data) 497 372 { … … 500 375 } 501 376 502 #ifdef PNG_FREE_ME_SUPPORTED503 377 if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) 504 #else505 if (mask & PNG_FREE_UNKN)506 #endif507 378 { 508 379 if (num != -1) … … 531 402 #endif 532 403 533 #if defined(PNG_hIST_SUPPORTED)404 #ifdef PNG_hIST_SUPPORTED 534 405 /* Free any hIST entry */ 535 #ifdef PNG_FREE_ME_SUPPORTED536 406 if ((mask & PNG_FREE_HIST) & info_ptr->free_me) 537 #else538 if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))539 #endif540 407 { 541 408 png_free(png_ptr, info_ptr->hist); 542 409 info_ptr->hist = NULL; 543 410 info_ptr->valid &= ~PNG_INFO_hIST; 544 #ifndef PNG_FREE_ME_SUPPORTED545 png_ptr->flags &= ~PNG_FLAG_FREE_HIST;546 #endif547 411 } 548 412 #endif 549 413 550 414 /* Free any PLTE entry that was internally allocated */ 551 #ifdef PNG_FREE_ME_SUPPORTED552 415 if ((mask & PNG_FREE_PLTE) & info_ptr->free_me) 553 #else554 if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))555 #endif556 416 { 557 417 png_zfree(png_ptr, info_ptr->palette); 558 418 info_ptr->palette = NULL; 559 419 info_ptr->valid &= ~PNG_INFO_PLTE; 560 #ifndef PNG_FREE_ME_SUPPORTED561 png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;562 #endif563 420 info_ptr->num_palette = 0; 564 421 } 565 422 566 #if defined(PNG_INFO_IMAGE_SUPPORTED)423 #ifdef PNG_INFO_IMAGE_SUPPORTED 567 424 /* Free any image bits attached to the info structure */ 568 #ifdef PNG_FREE_ME_SUPPORTED569 425 if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) 570 #else571 if (mask & PNG_FREE_ROWS)572 #endif573 426 { 574 427 if (info_ptr->row_pointers) … … 578 431 { 579 432 png_free(png_ptr, info_ptr->row_pointers[row]); 580 info_ptr->row_pointers[row] =NULL;433 info_ptr->row_pointers[row] = NULL; 581 434 } 582 435 png_free(png_ptr, info_ptr->row_pointers); 583 info_ptr->row_pointers =NULL;436 info_ptr->row_pointers = NULL; 584 437 } 585 438 info_ptr->valid &= ~PNG_INFO_IDAT; … … 587 440 #endif 588 441 589 #ifdef PNG_FREE_ME_SUPPORTED590 442 if (num == -1) 591 443 info_ptr->free_me &= ~mask; 592 444 else 593 445 info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL); 594 #endif595 446 } 596 447 … … 606 457 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); 607 458 608 #if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)459 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED 609 460 if (png_ptr->num_chunk_list) 610 461 { 611 462 png_free(png_ptr, png_ptr->chunk_list); 612 png_ptr->chunk_list =NULL;463 png_ptr->chunk_list = NULL; 613 464 png_ptr->num_chunk_list = 0; 614 465 } … … 632 483 633 484 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) 634 #if !defined(PNG_NO_STDIO)485 #ifdef PNG_STDIO_SUPPORTED 635 486 /* Initialize the default input/output functions for the PNG file. If you 636 487 * use your own read or write routines, you can call either png_set_read_fn() … … 643 494 { 644 495 png_debug(1, "in png_init_io"); 496 645 497 if (png_ptr == NULL) 646 498 return; 499 647 500 png_ptr->io_ptr = (png_voidp)fp; 648 501 } 649 502 #endif 650 503 651 #if defined(PNG_TIME_RFC1123_SUPPORTED)504 #ifdef PNG_TIME_RFC1123_SUPPORTED 652 505 /* Convert the supplied time into an RFC 1123 string suitable for use in 653 506 * a "Creation Time" or other text-based time string. … … 668 521 } 669 522 670 #if defined(_WIN32_WCE)671 {672 wchar_t time_buf[29];673 wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),674 ptime->day % 32, short_months[(ptime->month - 1) % 12],675 ptime->year, ptime->hour % 24, ptime->minute % 60,676 ptime->second % 61);677 WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,678 NULL, NULL);679 }680 #else681 523 #ifdef USE_FAR_KEYWORD 682 524 { … … 695 537 ptime->second % 61); 696 538 #endif 697 #endif /* _WIN32_WCE */698 539 return ((png_charp)png_ptr->time_buffer); 699 540 } … … 706 547 { 707 548 png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ 708 return ((png_charp) "\n libpng version 1.2.40 - September 10, 2009\n\ 709 Copyright (c) 1998-2009 Glenn Randers-Pehrson\n\ 710 Copyright (c) 1996-1997 Andreas Dilger\n\ 711 Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n"); 549 #ifdef PNG_STRING_COPYRIGHT 550 return PNG_STRING_COPYRIGHT 551 #else 552 #ifdef __STDC__ 553 return ((png_charp) PNG_STRING_NEWLINE \ 554 "libpng version 1.4.0 - January 3, 2010" PNG_STRING_NEWLINE \ 555 "Copyright (c) 1998-2010 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ 556 "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ 557 "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ 558 PNG_STRING_NEWLINE); 559 #else 560 return ((png_charp) "libpng version 1.4.0 - January 3, 2010\ 561 Copyright (c) 1998-2010 Glenn Randers-Pehrson\ 562 Copyright (c) 1996-1997 Andreas Dilger\ 563 Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."); 564 #endif 565 #endif 712 566 } 713 567 … … 741 595 /* Returns longer string containing both version and date */ 742 596 png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ 597 #ifdef __STDC__ 743 598 return ((png_charp) PNG_HEADER_VERSION_STRING 744 599 #ifndef PNG_READ_SUPPORTED 745 600 " (NO READ SUPPORT)" 746 601 #endif 747 "\n"); 602 PNG_STRING_NEWLINE); 603 #else 604 return ((png_charp) PNG_HEADER_VERSION_STRING); 605 #endif 748 606 } 749 607 … … 785 643 786 644 787 #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)788 #if !defined(PNG_1_0_X)789 /* This function was added to libpng 1.2.0 */790 int PNGAPI791 png_mmx_support(void)792 {793 /* Obsolete, to be removed from libpng-1.4.0 */794 return -1;795 }796 #endif /* PNG_1_0_X */797 #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */798 645 799 646 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) … … 811 658 812 659 /* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */ 813 #if defined(PNG_cHRM_SUPPORTED)814 #if !defined(PNG_NO_CHECK_cHRM)660 #ifdef PNG_cHRM_SUPPORTED 661 #ifdef PNG_CHECK_cHRM_SUPPORTED 815 662 816 663 /* … … 864 711 865 712 png_debug(1, "in function png_check_cHRM_fixed"); 713 866 714 if (png_ptr == NULL) 867 715 return 0; … … 922 770 return ret; 923 771 } 924 #endif /* NO_PNG_CHECK_cHRM*/772 #endif /* PNG_CHECK_cHRM_SUPPORTED */ 925 773 #endif /* PNG_cHRM_SUPPORTED */ 774 775 void /* PRIVATE */ 776 png_check_IHDR(png_structp png_ptr, 777 png_uint_32 width, png_uint_32 height, int bit_depth, 778 int color_type, int interlace_type, int compression_type, 779 int filter_type) 780 { 781 int error = 0; 782 783 /* Check for width and height valid values */ 784 if (width == 0) 785 { 786 png_warning(png_ptr, "Image width is zero in IHDR"); 787 error = 1; 788 } 789 790 if (height == 0) 791 { 792 png_warning(png_ptr, "Image height is zero in IHDR"); 793 error = 1; 794 } 795 796 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 797 if (width > png_ptr->user_width_max || width > PNG_USER_WIDTH_MAX) 798 #else 799 if (width > PNG_USER_WIDTH_MAX) 800 #endif 801 { 802 png_warning(png_ptr, "Image width exceeds user limit in IHDR"); 803 error = 1; 804 } 805 806 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 807 if (height > png_ptr->user_height_max || height > PNG_USER_HEIGHT_MAX) 808 #else 809 if (height > PNG_USER_HEIGHT_MAX) 810 #endif 811 { 812 png_warning(png_ptr, "Image height exceeds user limit in IHDR"); 813 error = 1; 814 } 815 816 if (width > PNG_UINT_31_MAX) 817 { 818 png_warning(png_ptr, "Invalid image width in IHDR"); 819 error = 1; 820 } 821 822 if ( height > PNG_UINT_31_MAX) 823 { 824 png_warning(png_ptr, "Invalid image height in IHDR"); 825 error = 1; 826 } 827 828 if ( width > (PNG_UINT_32_MAX 829 >> 3) /* 8-byte RGBA pixels */ 830 - 64 /* bigrowbuf hack */ 831 - 1 /* filter byte */ 832 - 7*8 /* rounding of width to multiple of 8 pixels */ 833 - 8) /* extra max_pixel_depth pad */ 834 png_warning(png_ptr, "Width is too large for libpng to process pixels"); 835 836 /* Check other values */ 837 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && 838 bit_depth != 8 && bit_depth != 16) 839 { 840 png_warning(png_ptr, "Invalid bit depth in IHDR"); 841 error = 1; 842 } 843 844 if (color_type < 0 || color_type == 1 || 845 color_type == 5 || color_type > 6) 846 { 847 png_warning(png_ptr, "Invalid color type in IHDR"); 848 error = 1; 849 } 850 851 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || 852 ((color_type == PNG_COLOR_TYPE_RGB || 853 color_type == PNG_COLOR_TYPE_GRAY_ALPHA || 854 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) 855 { 856 png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR"); 857 error = 1; 858 } 859 860 if (interlace_type >= PNG_INTERLACE_LAST) 861 { 862 png_warning(png_ptr, "Unknown interlace method in IHDR"); 863 error = 1; 864 } 865 866 if (compression_type != PNG_COMPRESSION_TYPE_BASE) 867 { 868 png_warning(png_ptr, "Unknown compression method in IHDR"); 869 error = 1; 870 } 871 872 #ifdef PNG_MNG_FEATURES_SUPPORTED 873 /* Accept filter_method 64 (intrapixel differencing) only if 874 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and 875 * 2. Libpng did not read a PNG signature (this filter_method is only 876 * used in PNG datastreams that are embedded in MNG datastreams) and 877 * 3. The application called png_permit_mng_features with a mask that 878 * included PNG_FLAG_MNG_FILTER_64 and 879 * 4. The filter_method is 64 and 880 * 5. The color_type is RGB or RGBA 881 */ 882 if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) && 883 png_ptr->mng_features_permitted) 884 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); 885 886 if (filter_type != PNG_FILTER_TYPE_BASE) 887 { 888 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 889 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && 890 ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) && 891 (color_type == PNG_COLOR_TYPE_RGB || 892 color_type == PNG_COLOR_TYPE_RGB_ALPHA))) 893 { 894 png_warning(png_ptr, "Unknown filter method in IHDR"); 895 error = 1; 896 } 897 898 if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) 899 { 900 png_warning(png_ptr, "Invalid filter method in IHDR"); 901 error = 1; 902 } 903 } 904 905 #else 906 if (filter_type != PNG_FILTER_TYPE_BASE) 907 { 908 png_warning(png_ptr, "Unknown filter method in IHDR"); 909 error = 1; 910 } 911 #endif 912 913 if (error == 1) 914 png_error(png_ptr, "Invalid IHDR data"); 915 } 926 916 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
Note:
See TracChangeset
for help on using the changeset viewer.