25 #ifdef PNG_READ_SUPPORTED
35 png_error(png_ptr,
"Too many bytes for PNG signature");
37 png_ptr->sig_bytes = (
png_byte)(num_bytes < 0 ? 0 : num_bytes);
51 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
56 else if (num_to_check < 1)
62 if (start + num_to_check > 8)
63 num_to_check = 8 -
start;
65 return ((
int)(
png_memcmp(&sig[start], &png_signature[start], num_to_check)));
70 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
85 png_warning (p,
"Potential overflow in png_zalloc()");
142 if (need_crc && length > 0)
144 uLong crc = png_ptr->crc;
150 safeLength = (
uInt)-1;
152 crc =
crc32(crc, ptr, safeLength);
159 length -= safeLength;
196 (user_png_ver[0] ==
'1' && user_png_ver[2] !=
png_libpng_ver[2]) ||
197 (user_png_ver[0] ==
'0' && user_png_ver[2] <
'9'))
199 #ifdef PNG_WARNINGS_SUPPORTED
203 pos =
png_safecat(m,
sizeof m, pos,
"Application built with libpng-");
205 pos =
png_safecat(m,
sizeof m, pos,
" but running with ");
211 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
234 png_debug(1,
"in png_create_info_struct");
239 #ifdef PNG_USER_MEM_SUPPORTED
241 png_ptr->malloc_fn, png_ptr->mem_ptr);
245 if (info_ptr !=
NULL)
261 png_debug(1,
"in png_destroy_info_struct");
266 if (info_ptr_ptr !=
NULL)
267 info_ptr = *info_ptr_ptr;
269 if (info_ptr !=
NULL)
273 #ifdef PNG_USER_MEM_SUPPORTED
279 *info_ptr_ptr =
NULL;
295 if (info_ptr ==
NULL)
315 if (png_ptr ==
NULL || info_ptr ==
NULL)
319 info_ptr->free_me |=
mask;
322 info_ptr->free_me &= ~mask;
326 "Unknown freer parameter in png_data_freer");
335 if (png_ptr ==
NULL || info_ptr ==
NULL)
338 #ifdef PNG_TEXT_SUPPORTED
344 if (info_ptr->text && info_ptr->text[num].key)
346 png_free(png_ptr, info_ptr->text[num].key);
347 info_ptr->text[
num].key =
NULL;
354 for (i = 0; i < info_ptr->num_text; i++)
357 info_ptr->text =
NULL;
358 info_ptr->num_text=0;
363 #ifdef PNG_tRNS_SUPPORTED
367 png_free(png_ptr, info_ptr->trans_alpha);
368 info_ptr->trans_alpha =
NULL;
373 #ifdef PNG_sCAL_SUPPORTED
377 png_free(png_ptr, info_ptr->scal_s_width);
378 png_free(png_ptr, info_ptr->scal_s_height);
379 info_ptr->scal_s_width =
NULL;
380 info_ptr->scal_s_height =
NULL;
385 #ifdef PNG_pCAL_SUPPORTED
389 png_free(png_ptr, info_ptr->pcal_purpose);
390 png_free(png_ptr, info_ptr->pcal_units);
391 info_ptr->pcal_purpose =
NULL;
392 info_ptr->pcal_units =
NULL;
393 if (info_ptr->pcal_params !=
NULL)
396 for (i = 0; i < (
int)info_ptr->pcal_nparams; i++)
398 png_free(png_ptr, info_ptr->pcal_params[i]);
399 info_ptr->pcal_params[
i] =
NULL;
401 png_free(png_ptr, info_ptr->pcal_params);
402 info_ptr->pcal_params =
NULL;
408 #ifdef PNG_iCCP_SUPPORTED
412 png_free(png_ptr, info_ptr->iccp_name);
413 png_free(png_ptr, info_ptr->iccp_profile);
414 info_ptr->iccp_name =
NULL;
415 info_ptr->iccp_profile =
NULL;
420 #ifdef PNG_sPLT_SUPPORTED
426 if (info_ptr->splt_palettes)
428 png_free(png_ptr, info_ptr->splt_palettes[num].name);
429 png_free(png_ptr, info_ptr->splt_palettes[num].entries);
430 info_ptr->splt_palettes[
num].name =
NULL;
431 info_ptr->splt_palettes[
num].entries =
NULL;
437 if (info_ptr->splt_palettes_num)
440 for (i = 0; i < (
int)info_ptr->splt_palettes_num; i++)
443 png_free(png_ptr, info_ptr->splt_palettes);
444 info_ptr->splt_palettes =
NULL;
445 info_ptr->splt_palettes_num = 0;
452 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
453 if (png_ptr->unknown_chunk.data)
455 png_free(png_ptr, png_ptr->unknown_chunk.data);
456 png_ptr->unknown_chunk.data =
NULL;
463 if (info_ptr->unknown_chunks)
465 png_free(png_ptr, info_ptr->unknown_chunks[num].data);
466 info_ptr->unknown_chunks[
num].data =
NULL;
474 if (info_ptr->unknown_chunks_num)
476 for (i = 0; i < info_ptr->unknown_chunks_num; i++)
479 png_free(png_ptr, info_ptr->unknown_chunks);
480 info_ptr->unknown_chunks =
NULL;
481 info_ptr->unknown_chunks_num = 0;
487 #ifdef PNG_hIST_SUPPORTED
492 info_ptr->hist =
NULL;
501 info_ptr->palette =
NULL;
503 info_ptr->num_palette = 0;
506 #ifdef PNG_INFO_IMAGE_SUPPORTED
510 if (info_ptr->row_pointers)
513 for (row = 0; row < (
int)info_ptr->height; row++)
515 png_free(png_ptr, info_ptr->row_pointers[row]);
516 info_ptr->row_pointers[
row] =
NULL;
518 png_free(png_ptr, info_ptr->row_pointers);
519 info_ptr->row_pointers =
NULL;
528 info_ptr->free_me &= ~mask;
542 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
543 if (png_ptr->num_chunk_list)
545 png_free(png_ptr, png_ptr->chunk_list);
546 png_ptr->chunk_list =
NULL;
547 png_ptr->num_chunk_list = 0;
565 return (png_ptr->io_ptr);
568 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
569 # ifdef PNG_STDIO_SUPPORTED
588 # ifdef PNG_TIME_RFC1123_SUPPORTED
595 static PNG_CONST char short_months[12][4] =
596 {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
597 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"};
602 if (ptime->year > 9999 ||
603 ptime->month == 0 || ptime->month > 12 ||
604 ptime->day == 0 || ptime->day > 31 ||
605 ptime->hour > 23 || ptime->minute > 59 ||
608 png_warning(png_ptr,
"Ignoring invalid time value");
616 # define APPEND_STRING(string)\
617 pos = png_safecat(png_ptr->time_buffer, sizeof png_ptr->time_buffer,\
619 # define APPEND_NUMBER(format, value)\
620 APPEND_STRING(PNG_FORMAT_NUMBER(number_buf, format, (value)))
622 if (pos < (sizeof png_ptr->time_buffer)-1)\
623 png_ptr->time_buffer[pos++] = (ch)
639 # undef APPEND_NUMBER
640 # undef APPEND_STRING
643 return png_ptr->time_buffer;
653 #ifdef PNG_STRING_COPYRIGHT
654 return PNG_STRING_COPYRIGHT
661 "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
664 return "libpng version 1.5.9 - February 18, 2012\
665 Copyright (c) 1998-2011 Glenn Randers-Pehrson\
666 Copyright (c) 1996-1997 Andreas Dilger\
667 Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
702 # ifndef PNG_READ_SUPPORTED
711 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
718 if (png_ptr ==
NULL || chunk_name ==
NULL || png_ptr->num_chunk_list <= 0)
721 p_end = png_ptr->chunk_list;
722 p = p_end + png_ptr->num_chunk_list*5;
749 #ifdef PNG_READ_SUPPORTED
771 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
777 # ifdef PNG_CHECK_cHRM_SUPPORTED
786 unsigned long xy_hi,xy_lo,yx_hi,yx_lo;
788 png_debug(1,
"in function png_check_cHRM_fixed");
800 if (white_x < 0 || white_y <= 0 ||
801 red_x < 0 || red_y < 0 ||
802 green_x < 0 || green_y < 0 ||
803 blue_x < 0 || blue_y < 0)
806 "Ignoring attempt to set negative chromaticity value");
837 if (xy_hi == yx_hi && xy_lo == yx_lo)
840 "Ignoring attempt to set cHRM RGB triangle with zero area");
848 #ifdef PNG_cHRM_SUPPORTED
1087 denominator = left -
right;
1099 red_inverse <= xy.
whitey )
1106 green_inverse <= xy.
whitey)
1114 if (blue_scale <= 0)
return 1;
1152 "extreme cHRM chunk cannot be converted to tristimulus values");
1159 png_error(png_ptr,
"internal error in png_XYZ_from_xy");
1179 png_warning(png_ptr,
"Image width is zero in IHDR");
1185 png_warning(png_ptr,
"Image height is zero in IHDR");
1189 # ifdef PNG_SET_USER_LIMITS_SUPPORTED
1190 if (width > png_ptr->user_width_max)
1196 png_warning(png_ptr,
"Image width exceeds user limit in IHDR");
1200 # ifdef PNG_SET_USER_LIMITS_SUPPORTED
1201 if (height > png_ptr->user_height_max)
1206 png_warning(png_ptr,
"Image height exceeds user limit in IHDR");
1212 png_warning(png_ptr,
"Invalid image width in IHDR");
1218 png_warning(png_ptr,
"Invalid image height in IHDR");
1228 png_warning(png_ptr,
"Width is too large for libpng to process pixels");
1231 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
1232 bit_depth != 8 && bit_depth != 16)
1234 png_warning(png_ptr,
"Invalid bit depth in IHDR");
1238 if (color_type < 0 || color_type == 1 ||
1239 color_type == 5 || color_type > 6)
1241 png_warning(png_ptr,
"Invalid color type in IHDR");
1250 png_warning(png_ptr,
"Invalid color type/bit depth combination in IHDR");
1256 png_warning(png_ptr,
"Unknown interlace method in IHDR");
1262 png_warning(png_ptr,
"Unknown compression method in IHDR");
1266 # ifdef PNG_MNG_FEATURES_SUPPORTED
1277 png_ptr->mng_features_permitted)
1278 png_warning(png_ptr,
"MNG features are not allowed in a PNG datastream");
1288 png_warning(png_ptr,
"Unknown filter method in IHDR");
1294 png_warning(png_ptr,
"Invalid filter method in IHDR");
1302 png_warning(png_ptr,
"Unknown filter method in IHDR");
1308 png_error(png_ptr,
"Invalid IHDR data");
1311 #if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)
1317 #define png_fp_add(state, flags) ((state) |= (flags))
1318 #define png_fp_set(state, value) ((state) = (value) | ((state) & PNG_FP_STICKY))
1324 int state = *statep;
1337 case 49:
case 50:
case 51:
case 52:
1338 case 53:
case 54:
case 55:
case 56:
1342 default:
goto PNG_FP_End;
1352 if (state & PNG_FP_SAW_ANY)
1372 if (state & PNG_FP_SAW_DOT)
1380 if ((state & PNG_FP_SAW_DIGIT) == 0)
1402 if ((state & PNG_FP_SAW_DIGIT) == 0)
1410 if (state & PNG_FP_SAW_ANY)
1428 default:
goto PNG_FP_End;
1454 (char_index == size ||
string[char_index] == 0))
1461 #ifdef PNG_READ_sCAL_SUPPORTED
1462 # ifdef PNG_FLOATING_POINT_SUPPORTED
1477 if (power < DBL_MIN_10_EXP)
return 0;
1478 recip = 1, power = -power;
1487 if (power & 1) d *= mult;
1513 precision = DBL_DIG;
1516 if (precision > DBL_DIG+1)
1517 precision = DBL_DIG+1;
1520 if (size >= precision+5)
1529 if (fp >= DBL_MIN && fp <= DBL_MAX)
1543 (
void)frexp(fp, &exp_b10);
1545 exp_b10 = (exp_b10 * 77) >> 8;
1550 while (base < DBL_MIN || base < fp)
1555 if (test <= DBL_MAX)
1556 ++exp_b10, base = test;
1570 while (fp >= 1) fp /= 10, ++exp_b10;
1579 int czero, clead, cdigits;
1585 if (exp_b10 < 0 && exp_b10 > -3)
1609 if (cdigits+czero-clead+1 < (
int)precision)
1622 if (cdigits == 0) --clead;
1626 while (cdigits > 0 && d > 9)
1630 if (exp_b10 != (-1))
1635 ch = *--ascii, ++
size;
1653 if (exp_b10 == (-1))
1662 ++
size, exp_b10 = 1;
1682 if (cdigits == 0) ++clead;
1687 cdigits += czero - clead;
1696 if (exp_b10 != (-1))
1698 if (exp_b10 == 0) *ascii++ = 46, --
size;
1702 *ascii++ = 48, --czero;
1705 if (exp_b10 != (-1))
1707 if (exp_b10 == 0) *ascii++ = 46, --
size;
1711 *ascii++ = (char)(48 + (
int)
d), ++cdigits;
1714 while (cdigits+czero-clead < (
int)precision && fp > DBL_MIN);
1725 if (exp_b10 >= (-1) && exp_b10 <= 2)
1734 while (--exp_b10 >= 0) *ascii++ = 48;
1752 *ascii++ = 69, --
size;
1759 unsigned int uexp_b10;
1763 *ascii++ = 45, --
size;
1764 uexp_b10 = -exp_b10;
1772 while (uexp_b10 > 0)
1774 exponent[cdigits++] = (char)(48 + uexp_b10 % 10);
1782 if ((
int)size > cdigits)
1784 while (cdigits > 0) *ascii++ = exponent[--cdigits];
1792 else if (!(fp >= DBL_MIN))
1809 png_error(png_ptr,
"ASCII conversion buffer too small");
1814 # ifdef PNG_FIXED_POINT_SUPPORTED
1830 *ascii++ = 45, --
size, num = -fp;
1834 if (num <= 0x80000000)
1836 unsigned int ndigits = 0,
first = 16 ;
1842 unsigned int tmp = num/10;
1844 digits[ndigits++] = (char)(48 + num);
1848 if (
first == 16 && num > 0)
1855 while (ndigits > 5) *ascii++ = digits[--ndigits];
1868 while (ndigits < i) *ascii++ = 48, --
i;
1869 while (ndigits >=
first) *ascii++ = digits[--ndigits];
1883 png_error(png_ptr,
"ASCII conversion buffer too small");
1888 #if defined(PNG_FLOATING_POINT_SUPPORTED) && \
1889 !defined(PNG_FIXED_POINT_MACRO_SUPPORTED)
1893 double r =
floor(100000 * fp + .5);
1895 if (r > 2147483647. || r < -2147483648.)
1896 png_fixed_error(png_ptr, text);
1902 #if defined(PNG_READ_GAMMA_SUPPORTED) || \
1903 defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG__READ_pHYs_SUPPORTED)
1917 if (a == 0 || times == 0)
1924 #ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
1942 negative = 1, A = -
a;
1947 negative = !negative, T = -times;
1952 negative = !negative, D = -
divisor;
1959 s16 = (A >> 16) * (T & 0xffff) +
1960 (A & 0xffff) * (T >> 16);
1964 s32 = (A >> 16) * (T >> 16) + (s16 >> 16);
1965 s00 = (A & 0xffff) * (T & 0xffff);
1967 s16 = (s16 & 0xffff) << 16;
1982 while (--bitshift >= 0)
1987 d32 = D >> (32-bitshift), d00 = D << bitshift;
1994 if (s00 < d00) --s32;
1995 s32 -= d32, s00 -= d00, result += 1<<bitshift;
1999 if (s32 == d32 && s00 >= d00)
2000 s32 = 0, s00 -= d00, result += 1<<bitshift;
2004 if (s00 >= (D >> 1))
2011 if ((negative && result <= 0) || (!negative && result >= 0))
2025 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
2038 png_warning(png_ptr,
"fixed point overflow ignored");
2043 #ifdef PNG_READ_GAMMA_SUPPORTED
2048 #ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2049 double r =
floor(1E10/a+.5);
2068 #ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2069 double r = a * 1E-5;
2090 #ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2113 #ifdef PNG_CHECK_cHRM_SUPPORTED
2133 unsigned long *lo_product)
2138 a = (v1 >> 16) & 0xffff;
2140 c = (v2 >> 16) & 0xffff;
2145 y = ((lo >> 16) & 0xffff) +
x;
2147 lo = (lo & 0xffff) | ((y & 0xffff) << 16);
2148 hi = (y >> 16) & 0xffff;
2152 *hi_product = (
unsigned long)hi;
2153 *lo_product = (
unsigned long)lo;
2157 #ifdef PNG_READ_GAMMA_SUPPORTED
2158 #ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED
2178 for (
i=128;
i<256;++
i) { .5 -
l(
i/255)/
l(2)*65536*65536; }
2180 4270715492U, 4222494797U, 4174646467U, 4127164793U, 4080044201U, 4033279239U,
2181 3986864580U, 3940795015U, 3895065449U, 3849670902U, 3804606499U, 3759867474U,
2182 3715449162U, 3671346997U, 3627556511U, 3584073329U, 3540893168U, 3498011834U,
2183 3455425220U, 3413129301U, 3371120137U, 3329393864U, 3287946700U, 3246774933U,
2184 3205874930U, 3165243125U, 3124876025U, 3084770202U, 3044922296U, 3005329011U,
2185 2965987113U, 2926893432U, 2888044853U, 2849438323U, 2811070844U, 2772939474U,
2186 2735041326U, 2697373562U, 2659933400U, 2622718104U, 2585724991U, 2548951424U,
2187 2512394810U, 2476052606U, 2439922311U, 2404001468U, 2368287663U, 2332778523U,
2188 2297471715U, 2262364947U, 2227455964U, 2192742551U, 2158222529U, 2123893754U,
2189 2089754119U, 2055801552U, 2022034013U, 1988449497U, 1955046031U, 1921821672U,
2190 1888774511U, 1855902668U, 1823204291U, 1790677560U, 1758320682U, 1726131893U,
2191 1694109454U, 1662251657U, 1630556815U, 1599023271U, 1567649391U, 1536433567U,
2192 1505374214U, 1474469770U, 1443718700U, 1413119487U, 1382670639U, 1352370686U,
2193 1322218179U, 1292211689U, 1262349810U, 1232631153U, 1203054352U, 1173618059U,
2194 1144320946U, 1115161701U, 1086139034U, 1057251672U, 1028498358U, 999877854U,
2195 971388940U, 943030410U, 914801076U, 886699767U, 858725327U, 830876614U,
2196 803152505U, 775551890U, 748073672U, 720716771U, 693480120U, 666362667U,
2197 639363374U, 612481215U, 585715177U, 559064263U, 532527486U, 506103872U,
2198 479792461U, 453592303U, 427502463U, 401522014U, 375650043U, 349885648U,
2199 324227938U, 298676034U, 273229066U, 247886176U, 222646516U, 197509248U,
2200 172473545U, 147538590U, 122703574U, 97967701U, 73330182U, 48790236U,
2210 65166, 64430, 63700, 62976, 62257, 61543, 60835, 60132, 59434, 58741, 58054,
2211 57371, 56693, 56020, 55352, 54689, 54030, 53375, 52726, 52080, 51439, 50803,
2212 50170, 49542, 48918, 48298, 47682, 47070, 46462, 45858, 45257, 44661, 44068,
2213 43479, 42894, 42312, 41733, 41159, 40587, 40020, 39455, 38894, 38336, 37782,
2214 37230, 36682, 36137, 35595, 35057, 34521, 33988, 33459, 32932, 32408, 31887,
2215 31369, 30854, 30341, 29832, 29325, 28820, 28319, 27820, 27324, 26830, 26339,
2216 25850, 25364, 24880, 24399, 23920, 23444, 22970, 22499, 22029, 21562, 21098,
2217 20636, 20175, 19718, 19262, 18808, 18357, 17908, 17461, 17016, 16573, 16132,
2218 15694, 15257, 14822, 14390, 13959, 13530, 13103, 12678, 12255, 11834, 11415,
2219 10997, 10582, 10168, 9756, 9346, 8937, 8531, 8126, 7723, 7321, 6921, 6523,
2220 6127, 5732, 5339, 4947, 4557, 4169, 3782, 3397, 3014, 2632, 2251, 1872, 1495,
2226 png_log8bit(
unsigned int x)
2228 unsigned int lg2 = 0;
2235 if ((x &= 0xff) == 0)
2238 if ((x & 0xf0) == 0)
2241 if ((x & 0xc0) == 0)
2244 if ((x & 0x80) == 0)
2248 return (
png_int_32)((lg2 << 16) + ((png_8bit_l2[x-128]+32768)>>16));
2284 unsigned int lg2 = 0;
2287 if ((x &= 0xffff) == 0)
2290 if ((x & 0xff00) == 0)
2293 if ((x & 0xf000) == 0)
2296 if ((x & 0xc000) == 0)
2299 if ((x & 0x8000) == 0)
2306 lg2 += (png_8bit_l2[(x>>8)-128]+8) >> 4;
2323 lg2 += ((23591U * (65536U-
x)) + (1U << (16+6-12-1))) >> (16+6-12);
2326 lg2 -= ((23499U * (x-65536U)) + (1U << (16+6-12-1))) >> (16+6-12);
2350 for (
i=0;
i<16;++
i) { .5 +
e(-
i/16*
l(2))*2^32; }
2353 4294967295U, 4112874773U, 3938502376U, 3771522796U, 3611622603U, 3458501653U,
2354 3311872529U, 3171459999U, 3037000500U, 2908241642U, 2784941738U, 2666869345U,
2355 2553802834U, 2445529972U, 2341847524U, 2242560872U
2361 for (
i=11;
i>=0;--
i){ print
i,
" ", (1 -
e(-(2^i)/65536*
l(2))) * 2^(32-i),
"\n"}
2362 11 44937.64284865548751208448
2363 10 45180.98734845585101160448
2364 9 45303.31936980687359311872
2365 8 45364.65110595323018870784
2366 7 45395.35850361789624614912
2367 6 45410.72259715102037508096
2368 5 45418.40724413220722311168
2369 4 45422.25021786898173001728
2370 3 45424.17186732298419044352
2371 2 45425.13273269940811464704
2372 1 45425.61317555035558641664
2373 0 45425.85339951654943850496
2379 if (x > 0 && x <= 0xfffff)
2391 e -= (((e >> 16) * 44938U) + 16U) >> 5;
2394 e -= (((e >> 16) * 45181U) + 32U) >> 6;
2397 e -= (((e >> 16) * 45303U) + 64U) >> 7;
2400 e -= (((e >> 16) * 45365U) + 128U) >> 8;
2403 e -= (((e >> 16) * 45395U) + 256U) >> 9;
2406 e -= (((e >> 16) * 45410U) + 512U) >> 10;
2409 e -= (((e >> 16) * 355U * (x & 0x3fU)) + 256U) >> 9;
2418 return png_32bit_exp[0];
2435 return (
png_byte)((x + 0x7fffffU) >> 24);
2453 if (value > 0 && value < 255)
2455 # ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2456 double r =
floor(255*pow(value/255.,gamma_val*.00001)+.5);
2463 return png_exp8bit(res);
2476 if (value > 0 && value < 65535)
2478 # ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2479 double r =
floor(65535*pow(value/65535.,gamma_val*.00001)+.5);
2486 return png_exp16bit(res);
2505 if (png_ptr->bit_depth == 8)
2537 PNG_CONST unsigned int max_by_2 = 1U << (15U-shift);
2543 for (i = 0; i <
num; i++)
2562 for (j = 0; j < 256; j++)
2565 # ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2567 double d =
floor(65535*pow(ig/(
double)max, gamma_val*.00001)+.5);
2571 ig = (ig * 65535U + max_by_2)/max;
2582 for (j = 0; j < 256; j++)
2587 ig = (ig * 65535U + max_by_2)/max;
2614 for (i = 0; i <
num; i++)
2635 for (i = 0; i < 255; ++
i)
2644 bound = (bound * max + 32768U)/65535U + 1U;
2646 while (last < bound)
2648 table[last & (0xffU >> shift)][last >> (8U - shift)] = out;
2654 while (last < (num << 8))
2656 table[last & (0xff >> shift)][last >> (8U - shift)] = 65535U;
2675 else for (i=0; i<256; ++
i)
2685 png_free(png_ptr, png_ptr->gamma_table);
2686 png_ptr->gamma_table =
NULL;
2688 if (png_ptr->gamma_16_table !=
NULL)
2691 int istop = (1 << (8 - png_ptr->gamma_shift));
2692 for (i = 0; i < istop; i++)
2694 png_free(png_ptr, png_ptr->gamma_16_table[i]);
2696 png_free(png_ptr, png_ptr->gamma_16_table);
2697 png_ptr->gamma_16_table =
NULL;
2700 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
2701 defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
2702 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
2703 png_free(png_ptr, png_ptr->gamma_from_1);
2704 png_ptr->gamma_from_1 =
NULL;
2705 png_free(png_ptr, png_ptr->gamma_to_1);
2706 png_ptr->gamma_to_1 =
NULL;
2708 if (png_ptr->gamma_16_from_1 !=
NULL)
2711 int istop = (1 << (8 - png_ptr->gamma_shift));
2712 for (i = 0; i < istop; i++)
2714 png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
2716 png_free(png_ptr, png_ptr->gamma_16_from_1);
2717 png_ptr->gamma_16_from_1 =
NULL;
2719 if (png_ptr->gamma_16_to_1 !=
NULL)
2722 int istop = (1 << (8 - png_ptr->gamma_shift));
2723 for (i = 0; i < istop; i++)
2725 png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
2727 png_free(png_ptr, png_ptr->gamma_16_to_1);
2728 png_ptr->gamma_16_to_1 =
NULL;
2741 png_debug(1,
"in png_build_gamma_table");
2749 if (png_ptr->gamma_table !=
NULL || png_ptr->gamma_16_table !=
NULL)
2751 png_warning(png_ptr,
"gamma table being rebuilt");
2759 png_ptr->screen_gamma) :
PNG_FP_1);
2761 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
2762 defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
2763 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
2770 png_ptr->screen_gamma > 0 ?
png_reciprocal(png_ptr->screen_gamma) :
2781 sig_bit = png_ptr->sig_bit.red;
2783 if (png_ptr->sig_bit.green > sig_bit)
2784 sig_bit = png_ptr->sig_bit.green;
2786 if (png_ptr->sig_bit.blue > sig_bit)
2787 sig_bit = png_ptr->sig_bit.blue;
2790 sig_bit = png_ptr->sig_bit.gray;
2810 if (sig_bit > 0 && sig_bit < 16U)
2829 png_ptr->gamma_shift = shift;
2831 #ifdef PNG_16BIT_SUPPORTED
2840 png_ptr->screen_gamma > 0 ?
png_product2(png_ptr->gamma,
2841 png_ptr->screen_gamma) :
PNG_FP_1);
2843 #ifdef PNG_16BIT_SUPPORTED
2847 png_ptr->screen_gamma) :
PNG_FP_1);
2850 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
2851 defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
2852 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
2863 png_ptr->screen_gamma > 0 ?
png_reciprocal(png_ptr->screen_gamma) :
INT32 INT32 * denominator
GLenum GLsizei GLenum GLenum const GLvoid * table
#define PNG_INTERLACE_LAST
void png_zfree(voidpf png_ptr, voidpf ptr)
png_libpng_version_1_5_9 Your_png_h_is_not_version_1_5_9
void PNGAPI png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, int num)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
#define PNG_UNUSED(param)
int png_user_version_check(png_structp png_ptr, png_const_charp user_png_ver)
PNG_CONST png_time FAR * png_const_timep
void png_ascii_from_fp(png_structp png_ptr, png_charp ascii, png_size_t size, double fp, unsigned int precision)
png_size_t FAR * png_size_tp
PNG_CONST png_struct FAR * png_const_structp
#define PNG_FLAG_MALLOC_NULL_MEM_OK
#define PNG_COLOR_TYPE_RGB
#define PNG_COLOR_TYPE_GRAY_ALPHA
static png_fixed_point png_product2(png_fixed_point a, png_fixed_point b)
#define PNG_COLOR_TYPE_PALETTE
#define PNG_SCALE_16_TO_8
png_const_charp PNGAPI png_get_libpng_ver(png_const_structp png_ptr)
png_fixed_point png_fixed(png_structp png_ptr, double fp, png_const_charp text)
return Display return Display Bool Bool int int e
png_fixed_point FAR * png_fixed_point_p
#define PNG_LIBPNG_VER_STRING
png_error(png_ptr,"Missing IHDR before iCCP")
void PNGAPI png_set_sig_bytes(png_structp png_ptr, int num_bytes)
png_fixed_point png_reciprocal(png_fixed_point a)
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
#define PNG_COLOR_TYPE_RGB_ALPHA
PNG_CONST char FAR * png_const_charp
return Display return Display Bool Bool int d
void PNGAPI png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
#define PNG_NUMBER_FORMAT_02u
#define PNG_HANDLE_CHUNK_AS_DEFAULT
void PNGAPI png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
size_t png_safecat(png_charp buffer, size_t bufsize, size_t pos, png_const_charp string)
png_size_t png_alloc_size_t
png_byte FAR *FAR * png_bytepp
#define PNG_FLAG_CRC_ANCILLARY_USE
int png_xy_from_XYZ(png_xy *xy, png_XYZ XYZ)
#define PNG_USER_WILL_FREE_DATA
png_const_charp PNGAPI png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime)
static void png_build_8bit_table(png_structp png_ptr, png_bytepp ptable, PNG_CONST png_fixed_point gamma_val)
GLenum GLenum GLvoid * row
#define PNG_NUMBER_FORMAT_u
void png_check_IHDR(png_structp png_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_struct FAR * png_structp
void png_info_destroy(png_structp png_ptr, png_infop info_ptr)
#define PNG_COLOR_MASK_COLOR
#define PNG_GAMMA_THRESHOLD_FIXED
png_const_charp PNGAPI png_get_header_version(png_const_structp png_ptr)
#define PNG_USER_HEIGHT_MAX
int png_check_fp_number(png_const_charp string, png_size_t size, int *statep, png_size_tp whereami)
png_fixed_point png_muldiv_warn(png_structp png_ptr, png_fixed_point a, png_int_32 times, png_int_32 divisor)
void png_destroy_struct(png_voidp struct_ptr)
#define PNG_FLAG_CRC_CRITICAL_IGNORE
EGLSurface EGLint EGLint EGLint width
void png_build_gamma_table(png_structp png_ptr, int bit_depth)
unsigned short png_uint_16
char * png_libpng_version_1_5_9
void PNGAPI png_warning(png_structp png_ptr, png_const_charp warning_message)
int png_check_cHRM_fixed(png_structp png_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)
png_voidp PNGAPI png_get_io_ptr(png_structp png_ptr)
void png_ascii_from_fixed(png_structp png_ptr, png_charp ascii, png_size_t size, png_fixed_point fp)
int PNGAPI png_handle_as_unknown(png_structp png_ptr, png_const_bytep chunk_name)
png_uint_16 FAR * png_uint_16p
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
PNG_CONST png_byte FAR * png_const_bytep
#define PNG_STRING_NEWLINE
int png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, png_int_32 divisor)
#define PNG_FLAG_CRC_ANCILLARY_NOWARN
png_fixed_point png_reciprocal2(png_fixed_point a, png_fixed_point b)
int ZEXPORT inflateReset(z_streamp strm)
#define PNG_DESTROY_WILL_FREE_DATA
#define PNG_FLAG_MNG_FILTER_64
EGLSurface EGLint EGLint y
#define APPEND_STRING(string)
#define PNG_FILTER_TYPE_BASE
int png_XYZ_from_xy(png_XYZ *XYZ, png_xy xy)
png_uint_16 FAR *FAR * png_uint_16pp
EGLSurface EGLint void ** value
void PNGAPI png_data_freer(png_structp png_ptr, png_infop info_ptr, int freer, png_uint_32 mask)
png_const_charp PNGAPI png_get_copyright(png_const_structp png_ptr)
void png_64bit_product(long v1, long v2, unsigned long *hi_product, unsigned long *lo_product)
#define PNG_COMPRESSION_TYPE_BASE
#define PNG_CHUNK_ANCILLIARY(c)
#define PNG_HEADER_VERSION_STRING
png_byte png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val)
static void png_build_16to8_table(png_structp png_ptr, png_uint_16pp *ptable, PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
png_int_32 png_fixed_point
void png_destroy_gamma_table(png_structp png_ptr)
void png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, png_voidp mem_ptr)
GLdouble GLdouble GLdouble r
GLdouble GLdouble GLdouble b
void png_calculate_crc(png_structp png_ptr, png_const_bytep ptr, png_size_t length)
#define APPEND_NUMBER(format, value)
#define PNG_INTRAPIXEL_DIFFERENCING
#define PNG_FUNCTION(type, name, args, attributes)
#define PNG_USER_WIDTH_MAX
#define PNG_FLAG_LIBRARY_MISMATCH
png_const_charp PNGAPI png_get_header_ver(png_const_structp png_ptr)
int png_check_fp_string(png_const_charp string, png_size_t size)
GLenum GLint GLint * precision
#define PNG_FLAG_CRC_ANCILLARY_MASK
#define png_fp_add(state, flags)
png_info FAR *FAR * png_infopp
int PNGAPI png_reset_zstream(png_structp png_ptr)
void PNGAPI png_free(png_structp png_ptr, png_voidp ptr)
int png_chunk_unknown_handling(png_structp png_ptr, png_uint_32 chunk_name)
#define PNG_HAVE_PNG_SIGNATURE
png_uint_16 png_gamma_correct(png_structp png_ptr, unsigned int value, png_fixed_point gamma_val)
static void png_build_16bit_table(png_structp png_ptr, png_uint_16pp *ptable, PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
png_uint_16 png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val)
static double png_pow10(int power)
void PNGAPI png_init_io(png_structp png_ptr, png_FILE_p fp)
int PNGAPI png_sig_cmp(png_const_bytep sig, png_size_t start, png_size_t num_to_check)
void png_reset_crc(png_structp png_ptr)
#define PNG_CSTRING_FROM_CHUNK(s, c)
GLfloat GLfloat GLfloat v2
int png_gamma_significant(png_fixed_point gamma_val)
#define png_fp_set(state, value)
png_uint_32 PNGAPI png_access_version_number(void)