16typedef png_libpng_version_1_6_53 Your_png_h_is_not_version_1_6_53;
25#define PNG_CHUNK(cHNK, index) != (index) || ((index)+1)
27#if 0 PNG_KNOWN_CHUNKS < 0
28# error PNG_KNOWN_CHUNKS chunk definitions are not in order
37#define PNG_CHUNK(cHNK, index) !PNG_CHUNK_NAME_VALID(png_ ## cHNK) ||
40# error png_cHNK not defined for some known cHNK
51#ifdef PNG_READ_SUPPORTED
53png_set_sig_bytes(png_structrp png_ptr,
int num_bytes)
55 unsigned int nb = (
unsigned int)num_bytes;
57 png_debug(1,
"in png_set_sig_bytes");
66 png_error(png_ptr,
"Too many bytes for PNG signature");
68 png_ptr->sig_bytes = (png_byte)nb;
80png_sig_cmp(png_const_bytep sig,
size_t start,
size_t num_to_check)
82 static const png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
87 else if (num_to_check < 1)
93 if (start + num_to_check > 8)
94 num_to_check = 8 - start;
96 return memcmp(&sig[start], &png_signature[start], num_to_check);
101#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
104png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED)
106 png_alloc_size_t num_bytes = size;
117 if (size != 0 && items >= (~(png_alloc_size_t)0) / size)
119 png_warning(png_voidcast(png_structrp, png_ptr),
120 "Potential overflow in png_zalloc()");
125 return png_malloc_warn(png_voidcast(png_structrp, png_ptr), num_bytes);
130png_zfree(voidpf png_ptr, voidpf ptr)
132 png_free(png_voidcast(png_const_structrp,png_ptr), ptr);
139png_reset_crc(png_structrp png_ptr)
142 png_ptr->crc = (png_uint_32)crc32(0, Z_NULL, 0);
151png_calculate_crc(png_structrp png_ptr, png_const_bytep ptr,
size_t length)
155 if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0)
157 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
158 (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
164 if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0)
173 if (need_crc != 0 && length > 0)
175 uLong crc = png_ptr->crc;
179 uInt safe_length = (uInt)length;
181 if (safe_length == 0)
182 safe_length = (uInt)-1;
185 crc = crc32(crc, ptr, safe_length);
192 length -= safe_length;
197 png_ptr->crc = (png_uint_32)crc;
205png_user_version_check(png_structrp png_ptr, png_const_charp user_png_ver)
212 if (user_png_ver != NULL)
220 if (user_png_ver[i] != PNG_LIBPNG_VER_STRING[i])
221 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
222 if (user_png_ver[i] ==
'.')
224 }
while (found_dots < 2 && user_png_ver[i] != 0 &&
225 PNG_LIBPNG_VER_STRING[i] != 0);
229 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
231 if ((png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) != 0)
233#ifdef PNG_WARNINGS_SUPPORTED
237 pos = png_safecat(m, (
sizeof m), pos,
238 "Application built with libpng-");
239 pos = png_safecat(m, (
sizeof m), pos, user_png_ver);
240 pos = png_safecat(m, (
sizeof m), pos,
" but running with ");
241 pos = png_safecat(m, (
sizeof m), pos, PNG_LIBPNG_VER_STRING);
244 png_warning(png_ptr, m);
257PNG_FUNCTION(png_structp ,
258png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
259 png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
260 png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED)
262 png_struct create_struct;
263# ifdef PNG_SETJMP_SUPPORTED
264 jmp_buf create_jmp_buf;
271 memset(&create_struct, 0, (
sizeof create_struct));
273# ifdef PNG_USER_LIMITS_SUPPORTED
274 create_struct.user_width_max = PNG_USER_WIDTH_MAX;
275 create_struct.user_height_max = PNG_USER_HEIGHT_MAX;
277# ifdef PNG_USER_CHUNK_CACHE_MAX
278 create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX;
281# if PNG_USER_CHUNK_MALLOC_MAX > 0
282 create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX;
285# elif defined PNG_MAX_MALLOC_64K
286 create_struct.user_chunk_malloc_max = 65536U;
289 create_struct.user_chunk_malloc_max = PNG_SIZE_MAX;
296# ifdef PNG_USER_MEM_SUPPORTED
297 png_set_mem_fn(&create_struct, mem_ptr, malloc_fn, free_fn);
300 PNG_UNUSED(malloc_fn)
309 png_set_error_fn(&create_struct, error_ptr, error_fn, warn_fn);
311# ifdef PNG_SETJMP_SUPPORTED
312 if (!setjmp(create_jmp_buf))
315# ifdef PNG_SETJMP_SUPPORTED
321 create_struct.jmp_buf_ptr = &create_jmp_buf;
322 create_struct.jmp_buf_size = 0;
323 create_struct.longjmp_fn = longjmp;
327 if (png_user_version_check(&create_struct, user_png_ver) != 0)
329 png_structrp png_ptr = png_voidcast(png_structrp,
330 png_malloc_warn(&create_struct, (
sizeof *png_ptr)));
337 create_struct.zstream.zalloc = png_zalloc;
338 create_struct.zstream.zfree = png_zfree;
339 create_struct.zstream.opaque = png_ptr;
341# ifdef PNG_SETJMP_SUPPORTED
343 create_struct.jmp_buf_ptr = NULL;
344 create_struct.jmp_buf_size = 0;
345 create_struct.longjmp_fn = 0;
348 *png_ptr = create_struct;
363PNG_FUNCTION(png_infop,PNGAPI
364png_create_info_struct,(png_const_structrp png_ptr),PNG_ALLOCATED)
368 png_debug(1,
"in png_create_info_struct");
378 info_ptr = png_voidcast(png_inforp, png_malloc_base(png_ptr,
379 (
sizeof *info_ptr)));
381 if (info_ptr != NULL)
382 memset(info_ptr, 0, (
sizeof *info_ptr));
396png_destroy_info_struct(png_const_structrp png_ptr, png_infopp info_ptr_ptr)
398 png_inforp info_ptr = NULL;
400 png_debug(1,
"in png_destroy_info_struct");
405 if (info_ptr_ptr != NULL)
406 info_ptr = *info_ptr_ptr;
408 if (info_ptr != NULL)
416 *info_ptr_ptr = NULL;
418 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
419 memset(info_ptr, 0, (
sizeof *info_ptr));
420 png_free(png_ptr, info_ptr);
433PNG_FUNCTION(
void,PNGAPI
434png_info_init_3,(png_infopp ptr_ptr,
size_t png_info_struct_size),
437 png_inforp info_ptr = *ptr_ptr;
439 png_debug(1,
"in png_info_init_3");
441 if (info_ptr == NULL)
444 if ((
sizeof (png_info)) > png_info_struct_size)
449 info_ptr = png_voidcast(png_inforp, png_malloc_base(NULL,
450 (
sizeof *info_ptr)));
451 if (info_ptr == NULL)
457 memset(info_ptr, 0, (
sizeof *info_ptr));
461png_data_freer(png_const_structrp png_ptr, png_inforp info_ptr,
462 int freer, png_uint_32 mask)
464 png_debug(1,
"in png_data_freer");
466 if (png_ptr == NULL || info_ptr == NULL)
469 if (freer == PNG_DESTROY_WILL_FREE_DATA)
470 info_ptr->free_me |= mask;
472 else if (freer == PNG_USER_WILL_FREE_DATA)
473 info_ptr->free_me &= ~mask;
476 png_error(png_ptr,
"Unknown freer parameter in png_data_freer");
480png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
483 png_debug(1,
"in png_free_data");
485 if (png_ptr == NULL || info_ptr == NULL)
488#ifdef PNG_TEXT_SUPPORTED
490 if (info_ptr->text != NULL &&
491 ((mask & PNG_FREE_TEXT) & info_ptr->free_me) != 0)
495 png_free(png_ptr, info_ptr->text[num].key);
496 info_ptr->text[num].key = NULL;
503 for (i = 0; i < info_ptr->num_text; i++)
504 png_free(png_ptr, info_ptr->text[i].key);
506 png_free(png_ptr, info_ptr->text);
507 info_ptr->text = NULL;
508 info_ptr->num_text = 0;
509 info_ptr->max_text = 0;
514#ifdef PNG_tRNS_SUPPORTED
516 if (((mask & PNG_FREE_TRNS) & info_ptr->free_me) != 0)
518 info_ptr->valid &= ~PNG_INFO_tRNS;
519 png_free(png_ptr, info_ptr->trans_alpha);
520 info_ptr->trans_alpha = NULL;
521 info_ptr->num_trans = 0;
525#ifdef PNG_sCAL_SUPPORTED
527 if (((mask & PNG_FREE_SCAL) & info_ptr->free_me) != 0)
529 png_free(png_ptr, info_ptr->scal_s_width);
530 png_free(png_ptr, info_ptr->scal_s_height);
531 info_ptr->scal_s_width = NULL;
532 info_ptr->scal_s_height = NULL;
533 info_ptr->valid &= ~PNG_INFO_sCAL;
537#ifdef PNG_pCAL_SUPPORTED
539 if (((mask & PNG_FREE_PCAL) & info_ptr->free_me) != 0)
541 png_free(png_ptr, info_ptr->pcal_purpose);
542 png_free(png_ptr, info_ptr->pcal_units);
543 info_ptr->pcal_purpose = NULL;
544 info_ptr->pcal_units = NULL;
546 if (info_ptr->pcal_params != NULL)
550 for (i = 0; i < info_ptr->pcal_nparams; i++)
551 png_free(png_ptr, info_ptr->pcal_params[i]);
553 png_free(png_ptr, info_ptr->pcal_params);
554 info_ptr->pcal_params = NULL;
556 info_ptr->valid &= ~PNG_INFO_pCAL;
560#ifdef PNG_iCCP_SUPPORTED
562 if (((mask & PNG_FREE_ICCP) & info_ptr->free_me) != 0)
564 png_free(png_ptr, info_ptr->iccp_name);
565 png_free(png_ptr, info_ptr->iccp_profile);
566 info_ptr->iccp_name = NULL;
567 info_ptr->iccp_profile = NULL;
568 info_ptr->valid &= ~PNG_INFO_iCCP;
572#ifdef PNG_sPLT_SUPPORTED
574 if (info_ptr->splt_palettes != NULL &&
575 ((mask & PNG_FREE_SPLT) & info_ptr->free_me) != 0)
579 png_free(png_ptr, info_ptr->splt_palettes[num].name);
580 png_free(png_ptr, info_ptr->splt_palettes[num].entries);
581 info_ptr->splt_palettes[num].name = NULL;
582 info_ptr->splt_palettes[num].entries = NULL;
589 for (i = 0; i < info_ptr->splt_palettes_num; i++)
591 png_free(png_ptr, info_ptr->splt_palettes[i].name);
592 png_free(png_ptr, info_ptr->splt_palettes[i].entries);
595 png_free(png_ptr, info_ptr->splt_palettes);
596 info_ptr->splt_palettes = NULL;
597 info_ptr->splt_palettes_num = 0;
598 info_ptr->valid &= ~PNG_INFO_sPLT;
603#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
604 if (info_ptr->unknown_chunks != NULL &&
605 ((mask & PNG_FREE_UNKN) & info_ptr->free_me) != 0)
609 png_free(png_ptr, info_ptr->unknown_chunks[num].data);
610 info_ptr->unknown_chunks[num].data = NULL;
617 for (i = 0; i < info_ptr->unknown_chunks_num; i++)
618 png_free(png_ptr, info_ptr->unknown_chunks[i].data);
620 png_free(png_ptr, info_ptr->unknown_chunks);
621 info_ptr->unknown_chunks = NULL;
622 info_ptr->unknown_chunks_num = 0;
627#ifdef PNG_eXIf_SUPPORTED
629 if (((mask & PNG_FREE_EXIF) & info_ptr->free_me) != 0)
633 png_free(png_ptr, info_ptr->exif);
634 info_ptr->exif = NULL;
636 info_ptr->valid &= ~PNG_INFO_eXIf;
640#ifdef PNG_hIST_SUPPORTED
642 if (((mask & PNG_FREE_HIST) & info_ptr->free_me) != 0)
644 png_free(png_ptr, info_ptr->hist);
645 info_ptr->hist = NULL;
646 info_ptr->valid &= ~PNG_INFO_hIST;
651 if (((mask & PNG_FREE_PLTE) & info_ptr->free_me) != 0)
653 png_free(png_ptr, info_ptr->palette);
654 info_ptr->palette = NULL;
655 info_ptr->valid &= ~PNG_INFO_PLTE;
656 info_ptr->num_palette = 0;
659#ifdef PNG_INFO_IMAGE_SUPPORTED
661 if (((mask & PNG_FREE_ROWS) & info_ptr->free_me) != 0)
663 if (info_ptr->row_pointers != NULL)
666 for (row = 0; row < info_ptr->height; row++)
667 png_free(png_ptr, info_ptr->row_pointers[row]);
669 png_free(png_ptr, info_ptr->row_pointers);
670 info_ptr->row_pointers = NULL;
672 info_ptr->valid &= ~PNG_INFO_IDAT;
677 mask &= ~PNG_FREE_MUL;
679 info_ptr->free_me &= ~mask;
688png_get_io_ptr(png_const_structrp png_ptr)
693 return png_ptr->io_ptr;
696#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
697# ifdef PNG_STDIO_SUPPORTED
705png_init_io(png_structrp png_ptr, FILE *fp)
707 png_debug(1,
"in png_init_io");
712 png_ptr->io_ptr = (png_voidp)fp;
716# ifdef PNG_SAVE_INT_32_SUPPORTED
728png_save_int_32(png_bytep buf, png_int_32 i)
730 png_save_uint_32(buf, (png_uint_32)i);
734# ifdef PNG_TIME_RFC1123_SUPPORTED
739png_convert_to_rfc1123_buffer(
char out[29], png_const_timep ptime)
741 static const char short_months[12][4] =
742 {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
743 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"};
748 if (ptime->year > 9999 ||
749 ptime->month == 0 || ptime->month > 12 ||
750 ptime->day == 0 || ptime->day > 31 ||
751 ptime->hour > 23 || ptime->minute > 59 ||
757 char number_buf[5] = {0, 0, 0, 0, 0};
759# define APPEND_STRING(string) pos = png_safecat(out, 29, pos, (string))
760# define APPEND_NUMBER(format, value)\
761 APPEND_STRING(PNG_FORMAT_NUMBER(number_buf, format, (value)))
762# define APPEND(ch) if (pos < 28) out[pos++] = (ch)
764 APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (
unsigned)ptime->day);
766 APPEND_STRING(short_months[(ptime->month - 1)]);
768 APPEND_NUMBER(PNG_NUMBER_FORMAT_u, ptime->year);
770 APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (
unsigned)ptime->hour);
772 APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (
unsigned)ptime->minute);
774 APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (
unsigned)ptime->second);
775 APPEND_STRING(
" +0000");
786# if PNG_LIBPNG_VER < 10700
792png_const_charp PNGAPI
793png_convert_to_rfc1123(png_structrp png_ptr, png_const_timep ptime)
798 if (png_convert_to_rfc1123_buffer(png_ptr->time_buffer, ptime) == 0)
799 png_warning(png_ptr,
"Ignoring invalid time value");
802 return png_ptr->time_buffer;
812png_const_charp PNGAPI
813png_get_copyright(png_const_structrp png_ptr)
816#ifdef PNG_STRING_COPYRIGHT
817 return PNG_STRING_COPYRIGHT
819 return PNG_STRING_NEWLINE \
820 "libpng version 1.6.53" PNG_STRING_NEWLINE \
821 "Copyright (c) 2018-2025 Cosmin Truta" PNG_STRING_NEWLINE \
822 "Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson" \
824 "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
825 "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
838png_const_charp PNGAPI
839png_get_libpng_ver(png_const_structrp png_ptr)
842 return png_get_header_ver(png_ptr);
845png_const_charp PNGAPI
846png_get_header_ver(png_const_structrp png_ptr)
850 return PNG_LIBPNG_VER_STRING;
853png_const_charp PNGAPI
854png_get_header_version(png_const_structrp png_ptr)
859 return PNG_HEADER_VERSION_STRING
860# ifndef PNG_READ_SUPPORTED
865 return PNG_HEADER_VERSION_STRING;
869#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
877png_build_grayscale_palette(
int bit_depth, png_colorp palette)
884 png_debug(1,
"in png_do_build_grayscale_palette");
917 for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
919 palette[i].red = (png_byte)(v & 0xff);
920 palette[i].green = (png_byte)(v & 0xff);
921 palette[i].blue = (png_byte)(v & 0xff);
926#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
928png_handle_as_unknown(png_const_structrp png_ptr, png_const_bytep chunk_name)
931 png_const_bytep p, p_end;
933 if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list == 0)
934 return PNG_HANDLE_CHUNK_AS_DEFAULT;
936 p_end = png_ptr->chunk_list;
937 p = p_end + png_ptr->num_chunk_list*5;
947 if (memcmp(chunk_name, p, 4) == 0)
957 return PNG_HANDLE_CHUNK_AS_DEFAULT;
960#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) ||\
961 defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
963png_chunk_unknown_handling(png_const_structrp png_ptr, png_uint_32 chunk_name)
965 png_byte chunk_string[5];
967 PNG_CSTRING_FROM_CHUNK(chunk_string, chunk_name);
968 return png_handle_as_unknown(png_ptr, chunk_string);
973#ifdef PNG_READ_SUPPORTED
976png_reset_zstream(png_structrp png_ptr)
979 return Z_STREAM_ERROR;
982 return inflateReset(&png_ptr->zstream);
988png_access_version_number(
void)
991 return (png_uint_32)PNG_LIBPNG_VER;
994#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
1000png_zstream_error(png_structrp png_ptr,
int ret)
1006 if (png_ptr->zstream.msg == NULL)
switch (ret)
1010 png_ptr->zstream.msg = PNGZ_MSG_CAST(
"unexpected zlib return code");
1015 png_ptr->zstream.msg = PNGZ_MSG_CAST(
"unexpected end of LZ stream");
1022 png_ptr->zstream.msg = PNGZ_MSG_CAST(
"missing LZ dictionary");
1027 png_ptr->zstream.msg = PNGZ_MSG_CAST(
"zlib IO error");
1030 case Z_STREAM_ERROR:
1032 png_ptr->zstream.msg = PNGZ_MSG_CAST(
"bad parameters to zlib");
1036 png_ptr->zstream.msg = PNGZ_MSG_CAST(
"damaged LZ stream");
1040 png_ptr->zstream.msg = PNGZ_MSG_CAST(
"insufficient memory");
1047 png_ptr->zstream.msg = PNGZ_MSG_CAST(
"truncated");
1050 case Z_VERSION_ERROR:
1051 png_ptr->zstream.msg = PNGZ_MSG_CAST(
"unsupported zlib version");
1054 case PNG_UNEXPECTED_ZLIB_RETURN:
1060 png_ptr->zstream.msg = PNGZ_MSG_CAST(
"unexpected zlib return");
1065#ifdef PNG_COLORSPACE_SUPPORTED
1067png_fp_add(png_int_32 addend0, png_int_32 addend1,
int *error)
1077 if (0x7fffffff - addend0 >= addend1)
1078 return addend0+addend1;
1080 else if (addend0 < 0)
1082 if (-0x7fffffff - addend0 <= addend1)
1083 return addend0+addend1;
1093png_fp_sub(png_int_32 addend0, png_int_32 addend1,
int *error)
1098 if (-0x7fffffff + addend1 <= addend0)
1099 return addend0-addend1;
1101 else if (addend1 < 0)
1103 if (0x7fffffff + addend1 >= addend0)
1104 return addend0-addend1;
1114png_safe_add(png_int_32 *addend0_and_result, png_int_32 addend1,
1121 int result = png_fp_add(*addend0_and_result,
1122 png_fp_add(addend1, addend2, &error),
1124 if (!error) *addend0_and_result = result;
1137 png_int_32 d, dred, dgreen, dblue, dwhite, whiteX, whiteY;
1143 if (png_safe_add(&d, XYZ->red_Y, XYZ->red_Z))
1146 if (png_muldiv(&xy->redx, XYZ->red_X, PNG_FP_1, dred) == 0)
1148 if (png_muldiv(&xy->redy, XYZ->red_Y, PNG_FP_1, dred) == 0)
1152 if (png_safe_add(&d, XYZ->green_Y, XYZ->green_Z))
1155 if (png_muldiv(&xy->greenx, XYZ->green_X, PNG_FP_1, dgreen) == 0)
1157 if (png_muldiv(&xy->greeny, XYZ->green_Y, PNG_FP_1, dgreen) == 0)
1161 if (png_safe_add(&d, XYZ->blue_Y, XYZ->blue_Z))
1164 if (png_muldiv(&xy->bluex, XYZ->blue_X, PNG_FP_1, dblue) == 0)
1166 if (png_muldiv(&xy->bluey, XYZ->blue_Y, PNG_FP_1, dblue) == 0)
1174 if (png_safe_add(&d, dred, dgreen))
1182 if (png_safe_add(&d, XYZ->green_X, XYZ->blue_X))
1187 if (png_safe_add(&d, XYZ->green_Y, XYZ->blue_Y))
1191 if (png_muldiv(&xy->whitex, whiteX, PNG_FP_1, dwhite) == 0)
1193 if (png_muldiv(&xy->whitey, whiteY, PNG_FP_1, dwhite) == 0)
1203 png_fixed_point red_inverse, green_inverse, blue_scale;
1204 png_fixed_point left, right, denominator;
1219 const png_fixed_point fpLimit = PNG_FP_1+(PNG_FP_1/10);
1220 if (xy->redx < 0 || xy->redx > fpLimit)
return 1;
1221 if (xy->redy < 0 || xy->redy > fpLimit-xy->redx)
return 1;
1222 if (xy->greenx < 0 || xy->greenx > fpLimit)
return 1;
1223 if (xy->greeny < 0 || xy->greeny > fpLimit-xy->greenx)
return 1;
1224 if (xy->bluex < 0 || xy->bluex > fpLimit)
return 1;
1225 if (xy->bluey < 0 || xy->bluey > fpLimit-xy->bluex)
return 1;
1226 if (xy->whitex < 0 || xy->whitex > fpLimit)
return 1;
1227 if (xy->whitey < 5 || xy->whitey > fpLimit-xy->whitex)
return 1;
1419 if (png_muldiv(&left, xy->greenx-xy->bluex, xy->redy - xy->bluey, 8) == 0)
1421 if (png_muldiv(&right, xy->greeny-xy->bluey, xy->redx - xy->bluex, 8) ==
1424 denominator = png_fp_sub(left, right, &error);
1425 if (error)
return 1;
1428 if (png_muldiv(&left, xy->greenx-xy->bluex, xy->whitey-xy->bluey, 8) == 0)
1430 if (png_muldiv(&right, xy->greeny-xy->bluey, xy->whitex-xy->bluex, 8) ==
1439 if (png_muldiv(&red_inverse, xy->whitey, denominator,
1440 png_fp_sub(left, right, &error)) == 0 || error ||
1441 red_inverse <= xy->whitey )
1445 if (png_muldiv(&left, xy->redy-xy->bluey, xy->whitex-xy->bluex, 8) == 0)
1447 if (png_muldiv(&right, xy->redx-xy->bluex, xy->whitey-xy->bluey, 8) == 0)
1449 if (png_muldiv(&green_inverse, xy->whitey, denominator,
1450 png_fp_sub(left, right, &error)) == 0 || error ||
1451 green_inverse <= xy->whitey)
1457 blue_scale = png_fp_sub(png_fp_sub(png_reciprocal(xy->whitey),
1458 png_reciprocal(red_inverse), &error),
1459 png_reciprocal(green_inverse), &error);
1460 if (error || blue_scale <= 0)
1468 if (png_muldiv(&XYZ->red_X, xy->redx, PNG_FP_1, red_inverse) == 0)
1470 if (png_muldiv(&XYZ->red_Y, xy->redy, PNG_FP_1, red_inverse) == 0)
1472 if (png_muldiv(&XYZ->red_Z, PNG_FP_1 - xy->redx - xy->redy, PNG_FP_1,
1476 if (png_muldiv(&XYZ->green_X, xy->greenx, PNG_FP_1, green_inverse) == 0)
1478 if (png_muldiv(&XYZ->green_Y, xy->greeny, PNG_FP_1, green_inverse) == 0)
1480 if (png_muldiv(&XYZ->green_Z, PNG_FP_1 - xy->greenx - xy->greeny, PNG_FP_1,
1481 green_inverse) == 0)
1484 if (png_muldiv(&XYZ->blue_X, xy->bluex, blue_scale, PNG_FP_1) == 0)
1486 if (png_muldiv(&XYZ->blue_Y, xy->bluey, blue_scale, PNG_FP_1) == 0)
1488 if (png_muldiv(&XYZ->blue_Z, PNG_FP_1 - xy->bluex - xy->bluey, blue_scale,
1496#ifdef PNG_READ_iCCP_SUPPORTED
1499png_icc_tag_char(png_uint_32
byte)
1502 if (
byte >= 32 &&
byte <= 126)
1509png_icc_tag_name(
char *name, png_uint_32 tag)
1512 name[1] = png_icc_tag_char(tag >> 24);
1513 name[2] = png_icc_tag_char(tag >> 16);
1514 name[3] = png_icc_tag_char(tag >> 8);
1515 name[4] = png_icc_tag_char(tag );
1520is_ICC_signature_char(png_alloc_size_t it)
1522 return it == 32 || (it >= 48 && it <= 57) || (it >= 65 && it <= 90) ||
1523 (it >= 97 && it <= 122);
1527is_ICC_signature(png_alloc_size_t it)
1529 return is_ICC_signature_char(it >> 24) &&
1530 is_ICC_signature_char((it >> 16) & 0xff) &&
1531 is_ICC_signature_char((it >> 8) & 0xff) &&
1532 is_ICC_signature_char(it & 0xff);
1536png_icc_profile_error(png_const_structrp png_ptr, png_const_charp name,
1537 png_alloc_size_t value, png_const_charp reason)
1542 pos = png_safecat(message, (
sizeof message), 0,
"profile '");
1543 pos = png_safecat(message, pos+79, pos, name);
1544 pos = png_safecat(message, (
sizeof message), pos,
"': ");
1545 if (is_ICC_signature(value) != 0)
1548 png_icc_tag_name(message+pos, (png_uint_32)value);
1550 message[pos++] =
':';
1551 message[pos++] =
' ';
1553# ifdef PNG_WARNINGS_SUPPORTED
1556 char number[PNG_NUMBER_BUFFER_SIZE];
1558 pos = png_safecat(message, (
sizeof message), pos,
1559 png_format_number(number, number+(
sizeof number),
1560 PNG_NUMBER_FORMAT_x, value));
1561 pos = png_safecat(message, (
sizeof message), pos,
"h: ");
1565 pos = png_safecat(message, (
sizeof message), pos, reason);
1568 png_chunk_benign_error(png_ptr, message);
1578static const png_byte D50_nCIEXYZ[12] =
1579 { 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d };
1582icc_check_length(png_const_structrp png_ptr, png_const_charp name,
1583 png_uint_32 profile_length)
1585 if (profile_length < 132)
1586 return png_icc_profile_error(png_ptr, name, profile_length,
"too short");
1591png_icc_check_length(png_const_structrp png_ptr, png_const_charp name,
1592 png_uint_32 profile_length)
1594 if (!icc_check_length(png_ptr, name, profile_length))
1603 if (profile_length > png_chunk_max(png_ptr))
1604 return png_icc_profile_error(png_ptr, name, profile_length,
1605 "profile too long");
1611png_icc_check_header(png_const_structrp png_ptr, png_const_charp name,
1612 png_uint_32 profile_length,
1613 png_const_bytep profile,
int color_type)
1622 temp = png_get_uint_32(profile);
1623 if (temp != profile_length)
1624 return png_icc_profile_error(png_ptr, name, temp,
1625 "length does not match profile");
1627 temp = (png_uint_32) (*(profile+8));
1628 if (temp > 3 && (profile_length & 3))
1629 return png_icc_profile_error(png_ptr, name, profile_length,
1632 temp = png_get_uint_32(profile+128);
1633 if (temp > 357913930 ||
1634 profile_length < 132+12*temp)
1635 return png_icc_profile_error(png_ptr, name, temp,
1636 "tag count too large");
1641 temp = png_get_uint_32(profile+64);
1643 return png_icc_profile_error(png_ptr, name, temp,
1644 "invalid rendering intent");
1649 if (temp >= PNG_sRGB_INTENT_LAST)
1650 (void)png_icc_profile_error(png_ptr, name, temp,
1651 "intent outside defined range");
1665 temp = png_get_uint_32(profile+36);
1666 if (temp != 0x61637370)
1667 return png_icc_profile_error(png_ptr, name, temp,
1668 "invalid signature");
1677 if (memcmp(profile+68, D50_nCIEXYZ, 12) != 0)
1678 (void)png_icc_profile_error(png_ptr, name, 0,
1679 "PCS illuminant is not D50");
1701 temp = png_get_uint_32(profile+16);
1705 if ((color_type & PNG_COLOR_MASK_COLOR) == 0)
1706 return png_icc_profile_error(png_ptr, name, temp,
1707 "RGB color space not permitted on grayscale PNG");
1711 if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
1712 return png_icc_profile_error(png_ptr, name, temp,
1713 "Gray color space not permitted on RGB PNG");
1717 return png_icc_profile_error(png_ptr, name, temp,
1718 "invalid ICC profile color space");
1730 temp = png_get_uint_32(profile+12);
1742 return png_icc_profile_error(png_ptr, name, temp,
1743 "invalid embedded Abstract ICC profile");
1752 return png_icc_profile_error(png_ptr, name, temp,
1753 "unexpected DeviceLink ICC profile class");
1760 (void)png_icc_profile_error(png_ptr, name, temp,
1761 "unexpected NamedColor ICC profile class");
1770 (void)png_icc_profile_error(png_ptr, name, temp,
1771 "unrecognized ICC profile class");
1778 temp = png_get_uint_32(profile+20);
1786 return png_icc_profile_error(png_ptr, name, temp,
1787 "unexpected ICC PCS encoding");
1794png_icc_check_tag_table(png_const_structrp png_ptr, png_const_charp name,
1795 png_uint_32 profile_length,
1796 png_const_bytep profile )
1798 png_uint_32 tag_count = png_get_uint_32(profile+128);
1800 png_const_bytep tag = profile+132;
1805 for (itag=0; itag < tag_count; ++itag, tag += 12)
1807 png_uint_32 tag_id = png_get_uint_32(tag+0);
1808 png_uint_32 tag_start = png_get_uint_32(tag+4);
1809 png_uint_32 tag_length = png_get_uint_32(tag+8);
1821 if (tag_start > profile_length || tag_length > profile_length - tag_start)
1822 return png_icc_profile_error(png_ptr, name, tag_id,
1823 "ICC profile tag outside profile");
1825 if ((tag_start & 3) != 0)
1831 (void)png_icc_profile_error(png_ptr, name, tag_id,
1832 "ICC profile tag start not a multiple of 4");
1840#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1841#if (defined PNG_READ_mDCV_SUPPORTED) || (defined PNG_READ_cHRM_SUPPORTED)
1843have_chromaticities(png_const_structrp png_ptr)
1861# ifdef PNG_READ_mDCV_SUPPORTED
1862 if (png_has_chunk(png_ptr, mDCV))
1864# define check_chromaticities 1
1867# ifdef PNG_READ_sRGB_SUPPORTED
1868 if (png_has_chunk(png_ptr, sRGB))
1872# ifdef PNG_READ_cHRM_SUPPORTED
1873 if (png_has_chunk(png_ptr, cHRM))
1875# define check_chromaticities 1
1883png_set_rgb_coefficients(png_structrp png_ptr)
1889 if (png_ptr->rgb_to_gray_coefficients_set == 0)
1891# if check_chromaticities
1894 if (have_chromaticities(png_ptr) &&
1895 png_XYZ_from_xy(&xyz, &png_ptr->chromaticities) == 0)
1900 png_fixed_point r = xyz.red_Y;
1901 png_fixed_point g = xyz.green_Y;
1902 png_fixed_point b = xyz.blue_Y;
1903 png_fixed_point total = r+g+b;
1906 r >= 0 && png_muldiv(&r, r, 32768, total) && r >= 0 && r <= 32768 &&
1907 g >= 0 && png_muldiv(&g, g, 32768, total) && g >= 0 && g <= 32768 &&
1908 b >= 0 && png_muldiv(&b, b, 32768, total) && b >= 0 && b <= 32768 &&
1920 else if (r+g+b < 32768)
1925 if (g >= r && g >= b)
1927 else if (r >= g && r >= b)
1936 "internal error handling cHRM coefficients");
1940 png_ptr->rgb_to_gray_red_coeff = (png_uint_16)r;
1941 png_ptr->rgb_to_gray_green_coeff = (png_uint_16)g;
1949 png_ptr->rgb_to_gray_red_coeff = 6968;
1950 png_ptr->rgb_to_gray_green_coeff = 23434;
1958png_check_IHDR(png_const_structrp png_ptr,
1959 png_uint_32 width, png_uint_32 height,
int bit_depth,
1960 int color_type,
int interlace_type,
int compression_type,
1968 png_warning(png_ptr,
"Image width is zero in IHDR");
1972 if (width > PNG_UINT_31_MAX)
1974 png_warning(png_ptr,
"Invalid image width in IHDR");
1986 if (((width + 7) & ~(png_alloc_size_t)7) >
2004 png_warning(png_ptr,
"Image width is too large for this architecture");
2008#ifdef PNG_SET_USER_LIMITS_SUPPORTED
2009 if (width > png_ptr->user_width_max)
2011 if (width > PNG_USER_WIDTH_MAX)
2014 png_warning(png_ptr,
"Image width exceeds user limit in IHDR");
2020 png_warning(png_ptr,
"Image height is zero in IHDR");
2024 if (height > PNG_UINT_31_MAX)
2026 png_warning(png_ptr,
"Invalid image height in IHDR");
2030#ifdef PNG_SET_USER_LIMITS_SUPPORTED
2031 if (height > png_ptr->user_height_max)
2033 if (height > PNG_USER_HEIGHT_MAX)
2036 png_warning(png_ptr,
"Image height exceeds user limit in IHDR");
2041 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
2042 bit_depth != 8 && bit_depth != 16)
2044 png_warning(png_ptr,
"Invalid bit depth in IHDR");
2048 if (color_type < 0 || color_type == 1 ||
2049 color_type == 5 || color_type > 6)
2051 png_warning(png_ptr,
"Invalid color type in IHDR");
2055 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
2056 ((color_type == PNG_COLOR_TYPE_RGB ||
2057 color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
2058 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
2060 png_warning(png_ptr,
"Invalid color type/bit depth combination in IHDR");
2064 if (interlace_type >= PNG_INTERLACE_LAST)
2066 png_warning(png_ptr,
"Unknown interlace method in IHDR");
2070 if (compression_type != PNG_COMPRESSION_TYPE_BASE)
2072 png_warning(png_ptr,
"Unknown compression method in IHDR");
2076#ifdef PNG_MNG_FEATURES_SUPPORTED
2086 if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 &&
2087 png_ptr->mng_features_permitted != 0)
2088 png_warning(png_ptr,
"MNG features are not allowed in a PNG datastream");
2090 if (filter_type != PNG_FILTER_TYPE_BASE)
2092 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 &&
2093 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
2094 ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) &&
2095 (color_type == PNG_COLOR_TYPE_RGB ||
2096 color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
2098 png_warning(png_ptr,
"Unknown filter method in IHDR");
2102 if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0)
2104 png_warning(png_ptr,
"Invalid filter method in IHDR");
2110 if (filter_type != PNG_FILTER_TYPE_BASE)
2112 png_warning(png_ptr,
"Unknown filter method in IHDR");
2118 png_error(png_ptr,
"Invalid IHDR data");
2121#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)
2127#define png_fp_add(state, flags) ((state) |= (flags))
2128#define png_fp_set(state, value) ((state) = (value) | ((state) & PNG_FP_STICKY))
2131png_check_fp_number(png_const_charp
string,
size_t size,
int *statep,
2134 int state = *statep;
2135 size_t i = *whereami;
2143 case 43: type = PNG_FP_SAW_SIGN;
break;
2144 case 45: type = PNG_FP_SAW_SIGN + PNG_FP_NEGATIVE;
break;
2145 case 46: type = PNG_FP_SAW_DOT;
break;
2146 case 48: type = PNG_FP_SAW_DIGIT;
break;
2147 case 49:
case 50:
case 51:
case 52:
2148 case 53:
case 54:
case 55:
case 56:
2149 case 57: type = PNG_FP_SAW_DIGIT + PNG_FP_NONZERO;
break;
2151 case 101: type = PNG_FP_SAW_E;
break;
2152 default:
goto PNG_FP_End;
2159 switch ((state & PNG_FP_STATE) + (type & PNG_FP_SAW_ANY))
2161 case PNG_FP_INTEGER + PNG_FP_SAW_SIGN:
2162 if ((state & PNG_FP_SAW_ANY) != 0)
2165 png_fp_add(state, type);
2168 case PNG_FP_INTEGER + PNG_FP_SAW_DOT:
2170 if ((state & PNG_FP_SAW_DOT) != 0)
2173 else if ((state & PNG_FP_SAW_DIGIT) != 0)
2174 png_fp_add(state, type);
2177 png_fp_set(state, PNG_FP_FRACTION | type);
2181 case PNG_FP_INTEGER + PNG_FP_SAW_DIGIT:
2182 if ((state & PNG_FP_SAW_DOT) != 0)
2183 png_fp_set(state, PNG_FP_FRACTION | PNG_FP_SAW_DOT);
2185 png_fp_add(state, type | PNG_FP_WAS_VALID);
2189 case PNG_FP_INTEGER + PNG_FP_SAW_E:
2190 if ((state & PNG_FP_SAW_DIGIT) == 0)
2193 png_fp_set(state, PNG_FP_EXPONENT);
2203 case PNG_FP_FRACTION + PNG_FP_SAW_DIGIT:
2204 png_fp_add(state, type | PNG_FP_WAS_VALID);
2207 case PNG_FP_FRACTION + PNG_FP_SAW_E:
2212 if ((state & PNG_FP_SAW_DIGIT) == 0)
2215 png_fp_set(state, PNG_FP_EXPONENT);
2219 case PNG_FP_EXPONENT + PNG_FP_SAW_SIGN:
2220 if ((state & PNG_FP_SAW_ANY) != 0)
2223 png_fp_add(state, PNG_FP_SAW_SIGN);
2230 case PNG_FP_EXPONENT + PNG_FP_SAW_DIGIT:
2231 png_fp_add(state, PNG_FP_SAW_DIGIT | PNG_FP_WAS_VALID);
2238 default:
goto PNG_FP_End;
2252 return (state & PNG_FP_SAW_DIGIT) != 0;
2258png_check_fp_string(png_const_charp
string,
size_t size)
2261 size_t char_index=0;
2263 if (png_check_fp_number(
string, size, &state, &char_index) != 0 &&
2264 (char_index == size ||
string[char_index] == 0))
2271#ifdef PNG_sCAL_SUPPORTED
2272# ifdef PNG_FLOATING_POINT_SUPPORTED
2287 if (power < DBL_MIN_10_EXP)
return 0;
2288 recip = 1; power = -power;
2297 if (power & 1) d *= mult;
2303 if (recip != 0) d = 1/d;
2314png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii,
size_t size,
2315 double fp,
unsigned int precision)
2323 precision = DBL_DIG;
2326 if (precision > DBL_DIG+1)
2327 precision = DBL_DIG+1;
2330 if (size >= precision+5)
2339 if (fp >= DBL_MIN && fp <= DBL_MAX)
2353 (void)frexp(fp, &exp_b10);
2355 exp_b10 = (exp_b10 * 77) >> 8;
2358 base = png_pow10(exp_b10);
2360 while (base < DBL_MIN || base < fp)
2363 double test = png_pow10(exp_b10+1);
2365 if (test <= DBL_MAX)
2367 ++exp_b10; base = test;
2384 fp /= 10; ++exp_b10;
2394 unsigned int czero, clead, cdigits;
2400 if (exp_b10 < 0 && exp_b10 > -3)
2424 if (cdigits+czero+1 < precision+clead)
2437 if (cdigits == 0) --clead;
2441 while (cdigits > 0 && d > 9)
2445 if (exp_b10 != (-1))
2450 ch = *--ascii; ++size;
2468 if (exp_b10 == (-1))
2478 ++size; exp_b10 = 1;
2499 if (cdigits == 0) ++clead;
2504 cdigits += czero - clead;
2513 if (exp_b10 != (-1))
2517 *ascii++ = 46; --size;
2522 *ascii++ = 48; --czero;
2525 if (exp_b10 != (-1))
2529 *ascii++ = 46; --size;
2534 *ascii++ = (char)(48 + (
int)d); ++cdigits;
2537 while (cdigits+czero < precision+clead && fp > DBL_MIN);
2548 if (exp_b10 >= (-1) && exp_b10 <= 2)
2557 while (exp_b10-- > 0) *ascii++ = 48;
2575 *ascii++ = 69; --size;
2582 unsigned int uexp_b10;
2586 *ascii++ = 45; --size;
2587 uexp_b10 = 0U-exp_b10;
2591 uexp_b10 = 0U+exp_b10;
2595 while (uexp_b10 > 0)
2597 exponent[cdigits++] = (char)(48 + uexp_b10 % 10);
2607 while (cdigits > 0) *ascii++ = exponent[--cdigits];
2615 else if (!(fp >= DBL_MIN))
2632 png_error(png_ptr,
"ASCII conversion buffer too small");
2636# ifdef PNG_FIXED_POINT_SUPPORTED
2640png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii,
2641 size_t size, png_fixed_point fp)
2653 *ascii++ = 45; num = (png_uint_32)(-fp);
2656 num = (png_uint_32)fp;
2658 if (num <= 0x80000000)
2660 unsigned int ndigits = 0, first = 16 ;
2661 char digits[10] = {0};
2666 unsigned int tmp = num/10;
2668 digits[ndigits++] = (char)(48 + num);
2672 if (first == 16 && num > 0)
2679 while (ndigits > 5) *ascii++ = digits[--ndigits];
2696 while (ndigits >= first) *ascii++ = digits[--ndigits];
2710 png_error(png_ptr,
"ASCII conversion buffer too small");
2715#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
2716 !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \
2717 (defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \
2718 defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \
2719 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \
2720 (defined(PNG_sCAL_SUPPORTED) && \
2721 defined(PNG_FLOATING_ARITHMETIC_SUPPORTED))
2723png_fixed(png_const_structrp png_ptr,
double fp, png_const_charp text)
2725 double r = floor(100000 * fp + .5);
2727 if (r > 2147483647. || r < -2147483648.)
2728 png_fixed_error(png_ptr, text);
2730# ifndef PNG_ERROR_TEXT_SUPPORTED
2734 return (png_fixed_point)r;
2738#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
2739 !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \
2740 (defined(PNG_cLLI_SUPPORTED) || defined(PNG_mDCV_SUPPORTED))
2742png_fixed_ITU(png_const_structrp png_ptr,
double fp, png_const_charp text)
2744 double r = floor(10000 * fp + .5);
2746 if (r > 2147483647. || r < 0)
2747 png_fixed_error(png_ptr, text);
2749# ifndef PNG_ERROR_TEXT_SUPPORTED
2753 return (png_uint_32)r;
2758#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_COLORSPACE_SUPPORTED) ||\
2759 defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)
2767png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times,
2773 if (a == 0 || times == 0)
2780#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2787 if (r <= 2147483647. && r >= -2147483648.)
2789 *res = (png_fixed_point)r;
2794 png_uint_32 A, T, D;
2795 png_uint_32 s16, s32, s00;
2798 negative = 1, A = -a;
2803 negative = !negative, T = -times;
2808 negative = !negative, D = -divisor;
2815 s16 = (A >> 16) * (T & 0xffff) +
2816 (A & 0xffff) * (T >> 16);
2820 s32 = (A >> 16) * (T >> 16) + (s16 >> 16);
2821 s00 = (A & 0xffff) * (T & 0xffff);
2823 s16 = (s16 & 0xffff) << 16;
2836 png_fixed_point result = 0;
2838 while (--bitshift >= 0)
2840 png_uint_32 d32, d00;
2843 d32 = D >> (32-bitshift), d00 = D << bitshift;
2850 if (s00 < d00) --s32;
2851 s32 -= d32, s00 -= d00, result += 1<<bitshift;
2855 if (s32 == d32 && s00 >= d00)
2856 s32 = 0, s00 -= d00, result += 1<<bitshift;
2860 if (s00 >= (D >> 1))
2867 if ((negative != 0 && result <= 0) ||
2868 (negative == 0 && result >= 0))
2883png_reciprocal(png_fixed_point a)
2885#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2886 double r = floor(1E10/a+.5);
2888 if (r <= 2147483647. && r >= -2147483648.)
2889 return (png_fixed_point)r;
2891 png_fixed_point res;
2893 if (png_muldiv(&res, 100000, 100000, a) != 0)
2901#ifdef PNG_READ_GAMMA_SUPPORTED
2906png_gamma_significant(png_fixed_point gamma_val)
2920 return gamma_val < PNG_FP_1 - PNG_GAMMA_THRESHOLD_FIXED ||
2921 gamma_val > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED;
2924#ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED
2926static png_fixed_point
2927png_product2(png_fixed_point a, png_fixed_point b)
2930#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2931 double r = a * 1E-5;
2935 if (r <= 2147483647. && r >= -2147483648.)
2936 return (png_fixed_point)r;
2938 png_fixed_point res;
2940 if (png_muldiv(&res, a, b, 100000) != 0)
2949png_reciprocal2(png_fixed_point a, png_fixed_point b)
2952#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2953 if (a != 0 && b != 0)
2959 if (r <= 2147483647. && r >= -2147483648.)
2960 return (png_fixed_point)r;
2968 png_fixed_point res = png_product2(a, b);
2971 return png_reciprocal(res);
2978#ifdef PNG_READ_GAMMA_SUPPORTED
2979#ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED
2997static const png_uint_32
3000 4270715492U, 4222494797U, 4174646467U, 4127164793U, 4080044201U, 4033279239U,
3001 3986864580U, 3940795015U, 3895065449U, 3849670902U, 3804606499U, 3759867474U,
3002 3715449162U, 3671346997U, 3627556511U, 3584073329U, 3540893168U, 3498011834U,
3003 3455425220U, 3413129301U, 3371120137U, 3329393864U, 3287946700U, 3246774933U,
3004 3205874930U, 3165243125U, 3124876025U, 3084770202U, 3044922296U, 3005329011U,
3005 2965987113U, 2926893432U, 2888044853U, 2849438323U, 2811070844U, 2772939474U,
3006 2735041326U, 2697373562U, 2659933400U, 2622718104U, 2585724991U, 2548951424U,
3007 2512394810U, 2476052606U, 2439922311U, 2404001468U, 2368287663U, 2332778523U,
3008 2297471715U, 2262364947U, 2227455964U, 2192742551U, 2158222529U, 2123893754U,
3009 2089754119U, 2055801552U, 2022034013U, 1988449497U, 1955046031U, 1921821672U,
3010 1888774511U, 1855902668U, 1823204291U, 1790677560U, 1758320682U, 1726131893U,
3011 1694109454U, 1662251657U, 1630556815U, 1599023271U, 1567649391U, 1536433567U,
3012 1505374214U, 1474469770U, 1443718700U, 1413119487U, 1382670639U, 1352370686U,
3013 1322218179U, 1292211689U, 1262349810U, 1232631153U, 1203054352U, 1173618059U,
3014 1144320946U, 1115161701U, 1086139034U, 1057251672U, 1028498358U, 999877854U,
3015 971388940U, 943030410U, 914801076U, 886699767U, 858725327U, 830876614U,
3016 803152505U, 775551890U, 748073672U, 720716771U, 693480120U, 666362667U,
3017 639363374U, 612481215U, 585715177U, 559064263U, 532527486U, 506103872U,
3018 479792461U, 453592303U, 427502463U, 401522014U, 375650043U, 349885648U,
3019 324227938U, 298676034U, 273229066U, 247886176U, 222646516U, 197509248U,
3020 172473545U, 147538590U, 122703574U, 97967701U, 73330182U, 48790236U,
3029 65166, 64430, 63700, 62976, 62257, 61543, 60835, 60132, 59434, 58741, 58054,
3030 57371, 56693, 56020, 55352, 54689, 54030, 53375, 52726, 52080, 51439, 50803,
3031 50170, 49542, 48918, 48298, 47682, 47070, 46462, 45858, 45257, 44661, 44068,
3032 43479, 42894, 42312, 41733, 41159, 40587, 40020, 39455, 38894, 38336, 37782,
3033 37230, 36682, 36137, 35595, 35057, 34521, 33988, 33459, 32932, 32408, 31887,
3034 31369, 30854, 30341, 29832, 29325, 28820, 28319, 27820, 27324, 26830, 26339,
3035 25850, 25364, 24880, 24399, 23920, 23444, 22970, 22499, 22029, 21562, 21098,
3036 20636, 20175, 19718, 19262, 18808, 18357, 17908, 17461, 17016, 16573, 16132,
3037 15694, 15257, 14822, 14390, 13959, 13530, 13103, 12678, 12255, 11834, 11415,
3038 10997, 10582, 10168, 9756, 9346, 8937, 8531, 8126, 7723, 7321, 6921, 6523,
3039 6127, 5732, 5339, 4947, 4557, 4169, 3782, 3397, 3014, 2632, 2251, 1872, 1495,
3045png_log8bit(
unsigned int x)
3047 unsigned int lg2 = 0;
3054 if ((x &= 0xff) == 0)
3057 if ((x & 0xf0) == 0)
3060 if ((x & 0xc0) == 0)
3063 if ((x & 0x80) == 0)
3067 return (png_int_32)((lg2 << 16) + ((png_8bit_l2[x-128]+32768)>>16));
3100#ifdef PNG_16BIT_SUPPORTED
3102png_log16bit(png_uint_32 x)
3104 unsigned int lg2 = 0;
3107 if ((x &= 0xffff) == 0)
3110 if ((x & 0xff00) == 0)
3113 if ((x & 0xf000) == 0)
3116 if ((x & 0xc000) == 0)
3119 if ((x & 0x8000) == 0)
3126 lg2 += (png_8bit_l2[(x>>8)-128]+8) >> 4;
3131 x = ((x << 16) + (x >> 9)) / (x >> 8);
3143 lg2 += ((23591U * (65536U-x)) + (1U << (16+6-12-1))) >> (16+6-12);
3146 lg2 -= ((23499U * (x-65536U)) + (1U << (16+6-12-1))) >> (16+6-12);
3149 return (png_int_32)((lg2 + 2048) >> 12);
3167static const png_uint_32
3171 4294967295U, 4112874773U, 3938502376U, 3771522796U, 3611622603U, 3458501653U,
3172 3311872529U, 3171459999U, 3037000500U, 2908241642U, 2784941738U, 2666869345U,
3173 2553802834U, 2445529972U, 2341847524U, 2242560872U
3178for (i=11;i>=0;--i){ print i,
" ", (1 - e(-(2^i)/65536*l(2))) * 2^(32-i),
"\n"}
3179 11 44937.64284865548751208448
3180 10 45180.98734845585101160448
3181 9 45303.31936980687359311872
3182 8 45364.65110595323018870784
3183 7 45395.35850361789624614912
3184 6 45410.72259715102037508096
3185 5 45418.40724413220722311168
3186 4 45422.25021786898173001728
3187 3 45424.17186732298419044352
3188 2 45425.13273269940811464704
3189 1 45425.61317555035558641664
3190 0 45425.85339951654943850496
3194png_exp(png_fixed_point x)
3196 if (x > 0 && x <= 0xfffff)
3199 png_uint_32 e = png_32bit_exp[(x >> 12) & 0x0f];
3208 e -= (((e >> 16) * 44938U) + 16U) >> 5;
3211 e -= (((e >> 16) * 45181U) + 32U) >> 6;
3214 e -= (((e >> 16) * 45303U) + 64U) >> 7;
3217 e -= (((e >> 16) * 45365U) + 128U) >> 8;
3220 e -= (((e >> 16) * 45395U) + 256U) >> 9;
3223 e -= (((e >> 16) * 45410U) + 512U) >> 10;
3226 e -= (((e >> 16) * 355U * (x & 0x3fU)) + 256U) >> 9;
3235 return png_32bit_exp[0];
3242png_exp8bit(png_fixed_point lg2)
3245 png_uint_32 x = png_exp(lg2);
3252 return (png_byte)(((x + 0x7fffffU) >> 24) & 0xff);
3255#ifdef PNG_16BIT_SUPPORTED
3257png_exp16bit(png_fixed_point lg2)
3260 png_uint_32 x = png_exp(lg2);
3264 return (png_uint_16)((x + 32767U) >> 16);
3270png_gamma_8bit_correct(
unsigned int value, png_fixed_point gamma_val)
3272 if (value > 0 && value < 255)
3274# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
3299 double r = floor(255*pow((
int)value/255.,gamma_val*.00001)+.5);
3302 png_int_32 lg2 = png_log8bit(value);
3303 png_fixed_point res;
3305 if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1) != 0)
3306 return png_exp8bit(res);
3313 return (png_byte)(value & 0xff);
3316#ifdef PNG_16BIT_SUPPORTED
3318png_gamma_16bit_correct(
unsigned int value, png_fixed_point gamma_val)
3320 if (value > 0 && value < 65535)
3322# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
3328 double r = floor(65535*pow((png_int_32)value/65535.,
3329 gamma_val*.00001)+.5);
3330 return (png_uint_16)r;
3332 png_int_32 lg2 = png_log16bit(value);
3333 png_fixed_point res;
3335 if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1) != 0)
3336 return png_exp16bit(res);
3343 return (png_uint_16)value;
3353png_gamma_correct(png_structrp png_ptr,
unsigned int value,
3354 png_fixed_point gamma_val)
3356 if (png_ptr->bit_depth == 8)
3357 return png_gamma_8bit_correct(value, gamma_val);
3359#ifdef PNG_16BIT_SUPPORTED
3361 return png_gamma_16bit_correct(value, gamma_val);
3368#ifdef PNG_16BIT_SUPPORTED
3378png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable,
3379 unsigned int shift, png_fixed_point gamma_val)
3382 unsigned int num = 1U << (8U - shift);
3383#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
3387 double fmax = 1.0 / (((png_int_32)1 << (16U - shift)) - 1);
3389 unsigned int max = (1U << (16U - shift)) - 1U;
3390 unsigned int max_by_2 = 1U << (15U - shift);
3393 png_uint_16pp table = *ptable =
3394 (png_uint_16pp)png_calloc(png_ptr, num * (
sizeof (png_uint_16p)));
3396 for (i = 0; i < num; i++)
3398 png_uint_16p sub_table = table[i] =
3399 (png_uint_16p)png_malloc(png_ptr, 256 * (
sizeof (png_uint_16)));
3404 if (png_gamma_significant(gamma_val) != 0)
3415 for (j = 0; j < 256; j++)
3417 png_uint_32 ig = (j << (8-shift)) + i;
3418# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
3423 double d = floor(65535.*pow(ig*fmax, gamma_val*.00001)+.5);
3424 sub_table[j] = (png_uint_16)d;
3427 ig = (ig * 65535U + max_by_2)/max;
3429 sub_table[j] = png_gamma_16bit_correct(ig, gamma_val);
3438 for (j = 0; j < 256; j++)
3440 png_uint_32 ig = (j << (8-shift)) + i;
3443 ig = (ig * 65535U + max_by_2)/max;
3445 sub_table[j] = (png_uint_16)ig;
3455png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable,
3456 unsigned int shift, png_fixed_point gamma_val)
3458 unsigned int num = 1U << (8U - shift);
3459 unsigned int max = (1U << (16U - shift))-1U;
3463 png_uint_16pp table = *ptable =
3464 (png_uint_16pp)png_calloc(png_ptr, num * (
sizeof (png_uint_16p)));
3470 for (i = 0; i < num; i++)
3471 table[i] = (png_uint_16p)png_malloc(png_ptr,
3472 256 * (
sizeof (png_uint_16)));
3491 for (i = 0; i < 255; ++i)
3494 png_uint_16 out = (png_uint_16)(i * 257U);
3497 png_uint_32 bound = png_gamma_16bit_correct(out+128U, gamma_val);
3500 bound = (bound * max + 32768U)/65535U + 1U;
3502 while (last < bound)
3504 table[last & (0xffU >> shift)][last >> (8U - shift)] = out;
3510 while (last < (num << 8))
3512 table[last & (0xff >> shift)][last >> (8U - shift)] = 65535U;
3523png_build_8bit_table(png_structrp png_ptr, png_bytepp ptable,
3524 png_fixed_point gamma_val)
3527 png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256);
3529 if (png_gamma_significant(gamma_val) != 0)
3530 for (i=0; i<256; i++)
3531 table[i] = png_gamma_8bit_correct(i, gamma_val);
3534 for (i=0; i<256; ++i)
3535 table[i] = (png_byte)(i & 0xff);
3542png_destroy_gamma_table(png_structrp png_ptr)
3544 png_free(png_ptr, png_ptr->gamma_table);
3545 png_ptr->gamma_table = NULL;
3547#ifdef PNG_16BIT_SUPPORTED
3548 if (png_ptr->gamma_16_table != NULL)
3551 int istop = (1 << (8 - png_ptr->gamma_shift));
3552 for (i = 0; i < istop; i++)
3554 png_free(png_ptr, png_ptr->gamma_16_table[i]);
3556 png_free(png_ptr, png_ptr->gamma_16_table);
3557 png_ptr->gamma_16_table = NULL;
3561#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
3562 defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
3563 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
3564 png_free(png_ptr, png_ptr->gamma_from_1);
3565 png_ptr->gamma_from_1 = NULL;
3566 png_free(png_ptr, png_ptr->gamma_to_1);
3567 png_ptr->gamma_to_1 = NULL;
3569#ifdef PNG_16BIT_SUPPORTED
3570 if (png_ptr->gamma_16_from_1 != NULL)
3573 int istop = (1 << (8 - png_ptr->gamma_shift));
3574 for (i = 0; i < istop; i++)
3576 png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
3578 png_free(png_ptr, png_ptr->gamma_16_from_1);
3579 png_ptr->gamma_16_from_1 = NULL;
3581 if (png_ptr->gamma_16_to_1 != NULL)
3584 int istop = (1 << (8 - png_ptr->gamma_shift));
3585 for (i = 0; i < istop; i++)
3587 png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
3589 png_free(png_ptr, png_ptr->gamma_16_to_1);
3590 png_ptr->gamma_16_to_1 = NULL;
3604#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
3605 defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
3606 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
3607# define GAMMA_TRANSFORMS 1
3609# define GAMMA_TRANSFORMS 0
3613png_build_gamma_table(png_structrp png_ptr,
int bit_depth)
3615 png_fixed_point file_gamma, screen_gamma;
3616 png_fixed_point correction;
3617# if GAMMA_TRANSFORMS
3618 png_fixed_point file_to_linear, linear_to_screen;
3621 png_debug(1,
"in png_build_gamma_table");
3629 if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL)
3631 png_warning(png_ptr,
"gamma table being rebuilt");
3632 png_destroy_gamma_table(png_ptr);
3639 file_gamma = png_ptr->file_gamma;
3640 screen_gamma = png_ptr->screen_gamma;
3641# if GAMMA_TRANSFORMS
3642 file_to_linear = png_reciprocal(file_gamma);
3645 if (screen_gamma > 0)
3647# if GAMMA_TRANSFORMS
3648 linear_to_screen = png_reciprocal(screen_gamma);
3650 correction = png_reciprocal2(screen_gamma, file_gamma);
3654# if GAMMA_TRANSFORMS
3655 linear_to_screen = file_gamma;
3657 correction = PNG_FP_1;
3662 png_build_8bit_table(png_ptr, &png_ptr->gamma_table, correction);
3665 if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0)
3667 png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1, file_to_linear);
3669 png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1,
3674#ifdef PNG_16BIT_SUPPORTED
3677 png_byte shift, sig_bit;
3679 if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
3681 sig_bit = png_ptr->sig_bit.red;
3683 if (png_ptr->sig_bit.green > sig_bit)
3684 sig_bit = png_ptr->sig_bit.green;
3686 if (png_ptr->sig_bit.blue > sig_bit)
3687 sig_bit = png_ptr->sig_bit.blue;
3690 sig_bit = png_ptr->sig_bit.gray;
3710 if (sig_bit > 0 && sig_bit < 16U)
3712 shift = (png_byte)((16U - sig_bit) & 0xff);
3717 if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0)
3723 if (shift < (16U - PNG_MAX_GAMMA_8))
3724 shift = (16U - PNG_MAX_GAMMA_8);
3730 png_ptr->gamma_shift = shift;
3737 if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0)
3738 png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift,
3739 png_reciprocal(correction));
3741 png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift,
3744# if GAMMA_TRANSFORMS
3745 if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0)
3747 png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift,
3754 png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift,
3764#ifdef PNG_SET_OPTION_SUPPORTED
3766png_set_option(png_structrp png_ptr,
int option,
int onoff)
3768 if (png_ptr != NULL && option >= 0 && option < PNG_OPTION_NEXT &&
3771 png_uint_32 mask = 3U << option;
3772 png_uint_32 setting = (2U + (onoff != 0)) << option;
3773 png_uint_32 current = png_ptr->options;
3775 png_ptr->options = (png_uint_32)((current & ~mask) | setting);
3777 return (
int)(current & mask) >> option;
3780 return PNG_OPTION_INVALID;
3785#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
3786 defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
3805#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
3807const png_uint_16 png_sRGB_table[256] =
3809 0,20,40,60,80,99,119,139,
3810 159,179,199,219,241,264,288,313,
3811 340,367,396,427,458,491,526,562,
3812 599,637,677,718,761,805,851,898,
3813 947,997,1048,1101,1156,1212,1270,1330,
3814 1391,1453,1517,1583,1651,1720,1790,1863,
3815 1937,2013,2090,2170,2250,2333,2418,2504,
3816 2592,2681,2773,2866,2961,3058,3157,3258,
3817 3360,3464,3570,3678,3788,3900,4014,4129,
3818 4247,4366,4488,4611,4736,4864,4993,5124,
3819 5257,5392,5530,5669,5810,5953,6099,6246,
3820 6395,6547,6700,6856,7014,7174,7335,7500,
3821 7666,7834,8004,8177,8352,8528,8708,8889,
3822 9072,9258,9445,9635,9828,10022,10219,10417,
3823 10619,10822,11028,11235,11446,11658,11873,12090,
3824 12309,12530,12754,12980,13209,13440,13673,13909,
3825 14146,14387,14629,14874,15122,15371,15623,15878,
3826 16135,16394,16656,16920,17187,17456,17727,18001,
3827 18277,18556,18837,19121,19407,19696,19987,20281,
3828 20577,20876,21177,21481,21787,22096,22407,22721,
3829 23038,23357,23678,24002,24329,24658,24990,25325,
3830 25662,26001,26344,26688,27036,27386,27739,28094,
3831 28452,28813,29176,29542,29911,30282,30656,31033,
3832 31412,31794,32179,32567,32957,33350,33745,34143,
3833 34544,34948,35355,35764,36176,36591,37008,37429,
3834 37852,38278,38706,39138,39572,40009,40449,40891,
3835 41337,41785,42236,42690,43147,43606,44069,44534,
3836 45002,45473,45947,46423,46903,47385,47871,48359,
3837 48850,49344,49841,50341,50844,51349,51858,52369,
3838 52884,53401,53921,54445,54971,55500,56032,56567,
3839 57105,57646,58190,58737,59287,59840,60396,60955,
3840 61517,62082,62650,63221,63795,64372,64952,65535
3847const png_uint_16 png_sRGB_base[512] =
3849 128,1782,3383,4644,5675,6564,7357,8074,
3850 8732,9346,9921,10463,10977,11466,11935,12384,
3851 12816,13233,13634,14024,14402,14769,15125,15473,
3852 15812,16142,16466,16781,17090,17393,17690,17981,
3853 18266,18546,18822,19093,19359,19621,19879,20133,
3854 20383,20630,20873,21113,21349,21583,21813,22041,
3855 22265,22487,22707,22923,23138,23350,23559,23767,
3856 23972,24175,24376,24575,24772,24967,25160,25352,
3857 25542,25730,25916,26101,26284,26465,26645,26823,
3858 27000,27176,27350,27523,27695,27865,28034,28201,
3859 28368,28533,28697,28860,29021,29182,29341,29500,
3860 29657,29813,29969,30123,30276,30429,30580,30730,
3861 30880,31028,31176,31323,31469,31614,31758,31902,
3862 32045,32186,32327,32468,32607,32746,32884,33021,
3863 33158,33294,33429,33564,33697,33831,33963,34095,
3864 34226,34357,34486,34616,34744,34873,35000,35127,
3865 35253,35379,35504,35629,35753,35876,35999,36122,
3866 36244,36365,36486,36606,36726,36845,36964,37083,
3867 37201,37318,37435,37551,37668,37783,37898,38013,
3868 38127,38241,38354,38467,38580,38692,38803,38915,
3869 39026,39136,39246,39356,39465,39574,39682,39790,
3870 39898,40005,40112,40219,40325,40431,40537,40642,
3871 40747,40851,40955,41059,41163,41266,41369,41471,
3872 41573,41675,41777,41878,41979,42079,42179,42279,
3873 42379,42478,42577,42676,42775,42873,42971,43068,
3874 43165,43262,43359,43456,43552,43648,43743,43839,
3875 43934,44028,44123,44217,44311,44405,44499,44592,
3876 44685,44778,44870,44962,45054,45146,45238,45329,
3877 45420,45511,45601,45692,45782,45872,45961,46051,
3878 46140,46229,46318,46406,46494,46583,46670,46758,
3879 46846,46933,47020,47107,47193,47280,47366,47452,
3880 47538,47623,47709,47794,47879,47964,48048,48133,
3881 48217,48301,48385,48468,48552,48635,48718,48801,
3882 48884,48966,49048,49131,49213,49294,49376,49458,
3883 49539,49620,49701,49782,49862,49943,50023,50103,
3884 50183,50263,50342,50422,50501,50580,50659,50738,
3885 50816,50895,50973,51051,51129,51207,51285,51362,
3886 51439,51517,51594,51671,51747,51824,51900,51977,
3887 52053,52129,52205,52280,52356,52432,52507,52582,
3888 52657,52732,52807,52881,52956,53030,53104,53178,
3889 53252,53326,53400,53473,53546,53620,53693,53766,
3890 53839,53911,53984,54056,54129,54201,54273,54345,
3891 54417,54489,54560,54632,54703,54774,54845,54916,
3892 54987,55058,55129,55199,55269,55340,55410,55480,
3893 55550,55620,55689,55759,55828,55898,55967,56036,
3894 56105,56174,56243,56311,56380,56448,56517,56585,
3895 56653,56721,56789,56857,56924,56992,57059,57127,
3896 57194,57261,57328,57395,57462,57529,57595,57662,
3897 57728,57795,57861,57927,57993,58059,58125,58191,
3898 58256,58322,58387,58453,58518,58583,58648,58713,
3899 58778,58843,58908,58972,59037,59101,59165,59230,
3900 59294,59358,59422,59486,59549,59613,59677,59740,
3901 59804,59867,59930,59993,60056,60119,60182,60245,
3902 60308,60370,60433,60495,60558,60620,60682,60744,
3903 60806,60868,60930,60992,61054,61115,61177,61238,
3904 61300,61361,61422,61483,61544,61605,61666,61727,
3905 61788,61848,61909,61969,62030,62090,62150,62211,
3906 62271,62331,62391,62450,62510,62570,62630,62689,
3907 62749,62808,62867,62927,62986,63045,63104,63163,
3908 63222,63281,63340,63398,63457,63515,63574,63632,
3909 63691,63749,63807,63865,63923,63981,64039,64097,
3910 64155,64212,64270,64328,64385,64443,64500,64557,
3911 64614,64672,64729,64786,64843,64900,64956,65013,
3912 65070,65126,65183,65239,65296,65352,65409,65465
3915const png_byte png_sRGB_delta[512] =
3917 207,201,158,129,113,100,90,82,77,72,68,64,61,59,56,54,
3918 52,50,49,47,46,45,43,42,41,40,39,39,38,37,36,36,
3919 35,34,34,33,33,32,32,31,31,30,30,30,29,29,28,28,
3920 28,27,27,27,27,26,26,26,25,25,25,25,24,24,24,24,
3921 23,23,23,23,23,22,22,22,22,22,22,21,21,21,21,21,
3922 21,20,20,20,20,20,20,20,20,19,19,19,19,19,19,19,
3923 19,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17,
3924 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
3925 16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,
3926 15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,
3927 14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,
3928 13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,
3929 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
3930 12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,
3931 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
3932 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
3933 11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
3934 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
3935 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
3936 10,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
3937 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
3938 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
3939 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
3940 9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
3941 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
3942 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
3943 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
3944 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
3945 8,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7,
3946 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
3947 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
3948 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
3953#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
3954 defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
3956png_image_free_function(png_voidp argument)
3958 png_imagep image = png_voidcast(png_imagep, argument);
3959 png_controlp cp = image->opaque;
3965 if (cp->png_ptr == NULL)
3969# ifdef PNG_STDIO_SUPPORTED
3970 if (cp->owned_file != 0)
3972 FILE *fp = png_voidcast(FILE *, cp->png_ptr->io_ptr);
3978 cp->png_ptr->io_ptr = NULL;
3991 png_free(c.png_ptr, cp);
3994 if (c.for_write != 0)
3996# ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
3997 png_destroy_write_struct(&c.png_ptr, &c.info_ptr);
3999 png_error(c.png_ptr,
"simplified write not supported");
4004# ifdef PNG_SIMPLIFIED_READ_SUPPORTED
4005 png_destroy_read_struct(&c.png_ptr, &c.info_ptr, NULL);
4007 png_error(c.png_ptr,
"simplified read not supported");
4016png_image_free(png_imagep image)
4022 if (image != NULL && image->opaque != NULL &&
4023 image->opaque->error_buf == NULL)
4025 png_image_free_function(image);
4026 image->opaque = NULL;
4031png_image_error(png_imagep image, png_const_charp error_message)
4034 png_safecat(image->message, (
sizeof image->message), 0, error_message);
4035 image->warning_or_error |= PNG_IMAGE_ERROR;
4036 png_image_free(image);