Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: third_party/libpng/pngset.c

Issue 140074: Updates the PNG library to 1.2.37, enables some functionality for O3D (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/libpng/pngrutil.c ('k') | third_party/libpng/pngtrans.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* pngset.c - storage of image information into info struct 2 /* pngset.c - storage of image information into info struct
3 * 3 *
4 * Last changed in libpng 1.2.36 [May 7, 2009] 4 * Last changed in libpng 1.2.37 [June 4, 2009]
5 * For conditions of distribution and use, see copyright notice in png.h 5 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson 6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9 * 9 *
10 * The functions here are used during reads to store data from the file 10 * The functions here are used during reads to store data from the file
11 * into the info struct, and during writes to store application data 11 * into the info struct, and during writes to store application data
12 * into the info struct for writing into the file. This abstracts the 12 * into the info struct for writing into the file. This abstracts the
13 * info struct and allows us to change the structure in the future. 13 * info struct and allows us to change the structure in the future.
14 */ 14 */
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 { 72 {
73 png_debug1(1, "in %s storage function", "cHRM fixed"); 73 png_debug1(1, "in %s storage function", "cHRM fixed");
74 if (png_ptr == NULL || info_ptr == NULL) 74 if (png_ptr == NULL || info_ptr == NULL)
75 return; 75 return;
76 76
77 #if !defined(PNG_NO_CHECK_cHRM) 77 #if !defined(PNG_NO_CHECK_cHRM)
78 if (png_check_cHRM_fixed(png_ptr, 78 if (png_check_cHRM_fixed(png_ptr,
79 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y)) 79 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
80 #endif 80 #endif
81 { 81 {
82 info_ptr->int_x_white = white_x; 82 info_ptr->int_x_white = white_x;
83 info_ptr->int_y_white = white_y; 83 info_ptr->int_y_white = white_y;
84 info_ptr->int_x_red = red_x; 84 info_ptr->int_x_red = red_x;
85 info_ptr->int_y_red = red_y; 85 info_ptr->int_y_red = red_y;
86 info_ptr->int_x_green = green_x; 86 info_ptr->int_x_green = green_x;
87 info_ptr->int_y_green = green_y; 87 info_ptr->int_y_green = green_y;
88 info_ptr->int_x_blue = blue_x; 88 info_ptr->int_x_blue = blue_x;
89 info_ptr->int_y_blue = blue_y; 89 info_ptr->int_y_blue = blue_y;
90 #ifdef PNG_FLOATING_POINT_SUPPORTED 90 #ifdef PNG_FLOATING_POINT_SUPPORTED
91 info_ptr->x_white = (float)(white_x/100000.); 91 info_ptr->x_white = (float)(white_x/100000.);
92 info_ptr->y_white = (float)(white_y/100000.); 92 info_ptr->y_white = (float)(white_y/100000.);
93 info_ptr->x_red = (float)( red_x/100000.); 93 info_ptr->x_red = (float)( red_x/100000.);
94 info_ptr->y_red = (float)( red_y/100000.); 94 info_ptr->y_red = (float)( red_y/100000.);
95 info_ptr->x_green = (float)(green_x/100000.); 95 info_ptr->x_green = (float)(green_x/100000.);
96 info_ptr->y_green = (float)(green_y/100000.); 96 info_ptr->y_green = (float)(green_y/100000.);
97 info_ptr->x_blue = (float)( blue_x/100000.); 97 info_ptr->x_blue = (float)( blue_x/100000.);
98 info_ptr->y_blue = (float)( blue_y/100000.); 98 info_ptr->y_blue = (float)( blue_y/100000.);
99 #endif 99 #endif
100 info_ptr->valid |= PNG_INFO_cHRM; 100 info_ptr->valid |= PNG_INFO_cHRM;
101 } 101 }
102 } 102 }
103 #endif /* PNG_FIXED_POINT_SUPPORTED */ 103 #endif /* PNG_FIXED_POINT_SUPPORTED */
104 #endif /* PNG_cHRM_SUPPORTED */ 104 #endif /* PNG_cHRM_SUPPORTED */
105 105
106 #if defined(PNG_gAMA_SUPPORTED) 106 #if defined(PNG_gAMA_SUPPORTED)
107 #ifdef PNG_FLOATING_POINT_SUPPORTED 107 #ifdef PNG_FLOATING_POINT_SUPPORTED
108 void PNGAPI 108 void PNGAPI
109 png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) 109 png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
110 { 110 {
(...skipping 22 matching lines...) Expand all
133 void PNGAPI 133 void PNGAPI
134 png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point 134 png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
135 int_gamma) 135 int_gamma)
136 { 136 {
137 png_fixed_point png_gamma; 137 png_fixed_point png_gamma;
138 138
139 png_debug1(1, "in %s storage function", "gAMA"); 139 png_debug1(1, "in %s storage function", "gAMA");
140 if (png_ptr == NULL || info_ptr == NULL) 140 if (png_ptr == NULL || info_ptr == NULL)
141 return; 141 return;
142 142
143 if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX) 143 if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX)
144 { 144 {
145 png_warning(png_ptr, "Limiting gamma to 21474.83"); 145 png_warning(png_ptr, "Limiting gamma to 21474.83");
146 png_gamma=PNG_UINT_31_MAX; 146 png_gamma=PNG_UINT_31_MAX;
147 } 147 }
148 else 148 else
149 { 149 {
150 if (int_gamma < 0) 150 if (int_gamma < 0)
151 { 151 {
152 png_warning(png_ptr, "Setting negative gamma to zero"); 152 png_warning(png_ptr, "Setting negative gamma to zero");
153 png_gamma = 0; 153 png_gamma = 0;
154 } 154 }
155 else 155 else
156 png_gamma = int_gamma; 156 png_gamma = int_gamma;
157 } 157 }
158 #ifdef PNG_FLOATING_POINT_SUPPORTED 158 #ifdef PNG_FLOATING_POINT_SUPPORTED
159 info_ptr->gamma = (float)(png_gamma/100000.); 159 info_ptr->gamma = (float)(png_gamma/100000.);
160 #endif 160 #endif
161 #ifdef PNG_FIXED_POINT_SUPPORTED 161 #ifdef PNG_FIXED_POINT_SUPPORTED
162 info_ptr->int_gamma = png_gamma; 162 info_ptr->int_gamma = png_gamma;
163 #endif 163 #endif
164 info_ptr->valid |= PNG_INFO_gAMA; 164 info_ptr->valid |= PNG_INFO_gAMA;
165 if (png_gamma == 0) 165 if (png_gamma == 0)
166 png_warning(png_ptr, "Setting gamma=0"); 166 png_warning(png_ptr, "Setting gamma=0");
167 } 167 }
168 #endif 168 #endif
169 169
170 #if defined(PNG_hIST_SUPPORTED) 170 #if defined(PNG_hIST_SUPPORTED)
171 void PNGAPI 171 void PNGAPI
172 png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) 172 png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
173 { 173 {
174 int i; 174 int i;
175 175
176 png_debug1(1, "in %s storage function", "hIST"); 176 png_debug1(1, "in %s storage function", "hIST");
177 if (png_ptr == NULL || info_ptr == NULL) 177 if (png_ptr == NULL || info_ptr == NULL)
178 return; 178 return;
179 if (info_ptr->num_palette == 0 || info_ptr->num_palette 179 if (info_ptr->num_palette == 0 || info_ptr->num_palette
180 > PNG_MAX_PALETTE_LENGTH) 180 > PNG_MAX_PALETTE_LENGTH)
181 { 181 {
182 png_warning(png_ptr, 182 png_warning(png_ptr,
183 "Invalid palette size, hIST allocation skipped."); 183 "Invalid palette size, hIST allocation skipped.");
184 return; 184 return;
185 } 185 }
186 186
187 #ifdef PNG_FREE_ME_SUPPORTED 187 #ifdef PNG_FREE_ME_SUPPORTED
188 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); 188 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
189 #endif 189 #endif
190 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in version 190 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
191 1.2.1 */ 191 * version 1.2.1
192 */
192 png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr, 193 png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
193 (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16))); 194 (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16)));
194 if (png_ptr->hist == NULL) 195 if (png_ptr->hist == NULL)
195 { 196 {
196 png_warning(png_ptr, "Insufficient memory for hIST chunk data."); 197 png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
197 return; 198 return;
198 } 199 }
199 200
200 for (i = 0; i < info_ptr->num_palette; i++) 201 for (i = 0; i < info_ptr->num_palette; i++)
201 png_ptr->hist[i] = hist[i]; 202 png_ptr->hist[i] = hist[i];
202 info_ptr->hist = png_ptr->hist; 203 info_ptr->hist = png_ptr->hist;
203 info_ptr->valid |= PNG_INFO_hIST; 204 info_ptr->valid |= PNG_INFO_hIST;
204 205
205 #ifdef PNG_FREE_ME_SUPPORTED 206 #ifdef PNG_FREE_ME_SUPPORTED
206 info_ptr->free_me |= PNG_FREE_HIST; 207 info_ptr->free_me |= PNG_FREE_HIST;
207 #else 208 #else
208 png_ptr->flags |= PNG_FLAG_FREE_HIST; 209 png_ptr->flags |= PNG_FLAG_FREE_HIST;
209 #endif 210 #endif
210 } 211 }
211 #endif 212 #endif
212 213
213 void PNGAPI 214 void PNGAPI
214 png_set_IHDR(png_structp png_ptr, png_infop info_ptr, 215 png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
215 png_uint_32 width, png_uint_32 height, int bit_depth, 216 png_uint_32 width, png_uint_32 height, int bit_depth,
216 int color_type, int interlace_type, int compression_type, 217 int color_type, int interlace_type, int compression_type,
217 int filter_type) 218 int filter_type)
218 { 219 {
219 png_debug1(1, "in %s storage function", "IHDR"); 220 png_debug1(1, "in %s storage function", "IHDR");
220 if (png_ptr == NULL || info_ptr == NULL) 221 if (png_ptr == NULL || info_ptr == NULL)
221 return; 222 return;
222 223
223 /* check for width and height valid values */ 224 /* Check for width and height valid values */
224 if (width == 0 || height == 0) 225 if (width == 0 || height == 0)
225 png_error(png_ptr, "Image width or height is zero in IHDR"); 226 png_error(png_ptr, "Image width or height is zero in IHDR");
226 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 227 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
227 if (width > png_ptr->user_width_max || height > png_ptr->user_height_max) 228 if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
228 png_error(png_ptr, "image size exceeds user limits in IHDR"); 229 png_error(png_ptr, "image size exceeds user limits in IHDR");
229 #else 230 #else
230 if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX) 231 if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
231 png_error(png_ptr, "image size exceeds user limits in IHDR"); 232 png_error(png_ptr, "image size exceeds user limits in IHDR");
232 #endif 233 #endif
233 if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX) 234 if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
234 png_error(png_ptr, "Invalid image size in IHDR"); 235 png_error(png_ptr, "Invalid image size in IHDR");
235 if ( width > (PNG_UINT_32_MAX 236 if ( width > (PNG_UINT_32_MAX
236 >> 3) /* 8-byte RGBA pixels */ 237 >> 3) /* 8-byte RGBA pixels */
237 - 64 /* bigrowbuf hack */ 238 - 64 /* bigrowbuf hack */
238 - 1 /* filter byte */ 239 - 1 /* filter byte */
239 - 7*8 /* rounding of width to multiple of 8 pixels */ 240 - 7*8 /* rounding of width to multiple of 8 pixels */
240 - 8) /* extra max_pixel_depth pad */ 241 - 8) /* extra max_pixel_depth pad */
241 png_warning(png_ptr, "Width is too large for libpng to process pixels"); 242 png_warning(png_ptr, "Width is too large for libpng to process pixels");
242 243
243 /* check other values */ 244 /* Check other values */
244 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && 245 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
245 bit_depth != 8 && bit_depth != 16) 246 bit_depth != 8 && bit_depth != 16)
246 png_error(png_ptr, "Invalid bit depth in IHDR"); 247 png_error(png_ptr, "Invalid bit depth in IHDR");
247 248
248 if (color_type < 0 || color_type == 1 || 249 if (color_type < 0 || color_type == 1 ||
249 color_type == 5 || color_type > 6) 250 color_type == 5 || color_type > 6)
250 png_error(png_ptr, "Invalid color type in IHDR"); 251 png_error(png_ptr, "Invalid color type in IHDR");
251 252
252 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || 253 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
253 ((color_type == PNG_COLOR_TYPE_RGB || 254 ((color_type == PNG_COLOR_TYPE_RGB ||
254 color_type == PNG_COLOR_TYPE_GRAY_ALPHA || 255 color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
255 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) 256 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
256 png_error(png_ptr, "Invalid color type/bit depth combination in IHDR"); 257 png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
257 258
258 if (interlace_type >= PNG_INTERLACE_LAST) 259 if (interlace_type >= PNG_INTERLACE_LAST)
259 png_error(png_ptr, "Unknown interlace method in IHDR"); 260 png_error(png_ptr, "Unknown interlace method in IHDR");
260 261
261 if (compression_type != PNG_COMPRESSION_TYPE_BASE) 262 if (compression_type != PNG_COMPRESSION_TYPE_BASE)
262 png_error(png_ptr, "Unknown compression method in IHDR"); 263 png_error(png_ptr, "Unknown compression method in IHDR");
263 264
264 #if defined(PNG_MNG_FEATURES_SUPPORTED) 265 #if defined(PNG_MNG_FEATURES_SUPPORTED)
265 /* Accept filter_method 64 (intrapixel differencing) only if 266 /* Accept filter_method 64 (intrapixel differencing) only if
266 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and 267 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
267 * 2. Libpng did not read a PNG signature (this filter_method is only 268 * 2. Libpng did not read a PNG signature (this filter_method is only
268 * used in PNG datastreams that are embedded in MNG datastreams) and 269 * used in PNG datastreams that are embedded in MNG datastreams) and
269 * 3. The application called png_permit_mng_features with a mask that 270 * 3. The application called png_permit_mng_features with a mask that
270 * included PNG_FLAG_MNG_FILTER_64 and 271 * included PNG_FLAG_MNG_FILTER_64 and
271 * 4. The filter_method is 64 and 272 * 4. The filter_method is 64 and
272 * 5. The color_type is RGB or RGBA 273 * 5. The color_type is RGB or RGBA
273 */ 274 */
274 if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted) 275 if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
275 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); 276 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
276 if (filter_type != PNG_FILTER_TYPE_BASE) 277 if (filter_type != PNG_FILTER_TYPE_BASE)
277 { 278 {
278 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 279 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
279 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && 280 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
280 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && 281 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
281 (color_type == PNG_COLOR_TYPE_RGB || 282 (color_type == PNG_COLOR_TYPE_RGB ||
282 color_type == PNG_COLOR_TYPE_RGB_ALPHA))) 283 color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
283 png_error(png_ptr, "Unknown filter method in IHDR"); 284 png_error(png_ptr, "Unknown filter method in IHDR");
284 if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) 285 if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
285 png_warning(png_ptr, "Invalid filter method in IHDR"); 286 png_warning(png_ptr, "Invalid filter method in IHDR");
286 } 287 }
287 #else 288 #else
288 if (filter_type != PNG_FILTER_TYPE_BASE) 289 if (filter_type != PNG_FILTER_TYPE_BASE)
289 png_error(png_ptr, "Unknown filter method in IHDR"); 290 png_error(png_ptr, "Unknown filter method in IHDR");
290 #endif 291 #endif
291 292
292 info_ptr->width = width; 293 info_ptr->width = width;
293 info_ptr->height = height; 294 info_ptr->height = height;
294 info_ptr->bit_depth = (png_byte)bit_depth; 295 info_ptr->bit_depth = (png_byte)bit_depth;
295 info_ptr->color_type =(png_byte) color_type; 296 info_ptr->color_type =(png_byte) color_type;
296 info_ptr->compression_type = (png_byte)compression_type; 297 info_ptr->compression_type = (png_byte)compression_type;
297 info_ptr->filter_type = (png_byte)filter_type; 298 info_ptr->filter_type = (png_byte)filter_type;
298 info_ptr->interlace_type = (png_byte)interlace_type; 299 info_ptr->interlace_type = (png_byte)interlace_type;
299 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 300 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
300 info_ptr->channels = 1; 301 info_ptr->channels = 1;
301 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) 302 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
302 info_ptr->channels = 3; 303 info_ptr->channels = 3;
303 else 304 else
304 info_ptr->channels = 1; 305 info_ptr->channels = 1;
305 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) 306 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
306 info_ptr->channels++; 307 info_ptr->channels++;
307 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); 308 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
308 309
309 /* check for potential overflow */ 310 /* Check for potential overflow */
310 if (width > (PNG_UINT_32_MAX 311 if (width > (PNG_UINT_32_MAX
311 >> 3) /* 8-byte RGBA pixels */ 312 >> 3) /* 8-byte RGBA pixels */
312 - 64 /* bigrowbuf hack */ 313 - 64 /* bigrowbuf hack */
313 - 1 /* filter byte */ 314 - 1 /* filter byte */
314 - 7*8 /* rounding of width to multiple of 8 pixels */ 315 - 7*8 /* rounding of width to multiple of 8 pixels */
315 - 8) /* extra max_pixel_depth pad */ 316 - 8) /* extra max_pixel_depth pad */
316 info_ptr->rowbytes = (png_size_t)0; 317 info_ptr->rowbytes = (png_size_t)0;
317 else 318 else
318 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); 319 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
319 } 320 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 void PNGAPI 490 void PNGAPI
490 png_set_PLTE(png_structp png_ptr, png_infop info_ptr, 491 png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
491 png_colorp palette, int num_palette) 492 png_colorp palette, int num_palette)
492 { 493 {
493 494
494 png_debug1(1, "in %s storage function", "PLTE"); 495 png_debug1(1, "in %s storage function", "PLTE");
495 if (png_ptr == NULL || info_ptr == NULL) 496 if (png_ptr == NULL || info_ptr == NULL)
496 return; 497 return;
497 498
498 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH) 499 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
499 { 500 {
500 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 501 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
501 png_error(png_ptr, "Invalid palette length"); 502 png_error(png_ptr, "Invalid palette length");
502 else 503 else
503 { 504 {
504 png_warning(png_ptr, "Invalid palette length"); 505 png_warning(png_ptr, "Invalid palette length");
505 return; 506 return;
506 } 507 }
507 } 508 }
508 509
509 /* 510 /*
510 * It may not actually be necessary to set png_ptr->palette here; 511 * It may not actually be necessary to set png_ptr->palette here;
511 * we do it for backward compatibility with the way the png_handle_tRNS 512 * we do it for backward compatibility with the way the png_handle_tRNS
512 * function used to do the allocation. 513 * function used to do the allocation.
513 */ 514 */
514 #ifdef PNG_FREE_ME_SUPPORTED 515 #ifdef PNG_FREE_ME_SUPPORTED
515 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); 516 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
516 #endif 517 #endif
517 518
518 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead 519 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
519 of num_palette entries, 520 * of num_palette entries, in case of an invalid PNG file that has
520 in case of an invalid PNG file that has too-large sample values. */ 521 * too-large sample values.
522 */
521 png_ptr->palette = (png_colorp)png_malloc(png_ptr, 523 png_ptr->palette = (png_colorp)png_malloc(png_ptr,
522 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); 524 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
523 png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH * 525 png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
524 png_sizeof(png_color)); 526 png_sizeof(png_color));
525 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color)); 527 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
526 info_ptr->palette = png_ptr->palette; 528 info_ptr->palette = png_ptr->palette;
527 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; 529 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
528 530
529 #ifdef PNG_FREE_ME_SUPPORTED 531 #ifdef PNG_FREE_ME_SUPPORTED
530 info_ptr->free_me |= PNG_FREE_PLTE; 532 info_ptr->free_me |= PNG_FREE_PLTE;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 red_x = (float).64; 615 red_x = (float).64;
614 red_y = (float).33; 616 red_y = (float).33;
615 green_x = (float).30; 617 green_x = (float).30;
616 green_y = (float).60; 618 green_y = (float).60;
617 blue_x = (float).15; 619 blue_x = (float).15;
618 blue_y = (float).06; 620 blue_y = (float).06;
619 #endif 621 #endif
620 622
621 #if !defined(PNG_NO_CHECK_cHRM) 623 #if !defined(PNG_NO_CHECK_cHRM)
622 if (png_check_cHRM_fixed(png_ptr, 624 if (png_check_cHRM_fixed(png_ptr,
623 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, 625 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
624 int_green_y, int_blue_x, int_blue_y)) 626 int_green_y, int_blue_x, int_blue_y))
625 #endif 627 #endif
626 { 628 {
627 #ifdef PNG_FIXED_POINT_SUPPORTED 629 #ifdef PNG_FIXED_POINT_SUPPORTED
628 png_set_cHRM_fixed(png_ptr, info_ptr, 630 png_set_cHRM_fixed(png_ptr, info_ptr,
629 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, 631 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
630 int_green_y, int_blue_x, int_blue_y); 632 int_green_y, int_blue_x, int_blue_y);
631 #endif 633 #endif
632 #ifdef PNG_FLOATING_POINT_SUPPORTED 634 #ifdef PNG_FLOATING_POINT_SUPPORTED
633 png_set_cHRM(png_ptr, info_ptr, 635 png_set_cHRM(png_ptr, info_ptr,
634 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); 636 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
635 #endif 637 #endif
636 } 638 }
637 #endif /* cHRM */ 639 #endif /* cHRM */
638 } 640 }
639 #endif /* sRGB */ 641 #endif /* sRGB */
640 642
641 643
642 #if defined(PNG_iCCP_SUPPORTED) 644 #if defined(PNG_iCCP_SUPPORTED)
643 void PNGAPI 645 void PNGAPI
644 png_set_iCCP(png_structp png_ptr, png_infop info_ptr, 646 png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 #ifdef PNG_FREE_ME_SUPPORTED 684 #ifdef PNG_FREE_ME_SUPPORTED
683 info_ptr->free_me |= PNG_FREE_ICCP; 685 info_ptr->free_me |= PNG_FREE_ICCP;
684 #endif 686 #endif
685 info_ptr->valid |= PNG_INFO_iCCP; 687 info_ptr->valid |= PNG_INFO_iCCP;
686 } 688 }
687 #endif 689 #endif
688 690
689 #if defined(PNG_TEXT_SUPPORTED) 691 #if defined(PNG_TEXT_SUPPORTED)
690 void PNGAPI 692 void PNGAPI
691 png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, 693 png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
692 int num_text) 694 int num_text)
693 { 695 {
694 int ret; 696 int ret;
695 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); 697 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
696 if (ret) 698 if (ret)
697 png_error(png_ptr, "Insufficient memory to store text"); 699 png_error(png_ptr, "Insufficient memory to store text");
698 } 700 }
699 701
700 int /* PRIVATE */ 702 int /* PRIVATE */
701 png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, 703 png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
702 int num_text) 704 int num_text)
703 { 705 {
704 int i; 706 int i;
705 707
706 png_debug1(1, "in %s storage function", (png_ptr->chunk_name[0] == '\0' ? 708 png_debug1(1, "in %s storage function", (png_ptr->chunk_name[0] == '\0' ?
707 "text" : (png_const_charp)png_ptr->chunk_name)); 709 "text" : (png_const_charp)png_ptr->chunk_name));
708 710
709 if (png_ptr == NULL || info_ptr == NULL || num_text == 0) 711 if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
710 return(0); 712 return(0);
711 713
712 /* Make sure we have enough space in the "text" array in info_struct 714 /* Make sure we have enough space in the "text" array in info_struct
713 * to hold all of the incoming text_ptr objects. 715 * to hold all of the incoming text_ptr objects.
714 */ 716 */
715 if (info_ptr->num_text + num_text > info_ptr->max_text) 717 if (info_ptr->num_text + num_text > info_ptr->max_text)
716 { 718 {
717 if (info_ptr->text != NULL) 719 if (info_ptr->text != NULL)
718 { 720 {
719 png_textp old_text; 721 png_textp old_text;
720 int old_max; 722 int old_max;
721 723
722 old_max = info_ptr->max_text; 724 old_max = info_ptr->max_text;
723 info_ptr->max_text = info_ptr->num_text + num_text + 8; 725 info_ptr->max_text = info_ptr->num_text + num_text + 8;
724 old_text = info_ptr->text; 726 old_text = info_ptr->text;
725 info_ptr->text = (png_textp)png_malloc_warn(png_ptr, 727 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
726 (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); 728 (png_uint_32)(info_ptr->max_text * png_sizeof(png_text)));
727 if (info_ptr->text == NULL) 729 if (info_ptr->text == NULL)
728 { 730 {
729 png_free(png_ptr, old_text); 731 png_free(png_ptr, old_text);
730 return(1); 732 return(1);
731 } 733 }
732 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max * 734 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
733 png_sizeof(png_text))); 735 png_sizeof(png_text)));
734 png_free(png_ptr, old_text); 736 png_free(png_ptr, old_text);
735 } 737 }
736 else 738 else
737 { 739 {
738 info_ptr->max_text = num_text + 8; 740 info_ptr->max_text = num_text + 8;
739 info_ptr->num_text = 0; 741 info_ptr->num_text = 0;
740 info_ptr->text = (png_textp)png_malloc_warn(png_ptr, 742 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
741 (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); 743 (png_uint_32)(info_ptr->max_text * png_sizeof(png_text)));
742 if (info_ptr->text == NULL) 744 if (info_ptr->text == NULL)
743 return(1); 745 return(1);
744 #ifdef PNG_FREE_ME_SUPPORTED 746 #ifdef PNG_FREE_ME_SUPPORTED
745 info_ptr->free_me |= PNG_FREE_TEXT; 747 info_ptr->free_me |= PNG_FREE_TEXT;
746 #endif 748 #endif
747 } 749 }
748 png_debug1(3, "allocated %d entries for info_ptr->text", 750 png_debug1(3, "allocated %d entries for info_ptr->text",
749 info_ptr->max_text); 751 info_ptr->max_text);
750 } 752 }
751 for (i = 0; i < num_text; i++) 753 for (i = 0; i < num_text; i++)
752 { 754 {
753 png_size_t text_length, key_len; 755 png_size_t text_length, key_len;
754 png_size_t lang_len, lang_key_len; 756 png_size_t lang_len, lang_key_len;
755 png_textp textp = &(info_ptr->text[info_ptr->num_text]); 757 png_textp textp = &(info_ptr->text[info_ptr->num_text]);
756 758
757 if (text_ptr[i].key == NULL) 759 if (text_ptr[i].key == NULL)
758 continue; 760 continue;
759 761
760 key_len = png_strlen(text_ptr[i].key); 762 key_len = png_strlen(text_ptr[i].key);
761 763
762 if (text_ptr[i].compression <= 0) 764 if (text_ptr[i].compression <= 0)
763 { 765 {
764 lang_len = 0; 766 lang_len = 0;
765 lang_key_len = 0; 767 lang_key_len = 0;
766 } 768 }
767 else 769 else
768 #ifdef PNG_iTXt_SUPPORTED 770 #ifdef PNG_iTXt_SUPPORTED
769 { 771 {
770 /* set iTXt data */ 772 /* Set iTXt data */
771 if (text_ptr[i].lang != NULL) 773 if (text_ptr[i].lang != NULL)
772 lang_len = png_strlen(text_ptr[i].lang); 774 lang_len = png_strlen(text_ptr[i].lang);
773 else 775 else
774 lang_len = 0; 776 lang_len = 0;
775 if (text_ptr[i].lang_key != NULL) 777 if (text_ptr[i].lang_key != NULL)
776 lang_key_len = png_strlen(text_ptr[i].lang_key); 778 lang_key_len = png_strlen(text_ptr[i].lang_key);
777 else 779 else
778 lang_key_len = 0; 780 lang_key_len = 0;
779 } 781 }
780 #else 782 #else
781 { 783 {
782 png_warning(png_ptr, "iTXt chunk not supported."); 784 png_warning(png_ptr, "iTXt chunk not supported.");
783 continue; 785 continue;
784 } 786 }
785 #endif 787 #endif
786 788
787 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') 789 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
788 { 790 {
789 text_length = 0; 791 text_length = 0;
790 #ifdef PNG_iTXt_SUPPORTED 792 #ifdef PNG_iTXt_SUPPORTED
791 if (text_ptr[i].compression > 0) 793 if (text_ptr[i].compression > 0)
792 textp->compression = PNG_ITXT_COMPRESSION_NONE; 794 textp->compression = PNG_ITXT_COMPRESSION_NONE;
793 else 795 else
794 #endif 796 #endif
795 textp->compression = PNG_TEXT_COMPRESSION_NONE; 797 textp->compression = PNG_TEXT_COMPRESSION_NONE;
796 } 798 }
797 else 799 else
798 { 800 {
799 text_length = png_strlen(text_ptr[i].text); 801 text_length = png_strlen(text_ptr[i].text);
800 textp->compression = text_ptr[i].compression; 802 textp->compression = text_ptr[i].compression;
801 } 803 }
802 804
803 textp->key = (png_charp)png_malloc_warn(png_ptr, 805 textp->key = (png_charp)png_malloc_warn(png_ptr,
804 (png_uint_32) 806 (png_uint_32)
805 (key_len + text_length + lang_len + lang_key_len + 4)); 807 (key_len + text_length + lang_len + lang_key_len + 4));
806 if (textp->key == NULL) 808 if (textp->key == NULL)
807 return(1); 809 return(1);
808 png_debug2(2, "Allocated %lu bytes at %x in png_set_text", 810 png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
809 (png_uint_32) 811 (png_uint_32)
810 (key_len + lang_len + lang_key_len + text_length + 4), 812 (key_len + lang_len + lang_key_len + text_length + 4),
811 (int)textp->key); 813 (int)textp->key);
812 814
813 png_memcpy(textp->key, text_ptr[i].key, 815 png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
814 (png_size_t)(key_len));
815 *(textp->key + key_len) = '\0'; 816 *(textp->key + key_len) = '\0';
816 #ifdef PNG_iTXt_SUPPORTED 817 #ifdef PNG_iTXt_SUPPORTED
817 if (text_ptr[i].compression > 0) 818 if (text_ptr[i].compression > 0)
818 { 819 {
819 textp->lang = textp->key + key_len + 1; 820 textp->lang = textp->key + key_len + 1;
820 png_memcpy(textp->lang, text_ptr[i].lang, lang_len); 821 png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
821 *(textp->lang + lang_len) = '\0'; 822 *(textp->lang + lang_len) = '\0';
822 textp->lang_key = textp->lang + lang_len + 1; 823 textp->lang_key = textp->lang + lang_len + 1;
823 png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len); 824 png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
824 *(textp->lang_key + lang_key_len) = '\0'; 825 *(textp->lang_key + lang_key_len) = '\0';
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 */ 892 */
892 893
893 #ifdef PNG_FREE_ME_SUPPORTED 894 #ifdef PNG_FREE_ME_SUPPORTED
894 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); 895 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
895 #endif 896 #endif
896 897
897 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ 898 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
898 png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr, 899 png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
899 (png_uint_32)PNG_MAX_PALETTE_LENGTH); 900 (png_uint_32)PNG_MAX_PALETTE_LENGTH);
900 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) 901 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
901 png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans); 902 png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
902 } 903 }
903 904
904 if (trans_values != NULL) 905 if (trans_values != NULL)
905 { 906 {
906 int sample_max = (1 << info_ptr->bit_depth); 907 int sample_max = (1 << info_ptr->bit_depth);
907 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY && 908 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
908 (int)trans_values->gray > sample_max) || 909 (int)trans_values->gray > sample_max) ||
909 (info_ptr->color_type == PNG_COLOR_TYPE_RGB && 910 (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
910 ((int)trans_values->red > sample_max || 911 ((int)trans_values->red > sample_max ||
911 (int)trans_values->green > sample_max || 912 (int)trans_values->green > sample_max ||
912 (int)trans_values->blue > sample_max))) 913 (int)trans_values->blue > sample_max)))
913 png_warning(png_ptr, 914 png_warning(png_ptr,
914 "tRNS chunk has out-of-range samples for bit_depth"); 915 "tRNS chunk has out-of-range samples for bit_depth");
915 png_memcpy(&(info_ptr->trans_values), trans_values, 916 png_memcpy(&(info_ptr->trans_values), trans_values,
916 png_sizeof(png_color_16)); 917 png_sizeof(png_color_16));
917 if (num_trans == 0) 918 if (num_trans == 0)
918 num_trans = 1; 919 num_trans = 1;
919 } 920 }
920 921
921 info_ptr->num_trans = (png_uint_16)num_trans; 922 info_ptr->num_trans = (png_uint_16)num_trans;
922 if (num_trans != 0) 923 if (num_trans != 0)
923 { 924 {
924 info_ptr->valid |= PNG_INFO_tRNS; 925 info_ptr->valid |= PNG_INFO_tRNS;
925 #ifdef PNG_FREE_ME_SUPPORTED 926 #ifdef PNG_FREE_ME_SUPPORTED
926 info_ptr->free_me |= PNG_FREE_TRNS; 927 info_ptr->free_me |= PNG_FREE_TRNS;
927 #else 928 #else
928 png_ptr->flags |= PNG_FLAG_FREE_TRNS; 929 png_ptr->flags |= PNG_FLAG_FREE_TRNS;
929 #endif 930 #endif
930 } 931 }
931 } 932 }
932 #endif 933 #endif
933 934
934 #if defined(PNG_sPLT_SUPPORTED) 935 #if defined(PNG_sPLT_SUPPORTED)
935 void PNGAPI 936 void PNGAPI
936 png_set_sPLT(png_structp png_ptr, 937 png_set_sPLT(png_structp png_ptr,
937 png_infop info_ptr, png_sPLT_tp entries, int nentries) 938 png_infop info_ptr, png_sPLT_tp entries, int nentries)
938 /* 939 /*
939 * entries - array of png_sPLT_t structures 940 * entries - array of png_sPLT_t structures
940 * to be added to the list of palettes 941 * to be added to the list of palettes
941 * in the info structure. 942 * in the info structure.
942 * nentries - number of palette structures to be 943 * nentries - number of palette structures to be
943 * added. 944 * added.
944 */ 945 */
945 { 946 {
946 png_sPLT_tp np; 947 png_sPLT_tp np;
947 int i; 948 int i;
948 949
949 if (png_ptr == NULL || info_ptr == NULL) 950 if (png_ptr == NULL || info_ptr == NULL)
950 return; 951 return;
951 952
952 np = (png_sPLT_tp)png_malloc_warn(png_ptr, 953 np = (png_sPLT_tp)png_malloc_warn(png_ptr,
953 (info_ptr->splt_palettes_num + nentries) * 954 (info_ptr->splt_palettes_num + nentries) *
954 (png_uint_32)png_sizeof(png_sPLT_t)); 955 (png_uint_32)png_sizeof(png_sPLT_t));
955 if (np == NULL) 956 if (np == NULL)
956 { 957 {
957 png_warning(png_ptr, "No memory for sPLT palettes."); 958 png_warning(png_ptr, "No memory for sPLT palettes.");
958 return; 959 return;
959 } 960 }
960 961
961 png_memcpy(np, info_ptr->splt_palettes, 962 png_memcpy(np, info_ptr->splt_palettes,
962 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t)); 963 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
963 png_free(png_ptr, info_ptr->splt_palettes); 964 png_free(png_ptr, info_ptr->splt_palettes);
964 info_ptr->splt_palettes=NULL; 965 info_ptr->splt_palettes=NULL;
965 966
966 for (i = 0; i < nentries; i++) 967 for (i = 0; i < nentries; i++)
967 { 968 {
968 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i; 969 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
969 png_sPLT_tp from = entries + i; 970 png_sPLT_tp from = entries + i;
970 png_uint_32 length; 971 png_uint_32 length;
971 972
972 length = png_strlen(from->name) + 1; 973 length = png_strlen(from->name) + 1;
973 to->name = (png_charp)png_malloc_warn(png_ptr, length); 974 to->name = (png_charp)png_malloc_warn(png_ptr, length);
974 if (to->name == NULL) 975 if (to->name == NULL)
975 { 976 {
976 png_warning(png_ptr, 977 png_warning(png_ptr,
977 "Out of memory while processing sPLT chunk"); 978 "Out of memory while processing sPLT chunk");
978 continue; 979 continue;
979 } 980 }
980 png_memcpy(to->name, from->name, length); 981 png_memcpy(to->name, from->name, length);
981 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, 982 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
982 (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry))); 983 (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry)));
983 if (to->entries == NULL) 984 if (to->entries == NULL)
984 { 985 {
985 png_warning(png_ptr, 986 png_warning(png_ptr,
986 "Out of memory while processing sPLT chunk"); 987 "Out of memory while processing sPLT chunk");
987 png_free(png_ptr, to->name); 988 png_free(png_ptr, to->name);
988 to->name = NULL; 989 to->name = NULL;
989 continue; 990 continue;
990 } 991 }
991 png_memcpy(to->entries, from->entries, 992 png_memcpy(to->entries, from->entries,
992 from->nentries * png_sizeof(png_sPLT_entry)); 993 from->nentries * png_sizeof(png_sPLT_entry));
993 to->nentries = from->nentries; 994 to->nentries = from->nentries;
994 to->depth = from->depth; 995 to->depth = from->depth;
995 } 996 }
996 997
997 info_ptr->splt_palettes = np; 998 info_ptr->splt_palettes = np;
998 info_ptr->splt_palettes_num += nentries; 999 info_ptr->splt_palettes_num += nentries;
999 info_ptr->valid |= PNG_INFO_sPLT; 1000 info_ptr->valid |= PNG_INFO_sPLT;
1000 #ifdef PNG_FREE_ME_SUPPORTED 1001 #ifdef PNG_FREE_ME_SUPPORTED
1001 info_ptr->free_me |= PNG_FREE_SPLT; 1002 info_ptr->free_me |= PNG_FREE_SPLT;
1002 #endif 1003 #endif
1003 } 1004 }
1004 #endif /* PNG_sPLT_SUPPORTED */ 1005 #endif /* PNG_sPLT_SUPPORTED */
1005 1006
1006 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) 1007 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1007 void PNGAPI 1008 void PNGAPI
1008 png_set_unknown_chunks(png_structp png_ptr, 1009 png_set_unknown_chunks(png_structp png_ptr,
1009 png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns) 1010 png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
1010 { 1011 {
1011 png_unknown_chunkp np; 1012 png_unknown_chunkp np;
1012 int i; 1013 int i;
1013 1014
1014 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0) 1015 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
1015 return; 1016 return;
1016 1017
1017 np = (png_unknown_chunkp)png_malloc_warn(png_ptr, 1018 np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
1018 (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) * 1019 (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) *
1019 png_sizeof(png_unknown_chunk))); 1020 png_sizeof(png_unknown_chunk)));
1020 if (np == NULL) 1021 if (np == NULL)
1021 { 1022 {
1022 png_warning(png_ptr, 1023 png_warning(png_ptr,
1023 "Out of memory while processing unknown chunk."); 1024 "Out of memory while processing unknown chunk.");
1024 return; 1025 return;
1025 } 1026 }
1026 1027
1027 png_memcpy(np, info_ptr->unknown_chunks, 1028 png_memcpy(np, info_ptr->unknown_chunks,
1028 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk)); 1029 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
1029 png_free(png_ptr, info_ptr->unknown_chunks); 1030 png_free(png_ptr, info_ptr->unknown_chunks);
1030 info_ptr->unknown_chunks=NULL; 1031 info_ptr->unknown_chunks=NULL;
1031 1032
1032 for (i = 0; i < num_unknowns; i++) 1033 for (i = 0; i < num_unknowns; i++)
1033 { 1034 {
1034 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i; 1035 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
1035 png_unknown_chunkp from = unknowns + i; 1036 png_unknown_chunkp from = unknowns + i;
1036 1037
1037 png_memcpy((png_charp)to->name, 1038 png_memcpy((png_charp)to->name,
1038 (png_charp)from->name, 1039 (png_charp)from->name,
1039 png_sizeof(from->name)); 1040 png_sizeof(from->name));
1040 to->name[png_sizeof(to->name)-1] = '\0'; 1041 to->name[png_sizeof(to->name)-1] = '\0';
1041 to->size = from->size; 1042 to->size = from->size;
1042 /* note our location in the read or write sequence */ 1043 /* Note our location in the read or write sequence */
1043 to->location = (png_byte)(png_ptr->mode & 0xff); 1044 to->location = (png_byte)(png_ptr->mode & 0xff);
1044 1045
1045 if (from->size == 0) 1046 if (from->size == 0)
1046 to->data=NULL; 1047 to->data=NULL;
1047 else 1048 else
1048 { 1049 {
1049 to->data = (png_bytep)png_malloc_warn(png_ptr, 1050 to->data = (png_bytep)png_malloc_warn(png_ptr,
1050 (png_uint_32)from->size); 1051 (png_uint_32)from->size);
1051 if (to->data == NULL) 1052 if (to->data == NULL)
1052 { 1053 {
1053 png_warning(png_ptr, 1054 png_warning(png_ptr,
1054 "Out of memory while processing unknown chunk."); 1055 "Out of memory while processing unknown chunk.");
1055 to->size = 0; 1056 to->size = 0;
1056 } 1057 }
1057 else 1058 else
1058 png_memcpy(to->data, from->data, from->size); 1059 png_memcpy(to->data, from->data, from->size);
1059 } 1060 }
1060 } 1061 }
1061 1062
1062 info_ptr->unknown_chunks = np; 1063 info_ptr->unknown_chunks = np;
1063 info_ptr->unknown_chunks_num += num_unknowns; 1064 info_ptr->unknown_chunks_num += num_unknowns;
1064 #ifdef PNG_FREE_ME_SUPPORTED 1065 #ifdef PNG_FREE_ME_SUPPORTED
1065 info_ptr->free_me |= PNG_FREE_UNKN; 1066 info_ptr->free_me |= PNG_FREE_UNKN;
1066 #endif 1067 #endif
1067 } 1068 }
1068 void PNGAPI 1069 void PNGAPI
1069 png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, 1070 png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
1070 int chunk, int location) 1071 int chunk, int location)
1071 { 1072 {
1072 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk < 1073 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
1073 (int)info_ptr->unknown_chunks_num) 1074 (int)info_ptr->unknown_chunks_num)
1074 info_ptr->unknown_chunks[chunk].location = (png_byte)location; 1075 info_ptr->unknown_chunks[chunk].location = (png_byte)location;
1075 } 1076 }
(...skipping 28 matching lines...) Expand all
1104 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES); 1105 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
1105 return (png_uint_32)png_ptr->mng_features_permitted; 1106 return (png_uint_32)png_ptr->mng_features_permitted;
1106 } 1107 }
1107 #endif 1108 #endif
1108 1109
1109 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) 1110 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1110 void PNGAPI 1111 void PNGAPI
1111 png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep 1112 png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
1112 chunk_list, int num_chunks) 1113 chunk_list, int num_chunks)
1113 { 1114 {
1114 png_bytep new_list, p; 1115 png_bytep new_list, p;
1115 int i, old_num_chunks; 1116 int i, old_num_chunks;
1116 if (png_ptr == NULL) 1117 if (png_ptr == NULL)
1117 return; 1118 return;
1118 if (num_chunks == 0) 1119 if (num_chunks == 0)
1119 { 1120 {
1120 if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE) 1121 if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
1121 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS; 1122 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
1122 else 1123 else
1123 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS; 1124 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
1124 1125
1125 if (keep == PNG_HANDLE_CHUNK_ALWAYS) 1126 if (keep == PNG_HANDLE_CHUNK_ALWAYS)
1126 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS; 1127 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1127 else 1128 else
1128 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS; 1129 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1129 return; 1130 return;
1130 } 1131 }
1131 if (chunk_list == NULL) 1132 if (chunk_list == NULL)
1132 return; 1133 return;
1133 old_num_chunks = png_ptr->num_chunk_list; 1134 old_num_chunks = png_ptr->num_chunk_list;
1134 new_list=(png_bytep)png_malloc(png_ptr, 1135 new_list=(png_bytep)png_malloc(png_ptr,
1135 (png_uint_32) 1136 (png_uint_32)
1136 (5*(num_chunks + old_num_chunks))); 1137 (5*(num_chunks + old_num_chunks)));
1137 if (png_ptr->chunk_list != NULL) 1138 if (png_ptr->chunk_list != NULL)
1138 { 1139 {
1139 png_memcpy(new_list, png_ptr->chunk_list, 1140 png_memcpy(new_list, png_ptr->chunk_list,
1140 (png_size_t)(5*old_num_chunks)); 1141 (png_size_t)(5*old_num_chunks));
1141 png_free(png_ptr, png_ptr->chunk_list); 1142 png_free(png_ptr, png_ptr->chunk_list);
1142 png_ptr->chunk_list=NULL; 1143 png_ptr->chunk_list=NULL;
1143 } 1144 }
1144 png_memcpy(new_list + 5*old_num_chunks, chunk_list, 1145 png_memcpy(new_list + 5*old_num_chunks, chunk_list,
1145 (png_size_t)(5*num_chunks)); 1146 (png_size_t)(5*num_chunks));
1146 for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5) 1147 for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
1147 *p=(png_byte)keep; 1148 *p=(png_byte)keep;
1148 png_ptr->num_chunk_list = old_num_chunks + num_chunks; 1149 png_ptr->num_chunk_list = old_num_chunks + num_chunks;
1149 png_ptr->chunk_list = new_list; 1150 png_ptr->chunk_list = new_list;
1150 #ifdef PNG_FREE_ME_SUPPORTED 1151 #ifdef PNG_FREE_ME_SUPPORTED
1151 png_ptr->free_me |= PNG_FREE_LIST; 1152 png_ptr->free_me |= PNG_FREE_LIST;
1152 #endif 1153 #endif
1153 } 1154 }
1154 #endif 1155 #endif
1155 1156
1156 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) 1157 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
1157 void PNGAPI 1158 void PNGAPI
1158 png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, 1159 png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
1159 png_user_chunk_ptr read_user_chunk_fn) 1160 png_user_chunk_ptr read_user_chunk_fn)
1160 { 1161 {
1161 png_debug(1, "in png_set_read_user_chunk_fn"); 1162 png_debug(1, "in png_set_read_user_chunk_fn");
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 void PNGAPI 1202 void PNGAPI
1202 png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) 1203 png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
1203 { 1204 {
1204 if (png_ptr && info_ptr) 1205 if (png_ptr && info_ptr)
1205 info_ptr->valid &= ~mask; 1206 info_ptr->valid &= ~mask;
1206 } 1207 }
1207 1208
1208 1209
1209 #ifndef PNG_1_0_X 1210 #ifndef PNG_1_0_X
1210 #ifdef PNG_ASSEMBLER_CODE_SUPPORTED 1211 #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
1211 /* function was added to libpng 1.2.0 and should always exist by default */ 1212 /* Function was added to libpng 1.2.0 and should always exist by default */
1212 void PNGAPI 1213 void PNGAPI
1213 png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags) 1214 png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
1214 { 1215 {
1215 /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ 1216 /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
1216 if (png_ptr != NULL) 1217 if (png_ptr != NULL)
1217 png_ptr->asm_flags = 0; 1218 png_ptr->asm_flags = 0;
1218 asm_flags = asm_flags; /* Quiet the compiler */ 1219 asm_flags = asm_flags; /* Quiet the compiler */
1219 } 1220 }
1220 1221
1221 /* this function was added to libpng 1.2.0 */ 1222 /* This function was added to libpng 1.2.0 */
1222 void PNGAPI 1223 void PNGAPI
1223 png_set_mmx_thresholds (png_structp png_ptr, 1224 png_set_mmx_thresholds (png_structp png_ptr,
1224 png_byte mmx_bitdepth_threshold, 1225 png_byte mmx_bitdepth_threshold,
1225 png_uint_32 mmx_rowbytes_threshold) 1226 png_uint_32 mmx_rowbytes_threshold)
1226 { 1227 {
1227 /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ 1228 /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
1228 if (png_ptr == NULL) 1229 if (png_ptr == NULL)
1229 return; 1230 return;
1230 /* Quiet the compiler */ 1231 /* Quiet the compiler */
1231 mmx_bitdepth_threshold = mmx_bitdepth_threshold; 1232 mmx_bitdepth_threshold = mmx_bitdepth_threshold;
1232 mmx_rowbytes_threshold = mmx_rowbytes_threshold; 1233 mmx_rowbytes_threshold = mmx_rowbytes_threshold;
1233 } 1234 }
1234 #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ 1235 #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
1235 1236
1236 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 1237 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
1237 /* this function was added to libpng 1.2.6 */ 1238 /* This function was added to libpng 1.2.6 */
1238 void PNGAPI 1239 void PNGAPI
1239 png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, 1240 png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
1240 png_uint_32 user_height_max) 1241 png_uint_32 user_height_max)
1241 { 1242 {
1242 /* Images with dimensions larger than these limits will be 1243 /* Images with dimensions larger than these limits will be
1243 * rejected by png_set_IHDR(). To accept any PNG datastream 1244 * rejected by png_set_IHDR(). To accept any PNG datastream
1244 * regardless of dimensions, set both limits to 0x7ffffffL. 1245 * regardless of dimensions, set both limits to 0x7ffffffL.
1245 */ 1246 */
1246 if (png_ptr == NULL) return; 1247 if (png_ptr == NULL)
1247 png_ptr->user_width_max = user_width_max; 1248 return;
1248 png_ptr->user_height_max = user_height_max; 1249 png_ptr->user_width_max = user_width_max;
1250 png_ptr->user_height_max = user_height_max;
1249 } 1251 }
1250 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ 1252 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1251 1253
1252 #endif /* ?PNG_1_0_X */ 1254 #endif /* ?PNG_1_0_X */
1253 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ 1255 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
OLDNEW
« no previous file with comments | « third_party/libpng/pngrutil.c ('k') | third_party/libpng/pngtrans.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698