]> git.saurik.com Git - wxWidgets.git/blame - src/png/pngset.c
Fix history in wxWebViewIE when using a custom file scheme.
[wxWidgets.git] / src / png / pngset.c
CommitLineData
0272a10d
VZ
1
2/* pngset.c - storage of image information into info struct
3 *
b61cc19c
PC
4 * Last changed in libpng 1.4.1 [February 25, 2010]
5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
0272a10d
VZ
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
b61cc19c
PC
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
0272a10d
VZ
13 * The functions here are used during reads to store data from the file
14 * into the info struct, and during writes to store application data
15 * into the info struct for writing into the file. This abstracts the
16 * info struct and allows us to change the structure in the future.
17 */
18
b61cc19c 19#define PNG_NO_PEDANTIC_WARNINGS
0272a10d 20#include "png.h"
0272a10d 21#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
b61cc19c 22#include "pngpriv.h"
0272a10d 23
b61cc19c 24#ifdef PNG_bKGD_SUPPORTED
0272a10d
VZ
25void PNGAPI
26png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
27{
970f6abe 28 png_debug1(1, "in %s storage function", "bKGD");
b61cc19c 29
0272a10d
VZ
30 if (png_ptr == NULL || info_ptr == NULL)
31 return;
32
33 png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
34 info_ptr->valid |= PNG_INFO_bKGD;
35}
36#endif
37
b61cc19c 38#ifdef PNG_cHRM_SUPPORTED
0272a10d
VZ
39#ifdef PNG_FLOATING_POINT_SUPPORTED
40void PNGAPI
41png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
42 double white_x, double white_y, double red_x, double red_y,
43 double green_x, double green_y, double blue_x, double blue_y)
44{
970f6abe 45 png_debug1(1, "in %s storage function", "cHRM");
b61cc19c 46
0272a10d
VZ
47 if (png_ptr == NULL || info_ptr == NULL)
48 return;
49
0272a10d
VZ
50 info_ptr->x_white = (float)white_x;
51 info_ptr->y_white = (float)white_y;
52 info_ptr->x_red = (float)red_x;
53 info_ptr->y_red = (float)red_y;
54 info_ptr->x_green = (float)green_x;
55 info_ptr->y_green = (float)green_y;
56 info_ptr->x_blue = (float)blue_x;
57 info_ptr->y_blue = (float)blue_y;
58#ifdef PNG_FIXED_POINT_SUPPORTED
59 info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
60 info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
61 info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
62 info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
63 info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
64 info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
65 info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
66 info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
67#endif
68 info_ptr->valid |= PNG_INFO_cHRM;
69}
b61cc19c
PC
70#endif /* PNG_FLOATING_POINT_SUPPORTED */
71
0272a10d
VZ
72#ifdef PNG_FIXED_POINT_SUPPORTED
73void PNGAPI
74png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
75 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
76 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
77 png_fixed_point blue_x, png_fixed_point blue_y)
78{
970f6abe 79 png_debug1(1, "in %s storage function", "cHRM fixed");
b61cc19c 80
0272a10d
VZ
81 if (png_ptr == NULL || info_ptr == NULL)
82 return;
83
b61cc19c 84#ifdef PNG_CHECK_cHRM_SUPPORTED
970f6abe
VZ
85 if (png_check_cHRM_fixed(png_ptr,
86 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
0272a10d
VZ
87#endif
88 {
b61cc19c
PC
89 info_ptr->int_x_white = white_x;
90 info_ptr->int_y_white = white_y;
91 info_ptr->int_x_red = red_x;
92 info_ptr->int_y_red = red_y;
93 info_ptr->int_x_green = green_x;
94 info_ptr->int_y_green = green_y;
95 info_ptr->int_x_blue = blue_x;
96 info_ptr->int_y_blue = blue_y;
97#ifdef PNG_FLOATING_POINT_SUPPORTED
98 info_ptr->x_white = (float)(white_x/100000.);
99 info_ptr->y_white = (float)(white_y/100000.);
100 info_ptr->x_red = (float)( red_x/100000.);
101 info_ptr->y_red = (float)( red_y/100000.);
102 info_ptr->x_green = (float)(green_x/100000.);
103 info_ptr->y_green = (float)(green_y/100000.);
104 info_ptr->x_blue = (float)( blue_x/100000.);
105 info_ptr->y_blue = (float)( blue_y/100000.);
106#endif
107 info_ptr->valid |= PNG_INFO_cHRM;
970f6abe 108 }
0272a10d 109}
970f6abe
VZ
110#endif /* PNG_FIXED_POINT_SUPPORTED */
111#endif /* PNG_cHRM_SUPPORTED */
0272a10d 112
b61cc19c 113#ifdef PNG_gAMA_SUPPORTED
0272a10d
VZ
114#ifdef PNG_FLOATING_POINT_SUPPORTED
115void PNGAPI
116png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
117{
b61cc19c
PC
118 double png_gamma;
119
970f6abe 120 png_debug1(1, "in %s storage function", "gAMA");
b61cc19c 121
0272a10d
VZ
122 if (png_ptr == NULL || info_ptr == NULL)
123 return;
124
125 /* Check for overflow */
126 if (file_gamma > 21474.83)
127 {
128 png_warning(png_ptr, "Limiting gamma to 21474.83");
b61cc19c 129 png_gamma=21474.83;
0272a10d
VZ
130 }
131 else
b61cc19c
PC
132 png_gamma = file_gamma;
133 info_ptr->gamma = (float)png_gamma;
0272a10d 134#ifdef PNG_FIXED_POINT_SUPPORTED
b61cc19c 135 info_ptr->int_gamma = (int)(png_gamma*100000.+.5);
0272a10d
VZ
136#endif
137 info_ptr->valid |= PNG_INFO_gAMA;
b61cc19c 138 if (png_gamma == 0.0)
0272a10d
VZ
139 png_warning(png_ptr, "Setting gamma=0");
140}
141#endif
142void PNGAPI
143png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
144 int_gamma)
145{
b61cc19c 146 png_fixed_point png_gamma;
0272a10d 147
970f6abe 148 png_debug1(1, "in %s storage function", "gAMA");
b61cc19c 149
0272a10d
VZ
150 if (png_ptr == NULL || info_ptr == NULL)
151 return;
152
b61cc19c 153 if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX)
0272a10d 154 {
b61cc19c
PC
155 png_warning(png_ptr, "Limiting gamma to 21474.83");
156 png_gamma=PNG_UINT_31_MAX;
0272a10d
VZ
157 }
158 else
159 {
b61cc19c
PC
160 if (int_gamma < 0)
161 {
162 png_warning(png_ptr, "Setting negative gamma to zero");
163 png_gamma = 0;
164 }
165 else
166 png_gamma = int_gamma;
0272a10d
VZ
167 }
168#ifdef PNG_FLOATING_POINT_SUPPORTED
b61cc19c 169 info_ptr->gamma = (float)(png_gamma/100000.);
0272a10d
VZ
170#endif
171#ifdef PNG_FIXED_POINT_SUPPORTED
b61cc19c 172 info_ptr->int_gamma = png_gamma;
0272a10d
VZ
173#endif
174 info_ptr->valid |= PNG_INFO_gAMA;
b61cc19c 175 if (png_gamma == 0)
0272a10d
VZ
176 png_warning(png_ptr, "Setting gamma=0");
177}
178#endif
179
b61cc19c 180#ifdef PNG_hIST_SUPPORTED
0272a10d
VZ
181void PNGAPI
182png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
183{
184 int i;
185
970f6abe 186 png_debug1(1, "in %s storage function", "hIST");
b61cc19c 187
0272a10d
VZ
188 if (png_ptr == NULL || info_ptr == NULL)
189 return;
b61cc19c 190
970f6abe 191 if (info_ptr->num_palette == 0 || info_ptr->num_palette
0272a10d
VZ
192 > PNG_MAX_PALETTE_LENGTH)
193 {
b61cc19c
PC
194 png_warning(png_ptr,
195 "Invalid palette size, hIST allocation skipped");
196 return;
0272a10d
VZ
197 }
198
0272a10d 199 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
b61cc19c
PC
200 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
201 * version 1.2.1
202 */
0272a10d 203 png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
b61cc19c 204 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16));
0272a10d 205 if (png_ptr->hist == NULL)
b61cc19c
PC
206 {
207 png_warning(png_ptr, "Insufficient memory for hIST chunk data");
208 return;
209 }
0272a10d
VZ
210
211 for (i = 0; i < info_ptr->num_palette; i++)
b61cc19c 212 png_ptr->hist[i] = hist[i];
0272a10d
VZ
213 info_ptr->hist = png_ptr->hist;
214 info_ptr->valid |= PNG_INFO_hIST;
215
0272a10d 216 info_ptr->free_me |= PNG_FREE_HIST;
0272a10d
VZ
217}
218#endif
219
220void PNGAPI
221png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
222 png_uint_32 width, png_uint_32 height, int bit_depth,
223 int color_type, int interlace_type, int compression_type,
224 int filter_type)
225{
970f6abe 226 png_debug1(1, "in %s storage function", "IHDR");
b61cc19c 227
0272a10d
VZ
228 if (png_ptr == NULL || info_ptr == NULL)
229 return;
230
0272a10d
VZ
231 info_ptr->width = width;
232 info_ptr->height = height;
233 info_ptr->bit_depth = (png_byte)bit_depth;
b61cc19c 234 info_ptr->color_type = (png_byte)color_type;
0272a10d
VZ
235 info_ptr->compression_type = (png_byte)compression_type;
236 info_ptr->filter_type = (png_byte)filter_type;
237 info_ptr->interlace_type = (png_byte)interlace_type;
b61cc19c
PC
238
239 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
240 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
241 info_ptr->compression_type, info_ptr->filter_type);
242
0272a10d
VZ
243 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
244 info_ptr->channels = 1;
245 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
246 info_ptr->channels = 3;
247 else
248 info_ptr->channels = 1;
249 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
250 info_ptr->channels++;
251 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
252
b61cc19c 253 /* Check for potential overflow */
0272a10d
VZ
254 if (width > (PNG_UINT_32_MAX
255 >> 3) /* 8-byte RGBA pixels */
256 - 64 /* bigrowbuf hack */
257 - 1 /* filter byte */
258 - 7*8 /* rounding of width to multiple of 8 pixels */
259 - 8) /* extra max_pixel_depth pad */
b61cc19c 260 info_ptr->rowbytes = 0;
0272a10d 261 else
970f6abe 262 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
0272a10d
VZ
263}
264
b61cc19c 265#ifdef PNG_oFFs_SUPPORTED
0272a10d
VZ
266void PNGAPI
267png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
268 png_int_32 offset_x, png_int_32 offset_y, int unit_type)
269{
970f6abe 270 png_debug1(1, "in %s storage function", "oFFs");
b61cc19c 271
0272a10d
VZ
272 if (png_ptr == NULL || info_ptr == NULL)
273 return;
274
275 info_ptr->x_offset = offset_x;
276 info_ptr->y_offset = offset_y;
277 info_ptr->offset_unit_type = (png_byte)unit_type;
278 info_ptr->valid |= PNG_INFO_oFFs;
279}
280#endif
281
b61cc19c 282#ifdef PNG_pCAL_SUPPORTED
0272a10d
VZ
283void PNGAPI
284png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
285 png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
286 png_charp units, png_charpp params)
287{
b61cc19c 288 png_size_t length;
0272a10d
VZ
289 int i;
290
970f6abe 291 png_debug1(1, "in %s storage function", "pCAL");
b61cc19c 292
0272a10d
VZ
293 if (png_ptr == NULL || info_ptr == NULL)
294 return;
295
296 length = png_strlen(purpose) + 1;
970f6abe
VZ
297 png_debug1(3, "allocating purpose for info (%lu bytes)",
298 (unsigned long)length);
0272a10d
VZ
299 info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
300 if (info_ptr->pcal_purpose == NULL)
970f6abe 301 {
b61cc19c 302 png_warning(png_ptr, "Insufficient memory for pCAL purpose");
970f6abe
VZ
303 return;
304 }
b61cc19c 305 png_memcpy(info_ptr->pcal_purpose, purpose, length);
0272a10d 306
970f6abe 307 png_debug(3, "storing X0, X1, type, and nparams in info");
0272a10d
VZ
308 info_ptr->pcal_X0 = X0;
309 info_ptr->pcal_X1 = X1;
310 info_ptr->pcal_type = (png_byte)type;
311 info_ptr->pcal_nparams = (png_byte)nparams;
312
313 length = png_strlen(units) + 1;
970f6abe
VZ
314 png_debug1(3, "allocating units for info (%lu bytes)",
315 (unsigned long)length);
0272a10d
VZ
316 info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
317 if (info_ptr->pcal_units == NULL)
970f6abe 318 {
b61cc19c 319 png_warning(png_ptr, "Insufficient memory for pCAL units");
970f6abe
VZ
320 return;
321 }
b61cc19c 322 png_memcpy(info_ptr->pcal_units, units, length);
0272a10d
VZ
323
324 info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
b61cc19c 325 (png_size_t)((nparams + 1) * png_sizeof(png_charp)));
0272a10d 326 if (info_ptr->pcal_params == NULL)
970f6abe 327 {
b61cc19c 328 png_warning(png_ptr, "Insufficient memory for pCAL params");
970f6abe
VZ
329 return;
330 }
0272a10d 331
b61cc19c 332 png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp));
0272a10d
VZ
333
334 for (i = 0; i < nparams; i++)
335 {
336 length = png_strlen(params[i]) + 1;
970f6abe
VZ
337 png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
338 (unsigned long)length);
0272a10d
VZ
339 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
340 if (info_ptr->pcal_params[i] == NULL)
970f6abe 341 {
b61cc19c
PC
342 png_warning(png_ptr, "Insufficient memory for pCAL parameter");
343 return;
970f6abe 344 }
b61cc19c 345 png_memcpy(info_ptr->pcal_params[i], params[i], length);
0272a10d
VZ
346 }
347
348 info_ptr->valid |= PNG_INFO_pCAL;
0272a10d 349 info_ptr->free_me |= PNG_FREE_PCAL;
0272a10d
VZ
350}
351#endif
352
353#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
354#ifdef PNG_FLOATING_POINT_SUPPORTED
355void PNGAPI
356png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
357 int unit, double width, double height)
358{
970f6abe 359 png_debug1(1, "in %s storage function", "sCAL");
b61cc19c 360
0272a10d
VZ
361 if (png_ptr == NULL || info_ptr == NULL)
362 return;
363
364 info_ptr->scal_unit = (png_byte)unit;
365 info_ptr->scal_pixel_width = width;
366 info_ptr->scal_pixel_height = height;
367
368 info_ptr->valid |= PNG_INFO_sCAL;
369}
370#else
371#ifdef PNG_FIXED_POINT_SUPPORTED
372void PNGAPI
373png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
374 int unit, png_charp swidth, png_charp sheight)
375{
b61cc19c 376 png_size_t length;
0272a10d 377
970f6abe 378 png_debug1(1, "in %s storage function", "sCAL");
b61cc19c 379
0272a10d
VZ
380 if (png_ptr == NULL || info_ptr == NULL)
381 return;
382
383 info_ptr->scal_unit = (png_byte)unit;
384
385 length = png_strlen(swidth) + 1;
970f6abe
VZ
386 png_debug1(3, "allocating unit for info (%u bytes)",
387 (unsigned int)length);
0272a10d
VZ
388 info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
389 if (info_ptr->scal_s_width == NULL)
390 {
391 png_warning(png_ptr,
b61cc19c 392 "Memory allocation failed while processing sCAL");
970f6abe 393 return;
0272a10d 394 }
b61cc19c 395 png_memcpy(info_ptr->scal_s_width, swidth, length);
0272a10d
VZ
396
397 length = png_strlen(sheight) + 1;
970f6abe
VZ
398 png_debug1(3, "allocating unit for info (%u bytes)",
399 (unsigned int)length);
0272a10d
VZ
400 info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
401 if (info_ptr->scal_s_height == NULL)
402 {
403 png_free (png_ptr, info_ptr->scal_s_width);
970f6abe 404 info_ptr->scal_s_width = NULL;
0272a10d 405 png_warning(png_ptr,
b61cc19c 406 "Memory allocation failed while processing sCAL");
970f6abe 407 return;
0272a10d 408 }
b61cc19c 409 png_memcpy(info_ptr->scal_s_height, sheight, length);
0272a10d 410 info_ptr->valid |= PNG_INFO_sCAL;
0272a10d 411 info_ptr->free_me |= PNG_FREE_SCAL;
0272a10d
VZ
412}
413#endif
414#endif
415#endif
416
b61cc19c 417#ifdef PNG_pHYs_SUPPORTED
0272a10d
VZ
418void PNGAPI
419png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
420 png_uint_32 res_x, png_uint_32 res_y, int unit_type)
421{
970f6abe 422 png_debug1(1, "in %s storage function", "pHYs");
b61cc19c 423
0272a10d
VZ
424 if (png_ptr == NULL || info_ptr == NULL)
425 return;
426
427 info_ptr->x_pixels_per_unit = res_x;
428 info_ptr->y_pixels_per_unit = res_y;
429 info_ptr->phys_unit_type = (png_byte)unit_type;
430 info_ptr->valid |= PNG_INFO_pHYs;
431}
432#endif
433
434void PNGAPI
435png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
436 png_colorp palette, int num_palette)
437{
438
970f6abe 439 png_debug1(1, "in %s storage function", "PLTE");
b61cc19c 440
0272a10d
VZ
441 if (png_ptr == NULL || info_ptr == NULL)
442 return;
443
444 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
b61cc19c
PC
445 {
446 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
0272a10d 447 png_error(png_ptr, "Invalid palette length");
b61cc19c
PC
448 else
449 {
0272a10d
VZ
450 png_warning(png_ptr, "Invalid palette length");
451 return;
b61cc19c
PC
452 }
453 }
0272a10d 454
b61cc19c 455 /* It may not actually be necessary to set png_ptr->palette here;
0272a10d
VZ
456 * we do it for backward compatibility with the way the png_handle_tRNS
457 * function used to do the allocation.
458 */
0272a10d 459 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
0272a10d
VZ
460
461 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
b61cc19c
PC
462 * of num_palette entries, in case of an invalid PNG file that has
463 * too-large sample values.
464 */
465 png_ptr->palette = (png_colorp)png_calloc(png_ptr,
0272a10d 466 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
970f6abe 467 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
0272a10d
VZ
468 info_ptr->palette = png_ptr->palette;
469 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
470
0272a10d 471 info_ptr->free_me |= PNG_FREE_PLTE;
0272a10d
VZ
472
473 info_ptr->valid |= PNG_INFO_PLTE;
474}
475
b61cc19c 476#ifdef PNG_sBIT_SUPPORTED
0272a10d
VZ
477void PNGAPI
478png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
479 png_color_8p sig_bit)
480{
970f6abe 481 png_debug1(1, "in %s storage function", "sBIT");
b61cc19c 482
0272a10d
VZ
483 if (png_ptr == NULL || info_ptr == NULL)
484 return;
485
970f6abe 486 png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
0272a10d
VZ
487 info_ptr->valid |= PNG_INFO_sBIT;
488}
489#endif
490
b61cc19c 491#ifdef PNG_sRGB_SUPPORTED
0272a10d
VZ
492void PNGAPI
493png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
494{
970f6abe 495 png_debug1(1, "in %s storage function", "sRGB");
b61cc19c 496
0272a10d
VZ
497 if (png_ptr == NULL || info_ptr == NULL)
498 return;
499
500 info_ptr->srgb_intent = (png_byte)intent;
501 info_ptr->valid |= PNG_INFO_sRGB;
502}
503
504void PNGAPI
505png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
506 int intent)
507{
b61cc19c 508#ifdef PNG_gAMA_SUPPORTED
0272a10d
VZ
509#ifdef PNG_FLOATING_POINT_SUPPORTED
510 float file_gamma;
511#endif
512#ifdef PNG_FIXED_POINT_SUPPORTED
513 png_fixed_point int_file_gamma;
514#endif
515#endif
b61cc19c 516#ifdef PNG_cHRM_SUPPORTED
0272a10d
VZ
517#ifdef PNG_FLOATING_POINT_SUPPORTED
518 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
519#endif
0272a10d
VZ
520 png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
521 int_green_y, int_blue_x, int_blue_y;
522#endif
970f6abe 523 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
b61cc19c 524
0272a10d
VZ
525 if (png_ptr == NULL || info_ptr == NULL)
526 return;
527
528 png_set_sRGB(png_ptr, info_ptr, intent);
529
b61cc19c 530#ifdef PNG_gAMA_SUPPORTED
0272a10d
VZ
531#ifdef PNG_FLOATING_POINT_SUPPORTED
532 file_gamma = (float).45455;
533 png_set_gAMA(png_ptr, info_ptr, file_gamma);
534#endif
535#ifdef PNG_FIXED_POINT_SUPPORTED
536 int_file_gamma = 45455L;
537 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
538#endif
539#endif
540
b61cc19c 541#ifdef PNG_cHRM_SUPPORTED
0272a10d
VZ
542 int_white_x = 31270L;
543 int_white_y = 32900L;
544 int_red_x = 64000L;
545 int_red_y = 33000L;
546 int_green_x = 30000L;
547 int_green_y = 60000L;
548 int_blue_x = 15000L;
549 int_blue_y = 6000L;
550
0272a10d
VZ
551#ifdef PNG_FLOATING_POINT_SUPPORTED
552 white_x = (float).3127;
553 white_y = (float).3290;
554 red_x = (float).64;
555 red_y = (float).33;
556 green_x = (float).30;
557 green_y = (float).60;
558 blue_x = (float).15;
559 blue_y = (float).06;
970f6abe 560#endif
0272a10d 561
970f6abe 562#ifdef PNG_FIXED_POINT_SUPPORTED
b61cc19c
PC
563 png_set_cHRM_fixed(png_ptr, info_ptr,
564 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
565 int_green_y, int_blue_x, int_blue_y);
0272a10d 566#endif
970f6abe 567#ifdef PNG_FLOATING_POINT_SUPPORTED
b61cc19c
PC
568 png_set_cHRM(png_ptr, info_ptr,
569 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
0272a10d 570#endif
970f6abe 571#endif /* cHRM */
0272a10d 572}
b61cc19c 573#endif /* sRGB */
0272a10d
VZ
574
575
b61cc19c 576#ifdef PNG_iCCP_SUPPORTED
0272a10d
VZ
577void PNGAPI
578png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
579 png_charp name, int compression_type,
580 png_charp profile, png_uint_32 proflen)
581{
582 png_charp new_iccp_name;
583 png_charp new_iccp_profile;
970f6abe 584 png_uint_32 length;
0272a10d 585
970f6abe 586 png_debug1(1, "in %s storage function", "iCCP");
b61cc19c 587
0272a10d
VZ
588 if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
589 return;
590
970f6abe
VZ
591 length = png_strlen(name)+1;
592 new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
0272a10d
VZ
593 if (new_iccp_name == NULL)
594 {
b61cc19c 595 png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
0272a10d
VZ
596 return;
597 }
970f6abe 598 png_memcpy(new_iccp_name, name, length);
0272a10d
VZ
599 new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
600 if (new_iccp_profile == NULL)
601 {
602 png_free (png_ptr, new_iccp_name);
970f6abe 603 png_warning(png_ptr,
b61cc19c 604 "Insufficient memory to process iCCP profile");
0272a10d
VZ
605 return;
606 }
607 png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
608
609 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
610
611 info_ptr->iccp_proflen = proflen;
612 info_ptr->iccp_name = new_iccp_name;
613 info_ptr->iccp_profile = new_iccp_profile;
614 /* Compression is always zero but is here so the API and info structure
b61cc19c
PC
615 * does not have to change if we introduce multiple compression types
616 */
0272a10d 617 info_ptr->iccp_compression = (png_byte)compression_type;
0272a10d 618 info_ptr->free_me |= PNG_FREE_ICCP;
0272a10d
VZ
619 info_ptr->valid |= PNG_INFO_iCCP;
620}
621#endif
622
b61cc19c 623#ifdef PNG_TEXT_SUPPORTED
0272a10d
VZ
624void PNGAPI
625png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
b61cc19c 626 int num_text)
0272a10d
VZ
627{
628 int ret;
970f6abe 629 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
0272a10d 630 if (ret)
b61cc19c 631 png_error(png_ptr, "Insufficient memory to store text");
0272a10d
VZ
632}
633
634int /* PRIVATE */
635png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
b61cc19c 636 int num_text)
0272a10d
VZ
637{
638 int i;
639
b61cc19c
PC
640 png_debug1(1, "in %s storage function", ((png_ptr == NULL ||
641 png_ptr->chunk_name[0] == '\0') ?
0272a10d
VZ
642 "text" : (png_const_charp)png_ptr->chunk_name));
643
644 if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
645 return(0);
646
647 /* Make sure we have enough space in the "text" array in info_struct
648 * to hold all of the incoming text_ptr objects.
649 */
650 if (info_ptr->num_text + num_text > info_ptr->max_text)
651 {
652 if (info_ptr->text != NULL)
653 {
654 png_textp old_text;
655 int old_max;
656
657 old_max = info_ptr->max_text;
658 info_ptr->max_text = info_ptr->num_text + num_text + 8;
659 old_text = info_ptr->text;
660 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
b61cc19c 661 (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
0272a10d 662 if (info_ptr->text == NULL)
b61cc19c
PC
663 {
664 png_free(png_ptr, old_text);
665 return(1);
666 }
0272a10d
VZ
667 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
668 png_sizeof(png_text)));
669 png_free(png_ptr, old_text);
670 }
671 else
672 {
673 info_ptr->max_text = num_text + 8;
674 info_ptr->num_text = 0;
675 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
b61cc19c 676 (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
0272a10d 677 if (info_ptr->text == NULL)
b61cc19c 678 return(1);
0272a10d 679 info_ptr->free_me |= PNG_FREE_TEXT;
0272a10d 680 }
970f6abe 681 png_debug1(3, "allocated %d entries for info_ptr->text",
0272a10d
VZ
682 info_ptr->max_text);
683 }
684 for (i = 0; i < num_text; i++)
685 {
970f6abe
VZ
686 png_size_t text_length, key_len;
687 png_size_t lang_len, lang_key_len;
0272a10d
VZ
688 png_textp textp = &(info_ptr->text[info_ptr->num_text]);
689
690 if (text_ptr[i].key == NULL)
691 continue;
692
693 key_len = png_strlen(text_ptr[i].key);
694
970f6abe 695 if (text_ptr[i].compression <= 0)
0272a10d 696 {
b61cc19c
PC
697 lang_len = 0;
698 lang_key_len = 0;
0272a10d 699 }
b61cc19c 700
0272a10d
VZ
701 else
702#ifdef PNG_iTXt_SUPPORTED
703 {
b61cc19c
PC
704 /* Set iTXt data */
705
706 if (text_ptr[i].lang != NULL)
707 lang_len = png_strlen(text_ptr[i].lang);
708 else
709 lang_len = 0;
710 if (text_ptr[i].lang_key != NULL)
711 lang_key_len = png_strlen(text_ptr[i].lang_key);
712 else
713 lang_key_len = 0;
0272a10d 714 }
b61cc19c 715#else /* PNG_iTXt_SUPPORTED */
0272a10d 716 {
b61cc19c
PC
717 png_warning(png_ptr, "iTXt chunk not supported");
718 continue;
0272a10d
VZ
719 }
720#endif
721
722 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
723 {
724 text_length = 0;
725#ifdef PNG_iTXt_SUPPORTED
970f6abe 726 if (text_ptr[i].compression > 0)
0272a10d
VZ
727 textp->compression = PNG_ITXT_COMPRESSION_NONE;
728 else
729#endif
730 textp->compression = PNG_TEXT_COMPRESSION_NONE;
731 }
b61cc19c 732
0272a10d
VZ
733 else
734 {
735 text_length = png_strlen(text_ptr[i].text);
736 textp->compression = text_ptr[i].compression;
737 }
738
739 textp->key = (png_charp)png_malloc_warn(png_ptr,
b61cc19c 740 (png_size_t)
970f6abe 741 (key_len + text_length + lang_len + lang_key_len + 4));
0272a10d 742 if (textp->key == NULL)
b61cc19c 743 return(1);
970f6abe 744 png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
b61cc19c
PC
745 (unsigned long)(png_uint_32)
746 (key_len + lang_len + lang_key_len + text_length + 4),
747 (int)textp->key);
0272a10d 748
b61cc19c 749 png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
970f6abe 750 *(textp->key + key_len) = '\0';
0272a10d
VZ
751#ifdef PNG_iTXt_SUPPORTED
752 if (text_ptr[i].compression > 0)
753 {
970f6abe 754 textp->lang = textp->key + key_len + 1;
0272a10d 755 png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
970f6abe
VZ
756 *(textp->lang + lang_len) = '\0';
757 textp->lang_key = textp->lang + lang_len + 1;
0272a10d 758 png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
970f6abe
VZ
759 *(textp->lang_key + lang_key_len) = '\0';
760 textp->text = textp->lang_key + lang_key_len + 1;
0272a10d
VZ
761 }
762 else
763#endif
764 {
765#ifdef PNG_iTXt_SUPPORTED
766 textp->lang=NULL;
767 textp->lang_key=NULL;
768#endif
970f6abe 769 textp->text = textp->key + key_len + 1;
0272a10d 770 }
970f6abe 771 if (text_length)
0272a10d
VZ
772 png_memcpy(textp->text, text_ptr[i].text,
773 (png_size_t)(text_length));
970f6abe 774 *(textp->text + text_length) = '\0';
0272a10d
VZ
775
776#ifdef PNG_iTXt_SUPPORTED
970f6abe 777 if (textp->compression > 0)
0272a10d
VZ
778 {
779 textp->text_length = 0;
780 textp->itxt_length = text_length;
781 }
782 else
783#endif
b61cc19c 784
0272a10d
VZ
785 {
786 textp->text_length = text_length;
787#ifdef PNG_iTXt_SUPPORTED
788 textp->itxt_length = 0;
789#endif
790 }
791 info_ptr->num_text++;
970f6abe 792 png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
0272a10d
VZ
793 }
794 return(0);
795}
796#endif
797
b61cc19c 798#ifdef PNG_tIME_SUPPORTED
0272a10d
VZ
799void PNGAPI
800png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
801{
970f6abe 802 png_debug1(1, "in %s storage function", "tIME");
b61cc19c 803
0272a10d
VZ
804 if (png_ptr == NULL || info_ptr == NULL ||
805 (png_ptr->mode & PNG_WROTE_tIME))
806 return;
807
970f6abe 808 png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
0272a10d
VZ
809 info_ptr->valid |= PNG_INFO_tIME;
810}
811#endif
812
b61cc19c 813#ifdef PNG_tRNS_SUPPORTED
0272a10d
VZ
814void PNGAPI
815png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
b61cc19c 816 png_bytep trans_alpha, int num_trans, png_color_16p trans_color)
0272a10d 817{
970f6abe 818 png_debug1(1, "in %s storage function", "tRNS");
b61cc19c 819
0272a10d
VZ
820 if (png_ptr == NULL || info_ptr == NULL)
821 return;
822
b61cc19c 823 if (trans_alpha != NULL)
0272a10d 824 {
b61cc19c 825 /* It may not actually be necessary to set png_ptr->trans_alpha here;
0272a10d
VZ
826 * we do it for backward compatibility with the way the png_handle_tRNS
827 * function used to do the allocation.
828 */
970f6abe 829
0272a10d 830 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
970f6abe 831
0272a10d 832 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
b61cc19c
PC
833 png_ptr->trans_alpha = info_ptr->trans_alpha = (png_bytep)png_malloc(png_ptr,
834 (png_size_t)PNG_MAX_PALETTE_LENGTH);
970f6abe 835 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
b61cc19c 836 png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
0272a10d
VZ
837 }
838
b61cc19c 839 if (trans_color != NULL)
0272a10d 840 {
970f6abe
VZ
841 int sample_max = (1 << info_ptr->bit_depth);
842 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
b61cc19c 843 (int)trans_color->gray > sample_max) ||
970f6abe 844 (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
b61cc19c
PC
845 ((int)trans_color->red > sample_max ||
846 (int)trans_color->green > sample_max ||
847 (int)trans_color->blue > sample_max)))
848 png_warning(png_ptr,
849 "tRNS chunk has out-of-range samples for bit_depth");
850 png_memcpy(&(info_ptr->trans_color), trans_color,
0272a10d
VZ
851 png_sizeof(png_color_16));
852 if (num_trans == 0)
b61cc19c 853 num_trans = 1;
0272a10d 854 }
970f6abe 855
0272a10d 856 info_ptr->num_trans = (png_uint_16)num_trans;
970f6abe
VZ
857 if (num_trans != 0)
858 {
859 info_ptr->valid |= PNG_INFO_tRNS;
970f6abe 860 info_ptr->free_me |= PNG_FREE_TRNS;
970f6abe 861 }
0272a10d
VZ
862}
863#endif
864
b61cc19c 865#ifdef PNG_sPLT_SUPPORTED
0272a10d
VZ
866void PNGAPI
867png_set_sPLT(png_structp png_ptr,
868 png_infop info_ptr, png_sPLT_tp entries, int nentries)
970f6abe
VZ
869/*
870 * entries - array of png_sPLT_t structures
871 * to be added to the list of palettes
872 * in the info structure.
873 * nentries - number of palette structures to be
874 * added.
875 */
0272a10d 876{
b61cc19c
PC
877 png_sPLT_tp np;
878 int i;
0272a10d 879
b61cc19c
PC
880 if (png_ptr == NULL || info_ptr == NULL)
881 return;
0272a10d 882
b61cc19c
PC
883 np = (png_sPLT_tp)png_malloc_warn(png_ptr,
884 (info_ptr->splt_palettes_num + nentries) *
885 (png_size_t)png_sizeof(png_sPLT_t));
886 if (np == NULL)
887 {
888 png_warning(png_ptr, "No memory for sPLT palettes");
0272a10d 889 return;
b61cc19c
PC
890 }
891
892 png_memcpy(np, info_ptr->splt_palettes,
893 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
894 png_free(png_ptr, info_ptr->splt_palettes);
895 info_ptr->splt_palettes=NULL;
896
897 for (i = 0; i < nentries; i++)
898 {
899 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
900 png_sPLT_tp from = entries + i;
901 png_uint_32 length;
902
903 length = png_strlen(from->name) + 1;
904 to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length);
905 if (to->name == NULL)
906 {
907 png_warning(png_ptr,
908 "Out of memory while processing sPLT chunk");
909 continue;
910 }
911 png_memcpy(to->name, from->name, length);
912 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
913 (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry)));
914 if (to->entries == NULL)
915 {
916 png_warning(png_ptr,
917 "Out of memory while processing sPLT chunk");
918 png_free(png_ptr, to->name);
919 to->name = NULL;
920 continue;
921 }
922 png_memcpy(to->entries, from->entries,
923 from->nentries * png_sizeof(png_sPLT_entry));
924 to->nentries = from->nentries;
925 to->depth = from->depth;
926 }
927
928 info_ptr->splt_palettes = np;
929 info_ptr->splt_palettes_num += nentries;
930 info_ptr->valid |= PNG_INFO_sPLT;
931 info_ptr->free_me |= PNG_FREE_SPLT;
0272a10d
VZ
932}
933#endif /* PNG_sPLT_SUPPORTED */
934
b61cc19c 935#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
0272a10d
VZ
936void PNGAPI
937png_set_unknown_chunks(png_structp png_ptr,
938 png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
939{
b61cc19c
PC
940 png_unknown_chunkp np;
941 int i;
942
943 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
944 return;
945
946 np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
947 (png_size_t)((info_ptr->unknown_chunks_num + num_unknowns) *
948 png_sizeof(png_unknown_chunk)));
949 if (np == NULL)
950 {
951 png_warning(png_ptr,
952 "Out of memory while processing unknown chunk");
953 return;
954 }
955
956 png_memcpy(np, info_ptr->unknown_chunks,
957 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
958 png_free(png_ptr, info_ptr->unknown_chunks);
959 info_ptr->unknown_chunks = NULL;
960
961 for (i = 0; i < num_unknowns; i++)
962 {
963 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
964 png_unknown_chunkp from = unknowns + i;
965
966 png_memcpy((png_charp)to->name, (png_charp)from->name,
967 png_sizeof(from->name));
968 to->name[png_sizeof(to->name)-1] = '\0';
969 to->size = from->size;
970 /* Note our location in the read or write sequence */
971 to->location = (png_byte)(png_ptr->mode & 0xff);
972
973 if (from->size == 0)
974 to->data=NULL;
975 else
976 {
977 to->data = (png_bytep)png_malloc_warn(png_ptr,
978 (png_size_t)from->size);
979 if (to->data == NULL)
980 {
981 png_warning(png_ptr,
982 "Out of memory while processing unknown chunk");
983 to->size = 0;
984 }
985 else
986 png_memcpy(to->data, from->data, from->size);
987 }
988 }
989
990 info_ptr->unknown_chunks = np;
991 info_ptr->unknown_chunks_num += num_unknowns;
992 info_ptr->free_me |= PNG_FREE_UNKN;
0272a10d
VZ
993}
994void PNGAPI
995png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
996 int chunk, int location)
997{
970f6abe 998 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
b61cc19c 999 (int)info_ptr->unknown_chunks_num)
0272a10d
VZ
1000 info_ptr->unknown_chunks[chunk].location = (png_byte)location;
1001}
1002#endif
1003
0272a10d 1004
b61cc19c 1005#ifdef PNG_MNG_FEATURES_SUPPORTED
0272a10d
VZ
1006png_uint_32 PNGAPI
1007png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
1008{
970f6abe 1009 png_debug(1, "in png_permit_mng_features");
b61cc19c 1010
0272a10d
VZ
1011 if (png_ptr == NULL)
1012 return (png_uint_32)0;
1013 png_ptr->mng_features_permitted =
1014 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
1015 return (png_uint_32)png_ptr->mng_features_permitted;
1016}
1017#endif
1018
b61cc19c 1019#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
0272a10d
VZ
1020void PNGAPI
1021png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
1022 chunk_list, int num_chunks)
1023{
b61cc19c
PC
1024 png_bytep new_list, p;
1025 int i, old_num_chunks;
1026 if (png_ptr == NULL)
1027 return;
1028 if (num_chunks == 0)
1029 {
970f6abe 1030 if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
b61cc19c 1031 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
0272a10d 1032 else
b61cc19c 1033 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
0272a10d 1034
970f6abe 1035 if (keep == PNG_HANDLE_CHUNK_ALWAYS)
b61cc19c 1036 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
0272a10d 1037 else
b61cc19c 1038 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
0272a10d 1039 return;
b61cc19c
PC
1040 }
1041 if (chunk_list == NULL)
0272a10d 1042 return;
b61cc19c
PC
1043 old_num_chunks = png_ptr->num_chunk_list;
1044 new_list=(png_bytep)png_malloc(png_ptr,
1045 (png_size_t)
970f6abe 1046 (5*(num_chunks + old_num_chunks)));
b61cc19c
PC
1047 if (png_ptr->chunk_list != NULL)
1048 {
1049 png_memcpy(new_list, png_ptr->chunk_list,
0272a10d 1050 (png_size_t)(5*old_num_chunks));
b61cc19c
PC
1051 png_free(png_ptr, png_ptr->chunk_list);
1052 png_ptr->chunk_list=NULL;
1053 }
1054 png_memcpy(new_list + 5*old_num_chunks, chunk_list,
0272a10d 1055 (png_size_t)(5*num_chunks));
b61cc19c
PC
1056 for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
1057 *p=(png_byte)keep;
1058 png_ptr->num_chunk_list = old_num_chunks + num_chunks;
1059 png_ptr->chunk_list = new_list;
1060 png_ptr->free_me |= PNG_FREE_LIST;
0272a10d
VZ
1061}
1062#endif
1063
b61cc19c 1064#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
0272a10d
VZ
1065void PNGAPI
1066png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
1067 png_user_chunk_ptr read_user_chunk_fn)
1068{
970f6abe 1069 png_debug(1, "in png_set_read_user_chunk_fn");
b61cc19c 1070
0272a10d
VZ
1071 if (png_ptr == NULL)
1072 return;
b61cc19c 1073
0272a10d
VZ
1074 png_ptr->read_user_chunk_fn = read_user_chunk_fn;
1075 png_ptr->user_chunk_ptr = user_chunk_ptr;
1076}
1077#endif
1078
b61cc19c 1079#ifdef PNG_INFO_IMAGE_SUPPORTED
0272a10d
VZ
1080void PNGAPI
1081png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
1082{
970f6abe 1083 png_debug1(1, "in %s storage function", "rows");
0272a10d
VZ
1084
1085 if (png_ptr == NULL || info_ptr == NULL)
1086 return;
1087
970f6abe 1088 if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
0272a10d
VZ
1089 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
1090 info_ptr->row_pointers = row_pointers;
970f6abe 1091 if (row_pointers)
0272a10d
VZ
1092 info_ptr->valid |= PNG_INFO_IDAT;
1093}
1094#endif
1095
0272a10d 1096void PNGAPI
970f6abe 1097png_set_compression_buffer_size(png_structp png_ptr,
b61cc19c 1098 png_size_t size)
0272a10d
VZ
1099{
1100 if (png_ptr == NULL)
1101 return;
970f6abe 1102 png_free(png_ptr, png_ptr->zbuf);
b61cc19c 1103 png_ptr->zbuf_size = size;
0272a10d
VZ
1104 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
1105 png_ptr->zstream.next_out = png_ptr->zbuf;
1106 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1107}
0272a10d
VZ
1108
1109void PNGAPI
1110png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
1111{
1112 if (png_ptr && info_ptr)
970f6abe 1113 info_ptr->valid &= ~mask;
0272a10d
VZ
1114}
1115
1116
b61cc19c
PC
1117
1118#ifdef PNG_SET_USER_LIMITS_SUPPORTED
1119/* This function was added to libpng 1.2.6 */
0272a10d 1120void PNGAPI
b61cc19c
PC
1121png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
1122 png_uint_32 user_height_max)
0272a10d 1123{
b61cc19c
PC
1124 /* Images with dimensions larger than these limits will be
1125 * rejected by png_set_IHDR(). To accept any PNG datastream
1126 * regardless of dimensions, set both limits to 0x7ffffffL.
1127 */
1128 if (png_ptr == NULL)
1129 return;
1130 png_ptr->user_width_max = user_width_max;
1131 png_ptr->user_height_max = user_height_max;
0272a10d
VZ
1132}
1133
b61cc19c 1134/* This function was added to libpng 1.4.0 */
0272a10d 1135void PNGAPI
b61cc19c
PC
1136png_set_chunk_cache_max (png_structp png_ptr,
1137 png_uint_32 user_chunk_cache_max)
0272a10d 1138{
b61cc19c
PC
1139 if (png_ptr)
1140 png_ptr->user_chunk_cache_max = user_chunk_cache_max;
0272a10d 1141}
0272a10d 1142
b61cc19c 1143/* This function was added to libpng 1.4.1 */
0272a10d 1144void PNGAPI
b61cc19c
PC
1145png_set_chunk_malloc_max (png_structp png_ptr,
1146 png_alloc_size_t user_chunk_malloc_max)
0272a10d 1147{
b61cc19c
PC
1148 if (png_ptr)
1149 png_ptr->user_chunk_malloc_max =
1150 (png_size_t)user_chunk_malloc_max;
0272a10d
VZ
1151}
1152#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1153
b61cc19c
PC
1154
1155#ifdef PNG_BENIGN_ERRORS_SUPPORTED
1156void PNGAPI
1157png_set_benign_errors(png_structp png_ptr, int allowed)
1158{
1159 png_debug(1, "in png_set_benign_errors");
1160
1161 if (allowed)
1162 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
1163 else
1164 png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
1165}
1166#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
0272a10d 1167#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */