13 #ifdef PNG_WRITE_SUPPORTED 22 buf[0] = (
png_byte)((i >> 24) & 0xff);
23 buf[1] = (
png_byte)((i >> 16) & 0xff);
24 buf[2] = (
png_byte)((i >> 8) & 0xff);
35 buf[0] = (
png_byte)((i >> 24) & 0xff);
36 buf[1] = (
png_byte)((i >> 16) & 0xff);
37 buf[2] = (
png_byte)((i >> 8) & 0xff);
48 buf[0] = (
png_byte)((i >> 8) & 0xff);
61 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
66 if (png_ptr->sig_bytes < 3)
67 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
83 if (png_ptr == NULL)
return;
99 png_debug2(0,
"Writing %s chunk, length = %lu\n", chunk_name,
100 (
unsigned long)length);
101 if (png_ptr == NULL)
return;
108 png_memcpy(png_ptr->chunk_name, chunk_name, 4);
123 if (png_ptr == NULL)
return;
124 if (data != NULL && length > 0)
140 if (png_ptr == NULL)
return;
148 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED) 184 return((
int)text_len);
189 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) 191 png_snprintf(msg, 50,
"Unknown compression type %d", compression);
214 png_ptr->zstream.avail_in = (
uInt)text_len;
215 png_ptr->zstream.next_in = (
Bytef *)text;
216 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
217 png_ptr->zstream.next_out = (
Bytef *)png_ptr->zbuf;
227 if (png_ptr->zstream.msg != NULL)
228 png_error(png_ptr, png_ptr->zstream.msg);
233 if (!(png_ptr->zstream.avail_out))
269 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
270 png_ptr->zstream.next_out = png_ptr->zbuf;
273 }
while (png_ptr->zstream.avail_in);
284 if (!(png_ptr->zstream.avail_out))
321 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
322 png_ptr->zstream.next_out = png_ptr->zbuf;
328 if (png_ptr->zstream.msg != NULL)
329 png_error(png_ptr, png_ptr->zstream.msg);
337 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
338 text_len += png_ptr->zbuf_size - (
png_size_t)png_ptr->zstream.avail_out;
340 return((
int)text_len);
369 if (png_ptr->zstream.avail_out < (
png_uint_32)png_ptr->zbuf_size)
371 (
png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
375 png_ptr->zstream.data_type =
Z_BINARY;
388 #ifdef PNG_USE_LOCAL_ARRAYS 406 case 16: png_ptr->channels = 1;
break;
407 default:
png_error(png_ptr,
"Invalid bit depth for grayscale image");
411 if (bit_depth != 8 && bit_depth != 16)
412 png_error(png_ptr,
"Invalid bit depth for RGB image");
413 png_ptr->channels = 3;
421 case 8: png_ptr->channels = 1;
break;
422 default:
png_error(png_ptr,
"Invalid bit depth for paletted image");
426 if (bit_depth != 8 && bit_depth != 16)
427 png_error(png_ptr,
"Invalid bit depth for grayscale+alpha image");
428 png_ptr->channels = 2;
431 if (bit_depth != 8 && bit_depth != 16)
432 png_error(png_ptr,
"Invalid bit depth for RGBA image");
433 png_ptr->channels = 4;
436 png_error(png_ptr,
"Invalid image color type specified");
441 png_warning(png_ptr,
"Invalid compression type specified");
457 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
464 png_warning(png_ptr,
"Invalid filter type specified");
468 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 472 png_warning(png_ptr,
"Invalid interlace type specified");
480 png_ptr->bit_depth = (
png_byte)bit_depth;
481 png_ptr->color_type = (
png_byte)color_type;
482 png_ptr->interlaced = (
png_byte)interlace_type;
483 #if defined(PNG_MNG_FEATURES_SUPPORTED) 484 png_ptr->filter_type = (
png_byte)filter_type;
486 png_ptr->compression_type = (
png_byte)compression_type;
487 png_ptr->width =
width;
490 png_ptr->pixel_depth = (
png_byte)(bit_depth * png_ptr->channels);
491 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
493 png_ptr->usr_width = png_ptr->width;
494 png_ptr->usr_bit_depth = png_ptr->bit_depth;
495 png_ptr->usr_channels = png_ptr->channels;
502 buf[10] = (
png_byte)compression_type;
512 png_ptr->zstream.opaque = (
voidpf)png_ptr;
513 if (!(png_ptr->do_filter))
516 png_ptr->bit_depth < 8)
521 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
528 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
530 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
531 png_ptr->zlib_mem_level = 8;
532 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
533 png_ptr->zlib_window_bits = 15;
534 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
535 png_ptr->zlib_method = 8;
536 ret =
deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
537 png_ptr->zlib_method, png_ptr->zlib_window_bits,
538 png_ptr->zlib_mem_level, png_ptr->zlib_strategy);
542 "zlib failed to initialize compressor -- version error");
544 "zlib failed to initialize compressor -- stream error");
546 "zlib failed to initialize compressor -- mem error");
547 png_error(png_ptr,
"zlib failed to initialize compressor");
549 png_ptr->zstream.next_out = png_ptr->zbuf;
550 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
553 png_ptr->zstream.data_type =
Z_BINARY;
565 #ifdef PNG_USE_LOCAL_ARRAYS 577 num_pal == 0) || num_pal > 256)
581 png_error(png_ptr,
"Invalid number of colors in palette");
585 png_warning(png_ptr,
"Invalid number of colors in palette");
593 "Ignoring request to write a PLTE chunk in grayscale PNG");
598 png_debug1(3,
"num_palette = %d\n", png_ptr->num_palette);
602 #ifndef PNG_NO_POINTER_INDEXING 603 for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
605 buf[0] = pal_ptr->red;
606 buf[1] = pal_ptr->green;
607 buf[2] = pal_ptr->blue;
613 for (i = 0; i < num_pal; i++)
615 buf[0] = pal_ptr[
i].red;
616 buf[1] = pal_ptr[
i].green;
617 buf[2] = pal_ptr[
i].blue;
629 #ifdef PNG_USE_LOCAL_ARRAYS 639 unsigned int z_cmf = data[0];
640 if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
646 png_ptr->height < 16384 && png_ptr->width < 16384)
648 png_uint_32 uncompressed_idat_size = png_ptr->height *
650 png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
651 unsigned int z_cinfo = z_cmf >> 4;
652 unsigned int half_z_window_size = 1 << (z_cinfo + 7);
653 while (uncompressed_idat_size <= half_z_window_size &&
654 half_z_window_size >= 256)
657 half_z_window_size >>= 1;
659 z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
664 data[1] += (
png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
670 "Invalid zlib compression method or flags in IDAT");
681 #ifdef PNG_USE_LOCAL_ARRAYS 690 #if defined(PNG_WRITE_gAMA_SUPPORTED) 692 #ifdef PNG_FLOATING_POINT_SUPPORTED 696 #ifdef PNG_USE_LOCAL_ARRAYS 704 igamma = (
png_uint_32)(file_gamma * 100000.0 + 0.5);
709 #ifdef PNG_FIXED_POINT_SUPPORTED 713 #ifdef PNG_USE_LOCAL_ARRAYS 726 #if defined(PNG_WRITE_sRGB_SUPPORTED) 731 #ifdef PNG_USE_LOCAL_ARRAYS 739 "Invalid sRGB rendering intent specified");
745 #if defined(PNG_WRITE_iCCP_SUPPORTED) 751 #ifdef PNG_USE_LOCAL_ARRAYS 757 int embedded_profile_len = 0;
770 png_warning(png_ptr,
"Empty keyword in iCCP chunk");
775 png_warning(png_ptr,
"Unknown compression type in iCCP chunk");
781 embedded_profile_len =
787 if (profile_len < embedded_profile_len)
790 "Embedded profile length too large in iCCP chunk");
794 if (profile_len > embedded_profile_len)
797 "Truncating profile to actual length in iCCP chunk");
798 profile_len = embedded_profile_len;
808 new_name[name_len + 1] = 0x00;
820 #if defined(PNG_WRITE_sPLT_SUPPORTED) 825 #ifdef PNG_USE_LOCAL_ARRAYS 831 int entry_size = (spalette->depth == 8 ? 6 : 10);
832 int palette_size = entry_size * spalette->nentries;
834 #ifdef PNG_NO_POINTER_INDEXING 840 spalette->name, &new_name))==0)
842 png_warning(png_ptr,
"Empty keyword in sPLT chunk");
854 #ifndef PNG_NO_POINTER_INDEXING 855 for (ep = spalette->entries; ep<spalette->
entries + spalette->nentries; ep++)
857 if (spalette->depth == 8)
876 ep=spalette->entries;
877 for (i=0; i>spalette->nentries; i++)
879 if (spalette->depth == 8)
884 entrybuf[3] = (
png_byte)ep[i].alpha;
904 #if defined(PNG_WRITE_sBIT_SUPPORTED) 909 #ifdef PNG_USE_LOCAL_ARRAYS 922 png_ptr->usr_bit_depth);
923 if (sbit->red == 0 || sbit->red > maxbits ||
924 sbit->green == 0 || sbit->green > maxbits ||
925 sbit->blue == 0 || sbit->blue > maxbits)
927 png_warning(png_ptr,
"Invalid sBIT depth specified");
931 buf[1] = sbit->green;
937 if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
939 png_warning(png_ptr,
"Invalid sBIT depth specified");
948 if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
950 png_warning(png_ptr,
"Invalid sBIT depth specified");
953 buf[size++] = sbit->alpha;
960 #if defined(PNG_WRITE_cHRM_SUPPORTED) 962 #ifdef PNG_FLOATING_POINT_SUPPORTED 968 #ifdef PNG_USE_LOCAL_ARRAYS 976 if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
977 white_x + white_y > 1.0)
979 png_warning(png_ptr,
"Invalid cHRM white point specified");
980 #if !defined(PNG_NO_CONSOLE_IO) 981 fprintf(stderr,
"white_x=%f, white_y=%f\n", white_x, white_y);
990 if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
992 png_warning(png_ptr,
"Invalid cHRM red point specified");
1000 if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
1002 png_warning(png_ptr,
"Invalid cHRM green point specified");
1010 if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
1012 png_warning(png_ptr,
"Invalid cHRM blue point specified");
1023 #ifdef PNG_FIXED_POINT_SUPPORTED 1030 #ifdef PNG_USE_LOCAL_ARRAYS 1037 if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
1039 png_warning(png_ptr,
"Invalid fixed cHRM white point specified");
1040 #if !defined(PNG_NO_CONSOLE_IO) 1041 fprintf(stderr,
"white_x=%ld, white_y=%ld\n", (
unsigned long)white_x,
1042 (
unsigned long)white_y);
1049 if (red_x + red_y > 100000L)
1051 png_warning(png_ptr,
"Invalid cHRM fixed red point specified");
1057 if (green_x + green_y > 100000L)
1059 png_warning(png_ptr,
"Invalid fixed cHRM green point specified");
1065 if (blue_x + blue_y > 100000L)
1067 png_warning(png_ptr,
"Invalid fixed cHRM blue point specified");
1078 #if defined(PNG_WRITE_tRNS_SUPPORTED) 1084 #ifdef PNG_USE_LOCAL_ARRAYS 1092 if (num_trans <= 0 || num_trans > (
int)png_ptr->num_palette)
1094 png_warning(png_ptr,
"Invalid number of transparent colors specified");
1104 if (tran->gray >= (1 << png_ptr->bit_depth))
1107 "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
1119 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
1122 "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
1129 png_warning(png_ptr,
"Can't write tRNS with an alpha channel");
1134 #if defined(PNG_WRITE_bKGD_SUPPORTED) 1139 #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 #if defined(PNG_WRITE_hIST_SUPPORTED) 1192 #ifdef PNG_USE_LOCAL_ARRAYS 1199 if (num_hist > (
int)png_ptr->num_palette)
1201 png_debug2(3,
"num_hist = %d, num_palette = %d\n", num_hist,
1202 png_ptr->num_palette);
1203 png_warning(png_ptr,
"Invalid number of histogram entries specified");
1209 for (i = 0; i < num_hist; i++)
1218 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ 1219 defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) 1241 if (key == NULL || (key_len =
png_strlen(key)) == 0)
1247 png_debug1(2,
"Keyword to be checked is '%s'\n", key);
1250 if (*new_key == NULL)
1252 png_warning(png_ptr,
"Out of memory while procesing keyword");
1257 for (kp = key, dp = *new_key; *kp !=
'\0'; kp++, dp++)
1262 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) 1266 "invalid keyword character 0x%02X", (
png_byte)*kp);
1269 png_warning(png_ptr,
"invalid character in keyword");
1281 kp = *new_key + key_len - 1;
1284 png_warning(png_ptr,
"trailing spaces removed from keyword");
1297 png_warning(png_ptr,
"leading spaces removed from keyword");
1306 png_debug1(2,
"Checking for multiple internal spaces in '%s'\n", kp);
1309 for (kflag = 0, dp = *new_key; *kp !=
'\0'; kp++)
1311 if (*kp ==
' ' && kflag == 0)
1316 else if (*kp ==
' ')
1329 png_warning(png_ptr,
"extra interior spaces removed from keyword");
1340 png_warning(png_ptr,
"keyword length must be 1 - 79 characters");
1349 #if defined(PNG_WRITE_tEXt_SUPPORTED) 1355 #ifdef PNG_USE_LOCAL_ARRAYS 1364 png_warning(png_ptr,
"Empty keyword in tEXt chunk");
1368 if (text == NULL || *text ==
'\0')
1392 #if defined(PNG_WRITE_zTXt_SUPPORTED) 1398 #ifdef PNG_USE_LOCAL_ARRAYS 1416 png_warning(png_ptr,
"Empty keyword in zTXt chunk");
1453 #if defined(PNG_WRITE_iTXt_SUPPORTED) 1459 #ifdef PNG_USE_LOCAL_ARRAYS 1462 png_size_t lang_len, key_len, lang_key_len, text_len;
1476 png_warning(png_ptr,
"Empty keyword in iTXt chunk");
1479 if (lang == NULL || (lang_len =
png_check_keyword(png_ptr, lang, &new_lang))==0)
1481 png_warning(png_ptr,
"Empty language field in iTXt chunk");
1486 if (lang_key == NULL)
1544 #if defined(PNG_WRITE_oFFs_SUPPORTED) 1550 #ifdef PNG_USE_LOCAL_ARRAYS 1557 png_warning(png_ptr,
"Unrecognized unit type for oFFs chunk");
1566 #if defined(PNG_WRITE_pCAL_SUPPORTED) 1572 #ifdef PNG_USE_LOCAL_ARRAYS 1575 png_size_t purpose_len, units_len, total_len;
1581 png_debug1(1,
"in png_write_pCAL (%d parameters)\n", nparams);
1583 png_warning(png_ptr,
"Unrecognized equation type for pCAL chunk");
1586 png_debug1(3,
"pCAL purpose length = %d\n", (
int)purpose_len);
1587 units_len =
png_strlen(units) + (nparams == 0 ? 0 : 1);
1588 png_debug1(3,
"pCAL units length = %d\n", (
int)units_len);
1589 total_len = purpose_len + units_len + 10;
1598 params_len[
i] =
png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
1599 png_debug2(3,
"pCAL parameter %d length = %lu\n", i,
1600 (
unsigned long) params_len[i]);
1604 png_debug1(3,
"pCAL total length = %d\n", (
int)total_len);
1628 #if defined(PNG_WRITE_sCAL_SUPPORTED) 1630 #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) 1634 #ifdef PNG_USE_LOCAL_ARRAYS 1642 buf[0] = (char)unit;
1643 #if defined(_WIN32_WCE) 1648 swprintf(wc_buf, TEXT(
"%12.12e"), width);
1649 wc_len = wcslen(wc_buf);
1650 WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
1651 total_len = wc_len + 2;
1652 swprintf(wc_buf, TEXT(
"%12.12e"), height);
1653 wc_len = wcslen(wc_buf);
1654 WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
1656 total_len += wc_len;
1661 png_snprintf(buf + total_len, 64-total_len,
"%12.12e", height);
1665 png_debug1(3,
"sCAL total length = %u\n", (
unsigned int)total_len);
1669 #ifdef PNG_FIXED_POINT_SUPPORTED 1674 #ifdef PNG_USE_LOCAL_ARRAYS 1684 total_len = wlen + hlen + 2;
1687 png_warning(png_ptr,
"Can't write sCAL (buffer too small)");
1695 png_debug1(3,
"sCAL total length = %u\n", (
unsigned int)total_len);
1702 #if defined(PNG_WRITE_pHYs_SUPPORTED) 1709 #ifdef PNG_USE_LOCAL_ARRAYS 1716 png_warning(png_ptr,
"Unrecognized unit type for pHYs chunk");
1726 #if defined(PNG_WRITE_tIME_SUPPORTED) 1733 #ifdef PNG_USE_LOCAL_ARRAYS 1739 if (mod_time->month > 12 || mod_time->month < 1 ||
1740 mod_time->day > 31 || mod_time->day < 1 ||
1741 mod_time->hour > 23 || mod_time->second > 60)
1743 png_warning(png_ptr,
"Invalid time specified for tIME chunk");
1748 buf[2] = mod_time->month;
1749 buf[3] = mod_time->day;
1750 buf[4] = mod_time->hour;
1751 buf[5] = mod_time->minute;
1752 buf[6] = mod_time->second;
1762 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1763 #ifdef PNG_USE_LOCAL_ARRAYS 1782 png_debug(1,
"in png_write_start_row\n");
1784 png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1);
1791 #ifndef PNG_NO_WRITE_FILTER 1831 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1833 if (png_ptr->interlaced)
1835 if (!(png_ptr->transformations & PNG_INTERLACE))
1837 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
1838 png_pass_ystart[0]) / png_pass_yinc[0];
1839 png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
1840 png_pass_start[0]) / png_pass_inc[0];
1844 png_ptr->num_rows = png_ptr->height;
1845 png_ptr->usr_width = png_ptr->width;
1851 png_ptr->num_rows = png_ptr->height;
1852 png_ptr->usr_width = png_ptr->width;
1854 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
1855 png_ptr->zstream.next_out = png_ptr->zbuf;
1862 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1863 #ifdef PNG_USE_LOCAL_ARRAYS 1882 png_debug(1,
"in png_write_finish_row\n");
1884 png_ptr->row_number++;
1887 if (png_ptr->row_number < png_ptr->num_rows)
1890 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1892 if (png_ptr->interlaced)
1894 png_ptr->row_number = 0;
1895 if (png_ptr->transformations & PNG_INTERLACE)
1905 if (png_ptr->pass >= 7)
1907 png_ptr->usr_width = (png_ptr->width +
1908 png_pass_inc[png_ptr->pass] - 1 -
1909 png_pass_start[png_ptr->pass]) /
1910 png_pass_inc[png_ptr->pass];
1911 png_ptr->num_rows = (png_ptr->height +
1912 png_pass_yinc[png_ptr->pass] - 1 -
1913 png_pass_ystart[png_ptr->pass]) /
1914 png_pass_yinc[png_ptr->pass];
1915 if (png_ptr->transformations & PNG_INTERLACE)
1917 }
while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
1922 if (png_ptr->pass < 7)
1924 if (png_ptr->prev_row != NULL)
1926 (
png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
1927 png_ptr->usr_bit_depth, png_ptr->width)) + 1);
1943 if (!(png_ptr->zstream.avail_out))
1946 png_ptr->zstream.next_out = png_ptr->zbuf;
1947 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
1952 if (png_ptr->zstream.msg != NULL)
1953 png_error(png_ptr, png_ptr->zstream.msg);
1960 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
1963 png_ptr->zstream.avail_out);
1967 png_ptr->zstream.data_type =
Z_BINARY;
1970 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 1981 #ifdef PNG_USE_LOCAL_ARRAYS 1991 png_debug(1,
"in png_do_write_interlace\n");
1993 #if defined(PNG_USELESS_TESTS_SUPPORTED) 1994 if (row != NULL && row_info != NULL && pass < 6)
2000 switch (row_info->pixel_depth)
2015 for (i = png_pass_start[pass]; i < row_width;
2016 i += png_pass_inc[pass])
2019 value = (
int)(*sp >> (7 - (
int)(i & 0x07))) & 0x01;
2020 d |= (value << shift);
2049 for (i = png_pass_start[pass]; i < row_width;
2050 i += png_pass_inc[pass])
2053 value = (*sp >> ((3 - (
int)(i & 0x03)) << 1)) & 0x03;
2054 d |= (value << shift);
2082 for (i = png_pass_start[pass]; i < row_width;
2083 i += png_pass_inc[pass])
2086 value = (*sp >> ((1 - (
int)(i & 0x01)) << 2)) & 0x0f;
2087 d |= (value << shift);
2113 pixel_bytes = (row_info->pixel_depth >> 3);
2116 for (i = png_pass_start[pass]; i < row_width;
2117 i += png_pass_inc[pass])
2131 row_info->width = (row_info->width +
2132 png_pass_inc[pass] - 1 -
2133 png_pass_start[pass]) /
2135 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
2145 #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1) 2146 #define PNG_HISHIFT 10 2147 #define PNG_LOMASK ((png_uint_32)0xffffL) 2148 #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT)) 2153 #ifndef PNG_NO_WRITE_FILTER 2156 png_byte filter_to_do = png_ptr->do_filter;
2158 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 2159 int num_p_filters = (
int)png_ptr->num_prev_filters;
2162 png_debug(1,
"in png_write_find_filter\n");
2164 bpp = (row_info->pixel_depth + 7) >> 3;
2166 prev_row = png_ptr->prev_row;
2168 best_row = png_ptr->row_buf;
2169 #ifndef PNG_NO_WRITE_FILTER 2206 for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
2209 sum += (v < 128) ? v : 256 - v;
2212 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 2221 for (j = 0; j < num_p_filters; j++)
2225 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
2227 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
2256 for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
2261 for (lp = row_buf + 1; i < row_bytes;
2262 i++, rp++, lp++, dp++)
2266 best_row = png_ptr->sub_row;
2276 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 2288 for (j = 0; j < num_p_filters; j++)
2292 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
2294 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
2311 for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
2316 sum += (v < 128) ? v : 256 - v;
2318 for (lp = row_buf + 1; i < row_bytes;
2319 i++, rp++, lp++, dp++)
2321 v = *dp = (
png_byte)(((
int)*rp - (
int)*lp) & 0xff);
2323 sum += (v < 128) ? v : 256 - v;
2329 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 2337 for (j = 0; j < num_p_filters; j++)
2341 sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
2343 sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
2363 best_row = png_ptr->sub_row;
2373 for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
2374 pp = prev_row + 1; i < row_bytes;
2375 i++, rp++, pp++, dp++)
2379 best_row = png_ptr->up_row;
2390 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 2398 for (j = 0; j < num_p_filters; j++)
2402 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
2404 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
2421 for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
2422 pp = prev_row + 1; i < row_bytes; i++)
2424 v = *dp++ = (
png_byte)(((
int)*rp++ - (
int)*pp++) & 0xff);
2426 sum += (v < 128) ? v : 256 - v;
2432 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 2440 for (j = 0; j < num_p_filters; j++)
2444 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
2446 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
2466 best_row = png_ptr->up_row;
2475 for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
2476 pp = prev_row + 1; i < bpp; i++)
2478 *dp++ = (
png_byte)(((
int)*rp++ - ((
int)*pp++ / 2)) & 0xff);
2480 for (lp = row_buf + 1; i < row_bytes; i++)
2482 *dp++ = (
png_byte)(((
int)*rp++ - (((
int)*pp++ + (
int)*lp++) / 2))
2485 best_row = png_ptr->avg_row;
2495 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 2503 for (j = 0; j < num_p_filters; j++)
2507 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
2509 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
2526 for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
2527 pp = prev_row + 1; i < bpp; i++)
2529 v = *dp++ = (
png_byte)(((
int)*rp++ - ((
int)*pp++ / 2)) & 0xff);
2531 sum += (v < 128) ? v : 256 - v;
2533 for (lp = row_buf + 1; i < row_bytes; i++)
2536 (
png_byte)(((
int)*rp++ - (((
int)*pp++ + (
int)*lp++) / 2)) & 0xff);
2538 sum += (v < 128) ? v : 256 - v;
2544 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 2552 for (j = 0; j < num_p_filters; j++)
2556 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
2558 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
2578 best_row = png_ptr->avg_row;
2587 for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
2588 pp = prev_row + 1; i < bpp; i++)
2590 *dp++ = (
png_byte)(((
int)*rp++ - (
int)*pp++) & 0xff);
2593 for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
2595 int a,
b,
c, pa, pb, pc, p;
2609 pa = p < 0 ? -p : p;
2610 pb = pc < 0 ? -pc : pc;
2611 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
2614 p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b :
c;
2616 *dp++ = (
png_byte)(((
int)*rp++ - p) & 0xff);
2618 best_row = png_ptr->paeth_row;
2628 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 2636 for (j = 0; j < num_p_filters; j++)
2640 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
2642 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
2659 for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
2660 pp = prev_row + 1; i < bpp; i++)
2662 v = *dp++ = (
png_byte)(((
int)*rp++ - (
int)*pp++) & 0xff);
2664 sum += (v < 128) ? v : 256 - v;
2667 for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
2669 int a,
b,
c, pa, pb, pc, p;
2675 #ifndef PNG_SLOW_PAETH 2683 pa = p < 0 ? -p : p;
2684 pb = pc < 0 ? -pc : pc;
2685 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
2687 p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b :
c;
2693 if (pa <= pb && pa <= pc)
2701 v = *dp++ = (
png_byte)(((
int)*rp++ - p) & 0xff);
2703 sum += (v < 128) ? v : 256 - v;
2709 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 2717 for (j = 0; j < num_p_filters; j++)
2721 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
2723 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
2742 best_row = png_ptr->paeth_row;
2750 #ifndef PNG_NO_WRITE_FILTER 2751 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 2753 if (png_ptr->num_prev_filters > 0)
2756 for (j = 1; j < num_p_filters; j++)
2758 png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
2760 png_ptr->prev_filters[j] = best_row[0];
2771 png_debug(1,
"in png_write_filtered_row\n");
2772 png_debug1(2,
"filter = %d\n", filtered_row[0]);
2775 png_ptr->zstream.next_in = filtered_row;
2776 png_ptr->zstream.avail_in = (
uInt)png_ptr->row_info.rowbytes + 1;
2787 if (png_ptr->zstream.msg != NULL)
2788 png_error(png_ptr, png_ptr->zstream.msg);
2794 if (!(png_ptr->zstream.avail_out))
2798 png_ptr->zstream.next_out = png_ptr->zbuf;
2799 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
2802 }
while (png_ptr->zstream.avail_in);
2805 if (png_ptr->prev_row != NULL)
2809 tptr = png_ptr->prev_row;
2810 png_ptr->prev_row = png_ptr->row_buf;
2811 png_ptr->row_buf = tptr;
2817 #if defined(PNG_WRITE_FLUSH_SUPPORTED) 2818 png_ptr->flush_rows++;
2820 if (png_ptr->flush_dist > 0 &&
2821 png_ptr->flush_rows >= png_ptr->flush_dist)
void png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
png_infop png_charpp int png_charpp profile
#define PNG_FILTER_VALUE_AVG
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_infop png_charp png_int_32 png_int_32 int int png_charp * units
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)
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
png_infop png_charp png_int_32 png_int_32 int * type
#define PNG_FILTER_HEURISTIC_WEIGHTED
png_infop double double double double double double double double * blue_y
static int png_text_compress(png_structp png_ptr, png_charp text, png_size_t text_len, int compression, compression_state *comp)
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_INTERLACE_NONE
png_color_16 FAR * png_color_16p
#define PNG_COLOR_TYPE_RGB
#define PNG_COLOR_TYPE_GRAY_ALPHA
void png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
#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
png_infop png_charpp name
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
png_infop png_charp png_int_32 png_int_32 int int png_charp png_charpp * params
#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)
void png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
png_bytep png_bytep 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
png_infop png_bytep * trans
voidpf png_zalloc(voidpf png_ptr, uInt items, uInt size)
png_infop png_charp png_int_32 * X0
png_infop png_uint_32 * width
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)
png_infop png_charpp int * compression_type
png_infop png_uint_16p * hist
void png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
#define PNG_TEXT_COMPRESSION_NONE
png_struct FAR * png_structp
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_error(png_structp png_ptr, png_const_charp error_message)
png_infop png_uint_32 png_uint_32 * height
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
#define PNG_FILTER_VALUE_SUB
def j(str, encoding="cp932")
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)
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)
void png_write_gAMA(png_structp png_ptr, double file_gamma)
png_uint_16 FAR * png_uint_16p
#define PNG_EQUATION_LAST
#define PNG_RESOLUTION_LAST
#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_uint_32 png_uint_32 int * bit_depth
png_infop double * file_gamma
#define PNG_FLAG_MNG_FILTER_64
fMat tran(const fMat &mat)
static void png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
void PNGAPI png_write_chunk_end(png_structp png_ptr)
png_infop png_sPLT_tpp entries
#define PNG_FILTER_TYPE_BASE
void png_write_tIME(png_structp png_ptr, png_timep mod_time)
PNG_CONST int FARDATA png_pass_inc[]
#define PNG_COLOR_MASK_ALPHA
png_infop png_charp * purpose
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 png_uint_32 png_uint_32 int int * color_type
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
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
#define Z_DEFAULT_STRATEGY
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_size_t png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
png_infop double * white_x
png_infop png_timep * mod_time
void png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
png_voidp PNGAPI png_malloc(png_structp png_ptr, png_uint_32 size)
void png_reset_crc(png_structp png_ptr)
png_voidp PNGAPI png_malloc_warn(png_structp png_ptr, png_uint_32 size)
#define Z_DEFAULT_COMPRESSION
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