blob: 01384408afea15f60f636ca8b1a4e5182e2771f0 [file] [log] [blame]
Andreas Dilger47a0c421997-05-16 02:46:07 -05001
2/* pngset.c - storage of image information into info struct
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06003 *
Glenn Randers-Pehrsond6d80752008-12-02 09:49:43 -06004 * Last changed in libpng 1.4.0 [December 2, 2008]
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06005 * For conditions of distribution and use, see copyright notice in png.h
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05006 * Copyright (c) 1998-2008 Glenn Randers-Pehrson
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -05007 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06009 *
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 Dilger47a0c421997-05-16 02:46:07 -050015
Andreas Dilger47a0c421997-05-16 02:46:07 -050016#include "png.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060017#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050018#include "pngpriv.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060019
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060020#if defined(PNG_bKGD_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050021void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -050022png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
23{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -050024 png_debug1(1, "in %s storage function", "bKGD");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060025 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050026 return;
27
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050028 png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
Andreas Dilger47a0c421997-05-16 02:46:07 -050029 info_ptr->valid |= PNG_INFO_bKGD;
30}
31#endif
32
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060033#if defined(PNG_cHRM_SUPPORTED)
34#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050035void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -050036png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
37 double white_x, double white_y, double red_x, double red_y,
38 double green_x, double green_y, double blue_x, double blue_y)
39{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -050040 png_debug1(1, "in %s storage function", "cHRM");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060041 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050042 return;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060043
Andreas Dilger47a0c421997-05-16 02:46:07 -050044 info_ptr->x_white = (float)white_x;
45 info_ptr->y_white = (float)white_y;
46 info_ptr->x_red = (float)red_x;
47 info_ptr->y_red = (float)red_y;
48 info_ptr->x_green = (float)green_x;
49 info_ptr->y_green = (float)green_y;
50 info_ptr->x_blue = (float)blue_x;
51 info_ptr->y_blue = (float)blue_y;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060052#ifdef PNG_FIXED_POINT_SUPPORTED
53 info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
54 info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060055 info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
56 info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060057 info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
58 info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060059 info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
60 info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060061#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -050062 info_ptr->valid |= PNG_INFO_cHRM;
63}
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -060064#endif /* PNG_FLOATING_POINT_SUPPORTED */
65
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060066#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050067void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060068png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060069 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
70 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
71 png_fixed_point blue_x, png_fixed_point blue_y)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060072{
Glenn Randers-Pehrsond6d80752008-12-02 09:49:43 -060073 png_debug1(1, "in %s storage function", "cHRM fixed");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060074 if (png_ptr == NULL || info_ptr == NULL)
75 return;
Andreas Dilger47a0c421997-05-16 02:46:07 -050076
Glenn Randers-Pehrson71a3c1f2008-11-26 12:00:38 -060077#if !defined(PNG_NO_CHECK_cHRM)
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -060078 if (png_check_cHRM_fixed(png_ptr,
79 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
Glenn Randers-Pehrson71a3c1f2008-11-26 12:00:38 -060080#endif
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050081 {
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -060082 info_ptr->int_x_white = white_x;
83 info_ptr->int_y_white = white_y;
84 info_ptr->int_x_red = red_x;
85 info_ptr->int_y_red = red_y;
86 info_ptr->int_x_green = green_x;
87 info_ptr->int_y_green = green_y;
88 info_ptr->int_x_blue = blue_x;
89 info_ptr->int_y_blue = blue_y;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060090#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -060091 info_ptr->x_white = (float)(white_x/100000.);
92 info_ptr->y_white = (float)(white_y/100000.);
93 info_ptr->x_red = (float)( red_x/100000.);
94 info_ptr->y_red = (float)( red_y/100000.);
95 info_ptr->x_green = (float)(green_x/100000.);
96 info_ptr->y_green = (float)(green_y/100000.);
97 info_ptr->x_blue = (float)( blue_x/100000.);
98 info_ptr->y_blue = (float)( blue_y/100000.);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060099#endif
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -0600100 info_ptr->valid |= PNG_INFO_cHRM;
101 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600102}
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -0600103#endif /* PNG_FIXED_POINT_SUPPORTED */
104#endif /* PNG_cHRM_SUPPORTED */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600105
106#if defined(PNG_gAMA_SUPPORTED)
107#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500108void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500109png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
110{
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600111 double gamma;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500112 png_debug1(1, "in %s storage function", "gAMA");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600113 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500114 return;
115
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600116 /* Check for overflow */
117 if (file_gamma > 21474.83)
118 {
119 png_warning(png_ptr, "Limiting gamma to 21474.83");
120 gamma=21474.83;
121 }
122 else
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500123 gamma = file_gamma;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600124 info_ptr->gamma = (float)gamma;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600125#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600126 info_ptr->int_gamma = (int)(gamma*100000.+.5);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600127#endif
128 info_ptr->valid |= PNG_INFO_gAMA;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500129 if (gamma == 0.0)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500130 png_warning(png_ptr, "Setting gamma=0");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600131}
132#endif
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500133void PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600134png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
135 int_gamma)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600136{
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600137 png_fixed_point gamma;
138
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500139 png_debug1(1, "in %s storage function", "gAMA");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600140 if (png_ptr == NULL || info_ptr == NULL)
141 return;
142
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500143 if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600144 {
145 png_warning(png_ptr, "Limiting gamma to 21474.83");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500146 gamma=PNG_UINT_31_MAX;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600147 }
148 else
149 {
150 if (int_gamma < 0)
151 {
152 png_warning(png_ptr, "Setting negative gamma to zero");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500153 gamma = 0;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600154 }
155 else
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500156 gamma = int_gamma;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600157 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600158#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600159 info_ptr->gamma = (float)(gamma/100000.);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600160#endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500161#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600162 info_ptr->int_gamma = gamma;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500163#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500164 info_ptr->valid |= PNG_INFO_gAMA;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500165 if (gamma == 0)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500166 png_warning(png_ptr, "Setting gamma=0");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500167}
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500168#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500169
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600170#if defined(PNG_hIST_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500171void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500172png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
173{
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500174 int i;
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600175
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500176 png_debug1(1, "in %s storage function", "hIST");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600177 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500178 return;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500179 if (info_ptr->num_palette == 0 || info_ptr->num_palette
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600180 > PNG_MAX_PALETTE_LENGTH)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500181 {
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600182 png_warning(png_ptr,
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500183 "Invalid palette size, hIST allocation skipped");
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500184 return;
185 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500186
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600187#ifdef PNG_FREE_ME_SUPPORTED
188 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
189#endif
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600190 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in version
191 1.2.1 */
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500192 png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500193 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500194 if (png_ptr->hist == NULL)
195 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500196 png_warning(png_ptr, "Insufficient memory for hIST chunk data");
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500197 return;
198 }
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600199
200 for (i = 0; i < info_ptr->num_palette; i++)
201 png_ptr->hist[i] = hist[i];
202 info_ptr->hist = png_ptr->hist;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500203 info_ptr->valid |= PNG_INFO_hIST;
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600204
205#ifdef PNG_FREE_ME_SUPPORTED
206 info_ptr->free_me |= PNG_FREE_HIST;
207#else
208 png_ptr->flags |= PNG_FLAG_FREE_HIST;
209#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500210}
211#endif
212
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500213void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500214png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
215 png_uint_32 width, png_uint_32 height, int bit_depth,
216 int color_type, int interlace_type, int compression_type,
217 int filter_type)
218{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500219 png_debug1(1, "in %s storage function", "IHDR");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600220 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500221 return;
222
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500223 /* check for width and height valid values */
224 if (width == 0 || height == 0)
225 png_error(png_ptr, "Image width or height is zero in IHDR");
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500226#ifdef PNG_SET_USER_LIMITS_SUPPORTED
227 if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
228 png_error(png_ptr, "image size exceeds user limits in IHDR");
229#else
230 if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
231 png_error(png_ptr, "image size exceeds user limits in IHDR");
232#endif
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500233 if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500234 png_error(png_ptr, "Invalid image size in IHDR");
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500235 if ( width > (PNG_UINT_32_MAX
236 >> 3) /* 8-byte RGBA pixels */
237 - 64 /* bigrowbuf hack */
238 - 1 /* filter byte */
239 - 7*8 /* rounding of width to multiple of 8 pixels */
240 - 8) /* extra max_pixel_depth pad */
241 png_warning(png_ptr, "Width is too large for libpng to process pixels");
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500242
243 /* check other values */
244 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
245 bit_depth != 8 && bit_depth != 16)
246 png_error(png_ptr, "Invalid bit depth in IHDR");
247
248 if (color_type < 0 || color_type == 1 ||
249 color_type == 5 || color_type > 6)
250 png_error(png_ptr, "Invalid color type in IHDR");
251
252 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
253 ((color_type == PNG_COLOR_TYPE_RGB ||
254 color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
255 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
256 png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
257
258 if (interlace_type >= PNG_INTERLACE_LAST)
259 png_error(png_ptr, "Unknown interlace method in IHDR");
260
261 if (compression_type != PNG_COMPRESSION_TYPE_BASE)
262 png_error(png_ptr, "Unknown compression method in IHDR");
263
264#if defined(PNG_MNG_FEATURES_SUPPORTED)
265 /* Accept filter_method 64 (intrapixel differencing) only if
266 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
267 * 2. Libpng did not read a PNG signature (this filter_method is only
268 * used in PNG datastreams that are embedded in MNG datastreams) and
269 * 3. The application called png_permit_mng_features with a mask that
270 * included PNG_FLAG_MNG_FILTER_64 and
271 * 4. The filter_method is 64 and
272 * 5. The color_type is RGB or RGBA
273 */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500274 if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
275 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
276 if (filter_type != PNG_FILTER_TYPE_BASE)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500277 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500278 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500279 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
280 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600281 (color_type == PNG_COLOR_TYPE_RGB ||
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500282 color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
283 png_error(png_ptr, "Unknown filter method in IHDR");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500284 if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500285 png_warning(png_ptr, "Invalid filter method in IHDR");
286 }
287#else
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500288 if (filter_type != PNG_FILTER_TYPE_BASE)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500289 png_error(png_ptr, "Unknown filter method in IHDR");
290#endif
291
Andreas Dilger47a0c421997-05-16 02:46:07 -0500292 info_ptr->width = width;
293 info_ptr->height = height;
294 info_ptr->bit_depth = (png_byte)bit_depth;
295 info_ptr->color_type =(png_byte) color_type;
296 info_ptr->compression_type = (png_byte)compression_type;
297 info_ptr->filter_type = (png_byte)filter_type;
298 info_ptr->interlace_type = (png_byte)interlace_type;
Glenn Randers-Pehrson25d82242002-05-01 11:51:26 -0500299 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
300 info_ptr->channels = 1;
301 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500302 info_ptr->channels = 3;
303 else
304 info_ptr->channels = 1;
305 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
306 info_ptr->channels++;
307 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600308
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500309 /* check for potential overflow */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500310 if (width > (PNG_UINT_32_MAX
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500311 >> 3) /* 8-byte RGBA pixels */
312 - 64 /* bigrowbuf hack */
313 - 1 /* filter byte */
314 - 7*8 /* rounding of width to multiple of 8 pixels */
315 - 8) /* extra max_pixel_depth pad */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500316 info_ptr->rowbytes = 0;
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500317 else
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500318 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500319}
320
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600321#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500322void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500323png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600324 png_int_32 offset_x, png_int_32 offset_y, int unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500325{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500326 png_debug1(1, "in %s storage function", "oFFs");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600327 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500328 return;
329
330 info_ptr->x_offset = offset_x;
331 info_ptr->y_offset = offset_y;
332 info_ptr->offset_unit_type = (png_byte)unit_type;
333 info_ptr->valid |= PNG_INFO_oFFs;
334}
335#endif
336
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600337#if defined(PNG_pCAL_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500338void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500339png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
340 png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
341 png_charp units, png_charpp params)
342{
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500343 png_size_t length;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600344 int i;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500345
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500346 png_debug1(1, "in %s storage function", "pCAL");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600347 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500348 return;
349
350 length = png_strlen(purpose) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500351 png_debug1(3, "allocating purpose for info (%lu bytes)",
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500352 (unsigned long)length);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500353 info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
354 if (info_ptr->pcal_purpose == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500355 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500356 png_warning(png_ptr, "Insufficient memory for pCAL purpose");
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500357 return;
358 }
359 png_memcpy(info_ptr->pcal_purpose, purpose, length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500360
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500361 png_debug(3, "storing X0, X1, type, and nparams in info");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500362 info_ptr->pcal_X0 = X0;
363 info_ptr->pcal_X1 = X1;
364 info_ptr->pcal_type = (png_byte)type;
365 info_ptr->pcal_nparams = (png_byte)nparams;
366
367 length = png_strlen(units) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500368 png_debug1(3, "allocating units for info (%lu bytes)",
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500369 (unsigned long)length);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500370 info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
371 if (info_ptr->pcal_units == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500372 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500373 png_warning(png_ptr, "Insufficient memory for pCAL units");
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500374 return;
375 }
376 png_memcpy(info_ptr->pcal_units, units, length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500377
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500378 info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500379 (png_size_t)((nparams + 1) * png_sizeof(png_charp)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500380 if (info_ptr->pcal_params == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500381 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500382 png_warning(png_ptr, "Insufficient memory for pCAL params");
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500383 return;
384 }
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500385
Andreas Dilger47a0c421997-05-16 02:46:07 -0500386 info_ptr->pcal_params[nparams] = NULL;
387
388 for (i = 0; i < nparams; i++)
389 {
390 length = png_strlen(params[i]) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500391 png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500392 (unsigned long)length);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500393 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
394 if (info_ptr->pcal_params[i] == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500395 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500396 png_warning(png_ptr, "Insufficient memory for pCAL parameter");
397 return;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500398 }
399 png_memcpy(info_ptr->pcal_params[i], params[i], length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500400 }
401
402 info_ptr->valid |= PNG_INFO_pCAL;
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500403#ifdef PNG_FREE_ME_SUPPORTED
404 info_ptr->free_me |= PNG_FREE_PCAL;
405#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500406}
407#endif
408
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600409#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
410#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500411void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600412png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600413 int unit, double width, double height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600414{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500415 png_debug1(1, "in %s storage function", "sCAL");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600416 if (png_ptr == NULL || info_ptr == NULL)
417 return;
418
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600419 info_ptr->scal_unit = (png_byte)unit;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600420 info_ptr->scal_pixel_width = width;
421 info_ptr->scal_pixel_height = height;
422
423 info_ptr->valid |= PNG_INFO_sCAL;
424}
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600425#else
426#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500427void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600428png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600429 int unit, png_charp swidth, png_charp sheight)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600430{
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500431 png_size_t length;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600432
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500433 png_debug1(1, "in %s storage function", "sCAL");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600434 if (png_ptr == NULL || info_ptr == NULL)
435 return;
436
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600437 info_ptr->scal_unit = (png_byte)unit;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600438
439 length = png_strlen(swidth) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500440 png_debug1(3, "allocating unit for info (%u bytes)",
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500441 (unsigned int)length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500442 info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
443 if (info_ptr->scal_s_width == NULL)
444 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500445 png_warning(png_ptr,
446 "Memory allocation failed while processing sCAL");
447 return;
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500448 }
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500449 png_memcpy(info_ptr->scal_s_width, swidth, length);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600450
451 length = png_strlen(sheight) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500452 png_debug1(3, "allocating unit for info (%u bytes)",
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500453 (unsigned int)length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500454 info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
455 if (info_ptr->scal_s_height == NULL)
456 {
457 png_free (png_ptr, info_ptr->scal_s_width);
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500458 info_ptr->scal_s_width = NULL;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500459 png_warning(png_ptr,
460 "Memory allocation failed while processing sCAL");
461 return;
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500462 }
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500463 png_memcpy(info_ptr->scal_s_height, sheight, length);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600464 info_ptr->valid |= PNG_INFO_sCAL;
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500465#ifdef PNG_FREE_ME_SUPPORTED
466 info_ptr->free_me |= PNG_FREE_SCAL;
467#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600468}
469#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600470#endif
471#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600472
473#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500474void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500475png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
476 png_uint_32 res_x, png_uint_32 res_y, int unit_type)
477{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500478 png_debug1(1, "in %s storage function", "pHYs");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600479 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500480 return;
481
482 info_ptr->x_pixels_per_unit = res_x;
483 info_ptr->y_pixels_per_unit = res_y;
484 info_ptr->phys_unit_type = (png_byte)unit_type;
485 info_ptr->valid |= PNG_INFO_pHYs;
486}
487#endif
488
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500489void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500490png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
491 png_colorp palette, int num_palette)
492{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600493
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500494 png_debug1(1, "in %s storage function", "PLTE");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600495 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500496 return;
497
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600498 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
499 {
500 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
501 png_error(png_ptr, "Invalid palette length");
502 else
503 {
504 png_warning(png_ptr, "Invalid palette length");
505 return;
506 }
507 }
508
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600509 /*
510 * It may not actually be necessary to set png_ptr->palette here;
511 * we do it for backward compatibility with the way the png_handle_tRNS
512 * function used to do the allocation.
513 */
514#ifdef PNG_FREE_ME_SUPPORTED
515 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
516#endif
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500517
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600518 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
519 of num_palette entries,
Glenn Randers-Pehrsondb3b88d2001-12-04 06:30:43 -0600520 in case of an invalid PNG file that has too-large sample values. */
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500521 png_ptr->palette = (png_colorp)png_malloc(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500522 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600523 png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500524 png_sizeof(png_color));
525 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600526 info_ptr->palette = png_ptr->palette;
527 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600528
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600529#ifdef PNG_FREE_ME_SUPPORTED
530 info_ptr->free_me |= PNG_FREE_PLTE;
531#else
532 png_ptr->flags |= PNG_FLAG_FREE_PLTE;
533#endif
534
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600535 info_ptr->valid |= PNG_INFO_PLTE;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500536}
537
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600538#if defined(PNG_sBIT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500539void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500540png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
541 png_color_8p sig_bit)
542{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500543 png_debug1(1, "in %s storage function", "sBIT");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600544 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500545 return;
546
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500547 png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500548 info_ptr->valid |= PNG_INFO_sBIT;
549}
550#endif
551
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600552#if defined(PNG_sRGB_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500553void PNGAPI
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600554png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600555{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500556 png_debug1(1, "in %s storage function", "sRGB");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600557 if (png_ptr == NULL || info_ptr == NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600558 return;
559
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600560 info_ptr->srgb_intent = (png_byte)intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600561 info_ptr->valid |= PNG_INFO_sRGB;
562}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600563
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500564void PNGAPI
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600565png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600566 int intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600567{
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600568#if defined(PNG_gAMA_SUPPORTED)
569#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600570 float file_gamma;
571#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600572#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600573 png_fixed_point int_file_gamma;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600574#endif
575#endif
576#if defined(PNG_cHRM_SUPPORTED)
577#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600578 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
579#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600580 png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600581 int_green_y, int_blue_x, int_blue_y;
582#endif
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500583 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600584 if (png_ptr == NULL || info_ptr == NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600585 return;
586
587 png_set_sRGB(png_ptr, info_ptr, intent);
588
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600589#if defined(PNG_gAMA_SUPPORTED)
590#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonab1e5831999-10-06 04:57:42 -0500591 file_gamma = (float).45455;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600592 png_set_gAMA(png_ptr, info_ptr, file_gamma);
593#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600594#ifdef PNG_FIXED_POINT_SUPPORTED
595 int_file_gamma = 45455L;
596 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
597#endif
598#endif
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600599
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600600#if defined(PNG_cHRM_SUPPORTED)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600601 int_white_x = 31270L;
602 int_white_y = 32900L;
603 int_red_x = 64000L;
604 int_red_y = 33000L;
605 int_green_x = 30000L;
606 int_green_y = 60000L;
607 int_blue_x = 15000L;
608 int_blue_y = 6000L;
609
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600610#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600611 white_x = (float).3127;
612 white_y = (float).3290;
613 red_x = (float).64;
614 red_y = (float).33;
615 green_x = (float).30;
616 green_y = (float).60;
617 blue_x = (float).15;
618 blue_y = (float).06;
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600619#endif
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600620
Glenn Randers-Pehrson71a3c1f2008-11-26 12:00:38 -0600621#if !defined(PNG_NO_CHECK_cHRM)
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600622 if (png_check_cHRM_fixed(png_ptr,
623 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
624 int_green_y, int_blue_x, int_blue_y))
Glenn Randers-Pehrson71a3c1f2008-11-26 12:00:38 -0600625#endif
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600626 {
627#ifdef PNG_FIXED_POINT_SUPPORTED
628 png_set_cHRM_fixed(png_ptr, info_ptr,
629 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
630 int_green_y, int_blue_x, int_blue_y);
631#endif
632#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -0600633 png_set_cHRM(png_ptr, info_ptr,
634 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600635#endif
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600636 }
637#endif /* cHRM */
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600638}
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600639#endif /* sRGB */
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600640
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600641
642#if defined(PNG_iCCP_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500643void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600644png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
645 png_charp name, int compression_type,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600646 png_charp profile, png_uint_32 proflen)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600647{
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500648 png_charp new_iccp_name;
649 png_charp new_iccp_profile;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500650 png_uint_32 length;
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500651
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500652 png_debug1(1, "in %s storage function", "iCCP");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600653 if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
654 return;
655
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500656 length = png_strlen(name)+1;
657 new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500658 if (new_iccp_name == NULL)
659 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500660 png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500661 return;
662 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500663 png_memcpy(new_iccp_name, name, length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500664 new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
665 if (new_iccp_profile == NULL)
666 {
667 png_free (png_ptr, new_iccp_name);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500668 png_warning(png_ptr,
669 "Insufficient memory to process iCCP profile");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500670 return;
671 }
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500672 png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
673
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500674 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500675
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600676 info_ptr->iccp_proflen = proflen;
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500677 info_ptr->iccp_name = new_iccp_name;
678 info_ptr->iccp_profile = new_iccp_profile;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600679 /* Compression is always zero but is here so the API and info structure
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500680 * does not have to change if we introduce multiple compression types */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600681 info_ptr->iccp_compression = (png_byte)compression_type;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500682#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600683 info_ptr->free_me |= PNG_FREE_ICCP;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500684#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600685 info_ptr->valid |= PNG_INFO_iCCP;
686}
687#endif
688
689#if defined(PNG_TEXT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500690void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500691png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
692 int num_text)
693{
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500694 int ret;
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500695 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500696 if (ret)
697 png_error(png_ptr, "Insufficient memory to store text");
698}
699
700int /* PRIVATE */
701png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
702 int num_text)
703{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500704 int i;
705
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500706 png_debug1(1, "in %s storage function", (png_ptr->chunk_name[0] == '\0' ?
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600707 "text" : (png_const_charp)png_ptr->chunk_name));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500708
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600709 if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500710 return(0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500711
712 /* Make sure we have enough space in the "text" array in info_struct
713 * to hold all of the incoming text_ptr objects.
714 */
715 if (info_ptr->num_text + num_text > info_ptr->max_text)
716 {
717 if (info_ptr->text != NULL)
718 {
719 png_textp old_text;
720 int old_max;
721
722 old_max = info_ptr->max_text;
723 info_ptr->max_text = info_ptr->num_text + num_text + 8;
724 old_text = info_ptr->text;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500725 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500726 (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500727 if (info_ptr->text == NULL)
728 {
729 png_free(png_ptr, old_text);
730 return(1);
731 }
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600732 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500733 png_sizeof(png_text)));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500734 png_free(png_ptr, old_text);
735 }
736 else
737 {
738 info_ptr->max_text = num_text + 8;
739 info_ptr->num_text = 0;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500740 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500741 (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500742 if (info_ptr->text == NULL)
743 return(1);
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500744#ifdef PNG_FREE_ME_SUPPORTED
745 info_ptr->free_me |= PNG_FREE_TEXT;
746#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500747 }
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500748 png_debug1(3, "allocated %d entries for info_ptr->text",
Andreas Dilger47a0c421997-05-16 02:46:07 -0500749 info_ptr->max_text);
750 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500751 for (i = 0; i < num_text; i++)
752 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500753 png_size_t text_length, key_len;
754 png_size_t lang_len, lang_key_len;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500755 png_textp textp = &(info_ptr->text[info_ptr->num_text]);
756
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500757 if (text_ptr[i].key == NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600758 continue;
759
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600760 key_len = png_strlen(text_ptr[i].key);
761
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500762 if (text_ptr[i].compression <= 0)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500763 {
764 lang_len = 0;
765 lang_key_len = 0;
766 }
767 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500768#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600769 {
770 /* set iTXt data */
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -0600771 if (text_ptr[i].lang != NULL)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500772 lang_len = png_strlen(text_ptr[i].lang);
773 else
774 lang_len = 0;
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500775 if (text_ptr[i].lang_key != NULL)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500776 lang_key_len = png_strlen(text_ptr[i].lang_key);
777 else
778 lang_key_len = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600779 }
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500780#else
781 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500782 png_warning(png_ptr, "iTXt chunk not supported");
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500783 continue;
784 }
785#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500786
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500787 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
Andreas Dilger47a0c421997-05-16 02:46:07 -0500788 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600789 text_length = 0;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500790#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500791 if (text_ptr[i].compression > 0)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600792 textp->compression = PNG_ITXT_COMPRESSION_NONE;
793 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500794#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600795 textp->compression = PNG_TEXT_COMPRESSION_NONE;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500796 }
797 else
798 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600799 text_length = png_strlen(text_ptr[i].text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500800 textp->compression = text_ptr[i].compression;
801 }
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500802
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500803 textp->key = (png_charp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500804 (png_size_t)
805 (key_len + text_length + lang_len + lang_key_len + 4));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500806 if (textp->key == NULL)
807 return(1);
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500808 png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500809 (unsigned long)(png_uint_32)
810 (key_len + lang_len + lang_key_len + text_length + 4),
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500811 (int)textp->key);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500812
813 png_memcpy(textp->key, text_ptr[i].key,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600814 (png_size_t)(key_len));
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500815 *(textp->key + key_len) = '\0';
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500816#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600817 if (text_ptr[i].compression > 0)
818 {
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500819 textp->lang = textp->key + key_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600820 png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500821 *(textp->lang + lang_len) = '\0';
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500822 textp->lang_key = textp->lang + lang_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600823 png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500824 *(textp->lang_key + lang_key_len) = '\0';
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500825 textp->text = textp->lang_key + lang_key_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600826 }
827 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500828#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600829 {
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500830#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500831 textp->lang=NULL;
832 textp->lang_key=NULL;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500833#endif
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500834 textp->text = textp->key + key_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600835 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500836 if (text_length)
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500837 png_memcpy(textp->text, text_ptr[i].text,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600838 (png_size_t)(text_length));
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500839 *(textp->text + text_length) = '\0';
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600840
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500841#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500842 if (textp->compression > 0)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600843 {
844 textp->text_length = 0;
845 textp->itxt_length = text_length;
846 }
847 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500848#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600849 {
850 textp->text_length = text_length;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500851#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600852 textp->itxt_length = 0;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500853#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600854 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500855 info_ptr->num_text++;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500856 png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500857 }
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500858 return(0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500859}
860#endif
861
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600862#if defined(PNG_tIME_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500863void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500864png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
865{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500866 png_debug1(1, "in %s storage function", "tIME");
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500867 if (png_ptr == NULL || info_ptr == NULL ||
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600868 (png_ptr->mode & PNG_WROTE_tIME))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500869 return;
870
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500871 png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500872 info_ptr->valid |= PNG_INFO_tIME;
873}
874#endif
875
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600876#if defined(PNG_tRNS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500877void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500878png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500879 png_bytep trans, int num_trans, png_color_16p trans_color)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500880{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500881 png_debug1(1, "in %s storage function", "tRNS");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600882 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500883 return;
884
885 if (trans != NULL)
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600886 {
887 /*
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500888 * It may not actually be necessary to set png_ptr->trans here;
889 * we do it for backward compatibility with the way the png_handle_tRNS
890 * function used to do the allocation.
891 */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500892
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600893#ifdef PNG_FREE_ME_SUPPORTED
894 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
895#endif
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500896
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600897 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500898 png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500899 (png_size_t)PNG_MAX_PALETTE_LENGTH);
900 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600901 png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600902 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500903
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500904 if (trans_color != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500905 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500906 int sample_max = (1 << info_ptr->bit_depth);
907 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500908 (int)trans_color->gray > sample_max) ||
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500909 (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500910 ((int)trans_color->red > sample_max ||
911 (int)trans_color->green > sample_max ||
912 (int)trans_color->blue > sample_max)))
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500913 png_warning(png_ptr,
914 "tRNS chunk has out-of-range samples for bit_depth");
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500915 png_memcpy(&(info_ptr->trans_color), trans_color,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500916 png_sizeof(png_color_16));
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600917 if (num_trans == 0)
918 num_trans = 1;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500919 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500920
Andreas Dilger47a0c421997-05-16 02:46:07 -0500921 info_ptr->num_trans = (png_uint_16)num_trans;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500922 if (num_trans != 0)
923 {
924 info_ptr->valid |= PNG_INFO_tRNS;
925#ifdef PNG_FREE_ME_SUPPORTED
926 info_ptr->free_me |= PNG_FREE_TRNS;
927#else
928 png_ptr->flags |= PNG_FLAG_FREE_TRNS;
929#endif
930 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500931}
932#endif
933
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600934#if defined(PNG_sPLT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500935void PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600936png_set_sPLT(png_structp png_ptr,
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600937 png_infop info_ptr, png_sPLT_tp entries, int nentries)
Glenn Randers-Pehrson3779c692006-11-07 20:38:11 -0600938/*
939 * entries - array of png_sPLT_t structures
940 * to be added to the list of palettes
941 * in the info structure.
942 * nentries - number of palette structures to be
943 * added.
944 */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600945{
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600946 png_sPLT_tp np;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600947 int i;
948
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -0600949 if (png_ptr == NULL || info_ptr == NULL)
950 return;
951
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500952 np = (png_sPLT_tp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500953 (info_ptr->splt_palettes_num + nentries) *
954 (png_size_t)png_sizeof(png_sPLT_t));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500955 if (np == NULL)
956 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500957 png_warning(png_ptr, "No memory for sPLT palettes");
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500958 return;
959 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600960
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600961 png_memcpy(np, info_ptr->splt_palettes,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500962 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600963 png_free(png_ptr, info_ptr->splt_palettes);
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500964 info_ptr->splt_palettes=NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600965
966 for (i = 0; i < nentries; i++)
967 {
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600968 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
969 png_sPLT_tp from = entries + i;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500970 png_uint_32 length;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600971
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500972 length = png_strlen(from->name) + 1;
973 to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length);
974 if (to->name == NULL)
975 {
976 png_warning(png_ptr,
977 "Out of memory while processing sPLT chunk");
978 continue;
979 }
980 png_memcpy(to->name, from->name, length);
981 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
982 (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry)));
983 if (to->entries == NULL)
984 {
985 png_warning(png_ptr,
986 "Out of memory while processing sPLT chunk");
987 png_free(png_ptr, to->name);
988 to->name = NULL;
989 continue;
990 }
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -0500991 png_memcpy(to->entries, from->entries,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500992 from->nentries * png_sizeof(png_sPLT_entry));
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -0500993 to->nentries = from->nentries;
994 to->depth = from->depth;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600995 }
996
997 info_ptr->splt_palettes = np;
998 info_ptr->splt_palettes_num += nentries;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600999 info_ptr->valid |= PNG_INFO_sPLT;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001000#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001001 info_ptr->free_me |= PNG_FREE_SPLT;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001002#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001003}
1004#endif /* PNG_sPLT_SUPPORTED */
1005
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -05001006#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001007void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001008png_set_unknown_chunks(png_structp png_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001009 png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001010{
1011 png_unknown_chunkp np;
1012 int i;
1013
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001014 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
1015 return;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001016
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -05001017 np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001018 (png_size_t)((info_ptr->unknown_chunks_num + num_unknowns) *
1019 png_sizeof(png_unknown_chunk)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -05001020 if (np == NULL)
1021 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001022 png_warning(png_ptr,
1023 "Out of memory while processing unknown chunk");
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -05001024 return;
1025 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001026
1027 png_memcpy(np, info_ptr->unknown_chunks,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001028 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001029 png_free(png_ptr, info_ptr->unknown_chunks);
1030
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001031 for (i = 0; i < num_unknowns; i++)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001032 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001033 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
1034 png_unknown_chunkp from = unknowns + i;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001035
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001036 png_memcpy((png_charp)to->name,
1037 (png_charp)from->name,
1038 png_sizeof(from->name));
1039 to->name[png_sizeof(to->name)-1] = '\0';
1040 to->size = from->size;
1041 /* note our location in the read or write sequence */
1042 to->location = (png_byte)(png_ptr->mode & 0xff);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001043
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001044 if (from->size == 0)
1045 to->data=NULL;
1046 else
1047 {
1048 to->data = (png_bytep)png_malloc_warn(png_ptr,
1049 (png_size_t)from->size);
1050 if (to->data == NULL)
1051 {
1052 png_warning(png_ptr,
1053 "Out of memory while processing unknown chunk");
1054 to->size = 0;
1055 }
1056 else
1057 png_memcpy(to->data, from->data, from->size);
1058 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001059 }
1060
1061 info_ptr->unknown_chunks = np;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001062 info_ptr->unknown_chunks_num += num_unknowns;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001063#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001064 info_ptr->free_me |= PNG_FREE_UNKN;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001065#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001066}
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001067void PNGAPI
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001068png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
1069 int chunk, int location)
1070{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001071 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001072 (int)info_ptr->unknown_chunks_num)
1073 info_ptr->unknown_chunks[chunk].location = (png_byte)location;
1074}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001075#endif
1076
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001077
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06001078#if defined(PNG_MNG_FEATURES_SUPPORTED)
1079png_uint_32 PNGAPI
1080png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
1081{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001082 png_debug(1, "in png_permit_mng_features");
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06001083 if (png_ptr == NULL)
1084 return (png_uint_32)0;
1085 png_ptr->mng_features_permitted =
1086 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
1087 return (png_uint_32)png_ptr->mng_features_permitted;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001088}
1089#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001090
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001091#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001092void PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001093png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
1094 chunk_list, int num_chunks)
1095{
1096 png_bytep new_list, p;
1097 int i, old_num_chunks;
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -06001098 if (png_ptr == NULL)
1099 return;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001100 if (num_chunks == 0)
1101 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001102 if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001103 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
1104 else
1105 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001106
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001107 if (keep == PNG_HANDLE_CHUNK_ALWAYS)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001108 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1109 else
1110 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1111 return;
1112 }
1113 if (chunk_list == NULL)
1114 return;
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -05001115 old_num_chunks = png_ptr->num_chunk_list;
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05001116 new_list=(png_bytep)png_malloc(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001117 (png_size_t)
1118 (5*(num_chunks + old_num_chunks)));
1119 if (png_ptr->chunk_list != NULL)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001120 {
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05001121 png_memcpy(new_list, png_ptr->chunk_list,
1122 (png_size_t)(5*old_num_chunks));
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001123 png_free(png_ptr, png_ptr->chunk_list);
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -05001124 png_ptr->chunk_list=NULL;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001125 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001126 png_memcpy(new_list + 5*old_num_chunks, chunk_list,
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05001127 (png_size_t)(5*num_chunks));
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -05001128 for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001129 *p=(png_byte)keep;
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -05001130 png_ptr->num_chunk_list = old_num_chunks + num_chunks;
1131 png_ptr->chunk_list = new_list;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001132#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001133 png_ptr->free_me |= PNG_FREE_LIST;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001134#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001135}
1136#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001137
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001138#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001139void PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001140png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
1141 png_user_chunk_ptr read_user_chunk_fn)
1142{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001143 png_debug(1, "in png_set_read_user_chunk_fn");
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -06001144 if (png_ptr == NULL)
1145 return;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001146 png_ptr->read_user_chunk_fn = read_user_chunk_fn;
1147 png_ptr->user_chunk_ptr = user_chunk_ptr;
1148}
1149#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001150
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001151#if defined(PNG_INFO_IMAGE_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001152void PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001153png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
1154{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001155 png_debug1(1, "in %s storage function", "rows");
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001156
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001157 if (png_ptr == NULL || info_ptr == NULL)
1158 return;
1159
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001160 if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001161 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001162 info_ptr->row_pointers = row_pointers;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001163 if (row_pointers)
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001164 info_ptr->valid |= PNG_INFO_IDAT;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001165}
1166#endif
1167
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001168#ifdef PNG_WRITE_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001169void PNGAPI
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001170png_set_compression_buffer_size(png_structp png_ptr,
1171 png_size_t size)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001172{
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -06001173 if (png_ptr == NULL)
1174 return;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001175 png_free(png_ptr, png_ptr->zbuf);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001176 png_ptr->zbuf_size = size;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001177 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
1178 png_ptr->zstream.next_out = png_ptr->zbuf;
1179 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1180}
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001181#endif
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001182
1183void PNGAPI
1184png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
1185{
1186 if (png_ptr && info_ptr)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001187 info_ptr->valid &= ~mask;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001188}
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06001189
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05001190
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001191
1192#ifdef PNG_SET_USER_LIMITS_SUPPORTED
1193/* this function was added to libpng 1.2.6 */
1194void PNGAPI
1195png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
1196 png_uint_32 user_height_max)
1197{
1198 /* Images with dimensions larger than these limits will be
1199 * rejected by png_set_IHDR(). To accept any PNG datastream
1200 * regardless of dimensions, set both limits to 0x7ffffffL.
1201 */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001202 if (png_ptr == NULL) return;
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001203 png_ptr->user_width_max = user_width_max;
1204 png_ptr->user_height_max = user_height_max;
1205}
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001206/* this function was added to libpng 1.4.0 */
1207void PNGAPI
1208png_set_chunk_cache_max (png_structp png_ptr,
1209 png_uint_32 user_chunk_cache_max)
1210{
1211 if (png_ptr == NULL) return;
1212 png_ptr->user_chunk_cache_max = user_chunk_cache_max;
1213 if (user_chunk_cache_max == 0x7fffffffL) /* Unlimited */
1214 png_ptr->user_chunk_cache_max = 0;
1215 else
1216 png_ptr->user_chunk_cache_max = user_chunk_cache_max + 1;
1217}
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001218#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1219
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001220
1221#if defined(PNG_BENIGN_ERRORS_SUPPORTED)
1222void PNGAPI
1223png_set_benign_errors(png_structp png_ptr, int allowed)
1224{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001225 png_debug(1, "in png_set_benign_errors");
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001226 if (allowed)
1227 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
1228 else
1229 png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
1230}
1231#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001232#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */