Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/3rdparty/libpng/pngset.c

    r2 r561  
    22/* pngset.c - storage of image information into info struct
    33 *
    4  * Last changed in libpng 1.2.27 [April 29, 2008]
    5  * For conditions of distribution and use, see copyright notice in png.h
    6  * Copyright (c) 1998-2008 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.2.40 [September 10, 2009]
     5 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
    76 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    87 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     8 *
     9 * This code is released under the libpng license.
     10 * For conditions of distribution and use, see the disclaimer
     11 * and license in png.h
    912 *
    1013 * The functions here are used during reads to store data from the file
     
    1619#define PNG_INTERNAL
    1720#include "png.h"
    18 
    1921#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
    2022
     
    2325png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
    2426{
    25    png_debug1(1, "in %s storage function\n", "bKGD");
     27   png_debug1(1, "in %s storage function", "bKGD");
     28
    2629   if (png_ptr == NULL || info_ptr == NULL)
    2730      return;
     
    3942   double green_x, double green_y, double blue_x, double blue_y)
    4043{
    41    png_debug1(1, "in %s storage function\n", "cHRM");
    42    if (png_ptr == NULL || info_ptr == NULL)
    43       return;
    44    if (!(white_x || white_y || red_x || red_y || green_x || green_y ||
    45        blue_x || blue_y))
    46    {
    47       png_warning(png_ptr,
    48         "Ignoring attempt to set all-zero chromaticity values");
    49       return;
    50    }
    51    if (white_x < 0.0 || white_y < 0.0 ||
    52          red_x < 0.0 ||   red_y < 0.0 ||
    53        green_x < 0.0 || green_y < 0.0 ||
    54         blue_x < 0.0 ||  blue_y < 0.0)
    55    {
    56       png_warning(png_ptr,
    57         "Ignoring attempt to set negative chromaticity value");
    58       return;
    59    }
    60    if (white_x > 21474.83 || white_y > 21474.83 ||
    61          red_x > 21474.83 ||   red_y > 21474.83 ||
    62        green_x > 21474.83 || green_y > 21474.83 ||
    63         blue_x > 21474.83 ||  blue_y > 21474.83)
    64    {
    65       png_warning(png_ptr,
    66         "Ignoring attempt to set chromaticity value exceeding 21474.83");
    67       return;
    68    }
     44   png_debug1(1, "in %s storage function", "cHRM");
     45
     46   if (png_ptr == NULL || info_ptr == NULL)
     47      return;
    6948
    7049   info_ptr->x_white = (float)white_x;
     
    8867   info_ptr->valid |= PNG_INFO_cHRM;
    8968}
    90 #endif
     69#endif /* PNG_FLOATING_POINT_SUPPORTED */
     70
    9171#ifdef PNG_FIXED_POINT_SUPPORTED
    9272void PNGAPI
     
    9676   png_fixed_point blue_x, png_fixed_point blue_y)
    9777{
    98    png_debug1(1, "in %s storage function\n", "cHRM");
    99    if (png_ptr == NULL || info_ptr == NULL)
    100       return;
    101 
    102    if (!(white_x || white_y || red_x || red_y || green_x || green_y ||
    103        blue_x || blue_y))
    104    {
    105       png_warning(png_ptr,
    106         "Ignoring attempt to set all-zero chromaticity values");
    107       return;
    108    }
    109    if (white_x < 0 || white_y < 0 ||
    110          red_x < 0 ||   red_y < 0 ||
    111        green_x < 0 || green_y < 0 ||
    112         blue_x < 0 ||  blue_y < 0)
    113    {
    114       png_warning(png_ptr,
    115         "Ignoring attempt to set negative chromaticity value");
    116       return;
    117    }
    118    if (white_x > (png_fixed_point) PNG_UINT_31_MAX ||
    119        white_y > (png_fixed_point) PNG_UINT_31_MAX ||
    120          red_x > (png_fixed_point) PNG_UINT_31_MAX ||
    121          red_y > (png_fixed_point) PNG_UINT_31_MAX ||
    122        green_x > (png_fixed_point) PNG_UINT_31_MAX ||
    123        green_y > (png_fixed_point) PNG_UINT_31_MAX ||
    124         blue_x > (png_fixed_point) PNG_UINT_31_MAX ||
    125         blue_y > (png_fixed_point) PNG_UINT_31_MAX )
    126    {
    127       png_warning(png_ptr,
    128         "Ignoring attempt to set chromaticity value exceeding 21474.83");
    129       return;
    130    }
    131    info_ptr->int_x_white = white_x;
    132    info_ptr->int_y_white = white_y;
    133    info_ptr->int_x_red   = red_x;
    134    info_ptr->int_y_red   = red_y;
    135    info_ptr->int_x_green = green_x;
    136    info_ptr->int_y_green = green_y;
    137    info_ptr->int_x_blue  = blue_x;
    138    info_ptr->int_y_blue  = blue_y;
    139 #ifdef PNG_FLOATING_POINT_SUPPORTED
    140    info_ptr->x_white = (float)(white_x/100000.);
    141    info_ptr->y_white = (float)(white_y/100000.);
    142    info_ptr->x_red   = (float)(  red_x/100000.);
    143    info_ptr->y_red   = (float)(  red_y/100000.);
    144    info_ptr->x_green = (float)(green_x/100000.);
    145    info_ptr->y_green = (float)(green_y/100000.);
    146    info_ptr->x_blue  = (float)( blue_x/100000.);
    147    info_ptr->y_blue  = (float)( blue_y/100000.);
    148 #endif
    149    info_ptr->valid |= PNG_INFO_cHRM;
    150 }
    151 #endif
    152 #endif
     78   png_debug1(1, "in %s storage function", "cHRM fixed");
     79
     80   if (png_ptr == NULL || info_ptr == NULL)
     81      return;
     82
     83#if !defined(PNG_NO_CHECK_cHRM)
     84   if (png_check_cHRM_fixed(png_ptr,
     85      white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
     86#endif
     87   {
     88      info_ptr->int_x_white = white_x;
     89      info_ptr->int_y_white = white_y;
     90      info_ptr->int_x_red   = red_x;
     91      info_ptr->int_y_red   = red_y;
     92      info_ptr->int_x_green = green_x;
     93      info_ptr->int_y_green = green_y;
     94      info_ptr->int_x_blue  = blue_x;
     95      info_ptr->int_y_blue  = blue_y;
     96#ifdef  PNG_FLOATING_POINT_SUPPORTED
     97      info_ptr->x_white = (float)(white_x/100000.);
     98      info_ptr->y_white = (float)(white_y/100000.);
     99      info_ptr->x_red   = (float)(  red_x/100000.);
     100      info_ptr->y_red   = (float)(  red_y/100000.);
     101      info_ptr->x_green = (float)(green_x/100000.);
     102      info_ptr->y_green = (float)(green_y/100000.);
     103      info_ptr->x_blue  = (float)( blue_x/100000.);
     104      info_ptr->y_blue  = (float)( blue_y/100000.);
     105#endif
     106      info_ptr->valid |= PNG_INFO_cHRM;
     107   }
     108}
     109#endif /* PNG_FIXED_POINT_SUPPORTED */
     110#endif /* PNG_cHRM_SUPPORTED */
    153111
    154112#if defined(PNG_gAMA_SUPPORTED)
     
    157115png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
    158116{
    159    double gamma;
    160    png_debug1(1, "in %s storage function\n", "gAMA");
     117   double png_gamma;
     118
     119   png_debug1(1, "in %s storage function", "gAMA");
     120
    161121   if (png_ptr == NULL || info_ptr == NULL)
    162122      return;
     
    166126   {
    167127      png_warning(png_ptr, "Limiting gamma to 21474.83");
    168       gamma=21474.83;
     128      png_gamma=21474.83;
    169129   }
    170130   else
    171       gamma=file_gamma;
    172    info_ptr->gamma = (float)gamma;
     131      png_gamma = file_gamma;
     132   info_ptr->gamma = (float)png_gamma;
    173133#ifdef PNG_FIXED_POINT_SUPPORTED
    174    info_ptr->int_gamma = (int)(gamma*100000.+.5);
     134   info_ptr->int_gamma = (int)(png_gamma*100000.+.5);
    175135#endif
    176136   info_ptr->valid |= PNG_INFO_gAMA;
    177    if(gamma == 0.0)
     137   if (png_gamma == 0.0)
    178138      png_warning(png_ptr, "Setting gamma=0");
    179139}
     
    183143   int_gamma)
    184144{
    185    png_fixed_point gamma;
    186 
    187    png_debug1(1, "in %s storage function\n", "gAMA");
    188    if (png_ptr == NULL || info_ptr == NULL)
    189       return;
    190 
    191    if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
    192    {
    193      png_warning(png_ptr, "Limiting gamma to 21474.83");
    194      gamma=PNG_UINT_31_MAX;
     145   png_fixed_point png_gamma;
     146
     147   png_debug1(1, "in %s storage function", "gAMA");
     148
     149   if (png_ptr == NULL || info_ptr == NULL)
     150      return;
     151
     152   if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX)
     153   {
     154      png_warning(png_ptr, "Limiting gamma to 21474.83");
     155      png_gamma=PNG_UINT_31_MAX;
    195156   }
    196157   else
    197158   {
    198      if (int_gamma < 0)
    199      {
    200        png_warning(png_ptr, "Setting negative gamma to zero");
    201        gamma=0;
    202      }
    203      else
    204        gamma=int_gamma;
     159      if (int_gamma < 0)
     160      {
     161         png_warning(png_ptr, "Setting negative gamma to zero");
     162         png_gamma = 0;
     163      }
     164      else
     165         png_gamma = int_gamma;
    205166   }
    206167#ifdef PNG_FLOATING_POINT_SUPPORTED
    207    info_ptr->gamma = (float)(gamma/100000.);
     168   info_ptr->gamma = (float)(png_gamma/100000.);
    208169#endif
    209170#ifdef PNG_FIXED_POINT_SUPPORTED
    210    info_ptr->int_gamma = gamma;
     171   info_ptr->int_gamma = png_gamma;
    211172#endif
    212173   info_ptr->valid |= PNG_INFO_gAMA;
    213    if(gamma == 0)
     174   if (png_gamma == 0)
    214175      png_warning(png_ptr, "Setting gamma=0");
    215176}
     
    222183   int i;
    223184
    224    png_debug1(1, "in %s storage function\n", "hIST");
    225    if (png_ptr == NULL || info_ptr == NULL)
    226       return;
     185   png_debug1(1, "in %s storage function", "hIST");
     186
     187   if (png_ptr == NULL || info_ptr == NULL)
     188      return;
     189
    227190   if (info_ptr->num_palette == 0 || info_ptr->num_palette
    228191       > PNG_MAX_PALETTE_LENGTH)
    229192   {
    230        png_warning(png_ptr,
    231           "Invalid palette size, hIST allocation skipped.");
    232        return;
     193      png_warning(png_ptr,
     194         "Invalid palette size, hIST allocation skipped.");
     195      return;
    233196   }
    234197
     
    236199   png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
    237200#endif
    238    /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in version
    239       1.2.1 */
     201   /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
     202    * version 1.2.1
     203    */
    240204   png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
    241       (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
     205      (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16)));
    242206   if (png_ptr->hist == NULL)
    243      {
    244        png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
    245        return;
    246      }
     207   {
     208      png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
     209      return;
     210   }
    247211
    248212   for (i = 0; i < info_ptr->num_palette; i++)
    249        png_ptr->hist[i] = hist[i];
     213      png_ptr->hist[i] = hist[i];
    250214   info_ptr->hist = png_ptr->hist;
    251215   info_ptr->valid |= PNG_INFO_hIST;
     
    265229   int filter_type)
    266230{
    267    png_debug1(1, "in %s storage function\n", "IHDR");
    268    if (png_ptr == NULL || info_ptr == NULL)
    269       return;
    270 
    271    /* check for width and height valid values */
     231   png_debug1(1, "in %s storage function", "IHDR");
     232
     233   if (png_ptr == NULL || info_ptr == NULL)
     234      return;
     235
     236   /* Check for width and height valid values */
    272237   if (width == 0 || height == 0)
    273238      png_error(png_ptr, "Image width or height is zero in IHDR");
     
    289254      png_warning(png_ptr, "Width is too large for libpng to process pixels");
    290255
    291    /* check other values */
     256   /* Check other values */
    292257   if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
    293       bit_depth != 8 && bit_depth != 16)
     258       bit_depth != 8 && bit_depth != 16)
    294259      png_error(png_ptr, "Invalid bit depth in IHDR");
    295260
    296261   if (color_type < 0 || color_type == 1 ||
    297       color_type == 5 || color_type > 6)
     262       color_type == 5 || color_type > 6)
    298263      png_error(png_ptr, "Invalid color type in IHDR");
    299264
     
    320285    * 5. The color_type is RGB or RGBA
    321286    */
    322    if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
    323       png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
    324    if(filter_type != PNG_FILTER_TYPE_BASE)
    325    {
    326      if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
    327         (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
    328         ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
    329         (color_type == PNG_COLOR_TYPE_RGB ||
     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 ||
    330295         color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
    331296        png_error(png_ptr, "Unknown filter method in IHDR");
    332      if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
     297     if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
    333298        png_warning(png_ptr, "Invalid filter method in IHDR");
    334299   }
    335300#else
    336    if(filter_type != PNG_FILTER_TYPE_BASE)
     301   if (filter_type != PNG_FILTER_TYPE_BASE)
    337302      png_error(png_ptr, "Unknown filter method in IHDR");
    338303#endif
     
    355320   info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
    356321
    357    /* check for potential overflow */
     322   /* Check for potential overflow */
    358323   if (width > (PNG_UINT_32_MAX
    359324                 >> 3)      /* 8-byte RGBA pixels */
     
    364329      info_ptr->rowbytes = (png_size_t)0;
    365330   else
    366       info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
     331      info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
    367332}
    368333
     
    372337   png_int_32 offset_x, png_int_32 offset_y, int unit_type)
    373338{
    374    png_debug1(1, "in %s storage function\n", "oFFs");
     339   png_debug1(1, "in %s storage function", "oFFs");
     340
    375341   if (png_ptr == NULL || info_ptr == NULL)
    376342      return;
     
    392358   int i;
    393359
    394    png_debug1(1, "in %s storage function\n", "pCAL");
     360   png_debug1(1, "in %s storage function", "pCAL");
     361
    395362   if (png_ptr == NULL || info_ptr == NULL)
    396363      return;
    397364
    398365   length = png_strlen(purpose) + 1;
    399    png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
     366   png_debug1(3, "allocating purpose for info (%lu bytes)",
     367     (unsigned long)length);
    400368   info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
    401369   if (info_ptr->pcal_purpose == NULL)
    402      {
    403        png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
    404        return;
    405      }
     370   {
     371      png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
     372      return;
     373   }
    406374   png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
    407375
    408    png_debug(3, "storing X0, X1, type, and nparams in info\n");
     376   png_debug(3, "storing X0, X1, type, and nparams in info");
    409377   info_ptr->pcal_X0 = X0;
    410378   info_ptr->pcal_X1 = X1;
     
    413381
    414382   length = png_strlen(units) + 1;
    415    png_debug1(3, "allocating units for info (%lu bytes)\n", length);
     383   png_debug1(3, "allocating units for info (%lu bytes)",
     384     (unsigned long)length);
    416385   info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
    417386   if (info_ptr->pcal_units == NULL)
    418      {
    419        png_warning(png_ptr, "Insufficient memory for pCAL units.");
    420        return;
    421      }
     387   {
     388      png_warning(png_ptr, "Insufficient memory for pCAL units.");
     389      return;
     390   }
    422391   png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
    423392
     
    425394      (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
    426395   if (info_ptr->pcal_params == NULL)
    427      {
    428        png_warning(png_ptr, "Insufficient memory for pCAL params.");
    429        return;
    430      }
    431 
    432    info_ptr->pcal_params[nparams] = NULL;
     396   {
     397      png_warning(png_ptr, "Insufficient memory for pCAL params.");
     398      return;
     399   }
     400
     401   png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp));
    433402
    434403   for (i = 0; i < nparams; i++)
    435404   {
    436405      length = png_strlen(params[i]) + 1;
    437       png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
     406      png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
     407        (unsigned long)length);
    438408      info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
    439409      if (info_ptr->pcal_params[i] == NULL)
    440         {
    441           png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
    442           return;
    443         }
     410      {
     411         png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
     412         return;
     413      }
    444414      png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
    445415   }
     
    458428             int unit, double width, double height)
    459429{
    460    png_debug1(1, "in %s storage function\n", "sCAL");
     430   png_debug1(1, "in %s storage function", "sCAL");
     431
    461432   if (png_ptr == NULL || info_ptr == NULL)
    462433      return;
     
    476447   png_uint_32 length;
    477448
    478    png_debug1(1, "in %s storage function\n", "sCAL");
     449   png_debug1(1, "in %s storage function", "sCAL");
     450
    479451   if (png_ptr == NULL || info_ptr == NULL)
    480452      return;
     
    483455
    484456   length = png_strlen(swidth) + 1;
    485    png_debug1(3, "allocating unit for info (%d bytes)\n", length);
     457   png_debug1(3, "allocating unit for info (%u bytes)",
     458      (unsigned int)length);
    486459   info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
    487460   if (info_ptr->scal_s_width == NULL)
     
    494467
    495468   length = png_strlen(sheight) + 1;
    496    png_debug1(3, "allocating unit for info (%d bytes)\n", length);
     469   png_debug1(3, "allocating unit for info (%u bytes)",
     470      (unsigned int)length);
    497471   info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
    498472   if (info_ptr->scal_s_height == NULL)
    499473   {
    500474      png_free (png_ptr, info_ptr->scal_s_width);
     475      info_ptr->scal_s_width = NULL;
    501476      png_warning(png_ptr,
    502477       "Memory allocation failed while processing sCAL.");
     
    518493   png_uint_32 res_x, png_uint_32 res_y, int unit_type)
    519494{
    520    png_debug1(1, "in %s storage function\n", "pHYs");
     495   png_debug1(1, "in %s storage function", "pHYs");
     496
    521497   if (png_ptr == NULL || info_ptr == NULL)
    522498      return;
     
    534510{
    535511
    536    png_debug1(1, "in %s storage function\n", "PLTE");
     512   png_debug1(1, "in %s storage function", "PLTE");
     513
    537514   if (png_ptr == NULL || info_ptr == NULL)
    538515      return;
    539516
    540517   if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
    541      {
    542        if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
     518   {
     519      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
    543520         png_error(png_ptr, "Invalid palette length");
    544        else
    545        {
     521      else
     522      {
    546523         png_warning(png_ptr, "Invalid palette length");
    547524         return;
    548        }
    549      }
     525      }
     526   }
    550527
    551528   /*
     
    559536
    560537   /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
    561       of num_palette entries,
    562       in case of an invalid PNG file that has too-large sample values. */
     538    * of num_palette entries, in case of an invalid PNG file that has
     539    * too-large sample values.
     540    */
    563541   png_ptr->palette = (png_colorp)png_malloc(png_ptr,
    564542      PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
    565543   png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
    566544      png_sizeof(png_color));
    567    png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
     545   png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
    568546   info_ptr->palette = png_ptr->palette;
    569547   info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
     
    583561   png_color_8p sig_bit)
    584562{
    585    png_debug1(1, "in %s storage function\n", "sBIT");
    586    if (png_ptr == NULL || info_ptr == NULL)
    587       return;
    588 
    589    png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
     563   png_debug1(1, "in %s storage function", "sBIT");
     564
     565   if (png_ptr == NULL || info_ptr == NULL)
     566      return;
     567
     568   png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
    590569   info_ptr->valid |= PNG_INFO_sBIT;
    591570}
     
    596575png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
    597576{
    598    png_debug1(1, "in %s storage function\n", "sRGB");
     577   png_debug1(1, "in %s storage function", "sRGB");
     578
    599579   if (png_ptr == NULL || info_ptr == NULL)
    600580      return;
     
    620600   float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
    621601#endif
    622 #ifdef PNG_FIXED_POINT_SUPPORTED
    623602   png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
    624603      int_green_y, int_blue_x, int_blue_y;
    625604#endif
    626 #endif
    627    png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
     605   png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
     606
    628607   if (png_ptr == NULL || info_ptr == NULL)
    629608      return;
     
    643622
    644623#if defined(PNG_cHRM_SUPPORTED)
    645 #ifdef PNG_FIXED_POINT_SUPPORTED
    646624   int_white_x = 31270L;
    647625   int_white_y = 32900L;
     
    653631   int_blue_y  =  6000L;
    654632
    655    png_set_cHRM_fixed(png_ptr, info_ptr,
    656       int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
    657       int_blue_x, int_blue_y);
    658 #endif
    659633#ifdef PNG_FLOATING_POINT_SUPPORTED
    660634   white_x = (float).3127;
     
    666640   blue_x  = (float).15;
    667641   blue_y  = (float).06;
    668 
    669    png_set_cHRM(png_ptr, info_ptr,
    670       white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
    671 #endif
    672 #endif
    673 }
    674 #endif
     642#endif
     643
     644#if !defined(PNG_NO_CHECK_cHRM)
     645   if (png_check_cHRM_fixed(png_ptr,
     646       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);
     654#endif
     655#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   }
     660#endif /* cHRM */
     661}
     662#endif /* sRGB */
    675663
    676664
     
    685673   png_uint_32 length;
    686674
    687    png_debug1(1, "in %s storage function\n", "iCCP");
     675   png_debug1(1, "in %s storage function", "iCCP");
     676
    688677   if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
    689678      return;
     
    701690   {
    702691      png_free (png_ptr, new_iccp_name);
    703       png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
     692      png_warning(png_ptr,
     693      "Insufficient memory to process iCCP profile.");
    704694      return;
    705695   }
     
    724714void PNGAPI
    725715png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
    726    int num_text)
     716             int num_text)
    727717{
    728718   int ret;
    729    ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
     719   ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
    730720   if (ret)
    731      png_error(png_ptr, "Insufficient memory to store text");
     721      png_error(png_ptr, "Insufficient memory to store text");
    732722}
    733723
    734724int /* PRIVATE */
    735725png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
    736    int num_text)
     726               int num_text)
    737727{
    738728   int i;
    739729
    740    png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
     730   png_debug1(1, "in %s storage function", ((png_ptr == NULL ||
     731      png_ptr->chunk_name[0] == '\0') ?
    741732      "text" : (png_const_charp)png_ptr->chunk_name));
    742733
     
    758749         old_text = info_ptr->text;
    759750         info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
    760             (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
     751            (png_uint_32)(info_ptr->max_text * png_sizeof(png_text)));
    761752         if (info_ptr->text == NULL)
    762            {
    763              png_free(png_ptr, old_text);
    764              return(1);
    765            }
     753         {
     754            png_free(png_ptr, old_text);
     755            return(1);
     756         }
    766757         png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
    767758            png_sizeof(png_text)));
     
    773764         info_ptr->num_text = 0;
    774765         info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
    775             (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
     766            (png_uint_32)(info_ptr->max_text * png_sizeof(png_text)));
    776767         if (info_ptr->text == NULL)
    777            return(1);
     768            return(1);
    778769#ifdef PNG_FREE_ME_SUPPORTED
    779770         info_ptr->free_me |= PNG_FREE_TEXT;
    780771#endif
    781772      }
    782       png_debug1(3, "allocated %d entries for info_ptr->text\n",
     773      png_debug1(3, "allocated %d entries for info_ptr->text",
    783774         info_ptr->max_text);
    784775   }
    785776   for (i = 0; i < num_text; i++)
    786777   {
    787       png_size_t text_length,key_len;
    788       png_size_t lang_len,lang_key_len;
     778      png_size_t text_length, key_len;
     779      png_size_t lang_len, lang_key_len;
    789780      png_textp textp = &(info_ptr->text[info_ptr->num_text]);
    790781
     
    794785      key_len = png_strlen(text_ptr[i].key);
    795786
    796       if(text_ptr[i].compression <= 0)
    797       {
    798         lang_len = 0;
    799         lang_key_len = 0;
     787      if (text_ptr[i].compression <= 0)
     788      {
     789         lang_len = 0;
     790         lang_key_len = 0;
    800791      }
    801792      else
    802793#ifdef PNG_iTXt_SUPPORTED
    803794      {
    804         /* set iTXt data */
    805         if (text_ptr[i].lang != NULL)
    806           lang_len = png_strlen(text_ptr[i].lang);
    807         else
    808           lang_len = 0;
    809         if (text_ptr[i].lang_key != NULL)
    810           lang_key_len = png_strlen(text_ptr[i].lang_key);
    811         else
    812           lang_key_len = 0;
     795         /* Set iTXt data */
     796         if (text_ptr[i].lang != NULL)
     797            lang_len = png_strlen(text_ptr[i].lang);
     798         else
     799            lang_len = 0;
     800         if (text_ptr[i].lang_key != NULL)
     801            lang_key_len = png_strlen(text_ptr[i].lang_key);
     802         else
     803            lang_key_len = 0;
    813804      }
    814805#else
    815806      {
    816         png_warning(png_ptr, "iTXt chunk not supported.");
    817         continue;
     807         png_warning(png_ptr, "iTXt chunk not supported.");
     808         continue;
    818809      }
    819810#endif
     
    823814         text_length = 0;
    824815#ifdef PNG_iTXt_SUPPORTED
    825          if(text_ptr[i].compression > 0)
     816         if (text_ptr[i].compression > 0)
    826817            textp->compression = PNG_ITXT_COMPRESSION_NONE;
    827818         else
     
    836827
    837828      textp->key = (png_charp)png_malloc_warn(png_ptr,
    838          (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
     829         (png_uint_32)
     830         (key_len + text_length + lang_len + lang_key_len + 4));
    839831      if (textp->key == NULL)
    840         return(1);
    841       png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
    842          (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
    843          (int)textp->key);
    844 
    845       png_memcpy(textp->key, text_ptr[i].key,
    846          (png_size_t)(key_len));
    847       *(textp->key+key_len) = '\0';
     832         return(1);
     833      png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
     834                 (png_uint_32)
     835                 (key_len + lang_len + lang_key_len + text_length + 4),
     836                 (int)textp->key);
     837
     838      png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
     839      *(textp->key + key_len) = '\0';
    848840#ifdef PNG_iTXt_SUPPORTED
    849841      if (text_ptr[i].compression > 0)
    850842      {
    851          textp->lang=textp->key + key_len + 1;
     843         textp->lang = textp->key + key_len + 1;
    852844         png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
    853          *(textp->lang+lang_len) = '\0';
    854          textp->lang_key=textp->lang + lang_len + 1;
     845         *(textp->lang + lang_len) = '\0';
     846         textp->lang_key = textp->lang + lang_len + 1;
    855847         png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
    856          *(textp->lang_key+lang_key_len) = '\0';
    857          textp->text=textp->lang_key + lang_key_len + 1;
     848         *(textp->lang_key + lang_key_len) = '\0';
     849         textp->text = textp->lang_key + lang_key_len + 1;
    858850      }
    859851      else
     
    864856         textp->lang_key=NULL;
    865857#endif
    866          textp->text=textp->key + key_len + 1;
    867       }
    868       if(text_length)
     858         textp->text = textp->key + key_len + 1;
     859      }
     860      if (text_length)
    869861         png_memcpy(textp->text, text_ptr[i].text,
    870862            (png_size_t)(text_length));
    871       *(textp->text+text_length) = '\0';
     863      *(textp->text + text_length) = '\0';
    872864
    873865#ifdef PNG_iTXt_SUPPORTED
    874       if(textp->compression > 0)
     866      if (textp->compression > 0)
    875867      {
    876868         textp->text_length = 0;
     
    886878      }
    887879      info_ptr->num_text++;
    888       png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
     880      png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
    889881   }
    890882   return(0);
     
    896888png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
    897889{
    898    png_debug1(1, "in %s storage function\n", "tIME");
     890   png_debug1(1, "in %s storage function", "tIME");
     891
    899892   if (png_ptr == NULL || info_ptr == NULL ||
    900893       (png_ptr->mode & PNG_WROTE_tIME))
    901894      return;
    902895
    903    png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
     896   png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
    904897   info_ptr->valid |= PNG_INFO_tIME;
    905898}
     
    911904   png_bytep trans, int num_trans, png_color_16p trans_values)
    912905{
    913    png_debug1(1, "in %s storage function\n", "tRNS");
    914    if (png_ptr == NULL || info_ptr == NULL)
    915       return;
    916 
    917    png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
     906   png_debug1(1, "in %s storage function", "tRNS");
     907
     908   if (png_ptr == NULL || info_ptr == NULL)
     909      return;
    918910
    919911   if (trans != NULL)
     
    925917        */
    926918
     919#ifdef PNG_FREE_ME_SUPPORTED
     920       png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
     921#endif
     922
    927923       /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
    928924       png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
    929925           (png_uint_32)PNG_MAX_PALETTE_LENGTH);
    930926       if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
    931          png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
     927          png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
    932928   }
    933929
     
    941937          (int)trans_values->green > sample_max ||
    942938          (int)trans_values->blue > sample_max)))
    943         png_warning(png_ptr,
    944            "tRNS chunk has out-of-range samples for bit_depth");
     939         png_warning(png_ptr,
     940            "tRNS chunk has out-of-range samples for bit_depth");
    945941      png_memcpy(&(info_ptr->trans_values), trans_values,
    946942         png_sizeof(png_color_16));
    947943      if (num_trans == 0)
    948         num_trans = 1;
     944         num_trans = 1;
    949945   }
    950946
     
    966962png_set_sPLT(png_structp png_ptr,
    967963             png_infop info_ptr, png_sPLT_tp entries, int nentries)
    968 {
    969     png_sPLT_tp np;
    970     int i;
    971 
    972     if (png_ptr == NULL || info_ptr == NULL)
    973        return;
    974 
    975     np = (png_sPLT_tp)png_malloc_warn(png_ptr,
    976         (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
    977     if (np == NULL)
    978     {
     964/*
     965 *  entries        - array of png_sPLT_t structures
     966 *                   to be added to the list of palettes
     967 *                   in the info structure.
     968 *  nentries       - number of palette structures to be
     969 *                   added.
     970 */
     971{
     972   png_sPLT_tp np;
     973   int i;
     974
     975   if (png_ptr == NULL || info_ptr == NULL)
     976      return;
     977
     978   np = (png_sPLT_tp)png_malloc_warn(png_ptr,
     979       (info_ptr->splt_palettes_num + nentries) *
     980        (png_uint_32)png_sizeof(png_sPLT_t));
     981   if (np == NULL)
     982   {
    979983      png_warning(png_ptr, "No memory for sPLT palettes.");
    980       return;
    981     }
    982 
    983     png_memcpy(np, info_ptr->splt_palettes,
    984            info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
    985     png_free(png_ptr, info_ptr->splt_palettes);
    986     info_ptr->splt_palettes=NULL;
    987 
    988     for (i = 0; i < nentries; i++)
    989     {
    990         png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
    991         png_sPLT_tp from = entries + i;
    992         png_uint_32 length;
    993 
    994         length = png_strlen(from->name) + 1;
     984     return;
     985   }
     986
     987   png_memcpy(np, info_ptr->splt_palettes,
     988          info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
     989   png_free(png_ptr, info_ptr->splt_palettes);
     990   info_ptr->splt_palettes=NULL;
     991
     992   for (i = 0; i < nentries; i++)
     993   {
     994      png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
     995      png_sPLT_tp from = entries + i;
     996      png_uint_32 length;
     997
     998      length = png_strlen(from->name) + 1;
    995999        to->name = (png_charp)png_malloc_warn(png_ptr, length);
    996         if (to->name == NULL)
    997         {
    998            png_warning(png_ptr,
    999              "Out of memory while processing sPLT chunk");
    1000            continue;
    1001         }
    1002         png_memcpy(to->name, from->name, length);
    1003         to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
    1004             from->nentries * png_sizeof(png_sPLT_entry));
    1005         if (to->entries == NULL)
    1006         {
    1007            png_warning(png_ptr,
    1008              "Out of memory while processing sPLT chunk");
    1009            png_free(png_ptr,to->name);
    1010            to->name = NULL;
    1011            continue;
    1012         }
    1013         png_memcpy(to->entries, from->entries,
    1014             from->nentries * png_sizeof(png_sPLT_entry));
    1015         to->nentries = from->nentries;
    1016         to->depth = from->depth;
    1017     }
    1018 
    1019     info_ptr->splt_palettes = np;
    1020     info_ptr->splt_palettes_num += nentries;
    1021     info_ptr->valid |= PNG_INFO_sPLT;
     1000      if (to->name == NULL)
     1001      {
     1002         png_warning(png_ptr,
     1003           "Out of memory while processing sPLT chunk");
     1004         continue;
     1005      }
     1006      png_memcpy(to->name, from->name, length);
     1007      to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
     1008            (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry)));
     1009      if (to->entries == NULL)
     1010      {
     1011         png_warning(png_ptr,
     1012           "Out of memory while processing sPLT chunk");
     1013         png_free(png_ptr, to->name);
     1014         to->name = NULL;
     1015         continue;
     1016      }
     1017      png_memcpy(to->entries, from->entries,
     1018          from->nentries * png_sizeof(png_sPLT_entry));
     1019      to->nentries = from->nentries;
     1020      to->depth = from->depth;
     1021   }
     1022
     1023   info_ptr->splt_palettes = np;
     1024   info_ptr->splt_palettes_num += nentries;
     1025   info_ptr->valid |= PNG_INFO_sPLT;
    10221026#ifdef PNG_FREE_ME_SUPPORTED
    1023     info_ptr->free_me |= PNG_FREE_SPLT;
     1027   info_ptr->free_me |= PNG_FREE_SPLT;
    10241028#endif
    10251029}
    10261030#endif /* PNG_sPLT_SUPPORTED */
    10271031
    1028 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
     1032#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
    10291033void PNGAPI
    10301034png_set_unknown_chunks(png_structp png_ptr,
    10311035   png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
    10321036{
    1033     png_unknown_chunkp np;
    1034     int i;
    1035 
    1036     if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
    1037         return;
    1038 
    1039     np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
    1040         (info_ptr->unknown_chunks_num + num_unknowns) *
    1041         png_sizeof(png_unknown_chunk));
    1042     if (np == NULL)
    1043     {
    1044        png_warning(png_ptr,
    1045           "Out of memory while processing unknown chunk.");
    1046        return;
    1047     }
    1048 
    1049     png_memcpy(np, info_ptr->unknown_chunks,
    1050            info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
    1051     png_free(png_ptr, info_ptr->unknown_chunks);
    1052     info_ptr->unknown_chunks=NULL;
    1053 
    1054     for (i = 0; i < num_unknowns; i++)
    1055     {
    1056        png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
    1057        png_unknown_chunkp from = unknowns + i;
    1058 
    1059        png_memcpy((png_charp)to->name,
    1060                   (png_charp)from->name,
    1061                   png_sizeof(from->name));
    1062        to->name[png_sizeof(to->name)-1] = '\0';
    1063        to->size = from->size;
    1064        /* note our location in the read or write sequence */
    1065        to->location = (png_byte)(png_ptr->mode & 0xff);
    1066 
    1067        if (from->size == 0)
    1068           to->data=NULL;
    1069        else
    1070        {
    1071           to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
    1072           if (to->data == NULL)
    1073           {
    1074              png_warning(png_ptr,
    1075               "Out of memory while processing unknown chunk.");
    1076              to->size=0;
    1077           }
    1078           else
    1079              png_memcpy(to->data, from->data, from->size);
    1080        }
    1081     }
    1082 
    1083     info_ptr->unknown_chunks = np;
    1084     info_ptr->unknown_chunks_num += num_unknowns;
     1037   png_unknown_chunkp np;
     1038   int i;
     1039
     1040   if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
     1041      return;
     1042
     1043   np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
     1044       (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) *
     1045       png_sizeof(png_unknown_chunk)));
     1046   if (np == NULL)
     1047   {
     1048      png_warning(png_ptr,
     1049         "Out of memory while processing unknown chunk.");
     1050      return;
     1051   }
     1052
     1053   png_memcpy(np, info_ptr->unknown_chunks,
     1054          info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
     1055   png_free(png_ptr, info_ptr->unknown_chunks);
     1056   info_ptr->unknown_chunks=NULL;
     1057
     1058   for (i = 0; i < num_unknowns; i++)
     1059   {
     1060      png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
     1061      png_unknown_chunkp from = unknowns + i;
     1062
     1063      png_memcpy((png_charp)to->name,
     1064                 (png_charp)from->name,
     1065                 png_sizeof(from->name));
     1066      to->name[png_sizeof(to->name)-1] = '\0';
     1067      to->size = from->size;
     1068      /* Note our location in the read or write sequence */
     1069      to->location = (png_byte)(png_ptr->mode & 0xff);
     1070
     1071      if (from->size == 0)
     1072         to->data=NULL;
     1073      else
     1074      {
     1075         to->data = (png_bytep)png_malloc_warn(png_ptr,
     1076           (png_uint_32)from->size);
     1077         if (to->data == NULL)
     1078         {
     1079            png_warning(png_ptr,
     1080             "Out of memory while processing unknown chunk.");
     1081            to->size = 0;
     1082         }
     1083         else
     1084            png_memcpy(to->data, from->data, from->size);
     1085      }
     1086   }
     1087
     1088   info_ptr->unknown_chunks = np;
     1089   info_ptr->unknown_chunks_num += num_unknowns;
    10851090#ifdef PNG_FREE_ME_SUPPORTED
    1086     info_ptr->free_me |= PNG_FREE_UNKN;
     1091   info_ptr->free_me |= PNG_FREE_UNKN;
    10871092#endif
    10881093}
     
    10911096   int chunk, int location)
    10921097{
    1093    if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
     1098   if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
    10941099         (int)info_ptr->unknown_chunks_num)
    10951100      info_ptr->unknown_chunks[chunk].location = (png_byte)location;
     
    11051110   /* This function is deprecated in favor of png_permit_mng_features()
    11061111      and will be removed from libpng-1.3.0 */
    1107    png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
     1112
     1113   png_debug(1, "in png_permit_empty_plte, DEPRECATED.");
     1114
    11081115   if (png_ptr == NULL)
    11091116      return;
     
    11191126png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
    11201127{
    1121    png_debug(1, "in png_permit_mng_features\n");
     1128   png_debug(1, "in png_permit_mng_features");
     1129
    11221130   if (png_ptr == NULL)
    11231131      return (png_uint_32)0;
     
    11331141   chunk_list, int num_chunks)
    11341142{
    1135     png_bytep new_list, p;
    1136     int i, old_num_chunks;
    1137     if (png_ptr == NULL)
    1138        return;
    1139     if (num_chunks == 0)
    1140     {
    1141       if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
    1142         png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
     1143   png_bytep new_list, p;
     1144   int i, old_num_chunks;
     1145   if (png_ptr == NULL)
     1146      return;
     1147   if (num_chunks == 0)
     1148   {
     1149      if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
     1150         png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
    11431151      else
    1144         png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
    1145 
    1146       if(keep == PNG_HANDLE_CHUNK_ALWAYS)
    1147         png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
     1152         png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
     1153
     1154      if (keep == PNG_HANDLE_CHUNK_ALWAYS)
     1155         png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
    11481156      else
    1149         png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
    1150       return;
    1151     }
    1152     if (chunk_list == NULL)
    1153       return;
    1154     old_num_chunks=png_ptr->num_chunk_list;
    1155     new_list=(png_bytep)png_malloc(png_ptr,
    1156        (png_uint_32)(5*(num_chunks+old_num_chunks)));
    1157     if(png_ptr->chunk_list != NULL)
    1158     {
    1159        png_memcpy(new_list, png_ptr->chunk_list,
    1160           (png_size_t)(5*old_num_chunks));
    1161        png_free(png_ptr, png_ptr->chunk_list);
    1162        png_ptr->chunk_list=NULL;
    1163     }
    1164     png_memcpy(new_list+5*old_num_chunks, chunk_list,
    1165        (png_size_t)(5*num_chunks));
    1166     for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
    1167        *p=(png_byte)keep;
    1168     png_ptr->num_chunk_list=old_num_chunks+num_chunks;
    1169     png_ptr->chunk_list=new_list;
     1157         png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
     1158      return;
     1159   }
     1160   if (chunk_list == NULL)
     1161      return;
     1162   old_num_chunks = png_ptr->num_chunk_list;
     1163   new_list=(png_bytep)png_malloc(png_ptr,
     1164      (png_uint_32)
     1165      (5*(num_chunks + old_num_chunks)));
     1166   if (png_ptr->chunk_list != NULL)
     1167   {
     1168      png_memcpy(new_list, png_ptr->chunk_list,
     1169         (png_size_t)(5*old_num_chunks));
     1170      png_free(png_ptr, png_ptr->chunk_list);
     1171      png_ptr->chunk_list=NULL;
     1172   }
     1173   png_memcpy(new_list + 5*old_num_chunks, chunk_list,
     1174      (png_size_t)(5*num_chunks));
     1175   for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
     1176      *p=(png_byte)keep;
     1177   png_ptr->num_chunk_list = old_num_chunks + num_chunks;
     1178   png_ptr->chunk_list = new_list;
    11701179#ifdef PNG_FREE_ME_SUPPORTED
    1171     png_ptr->free_me |= PNG_FREE_LIST;
     1180   png_ptr->free_me |= PNG_FREE_LIST;
    11721181#endif
    11731182}
     
    11791188   png_user_chunk_ptr read_user_chunk_fn)
    11801189{
    1181    png_debug(1, "in png_set_read_user_chunk_fn\n");
     1190   png_debug(1, "in png_set_read_user_chunk_fn");
     1191
    11821192   if (png_ptr == NULL)
    11831193      return;
     1194
    11841195   png_ptr->read_user_chunk_fn = read_user_chunk_fn;
    11851196   png_ptr->user_chunk_ptr = user_chunk_ptr;
     
    11911202png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
    11921203{
    1193    png_debug1(1, "in %s storage function\n", "rows");
    1194 
    1195    if (png_ptr == NULL || info_ptr == NULL)
    1196       return;
    1197 
    1198    if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
     1204   png_debug1(1, "in %s storage function", "rows");
     1205
     1206   if (png_ptr == NULL || info_ptr == NULL)
     1207      return;
     1208
     1209   if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
    11991210      png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
    12001211   info_ptr->row_pointers = row_pointers;
    1201    if(row_pointers)
     1212   if (row_pointers)
    12021213      info_ptr->valid |= PNG_INFO_IDAT;
    12031214}
     
    12061217#ifdef PNG_WRITE_SUPPORTED
    12071218void PNGAPI
    1208 png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
     1219png_set_compression_buffer_size(png_structp png_ptr,
     1220    png_uint_32 size)
    12091221{
    12101222    if (png_ptr == NULL)
     
    12281240#ifndef PNG_1_0_X
    12291241#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
    1230 /* function was added to libpng 1.2.0 and should always exist by default */
     1242/* Function was added to libpng 1.2.0 and should always exist by default */
    12311243void PNGAPI
    12321244png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
     
    12351247    if (png_ptr != NULL)
    12361248    png_ptr->asm_flags = 0;
    1237 }
    1238 
    1239 /* this function was added to libpng 1.2.0 */
     1249    asm_flags = asm_flags; /* Quiet the compiler */
     1250}
     1251
     1252/* This function was added to libpng 1.2.0 */
    12401253void PNGAPI
    12411254png_set_mmx_thresholds (png_structp png_ptr,
     
    12461259    if (png_ptr == NULL)
    12471260       return;
     1261    /* Quiet the compiler */
     1262    mmx_bitdepth_threshold = mmx_bitdepth_threshold;
     1263    mmx_rowbytes_threshold = mmx_rowbytes_threshold;
    12481264}
    12491265#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
    12501266
    12511267#ifdef PNG_SET_USER_LIMITS_SUPPORTED
    1252 /* this function was added to libpng 1.2.6 */
     1268/* This function was added to libpng 1.2.6 */
    12531269void PNGAPI
    12541270png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
    12551271    png_uint_32 user_height_max)
    12561272{
    1257     /* Images with dimensions larger than these limits will be
    1258      * rejected by png_set_IHDR().  To accept any PNG datastream
    1259      * regardless of dimensions, set both limits to 0x7ffffffL.
    1260      */
    1261     if(png_ptr == NULL) return;
    1262     png_ptr->user_width_max = user_width_max;
    1263     png_ptr->user_height_max = user_height_max;
     1273   /* Images with dimensions larger than these limits will be
     1274    * rejected by png_set_IHDR().  To accept any PNG datastream
     1275    * regardless of dimensions, set both limits to 0x7ffffffL.
     1276    */
     1277   if (png_ptr == NULL)
     1278      return;
     1279   png_ptr->user_width_max = user_width_max;
     1280   png_ptr->user_height_max = user_height_max;
    12641281}
    12651282#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
Note: See TracChangeset for help on using the changeset viewer.