Back to index

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