blob: c9ab8f6d734608cf2bcd9a28de96daebcb8c3b97 [file] [log] [blame]
The Android Open Source Project893912b2009-03-03 19:30:05 -08001
2/* pngset.c - storage of image information into info struct
3 *
Patrick Scott5f6bd842010-06-28 16:55:16 -04004 * Last changed in libpng 1.2.43 [February 25, 2010]
5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
The Android Open Source Project893912b2009-03-03 19:30:05 -08006 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
Patrick Scotta0bb96c2009-07-22 11:50:02 -04009 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
The Android Open Source Project893912b2009-03-03 19:30:05 -080013 * The functions here are used during reads to store data from the file
14 * into the info struct, and during writes to store application data
15 * into the info struct for writing into the file. This abstracts the
16 * info struct and allows us to change the structure in the future.
17 */
18
19#define PNG_INTERNAL
Patrick Scott5f6bd842010-06-28 16:55:16 -040020#define PNG_NO_PEDANTIC_WARNINGS
The Android Open Source Project893912b2009-03-03 19:30:05 -080021#include "png.h"
The Android Open Source Project893912b2009-03-03 19:30:05 -080022#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
23
Patrick Scott5f6bd842010-06-28 16:55:16 -040024#ifdef PNG_bKGD_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -080025void PNGAPI
26png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
27{
The Android Open Source Project4215dd12009-03-09 11:52:12 -070028 png_debug1(1, "in %s storage function", "bKGD");
Patrick Scott5f6bd842010-06-28 16:55:16 -040029
The Android Open Source Project893912b2009-03-03 19:30:05 -080030 if (png_ptr == NULL || info_ptr == NULL)
31 return;
32
33 png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
34 info_ptr->valid |= PNG_INFO_bKGD;
35}
36#endif
37
Patrick Scott5f6bd842010-06-28 16:55:16 -040038#ifdef PNG_cHRM_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -080039#ifdef PNG_FLOATING_POINT_SUPPORTED
40void PNGAPI
41png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
42 double white_x, double white_y, double red_x, double red_y,
43 double green_x, double green_y, double blue_x, double blue_y)
44{
The Android Open Source Project4215dd12009-03-09 11:52:12 -070045 png_debug1(1, "in %s storage function", "cHRM");
Patrick Scott5f6bd842010-06-28 16:55:16 -040046
The Android Open Source Project893912b2009-03-03 19:30:05 -080047 if (png_ptr == NULL || info_ptr == NULL)
48 return;
The Android Open Source Project893912b2009-03-03 19:30:05 -080049
50 info_ptr->x_white = (float)white_x;
51 info_ptr->y_white = (float)white_y;
52 info_ptr->x_red = (float)red_x;
53 info_ptr->y_red = (float)red_y;
54 info_ptr->x_green = (float)green_x;
55 info_ptr->y_green = (float)green_y;
56 info_ptr->x_blue = (float)blue_x;
57 info_ptr->y_blue = (float)blue_y;
58#ifdef PNG_FIXED_POINT_SUPPORTED
59 info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
60 info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
61 info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
62 info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
63 info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
64 info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
65 info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
66 info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
67#endif
68 info_ptr->valid |= PNG_INFO_cHRM;
69}
The Android Open Source Project4215dd12009-03-09 11:52:12 -070070#endif /* PNG_FLOATING_POINT_SUPPORTED */
71
The Android Open Source Project893912b2009-03-03 19:30:05 -080072#ifdef PNG_FIXED_POINT_SUPPORTED
73void PNGAPI
74png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
75 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
76 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
77 png_fixed_point blue_x, png_fixed_point blue_y)
78{
The Android Open Source Project4215dd12009-03-09 11:52:12 -070079 png_debug1(1, "in %s storage function", "cHRM fixed");
Patrick Scott5f6bd842010-06-28 16:55:16 -040080
The Android Open Source Project893912b2009-03-03 19:30:05 -080081 if (png_ptr == NULL || info_ptr == NULL)
82 return;
83
Patrick Scott5f6bd842010-06-28 16:55:16 -040084#ifdef PNG_CHECK_cHRM_SUPPORTED
The Android Open Source Project4215dd12009-03-09 11:52:12 -070085 if (png_check_cHRM_fixed(png_ptr,
86 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
87#endif
The Android Open Source Project893912b2009-03-03 19:30:05 -080088 {
Patrick Scotta0bb96c2009-07-22 11:50:02 -040089 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.);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800106#endif
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400107 info_ptr->valid |= PNG_INFO_cHRM;
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700108 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800109}
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700110#endif /* PNG_FIXED_POINT_SUPPORTED */
111#endif /* PNG_cHRM_SUPPORTED */
The Android Open Source Project893912b2009-03-03 19:30:05 -0800112
Patrick Scott5f6bd842010-06-28 16:55:16 -0400113#ifdef PNG_gAMA_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800114#ifdef PNG_FLOATING_POINT_SUPPORTED
115void PNGAPI
116png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
117{
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400118 double png_gamma;
Patrick Scott5f6bd842010-06-28 16:55:16 -0400119
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700120 png_debug1(1, "in %s storage function", "gAMA");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400121
The Android Open Source Project893912b2009-03-03 19:30:05 -0800122 if (png_ptr == NULL || info_ptr == NULL)
123 return;
124
125 /* Check for overflow */
126 if (file_gamma > 21474.83)
127 {
128 png_warning(png_ptr, "Limiting gamma to 21474.83");
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400129 png_gamma=21474.83;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800130 }
131 else
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400132 png_gamma = file_gamma;
133 info_ptr->gamma = (float)png_gamma;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800134#ifdef PNG_FIXED_POINT_SUPPORTED
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400135 info_ptr->int_gamma = (int)(png_gamma*100000.+.5);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800136#endif
137 info_ptr->valid |= PNG_INFO_gAMA;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400138 if (png_gamma == 0.0)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800139 png_warning(png_ptr, "Setting gamma=0");
140}
141#endif
142void PNGAPI
143png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
144 int_gamma)
145{
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400146 png_fixed_point png_gamma;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800147
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700148 png_debug1(1, "in %s storage function", "gAMA");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400149
The Android Open Source Project893912b2009-03-03 19:30:05 -0800150 if (png_ptr == NULL || info_ptr == NULL)
151 return;
152
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400153 if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800154 {
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400155 png_warning(png_ptr, "Limiting gamma to 21474.83");
156 png_gamma=PNG_UINT_31_MAX;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800157 }
158 else
159 {
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400160 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;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800167 }
168#ifdef PNG_FLOATING_POINT_SUPPORTED
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400169 info_ptr->gamma = (float)(png_gamma/100000.);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800170#endif
171#ifdef PNG_FIXED_POINT_SUPPORTED
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400172 info_ptr->int_gamma = png_gamma;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800173#endif
174 info_ptr->valid |= PNG_INFO_gAMA;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400175 if (png_gamma == 0)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800176 png_warning(png_ptr, "Setting gamma=0");
177}
178#endif
179
Patrick Scott5f6bd842010-06-28 16:55:16 -0400180#ifdef PNG_hIST_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800181void PNGAPI
182png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
183{
184 int i;
185
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700186 png_debug1(1, "in %s storage function", "hIST");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400187
The Android Open Source Project893912b2009-03-03 19:30:05 -0800188 if (png_ptr == NULL || info_ptr == NULL)
189 return;
Patrick Scott5f6bd842010-06-28 16:55:16 -0400190
The Android Open Source Project893912b2009-03-03 19:30:05 -0800191 if (info_ptr->num_palette == 0 || info_ptr->num_palette
192 > PNG_MAX_PALETTE_LENGTH)
193 {
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400194 png_warning(png_ptr,
195 "Invalid palette size, hIST allocation skipped.");
196 return;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800197 }
198
199#ifdef PNG_FREE_ME_SUPPORTED
200 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
201#endif
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400202 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
203 * version 1.2.1
204 */
The Android Open Source Project893912b2009-03-03 19:30:05 -0800205 png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700206 (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16)));
The Android Open Source Project893912b2009-03-03 19:30:05 -0800207 if (png_ptr->hist == NULL)
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400208 {
209 png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
210 return;
211 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800212
213 for (i = 0; i < info_ptr->num_palette; i++)
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400214 png_ptr->hist[i] = hist[i];
The Android Open Source Project893912b2009-03-03 19:30:05 -0800215 info_ptr->hist = png_ptr->hist;
216 info_ptr->valid |= PNG_INFO_hIST;
217
218#ifdef PNG_FREE_ME_SUPPORTED
219 info_ptr->free_me |= PNG_FREE_HIST;
220#else
221 png_ptr->flags |= PNG_FLAG_FREE_HIST;
222#endif
223}
224#endif
225
226void PNGAPI
227png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
228 png_uint_32 width, png_uint_32 height, int bit_depth,
229 int color_type, int interlace_type, int compression_type,
230 int filter_type)
231{
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700232 png_debug1(1, "in %s storage function", "IHDR");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400233
The Android Open Source Project893912b2009-03-03 19:30:05 -0800234 if (png_ptr == NULL || info_ptr == NULL)
235 return;
236
The Android Open Source Project893912b2009-03-03 19:30:05 -0800237 info_ptr->width = width;
238 info_ptr->height = height;
239 info_ptr->bit_depth = (png_byte)bit_depth;
Patrick Scott5f6bd842010-06-28 16:55:16 -0400240 info_ptr->color_type = (png_byte)color_type;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800241 info_ptr->compression_type = (png_byte)compression_type;
242 info_ptr->filter_type = (png_byte)filter_type;
243 info_ptr->interlace_type = (png_byte)interlace_type;
Patrick Scott5f6bd842010-06-28 16:55:16 -0400244
245 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
246 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
247 info_ptr->compression_type, info_ptr->filter_type);
248
The Android Open Source Project893912b2009-03-03 19:30:05 -0800249 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
250 info_ptr->channels = 1;
251 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
252 info_ptr->channels = 3;
253 else
254 info_ptr->channels = 1;
255 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
256 info_ptr->channels++;
257 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
258
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400259 /* Check for potential overflow */
The Android Open Source Project893912b2009-03-03 19:30:05 -0800260 if (width > (PNG_UINT_32_MAX
261 >> 3) /* 8-byte RGBA pixels */
262 - 64 /* bigrowbuf hack */
263 - 1 /* filter byte */
264 - 7*8 /* rounding of width to multiple of 8 pixels */
265 - 8) /* extra max_pixel_depth pad */
266 info_ptr->rowbytes = (png_size_t)0;
267 else
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700268 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800269}
270
Patrick Scott5f6bd842010-06-28 16:55:16 -0400271#ifdef PNG_oFFs_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800272void PNGAPI
273png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
274 png_int_32 offset_x, png_int_32 offset_y, int unit_type)
275{
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700276 png_debug1(1, "in %s storage function", "oFFs");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400277
The Android Open Source Project893912b2009-03-03 19:30:05 -0800278 if (png_ptr == NULL || info_ptr == NULL)
279 return;
280
281 info_ptr->x_offset = offset_x;
282 info_ptr->y_offset = offset_y;
283 info_ptr->offset_unit_type = (png_byte)unit_type;
284 info_ptr->valid |= PNG_INFO_oFFs;
285}
286#endif
287
Patrick Scott5f6bd842010-06-28 16:55:16 -0400288#ifdef PNG_pCAL_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800289void PNGAPI
290png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
291 png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
292 png_charp units, png_charpp params)
293{
294 png_uint_32 length;
295 int i;
296
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700297 png_debug1(1, "in %s storage function", "pCAL");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400298
The Android Open Source Project893912b2009-03-03 19:30:05 -0800299 if (png_ptr == NULL || info_ptr == NULL)
300 return;
301
302 length = png_strlen(purpose) + 1;
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700303 png_debug1(3, "allocating purpose for info (%lu bytes)",
304 (unsigned long)length);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800305 info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
306 if (info_ptr->pcal_purpose == NULL)
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700307 {
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400308 png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700309 return;
310 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800311 png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
312
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700313 png_debug(3, "storing X0, X1, type, and nparams in info");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800314 info_ptr->pcal_X0 = X0;
315 info_ptr->pcal_X1 = X1;
316 info_ptr->pcal_type = (png_byte)type;
317 info_ptr->pcal_nparams = (png_byte)nparams;
318
319 length = png_strlen(units) + 1;
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700320 png_debug1(3, "allocating units for info (%lu bytes)",
321 (unsigned long)length);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800322 info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
323 if (info_ptr->pcal_units == NULL)
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700324 {
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400325 png_warning(png_ptr, "Insufficient memory for pCAL units.");
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700326 return;
327 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800328 png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
329
330 info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
331 (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
332 if (info_ptr->pcal_params == NULL)
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700333 {
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400334 png_warning(png_ptr, "Insufficient memory for pCAL params.");
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700335 return;
336 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800337
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700338 png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp));
The Android Open Source Project893912b2009-03-03 19:30:05 -0800339
340 for (i = 0; i < nparams; i++)
341 {
342 length = png_strlen(params[i]) + 1;
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700343 png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
344 (unsigned long)length);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800345 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
346 if (info_ptr->pcal_params[i] == NULL)
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700347 {
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400348 png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
349 return;
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700350 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800351 png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
352 }
353
354 info_ptr->valid |= PNG_INFO_pCAL;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400355#ifdef PNG_FREE_ME_SUPPORTED
356 info_ptr->free_me |= PNG_FREE_PCAL;
357#endif
The Android Open Source Project893912b2009-03-03 19:30:05 -0800358}
359#endif
360
361#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
362#ifdef PNG_FLOATING_POINT_SUPPORTED
363void PNGAPI
364png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
365 int unit, double width, double height)
366{
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700367 png_debug1(1, "in %s storage function", "sCAL");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400368
The Android Open Source Project893912b2009-03-03 19:30:05 -0800369 if (png_ptr == NULL || info_ptr == NULL)
370 return;
371
372 info_ptr->scal_unit = (png_byte)unit;
373 info_ptr->scal_pixel_width = width;
374 info_ptr->scal_pixel_height = height;
375
376 info_ptr->valid |= PNG_INFO_sCAL;
377}
378#else
379#ifdef PNG_FIXED_POINT_SUPPORTED
380void PNGAPI
381png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
382 int unit, png_charp swidth, png_charp sheight)
383{
384 png_uint_32 length;
385
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700386 png_debug1(1, "in %s storage function", "sCAL");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400387
The Android Open Source Project893912b2009-03-03 19:30:05 -0800388 if (png_ptr == NULL || info_ptr == NULL)
389 return;
390
391 info_ptr->scal_unit = (png_byte)unit;
392
393 length = png_strlen(swidth) + 1;
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700394 png_debug1(3, "allocating unit for info (%u bytes)",
395 (unsigned int)length);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800396 info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
397 if (info_ptr->scal_s_width == NULL)
398 {
399 png_warning(png_ptr,
Patrick Scott5f6bd842010-06-28 16:55:16 -0400400 "Memory allocation failed while processing sCAL.");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800401 return;
402 }
403 png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
404
405 length = png_strlen(sheight) + 1;
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700406 png_debug1(3, "allocating unit for info (%u bytes)",
407 (unsigned int)length);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800408 info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
409 if (info_ptr->scal_s_height == NULL)
410 {
411 png_free (png_ptr, info_ptr->scal_s_width);
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700412 info_ptr->scal_s_width = NULL;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800413 png_warning(png_ptr,
Patrick Scott5f6bd842010-06-28 16:55:16 -0400414 "Memory allocation failed while processing sCAL.");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800415 return;
416 }
417 png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
418 info_ptr->valid |= PNG_INFO_sCAL;
419#ifdef PNG_FREE_ME_SUPPORTED
420 info_ptr->free_me |= PNG_FREE_SCAL;
421#endif
422}
423#endif
424#endif
425#endif
426
Patrick Scott5f6bd842010-06-28 16:55:16 -0400427#ifdef PNG_pHYs_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800428void PNGAPI
429png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
430 png_uint_32 res_x, png_uint_32 res_y, int unit_type)
431{
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700432 png_debug1(1, "in %s storage function", "pHYs");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400433
The Android Open Source Project893912b2009-03-03 19:30:05 -0800434 if (png_ptr == NULL || info_ptr == NULL)
435 return;
436
437 info_ptr->x_pixels_per_unit = res_x;
438 info_ptr->y_pixels_per_unit = res_y;
439 info_ptr->phys_unit_type = (png_byte)unit_type;
440 info_ptr->valid |= PNG_INFO_pHYs;
441}
442#endif
443
444void PNGAPI
445png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
446 png_colorp palette, int num_palette)
447{
448
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700449 png_debug1(1, "in %s storage function", "PLTE");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400450
The Android Open Source Project893912b2009-03-03 19:30:05 -0800451 if (png_ptr == NULL || info_ptr == NULL)
452 return;
453
454 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400455 {
456 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800457 png_error(png_ptr, "Invalid palette length");
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400458 else
459 {
The Android Open Source Project893912b2009-03-03 19:30:05 -0800460 png_warning(png_ptr, "Invalid palette length");
461 return;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400462 }
463 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800464
Patrick Scott5f6bd842010-06-28 16:55:16 -0400465 /* It may not actually be necessary to set png_ptr->palette here;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800466 * we do it for backward compatibility with the way the png_handle_tRNS
467 * function used to do the allocation.
468 */
469#ifdef PNG_FREE_ME_SUPPORTED
470 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
471#endif
472
473 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400474 * of num_palette entries, in case of an invalid PNG file that has
475 * too-large sample values.
476 */
Patrick Scott5f6bd842010-06-28 16:55:16 -0400477 png_ptr->palette = (png_colorp)png_calloc(png_ptr,
The Android Open Source Project893912b2009-03-03 19:30:05 -0800478 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700479 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
The Android Open Source Project893912b2009-03-03 19:30:05 -0800480 info_ptr->palette = png_ptr->palette;
481 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
482
483#ifdef PNG_FREE_ME_SUPPORTED
484 info_ptr->free_me |= PNG_FREE_PLTE;
485#else
486 png_ptr->flags |= PNG_FLAG_FREE_PLTE;
487#endif
488
489 info_ptr->valid |= PNG_INFO_PLTE;
490}
491
Patrick Scott5f6bd842010-06-28 16:55:16 -0400492#ifdef PNG_sBIT_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800493void PNGAPI
494png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
495 png_color_8p sig_bit)
496{
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700497 png_debug1(1, "in %s storage function", "sBIT");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400498
The Android Open Source Project893912b2009-03-03 19:30:05 -0800499 if (png_ptr == NULL || info_ptr == NULL)
500 return;
501
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700502 png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
The Android Open Source Project893912b2009-03-03 19:30:05 -0800503 info_ptr->valid |= PNG_INFO_sBIT;
504}
505#endif
506
Patrick Scott5f6bd842010-06-28 16:55:16 -0400507#ifdef PNG_sRGB_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800508void PNGAPI
509png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
510{
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700511 png_debug1(1, "in %s storage function", "sRGB");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400512
The Android Open Source Project893912b2009-03-03 19:30:05 -0800513 if (png_ptr == NULL || info_ptr == NULL)
514 return;
515
516 info_ptr->srgb_intent = (png_byte)intent;
517 info_ptr->valid |= PNG_INFO_sRGB;
518}
519
520void PNGAPI
521png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
522 int intent)
523{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400524#ifdef PNG_gAMA_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800525#ifdef PNG_FLOATING_POINT_SUPPORTED
526 float file_gamma;
527#endif
528#ifdef PNG_FIXED_POINT_SUPPORTED
529 png_fixed_point int_file_gamma;
530#endif
531#endif
Patrick Scott5f6bd842010-06-28 16:55:16 -0400532#ifdef PNG_cHRM_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800533#ifdef PNG_FLOATING_POINT_SUPPORTED
534 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
535#endif
The Android Open Source Project893912b2009-03-03 19:30:05 -0800536 png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
537 int_green_y, int_blue_x, int_blue_y;
538#endif
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700539 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400540
The Android Open Source Project893912b2009-03-03 19:30:05 -0800541 if (png_ptr == NULL || info_ptr == NULL)
542 return;
543
544 png_set_sRGB(png_ptr, info_ptr, intent);
545
Patrick Scott5f6bd842010-06-28 16:55:16 -0400546#ifdef PNG_gAMA_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800547#ifdef PNG_FLOATING_POINT_SUPPORTED
548 file_gamma = (float).45455;
549 png_set_gAMA(png_ptr, info_ptr, file_gamma);
550#endif
551#ifdef PNG_FIXED_POINT_SUPPORTED
552 int_file_gamma = 45455L;
553 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
554#endif
555#endif
556
Patrick Scott5f6bd842010-06-28 16:55:16 -0400557#ifdef PNG_cHRM_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800558 int_white_x = 31270L;
559 int_white_y = 32900L;
560 int_red_x = 64000L;
561 int_red_y = 33000L;
562 int_green_x = 30000L;
563 int_green_y = 60000L;
564 int_blue_x = 15000L;
565 int_blue_y = 6000L;
566
The Android Open Source Project893912b2009-03-03 19:30:05 -0800567#ifdef PNG_FLOATING_POINT_SUPPORTED
568 white_x = (float).3127;
569 white_y = (float).3290;
570 red_x = (float).64;
571 red_y = (float).33;
572 green_x = (float).30;
573 green_y = (float).60;
574 blue_x = (float).15;
575 blue_y = (float).06;
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700576#endif
The Android Open Source Project893912b2009-03-03 19:30:05 -0800577
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700578#ifdef PNG_FIXED_POINT_SUPPORTED
Patrick Scott5f6bd842010-06-28 16:55:16 -0400579 png_set_cHRM_fixed(png_ptr, info_ptr,
580 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
581 int_green_y, int_blue_x, int_blue_y);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800582#endif
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700583#ifdef PNG_FLOATING_POINT_SUPPORTED
Patrick Scott5f6bd842010-06-28 16:55:16 -0400584 png_set_cHRM(png_ptr, info_ptr,
585 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700586#endif
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700587#endif /* cHRM */
The Android Open Source Project893912b2009-03-03 19:30:05 -0800588}
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700589#endif /* sRGB */
The Android Open Source Project893912b2009-03-03 19:30:05 -0800590
591
Patrick Scott5f6bd842010-06-28 16:55:16 -0400592#ifdef PNG_iCCP_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800593void PNGAPI
594png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
595 png_charp name, int compression_type,
596 png_charp profile, png_uint_32 proflen)
597{
598 png_charp new_iccp_name;
599 png_charp new_iccp_profile;
600 png_uint_32 length;
601
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700602 png_debug1(1, "in %s storage function", "iCCP");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400603
The Android Open Source Project893912b2009-03-03 19:30:05 -0800604 if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
605 return;
606
607 length = png_strlen(name)+1;
608 new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
609 if (new_iccp_name == NULL)
610 {
Patrick Scott5f6bd842010-06-28 16:55:16 -0400611 png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800612 return;
613 }
614 png_memcpy(new_iccp_name, name, length);
615 new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
616 if (new_iccp_profile == NULL)
617 {
618 png_free (png_ptr, new_iccp_name);
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700619 png_warning(png_ptr,
Patrick Scott5f6bd842010-06-28 16:55:16 -0400620 "Insufficient memory to process iCCP profile.");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800621 return;
622 }
623 png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
624
625 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
626
627 info_ptr->iccp_proflen = proflen;
628 info_ptr->iccp_name = new_iccp_name;
629 info_ptr->iccp_profile = new_iccp_profile;
630 /* Compression is always zero but is here so the API and info structure
Patrick Scott5f6bd842010-06-28 16:55:16 -0400631 * does not have to change if we introduce multiple compression types
632 */
The Android Open Source Project893912b2009-03-03 19:30:05 -0800633 info_ptr->iccp_compression = (png_byte)compression_type;
634#ifdef PNG_FREE_ME_SUPPORTED
635 info_ptr->free_me |= PNG_FREE_ICCP;
636#endif
637 info_ptr->valid |= PNG_INFO_iCCP;
638}
639#endif
640
Patrick Scott5f6bd842010-06-28 16:55:16 -0400641#ifdef PNG_TEXT_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800642void PNGAPI
643png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400644 int num_text)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800645{
646 int ret;
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700647 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800648 if (ret)
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400649 png_error(png_ptr, "Insufficient memory to store text");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800650}
651
652int /* PRIVATE */
653png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400654 int num_text)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800655{
656 int i;
657
Patrick Scott5f6bd842010-06-28 16:55:16 -0400658 png_debug1(1, "in %s storage function", ((png_ptr == NULL ||
659 png_ptr->chunk_name[0] == '\0') ?
The Android Open Source Project893912b2009-03-03 19:30:05 -0800660 "text" : (png_const_charp)png_ptr->chunk_name));
661
662 if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
663 return(0);
664
665 /* Make sure we have enough space in the "text" array in info_struct
666 * to hold all of the incoming text_ptr objects.
667 */
668 if (info_ptr->num_text + num_text > info_ptr->max_text)
669 {
Terry Heo (Woncheol)5e124012012-04-20 14:53:48 +0900670 int old_max_text = info_ptr->max_text;
671 int old_num_text = info_ptr->num_text;
672
The Android Open Source Project893912b2009-03-03 19:30:05 -0800673 if (info_ptr->text != NULL)
674 {
675 png_textp old_text;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800676
The Android Open Source Project893912b2009-03-03 19:30:05 -0800677 info_ptr->max_text = info_ptr->num_text + num_text + 8;
678 old_text = info_ptr->text;
Terry Heo (Woncheol)5e124012012-04-20 14:53:48 +0900679
The Android Open Source Project893912b2009-03-03 19:30:05 -0800680 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700681 (png_uint_32)(info_ptr->max_text * png_sizeof(png_text)));
The Android Open Source Project893912b2009-03-03 19:30:05 -0800682 if (info_ptr->text == NULL)
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400683 {
Terry Heo (Woncheol)5e124012012-04-20 14:53:48 +0900684 /* Restore to previous condition */
685 info_ptr->max_text = old_max_text;
686 info_ptr->text = old_text;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400687 return(1);
688 }
Terry Heo (Woncheol)5e124012012-04-20 14:53:48 +0900689 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max_text *
The Android Open Source Project893912b2009-03-03 19:30:05 -0800690 png_sizeof(png_text)));
691 png_free(png_ptr, old_text);
692 }
693 else
694 {
695 info_ptr->max_text = num_text + 8;
696 info_ptr->num_text = 0;
697 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700698 (png_uint_32)(info_ptr->max_text * png_sizeof(png_text)));
The Android Open Source Project893912b2009-03-03 19:30:05 -0800699 if (info_ptr->text == NULL)
Terry Heo (Woncheol)5e124012012-04-20 14:53:48 +0900700 {
701 /* Restore to previous condition */
702 info_ptr->num_text = old_num_text;
703 info_ptr->max_text = old_max_text;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400704 return(1);
Terry Heo (Woncheol)5e124012012-04-20 14:53:48 +0900705 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800706#ifdef PNG_FREE_ME_SUPPORTED
707 info_ptr->free_me |= PNG_FREE_TEXT;
708#endif
709 }
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700710 png_debug1(3, "allocated %d entries for info_ptr->text",
The Android Open Source Project893912b2009-03-03 19:30:05 -0800711 info_ptr->max_text);
712 }
Terry Heo (Woncheol)5e124012012-04-20 14:53:48 +0900713
The Android Open Source Project893912b2009-03-03 19:30:05 -0800714 for (i = 0; i < num_text; i++)
715 {
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700716 png_size_t text_length, key_len;
717 png_size_t lang_len, lang_key_len;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800718 png_textp textp = &(info_ptr->text[info_ptr->num_text]);
719
720 if (text_ptr[i].key == NULL)
721 continue;
722
723 key_len = png_strlen(text_ptr[i].key);
724
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700725 if (text_ptr[i].compression <= 0)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800726 {
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400727 lang_len = 0;
728 lang_key_len = 0;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800729 }
Patrick Scott5f6bd842010-06-28 16:55:16 -0400730
The Android Open Source Project893912b2009-03-03 19:30:05 -0800731 else
732#ifdef PNG_iTXt_SUPPORTED
733 {
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400734 /* Set iTXt data */
Patrick Scott5f6bd842010-06-28 16:55:16 -0400735
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400736 if (text_ptr[i].lang != NULL)
737 lang_len = png_strlen(text_ptr[i].lang);
738 else
739 lang_len = 0;
740 if (text_ptr[i].lang_key != NULL)
741 lang_key_len = png_strlen(text_ptr[i].lang_key);
742 else
743 lang_key_len = 0;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800744 }
Patrick Scott5f6bd842010-06-28 16:55:16 -0400745#else /* PNG_iTXt_SUPPORTED */
The Android Open Source Project893912b2009-03-03 19:30:05 -0800746 {
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400747 png_warning(png_ptr, "iTXt chunk not supported.");
748 continue;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800749 }
750#endif
751
752 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
753 {
754 text_length = 0;
755#ifdef PNG_iTXt_SUPPORTED
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700756 if (text_ptr[i].compression > 0)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800757 textp->compression = PNG_ITXT_COMPRESSION_NONE;
758 else
759#endif
760 textp->compression = PNG_TEXT_COMPRESSION_NONE;
761 }
Patrick Scott5f6bd842010-06-28 16:55:16 -0400762
The Android Open Source Project893912b2009-03-03 19:30:05 -0800763 else
764 {
765 text_length = png_strlen(text_ptr[i].text);
766 textp->compression = text_ptr[i].compression;
767 }
768
769 textp->key = (png_charp)png_malloc_warn(png_ptr,
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700770 (png_uint_32)
771 (key_len + text_length + lang_len + lang_key_len + 4));
The Android Open Source Project893912b2009-03-03 19:30:05 -0800772 if (textp->key == NULL)
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400773 return(1);
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700774 png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400775 (png_uint_32)
776 (key_len + lang_len + lang_key_len + text_length + 4),
777 (int)textp->key);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800778
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400779 png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700780 *(textp->key + key_len) = '\0';
The Android Open Source Project893912b2009-03-03 19:30:05 -0800781#ifdef PNG_iTXt_SUPPORTED
782 if (text_ptr[i].compression > 0)
783 {
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700784 textp->lang = textp->key + key_len + 1;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800785 png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700786 *(textp->lang + lang_len) = '\0';
787 textp->lang_key = textp->lang + lang_len + 1;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800788 png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700789 *(textp->lang_key + lang_key_len) = '\0';
790 textp->text = textp->lang_key + lang_key_len + 1;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800791 }
792 else
793#endif
794 {
795#ifdef PNG_iTXt_SUPPORTED
796 textp->lang=NULL;
797 textp->lang_key=NULL;
798#endif
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700799 textp->text = textp->key + key_len + 1;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800800 }
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700801 if (text_length)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800802 png_memcpy(textp->text, text_ptr[i].text,
803 (png_size_t)(text_length));
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700804 *(textp->text + text_length) = '\0';
The Android Open Source Project893912b2009-03-03 19:30:05 -0800805
806#ifdef PNG_iTXt_SUPPORTED
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700807 if (textp->compression > 0)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800808 {
809 textp->text_length = 0;
810 textp->itxt_length = text_length;
811 }
812 else
813#endif
Patrick Scott5f6bd842010-06-28 16:55:16 -0400814
The Android Open Source Project893912b2009-03-03 19:30:05 -0800815 {
816 textp->text_length = text_length;
817#ifdef PNG_iTXt_SUPPORTED
818 textp->itxt_length = 0;
819#endif
820 }
821 info_ptr->num_text++;
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700822 png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800823 }
824 return(0);
825}
826#endif
827
Patrick Scott5f6bd842010-06-28 16:55:16 -0400828#ifdef PNG_tIME_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800829void PNGAPI
830png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
831{
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700832 png_debug1(1, "in %s storage function", "tIME");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400833
The Android Open Source Project893912b2009-03-03 19:30:05 -0800834 if (png_ptr == NULL || info_ptr == NULL ||
835 (png_ptr->mode & PNG_WROTE_tIME))
836 return;
837
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700838 png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
The Android Open Source Project893912b2009-03-03 19:30:05 -0800839 info_ptr->valid |= PNG_INFO_tIME;
840}
841#endif
842
Patrick Scott5f6bd842010-06-28 16:55:16 -0400843#ifdef PNG_tRNS_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800844void PNGAPI
845png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
846 png_bytep trans, int num_trans, png_color_16p trans_values)
847{
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700848 png_debug1(1, "in %s storage function", "tRNS");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400849
The Android Open Source Project893912b2009-03-03 19:30:05 -0800850 if (png_ptr == NULL || info_ptr == NULL)
851 return;
852
The Android Open Source Project893912b2009-03-03 19:30:05 -0800853 if (trans != NULL)
854 {
Patrick Scott5f6bd842010-06-28 16:55:16 -0400855 /* It may not actually be necessary to set png_ptr->trans here;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800856 * we do it for backward compatibility with the way the png_handle_tRNS
857 * function used to do the allocation.
858 */
859
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700860#ifdef PNG_FREE_ME_SUPPORTED
861 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
862#endif
863
The Android Open Source Project893912b2009-03-03 19:30:05 -0800864 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
865 png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
866 (png_uint_32)PNG_MAX_PALETTE_LENGTH);
867 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400868 png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800869 }
870
871 if (trans_values != NULL)
872 {
873 int sample_max = (1 << info_ptr->bit_depth);
874 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
875 (int)trans_values->gray > sample_max) ||
876 (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
877 ((int)trans_values->red > sample_max ||
878 (int)trans_values->green > sample_max ||
879 (int)trans_values->blue > sample_max)))
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400880 png_warning(png_ptr,
881 "tRNS chunk has out-of-range samples for bit_depth");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800882 png_memcpy(&(info_ptr->trans_values), trans_values,
883 png_sizeof(png_color_16));
884 if (num_trans == 0)
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400885 num_trans = 1;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800886 }
887
888 info_ptr->num_trans = (png_uint_16)num_trans;
889 if (num_trans != 0)
890 {
891 info_ptr->valid |= PNG_INFO_tRNS;
892#ifdef PNG_FREE_ME_SUPPORTED
893 info_ptr->free_me |= PNG_FREE_TRNS;
894#else
895 png_ptr->flags |= PNG_FLAG_FREE_TRNS;
896#endif
897 }
898}
899#endif
900
Patrick Scott5f6bd842010-06-28 16:55:16 -0400901#ifdef PNG_sPLT_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800902void PNGAPI
903png_set_sPLT(png_structp png_ptr,
904 png_infop info_ptr, png_sPLT_tp entries, int nentries)
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700905/*
906 * entries - array of png_sPLT_t structures
907 * to be added to the list of palettes
908 * in the info structure.
909 * nentries - number of palette structures to be
910 * added.
911 */
The Android Open Source Project893912b2009-03-03 19:30:05 -0800912{
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400913 png_sPLT_tp np;
914 int i;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800915
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400916 if (png_ptr == NULL || info_ptr == NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800917 return;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800918
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400919 np = (png_sPLT_tp)png_malloc_warn(png_ptr,
920 (info_ptr->splt_palettes_num + nentries) *
921 (png_uint_32)png_sizeof(png_sPLT_t));
922 if (np == NULL)
923 {
924 png_warning(png_ptr, "No memory for sPLT palettes.");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400925 return;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400926 }
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700927
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400928 png_memcpy(np, info_ptr->splt_palettes,
Patrick Scott5f6bd842010-06-28 16:55:16 -0400929 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400930 png_free(png_ptr, info_ptr->splt_palettes);
931 info_ptr->splt_palettes=NULL;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800932
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400933 for (i = 0; i < nentries; i++)
934 {
935 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
936 png_sPLT_tp from = entries + i;
937 png_uint_32 length;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800938
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400939 length = png_strlen(from->name) + 1;
Patrick Scott5f6bd842010-06-28 16:55:16 -0400940 to->name = (png_charp)png_malloc_warn(png_ptr, length);
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400941 if (to->name == NULL)
942 {
943 png_warning(png_ptr,
944 "Out of memory while processing sPLT chunk");
945 continue;
946 }
947 png_memcpy(to->name, from->name, length);
948 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
Patrick Scott5f6bd842010-06-28 16:55:16 -0400949 (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry)));
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400950 if (to->entries == NULL)
951 {
952 png_warning(png_ptr,
953 "Out of memory while processing sPLT chunk");
954 png_free(png_ptr, to->name);
955 to->name = NULL;
956 continue;
957 }
958 png_memcpy(to->entries, from->entries,
959 from->nentries * png_sizeof(png_sPLT_entry));
960 to->nentries = from->nentries;
961 to->depth = from->depth;
962 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800963
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400964 info_ptr->splt_palettes = np;
965 info_ptr->splt_palettes_num += nentries;
966 info_ptr->valid |= PNG_INFO_sPLT;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800967#ifdef PNG_FREE_ME_SUPPORTED
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400968 info_ptr->free_me |= PNG_FREE_SPLT;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800969#endif
970}
971#endif /* PNG_sPLT_SUPPORTED */
972
Patrick Scott5f6bd842010-06-28 16:55:16 -0400973#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800974void PNGAPI
975png_set_unknown_chunks(png_structp png_ptr,
976 png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
977{
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400978 png_unknown_chunkp np;
979 int i;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800980
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400981 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
982 return;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800983
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400984 np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
985 (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) *
986 png_sizeof(png_unknown_chunk)));
987 if (np == NULL)
988 {
989 png_warning(png_ptr,
Patrick Scott5f6bd842010-06-28 16:55:16 -0400990 "Out of memory while processing unknown chunk.");
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400991 return;
992 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800993
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400994 png_memcpy(np, info_ptr->unknown_chunks,
Patrick Scott5f6bd842010-06-28 16:55:16 -0400995 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400996 png_free(png_ptr, info_ptr->unknown_chunks);
Patrick Scott5f6bd842010-06-28 16:55:16 -0400997 info_ptr->unknown_chunks = NULL;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800998
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400999 for (i = 0; i < num_unknowns; i++)
1000 {
1001 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
1002 png_unknown_chunkp from = unknowns + i;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001003
Patrick Scott5f6bd842010-06-28 16:55:16 -04001004 png_memcpy((png_charp)to->name, (png_charp)from->name,
1005 png_sizeof(from->name));
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001006 to->name[png_sizeof(to->name)-1] = '\0';
1007 to->size = from->size;
1008 /* Note our location in the read or write sequence */
1009 to->location = (png_byte)(png_ptr->mode & 0xff);
The Android Open Source Project893912b2009-03-03 19:30:05 -08001010
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001011 if (from->size == 0)
1012 to->data=NULL;
1013 else
1014 {
1015 to->data = (png_bytep)png_malloc_warn(png_ptr,
1016 (png_uint_32)from->size);
1017 if (to->data == NULL)
1018 {
1019 png_warning(png_ptr,
1020 "Out of memory while processing unknown chunk.");
1021 to->size = 0;
1022 }
1023 else
1024 png_memcpy(to->data, from->data, from->size);
1025 }
1026 }
The Android Open Source Project893912b2009-03-03 19:30:05 -08001027
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001028 info_ptr->unknown_chunks = np;
1029 info_ptr->unknown_chunks_num += num_unknowns;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001030#ifdef PNG_FREE_ME_SUPPORTED
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001031 info_ptr->free_me |= PNG_FREE_UNKN;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001032#endif
1033}
1034void PNGAPI
1035png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
1036 int chunk, int location)
1037{
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001038 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
Patrick Scott5f6bd842010-06-28 16:55:16 -04001039 (int)info_ptr->unknown_chunks_num)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001040 info_ptr->unknown_chunks[chunk].location = (png_byte)location;
1041}
1042#endif
1043
1044#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
1045#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
1046 defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
1047void PNGAPI
1048png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
1049{
1050 /* This function is deprecated in favor of png_permit_mng_features()
1051 and will be removed from libpng-1.3.0 */
Patrick Scott5f6bd842010-06-28 16:55:16 -04001052
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001053 png_debug(1, "in png_permit_empty_plte, DEPRECATED.");
Patrick Scott5f6bd842010-06-28 16:55:16 -04001054
The Android Open Source Project893912b2009-03-03 19:30:05 -08001055 if (png_ptr == NULL)
1056 return;
1057 png_ptr->mng_features_permitted = (png_byte)
1058 ((png_ptr->mng_features_permitted & (~PNG_FLAG_MNG_EMPTY_PLTE)) |
1059 ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
1060}
1061#endif
1062#endif
1063
Patrick Scott5f6bd842010-06-28 16:55:16 -04001064#ifdef PNG_MNG_FEATURES_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -08001065png_uint_32 PNGAPI
1066png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
1067{
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001068 png_debug(1, "in png_permit_mng_features");
Patrick Scott5f6bd842010-06-28 16:55:16 -04001069
The Android Open Source Project893912b2009-03-03 19:30:05 -08001070 if (png_ptr == NULL)
1071 return (png_uint_32)0;
1072 png_ptr->mng_features_permitted =
1073 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
1074 return (png_uint_32)png_ptr->mng_features_permitted;
1075}
1076#endif
1077
Patrick Scott5f6bd842010-06-28 16:55:16 -04001078#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -08001079void PNGAPI
1080png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
1081 chunk_list, int num_chunks)
1082{
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001083 png_bytep new_list, p;
1084 int i, old_num_chunks;
1085 if (png_ptr == NULL)
1086 return;
1087 if (num_chunks == 0)
1088 {
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001089 if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001090 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001091 else
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001092 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001093
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001094 if (keep == PNG_HANDLE_CHUNK_ALWAYS)
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001095 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001096 else
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001097 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001098 return;
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001099 }
1100 if (chunk_list == NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001101 return;
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001102 old_num_chunks = png_ptr->num_chunk_list;
1103 new_list=(png_bytep)png_malloc(png_ptr,
1104 (png_uint_32)
Patrick Scott5f6bd842010-06-28 16:55:16 -04001105 (5*(num_chunks + old_num_chunks)));
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001106 if (png_ptr->chunk_list != NULL)
1107 {
1108 png_memcpy(new_list, png_ptr->chunk_list,
Patrick Scott5f6bd842010-06-28 16:55:16 -04001109 (png_size_t)(5*old_num_chunks));
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001110 png_free(png_ptr, png_ptr->chunk_list);
1111 png_ptr->chunk_list=NULL;
1112 }
1113 png_memcpy(new_list + 5*old_num_chunks, chunk_list,
Patrick Scott5f6bd842010-06-28 16:55:16 -04001114 (png_size_t)(5*num_chunks));
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001115 for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
1116 *p=(png_byte)keep;
1117 png_ptr->num_chunk_list = old_num_chunks + num_chunks;
1118 png_ptr->chunk_list = new_list;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001119#ifdef PNG_FREE_ME_SUPPORTED
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001120 png_ptr->free_me |= PNG_FREE_LIST;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001121#endif
1122}
1123#endif
1124
Patrick Scott5f6bd842010-06-28 16:55:16 -04001125#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -08001126void PNGAPI
1127png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
1128 png_user_chunk_ptr read_user_chunk_fn)
1129{
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001130 png_debug(1, "in png_set_read_user_chunk_fn");
Patrick Scott5f6bd842010-06-28 16:55:16 -04001131
The Android Open Source Project893912b2009-03-03 19:30:05 -08001132 if (png_ptr == NULL)
1133 return;
Patrick Scott5f6bd842010-06-28 16:55:16 -04001134
The Android Open Source Project893912b2009-03-03 19:30:05 -08001135 png_ptr->read_user_chunk_fn = read_user_chunk_fn;
1136 png_ptr->user_chunk_ptr = user_chunk_ptr;
1137}
1138#endif
1139
Patrick Scott5f6bd842010-06-28 16:55:16 -04001140#ifdef PNG_INFO_IMAGE_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -08001141void PNGAPI
1142png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
1143{
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001144 png_debug1(1, "in %s storage function", "rows");
The Android Open Source Project893912b2009-03-03 19:30:05 -08001145
1146 if (png_ptr == NULL || info_ptr == NULL)
1147 return;
1148
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001149 if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
The Android Open Source Project893912b2009-03-03 19:30:05 -08001150 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
1151 info_ptr->row_pointers = row_pointers;
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001152 if (row_pointers)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001153 info_ptr->valid |= PNG_INFO_IDAT;
1154}
1155#endif
1156
The Android Open Source Project893912b2009-03-03 19:30:05 -08001157void PNGAPI
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001158png_set_compression_buffer_size(png_structp png_ptr,
1159 png_uint_32 size)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001160{
1161 if (png_ptr == NULL)
1162 return;
1163 png_free(png_ptr, png_ptr->zbuf);
1164 png_ptr->zbuf_size = (png_size_t)size;
1165 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
1166 png_ptr->zstream.next_out = png_ptr->zbuf;
1167 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1168}
The Android Open Source Project893912b2009-03-03 19:30:05 -08001169
1170void PNGAPI
1171png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
1172{
1173 if (png_ptr && info_ptr)
1174 info_ptr->valid &= ~mask;
1175}
1176
1177
1178#ifndef PNG_1_0_X
1179#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001180/* Function was added to libpng 1.2.0 and should always exist by default */
The Android Open Source Project893912b2009-03-03 19:30:05 -08001181void PNGAPI
1182png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
1183{
1184/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
1185 if (png_ptr != NULL)
1186 png_ptr->asm_flags = 0;
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001187 asm_flags = asm_flags; /* Quiet the compiler */
The Android Open Source Project893912b2009-03-03 19:30:05 -08001188}
1189
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001190/* This function was added to libpng 1.2.0 */
The Android Open Source Project893912b2009-03-03 19:30:05 -08001191void PNGAPI
1192png_set_mmx_thresholds (png_structp png_ptr,
1193 png_byte mmx_bitdepth_threshold,
1194 png_uint_32 mmx_rowbytes_threshold)
1195{
1196/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
1197 if (png_ptr == NULL)
1198 return;
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001199 /* Quiet the compiler */
1200 mmx_bitdepth_threshold = mmx_bitdepth_threshold;
1201 mmx_rowbytes_threshold = mmx_rowbytes_threshold;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001202}
1203#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
1204
1205#ifdef PNG_SET_USER_LIMITS_SUPPORTED
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001206/* This function was added to libpng 1.2.6 */
The Android Open Source Project893912b2009-03-03 19:30:05 -08001207void PNGAPI
1208png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
1209 png_uint_32 user_height_max)
1210{
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001211 /* Images with dimensions larger than these limits will be
1212 * rejected by png_set_IHDR(). To accept any PNG datastream
1213 * regardless of dimensions, set both limits to 0x7ffffffL.
1214 */
1215 if (png_ptr == NULL)
1216 return;
1217 png_ptr->user_width_max = user_width_max;
1218 png_ptr->user_height_max = user_height_max;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001219}
1220#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1221
Patrick Scott5f6bd842010-06-28 16:55:16 -04001222
1223#ifdef PNG_BENIGN_ERRORS_SUPPORTED
1224void PNGAPI
1225png_set_benign_errors(png_structp png_ptr, int allowed)
1226{
1227 png_debug(1, "in png_set_benign_errors");
1228
1229 if (allowed)
1230 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
1231 else
1232 png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
1233}
1234#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
The Android Open Source Project893912b2009-03-03 19:30:05 -08001235#endif /* ?PNG_1_0_X */
1236#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */