blob: 36efb5635a86ab132cadfbf3c768185e7f0b22e8 [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-Pehrson65a22372010-03-03 05:38:29 -06004 * Last changed in libpng 1.5.0 [March 3, 2010]
Glenn Randers-Pehrsone69b55d2010-01-01 10:29:06 -06005 * Copyright (c) 1998-2010 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-Pehrsonf9795312010-02-09 01:16:48 -060019#define PNG_EXPOSE_INTERNAL_STRUCTURES
Glenn Randers-Pehrson03f9b022009-12-04 08:40:41 -060020#define PNG_NO_PEDANTIC_WARNINGS
Andreas Dilger47a0c421997-05-16 02:46:07 -050021#include "png.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060022#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050023#include "pngpriv.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060024
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -050025#ifdef PNG_bKGD_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050026void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -050027png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
28{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -050029 png_debug1(1, "in %s storage function", "bKGD");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -050030
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060031 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050032 return;
33
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050034 png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
Andreas Dilger47a0c421997-05-16 02:46:07 -050035 info_ptr->valid |= PNG_INFO_bKGD;
36}
37#endif
38
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -050039#ifdef PNG_cHRM_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060040#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050041void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -050042png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -060043 double white_x, double white_y, double red_x, double red_y,
44 double green_x, double green_y, double blue_x, double blue_y)
Andreas Dilger47a0c421997-05-16 02:46:07 -050045{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -050046 png_debug1(1, "in %s storage function", "cHRM");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -050047
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060048 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050049 return;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060050
Andreas Dilger47a0c421997-05-16 02:46:07 -050051 info_ptr->x_white = (float)white_x;
52 info_ptr->y_white = (float)white_y;
53 info_ptr->x_red = (float)red_x;
54 info_ptr->y_red = (float)red_y;
55 info_ptr->x_green = (float)green_x;
56 info_ptr->y_green = (float)green_y;
57 info_ptr->x_blue = (float)blue_x;
58 info_ptr->y_blue = (float)blue_y;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060059#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -060060 info_ptr->int_x_white = (png_fixed_point)(white_x*100000. + 0.5);
61 info_ptr->int_y_white = (png_fixed_point)(white_y*100000. + 0.5);
62 info_ptr->int_x_red = (png_fixed_point)( red_x*100000. + 0.5);
63 info_ptr->int_y_red = (png_fixed_point)( red_y*100000. + 0.5);
64 info_ptr->int_x_green = (png_fixed_point)(green_x*100000. + 0.5);
65 info_ptr->int_y_green = (png_fixed_point)(green_y*100000. + 0.5);
66 info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000. + 0.5);
67 info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000. + 0.5);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060068#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -050069 info_ptr->valid |= PNG_INFO_cHRM;
70}
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -060071#endif /* PNG_FLOATING_POINT_SUPPORTED */
72
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060073#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050074void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060075png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -060076 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
77 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
78 png_fixed_point blue_x, png_fixed_point blue_y)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060079{
Glenn Randers-Pehrsond6d80752008-12-02 09:49:43 -060080 png_debug1(1, "in %s storage function", "cHRM fixed");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -050081
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060082 if (png_ptr == NULL || info_ptr == NULL)
83 return;
Andreas Dilger47a0c421997-05-16 02:46:07 -050084
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -050085#ifdef PNG_CHECK_cHRM_SUPPORTED
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -060086 if (png_check_cHRM_fixed(png_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -060087 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
Glenn Randers-Pehrson71a3c1f2008-11-26 12:00:38 -060088#endif
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050089 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050090 info_ptr->int_x_white = white_x;
91 info_ptr->int_y_white = white_y;
92 info_ptr->int_x_red = red_x;
93 info_ptr->int_y_red = red_y;
94 info_ptr->int_x_green = green_x;
95 info_ptr->int_y_green = green_y;
96 info_ptr->int_x_blue = blue_x;
97 info_ptr->int_y_blue = blue_y;
98#ifdef PNG_FLOATING_POINT_SUPPORTED
99 info_ptr->x_white = (float)(white_x/100000.);
100 info_ptr->y_white = (float)(white_y/100000.);
101 info_ptr->x_red = (float)( red_x/100000.);
102 info_ptr->y_red = (float)( red_y/100000.);
103 info_ptr->x_green = (float)(green_x/100000.);
104 info_ptr->y_green = (float)(green_y/100000.);
105 info_ptr->x_blue = (float)( blue_x/100000.);
106 info_ptr->y_blue = (float)( blue_y/100000.);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600107#endif
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500108 info_ptr->valid |= PNG_INFO_cHRM;
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -0600109 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600110}
Glenn Randers-Pehrsonf7831012008-11-13 06:05:13 -0600111#endif /* PNG_FIXED_POINT_SUPPORTED */
112#endif /* PNG_cHRM_SUPPORTED */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600113
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500114#ifdef PNG_gAMA_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600115#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500116void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500117png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
118{
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500119 double png_gamma;
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500120
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500121 png_debug1(1, "in %s storage function", "gAMA");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500122
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600123 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500124 return;
125
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600126 /* Check for overflow */
127 if (file_gamma > 21474.83)
128 {
129 png_warning(png_ptr, "Limiting gamma to 21474.83");
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600130 png_gamma = 21474.83;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600131 }
132 else
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500133 png_gamma = file_gamma;
134 info_ptr->gamma = (float)png_gamma;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600135#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson4db4aff2009-04-20 11:49:24 -0500136 info_ptr->int_gamma = (int)(png_gamma*100000.+.5);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600137#endif
138 info_ptr->valid |= PNG_INFO_gAMA;
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500139 if (png_gamma == 0.0)
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600140 png_warning(png_ptr, "Setting gamma = 0");
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600141}
142#endif
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500143void PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600144png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600145 int_gamma)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600146{
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500147 png_fixed_point png_gamma;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600148
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500149 png_debug1(1, "in %s storage function", "gAMA");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500150
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600151 if (png_ptr == NULL || info_ptr == NULL)
152 return;
153
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500154 if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX)
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600155 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500156 png_warning(png_ptr, "Limiting gamma to 21474.83");
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600157 png_gamma = PNG_UINT_31_MAX;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600158 }
159 else
160 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500161 if (int_gamma < 0)
162 {
163 png_warning(png_ptr, "Setting negative gamma to zero");
164 png_gamma = 0;
165 }
166 else
167 png_gamma = int_gamma;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600168 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600169#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson4db4aff2009-04-20 11:49:24 -0500170 info_ptr->gamma = (float)(png_gamma/100000.);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600171#endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500172#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500173 info_ptr->int_gamma = png_gamma;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500174#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500175 info_ptr->valid |= PNG_INFO_gAMA;
Glenn Randers-Pehrson8764c252009-04-19 07:52:22 -0500176 if (png_gamma == 0)
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600177 png_warning(png_ptr, "Setting gamma = 0");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500178}
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500179#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500180
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500181#ifdef PNG_hIST_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500182void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500183png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
184{
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500185 int i;
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600186
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500187 png_debug1(1, "in %s storage function", "hIST");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500188
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600189 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500190 return;
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500191
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500192 if (info_ptr->num_palette == 0 || info_ptr->num_palette
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600193 > PNG_MAX_PALETTE_LENGTH)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500194 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500195 png_warning(png_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600196 "Invalid palette size, hIST allocation skipped");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500197 return;
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500198 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500199
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600200 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500201 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
202 * version 1.2.1
203 */
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500204 png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600205 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500206 if (png_ptr->hist == NULL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500207 {
208 png_warning(png_ptr, "Insufficient memory for hIST chunk data");
209 return;
210 }
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600211
212 for (i = 0; i < info_ptr->num_palette; i++)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500213 png_ptr->hist[i] = hist[i];
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600214 info_ptr->hist = png_ptr->hist;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500215 info_ptr->valid |= PNG_INFO_hIST;
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600216
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600217 info_ptr->free_me |= PNG_FREE_HIST;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500218}
219#endif
220
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500221void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500222png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
223 png_uint_32 width, png_uint_32 height, int bit_depth,
224 int color_type, int interlace_type, int compression_type,
225 int filter_type)
226{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500227 png_debug1(1, "in %s storage function", "IHDR");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500228
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600229 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500230 return;
231
232 info_ptr->width = width;
233 info_ptr->height = height;
234 info_ptr->bit_depth = (png_byte)bit_depth;
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500235 info_ptr->color_type = (png_byte)color_type;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500236 info_ptr->compression_type = (png_byte)compression_type;
237 info_ptr->filter_type = (png_byte)filter_type;
238 info_ptr->interlace_type = (png_byte)interlace_type;
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500239
240 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
241 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
242 info_ptr->compression_type, info_ptr->filter_type);
243
Glenn Randers-Pehrson25d82242002-05-01 11:51:26 -0500244 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
245 info_ptr->channels = 1;
246 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500247 info_ptr->channels = 3;
248 else
249 info_ptr->channels = 1;
250 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
251 info_ptr->channels++;
252 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600253
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500254 /* Check for potential overflow */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500255 if (width > (PNG_UINT_32_MAX
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600256 >> 3) /* 8-byte RRGGBBAA pixels */
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500257 - 64 /* bigrowbuf hack */
258 - 1 /* filter byte */
259 - 7*8 /* rounding of width to multiple of 8 pixels */
260 - 8) /* extra max_pixel_depth pad */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500261 info_ptr->rowbytes = 0;
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500262 else
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500263 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500264}
265
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500266#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500267void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500268png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600269 png_int_32 offset_x, png_int_32 offset_y, int unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500270{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500271 png_debug1(1, "in %s storage function", "oFFs");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500272
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600273 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500274 return;
275
276 info_ptr->x_offset = offset_x;
277 info_ptr->y_offset = offset_y;
278 info_ptr->offset_unit_type = (png_byte)unit_type;
279 info_ptr->valid |= PNG_INFO_oFFs;
280}
281#endif
282
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500283#ifdef PNG_pCAL_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500284void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500285png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600286 png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
287 png_charp units, png_charpp params)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500288{
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500289 png_size_t length;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600290 int i;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500291
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500292 png_debug1(1, "in %s storage function", "pCAL");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500293
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600294 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500295 return;
296
297 length = png_strlen(purpose) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500298 png_debug1(3, "allocating purpose for info (%lu bytes)",
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600299 (unsigned long)length);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500300 info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
301 if (info_ptr->pcal_purpose == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500302 {
Glenn Randers-Pehrson83fb8552009-06-16 17:52:23 -0500303 png_warning(png_ptr, "Insufficient memory for pCAL purpose");
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500304 return;
305 }
306 png_memcpy(info_ptr->pcal_purpose, purpose, length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500307
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500308 png_debug(3, "storing X0, X1, type, and nparams in info");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500309 info_ptr->pcal_X0 = X0;
310 info_ptr->pcal_X1 = X1;
311 info_ptr->pcal_type = (png_byte)type;
312 info_ptr->pcal_nparams = (png_byte)nparams;
313
314 length = png_strlen(units) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500315 png_debug1(3, "allocating units for info (%lu bytes)",
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500316 (unsigned long)length);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500317 info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
318 if (info_ptr->pcal_units == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500319 {
Glenn Randers-Pehrson83fb8552009-06-16 17:52:23 -0500320 png_warning(png_ptr, "Insufficient memory for pCAL units");
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500321 return;
322 }
323 png_memcpy(info_ptr->pcal_units, units, length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500324
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500325 info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500326 (png_size_t)((nparams + 1) * png_sizeof(png_charp)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500327 if (info_ptr->pcal_params == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500328 {
Glenn Randers-Pehrson83fb8552009-06-16 17:52:23 -0500329 png_warning(png_ptr, "Insufficient memory for pCAL params");
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500330 return;
331 }
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500332
Glenn Randers-Pehrson0ffb71a2009-02-28 06:08:20 -0600333 png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500334
335 for (i = 0; i < nparams; i++)
336 {
337 length = png_strlen(params[i]) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500338 png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500339 (unsigned long)length);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500340 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
341 if (info_ptr->pcal_params[i] == NULL)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500342 {
Glenn Randers-Pehrson83fb8552009-06-16 17:52:23 -0500343 png_warning(png_ptr, "Insufficient memory for pCAL parameter");
344 return;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500345 }
346 png_memcpy(info_ptr->pcal_params[i], params[i], length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500347 }
348
349 info_ptr->valid |= PNG_INFO_pCAL;
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500350 info_ptr->free_me |= PNG_FREE_PCAL;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500351}
352#endif
353
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600354#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
355#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500356void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600357png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600358 int unit, double width, double height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600359{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500360 png_debug1(1, "in %s storage function", "sCAL");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500361
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600362 if (png_ptr == NULL || info_ptr == NULL)
363 return;
364
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600365 info_ptr->scal_unit = (png_byte)unit;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600366 info_ptr->scal_pixel_width = width;
367 info_ptr->scal_pixel_height = height;
368
369 info_ptr->valid |= PNG_INFO_sCAL;
370}
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600371#else
372#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500373void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600374png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600375 int unit, png_charp swidth, png_charp sheight)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600376{
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500377 png_size_t length;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600378
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500379 png_debug1(1, "in %s storage function", "sCAL");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500380
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600381 if (png_ptr == NULL || info_ptr == NULL)
382 return;
383
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600384 info_ptr->scal_unit = (png_byte)unit;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600385
386 length = png_strlen(swidth) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500387 png_debug1(3, "allocating unit for info (%u bytes)",
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600388 (unsigned int)length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500389 info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
390 if (info_ptr->scal_s_width == NULL)
391 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500392 png_warning(png_ptr,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600393 "Memory allocation failed while processing sCAL");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500394 return;
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500395 }
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500396 png_memcpy(info_ptr->scal_s_width, swidth, length);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600397
398 length = png_strlen(sheight) + 1;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500399 png_debug1(3, "allocating unit for info (%u bytes)",
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500400 (unsigned int)length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500401 info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
402 if (info_ptr->scal_s_height == NULL)
403 {
404 png_free (png_ptr, info_ptr->scal_s_width);
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500405 info_ptr->scal_s_width = NULL;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500406 png_warning(png_ptr,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600407 "Memory allocation failed while processing sCAL");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500408 return;
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500409 }
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500410 png_memcpy(info_ptr->scal_s_height, sheight, length);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600411 info_ptr->valid |= PNG_INFO_sCAL;
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500412 info_ptr->free_me |= PNG_FREE_SCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600413}
414#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600415#endif
416#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600417
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500418#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500419void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500420png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600421 png_uint_32 res_x, png_uint_32 res_y, int unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500422{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500423 png_debug1(1, "in %s storage function", "pHYs");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500424
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600425 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500426 return;
427
428 info_ptr->x_pixels_per_unit = res_x;
429 info_ptr->y_pixels_per_unit = res_y;
430 info_ptr->phys_unit_type = (png_byte)unit_type;
431 info_ptr->valid |= PNG_INFO_pHYs;
432}
433#endif
434
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500435void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500436png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600437 png_colorp palette, int num_palette)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500438{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600439
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500440 png_debug1(1, "in %s storage function", "PLTE");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500441
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600442 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500443 return;
444
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600445 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500446 {
447 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600448 png_error(png_ptr, "Invalid palette length");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500449 else
450 {
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600451 png_warning(png_ptr, "Invalid palette length");
452 return;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500453 }
454 }
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600455
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600456 /* It may not actually be necessary to set png_ptr->palette here;
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600457 * we do it for backward compatibility with the way the png_handle_tRNS
458 * function used to do the allocation.
459 */
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600460 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500461
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600462 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500463 * of num_palette entries, in case of an invalid PNG file that has
464 * too-large sample values.
465 */
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -0600466 png_ptr->palette = (png_colorp)png_calloc(png_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600467 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500468 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600469 info_ptr->palette = png_ptr->palette;
470 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600471
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600472 info_ptr->free_me |= PNG_FREE_PLTE;
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600473
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600474 info_ptr->valid |= PNG_INFO_PLTE;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500475}
476
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500477#ifdef PNG_sBIT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500478void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500479png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600480 png_color_8p sig_bit)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500481{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500482 png_debug1(1, "in %s storage function", "sBIT");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500483
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600484 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500485 return;
486
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500487 png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500488 info_ptr->valid |= PNG_INFO_sBIT;
489}
490#endif
491
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500492#ifdef PNG_sRGB_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500493void PNGAPI
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600494png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600495{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500496 png_debug1(1, "in %s storage function", "sRGB");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500497
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600498 if (png_ptr == NULL || info_ptr == NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600499 return;
500
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600501 info_ptr->srgb_intent = (png_byte)intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600502 info_ptr->valid |= PNG_INFO_sRGB;
503}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600504
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500505void PNGAPI
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600506png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600507 int intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600508{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500509#ifdef PNG_gAMA_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600510#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600511 float file_gamma;
512#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600513#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600514 png_fixed_point int_file_gamma;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600515#endif
516#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500517#ifdef PNG_cHRM_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600518#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600519 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
520#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600521 png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600522 int_green_y, int_blue_x, int_blue_y;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600523#endif
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500524 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500525
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600526 if (png_ptr == NULL || info_ptr == NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600527 return;
528
529 png_set_sRGB(png_ptr, info_ptr, intent);
530
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500531#ifdef PNG_gAMA_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600532#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrsonab1e5831999-10-06 04:57:42 -0500533 file_gamma = (float).45455;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600534 png_set_gAMA(png_ptr, info_ptr, file_gamma);
535#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600536#ifdef PNG_FIXED_POINT_SUPPORTED
537 int_file_gamma = 45455L;
538 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
539#endif
540#endif
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600541
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500542#ifdef PNG_cHRM_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600543 int_white_x = 31270L;
544 int_white_y = 32900L;
545 int_red_x = 64000L;
546 int_red_y = 33000L;
547 int_green_x = 30000L;
548 int_green_y = 60000L;
549 int_blue_x = 15000L;
550 int_blue_y = 6000L;
551
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600552#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600553 white_x = (float).3127;
554 white_y = (float).3290;
555 red_x = (float).64;
556 red_y = (float).33;
557 green_x = (float).30;
558 green_y = (float).60;
559 blue_x = (float).15;
560 blue_y = (float).06;
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600561#endif
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600562
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600563#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson85b02372009-09-24 19:49:13 -0500564 png_set_cHRM_fixed(png_ptr, info_ptr,
565 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
566 int_green_y, int_blue_x, int_blue_y);
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600567#endif
568#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson85b02372009-09-24 19:49:13 -0500569 png_set_cHRM(png_ptr, info_ptr,
570 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600571#endif
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600572#endif /* cHRM */
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600573}
Glenn Randers-Pehrson02a5e332008-11-24 22:10:23 -0600574#endif /* sRGB */
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600575
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600576
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500577#ifdef PNG_iCCP_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500578void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600579png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600580 png_charp name, int compression_type,
581 png_charp profile, png_uint_32 proflen)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600582{
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500583 png_charp new_iccp_name;
584 png_charp new_iccp_profile;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500585 png_uint_32 length;
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500586
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500587 png_debug1(1, "in %s storage function", "iCCP");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500588
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600589 if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
590 return;
591
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500592 length = png_strlen(name)+1;
593 new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500594 if (new_iccp_name == NULL)
595 {
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600596 png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500597 return;
598 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500599 png_memcpy(new_iccp_name, name, length);
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500600 new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
601 if (new_iccp_profile == NULL)
602 {
603 png_free (png_ptr, new_iccp_name);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500604 png_warning(png_ptr,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600605 "Insufficient memory to process iCCP profile");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500606 return;
607 }
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500608 png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
609
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500610 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500611
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600612 info_ptr->iccp_proflen = proflen;
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500613 info_ptr->iccp_name = new_iccp_name;
614 info_ptr->iccp_profile = new_iccp_profile;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600615 /* Compression is always zero but is here so the API and info structure
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600616 * does not have to change if we introduce multiple compression types
617 */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600618 info_ptr->iccp_compression = (png_byte)compression_type;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600619 info_ptr->free_me |= PNG_FREE_ICCP;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600620 info_ptr->valid |= PNG_INFO_iCCP;
621}
622#endif
623
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500624#ifdef PNG_TEXT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500625void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500626png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600627 int num_text)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500628{
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500629 int ret;
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500630 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500631 if (ret)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500632 png_error(png_ptr, "Insufficient memory to store text");
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500633}
634
635int /* PRIVATE */
636png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600637 int num_text)
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500638{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500639 int i;
640
Glenn Randers-Pehrsone2a118f2009-07-27 22:08:25 -0500641 png_debug1(1, "in %s storage function", ((png_ptr == NULL ||
642 png_ptr->chunk_name[0] == '\0') ?
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600643 "text" : (png_const_charp)png_ptr->chunk_name));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500644
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600645 if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500646 return(0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500647
648 /* Make sure we have enough space in the "text" array in info_struct
649 * to hold all of the incoming text_ptr objects.
650 */
651 if (info_ptr->num_text + num_text > info_ptr->max_text)
652 {
653 if (info_ptr->text != NULL)
654 {
655 png_textp old_text;
656 int old_max;
657
658 old_max = info_ptr->max_text;
659 info_ptr->max_text = info_ptr->num_text + num_text + 8;
660 old_text = info_ptr->text;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500661 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500662 (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500663 if (info_ptr->text == NULL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500664 {
665 png_free(png_ptr, old_text);
666 return(1);
667 }
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600668 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600669 png_sizeof(png_text)));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500670 png_free(png_ptr, old_text);
671 }
672 else
673 {
674 info_ptr->max_text = num_text + 8;
675 info_ptr->num_text = 0;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500676 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600677 (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500678 if (info_ptr->text == NULL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500679 return(1);
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500680 info_ptr->free_me |= PNG_FREE_TEXT;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500681 }
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500682 png_debug1(3, "allocated %d entries for info_ptr->text",
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600683 info_ptr->max_text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500684 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500685 for (i = 0; i < num_text; i++)
686 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500687 png_size_t text_length, key_len;
688 png_size_t lang_len, lang_key_len;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500689 png_textp textp = &(info_ptr->text[info_ptr->num_text]);
690
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500691 if (text_ptr[i].key == NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600692 continue;
693
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600694 key_len = png_strlen(text_ptr[i].key);
695
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500696 if (text_ptr[i].compression <= 0)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500697 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500698 lang_len = 0;
699 lang_key_len = 0;
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500700 }
Glenn Randers-Pehrsonef29a5e2009-10-31 19:37:05 -0500701
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500702 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500703#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600704 {
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500705 /* Set iTXt data */
Glenn Randers-Pehrsond6ea40a2009-11-02 07:32:00 -0600706
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500707 if (text_ptr[i].lang != NULL)
708 lang_len = png_strlen(text_ptr[i].lang);
709 else
710 lang_len = 0;
711 if (text_ptr[i].lang_key != NULL)
712 lang_key_len = png_strlen(text_ptr[i].lang_key);
713 else
714 lang_key_len = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600715 }
Glenn Randers-Pehrsond6ea40a2009-11-02 07:32:00 -0600716#else /* PNG_iTXt_SUPPORTED */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500717 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500718 png_warning(png_ptr, "iTXt chunk not supported");
719 continue;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500720 }
721#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500722
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500723 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
Andreas Dilger47a0c421997-05-16 02:46:07 -0500724 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600725 text_length = 0;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500726#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500727 if (text_ptr[i].compression > 0)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600728 textp->compression = PNG_ITXT_COMPRESSION_NONE;
729 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500730#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600731 textp->compression = PNG_TEXT_COMPRESSION_NONE;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500732 }
Glenn Randers-Pehrsonef29a5e2009-10-31 19:37:05 -0500733
Andreas Dilger47a0c421997-05-16 02:46:07 -0500734 else
735 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600736 text_length = png_strlen(text_ptr[i].text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500737 textp->compression = text_ptr[i].compression;
738 }
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500739
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500740 textp->key = (png_charp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600741 (png_size_t)
742 (key_len + text_length + lang_len + lang_key_len + 4));
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500743 if (textp->key == NULL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500744 return(1);
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500745 png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600746 (unsigned long)(png_uint_32)
747 (key_len + lang_len + lang_key_len + text_length + 4),
748 (int)textp->key);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500749
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500750 png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500751 *(textp->key + key_len) = '\0';
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500752#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600753 if (text_ptr[i].compression > 0)
754 {
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500755 textp->lang = textp->key + key_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600756 png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500757 *(textp->lang + lang_len) = '\0';
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500758 textp->lang_key = textp->lang + lang_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600759 png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500760 *(textp->lang_key + lang_key_len) = '\0';
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500761 textp->text = textp->lang_key + lang_key_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600762 }
763 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500764#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600765 {
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500766#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500767 textp->lang=NULL;
768 textp->lang_key=NULL;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500769#endif
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500770 textp->text = textp->key + key_len + 1;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600771 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500772 if (text_length)
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500773 png_memcpy(textp->text, text_ptr[i].text,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600774 (png_size_t)(text_length));
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500775 *(textp->text + text_length) = '\0';
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600776
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500777#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500778 if (textp->compression > 0)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600779 {
780 textp->text_length = 0;
781 textp->itxt_length = text_length;
782 }
783 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500784#endif
Glenn Randers-Pehrsonef29a5e2009-10-31 19:37:05 -0500785
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600786 {
787 textp->text_length = text_length;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500788#ifdef PNG_iTXt_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600789 textp->itxt_length = 0;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500790#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600791 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500792 info_ptr->num_text++;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500793 png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500794 }
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500795 return(0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500796}
797#endif
798
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500799#ifdef PNG_tIME_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500800void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500801png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
802{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500803 png_debug1(1, "in %s storage function", "tIME");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500804
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500805 if (png_ptr == NULL || info_ptr == NULL ||
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600806 (png_ptr->mode & PNG_WROTE_tIME))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500807 return;
808
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500809 png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500810 info_ptr->valid |= PNG_INFO_tIME;
811}
812#endif
813
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500814#ifdef PNG_tRNS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500815void PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500816png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600817 png_bytep trans_alpha, int num_trans, png_color_16p trans_color)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500818{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500819 png_debug1(1, "in %s storage function", "tRNS");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500820
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600821 if (png_ptr == NULL || info_ptr == NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500822 return;
823
Glenn Randers-Pehrson6abea752009-08-08 16:52:06 -0500824 if (trans_alpha != NULL)
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600825 {
Glenn Randers-Pehrsonef29a5e2009-10-31 19:37:05 -0500826 /* It may not actually be necessary to set png_ptr->trans_alpha here;
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500827 * we do it for backward compatibility with the way the png_handle_tRNS
828 * function used to do the allocation.
829 */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500830
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600831 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500832
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600833 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
Glenn Randers-Pehrson6abea752009-08-08 16:52:06 -0500834 png_ptr->trans_alpha = info_ptr->trans_alpha = (png_bytep)png_malloc(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500835 (png_size_t)PNG_MAX_PALETTE_LENGTH);
836 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
Glenn Randers-Pehrson6abea752009-08-08 16:52:06 -0500837 png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
Glenn Randers-Pehrson76e5fd62000-12-28 07:50:05 -0600838 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500839
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500840 if (trans_color != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500841 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500842 int sample_max = (1 << info_ptr->bit_depth);
843 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500844 (int)trans_color->gray > sample_max) ||
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500845 (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500846 ((int)trans_color->red > sample_max ||
847 (int)trans_color->green > sample_max ||
848 (int)trans_color->blue > sample_max)))
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500849 png_warning(png_ptr,
850 "tRNS chunk has out-of-range samples for bit_depth");
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500851 png_memcpy(&(info_ptr->trans_color), trans_color,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500852 png_sizeof(png_color_16));
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600853 if (num_trans == 0)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500854 num_trans = 1;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500855 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500856
Andreas Dilger47a0c421997-05-16 02:46:07 -0500857 info_ptr->num_trans = (png_uint_16)num_trans;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500858 if (num_trans != 0)
859 {
860 info_ptr->valid |= PNG_INFO_tRNS;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500861 info_ptr->free_me |= PNG_FREE_TRNS;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500862 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500863}
864#endif
865
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500866#ifdef PNG_sPLT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500867void PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600868png_set_sPLT(png_structp png_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600869 png_infop info_ptr, png_sPLT_tp entries, int nentries)
Glenn Randers-Pehrson3779c692006-11-07 20:38:11 -0600870/*
871 * entries - array of png_sPLT_t structures
872 * to be added to the list of palettes
873 * in the info structure.
874 * nentries - number of palette structures to be
875 * added.
876 */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600877{
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500878 png_sPLT_tp np;
879 int i;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600880
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500881 if (png_ptr == NULL || info_ptr == NULL)
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500882 return;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600883
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500884 np = (png_sPLT_tp)png_malloc_warn(png_ptr,
885 (info_ptr->splt_palettes_num + nentries) *
886 (png_size_t)png_sizeof(png_sPLT_t));
887 if (np == NULL)
888 {
889 png_warning(png_ptr, "No memory for sPLT palettes");
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600890 return;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500891 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600892
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500893 png_memcpy(np, info_ptr->splt_palettes,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600894 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500895 png_free(png_ptr, info_ptr->splt_palettes);
896 info_ptr->splt_palettes=NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600897
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500898 for (i = 0; i < nentries; i++)
899 {
900 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
901 png_sPLT_tp from = entries + i;
902 png_uint_32 length;
903
904 length = png_strlen(from->name) + 1;
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600905 to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500906 if (to->name == NULL)
907 {
908 png_warning(png_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600909 "Out of memory while processing sPLT chunk");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500910 continue;
911 }
912 png_memcpy(to->name, from->name, length);
913 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600914 (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry)));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500915 if (to->entries == NULL)
916 {
917 png_warning(png_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600918 "Out of memory while processing sPLT chunk");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500919 png_free(png_ptr, to->name);
920 to->name = NULL;
921 continue;
922 }
923 png_memcpy(to->entries, from->entries,
924 from->nentries * png_sizeof(png_sPLT_entry));
925 to->nentries = from->nentries;
926 to->depth = from->depth;
927 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600928
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500929 info_ptr->splt_palettes = np;
930 info_ptr->splt_palettes_num += nentries;
931 info_ptr->valid |= PNG_INFO_sPLT;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500932 info_ptr->free_me |= PNG_FREE_SPLT;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600933}
934#endif /* PNG_sPLT_SUPPORTED */
935
Glenn Randers-Pehrson6ba90882009-12-25 14:26:13 -0600936#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500937void PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600938png_set_unknown_chunks(png_structp png_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600939 png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600940{
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500941 png_unknown_chunkp np;
942 int i;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600943
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500944 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
Glenn Randers-Pehrson83fb8552009-06-16 17:52:23 -0500945 return;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600946
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500947 np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
948 (png_size_t)((info_ptr->unknown_chunks_num + num_unknowns) *
949 png_sizeof(png_unknown_chunk)));
950 if (np == NULL)
951 {
952 png_warning(png_ptr,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600953 "Out of memory while processing unknown chunk");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500954 return;
955 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600956
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500957 png_memcpy(np, info_ptr->unknown_chunks,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600958 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500959 png_free(png_ptr, info_ptr->unknown_chunks);
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600960 info_ptr->unknown_chunks = NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600961
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500962 for (i = 0; i < num_unknowns; i++)
963 {
964 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
965 png_unknown_chunkp from = unknowns + i;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600966
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -0600967 png_memcpy((png_charp)to->name, (png_charp)from->name,
968 png_sizeof(from->name));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500969 to->name[png_sizeof(to->name)-1] = '\0';
970 to->size = from->size;
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500971 /* Note our location in the read or write sequence */
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500972 to->location = (png_byte)(png_ptr->mode & 0xff);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600973
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500974 if (from->size == 0)
975 to->data=NULL;
976 else
977 {
978 to->data = (png_bytep)png_malloc_warn(png_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600979 (png_size_t)from->size);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500980 if (to->data == NULL)
981 {
982 png_warning(png_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600983 "Out of memory while processing unknown chunk");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500984 to->size = 0;
985 }
986 else
987 png_memcpy(to->data, from->data, from->size);
988 }
989 }
990
991 info_ptr->unknown_chunks = np;
992 info_ptr->unknown_chunks_num += num_unknowns;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500993 info_ptr->free_me |= PNG_FREE_UNKN;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600994}
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500995void PNGAPI
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500996png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -0600997 int chunk, int location)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500998{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500999 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -06001000 (int)info_ptr->unknown_chunks_num)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001001 info_ptr->unknown_chunks[chunk].location = (png_byte)location;
1002}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001003#endif
1004
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001005
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001006#ifdef PNG_MNG_FEATURES_SUPPORTED
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06001007png_uint_32 PNGAPI
1008png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
1009{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001010 png_debug(1, "in png_permit_mng_features");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -05001011
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06001012 if (png_ptr == NULL)
1013 return (png_uint_32)0;
1014 png_ptr->mng_features_permitted =
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -06001015 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06001016 return (png_uint_32)png_ptr->mng_features_permitted;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001017}
1018#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001019
Glenn Randers-Pehrson6ba90882009-12-25 14:26:13 -06001020#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001021void PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001022png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -06001023 chunk_list, int num_chunks)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001024{
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001025 png_bytep new_list, p;
1026 int i, old_num_chunks;
1027 if (png_ptr == NULL)
1028 return;
1029 if (num_chunks == 0)
1030 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001031 if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001032 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001033 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001034 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001035
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001036 if (keep == PNG_HANDLE_CHUNK_ALWAYS)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001037 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001038 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001039 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001040 return;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001041 }
1042 if (chunk_list == NULL)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001043 return;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001044 old_num_chunks = png_ptr->num_chunk_list;
1045 new_list=(png_bytep)png_malloc(png_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -06001046 (png_size_t)
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -06001047 (5*(num_chunks + old_num_chunks)));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001048 if (png_ptr->chunk_list != NULL)
1049 {
1050 png_memcpy(new_list, png_ptr->chunk_list,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -06001051 (png_size_t)(5*old_num_chunks));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001052 png_free(png_ptr, png_ptr->chunk_list);
1053 png_ptr->chunk_list=NULL;
1054 }
1055 png_memcpy(new_list + 5*old_num_chunks, chunk_list,
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -06001056 (png_size_t)(5*num_chunks));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001057 for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
1058 *p=(png_byte)keep;
1059 png_ptr->num_chunk_list = old_num_chunks + num_chunks;
1060 png_ptr->chunk_list = new_list;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001061 png_ptr->free_me |= PNG_FREE_LIST;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001062}
1063#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001064
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001065#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001066void PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001067png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
Glenn Randers-Pehrsonda301352010-03-06 06:42:48 -06001068 png_user_chunk_ptr read_user_chunk_fn)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001069{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001070 png_debug(1, "in png_set_read_user_chunk_fn");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -05001071
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -06001072 if (png_ptr == NULL)
1073 return;
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -05001074
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001075 png_ptr->read_user_chunk_fn = read_user_chunk_fn;
1076 png_ptr->user_chunk_ptr = user_chunk_ptr;
1077}
1078#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001079
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001080#ifdef PNG_INFO_IMAGE_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001081void PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001082png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
1083{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001084 png_debug1(1, "in %s storage function", "rows");
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001085
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001086 if (png_ptr == NULL || info_ptr == NULL)
1087 return;
1088
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001089 if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001090 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001091 info_ptr->row_pointers = row_pointers;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001092 if (row_pointers)
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001093 info_ptr->valid |= PNG_INFO_IDAT;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001094}
1095#endif
1096
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-Pehrsonfc4a1432000-05-17 17:39:34 -05001109
1110void PNGAPI
1111png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
1112{
1113 if (png_ptr && info_ptr)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001114 info_ptr->valid &= ~mask;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05001115}
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06001116
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05001117
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001118
1119#ifdef PNG_SET_USER_LIMITS_SUPPORTED
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -05001120/* This function was added to libpng 1.2.6 */
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001121void PNGAPI
1122png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
1123 png_uint_32 user_height_max)
1124{
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001125 /* Images with dimensions larger than these limits will be
1126 * rejected by png_set_IHDR(). To accept any PNG datastream
1127 * regardless of dimensions, set both limits to 0x7ffffffL.
1128 */
1129 if (png_ptr == NULL)
1130 return;
1131 png_ptr->user_width_max = user_width_max;
1132 png_ptr->user_height_max = user_height_max;
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001133}
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001134
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-Pehrsone3f3c4e2010-02-07 18:08:50 -06001140 if (png_ptr)
1141 png_ptr->user_chunk_cache_max = user_chunk_cache_max;
1142}
1143
1144/* This function was added to libpng 1.4.1 */
1145void PNGAPI
1146png_set_chunk_malloc_max (png_structp png_ptr,
1147 png_alloc_size_t user_chunk_malloc_max)
1148{
1149 if (png_ptr)
1150 png_ptr->user_chunk_malloc_max =
1151 (png_size_t)user_chunk_malloc_max;
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001152}
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001153#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1154
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001155
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001156#ifdef PNG_BENIGN_ERRORS_SUPPORTED
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001157void PNGAPI
1158png_set_benign_errors(png_structp png_ptr, int allowed)
1159{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001160 png_debug(1, "in png_set_benign_errors");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -05001161
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001162 if (allowed)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001163 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001164 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001165 png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05001166}
1167#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001168#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */