20#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
22#ifdef PNG_bKGD_SUPPORTED
24png_set_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
25 png_const_color_16p background)
27 png_debug1(1,
"in %s storage function",
"bKGD");
29 if (png_ptr == NULL || info_ptr == NULL || background == NULL)
32 info_ptr->background = *background;
33 info_ptr->valid |= PNG_INFO_bKGD;
37#ifdef PNG_cHRM_SUPPORTED
39png_set_cHRM_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
40 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
41 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
42 png_fixed_point blue_x, png_fixed_point blue_y)
44 png_debug1(1,
"in %s storage function",
"cHRM fixed");
46 if (png_ptr == NULL || info_ptr == NULL)
49 info_ptr->cHRM.redx = red_x;
50 info_ptr->cHRM.redy = red_y;
51 info_ptr->cHRM.greenx = green_x;
52 info_ptr->cHRM.greeny = green_y;
53 info_ptr->cHRM.bluex = blue_x;
54 info_ptr->cHRM.bluey = blue_y;
55 info_ptr->cHRM.whitex = white_x;
56 info_ptr->cHRM.whitey = white_y;
58 info_ptr->valid |= PNG_INFO_cHRM;
62png_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
63 png_fixed_point int_red_X, png_fixed_point int_red_Y,
64 png_fixed_point int_red_Z, png_fixed_point int_green_X,
65 png_fixed_point int_green_Y, png_fixed_point int_green_Z,
66 png_fixed_point int_blue_X, png_fixed_point int_blue_Y,
67 png_fixed_point int_blue_Z)
72 png_debug1(1,
"in %s storage function",
"cHRM XYZ fixed");
74 if (png_ptr == NULL || info_ptr == NULL)
77 XYZ.red_X = int_red_X;
78 XYZ.red_Y = int_red_Y;
79 XYZ.red_Z = int_red_Z;
80 XYZ.green_X = int_green_X;
81 XYZ.green_Y = int_green_Y;
82 XYZ.green_Z = int_green_Z;
83 XYZ.blue_X = int_blue_X;
84 XYZ.blue_Y = int_blue_Y;
85 XYZ.blue_Z = int_blue_Z;
87 if (png_xy_from_XYZ(&xy, &XYZ) == 0)
90 info_ptr->valid |= PNG_INFO_cHRM;
94 png_app_error(png_ptr,
"invalid cHRM XYZ");
97# ifdef PNG_FLOATING_POINT_SUPPORTED
99png_set_cHRM(png_const_structrp png_ptr, png_inforp info_ptr,
100 double white_x,
double white_y,
double red_x,
double red_y,
101 double green_x,
double green_y,
double blue_x,
double blue_y)
103 png_set_cHRM_fixed(png_ptr, info_ptr,
104 png_fixed(png_ptr, white_x,
"cHRM White X"),
105 png_fixed(png_ptr, white_y,
"cHRM White Y"),
106 png_fixed(png_ptr, red_x,
"cHRM Red X"),
107 png_fixed(png_ptr, red_y,
"cHRM Red Y"),
108 png_fixed(png_ptr, green_x,
"cHRM Green X"),
109 png_fixed(png_ptr, green_y,
"cHRM Green Y"),
110 png_fixed(png_ptr, blue_x,
"cHRM Blue X"),
111 png_fixed(png_ptr, blue_y,
"cHRM Blue Y"));
115png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr,
double red_X,
116 double red_Y,
double red_Z,
double green_X,
double green_Y,
double green_Z,
117 double blue_X,
double blue_Y,
double blue_Z)
119 png_set_cHRM_XYZ_fixed(png_ptr, info_ptr,
120 png_fixed(png_ptr, red_X,
"cHRM Red X"),
121 png_fixed(png_ptr, red_Y,
"cHRM Red Y"),
122 png_fixed(png_ptr, red_Z,
"cHRM Red Z"),
123 png_fixed(png_ptr, green_X,
"cHRM Green X"),
124 png_fixed(png_ptr, green_Y,
"cHRM Green Y"),
125 png_fixed(png_ptr, green_Z,
"cHRM Green Z"),
126 png_fixed(png_ptr, blue_X,
"cHRM Blue X"),
127 png_fixed(png_ptr, blue_Y,
"cHRM Blue Y"),
128 png_fixed(png_ptr, blue_Z,
"cHRM Blue Z"));
134#ifdef PNG_cICP_SUPPORTED
136png_set_cICP(png_const_structrp png_ptr, png_inforp info_ptr,
137 png_byte colour_primaries, png_byte transfer_function,
138 png_byte matrix_coefficients, png_byte video_full_range_flag)
140 png_debug1(1,
"in %s storage function",
"cICP");
142 if (png_ptr == NULL || info_ptr == NULL)
145 info_ptr->cicp_colour_primaries = colour_primaries;
146 info_ptr->cicp_transfer_function = transfer_function;
147 info_ptr->cicp_matrix_coefficients = matrix_coefficients;
148 info_ptr->cicp_video_full_range_flag = video_full_range_flag;
150 if (info_ptr->cicp_matrix_coefficients != 0)
152 png_warning(png_ptr,
"Invalid cICP matrix coefficients");
156 info_ptr->valid |= PNG_INFO_cICP;
160#ifdef PNG_cLLI_SUPPORTED
162png_set_cLLI_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
166 png_uint_32 maxCLL, png_uint_32 maxFALL)
168 png_debug1(1,
"in %s storage function",
"cLLI");
170 if (png_ptr == NULL || info_ptr == NULL)
174 if (maxCLL > 0x7FFFFFFFU || maxFALL > 0x7FFFFFFFU)
182 png_chunk_report(png_ptr,
"cLLI light level exceeds PNG limit",
183 PNG_CHUNK_WRITE_ERROR);
187 info_ptr->maxCLL = maxCLL;
188 info_ptr->maxFALL = maxFALL;
189 info_ptr->valid |= PNG_INFO_cLLI;
192# ifdef PNG_FLOATING_POINT_SUPPORTED
194png_set_cLLI(png_const_structrp png_ptr, png_inforp info_ptr,
195 double maxCLL,
double maxFALL)
197 png_set_cLLI_fixed(png_ptr, info_ptr,
198 png_fixed_ITU(png_ptr, maxCLL,
"png_set_cLLI(maxCLL)"),
199 png_fixed_ITU(png_ptr, maxFALL,
"png_set_cLLI(maxFALL)"));
204#ifdef PNG_mDCV_SUPPORTED
206png_ITU_fixed_16(
int *error, png_fixed_point v)
215 if (v > 65535 || v < 0)
221 return (png_uint_16)v;
225png_set_mDCV_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
226 png_fixed_point white_x, png_fixed_point white_y,
227 png_fixed_point red_x, png_fixed_point red_y,
228 png_fixed_point green_x, png_fixed_point green_y,
229 png_fixed_point blue_x, png_fixed_point blue_y,
233 png_uint_16 rx, ry, gx, gy, bx, by, wx, wy;
236 png_debug1(1,
"in %s storage function",
"mDCV");
238 if (png_ptr == NULL || info_ptr == NULL)
243 rx = png_ITU_fixed_16(&error, red_x);
244 ry = png_ITU_fixed_16(&error, red_y);
245 gx = png_ITU_fixed_16(&error, green_x);
246 gy = png_ITU_fixed_16(&error, green_y);
247 bx = png_ITU_fixed_16(&error, blue_x);
248 by = png_ITU_fixed_16(&error, blue_y);
249 wx = png_ITU_fixed_16(&error, white_x);
250 wy = png_ITU_fixed_16(&error, white_y);
254 png_chunk_report(png_ptr,
255 "mDCV chromaticities outside representable range",
256 PNG_CHUNK_WRITE_ERROR);
261 if (maxDL > 0x7FFFFFFFU || minDL > 0x7FFFFFFFU)
269 png_chunk_report(png_ptr,
"mDCV display light level exceeds PNG limit",
270 PNG_CHUNK_WRITE_ERROR);
282 info_ptr->mastering_red_x = rx;
283 info_ptr->mastering_red_y = ry;
284 info_ptr->mastering_green_x = gx;
285 info_ptr->mastering_green_y = gy;
286 info_ptr->mastering_blue_x = bx;
287 info_ptr->mastering_blue_y = by;
288 info_ptr->mastering_white_x = wx;
289 info_ptr->mastering_white_y = wy;
290 info_ptr->mastering_maxDL = maxDL;
291 info_ptr->mastering_minDL = minDL;
292 info_ptr->valid |= PNG_INFO_mDCV;
295# ifdef PNG_FLOATING_POINT_SUPPORTED
297png_set_mDCV(png_const_structrp png_ptr, png_inforp info_ptr,
298 double white_x,
double white_y,
double red_x,
double red_y,
double green_x,
299 double green_y,
double blue_x,
double blue_y,
300 double maxDL,
double minDL)
302 png_set_mDCV_fixed(png_ptr, info_ptr,
303 png_fixed(png_ptr, white_x,
"png_set_mDCV(white(x))"),
304 png_fixed(png_ptr, white_y,
"png_set_mDCV(white(y))"),
305 png_fixed(png_ptr, red_x,
"png_set_mDCV(red(x))"),
306 png_fixed(png_ptr, red_y,
"png_set_mDCV(red(y))"),
307 png_fixed(png_ptr, green_x,
"png_set_mDCV(green(x))"),
308 png_fixed(png_ptr, green_y,
"png_set_mDCV(green(y))"),
309 png_fixed(png_ptr, blue_x,
"png_set_mDCV(blue(x))"),
310 png_fixed(png_ptr, blue_y,
"png_set_mDCV(blue(y))"),
311 png_fixed_ITU(png_ptr, maxDL,
"png_set_mDCV(maxDL)"),
312 png_fixed_ITU(png_ptr, minDL,
"png_set_mDCV(minDL)"));
317#ifdef PNG_eXIf_SUPPORTED
319png_set_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
322 png_warning(png_ptr,
"png_set_eXIf does not work; use png_set_eXIf_1");
328png_set_eXIf_1(png_const_structrp png_ptr, png_inforp info_ptr,
329 png_uint_32 num_exif, png_bytep exif)
333 png_debug1(1,
"in %s storage function",
"eXIf");
335 if (png_ptr == NULL || info_ptr == NULL ||
336 (png_ptr->mode & PNG_WROTE_eXIf) != 0)
339 new_exif = png_voidcast(png_bytep, png_malloc_warn(png_ptr, num_exif));
341 if (new_exif == NULL)
343 png_warning(png_ptr,
"Insufficient memory for eXIf chunk data");
347 memcpy(new_exif, exif, (
size_t)num_exif);
349 png_free_data(png_ptr, info_ptr, PNG_FREE_EXIF, 0);
351 info_ptr->num_exif = num_exif;
352 info_ptr->exif = new_exif;
353 info_ptr->free_me |= PNG_FREE_EXIF;
354 info_ptr->valid |= PNG_INFO_eXIf;
358#ifdef PNG_gAMA_SUPPORTED
360png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
361 png_fixed_point file_gamma)
363 png_debug1(1,
"in %s storage function",
"gAMA");
365 if (png_ptr == NULL || info_ptr == NULL)
368 info_ptr->gamma = file_gamma;
369 info_ptr->valid |= PNG_INFO_gAMA;
372# ifdef PNG_FLOATING_POINT_SUPPORTED
374png_set_gAMA(png_const_structrp png_ptr, png_inforp info_ptr,
double file_gamma)
376 png_set_gAMA_fixed(png_ptr, info_ptr, png_fixed(png_ptr, file_gamma,
382#ifdef PNG_hIST_SUPPORTED
384png_set_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
385 png_const_uint_16p hist)
389 png_debug1(1,
"in %s storage function",
"hIST");
391 if (png_ptr == NULL || info_ptr == NULL)
394 if (info_ptr->num_palette == 0 || info_ptr->num_palette
395 > PNG_MAX_PALETTE_LENGTH)
398 "Invalid palette size, hIST allocation skipped");
403 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
408 info_ptr->hist = png_voidcast(png_uint_16p, png_malloc_warn(png_ptr,
409 PNG_MAX_PALETTE_LENGTH * (
sizeof (png_uint_16))));
411 if (info_ptr->hist == NULL)
413 png_warning(png_ptr,
"Insufficient memory for hIST chunk data");
417 for (i = 0; i < info_ptr->num_palette; i++)
418 info_ptr->hist[i] = hist[i];
420 info_ptr->free_me |= PNG_FREE_HIST;
421 info_ptr->valid |= PNG_INFO_hIST;
426png_set_IHDR(png_const_structrp png_ptr, png_inforp info_ptr,
427 png_uint_32 width, png_uint_32 height,
int bit_depth,
428 int color_type,
int interlace_type,
int compression_type,
431 png_debug1(1,
"in %s storage function",
"IHDR");
433 if (png_ptr == NULL || info_ptr == NULL)
436 info_ptr->width = width;
437 info_ptr->height = height;
438 info_ptr->bit_depth = (png_byte)bit_depth;
439 info_ptr->color_type = (png_byte)color_type;
440 info_ptr->compression_type = (png_byte)compression_type;
441 info_ptr->filter_type = (png_byte)filter_type;
442 info_ptr->interlace_type = (png_byte)interlace_type;
444 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
445 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
446 info_ptr->compression_type, info_ptr->filter_type);
448 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
449 info_ptr->channels = 1;
451 else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
452 info_ptr->channels = 3;
455 info_ptr->channels = 1;
457 if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)
458 info_ptr->channels++;
460 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
462 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
465#ifdef PNG_oFFs_SUPPORTED
467png_set_oFFs(png_const_structrp png_ptr, png_inforp info_ptr,
468 png_int_32 offset_x, png_int_32 offset_y,
int unit_type)
470 png_debug1(1,
"in %s storage function",
"oFFs");
472 if (png_ptr == NULL || info_ptr == NULL)
475 info_ptr->x_offset = offset_x;
476 info_ptr->y_offset = offset_y;
477 info_ptr->offset_unit_type = (png_byte)unit_type;
478 info_ptr->valid |= PNG_INFO_oFFs;
482#ifdef PNG_pCAL_SUPPORTED
484png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
485 png_const_charp purpose, png_int_32 X0, png_int_32 X1,
int type,
486 int nparams, png_const_charp units, png_charpp params)
491 png_debug1(1,
"in %s storage function",
"pCAL");
493 if (png_ptr == NULL || info_ptr == NULL || purpose == NULL || units == NULL
494 || (nparams > 0 && params == NULL))
497 length = strlen(purpose) + 1;
498 png_debug1(3,
"allocating purpose for info (%lu bytes)",
499 (
unsigned long)length);
504 if (type < 0 || type > 3)
506 png_chunk_report(png_ptr,
"Invalid pCAL equation type",
507 PNG_CHUNK_WRITE_ERROR);
511 if (nparams < 0 || nparams > 255)
513 png_chunk_report(png_ptr,
"Invalid pCAL parameter count",
514 PNG_CHUNK_WRITE_ERROR);
519 for (i=0; i<nparams; ++i)
521 if (params[i] == NULL ||
522 !png_check_fp_string(params[i], strlen(params[i])))
524 png_chunk_report(png_ptr,
"Invalid format for pCAL parameter",
525 PNG_CHUNK_WRITE_ERROR);
530 info_ptr->pcal_purpose = png_voidcast(png_charp,
531 png_malloc_warn(png_ptr, length));
533 if (info_ptr->pcal_purpose == NULL)
535 png_chunk_report(png_ptr,
"Insufficient memory for pCAL purpose",
536 PNG_CHUNK_WRITE_ERROR);
540 memcpy(info_ptr->pcal_purpose, purpose, length);
542 info_ptr->free_me |= PNG_FREE_PCAL;
544 png_debug(3,
"storing X0, X1, type, and nparams in info");
545 info_ptr->pcal_X0 = X0;
546 info_ptr->pcal_X1 = X1;
547 info_ptr->pcal_type = (png_byte)type;
548 info_ptr->pcal_nparams = (png_byte)nparams;
550 length = strlen(units) + 1;
551 png_debug1(3,
"allocating units for info (%lu bytes)",
552 (
unsigned long)length);
554 info_ptr->pcal_units = png_voidcast(png_charp,
555 png_malloc_warn(png_ptr, length));
557 if (info_ptr->pcal_units == NULL)
559 png_warning(png_ptr,
"Insufficient memory for pCAL units");
563 memcpy(info_ptr->pcal_units, units, length);
565 info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,
566 (
size_t)(((
unsigned int)nparams + 1) * (
sizeof (png_charp)))));
568 if (info_ptr->pcal_params == NULL)
570 png_warning(png_ptr,
"Insufficient memory for pCAL params");
574 memset(info_ptr->pcal_params, 0, ((
unsigned int)nparams + 1) *
575 (sizeof (png_charp)));
577 for (i = 0; i < nparams; i++)
579 length = strlen(params[i]) + 1;
580 png_debug2(3,
"allocating parameter %d for info (%lu bytes)", i,
581 (
unsigned long)length);
583 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
585 if (info_ptr->pcal_params[i] == NULL)
587 png_warning(png_ptr,
"Insufficient memory for pCAL parameter");
591 memcpy(info_ptr->pcal_params[i], params[i], length);
594 info_ptr->valid |= PNG_INFO_pCAL;
598#ifdef PNG_sCAL_SUPPORTED
600png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,
601 int unit, png_const_charp swidth, png_const_charp sheight)
603 size_t lengthw = 0, lengthh = 0;
605 png_debug1(1,
"in %s storage function",
"sCAL");
607 if (png_ptr == NULL || info_ptr == NULL)
613 if (unit != 1 && unit != 2)
614 png_error(png_ptr,
"Invalid sCAL unit");
616 if (swidth == NULL || (lengthw = strlen(swidth)) == 0 ||
617 swidth[0] == 45 || !png_check_fp_string(swidth, lengthw))
618 png_error(png_ptr,
"Invalid sCAL width");
620 if (sheight == NULL || (lengthh = strlen(sheight)) == 0 ||
621 sheight[0] == 45 || !png_check_fp_string(sheight, lengthh))
622 png_error(png_ptr,
"Invalid sCAL height");
624 info_ptr->scal_unit = (png_byte)unit;
628 png_debug1(3,
"allocating unit for info (%u bytes)", (
unsigned int)lengthw);
630 info_ptr->scal_s_width = png_voidcast(png_charp,
631 png_malloc_warn(png_ptr, lengthw));
633 if (info_ptr->scal_s_width == NULL)
635 png_warning(png_ptr,
"Memory allocation failed while processing sCAL");
640 memcpy(info_ptr->scal_s_width, swidth, lengthw);
644 png_debug1(3,
"allocating unit for info (%u bytes)", (
unsigned int)lengthh);
646 info_ptr->scal_s_height = png_voidcast(png_charp,
647 png_malloc_warn(png_ptr, lengthh));
649 if (info_ptr->scal_s_height == NULL)
651 png_free(png_ptr, info_ptr->scal_s_width);
652 info_ptr->scal_s_width = NULL;
654 png_warning(png_ptr,
"Memory allocation failed while processing sCAL");
658 memcpy(info_ptr->scal_s_height, sheight, lengthh);
660 info_ptr->free_me |= PNG_FREE_SCAL;
661 info_ptr->valid |= PNG_INFO_sCAL;
664# ifdef PNG_FLOATING_POINT_SUPPORTED
666png_set_sCAL(png_const_structrp png_ptr, png_inforp info_ptr,
int unit,
667 double width,
double height)
669 png_debug1(1,
"in %s storage function",
"sCAL");
673 png_warning(png_ptr,
"Invalid sCAL width ignored");
675 else if (height <= 0)
676 png_warning(png_ptr,
"Invalid sCAL height ignored");
681 char swidth[PNG_sCAL_MAX_DIGITS+1];
682 char sheight[PNG_sCAL_MAX_DIGITS+1];
684 png_ascii_from_fp(png_ptr, swidth, (
sizeof swidth), width,
686 png_ascii_from_fp(png_ptr, sheight, (
sizeof sheight), height,
689 png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
694# ifdef PNG_FIXED_POINT_SUPPORTED
696png_set_sCAL_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
int unit,
697 png_fixed_point width, png_fixed_point height)
699 png_debug1(1,
"in %s storage function",
"sCAL");
703 png_warning(png_ptr,
"Invalid sCAL width ignored");
705 else if (height <= 0)
706 png_warning(png_ptr,
"Invalid sCAL height ignored");
711 char swidth[PNG_sCAL_MAX_DIGITS+1];
712 char sheight[PNG_sCAL_MAX_DIGITS+1];
714 png_ascii_from_fixed(png_ptr, swidth, (
sizeof swidth), width);
715 png_ascii_from_fixed(png_ptr, sheight, (
sizeof sheight), height);
717 png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
723#ifdef PNG_pHYs_SUPPORTED
725png_set_pHYs(png_const_structrp png_ptr, png_inforp info_ptr,
726 png_uint_32 res_x, png_uint_32 res_y,
int unit_type)
728 png_debug1(1,
"in %s storage function",
"pHYs");
730 if (png_ptr == NULL || info_ptr == NULL)
733 info_ptr->x_pixels_per_unit = res_x;
734 info_ptr->y_pixels_per_unit = res_y;
735 info_ptr->phys_unit_type = (png_byte)unit_type;
736 info_ptr->valid |= PNG_INFO_pHYs;
741png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
742 png_const_colorp palette,
int num_palette)
745 png_uint_32 max_palette_length;
747 png_debug1(1,
"in %s storage function",
"PLTE");
749 if (png_ptr == NULL || info_ptr == NULL)
752 max_palette_length = (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ?
753 (1 << info_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH;
755 if (num_palette < 0 || num_palette > (
int) max_palette_length)
757 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
758 png_error(png_ptr,
"Invalid palette length");
762 png_warning(png_ptr,
"Invalid palette length");
768 if ((num_palette > 0 && palette == NULL) ||
770# ifdef PNG_MNG_FEATURES_SUPPORTED
771 && (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0
775 png_error(png_ptr,
"Invalid palette");
785 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
791 png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr,
792 PNG_MAX_PALETTE_LENGTH * (
sizeof (png_color))));
795 memcpy(png_ptr->palette, palette, (
unsigned int)num_palette *
796 (sizeof (png_color)));
798 info_ptr->palette = png_ptr->palette;
799 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
800 info_ptr->free_me |= PNG_FREE_PLTE;
801 info_ptr->valid |= PNG_INFO_PLTE;
804#ifdef PNG_sBIT_SUPPORTED
806png_set_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
807 png_const_color_8p sig_bit)
809 png_debug1(1,
"in %s storage function",
"sBIT");
811 if (png_ptr == NULL || info_ptr == NULL || sig_bit == NULL)
814 info_ptr->sig_bit = *sig_bit;
815 info_ptr->valid |= PNG_INFO_sBIT;
819#ifdef PNG_sRGB_SUPPORTED
821png_set_sRGB(png_const_structrp png_ptr, png_inforp info_ptr,
int srgb_intent)
823 png_debug1(1,
"in %s storage function",
"sRGB");
825 if (png_ptr == NULL || info_ptr == NULL)
828 info_ptr->rendering_intent = srgb_intent;
829 info_ptr->valid |= PNG_INFO_sRGB;
833png_set_sRGB_gAMA_and_cHRM(png_const_structrp png_ptr, png_inforp info_ptr,
836 png_debug1(1,
"in %s storage function",
"sRGB_gAMA_and_cHRM");
838 if (png_ptr == NULL || info_ptr == NULL)
841 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
843# ifdef PNG_gAMA_SUPPORTED
844 png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE);
847# ifdef PNG_cHRM_SUPPORTED
848 png_set_cHRM_fixed(png_ptr, info_ptr,
859#ifdef PNG_iCCP_SUPPORTED
861png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
862 png_const_charp name,
int compression_type,
863 png_const_bytep profile, png_uint_32 proflen)
865 png_charp new_iccp_name;
866 png_bytep new_iccp_profile;
869 png_debug1(1,
"in %s storage function",
"iCCP");
871 if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
874 if (compression_type != PNG_COMPRESSION_TYPE_BASE)
875 png_app_error(png_ptr,
"Invalid iCCP compression method");
877 length = strlen(name)+1;
878 new_iccp_name = png_voidcast(png_charp, png_malloc_warn(png_ptr, length));
880 if (new_iccp_name == NULL)
882 png_benign_error(png_ptr,
"Insufficient memory to process iCCP chunk");
887 memcpy(new_iccp_name, name, length);
888 new_iccp_profile = png_voidcast(png_bytep,
889 png_malloc_warn(png_ptr, proflen));
891 if (new_iccp_profile == NULL)
893 png_free(png_ptr, new_iccp_name);
894 png_benign_error(png_ptr,
895 "Insufficient memory to process iCCP profile");
900 memcpy(new_iccp_profile, profile, proflen);
902 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
904 info_ptr->iccp_proflen = proflen;
905 info_ptr->iccp_name = new_iccp_name;
906 info_ptr->iccp_profile = new_iccp_profile;
907 info_ptr->free_me |= PNG_FREE_ICCP;
908 info_ptr->valid |= PNG_INFO_iCCP;
912#ifdef PNG_TEXT_SUPPORTED
914png_set_text(png_const_structrp png_ptr, png_inforp info_ptr,
915 png_const_textp text_ptr,
int num_text)
918 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
921 png_error(png_ptr,
"Insufficient memory to store text");
925png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
926 png_const_textp text_ptr,
int num_text)
930 png_debug1(1,
"in text storage function, chunk typeid = 0x%lx",
931 png_ptr == NULL ? 0xabadca11UL : (
unsigned long)png_ptr->chunk_name);
933 if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL)
941 if (num_text > info_ptr->max_text - info_ptr->num_text)
943 int old_num_text = info_ptr->num_text;
945 png_textp new_text = NULL;
948 max_text = old_num_text;
949 if (num_text <= INT_MAX - max_text)
951 max_text += num_text;
954 if (max_text < INT_MAX-8)
955 max_text = (max_text + 8) & ~0x7;
963 new_text = png_voidcast(png_textp,png_realloc_array(png_ptr,
964 info_ptr->text, old_num_text, max_text-old_num_text,
968 if (new_text == NULL)
970 png_chunk_report(png_ptr,
"too many text chunks",
971 PNG_CHUNK_WRITE_ERROR);
976 png_free(png_ptr, info_ptr->text);
978 info_ptr->text = new_text;
979 info_ptr->free_me |= PNG_FREE_TEXT;
980 info_ptr->max_text = max_text;
983 png_debug1(3,
"allocated %d entries for info_ptr->text", max_text);
986 for (i = 0; i < num_text; i++)
988 size_t text_length, key_len;
989 size_t lang_len, lang_key_len;
990 png_textp textp = &(info_ptr->text[info_ptr->num_text]);
992 if (text_ptr[i].key == NULL)
995 if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE ||
996 text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)
998 png_chunk_report(png_ptr,
"text compression mode is out of range",
999 PNG_CHUNK_WRITE_ERROR);
1003 key_len = strlen(text_ptr[i].key);
1005 if (text_ptr[i].compression <= 0)
1012# ifdef PNG_iTXt_SUPPORTED
1016 if (text_ptr[i].lang != NULL)
1017 lang_len = strlen(text_ptr[i].lang);
1022 if (text_ptr[i].lang_key != NULL)
1023 lang_key_len = strlen(text_ptr[i].lang_key);
1030 png_chunk_report(png_ptr,
"iTXt chunk not supported",
1031 PNG_CHUNK_WRITE_ERROR);
1036 if (text_ptr[i].text == NULL || text_ptr[i].text[0] ==
'\0')
1039# ifdef PNG_iTXt_SUPPORTED
1040 if (text_ptr[i].compression > 0)
1041 textp->compression = PNG_ITXT_COMPRESSION_NONE;
1045 textp->compression = PNG_TEXT_COMPRESSION_NONE;
1050 text_length = strlen(text_ptr[i].text);
1051 textp->compression = text_ptr[i].compression;
1054 textp->key = png_voidcast(png_charp,png_malloc_base(png_ptr,
1055 key_len + text_length + lang_len + lang_key_len + 4));
1057 if (textp->key == NULL)
1059 png_chunk_report(png_ptr,
"text chunk: out of memory",
1060 PNG_CHUNK_WRITE_ERROR);
1065 png_debug2(2,
"Allocated %lu bytes at %p in png_set_text",
1066 (
unsigned long)(png_uint_32)
1067 (key_len + lang_len + lang_key_len + text_length + 4),
1070 memcpy(textp->key, text_ptr[i].key, key_len);
1071 *(textp->key + key_len) =
'\0';
1073 if (text_ptr[i].compression > 0)
1075 textp->lang = textp->key + key_len + 1;
1076 memcpy(textp->lang, text_ptr[i].lang, lang_len);
1077 *(textp->lang + lang_len) =
'\0';
1078 textp->lang_key = textp->lang + lang_len + 1;
1079 memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
1080 *(textp->lang_key + lang_key_len) =
'\0';
1081 textp->text = textp->lang_key + lang_key_len + 1;
1087 textp->lang_key=NULL;
1088 textp->text = textp->key + key_len + 1;
1091 if (text_length != 0)
1092 memcpy(textp->text, text_ptr[i].text, text_length);
1094 *(textp->text + text_length) =
'\0';
1096# ifdef PNG_iTXt_SUPPORTED
1097 if (textp->compression > 0)
1099 textp->text_length = 0;
1100 textp->itxt_length = text_length;
1106 textp->text_length = text_length;
1107 textp->itxt_length = 0;
1110 info_ptr->num_text++;
1111 png_debug1(3,
"transferred text chunk %d", info_ptr->num_text);
1118#ifdef PNG_tIME_SUPPORTED
1120png_set_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
1121 png_const_timep mod_time)
1123 png_debug1(1,
"in %s storage function",
"tIME");
1125 if (png_ptr == NULL || info_ptr == NULL || mod_time == NULL ||
1126 (png_ptr->mode & PNG_WROTE_tIME) != 0)
1129 if (mod_time->month == 0 || mod_time->month > 12 ||
1130 mod_time->day == 0 || mod_time->day > 31 ||
1131 mod_time->hour > 23 || mod_time->minute > 59 ||
1132 mod_time->second > 60)
1134 png_warning(png_ptr,
"Ignoring invalid time value");
1139 info_ptr->mod_time = *mod_time;
1140 info_ptr->valid |= PNG_INFO_tIME;
1144#ifdef PNG_tRNS_SUPPORTED
1146png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
1147 png_const_bytep trans_alpha,
int num_trans, png_const_color_16p trans_color)
1149 png_debug1(1,
"in %s storage function",
"tRNS");
1151 if (png_ptr == NULL || info_ptr == NULL)
1155 if (trans_alpha != NULL)
1166 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
1168 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
1171 info_ptr->trans_alpha = png_voidcast(png_bytep,
1172 png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH));
1173 memcpy(info_ptr->trans_alpha, trans_alpha, (
size_t)num_trans);
1175 info_ptr->free_me |= PNG_FREE_TRNS;
1176 info_ptr->valid |= PNG_INFO_tRNS;
1178 png_ptr->trans_alpha = info_ptr->trans_alpha;
1181 if (trans_color != NULL)
1183#ifdef PNG_WARNINGS_SUPPORTED
1184 if (info_ptr->bit_depth < 16)
1186 int sample_max = (1 << info_ptr->bit_depth) - 1;
1188 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
1189 trans_color->gray > sample_max) ||
1190 (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
1191 (trans_color->red > sample_max ||
1192 trans_color->green > sample_max ||
1193 trans_color->blue > sample_max)))
1194 png_warning(png_ptr,
1195 "tRNS chunk has out-of-range samples for bit_depth");
1199 info_ptr->trans_color = *trans_color;
1205 info_ptr->num_trans = (png_uint_16)num_trans;
1209 info_ptr->free_me |= PNG_FREE_TRNS;
1210 info_ptr->valid |= PNG_INFO_tRNS;
1215#ifdef PNG_sPLT_SUPPORTED
1217png_set_sPLT(png_const_structrp png_ptr,
1218 png_inforp info_ptr, png_const_sPLT_tp entries,
int nentries)
1230 png_debug1(1,
"in %s storage function",
"sPLT");
1232 if (png_ptr == NULL || info_ptr == NULL || nentries <= 0 || entries == NULL)
1238 np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr,
1239 info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries,
1245 png_chunk_report(png_ptr,
"too many sPLT chunks", PNG_CHUNK_WRITE_ERROR);
1249 png_free(png_ptr, info_ptr->splt_palettes);
1251 info_ptr->splt_palettes = np;
1252 info_ptr->free_me |= PNG_FREE_SPLT;
1254 np += info_ptr->splt_palettes_num;
1261 if (entries->name == NULL || entries->entries == NULL)
1264 png_app_error(png_ptr,
"png_set_sPLT: invalid sPLT");
1269 np->depth = entries->depth;
1274 length = strlen(entries->name) + 1;
1275 np->name = png_voidcast(png_charp, png_malloc_base(png_ptr, length));
1277 if (np->name == NULL)
1280 memcpy(np->name, entries->name, length);
1286 np->entries = png_voidcast(png_sPLT_entryp, png_malloc_array(png_ptr,
1287 entries->nentries, sizeof (png_sPLT_entry)));
1289 if (np->entries == NULL)
1291 png_free(png_ptr, np->name);
1296 np->nentries = entries->nentries;
1300 memcpy(np->entries, entries->entries,
1301 (
unsigned int)entries->nentries * sizeof (png_sPLT_entry));
1306 info_ptr->valid |= PNG_INFO_sPLT;
1307 ++(info_ptr->splt_palettes_num);
1314 png_chunk_report(png_ptr,
"sPLT out of memory", PNG_CHUNK_WRITE_ERROR);
1318#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
1320check_location(png_const_structrp png_ptr,
int location)
1322 location &= (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT);
1328 if (location == 0 && (png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
1331 png_app_warning(png_ptr,
1332 "png_set_unknown_chunks now expects a valid location");
1334 location = (png_byte)(png_ptr->mode &
1335 (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));
1342 png_error(png_ptr,
"invalid location in png_set_unknown_chunks");
1347 while (location != (location & -location))
1348 location &= ~(location & -location);
1353 return (png_byte)location;
1357png_set_unknown_chunks(png_const_structrp png_ptr,
1358 png_inforp info_ptr, png_const_unknown_chunkp unknowns,
int num_unknowns)
1360 png_unknown_chunkp np;
1362 if (png_ptr == NULL || info_ptr == NULL || num_unknowns <= 0 ||
1372# if !defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \
1373 defined(PNG_READ_SUPPORTED)
1374 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
1376 png_app_error(png_ptr,
"no unknown chunk support on read");
1381# if !defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \
1382 defined(PNG_WRITE_SUPPORTED)
1383 if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
1385 png_app_error(png_ptr,
"no unknown chunk support on write");
1396 np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr,
1397 info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns,
1402 png_chunk_report(png_ptr,
"too many unknown chunks",
1403 PNG_CHUNK_WRITE_ERROR);
1407 png_free(png_ptr, info_ptr->unknown_chunks);
1409 info_ptr->unknown_chunks = np;
1410 info_ptr->free_me |= PNG_FREE_UNKN;
1412 np += info_ptr->unknown_chunks_num;
1417 for (; num_unknowns > 0; --num_unknowns, ++unknowns)
1419 memcpy(np->name, unknowns->name, (
sizeof np->name));
1420 np->name[(
sizeof np->name)-1] =
'\0';
1421 np->location = check_location(png_ptr, unknowns->location);
1423 if (unknowns->size == 0)
1431 np->data = png_voidcast(png_bytep,
1432 png_malloc_base(png_ptr, unknowns->size));
1434 if (np->data == NULL)
1436 png_chunk_report(png_ptr,
"unknown chunk: out of memory",
1437 PNG_CHUNK_WRITE_ERROR);
1442 memcpy(np->data, unknowns->data, unknowns->size);
1443 np->size = unknowns->size;
1451 ++(info_ptr->unknown_chunks_num);
1456png_set_unknown_chunk_location(png_const_structrp png_ptr, png_inforp info_ptr,
1457 int chunk,
int location)
1464 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 &&
1465 chunk < info_ptr->unknown_chunks_num)
1467 if ((location & (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)) == 0)
1469 png_app_error(png_ptr,
"invalid unknown chunk location");
1471 if (((
unsigned int)location & PNG_HAVE_IDAT) != 0)
1472 location = PNG_AFTER_IDAT;
1475 location = PNG_HAVE_IHDR;
1478 info_ptr->unknown_chunks[chunk].location =
1479 check_location(png_ptr, location);
1484#ifdef PNG_MNG_FEATURES_SUPPORTED
1486png_permit_mng_features(png_structrp png_ptr, png_uint_32 mng_features)
1488 png_debug(1,
"in png_permit_mng_features");
1490 if (png_ptr == NULL)
1493 png_ptr->mng_features_permitted = mng_features & PNG_ALL_MNG_FEATURES;
1495 return png_ptr->mng_features_permitted;
1499#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
1501add_one_chunk(png_bytep list,
unsigned int count, png_const_bytep add,
int keep)
1508 for (i=0; i<count; ++i, list += 5)
1510 if (memcmp(list, add, 4) == 0)
1512 list[4] = (png_byte)keep;
1518 if (keep != PNG_HANDLE_CHUNK_AS_DEFAULT)
1521 memcpy(list, add, 4);
1522 list[4] = (png_byte)keep;
1529png_set_keep_unknown_chunks(png_structrp png_ptr,
int keep,
1530 png_const_bytep chunk_list,
int num_chunks_in)
1533 unsigned int num_chunks, old_num_chunks;
1535 if (png_ptr == NULL)
1538 if (keep < 0 || keep >= PNG_HANDLE_CHUNK_LAST)
1540 png_app_error(png_ptr,
"png_set_keep_unknown_chunks: invalid keep");
1545 if (num_chunks_in <= 0)
1547 png_ptr->unknown_default = keep;
1550 if (num_chunks_in == 0)
1554 if (num_chunks_in < 0)
1559 static const png_byte chunks_to_ignore[] = {
1560 98, 75, 71, 68,
'\0',
1561 99, 72, 82, 77,
'\0',
1562 99, 73, 67, 80,
'\0',
1563 99, 76, 76, 73,
'\0',
1564 101, 88, 73, 102,
'\0',
1565 103, 65, 77, 65,
'\0',
1566 104, 73, 83, 84,
'\0',
1567 105, 67, 67, 80,
'\0',
1568 105, 84, 88, 116,
'\0',
1569 109, 68, 67, 86,
'\0',
1570 111, 70, 70, 115,
'\0',
1571 112, 67, 65, 76,
'\0',
1572 112, 72, 89, 115,
'\0',
1573 115, 66, 73, 84,
'\0',
1574 115, 67, 65, 76,
'\0',
1575 115, 80, 76, 84,
'\0',
1576 115, 84, 69, 82,
'\0',
1577 115, 82, 71, 66,
'\0',
1578 116, 69, 88, 116,
'\0',
1579 116, 73, 77, 69,
'\0',
1580 122, 84, 88, 116,
'\0'
1583 chunk_list = chunks_to_ignore;
1584 num_chunks = (
unsigned int)(
sizeof chunks_to_ignore)/5U;
1589 if (chunk_list == NULL)
1594 png_app_error(png_ptr,
"png_set_keep_unknown_chunks: no chunk list");
1599 num_chunks = (
unsigned int)num_chunks_in;
1602 old_num_chunks = png_ptr->num_chunk_list;
1603 if (png_ptr->chunk_list == NULL)
1608 if (num_chunks + old_num_chunks > UINT_MAX/5)
1610 png_app_error(png_ptr,
"png_set_keep_unknown_chunks: too many chunks");
1621 new_list = png_voidcast(png_bytep, png_malloc(png_ptr,
1622 5 * (num_chunks + old_num_chunks)));
1624 if (old_num_chunks > 0)
1625 memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks);
1628 else if (old_num_chunks > 0)
1629 new_list = png_ptr->chunk_list;
1639 if (new_list != NULL)
1641 png_const_bytep inlist;
1645 for (i=0; i<num_chunks; ++i)
1647 old_num_chunks = add_one_chunk(new_list, old_num_chunks,
1648 chunk_list+5*i, keep);
1653 for (i=0, inlist=outlist=new_list; i<old_num_chunks; ++i, inlist += 5)
1657 if (outlist != inlist)
1658 memcpy(outlist, inlist, 5);
1665 if (num_chunks == 0)
1667 if (png_ptr->chunk_list != new_list)
1668 png_free(png_ptr, new_list);
1677 png_ptr->num_chunk_list = num_chunks;
1679 if (png_ptr->chunk_list != new_list)
1681 if (png_ptr->chunk_list != NULL)
1682 png_free(png_ptr, png_ptr->chunk_list);
1684 png_ptr->chunk_list = new_list;
1689#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
1691png_set_read_user_chunk_fn(png_structrp png_ptr, png_voidp user_chunk_ptr,
1692 png_user_chunk_ptr read_user_chunk_fn)
1694 png_debug(1,
"in png_set_read_user_chunk_fn");
1696 if (png_ptr == NULL)
1699 png_ptr->read_user_chunk_fn = read_user_chunk_fn;
1700 png_ptr->user_chunk_ptr = user_chunk_ptr;
1704#ifdef PNG_INFO_IMAGE_SUPPORTED
1706png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr,
1707 png_bytepp row_pointers)
1709 png_debug(1,
"in png_set_rows");
1711 if (png_ptr == NULL || info_ptr == NULL)
1714 if (info_ptr->row_pointers != NULL &&
1715 (info_ptr->row_pointers != row_pointers))
1716 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
1718 info_ptr->row_pointers = row_pointers;
1720 if (row_pointers != NULL)
1721 info_ptr->valid |= PNG_INFO_IDAT;
1726png_set_compression_buffer_size(png_structrp png_ptr,
size_t size)
1728 png_debug(1,
"in png_set_compression_buffer_size");
1730 if (png_ptr == NULL)
1733 if (size == 0 || size > PNG_UINT_31_MAX)
1734 png_error(png_ptr,
"invalid compression buffer size");
1736# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1737 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
1739 png_ptr->IDAT_read_size = (png_uint_32)size;
1744# ifdef PNG_WRITE_SUPPORTED
1745 if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
1747 if (png_ptr->zowner != 0)
1749 png_warning(png_ptr,
1750 "Compression buffer size cannot be changed because it is in use");
1759 if (size > ZLIB_IO_MAX)
1761 png_warning(png_ptr,
1762 "Compression buffer size limited to system maximum");
1772 png_warning(png_ptr,
1773 "Compression buffer size cannot be reduced below 6");
1778 if (png_ptr->zbuffer_size != size)
1780 png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
1781 png_ptr->zbuffer_size = (uInt)size;
1788png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr,
int mask)
1790 if (png_ptr != NULL && info_ptr != NULL)
1791 info_ptr->valid &= (
unsigned int)(~mask);
1795#ifdef PNG_SET_USER_LIMITS_SUPPORTED
1798png_set_user_limits(png_structrp png_ptr, png_uint_32 user_width_max,
1799 png_uint_32 user_height_max)
1801 png_debug(1,
"in png_set_user_limits");
1807 if (png_ptr == NULL)
1810 png_ptr->user_width_max = user_width_max;
1811 png_ptr->user_height_max = user_height_max;
1816png_set_chunk_cache_max(png_structrp png_ptr, png_uint_32 user_chunk_cache_max)
1818 png_debug(1,
"in png_set_chunk_cache_max");
1820 if (png_ptr != NULL)
1821 png_ptr->user_chunk_cache_max = user_chunk_cache_max;
1826png_set_chunk_malloc_max(png_structrp png_ptr,
1827 png_alloc_size_t user_chunk_malloc_max)
1829 png_debug(1,
"in png_set_chunk_malloc_max");
1836 if (png_ptr != NULL)
1838 if (user_chunk_malloc_max == 0U)
1840# ifdef PNG_MAX_MALLOC_64K
1841 png_ptr->user_chunk_malloc_max = 65536U;
1843 png_ptr->user_chunk_malloc_max = PNG_SIZE_MAX;
1847 png_ptr->user_chunk_malloc_max = user_chunk_malloc_max;
1853#ifdef PNG_BENIGN_ERRORS_SUPPORTED
1855png_set_benign_errors(png_structrp png_ptr,
int allowed)
1857 png_debug(1,
"in png_set_benign_errors");
1866 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN |
1867 PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN;
1870 png_ptr->flags &= ~(PNG_FLAG_BENIGN_ERRORS_WARN |
1871 PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN);
1875#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
1885png_set_check_for_invalid_index(png_structrp png_ptr,
int allowed)
1887 png_debug(1,
"in png_set_check_for_invalid_index");
1890 png_ptr->num_palette_max = 0;
1893 png_ptr->num_palette_max = -1;
1897#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) || \
1898 defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
1910png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
1912#ifdef PNG_WARNINGS_SUPPORTED
1913 png_const_charp orig_key = key;
1915 png_uint_32 key_len = 0;
1916 int bad_character = 0;
1919 png_debug(1,
"in png_check_keyword");
1927 while (*key && key_len < 79)
1929 png_byte ch = (png_byte)*key++;
1931 if ((ch > 32 && ch <= 126) || (ch >= 161 ))
1933 *new_key++ = ch; ++key_len; space = 0;
1936 else if (space == 0)
1941 *new_key++ = 32; ++key_len; space = 1;
1948 else if (bad_character == 0)
1952 if (key_len > 0 && space != 0)
1954 --key_len; --new_key;
1955 if (bad_character == 0)
1965#ifdef PNG_WARNINGS_SUPPORTED
1968 png_warning(png_ptr,
"keyword truncated");
1970 else if (bad_character != 0)
1972 PNG_WARNING_PARAMETERS(p)
1974 png_warning_parameter(p, 1, orig_key);
1975 png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_02x, bad_character);
1977 png_formatted_warning(png_ptr, p,
"keyword \"@1\": bad character '0x@2'");