233
234
if (png_ptr == NULL || info_ptr == NULL)
236
/* Check for width and height valid values */
237
if (width == 0 || height == 0)
238
png_error(png_ptr, "Image width or height is zero in IHDR");
239
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
240
if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
241
png_error(png_ptr, "image size exceeds user limits in IHDR");
243
if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
244
png_error(png_ptr, "image size exceeds user limits in IHDR");
246
if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
247
png_error(png_ptr, "Invalid image size in IHDR");
248
if ( width > (PNG_UINT_32_MAX
249
>> 3) /* 8-byte RGBA pixels */
250
- 64 /* bigrowbuf hack */
251
- 1 /* filter byte */
252
- 7*8 /* rounding of width to multiple of 8 pixels */
253
- 8) /* extra max_pixel_depth pad */
254
png_warning(png_ptr, "Width is too large for libpng to process pixels");
256
/* Check other values */
257
if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
258
bit_depth != 8 && bit_depth != 16)
259
png_error(png_ptr, "Invalid bit depth in IHDR");
261
if (color_type < 0 || color_type == 1 ||
262
color_type == 5 || color_type > 6)
263
png_error(png_ptr, "Invalid color type in IHDR");
265
if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
266
((color_type == PNG_COLOR_TYPE_RGB ||
267
color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
268
color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
269
png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
271
if (interlace_type >= PNG_INTERLACE_LAST)
272
png_error(png_ptr, "Unknown interlace method in IHDR");
274
if (compression_type != PNG_COMPRESSION_TYPE_BASE)
275
png_error(png_ptr, "Unknown compression method in IHDR");
277
#if defined(PNG_MNG_FEATURES_SUPPORTED)
278
/* Accept filter_method 64 (intrapixel differencing) only if
279
* 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
280
* 2. Libpng did not read a PNG signature (this filter_method is only
281
* used in PNG datastreams that are embedded in MNG datastreams) and
282
* 3. The application called png_permit_mng_features with a mask that
283
* included PNG_FLAG_MNG_FILTER_64 and
284
* 4. The filter_method is 64 and
285
* 5. The color_type is RGB or RGBA
287
if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
288
png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
289
if (filter_type != PNG_FILTER_TYPE_BASE)
291
if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
292
(filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
293
((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
294
(color_type == PNG_COLOR_TYPE_RGB ||
295
color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
296
png_error(png_ptr, "Unknown filter method in IHDR");
297
if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
298
png_warning(png_ptr, "Invalid filter method in IHDR");
301
if (filter_type != PNG_FILTER_TYPE_BASE)
302
png_error(png_ptr, "Unknown filter method in IHDR");
305
237
info_ptr->width = width;
306
238
info_ptr->height = height;
307
239
info_ptr->bit_depth = (png_byte)bit_depth;
308
info_ptr->color_type =(png_byte) color_type;
240
info_ptr->color_type = (png_byte)color_type;
309
241
info_ptr->compression_type = (png_byte)compression_type;
310
242
info_ptr->filter_type = (png_byte)filter_type;
311
243
info_ptr->interlace_type = (png_byte)interlace_type;
245
png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
246
info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
247
info_ptr->compression_type, info_ptr->filter_type);
312
249
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
313
250
info_ptr->channels = 1;
314
251
else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
538
475
* of num_palette entries, in case of an invalid PNG file that has
539
476
* too-large sample values.
541
png_ptr->palette = (png_colorp)png_malloc(png_ptr,
478
png_ptr->palette = (png_colorp)png_calloc(png_ptr,
542
479
PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
543
png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
544
png_sizeof(png_color));
545
480
png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
546
481
info_ptr->palette = png_ptr->palette;
547
482
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
641
576
blue_y = (float).06;
644
#if !defined(PNG_NO_CHECK_cHRM)
645
if (png_check_cHRM_fixed(png_ptr,
579
#ifdef PNG_FIXED_POINT_SUPPORTED
580
png_set_cHRM_fixed(png_ptr, info_ptr,
646
581
int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
647
int_green_y, int_blue_x, int_blue_y))
650
#ifdef PNG_FIXED_POINT_SUPPORTED
651
png_set_cHRM_fixed(png_ptr, info_ptr,
652
int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
653
int_green_y, int_blue_x, int_blue_y);
582
int_green_y, int_blue_x, int_blue_y);
655
584
#ifdef PNG_FLOATING_POINT_SUPPORTED
656
png_set_cHRM(png_ptr, info_ptr,
657
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
585
png_set_cHRM(png_ptr, info_ptr,
586
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
660
588
#endif /* cHRM */
662
590
#endif /* sRGB */
665
#if defined(PNG_iCCP_SUPPORTED)
593
#ifdef PNG_iCCP_SUPPORTED
667
595
png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
668
596
png_charp name, int compression_type,