Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1 | |
| 2 | /* pngset.c - storage of image information into info struct |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 3 | * |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 4 | * libpng 1.0.5h - December 10, 1999 |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 5 | * For conditions of distribution and use, see copyright notice in png.h |
| 6 | * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. |
| 7 | * Copyright (c) 1996, 1997 Andreas Dilger |
Glenn Randers-Pehrson | c944229 | 1999-01-06 21:50:16 -0600 | [diff] [blame] | 8 | * Copyright (c) 1998, 1999 Glenn Randers-Pehrson |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 9 | * |
| 10 | * The functions here are used during reads to store data from the file |
| 11 | * into the info struct, and during writes to store application data |
| 12 | * into the info struct for writing into the file. This abstracts the |
| 13 | * info struct and allows us to change the structure in the future. |
| 14 | */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 15 | |
| 16 | #define PNG_INTERNAL |
| 17 | #include "png.h" |
| 18 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 19 | #if defined(PNG_bKGD_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 20 | void |
| 21 | png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background) |
| 22 | { |
| 23 | png_debug1(1, "in %s storage function\n", "bKGD"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 24 | if (png_ptr == NULL || info_ptr == NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 25 | return; |
| 26 | |
| 27 | png_memcpy(&(info_ptr->background), background, sizeof(png_color_16)); |
| 28 | info_ptr->valid |= PNG_INFO_bKGD; |
| 29 | } |
| 30 | #endif |
| 31 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 32 | #if defined(PNG_cHRM_SUPPORTED) |
| 33 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 34 | void |
| 35 | png_set_cHRM(png_structp png_ptr, png_infop info_ptr, |
| 36 | double white_x, double white_y, double red_x, double red_y, |
| 37 | double green_x, double green_y, double blue_x, double blue_y) |
| 38 | { |
| 39 | png_debug1(1, "in %s storage function\n", "cHRM"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 40 | if (png_ptr == NULL || info_ptr == NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 41 | return; |
| 42 | |
| 43 | info_ptr->x_white = (float)white_x; |
| 44 | info_ptr->y_white = (float)white_y; |
| 45 | info_ptr->x_red = (float)red_x; |
| 46 | info_ptr->y_red = (float)red_y; |
| 47 | info_ptr->x_green = (float)green_x; |
| 48 | info_ptr->y_green = (float)green_y; |
| 49 | info_ptr->x_blue = (float)blue_x; |
| 50 | info_ptr->y_blue = (float)blue_y; |
| 51 | info_ptr->valid |= PNG_INFO_cHRM; |
| 52 | } |
| 53 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 54 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 55 | void |
| 56 | png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, |
| 57 | png_uint_32 white_x, png_uint_32 white_y, png_uint_32 red_x, |
| 58 | png_uint_32 red_y, png_uint_32 green_x, png_uint_32 green_y, |
| 59 | png_uint_32 blue_x, png_uint_32 blue_y) |
| 60 | { |
| 61 | png_debug1(1, "in %s storage function\n", "cHRM"); |
| 62 | if (png_ptr == NULL || info_ptr == NULL) |
| 63 | return; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 64 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 65 | info_ptr->int_x_white = white_x; |
| 66 | info_ptr->int_y_white = white_y; |
| 67 | info_ptr->int_x_red = red_x; |
| 68 | info_ptr->int_y_red = red_y; |
| 69 | info_ptr->int_x_green = green_x; |
| 70 | info_ptr->int_y_green = green_y; |
| 71 | info_ptr->int_x_blue = blue_x; |
| 72 | info_ptr->int_y_blue = blue_y; |
| 73 | info_ptr->valid |= PNG_INFO_cHRM; |
| 74 | } |
| 75 | #endif |
| 76 | #endif |
| 77 | |
| 78 | #if defined(PNG_gAMA_SUPPORTED) |
| 79 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 80 | void |
| 81 | png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) |
| 82 | { |
| 83 | png_debug1(1, "in %s storage function\n", "gAMA"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 84 | if (png_ptr == NULL || info_ptr == NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 85 | return; |
| 86 | |
| 87 | info_ptr->gamma = (float)file_gamma; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 88 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 89 | info_ptr->int_gamma = (int)(file_gamma*100000.+.5); |
| 90 | #endif |
| 91 | info_ptr->valid |= PNG_INFO_gAMA; |
| 92 | } |
| 93 | #endif |
| 94 | #endif |
| 95 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 96 | void |
| 97 | png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_uint_32 int_gamma) |
| 98 | { |
| 99 | png_debug1(1, "in %s storage function\n", "gAMA"); |
| 100 | if (png_ptr == NULL || info_ptr == NULL) |
| 101 | return; |
| 102 | |
| 103 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 104 | info_ptr->gamma = (float)int_gamma/100000.; |
| 105 | #endif |
| 106 | info_ptr->int_gamma = int_gamma; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 107 | info_ptr->valid |= PNG_INFO_gAMA; |
| 108 | } |
| 109 | #endif |
| 110 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 111 | #if defined(PNG_hIST_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 112 | void |
| 113 | png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) |
| 114 | { |
| 115 | png_debug1(1, "in %s storage function\n", "hIST"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 116 | if (png_ptr == NULL || info_ptr == NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 117 | return; |
| 118 | |
| 119 | info_ptr->hist = hist; |
| 120 | info_ptr->valid |= PNG_INFO_hIST; |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | void |
| 125 | png_set_IHDR(png_structp png_ptr, png_infop info_ptr, |
| 126 | png_uint_32 width, png_uint_32 height, int bit_depth, |
| 127 | int color_type, int interlace_type, int compression_type, |
| 128 | int filter_type) |
| 129 | { |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 130 | int rowbytes_per_pixel; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 131 | png_debug1(1, "in %s storage function\n", "IHDR"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 132 | if (png_ptr == NULL || info_ptr == NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 133 | return; |
| 134 | |
| 135 | info_ptr->width = width; |
| 136 | info_ptr->height = height; |
| 137 | info_ptr->bit_depth = (png_byte)bit_depth; |
| 138 | info_ptr->color_type =(png_byte) color_type; |
| 139 | info_ptr->compression_type = (png_byte)compression_type; |
| 140 | info_ptr->filter_type = (png_byte)filter_type; |
| 141 | info_ptr->interlace_type = (png_byte)interlace_type; |
| 142 | if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
| 143 | info_ptr->channels = 1; |
| 144 | else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) |
| 145 | info_ptr->channels = 3; |
| 146 | else |
| 147 | info_ptr->channels = 1; |
| 148 | if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) |
| 149 | info_ptr->channels++; |
| 150 | info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 151 | |
| 152 | /* check for overflow */ |
| 153 | rowbytes_per_pixel = (info_ptr->pixel_depth + 7) >> 3; |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 154 | if (( width > PNG_MAX_UINT/rowbytes_per_pixel)) |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 155 | { |
| 156 | png_warning(png_ptr, |
| 157 | "Width too large to process image data; rowbytes will overflow."); |
| 158 | info_ptr->rowbytes = (png_size_t)0; |
| 159 | } |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 160 | else |
| 161 | info_ptr->rowbytes = (info_ptr->width * info_ptr->pixel_depth + 7) >> 3; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 164 | #if defined(PNG_oFFs_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 165 | void |
| 166 | png_set_oFFs(png_structp png_ptr, png_infop info_ptr, |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 167 | png_int_32 offset_x, png_int_32 offset_y, int unit_type) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 168 | { |
| 169 | png_debug1(1, "in %s storage function\n", "oFFs"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 170 | if (png_ptr == NULL || info_ptr == NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 171 | return; |
| 172 | |
| 173 | info_ptr->x_offset = offset_x; |
| 174 | info_ptr->y_offset = offset_y; |
| 175 | info_ptr->offset_unit_type = (png_byte)unit_type; |
| 176 | info_ptr->valid |= PNG_INFO_oFFs; |
| 177 | } |
| 178 | #endif |
| 179 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 180 | #if defined(PNG_pCAL_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 181 | void |
| 182 | png_set_pCAL(png_structp png_ptr, png_infop info_ptr, |
| 183 | png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, |
| 184 | png_charp units, png_charpp params) |
| 185 | { |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 186 | png_uint_32 length; |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 187 | int i; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 188 | |
| 189 | png_debug1(1, "in %s storage function\n", "pCAL"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 190 | if (png_ptr == NULL || info_ptr == NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 191 | return; |
| 192 | |
| 193 | length = png_strlen(purpose) + 1; |
| 194 | png_debug1(3, "allocating purpose for info (%d bytes)\n", length); |
| 195 | info_ptr->pcal_purpose = (png_charp)png_malloc(png_ptr, length); |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 196 | png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 197 | |
| 198 | png_debug(3, "storing X0, X1, type, and nparams in info\n"); |
| 199 | info_ptr->pcal_X0 = X0; |
| 200 | info_ptr->pcal_X1 = X1; |
| 201 | info_ptr->pcal_type = (png_byte)type; |
| 202 | info_ptr->pcal_nparams = (png_byte)nparams; |
| 203 | |
| 204 | length = png_strlen(units) + 1; |
| 205 | png_debug1(3, "allocating units for info (%d bytes)\n", length); |
| 206 | info_ptr->pcal_units = (png_charp)png_malloc(png_ptr, length); |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 207 | png_memcpy(info_ptr->pcal_units, units, (png_size_t)length); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 208 | |
| 209 | info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 210 | (png_uint_32)((nparams + 1) * sizeof(png_charp))); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 211 | info_ptr->pcal_params[nparams] = NULL; |
| 212 | |
| 213 | for (i = 0; i < nparams; i++) |
| 214 | { |
| 215 | length = png_strlen(params[i]) + 1; |
| 216 | png_debug2(3, "allocating parameter %d for info (%d bytes)\n", i, length); |
| 217 | info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length); |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 218 | png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | info_ptr->valid |= PNG_INFO_pCAL; |
| 222 | } |
| 223 | #endif |
| 224 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 225 | #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED) |
| 226 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 227 | void |
| 228 | png_set_sCAL(png_structp png_ptr, png_infop info_ptr, |
| 229 | png_charp unit, double width, double height) |
| 230 | { |
| 231 | png_uint_32 length; |
| 232 | |
| 233 | png_debug1(1, "in %s storage function\n", "sCAL"); |
| 234 | if (png_ptr == NULL || info_ptr == NULL) |
| 235 | return; |
| 236 | |
| 237 | length = png_strlen(unit) + 1; |
| 238 | png_debug1(3, "allocating unit for info (%d bytes)\n", length); |
| 239 | info_ptr->scal_unit = (png_charp)png_malloc(png_ptr, length); |
| 240 | png_memcpy(info_ptr->scal_unit, unit, (png_size_t)length); |
| 241 | info_ptr->scal_pixel_width = width; |
| 242 | info_ptr->scal_pixel_height = height; |
| 243 | |
| 244 | info_ptr->valid |= PNG_INFO_sCAL; |
| 245 | } |
| 246 | #endif |
| 247 | void |
| 248 | png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, |
| 249 | png_charp unit, png_charp swidth, png_charp sheight) |
| 250 | { |
| 251 | png_uint_32 length; |
| 252 | |
| 253 | png_debug1(1, "in %s storage function\n", "sCAL"); |
| 254 | if (png_ptr == NULL || info_ptr == NULL) |
| 255 | return; |
| 256 | |
| 257 | length = png_strlen(unit) + 1; |
| 258 | png_debug1(3, "allocating unit for info (%d bytes)\n", length); |
| 259 | info_ptr->scal_unit = (png_charp)png_malloc(png_ptr, length); |
| 260 | png_memcpy(info_ptr->scal_unit, unit, (png_size_t)length); |
| 261 | |
| 262 | length = png_strlen(swidth) + 1; |
| 263 | png_debug1(3, "allocating unit for info (%d bytes)\n", length); |
| 264 | info_ptr->scal_s_width = (png_charp)png_malloc(png_ptr, length); |
| 265 | png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length); |
| 266 | |
| 267 | length = png_strlen(sheight) + 1; |
| 268 | png_debug1(3, "allocating unit for info (%d bytes)\n", length); |
| 269 | info_ptr->scal_s_width = (png_charp)png_malloc(png_ptr, length); |
| 270 | png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length); |
| 271 | |
| 272 | info_ptr->valid |= PNG_INFO_sCAL; |
| 273 | } |
| 274 | #endif |
| 275 | |
| 276 | #if defined(PNG_pHYs_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 277 | void |
| 278 | png_set_pHYs(png_structp png_ptr, png_infop info_ptr, |
| 279 | png_uint_32 res_x, png_uint_32 res_y, int unit_type) |
| 280 | { |
| 281 | png_debug1(1, "in %s storage function\n", "pHYs"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 282 | if (png_ptr == NULL || info_ptr == NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 283 | return; |
| 284 | |
| 285 | info_ptr->x_pixels_per_unit = res_x; |
| 286 | info_ptr->y_pixels_per_unit = res_y; |
| 287 | info_ptr->phys_unit_type = (png_byte)unit_type; |
| 288 | info_ptr->valid |= PNG_INFO_pHYs; |
| 289 | } |
| 290 | #endif |
| 291 | |
| 292 | void |
| 293 | png_set_PLTE(png_structp png_ptr, png_infop info_ptr, |
| 294 | png_colorp palette, int num_palette) |
| 295 | { |
| 296 | png_debug1(1, "in %s storage function\n", "PLTE"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 297 | if (png_ptr == NULL || info_ptr == NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 298 | return; |
| 299 | |
| 300 | info_ptr->palette = palette; |
| 301 | info_ptr->num_palette = (png_uint_16)num_palette; |
| 302 | info_ptr->valid |= PNG_INFO_PLTE; |
| 303 | } |
| 304 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 305 | #if defined(PNG_sBIT_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 306 | void |
| 307 | png_set_sBIT(png_structp png_ptr, png_infop info_ptr, |
| 308 | png_color_8p sig_bit) |
| 309 | { |
| 310 | png_debug1(1, "in %s storage function\n", "sBIT"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 311 | if (png_ptr == NULL || info_ptr == NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 312 | return; |
| 313 | |
| 314 | png_memcpy(&(info_ptr->sig_bit), sig_bit, sizeof (png_color_8)); |
| 315 | info_ptr->valid |= PNG_INFO_sBIT; |
| 316 | } |
| 317 | #endif |
| 318 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 319 | #if defined(PNG_sRGB_SUPPORTED) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 320 | void |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 321 | png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 322 | { |
| 323 | png_debug1(1, "in %s storage function\n", "sRGB"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 324 | if (png_ptr == NULL || info_ptr == NULL) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 325 | return; |
| 326 | |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 327 | info_ptr->srgb_intent = (png_byte)intent; |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 328 | info_ptr->valid |= PNG_INFO_sRGB; |
| 329 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 330 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 331 | void |
| 332 | png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 333 | int intent) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 334 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 335 | #if defined(PNG_gAMA_SUPPORTED) |
| 336 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 337 | float file_gamma; |
| 338 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 339 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 340 | png_uint_32 int_file_gamma; |
| 341 | #endif |
| 342 | #endif |
| 343 | #if defined(PNG_cHRM_SUPPORTED) |
| 344 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 345 | float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; |
| 346 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 347 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 348 | png_uint_32 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, |
| 349 | int_green_y, int_blue_x, int_blue_y; |
| 350 | #endif |
| 351 | #endif |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 352 | png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 353 | if (png_ptr == NULL || info_ptr == NULL) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 354 | return; |
| 355 | |
| 356 | png_set_sRGB(png_ptr, info_ptr, intent); |
| 357 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 358 | #if defined(PNG_gAMA_SUPPORTED) |
| 359 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
Glenn Randers-Pehrson | ab1e583 | 1999-10-06 04:57:42 -0500 | [diff] [blame] | 360 | file_gamma = (float).45455; |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 361 | png_set_gAMA(png_ptr, info_ptr, file_gamma); |
| 362 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 363 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 364 | int_file_gamma = 45455L; |
| 365 | png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); |
| 366 | #endif |
| 367 | #endif |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 368 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 369 | #if defined(PNG_cHRM_SUPPORTED) |
| 370 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 371 | int_white_x = 31270L; |
| 372 | int_white_y = 32900L; |
| 373 | int_red_x = 64000L; |
| 374 | int_red_y = 33000L; |
| 375 | int_green_x = 30000L; |
| 376 | int_green_y = 60000L; |
| 377 | int_blue_x = 15000L; |
| 378 | int_blue_y = 6000L; |
| 379 | |
| 380 | png_set_cHRM_fixed(png_ptr, info_ptr, |
| 381 | int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y, |
| 382 | int_blue_x, int_blue_y); |
| 383 | #endif |
| 384 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 385 | white_x = (float).3127; |
| 386 | white_y = (float).3290; |
| 387 | red_x = (float).64; |
| 388 | red_y = (float).33; |
| 389 | green_x = (float).30; |
| 390 | green_y = (float).60; |
| 391 | blue_x = (float).15; |
| 392 | blue_y = (float).06; |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 393 | |
| 394 | png_set_cHRM(png_ptr, info_ptr, |
| 395 | white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 396 | #endif |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 397 | #endif |
| 398 | } |
| 399 | #endif |
| 400 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 401 | |
| 402 | #if defined(PNG_iCCP_SUPPORTED) |
| 403 | void |
| 404 | png_set_iCCP(png_structp png_ptr, png_infop info_ptr, |
| 405 | png_charp name, int compression_type, |
| 406 | png_charp profile, int proflen) |
| 407 | { |
| 408 | png_debug1(1, "in %s storage function\n", "iCCP"); |
| 409 | if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) |
| 410 | return; |
| 411 | |
| 412 | info_ptr->iccp_name = png_malloc(png_ptr, png_strlen(name)+1); |
| 413 | strcpy(info_ptr->iccp_name, name); |
| 414 | info_ptr->iccp_profile = png_malloc(png_ptr, proflen); |
| 415 | memcpy(info_ptr->iccp_profile, profile, proflen); |
| 416 | info_ptr->iccp_proflen = (png_uint_32)proflen; |
| 417 | /* Compression is always zero but is here so the API and info structure |
| 418 | * does not have to change * if we introduce multiple compression types */ |
| 419 | info_ptr->iccp_compression = (png_byte)compression_type; |
| 420 | info_ptr->valid |= PNG_INFO_iCCP; |
| 421 | } |
| 422 | #endif |
| 423 | |
| 424 | #if defined(PNG_TEXT_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 425 | void |
| 426 | png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, |
| 427 | int num_text) |
| 428 | { |
| 429 | int i; |
| 430 | |
| 431 | png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ? |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 432 | "text" : (png_const_charp)png_ptr->chunk_name)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 433 | |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 434 | if (png_ptr == NULL || info_ptr == NULL || num_text == 0) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 435 | return; |
| 436 | |
| 437 | /* Make sure we have enough space in the "text" array in info_struct |
| 438 | * to hold all of the incoming text_ptr objects. |
| 439 | */ |
| 440 | if (info_ptr->num_text + num_text > info_ptr->max_text) |
| 441 | { |
| 442 | if (info_ptr->text != NULL) |
| 443 | { |
| 444 | png_textp old_text; |
| 445 | int old_max; |
| 446 | |
| 447 | old_max = info_ptr->max_text; |
| 448 | info_ptr->max_text = info_ptr->num_text + num_text + 8; |
| 449 | old_text = info_ptr->text; |
| 450 | info_ptr->text = (png_textp)png_malloc(png_ptr, |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 451 | (png_uint_32)(info_ptr->max_text * sizeof (png_text))); |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 452 | png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max * |
| 453 | sizeof(png_text))); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 454 | png_free(png_ptr, old_text); |
| 455 | } |
| 456 | else |
| 457 | { |
| 458 | info_ptr->max_text = num_text + 8; |
| 459 | info_ptr->num_text = 0; |
| 460 | info_ptr->text = (png_textp)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 461 | (png_uint_32)(info_ptr->max_text * sizeof (png_text))); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 462 | } |
| 463 | png_debug1(3, "allocated %d entries for info_ptr->text\n", |
| 464 | info_ptr->max_text); |
| 465 | } |
| 466 | |
| 467 | for (i = 0; i < num_text; i++) |
| 468 | { |
| 469 | png_textp textp = &(info_ptr->text[info_ptr->num_text]); |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 470 | png_charp key,text; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 471 | |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 472 | if (text_ptr[i].key == (png_charp)NULL) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 473 | continue; |
| 474 | |
| 475 | #ifdef PNG_iTXt_SUPPORTED |
| 476 | textp->lang = text_ptr[i].lang; |
| 477 | textp->translated_key = text_ptr[i].translated_key; |
| 478 | #else |
| 479 | textp->lang = NULL; |
| 480 | textp->translated_key = NULL; |
| 481 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 482 | |
| 483 | if (text_ptr[i].text[0] == '\0') |
| 484 | { |
| 485 | textp->text_length = 0; |
| 486 | textp->compression = PNG_TEXT_COMPRESSION_NONE; |
| 487 | } |
| 488 | else |
| 489 | { |
| 490 | textp->text_length = png_strlen(text_ptr[i].text); |
| 491 | textp->compression = text_ptr[i].compression; |
| 492 | } |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 493 | key=text_ptr[i].key; |
| 494 | for (text = key; *text++;) |
| 495 | /* empty loop to find the byte after the zero byte after the |
| 496 | end of key */ ; |
| 497 | |
| 498 | textp->key = (png_charp)png_malloc(png_ptr, |
| 499 | (png_uint_32)(text+textp->text_length - key)+1); |
| 500 | /* Caution: the calling program, not libpng, is responsible for |
| 501 | freeing this, if libpng wasn't the caller. */ |
| 502 | png_debug2(2, "Allocated %d bytes at %x in png_set_text\n", |
| 503 | text+textp->text_length-key+1, textp->key); |
| 504 | |
| 505 | png_memcpy(textp->key, text_ptr[i].key, |
| 506 | (png_size_t)(text - key)); /* includes the zero-byte separator */ |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 507 | |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 508 | textp->text = textp->key + (text-key); |
| 509 | if(textp->text_length) |
| 510 | { |
| 511 | png_memcpy(textp->text, text_ptr[i].text, |
| 512 | (png_size_t)(textp->text_length)); |
| 513 | *(textp->text+textp->text_length) = '\0'; |
| 514 | } |
| 515 | else |
| 516 | textp->text--; |
| 517 | info_ptr->text[info_ptr->num_text]= *textp; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 518 | info_ptr->num_text++; |
| 519 | png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text); |
| 520 | } |
| 521 | } |
| 522 | #endif |
| 523 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 524 | #if defined(PNG_tIME_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 525 | void |
| 526 | png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) |
| 527 | { |
| 528 | png_debug1(1, "in %s storage function\n", "tIME"); |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 529 | if (png_ptr == NULL || info_ptr == NULL || |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 530 | (png_ptr->mode & PNG_WROTE_tIME)) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 531 | return; |
| 532 | |
| 533 | png_memcpy(&(info_ptr->mod_time), mod_time, sizeof (png_time)); |
| 534 | info_ptr->valid |= PNG_INFO_tIME; |
| 535 | } |
| 536 | #endif |
| 537 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 538 | #if defined(PNG_tRNS_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 539 | void |
| 540 | png_set_tRNS(png_structp png_ptr, png_infop info_ptr, |
| 541 | png_bytep trans, int num_trans, png_color_16p trans_values) |
| 542 | { |
| 543 | png_debug1(1, "in %s storage function\n", "tRNS"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 544 | if (png_ptr == NULL || info_ptr == NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 545 | return; |
| 546 | |
| 547 | if (trans != NULL) |
| 548 | { |
| 549 | info_ptr->trans = trans; |
| 550 | } |
| 551 | |
| 552 | if (trans_values != NULL) |
| 553 | { |
| 554 | png_memcpy(&(info_ptr->trans_values), trans_values, |
| 555 | sizeof(png_color_16)); |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 556 | if (num_trans == 0) |
| 557 | num_trans = 1; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 558 | } |
| 559 | info_ptr->num_trans = (png_uint_16)num_trans; |
| 560 | info_ptr->valid |= PNG_INFO_tRNS; |
| 561 | } |
| 562 | #endif |
| 563 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 564 | #if defined(PNG_sPLT_SUPPORTED) |
| 565 | void |
| 566 | png_set_spalettes(png_structp png_ptr, |
| 567 | png_infop info_ptr, png_spalette_p entries, int nentries) |
| 568 | { |
| 569 | png_spalette_p np; |
| 570 | int i; |
| 571 | |
| 572 | np = (png_spalette_p)png_malloc(png_ptr, |
| 573 | (info_ptr->splt_palettes_num + nentries) * sizeof(png_spalette)); |
| 574 | |
| 575 | memcpy(np, info_ptr->splt_palettes, |
| 576 | info_ptr->splt_palettes_num * sizeof(png_spalette)); |
| 577 | png_free(png_ptr, info_ptr->splt_palettes); |
| 578 | |
| 579 | for (i = 0; i < nentries; i++) |
| 580 | { |
| 581 | png_spalette_p to = np + info_ptr->splt_palettes_num + i; |
| 582 | png_spalette_p from = entries + i; |
| 583 | |
| 584 | to->name = (png_charp)png_malloc(png_ptr, |
| 585 | png_strlen(from->name) + 1); |
| 586 | png_strcpy(to->name, from->name); |
| 587 | to->entries = (png_spalette_entryp)png_malloc(png_ptr, |
| 588 | from->nentries * sizeof(png_spalette)); |
| 589 | memcpy(to->entries, from->entries, |
| 590 | from->nentries * sizeof(png_spalette)); |
| 591 | } |
| 592 | |
| 593 | info_ptr->splt_palettes = np; |
| 594 | info_ptr->splt_palettes_num += nentries; |
| 595 | } |
| 596 | #endif /* PNG_sPLT_SUPPORTED */ |
| 597 | |
| 598 | #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 599 | void |
| 600 | png_set_unknown_chunks(png_structp png_ptr, |
| 601 | png_infop info_ptr, png_unknown_chunkp unknowns, int nunknowns) |
| 602 | { |
| 603 | png_unknown_chunkp np; |
| 604 | int i; |
| 605 | |
| 606 | np = (png_unknown_chunkp)png_malloc(png_ptr, |
| 607 | (info_ptr->unknown_chunks_num + nunknowns) * sizeof(png_unknown_chunk)); |
| 608 | |
| 609 | memcpy(np, info_ptr->unknown_chunks, |
| 610 | info_ptr->unknown_chunks_num * sizeof(png_unknown_chunk)); |
| 611 | png_free(png_ptr, info_ptr->unknown_chunks); |
| 612 | |
| 613 | for (i = 0; i < nunknowns; i++) |
| 614 | { |
| 615 | png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i; |
| 616 | png_unknown_chunkp from = unknowns + i; |
| 617 | |
| 618 | png_strcpy(to->name, from->name); |
| 619 | to->data = (png_bytep)png_malloc(png_ptr, from->size); |
| 620 | memcpy(to->data, from->data, from->size); |
| 621 | to->size = from->size; |
| 622 | |
| 623 | /* note our location in the read or write sequence */ |
| 624 | to->location = png_ptr->mode; |
| 625 | } |
| 626 | |
| 627 | info_ptr->unknown_chunks = np; |
| 628 | info_ptr->unknown_chunks_num += nunknowns; |
| 629 | } |
| 630 | #endif |
| 631 | |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 632 | #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) |
| 633 | void |
| 634 | png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted) |
| 635 | { |
| 636 | png_debug1(1, "in png_permit_empty_plte\n", ""); |
| 637 | if (png_ptr == NULL) |
| 638 | return; |
| 639 | png_ptr->empty_plte_permitted=(png_byte)empty_plte_permitted; |
| 640 | } |
| 641 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |