blob: 2e059d1ea25638ac534e70ce30784057ebd22d7b [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-Pehrsonf7831012008-11-13 06:05:13 -06004 * Last changed in libpng 1.4.0 [November 13, 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-Pehrsonf7831012008-11-13 06:05:13 -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-Pehrsonf7831012008-11-13 06:05:13 -060077 if (png_check_cHRM_fixed(png_ptr,
78 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050079 {
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -060080 info_ptr->int_x_white = white_x;
81 info_ptr->int_y_white = white_y;
82 info_ptr->int_x_red = red_x;
83 info_ptr->int_y_red = red_y;
84 info_ptr->int_x_green = green_x;
85 info_ptr->int_y_green = green_y;
86 info_ptr->int_x_blue = blue_x;
87 info_ptr->int_y_blue = blue_y;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060088#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -060089 info_ptr->x_white = (float)(white_x/100000.);
90 info_ptr->y_white = (float)(white_y/100000.);
91 info_ptr->x_red = (float)( red_x/100000.);
92 info_ptr->y_red = (float)( red_y/100000.);
93 info_ptr->x_green = (float)(green_x/100000.);
94 info_ptr->y_green = (float)(green_y/100000.);
95 info_ptr->x_blue = (float)( blue_x/100000.);
96 info_ptr->y_blue = (float)( blue_y/100000.);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060097#endif
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -060098 info_ptr->valid |= PNG_INFO_cHRM;
99 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600100}
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -0600101#endif /* PNG_FIXED_POINT_SUPPORTED */
102#endif /* PNG_cHRM_SUPPORTED */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600103
104#if defined(PNG_gAMA_SUPPORTED)
105#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500106void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500107png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
108{
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600109 double gamma;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500110 png_debug1(1, "in %s storage function", "gAMA");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600111 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500112 return;
113
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600114 /* Check for overflow */
115 if (file_gamma > 21474.83)
116 {
117 png_warning(png_ptr, "Limiting gamma to 21474.83");
118 gamma=21474.83;
119 }
120 else
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500121 gamma = file_gamma;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600122 info_ptr->gamma = (float)gamma;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600123#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600124 info_ptr->int_gamma = (int)(gamma*100000.+.5);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600125#endif
126 info_ptr->valid |= PNG_INFO_gAMA;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500127 if (gamma == 0.0)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500128 png_warning(png_ptr, "Setting gamma=0");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600129}
130#endif
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500131void PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600132png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
133 int_gamma)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600134{
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600135 png_fixed_point gamma;
136
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500137 png_debug1(1, "in %s storage function", "gAMA");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600138 if (png_ptr == NULL || info_ptr == NULL)
139 return;
140
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500141 if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600142 {
143 png_warning(png_ptr, "Limiting gamma to 21474.83");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500144 gamma=PNG_UINT_31_MAX;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600145 }
146 else
147 {
148 if (int_gamma < 0)
149 {
150 png_warning(png_ptr, "Setting negative gamma to zero");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500151 gamma = 0;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600152 }
153 else
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500154 gamma = int_gamma;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600155 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600156#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600157 info_ptr->gamma = (float)(gamma/100000.);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600158#endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500159#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600160 info_ptr->int_gamma = gamma;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500161#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500162 info_ptr->valid |= PNG_INFO_gAMA;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500163 if (gamma == 0)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500164 png_warning(png_ptr, "Setting gamma=0");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500165}
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500166#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500167
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600168#if defined(PNG_hIST_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500169void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500170png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
171{
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500172 int i;
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600173
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500174 png_debug1(1, "in %s storage function", "hIST");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600175 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500176 return;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500177 if (info_ptr->num_palette == 0 || info_ptr->num_palette
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600178 > PNG_MAX_PALETTE_LENGTH)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500179 {
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600180 png_warning(png_ptr,
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500181 "Invalid palette size, hIST allocation skipped");
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500182 return;
183 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500184
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600185#ifdef PNG_FREE_ME_SUPPORTED
186 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
187#endif
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600188 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in version
189 1.2.1 */
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500190 png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500191 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500192 if (png_ptr->hist == NULL)
193 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500194 png_warning(png_ptr, "Insufficient memory for hIST chunk data");
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500195 return;
196 }
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600197
198 for (i = 0; i < info_ptr->num_palette; i++)
199 png_ptr->hist[i] = hist[i];
200 info_ptr->hist = png_ptr->hist;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500201 info_ptr->valid |= PNG_INFO_hIST;
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600202
203#ifdef PNG_FREE_ME_SUPPORTED
204 info_ptr->free_me |= PNG_FREE_HIST;
205#else
206 png_ptr->flags |= PNG_FLAG_FREE_HIST;
207#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500208}
209#endif
210
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500211void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500212png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
213 png_uint_32 width, png_uint_32 height, int bit_depth,
214 int color_type, int interlace_type, int compression_type,
215 int filter_type)
216{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500217 png_debug1(1, "in %s storage function", "IHDR");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600218 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500219 return;
220
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500221 /* check for width and height valid values */
222 if (width == 0 || height == 0)
223 png_error(png_ptr, "Image width or height is zero in IHDR");
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500224#ifdef PNG_SET_USER_LIMITS_SUPPORTED
225 if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
226 png_error(png_ptr, "image size exceeds user limits in IHDR");
227#else
228 if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
229 png_error(png_ptr, "image size exceeds user limits in IHDR");
230#endif
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500231 if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500232 png_error(png_ptr, "Invalid image size in IHDR");
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500233 if ( width > (PNG_UINT_32_MAX
234 >> 3) /* 8-byte RGBA pixels */
235 - 64 /* bigrowbuf hack */
236 - 1 /* filter byte */
237 - 7*8 /* rounding of width to multiple of 8 pixels */
238 - 8) /* extra max_pixel_depth pad */
239 png_warning(png_ptr, "Width is too large for libpng to process pixels");
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500240
241 /* check other values */
242 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
243 bit_depth != 8 && bit_depth != 16)
244 png_error(png_ptr, "Invalid bit depth in IHDR");
245
246 if (color_type < 0 || color_type == 1 ||
247 color_type == 5 || color_type > 6)
248 png_error(png_ptr, "Invalid color type in IHDR");
249
250 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
251 ((color_type == PNG_COLOR_TYPE_RGB ||
252 color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
253 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
254 png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
255
256 if (interlace_type >= PNG_INTERLACE_LAST)
257 png_error(png_ptr, "Unknown interlace method in IHDR");
258
259 if (compression_type != PNG_COMPRESSION_TYPE_BASE)
260 png_error(png_ptr, "Unknown compression method in IHDR");
261
262#if defined(PNG_MNG_FEATURES_SUPPORTED)
263 /* Accept filter_method 64 (intrapixel differencing) only if
264 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
265 * 2. Libpng did not read a PNG signature (this filter_method is only
266 * used in PNG datastreams that are embedded in MNG datastreams) and
267 * 3. The application called png_permit_mng_features with a mask that
268 * included PNG_FLAG_MNG_FILTER_64 and
269 * 4. The filter_method is 64 and
270 * 5. The color_type is RGB or RGBA
271 */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500272 if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
273 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
274 if (filter_type != PNG_FILTER_TYPE_BASE)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500275 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500276 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500277 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
278 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600279 (color_type == PNG_COLOR_TYPE_RGB ||
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500280 color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
281 png_error(png_ptr, "Unknown filter method in IHDR");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500282 if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500283 png_warning(png_ptr, "Invalid filter method in IHDR");
284 }
285#else
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500286 if (filter_type != PNG_FILTER_TYPE_BASE)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500287 png_error(png_ptr, "Unknown filter method in IHDR");
288#endif
289
Andreas Dilger47a0c421997-05-16 02:46:07 -0500290 info_ptr->width = width;
291 info_ptr->height = height;
292 info_ptr->bit_depth = (png_byte)bit_depth;
293 info_ptr->color_type =(png_byte) color_type;
294 info_ptr->compression_type = (png_byte)compression_type;
295 info_ptr->filter_type = (png_byte)filter_type;
296 info_ptr->interlace_type = (png_byte)interlace_type;
Glenn Randers-Pehrson25d82242002-05-01 11:51:26 -0500297 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
298 info_ptr->channels = 1;
299 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500300 info_ptr->channels = 3;
301 else
302 info_ptr->channels = 1;
303 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
304 info_ptr->channels++;
305 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600306
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500307 /* check for potential overflow */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500308 if (width > (PNG_UINT_32_MAX
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500309 >> 3) /* 8-byte RGBA pixels */
310 - 64 /* bigrowbuf hack */
311 - 1 /* filter byte */
312 - 7*8 /* rounding of width to multiple of 8 pixels */
313 - 8) /* extra max_pixel_depth pad */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500314 info_ptr->rowbytes = 0;
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500315 else
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500316 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500317}
318
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600319#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500320void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500321png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600322 png_int_32 offset_x, png_int_32 offset_y, int unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500323{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500324 png_debug1(1, "in %s storage function", "oFFs");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600325 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500326 return;
327
328 info_ptr->x_offset = offset_x;
329 info_ptr->y_offset = offset_y;
330 info_ptr->offset_unit_type = (png_byte)unit_type;
331 info_ptr->valid |= PNG_INFO_oFFs;
332}
333#endif
334
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600335#if defined(PNG_pCAL_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500336void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500337png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
338 png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
339 png_charp units, png_charpp params)
340{
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500341 png_size_t length;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600342 int i;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500343
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500344 png_debug1(1, "in %s storage function", "pCAL");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600345 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500346 return;
347
348 length = png_strlen(purpose) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500349 png_debug1(3, "allocating purpose for info (%lu bytes)",
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500350 (unsigned long)length);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500351 info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
352 if (info_ptr->pcal_purpose == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500353 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500354 png_warning(png_ptr, "Insufficient memory for pCAL purpose");
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500355 return;
356 }
357 png_memcpy(info_ptr->pcal_purpose, purpose, length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500358
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500359 png_debug(3, "storing X0, X1, type, and nparams in info");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500360 info_ptr->pcal_X0 = X0;
361 info_ptr->pcal_X1 = X1;
362 info_ptr->pcal_type = (png_byte)type;
363 info_ptr->pcal_nparams = (png_byte)nparams;
364
365 length = png_strlen(units) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500366 png_debug1(3, "allocating units for info (%lu bytes)",
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500367 (unsigned long)length);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500368 info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
369 if (info_ptr->pcal_units == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500370 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500371 png_warning(png_ptr, "Insufficient memory for pCAL units");
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500372 return;
373 }
374 png_memcpy(info_ptr->pcal_units, units, length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500375
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500376 info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500377 (png_size_t)((nparams + 1) * png_sizeof(png_charp)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500378 if (info_ptr->pcal_params == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500379 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500380 png_warning(png_ptr, "Insufficient memory for pCAL params");
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500381 return;
382 }
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500383
Andreas Dilger47a0c421997-05-16 02:46:07 -0500384 info_ptr->pcal_params[nparams] = NULL;
385
386 for (i = 0; i < nparams; i++)
387 {
388 length = png_strlen(params[i]) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500389 png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500390 (unsigned long)length);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500391 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
392 if (info_ptr->pcal_params[i] == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500393 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500394 png_warning(png_ptr, "Insufficient memory for pCAL parameter");
395 return;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500396 }
397 png_memcpy(info_ptr->pcal_params[i], params[i], length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500398 }
399
400 info_ptr->valid |= PNG_INFO_pCAL;
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500401#ifdef PNG_FREE_ME_SUPPORTED
402 info_ptr->free_me |= PNG_FREE_PCAL;
403#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500404}
405#endif
406
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600407#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
408#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500409void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600410png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600411 int unit, double width, double height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600412{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500413 png_debug1(1, "in %s storage function", "sCAL");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600414 if (png_ptr == NULL || info_ptr == NULL)
415 return;
416
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600417 info_ptr->scal_unit = (png_byte)unit;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600418 info_ptr->scal_pixel_width = width;
419 info_ptr->scal_pixel_height = height;
420
421 info_ptr->valid |= PNG_INFO_sCAL;
422}
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600423#else
424#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500425void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600426png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600427 int unit, png_charp swidth, png_charp sheight)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600428{
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500429 png_size_t length;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600430
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500431 png_debug1(1, "in %s storage function", "sCAL");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600432 if (png_ptr == NULL || info_ptr == NULL)
433 return;
434
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600435 info_ptr->scal_unit = (png_byte)unit;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600436
437 length = png_strlen(swidth) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500438 png_debug1(3, "allocating unit for info (%u bytes)",
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500439 (unsigned int)length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500440 info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
441 if (info_ptr->scal_s_width == NULL)
442 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500443 png_warning(png_ptr,
444 "Memory allocation failed while processing sCAL");
445 return;
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500446 }
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500447 png_memcpy(info_ptr->scal_s_width, swidth, length);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600448
449 length = png_strlen(sheight) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500450 png_debug1(3, "allocating unit for info (%u bytes)",
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500451 (unsigned int)length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500452 info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
453 if (info_ptr->scal_s_height == NULL)
454 {
455 png_free (png_ptr, info_ptr->scal_s_width);
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500456 info_ptr->scal_s_width = NULL;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500457 png_warning(png_ptr,
458 "Memory allocation failed while processing sCAL");
459 return;
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500460 }
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500461 png_memcpy(info_ptr->scal_s_height, sheight, length);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600462 info_ptr->valid |= PNG_INFO_sCAL;
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500463#ifdef PNG_FREE_ME_SUPPORTED
464 info_ptr->free_me |= PNG_FREE_SCAL;
465#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600466}
467#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600468#endif
469#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600470
471#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500472void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500473png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
474 png_uint_32 res_x, png_uint_32 res_y, int unit_type)
475{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500476 png_debug1(1, "in %s storage function", "pHYs");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600477 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500478 return;
479
480 info_ptr->x_pixels_per_unit = res_x;
481 info_ptr->y_pixels_per_unit = res_y;
482 info_ptr->phys_unit_type = (png_byte)unit_type;
483 info_ptr->valid |= PNG_INFO_pHYs;
484}
485#endif
486
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500487void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500488png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
489 png_colorp palette, int num_palette)
490{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600491
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500492 png_debug1(1, "in %s storage function", "PLTE");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600493 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500494 return;
495
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600496 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
497 {
498 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
499 png_error(png_ptr, "Invalid palette length");
500 else
501 {
502 png_warning(png_ptr, "Invalid palette length");
503 return;
504 }
505 }
506
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600507 /*
508 * It may not actually be necessary to set png_ptr->palette here;
509 * we do it for backward compatibility with the way the png_handle_tRNS
510 * function used to do the allocation.
511 */
512#ifdef PNG_FREE_ME_SUPPORTED
513 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
514#endif
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500515
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600516 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
517 of num_palette entries,
Glenn Randers-Pehrsondb3b88d2001-12-04 06:30:43 -0600518 in case of an invalid PNG file that has too-large sample values. */
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500519 png_ptr->palette = (png_colorp)png_malloc(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500520 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600521 png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500522 png_sizeof(png_color));
523 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600524 info_ptr->palette = png_ptr->palette;
525 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600526
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600527#ifdef PNG_FREE_ME_SUPPORTED
528 info_ptr->free_me |= PNG_FREE_PLTE;
529#else
530 png_ptr->flags |= PNG_FLAG_FREE_PLTE;
531#endif
532
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600533 info_ptr->valid |= PNG_INFO_PLTE;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500534}
535
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600536#if defined(PNG_sBIT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500537void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500538png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
539 png_color_8p sig_bit)
540{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500541 png_debug1(1, "in %s storage function", "sBIT");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600542 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500543 return;
544
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500545 png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500546 info_ptr->valid |= PNG_INFO_sBIT;
547}
548#endif
549
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600550#if defined(PNG_sRGB_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500551void PNGAPI
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600552png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600553{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500554 png_debug1(1, "in %s storage function", "sRGB");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600555 if (png_ptr == NULL || info_ptr == NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600556 return;
557
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600558 info_ptr->srgb_intent = (png_byte)intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600559 info_ptr->valid |= PNG_INFO_sRGB;
560}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600561
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500562void PNGAPI
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600563png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600564 int intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600565{
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600566#if defined(PNG_gAMA_SUPPORTED)
567#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600568 float file_gamma;
569#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600570#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600571 png_fixed_point int_file_gamma;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600572#endif
573#endif
574#if defined(PNG_cHRM_SUPPORTED)
575#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600576 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
577#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600578#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600579 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 -0600580 int_green_y, int_blue_x, int_blue_y;
581#endif
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)
601#ifdef PNG_FIXED_POINT_SUPPORTED
602 int_white_x = 31270L;
603 int_white_y = 32900L;
604 int_red_x = 64000L;
605 int_red_y = 33000L;
606 int_green_x = 30000L;
607 int_green_y = 60000L;
608 int_blue_x = 15000L;
609 int_blue_y = 6000L;
610
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -0600611 if (png_check_cHRM_fixed(png_ptr,
612 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
613 int_green_y, int_blue_x, int_blue_y))
614 png_set_cHRM_fixed(png_ptr, info_ptr,
615 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
616 int_green_y, int_blue_x, int_blue_y);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600617#endif
618#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600619 white_x = (float).3127;
620 white_y = (float).3290;
621 red_x = (float).64;
622 red_y = (float).33;
623 green_x = (float).30;
624 green_y = (float).60;
625 blue_x = (float).15;
626 blue_y = (float).06;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600627
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -0600628 if (png_check_cHRM(png_ptr,
629 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
630 png_set_cHRM(png_ptr, info_ptr,
631 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600632#endif
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600633#endif
634}
635#endif
636
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600637
638#if defined(PNG_iCCP_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500639void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600640png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
641 png_charp name, int compression_type,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600642 png_charp profile, png_uint_32 proflen)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600643{
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500644 png_charp new_iccp_name;
645 png_charp new_iccp_profile;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500646 png_uint_32 length;
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500647
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500648 png_debug1(1, "in %s storage function", "iCCP");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600649 if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
650 return;
651
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500652 length = png_strlen(name)+1;
653 new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500654 if (new_iccp_name == NULL)
655 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500656 png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500657 return;
658 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500659 png_memcpy(new_iccp_name, name, length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500660 new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
661 if (new_iccp_profile == NULL)
662 {
663 png_free (png_ptr, new_iccp_name);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500664 png_warning(png_ptr,
665 "Insufficient memory to process iCCP profile");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500666 return;
667 }
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500668 png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
669
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500670 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500671
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600672 info_ptr->iccp_proflen = proflen;
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500673 info_ptr->iccp_name = new_iccp_name;
674 info_ptr->iccp_profile = new_iccp_profile;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600675 /* Compression is always zero but is here so the API and info structure
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500676 * does not have to change if we introduce multiple compression types */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600677 info_ptr->iccp_compression = (png_byte)compression_type;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500678#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600679 info_ptr->free_me |= PNG_FREE_ICCP;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500680#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600681 info_ptr->valid |= PNG_INFO_iCCP;
682}
683#endif
684
685#if defined(PNG_TEXT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500686void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500687png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
688 int num_text)
689{
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500690 int ret;
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500691 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500692 if (ret)
693 png_error(png_ptr, "Insufficient memory to store text");
694}
695
696int /* PRIVATE */
697png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
698 int num_text)
699{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500700 int i;
701
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500702 png_debug1(1, "in %s storage function", (png_ptr->chunk_name[0] == '\0' ?
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600703 "text" : (png_const_charp)png_ptr->chunk_name));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500704
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600705 if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500706 return(0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500707
708 /* Make sure we have enough space in the "text" array in info_struct
709 * to hold all of the incoming text_ptr objects.
710 */
711 if (info_ptr->num_text + num_text > info_ptr->max_text)
712 {
713 if (info_ptr->text != NULL)
714 {
715 png_textp old_text;
716 int old_max;
717
718 old_max = info_ptr->max_text;
719 info_ptr->max_text = info_ptr->num_text + num_text + 8;
720 old_text = info_ptr->text;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500721 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500722 (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500723 if (info_ptr->text == NULL)
724 {
725 png_free(png_ptr, old_text);
726 return(1);
727 }
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600728 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500729 png_sizeof(png_text)));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500730 png_free(png_ptr, old_text);
731 }
732 else
733 {
734 info_ptr->max_text = num_text + 8;
735 info_ptr->num_text = 0;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500736 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500737 (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500738 if (info_ptr->text == NULL)
739 return(1);
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500740#ifdef PNG_FREE_ME_SUPPORTED
741 info_ptr->free_me |= PNG_FREE_TEXT;
742#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500743 }
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500744 png_debug1(3, "allocated %d entries for info_ptr->text",
Andreas Dilger47a0c421997-05-16 02:46:07 -0500745 info_ptr->max_text);
746 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500747 for (i = 0; i < num_text; i++)
748 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500749 png_size_t text_length, key_len;
750 png_size_t lang_len, lang_key_len;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500751 png_textp textp = &(info_ptr->text[info_ptr->num_text]);
752
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500753 if (text_ptr[i].key == NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600754 continue;
755
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600756 key_len = png_strlen(text_ptr[i].key);
757
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500758 if (text_ptr[i].compression <= 0)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500759 {
760 lang_len = 0;
761 lang_key_len = 0;
762 }
763 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500764#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600765 {
766 /* set iTXt data */
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -0600767 if (text_ptr[i].lang != NULL)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500768 lang_len = png_strlen(text_ptr[i].lang);
769 else
770 lang_len = 0;
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500771 if (text_ptr[i].lang_key != NULL)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500772 lang_key_len = png_strlen(text_ptr[i].lang_key);
773 else
774 lang_key_len = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600775 }
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500776#else
777 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500778 png_warning(png_ptr, "iTXt chunk not supported");
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500779 continue;
780 }
781#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500782
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500783 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
Andreas Dilger47a0c421997-05-16 02:46:07 -0500784 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600785 text_length = 0;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500786#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500787 if (text_ptr[i].compression > 0)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600788 textp->compression = PNG_ITXT_COMPRESSION_NONE;
789 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500790#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600791 textp->compression = PNG_TEXT_COMPRESSION_NONE;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500792 }
793 else
794 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600795 text_length = png_strlen(text_ptr[i].text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500796 textp->compression = text_ptr[i].compression;
797 }
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500798
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500799 textp->key = (png_charp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500800 (png_size_t)
801 (key_len + text_length + lang_len + lang_key_len + 4));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500802 if (textp->key == NULL)
803 return(1);
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500804 png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500805 (unsigned long)(png_uint_32)
806 (key_len + lang_len + lang_key_len + text_length + 4),
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500807 (int)textp->key);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500808
809 png_memcpy(textp->key, text_ptr[i].key,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600810 (png_size_t)(key_len));
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500811 *(textp->key + key_len) = '\0';
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500812#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600813 if (text_ptr[i].compression > 0)
814 {
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500815 textp->lang = textp->key + key_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600816 png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500817 *(textp->lang + lang_len) = '\0';
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500818 textp->lang_key = textp->lang + lang_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600819 png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500820 *(textp->lang_key + lang_key_len) = '\0';
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500821 textp->text = textp->lang_key + lang_key_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600822 }
823 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500824#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600825 {
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500826#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500827 textp->lang=NULL;
828 textp->lang_key=NULL;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500829#endif
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500830 textp->text = textp->key + key_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600831 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500832 if (text_length)
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500833 png_memcpy(textp->text, text_ptr[i].text,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600834 (png_size_t)(text_length));
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500835 *(textp->text + text_length) = '\0';
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600836
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500837#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500838 if (textp->compression > 0)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600839 {
840 textp->text_length = 0;
841 textp->itxt_length = text_length;
842 }
843 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500844#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600845 {
846 textp->text_length = text_length;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500847#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600848 textp->itxt_length = 0;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500849#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600850 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500851 info_ptr->num_text++;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500852 png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500853 }
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500854 return(0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500855}
856#endif
857
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600858#if defined(PNG_tIME_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500859void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500860png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
861{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500862 png_debug1(1, "in %s storage function", "tIME");
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500863 if (png_ptr == NULL || info_ptr == NULL ||
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600864 (png_ptr->mode & PNG_WROTE_tIME))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500865 return;
866
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500867 png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500868 info_ptr->valid |= PNG_INFO_tIME;
869}
870#endif
871
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600872#if defined(PNG_tRNS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500873void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500874png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500875 png_bytep trans, int num_trans, png_color_16p trans_color)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500876{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500877 png_debug1(1, "in %s storage function", "tRNS");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600878 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500879 return;
880
881 if (trans != NULL)
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600882 {
883 /*
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500884 * It may not actually be necessary to set png_ptr->trans here;
885 * we do it for backward compatibility with the way the png_handle_tRNS
886 * function used to do the allocation.
887 */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500888
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600889#ifdef PNG_FREE_ME_SUPPORTED
890 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
891#endif
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500892
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600893 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500894 png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500895 (png_size_t)PNG_MAX_PALETTE_LENGTH);
896 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600897 png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600898 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500899
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500900 if (trans_color != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500901 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500902 int sample_max = (1 << info_ptr->bit_depth);
903 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500904 (int)trans_color->gray > sample_max) ||
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500905 (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500906 ((int)trans_color->red > sample_max ||
907 (int)trans_color->green > sample_max ||
908 (int)trans_color->blue > sample_max)))
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500909 png_warning(png_ptr,
910 "tRNS chunk has out-of-range samples for bit_depth");
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500911 png_memcpy(&(info_ptr->trans_color), trans_color,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500912 png_sizeof(png_color_16));
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600913 if (num_trans == 0)
914 num_trans = 1;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500915 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500916
Andreas Dilger47a0c421997-05-16 02:46:07 -0500917 info_ptr->num_trans = (png_uint_16)num_trans;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500918 if (num_trans != 0)
919 {
920 info_ptr->valid |= PNG_INFO_tRNS;
921#ifdef PNG_FREE_ME_SUPPORTED
922 info_ptr->free_me |= PNG_FREE_TRNS;
923#else
924 png_ptr->flags |= PNG_FLAG_FREE_TRNS;
925#endif
926 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500927}
928#endif
929
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600930#if defined(PNG_sPLT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500931void PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600932png_set_sPLT(png_structp png_ptr,
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600933 png_infop info_ptr, png_sPLT_tp entries, int nentries)
Glenn Randers-Pehrson3779c692006-11-07 20:38:11 -0600934/*
935 * entries - array of png_sPLT_t structures
936 * to be added to the list of palettes
937 * in the info structure.
938 * nentries - number of palette structures to be
939 * added.
940 */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600941{
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600942 png_sPLT_tp np;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600943 int i;
944
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -0600945 if (png_ptr == NULL || info_ptr == NULL)
946 return;
947
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500948 np = (png_sPLT_tp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500949 (info_ptr->splt_palettes_num + nentries) *
950 (png_size_t)png_sizeof(png_sPLT_t));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500951 if (np == NULL)
952 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500953 png_warning(png_ptr, "No memory for sPLT palettes");
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500954 return;
955 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600956
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600957 png_memcpy(np, info_ptr->splt_palettes,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500958 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600959 png_free(png_ptr, info_ptr->splt_palettes);
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500960 info_ptr->splt_palettes=NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600961
962 for (i = 0; i < nentries; i++)
963 {
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600964 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
965 png_sPLT_tp from = entries + i;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500966 png_uint_32 length;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600967
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500968 length = png_strlen(from->name) + 1;
969 to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length);
970 if (to->name == NULL)
971 {
972 png_warning(png_ptr,
973 "Out of memory while processing sPLT chunk");
974 continue;
975 }
976 png_memcpy(to->name, from->name, length);
977 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
978 (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry)));
979 if (to->entries == NULL)
980 {
981 png_warning(png_ptr,
982 "Out of memory while processing sPLT chunk");
983 png_free(png_ptr, to->name);
984 to->name = NULL;
985 continue;
986 }
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -0500987 png_memcpy(to->entries, from->entries,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500988 from->nentries * png_sizeof(png_sPLT_entry));
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -0500989 to->nentries = from->nentries;
990 to->depth = from->depth;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600991 }
992
993 info_ptr->splt_palettes = np;
994 info_ptr->splt_palettes_num += nentries;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600995 info_ptr->valid |= PNG_INFO_sPLT;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500996#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600997 info_ptr->free_me |= PNG_FREE_SPLT;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500998#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600999}
1000#endif /* PNG_sPLT_SUPPORTED */
1001
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -05001002#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001003void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001004png_set_unknown_chunks(png_structp png_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001005 png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001006{
1007 png_unknown_chunkp np;
1008 int i;
1009
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001010 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
1011 return;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001012
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -05001013 np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001014 (png_size_t)((info_ptr->unknown_chunks_num + num_unknowns) *
1015 png_sizeof(png_unknown_chunk)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -05001016 if (np == NULL)
1017 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001018 png_warning(png_ptr,
1019 "Out of memory while processing unknown chunk");
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -05001020 return;
1021 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001022
1023 png_memcpy(np, info_ptr->unknown_chunks,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001024 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001025 png_free(png_ptr, info_ptr->unknown_chunks);
1026
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001027 for (i = 0; i < num_unknowns; i++)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001028 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001029 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
1030 png_unknown_chunkp from = unknowns + i;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001031
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001032 png_memcpy((png_charp)to->name,
1033 (png_charp)from->name,
1034 png_sizeof(from->name));
1035 to->name[png_sizeof(to->name)-1] = '\0';
1036 to->size = from->size;
1037 /* note our location in the read or write sequence */
1038 to->location = (png_byte)(png_ptr->mode & 0xff);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001039
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001040 if (from->size == 0)
1041 to->data=NULL;
1042 else
1043 {
1044 to->data = (png_bytep)png_malloc_warn(png_ptr,
1045 (png_size_t)from->size);
1046 if (to->data == NULL)
1047 {
1048 png_warning(png_ptr,
1049 "Out of memory while processing unknown chunk");
1050 to->size = 0;
1051 }
1052 else
1053 png_memcpy(to->data, from->data, from->size);
1054 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001055 }
1056
1057 info_ptr->unknown_chunks = np;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001058 info_ptr->unknown_chunks_num += num_unknowns;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001059#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001060 info_ptr->free_me |= PNG_FREE_UNKN;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001061#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001062}
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001063void PNGAPI
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001064png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
1065 int chunk, int location)
1066{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001067 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001068 (int)info_ptr->unknown_chunks_num)
1069 info_ptr->unknown_chunks[chunk].location = (png_byte)location;
1070}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001071#endif
1072
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001073
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06001074#if defined(PNG_MNG_FEATURES_SUPPORTED)
1075png_uint_32 PNGAPI
1076png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
1077{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001078 png_debug(1, "in png_permit_mng_features");
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06001079 if (png_ptr == NULL)
1080 return (png_uint_32)0;
1081 png_ptr->mng_features_permitted =
1082 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
1083 return (png_uint_32)png_ptr->mng_features_permitted;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001084}
1085#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001086
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001087#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001088void PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001089png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
1090 chunk_list, int num_chunks)
1091{
1092 png_bytep new_list, p;
1093 int i, old_num_chunks;
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -06001094 if (png_ptr == NULL)
1095 return;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001096 if (num_chunks == 0)
1097 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001098 if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001099 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
1100 else
1101 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001102
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001103 if (keep == PNG_HANDLE_CHUNK_ALWAYS)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001104 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1105 else
1106 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1107 return;
1108 }
1109 if (chunk_list == NULL)
1110 return;
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -05001111 old_num_chunks = png_ptr->num_chunk_list;
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05001112 new_list=(png_bytep)png_malloc(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001113 (png_size_t)
1114 (5*(num_chunks + old_num_chunks)));
1115 if (png_ptr->chunk_list != NULL)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001116 {
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05001117 png_memcpy(new_list, png_ptr->chunk_list,
1118 (png_size_t)(5*old_num_chunks));
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001119 png_free(png_ptr, png_ptr->chunk_list);
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -05001120 png_ptr->chunk_list=NULL;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001121 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001122 png_memcpy(new_list + 5*old_num_chunks, chunk_list,
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05001123 (png_size_t)(5*num_chunks));
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -05001124 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 -06001125 *p=(png_byte)keep;
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -05001126 png_ptr->num_chunk_list = old_num_chunks + num_chunks;
1127 png_ptr->chunk_list = new_list;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001128#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001129 png_ptr->free_me |= PNG_FREE_LIST;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001130#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001131}
1132#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001133
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001134#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001135void PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001136png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
1137 png_user_chunk_ptr read_user_chunk_fn)
1138{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001139 png_debug(1, "in png_set_read_user_chunk_fn");
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -06001140 if (png_ptr == NULL)
1141 return;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001142 png_ptr->read_user_chunk_fn = read_user_chunk_fn;
1143 png_ptr->user_chunk_ptr = user_chunk_ptr;
1144}
1145#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001146
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001147#if defined(PNG_INFO_IMAGE_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001148void PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001149png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
1150{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001151 png_debug1(1, "in %s storage function", "rows");
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001152
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001153 if (png_ptr == NULL || info_ptr == NULL)
1154 return;
1155
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001156 if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001157 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001158 info_ptr->row_pointers = row_pointers;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001159 if (row_pointers)
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001160 info_ptr->valid |= PNG_INFO_IDAT;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001161}
1162#endif
1163
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001164#ifdef PNG_WRITE_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001165void PNGAPI
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001166png_set_compression_buffer_size(png_structp png_ptr,
1167 png_size_t size)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001168{
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -06001169 if (png_ptr == NULL)
1170 return;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001171 png_free(png_ptr, png_ptr->zbuf);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001172 png_ptr->zbuf_size = size;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001173 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
1174 png_ptr->zstream.next_out = png_ptr->zbuf;
1175 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1176}
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001177#endif
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001178
1179void PNGAPI
1180png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
1181{
1182 if (png_ptr && info_ptr)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001183 info_ptr->valid &= ~mask;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001184}
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06001185
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05001186
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001187
1188#ifdef PNG_SET_USER_LIMITS_SUPPORTED
1189/* this function was added to libpng 1.2.6 */
1190void PNGAPI
1191png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
1192 png_uint_32 user_height_max)
1193{
1194 /* Images with dimensions larger than these limits will be
1195 * rejected by png_set_IHDR(). To accept any PNG datastream
1196 * regardless of dimensions, set both limits to 0x7ffffffL.
1197 */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001198 if (png_ptr == NULL) return;
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001199 png_ptr->user_width_max = user_width_max;
1200 png_ptr->user_height_max = user_height_max;
1201}
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001202/* this function was added to libpng 1.4.0 */
1203void PNGAPI
1204png_set_chunk_cache_max (png_structp png_ptr,
1205 png_uint_32 user_chunk_cache_max)
1206{
1207 if (png_ptr == NULL) return;
1208 png_ptr->user_chunk_cache_max = user_chunk_cache_max;
1209 if (user_chunk_cache_max == 0x7fffffffL) /* Unlimited */
1210 png_ptr->user_chunk_cache_max = 0;
1211 else
1212 png_ptr->user_chunk_cache_max = user_chunk_cache_max + 1;
1213}
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001214#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1215
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001216
1217#if defined(PNG_BENIGN_ERRORS_SUPPORTED)
1218void PNGAPI
1219png_set_benign_errors(png_structp png_ptr, int allowed)
1220{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001221 png_debug(1, "in png_set_benign_errors");
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001222 if (allowed)
1223 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
1224 else
1225 png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
1226}
1227#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001228#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */