Changeset 43 for vendor/libpng/pngset.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/pngset.c

    r11 r43  
    22/* pngset.c - storage of image information into info struct 
    33 * 
    4  * Last changed in libpng 1.2.40 [September 10, 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.) 
     
    1818 
    1919#define PNG_INTERNAL 
     20#define PNG_NO_PEDANTIC_WARNINGS 
    2021#include "png.h" 
    2122#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) 
    2223 
    23 #if defined(PNG_bKGD_SUPPORTED) 
     24#ifdef PNG_bKGD_SUPPORTED 
    2425void PNGAPI 
    2526png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background) 
     
    3536#endif 
    3637 
    37 #if defined(PNG_cHRM_SUPPORTED) 
     38#ifdef PNG_cHRM_SUPPORTED 
    3839#ifdef PNG_FLOATING_POINT_SUPPORTED 
    3940void PNGAPI 
     
    8182      return; 
    8283 
    83 #if !defined(PNG_NO_CHECK_cHRM) 
     84#ifdef PNG_CHECK_cHRM_SUPPORTED 
    8485   if (png_check_cHRM_fixed(png_ptr, 
    8586      white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y)) 
     
    110111#endif /* PNG_cHRM_SUPPORTED */ 
    111112 
    112 #if defined(PNG_gAMA_SUPPORTED) 
     113#ifdef PNG_gAMA_SUPPORTED 
    113114#ifdef PNG_FLOATING_POINT_SUPPORTED 
    114115void PNGAPI 
     
    177178#endif 
    178179 
    179 #if defined(PNG_hIST_SUPPORTED) 
     180#ifdef PNG_hIST_SUPPORTED 
    180181void PNGAPI 
    181182png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) 
     
    234235      return; 
    235236 
    236    /* Check for width and height valid values */ 
    237    if (width == 0 || height == 0) 
    238       png_error(png_ptr, "Image width or height is zero in IHDR"); 
    239 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 
    240    if (width > png_ptr->user_width_max || height > png_ptr->user_height_max) 
    241       png_error(png_ptr, "image size exceeds user limits in IHDR"); 
    242 #else 
    243    if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX) 
    244       png_error(png_ptr, "image size exceeds user limits in IHDR"); 
    245 #endif 
    246    if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX) 
    247       png_error(png_ptr, "Invalid image size in IHDR"); 
    248    if ( width > (PNG_UINT_32_MAX 
    249                  >> 3)      /* 8-byte RGBA pixels */ 
    250                  - 64       /* bigrowbuf hack */ 
    251                  - 1        /* filter byte */ 
    252                  - 7*8      /* rounding of width to multiple of 8 pixels */ 
    253                  - 8)       /* extra max_pixel_depth pad */ 
    254       png_warning(png_ptr, "Width is too large for libpng to process pixels"); 
    255  
    256    /* Check other values */ 
    257    if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && 
    258        bit_depth != 8 && bit_depth != 16) 
    259       png_error(png_ptr, "Invalid bit depth in IHDR"); 
    260  
    261    if (color_type < 0 || color_type == 1 || 
    262        color_type == 5 || color_type > 6) 
    263       png_error(png_ptr, "Invalid color type in IHDR"); 
    264  
    265    if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || 
    266        ((color_type == PNG_COLOR_TYPE_RGB || 
    267          color_type == PNG_COLOR_TYPE_GRAY_ALPHA || 
    268          color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) 
    269       png_error(png_ptr, "Invalid color type/bit depth combination in IHDR"); 
    270  
    271    if (interlace_type >= PNG_INTERLACE_LAST) 
    272       png_error(png_ptr, "Unknown interlace method in IHDR"); 
    273  
    274    if (compression_type != PNG_COMPRESSION_TYPE_BASE) 
    275       png_error(png_ptr, "Unknown compression method in IHDR"); 
    276  
    277 #if defined(PNG_MNG_FEATURES_SUPPORTED) 
    278    /* Accept filter_method 64 (intrapixel differencing) only if 
    279     * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and 
    280     * 2. Libpng did not read a PNG signature (this filter_method is only 
    281     *    used in PNG datastreams that are embedded in MNG datastreams) and 
    282     * 3. The application called png_permit_mng_features with a mask that 
    283     *    included PNG_FLAG_MNG_FILTER_64 and 
    284     * 4. The filter_method is 64 and 
    285     * 5. The color_type is RGB or RGBA 
    286     */ 
    287    if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted) 
    288       png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); 
    289    if (filter_type != PNG_FILTER_TYPE_BASE) 
    290    { 
    291      if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 
    292          (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && 
    293          ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && 
    294          (color_type == PNG_COLOR_TYPE_RGB || 
    295          color_type == PNG_COLOR_TYPE_RGB_ALPHA))) 
    296         png_error(png_ptr, "Unknown filter method in IHDR"); 
    297      if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) 
    298         png_warning(png_ptr, "Invalid filter method in IHDR"); 
    299    } 
    300 #else 
    301    if (filter_type != PNG_FILTER_TYPE_BASE) 
    302       png_error(png_ptr, "Unknown filter method in IHDR"); 
    303 #endif 
    304  
    305237   info_ptr->width = width; 
    306238   info_ptr->height = height; 
    307239   info_ptr->bit_depth = (png_byte)bit_depth; 
    308    info_ptr->color_type =(png_byte) color_type; 
     240   info_ptr->color_type = (png_byte)color_type; 
    309241   info_ptr->compression_type = (png_byte)compression_type; 
    310242   info_ptr->filter_type = (png_byte)filter_type; 
    311243   info_ptr->interlace_type = (png_byte)interlace_type; 
     244 
     245   png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, 
     246       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, 
     247       info_ptr->compression_type, info_ptr->filter_type); 
     248 
    312249   if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 
    313250      info_ptr->channels = 1; 
     
    332269} 
    333270 
    334 #if defined(PNG_oFFs_SUPPORTED) 
     271#ifdef PNG_oFFs_SUPPORTED 
    335272void PNGAPI 
    336273png_set_oFFs(png_structp png_ptr, png_infop info_ptr, 
     
    349286#endif 
    350287 
    351 #if defined(PNG_pCAL_SUPPORTED) 
     288#ifdef PNG_pCAL_SUPPORTED 
    352289void PNGAPI 
    353290png_set_pCAL(png_structp png_ptr, png_infop info_ptr, 
     
    461398   { 
    462399      png_warning(png_ptr, 
    463        "Memory allocation failed while processing sCAL."); 
     400         "Memory allocation failed while processing sCAL."); 
    464401      return; 
    465402   } 
     
    475412      info_ptr->scal_s_width = NULL; 
    476413      png_warning(png_ptr, 
    477        "Memory allocation failed while processing sCAL."); 
     414         "Memory allocation failed while processing sCAL."); 
    478415      return; 
    479416   } 
     
    488425#endif 
    489426 
    490 #if defined(PNG_pHYs_SUPPORTED) 
     427#ifdef PNG_pHYs_SUPPORTED 
    491428void PNGAPI 
    492429png_set_pHYs(png_structp png_ptr, png_infop info_ptr, 
     
    526463   } 
    527464 
    528    /* 
    529     * It may not actually be necessary to set png_ptr->palette here; 
     465   /* It may not actually be necessary to set png_ptr->palette here; 
    530466    * we do it for backward compatibility with the way the png_handle_tRNS 
    531467    * function used to do the allocation. 
     
    539475    * too-large sample values. 
    540476    */ 
    541    png_ptr->palette = (png_colorp)png_malloc(png_ptr, 
     477   png_ptr->palette = (png_colorp)png_calloc(png_ptr, 
    542478      PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); 
    543    png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH * 
    544       png_sizeof(png_color)); 
    545479   png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color)); 
    546480   info_ptr->palette = png_ptr->palette; 
     
    556490} 
    557491 
    558 #if defined(PNG_sBIT_SUPPORTED) 
     492#ifdef PNG_sBIT_SUPPORTED 
    559493void PNGAPI 
    560494png_set_sBIT(png_structp png_ptr, png_infop info_ptr, 
     
    571505#endif 
    572506 
    573 #if defined(PNG_sRGB_SUPPORTED) 
     507#ifdef PNG_sRGB_SUPPORTED 
    574508void PNGAPI 
    575509png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent) 
     
    588522   int intent) 
    589523{ 
    590 #if defined(PNG_gAMA_SUPPORTED) 
     524#ifdef PNG_gAMA_SUPPORTED 
    591525#ifdef PNG_FLOATING_POINT_SUPPORTED 
    592526   float file_gamma; 
     
    596530#endif 
    597531#endif 
    598 #if defined(PNG_cHRM_SUPPORTED) 
     532#ifdef PNG_cHRM_SUPPORTED 
    599533#ifdef PNG_FLOATING_POINT_SUPPORTED 
    600534   float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; 
     
    610544   png_set_sRGB(png_ptr, info_ptr, intent); 
    611545 
    612 #if defined(PNG_gAMA_SUPPORTED) 
     546#ifdef PNG_gAMA_SUPPORTED 
    613547#ifdef PNG_FLOATING_POINT_SUPPORTED 
    614548   file_gamma = (float).45455; 
     
    621555#endif 
    622556 
    623 #if defined(PNG_cHRM_SUPPORTED) 
     557#ifdef PNG_cHRM_SUPPORTED 
    624558   int_white_x = 31270L; 
    625559   int_white_y = 32900L; 
     
    642576#endif 
    643577 
    644 #if !defined(PNG_NO_CHECK_cHRM) 
    645    if (png_check_cHRM_fixed(png_ptr, 
     578#ifdef PNG_FIXED_POINT_SUPPORTED 
     579   png_set_cHRM_fixed(png_ptr, info_ptr, 
    646580       int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, 
    647        int_green_y, int_blue_x, int_blue_y)) 
    648 #endif 
    649    { 
    650 #ifdef PNG_FIXED_POINT_SUPPORTED 
    651       png_set_cHRM_fixed(png_ptr, info_ptr, 
    652           int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, 
    653           int_green_y, int_blue_x, int_blue_y); 
     581       int_green_y, int_blue_x, int_blue_y); 
    654582#endif 
    655583#ifdef PNG_FLOATING_POINT_SUPPORTED 
    656       png_set_cHRM(png_ptr, info_ptr, 
    657           white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); 
    658 #endif 
    659    } 
     584   png_set_cHRM(png_ptr, info_ptr, 
     585       white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); 
     586#endif 
    660587#endif /* cHRM */ 
    661588} 
     
    663590 
    664591 
    665 #if defined(PNG_iCCP_SUPPORTED) 
     592#ifdef PNG_iCCP_SUPPORTED 
    666593void PNGAPI 
    667594png_set_iCCP(png_structp png_ptr, png_infop info_ptr, 
     
    682609   if (new_iccp_name == NULL) 
    683610   { 
    684       png_warning(png_ptr, "Insufficient memory to process iCCP chunk."); 
     611        png_warning(png_ptr, "Insufficient memory to process iCCP chunk."); 
    685612      return; 
    686613   } 
     
    691618      png_free (png_ptr, new_iccp_name); 
    692619      png_warning(png_ptr, 
    693       "Insufficient memory to process iCCP profile."); 
     620          "Insufficient memory to process iCCP profile."); 
    694621      return; 
    695622   } 
     
    702629   info_ptr->iccp_profile = new_iccp_profile; 
    703630   /* Compression is always zero but is here so the API and info structure 
    704     * does not have to change if we introduce multiple compression types */ 
     631    * does not have to change if we introduce multiple compression types 
     632    */ 
    705633   info_ptr->iccp_compression = (png_byte)compression_type; 
    706634#ifdef PNG_FREE_ME_SUPPORTED 
     
    711639#endif 
    712640 
    713 #if defined(PNG_TEXT_SUPPORTED) 
     641#ifdef PNG_TEXT_SUPPORTED 
    714642void PNGAPI 
    715643png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, 
     
    790718         lang_key_len = 0; 
    791719      } 
     720 
    792721      else 
    793722#ifdef PNG_iTXt_SUPPORTED 
    794723      { 
    795724         /* Set iTXt data */ 
     725 
    796726         if (text_ptr[i].lang != NULL) 
    797727            lang_len = png_strlen(text_ptr[i].lang); 
     
    803733            lang_key_len = 0; 
    804734      } 
    805 #else 
     735#else /* PNG_iTXt_SUPPORTED */ 
    806736      { 
    807737         png_warning(png_ptr, "iTXt chunk not supported."); 
     
    820750            textp->compression = PNG_TEXT_COMPRESSION_NONE; 
    821751      } 
     752 
    822753      else 
    823754      { 
     
    871802      else 
    872803#endif 
     804 
    873805      { 
    874806         textp->text_length = text_length; 
     
    884816#endif 
    885817 
    886 #if defined(PNG_tIME_SUPPORTED) 
     818#ifdef PNG_tIME_SUPPORTED 
    887819void PNGAPI 
    888820png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) 
     
    899831#endif 
    900832 
    901 #if defined(PNG_tRNS_SUPPORTED) 
     833#ifdef PNG_tRNS_SUPPORTED 
    902834void PNGAPI 
    903835png_set_tRNS(png_structp png_ptr, png_infop info_ptr, 
     
    911843   if (trans != NULL) 
    912844   { 
    913        /* 
    914         * It may not actually be necessary to set png_ptr->trans here; 
     845       /* It may not actually be necessary to set png_ptr->trans here; 
    915846        * we do it for backward compatibility with the way the png_handle_tRNS 
    916847        * function used to do the allocation. 
     
    958889#endif 
    959890 
    960 #if defined(PNG_sPLT_SUPPORTED) 
     891#ifdef PNG_sPLT_SUPPORTED 
    961892void PNGAPI 
    962893png_set_sPLT(png_structp png_ptr, 
     
    982913   { 
    983914      png_warning(png_ptr, "No memory for sPLT palettes."); 
    984      return; 
     915      return; 
    985916   } 
    986917 
    987918   png_memcpy(np, info_ptr->splt_palettes, 
    988           info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t)); 
     919       info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t)); 
    989920   png_free(png_ptr, info_ptr->splt_palettes); 
    990921   info_ptr->splt_palettes=NULL; 
     
    997928 
    998929      length = png_strlen(from->name) + 1; 
    999         to->name = (png_charp)png_malloc_warn(png_ptr, length); 
     930      to->name = (png_charp)png_malloc_warn(png_ptr, length); 
    1000931      if (to->name == NULL) 
    1001932      { 
     
    1006937      png_memcpy(to->name, from->name, length); 
    1007938      to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, 
    1008             (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry))); 
     939          (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry))); 
    1009940      if (to->entries == NULL) 
    1010941      { 
     
    1030961#endif /* PNG_sPLT_SUPPORTED */ 
    1031962 
    1032 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED 
     963#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED 
    1033964void PNGAPI 
    1034965png_set_unknown_chunks(png_structp png_ptr, 
     
    1047978   { 
    1048979      png_warning(png_ptr, 
    1049          "Out of memory while processing unknown chunk."); 
     980          "Out of memory while processing unknown chunk."); 
    1050981      return; 
    1051982   } 
    1052983 
    1053984   png_memcpy(np, info_ptr->unknown_chunks, 
    1054           info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk)); 
     985       info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk)); 
    1055986   png_free(png_ptr, info_ptr->unknown_chunks); 
    1056    info_ptr->unknown_chunks=NULL; 
     987   info_ptr->unknown_chunks = NULL; 
    1057988 
    1058989   for (i = 0; i < num_unknowns; i++) 
     
    1061992      png_unknown_chunkp from = unknowns + i; 
    1062993 
    1063       png_memcpy((png_charp)to->name, 
    1064                  (png_charp)from->name, 
    1065                  png_sizeof(from->name)); 
     994      png_memcpy((png_charp)to->name, (png_charp)from->name, 
     995          png_sizeof(from->name)); 
    1066996      to->name[png_sizeof(to->name)-1] = '\0'; 
    1067997      to->size = from->size; 
     
    10971027{ 
    10981028   if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk < 
    1099          (int)info_ptr->unknown_chunks_num) 
     1029       (int)info_ptr->unknown_chunks_num) 
    11001030      info_ptr->unknown_chunks[chunk].location = (png_byte)location; 
    11011031} 
     
    11221052#endif 
    11231053 
    1124 #if defined(PNG_MNG_FEATURES_SUPPORTED) 
     1054#ifdef PNG_MNG_FEATURES_SUPPORTED 
    11251055png_uint_32 PNGAPI 
    11261056png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features) 
     
    11361066#endif 
    11371067 
    1138 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) 
     1068#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED 
    11391069void PNGAPI 
    11401070png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep 
     
    11631093   new_list=(png_bytep)png_malloc(png_ptr, 
    11641094      (png_uint_32) 
    1165       (5*(num_chunks + old_num_chunks))); 
     1095       (5*(num_chunks + old_num_chunks))); 
    11661096   if (png_ptr->chunk_list != NULL) 
    11671097   { 
    11681098      png_memcpy(new_list, png_ptr->chunk_list, 
    1169          (png_size_t)(5*old_num_chunks)); 
     1099          (png_size_t)(5*old_num_chunks)); 
    11701100      png_free(png_ptr, png_ptr->chunk_list); 
    11711101      png_ptr->chunk_list=NULL; 
    11721102   } 
    11731103   png_memcpy(new_list + 5*old_num_chunks, chunk_list, 
    1174       (png_size_t)(5*num_chunks)); 
     1104       (png_size_t)(5*num_chunks)); 
    11751105   for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5) 
    11761106      *p=(png_byte)keep; 
     
    11831113#endif 
    11841114 
    1185 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) 
     1115#ifdef PNG_READ_USER_CHUNKS_SUPPORTED 
    11861116void PNGAPI 
    11871117png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, 
     
    11981128#endif 
    11991129 
    1200 #if defined(PNG_INFO_IMAGE_SUPPORTED) 
     1130#ifdef PNG_INFO_IMAGE_SUPPORTED 
    12011131void PNGAPI 
    12021132png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) 
     
    12821212#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ 
    12831213 
     1214 
     1215#ifdef PNG_BENIGN_ERRORS_SUPPORTED 
     1216void PNGAPI 
     1217png_set_benign_errors(png_structp png_ptr, int allowed) 
     1218{ 
     1219   png_debug(1, "in png_set_benign_errors"); 
     1220 
     1221   if (allowed) 
     1222      png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; 
     1223   else 
     1224      png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN; 
     1225} 
     1226#endif /* PNG_BENIGN_ERRORS_SUPPORTED */ 
    12841227#endif /* ?PNG_1_0_X */ 
    12851228#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */