18 #define PNG_NO_PEDANTIC_WARNINGS 20 #ifdef PNG_READ_SUPPORTED 22 #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500) 23 # define WIN32_WCE_OLD 26 #ifdef PNG_FLOATING_POINT_SUPPORTED 36 len = MultiByteToWideChar(CP_ACP, 0, nptr, -1,
NULL, 0);
40 MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
41 result = wcstod(str, &end);
42 len = WideCharToMultiByte(CP_ACP, 0, end, -1,
NULL, 0,
NULL,
NULL);
43 *endptr = (
char *)nptr + (
png_strlen(nptr) - len + 1);
49 # define png_strtod(p,a,b) strtod(a,b) 56 #ifdef PNG_READ_BIG_ENDIAN_SUPPORTED 66 png_error(png_ptr,
"PNG unsigned integer out of range.");
69 #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED 124 png_debug2(0,
"Reading %s chunk, length = %lu",
125 png_ptr->chunk_name, length);
158 for (i = (
png_size_t)skip; i > istop; i -= istop)
160 png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
169 if (((png_ptr->chunk_name[0] & 0x20) &&
170 !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
171 (!(png_ptr->chunk_name[0] & 0x20) &&
172 (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
196 if (png_ptr->chunk_name[0] & 0x20)
198 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
199 (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
204 if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
213 return ((
int)(crc != png_ptr->crc));
219 #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \ 220 defined(PNG_READ_iCCP_SUPPORTED) 228 png_ptr->zstream.avail_in =
size;
237 png_ptr->zstream.next_out = png_ptr->zbuf;
238 png_ptr->zstream.avail_out = png_ptr->zbuf_size;
241 avail = png_ptr->zbuf_size - png_ptr->zstream.avail_out;
248 if (
output != 0 && output_size > count)
263 png_ptr->zstream.avail_in = 0;
275 if (png_ptr->zstream.msg != 0)
276 msg = png_ptr->zstream.msg;
279 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 285 msg =
"Buffer error in compressed datastream in %s chunk";
288 msg =
"Data error in compressed datastream in %s chunk";
291 msg =
"Incomplete compressed datastream in %s chunk";
295 png_snprintf(umsg,
sizeof umsg, msg, png_ptr->chunk_name);
299 msg =
"Damaged compressed datastream in chunk other than IDAT";
303 #ifndef PNG_STDIO_SUPPORTED 328 if (prefix_size > chunklength)
337 png_size_t expanded_size = png_inflate(png_ptr,
338 (
png_bytep)(png_ptr->chunkdata + prefix_size),
339 chunklength - prefix_size,
346 expanded_size >= (~(
png_size_t)0) - 1 - prefix_size
352 png_warning(png_ptr,
"Exceeded size limit while expanding chunk");
359 else if (expanded_size > 0)
365 prefix_size + expanded_size + 1);
369 png_memcpy(text, png_ptr->chunkdata, prefix_size);
370 new_size = png_inflate(png_ptr,
371 (
png_bytep)(png_ptr->chunkdata + prefix_size),
372 chunklength - prefix_size,
373 (
png_bytep)(text + prefix_size), expanded_size);
374 text[prefix_size + expanded_size] = 0;
376 if (new_size == expanded_size)
378 png_free(png_ptr, png_ptr->chunkdata);
379 png_ptr->chunkdata = text;
380 *newlength = prefix_size + expanded_size;
388 png_warning(png_ptr,
"Not enough memory to decompress chunk.");
394 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 397 png_snprintf(umsg,
sizeof umsg,
"Unknown zTXt compression type %d",
401 png_warning(png_ptr,
"Unknown zTXt compression type");
416 png_memcpy(text, png_ptr->chunkdata, prefix_size);
417 png_free(png_ptr, png_ptr->chunkdata);
418 png_ptr->chunkdata = text;
421 *(png_ptr->chunkdata + prefix_size) = 0x00;
426 *newlength = prefix_size;
446 png_error(png_ptr,
"Invalid IHDR chunk");
457 compression_type = buf[10];
458 filter_type = buf[11];
459 interlace_type = buf[12];
462 png_ptr->width =
width;
464 png_ptr->bit_depth = (
png_byte)bit_depth;
465 png_ptr->interlaced = (
png_byte)interlace_type;
466 png_ptr->color_type = (
png_byte)color_type;
467 #ifdef PNG_MNG_FEATURES_SUPPORTED 468 png_ptr->filter_type = (
png_byte)filter_type;
470 png_ptr->compression_type = (
png_byte)compression_type;
473 switch (png_ptr->color_type)
477 png_ptr->channels = 1;
481 png_ptr->channels = 3;
485 png_ptr->channels = 2;
489 png_ptr->channels = 4;
494 png_ptr->pixel_depth = (
png_byte)(png_ptr->bit_depth *
496 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width);
497 png_debug1(3,
"bit_depth = %d", png_ptr->bit_depth);
498 png_debug1(3,
"channels = %d", png_ptr->channels);
499 png_debug1(3,
"rowbytes = %lu", png_ptr->rowbytes);
500 png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
501 color_type, interlace_type, compression_type, filter_type);
509 int max_palette_length,
num,
i;
510 #ifdef PNG_POINTER_INDEXING_SUPPORTED 517 png_error(png_ptr,
"Missing IHDR before PLTE");
527 png_error(png_ptr,
"Duplicate PLTE chunk");
534 "Ignoring PLTE chunk in grayscale PNG");
538 #ifndef PNG_READ_OPT_PLTE_SUPPORTED 557 png_error(png_ptr,
"Invalid palette chunk");
562 num = (
int)length / 3;
570 max_palette_length = (1 << png_ptr->bit_depth);
574 if (num > max_palette_length)
575 num = max_palette_length;
577 #ifdef PNG_POINTER_INDEXING_SUPPORTED 578 for (i = 0, pal_ptr = palette; i <
num; i++, pal_ptr++)
583 pal_ptr->red = buf[0];
584 pal_ptr->green = buf[1];
585 pal_ptr->blue = buf[2];
588 for (i = 0; i <
num; i++)
594 palette[
i].
red = buf[0];
595 palette[
i].
green = buf[1];
596 palette[
i].
blue = buf[2];
605 #ifndef PNG_READ_OPT_PLTE_SUPPORTED 611 #ifndef PNG_READ_OPT_PLTE_SUPPORTED 618 if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
620 if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
631 else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
640 #ifdef PNG_READ_tRNS_SUPPORTED 647 png_warning(png_ptr,
"Truncating incorrect tRNS chunk length");
652 png_warning(png_ptr,
"Truncating incorrect info tRNS chunk length");
675 png_warning(png_ptr,
"Incorrect IEND chunk length");
682 #ifdef PNG_READ_gAMA_SUPPORTED 687 #ifdef PNG_FLOATING_POINT_SUPPORTED 695 png_error(png_ptr,
"Missing IHDR before gAMA");
719 png_warning(png_ptr,
"Incorrect gAMA chunk length");
733 "Ignoring gAMA chunk with gamma=0");
737 #ifdef PNG_READ_sRGB_SUPPORTED 739 if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
742 "Ignoring incorrect gAMA value when sRGB is also present");
743 #ifdef PNG_CONSOLE_IO_SUPPORTED 744 fprintf(stderr,
"gamma = (%d/100000)", (
int)igamma);
750 #ifdef PNG_FLOATING_POINT_SUPPORTED 751 file_gamma = (float)igamma / (
float)100000.0;
752 # ifdef PNG_READ_GAMMA_SUPPORTED 757 #ifdef PNG_FIXED_POINT_SUPPORTED 763 #ifdef PNG_READ_sBIT_SUPPORTED 772 buf[0] = buf[1] = buf[2] = buf[3] = 0;
775 png_error(png_ptr,
"Missing IHDR before sBIT");
799 if (length != truelen || length > 4)
801 png_warning(png_ptr,
"Incorrect sBIT chunk length");
812 png_ptr->sig_bit.red = buf[0];
813 png_ptr->sig_bit.green = buf[1];
814 png_ptr->sig_bit.blue = buf[2];
815 png_ptr->sig_bit.alpha = buf[3];
819 png_ptr->sig_bit.gray = buf[0];
820 png_ptr->sig_bit.red = buf[0];
821 png_ptr->sig_bit.green = buf[0];
822 png_ptr->sig_bit.blue = buf[0];
823 png_ptr->sig_bit.alpha = buf[1];
829 #ifdef PNG_READ_cHRM_SUPPORTED 834 #ifdef PNG_FLOATING_POINT_SUPPORTED 837 png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
838 int_y_green, int_x_blue, int_y_blue;
845 png_error(png_ptr,
"Missing IHDR before cHRM");
869 png_warning(png_ptr,
"Incorrect cHRM chunk length");
898 #ifdef PNG_FLOATING_POINT_SUPPORTED 899 white_x = (float)int_x_white / (
float)100000.0;
900 white_y = (float)int_y_white / (
float)100000.0;
901 red_x = (float)int_x_red / (
float)100000.0;
902 red_y = (float)int_y_red / (
float)100000.0;
903 green_x = (float)int_x_green / (
float)100000.0;
904 green_y = (float)int_y_green / (
float)100000.0;
905 blue_x = (float)int_x_blue / (
float)100000.0;
906 blue_y = (float)int_y_blue / (
float)100000.0;
909 #ifdef PNG_READ_sRGB_SUPPORTED 912 if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
913 PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
914 PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
915 PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
916 PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
917 PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
918 PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
919 PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
922 "Ignoring incorrect cHRM value when sRGB is also present");
923 #ifdef PNG_CONSOLE_IO_SUPPORTED 924 #ifdef PNG_FLOATING_POINT_SUPPORTED 925 fprintf(stderr,
"wx=%f, wy=%f, rx=%f, ry=%f\n",
926 white_x, white_y, red_x, red_y);
927 fprintf(stderr,
"gx=%f, gy=%f, bx=%f, by=%f\n",
928 green_x, green_y, blue_x, blue_y);
930 fprintf(stderr,
"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
931 (
long)int_x_white, (
long)int_y_white,
932 (
long)int_x_red, (
long)int_y_red);
933 fprintf(stderr,
"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
934 (
long)int_x_green, (
long)int_y_green,
935 (
long)int_x_blue, (
long)int_y_blue);
943 #ifdef PNG_FLOATING_POINT_SUPPORTED 945 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
947 #ifdef PNG_FIXED_POINT_SUPPORTED 949 int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
950 int_y_green, int_x_blue, int_y_blue);
955 #ifdef PNG_READ_sRGB_SUPPORTED 965 png_error(png_ptr,
"Missing IHDR before sRGB");
985 png_warning(png_ptr,
"Incorrect sRGB chunk length");
1002 #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) 1006 #ifdef PNG_FIXED_POINT_SUPPORTED 1007 igamma=info_ptr->int_gamma;
1009 # ifdef PNG_FLOATING_POINT_SUPPORTED 1013 if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
1016 "Ignoring incorrect gAMA value when sRGB is also present");
1017 #ifdef PNG_CONSOLE_IO_SUPPORTED 1018 # ifdef PNG_FIXED_POINT_SUPPORTED 1019 fprintf(stderr,
"incorrect gamma=(%d/100000)\n",
1020 (
int)png_ptr->int_gamma);
1022 # ifdef PNG_FLOATING_POINT_SUPPORTED 1023 fprintf(stderr,
"incorrect gamma=%f\n", png_ptr->gamma);
1031 #ifdef PNG_READ_cHRM_SUPPORTED 1032 #ifdef PNG_FIXED_POINT_SUPPORTED 1034 if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
1035 PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
1036 PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
1037 PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
1038 PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
1039 PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
1040 PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
1041 PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
1044 "Ignoring incorrect cHRM value when sRGB is also present");
1053 #ifdef PNG_READ_iCCP_SUPPORTED 1063 png_size_t slength, prefix_length, data_length;
1068 png_error(png_ptr,
"Missing IHDR before iCCP");
1086 #ifdef PNG_MAX_MALLOC_64K 1089 png_warning(png_ptr,
"iCCP chunk too large to fit in memory");
1095 png_free(png_ptr, png_ptr->chunkdata);
1102 png_free(png_ptr, png_ptr->chunkdata);
1103 png_ptr->chunkdata =
NULL;
1107 png_ptr->chunkdata[slength] = 0x00;
1109 for (profile = png_ptr->chunkdata; *profile; profile++)
1117 if (slength < 1U || profile >= png_ptr->chunkdata + slength - 1U)
1119 png_free(png_ptr, png_ptr->chunkdata);
1120 png_ptr->chunkdata =
NULL;
1126 compression_type = *profile++;
1127 if (compression_type)
1129 png_warning(png_ptr,
"Ignoring nonzero compression type in iCCP chunk");
1130 compression_type = 0x00;
1134 prefix_length = profile - png_ptr->chunkdata;
1136 slength, prefix_length, &data_length);
1138 profile_length = data_length - prefix_length;
1140 if ( prefix_length > data_length || profile_length < 4)
1142 png_free(png_ptr, png_ptr->chunkdata);
1143 png_ptr->chunkdata =
NULL;
1144 png_warning(png_ptr,
"Profile size field missing from iCCP chunk");
1149 pC = (
png_bytep)(png_ptr->chunkdata + prefix_length);
1155 if (profile_size < profile_length)
1156 profile_length = profile_size;
1158 if (profile_size > profile_length)
1160 png_free(png_ptr, png_ptr->chunkdata);
1161 png_ptr->chunkdata =
NULL;
1162 png_warning(png_ptr,
"Ignoring truncated iCCP profile.");
1167 compression_type, png_ptr->chunkdata + prefix_length, profile_length);
1168 png_free(png_ptr, png_ptr->chunkdata);
1169 png_ptr->chunkdata =
NULL;
1173 #ifdef PNG_READ_sPLT_SUPPORTED 1180 #ifdef PNG_POINTER_INDEXING_SUPPORTED 1183 int data_length, entry_size,
i;
1189 #ifdef PNG_USER_LIMITS_SUPPORTED 1191 if (png_ptr->user_chunk_cache_max != 0)
1193 if (png_ptr->user_chunk_cache_max == 1)
1198 if (--png_ptr->user_chunk_cache_max == 1)
1200 png_warning(png_ptr,
"No space in chunk cache for sPLT");
1208 png_error(png_ptr,
"Missing IHDR before sPLT");
1216 #ifdef PNG_MAX_MALLOC_64K 1219 png_warning(png_ptr,
"sPLT chunk too large to fit in memory");
1225 png_free(png_ptr, png_ptr->chunkdata);
1232 png_free(png_ptr, png_ptr->chunkdata);
1233 png_ptr->chunkdata =
NULL;
1237 png_ptr->chunkdata[slength] = 0x00;
1239 for (entry_start = (
png_bytep)png_ptr->chunkdata; *entry_start;
1246 entry_start > (
png_bytep)png_ptr->chunkdata + slength - 2U)
1248 png_free(png_ptr, png_ptr->chunkdata);
1249 png_ptr->chunkdata =
NULL;
1254 new_palette.
depth = *entry_start++;
1255 entry_size = (new_palette.
depth == 8 ? 6 : 10);
1256 data_length = (slength - (entry_start - (
png_bytep)png_ptr->chunkdata));
1259 if (data_length % entry_size)
1261 png_free(png_ptr, png_ptr->chunkdata);
1262 png_ptr->chunkdata =
NULL;
1263 png_warning(png_ptr,
"sPLT chunk has bad length");
1278 png_warning(png_ptr,
"sPLT chunk requires too much memory");
1282 #ifdef PNG_POINTER_INDEXING_SUPPORTED 1283 for (i = 0; i < new_palette.
nentries; i++)
1287 if (new_palette.
depth == 8)
1289 pp->red = *entry_start++;
1290 pp->green = *entry_start++;
1291 pp->blue = *entry_start++;
1292 pp->alpha = *entry_start++;
1305 for (i = 0; i < new_palette.
nentries; i++)
1308 if (new_palette.
depth == 8)
1310 pp[
i].red = *entry_start++;
1311 pp[
i].green = *entry_start++;
1312 pp[
i].blue = *entry_start++;
1313 pp[
i].alpha = *entry_start++;
1327 new_palette.
name = png_ptr->chunkdata;
1331 png_free(png_ptr, png_ptr->chunkdata);
1332 png_ptr->chunkdata =
NULL;
1337 #ifdef PNG_READ_tRNS_SUPPORTED 1346 png_error(png_ptr,
"Missing IHDR before tRNS");
1366 png_warning(png_ptr,
"Incorrect tRNS chunk length");
1372 png_ptr->num_trans = 1;
1381 png_warning(png_ptr,
"Incorrect tRNS chunk length");
1386 png_ptr->num_trans = 1;
1401 png_warning(png_ptr,
"Incorrect tRNS chunk length");
1416 png_warning(png_ptr,
"tRNS chunk not allowed with alpha channel");
1423 png_ptr->num_trans = 0;
1427 png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
1428 &(png_ptr->trans_values));
1432 #ifdef PNG_READ_bKGD_SUPPORTED 1442 png_error(png_ptr,
"Missing IHDR before bKGD");
1470 if (length != truelen)
1472 png_warning(png_ptr,
"Incorrect bKGD chunk length");
1487 png_ptr->background.index = buf[0];
1488 if (info_ptr && info_ptr->num_palette)
1490 if (buf[0] >= info_ptr->num_palette)
1492 png_warning(png_ptr,
"Incorrect bKGD chunk index value");
1495 png_ptr->background.red =
1497 png_ptr->background.green =
1499 png_ptr->background.blue =
1505 png_ptr->background.red =
1506 png_ptr->background.green =
1507 png_ptr->background.blue =
1517 png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
1521 #ifdef PNG_READ_hIST_SUPPORTED 1525 unsigned int num,
i;
1531 png_error(png_ptr,
"Missing IHDR before hIST");
1552 length != (
unsigned int) (2*png_ptr->num_palette))
1554 png_warning(png_ptr,
"Incorrect hIST chunk length");
1561 for (i = 0; i <
num; i++)
1576 #ifdef PNG_READ_pHYs_SUPPORTED 1587 png_error(png_ptr,
"Missing IHDR before pHYs");
1603 png_warning(png_ptr,
"Incorrect pHYs chunk length");
1615 png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
1619 #ifdef PNG_READ_oFFs_SUPPORTED 1630 png_error(png_ptr,
"Missing IHDR before oFFs");
1646 png_warning(png_ptr,
"Incorrect oFFs chunk length");
1658 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
1662 #ifdef PNG_READ_pCAL_SUPPORTED 1677 png_error(png_ptr,
"Missing IHDR before pCAL");
1691 png_debug1(2,
"Allocating and reading pCAL chunk data (%lu bytes)",
1693 png_free(png_ptr, png_ptr->chunkdata);
1695 if (png_ptr->chunkdata ==
NULL)
1697 png_warning(png_ptr,
"No memory for pCAL purpose.");
1705 png_free(png_ptr, png_ptr->chunkdata);
1706 png_ptr->chunkdata =
NULL;
1710 png_ptr->chunkdata[slength] = 0x00;
1712 png_debug(3,
"Finding end of pCAL purpose string");
1713 for (buf = png_ptr->chunkdata; *buf; buf++)
1716 endptr = png_ptr->chunkdata + slength;
1720 if (slength < 12U || endptr - buf <= 12)
1723 png_free(png_ptr, png_ptr->chunkdata);
1724 png_ptr->chunkdata =
NULL;
1728 png_debug(3,
"Reading pCAL X0, X1, type, nparams, and units");
1735 png_debug(3,
"Checking pCAL equation type and number of parameters");
1743 png_warning(png_ptr,
"Invalid pCAL parameters for equation type");
1744 png_free(png_ptr, png_ptr->chunkdata);
1745 png_ptr->chunkdata =
NULL;
1750 png_warning(png_ptr,
"Unrecognized equation type for pCAL chunk");
1753 for (buf = units; *
buf; buf++)
1756 png_debug(3,
"Allocating pCAL parameters array");
1761 png_free(png_ptr, png_ptr->chunkdata);
1762 png_ptr->chunkdata =
NULL;
1763 png_warning(png_ptr,
"No memory for pCAL params.");
1768 for (i = 0; i < (
int)nparams; i++)
1772 png_debug1(3,
"Reading pCAL parameter %d", i);
1773 for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
1780 png_free(png_ptr, png_ptr->chunkdata);
1781 png_ptr->chunkdata =
NULL;
1787 png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams,
1790 png_free(png_ptr, png_ptr->chunkdata);
1791 png_ptr->chunkdata =
NULL;
1796 #ifdef PNG_READ_sCAL_SUPPORTED 1802 #ifdef PNG_FLOATING_POINT_SUPPORTED 1806 #ifdef PNG_FIXED_POINT_SUPPORTED 1815 png_error(png_ptr,
"Missing IHDR before sCAL");
1830 else if (length < 4)
1837 png_debug1(2,
"Allocating and reading sCAL chunk data (%lu bytes)",
1840 if (png_ptr->chunkdata ==
NULL)
1842 png_warning(png_ptr,
"Out of memory while processing sCAL chunk");
1851 png_free(png_ptr, png_ptr->chunkdata);
1852 png_ptr->chunkdata =
NULL;
1856 png_ptr->chunkdata[slength] = 0x00;
1858 ep = png_ptr->chunkdata + 1;
1860 #ifdef PNG_FLOATING_POINT_SUPPORTED 1864 png_warning(png_ptr,
"malformed width string in sCAL chunk");
1865 png_free(png_ptr, png_ptr->chunkdata);
1866 png_ptr->chunkdata =
NULL;
1870 #ifdef PNG_FIXED_POINT_SUPPORTED 1874 png_warning(png_ptr,
"Out of memory while processing sCAL chunk width");
1875 png_free(png_ptr, png_ptr->chunkdata);
1876 png_ptr->chunkdata =
NULL;
1883 for (ep = png_ptr->chunkdata + 1; *ep; ep++)
1887 if (png_ptr->chunkdata + slength < ep)
1890 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) 1893 png_free(png_ptr, png_ptr->chunkdata);
1894 png_ptr->chunkdata =
NULL;
1898 #ifdef PNG_FLOATING_POINT_SUPPORTED 1902 png_warning(png_ptr,
"malformed height string in sCAL chunk");
1903 png_free(png_ptr, png_ptr->chunkdata);
1904 png_ptr->chunkdata =
NULL;
1905 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) 1911 #ifdef PNG_FIXED_POINT_SUPPORTED 1913 if (sheight ==
NULL)
1915 png_warning(png_ptr,
"Out of memory while processing sCAL chunk height");
1916 png_free(png_ptr, png_ptr->chunkdata);
1917 png_ptr->chunkdata =
NULL;
1918 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) 1927 if (png_ptr->chunkdata + slength < ep
1929 || width <= 0. || height <= 0.
1934 png_free(png_ptr, png_ptr->chunkdata);
1935 png_ptr->chunkdata =
NULL;
1936 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) 1944 #ifdef PNG_FLOATING_POINT_SUPPORTED 1945 png_set_sCAL(png_ptr, info_ptr, png_ptr->chunkdata[0], width, height);
1947 #ifdef PNG_FIXED_POINT_SUPPORTED 1948 png_set_sCAL_s(png_ptr, info_ptr, png_ptr->chunkdata[0], swidth, sheight);
1952 png_free(png_ptr, png_ptr->chunkdata);
1953 png_ptr->chunkdata =
NULL;
1954 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) 1961 #ifdef PNG_READ_tIME_SUPPORTED 1971 png_error(png_ptr,
"Out of place tIME chunk");
1984 png_warning(png_ptr,
"Incorrect tIME chunk length");
1993 mod_time.
second = buf[6];
1994 mod_time.
minute = buf[5];
1995 mod_time.
hour = buf[4];
1996 mod_time.
day = buf[3];
1997 mod_time.
month = buf[2];
2004 #ifdef PNG_READ_tEXt_SUPPORTED 2018 #ifdef PNG_USER_LIMITS_SUPPORTED 2019 if (png_ptr->user_chunk_cache_max != 0)
2021 if (png_ptr->user_chunk_cache_max == 1)
2026 if (--png_ptr->user_chunk_cache_max == 1)
2028 png_warning(png_ptr,
"No space in chunk cache for tEXt");
2036 png_error(png_ptr,
"Missing IHDR before tEXt");
2041 #ifdef PNG_MAX_MALLOC_64K 2044 png_warning(png_ptr,
"tEXt chunk too large to fit in memory");
2050 png_free(png_ptr, png_ptr->chunkdata);
2053 if (png_ptr->chunkdata ==
NULL)
2055 png_warning(png_ptr,
"No memory to process text chunk.");
2063 png_free(png_ptr, png_ptr->chunkdata);
2064 png_ptr->chunkdata =
NULL;
2068 key = png_ptr->chunkdata;
2070 key[slength] = 0x00;
2072 for (text = key; *text; text++)
2075 if (text != key + slength)
2080 if (text_ptr ==
NULL)
2082 png_warning(png_ptr,
"Not enough memory to process text chunk.");
2083 png_free(png_ptr, png_ptr->chunkdata);
2084 png_ptr->chunkdata =
NULL;
2088 text_ptr->key = key;
2089 #ifdef PNG_iTXt_SUPPORTED 2090 text_ptr->lang =
NULL;
2091 text_ptr->lang_key =
NULL;
2092 text_ptr->itxt_length = 0;
2094 text_ptr->text = text;
2099 png_free(png_ptr, png_ptr->chunkdata);
2100 png_ptr->chunkdata =
NULL;
2103 png_warning(png_ptr,
"Insufficient memory to process text chunk.");
2107 #ifdef PNG_READ_zTXt_SUPPORTED 2120 #ifdef PNG_USER_LIMITS_SUPPORTED 2121 if (png_ptr->user_chunk_cache_max != 0)
2123 if (png_ptr->user_chunk_cache_max == 1)
2128 if (--png_ptr->user_chunk_cache_max == 1)
2130 png_warning(png_ptr,
"No space in chunk cache for zTXt");
2138 png_error(png_ptr,
"Missing IHDR before zTXt");
2143 #ifdef PNG_MAX_MALLOC_64K 2148 png_warning(png_ptr,
"zTXt chunk too large to fit in memory");
2154 png_free(png_ptr, png_ptr->chunkdata);
2156 if (png_ptr->chunkdata ==
NULL)
2158 png_warning(png_ptr,
"Out of memory processing zTXt chunk.");
2165 png_free(png_ptr, png_ptr->chunkdata);
2166 png_ptr->chunkdata =
NULL;
2170 png_ptr->chunkdata[slength] = 0x00;
2172 for (text = png_ptr->chunkdata; *text; text++)
2176 if (slength < 2U || text >= png_ptr->chunkdata + slength - 2U)
2179 png_free(png_ptr, png_ptr->chunkdata);
2180 png_ptr->chunkdata =
NULL;
2185 comp_type = *(++text);
2188 png_warning(png_ptr,
"Unknown compression type in zTXt chunk");
2193 prefix_len = text - png_ptr->chunkdata;
2200 if (text_ptr ==
NULL)
2202 png_warning(png_ptr,
"Not enough memory to process zTXt chunk.");
2203 png_free(png_ptr, png_ptr->chunkdata);
2204 png_ptr->chunkdata =
NULL;
2207 text_ptr->compression = comp_type;
2208 text_ptr->key = png_ptr->chunkdata;
2209 #ifdef PNG_iTXt_SUPPORTED 2210 text_ptr->lang =
NULL;
2211 text_ptr->lang_key =
NULL;
2212 text_ptr->itxt_length = 0;
2214 text_ptr->text = png_ptr->chunkdata + prefix_len;
2215 text_ptr->text_length = data_len;
2220 png_free(png_ptr, png_ptr->chunkdata);
2221 png_ptr->chunkdata =
NULL;
2223 png_error(png_ptr,
"Insufficient memory to store zTXt chunk.");
2227 #ifdef PNG_READ_iTXt_SUPPORTED 2241 #ifdef PNG_USER_LIMITS_SUPPORTED 2242 if (png_ptr->user_chunk_cache_max != 0)
2244 if (png_ptr->user_chunk_cache_max == 1)
2249 if (--png_ptr->user_chunk_cache_max == 1)
2251 png_warning(png_ptr,
"No space in chunk cache for iTXt");
2259 png_error(png_ptr,
"Missing IHDR before iTXt");
2264 #ifdef PNG_MAX_MALLOC_64K 2269 png_warning(png_ptr,
"iTXt chunk too large to fit in memory");
2275 png_free(png_ptr, png_ptr->chunkdata);
2277 if (png_ptr->chunkdata ==
NULL)
2279 png_warning(png_ptr,
"No memory to process iTXt chunk.");
2286 png_free(png_ptr, png_ptr->chunkdata);
2287 png_ptr->chunkdata =
NULL;
2291 png_ptr->chunkdata[slength] = 0x00;
2293 for (lang = png_ptr->chunkdata; *lang; lang++)
2302 if (slength < 3U || lang >= png_ptr->chunkdata + slength - 3U)
2305 png_free(png_ptr, png_ptr->chunkdata);
2306 png_ptr->chunkdata =
NULL;
2311 comp_flag = *lang++;
2312 comp_type = *lang++;
2315 for (lang_key = lang; *lang_key; lang_key++)
2319 if (lang_key >= png_ptr->chunkdata + slength)
2322 png_free(png_ptr, png_ptr->chunkdata);
2323 png_ptr->chunkdata =
NULL;
2327 for (text = lang_key; *text; text++)
2330 if (text >= png_ptr->chunkdata + slength)
2333 png_free(png_ptr, png_ptr->chunkdata);
2334 png_ptr->chunkdata =
NULL;
2338 prefix_len = text - png_ptr->chunkdata;
2340 key=png_ptr->chunkdata;
2343 (
size_t)length, prefix_len, &data_len);
2345 data_len =
png_strlen(png_ptr->chunkdata + prefix_len);
2348 if (text_ptr ==
NULL)
2350 png_warning(png_ptr,
"Not enough memory to process iTXt chunk.");
2351 png_free(png_ptr, png_ptr->chunkdata);
2352 png_ptr->chunkdata =
NULL;
2355 text_ptr->compression = (
int)comp_flag + 1;
2356 text_ptr->lang_key = png_ptr->chunkdata + (lang_key - key);
2357 text_ptr->lang = png_ptr->chunkdata + (lang - key);
2358 text_ptr->itxt_length = data_len;
2359 text_ptr->text_length = 0;
2360 text_ptr->key = png_ptr->chunkdata;
2361 text_ptr->text = png_ptr->chunkdata + prefix_len;
2366 png_free(png_ptr, png_ptr->chunkdata);
2367 png_ptr->chunkdata =
NULL;
2369 png_error(png_ptr,
"Insufficient memory to store iTXt chunk.");
2385 #ifdef PNG_USER_LIMITS_SUPPORTED 2386 if (png_ptr->user_chunk_cache_max != 0)
2388 if (png_ptr->user_chunk_cache_max == 1)
2393 if (--png_ptr->user_chunk_cache_max == 1)
2395 png_warning(png_ptr,
"No space in chunk cache for unknown chunk");
2404 #ifdef PNG_USE_LOCAL_ARRAYS 2407 if (
png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
2411 if (!(png_ptr->chunk_name[0] & 0x20))
2413 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED 2417 && png_ptr->read_user_chunk_fn ==
NULL 2424 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED 2425 if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
2427 || (png_ptr->read_user_chunk_fn !=
NULL)
2431 #ifdef PNG_MAX_MALLOC_64K 2434 png_warning(png_ptr,
"unknown chunk too large to fit in memory");
2442 png_ptr->unknown_chunk.name[
png_sizeof(png_ptr->unknown_chunk.name)-1]
2444 png_ptr->unknown_chunk.size = (
png_size_t)length;
2446 png_ptr->unknown_chunk.data =
NULL;
2452 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED 2453 if (png_ptr->read_user_chunk_fn !=
NULL)
2457 ret = (*(png_ptr->read_user_chunk_fn))
2458 (png_ptr, &png_ptr->unknown_chunk);
2463 if (!(png_ptr->chunk_name[0] & 0x20))
2464 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED 2470 &png_ptr->unknown_chunk, 1);
2476 png_free(png_ptr, png_ptr->unknown_chunk.data);
2477 png_ptr->unknown_chunk.data =
NULL;
2485 #ifndef PNG_READ_USER_CHUNKS_SUPPORTED 2496 #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) 2501 png_debug(1,
"in png_check_chunk_name");
2527 PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
2531 switch (png_ptr->row_info.pixel_depth)
2537 int s_inc, s_start, s_end;
2543 #ifdef PNG_READ_PACKSWAP_SUPPORTED 2544 if (png_ptr->transformations & PNG_PACKSWAP)
2560 for (i = 0; i < row_width; i++)
2566 value = (*sp >> shift) & 0x01;
2567 *dp &= (
png_byte)((0x7f7f >> (7 - shift)) & 0xff);
2591 int s_start, s_end, s_inc;
2598 #ifdef PNG_READ_PACKSWAP_SUPPORTED 2599 if (png_ptr->transformations & PNG_PACKSWAP)
2615 for (i = 0; i < row_width; i++)
2619 value = (*sp >> shift) & 0x03;
2620 *dp &= (
png_byte)((0x3f3f >> (6 - shift)) & 0xff);
2643 int s_start, s_end, s_inc;
2650 #ifdef PNG_READ_PACKSWAP_SUPPORTED 2651 if (png_ptr->transformations & PNG_PACKSWAP)
2666 for (i = 0; i < row_width; i++)
2670 value = (*sp >> shift) & 0xf;
2671 *dp &= (
png_byte)((0xf0f >> (4 - shift)) & 0xff);
2694 png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
2700 for (i = 0; i < row_width; i++)
2721 #ifdef PNG_READ_INTERLACING_SUPPORTED 2731 int pass = png_ptr->pass;
2732 png_uint_32 transformations = png_ptr->transformations;
2735 #ifndef PNG_USE_GLOBAL_ARRAYS 2739 png_debug(1,
"in png_do_read_interlace");
2740 if (row !=
NULL && row_info !=
NULL)
2744 final_width = row_info->width * png_pass_inc[pass];
2746 switch (row_info->pixel_depth)
2753 int s_start, s_end, s_inc;
2754 int jstop = png_pass_inc[pass];
2759 #ifdef PNG_READ_PACKSWAP_SUPPORTED 2760 if (transformations & PNG_PACKSWAP)
2762 sshift = (
int)((row_info->width + 7) & 0x07);
2763 dshift = (
int)((final_width + 7) & 0x07);
2771 sshift = 7 - (
int)((row_info->width + 7) & 0x07);
2772 dshift = 7 - (
int)((final_width + 7) & 0x07);
2778 for (i = 0; i < row_info->width; i++)
2780 v = (
png_byte)((*sp >> sshift) & 0x01);
2781 for (j = 0; j < jstop; j++)
2783 *dp &= (
png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
2785 if (dshift == s_end)
2793 if (sshift == s_end)
2808 int s_start, s_end, s_inc;
2809 int jstop = png_pass_inc[pass];
2812 #ifdef PNG_READ_PACKSWAP_SUPPORTED 2813 if (transformations & PNG_PACKSWAP)
2815 sshift = (
int)(((row_info->width + 3) & 0x03) << 1);
2816 dshift = (
int)(((final_width + 3) & 0x03) << 1);
2824 sshift = (
int)((3 - ((row_info->width + 3) & 0x03)) << 1);
2825 dshift = (
int)((3 - ((final_width + 3) & 0x03)) << 1);
2831 for (i = 0; i < row_info->width; i++)
2836 v = (
png_byte)((*sp >> sshift) & 0x03);
2837 for (j = 0; j < jstop; j++)
2839 *dp &= (
png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
2841 if (dshift == s_end)
2849 if (sshift == s_end)
2864 int s_start, s_end, s_inc;
2866 int jstop = png_pass_inc[pass];
2868 #ifdef PNG_READ_PACKSWAP_SUPPORTED 2869 if (transformations & PNG_PACKSWAP)
2871 sshift = (
int)(((row_info->width + 1) & 0x01) << 2);
2872 dshift = (
int)(((final_width + 1) & 0x01) << 2);
2880 sshift = (
int)((1 - ((row_info->width + 1) & 0x01)) << 2);
2881 dshift = (
int)((1 - ((final_width + 1) & 0x01)) << 2);
2887 for (i = 0; i < row_info->width; i++)
2892 for (j = 0; j < jstop; j++)
2894 *dp &= (
png_byte)((0xf0f >> (4 - dshift)) & 0xff);
2896 if (dshift == s_end)
2904 if (sshift == s_end)
2916 png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
2921 int jstop = png_pass_inc[pass];
2924 for (i = 0; i < row_info->width; i++)
2930 for (j = 0; j < jstop; j++)
2940 row_info->width = final_width;
2941 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width);
2943 #ifndef PNG_READ_PACKSWAP_SUPPORTED 2954 png_debug2(2,
"row = %lu, filter = %d", png_ptr->row_number, filter);
2963 png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
2967 for (i = bpp; i < istop; i++)
2969 *rp = (
png_byte)(((
int)(*rp) + (
int)(*lp++)) & 0xff);
2981 for (i = 0; i < istop; i++)
2983 *rp = (
png_byte)(((
int)(*rp) + (
int)(*pp++)) & 0xff);
2994 png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
2997 for (i = 0; i < bpp; i++)
3000 ((
int)(*pp++) / 2 )) & 0xff);
3004 for (i = 0; i < istop; i++)
3007 (
int)(*pp++ + *lp++) / 2 ) & 0xff);
3019 png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
3022 for (i = 0; i < bpp; i++)
3024 *rp = (
png_byte)(((
int)(*rp) + (
int)(*pp++)) & 0xff);
3028 for (i = 0; i < istop; i++)
3030 int a,
b,
c, pa, pb, pc,
p;
3044 pa = p < 0 ? -
p :
p;
3045 pb = pc < 0 ? -pc : pc;
3046 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
3058 p = (pa <= pb && pa <= pc) ? a : (pb <= pc) ?
b :
c;
3060 *rp = (
png_byte)(((
int)(*rp) +
p) & 0xff);
3066 png_warning(png_ptr,
"Ignoring bad adaptive filter type");
3072 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED 3076 #ifdef PNG_READ_INTERLACING_SUPPORTED 3077 #ifndef PNG_USE_GLOBAL_ARRAYS 3095 png_ptr->row_number++;
3096 if (png_ptr->row_number < png_ptr->num_rows)
3099 #ifdef PNG_READ_INTERLACING_SUPPORTED 3100 if (png_ptr->interlaced)
3102 png_ptr->row_number = 0;
3104 png_ptr->rowbytes + 1);
3108 if (png_ptr->pass >= 7)
3110 png_ptr->iwidth = (png_ptr->width +
3111 png_pass_inc[png_ptr->pass] - 1 -
3112 png_pass_start[png_ptr->pass]) /
3113 png_pass_inc[png_ptr->pass];
3115 if (!(png_ptr->transformations & PNG_INTERLACE))
3117 png_ptr->num_rows = (png_ptr->height +
3118 png_pass_yinc[png_ptr->pass] - 1 -
3119 png_pass_ystart[png_ptr->pass]) /
3120 png_pass_yinc[png_ptr->pass];
3121 if (!(png_ptr->num_rows))
3126 }
while (png_ptr->iwidth == 0);
3128 if (png_ptr->pass < 7)
3133 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
3135 #ifdef PNG_USE_LOCAL_ARRAYS 3141 png_ptr->zstream.next_out = (
Byte *)&extra;
3142 png_ptr->zstream.avail_out = (
uInt)1;
3145 if (!(png_ptr->zstream.avail_in))
3147 while (!png_ptr->idat_size)
3157 if (
png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
3158 png_error(png_ptr,
"Not enough image data");
3161 png_ptr->zstream.avail_in = (
uInt)png_ptr->zbuf_size;
3162 png_ptr->zstream.next_in = png_ptr->zbuf;
3163 if (png_ptr->zbuf_size > png_ptr->idat_size)
3164 png_ptr->zstream.avail_in = (
uInt)png_ptr->idat_size;
3165 png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
3166 png_ptr->idat_size -= png_ptr->zstream.avail_in;
3171 if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
3175 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
3179 png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
3180 "Decompression Error");
3182 if (!(png_ptr->zstream.avail_out))
3186 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
3191 png_ptr->zstream.avail_out = 0;
3194 if (png_ptr->idat_size || png_ptr->zstream.avail_in)
3206 #ifdef PNG_READ_INTERLACING_SUPPORTED 3207 #ifndef PNG_USE_GLOBAL_ARRAYS 3224 int max_pixel_depth;
3228 png_ptr->zstream.avail_in = 0;
3230 #ifdef PNG_READ_INTERLACING_SUPPORTED 3231 if (png_ptr->interlaced)
3233 if (!(png_ptr->transformations & PNG_INTERLACE))
3234 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
3235 png_pass_ystart[0]) / png_pass_yinc[0];
3237 png_ptr->num_rows = png_ptr->height;
3239 png_ptr->iwidth = (png_ptr->width +
3240 png_pass_inc[png_ptr->pass] - 1 -
3241 png_pass_start[png_ptr->pass]) /
3242 png_pass_inc[png_ptr->pass];
3247 png_ptr->num_rows = png_ptr->height;
3248 png_ptr->iwidth = png_ptr->width;
3250 max_pixel_depth = png_ptr->pixel_depth;
3252 #ifdef PNG_READ_PACK_SUPPORTED 3253 if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
3254 max_pixel_depth = 8;
3257 #ifdef PNG_READ_EXPAND_SUPPORTED 3258 if (png_ptr->transformations & PNG_EXPAND)
3262 if (png_ptr->num_trans)
3263 max_pixel_depth = 32;
3265 max_pixel_depth = 24;
3269 if (max_pixel_depth < 8)
3270 max_pixel_depth = 8;
3271 if (png_ptr->num_trans)
3272 max_pixel_depth *= 2;
3276 if (png_ptr->num_trans)
3278 max_pixel_depth *= 4;
3279 max_pixel_depth /= 3;
3285 #ifdef PNG_READ_FILLER_SUPPORTED 3286 if (png_ptr->transformations & (PNG_FILLER))
3289 max_pixel_depth = 32;
3292 if (max_pixel_depth <= 8)
3293 max_pixel_depth = 16;
3295 max_pixel_depth = 32;
3299 if (max_pixel_depth <= 32)
3300 max_pixel_depth = 32;
3302 max_pixel_depth = 64;
3307 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED 3308 if (png_ptr->transformations & PNG_GRAY_TO_RGB)
3312 (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
3315 (png_ptr->transformations & (PNG_FILLER)) ||
3319 if (max_pixel_depth <= 16)
3320 max_pixel_depth = 32;
3322 max_pixel_depth = 64;
3326 if (max_pixel_depth <= 8)
3329 max_pixel_depth = 32;
3331 max_pixel_depth = 24;
3334 max_pixel_depth = 64;
3336 max_pixel_depth = 48;
3341 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \ 3342 defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) 3343 if (png_ptr->transformations & PNG_USER_TRANSFORM)
3345 int user_pixel_depth = png_ptr->user_transform_depth*
3346 png_ptr->user_transform_channels;
3347 if (user_pixel_depth > max_pixel_depth)
3348 max_pixel_depth=user_pixel_depth;
3355 row_bytes = ((png_ptr->width + 7) & ~((
png_uint_32)7));
3359 row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +
3360 1 + ((max_pixel_depth + 7) >> 3);
3361 #ifdef PNG_MAX_MALLOC_64K 3363 png_error(png_ptr,
"This image requires a row greater than 64KB");
3366 if (row_bytes + 64 > png_ptr->old_big_row_buf_size)
3368 png_free(png_ptr, png_ptr->big_row_buf);
3369 if (png_ptr->interlaced)
3375 png_ptr->old_big_row_buf_size = row_bytes + 64;
3378 png_ptr->row_buf = png_ptr->big_row_buf + 32;
3379 png_ptr->old_big_row_buf_size = row_bytes + 64;
3382 #ifdef PNG_MAX_MALLOC_64K 3384 png_error(png_ptr,
"This image requires a row greater than 64KB");
3387 png_error(png_ptr,
"Row has too many bytes to allocate in memory.");
3389 if (row_bytes + 1 > png_ptr->old_prev_row_size)
3391 png_free(png_ptr, png_ptr->prev_row);
3395 png_ptr->old_prev_row_size = row_bytes + 1;
3398 png_ptr->rowbytes = row_bytes;
3400 png_debug1(3,
"width = %lu,", png_ptr->width);
3401 png_debug1(3,
"height = %lu,", png_ptr->height);
3402 png_debug1(3,
"iwidth = %lu,", png_ptr->iwidth);
3403 png_debug1(3,
"num_rows = %lu,", png_ptr->num_rows);
3404 png_debug1(3,
"rowbytes = %lu,", png_ptr->rowbytes);
3406 PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1);
3408 png_ptr->flags |= PNG_FLAG_ROW_INIT;
GLenum GLuint GLenum GLsizei length
void PNGAPI png_set_iCCP(png_structp png_ptr, png_infop info_ptr, png_charp name, int compression_type, png_charp profile, png_uint_32 proflen)
png_infop png_charpp int png_charpp profile
#define PNG_FILTER_VALUE_AVG
GLint GLint GLsizei GLsizei height
void PNGAPI png_set_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_type, int compression_type, int filter_type)
png_infop png_uint_32 * res_x
PNG_CONST int FARDATA png_pass_start[]
void PNGAPI png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
void PNGAPI png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, png_fixed_point blue_y)
void PNGAPI png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
void png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
GLboolean GLboolean GLboolean GLboolean a
png_infop png_uint_32 png_uint_32 * res_y
png_infop double double double double double double double double * blue_y
png_infop png_textp * text_ptr
png_infop double double double double double double double * blue_x
#define PNG_MAX_PALETTE_LENGTH
png_voidp png_calloc(png_structp png_ptr, png_uint_32 size)
void PNGAPI png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
#define PNG_COLOR_TYPE_RGB
#define PNG_COLOR_TYPE_GRAY_ALPHA
void PNGAPI png_set_unknown_chunks(png_structp png_ptr, png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
#define PNG_EQUATION_LINEAR
#define PNG_COLOR_TYPE_PALETTE
void png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void PNGAPI png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, int intent)
PNG_CONST int FARDATA png_pass_yinc[]
#define PNG_UNUSED(param)
void png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_infop png_charp png_int_32 png_int_32 * X1
#define PNG_FILTER_VALUE_PAETH
png_uint_32 PNGAPI png_get_uint_32(png_bytep buf)
void PNGAPI png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
GLint GLint GLsizei width
png_infop png_int_32 png_int_32 * offset_y
#define PNG_READ_FILLER_SUPPORTED
#define PNG_COLOR_TYPE_RGB_ALPHA
int ZEXPORT inflateReset(z_streamp strm)
png_infop png_int_32 * offset_x
int PNGAPI png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
png_uint_16 PNGAPI png_get_uint_16(png_bytep buf)
void png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
PNG_CONST int FARDATA png_pass_ystart[]
GLboolean GLboolean GLboolean b
void png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void PNGAPI png_set_sCAL(png_structp png_ptr, png_infop info_ptr, int unit, double width, double height)
png_infop double double double double * red_y
void PNGAPI png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
#define PNG_sRGB_INTENT_LAST
GLenum GLuint GLenum GLsizei const GLchar * buf
void PNGAPI png_set_oFFs(png_structp png_ptr, png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y, int unit_type)
void PNGAPI png_set_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p sig_bit)
void png_read_finish_row(png_structp png_ptr)
void PNGAPI png_set_sPLT(png_structp png_ptr, png_infop info_ptr, png_sPLT_tp entries, int nentries)
png_infop png_charp png_int_32 * X0
void png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
void png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
GLenum GLenum GLvoid * row
void png_init_read_transformations(png_structp png_ptr)
png_infop png_charpp int * compression_type
#define PNG_TEXT_COMPRESSION_zTXt
void png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#define PNG_USER_CHUNK_MALLOC_MAX
#define PNG_TEXT_COMPRESSION_NONE
png_struct FAR * png_structp
void png_read_start_row(png_structp png_ptr)
#define PNG_HANDLE_CHUNK_ALWAYS
#define png_error(s1, s2)
#define PNG_COLOR_MASK_COLOR
void png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_int_32 PNGAPI png_get_int_32(png_bytep buf)
unsigned short png_uint_16
GLsizei GLsizei GLenum GLenum const GLvoid * data
void PNGAPI png_set_cHRM(png_structp png_ptr, png_infop info_ptr, double white_x, double white_y, double red_x, double red_y, double green_x, double green_y, double blue_x, double blue_y)
void png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void png_do_read_interlace(png_structp png_ptr)
void PNGAPI png_set_pCAL(png_structp png_ptr, png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
#define PNG_FILTER_VALUE_SUB
#define PNG_COLOR_TYPE_GRAY
png_sPLT_entry FAR * png_sPLT_entryp
void PNGAPI png_warning(png_structp png_ptr, png_const_charp warning_message)
void png_combine_row(png_structp png_ptr, png_bytep row, int mask)
int ZEXPORT inflate(z_streamp strm, int flush)
#define PNG_EQUATION_ARBITRARY
void PNGAPI png_set_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp palette, int num_palette)
#define PNG_READ_USER_CHUNKS_SUPPORTED
void png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#define PNG_EQUATION_LAST
GLsizei const GLfloat * value
#define png_debug1(l, m, p1)
int png_crc_finish(png_structp png_ptr, png_uint_32 skip)
void PNGAPI png_chunk_error(png_structp png_ptr, png_const_charp error_message)
#define PNG_FILTER_VALUE_UP
local void skip(file *in, unsigned n)
png_infop double * file_gamma
int png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, int num_text)
png_uint_32 PNGAPI png_get_uint_31(png_structp png_ptr, png_bytep buf)
void png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if(!abbox) return FT_THROW(Invalid_Argument)
void png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
PNG_CONST int FARDATA png_pass_inc[]
#define PNG_READ_EXPAND_SUPPORTED
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLenum const GLfloat * params
void png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter)
#define PNG_FLOATING_POINT_SUPPORTED
#define PNG_COMPRESSION_TYPE_BASE
png_infop double double double double double double * green_y
png_infop double double * white_y
png_infop png_charp png_int_32 png_int_32 int int * nparams
void png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#define PNG_READ_sRGB_SUPPORTED
png_int_32 png_fixed_point
png_infop double double double * red_x
#define PNG_EQUATION_HYPERBOLIC
char FAR *FAR * png_charpp
void png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_voidp PNGAPI png_memset_check(png_structp png_ptr, png_voidp s1, int value, png_uint_32 length)
#define PNG_FILTER_VALUE_NONE
void png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
int png_crc_error(png_structp png_ptr)
png_infop png_int_32 png_int_32 int * unit_type
void png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
GLuint GLuint GLsizei count
#define PNG_EQUATION_BASE_E
void png_decompress_chunk(png_structp png_ptr, int comp_type, png_size_t chunklength, png_size_t prefix_size, png_size_t *newlength)
void png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void PNGAPI png_set_tRNS(png_structp png_ptr, png_infop info_ptr, png_bytep trans, int num_trans, png_color_16p trans_values)
png_infop double double double double double * green_x
void PNGAPI png_set_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type)
unsigned long png_uint_32
png_row_info FAR * png_row_infop
void png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#define png_strtod(p, a, b)
void PNGAPI png_free(png_structp png_ptr, png_voidp ptr)
#define png_debug2(l, m, p1, p2)
png_infop double * white_x
png_infop png_timep * mod_time
void png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
png_voidp PNGAPI png_malloc(png_structp png_ptr, png_uint_32 size)
void png_reset_crc(png_structp png_ptr)
png_voidp PNGAPI png_malloc_warn(png_structp png_ptr, png_uint_32 size)
output(gif_dest_ptr dinfo, int code)
png_uint_32 png_read_chunk_header(png_structp png_ptr)
void PNGAPI png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point int_gamma)
png_color FAR * png_colorp