Changeset 43 for vendor/libpng/png.c

Show
Ignore:
Timestamp:
02/15/10 11:37:15 (2 years ago)
Author:
Carsten
Message:

Upgraded vendor/libpng from 1.2.40 to 1.2.42.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vendor/libpng/png.c

    r11 r43  
    22/* png.c - location for general purpose libpng functions 
    33 * 
    4  * Last changed in libpng 1.2.39 [August 13, 2009] 
    5  * Copyright (c) 1998-2009 Glenn Randers-Pehrson 
     4 * Last changed in libpng 1.2.42 [January 3, 2010] 
     5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson 
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 
     
    1414#define PNG_INTERNAL 
    1515#define PNG_NO_EXTERN 
     16#define PNG_NO_PEDANTIC_WARNINGS 
    1617#include "png.h" 
    1718 
    1819/* 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; 
     20typedef version_1_2_42 Your_png_h_is_not_version_1_2_42; 
    2021 
    2122/* Version information for C files.  This had better match the version 
    22  * string defined in png.h.  */ 
     23 * string defined in png.h. 
     24 */ 
    2325 
    2426#ifdef PNG_USE_GLOBAL_ARRAYS 
     
    9698png_set_sig_bytes(png_structp png_ptr, int num_bytes) 
    9799{ 
     100   png_debug(1, "in png_set_sig_bytes"); 
     101 
    98102   if (png_ptr == NULL) 
    99103      return; 
    100    png_debug(1, "in png_set_sig_bytes"); 
     104 
    101105   if (num_bytes > 8) 
    102106      png_error(png_ptr, "Too many bytes for PNG signature."); 
     
    247251 
    248252   png_debug(1, "in png_create_info_struct"); 
     253 
    249254   if (png_ptr == NULL) 
    250255      return (NULL); 
     256 
    251257#ifdef PNG_USER_MEM_SUPPORTED 
    252258   info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, 
     
    270276{ 
    271277   png_infop info_ptr = NULL; 
     278 
     279   png_debug(1, "in png_destroy_info_struct"); 
     280 
    272281   if (png_ptr == NULL) 
    273282      return; 
    274283 
    275    png_debug(1, "in png_destroy_info_struct"); 
    276284   if (info_ptr_ptr != NULL) 
    277285      info_ptr = *info_ptr_ptr; 
     
    310318   png_infop info_ptr = *ptr_ptr; 
    311319 
     320   png_debug(1, "in png_info_init_3"); 
     321 
    312322   if (info_ptr == NULL) 
    313323      return; 
    314  
    315    png_debug(1, "in png_info_init_3"); 
    316324 
    317325   if (png_sizeof(png_info) > png_info_struct_size) 
     
    332340{ 
    333341   png_debug(1, "in png_data_freer"); 
     342 
    334343   if (png_ptr == NULL || info_ptr == NULL) 
    335344      return; 
     345 
    336346   if (freer == PNG_DESTROY_WILL_FREE_DATA) 
    337347      info_ptr->free_me |= mask; 
     
    349359{ 
    350360   png_debug(1, "in png_free_data"); 
     361 
    351362   if (png_ptr == NULL || info_ptr == NULL) 
    352363      return; 
    353364 
    354 #if defined(PNG_TEXT_SUPPORTED) 
     365#ifdef PNG_TEXT_SUPPORTED 
    355366   /* Free text item num or (if num == -1) all text items */ 
    356367#ifdef PNG_FREE_ME_SUPPORTED 
     
    380391#endif 
    381392 
    382 #if defined(PNG_tRNS_SUPPORTED) 
     393#ifdef PNG_tRNS_SUPPORTED 
    383394   /* Free any tRNS entry */ 
    384395#ifdef PNG_FREE_ME_SUPPORTED 
     
    397408#endif 
    398409 
    399 #if defined(PNG_sCAL_SUPPORTED) 
     410#ifdef PNG_sCAL_SUPPORTED 
    400411   /* Free any sCAL entry */ 
    401412#ifdef PNG_FREE_ME_SUPPORTED 
     
    415426#endif 
    416427 
    417 #if defined(PNG_pCAL_SUPPORTED) 
     428#ifdef PNG_pCAL_SUPPORTED 
    418429   /* Free any pCAL entry */ 
    419430#ifdef PNG_FREE_ME_SUPPORTED 
     
    433444            { 
    434445               png_free(png_ptr, info_ptr->pcal_params[i]); 
    435                info_ptr->pcal_params[i]=NULL; 
     446               info_ptr->pcal_params[i] = NULL; 
    436447            } 
    437448            png_free(png_ptr, info_ptr->pcal_params); 
     
    442453#endif 
    443454 
    444 #if defined(PNG_iCCP_SUPPORTED) 
     455#ifdef PNG_iCCP_SUPPORTED 
    445456   /* Free any iCCP entry */ 
    446457#ifdef PNG_FREE_ME_SUPPORTED 
     
    458469#endif 
    459470 
    460 #if defined(PNG_sPLT_SUPPORTED) 
     471#ifdef PNG_sPLT_SUPPORTED 
    461472   /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ 
    462473#ifdef PNG_FREE_ME_SUPPORTED 
     
    493504#endif 
    494505 
    495 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) 
     506#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED 
    496507   if (png_ptr->unknown_chunk.data) 
    497508   { 
     
    531542#endif 
    532543 
    533 #if defined(PNG_hIST_SUPPORTED) 
     544#ifdef PNG_hIST_SUPPORTED 
    534545   /* Free any hIST entry */ 
    535546#ifdef PNG_FREE_ME_SUPPORTED 
     
    564575   } 
    565576 
    566 #if defined(PNG_INFO_IMAGE_SUPPORTED) 
     577#ifdef PNG_INFO_IMAGE_SUPPORTED 
    567578   /* Free any image bits attached to the info structure */ 
    568579#ifdef PNG_FREE_ME_SUPPORTED 
     
    578589         { 
    579590            png_free(png_ptr, info_ptr->row_pointers[row]); 
    580             info_ptr->row_pointers[row]=NULL; 
     591            info_ptr->row_pointers[row] = NULL; 
    581592         } 
    582593         png_free(png_ptr, info_ptr->row_pointers); 
    583          info_ptr->row_pointers=NULL; 
     594         info_ptr->row_pointers = NULL; 
    584595      } 
    585596      info_ptr->valid &= ~PNG_INFO_IDAT; 
     
    606617   png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); 
    607618 
    608 #if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) 
     619#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED 
    609620   if (png_ptr->num_chunk_list) 
    610621   { 
    611622      png_free(png_ptr, png_ptr->chunk_list); 
    612       png_ptr->chunk_list=NULL; 
     623      png_ptr->chunk_list = NULL; 
    613624      png_ptr->num_chunk_list = 0; 
    614625   } 
     
    632643 
    633644#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) 
    634 #if !defined(PNG_NO_STDIO) 
     645#ifdef PNG_STDIO_SUPPORTED 
    635646/* Initialize the default input/output functions for the PNG file.  If you 
    636647 * use your own read or write routines, you can call either png_set_read_fn() 
     
    643654{ 
    644655   png_debug(1, "in png_init_io"); 
     656 
    645657   if (png_ptr == NULL) 
    646658      return; 
     659 
    647660   png_ptr->io_ptr = (png_voidp)fp; 
    648661} 
    649662#endif 
    650663 
    651 #if defined(PNG_TIME_RFC1123_SUPPORTED) 
     664#ifdef PNG_TIME_RFC1123_SUPPORTED 
    652665/* Convert the supplied time into an RFC 1123 string suitable for use in 
    653666 * a "Creation Time" or other text-based time string. 
     
    668681   } 
    669682 
    670 #if defined(_WIN32_WCE) 
     683#ifdef _WIN32_WCE 
    671684   { 
    672685      wchar_t time_buf[29]; 
     
    706719{ 
    707720   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"); 
     721#ifdef PNG_STRING_COPYRIGHT 
     722      return PNG_STRING_COPYRIGHT 
     723#else 
     724#ifdef __STDC__ 
     725   return ((png_charp) PNG_STRING_NEWLINE \ 
     726     "libpng version 1.2.42 - January 3, 2010" PNG_STRING_NEWLINE \ 
     727     "Copyright (c) 1998-2010 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ 
     728     "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ 
     729     "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ 
     730     PNG_STRING_NEWLINE); 
     731#else 
     732      return ((png_charp) "libpng version 1.2.42 - January 3, 2010\ 
     733      Copyright (c) 1998-2010 Glenn Randers-Pehrson\ 
     734      Copyright (c) 1996-1997 Andreas Dilger\ 
     735      Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."); 
     736#endif 
     737#endif 
    712738} 
    713739 
     
    741767   /* Returns longer string containing both version and date */ 
    742768   png_ptr = png_ptr;  /* Silence compiler warning about unused png_ptr */ 
     769#ifdef __STDC__ 
    743770   return ((png_charp) PNG_HEADER_VERSION_STRING 
    744771#ifndef PNG_READ_SUPPORTED 
    745772   "     (NO READ SUPPORT)" 
    746773#endif 
    747    "\n"); 
     774   PNG_STRING_NEWLINE); 
     775#else 
     776   return ((png_charp) PNG_HEADER_VERSION_STRING); 
     777#endif 
    748778} 
    749779 
     
    786816 
    787817#if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) 
    788 #if !defined(PNG_1_0_X) 
     818#ifndef PNG_1_0_X 
    789819/* This function was added to libpng 1.2.0 */ 
    790820int PNGAPI 
     
    811841 
    812842/* 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) 
     843#ifdef PNG_cHRM_SUPPORTED 
     844#ifdef PNG_CHECK_cHRM_SUPPORTED 
    815845 
    816846/* 
     
    864894 
    865895   png_debug(1, "in function png_check_cHRM_fixed"); 
     896 
    866897   if (png_ptr == NULL) 
    867898      return 0; 
     
    922953   return ret; 
    923954} 
    924 #endif /* NO_PNG_CHECK_cHRM */ 
     955#endif /* PNG_CHECK_cHRM_SUPPORTED */ 
    925956#endif /* PNG_cHRM_SUPPORTED */ 
     957 
     958void /* PRIVATE */ 
     959png_check_IHDR(png_structp png_ptr, 
     960   png_uint_32 width, png_uint_32 height, int bit_depth, 
     961   int color_type, int interlace_type, int compression_type, 
     962   int filter_type) 
     963{ 
     964   int error = 0; 
     965 
     966   /* Check for width and height valid values */ 
     967   if (width == 0) 
     968   { 
     969      png_warning(png_ptr, "Image width is zero in IHDR"); 
     970      error = 1; 
     971   } 
     972 
     973   if (height == 0) 
     974   { 
     975      png_warning(png_ptr, "Image height is zero in IHDR"); 
     976      error = 1; 
     977   } 
     978 
     979#ifdef PNG_SET_USER_LIMITS_SUPPORTED 
     980   if (width > png_ptr->user_width_max || width > PNG_USER_WIDTH_MAX) 
     981#else 
     982   if (width > PNG_USER_WIDTH_MAX) 
     983#endif 
     984   { 
     985      png_warning(png_ptr, "Image width exceeds user limit in IHDR"); 
     986      error = 1; 
     987   } 
     988 
     989#ifdef PNG_SET_USER_LIMITS_SUPPORTED 
     990   if (height > png_ptr->user_height_max || height > PNG_USER_HEIGHT_MAX) 
     991#else 
     992   if (height > PNG_USER_HEIGHT_MAX) 
     993#endif 
     994   { 
     995      png_warning(png_ptr, "Image height exceeds user limit in IHDR"); 
     996      error = 1; 
     997   } 
     998 
     999   if (width > PNG_UINT_31_MAX) 
     1000   { 
     1001      png_warning(png_ptr, "Invalid image width in IHDR"); 
     1002      error = 1; 
     1003   } 
     1004 
     1005   if ( height > PNG_UINT_31_MAX) 
     1006   { 
     1007      png_warning(png_ptr, "Invalid image height in IHDR"); 
     1008      error = 1; 
     1009   } 
     1010 
     1011   if ( width > (PNG_UINT_32_MAX 
     1012                 >> 3)      /* 8-byte RGBA pixels */ 
     1013                 - 64       /* bigrowbuf hack */ 
     1014                 - 1        /* filter byte */ 
     1015                 - 7*8      /* rounding of width to multiple of 8 pixels */ 
     1016                 - 8)       /* extra max_pixel_depth pad */ 
     1017      png_warning(png_ptr, "Width is too large for libpng to process pixels"); 
     1018 
     1019   /* Check other values */ 
     1020   if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && 
     1021       bit_depth != 8 && bit_depth != 16) 
     1022   { 
     1023      png_warning(png_ptr, "Invalid bit depth in IHDR"); 
     1024      error = 1; 
     1025   } 
     1026 
     1027   if (color_type < 0 || color_type == 1 || 
     1028       color_type == 5 || color_type > 6) 
     1029   { 
     1030      png_warning(png_ptr, "Invalid color type in IHDR"); 
     1031      error = 1; 
     1032   } 
     1033 
     1034   if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || 
     1035       ((color_type == PNG_COLOR_TYPE_RGB || 
     1036         color_type == PNG_COLOR_TYPE_GRAY_ALPHA || 
     1037         color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) 
     1038   { 
     1039      png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR"); 
     1040      error = 1; 
     1041   } 
     1042 
     1043   if (interlace_type >= PNG_INTERLACE_LAST) 
     1044   { 
     1045      png_warning(png_ptr, "Unknown interlace method in IHDR"); 
     1046      error = 1; 
     1047   } 
     1048 
     1049   if (compression_type != PNG_COMPRESSION_TYPE_BASE) 
     1050   { 
     1051      png_warning(png_ptr, "Unknown compression method in IHDR"); 
     1052      error = 1; 
     1053   } 
     1054 
     1055#ifdef PNG_MNG_FEATURES_SUPPORTED 
     1056   /* Accept filter_method 64 (intrapixel differencing) only if 
     1057    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and 
     1058    * 2. Libpng did not read a PNG signature (this filter_method is only 
     1059    *    used in PNG datastreams that are embedded in MNG datastreams) and 
     1060    * 3. The application called png_permit_mng_features with a mask that 
     1061    *    included PNG_FLAG_MNG_FILTER_64 and 
     1062    * 4. The filter_method is 64 and 
     1063    * 5. The color_type is RGB or RGBA 
     1064    */ 
     1065   if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) && 
     1066       png_ptr->mng_features_permitted) 
     1067      png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); 
     1068 
     1069   if (filter_type != PNG_FILTER_TYPE_BASE) 
     1070   { 
     1071      if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 
     1072         (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && 
     1073         ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) && 
     1074         (color_type == PNG_COLOR_TYPE_RGB || 
     1075         color_type == PNG_COLOR_TYPE_RGB_ALPHA))) 
     1076      { 
     1077         png_warning(png_ptr, "Unknown filter method in IHDR"); 
     1078         error = 1; 
     1079      } 
     1080 
     1081      if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) 
     1082      { 
     1083         png_warning(png_ptr, "Invalid filter method in IHDR"); 
     1084         error = 1; 
     1085      } 
     1086   } 
     1087 
     1088#else 
     1089   if (filter_type != PNG_FILTER_TYPE_BASE) 
     1090   { 
     1091      png_warning(png_ptr, "Unknown filter method in IHDR"); 
     1092      error = 1; 
     1093   } 
     1094#endif 
     1095 
     1096   if (error == 1) 
     1097      png_error(png_ptr, "Invalid IHDR data"); 
     1098} 
    9261099#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */