pngset.c

Go to the documentation of this file.
00001 
00002 /* pngset.c - storage of image information into info struct
00003  *
00004  * Last changed in libpng 1.2.22 [November 6, 2007]
00005  * For conditions of distribution and use, see copyright notice in png.h
00006  * Copyright (c) 1998-2007 Glenn Randers-Pehrson
00007  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
00008  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
00009  *
00010  * The functions here are used during reads to store data from the file
00011  * into the info struct, and during writes to store application data
00012  * into the info struct for writing into the file.  This abstracts the
00013  * info struct and allows us to change the structure in the future.
00014  */
00015 
00016 #define PNG_INTERNAL
00017 #include "png.h"
00018 
00019 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
00020 
00021 #if defined(PNG_bKGD_SUPPORTED)
00022 void PNGAPI
00023 png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
00024 {
00025    png_debug1(1, "in %s storage function\n", "bKGD");
00026    if (png_ptr == NULL || info_ptr == NULL)
00027       return;
00028 
00029    png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
00030    info_ptr->valid |= PNG_INFO_bKGD;
00031 }
00032 #endif
00033 
00034 #if defined(PNG_cHRM_SUPPORTED)
00035 #ifdef PNG_FLOATING_POINT_SUPPORTED
00036 void PNGAPI
00037 png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
00038    double white_x, double white_y, double red_x, double red_y,
00039    double green_x, double green_y, double blue_x, double blue_y)
00040 {
00041    png_debug1(1, "in %s storage function\n", "cHRM");
00042    if (png_ptr == NULL || info_ptr == NULL)
00043       return;
00044    if (!(white_x || white_y || red_x || red_y || green_x || green_y ||
00045        blue_x || blue_y))
00046    {
00047       png_warning(png_ptr,
00048         "Ignoring attempt to set all-zero chromaticity values");
00049       return;
00050    }
00051    if (white_x < 0.0 || white_y < 0.0 ||
00052          red_x < 0.0 ||   red_y < 0.0 ||
00053        green_x < 0.0 || green_y < 0.0 ||
00054         blue_x < 0.0 ||  blue_y < 0.0)
00055    {
00056       png_warning(png_ptr,
00057         "Ignoring attempt to set negative chromaticity value");
00058       return;
00059    }
00060    if (white_x > 21474.83 || white_y > 21474.83 ||
00061          red_x > 21474.83 ||   red_y > 21474.83 ||
00062        green_x > 21474.83 || green_y > 21474.83 ||
00063         blue_x > 21474.83 ||  blue_y > 21474.83)
00064    {
00065       png_warning(png_ptr,
00066         "Ignoring attempt to set chromaticity value exceeding 21474.83");
00067       return;
00068    }
00069 
00070    info_ptr->x_white = (float)white_x;
00071    info_ptr->y_white = (float)white_y;
00072    info_ptr->x_red   = (float)red_x;
00073    info_ptr->y_red   = (float)red_y;
00074    info_ptr->x_green = (float)green_x;
00075    info_ptr->y_green = (float)green_y;
00076    info_ptr->x_blue  = (float)blue_x;
00077    info_ptr->y_blue  = (float)blue_y;
00078 #ifdef PNG_FIXED_POINT_SUPPORTED
00079    info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
00080    info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
00081    info_ptr->int_x_red   = (png_fixed_point)(  red_x*100000.+0.5);
00082    info_ptr->int_y_red   = (png_fixed_point)(  red_y*100000.+0.5);
00083    info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
00084    info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
00085    info_ptr->int_x_blue  = (png_fixed_point)( blue_x*100000.+0.5);
00086    info_ptr->int_y_blue  = (png_fixed_point)( blue_y*100000.+0.5);
00087 #endif
00088    info_ptr->valid |= PNG_INFO_cHRM;
00089 }
00090 #endif
00091 #ifdef PNG_FIXED_POINT_SUPPORTED
00092 void PNGAPI
00093 png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
00094    png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
00095    png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
00096    png_fixed_point blue_x, png_fixed_point blue_y)
00097 {
00098    png_debug1(1, "in %s storage function\n", "cHRM");
00099    if (png_ptr == NULL || info_ptr == NULL)
00100       return;
00101 
00102    if (!(white_x || white_y || red_x || red_y || green_x || green_y ||
00103        blue_x || blue_y))
00104    {
00105       png_warning(png_ptr,
00106         "Ignoring attempt to set all-zero chromaticity values");
00107       return;
00108    }
00109    if (white_x < 0 || white_y < 0 ||
00110          red_x < 0 ||   red_y < 0 ||
00111        green_x < 0 || green_y < 0 ||
00112         blue_x < 0 ||  blue_y < 0)
00113    {
00114       png_warning(png_ptr,
00115         "Ignoring attempt to set negative chromaticity value");
00116       return;
00117    }
00118 #ifdef PNG_FLOATING_POINT_SUPPORTED
00119    if (white_x > (double) PNG_UINT_31_MAX ||
00120        white_y > (double) PNG_UINT_31_MAX ||
00121          red_x > (double) PNG_UINT_31_MAX ||
00122          red_y > (double) PNG_UINT_31_MAX ||
00123        green_x > (double) PNG_UINT_31_MAX ||
00124        green_y > (double) PNG_UINT_31_MAX ||
00125         blue_x > (double) PNG_UINT_31_MAX ||
00126         blue_y > (double) PNG_UINT_31_MAX)
00127 #else
00128    if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
00129        white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
00130          red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
00131          red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
00132        green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
00133        green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
00134         blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
00135         blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
00136 #endif
00137    {
00138       png_warning(png_ptr,
00139         "Ignoring attempt to set chromaticity value exceeding 21474.83");
00140       return;
00141    }
00142    info_ptr->int_x_white = white_x;
00143    info_ptr->int_y_white = white_y;
00144    info_ptr->int_x_red   = red_x;
00145    info_ptr->int_y_red   = red_y;
00146    info_ptr->int_x_green = green_x;
00147    info_ptr->int_y_green = green_y;
00148    info_ptr->int_x_blue  = blue_x;
00149    info_ptr->int_y_blue  = blue_y;
00150 #ifdef PNG_FLOATING_POINT_SUPPORTED
00151    info_ptr->x_white = (float)(white_x/100000.);
00152    info_ptr->y_white = (float)(white_y/100000.);
00153    info_ptr->x_red   = (float)(  red_x/100000.);
00154    info_ptr->y_red   = (float)(  red_y/100000.);
00155    info_ptr->x_green = (float)(green_x/100000.);
00156    info_ptr->y_green = (float)(green_y/100000.);
00157    info_ptr->x_blue  = (float)( blue_x/100000.);
00158    info_ptr->y_blue  = (float)( blue_y/100000.);
00159 #endif
00160    info_ptr->valid |= PNG_INFO_cHRM;
00161 }
00162 #endif
00163 #endif
00164 
00165 #if defined(PNG_gAMA_SUPPORTED)
00166 #ifdef PNG_FLOATING_POINT_SUPPORTED
00167 void PNGAPI
00168 png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
00169 {
00170    double gamma;
00171    png_debug1(1, "in %s storage function\n", "gAMA");
00172    if (png_ptr == NULL || info_ptr == NULL)
00173       return;
00174 
00175    /* Check for overflow */
00176    if (file_gamma > 21474.83)
00177    {
00178       png_warning(png_ptr, "Limiting gamma to 21474.83");
00179       gamma=21474.83;
00180    }
00181    else
00182       gamma=file_gamma;
00183    info_ptr->gamma = (float)gamma;
00184 #ifdef PNG_FIXED_POINT_SUPPORTED
00185    info_ptr->int_gamma = (int)(gamma*100000.+.5);
00186 #endif
00187    info_ptr->valid |= PNG_INFO_gAMA;
00188    if(gamma == 0.0)
00189       png_warning(png_ptr, "Setting gamma=0");
00190 }
00191 #endif
00192 void PNGAPI
00193 png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
00194    int_gamma)
00195 {
00196    png_fixed_point gamma;
00197 
00198    png_debug1(1, "in %s storage function\n", "gAMA");
00199    if (png_ptr == NULL || info_ptr == NULL)
00200       return;
00201 
00202    if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
00203    {
00204      png_warning(png_ptr, "Limiting gamma to 21474.83");
00205      gamma=PNG_UINT_31_MAX;
00206    }
00207    else
00208    {
00209      if (int_gamma < 0)
00210      {
00211        png_warning(png_ptr, "Setting negative gamma to zero");
00212        gamma=0;
00213      }
00214      else
00215        gamma=int_gamma;
00216    }
00217 #ifdef PNG_FLOATING_POINT_SUPPORTED
00218    info_ptr->gamma = (float)(gamma/100000.);
00219 #endif
00220 #ifdef PNG_FIXED_POINT_SUPPORTED
00221    info_ptr->int_gamma = gamma;
00222 #endif
00223    info_ptr->valid |= PNG_INFO_gAMA;
00224    if(gamma == 0)
00225       png_warning(png_ptr, "Setting gamma=0");
00226 }
00227 #endif
00228 
00229 #if defined(PNG_hIST_SUPPORTED)
00230 void PNGAPI
00231 png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
00232 {
00233    int i;
00234 
00235    png_debug1(1, "in %s storage function\n", "hIST");
00236    if (png_ptr == NULL || info_ptr == NULL)
00237       return;
00238    if (info_ptr->num_palette == 0 || info_ptr->num_palette
00239        > PNG_MAX_PALETTE_LENGTH)
00240    {
00241        png_warning(png_ptr,
00242           "Invalid palette size, hIST allocation skipped.");
00243        return;
00244    }
00245 
00246 #ifdef PNG_FREE_ME_SUPPORTED
00247    png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
00248 #endif
00249    /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in version
00250       1.2.1 */
00251    png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
00252       (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
00253    if (png_ptr->hist == NULL)
00254      {
00255        png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
00256        return;
00257      }
00258 
00259    for (i = 0; i < info_ptr->num_palette; i++)
00260        png_ptr->hist[i] = hist[i];
00261    info_ptr->hist = png_ptr->hist;
00262    info_ptr->valid |= PNG_INFO_hIST;
00263 
00264 #ifdef PNG_FREE_ME_SUPPORTED
00265    info_ptr->free_me |= PNG_FREE_HIST;
00266 #else
00267    png_ptr->flags |= PNG_FLAG_FREE_HIST;
00268 #endif
00269 }
00270 #endif
00271 
00272 void PNGAPI
00273 png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
00274    png_uint_32 width, png_uint_32 height, int bit_depth,
00275    int color_type, int interlace_type, int compression_type,
00276    int filter_type)
00277 {
00278    png_debug1(1, "in %s storage function\n", "IHDR");
00279    if (png_ptr == NULL || info_ptr == NULL)
00280       return;
00281 
00282    /* check for width and height valid values */
00283    if (width == 0 || height == 0)
00284       png_error(png_ptr, "Image width or height is zero in IHDR");
00285 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
00286    if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
00287       png_error(png_ptr, "image size exceeds user limits in IHDR");
00288 #else
00289    if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
00290       png_error(png_ptr, "image size exceeds user limits in IHDR");
00291 #endif
00292    if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
00293       png_error(png_ptr, "Invalid image size in IHDR");
00294    if ( width > (PNG_UINT_32_MAX
00295                  >> 3)      /* 8-byte RGBA pixels */
00296                  - 64       /* bigrowbuf hack */
00297                  - 1        /* filter byte */
00298                  - 7*8      /* rounding of width to multiple of 8 pixels */
00299                  - 8)       /* extra max_pixel_depth pad */
00300       png_warning(png_ptr, "Width is too large for libpng to process pixels");
00301 
00302    /* check other values */
00303    if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
00304       bit_depth != 8 && bit_depth != 16)
00305       png_error(png_ptr, "Invalid bit depth in IHDR");
00306 
00307    if (color_type < 0 || color_type == 1 ||
00308       color_type == 5 || color_type > 6)
00309       png_error(png_ptr, "Invalid color type in IHDR");
00310 
00311    if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
00312        ((color_type == PNG_COLOR_TYPE_RGB ||
00313          color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
00314          color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
00315       png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
00316 
00317    if (interlace_type >= PNG_INTERLACE_LAST)
00318       png_error(png_ptr, "Unknown interlace method in IHDR");
00319 
00320    if (compression_type != PNG_COMPRESSION_TYPE_BASE)
00321       png_error(png_ptr, "Unknown compression method in IHDR");
00322 
00323 #if defined(PNG_MNG_FEATURES_SUPPORTED)
00324    /* Accept filter_method 64 (intrapixel differencing) only if
00325     * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
00326     * 2. Libpng did not read a PNG signature (this filter_method is only
00327     *    used in PNG datastreams that are embedded in MNG datastreams) and
00328     * 3. The application called png_permit_mng_features with a mask that
00329     *    included PNG_FLAG_MNG_FILTER_64 and
00330     * 4. The filter_method is 64 and
00331     * 5. The color_type is RGB or RGBA
00332     */
00333    if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
00334       png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
00335    if(filter_type != PNG_FILTER_TYPE_BASE)
00336    {
00337      if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
00338         (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
00339         ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
00340         (color_type == PNG_COLOR_TYPE_RGB ||
00341          color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
00342         png_error(png_ptr, "Unknown filter method in IHDR");
00343      if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
00344         png_warning(png_ptr, "Invalid filter method in IHDR");
00345    }
00346 #else
00347    if(filter_type != PNG_FILTER_TYPE_BASE)
00348       png_error(png_ptr, "Unknown filter method in IHDR");
00349 #endif
00350 
00351    info_ptr->width = width;
00352    info_ptr->height = height;
00353    info_ptr->bit_depth = (png_byte)bit_depth;
00354    info_ptr->color_type =(png_byte) color_type;
00355    info_ptr->compression_type = (png_byte)compression_type;
00356    info_ptr->filter_type = (png_byte)filter_type;
00357    info_ptr->interlace_type = (png_byte)interlace_type;
00358    if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
00359       info_ptr->channels = 1;
00360    else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
00361       info_ptr->channels = 3;
00362    else
00363       info_ptr->channels = 1;
00364    if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
00365       info_ptr->channels++;
00366    info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
00367 
00368    /* check for potential overflow */
00369    if (width > (PNG_UINT_32_MAX
00370                  >> 3)      /* 8-byte RGBA pixels */
00371                  - 64       /* bigrowbuf hack */
00372                  - 1        /* filter byte */
00373                  - 7*8      /* rounding of width to multiple of 8 pixels */
00374                  - 8)       /* extra max_pixel_depth pad */
00375       info_ptr->rowbytes = (png_size_t)0;
00376    else
00377       info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
00378 }
00379 
00380 #if defined(PNG_oFFs_SUPPORTED)
00381 void PNGAPI
00382 png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
00383    png_int_32 offset_x, png_int_32 offset_y, int unit_type)
00384 {
00385    png_debug1(1, "in %s storage function\n", "oFFs");
00386    if (png_ptr == NULL || info_ptr == NULL)
00387       return;
00388 
00389    info_ptr->x_offset = offset_x;
00390    info_ptr->y_offset = offset_y;
00391    info_ptr->offset_unit_type = (png_byte)unit_type;
00392    info_ptr->valid |= PNG_INFO_oFFs;
00393 }
00394 #endif
00395 
00396 #if defined(PNG_pCAL_SUPPORTED)
00397 void PNGAPI
00398 png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
00399    png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
00400    png_charp units, png_charpp params)
00401 {
00402    png_uint_32 length;
00403    int i;
00404 
00405    png_debug1(1, "in %s storage function\n", "pCAL");
00406    if (png_ptr == NULL || info_ptr == NULL)
00407       return;
00408 
00409    length = png_strlen(purpose) + 1;
00410    png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
00411    info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
00412    if (info_ptr->pcal_purpose == NULL)
00413      {
00414        png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
00415        return;
00416      }
00417    png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
00418 
00419    png_debug(3, "storing X0, X1, type, and nparams in info\n");
00420    info_ptr->pcal_X0 = X0;
00421    info_ptr->pcal_X1 = X1;
00422    info_ptr->pcal_type = (png_byte)type;
00423    info_ptr->pcal_nparams = (png_byte)nparams;
00424 
00425    length = png_strlen(units) + 1;
00426    png_debug1(3, "allocating units for info (%lu bytes)\n", length);
00427    info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
00428    if (info_ptr->pcal_units == NULL)
00429      {
00430        png_warning(png_ptr, "Insufficient memory for pCAL units.");
00431        return;
00432      }
00433    png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
00434 
00435    info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
00436       (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
00437    if (info_ptr->pcal_params == NULL)
00438      {
00439        png_warning(png_ptr, "Insufficient memory for pCAL params.");
00440        return;
00441      }
00442 
00443    info_ptr->pcal_params[nparams] = NULL;
00444 
00445    for (i = 0; i < nparams; i++)
00446    {
00447       length = png_strlen(params[i]) + 1;
00448       png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
00449       info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
00450       if (info_ptr->pcal_params[i] == NULL)
00451         {
00452           png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
00453           return;
00454         }
00455       png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
00456    }
00457 
00458    info_ptr->valid |= PNG_INFO_pCAL;
00459 #ifdef PNG_FREE_ME_SUPPORTED
00460    info_ptr->free_me |= PNG_FREE_PCAL;
00461 #endif
00462 }
00463 #endif
00464 
00465 #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
00466 #ifdef PNG_FLOATING_POINT_SUPPORTED
00467 void PNGAPI
00468 png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
00469              int unit, double width, double height)
00470 {
00471    png_debug1(1, "in %s storage function\n", "sCAL");
00472    if (png_ptr == NULL || info_ptr == NULL)
00473       return;
00474 
00475    info_ptr->scal_unit = (png_byte)unit;
00476    info_ptr->scal_pixel_width = width;
00477    info_ptr->scal_pixel_height = height;
00478 
00479    info_ptr->valid |= PNG_INFO_sCAL;
00480 }
00481 #else
00482 #ifdef PNG_FIXED_POINT_SUPPORTED
00483 void PNGAPI
00484 png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
00485              int unit, png_charp swidth, png_charp sheight)
00486 {
00487    png_uint_32 length;
00488 
00489    png_debug1(1, "in %s storage function\n", "sCAL");
00490    if (png_ptr == NULL || info_ptr == NULL)
00491       return;
00492 
00493    info_ptr->scal_unit = (png_byte)unit;
00494 
00495    length = png_strlen(swidth) + 1;
00496    png_debug1(3, "allocating unit for info (%d bytes)\n", length);
00497    info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
00498    if (info_ptr->scal_s_width == NULL)
00499    {
00500       png_warning(png_ptr,
00501        "Memory allocation failed while processing sCAL.");
00502    }
00503    png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
00504 
00505    length = png_strlen(sheight) + 1;
00506    png_debug1(3, "allocating unit for info (%d bytes)\n", length);
00507    info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
00508    if (info_ptr->scal_s_height == NULL)
00509    {
00510       png_free (png_ptr, info_ptr->scal_s_width);
00511       png_warning(png_ptr,
00512        "Memory allocation failed while processing sCAL.");
00513    }
00514    png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
00515 
00516    info_ptr->valid |= PNG_INFO_sCAL;
00517 #ifdef PNG_FREE_ME_SUPPORTED
00518    info_ptr->free_me |= PNG_FREE_SCAL;
00519 #endif
00520 }
00521 #endif
00522 #endif
00523 #endif
00524 
00525 #if defined(PNG_pHYs_SUPPORTED)
00526 void PNGAPI
00527 png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
00528    png_uint_32 res_x, png_uint_32 res_y, int unit_type)
00529 {
00530    png_debug1(1, "in %s storage function\n", "pHYs");
00531    if (png_ptr == NULL || info_ptr == NULL)
00532       return;
00533 
00534    info_ptr->x_pixels_per_unit = res_x;
00535    info_ptr->y_pixels_per_unit = res_y;
00536    info_ptr->phys_unit_type = (png_byte)unit_type;
00537    info_ptr->valid |= PNG_INFO_pHYs;
00538 }
00539 #endif
00540 
00541 void PNGAPI
00542 png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
00543    png_colorp palette, int num_palette)
00544 {
00545 
00546    png_debug1(1, "in %s storage function\n", "PLTE");
00547    if (png_ptr == NULL || info_ptr == NULL)
00548       return;
00549 
00550    if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
00551      {
00552        if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
00553          png_error(png_ptr, "Invalid palette length");
00554        else
00555        {
00556          png_warning(png_ptr, "Invalid palette length");
00557          return;
00558        }
00559      }
00560 
00561    /*
00562     * It may not actually be necessary to set png_ptr->palette here;
00563     * we do it for backward compatibility with the way the png_handle_tRNS
00564     * function used to do the allocation.
00565     */
00566 #ifdef PNG_FREE_ME_SUPPORTED
00567    png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
00568 #endif
00569 
00570    /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
00571       of num_palette entries,
00572       in case of an invalid PNG file that has too-large sample values. */
00573    png_ptr->palette = (png_colorp)png_malloc(png_ptr,
00574       PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
00575    png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
00576       png_sizeof(png_color));
00577    png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
00578    info_ptr->palette = png_ptr->palette;
00579    info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
00580 
00581 #ifdef PNG_FREE_ME_SUPPORTED
00582    info_ptr->free_me |= PNG_FREE_PLTE;
00583 #else
00584    png_ptr->flags |= PNG_FLAG_FREE_PLTE;
00585 #endif
00586 
00587    info_ptr->valid |= PNG_INFO_PLTE;
00588 }
00589 
00590 #if defined(PNG_sBIT_SUPPORTED)
00591 void PNGAPI
00592 png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
00593    png_color_8p sig_bit)
00594 {
00595    png_debug1(1, "in %s storage function\n", "sBIT");
00596    if (png_ptr == NULL || info_ptr == NULL)
00597       return;
00598 
00599    png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
00600    info_ptr->valid |= PNG_INFO_sBIT;
00601 }
00602 #endif
00603 
00604 #if defined(PNG_sRGB_SUPPORTED)
00605 void PNGAPI
00606 png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
00607 {
00608    png_debug1(1, "in %s storage function\n", "sRGB");
00609    if (png_ptr == NULL || info_ptr == NULL)
00610       return;
00611 
00612    info_ptr->srgb_intent = (png_byte)intent;
00613    info_ptr->valid |= PNG_INFO_sRGB;
00614 }
00615 
00616 void PNGAPI
00617 png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
00618    int intent)
00619 {
00620 #if defined(PNG_gAMA_SUPPORTED)
00621 #ifdef PNG_FLOATING_POINT_SUPPORTED
00622    float file_gamma;
00623 #endif
00624 #ifdef PNG_FIXED_POINT_SUPPORTED
00625    png_fixed_point int_file_gamma;
00626 #endif
00627 #endif
00628 #if defined(PNG_cHRM_SUPPORTED)
00629 #ifdef PNG_FLOATING_POINT_SUPPORTED
00630    float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
00631 #endif
00632 #ifdef PNG_FIXED_POINT_SUPPORTED
00633    png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
00634       int_green_y, int_blue_x, int_blue_y;
00635 #endif
00636 #endif
00637    png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
00638    if (png_ptr == NULL || info_ptr == NULL)
00639       return;
00640 
00641    png_set_sRGB(png_ptr, info_ptr, intent);
00642 
00643 #if defined(PNG_gAMA_SUPPORTED)
00644 #ifdef PNG_FLOATING_POINT_SUPPORTED
00645    file_gamma = (float).45455;
00646    png_set_gAMA(png_ptr, info_ptr, file_gamma);
00647 #endif
00648 #ifdef PNG_FIXED_POINT_SUPPORTED
00649    int_file_gamma = 45455L;
00650    png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
00651 #endif
00652 #endif
00653 
00654 #if defined(PNG_cHRM_SUPPORTED)
00655 #ifdef PNG_FIXED_POINT_SUPPORTED
00656    int_white_x = 31270L;
00657    int_white_y = 32900L;
00658    int_red_x   = 64000L;
00659    int_red_y   = 33000L;
00660    int_green_x = 30000L;
00661    int_green_y = 60000L;
00662    int_blue_x  = 15000L;
00663    int_blue_y  =  6000L;
00664 
00665    png_set_cHRM_fixed(png_ptr, info_ptr,
00666       int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
00667       int_blue_x, int_blue_y);
00668 #endif
00669 #ifdef PNG_FLOATING_POINT_SUPPORTED
00670    white_x = (float).3127;
00671    white_y = (float).3290;
00672    red_x   = (float).64;
00673    red_y   = (float).33;
00674    green_x = (float).30;
00675    green_y = (float).60;
00676    blue_x  = (float).15;
00677    blue_y  = (float).06;
00678 
00679    png_set_cHRM(png_ptr, info_ptr,
00680       white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
00681 #endif
00682 #endif
00683 }
00684 #endif
00685 
00686 
00687 #if defined(PNG_iCCP_SUPPORTED)
00688 void PNGAPI
00689 png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
00690              png_charp name, int compression_type,
00691              png_charp profile, png_uint_32 proflen)
00692 {
00693    png_charp new_iccp_name;
00694    png_charp new_iccp_profile;
00695    png_uint_32 length;
00696 
00697    png_debug1(1, "in %s storage function\n", "iCCP");
00698    if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
00699       return;
00700 
00701    length = png_strlen(name)+1;
00702    new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
00703    if (new_iccp_name == NULL)
00704    {
00705       png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
00706       return;
00707    }
00708    png_memcpy(new_iccp_name, name, length);
00709    new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
00710    if (new_iccp_profile == NULL)
00711    {
00712       png_free (png_ptr, new_iccp_name);
00713       png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
00714       return;
00715    }
00716    png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
00717 
00718    png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
00719 
00720    info_ptr->iccp_proflen = proflen;
00721    info_ptr->iccp_name = new_iccp_name;
00722    info_ptr->iccp_profile = new_iccp_profile;
00723    /* Compression is always zero but is here so the API and info structure
00724     * does not have to change if we introduce multiple compression types */
00725    info_ptr->iccp_compression = (png_byte)compression_type;
00726 #ifdef PNG_FREE_ME_SUPPORTED
00727    info_ptr->free_me |= PNG_FREE_ICCP;
00728 #endif
00729    info_ptr->valid |= PNG_INFO_iCCP;
00730 }
00731 #endif
00732 
00733 #if defined(PNG_TEXT_SUPPORTED)
00734 void PNGAPI
00735 png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
00736    int num_text)
00737 {
00738    int ret;
00739    ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
00740    if (ret)
00741      png_error(png_ptr, "Insufficient memory to store text");
00742 }
00743 
00744 int /* PRIVATE */
00745 png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
00746    int num_text)
00747 {
00748    int i;
00749 
00750    png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
00751       "text" : (png_const_charp)png_ptr->chunk_name));
00752 
00753    if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
00754       return(0);
00755 
00756    /* Make sure we have enough space in the "text" array in info_struct
00757     * to hold all of the incoming text_ptr objects.
00758     */
00759    if (info_ptr->num_text + num_text > info_ptr->max_text)
00760    {
00761       if (info_ptr->text != NULL)
00762       {
00763          png_textp old_text;
00764          int old_max;
00765 
00766          old_max = info_ptr->max_text;
00767          info_ptr->max_text = info_ptr->num_text + num_text + 8;
00768          old_text = info_ptr->text;
00769          info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
00770             (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
00771          if (info_ptr->text == NULL)
00772            {
00773              png_free(png_ptr, old_text);
00774              return(1);
00775            }
00776          png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
00777             png_sizeof(png_text)));
00778          png_free(png_ptr, old_text);
00779       }
00780       else
00781       {
00782          info_ptr->max_text = num_text + 8;
00783          info_ptr->num_text = 0;
00784          info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
00785             (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
00786          if (info_ptr->text == NULL)
00787            return(1);
00788 #ifdef PNG_FREE_ME_SUPPORTED
00789          info_ptr->free_me |= PNG_FREE_TEXT;
00790 #endif
00791       }
00792       png_debug1(3, "allocated %d entries for info_ptr->text\n",
00793          info_ptr->max_text);
00794    }
00795    for (i = 0; i < num_text; i++)
00796    {
00797       png_size_t text_length,key_len;
00798       png_size_t lang_len,lang_key_len;
00799       png_textp textp = &(info_ptr->text[info_ptr->num_text]);
00800 
00801       if (text_ptr[i].key == NULL)
00802           continue;
00803 
00804       key_len = png_strlen(text_ptr[i].key);
00805 
00806       if(text_ptr[i].compression <= 0)
00807       {
00808         lang_len = 0;
00809         lang_key_len = 0;
00810       }
00811       else
00812 #ifdef PNG_iTXt_SUPPORTED
00813       {
00814         /* set iTXt data */
00815         if (text_ptr[i].lang != NULL)
00816           lang_len = png_strlen(text_ptr[i].lang);
00817         else
00818           lang_len = 0;
00819         if (text_ptr[i].lang_key != NULL)
00820           lang_key_len = png_strlen(text_ptr[i].lang_key);
00821         else
00822           lang_key_len = 0;
00823       }
00824 #else
00825       {
00826         png_warning(png_ptr, "iTXt chunk not supported.");
00827         continue;
00828       }
00829 #endif
00830 
00831       if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
00832       {
00833          text_length = 0;
00834 #ifdef PNG_iTXt_SUPPORTED
00835          if(text_ptr[i].compression > 0)
00836             textp->compression = PNG_ITXT_COMPRESSION_NONE;
00837          else
00838 #endif
00839             textp->compression = PNG_TEXT_COMPRESSION_NONE;
00840       }
00841       else
00842       {
00843          text_length = png_strlen(text_ptr[i].text);
00844          textp->compression = text_ptr[i].compression;
00845       }
00846 
00847       textp->key = (png_charp)png_malloc_warn(png_ptr,
00848          (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
00849       if (textp->key == NULL)
00850         return(1);
00851       png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
00852          (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
00853          (int)textp->key);
00854 
00855       png_memcpy(textp->key, text_ptr[i].key,
00856          (png_size_t)(key_len));
00857       *(textp->key+key_len) = '\0';
00858 #ifdef PNG_iTXt_SUPPORTED
00859       if (text_ptr[i].compression > 0)
00860       {
00861          textp->lang=textp->key + key_len + 1;
00862          png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
00863          *(textp->lang+lang_len) = '\0';
00864          textp->lang_key=textp->lang + lang_len + 1;
00865          png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
00866          *(textp->lang_key+lang_key_len) = '\0';
00867          textp->text=textp->lang_key + lang_key_len + 1;
00868       }
00869       else
00870 #endif
00871       {
00872 #ifdef PNG_iTXt_SUPPORTED
00873          textp->lang=NULL;
00874          textp->lang_key=NULL;
00875 #endif
00876          textp->text=textp->key + key_len + 1;
00877       }
00878       if(text_length)
00879          png_memcpy(textp->text, text_ptr[i].text,
00880             (png_size_t)(text_length));
00881       *(textp->text+text_length) = '\0';
00882 
00883 #ifdef PNG_iTXt_SUPPORTED
00884       if(textp->compression > 0)
00885       {
00886          textp->text_length = 0;
00887          textp->itxt_length = text_length;
00888       }
00889       else
00890 #endif
00891       {
00892          textp->text_length = text_length;
00893 #ifdef PNG_iTXt_SUPPORTED
00894          textp->itxt_length = 0;
00895 #endif
00896       }
00897       info_ptr->num_text++;
00898       png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
00899    }
00900    return(0);
00901 }
00902 #endif
00903 
00904 #if defined(PNG_tIME_SUPPORTED)
00905 void PNGAPI
00906 png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
00907 {
00908    png_debug1(1, "in %s storage function\n", "tIME");
00909    if (png_ptr == NULL || info_ptr == NULL ||
00910        (png_ptr->mode & PNG_WROTE_tIME))
00911       return;
00912 
00913    png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
00914    info_ptr->valid |= PNG_INFO_tIME;
00915 }
00916 #endif
00917 
00918 #if defined(PNG_tRNS_SUPPORTED)
00919 void PNGAPI
00920 png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
00921    png_bytep trans, int num_trans, png_color_16p trans_values)
00922 {
00923    png_debug1(1, "in %s storage function\n", "tRNS");
00924    if (png_ptr == NULL || info_ptr == NULL)
00925       return;
00926 
00927    if (trans != NULL)
00928    {
00929        /*
00930         * It may not actually be necessary to set png_ptr->trans here;
00931         * we do it for backward compatibility with the way the png_handle_tRNS
00932         * function used to do the allocation.
00933         */
00934 #ifdef PNG_FREE_ME_SUPPORTED
00935        png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
00936 #endif
00937        /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
00938        png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
00939            (png_uint_32)PNG_MAX_PALETTE_LENGTH);
00940        if (num_trans <= PNG_MAX_PALETTE_LENGTH)
00941          png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
00942 #ifdef PNG_FREE_ME_SUPPORTED
00943        info_ptr->free_me |= PNG_FREE_TRNS;
00944 #else
00945        png_ptr->flags |= PNG_FLAG_FREE_TRNS;
00946 #endif
00947    }
00948 
00949    if (trans_values != NULL)
00950    {
00951       png_memcpy(&(info_ptr->trans_values), trans_values,
00952          png_sizeof(png_color_16));
00953       if (num_trans == 0)
00954         num_trans = 1;
00955    }
00956    info_ptr->num_trans = (png_uint_16)num_trans;
00957    info_ptr->valid |= PNG_INFO_tRNS;
00958 }
00959 #endif
00960 
00961 #if defined(PNG_sPLT_SUPPORTED)
00962 void PNGAPI
00963 png_set_sPLT(png_structp png_ptr,
00964              png_infop info_ptr, png_sPLT_tp entries, int nentries)
00965 {
00966     png_sPLT_tp np;
00967     int i;
00968 
00969     if (png_ptr == NULL || info_ptr == NULL)
00970        return;
00971 
00972     np = (png_sPLT_tp)png_malloc_warn(png_ptr,
00973         (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
00974     if (np == NULL)
00975     {
00976       png_warning(png_ptr, "No memory for sPLT palettes.");
00977       return;
00978     }
00979 
00980     png_memcpy(np, info_ptr->splt_palettes,
00981            info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
00982     png_free(png_ptr, info_ptr->splt_palettes);
00983     info_ptr->splt_palettes=NULL;
00984 
00985     for (i = 0; i < nentries; i++)
00986     {
00987         png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
00988         png_sPLT_tp from = entries + i;
00989         png_uint_32 length;
00990 
00991         length = png_strlen(from->name) + 1;
00992         to->name = (png_charp)png_malloc_warn(png_ptr, length);
00993         if (to->name == NULL)
00994         {
00995            png_warning(png_ptr,
00996              "Out of memory while processing sPLT chunk");
00997         }
00998         /* TODO: use png_malloc_warn */
00999         png_memcpy(to->name, from->name, length);
01000         to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
01001             from->nentries * png_sizeof(png_sPLT_entry));
01002         /* TODO: use png_malloc_warn */
01003         png_memcpy(to->entries, from->entries,
01004             from->nentries * png_sizeof(png_sPLT_entry));
01005         if (to->entries == NULL)
01006         {
01007            png_warning(png_ptr,
01008              "Out of memory while processing sPLT chunk");
01009            png_free(png_ptr,to->name);
01010            to->name = NULL;
01011         }
01012         to->nentries = from->nentries;
01013         to->depth = from->depth;
01014     }
01015 
01016     info_ptr->splt_palettes = np;
01017     info_ptr->splt_palettes_num += nentries;
01018     info_ptr->valid |= PNG_INFO_sPLT;
01019 #ifdef PNG_FREE_ME_SUPPORTED
01020     info_ptr->free_me |= PNG_FREE_SPLT;
01021 #endif
01022 }
01023 #endif /* PNG_sPLT_SUPPORTED */
01024 
01025 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
01026 void PNGAPI
01027 png_set_unknown_chunks(png_structp png_ptr,
01028    png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
01029 {
01030     png_unknown_chunkp np;
01031     int i;
01032 
01033     if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
01034         return;
01035 
01036     np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
01037         (info_ptr->unknown_chunks_num + num_unknowns) *
01038         png_sizeof(png_unknown_chunk));
01039     if (np == NULL)
01040     {
01041        png_warning(png_ptr,
01042           "Out of memory while processing unknown chunk.");
01043        return;
01044     }
01045 
01046     png_memcpy(np, info_ptr->unknown_chunks,
01047            info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
01048     png_free(png_ptr, info_ptr->unknown_chunks);
01049     info_ptr->unknown_chunks=NULL;
01050 
01051     for (i = 0; i < num_unknowns; i++)
01052     {
01053         png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
01054         png_unknown_chunkp from = unknowns + i;
01055 
01056         png_memcpy((png_charp)to->name, 
01057                    (png_charp)from->name, 
01058                    png_sizeof(from->name));
01059         to->name[png_sizeof(to->name)-1] = '\0';
01060 
01061         to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
01062         if (to->data == NULL)
01063         {
01064            png_warning(png_ptr,
01065               "Out of memory while processing unknown chunk.");
01066         }
01067         else
01068         {
01069            png_memcpy(to->data, from->data, from->size);
01070            to->size = from->size;
01071 
01072            /* note our location in the read or write sequence */
01073            to->location = (png_byte)(png_ptr->mode & 0xff);
01074         }
01075     }
01076 
01077     info_ptr->unknown_chunks = np;
01078     info_ptr->unknown_chunks_num += num_unknowns;
01079 #ifdef PNG_FREE_ME_SUPPORTED
01080     info_ptr->free_me |= PNG_FREE_UNKN;
01081 #endif
01082 }
01083 void PNGAPI
01084 png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
01085    int chunk, int location)
01086 {
01087    if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
01088          (int)info_ptr->unknown_chunks_num)
01089       info_ptr->unknown_chunks[chunk].location = (png_byte)location;
01090 }
01091 #endif
01092 
01093 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
01094 #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
01095     defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
01096 void PNGAPI
01097 png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
01098 {
01099    /* This function is deprecated in favor of png_permit_mng_features()
01100       and will be removed from libpng-1.3.0 */
01101    png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
01102    if (png_ptr == NULL)
01103       return;
01104    png_ptr->mng_features_permitted = (png_byte)
01105      ((png_ptr->mng_features_permitted & (~PNG_FLAG_MNG_EMPTY_PLTE)) |
01106      ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
01107 }
01108 #endif
01109 #endif
01110 
01111 #if defined(PNG_MNG_FEATURES_SUPPORTED)
01112 png_uint_32 PNGAPI
01113 png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
01114 {
01115    png_debug(1, "in png_permit_mng_features\n");
01116    if (png_ptr == NULL)
01117       return (png_uint_32)0;
01118    png_ptr->mng_features_permitted =
01119      (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
01120    return (png_uint_32)png_ptr->mng_features_permitted;
01121 }
01122 #endif
01123 
01124 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
01125 void PNGAPI
01126 png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
01127    chunk_list, int num_chunks)
01128 {
01129     png_bytep new_list, p;
01130     int i, old_num_chunks;
01131     if (png_ptr == NULL)
01132        return;
01133     if (num_chunks == 0)
01134     {
01135       if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
01136         png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
01137       else
01138         png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
01139 
01140       if(keep == PNG_HANDLE_CHUNK_ALWAYS)
01141         png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
01142       else
01143         png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
01144       return;
01145     }
01146     if (chunk_list == NULL)
01147       return;
01148     old_num_chunks=png_ptr->num_chunk_list;
01149     new_list=(png_bytep)png_malloc(png_ptr,
01150        (png_uint_32)(5*(num_chunks+old_num_chunks)));
01151     if(png_ptr->chunk_list != NULL)
01152     {
01153        png_memcpy(new_list, png_ptr->chunk_list,
01154           (png_size_t)(5*old_num_chunks));
01155        png_free(png_ptr, png_ptr->chunk_list);
01156        png_ptr->chunk_list=NULL;
01157     }
01158     png_memcpy(new_list+5*old_num_chunks, chunk_list,
01159        (png_size_t)(5*num_chunks));
01160     for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
01161        *p=(png_byte)keep;
01162     png_ptr->num_chunk_list=old_num_chunks+num_chunks;
01163     png_ptr->chunk_list=new_list;
01164 #ifdef PNG_FREE_ME_SUPPORTED
01165     png_ptr->free_me |= PNG_FREE_LIST;
01166 #endif
01167 }
01168 #endif
01169 
01170 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
01171 void PNGAPI
01172 png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
01173    png_user_chunk_ptr read_user_chunk_fn)
01174 {
01175    png_debug(1, "in png_set_read_user_chunk_fn\n");
01176    if (png_ptr == NULL)
01177       return;
01178    png_ptr->read_user_chunk_fn = read_user_chunk_fn;
01179    png_ptr->user_chunk_ptr = user_chunk_ptr;
01180 }
01181 #endif
01182 
01183 #if defined(PNG_INFO_IMAGE_SUPPORTED)
01184 void PNGAPI
01185 png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
01186 {
01187    png_debug1(1, "in %s storage function\n", "rows");
01188 
01189    if (png_ptr == NULL || info_ptr == NULL)
01190       return;
01191 
01192    if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
01193       png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
01194    info_ptr->row_pointers = row_pointers;
01195    if(row_pointers)
01196       info_ptr->valid |= PNG_INFO_IDAT;
01197 }
01198 #endif
01199 
01200 #ifdef PNG_WRITE_SUPPORTED
01201 void PNGAPI
01202 png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
01203 {
01204     if (png_ptr == NULL)
01205        return;
01206     if(png_ptr->zbuf)
01207        png_free(png_ptr, png_ptr->zbuf);
01208     png_ptr->zbuf_size = (png_size_t)size;
01209     png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
01210     png_ptr->zstream.next_out = png_ptr->zbuf;
01211     png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
01212 }
01213 #endif
01214 
01215 void PNGAPI
01216 png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
01217 {
01218    if (png_ptr && info_ptr)
01219       info_ptr->valid &= ~mask;
01220 }
01221 
01222 
01223 #ifndef PNG_1_0_X
01224 #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
01225 /* function was added to libpng 1.2.0 and should always exist by default */
01226 void PNGAPI
01227 png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
01228 {
01229 /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
01230     if (png_ptr != NULL)
01231     png_ptr->asm_flags = 0;
01232 }
01233 
01234 /* this function was added to libpng 1.2.0 */
01235 void PNGAPI
01236 png_set_mmx_thresholds (png_structp png_ptr,
01237                         png_byte mmx_bitdepth_threshold,
01238                         png_uint_32 mmx_rowbytes_threshold)
01239 {
01240 /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
01241     if (png_ptr == NULL)
01242        return;
01243 }
01244 #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
01245 
01246 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
01247 /* this function was added to libpng 1.2.6 */
01248 void PNGAPI
01249 png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
01250     png_uint_32 user_height_max)
01251 {
01252     /* Images with dimensions larger than these limits will be
01253      * rejected by png_set_IHDR().  To accept any PNG datastream
01254      * regardless of dimensions, set both limits to 0x7ffffffL.
01255      */
01256     if(png_ptr == NULL) return;
01257     png_ptr->user_width_max = user_width_max;
01258     png_ptr->user_height_max = user_height_max;
01259 }
01260 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
01261 
01262 #endif /* ?PNG_1_0_X */
01263 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */

Generated on Tue Jul 5 14:13:31 2011 for ROOT_528-00b_version by  doxygen 1.5.1