blob: a0961e34afe59ad4bca04cb43b06e35dfb22ebce [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-Pehrsonf81b50b2009-12-29 16:50:15 -06004 * Last changed in libpng 1.4.0 [December 29, 2009]
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -06005 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -05006 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06008 *
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -05009 * This code is released under the libpng license.
Glenn Randers-Pehrsonc332bbc2009-06-25 13:43:50 -050010 * For conditions of distribution and use, see the disclaimer
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -050011 * and license in png.h
Glenn Randers-Pehrson3e61d792009-06-24 09:31:28 -050012 *
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060013 * The functions here are used during reads to store data from the file
14 * into the info struct, and during writes to store application data
15 * into the info struct for writing into the file. This abstracts the
16 * info struct and allows us to change the structure in the future.
17 */
Andreas Dilger47a0c421997-05-16 02:46:07 -050018
Glenn Randers-Pehrson03f9b022009-12-04 08:40:41 -060019#define PNG_NO_PEDANTIC_WARNINGS
Andreas Dilger47a0c421997-05-16 02:46:07 -050020#include "png.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060021#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050022#include "pngpriv.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060023
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -050024#ifdef PNG_bKGD_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050025void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -050026png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
27{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -050028 png_debug1(1, "in %s storage function", "bKGD");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -050029
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060030 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050031 return;
32
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050033 png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
Andreas Dilger47a0c421997-05-16 02:46:07 -050034 info_ptr->valid |= PNG_INFO_bKGD;
35}
36#endif
37
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -050038#ifdef PNG_cHRM_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060039#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050040void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -050041png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
42 double white_x, double white_y, double red_x, double red_y,
43 double green_x, double green_y, double blue_x, double blue_y)
44{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -050045 png_debug1(1, "in %s storage function", "cHRM");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -050046
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060047 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050048 return;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060049
Andreas Dilger47a0c421997-05-16 02:46:07 -050050 info_ptr->x_white = (float)white_x;
51 info_ptr->y_white = (float)white_y;
52 info_ptr->x_red = (float)red_x;
53 info_ptr->y_red = (float)red_y;
54 info_ptr->x_green = (float)green_x;
55 info_ptr->y_green = (float)green_y;
56 info_ptr->x_blue = (float)blue_x;
57 info_ptr->y_blue = (float)blue_y;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060058#ifdef PNG_FIXED_POINT_SUPPORTED
59 info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
60 info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060061 info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
62 info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060063 info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
64 info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060065 info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
66 info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060067#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -050068 info_ptr->valid |= PNG_INFO_cHRM;
69}
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -060070#endif /* PNG_FLOATING_POINT_SUPPORTED */
71
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060072#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050073void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060074png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060075 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
76 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
77 png_fixed_point blue_x, png_fixed_point blue_y)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060078{
Glenn Randers-Pehrsond6d80752008-12-02 09:49:43 -060079 png_debug1(1, "in %s storage function", "cHRM fixed");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -050080
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060081 if (png_ptr == NULL || info_ptr == NULL)
82 return;
Andreas Dilger47a0c421997-05-16 02:46:07 -050083
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -050084#ifdef PNG_CHECK_cHRM_SUPPORTED
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -060085 if (png_check_cHRM_fixed(png_ptr,
86 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
Glenn Randers-Pehrson71a3c1f2008-11-26 12:00:38 -060087#endif
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050088 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050089 info_ptr->int_x_white = white_x;
90 info_ptr->int_y_white = white_y;
91 info_ptr->int_x_red = red_x;
92 info_ptr->int_y_red = red_y;
93 info_ptr->int_x_green = green_x;
94 info_ptr->int_y_green = green_y;
95 info_ptr->int_x_blue = blue_x;
96 info_ptr->int_y_blue = blue_y;
97#ifdef PNG_FLOATING_POINT_SUPPORTED
98 info_ptr->x_white = (float)(white_x/100000.);
99 info_ptr->y_white = (float)(white_y/100000.);
100 info_ptr->x_red = (float)( red_x/100000.);
101 info_ptr->y_red = (float)( red_y/100000.);
102 info_ptr->x_green = (float)(green_x/100000.);
103 info_ptr->y_green = (float)(green_y/100000.);
104 info_ptr->x_blue = (float)( blue_x/100000.);
105 info_ptr->y_blue = (float)( blue_y/100000.);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600106#endif
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500107 info_ptr->valid |= PNG_INFO_cHRM;
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -0600108 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600109}
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -0600110#endif /* PNG_FIXED_POINT_SUPPORTED */
111#endif /* PNG_cHRM_SUPPORTED */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600112
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500113#ifdef PNG_gAMA_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600114#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500115void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500116png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
117{
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500118 double png_gamma;
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500119
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500120 png_debug1(1, "in %s storage function", "gAMA");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500121
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600122 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500123 return;
124
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600125 /* Check for overflow */
126 if (file_gamma > 21474.83)
127 {
128 png_warning(png_ptr, "Limiting gamma to 21474.83");
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500129 png_gamma=21474.83;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600130 }
131 else
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500132 png_gamma = file_gamma;
133 info_ptr->gamma = (float)png_gamma;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600134#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson4db4aff2009-04-20 11:49:24 -0500135 info_ptr->int_gamma = (int)(png_gamma*100000.+.5);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600136#endif
137 info_ptr->valid |= PNG_INFO_gAMA;
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500138 if (png_gamma == 0.0)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500139 png_warning(png_ptr, "Setting gamma=0");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600140}
141#endif
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500142void PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600143png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
144 int_gamma)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600145{
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500146 png_fixed_point png_gamma;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600147
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500148 png_debug1(1, "in %s storage function", "gAMA");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500149
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600150 if (png_ptr == NULL || info_ptr == NULL)
151 return;
152
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500153 if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX)
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600154 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500155 png_warning(png_ptr, "Limiting gamma to 21474.83");
156 png_gamma=PNG_UINT_31_MAX;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600157 }
158 else
159 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500160 if (int_gamma < 0)
161 {
162 png_warning(png_ptr, "Setting negative gamma to zero");
163 png_gamma = 0;
164 }
165 else
166 png_gamma = int_gamma;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600167 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600168#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson4db4aff2009-04-20 11:49:24 -0500169 info_ptr->gamma = (float)(png_gamma/100000.);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600170#endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500171#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500172 info_ptr->int_gamma = png_gamma;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500173#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500174 info_ptr->valid |= PNG_INFO_gAMA;
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500175 if (png_gamma == 0)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500176 png_warning(png_ptr, "Setting gamma=0");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500177}
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500178#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500179
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500180#ifdef PNG_hIST_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500181void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500182png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
183{
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500184 int i;
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600185
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500186 png_debug1(1, "in %s storage function", "hIST");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500187
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600188 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500189 return;
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500190
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500191 if (info_ptr->num_palette == 0 || info_ptr->num_palette
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600192 > PNG_MAX_PALETTE_LENGTH)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500193 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500194 png_warning(png_ptr,
195 "Invalid palette size, hIST allocation skipped");
196 return;
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500197 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500198
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600199 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500200 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
201 * version 1.2.1
202 */
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500203 png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500204 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500205 if (png_ptr->hist == NULL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500206 {
207 png_warning(png_ptr, "Insufficient memory for hIST chunk data");
208 return;
209 }
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600210
211 for (i = 0; i < info_ptr->num_palette; i++)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500212 png_ptr->hist[i] = hist[i];
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600213 info_ptr->hist = png_ptr->hist;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500214 info_ptr->valid |= PNG_INFO_hIST;
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600215
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600216 info_ptr->free_me |= PNG_FREE_HIST;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500217}
218#endif
219
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500220void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500221png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
222 png_uint_32 width, png_uint_32 height, int bit_depth,
223 int color_type, int interlace_type, int compression_type,
224 int filter_type)
225{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500226 png_debug1(1, "in %s storage function", "IHDR");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500227
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600228 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500229 return;
230
231 info_ptr->width = width;
232 info_ptr->height = height;
233 info_ptr->bit_depth = (png_byte)bit_depth;
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500234 info_ptr->color_type = (png_byte)color_type;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500235 info_ptr->compression_type = (png_byte)compression_type;
236 info_ptr->filter_type = (png_byte)filter_type;
237 info_ptr->interlace_type = (png_byte)interlace_type;
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500238
239 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
240 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
241 info_ptr->compression_type, info_ptr->filter_type);
242
Glenn Randers-Pehrson25d82242002-05-01 11:51:26 -0500243 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
244 info_ptr->channels = 1;
245 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500246 info_ptr->channels = 3;
247 else
248 info_ptr->channels = 1;
249 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
250 info_ptr->channels++;
251 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600252
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500253 /* Check for potential overflow */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500254 if (width > (PNG_UINT_32_MAX
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500255 >> 3) /* 8-byte RGBA pixels */
256 - 64 /* bigrowbuf hack */
257 - 1 /* filter byte */
258 - 7*8 /* rounding of width to multiple of 8 pixels */
259 - 8) /* extra max_pixel_depth pad */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500260 info_ptr->rowbytes = 0;
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500261 else
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500262 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500263}
264
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500265#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500266void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500267png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600268 png_int_32 offset_x, png_int_32 offset_y, int unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500269{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500270 png_debug1(1, "in %s storage function", "oFFs");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500271
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600272 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500273 return;
274
275 info_ptr->x_offset = offset_x;
276 info_ptr->y_offset = offset_y;
277 info_ptr->offset_unit_type = (png_byte)unit_type;
278 info_ptr->valid |= PNG_INFO_oFFs;
279}
280#endif
281
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500282#ifdef PNG_pCAL_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500283void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500284png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
285 png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
286 png_charp units, png_charpp params)
287{
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500288 png_size_t length;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600289 int i;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500290
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500291 png_debug1(1, "in %s storage function", "pCAL");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500292
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600293 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500294 return;
295
296 length = png_strlen(purpose) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500297 png_debug1(3, "allocating purpose for info (%lu bytes)",
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500298 (unsigned long)length);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500299 info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
300 if (info_ptr->pcal_purpose == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500301 {
Glenn Randers-Pehrson83fb8552009-06-16 17:52:23 -0500302 png_warning(png_ptr, "Insufficient memory for pCAL purpose");
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500303 return;
304 }
305 png_memcpy(info_ptr->pcal_purpose, purpose, length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500306
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500307 png_debug(3, "storing X0, X1, type, and nparams in info");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500308 info_ptr->pcal_X0 = X0;
309 info_ptr->pcal_X1 = X1;
310 info_ptr->pcal_type = (png_byte)type;
311 info_ptr->pcal_nparams = (png_byte)nparams;
312
313 length = png_strlen(units) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500314 png_debug1(3, "allocating units for info (%lu bytes)",
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500315 (unsigned long)length);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500316 info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
317 if (info_ptr->pcal_units == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500318 {
Glenn Randers-Pehrson83fb8552009-06-16 17:52:23 -0500319 png_warning(png_ptr, "Insufficient memory for pCAL units");
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500320 return;
321 }
322 png_memcpy(info_ptr->pcal_units, units, length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500323
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500324 info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500325 (png_size_t)((nparams + 1) * png_sizeof(png_charp)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500326 if (info_ptr->pcal_params == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500327 {
Glenn Randers-Pehrson83fb8552009-06-16 17:52:23 -0500328 png_warning(png_ptr, "Insufficient memory for pCAL params");
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500329 return;
330 }
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500331
Glenn Randers-Pehrson0ffb71a2009-02-28 06:08:20 -0600332 png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500333
334 for (i = 0; i < nparams; i++)
335 {
336 length = png_strlen(params[i]) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500337 png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500338 (unsigned long)length);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500339 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
340 if (info_ptr->pcal_params[i] == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500341 {
Glenn Randers-Pehrson83fb8552009-06-16 17:52:23 -0500342 png_warning(png_ptr, "Insufficient memory for pCAL parameter");
343 return;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500344 }
345 png_memcpy(info_ptr->pcal_params[i], params[i], length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500346 }
347
348 info_ptr->valid |= PNG_INFO_pCAL;
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500349 info_ptr->free_me |= PNG_FREE_PCAL;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500350}
351#endif
352
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600353#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
354#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500355void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600356png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600357 int unit, double width, double height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600358{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500359 png_debug1(1, "in %s storage function", "sCAL");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500360
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600361 if (png_ptr == NULL || info_ptr == NULL)
362 return;
363
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600364 info_ptr->scal_unit = (png_byte)unit;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600365 info_ptr->scal_pixel_width = width;
366 info_ptr->scal_pixel_height = height;
367
368 info_ptr->valid |= PNG_INFO_sCAL;
369}
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600370#else
371#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500372void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600373png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600374 int unit, png_charp swidth, png_charp sheight)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600375{
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500376 png_size_t length;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600377
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500378 png_debug1(1, "in %s storage function", "sCAL");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500379
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600380 if (png_ptr == NULL || info_ptr == NULL)
381 return;
382
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600383 info_ptr->scal_unit = (png_byte)unit;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600384
385 length = png_strlen(swidth) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500386 png_debug1(3, "allocating unit for info (%u bytes)",
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500387 (unsigned int)length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500388 info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
389 if (info_ptr->scal_s_width == NULL)
390 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500391 png_warning(png_ptr,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600392 "Memory allocation failed while processing sCAL");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500393 return;
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500394 }
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500395 png_memcpy(info_ptr->scal_s_width, swidth, length);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600396
397 length = png_strlen(sheight) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500398 png_debug1(3, "allocating unit for info (%u bytes)",
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500399 (unsigned int)length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500400 info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
401 if (info_ptr->scal_s_height == NULL)
402 {
403 png_free (png_ptr, info_ptr->scal_s_width);
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500404 info_ptr->scal_s_width = NULL;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500405 png_warning(png_ptr,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600406 "Memory allocation failed while processing sCAL");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500407 return;
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500408 }
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500409 png_memcpy(info_ptr->scal_s_height, sheight, length);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600410 info_ptr->valid |= PNG_INFO_sCAL;
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500411 info_ptr->free_me |= PNG_FREE_SCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600412}
413#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600414#endif
415#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600416
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500417#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500418void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500419png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
420 png_uint_32 res_x, png_uint_32 res_y, int unit_type)
421{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500422 png_debug1(1, "in %s storage function", "pHYs");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500423
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600424 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500425 return;
426
427 info_ptr->x_pixels_per_unit = res_x;
428 info_ptr->y_pixels_per_unit = res_y;
429 info_ptr->phys_unit_type = (png_byte)unit_type;
430 info_ptr->valid |= PNG_INFO_pHYs;
431}
432#endif
433
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500434void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500435png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
436 png_colorp palette, int num_palette)
437{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600438
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500439 png_debug1(1, "in %s storage function", "PLTE");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500440
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600441 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500442 return;
443
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600444 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500445 {
446 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600447 png_error(png_ptr, "Invalid palette length");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500448 else
449 {
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600450 png_warning(png_ptr, "Invalid palette length");
451 return;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500452 }
453 }
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600454
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600455 /* It may not actually be necessary to set png_ptr->palette here;
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600456 * we do it for backward compatibility with the way the png_handle_tRNS
457 * function used to do the allocation.
458 */
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600459 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500460
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600461 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500462 * of num_palette entries, in case of an invalid PNG file that has
463 * too-large sample values.
464 */
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -0600465 png_ptr->palette = (png_colorp)png_calloc(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500466 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500467 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600468 info_ptr->palette = png_ptr->palette;
469 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600470
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600471 info_ptr->free_me |= PNG_FREE_PLTE;
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600472
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600473 info_ptr->valid |= PNG_INFO_PLTE;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500474}
475
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500476#ifdef PNG_sBIT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500477void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500478png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
479 png_color_8p sig_bit)
480{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500481 png_debug1(1, "in %s storage function", "sBIT");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500482
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600483 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500484 return;
485
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500486 png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500487 info_ptr->valid |= PNG_INFO_sBIT;
488}
489#endif
490
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500491#ifdef PNG_sRGB_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500492void PNGAPI
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600493png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600494{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500495 png_debug1(1, "in %s storage function", "sRGB");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500496
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600497 if (png_ptr == NULL || info_ptr == NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600498 return;
499
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600500 info_ptr->srgb_intent = (png_byte)intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600501 info_ptr->valid |= PNG_INFO_sRGB;
502}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600503
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500504void PNGAPI
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600505png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600506 int intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600507{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500508#ifdef PNG_gAMA_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600509#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600510 float file_gamma;
511#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600512#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600513 png_fixed_point int_file_gamma;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600514#endif
515#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500516#ifdef PNG_cHRM_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600517#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600518 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
519#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600520 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 -0600521 int_green_y, int_blue_x, int_blue_y;
522#endif
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500523 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500524
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600525 if (png_ptr == NULL || info_ptr == NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600526 return;
527
528 png_set_sRGB(png_ptr, info_ptr, intent);
529
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500530#ifdef PNG_gAMA_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600531#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonab1e5831999-10-06 04:57:42 -0500532 file_gamma = (float).45455;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600533 png_set_gAMA(png_ptr, info_ptr, file_gamma);
534#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600535#ifdef PNG_FIXED_POINT_SUPPORTED
536 int_file_gamma = 45455L;
537 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
538#endif
539#endif
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600540
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500541#ifdef PNG_cHRM_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600542 int_white_x = 31270L;
543 int_white_y = 32900L;
544 int_red_x = 64000L;
545 int_red_y = 33000L;
546 int_green_x = 30000L;
547 int_green_y = 60000L;
548 int_blue_x = 15000L;
549 int_blue_y = 6000L;
550
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600551#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600552 white_x = (float).3127;
553 white_y = (float).3290;
554 red_x = (float).64;
555 red_y = (float).33;
556 green_x = (float).30;
557 green_y = (float).60;
558 blue_x = (float).15;
559 blue_y = (float).06;
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600560#endif
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600561
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600562#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson85b02372009-09-24 19:49:13 -0500563 png_set_cHRM_fixed(png_ptr, info_ptr,
564 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
565 int_green_y, int_blue_x, int_blue_y);
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600566#endif
567#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson85b02372009-09-24 19:49:13 -0500568 png_set_cHRM(png_ptr, info_ptr,
569 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600570#endif
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600571#endif /* cHRM */
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600572}
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600573#endif /* sRGB */
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600574
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600575
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500576#ifdef PNG_iCCP_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500577void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600578png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
579 png_charp name, int compression_type,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600580 png_charp profile, png_uint_32 proflen)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600581{
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500582 png_charp new_iccp_name;
583 png_charp new_iccp_profile;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500584 png_uint_32 length;
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500585
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500586 png_debug1(1, "in %s storage function", "iCCP");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500587
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600588 if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
589 return;
590
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500591 length = png_strlen(name)+1;
592 new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500593 if (new_iccp_name == NULL)
594 {
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600595 png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500596 return;
597 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500598 png_memcpy(new_iccp_name, name, length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500599 new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
600 if (new_iccp_profile == NULL)
601 {
602 png_free (png_ptr, new_iccp_name);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500603 png_warning(png_ptr,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600604 "Insufficient memory to process iCCP profile");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500605 return;
606 }
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500607 png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
608
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500609 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500610
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600611 info_ptr->iccp_proflen = proflen;
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500612 info_ptr->iccp_name = new_iccp_name;
613 info_ptr->iccp_profile = new_iccp_profile;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600614 /* Compression is always zero but is here so the API and info structure
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600615 * does not have to change if we introduce multiple compression types
616 */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600617 info_ptr->iccp_compression = (png_byte)compression_type;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600618 info_ptr->free_me |= PNG_FREE_ICCP;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600619 info_ptr->valid |= PNG_INFO_iCCP;
620}
621#endif
622
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500623#ifdef PNG_TEXT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500624void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500625png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500626 int num_text)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500627{
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500628 int ret;
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500629 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500630 if (ret)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500631 png_error(png_ptr, "Insufficient memory to store text");
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500632}
633
634int /* PRIVATE */
635png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500636 int num_text)
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500637{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500638 int i;
639
Glenn Randers-Pehrsone2a118f2009-07-27 22:08:25 -0500640 png_debug1(1, "in %s storage function", ((png_ptr == NULL ||
641 png_ptr->chunk_name[0] == '\0') ?
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600642 "text" : (png_const_charp)png_ptr->chunk_name));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500643
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600644 if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500645 return(0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500646
647 /* Make sure we have enough space in the "text" array in info_struct
648 * to hold all of the incoming text_ptr objects.
649 */
650 if (info_ptr->num_text + num_text > info_ptr->max_text)
651 {
652 if (info_ptr->text != NULL)
653 {
654 png_textp old_text;
655 int old_max;
656
657 old_max = info_ptr->max_text;
658 info_ptr->max_text = info_ptr->num_text + num_text + 8;
659 old_text = info_ptr->text;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500660 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500661 (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500662 if (info_ptr->text == NULL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500663 {
664 png_free(png_ptr, old_text);
665 return(1);
666 }
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600667 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500668 png_sizeof(png_text)));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500669 png_free(png_ptr, old_text);
670 }
671 else
672 {
673 info_ptr->max_text = num_text + 8;
674 info_ptr->num_text = 0;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500675 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500676 (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500677 if (info_ptr->text == NULL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500678 return(1);
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500679 info_ptr->free_me |= PNG_FREE_TEXT;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500680 }
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500681 png_debug1(3, "allocated %d entries for info_ptr->text",
Andreas Dilger47a0c421997-05-16 02:46:07 -0500682 info_ptr->max_text);
683 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500684 for (i = 0; i < num_text; i++)
685 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500686 png_size_t text_length, key_len;
687 png_size_t lang_len, lang_key_len;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500688 png_textp textp = &(info_ptr->text[info_ptr->num_text]);
689
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500690 if (text_ptr[i].key == NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600691 continue;
692
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600693 key_len = png_strlen(text_ptr[i].key);
694
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500695 if (text_ptr[i].compression <= 0)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500696 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500697 lang_len = 0;
698 lang_key_len = 0;
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500699 }
Glenn Randers-Pehrsonef29a5e2009-10-31 19:37:05 -0500700
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500701 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500702#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600703 {
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500704 /* Set iTXt data */
Glenn Randers-Pehrsond6ea40a2009-11-02 07:32:00 -0600705
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500706 if (text_ptr[i].lang != NULL)
707 lang_len = png_strlen(text_ptr[i].lang);
708 else
709 lang_len = 0;
710 if (text_ptr[i].lang_key != NULL)
711 lang_key_len = png_strlen(text_ptr[i].lang_key);
712 else
713 lang_key_len = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600714 }
Glenn Randers-Pehrsond6ea40a2009-11-02 07:32:00 -0600715#else /* PNG_iTXt_SUPPORTED */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500716 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500717 png_warning(png_ptr, "iTXt chunk not supported");
718 continue;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500719 }
720#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500721
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500722 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
Andreas Dilger47a0c421997-05-16 02:46:07 -0500723 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600724 text_length = 0;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500725#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500726 if (text_ptr[i].compression > 0)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600727 textp->compression = PNG_ITXT_COMPRESSION_NONE;
728 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500729#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600730 textp->compression = PNG_TEXT_COMPRESSION_NONE;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500731 }
Glenn Randers-Pehrsonef29a5e2009-10-31 19:37:05 -0500732
Andreas Dilger47a0c421997-05-16 02:46:07 -0500733 else
734 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600735 text_length = png_strlen(text_ptr[i].text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500736 textp->compression = text_ptr[i].compression;
737 }
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500738
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500739 textp->key = (png_charp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500740 (png_size_t)
741 (key_len + text_length + lang_len + lang_key_len + 4));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500742 if (textp->key == NULL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500743 return(1);
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500744 png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500745 (unsigned long)(png_uint_32)
746 (key_len + lang_len + lang_key_len + text_length + 4),
747 (int)textp->key);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500748
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500749 png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500750 *(textp->key + key_len) = '\0';
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500751#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600752 if (text_ptr[i].compression > 0)
753 {
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500754 textp->lang = textp->key + key_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600755 png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500756 *(textp->lang + lang_len) = '\0';
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500757 textp->lang_key = textp->lang + lang_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600758 png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500759 *(textp->lang_key + lang_key_len) = '\0';
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500760 textp->text = textp->lang_key + lang_key_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600761 }
762 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500763#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600764 {
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500765#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500766 textp->lang=NULL;
767 textp->lang_key=NULL;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500768#endif
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500769 textp->text = textp->key + key_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600770 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500771 if (text_length)
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500772 png_memcpy(textp->text, text_ptr[i].text,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600773 (png_size_t)(text_length));
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500774 *(textp->text + text_length) = '\0';
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600775
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500776#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500777 if (textp->compression > 0)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600778 {
779 textp->text_length = 0;
780 textp->itxt_length = text_length;
781 }
782 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500783#endif
Glenn Randers-Pehrsonef29a5e2009-10-31 19:37:05 -0500784
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600785 {
786 textp->text_length = text_length;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500787#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600788 textp->itxt_length = 0;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500789#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600790 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500791 info_ptr->num_text++;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500792 png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500793 }
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500794 return(0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500795}
796#endif
797
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500798#ifdef PNG_tIME_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500799void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500800png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
801{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500802 png_debug1(1, "in %s storage function", "tIME");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500803
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500804 if (png_ptr == NULL || info_ptr == NULL ||
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600805 (png_ptr->mode & PNG_WROTE_tIME))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500806 return;
807
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500808 png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500809 info_ptr->valid |= PNG_INFO_tIME;
810}
811#endif
812
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500813#ifdef PNG_tRNS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500814void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500815png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson6abea752009-08-08 16:52:06 -0500816 png_bytep trans_alpha, int num_trans, png_color_16p trans_color)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500817{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500818 png_debug1(1, "in %s storage function", "tRNS");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500819
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600820 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500821 return;
822
Glenn Randers-Pehrson6abea752009-08-08 16:52:06 -0500823 if (trans_alpha != NULL)
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600824 {
Glenn Randers-Pehrsonef29a5e2009-10-31 19:37:05 -0500825 /* It may not actually be necessary to set png_ptr->trans_alpha here;
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500826 * we do it for backward compatibility with the way the png_handle_tRNS
827 * function used to do the allocation.
828 */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500829
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600830 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500831
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600832 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
Glenn Randers-Pehrson6abea752009-08-08 16:52:06 -0500833 png_ptr->trans_alpha = info_ptr->trans_alpha = (png_bytep)png_malloc(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500834 (png_size_t)PNG_MAX_PALETTE_LENGTH);
835 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
Glenn Randers-Pehrson6abea752009-08-08 16:52:06 -0500836 png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600837 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500838
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500839 if (trans_color != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500840 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500841 int sample_max = (1 << info_ptr->bit_depth);
842 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500843 (int)trans_color->gray > sample_max) ||
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500844 (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500845 ((int)trans_color->red > sample_max ||
846 (int)trans_color->green > sample_max ||
847 (int)trans_color->blue > sample_max)))
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500848 png_warning(png_ptr,
849 "tRNS chunk has out-of-range samples for bit_depth");
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500850 png_memcpy(&(info_ptr->trans_color), trans_color,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500851 png_sizeof(png_color_16));
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600852 if (num_trans == 0)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500853 num_trans = 1;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500854 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500855
Andreas Dilger47a0c421997-05-16 02:46:07 -0500856 info_ptr->num_trans = (png_uint_16)num_trans;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500857 if (num_trans != 0)
858 {
859 info_ptr->valid |= PNG_INFO_tRNS;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500860 info_ptr->free_me |= PNG_FREE_TRNS;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500861 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500862}
863#endif
864
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500865#ifdef PNG_sPLT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500866void PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600867png_set_sPLT(png_structp png_ptr,
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600868 png_infop info_ptr, png_sPLT_tp entries, int nentries)
Glenn Randers-Pehrson3779c692006-11-07 20:38:11 -0600869/*
870 * entries - array of png_sPLT_t structures
871 * to be added to the list of palettes
872 * in the info structure.
873 * nentries - number of palette structures to be
874 * added.
875 */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600876{
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500877 png_sPLT_tp np;
878 int i;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600879
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500880 if (png_ptr == NULL || info_ptr == NULL)
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500881 return;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600882
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500883 np = (png_sPLT_tp)png_malloc_warn(png_ptr,
884 (info_ptr->splt_palettes_num + nentries) *
885 (png_size_t)png_sizeof(png_sPLT_t));
886 if (np == NULL)
887 {
888 png_warning(png_ptr, "No memory for sPLT palettes");
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600889 return;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500890 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600891
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500892 png_memcpy(np, info_ptr->splt_palettes,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600893 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500894 png_free(png_ptr, info_ptr->splt_palettes);
895 info_ptr->splt_palettes=NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600896
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500897 for (i = 0; i < nentries; i++)
898 {
899 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
900 png_sPLT_tp from = entries + i;
901 png_uint_32 length;
902
903 length = png_strlen(from->name) + 1;
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600904 to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500905 if (to->name == NULL)
906 {
907 png_warning(png_ptr,
908 "Out of memory while processing sPLT chunk");
909 continue;
910 }
911 png_memcpy(to->name, from->name, length);
912 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600913 (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry)));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500914 if (to->entries == NULL)
915 {
916 png_warning(png_ptr,
917 "Out of memory while processing sPLT chunk");
918 png_free(png_ptr, to->name);
919 to->name = NULL;
920 continue;
921 }
922 png_memcpy(to->entries, from->entries,
923 from->nentries * png_sizeof(png_sPLT_entry));
924 to->nentries = from->nentries;
925 to->depth = from->depth;
926 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600927
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500928 info_ptr->splt_palettes = np;
929 info_ptr->splt_palettes_num += nentries;
930 info_ptr->valid |= PNG_INFO_sPLT;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500931 info_ptr->free_me |= PNG_FREE_SPLT;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600932}
933#endif /* PNG_sPLT_SUPPORTED */
934
Glenn Randers-Pehrson6ba90882009-12-25 14:26:13 -0600935#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500936void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600937png_set_unknown_chunks(png_structp png_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600938 png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600939{
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500940 png_unknown_chunkp np;
941 int i;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600942
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500943 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
Glenn Randers-Pehrson83fb8552009-06-16 17:52:23 -0500944 return;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600945
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500946 np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
947 (png_size_t)((info_ptr->unknown_chunks_num + num_unknowns) *
948 png_sizeof(png_unknown_chunk)));
949 if (np == NULL)
950 {
951 png_warning(png_ptr,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600952 "Out of memory while processing unknown chunk");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500953 return;
954 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600955
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500956 png_memcpy(np, info_ptr->unknown_chunks,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600957 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500958 png_free(png_ptr, info_ptr->unknown_chunks);
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600959 info_ptr->unknown_chunks = NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600960
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500961 for (i = 0; i < num_unknowns; i++)
962 {
963 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
964 png_unknown_chunkp from = unknowns + i;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600965
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600966 png_memcpy((png_charp)to->name, (png_charp)from->name,
967 png_sizeof(from->name));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500968 to->name[png_sizeof(to->name)-1] = '\0';
969 to->size = from->size;
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500970 /* Note our location in the read or write sequence */
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500971 to->location = (png_byte)(png_ptr->mode & 0xff);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600972
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500973 if (from->size == 0)
974 to->data=NULL;
975 else
976 {
977 to->data = (png_bytep)png_malloc_warn(png_ptr,
978 (png_size_t)from->size);
979 if (to->data == NULL)
980 {
981 png_warning(png_ptr,
982 "Out of memory while processing unknown chunk");
983 to->size = 0;
984 }
985 else
986 png_memcpy(to->data, from->data, from->size);
987 }
988 }
989
990 info_ptr->unknown_chunks = np;
991 info_ptr->unknown_chunks_num += num_unknowns;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500992 info_ptr->free_me |= PNG_FREE_UNKN;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600993}
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500994void PNGAPI
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500995png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
996 int chunk, int location)
997{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500998 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600999 (int)info_ptr->unknown_chunks_num)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001000 info_ptr->unknown_chunks[chunk].location = (png_byte)location;
1001}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001002#endif
1003
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001004
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001005#ifdef PNG_MNG_FEATURES_SUPPORTED
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06001006png_uint_32 PNGAPI
1007png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
1008{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001009 png_debug(1, "in png_permit_mng_features");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -05001010
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06001011 if (png_ptr == NULL)
1012 return (png_uint_32)0;
1013 png_ptr->mng_features_permitted =
1014 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
1015 return (png_uint_32)png_ptr->mng_features_permitted;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001016}
1017#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001018
Glenn Randers-Pehrson6ba90882009-12-25 14:26:13 -06001019#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001020void PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001021png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
1022 chunk_list, int num_chunks)
1023{
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001024 png_bytep new_list, p;
1025 int i, old_num_chunks;
1026 if (png_ptr == NULL)
1027 return;
1028 if (num_chunks == 0)
1029 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001030 if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001031 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001032 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001033 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001034
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001035 if (keep == PNG_HANDLE_CHUNK_ALWAYS)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001036 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001037 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001038 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001039 return;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001040 }
1041 if (chunk_list == NULL)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001042 return;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001043 old_num_chunks = png_ptr->num_chunk_list;
1044 new_list=(png_bytep)png_malloc(png_ptr,
1045 (png_size_t)
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -06001046 (5*(num_chunks + old_num_chunks)));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001047 if (png_ptr->chunk_list != NULL)
1048 {
1049 png_memcpy(new_list, png_ptr->chunk_list,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -06001050 (png_size_t)(5*old_num_chunks));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001051 png_free(png_ptr, png_ptr->chunk_list);
1052 png_ptr->chunk_list=NULL;
1053 }
1054 png_memcpy(new_list + 5*old_num_chunks, chunk_list,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -06001055 (png_size_t)(5*num_chunks));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001056 for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
1057 *p=(png_byte)keep;
1058 png_ptr->num_chunk_list = old_num_chunks + num_chunks;
1059 png_ptr->chunk_list = new_list;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001060 png_ptr->free_me |= PNG_FREE_LIST;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001061}
1062#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001063
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001064#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001065void PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001066png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
1067 png_user_chunk_ptr read_user_chunk_fn)
1068{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001069 png_debug(1, "in png_set_read_user_chunk_fn");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -05001070
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -06001071 if (png_ptr == NULL)
1072 return;
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -05001073
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001074 png_ptr->read_user_chunk_fn = read_user_chunk_fn;
1075 png_ptr->user_chunk_ptr = user_chunk_ptr;
1076}
1077#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001078
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001079#ifdef PNG_INFO_IMAGE_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001080void PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001081png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
1082{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001083 png_debug1(1, "in %s storage function", "rows");
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001084
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001085 if (png_ptr == NULL || info_ptr == NULL)
1086 return;
1087
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001088 if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001089 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001090 info_ptr->row_pointers = row_pointers;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001091 if (row_pointers)
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001092 info_ptr->valid |= PNG_INFO_IDAT;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001093}
1094#endif
1095
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001096#ifdef PNG_WRITE_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001097void PNGAPI
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001098png_set_compression_buffer_size(png_structp png_ptr,
1099 png_size_t size)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001100{
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -06001101 if (png_ptr == NULL)
1102 return;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001103 png_free(png_ptr, png_ptr->zbuf);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001104 png_ptr->zbuf_size = size;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001105 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
1106 png_ptr->zstream.next_out = png_ptr->zbuf;
1107 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1108}
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001109#endif
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001110
1111void PNGAPI
1112png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
1113{
1114 if (png_ptr && info_ptr)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001115 info_ptr->valid &= ~mask;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001116}
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06001117
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05001118
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001119
1120#ifdef PNG_SET_USER_LIMITS_SUPPORTED
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -05001121/* This function was added to libpng 1.2.6 */
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001122void PNGAPI
1123png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
1124 png_uint_32 user_height_max)
1125{
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001126 /* Images with dimensions larger than these limits will be
1127 * rejected by png_set_IHDR(). To accept any PNG datastream
1128 * regardless of dimensions, set both limits to 0x7ffffffL.
1129 */
1130 if (png_ptr == NULL)
1131 return;
1132 png_ptr->user_width_max = user_width_max;
1133 png_ptr->user_height_max = user_height_max;
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001134}
Glenn Randers-Pehrson17ca3402009-11-09 06:51:16 -06001135/* This function was added to libpng 1.4.0 */
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001136void PNGAPI
1137png_set_chunk_cache_max (png_structp png_ptr,
1138 png_uint_32 user_chunk_cache_max)
1139{
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001140 if (png_ptr == NULL)
1141 return;
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001142 png_ptr->user_chunk_cache_max = user_chunk_cache_max;
1143 if (user_chunk_cache_max == 0x7fffffffL) /* Unlimited */
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001144 png_ptr->user_chunk_cache_max = 0;
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001145 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001146 png_ptr->user_chunk_cache_max = user_chunk_cache_max + 1;
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001147}
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001148#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1149
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001150
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001151#ifdef PNG_BENIGN_ERRORS_SUPPORTED
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001152void PNGAPI
1153png_set_benign_errors(png_structp png_ptr, int allowed)
1154{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001155 png_debug(1, "in png_set_benign_errors");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -05001156
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001157 if (allowed)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001158 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001159 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001160 png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001161}
1162#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001163#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */