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/pngwutil.c

    r11 r43  
    22/* pngwutil.c - utilities to write a PNG file 
    33 * 
    4  * Last changed in libpng 1.2.40 [September 10, 2009] 
     4 * Last changed in libpng 1.2.41 [December 3, 2009] 
    55 * Copyright (c) 1998-2009 Glenn Randers-Pehrson 
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 
     
    1313 
    1414#define PNG_INTERNAL 
     15#define PNG_NO_PEDANTIC_WARNINGS 
    1516#include "png.h" 
    1617#ifdef PNG_WRITE_SUPPORTED 
     
    5960 * bytes have already been written. 
    6061 */ 
    61 void /* PRIVATE */ 
     62void PNGAPI 
    6263png_write_sig(png_structp png_ptr) 
    6364{ 
     
    107108      return; 
    108109 
     110 
    109111   /* Write the length and the chunk name */ 
    110112   png_save_uint_32(buf, length); 
     
    193195   if (compression >= PNG_TEXT_COMPRESSION_LAST) 
    194196   { 
    195 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) 
     197#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 
    196198      char msg[50]; 
    197199      png_snprintf(msg, 50, "Unknown compression type %d", compression); 
     
    460462    */ 
    461463   if ( 
    462 #if defined(PNG_MNG_FEATURES_SUPPORTED) 
     464#ifdef PNG_MNG_FEATURES_SUPPORTED 
    463465      !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 
    464466      ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && 
     
    488490   png_ptr->color_type = (png_byte)color_type; 
    489491   png_ptr->interlaced = (png_byte)interlace_type; 
    490 #if defined(PNG_MNG_FEATURES_SUPPORTED) 
     492#ifdef PNG_MNG_FEATURES_SUPPORTED 
    491493   png_ptr->filter_type = (png_byte)filter_type; 
    492494#endif 
     
    580582 
    581583   if (( 
    582 #if defined(PNG_MNG_FEATURES_SUPPORTED) 
     584#ifdef PNG_MNG_FEATURES_SUPPORTED 
    583585        !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && 
    584586#endif 
     
    608610   png_write_chunk_start(png_ptr, (png_bytep)png_PLTE, 
    609611     (png_uint_32)(num_pal * 3)); 
    610 #ifndef PNG_NO_POINTER_INDEXING 
     612#ifdef PNG_POINTER_INDEXING_SUPPORTED 
    611613   for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) 
    612614   { 
     
    701703} 
    702704 
    703 #if defined(PNG_WRITE_gAMA_SUPPORTED) 
     705#ifdef PNG_WRITE_gAMA_SUPPORTED 
    704706/* Write a gAMA chunk */ 
    705707#ifdef PNG_FLOATING_POINT_SUPPORTED 
     
    739741#endif 
    740742 
    741 #if defined(PNG_WRITE_sRGB_SUPPORTED) 
     743#ifdef PNG_WRITE_sRGB_SUPPORTED 
    742744/* Write a sRGB chunk */ 
    743745void /* PRIVATE */ 
     
    759761#endif 
    760762 
    761 #if defined(PNG_WRITE_iCCP_SUPPORTED) 
     763#ifdef PNG_WRITE_iCCP_SUPPORTED 
    762764/* Write an iCCP chunk */ 
    763765void /* PRIVATE */ 
     
    840842#endif 
    841843 
    842 #if defined(PNG_WRITE_sPLT_SUPPORTED) 
     844#ifdef PNG_WRITE_sPLT_SUPPORTED 
    843845/* Write a sPLT chunk */ 
    844846void /* PRIVATE */ 
     
    854856   int palette_size = entry_size * spalette->nentries; 
    855857   png_sPLT_entryp ep; 
    856 #ifdef PNG_NO_POINTER_INDEXING 
     858#ifndef PNG_POINTER_INDEXING_SUPPORTED 
    857859   int i; 
    858860#endif 
     
    871873 
    872874   /* Loop through each palette entry, writing appropriately */ 
    873 #ifndef PNG_NO_POINTER_INDEXING 
     875#ifdef PNG_POINTER_INDEXING_SUPPORTED 
    874876   for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++) 
    875877   { 
     
    921923#endif 
    922924 
    923 #if defined(PNG_WRITE_sBIT_SUPPORTED) 
     925#ifdef PNG_WRITE_sBIT_SUPPORTED 
    924926/* Write the sBIT chunk */ 
    925927void /* PRIVATE */ 
     
    978980#endif 
    979981 
    980 #if defined(PNG_WRITE_cHRM_SUPPORTED) 
     982#ifdef PNG_WRITE_cHRM_SUPPORTED 
    981983/* Write the cHRM chunk */ 
    982984#ifdef PNG_FLOATING_POINT_SUPPORTED 
     
    10051007   int_blue_y  = (png_uint_32)(blue_y  * 100000.0 + 0.5); 
    10061008 
    1007 #if !defined(PNG_NO_CHECK_cHRM) 
     1009#ifdef PNG_CHECK_cHRM_SUPPORTED 
    10081010   if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y, 
    10091011      int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y)) 
     
    10431045 
    10441046   /* Each value is saved in 1/100,000ths */ 
    1045 #if !defined(PNG_NO_CHECK_cHRM) 
     1047#ifdef PNG_CHECK_cHRM_SUPPORTED 
    10461048   if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y, 
    10471049      green_x, green_y, blue_x, blue_y)) 
     
    10661068#endif 
    10671069 
    1068 #if defined(PNG_WRITE_tRNS_SUPPORTED) 
     1070#ifdef PNG_WRITE_tRNS_SUPPORTED 
    10691071/* Write the tRNS chunk */ 
    10701072void /* PRIVATE */ 
     
    11231125#endif 
    11241126 
    1125 #if defined(PNG_WRITE_bKGD_SUPPORTED) 
     1127#ifdef PNG_WRITE_bKGD_SUPPORTED 
    11261128/* Write the background chunk */ 
    11271129void /* PRIVATE */ 
     
    11381140   { 
    11391141      if ( 
    1140 #if defined(PNG_MNG_FEATURES_SUPPORTED) 
     1142#ifdef PNG_MNG_FEATURES_SUPPORTED 
    11411143          (png_ptr->num_palette || 
    11421144          (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && 
     
    11771179#endif 
    11781180 
    1179 #if defined(PNG_WRITE_hIST_SUPPORTED) 
     1181#ifdef PNG_WRITE_hIST_SUPPORTED 
    11801182/* Write the histogram */ 
    11811183void /* PRIVATE */ 
     
    12541256         ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1)) 
    12551257      { 
    1256 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) 
     1258#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 
    12571259         char msg[40]; 
    12581260 
     
    13411343#endif 
    13421344 
    1343 #if defined(PNG_WRITE_tEXt_SUPPORTED) 
     1345#ifdef PNG_WRITE_tEXt_SUPPORTED 
    13441346/* Write a tEXt chunk */ 
    13451347void /* PRIVATE */ 
     
    13821384#endif 
    13831385 
    1384 #if defined(PNG_WRITE_zTXt_SUPPORTED) 
     1386#ifdef PNG_WRITE_zTXt_SUPPORTED 
    13851387/* Write a compressed text chunk */ 
    13861388void /* PRIVATE */ 
     
    14421444#endif 
    14431445 
    1444 #if defined(PNG_WRITE_iTXt_SUPPORTED) 
     1446#ifdef PNG_WRITE_iTXt_SUPPORTED 
    14451447/* Write an iTXt chunk */ 
    14461448void /* PRIVATE */ 
     
    15311533#endif 
    15321534 
    1533 #if defined(PNG_WRITE_oFFs_SUPPORTED) 
     1535#ifdef PNG_WRITE_oFFs_SUPPORTED 
    15341536/* Write the oFFs chunk */ 
    15351537void /* PRIVATE */ 
     
    15541556} 
    15551557#endif 
    1556 #if defined(PNG_WRITE_pCAL_SUPPORTED) 
     1558#ifdef PNG_WRITE_pCAL_SUPPORTED 
    15571559/* Write the pCAL chunk (described in the PNG extensions document) */ 
    15581560void /* PRIVATE */ 
     
    16171619#endif 
    16181620 
    1619 #if defined(PNG_WRITE_sCAL_SUPPORTED) 
     1621#ifdef PNG_WRITE_sCAL_SUPPORTED 
    16201622/* Write the sCAL chunk */ 
    1621 #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) 
     1623#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) 
    16221624void /* PRIVATE */ 
    16231625png_write_sCAL(png_structp png_ptr, int unit, double width, double height) 
     
    16321634 
    16331635   buf[0] = (char)unit; 
    1634 #if defined(_WIN32_WCE) 
     1636#ifdef _WIN32_WCE 
    16351637/* sprintf() function is not supported on WindowsCE */ 
    16361638   { 
     
    16911693#endif 
    16921694 
    1693 #if defined(PNG_WRITE_pHYs_SUPPORTED) 
     1695#ifdef PNG_WRITE_pHYs_SUPPORTED 
    16941696/* Write the pHYs chunk */ 
    16951697void /* PRIVATE */ 
     
    17161718#endif 
    17171719 
    1718 #if defined(PNG_WRITE_tIME_SUPPORTED) 
     1720#ifdef PNG_WRITE_tIME_SUPPORTED 
    17191721/* Write the tIME chunk.  Use either png_convert_from_struct_tm() 
    17201722 * or png_convert_from_time_t(), or fill in the structure yourself. 
     
    17541756{ 
    17551757#ifdef PNG_WRITE_INTERLACING_SUPPORTED 
    1756 #ifdef PNG_USE_LOCAL_ARRAYS 
    17571758   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 
    17581759 
     
    17681769   /* Offset to next interlace block in the y direction */ 
    17691770   int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 
    1770 #endif 
    17711771#endif 
    17721772 
     
    17831783   png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; 
    17841784 
    1785 #ifndef PNG_NO_WRITE_FILTER 
     1785#ifdef PNG_WRITE_FILTER_SUPPORTED 
    17861786   /* Set up filtering buffer, if using this filter */ 
    17871787   if (png_ptr->do_filter & PNG_FILTER_SUB) 
     
    17951795   if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) 
    17961796   { 
    1797      /* Set up previous row buffer */ 
    1798      png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, 
    1799         (png_uint_32)buf_size); 
    1800      png_memset(png_ptr->prev_row, 0, buf_size); 
     1797      /* Set up previous row buffer */ 
     1798      png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, 
     1799         (png_uint_32)buf_size); 
    18011800 
    18021801      if (png_ptr->do_filter & PNG_FILTER_UP) 
    18031802      { 
    18041803         png_ptr->up_row = (png_bytep)png_malloc(png_ptr, 
    1805            (png_uint_32)(png_ptr->rowbytes + 1)); 
     1804            (png_uint_32)(png_ptr->rowbytes + 1)); 
    18061805         png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; 
    18071806      } 
     
    18101809      { 
    18111810         png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, 
    1812            (png_uint_32)(png_ptr->rowbytes + 1)); 
     1811            (png_uint_32)(png_ptr->rowbytes + 1)); 
    18131812         png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; 
    18141813      } 
     
    18171816      { 
    18181817         png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, 
    1819            (png_uint_32)(png_ptr->rowbytes + 1)); 
     1818            (png_uint_32)(png_ptr->rowbytes + 1)); 
    18201819         png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; 
    18211820      } 
    18221821   } 
    1823 #endif /* PNG_NO_WRITE_FILTER */ 
     1822#endif /* PNG_WRITE_FILTER_SUPPORTED */ 
    18241823 
    18251824#ifdef PNG_WRITE_INTERLACING_SUPPORTED 
     
    18551854{ 
    18561855#ifdef PNG_WRITE_INTERLACING_SUPPORTED 
    1857 #ifdef PNG_USE_LOCAL_ARRAYS 
    18581856   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 
    18591857 
     
    18691867   /* Offset to next interlace block in the y direction */ 
    18701868   int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 
    1871 #endif 
    18721869#endif 
    18731870 
     
    19631960} 
    19641961 
    1965 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 
     1962#ifdef PNG_WRITE_INTERLACING_SUPPORTED 
    19661963/* Pick out the correct pixels for the interlace pass. 
    19671964 * The basic idea here is to go through the row with a source 
     
    19741971png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) 
    19751972{ 
    1976 #ifdef PNG_USE_LOCAL_ARRAYS 
    19771973   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 
    19781974 
     
    19821978   /* Offset to next interlace block */ 
    19831979   int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 
    1984 #endif 
    19851980 
    19861981   png_debug(1, "in png_do_write_interlace"); 
    19871982 
    19881983   /* We don't have to do anything on the last pass (6) */ 
    1989 #if defined(PNG_USELESS_TESTS_SUPPORTED) 
     1984#ifdef PNG_USELESS_TESTS_SUPPORTED 
    19901985   if (row != NULL && row_info != NULL && pass < 6) 
    19911986#else 
     
    21472142{ 
    21482143   png_bytep best_row; 
    2149 #ifndef PNG_NO_WRITE_FILTER 
     2144#ifdef PNG_WRITE_FILTER_SUPPORTED 
    21502145   png_bytep prev_row, row_buf; 
    21512146   png_uint_32 mins, bpp; 
     
    21582153   png_debug(1, "in png_write_find_filter"); 
    21592154 
     2155#ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
     2156  if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS) 
     2157  { 
     2158      /* These will never be selected so we need not test them. */ 
     2159      filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH); 
     2160  } 
     2161#endif  
     2162 
    21602163   /* Find out how many bytes offset each pixel is */ 
    21612164   bpp = (row_info->pixel_depth + 7) >> 3; 
     
    21642167#endif 
    21652168   best_row = png_ptr->row_buf; 
    2166 #ifndef PNG_NO_WRITE_FILTER 
     2169#ifdef PNG_WRITE_FILTER_SUPPORTED 
    21672170   row_buf = best_row; 
    21682171   mins = PNG_MAXSUM; 
     
    22072210      } 
    22082211 
    2209 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 
     2212#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    22102213      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 
    22112214      { 
     
    22712274      int v; 
    22722275 
    2273 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 
     2276#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    22742277      /* We temporarily increase the "minimum sum" by the factor we 
    22752278       * would reduce the sum of this filter, so that we can do the 
     
    23242327      } 
    23252328 
    2326 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 
     2329#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    23272330      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 
    23282331      { 
     
    23852388 
    23862389 
    2387 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 
     2390#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    23882391      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 
    23892392      { 
     
    24272430      } 
    24282431 
    2429 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 
     2432#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    24302433      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 
    24312434      { 
     
    24902493      int v; 
    24912494 
    2492 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 
     2495#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    24932496      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 
    24942497      { 
     
    25392542      } 
    25402543 
    2541 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 
     2544#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    25422545      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 
    25432546      { 
     
    26232626      int v; 
    26242627 
    2625 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 
     2628#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    26262629      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 
    26272630      { 
     
    27042707      } 
    27052708 
    2706 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 
     2709#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    27072710      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 
    27082711      { 
     
    27402743      } 
    27412744   } 
    2742 #endif /* PNG_NO_WRITE_FILTER */ 
     2745#endif /* PNG_WRITE_FILTER_SUPPORTED */ 
    27432746   /* Do the actual writing of the filtered row data from the chosen filter. */ 
    27442747 
    27452748   png_write_filtered_row(png_ptr, best_row); 
    27462749 
    2747 #ifndef PNG_NO_WRITE_FILTER 
    2748 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 
     2750#ifdef PNG_WRITE_FILTER_SUPPORTED 
     2751#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    27492752   /* Save the type of filter we picked this time for future calculations */ 
    27502753   if (png_ptr->num_prev_filters > 0) 
     
    27582761   } 
    27592762#endif 
    2760 #endif /* PNG_NO_WRITE_FILTER */ 
     2763#endif /* PNG_WRITE_FILTER_SUPPORTED */ 
    27612764} 
    27622765 
     
    28132816   png_write_finish_row(png_ptr); 
    28142817 
    2815 #if defined(PNG_WRITE_FLUSH_SUPPORTED) 
     2818#ifdef PNG_WRITE_FLUSH_SUPPORTED 
    28162819   png_ptr->flush_rows++; 
    28172820