?? pngset.c
字號:
/* pngset.c - storage of image information into info struct * * libpng 1.0.9 - January 31, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 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, 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; 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; 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){ png_debug1(1, "in %s storage function\n", "gAMA"); if (png_ptr == NULL || info_ptr == NULL) return; info_ptr->gamma = (float)file_gamma;#ifdef PNG_FIXED_POINT_SUPPORTED info_ptr->int_gamma = (int)(file_gamma*100000.+.5);#endif info_ptr->valid |= PNG_INFO_gAMA;}#endif#endifvoid PNGAPIpng_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point int_gamma){ png_debug1(1, "in %s storage function\n", "gAMA"); if (png_ptr == NULL || info_ptr == NULL) return;#ifdef PNG_FLOATING_POINT_SUPPORTED info_ptr->gamma = (float)(int_gamma/100000.);#endif#ifdef PNG_FIXED_POINT_SUPPORTED info_ptr->int_gamma = int_gamma;#endif info_ptr->valid |= PNG_INFO_gAMA;}#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.");#ifdef PNG_FREE_ME_SUPPORTED png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);#endif png_ptr->hist = (png_uint_16p)png_malloc(png_ptr, (png_uint_32)(info_ptr->num_palette * sizeof (png_uint_16))); 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){ int rowbytes_per_pixel; png_debug1(1, "in %s storage function\n", "IHDR"); if (png_ptr == NULL || info_ptr == NULL) return; 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 overflow */ rowbytes_per_pixel = (info_ptr->pixel_depth + 7) >> 3; if (( width > PNG_MAX_UINT/rowbytes_per_pixel)) { png_warning(png_ptr, "Width too large to process image data; rowbytes will overflow."); info_ptr->rowbytes = (png_size_t)0; } else info_ptr->rowbytes = (info_ptr->width * info_ptr->pixel_depth + 7) >> 3;}#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(png_ptr, length); 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(png_ptr, length); png_memcpy(info_ptr->pcal_units, units, (png_size_t)length); info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr, (png_uint_32)((nparams + 1) * sizeof(png_charp))); info_ptr->pcal_params[nparams] = NULL; for (i = 0; i < nparams; i++) { length = png_strlen(params[i]) + 1; png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length); info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length); png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length); } info_ptr->valid |= PNG_INFO_pCAL;#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_PCAL;#endif}#endif#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)#ifdef PNG_FLOATING_POINT_SUPPORTEDvoid PNGAPIpng_set_sCAL(png_structp png_ptr, png_infop info_ptr, int unit, double width, double height){ png_debug1(1, "in %s storage function\n", "sCAL"); if (png_ptr == NULL || info_ptr == NULL) return; info_ptr->scal_unit = (png_byte)unit; info_ptr->scal_pixel_width = width; info_ptr->scal_pixel_height = height; info_ptr->valid |= PNG_INFO_sCAL;}#else#ifdef PNG_FIXED_POINT_SUPPORTEDvoid PNGAPIpng_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, int unit, png_charp swidth, png_charp sheight){ png_uint_32 length; png_debug1(1, "in %s storage function\n", "sCAL"); if (png_ptr == NULL || info_ptr == NULL) return; info_ptr->scal_unit = (png_byte)unit; length = png_strlen(swidth) + 1; png_debug1(3, "allocating unit for info (%d bytes)\n", length); info_ptr->scal_s_width = (png_charp)png_malloc(png_ptr, length); png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length); length = png_strlen(sheight) + 1; png_debug1(3, "allocating unit for info (%d bytes)\n", length); info_ptr->scal_s_width = (png_charp)png_malloc(png_ptr, length); png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length); info_ptr->valid |= PNG_INFO_sCAL;#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_SCAL;#endif}#endif#endif#endif#if defined(PNG_pHYs_SUPPORTED)void PNGAPIpng_set_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type){ png_debug1(1, "in %s storage function\n", "pHYs"); if (png_ptr == NULL || info_ptr == NULL) return; info_ptr->x_pixels_per_unit = res_x; info_ptr->y_pixels_per_unit = res_y; info_ptr->phys_unit_type = (png_byte)unit_type; info_ptr->valid |= PNG_INFO_pHYs;}#endifvoid PNGAPIpng_set_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp palette, int num_palette){ png_debug1(1, "in %s storage function\n", "PLTE"); if (png_ptr == NULL || info_ptr == NULL) return; /* * It may not actually be necessary to set png_ptr->palette here; * we do it for backward compatibility with the way the png_handle_tRNS * function used to do the allocation. */#ifdef PNG_FREE_ME_SUPPORTED png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);#endif png_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)num_palette, sizeof (png_color)); memcpy(png_ptr->palette, palette, num_palette * sizeof (png_color)); info_ptr->palette = png_ptr->palette; info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;#ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_PLTE;#else png_ptr->flags |= PNG_FLAG_FREE_PLTE;#endif info_ptr->valid |= PNG_INFO_PLTE;}#if defined(PNG_sBIT_SUPPORTED)void PNGAPIpng_set_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p sig_bit){ png_debug1(1, "in %s storage function\n", "sBIT"); if (png_ptr == NULL || info_ptr == NULL) return; png_memcpy(&(info_ptr->sig_bit), sig_bit, sizeof (png_color_8)); info_ptr->valid |= PNG_INFO_sBIT;}#endif#if defined(PNG_sRGB_SUPPORTED)void PNGAPIpng_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent){ png_debug1(1, "in %s storage function\n", "sRGB"); if (png_ptr == NULL || info_ptr == NULL) return; info_ptr->srgb_intent = (png_byte)intent; info_ptr->valid |= PNG_INFO_sRGB;}void PNGAPIpng_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, int intent){#if defined(PNG_gAMA_SUPPORTED)#ifdef PNG_FLOATING_POINT_SUPPORTED float file_gamma;#endif#ifdef PNG_FIXED_POINT_SUPPORTED png_fixed_point int_file_gamma;#endif#endif#if defined(PNG_cHRM_SUPPORTED)#ifdef PNG_FLOATING_POINT_SUPPORTED float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;#endif#ifdef PNG_FIXED_POINT_SUPPORTED png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y;#endif#endif png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM"); if (png_ptr == NULL || info_ptr == NULL) return; png_set_sRGB(png_ptr, info_ptr, intent);#if defined(PNG_gAMA_SUPPORTED)#ifdef PNG_FLOATING_POINT_SUPPORTED file_gamma = (float).45455; png_set_gAMA(png_ptr, info_ptr, file_gamma);#endif#ifdef PNG_FIXED_POINT_SUPPORTED int_file_gamma = 45455L; png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);#endif#endif#if defined(PNG_cHRM_SUPPORTED)#ifdef PNG_FIXED_POINT_SUPPORTED int_white_x = 31270L; int_white_y = 32900L; int_red_x = 64000L; int_red_y = 33000L; int_green_x = 30000L; int_green_y = 60000L; int_blue_x = 15000L; int_blue_y = 6000L; png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y);#endif#ifdef PNG_FLOATING_POINT_SUPPORTED white_x = (float).3127; white_y = (float).3290; red_x = (float).64; red_y = (float).33; green_x = (float).30; green_y = (float).60; blue_x = (float).15; blue_y = (float).06; png_set_cHRM(png_ptr, info_ptr, white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -