15 #define PNG_NO_PEDANTIC_WARNINGS 17 #ifdef PNG_WRITE_SUPPORTED 26 buf[0] = (
png_byte)((i >> 24) & 0xff);
27 buf[1] = (
png_byte)((i >> 16) & 0xff);
28 buf[2] = (
png_byte)((i >> 8) & 0xff);
39 buf[0] = (
png_byte)((i >> 24) & 0xff);
40 buf[1] = (
png_byte)((i >> 16) & 0xff);
41 buf[2] = (
png_byte)((i >> 8) & 0xff);
52 buf[0] = (
png_byte)((i >> 8) & 0xff);
65 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
70 if (png_ptr->sig_bytes < 3)
71 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
104 png_debug2(0,
"Writing %s chunk, length = %lu", chunk_name,
105 (
unsigned long)length);
116 png_memcpy(png_ptr->chunk_name, chunk_name, 4);
133 if (data !=
NULL && length > 0)
149 if (png_ptr ==
NULL)
return;
157 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED) 177 compression_state *comp)
181 comp->num_output_ptr = 0;
182 comp->max_output_ptr = 0;
183 comp->output_ptr =
NULL;
191 comp->input_len = text_len;
192 return((
int)text_len);
197 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 199 png_snprintf(msg, 50,
"Unknown compression type %d", compression);
222 png_ptr->zstream.avail_in = (
uInt)text_len;
223 png_ptr->zstream.next_in = (
Bytef *)text;
224 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
225 png_ptr->zstream.next_out = (
Bytef *)png_ptr->zbuf;
235 if (png_ptr->zstream.msg !=
NULL)
236 png_error(png_ptr, png_ptr->zstream.msg);
241 if (!(png_ptr->zstream.avail_out))
244 if (comp->num_output_ptr >= comp->max_output_ptr)
248 old_max = comp->max_output_ptr;
249 comp->max_output_ptr = comp->num_output_ptr + 4;
250 if (comp->output_ptr !=
NULL)
254 old_ptr = comp->output_ptr;
269 comp->output_ptr[comp->num_output_ptr] =
272 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
274 comp->num_output_ptr++;
277 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
278 png_ptr->zstream.next_out = png_ptr->zbuf;
281 }
while (png_ptr->zstream.avail_in);
292 if (!(png_ptr->zstream.avail_out))
295 if (comp->num_output_ptr >= comp->max_output_ptr)
299 old_max = comp->max_output_ptr;
300 comp->max_output_ptr = comp->num_output_ptr + 4;
301 if (comp->output_ptr !=
NULL)
305 old_ptr = comp->output_ptr;
321 comp->output_ptr[comp->num_output_ptr] =
324 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
326 comp->num_output_ptr++;
329 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
330 png_ptr->zstream.next_out = png_ptr->zbuf;
336 if (png_ptr->zstream.msg !=
NULL)
337 png_error(png_ptr, png_ptr->zstream.msg);
344 text_len = png_ptr->zbuf_size * comp->num_output_ptr;
345 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
346 text_len += png_ptr->zbuf_size - (
png_size_t)png_ptr->zstream.avail_out;
348 return((
int)text_len);
353 png_write_compressed_data_out(
png_structp png_ptr, compression_state *comp)
366 for (i = 0; i < comp->num_output_ptr; i++)
370 png_free(png_ptr, comp->output_ptr[i]);
371 comp->output_ptr[
i]=
NULL;
373 if (comp->max_output_ptr != 0)
374 png_free(png_ptr, comp->output_ptr);
375 comp->output_ptr=
NULL;
377 if (png_ptr->zstream.avail_out < (
png_uint_32)png_ptr->zbuf_size)
379 (
png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
383 png_ptr->zstream.data_type =
Z_BINARY;
396 #ifdef PNG_USE_LOCAL_ARRAYS 415 case 16: png_ptr->channels = 1;
break;
417 "Invalid bit depth for grayscale image");
421 if (bit_depth != 8 && bit_depth != 16)
422 png_error(png_ptr,
"Invalid bit depth for RGB image");
423 png_ptr->channels = 3;
431 case 8: png_ptr->channels = 1;
break;
432 default:
png_error(png_ptr,
"Invalid bit depth for paletted image");
436 if (bit_depth != 8 && bit_depth != 16)
437 png_error(png_ptr,
"Invalid bit depth for grayscale+alpha image");
438 png_ptr->channels = 2;
441 if (bit_depth != 8 && bit_depth != 16)
442 png_error(png_ptr,
"Invalid bit depth for RGBA image");
443 png_ptr->channels = 4;
446 png_error(png_ptr,
"Invalid image color type specified");
451 png_warning(png_ptr,
"Invalid compression type specified");
467 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
474 png_warning(png_ptr,
"Invalid filter type specified");
478 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 482 png_warning(png_ptr,
"Invalid interlace type specified");
490 png_ptr->bit_depth = (
png_byte)bit_depth;
491 png_ptr->color_type = (
png_byte)color_type;
492 png_ptr->interlaced = (
png_byte)interlace_type;
493 #ifdef PNG_MNG_FEATURES_SUPPORTED 494 png_ptr->filter_type = (
png_byte)filter_type;
496 png_ptr->compression_type = (
png_byte)compression_type;
497 png_ptr->width =
width;
500 png_ptr->pixel_depth = (
png_byte)(bit_depth * png_ptr->channels);
501 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
503 png_ptr->usr_width = png_ptr->width;
504 png_ptr->usr_bit_depth = png_ptr->bit_depth;
505 png_ptr->usr_channels = png_ptr->channels;
512 buf[10] = (
png_byte)compression_type;
522 png_ptr->zstream.opaque = (
voidpf)png_ptr;
523 if (!(png_ptr->do_filter))
526 png_ptr->bit_depth < 8)
531 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
538 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
540 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
541 png_ptr->zlib_mem_level = 8;
542 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
543 png_ptr->zlib_window_bits = 15;
544 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
545 png_ptr->zlib_method = 8;
546 ret =
deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
547 png_ptr->zlib_method, png_ptr->zlib_window_bits,
548 png_ptr->zlib_mem_level, png_ptr->zlib_strategy);
552 "zlib failed to initialize compressor -- version error");
554 "zlib failed to initialize compressor -- stream error");
556 "zlib failed to initialize compressor -- mem error");
557 png_error(png_ptr,
"zlib failed to initialize compressor");
559 png_ptr->zstream.next_out = png_ptr->zbuf;
560 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
563 png_ptr->zstream.data_type =
Z_BINARY;
575 #ifdef PNG_USE_LOCAL_ARRAYS 591 num_pal == 0) || num_pal > max_palette_length)
595 png_error(png_ptr,
"Invalid number of colors in palette");
599 png_warning(png_ptr,
"Invalid number of colors in palette");
607 "Ignoring request to write a PLTE chunk in grayscale PNG");
612 png_debug1(3,
"num_palette = %d", png_ptr->num_palette);
616 #ifdef PNG_POINTER_INDEXING_SUPPORTED 617 for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
619 buf[0] = pal_ptr->red;
620 buf[1] = pal_ptr->green;
621 buf[2] = pal_ptr->blue;
629 for (i = 0; i < num_pal; i++)
631 buf[0] = pal_ptr[
i].red;
632 buf[1] = pal_ptr[
i].green;
633 buf[2] = pal_ptr[
i].blue;
645 #ifdef PNG_USE_LOCAL_ARRAYS 656 unsigned int z_cmf = data[0];
657 if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
665 png_ptr->height < 16384 && png_ptr->width < 16384)
667 png_uint_32 uncompressed_idat_size = png_ptr->height *
669 png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
670 unsigned int z_cinfo = z_cmf >> 4;
671 unsigned int half_z_window_size = 1 << (z_cinfo + 7);
672 while (uncompressed_idat_size <= half_z_window_size &&
673 half_z_window_size >= 256)
676 half_z_window_size >>= 1;
678 z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
683 data[1] += (
png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
689 "Invalid zlib compression method or flags in IDAT");
700 #ifdef PNG_USE_LOCAL_ARRAYS 711 #ifdef PNG_WRITE_gAMA_SUPPORTED 713 #ifdef PNG_FLOATING_POINT_SUPPORTED 717 #ifdef PNG_USE_LOCAL_ARRAYS 726 igamma = (
png_uint_32)(file_gamma * 100000.0 + 0.5);
731 #ifdef PNG_FIXED_POINT_SUPPORTED 735 #ifdef PNG_USE_LOCAL_ARRAYS 749 #ifdef PNG_WRITE_sRGB_SUPPORTED 754 #ifdef PNG_USE_LOCAL_ARRAYS 763 "Invalid sRGB rendering intent specified");
769 #ifdef PNG_WRITE_iCCP_SUPPORTED 775 #ifdef PNG_USE_LOCAL_ARRAYS 780 compression_state comp;
781 int embedded_profile_len = 0;
785 comp.num_output_ptr = 0;
786 comp.max_output_ptr = 0;
787 comp.output_ptr =
NULL;
796 png_warning(png_ptr,
"Unknown compression type in iCCP chunk");
802 embedded_profile_len =
808 if (embedded_profile_len < 0)
811 "Embedded profile length in iCCP chunk is negative");
816 if (profile_len < embedded_profile_len)
819 "Embedded profile length too large in iCCP chunk");
824 if (profile_len > embedded_profile_len)
827 "Truncating profile to actual length in iCCP chunk");
828 profile_len = embedded_profile_len;
832 profile_len = png_text_compress(png_ptr, profile,
838 new_name[name_len + 1] = 0x00;
843 png_write_compressed_data_out(png_ptr, &comp);
850 #ifdef PNG_WRITE_sPLT_SUPPORTED 855 #ifdef PNG_USE_LOCAL_ARRAYS 861 int entry_size = (spalette->depth == 8 ? 6 : 10);
862 int palette_size = entry_size * spalette->nentries;
864 #ifndef PNG_POINTER_INDEXING_SUPPORTED 881 #ifdef PNG_POINTER_INDEXING_SUPPORTED 882 for (ep = spalette->entries; ep<spalette->
entries + spalette->nentries; ep++)
884 if (spalette->depth == 8)
903 ep=spalette->entries;
904 for (i=0; i>spalette->nentries; i++)
906 if (spalette->depth == 8)
931 #ifdef PNG_WRITE_sBIT_SUPPORTED 936 #ifdef PNG_USE_LOCAL_ARRAYS 950 png_ptr->usr_bit_depth);
951 if (sbit->red == 0 || sbit->red > maxbits ||
952 sbit->green == 0 || sbit->green > maxbits ||
953 sbit->blue == 0 || sbit->blue > maxbits)
955 png_warning(png_ptr,
"Invalid sBIT depth specified");
959 buf[1] = sbit->green;
965 if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
967 png_warning(png_ptr,
"Invalid sBIT depth specified");
976 if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
978 png_warning(png_ptr,
"Invalid sBIT depth specified");
981 buf[size++] = sbit->alpha;
988 #ifdef PNG_WRITE_cHRM_SUPPORTED 990 #ifdef PNG_FLOATING_POINT_SUPPORTED 996 #ifdef PNG_USE_LOCAL_ARRAYS 1006 int_white_x = (
png_uint_32)(white_x * 100000.0 + 0.5);
1007 int_white_y = (
png_uint_32)(white_y * 100000.0 + 0.5);
1008 int_red_x = (
png_uint_32)(red_x * 100000.0 + 0.5);
1009 int_red_y = (
png_uint_32)(red_y * 100000.0 + 0.5);
1010 int_green_x = (
png_uint_32)(green_x * 100000.0 + 0.5);
1011 int_green_y = (
png_uint_32)(green_y * 100000.0 + 0.5);
1012 int_blue_x = (
png_uint_32)(blue_x * 100000.0 + 0.5);
1013 int_blue_y = (
png_uint_32)(blue_y * 100000.0 + 0.5);
1015 #ifdef PNG_CHECK_cHRM_SUPPORTED 1017 int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y))
1038 #ifdef PNG_FIXED_POINT_SUPPORTED 1045 #ifdef PNG_USE_LOCAL_ARRAYS 1053 #ifdef PNG_CHECK_cHRM_SUPPORTED 1055 green_x, green_y, blue_x, blue_y))
1076 #ifdef PNG_WRITE_tRNS_SUPPORTED 1082 #ifdef PNG_USE_LOCAL_ARRAYS 1091 if (num_trans <= 0 || num_trans > (
int)png_ptr->num_palette)
1093 png_warning(png_ptr,
"Invalid number of transparent colors specified");
1103 if (tran->gray >= (1 << png_ptr->bit_depth))
1106 "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
1118 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
1121 "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
1128 png_warning(png_ptr,
"Can't write tRNS with an alpha channel");
1133 #ifdef PNG_WRITE_bKGD_SUPPORTED 1138 #ifdef PNG_USE_LOCAL_ARRAYS 1149 (png_ptr->num_palette ||
1152 back->index >= png_ptr->num_palette)
1154 png_warning(png_ptr,
"Invalid background palette index");
1157 buf[0] = back->index;
1165 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
1168 "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
1175 if (back->gray >= (1 << png_ptr->bit_depth))
1178 "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
1187 #ifdef PNG_WRITE_hIST_SUPPORTED 1192 #ifdef PNG_USE_LOCAL_ARRAYS 1200 if (num_hist > (
int)png_ptr->num_palette)
1202 png_debug2(3,
"num_hist = %d, num_palette = %d", num_hist,
1203 png_ptr->num_palette);
1204 png_warning(png_ptr,
"Invalid number of histogram entries specified");
1210 for (i = 0; i < num_hist; i++)
1219 #ifdef PNG_WRITE_tEXt_SUPPORTED 1225 #ifdef PNG_USE_LOCAL_ARRAYS 1236 if (text ==
NULL || *text ==
'\0')
1260 #ifdef PNG_WRITE_zTXt_SUPPORTED 1266 #ifdef PNG_USE_LOCAL_ARRAYS 1272 compression_state comp;
1276 comp.num_output_ptr = 0;
1277 comp.max_output_ptr = 0;
1278 comp.output_ptr =
NULL;
1298 text_len = png_text_compress(png_ptr, text, text_len, compression,
1313 png_write_compressed_data_out(png_ptr, &comp);
1320 #ifdef PNG_WRITE_iTXt_SUPPORTED 1326 #ifdef PNG_USE_LOCAL_ARRAYS 1329 png_size_t lang_len, key_len, lang_key_len, text_len;
1333 compression_state comp;
1337 comp.num_output_ptr = 0;
1338 comp.max_output_ptr = 0;
1339 comp.output_ptr =
NULL;
1347 png_warning(png_ptr,
"Empty language field in iTXt chunk");
1352 if (lang_key ==
NULL)
1363 text_len = png_text_compress(png_ptr, text, text_len, compression-2,
1401 png_write_compressed_data_out(png_ptr, &comp);
1409 #ifdef PNG_WRITE_oFFs_SUPPORTED 1415 #ifdef PNG_USE_LOCAL_ARRAYS 1423 png_warning(png_ptr,
"Unrecognized unit type for oFFs chunk");
1432 #ifdef PNG_WRITE_pCAL_SUPPORTED 1438 #ifdef PNG_USE_LOCAL_ARRAYS 1441 png_size_t purpose_len, units_len, total_len;
1447 png_debug1(1,
"in png_write_pCAL (%d parameters)", nparams);
1450 png_warning(png_ptr,
"Unrecognized equation type for pCAL chunk");
1453 png_debug1(3,
"pCAL purpose length = %d", (
int)purpose_len);
1454 units_len =
png_strlen(units) + (nparams == 0 ? 0 : 1);
1455 png_debug1(3,
"pCAL units length = %d", (
int)units_len);
1456 total_len = purpose_len + units_len + 10;
1465 params_len[
i] =
png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
1466 png_debug2(3,
"pCAL parameter %d length = %lu", i,
1467 (
unsigned long) params_len[i]);
1471 png_debug1(3,
"pCAL total length = %d", (
int)total_len);
1495 #ifdef PNG_WRITE_sCAL_SUPPORTED 1497 #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) 1501 #ifdef PNG_USE_LOCAL_ARRAYS 1509 buf[0] = (char)unit;
1515 swprintf(wc_buf, TEXT(
"%12.12e"), width);
1516 wc_len = wcslen(wc_buf);
1517 WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len,
NULL,
1519 total_len = wc_len + 2;
1520 swprintf(wc_buf, TEXT(
"%12.12e"), height);
1521 wc_len = wcslen(wc_buf);
1522 WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
1524 total_len += wc_len;
1529 png_snprintf(buf + total_len, 64-total_len,
"%12.12e", height);
1533 png_debug1(3,
"sCAL total length = %u", (
unsigned int)total_len);
1537 #ifdef PNG_FIXED_POINT_SUPPORTED 1542 #ifdef PNG_USE_LOCAL_ARRAYS 1552 total_len = wlen + hlen + 2;
1555 png_warning(png_ptr,
"Can't write sCAL (buffer too small)");
1563 png_debug1(3,
"sCAL total length = %u", (
unsigned int)total_len);
1570 #ifdef PNG_WRITE_pHYs_SUPPORTED 1577 #ifdef PNG_USE_LOCAL_ARRAYS 1585 png_warning(png_ptr,
"Unrecognized unit type for pHYs chunk");
1595 #ifdef PNG_WRITE_tIME_SUPPORTED 1602 #ifdef PNG_USE_LOCAL_ARRAYS 1609 if (mod_time->month > 12 || mod_time->month < 1 ||
1610 mod_time->day > 31 || mod_time->day < 1 ||
1611 mod_time->hour > 23 || mod_time->second > 60)
1613 png_warning(png_ptr,
"Invalid time specified for tIME chunk");
1618 buf[2] = mod_time->month;
1619 buf[3] = mod_time->day;
1620 buf[4] = mod_time->hour;
1621 buf[5] = mod_time->minute;
1622 buf[6] = mod_time->second;
1632 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1633 #ifndef PNG_USE_GLOBAL_ARRAYS 1655 png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1);
1662 #ifdef PNG_WRITE_FILTER_SUPPORTED 1701 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1703 if (png_ptr->interlaced)
1705 if (!(png_ptr->transformations & PNG_INTERLACE))
1707 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
1708 png_pass_ystart[0]) / png_pass_yinc[0];
1709 png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
1710 png_pass_start[0]) / png_pass_inc[0];
1714 png_ptr->num_rows = png_ptr->height;
1715 png_ptr->usr_width = png_ptr->width;
1721 png_ptr->num_rows = png_ptr->height;
1722 png_ptr->usr_width = png_ptr->width;
1724 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
1725 png_ptr->zstream.next_out = png_ptr->zbuf;
1732 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1733 #ifndef PNG_USE_GLOBAL_ARRAYS 1752 png_debug(1,
"in png_write_finish_row");
1755 png_ptr->row_number++;
1758 if (png_ptr->row_number < png_ptr->num_rows)
1761 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1763 if (png_ptr->interlaced)
1765 png_ptr->row_number = 0;
1766 if (png_ptr->transformations & PNG_INTERLACE)
1776 if (png_ptr->pass >= 7)
1778 png_ptr->usr_width = (png_ptr->width +
1779 png_pass_inc[png_ptr->pass] - 1 -
1780 png_pass_start[png_ptr->pass]) /
1781 png_pass_inc[png_ptr->pass];
1782 png_ptr->num_rows = (png_ptr->height +
1783 png_pass_yinc[png_ptr->pass] - 1 -
1784 png_pass_ystart[png_ptr->pass]) /
1785 png_pass_yinc[png_ptr->pass];
1786 if (png_ptr->transformations & PNG_INTERLACE)
1788 }
while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
1793 if (png_ptr->pass < 7)
1795 if (png_ptr->prev_row !=
NULL)
1797 (
png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
1798 png_ptr->usr_bit_depth, png_ptr->width)) + 1);
1814 if (!(png_ptr->zstream.avail_out))
1817 png_ptr->zstream.next_out = png_ptr->zbuf;
1818 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
1823 if (png_ptr->zstream.msg !=
NULL)
1824 png_error(png_ptr, png_ptr->zstream.msg);
1831 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
1834 png_ptr->zstream.avail_out);
1838 png_ptr->zstream.data_type =
Z_BINARY;
1841 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1854 #ifndef PNG_USE_GLOBAL_ARRAYS 1862 png_debug(1,
"in png_do_write_interlace");
1865 #ifdef PNG_USELESS_TESTS_SUPPORTED 1866 if (row !=
NULL && row_info !=
NULL && pass < 6)
1872 switch (row_info->pixel_depth)
1887 for (i = png_pass_start[pass]; i < row_width;
1888 i += png_pass_inc[pass])
1891 value = (
int)(*sp >> (7 - (
int)(i & 0x07))) & 0x01;
1892 d |= (value << shift);
1921 for (i = png_pass_start[pass]; i < row_width;
1922 i += png_pass_inc[pass])
1925 value = (*sp >> ((3 - (
int)(i & 0x03)) << 1)) & 0x03;
1926 d |= (value << shift);
1954 for (i = png_pass_start[pass]; i < row_width;
1955 i += png_pass_inc[pass])
1958 value = (*sp >> ((1 - (
int)(i & 0x01)) << 2)) & 0x0f;
1959 d |= (value << shift);
1985 pixel_bytes = (row_info->pixel_depth >> 3);
1988 for (i = png_pass_start[pass]; i < row_width;
1989 i += png_pass_inc[pass])
2003 row_info->width = (row_info->width +
2004 png_pass_inc[pass] - 1 -
2005 png_pass_start[pass]) /
2007 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
2017 #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1) 2018 #define PNG_HISHIFT 10 2019 #define PNG_LOMASK ((png_uint_32)0xffffL) 2020 #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT)) 2025 #ifdef PNG_WRITE_FILTER_SUPPORTED 2028 png_byte filter_to_do = png_ptr->do_filter;
2031 png_debug(1,
"in png_write_find_filter");
2034 bpp = (row_info->pixel_depth + 7) >> 3;
2036 prev_row = png_ptr->prev_row;
2038 best_row = png_ptr->row_buf;
2039 #ifdef PNG_WRITE_FILTER_SUPPORTED 2076 for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
2079 sum += (v < 128) ? v : 256 - v;
2091 for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
2096 for (lp = row_buf + 1; i < row_bytes;
2097 i++, rp++, lp++, dp++)
2101 best_row = png_ptr->sub_row;
2111 for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
2116 sum += (v < 128) ? v : 256 - v;
2118 for (lp = row_buf + 1; i < row_bytes;
2119 i++, rp++, lp++, dp++)
2121 v = *dp = (
png_byte)(((
int)*rp - (
int)*lp) & 0xff);
2123 sum += (v < 128) ? v : 256 - v;
2132 best_row = png_ptr->sub_row;
2142 for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
2143 pp = prev_row + 1; i < row_bytes;
2144 i++, rp++, pp++, dp++)
2148 best_row = png_ptr->up_row;
2158 for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
2159 pp = prev_row + 1; i < row_bytes; i++)
2161 v = *dp++ = (
png_byte)(((
int)*rp++ - (
int)*pp++) & 0xff);
2163 sum += (v < 128) ? v : 256 - v;
2172 best_row = png_ptr->up_row;
2181 for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
2182 pp = prev_row + 1; i < bpp; i++)
2184 *dp++ = (
png_byte)(((
int)*rp++ - ((
int)*pp++ / 2)) & 0xff);
2186 for (lp = row_buf + 1; i < row_bytes; i++)
2188 *dp++ = (
png_byte)(((
int)*rp++ - (((
int)*pp++ + (
int)*lp++) / 2))
2191 best_row = png_ptr->avg_row;
2201 for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
2202 pp = prev_row + 1; i < bpp; i++)
2204 v = *dp++ = (
png_byte)(((
int)*rp++ - ((
int)*pp++ / 2)) & 0xff);
2206 sum += (v < 128) ? v : 256 - v;
2208 for (lp = row_buf + 1; i < row_bytes; i++)
2211 (
png_byte)(((
int)*rp++ - (((
int)*pp++ + (
int)*lp++) / 2)) & 0xff);
2213 sum += (v < 128) ? v : 256 - v;
2222 best_row = png_ptr->avg_row;
2231 for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
2232 pp = prev_row + 1; i < bpp; i++)
2234 *dp++ = (
png_byte)(((
int)*rp++ - (
int)*pp++) & 0xff);
2237 for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
2239 int a,
b,
c, pa, pb, pc,
p;
2253 pa = p < 0 ? -
p :
p;
2254 pb = pc < 0 ? -pc : pc;
2255 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
2258 p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ?
b :
c;
2260 *dp++ = (
png_byte)(((
int)*rp++ -
p) & 0xff);
2262 best_row = png_ptr->paeth_row;
2272 for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
2273 pp = prev_row + 1; i < bpp; i++)
2275 v = *dp++ = (
png_byte)(((
int)*rp++ - (
int)*pp++) & 0xff);
2277 sum += (v < 128) ? v : 256 - v;
2280 for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
2282 int a,
b,
c, pa, pb, pc,
p;
2288 #ifndef PNG_SLOW_PAETH 2296 pa = p < 0 ? -
p :
p;
2297 pb = pc < 0 ? -pc : pc;
2298 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
2300 p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ?
b :
c;
2306 if (pa <= pb && pa <= pc)
2314 v = *dp++ = (
png_byte)(((
int)*rp++ - p) & 0xff);
2316 sum += (v < 128) ? v : 256 - v;
2324 best_row = png_ptr->paeth_row;
2338 png_debug(1,
"in png_write_filtered_row");
2340 png_debug1(2,
"filter = %d", filtered_row[0]);
2343 png_ptr->zstream.next_in = filtered_row;
2344 png_ptr->zstream.avail_in = (
uInt)png_ptr->row_info.rowbytes + 1;
2355 if (png_ptr->zstream.msg !=
NULL)
2356 png_error(png_ptr, png_ptr->zstream.msg);
2362 if (!(png_ptr->zstream.avail_out))
2366 png_ptr->zstream.next_out = png_ptr->zbuf;
2367 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
2370 }
while (png_ptr->zstream.avail_in);
2373 if (png_ptr->prev_row !=
NULL)
2377 tptr = png_ptr->prev_row;
2378 png_ptr->prev_row = png_ptr->row_buf;
2379 png_ptr->row_buf = tptr;
2385 #ifdef PNG_WRITE_FLUSH_SUPPORTED 2386 png_ptr->flush_rows++;
2388 if (png_ptr->flush_dist > 0 &&
2389 png_ptr->flush_rows >= png_ptr->flush_dist)
void png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
GLenum GLuint GLenum GLsizei length
png_infop png_charpp int png_charpp profile
#define PNG_FILTER_VALUE_AVG
GLint GLint GLsizei GLsizei height
void PNGAPI png_write_chunk(png_structp png_ptr, png_bytep chunk_name, png_bytep data, png_size_t length)
#define PNG_TEXT_COMPRESSION_LAST
PNG_CONST int FARDATA png_pass_start[]
void png_write_start_row(png_structp png_ptr)
void png_zfree(voidpf png_ptr, voidpf ptr)
void png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
GLboolean GLboolean GLboolean GLboolean a
png_infop double double double double double double double double * blue_y
png_infop double double double double double double double * blue_x
void PNGAPI png_save_int_32(png_bytep buf, png_int_32 i)
#define PNG_MAX_PALETTE_LENGTH
png_voidp png_calloc(png_structp png_ptr, png_uint_32 size)
#define PNG_INTERLACE_NONE
png_color_16 FAR * png_color_16p
#define PNG_COLOR_TYPE_RGB
png_infop png_fixed_point png_fixed_point png_fixed_point * int_red_x
#define PNG_COLOR_TYPE_GRAY_ALPHA
void png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
png_infop png_fixed_point png_fixed_point png_fixed_point png_fixed_point png_fixed_point png_fixed_point png_fixed_point png_fixed_point * int_blue_y
#define PNG_INTERLACE_ADAM7
#define PNG_COLOR_TYPE_PALETTE
void png_write_sig(png_structp png_ptr)
PNG_CONST int FARDATA png_pass_yinc[]
png_infop png_charp png_int_32 png_int_32 * X1
#define PNG_FILTER_VALUE_PAETH
#define Z_DEFAULT_COMPRESSION
GLint GLint GLsizei width
#define PNG_MNG_FEATURES_SUPPORTED
#define PNG_COLOR_TYPE_RGB_ALPHA
void png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
void png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, int unit_type)
PNG_CONST int FARDATA png_pass_ystart[]
void png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
GLboolean GLboolean GLboolean b
void png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
void png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, png_charp profile, int profile_len)
png_infop double double double double * red_y
#define PNG_sRGB_INTENT_LAST
GLenum GLuint GLenum GLsizei const GLchar * buf
png_infop png_bytep * trans
png_infop png_fixed_point png_fixed_point png_fixed_point png_fixed_point png_fixed_point * int_green_x
voidpf png_zalloc(voidpf png_ptr, uInt items, uInt size)
png_infop png_charp png_int_32 * X0
void png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text, png_size_t text_len)
void png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, int unit_type)
void png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
GLenum GLenum GLvoid * row
png_infop png_charpp int * compression_type
png_infop png_fixed_point * int_white_x
png_infop png_uint_16p * hist
void png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
#define PNG_TEXT_COMPRESSION_NONE
GLenum GLenum GLenum input
png_struct FAR * png_structp
#define png_error(s1, s2)
void png_write_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)
#define PNG_COLOR_MASK_COLOR
#define PNG_ITXT_COMPRESSION_NONE
void PNGAPI png_write_flush(png_structp png_ptr)
void png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
unsigned short png_uint_16
GLsizei GLsizei GLenum GLenum const GLvoid * data
#define PNG_FILTER_VALUE_SUB
void png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int compression_type, int filter_type, int interlace_type)
void png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran, int num_trans, int color_type)
png_infop png_bytep int * num_trans
#define PNG_COLOR_TYPE_GRAY
void png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
png_sPLT_entry FAR * png_sPLT_entryp
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)
void png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
#define Z_DEFAULT_STRATEGY
void png_write_gAMA(png_structp png_ptr, double file_gamma)
png_uint_16 FAR * png_uint_16p
png_infop png_fixed_point png_fixed_point * int_white_y
#define PNG_EQUATION_LAST
#define PNG_RESOLUTION_LAST
GLsizei const GLfloat * value
#define png_debug1(l, m, p1)
#define PNG_FILTER_VALUE_UP
int ZEXPORT deflate(z_streamp strm, int flush)
void PNGAPI png_save_uint_32(png_bytep buf, png_uint_32 i)
png_infop png_fixed_point png_fixed_point png_fixed_point png_fixed_point * int_red_y
png_infop double * file_gamma
#define PNG_FLAG_MNG_FILTER_64
GLuint const GLchar * name
void PNGAPI png_write_chunk_end(png_structp png_ptr)
png_infop png_sPLT_tpp entries
if(!abbox) return FT_THROW(Invalid_Argument)
#define PNG_FILTER_TYPE_BASE
void png_write_tIME(png_structp png_ptr, png_timep mod_time)
PNG_CONST int FARDATA png_pass_inc[]
GLenum const GLfloat * params
#define PNG_COLOR_MASK_ALPHA
png_infop png_charp * purpose
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
void png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
#define PNG_COMPRESSION_TYPE_BASE
void png_write_sRGB(png_structp png_ptr, int srgb_intent)
png_infop double double double double double double * green_y
png_sPLT_t FAR * png_sPLT_tp
png_infop double double * white_y
void PNGAPI png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
png_infop png_charp png_int_32 png_int_32 int int * nparams
png_color_8 FAR * png_color_8p
png_size_t png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
void png_write_IEND(png_structp png_ptr)
png_int_32 png_fixed_point
png_infop double double double * red_x
char FAR *FAR * png_charpp
void png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
#define PNG_FILTER_VALUE_NONE
png_infop png_int_32 png_int_32 int * unit_type
void PNGAPI png_save_uint_16(png_bytep buf, unsigned int i)
#define PNG_INTRAPIXEL_DIFFERENCING
#define PNG_FLAG_MNG_EMPTY_PLTE
GLfloat GLfloat GLfloat alpha
png_uint_32 FAR * png_uint_32p
int ZEXPORT deflateReset(z_streamp strm)
void png_write_finish_row(png_structp png_ptr)
void PNGAPI png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name, png_uint_32 length)
png_infop double double double double double * green_x
unsigned long png_uint_32
png_row_info FAR * png_row_infop
void png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text, png_size_t text_len, int compression)
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_fixed_point png_fixed_point png_fixed_point png_fixed_point png_fixed_point png_fixed_point * int_green_y
png_infop png_timep * mod_time
void png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
png_infop png_fixed_point png_fixed_point png_fixed_point png_fixed_point png_fixed_point png_fixed_point png_fixed_point * int_blue_x
png_voidp PNGAPI png_malloc(png_structp png_ptr, png_uint_32 size)
void png_reset_crc(png_structp png_ptr)
void png_write_cHRM(png_structp png_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)
png_color FAR * png_colorp