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


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:18