⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pngset.c

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 C
📖 第 1 页 / 共 3 页
字号:
/* pngset.c - storage of image information into info struct * * libpng 1.2.8 - December 3, 2004 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2004 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * * The functions here are used during reads to store data from the file * into the info struct, and during writes to store application data * into the info struct for writing into the file.  This abstracts the * info struct and allows us to change the structure in the future. */#define PNG_INTERNAL#include "png.h"#if defined(PNG_bKGD_SUPPORTED)void PNGAPIpng_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background){   png_debug1(1, "in %s storage function\n", "bKGD");   if (png_ptr == NULL || info_ptr == NULL)      return;   png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));   info_ptr->valid |= PNG_INFO_bKGD;}#endif#if defined(PNG_cHRM_SUPPORTED)#ifdef PNG_FLOATING_POINT_SUPPORTEDvoid PNGAPIpng_set_cHRM(png_structp png_ptr, png_infop info_ptr,   double white_x, double white_y, double red_x, double red_y,   double green_x, double green_y, double blue_x, double blue_y){   png_debug1(1, "in %s storage function\n", "cHRM");   if (png_ptr == NULL || info_ptr == NULL)      return;   if (white_x < 0.0 || white_y < 0.0 ||         red_x < 0.0 ||   red_y < 0.0 ||       green_x < 0.0 || green_y < 0.0 ||        blue_x < 0.0 ||  blue_y < 0.0)   {      png_warning(png_ptr,        "Ignoring attempt to set negative chromaticity value");      return;   }   if (white_x > 21474.83 || white_y > 21474.83 ||         red_x > 21474.83 ||   red_y > 21474.83 ||       green_x > 21474.83 || green_y > 21474.83 ||        blue_x > 21474.83 ||  blue_y > 21474.83)   {      png_warning(png_ptr,        "Ignoring attempt to set chromaticity value exceeding 21474.83");      return;   }   info_ptr->x_white = (float)white_x;   info_ptr->y_white = (float)white_y;   info_ptr->x_red   = (float)red_x;   info_ptr->y_red   = (float)red_y;   info_ptr->x_green = (float)green_x;   info_ptr->y_green = (float)green_y;   info_ptr->x_blue  = (float)blue_x;   info_ptr->y_blue  = (float)blue_y;#ifdef PNG_FIXED_POINT_SUPPORTED   info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);   info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);   info_ptr->int_x_red   = (png_fixed_point)(  red_x*100000.+0.5);   info_ptr->int_y_red   = (png_fixed_point)(  red_y*100000.+0.5);   info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);   info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);   info_ptr->int_x_blue  = (png_fixed_point)( blue_x*100000.+0.5);   info_ptr->int_y_blue  = (png_fixed_point)( blue_y*100000.+0.5);#endif   info_ptr->valid |= PNG_INFO_cHRM;}#endif#ifdef PNG_FIXED_POINT_SUPPORTEDvoid PNGAPIpng_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,   png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,   png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,   png_fixed_point blue_x, png_fixed_point blue_y){   png_debug1(1, "in %s storage function\n", "cHRM");   if (png_ptr == NULL || info_ptr == NULL)      return;   if (white_x < 0 || white_y < 0 ||         red_x < 0 ||   red_y < 0 ||       green_x < 0 || green_y < 0 ||        blue_x < 0 ||  blue_y < 0)   {      png_warning(png_ptr,        "Ignoring attempt to set negative chromaticity value");      return;   }   if (white_x > (double) PNG_UINT_31_MAX ||       white_y > (double) PNG_UINT_31_MAX ||         red_x > (double) PNG_UINT_31_MAX ||         red_y > (double) PNG_UINT_31_MAX ||       green_x > (double) PNG_UINT_31_MAX ||       green_y > (double) PNG_UINT_31_MAX ||        blue_x > (double) PNG_UINT_31_MAX ||        blue_y > (double) PNG_UINT_31_MAX)   {      png_warning(png_ptr,        "Ignoring attempt to set chromaticity value exceeding 21474.83");      return;   }   info_ptr->int_x_white = white_x;   info_ptr->int_y_white = white_y;   info_ptr->int_x_red   = red_x;   info_ptr->int_y_red   = red_y;   info_ptr->int_x_green = green_x;   info_ptr->int_y_green = green_y;   info_ptr->int_x_blue  = blue_x;   info_ptr->int_y_blue  = blue_y;#ifdef PNG_FLOATING_POINT_SUPPORTED   info_ptr->x_white = (float)(white_x/100000.);   info_ptr->y_white = (float)(white_y/100000.);   info_ptr->x_red   = (float)(  red_x/100000.);   info_ptr->y_red   = (float)(  red_y/100000.);   info_ptr->x_green = (float)(green_x/100000.);   info_ptr->y_green = (float)(green_y/100000.);   info_ptr->x_blue  = (float)( blue_x/100000.);   info_ptr->y_blue  = (float)( blue_y/100000.);#endif   info_ptr->valid |= PNG_INFO_cHRM;}#endif#endif#if defined(PNG_gAMA_SUPPORTED)#ifdef PNG_FLOATING_POINT_SUPPORTEDvoid PNGAPIpng_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma){   double gamma;   png_debug1(1, "in %s storage function\n", "gAMA");   if (png_ptr == NULL || info_ptr == NULL)      return;   /* Check for overflow */   if (file_gamma > 21474.83)   {      png_warning(png_ptr, "Limiting gamma to 21474.83");      gamma=21474.83;   }   else      gamma=file_gamma;   info_ptr->gamma = (float)gamma;#ifdef PNG_FIXED_POINT_SUPPORTED   info_ptr->int_gamma = (int)(gamma*100000.+.5);#endif   info_ptr->valid |= PNG_INFO_gAMA;   if(gamma == 0.0)      png_warning(png_ptr, "Setting gamma=0");}#endifvoid PNGAPIpng_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point   int_gamma){   png_fixed_point gamma;   png_debug1(1, "in %s storage function\n", "gAMA");   if (png_ptr == NULL || info_ptr == NULL)      return;   if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)   {     png_warning(png_ptr, "Limiting gamma to 21474.83");     gamma=PNG_UINT_31_MAX;   }   else   {     if (int_gamma < 0)     {       png_warning(png_ptr, "Setting negative gamma to zero");       gamma=0;     }     else       gamma=int_gamma;   }#ifdef PNG_FLOATING_POINT_SUPPORTED   info_ptr->gamma = (float)(gamma/100000.);#endif#ifdef PNG_FIXED_POINT_SUPPORTED   info_ptr->int_gamma = gamma;#endif   info_ptr->valid |= PNG_INFO_gAMA;   if(gamma == 0)      png_warning(png_ptr, "Setting gamma=0");}#endif#if defined(PNG_hIST_SUPPORTED)void PNGAPIpng_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist){   int i;   png_debug1(1, "in %s storage function\n", "hIST");   if (png_ptr == NULL || info_ptr == NULL)      return;   if (info_ptr->num_palette == 0)   {       png_warning(png_ptr,          "Palette size 0, hIST allocation skipped.");       return;   }#ifdef PNG_FREE_ME_SUPPORTED   png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);#endif   /* Changed from info->num_palette to 256 in version 1.2.1 */   png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,      (png_uint_32)(256 * png_sizeof (png_uint_16)));   if (png_ptr->hist == NULL)     {       png_warning(png_ptr, "Insufficient memory for hIST chunk data.");       return;     }   for (i = 0; i < info_ptr->num_palette; i++)       png_ptr->hist[i] = hist[i];   info_ptr->hist = png_ptr->hist;   info_ptr->valid |= PNG_INFO_hIST;#ifdef PNG_FREE_ME_SUPPORTED   info_ptr->free_me |= PNG_FREE_HIST;#else   png_ptr->flags |= PNG_FLAG_FREE_HIST;#endif}#endifvoid PNGAPIpng_set_IHDR(png_structp png_ptr, png_infop info_ptr,   png_uint_32 width, png_uint_32 height, int bit_depth,   int color_type, int interlace_type, int compression_type,   int filter_type){   png_debug1(1, "in %s storage function\n", "IHDR");   if (png_ptr == NULL || info_ptr == NULL)      return;   /* check for width and height valid values */   if (width == 0 || height == 0)      png_error(png_ptr, "Image width or height is zero in IHDR");#ifdef PNG_SET_USER_LIMITS_SUPPORTED   if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)      png_error(png_ptr, "image size exceeds user limits in IHDR");#else   if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)      png_error(png_ptr, "image size exceeds user limits in IHDR");#endif   if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)      png_error(png_ptr, "Invalid image size in IHDR");   if ( width > (PNG_UINT_32_MAX                 >> 3)      /* 8-byte RGBA pixels */                 - 64       /* bigrowbuf hack */                 - 1        /* filter byte */                 - 7*8      /* rounding of width to multiple of 8 pixels */                 - 8)       /* extra max_pixel_depth pad */      png_warning(png_ptr, "Width is too large for libpng to process pixels");   /* check other values */   if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&      bit_depth != 8 && bit_depth != 16)      png_error(png_ptr, "Invalid bit depth in IHDR");   if (color_type < 0 || color_type == 1 ||      color_type == 5 || color_type > 6)      png_error(png_ptr, "Invalid color type in IHDR");   if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||       ((color_type == PNG_COLOR_TYPE_RGB ||         color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||         color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))      png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");   if (interlace_type >= PNG_INTERLACE_LAST)      png_error(png_ptr, "Unknown interlace method in IHDR");   if (compression_type != PNG_COMPRESSION_TYPE_BASE)      png_error(png_ptr, "Unknown compression method in IHDR");#if defined(PNG_MNG_FEATURES_SUPPORTED)   /* Accept filter_method 64 (intrapixel differencing) only if    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and    * 2. Libpng did not read a PNG signature (this filter_method is only    *    used in PNG datastreams that are embedded in MNG datastreams) and    * 3. The application called png_permit_mng_features with a mask that    *    included PNG_FLAG_MNG_FILTER_64 and    * 4. The filter_method is 64 and    * 5. The color_type is RGB or RGBA    */   if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)      png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n");   if(filter_type != PNG_FILTER_TYPE_BASE)   {     if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&        (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&        ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&        (color_type == PNG_COLOR_TYPE_RGB ||          color_type == PNG_COLOR_TYPE_RGB_ALPHA)))        png_error(png_ptr, "Unknown filter method in IHDR");     if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)        png_warning(png_ptr, "Invalid filter method in IHDR");   }#else   if(filter_type != PNG_FILTER_TYPE_BASE)      png_error(png_ptr, "Unknown filter method in IHDR");#endif   info_ptr->width = width;   info_ptr->height = height;   info_ptr->bit_depth = (png_byte)bit_depth;   info_ptr->color_type =(png_byte) color_type;   info_ptr->compression_type = (png_byte)compression_type;   info_ptr->filter_type = (png_byte)filter_type;   info_ptr->interlace_type = (png_byte)interlace_type;   if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)      info_ptr->channels = 1;   else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)      info_ptr->channels = 3;   else      info_ptr->channels = 1;   if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)      info_ptr->channels++;   info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);   /* check for potential overflow */   if ( width > (PNG_UINT_32_MAX                 >> 3)      /* 8-byte RGBA pixels */                 - 64       /* bigrowbuf hack */                 - 1        /* filter byte */                 - 7*8      /* rounding of width to multiple of 8 pixels */                 - 8)       /* extra max_pixel_depth pad */      info_ptr->rowbytes = (png_size_t)0;   else      info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);}#if defined(PNG_oFFs_SUPPORTED)void PNGAPIpng_set_oFFs(png_structp png_ptr, png_infop info_ptr,   png_int_32 offset_x, png_int_32 offset_y, int unit_type){   png_debug1(1, "in %s storage function\n", "oFFs");   if (png_ptr == NULL || info_ptr == NULL)      return;   info_ptr->x_offset = offset_x;   info_ptr->y_offset = offset_y;   info_ptr->offset_unit_type = (png_byte)unit_type;   info_ptr->valid |= PNG_INFO_oFFs;}#endif#if defined(PNG_pCAL_SUPPORTED)void PNGAPIpng_set_pCAL(png_structp png_ptr, png_infop info_ptr,   png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,   png_charp units, png_charpp params){   png_uint_32 length;   int i;   png_debug1(1, "in %s storage function\n", "pCAL");   if (png_ptr == NULL || info_ptr == NULL)      return;   length = png_strlen(purpose) + 1;   png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);   info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);   if (info_ptr->pcal_purpose == NULL)     {       png_warning(png_ptr, "Insufficient memory for pCAL purpose.");       return;     }   png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);   png_debug(3, "storing X0, X1, type, and nparams in info\n");   info_ptr->pcal_X0 = X0;   info_ptr->pcal_X1 = X1;   info_ptr->pcal_type = (png_byte)type;   info_ptr->pcal_nparams = (png_byte)nparams;   length = png_strlen(units) + 1;   png_debug1(3, "allocating units for info (%lu bytes)\n", length);   info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);   if (info_ptr->pcal_units == NULL)     {       png_warning(png_ptr, "Insufficient memory for pCAL units.");       return;     }   png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);   info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -