19 #ifdef PNG_READ_SUPPORTED
21 #define png_strtod(p,a,b) strtod(a,b)
29 png_error(png_ptr,
"PNG unsigned integer out of range");
34 #if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_READ_cHRM_SUPPORTED)
40 #define PNG_FIXED_ERROR (-1)
52 png_warning(png_ptr,
"PNG fixed point integer out of range");
58 #ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
90 if ((uval & 0x80000000) == 0)
93 uval = (uval ^ 0xffffffff) + 1;
107 ((
unsigned int)(*
buf) << 8) +
108 ((
unsigned int)(*(
buf + 1)));
122 if (png_ptr->sig_bytes >= 8)
125 num_checked = png_ptr->sig_bytes;
126 num_to_check = 8 - num_checked;
128 #ifdef PNG_IO_STATE_SUPPORTED
133 png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
134 png_ptr->sig_bytes = 8;
136 if (
png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
138 if (num_checked < 4 &&
139 png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
142 png_error(png_ptr,
"PNG file corrupted by ASCII conversion");
157 #ifdef PNG_IO_STATE_SUPPORTED
170 png_debug2(0,
"Reading %lx chunk, length = %lu",
171 (
unsigned long)png_ptr->chunk_name, (
unsigned long)length);
180 #ifdef PNG_IO_STATE_SUPPORTED
209 for (i = (
png_size_t)skip; i > istop; i -= istop)
211 png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
263 #ifdef PNG_IO_STATE_SUPPORTED
273 return ((
int)(crc != png_ptr->crc));
280 #ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED
296 png_ptr->zstream.next_in =
data;
298 png_ptr->zstream.avail_in = 0;
311 if (png_ptr->zstream.avail_in == 0 && size > 0)
316 png_ptr->zstream.avail_in = (
uInt)size;
330 png_ptr->zstream.next_out = png_ptr->zbuf;
331 png_ptr->zstream.avail_out = png_ptr->zbuf_size;
334 avail = png_ptr->zbuf_size - png_ptr->zstream.avail_out;
343 if (output != 0 && output_size > count)
350 png_memcpy(output + count, png_ptr->zbuf, copy);
361 png_ptr->zstream.avail_in = 0;
371 # ifdef PNG_WARNINGS_SUPPORTED
375 if (png_ptr->zstream.msg != 0)
376 msg = png_ptr->zstream.msg;
381 msg =
"Buffer error in compressed datastream";
385 msg =
"Data error in compressed datastream";
389 msg =
"Incomplete compressed datastream";
417 if (prefix_size > chunklength)
427 (
png_bytep)(png_ptr->chunkdata + prefix_size),
428 chunklength - prefix_size,
436 expanded_size >= (~(
png_size_t)0) - 1 - prefix_size
438 || (png_ptr->user_chunk_malloc_max &&
439 (prefix_size + expanded_size >= png_ptr->user_chunk_malloc_max - 1))
447 png_warning(png_ptr,
"Exceeded size limit while expanding chunk");
454 else if (expanded_size > 0)
459 prefix_size + expanded_size + 1);
463 png_memcpy(text, png_ptr->chunkdata, prefix_size);
465 (
png_bytep)(png_ptr->chunkdata + prefix_size),
466 chunklength - prefix_size,
467 (
png_bytep)(text + prefix_size), expanded_size);
468 text[prefix_size + expanded_size] = 0;
470 if (new_size == expanded_size)
472 png_free(png_ptr, png_ptr->chunkdata);
473 png_ptr->chunkdata = text;
474 *newlength = prefix_size + expanded_size;
483 png_warning(png_ptr,
"Not enough memory to decompress chunk");
506 png_memcpy(text, png_ptr->chunkdata, prefix_size);
508 png_free(png_ptr, png_ptr->chunkdata);
509 png_ptr->chunkdata = text;
512 *(png_ptr->chunkdata + prefix_size) = 0x00;
517 *newlength = prefix_size;
537 png_error(png_ptr,
"Invalid IHDR chunk");
548 compression_type = buf[10];
549 filter_type = buf[11];
550 interlace_type = buf[12];
553 png_ptr->width =
width;
555 png_ptr->bit_depth = (
png_byte)bit_depth;
556 png_ptr->interlaced = (
png_byte)interlace_type;
557 png_ptr->color_type = (
png_byte)color_type;
558 #ifdef PNG_MNG_FEATURES_SUPPORTED
559 png_ptr->filter_type = (
png_byte)filter_type;
561 png_ptr->compression_type = (
png_byte)compression_type;
564 switch (png_ptr->color_type)
569 png_ptr->channels = 1;
573 png_ptr->channels = 3;
577 png_ptr->channels = 2;
581 png_ptr->channels = 4;
586 png_ptr->pixel_depth = (
png_byte)(png_ptr->bit_depth *
588 png_ptr->rowbytes =
PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width);
589 png_debug1(3,
"bit_depth = %d", png_ptr->bit_depth);
590 png_debug1(3,
"channels = %d", png_ptr->channels);
591 png_debug1(3,
"rowbytes = %lu", (
unsigned long)png_ptr->rowbytes);
592 png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
593 color_type, interlace_type, compression_type, filter_type);
602 #ifdef PNG_POINTER_INDEXING_SUPPORTED
609 png_error(png_ptr,
"Missing IHDR before PLTE");
619 png_error(png_ptr,
"Duplicate PLTE chunk");
626 "Ignoring PLTE chunk in grayscale PNG");
631 #ifndef PNG_READ_OPT_PLTE_SUPPORTED
650 png_error(png_ptr,
"Invalid palette chunk");
654 num = (
int)length / 3;
656 #ifdef PNG_POINTER_INDEXING_SUPPORTED
657 for (i = 0, pal_ptr = palette; i <
num; i++, pal_ptr++)
662 pal_ptr->red = buf[0];
663 pal_ptr->green = buf[1];
664 pal_ptr->blue = buf[2];
667 for (i = 0; i <
num; i++)
673 palette[
i].
red = buf[0];
674 palette[
i].
green = buf[1];
675 palette[
i].
blue = buf[2];
684 #ifndef PNG_READ_OPT_PLTE_SUPPORTED
691 #ifndef PNG_READ_OPT_PLTE_SUPPORTED
723 #ifdef PNG_READ_tRNS_SUPPORTED
730 png_warning(png_ptr,
"Truncating incorrect tRNS chunk length");
736 png_warning(png_ptr,
"Truncating incorrect info tRNS chunk length");
759 png_warning(png_ptr,
"Incorrect IEND chunk length");
767 #ifdef PNG_READ_gAMA_SUPPORTED
777 png_error(png_ptr,
"Missing IHDR before gAMA");
803 png_warning(png_ptr,
"Incorrect gAMA chunk length");
819 "Ignoring gAMA chunk with out of range gamma");
824 # ifdef PNG_READ_sRGB_SUPPORTED
832 "Ignoring incorrect gAMA value @1 when sRGB is also present");
838 # ifdef PNG_READ_GAMMA_SUPPORTED
840 png_ptr->gamma = igamma;
847 #ifdef PNG_READ_sBIT_SUPPORTED
856 buf[0] = buf[1] = buf[2] = buf[3] = 0;
859 png_error(png_ptr,
"Missing IHDR before sBIT");
887 if (length != truelen || length > 4)
889 png_warning(png_ptr,
"Incorrect sBIT chunk length");
901 png_ptr->sig_bit.red = buf[0];
902 png_ptr->sig_bit.green = buf[1];
903 png_ptr->sig_bit.blue = buf[2];
904 png_ptr->sig_bit.alpha = buf[3];
909 png_ptr->sig_bit.gray = buf[0];
910 png_ptr->sig_bit.red = buf[0];
911 png_ptr->sig_bit.green = buf[0];
912 png_ptr->sig_bit.blue = buf[0];
913 png_ptr->sig_bit.alpha = buf[1];
920 #ifdef PNG_READ_cHRM_SUPPORTED
925 png_fixed_point x_white, y_white, x_red, y_red, x_green, y_green, x_blue,
931 png_error(png_ptr,
"Missing IHDR before cHRM");
957 png_warning(png_ptr,
"Incorrect cHRM chunk length");
985 png_warning(png_ptr,
"Ignoring cHRM chunk with negative chromaticities");
989 #ifdef PNG_READ_sRGB_SUPPORTED
1013 "Ignoring incorrect cHRM white(@1,@2) r(@3,@4)g(@5,@6)b(@7,@8) "
1014 "when sRGB is also present");
1020 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1025 if (!png_ptr->rgb_to_gray_coefficients_set)
1051 r >= 0 && r <= 32768 &&
1053 g >= 0 && g <= 32768 &&
1055 b >= 0 && b <= 32768 &&
1067 else if (r+g+b < 32768)
1072 if (g >= r && g >= b)
1074 else if (r >= g && r >= b)
1083 "internal error handling cHRM coefficients");
1086 png_ptr->rgb_to_gray_green_coeff = (
png_uint_16)g;
1094 png_error(png_ptr,
"internal error handling cHRM->XYZ");
1101 x_green, y_green, x_blue, y_blue);
1105 #ifdef PNG_READ_sRGB_SUPPORTED
1115 png_error(png_ptr,
"Missing IHDR before sRGB");
1137 png_warning(png_ptr,
"Incorrect sRGB chunk length");
1156 #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
1167 "Ignoring incorrect gAMA value @1 when sRGB is also present");
1172 #ifdef PNG_READ_cHRM_SUPPORTED
1184 "Ignoring incorrect cHRM value when sRGB is also present");
1192 png_ptr->is_sRGB = 1;
1194 # ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1196 if (!png_ptr->rgb_to_gray_coefficients_set)
1218 png_ptr->rgb_to_gray_red_coeff = 6968;
1219 png_ptr->rgb_to_gray_green_coeff = 23434;
1225 png_ptr->rgb_to_gray_coefficients_set = 1;
1233 #ifdef PNG_READ_iCCP_SUPPORTED
1249 png_error(png_ptr,
"Missing IHDR before iCCP");
1269 #ifdef PNG_MAX_MALLOC_64K
1272 png_warning(png_ptr,
"iCCP chunk too large to fit in memory");
1278 png_free(png_ptr, png_ptr->chunkdata);
1279 png_ptr->chunkdata = (
png_charp)png_malloc(png_ptr, length + 1);
1285 png_free(png_ptr, png_ptr->chunkdata);
1286 png_ptr->chunkdata =
NULL;
1290 png_ptr->chunkdata[
slength] = 0x00;
1292 for (profile = png_ptr->chunkdata; *profile; profile++)
1300 if (profile >= png_ptr->chunkdata + slength - 1)
1302 png_free(png_ptr, png_ptr->chunkdata);
1303 png_ptr->chunkdata =
NULL;
1309 compression_type = *profile++;
1311 if (compression_type)
1313 png_warning(png_ptr,
"Ignoring nonzero compression type in iCCP chunk");
1314 compression_type = 0x00;
1318 prefix_length = profile - png_ptr->chunkdata;
1320 slength, prefix_length, &data_length);
1324 if (prefix_length > data_length || profile_length < 4)
1326 png_free(png_ptr, png_ptr->chunkdata);
1327 png_ptr->chunkdata =
NULL;
1328 png_warning(png_ptr,
"Profile size field missing from iCCP chunk");
1333 pC = (
png_bytep)(png_ptr->chunkdata + prefix_length);
1334 profile_size = ((*(
pC )) << 24) |
1335 ((*(pC + 1)) << 16) |
1336 ((*(pC + 2)) << 8) |
1342 if (profile_size < profile_length)
1346 if (profile_size > profile_length)
1350 png_free(png_ptr, png_ptr->chunkdata);
1351 png_ptr->chunkdata =
NULL;
1356 "Ignoring iCCP chunk with declared size = @1 and actual length = @2");
1361 compression_type, (
png_bytep)png_ptr->chunkdata + prefix_length,
1363 png_free(png_ptr, png_ptr->chunkdata);
1364 png_ptr->chunkdata =
NULL;
1368 #ifdef PNG_READ_sPLT_SUPPORTED
1385 #ifdef PNG_USER_LIMITS_SUPPORTED
1387 if (png_ptr->user_chunk_cache_max != 0)
1389 if (png_ptr->user_chunk_cache_max == 1)
1395 if (--png_ptr->user_chunk_cache_max == 1)
1397 png_warning(png_ptr,
"No space in chunk cache for sPLT");
1405 png_error(png_ptr,
"Missing IHDR before sPLT");
1414 #ifdef PNG_MAX_MALLOC_64K
1417 png_warning(png_ptr,
"sPLT chunk too large to fit in memory");
1423 png_free(png_ptr, png_ptr->chunkdata);
1424 png_ptr->chunkdata = (
png_charp)png_malloc(png_ptr, length + 1);
1435 png_free(png_ptr, png_ptr->chunkdata);
1436 png_ptr->chunkdata =
NULL;
1440 png_ptr->chunkdata[
slength] = 0x00;
1442 for (entry_start = (
png_bytep)png_ptr->chunkdata; *entry_start;
1449 if (entry_start > (
png_bytep)png_ptr->chunkdata + slength - 2)
1451 png_free(png_ptr, png_ptr->chunkdata);
1452 png_ptr->chunkdata =
NULL;
1458 entry_size = (new_palette.
depth == 8 ? 6 : 10);
1463 data_length = length - (
png_uint_32)(entry_start -
1467 if (data_length % entry_size)
1469 png_free(png_ptr, png_ptr->chunkdata);
1470 png_ptr->chunkdata =
NULL;
1471 png_warning(png_ptr,
"sPLT chunk has bad length");
1491 png_warning(png_ptr,
"sPLT chunk requires too much memory");
1495 #ifdef PNG_POINTER_INDEXING_SUPPORTED
1500 if (new_palette.
depth == 8)
1502 pp->red = *entry_start++;
1503 pp->green = *entry_start++;
1504 pp->blue = *entry_start++;
1505 pp->alpha = *entry_start++;
1521 for (i = 0; i < new_palette.
nentries; i++)
1524 if (new_palette.
depth == 8)
1526 pp[
i].red = *entry_start++;
1527 pp[
i].green = *entry_start++;
1528 pp[
i].blue = *entry_start++;
1529 pp[
i].alpha = *entry_start++;
1545 new_palette.
name = png_ptr->chunkdata;
1549 png_free(png_ptr, png_ptr->chunkdata);
1550 png_ptr->chunkdata =
NULL;
1555 #ifdef PNG_READ_tRNS_SUPPORTED
1564 png_error(png_ptr,
"Missing IHDR before tRNS");
1586 png_warning(png_ptr,
"Incorrect tRNS chunk length");
1592 png_ptr->num_trans = 1;
1602 png_warning(png_ptr,
"Incorrect tRNS chunk length");
1608 png_ptr->num_trans = 1;
1625 png_warning(png_ptr,
"Incorrect tRNS chunk length");
1643 png_warning(png_ptr,
"tRNS chunk not allowed with alpha channel");
1650 png_ptr->num_trans = 0;
1654 png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
1655 &(png_ptr->trans_color));
1659 #ifdef PNG_READ_bKGD_SUPPORTED
1670 png_error(png_ptr,
"Missing IHDR before bKGD");
1703 if (length != truelen)
1705 png_warning(png_ptr,
"Incorrect bKGD chunk length");
1722 background.
index = buf[0];
1724 if (info_ptr && info_ptr->num_palette)
1726 if (buf[0] >= info_ptr->num_palette)
1728 png_warning(png_ptr,
"Incorrect bKGD chunk index value");
1738 background.
red = background.
green = background.
blue = 0;
1740 background.
gray = 0;
1745 background.
index = 0;
1754 background.
index = 0;
1758 background.
gray = 0;
1765 #ifdef PNG_READ_hIST_SUPPORTED
1769 unsigned int num,
i;
1775 png_error(png_ptr,
"Missing IHDR before hIST");
1800 if (num != (
unsigned int)png_ptr->num_palette || num >
1803 png_warning(png_ptr,
"Incorrect hIST chunk length");
1808 for (i = 0; i <
num; i++)
1823 #ifdef PNG_READ_pHYs_SUPPORTED
1834 png_error(png_ptr,
"Missing IHDR before pHYs");
1852 png_warning(png_ptr,
"Incorrect pHYs chunk length");
1865 png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
1869 #ifdef PNG_READ_oFFs_SUPPORTED
1880 png_error(png_ptr,
"Missing IHDR before oFFs");
1898 png_warning(png_ptr,
"Incorrect oFFs chunk length");
1911 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
1915 #ifdef PNG_READ_pCAL_SUPPORTED
1930 png_error(png_ptr,
"Missing IHDR before pCAL");
1946 png_debug1(2,
"Allocating and reading pCAL chunk data (%u bytes)",
1948 png_free(png_ptr, png_ptr->chunkdata);
1949 png_ptr->chunkdata = (
png_charp)png_malloc_warn(png_ptr, length + 1);
1951 if (png_ptr->chunkdata ==
NULL)
1953 png_warning(png_ptr,
"No memory for pCAL purpose");
1962 png_free(png_ptr, png_ptr->chunkdata);
1963 png_ptr->chunkdata =
NULL;
1967 png_ptr->chunkdata[
slength] = 0x00;
1969 png_debug(3,
"Finding end of pCAL purpose string");
1970 for (buf = png_ptr->chunkdata; *buf; buf++)
1973 endptr = png_ptr->chunkdata +
slength;
1978 if (endptr <= buf + 12)
1981 png_free(png_ptr, png_ptr->chunkdata);
1982 png_ptr->chunkdata =
NULL;
1986 png_debug(3,
"Reading pCAL X0, X1, type, nparams, and units");
1993 png_debug(3,
"Checking pCAL equation type and number of parameters");
2002 png_warning(png_ptr,
"Invalid pCAL parameters for equation type");
2003 png_free(png_ptr, png_ptr->chunkdata);
2004 png_ptr->chunkdata =
NULL;
2010 png_warning(png_ptr,
"Unrecognized equation type for pCAL chunk");
2013 for (buf = units; *
buf; buf++)
2016 png_debug(3,
"Allocating pCAL parameters array");
2018 params = (
png_charpp)png_malloc_warn(png_ptr,
2023 png_free(png_ptr, png_ptr->chunkdata);
2024 png_ptr->chunkdata =
NULL;
2025 png_warning(png_ptr,
"No memory for pCAL params");
2030 for (i = 0; i < (
int)nparams; i++)
2034 png_debug1(3,
"Reading pCAL parameter %d", i);
2036 for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
2043 png_free(png_ptr, png_ptr->chunkdata);
2044 png_ptr->chunkdata =
NULL;
2050 png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams,
2053 png_free(png_ptr, png_ptr->chunkdata);
2054 png_ptr->chunkdata =
NULL;
2059 #ifdef PNG_READ_sCAL_SUPPORTED
2070 png_error(png_ptr,
"Missing IHDR before sCAL");
2087 else if (length < 4)
2094 png_debug1(2,
"Allocating and reading sCAL chunk data (%u bytes)",
2097 png_ptr->chunkdata = (
png_charp)png_malloc_warn(png_ptr, length + 1);
2099 if (png_ptr->chunkdata ==
NULL)
2101 png_warning(png_ptr,
"Out of memory while processing sCAL chunk");
2108 png_ptr->chunkdata[
slength] = 0x00;
2112 png_free(png_ptr, png_ptr->chunkdata);
2113 png_ptr->chunkdata =
NULL;
2118 if (png_ptr->chunkdata[0] != 1 && png_ptr->chunkdata[0] != 2)
2120 png_warning(png_ptr,
"Invalid sCAL ignored: invalid unit");
2121 png_free(png_ptr, png_ptr->chunkdata);
2122 png_ptr->chunkdata =
NULL;
2133 i >= slength || png_ptr->chunkdata[i++] != 0)
2134 png_warning(png_ptr,
"Invalid sCAL chunk ignored: bad width format");
2137 png_warning(png_ptr,
"Invalid sCAL chunk ignored: non-positive width");
2146 png_warning(png_ptr,
"Invalid sCAL chunk ignored: bad height format");
2150 "Invalid sCAL chunk ignored: non-positive height");
2155 png_ptr->chunkdata+1, png_ptr->chunkdata+heighti);
2159 png_free(png_ptr, png_ptr->chunkdata);
2160 png_ptr->chunkdata =
NULL;
2164 #ifdef PNG_READ_tIME_SUPPORTED
2174 png_error(png_ptr,
"Out of place tIME chunk");
2188 png_warning(png_ptr,
"Incorrect tIME chunk length");
2198 mod_time.
second = buf[6];
2199 mod_time.
minute = buf[5];
2200 mod_time.
hour = buf[4];
2201 mod_time.
day = buf[3];
2202 mod_time.
month = buf[2];
2209 #ifdef PNG_READ_tEXt_SUPPORTED
2223 #ifdef PNG_USER_LIMITS_SUPPORTED
2224 if (png_ptr->user_chunk_cache_max != 0)
2226 if (png_ptr->user_chunk_cache_max == 1)
2232 if (--png_ptr->user_chunk_cache_max == 1)
2234 png_warning(png_ptr,
"No space in chunk cache for tEXt");
2242 png_error(png_ptr,
"Missing IHDR before tEXt");
2247 #ifdef PNG_MAX_MALLOC_64K
2250 png_warning(png_ptr,
"tEXt chunk too large to fit in memory");
2256 png_free(png_ptr, png_ptr->chunkdata);
2258 png_ptr->chunkdata = (
png_charp)png_malloc_warn(png_ptr, length + 1);
2260 if (png_ptr->chunkdata ==
NULL)
2262 png_warning(png_ptr,
"No memory to process text chunk");
2271 png_free(png_ptr, png_ptr->chunkdata);
2272 png_ptr->chunkdata =
NULL;
2276 key = png_ptr->chunkdata;
2280 for (text = key; *text; text++)
2283 if (text != key + slength)
2286 text_ptr = (
png_textp)png_malloc_warn(png_ptr,
2289 if (text_ptr ==
NULL)
2291 png_warning(png_ptr,
"Not enough memory to process text chunk");
2292 png_free(png_ptr, png_ptr->chunkdata);
2293 png_ptr->chunkdata =
NULL;
2298 text_ptr->key = key;
2299 text_ptr->lang =
NULL;
2300 text_ptr->lang_key =
NULL;
2301 text_ptr->itxt_length = 0;
2302 text_ptr->text = text;
2307 png_free(png_ptr, png_ptr->chunkdata);
2308 png_ptr->chunkdata =
NULL;
2312 png_warning(png_ptr,
"Insufficient memory to process text chunk");
2316 #ifdef PNG_READ_zTXt_SUPPORTED
2329 #ifdef PNG_USER_LIMITS_SUPPORTED
2330 if (png_ptr->user_chunk_cache_max != 0)
2332 if (png_ptr->user_chunk_cache_max == 1)
2338 if (--png_ptr->user_chunk_cache_max == 1)
2340 png_warning(png_ptr,
"No space in chunk cache for zTXt");
2348 png_error(png_ptr,
"Missing IHDR before zTXt");
2353 #ifdef PNG_MAX_MALLOC_64K
2359 png_warning(png_ptr,
"zTXt chunk too large to fit in memory");
2365 png_free(png_ptr, png_ptr->chunkdata);
2366 png_ptr->chunkdata = (
png_charp)png_malloc_warn(png_ptr, length + 1);
2368 if (png_ptr->chunkdata ==
NULL)
2370 png_warning(png_ptr,
"Out of memory processing zTXt chunk");
2379 png_free(png_ptr, png_ptr->chunkdata);
2380 png_ptr->chunkdata =
NULL;
2384 png_ptr->chunkdata[
slength] = 0x00;
2386 for (text = png_ptr->chunkdata; *text; text++)
2390 if (text >= png_ptr->chunkdata + slength - 2)
2393 png_free(png_ptr, png_ptr->chunkdata);
2394 png_ptr->chunkdata =
NULL;
2400 comp_type = *(++text);
2404 png_warning(png_ptr,
"Unknown compression type in zTXt chunk");
2411 prefix_len = text - png_ptr->chunkdata;
2416 text_ptr = (
png_textp)png_malloc_warn(png_ptr,
2419 if (text_ptr ==
NULL)
2421 png_warning(png_ptr,
"Not enough memory to process zTXt chunk");
2422 png_free(png_ptr, png_ptr->chunkdata);
2423 png_ptr->chunkdata =
NULL;
2427 text_ptr->compression = comp_type;
2428 text_ptr->key = png_ptr->chunkdata;
2429 text_ptr->lang =
NULL;
2430 text_ptr->lang_key =
NULL;
2431 text_ptr->itxt_length = 0;
2432 text_ptr->text = png_ptr->chunkdata + prefix_len;
2433 text_ptr->text_length = data_len;
2438 png_free(png_ptr, png_ptr->chunkdata);
2439 png_ptr->chunkdata =
NULL;
2442 png_error(png_ptr,
"Insufficient memory to store zTXt chunk");
2446 #ifdef PNG_READ_iTXt_SUPPORTED
2460 #ifdef PNG_USER_LIMITS_SUPPORTED
2461 if (png_ptr->user_chunk_cache_max != 0)
2463 if (png_ptr->user_chunk_cache_max == 1)
2469 if (--png_ptr->user_chunk_cache_max == 1)
2471 png_warning(png_ptr,
"No space in chunk cache for iTXt");
2479 png_error(png_ptr,
"Missing IHDR before iTXt");
2484 #ifdef PNG_MAX_MALLOC_64K
2490 png_warning(png_ptr,
"iTXt chunk too large to fit in memory");
2496 png_free(png_ptr, png_ptr->chunkdata);
2497 png_ptr->chunkdata = (
png_charp)png_malloc_warn(png_ptr, length + 1);
2499 if (png_ptr->chunkdata ==
NULL)
2501 png_warning(png_ptr,
"No memory to process iTXt chunk");
2510 png_free(png_ptr, png_ptr->chunkdata);
2511 png_ptr->chunkdata =
NULL;
2515 png_ptr->chunkdata[
slength] = 0x00;
2517 for (lang = png_ptr->chunkdata; *lang; lang++)
2527 if (lang >= png_ptr->chunkdata + slength - 3)
2530 png_free(png_ptr, png_ptr->chunkdata);
2531 png_ptr->chunkdata =
NULL;
2537 comp_flag = *lang++;
2538 comp_type = *lang++;
2543 png_warning(png_ptr,
"Unknown iTXt compression type or method");
2544 png_free(png_ptr, png_ptr->chunkdata);
2545 png_ptr->chunkdata =
NULL;
2549 for (lang_key = lang; *lang_key; lang_key++)
2554 if (lang_key >= png_ptr->chunkdata + slength)
2557 png_free(png_ptr, png_ptr->chunkdata);
2558 png_ptr->chunkdata =
NULL;
2562 for (text = lang_key; *text; text++)
2567 if (text >= png_ptr->chunkdata + slength)
2570 png_free(png_ptr, png_ptr->chunkdata);
2571 png_ptr->chunkdata =
NULL;
2575 prefix_len = text - png_ptr->chunkdata;
2577 key=png_ptr->chunkdata;
2581 (
size_t)length, prefix_len, &data_len);
2584 data_len =
png_strlen(png_ptr->chunkdata + prefix_len);
2586 text_ptr = (
png_textp)png_malloc_warn(png_ptr,
2589 if (text_ptr ==
NULL)
2591 png_warning(png_ptr,
"Not enough memory to process iTXt chunk");
2592 png_free(png_ptr, png_ptr->chunkdata);
2593 png_ptr->chunkdata =
NULL;
2597 text_ptr->compression = (
int)comp_flag + 1;
2598 text_ptr->lang_key = png_ptr->chunkdata + (lang_key - key);
2599 text_ptr->lang = png_ptr->chunkdata + (lang - key);
2600 text_ptr->itxt_length = data_len;
2601 text_ptr->text_length = 0;
2602 text_ptr->key = png_ptr->chunkdata;
2603 text_ptr->text = png_ptr->chunkdata + prefix_len;
2608 png_free(png_ptr, png_ptr->chunkdata);
2609 png_ptr->chunkdata =
NULL;
2612 png_error(png_ptr,
"Insufficient memory to store iTXt chunk");
2629 #ifdef PNG_USER_LIMITS_SUPPORTED
2630 if (png_ptr->user_chunk_cache_max != 0)
2632 if (png_ptr->user_chunk_cache_max == 1)
2638 if (--png_ptr->user_chunk_cache_max == 1)
2640 png_warning(png_ptr,
"No space in chunk cache for unknown chunk");
2649 if (png_ptr->chunk_name !=
png_IDAT)
2655 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2659 && png_ptr->read_user_chunk_fn ==
NULL
2663 png_chunk_error(png_ptr,
"unknown critical chunk");
2666 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
2669 || (png_ptr->read_user_chunk_fn !=
NULL)
2673 #ifdef PNG_MAX_MALLOC_64K
2676 png_warning(png_ptr,
"unknown chunk too large to fit in memory");
2677 skip = length - 65535;
2688 png_ptr->unknown_chunk.size = (
png_size_t)length;
2691 png_ptr->unknown_chunk.data =
NULL;
2695 png_ptr->unknown_chunk.data = (
png_bytep)png_malloc(png_ptr, length);
2696 png_crc_read(png_ptr, png_ptr->unknown_chunk.data, length);
2699 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
2700 if (png_ptr->read_user_chunk_fn !=
NULL)
2705 ret = (*(png_ptr->read_user_chunk_fn))
2706 (png_ptr, &png_ptr->unknown_chunk);
2709 png_chunk_error(png_ptr,
"error in user chunk");
2715 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2719 png_chunk_error(png_ptr,
"unknown critical chunk");
2723 &png_ptr->unknown_chunk, 1);
2731 png_free(png_ptr, png_ptr->unknown_chunk.data);
2732 png_ptr->unknown_chunk.data =
NULL;
2741 #ifndef PNG_READ_USER_CHUNKS_SUPPORTED
2763 png_debug(1,
"in png_check_chunk_name");
2765 for (i=1; i<=4; ++
i)
2767 int c = chunk_name & 0xff;
2770 png_chunk_error(png_ptr,
"invalid chunk type");
2786 unsigned int pixel_depth = png_ptr->transformed_pixel_depth;
2789 unsigned int pass = png_ptr->pass;
2792 unsigned int end_mask;
2799 if (pixel_depth == 0)
2800 png_error(png_ptr,
"internal row logic error");
2806 if (png_ptr->info_rowbytes != 0 && png_ptr->info_rowbytes !=
2808 png_error(png_ptr,
"internal row size calculation error");
2812 png_error(png_ptr,
"internal row width error");
2818 end_mask = (pixel_depth * row_width) & 7;
2822 end_ptr = dp +
PNG_ROWBYTES(pixel_depth, row_width) - 1;
2823 end_byte = *end_ptr;
2824 # ifdef PNG_READ_PACKSWAP_SUPPORTED
2826 end_mask = 0xff << end_mask;
2830 end_mask = 0xff >> end_mask;
2840 #ifdef PNG_READ_INTERLACING_SUPPORTED
2841 if (png_ptr->interlaced && (png_ptr->transformations &
PNG_INTERLACE) &&
2842 pass < 6 && (display == 0 ||
2844 (display == 1 && (pass & 1) != 0)))
2852 if (pixel_depth < 8)
2891 # if PNG_USE_COMPILE_TIME_MASKS
2892 # define PNG_LSR(x,s) ((x)>>((s) & 0x1f))
2893 # define PNG_LSL(x,s) ((x)<<((s) & 0x1f))
2895 # define PNG_LSR(x,s) ((x)>>(s))
2896 # define PNG_LSL(x,s) ((x)<<(s))
2898 # define S_COPY(p,x) (((p)<4 ? PNG_LSR(0x80088822,(3-(p))*8+(7-(x))) :\
2899 PNG_LSR(0xaa55ff00,(7-(p))*8+(7-(x)))) & 1)
2900 # define B_COPY(p,x) (((p)<4 ? PNG_LSR(0xff0fff33,(3-(p))*8+(7-(x))) :\
2901 PNG_LSR(0xff55ff00,(7-(p))*8+(7-(x)))) & 1)
2909 # define PIXEL_MASK(p,x,d,s) \
2910 (PNG_LSL(((PNG_LSL(1U,(d)))-1),(((x)*(d))^((s)?8-(d):0))))
2914 # define S_MASKx(p,x,d,s) (S_COPY(p,x)?PIXEL_MASK(p,x,d,s):0)
2915 # define B_MASKx(p,x,d,s) (B_COPY(p,x)?PIXEL_MASK(p,x,d,s):0)
2921 # define MASK_EXPAND(m,d) ((m)*((d)==1?0x01010101:((d)==2?0x00010001:1)))
2923 # define S_MASK(p,d,s) MASK_EXPAND(S_MASKx(p,0,d,s) + S_MASKx(p,1,d,s) +\
2924 S_MASKx(p,2,d,s) + S_MASKx(p,3,d,s) + S_MASKx(p,4,d,s) +\
2925 S_MASKx(p,5,d,s) + S_MASKx(p,6,d,s) + S_MASKx(p,7,d,s), d)
2927 # define B_MASK(p,d,s) MASK_EXPAND(B_MASKx(p,0,d,s) + B_MASKx(p,1,d,s) +\
2928 B_MASKx(p,2,d,s) + B_MASKx(p,3,d,s) + B_MASKx(p,4,d,s) +\
2929 B_MASKx(p,5,d,s) + B_MASKx(p,6,d,s) + B_MASKx(p,7,d,s), d)
2931 #if PNG_USE_COMPILE_TIME_MASKS
2937 # define S_MASKS(d,s) { S_MASK(0,d,s), S_MASK(1,d,s), S_MASK(2,d,s),\
2938 S_MASK(3,d,s), S_MASK(4,d,s), S_MASK(5,d,s) }
2940 # define B_MASKS(d,s) { B_MASK(1,d,s), S_MASK(3,d,s), S_MASK(5,d,s) }
2942 # define DEPTH_INDEX(d) ((d)==1?0:((d)==2?1:2))
2966 # define MASK(pass,depth,display,png)\
2967 ((display)?display_mask[png][DEPTH_INDEX(depth)][pass>>1]:\
2968 row_mask[png][DEPTH_INDEX(depth)][pass])
2974 # define MASK(pass,depth,display,png)\
2975 ((display)?B_MASK(pass,depth,png):S_MASK(pass,depth,png))
2986 # ifdef PNG_READ_PACKSWAP_SUPPORTED
2988 mask =
MASK(pass, pixel_depth, display, 0);
2992 mask =
MASK(pass, pixel_depth, display, 1);
3003 mask = (m >> 8) | (m << 24);
3009 *dp = (
png_byte)((*dp & ~m) | (*sp &
m));
3018 if (row_width <= pixels_per_byte)
3021 row_width -= pixels_per_byte;
3029 unsigned int bytes_to_copy, bytes_to_jump;
3032 if (pixel_depth & 7)
3033 png_error(png_ptr,
"invalid user transform pixel depth");
3036 row_width *= pixel_depth;
3057 bytes_to_copy = (1<<((6-pass)>>1)) * pixel_depth;
3060 if (bytes_to_copy > row_width)
3061 bytes_to_copy = row_width;
3065 bytes_to_copy = pixel_depth;
3078 switch (bytes_to_copy)
3085 if (row_width <= bytes_to_jump)
3088 dp += bytes_to_jump;
3089 sp += bytes_to_jump;
3090 row_width -= bytes_to_jump;
3099 dp[0] = sp[0], dp[1] = sp[1];
3101 if (row_width <= bytes_to_jump)
3104 sp += bytes_to_jump;
3105 dp += bytes_to_jump;
3106 row_width -= bytes_to_jump;
3108 while (row_width > 1);
3120 dp[0] = sp[0], dp[1] = sp[1], dp[2] = sp[2];
3122 if (row_width <= bytes_to_jump)
3125 sp += bytes_to_jump;
3126 dp += bytes_to_jump;
3127 row_width -= bytes_to_jump;
3131 #if PNG_ALIGN_TYPE != PNG_ALIGN_NONE
3137 if (bytes_to_copy < 16 &&
3153 unsigned int skip = (bytes_to_jump-bytes_to_copy) /
3158 size_t c = bytes_to_copy;
3166 if (row_width <= bytes_to_jump)
3171 row_width -= bytes_to_jump;
3173 while (bytes_to_copy <= row_width);
3183 while (--row_width > 0);
3194 unsigned int skip = (bytes_to_jump-bytes_to_copy) /
3199 size_t c = bytes_to_copy;
3207 if (row_width <= bytes_to_jump)
3212 row_width -= bytes_to_jump;
3214 while (bytes_to_copy <= row_width);
3221 while (--row_width > 0);
3232 if (row_width <= bytes_to_jump)
3235 sp += bytes_to_jump;
3236 dp += bytes_to_jump;
3237 row_width -= bytes_to_jump;
3238 if (bytes_to_copy > row_width)
3239 bytes_to_copy = row_width;
3258 if (end_ptr !=
NULL)
3259 *end_ptr = (
png_byte)((end_byte & end_mask) | (*end_ptr & ~end_mask));
3262 #ifdef PNG_READ_INTERLACING_SUPPORTED
3269 static PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
3271 png_debug(1,
"in png_do_read_interlace");
3272 if (row !=
NULL && row_info !=
NULL)
3276 final_width = row_info->width * png_pass_inc[pass];
3278 switch (row_info->pixel_depth)
3285 int s_start, s_end, s_inc;
3286 int jstop = png_pass_inc[pass];
3291 #ifdef PNG_READ_PACKSWAP_SUPPORTED
3294 sshift = (
int)((row_info->width + 7) & 0x07);
3295 dshift = (
int)((final_width + 7) & 0x07);
3304 sshift = 7 - (
int)((row_info->width + 7) & 0x07);
3305 dshift = 7 - (
int)((final_width + 7) & 0x07);
3311 for (i = 0; i < row_info->width; i++)
3313 v = (
png_byte)((*sp >> sshift) & 0x01);
3314 for (j = 0; j < jstop; j++)
3316 *dp &= (
png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
3319 if (dshift == s_end)
3329 if (sshift == s_end)
3346 int s_start, s_end, s_inc;
3347 int jstop = png_pass_inc[pass];
3350 #ifdef PNG_READ_PACKSWAP_SUPPORTED
3353 sshift = (
int)(((row_info->width + 3) & 0x03) << 1);
3354 dshift = (
int)(((final_width + 3) & 0x03) << 1);
3363 sshift = (
int)((3 - ((row_info->width + 3) & 0x03)) << 1);
3364 dshift = (
int)((3 - ((final_width + 3) & 0x03)) << 1);
3370 for (i = 0; i < row_info->width; i++)
3375 v = (
png_byte)((*sp >> sshift) & 0x03);
3376 for (j = 0; j < jstop; j++)
3378 *dp &= (
png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
3381 if (dshift == s_end)
3391 if (sshift == s_end)
3408 int s_start, s_end, s_inc;
3410 int jstop = png_pass_inc[pass];
3412 #ifdef PNG_READ_PACKSWAP_SUPPORTED
3415 sshift = (
int)(((row_info->width + 1) & 0x01) << 2);
3416 dshift = (
int)(((final_width + 1) & 0x01) << 2);
3425 sshift = (
int)((1 - ((row_info->width + 1) & 0x01)) << 2);
3426 dshift = (
int)((1 - ((final_width + 1) & 0x01)) << 2);
3432 for (i = 0; i < row_info->width; i++)
3437 for (j = 0; j < jstop; j++)
3439 *dp &= (
png_byte)((0xf0f >> (4 - dshift)) & 0xff);
3442 if (dshift == s_end)
3452 if (sshift == s_end)
3466 png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
3473 int jstop = png_pass_inc[pass];
3476 for (i = 0; i < row_info->width; i++)
3483 for (j = 0; j < jstop; j++)
3495 row_info->width = final_width;
3496 row_info->rowbytes =
PNG_ROWBYTES(row_info->pixel_depth, final_width);
3498 #ifndef PNG_READ_PACKSWAP_SUPPORTED
3510 unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
3515 for (i = bpp; i < istop; i++)
3517 *rp = (
png_byte)(((
int)(*rp) + (
int)(*(rp-bpp))) & 0xff);
3531 for (i = 0; i < istop; i++)
3533 *rp = (
png_byte)(((
int)(*rp) + (
int)(*pp++)) & 0xff);
3545 unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
3548 for (i = 0; i < bpp; i++)
3551 ((
int)(*pp++) / 2 )) & 0xff);
3556 for (i = 0; i < istop; i++)
3559 (
int)(*pp++ + *(rp-bpp)) / 2 ) & 0xff);
3569 png_bytep rp_end = row + row_info->rowbytes;
3578 while (row < rp_end)
3580 int b, pa, pb, pc,
p;
3593 pa = p < 0 ? -p :
p;
3594 pb = pc < 0 ? -pc : pc;
3595 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
3601 if (pb < pa) pa = pb, a =
b;
3617 int bpp = (row_info->pixel_depth + 7) >> 3;
3623 while (row < rp_end)
3625 int a = *row + *prev_row++;
3630 rp_end += row_info->rowbytes - bpp;
3632 while (row < rp_end)
3634 int a,
b,
c, pa, pb, pc,
p;
3636 c = *(prev_row - bpp);
3648 pa = p < 0 ? -p :
p;
3649 pb = pc < 0 ? -pc : pc;
3650 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
3653 if (pb < pa) pa = pb, a =
b;
3667 #include <asm/hwcap.h>
3669 static int png_have_hwcap(
unsigned cap)
3671 FILE *
f = fopen(
"/proc/self/auxv",
"r");
3678 while (fread(&aux,
sizeof(aux), 1, f) > 0)
3680 if (aux.a_type == AT_HWCAP &&
3681 aux.a_un.a_val & cap)
3695 png_init_filter_functions_neon(
png_structp pp,
unsigned int bpp)
3698 if (!png_have_hwcap(HWCAP_NEON))
3709 png_read_filter_row_paeth3_neon;
3717 png_read_filter_row_paeth4_neon;
3725 unsigned int bpp = (pp->pixel_depth + 7) >> 3;
3738 png_init_filter_functions_neon(pp, bpp);
3746 if (pp->read_filter[0] ==
NULL)
3749 pp->read_filter[filter-1](row_info,
row, prev_row);
3752 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
3756 #ifdef PNG_READ_INTERLACING_SUPPORTED
3773 png_ptr->row_number++;
3774 if (png_ptr->row_number < png_ptr->num_rows)
3777 #ifdef PNG_READ_INTERLACING_SUPPORTED
3778 if (png_ptr->interlaced)
3780 png_ptr->row_number = 0;
3785 png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
3791 if (png_ptr->pass >= 7)
3794 png_ptr->iwidth = (png_ptr->width +
3795 png_pass_inc[png_ptr->pass] - 1 -
3796 png_pass_start[png_ptr->pass]) /
3797 png_pass_inc[png_ptr->pass];
3801 png_ptr->num_rows = (png_ptr->height +
3802 png_pass_yinc[png_ptr->pass] - 1 -
3803 png_pass_ystart[png_ptr->pass]) /
3804 png_pass_yinc[png_ptr->pass];
3810 }
while (png_ptr->num_rows == 0 || png_ptr->iwidth == 0);
3812 if (png_ptr->pass < 7)
3822 png_ptr->zstream.next_out = (
Byte *)&extra;
3823 png_ptr->zstream.avail_out = (
uInt)1;
3827 if (!(png_ptr->zstream.avail_in))
3829 while (!png_ptr->idat_size)
3833 if (png_ptr->chunk_name !=
png_IDAT)
3834 png_error(png_ptr,
"Not enough image data");
3837 png_ptr->zstream.avail_in = (
uInt)png_ptr->zbuf_size;
3838 png_ptr->zstream.next_in = png_ptr->zbuf;
3840 if (png_ptr->zbuf_size > png_ptr->idat_size)
3841 png_ptr->zstream.avail_in = (
uInt)png_ptr->idat_size;
3843 png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
3844 png_ptr->idat_size -= png_ptr->zstream.avail_in;
3851 if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
3861 png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
3862 "Decompression Error");
3864 if (!(png_ptr->zstream.avail_out))
3873 png_ptr->zstream.avail_out = 0;
3876 if (png_ptr->idat_size || png_ptr->zstream.avail_in)
3888 #ifdef PNG_READ_INTERLACING_SUPPORTED
3904 int max_pixel_depth;
3908 png_ptr->zstream.avail_in = 0;
3909 #ifdef PNG_READ_TRANSFORMS_SUPPORTED
3912 #ifdef PNG_READ_INTERLACING_SUPPORTED
3913 if (png_ptr->interlaced)
3916 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
3917 png_pass_ystart[0]) / png_pass_yinc[0];
3920 png_ptr->num_rows = png_ptr->height;
3922 png_ptr->iwidth = (png_ptr->width +
3923 png_pass_inc[png_ptr->pass] - 1 -
3924 png_pass_start[png_ptr->pass]) /
3925 png_pass_inc[png_ptr->pass];
3931 png_ptr->num_rows = png_ptr->height;
3932 png_ptr->iwidth = png_ptr->width;
3935 max_pixel_depth = png_ptr->pixel_depth;
3947 #ifdef PNG_READ_PACK_SUPPORTED
3948 if ((png_ptr->transformations &
PNG_PACK) && png_ptr->bit_depth < 8)
3949 max_pixel_depth = 8;
3952 #ifdef PNG_READ_EXPAND_SUPPORTED
3957 if (png_ptr->num_trans)
3958 max_pixel_depth = 32;
3961 max_pixel_depth = 24;
3966 if (max_pixel_depth < 8)
3967 max_pixel_depth = 8;
3969 if (png_ptr->num_trans)
3970 max_pixel_depth *= 2;
3975 if (png_ptr->num_trans)
3977 max_pixel_depth *= 4;
3978 max_pixel_depth /= 3;
3984 #ifdef PNG_READ_EXPAND_16_SUPPORTED
3987 # ifdef PNG_READ_EXPAND_SUPPORTED
3993 if (png_ptr->bit_depth < 16)
3994 max_pixel_depth *= 2;
4002 #ifdef PNG_READ_FILLER_SUPPORTED
4007 if (max_pixel_depth <= 8)
4008 max_pixel_depth = 16;
4011 max_pixel_depth = 32;
4017 if (max_pixel_depth <= 32)
4018 max_pixel_depth = 32;
4021 max_pixel_depth = 64;
4026 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
4031 (png_ptr->num_trans && (png_ptr->transformations &
PNG_EXPAND)) ||
4038 if (max_pixel_depth <= 16)
4039 max_pixel_depth = 32;
4042 max_pixel_depth = 64;
4047 if (max_pixel_depth <= 8)
4050 max_pixel_depth = 32;
4053 max_pixel_depth = 24;
4057 max_pixel_depth = 64;
4060 max_pixel_depth = 48;
4065 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
4066 defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
4069 int user_pixel_depth = png_ptr->user_transform_depth *
4070 png_ptr->user_transform_channels;
4072 if (user_pixel_depth > max_pixel_depth)
4073 max_pixel_depth = user_pixel_depth;
4080 png_ptr->maximum_pixel_depth = (
png_byte)max_pixel_depth;
4081 png_ptr->transformed_pixel_depth = 0;
4086 row_bytes = ((png_ptr->width + 7) & ~((
png_uint_32)7));
4091 1 + ((max_pixel_depth + 7) >> 3);
4093 #ifdef PNG_MAX_MALLOC_64K
4095 png_error(png_ptr,
"This image requires a row greater than 64KB");
4098 if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
4100 png_free(png_ptr, png_ptr->big_row_buf);
4101 png_free(png_ptr, png_ptr->big_prev_row);
4103 if (png_ptr->interlaced)
4104 png_ptr->big_row_buf = (
png_bytep)png_calloc(png_ptr,
4108 png_ptr->big_row_buf = (
png_bytep)png_malloc(png_ptr, row_bytes + 48);
4110 png_ptr->big_prev_row = (
png_bytep)png_malloc(png_ptr, row_bytes + 48);
4112 #ifdef PNG_ALIGNED_MEMORY_SUPPORTED
4121 png_bytep temp = png_ptr->big_row_buf + 32;
4123 png_ptr->row_buf = temp - extra - 1;
4125 temp = png_ptr->big_prev_row + 32;
4127 png_ptr->prev_row = temp - extra - 1;
4132 png_ptr->row_buf = png_ptr->big_row_buf + 31;
4133 png_ptr->prev_row = png_ptr->big_prev_row + 31;
4135 png_ptr->old_big_row_buf_size = row_bytes + 48;
4138 #ifdef PNG_MAX_MALLOC_64K
4139 if (png_ptr->rowbytes > 65535)
4140 png_error(png_ptr,
"This image requires a row greater than 64KB");
4144 png_error(png_ptr,
"Row has too many bytes to allocate in memory");
4146 png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
4148 png_debug1(3,
"width = %u,", png_ptr->width);
4149 png_debug1(3,
"height = %u,", png_ptr->height);
4150 png_debug1(3,
"iwidth = %u,", png_ptr->iwidth);
4151 png_debug1(3,
"num_rows = %u,", png_ptr->num_rows);
4152 png_debug1(3,
"rowbytes = %lu,", (
unsigned long)png_ptr->rowbytes);
4154 (
unsigned long)
PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1);
#define PNG_FILTER_VALUE_AVG
#define png_get_uint_16(buf)
static void png_read_filter_row_sub(png_row_infop row_info, png_bytep row, png_const_bytep prev_row)
static void png_init_filter_functions(png_structp pp)
static void png_read_filter_row_up(png_row_infop row_info, png_bytep row, png_const_bytep prev_row)
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)
void png_read_filter_row(png_structp pp, png_row_infop row_info, png_bytep row, png_const_bytep prev_row, int filter)
GLuint const GLfloat * val
void PNGAPI png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, int unit, png_const_charp swidth, png_const_charp sheight)
#define PNG_USER_CHUNK_MALLOC_MAX
#define PNG_FILTER_VALUE_LAST
#define PNG_READ_USER_CHUNKS_SUPPORTED
void png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
#define png_get_uint_32(buf)
void PNGAPI png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time)
#define PNG_UNUSED(param)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
#define PNG_MAX_PALETTE_LENGTH
static png_size_t png_inflate(png_structp png_ptr, png_bytep data, png_size_t size, png_bytep output, png_size_t output_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
#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 png_check_chunk_name(png_structp png_ptr, png_uint_32 chunk_name)
#define PNG_FILTER_VALUE_PAETH
png_error(png_ptr,"Missing IHDR before iCCP")
void PNGAPI png_set_unknown_chunks(png_structp png_ptr, png_infop info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
#define PNG_IO_CHUNK_DATA
PNG_CONST png_uint_32 FAR * png_const_uint_32p
int png_XYZ_from_xy_checked(png_structp png_ptr, png_XYZ *XYZ, png_xy xy)
EGLSurface EGLint EGLint EGLint EGLint height
GLboolean GLboolean GLboolean GLboolean a
void PNGFAPI png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point file_gamma)
static void png_read_filter_row_avg(png_row_infop row_info, png_bytep row, png_const_bytep prev_row)
#define PNG_COLOR_TYPE_RGB_ALPHA
#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS
PNG_CONST char FAR * png_const_charp
void png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
#define PNG_FP_IS_POSITIVE(state)
void png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
static void png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row, png_const_bytep prev_row)
#define PNG_sRGB_INTENT_LAST
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)
#define PNG_WARNING_PARAMETERS(p)
void PNGAPI png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message)
void png_read_finish_row(png_structp png_ptr)
png_set_iCCP(png_ptr, info_ptr, png_ptr->chunkdata, compression_type,(png_bytep) png_ptr->chunkdata+prefix_length, profile_size)
void png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_size_t png_alloc_size_t
#define PNG_FLAG_ROW_INIT
#define PNG_CHUNK_CRITICAL(c)
void png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void png_init_read_transformations(png_structp png_ptr)
void PNGAPI png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, int srgb_intent)
#define PNG_TEXT_COMPRESSION_zTXt
#define PNG_FLAG_CRC_ANCILLARY_USE
void png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void PNGAPI png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_const_color_16p background)
void png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
static png_fixed_point png_get_fixed_point(png_structp png_ptr, png_const_bytep buf)
#define PNG_TEXT_COMPRESSION_NONE
#define PNG_READ_sRGB_SUPPORTED
GLenum GLenum GLvoid * row
#define PNG_NUMBER_FORMAT_u
void PNGAPI png_set_sBIT(png_structp png_ptr, png_infop info_ptr, png_const_color_8p sig_bit)
png_struct FAR * png_structp
void png_read_start_row(png_structp png_ptr)
#define PNG_HANDLE_CHUNK_ALWAYS
void png_warning_parameter_signed(png_warning_parameters p, int number, int format, png_int_32 value)
void PNGAPI png_set_PLTE(png_structp png_ptr, png_infop info_ptr, png_const_colorp palette, int num_palette)
#define PNG_COLOR_MASK_COLOR
static void png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row, png_const_bytep prev_row)
#define PNG_PASS_START_COL(pass)
void png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
int png_check_fp_number(png_const_charp string, png_size_t size, int *statep, png_size_tp whereami)
#define PNG_FLAG_CRC_CRITICAL_IGNORE
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
#define PNG_CHUNK_FROM_STRING(s)
png_set_sPLT(png_ptr, info_ptr,&new_palette, 1)
EGLSurface EGLint EGLint EGLint width
unsigned short png_uint_16
void png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#define PNG_READ_EXPAND_SUPPORTED
#define PNG_FILTER_VALUE_SUB
#define PNG_COLOR_TYPE_GRAY
#define PNG_FLAG_CRC_CRITICAL_USE
void png_combine_row(png_structp png_ptr, png_bytep dp, int display)
png_sPLT_entry FAR * png_sPLT_entryp
void PNGAPI png_warning(png_structp png_ptr, png_const_charp warning_message)
#define PNG_EQUATION_ARBITRARY
#define PNG_NUMBER_FORMAT_d
png_uint_16 FAR * png_uint_16p
PNG_CONST png_byte FAR * png_const_bytep
#define png_debug1(l, m, p1)
int png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, png_int_32 divisor)
int ZEXPORT inflate(z_streamp strm, int flush)
#define PNG_FLAG_CRC_ANCILLARY_NOWARN
void png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void PNGFAPI 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)
#define PNG_EQUATION_LAST
#define PNG_FLAG_ZLIB_FINISHED
void png_read_sig(png_structp png_ptr, png_infop info_ptr)
#define MASK(pass, depth, display, png)
int png_crc_finish(png_structp png_ptr, png_uint_32 skip)
#define PNG_READ_FILLER_SUPPORTED
#define PNG_FILTER_VALUE_UP
#define png_get_int_32(buf)
int ZEXPORT inflateReset(z_streamp strm)
png_uint_32 PNGAPI png_get_uint_31(png_structp png_ptr, png_const_bytep buf)
int png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_const_textp text_ptr, int num_text)
void PNGAPI png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_const_uint_16p hist)
void png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
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)
#define PNG_OUT_OF_RANGE(value, ideal, delta)
png_row_info FAR * png_row_infop
#define PNG_COMPRESSION_TYPE_BASE
#define PNG_CHUNK_ANCILLIARY(c)
GLenum GLuint GLsizei const GLchar * buf
void PNGAPI png_set_tRNS(png_structp png_ptr, png_infop info_ptr, png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color)
#define PNG_PASS_COL_OFFSET(pass)
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)
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
png_int_32 png_fixed_point
#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)
void png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, png_uint_32 transformations)
GLdouble GLdouble GLdouble r
GLdouble GLdouble GLdouble b
#define PNG_FILTER_VALUE_NONE
void png_calculate_crc(png_structp png_ptr, png_const_bytep ptr, png_size_t length)
void png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
int png_crc_error(png_structp png_ptr)
#define PNG_USER_TRANSFORM
void png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#define PNG_EQUATION_BASE_E
#define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
void png_decompress_chunk(png_structp png_ptr, int comp_type, png_size_t chunklength, png_size_t prefix_size, png_size_t *newlength)
png_uint_32 FAR * png_uint_32p
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)
#define PNG_FLAG_CRC_ANCILLARY_MASK
void png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void PNGAPI png_free(png_structp png_ptr, png_voidp ptr)
#define PNG_ROWBYTES(pixel_bits, width)
void PNGAPI png_set_pCAL(png_structp png_ptr, png_infop info_ptr, png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_const_charp units, png_charpp params)
int png_chunk_unknown_handling(png_structp png_ptr, png_uint_32 chunk_name)
#define png_isaligned(ptr, type)
#define PNG_HAVE_PNG_SIGNATURE
#define PNG_NUMBER_FORMAT_fixed
void png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_alloc_size_t profile_length
void png_formatted_warning(png_structp png_ptr, png_warning_parameters p, png_const_charp message)
int PNGAPI png_sig_cmp(png_const_bytep sig, png_size_t start, png_size_t num_to_check)
PNG_CONST png_uint_16 FAR * png_const_uint_16p
void png_reset_crc(png_structp png_ptr)
#define PNG_CSTRING_FROM_CHUNK(s, c)
void png_warning_parameter_unsigned(png_warning_parameters p, int number, int format, png_alloc_size_t value)
png_uint_32 png_read_chunk_header(png_structp png_ptr)
#define png_debug2(l, m, p1, p2)
png_color FAR * png_colorp