16 #ifdef PNG_WRITE_SUPPORTED 18 #ifdef PNG_WRITE_INT_FUNCTIONS_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);
32 #ifdef PNG_SAVE_INT_32_SUPPORTED 42 buf[0] = (
png_byte)((i >> 24) & 0xff);
43 buf[1] = (
png_byte)((i >> 16) & 0xff);
44 buf[2] = (
png_byte)((i >> 8) & 0xff);
56 buf[0] = (
png_byte)((i >> 8) & 0xff);
70 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
72 #ifdef PNG_IO_STATE_SUPPORTED 81 if (png_ptr->sig_bytes < 3)
116 png_debug2(0,
"Writing %s chunk, length = %lu", chunk_name,
117 (
unsigned long)length);
122 #ifdef PNG_IO_STATE_SUPPORTED 135 png_memcpy(png_ptr->chunk_name, chunk_name, 4);
142 #ifdef PNG_IO_STATE_SUPPORTED 163 if (data != NULL && length > 0)
180 if (png_ptr == NULL)
return;
182 #ifdef PNG_IO_STATE_SUPPORTED 195 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED) 230 return((
int)text_len);
235 #ifdef PNG_CONSOLE_IO_SUPPORTED 237 png_snprintf(msg, 50,
"Unknown compression type %d", compression);
261 png_ptr->zstream.avail_in = (
uInt)text_len;
263 png_ptr->zstream.next_in = (
Bytef *)text;
264 png_ptr->zstream.avail_out = png_ptr->zbuf_size;
265 png_ptr->zstream.next_out = png_ptr->zbuf;
276 if (png_ptr->zstream.msg != NULL)
277 png_error(png_ptr, png_ptr->zstream.msg);
280 png_error(png_ptr,
"zlib error");
284 if (!(png_ptr->zstream.avail_out))
325 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
326 png_ptr->zstream.next_out = png_ptr->zbuf;
329 }
while (png_ptr->zstream.avail_in);
340 if (!(png_ptr->zstream.avail_out))
383 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
384 png_ptr->zstream.next_out = png_ptr->zbuf;
390 if (png_ptr->zstream.msg != NULL)
391 png_error(png_ptr, png_ptr->zstream.msg);
394 png_error(png_ptr,
"zlib error");
401 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
402 text_len += png_ptr->zbuf_size - (
png_size_t)png_ptr->zstream.avail_out;
404 return((
int)text_len);
434 if (png_ptr->zstream.avail_out < (
png_uint_32)png_ptr->zbuf_size)
436 (
png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
440 png_ptr->zstream.data_type =
Z_BINARY;
450 int bit_depth,
int color_type,
int compression_type,
int filter_type,
470 #ifdef PNG_WRITE_16BIT_SUPPORTED 473 png_ptr->channels = 1;
break;
477 "Invalid bit depth for grayscale image");
482 #ifdef PNG_WRITE_16BIT_SUPPORTED 483 if (bit_depth != 8 && bit_depth != 16)
487 png_error(png_ptr,
"Invalid bit depth for RGB image");
489 png_ptr->channels = 3;
499 png_ptr->channels = 1;
503 png_error(png_ptr,
"Invalid bit depth for paletted image");
508 if (bit_depth != 8 && bit_depth != 16)
509 png_error(png_ptr,
"Invalid bit depth for grayscale+alpha image");
511 png_ptr->channels = 2;
515 #ifdef PNG_WRITE_16BIT_SUPPORTED 516 if (bit_depth != 8 && bit_depth != 16)
520 png_error(png_ptr,
"Invalid bit depth for RGBA image");
522 png_ptr->channels = 4;
526 png_error(png_ptr,
"Invalid image color type specified");
531 png_warning(png_ptr,
"Invalid compression type specified");
554 png_warning(png_ptr,
"Invalid filter type specified");
558 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 562 png_warning(png_ptr,
"Invalid interlace type specified");
570 png_ptr->bit_depth = (
png_byte)bit_depth;
571 png_ptr->color_type = (
png_byte)color_type;
572 png_ptr->interlaced = (
png_byte)interlace_type;
573 #ifdef PNG_MNG_FEATURES_SUPPORTED 574 png_ptr->filter_type = (
png_byte)filter_type;
576 png_ptr->compression_type = (
png_byte)compression_type;
577 png_ptr->width = width;
578 png_ptr->height = height;
580 png_ptr->pixel_depth = (
png_byte)(bit_depth * png_ptr->channels);
581 png_ptr->rowbytes =
PNG_ROWBYTES(png_ptr->pixel_depth, width);
583 png_ptr->usr_width = png_ptr->width;
584 png_ptr->usr_bit_depth = png_ptr->bit_depth;
585 png_ptr->usr_channels = png_ptr->channels;
592 buf[10] = (
png_byte)compression_type;
600 png_ptr->zstream.zalloc = png_zalloc;
602 png_ptr->zstream.opaque = (
voidpf)png_ptr;
604 if (!(png_ptr->do_filter))
607 png_ptr->bit_depth < 8)
627 png_ptr->zlib_mem_level = 8;
630 png_ptr->zlib_window_bits = 15;
633 png_ptr->zlib_method = 8;
635 ret =
deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
636 png_ptr->zlib_method, png_ptr->zlib_window_bits,
637 png_ptr->zlib_mem_level, png_ptr->zlib_strategy);
643 "zlib failed to initialize compressor -- version error");
647 "zlib failed to initialize compressor -- stream error");
651 "zlib failed to initialize compressor -- mem error");
653 png_error(png_ptr,
"zlib failed to initialize compressor");
656 png_ptr->zstream.next_out = png_ptr->zbuf;
657 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
661 png_ptr->zstream.data_type =
Z_BINARY;
685 num_pal == 0) || num_pal > 256)
689 png_error(png_ptr,
"Invalid number of colors in palette");
694 png_warning(png_ptr,
"Invalid number of colors in palette");
702 "Ignoring request to write a PLTE chunk in grayscale PNG");
708 png_debug1(3,
"num_palette = %d", png_ptr->num_palette);
711 #ifdef PNG_POINTER_INDEXING_SUPPORTED 713 for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
715 buf[0] = pal_ptr->red;
716 buf[1] = pal_ptr->green;
717 buf[2] = pal_ptr->blue;
727 for (i = 0; i < num_pal; i++)
729 buf[0] = pal_ptr[i].red;
730 buf[1] = pal_ptr[i].green;
731 buf[2] = pal_ptr[i].blue;
753 unsigned int z_cmf = data[0];
754 if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
762 png_ptr->height < 16384 && png_ptr->width < 16384)
764 png_uint_32 uncompressed_idat_size = png_ptr->height *
766 png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
767 unsigned int z_cinfo = z_cmf >> 4;
768 unsigned int half_z_window_size = 1 << (z_cinfo + 7);
769 while (uncompressed_idat_size <= half_z_window_size &&
770 half_z_window_size >= 256)
773 half_z_window_size >>= 1;
776 z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
778 if (data[0] != z_cmf)
782 tmp = data[1] & 0xe0;
783 tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f;
791 "Invalid zlib compression method or flags in IDAT");
810 #ifdef PNG_WRITE_gAMA_SUPPORTED 826 #ifdef PNG_WRITE_sRGB_SUPPORTED 838 "Invalid sRGB rendering intent specified");
845 #ifdef PNG_WRITE_iCCP_SUPPORTED 855 int embedded_profile_len = 0;
869 png_warning(png_ptr,
"Unknown compression type in iCCP chunk");
875 embedded_profile_len =
881 if (embedded_profile_len < 0)
884 "Embedded profile length in iCCP chunk is negative");
890 if (profile_len < embedded_profile_len)
893 "Embedded profile length too large in iCCP chunk");
899 if (profile_len > embedded_profile_len)
902 "Truncating profile to actual length in iCCP chunk");
904 profile_len = embedded_profile_len;
908 profile_len = png_text_compress(png_ptr, profile,
915 new_name[name_len + 1] = 0x00;
921 png_write_compressed_data_out(png_ptr, &comp);
928 #ifdef PNG_WRITE_sPLT_SUPPORTED 937 png_size_t entry_size = (spalette->depth == 8 ? 6 : 10);
938 png_size_t palette_size = entry_size * spalette->nentries;
940 #ifndef PNG_POINTER_INDEXING_SUPPORTED 959 #ifdef PNG_POINTER_INDEXING_SUPPORTED 960 for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++)
962 if (spalette->depth == 8)
983 ep=spalette->entries;
984 for (i = 0; i>spalette->nentries; i++)
986 if (spalette->depth == 8)
989 entrybuf[1] = (
png_byte)ep[i].green;
991 entrybuf[3] = (
png_byte)ep[i].alpha;
1013 #ifdef PNG_WRITE_sBIT_SUPPORTED 1030 png_ptr->usr_bit_depth);
1032 if (sbit->red == 0 || sbit->red > maxbits ||
1033 sbit->green == 0 || sbit->green > maxbits ||
1034 sbit->blue == 0 || sbit->blue > maxbits)
1036 png_warning(png_ptr,
"Invalid sBIT depth specified");
1041 buf[1] = sbit->green;
1042 buf[2] = sbit->blue;
1048 if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
1050 png_warning(png_ptr,
"Invalid sBIT depth specified");
1054 buf[0] = sbit->gray;
1060 if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
1062 png_warning(png_ptr,
"Invalid sBIT depth specified");
1066 buf[size++] = sbit->alpha;
1073 #ifdef PNG_WRITE_cHRM_SUPPORTED 1087 #ifdef PNG_CHECK_cHRM_SUPPORTED 1089 green_x, green_y, blue_x, blue_y))
1109 #ifdef PNG_WRITE_tRNS_SUPPORTED 1122 if (num_trans <= 0 || num_trans > (
int)png_ptr->num_palette)
1124 png_warning(png_ptr,
"Invalid number of transparent colors specified");
1135 if (tran->gray >= (1 << png_ptr->bit_depth))
1138 "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
1153 #ifdef PNG_WRITE_16BIT_SUPPORTED 1154 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
1156 if (buf[0] | buf[2] | buf[4])
1160 "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
1169 png_warning(png_ptr,
"Can't write tRNS with an alpha channel");
1174 #ifdef PNG_WRITE_bKGD_SUPPORTED 1188 (png_ptr->num_palette ||
1191 back->index >= png_ptr->num_palette)
1193 png_warning(png_ptr,
"Invalid background palette index");
1197 buf[0] = back->index;
1206 #ifdef PNG_WRITE_16BIT_SUPPORTED 1207 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
1209 if (buf[0] | buf[2] | buf[4])
1213 "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
1223 if (back->gray >= (1 << png_ptr->bit_depth))
1226 "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
1237 #ifdef PNG_WRITE_hIST_SUPPORTED 1248 if (num_hist > (
int)png_ptr->num_palette)
1250 png_debug2(3,
"num_hist = %d, num_palette = %d", num_hist,
1251 png_ptr->num_palette);
1253 png_warning(png_ptr,
"Invalid number of histogram entries specified");
1259 for (i = 0; i < num_hist; i++)
1269 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ 1270 defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) 1294 if (key == NULL || (key_len =
png_strlen(key)) == 0)
1300 png_debug1(2,
"Keyword to be checked is '%s'", key);
1304 if (*new_key == NULL)
1306 png_warning(png_ptr,
"Out of memory while procesing keyword");
1311 for (ikp = key, dp = *new_key; *ikp !=
'\0'; ikp++, dp++)
1316 #ifdef PNG_CONSOLE_IO_SUPPORTED 1320 "invalid keyword character 0x%02X", (
png_byte)*ikp);
1323 png_warning(png_ptr,
"invalid character in keyword");
1336 kp = *new_key + key_len - 1;
1339 png_warning(png_ptr,
"trailing spaces removed from keyword");
1352 png_warning(png_ptr,
"leading spaces removed from keyword");
1361 png_debug1(2,
"Checking for multiple internal spaces in '%s'", kp);
1364 for (kflag = 0, dp = *new_key; *kp !=
'\0'; kp++)
1366 if (*kp ==
' ' && kflag == 0)
1372 else if (*kp ==
' ')
1386 png_warning(png_ptr,
"extra interior spaces removed from keyword");
1396 png_warning(png_ptr,
"keyword length must be 1 - 79 characters");
1397 (*new_key)[79] =
'\0';
1405 #ifdef PNG_WRITE_tEXt_SUPPORTED 1420 if (text == NULL || *text ==
'\0')
1447 #ifdef PNG_WRITE_zTXt_SUPPORTED 1483 text_len = png_text_compress(png_ptr, text, text_len, compression,
1502 png_write_compressed_data_out(png_ptr, &comp);
1509 #ifdef PNG_WRITE_iTXt_SUPPORTED 1516 png_size_t lang_len, key_len, lang_key_len, text_len;
1534 png_warning(png_ptr,
"Empty language field in iTXt chunk");
1539 if (lang_key == NULL)
1552 text_len = png_text_compress(png_ptr, text, text_len, compression - 2,
1594 png_write_compressed_data_out(png_ptr, &comp);
1603 #ifdef PNG_WRITE_oFFs_SUPPORTED 1615 png_warning(png_ptr,
"Unrecognized unit type for oFFs chunk");
1624 #ifdef PNG_WRITE_pCAL_SUPPORTED 1632 png_size_t purpose_len, units_len, total_len;
1638 png_debug1(1,
"in png_write_pCAL (%d parameters)", nparams);
1641 png_warning(png_ptr,
"Unrecognized equation type for pCAL chunk");
1644 png_debug1(3,
"pCAL purpose length = %d", (
int)purpose_len);
1645 units_len =
png_strlen(units) + (nparams == 0 ? 0 : 1);
1646 png_debug1(3,
"pCAL units length = %d", (
int)units_len);
1647 total_len = purpose_len + units_len + 10;
1655 for (i = 0; i < nparams; i++)
1657 params_len[i] =
png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
1658 png_debug2(3,
"pCAL parameter %d length = %lu", i,
1659 (
unsigned long)params_len[i]);
1663 png_debug1(3,
"pCAL total length = %d", (
int)total_len);
1676 for (i = 0; i < nparams; i++)
1687 #ifdef PNG_WRITE_sCAL_SUPPORTED 1701 total_len = wlen + hlen + 2;
1705 png_warning(png_ptr,
"Can't write sCAL (buffer too small)");
1713 png_debug1(3,
"sCAL total length = %u", (
unsigned int)total_len);
1718 #ifdef PNG_WRITE_pHYs_SUPPORTED 1731 png_warning(png_ptr,
"Unrecognized unit type for pHYs chunk");
1741 #ifdef PNG_WRITE_tIME_SUPPORTED 1753 if (mod_time->month > 12 || mod_time->month < 1 ||
1754 mod_time->day > 31 || mod_time->day < 1 ||
1755 mod_time->hour > 23 || mod_time->second > 60)
1757 png_warning(png_ptr,
"Invalid time specified for tIME chunk");
1762 buf[2] = mod_time->month;
1763 buf[3] = mod_time->day;
1764 buf[4] = mod_time->hour;
1765 buf[5] = mod_time->minute;
1766 buf[6] = mod_time->second;
1776 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1780 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
1783 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
1786 int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
1789 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
1797 png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1);
1800 png_ptr->row_buf = (
png_bytep)png_malloc(png_ptr,
1805 #ifdef PNG_WRITE_FILTER_SUPPORTED 1809 png_ptr->sub_row = (
png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1);
1818 png_ptr->prev_row = (
png_bytep)png_calloc(png_ptr,
1823 png_ptr->up_row = (
png_bytep)png_malloc(png_ptr,
1824 png_ptr->rowbytes + 1);
1831 png_ptr->avg_row = (
png_bytep)png_malloc(png_ptr,
1832 png_ptr->rowbytes + 1);
1839 png_ptr->paeth_row = (
png_bytep)png_malloc(png_ptr,
1840 png_ptr->rowbytes + 1);
1847 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1849 if (png_ptr->interlaced)
1853 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
1854 png_pass_ystart[0]) / png_pass_yinc[0];
1856 png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
1857 png_pass_start[0]) / png_pass_inc[0];
1862 png_ptr->num_rows = png_ptr->height;
1863 png_ptr->usr_width = png_ptr->width;
1870 png_ptr->num_rows = png_ptr->height;
1871 png_ptr->usr_width = png_ptr->width;
1874 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
1875 png_ptr->zstream.next_out = png_ptr->zbuf;
1882 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1886 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
1889 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
1892 int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
1895 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
1900 png_debug(1,
"in png_write_finish_row");
1903 png_ptr->row_number++;
1906 if (png_ptr->row_number < png_ptr->num_rows)
1909 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1911 if (png_ptr->interlaced)
1913 png_ptr->row_number = 0;
1926 if (png_ptr->pass >= 7)
1929 png_ptr->usr_width = (png_ptr->width +
1930 png_pass_inc[png_ptr->pass] - 1 -
1931 png_pass_start[png_ptr->pass]) /
1932 png_pass_inc[png_ptr->pass];
1934 png_ptr->num_rows = (png_ptr->height +
1935 png_pass_yinc[png_ptr->pass] - 1 -
1936 png_pass_ystart[png_ptr->pass]) /
1937 png_pass_yinc[png_ptr->pass];
1942 }
while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
1947 if (png_ptr->pass < 7)
1949 if (png_ptr->prev_row != NULL)
1952 png_ptr->usr_bit_depth, png_ptr->width)) + 1);
1970 if (!(png_ptr->zstream.avail_out))
1973 png_ptr->zstream.next_out = png_ptr->zbuf;
1974 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
1980 if (png_ptr->zstream.msg != NULL)
1981 png_error(png_ptr, png_ptr->zstream.msg);
1984 png_error(png_ptr,
"zlib error");
1989 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
1992 png_ptr->zstream.avail_out);
1996 png_ptr->zstream.data_type =
Z_BINARY;
1999 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 2013 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
2016 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
2018 png_debug(1,
"in png_do_write_interlace");
2024 switch (row_info->pixel_depth)
2040 for (i = png_pass_start[pass]; i < row_width;
2041 i += png_pass_inc[pass])
2044 value = (int)(*sp >> (7 - (
int)(i & 0x07))) & 0x01;
2045 d |= (value << shift);
2078 for (i = png_pass_start[pass]; i < row_width;
2079 i += png_pass_inc[pass])
2082 value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
2083 d |= (value << shift);
2114 for (i = png_pass_start[pass]; i < row_width;
2115 i += png_pass_inc[pass])
2118 value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
2119 d |= (value << shift);
2149 pixel_bytes = (row_info->pixel_depth >> 3);
2152 for (i = png_pass_start[pass]; i < row_width;
2153 i += png_pass_inc[pass])
2169 row_info->width = (row_info->width +
2170 png_pass_inc[pass] - 1 -
2171 png_pass_start[pass]) /
2174 row_info->rowbytes =
PNG_ROWBYTES(row_info->pixel_depth,
2184 #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1) 2185 #define PNG_HISHIFT 10 2186 #define PNG_LOMASK ((png_uint_32)0xffffL) 2187 #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT)) 2192 #ifdef PNG_WRITE_FILTER_SUPPORTED 2195 png_byte filter_to_do = png_ptr->do_filter;
2197 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2198 int num_p_filters = (int)png_ptr->num_prev_filters;
2201 png_debug(1,
"in png_write_find_filter");
2203 #ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2212 bpp = (row_info->pixel_depth + 7) >> 3;
2214 prev_row = png_ptr->prev_row;
2216 best_row = png_ptr->row_buf;
2217 #ifdef PNG_WRITE_FILTER_SUPPORTED 2256 for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
2259 sum += (v < 128) ? v : 256 - v;
2262 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2271 for (j = 0; j < num_p_filters; j++)
2275 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
2278 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
2310 for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
2316 for (lp = row_buf + 1; i < row_bytes;
2317 i++, rp++, lp++, dp++)
2319 *dp = (
png_byte)(((
int)*rp - (int)*lp) & 0xff);
2322 best_row = png_ptr->sub_row;
2332 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2344 for (j = 0; j < num_p_filters; j++)
2348 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
2351 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
2370 for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
2375 sum += (v < 128) ? v : 256 - v;
2378 for (lp = row_buf + 1; i < row_bytes;
2379 i++, rp++, lp++, dp++)
2381 v = *dp = (
png_byte)(((
int)*rp - (int)*lp) & 0xff);
2383 sum += (v < 128) ? v : 256 - v;
2389 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2397 for (j = 0; j < num_p_filters; j++)
2401 sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
2404 sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
2426 best_row = png_ptr->sub_row;
2436 for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
2437 pp = prev_row + 1; i < row_bytes;
2438 i++, rp++, pp++, dp++)
2440 *dp = (
png_byte)(((
int)*rp - (int)*pp) & 0xff);
2443 best_row = png_ptr->up_row;
2454 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2462 for (j = 0; j < num_p_filters; j++)
2466 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
2469 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
2488 for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
2489 pp = prev_row + 1; i < row_bytes; i++)
2491 v = *dp++ = (
png_byte)(((
int)*rp++ - (int)*pp++) & 0xff);
2493 sum += (v < 128) ? v : 256 - v;
2499 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2507 for (j = 0; j < num_p_filters; j++)
2511 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
2514 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
2536 best_row = png_ptr->up_row;
2546 for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
2547 pp = prev_row + 1; i < bpp; i++)
2549 *dp++ = (
png_byte)(((
int)*rp++ - ((int)*pp++ / 2)) & 0xff);
2552 for (lp = row_buf + 1; i < row_bytes; i++)
2554 *dp++ = (
png_byte)(((
int)*rp++ - (((int)*pp++ + (
int)*lp++) / 2))
2557 best_row = png_ptr->avg_row;
2567 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2575 for (j = 0; j < num_p_filters; j++)
2579 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
2582 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
2601 for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
2602 pp = prev_row + 1; i < bpp; i++)
2604 v = *dp++ = (
png_byte)(((
int)*rp++ - ((int)*pp++ / 2)) & 0xff);
2606 sum += (v < 128) ? v : 256 - v;
2609 for (lp = row_buf + 1; i < row_bytes; i++)
2612 (
png_byte)(((
int)*rp++ - (((int)*pp++ + (
int)*lp++) / 2)) & 0xff);
2614 sum += (v < 128) ? v : 256 - v;
2620 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2628 for (j = 0; j < num_p_filters; j++)
2632 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
2635 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
2657 best_row = png_ptr->avg_row;
2667 for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
2668 pp = prev_row + 1; i < bpp; i++)
2670 *dp++ = (
png_byte)(((
int)*rp++ - (int)*pp++) & 0xff);
2673 for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
2675 int a,
b, c, pa, pb, pc, p;
2689 pa = p < 0 ? -p : p;
2690 pb = pc < 0 ? -pc : pc;
2691 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
2694 p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
2696 *dp++ = (
png_byte)(((
int)*rp++ - p) & 0xff);
2698 best_row = png_ptr->paeth_row;
2708 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2716 for (j = 0; j < num_p_filters; j++)
2720 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
2723 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
2742 for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
2743 pp = prev_row + 1; i < bpp; i++)
2745 v = *dp++ = (
png_byte)(((
int)*rp++ - (int)*pp++) & 0xff);
2747 sum += (v < 128) ? v : 256 - v;
2750 for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
2752 int a,
b, c, pa, pb, pc, p;
2758 #ifndef PNG_SLOW_PAETH 2766 pa = p < 0 ? -p : p;
2767 pb = pc < 0 ? -pc : pc;
2768 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
2770 p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
2777 if (pa <= pb && pa <= pc)
2787 v = *dp++ = (
png_byte)(((
int)*rp++ - p) & 0xff);
2789 sum += (v < 128) ? v : 256 - v;
2795 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2803 for (j = 0; j < num_p_filters; j++)
2807 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
2810 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
2831 best_row = png_ptr->paeth_row;
2839 #ifdef PNG_WRITE_FILTER_SUPPORTED 2840 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2842 if (png_ptr->num_prev_filters > 0)
2846 for (j = 1; j < num_p_filters; j++)
2848 png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
2851 png_ptr->prev_filters[j] = best_row[0];
2864 png_debug(1,
"in png_write_filtered_row");
2866 png_debug1(2,
"filter = %d", filtered_row[0]);
2869 png_ptr->zstream.next_in = filtered_row;
2870 png_ptr->zstream.avail_in = 0;
2871 avail = png_ptr->row_info.rowbytes + 1;
2885 if (png_ptr->zstream.avail_in == 0)
2896 png_ptr->zstream.avail_in = (
uInt)avail;
2907 if (png_ptr->zstream.msg != NULL)
2908 png_error(png_ptr, png_ptr->zstream.msg);
2911 png_error(png_ptr,
"zlib error");
2915 if (!(png_ptr->zstream.avail_out))
2919 png_ptr->zstream.next_out = png_ptr->zbuf;
2920 png_ptr->zstream.avail_out = (
uInt)png_ptr->zbuf_size;
2923 }
while (avail > 0 || png_ptr->zstream.avail_in > 0);
2926 if (png_ptr->prev_row != NULL)
2930 tptr = png_ptr->prev_row;
2931 png_ptr->prev_row = png_ptr->row_buf;
2932 png_ptr->row_buf = tptr;
2938 #ifdef PNG_WRITE_FLUSH_SUPPORTED 2939 png_ptr->flush_rows++;
2941 if (png_ptr->flush_dist > 0 &&
2942 png_ptr->flush_rows >= png_ptr->flush_dist)
#define PNG_FILTER_VALUE_AVG
#define PNG_TEXT_COMPRESSION_LAST
void png_write_start_row(png_structp png_ptr)
void png_zfree(voidpf png_ptr, voidpf ptr)
void png_write_sPLT(png_structp png_ptr, png_const_sPLT_tp spalette)
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
void png_write_PLTE(png_structp png_ptr, png_const_colorp palette, png_uint_32 num_pal)
PNG_CONST png_time FAR * png_const_timep
#define PNG_FILTER_HEURISTIC_WEIGHTED
void png_write_sBIT(png_structp png_ptr, png_const_color_8p sbit, int color_type)
void PNGAPI png_save_int_32(png_bytep buf, png_int_32 i)
#define PNG_INTERLACE_NONE
#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
#define PNG_FILTER_VALUE_PAETH
#define PNG_IO_CHUNK_DATA
void png_write_zTXt(png_structp png_ptr, png_const_charp key, png_const_charp text, png_size_t text_len, int compression)
#define PNG_COLOR_TYPE_RGB_ALPHA
PNG_CONST png_color FAR * png_const_colorp
PNG_CONST char FAR * png_const_charp
void png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, int unit_type)
void png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
PNG_CONST png_color_8 FAR * png_const_color_8p
#define PNG_sRGB_INTENT_LAST
#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL
void png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_const_charp units, png_charpp params)
png_size_t png_alloc_size_t
void png_write_data(png_structp png_ptr, png_const_bytep data, png_size_t length)
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)
#define PNG_MNG_FEATURES_SUPPORTED
png_byte FAR *FAR * png_bytepp
unsigned long png_uint_32
#define PNG_TEXT_COMPRESSION_NONE
png_struct FAR * png_structp
void png_write_tIME(png_structp png_ptr, png_const_timep mod_time)
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)
void png_write_tEXt(png_structp png_ptr, png_const_charp key, png_const_charp text, png_size_t text_len)
#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
#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)
#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)
PNG_CONST png_byte FAR * png_const_bytep
#define png_debug1(l, m, p1)
#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS
#define PNG_EQUATION_LAST
#define PNG_RESOLUTION_LAST
PNG_CONST png_color_16 FAR * png_const_color_16p
void png_write_iCCP(png_structp png_ptr, png_const_charp name, int compression_type, png_const_charp profile, int profile_len)
#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)
#define PNG_FLAG_ZLIB_CUSTOM_METHOD
png_size_t png_check_keyword(png_structp png_ptr, png_const_charp key, png_charpp new_key)
#define PNG_FLAG_MNG_FILTER_64
#define PNG_FLAG_ZLIB_CUSTOM_LEVEL
void PNGAPI png_write_chunk_end(png_structp png_ptr)
#define PNG_FILTER_TYPE_BASE
#define PNG_COLOR_MASK_ALPHA
png_row_info FAR * png_row_infop
#define PNG_COMPRESSION_TYPE_BASE
void png_write_sRGB(png_structp png_ptr, int srgb_intent)
void PNGAPI png_write_sig(png_structp png_ptr)
void png_write_tRNS(png_structp png_ptr, png_const_bytep trans_alpha, png_const_color_16p tran, int num_trans, int color_type)
void png_write_IEND(png_structp png_ptr)
void png_write_iTXt(png_structp png_ptr, int compression, png_const_charp key, png_const_charp lang, png_const_charp lang_key, png_const_charp text)
png_int_32 png_fixed_point
char FAR *FAR * png_charpp
#define PNG_FILTER_VALUE_NONE
void png_calculate_crc(png_structp png_ptr, png_const_bytep ptr, png_size_t length)
void PNGAPI png_save_uint_16(png_bytep buf, unsigned int i)
#define PNG_INTRAPIXEL_DIFFERENCING
#define PNG_FLAG_MNG_EMPTY_PLTE
void png_write_hIST(png_structp png_ptr, png_const_uint_16p hist, int num_hist)
void PNGAPI png_write_chunk(png_structp png_ptr, png_const_bytep chunk_name, png_const_bytep data, png_size_t length)
PNG_CONST png_sPLT_t FAR * png_const_sPLT_tp
#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_free(png_structp png_ptr, png_voidp ptr)
#define PNG_ROWBYTES(pixel_bits, width)
#define PNG_HAVE_PNG_SIGNATURE
void PNGAPI png_write_chunk_start(png_structp png_ptr, png_const_bytep chunk_name, png_uint_32 length)
void png_write_sCAL_s(png_structp png_ptr, int unit, png_const_charp width, png_const_charp height)
void png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
PNG_CONST png_uint_16 FAR * png_const_uint_16p
void png_reset_crc(png_structp png_ptr)
#define Z_DEFAULT_COMPRESSION
void PNGAPI png_write_chunk_data(png_structp png_ptr, png_const_bytep data, png_size_t length)
#define png_debug2(l, m, p1, p2)
void png_write_bKGD(png_structp png_ptr, png_const_color_16p back, int color_type)
#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY