Lines Matching refs:png_ptr
63 png_write_sig(png_structp png_ptr) in png_write_sig() argument
68 png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes], in png_write_sig()
69 (png_size_t)(8 - png_ptr->sig_bytes)); in png_write_sig()
70 if (png_ptr->sig_bytes < 3) in png_write_sig()
71 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; in png_write_sig()
84 png_write_chunk(png_structp png_ptr, png_bytep chunk_name, in png_write_chunk() argument
87 if (png_ptr == NULL) in png_write_chunk()
89 png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length); in png_write_chunk()
90 png_write_chunk_data(png_ptr, data, (png_size_t)length); in png_write_chunk()
91 png_write_chunk_end(png_ptr); in png_write_chunk()
99 png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name, in png_write_chunk_start() argument
107 if (png_ptr == NULL) in png_write_chunk_start()
114 png_write_data(png_ptr, buf, (png_size_t)8); in png_write_chunk_start()
116 png_memcpy(png_ptr->chunk_name, chunk_name, 4); in png_write_chunk_start()
118 png_reset_crc(png_ptr); in png_write_chunk_start()
119 png_calculate_crc(png_ptr, chunk_name, (png_size_t)4); in png_write_chunk_start()
128 png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length) in png_write_chunk_data() argument
131 if (png_ptr == NULL) in png_write_chunk_data()
135 png_write_data(png_ptr, data, length); in png_write_chunk_data()
139 png_calculate_crc(png_ptr, data, length); in png_write_chunk_data()
145 png_write_chunk_end(png_structp png_ptr) in png_write_chunk_end() argument
149 if (png_ptr == NULL) return; in png_write_chunk_end()
152 png_save_uint_32(buf, png_ptr->crc); in png_write_chunk_end()
154 png_write_data(png_ptr, buf, (png_size_t)4); in png_write_chunk_end()
175 png_text_compress(png_structp png_ptr, in png_text_compress() argument
200 png_warning(png_ptr, msg); in png_text_compress()
202 png_warning(png_ptr, "Unknown compression type"); in png_text_compress()
222 png_ptr->zstream.avail_in = (uInt)text_len; in png_text_compress()
223 png_ptr->zstream.next_in = (Bytef *)text; in png_text_compress()
224 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; in png_text_compress()
225 png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf; in png_text_compress()
231 ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); in png_text_compress()
235 if (png_ptr->zstream.msg != NULL) in png_text_compress()
236 png_error(png_ptr, png_ptr->zstream.msg); in png_text_compress()
238 png_error(png_ptr, "zlib error"); in png_text_compress()
241 if (!(png_ptr->zstream.avail_out)) in png_text_compress()
255 comp->output_ptr = (png_charpp)png_malloc(png_ptr, in png_text_compress()
260 png_free(png_ptr, old_ptr); in png_text_compress()
263 comp->output_ptr = (png_charpp)png_malloc(png_ptr, in png_text_compress()
270 (png_charp)png_malloc(png_ptr, in png_text_compress()
271 (png_uint_32)png_ptr->zbuf_size); in png_text_compress()
272 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, in png_text_compress()
273 png_ptr->zbuf_size); in png_text_compress()
277 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; in png_text_compress()
278 png_ptr->zstream.next_out = png_ptr->zbuf; in png_text_compress()
281 } while (png_ptr->zstream.avail_in); in png_text_compress()
287 ret = deflate(&png_ptr->zstream, Z_FINISH); in png_text_compress()
292 if (!(png_ptr->zstream.avail_out)) in png_text_compress()
307 comp->output_ptr = (png_charpp)png_malloc(png_ptr, in png_text_compress()
312 png_free(png_ptr, old_ptr); in png_text_compress()
315 comp->output_ptr = (png_charpp)png_malloc(png_ptr, in png_text_compress()
322 (png_charp)png_malloc(png_ptr, in png_text_compress()
323 (png_uint_32)png_ptr->zbuf_size); in png_text_compress()
324 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, in png_text_compress()
325 png_ptr->zbuf_size); in png_text_compress()
329 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; in png_text_compress()
330 png_ptr->zstream.next_out = png_ptr->zbuf; in png_text_compress()
336 if (png_ptr->zstream.msg != NULL) in png_text_compress()
337 png_error(png_ptr, png_ptr->zstream.msg); in png_text_compress()
339 png_error(png_ptr, "zlib error"); in png_text_compress()
344 text_len = png_ptr->zbuf_size * comp->num_output_ptr; in png_text_compress()
345 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) in png_text_compress()
346 text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out; in png_text_compress()
353 png_write_compressed_data_out(png_structp png_ptr, compression_state *comp) in png_write_compressed_data_out() argument
360 png_write_chunk_data(png_ptr, (png_bytep)comp->input, in png_write_compressed_data_out()
368 png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i], in png_write_compressed_data_out()
369 (png_size_t)png_ptr->zbuf_size); in png_write_compressed_data_out()
370 png_free(png_ptr, comp->output_ptr[i]); in png_write_compressed_data_out()
374 png_free(png_ptr, comp->output_ptr); in png_write_compressed_data_out()
377 if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) in png_write_compressed_data_out()
378 png_write_chunk_data(png_ptr, png_ptr->zbuf, in png_write_compressed_data_out()
379 (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out)); in png_write_compressed_data_out()
382 deflateReset(&png_ptr->zstream); in png_write_compressed_data_out()
383 png_ptr->zstream.data_type = Z_BINARY; in png_write_compressed_data_out()
392 png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, in png_write_IHDR() argument
415 case 16: png_ptr->channels = 1; break; in png_write_IHDR()
416 default: png_error(png_ptr, in png_write_IHDR()
422 png_error(png_ptr, "Invalid bit depth for RGB image"); in png_write_IHDR()
423 png_ptr->channels = 3; in png_write_IHDR()
431 case 8: png_ptr->channels = 1; break; in png_write_IHDR()
432 default: png_error(png_ptr, "Invalid bit depth for paletted image"); in png_write_IHDR()
437 png_error(png_ptr, "Invalid bit depth for grayscale+alpha image"); in png_write_IHDR()
438 png_ptr->channels = 2; in png_write_IHDR()
442 png_error(png_ptr, "Invalid bit depth for RGBA image"); in png_write_IHDR()
443 png_ptr->channels = 4; in png_write_IHDR()
446 png_error(png_ptr, "Invalid image color type specified"); in png_write_IHDR()
451 png_warning(png_ptr, "Invalid compression type specified"); in png_write_IHDR()
466 !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && in png_write_IHDR()
467 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && in png_write_IHDR()
474 png_warning(png_ptr, "Invalid filter type specified"); in png_write_IHDR()
482 png_warning(png_ptr, "Invalid interlace type specified"); in png_write_IHDR()
490 png_ptr->bit_depth = (png_byte)bit_depth; in png_write_IHDR()
491 png_ptr->color_type = (png_byte)color_type; in png_write_IHDR()
492 png_ptr->interlaced = (png_byte)interlace_type; in png_write_IHDR()
494 png_ptr->filter_type = (png_byte)filter_type; in png_write_IHDR()
496 png_ptr->compression_type = (png_byte)compression_type; in png_write_IHDR()
497 png_ptr->width = width; in png_write_IHDR()
498 png_ptr->height = height; in png_write_IHDR()
500 png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels); in png_write_IHDR()
501 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width); in png_write_IHDR()
503 png_ptr->usr_width = png_ptr->width; in png_write_IHDR()
504 png_ptr->usr_bit_depth = png_ptr->bit_depth; in png_write_IHDR()
505 png_ptr->usr_channels = png_ptr->channels; in png_write_IHDR()
517 png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13); in png_write_IHDR()
520 png_ptr->zstream.zalloc = png_zalloc; in png_write_IHDR()
521 png_ptr->zstream.zfree = png_zfree; in png_write_IHDR()
522 png_ptr->zstream.opaque = (voidpf)png_ptr; in png_write_IHDR()
523 if (!(png_ptr->do_filter)) in png_write_IHDR()
525 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE || in png_write_IHDR()
526 png_ptr->bit_depth < 8) in png_write_IHDR()
527 png_ptr->do_filter = PNG_FILTER_NONE; in png_write_IHDR()
529 png_ptr->do_filter = PNG_ALL_FILTERS; in png_write_IHDR()
531 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY)) in png_write_IHDR()
533 if (png_ptr->do_filter != PNG_FILTER_NONE) in png_write_IHDR()
534 png_ptr->zlib_strategy = Z_FILTERED; in png_write_IHDR()
536 png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY; in png_write_IHDR()
538 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL)) in png_write_IHDR()
539 png_ptr->zlib_level = Z_DEFAULT_COMPRESSION; in png_write_IHDR()
540 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL)) in png_write_IHDR()
541 png_ptr->zlib_mem_level = 8; in png_write_IHDR()
542 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS)) in png_write_IHDR()
543 png_ptr->zlib_window_bits = 15; in png_write_IHDR()
544 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD)) in png_write_IHDR()
545 png_ptr->zlib_method = 8; in png_write_IHDR()
546 ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level, in png_write_IHDR()
547 png_ptr->zlib_method, png_ptr->zlib_window_bits, in png_write_IHDR()
548 png_ptr->zlib_mem_level, png_ptr->zlib_strategy); in png_write_IHDR()
551 if (ret == Z_VERSION_ERROR) png_error(png_ptr, in png_write_IHDR()
553 if (ret == Z_STREAM_ERROR) png_error(png_ptr, in png_write_IHDR()
555 if (ret == Z_MEM_ERROR) png_error(png_ptr, in png_write_IHDR()
557 png_error(png_ptr, "zlib failed to initialize compressor"); in png_write_IHDR()
559 png_ptr->zstream.next_out = png_ptr->zbuf; in png_write_IHDR()
560 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; in png_write_IHDR()
563 png_ptr->zstream.data_type = Z_BINARY; in png_write_IHDR()
565 png_ptr->mode = PNG_HAVE_IHDR; in png_write_IHDR()
573 png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal) in png_write_PLTE() argument
586 !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && in png_write_PLTE()
590 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) in png_write_PLTE()
592 png_error(png_ptr, "Invalid number of colors in palette"); in png_write_PLTE()
596 png_warning(png_ptr, "Invalid number of colors in palette"); in png_write_PLTE()
601 if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) in png_write_PLTE()
603 png_warning(png_ptr, in png_write_PLTE()
608 png_ptr->num_palette = (png_uint_16)num_pal; in png_write_PLTE()
609 png_debug1(3, "num_palette = %d", png_ptr->num_palette); in png_write_PLTE()
611 png_write_chunk_start(png_ptr, (png_bytep)png_PLTE, in png_write_PLTE()
619 png_write_chunk_data(png_ptr, buf, (png_size_t)3); in png_write_PLTE()
631 png_write_chunk_data(png_ptr, buf, (png_size_t)3); in png_write_PLTE()
634 png_write_chunk_end(png_ptr); in png_write_PLTE()
635 png_ptr->mode |= PNG_HAVE_PLTE; in png_write_PLTE()
640 png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) in png_write_IDAT() argument
650 if (!(png_ptr->mode & PNG_HAVE_IDAT) && in png_write_IDAT()
651 png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) in png_write_IDAT()
662 png_ptr->height < 16384 && png_ptr->width < 16384) in png_write_IDAT()
664 png_uint_32 uncompressed_idat_size = png_ptr->height * in png_write_IDAT()
665 ((png_ptr->width * in png_write_IDAT()
666 png_ptr->channels * png_ptr->bit_depth + 15) >> 3); in png_write_IDAT()
685 png_error(png_ptr, in png_write_IDAT()
689 png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length); in png_write_IDAT()
690 png_ptr->mode |= PNG_HAVE_IDAT; in png_write_IDAT()
695 png_write_IEND(png_structp png_ptr) in png_write_IEND() argument
703 png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL, in png_write_IEND()
705 png_ptr->mode |= PNG_HAVE_IEND; in png_write_IEND()
712 png_write_gAMA(png_structp png_ptr, double file_gamma) in png_write_gAMA() argument
725 png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4); in png_write_gAMA()
730 png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma) in png_write_gAMA_fixed() argument
741 png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4); in png_write_gAMA_fixed()
749 png_write_sRGB(png_structp png_ptr, int srgb_intent) in png_write_sRGB() argument
759 png_warning(png_ptr, in png_write_sRGB()
762 png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1); in png_write_sRGB()
769 png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, in png_write_iCCP() argument
788 if ((name_len = png_check_keyword(png_ptr, name, in png_write_iCCP()
793 png_warning(png_ptr, "Unknown compression type in iCCP chunk"); in png_write_iCCP()
807 png_warning(png_ptr, in png_write_iCCP()
809 png_free(png_ptr, new_name); in png_write_iCCP()
815 png_warning(png_ptr, in png_write_iCCP()
817 png_free(png_ptr, new_name); in png_write_iCCP()
823 png_warning(png_ptr, in png_write_iCCP()
829 profile_len = png_text_compress(png_ptr, profile, in png_write_iCCP()
833 png_write_chunk_start(png_ptr, (png_bytep)png_iCCP, in png_write_iCCP()
836 png_write_chunk_data(png_ptr, (png_bytep)new_name, in png_write_iCCP()
840 png_write_compressed_data_out(png_ptr, &comp); in png_write_iCCP()
842 png_write_chunk_end(png_ptr); in png_write_iCCP()
843 png_free(png_ptr, new_name); in png_write_iCCP()
850 png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette) in png_write_sPLT() argument
867 if ((name_len = png_check_keyword(png_ptr,spalette->name, &new_name))==0) in png_write_sPLT()
871 png_write_chunk_start(png_ptr, (png_bytep)png_sPLT, in png_write_sPLT()
873 png_write_chunk_data(png_ptr, (png_bytep)new_name, in png_write_sPLT()
875 png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1); in png_write_sPLT()
897 png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); in png_write_sPLT()
919 png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); in png_write_sPLT()
923 png_write_chunk_end(png_ptr); in png_write_sPLT()
924 png_free(png_ptr, new_name); in png_write_sPLT()
931 png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type) in png_write_sBIT() argument
947 png_ptr->usr_bit_depth); in png_write_sBIT()
952 png_warning(png_ptr, "Invalid sBIT depth specified"); in png_write_sBIT()
962 if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth) in png_write_sBIT()
964 png_warning(png_ptr, "Invalid sBIT depth specified"); in png_write_sBIT()
973 if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth) in png_write_sBIT()
975 png_warning(png_ptr, "Invalid sBIT depth specified"); in png_write_sBIT()
981 png_write_chunk(png_ptr, (png_bytep)png_sBIT, buf, size); in png_write_sBIT()
989 png_write_cHRM(png_structp png_ptr, double white_x, double white_y, in png_write_cHRM() argument
1013 if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y, in png_write_cHRM()
1031 png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32); in png_write_cHRM()
1037 png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x, in png_write_cHRM_fixed() argument
1051 if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y, in png_write_cHRM_fixed()
1067 png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32); in png_write_cHRM_fixed()
1076 png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran, in png_write_tRNS() argument
1088 if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette) in png_write_tRNS()
1090 png_warning(png_ptr, "Invalid number of transparent colors specified"); in png_write_tRNS()
1094 png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans, in png_write_tRNS()
1100 if (tran->gray >= (1 << png_ptr->bit_depth)) in png_write_tRNS()
1102 png_warning(png_ptr, in png_write_tRNS()
1107 png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2); in png_write_tRNS()
1115 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) in png_write_tRNS()
1117 png_warning(png_ptr, in png_write_tRNS()
1121 png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6); in png_write_tRNS()
1125 png_warning(png_ptr, "Can't write tRNS with an alpha channel"); in png_write_tRNS()
1133 png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type) in png_write_bKGD() argument
1146 (png_ptr->num_palette || in png_write_bKGD()
1147 (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && in png_write_bKGD()
1149 back->index >= png_ptr->num_palette) in png_write_bKGD()
1151 png_warning(png_ptr, "Invalid background palette index"); in png_write_bKGD()
1155 png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)1); in png_write_bKGD()
1162 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) in png_write_bKGD()
1164 png_warning(png_ptr, in png_write_bKGD()
1168 png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6); in png_write_bKGD()
1172 if (back->gray >= (1 << png_ptr->bit_depth)) in png_write_bKGD()
1174 png_warning(png_ptr, in png_write_bKGD()
1179 png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2); in png_write_bKGD()
1187 png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist) in png_write_hIST() argument
1197 if (num_hist > (int)png_ptr->num_palette) in png_write_hIST()
1200 png_ptr->num_palette); in png_write_hIST()
1201 png_warning(png_ptr, "Invalid number of histogram entries specified"); in png_write_hIST()
1205 png_write_chunk_start(png_ptr, (png_bytep)png_hIST, in png_write_hIST()
1210 png_write_chunk_data(png_ptr, buf, (png_size_t)2); in png_write_hIST()
1212 png_write_chunk_end(png_ptr); in png_write_hIST()
1229 png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key) in png_check_keyword() argument
1242 png_warning(png_ptr, "zero length keyword"); in png_check_keyword()
1248 *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2)); in png_check_keyword()
1251 png_warning(png_ptr, "Out of memory while procesing keyword"); in png_check_keyword()
1266 png_warning(png_ptr, msg); in png_check_keyword()
1268 png_warning(png_ptr, "invalid character in keyword"); in png_check_keyword()
1283 png_warning(png_ptr, "trailing spaces removed from keyword"); in png_check_keyword()
1296 png_warning(png_ptr, "leading spaces removed from keyword"); in png_check_keyword()
1328 png_warning(png_ptr, "extra interior spaces removed from keyword"); in png_check_keyword()
1332 png_free(png_ptr, *new_key); in png_check_keyword()
1334 png_warning(png_ptr, "Zero length keyword"); in png_check_keyword()
1339 png_warning(png_ptr, "keyword length must be 1 - 79 characters"); in png_check_keyword()
1351 png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text, in png_write_tEXt() argument
1362 if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) in png_write_tEXt()
1371 png_write_chunk_start(png_ptr, (png_bytep)png_tEXt, in png_write_tEXt()
1379 png_write_chunk_data(png_ptr, (png_bytep)new_key, in png_write_tEXt()
1382 png_write_chunk_data(png_ptr, (png_bytep)text, (png_size_t)text_len); in png_write_tEXt()
1384 png_write_chunk_end(png_ptr); in png_write_tEXt()
1385 png_free(png_ptr, new_key); in png_write_tEXt()
1392 png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text, in png_write_zTXt() argument
1411 if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) in png_write_zTXt()
1413 png_free(png_ptr, new_key); in png_write_zTXt()
1419 png_write_tEXt(png_ptr, new_key, text, (png_size_t)0); in png_write_zTXt()
1420 png_free(png_ptr, new_key); in png_write_zTXt()
1427 text_len = png_text_compress(png_ptr, text, text_len, compression, in png_write_zTXt()
1431 png_write_chunk_start(png_ptr, (png_bytep)png_zTXt, in png_write_zTXt()
1434 png_write_chunk_data(png_ptr, (png_bytep)new_key, in png_write_zTXt()
1436 png_free(png_ptr, new_key); in png_write_zTXt()
1440 png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1); in png_write_zTXt()
1442 png_write_compressed_data_out(png_ptr, &comp); in png_write_zTXt()
1445 png_write_chunk_end(png_ptr); in png_write_zTXt()
1452 png_write_iTXt(png_structp png_ptr, int compression, png_charp key, in png_write_iTXt() argument
1471 if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) in png_write_iTXt()
1474 if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0) in png_write_iTXt()
1476 png_warning(png_ptr, "Empty language field in iTXt chunk"); in png_write_iTXt()
1492 text_len = png_text_compress(png_ptr, text, text_len, compression-2, in png_write_iTXt()
1499 png_write_chunk_start(png_ptr, (png_bytep)png_iTXt, in png_write_iTXt()
1512 png_write_chunk_data(png_ptr, (png_bytep)new_key, in png_write_iTXt()
1523 png_write_chunk_data(png_ptr, cbuf, (png_size_t)2); in png_write_iTXt()
1526 png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), in png_write_iTXt()
1528 png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), in png_write_iTXt()
1530 png_write_compressed_data_out(png_ptr, &comp); in png_write_iTXt()
1532 png_write_chunk_end(png_ptr); in png_write_iTXt()
1533 png_free(png_ptr, new_key); in png_write_iTXt()
1534 png_free(png_ptr, new_lang); in png_write_iTXt()
1541 png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, in png_write_oFFs() argument
1552 png_warning(png_ptr, "Unrecognized unit type for oFFs chunk"); in png_write_oFFs()
1558 png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9); in png_write_oFFs()
1564 png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, in png_write_pCAL() argument
1579 png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); in png_write_pCAL()
1581 purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1; in png_write_pCAL()
1587 params_len = (png_uint_32p)png_malloc(png_ptr, in png_write_pCAL()
1601 png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len); in png_write_pCAL()
1602 png_write_chunk_data(png_ptr, (png_bytep)new_purpose, in png_write_pCAL()
1608 png_write_chunk_data(png_ptr, buf, (png_size_t)10); in png_write_pCAL()
1609 png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len); in png_write_pCAL()
1611 png_free(png_ptr, new_purpose); in png_write_pCAL()
1615 png_write_chunk_data(png_ptr, (png_bytep)params[i], in png_write_pCAL()
1619 png_free(png_ptr, params_len); in png_write_pCAL()
1620 png_write_chunk_end(png_ptr); in png_write_pCAL()
1628 png_write_sCAL(png_structp png_ptr, int unit, double width, double height) in png_write_sCAL() argument
1663 png_write_chunk(png_ptr, (png_bytep)png_sCAL, (png_bytep)buf, total_len); in png_write_sCAL()
1668 png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width, in png_write_sCAL_s() argument
1684 png_warning(png_ptr, "Can't write sCAL (buffer too small)"); in png_write_sCAL_s()
1693 png_write_chunk(png_ptr, (png_bytep)png_sCAL, buf, total_len); in png_write_sCAL_s()
1702 png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, in png_write_pHYs() argument
1714 png_warning(png_ptr, "Unrecognized unit type for pHYs chunk"); in png_write_pHYs()
1720 png_write_chunk(png_ptr, (png_bytep)png_pHYs, buf, (png_size_t)9); in png_write_pHYs()
1729 png_write_tIME(png_structp png_ptr, png_timep mod_time) in png_write_tIME() argument
1742 png_warning(png_ptr, "Invalid time specified for tIME chunk"); in png_write_tIME()
1753 png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, (png_size_t)7); in png_write_tIME()
1759 png_write_start_row(png_structp png_ptr) in png_write_start_row() argument
1782 png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1); in png_write_start_row()
1785 png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, in png_write_start_row()
1787 png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; in png_write_start_row()
1791 if (png_ptr->do_filter & PNG_FILTER_SUB) in png_write_start_row()
1793 png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, in png_write_start_row()
1794 (png_uint_32)(png_ptr->rowbytes + 1)); in png_write_start_row()
1795 png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; in png_write_start_row()
1799 if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) in png_write_start_row()
1802 png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, in png_write_start_row()
1805 if (png_ptr->do_filter & PNG_FILTER_UP) in png_write_start_row()
1807 png_ptr->up_row = (png_bytep)png_malloc(png_ptr, in png_write_start_row()
1808 (png_uint_32)(png_ptr->rowbytes + 1)); in png_write_start_row()
1809 png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; in png_write_start_row()
1812 if (png_ptr->do_filter & PNG_FILTER_AVG) in png_write_start_row()
1814 png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, in png_write_start_row()
1815 (png_uint_32)(png_ptr->rowbytes + 1)); in png_write_start_row()
1816 png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; in png_write_start_row()
1819 if (png_ptr->do_filter & PNG_FILTER_PAETH) in png_write_start_row()
1821 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, in png_write_start_row()
1822 (png_uint_32)(png_ptr->rowbytes + 1)); in png_write_start_row()
1823 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; in png_write_start_row()
1830 if (png_ptr->interlaced) in png_write_start_row()
1832 if (!(png_ptr->transformations & PNG_INTERLACE)) in png_write_start_row()
1834 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - in png_write_start_row()
1836 png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 - in png_write_start_row()
1841 png_ptr->num_rows = png_ptr->height; in png_write_start_row()
1842 png_ptr->usr_width = png_ptr->width; in png_write_start_row()
1848 png_ptr->num_rows = png_ptr->height; in png_write_start_row()
1849 png_ptr->usr_width = png_ptr->width; in png_write_start_row()
1851 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; in png_write_start_row()
1852 png_ptr->zstream.next_out = png_ptr->zbuf; in png_write_start_row()
1857 png_write_finish_row(png_structp png_ptr) in png_write_finish_row() argument
1880 png_ptr->row_number++; in png_write_finish_row()
1883 if (png_ptr->row_number < png_ptr->num_rows) in png_write_finish_row()
1888 if (png_ptr->interlaced) in png_write_finish_row()
1890 png_ptr->row_number = 0; in png_write_finish_row()
1891 if (png_ptr->transformations & PNG_INTERLACE) in png_write_finish_row()
1893 png_ptr->pass++; in png_write_finish_row()
1900 png_ptr->pass++; in png_write_finish_row()
1901 if (png_ptr->pass >= 7) in png_write_finish_row()
1903 png_ptr->usr_width = (png_ptr->width + in png_write_finish_row()
1904 png_pass_inc[png_ptr->pass] - 1 - in png_write_finish_row()
1905 png_pass_start[png_ptr->pass]) / in png_write_finish_row()
1906 png_pass_inc[png_ptr->pass]; in png_write_finish_row()
1907 png_ptr->num_rows = (png_ptr->height + in png_write_finish_row()
1908 png_pass_yinc[png_ptr->pass] - 1 - in png_write_finish_row()
1909 png_pass_ystart[png_ptr->pass]) / in png_write_finish_row()
1910 png_pass_yinc[png_ptr->pass]; in png_write_finish_row()
1911 if (png_ptr->transformations & PNG_INTERLACE) in png_write_finish_row()
1913 } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0); in png_write_finish_row()
1918 if (png_ptr->pass < 7) in png_write_finish_row()
1920 if (png_ptr->prev_row != NULL) in png_write_finish_row()
1921 png_memset(png_ptr->prev_row, 0, in png_write_finish_row()
1922 (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels* in png_write_finish_row()
1923 png_ptr->usr_bit_depth, png_ptr->width)) + 1); in png_write_finish_row()
1934 ret = deflate(&png_ptr->zstream, Z_FINISH); in png_write_finish_row()
1939 if (!(png_ptr->zstream.avail_out)) in png_write_finish_row()
1941 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); in png_write_finish_row()
1942 png_ptr->zstream.next_out = png_ptr->zbuf; in png_write_finish_row()
1943 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; in png_write_finish_row()
1948 if (png_ptr->zstream.msg != NULL) in png_write_finish_row()
1949 png_error(png_ptr, png_ptr->zstream.msg); in png_write_finish_row()
1951 png_error(png_ptr, "zlib error"); in png_write_finish_row()
1956 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) in png_write_finish_row()
1958 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size - in png_write_finish_row()
1959 png_ptr->zstream.avail_out); in png_write_finish_row()
1962 deflateReset(&png_ptr->zstream); in png_write_finish_row()
1963 png_ptr->zstream.data_type = Z_BINARY; in png_write_finish_row()
2145 png_write_find_filter(png_structp png_ptr, png_row_infop row_info) in png_write_find_filter() argument
2151 png_byte filter_to_do = png_ptr->do_filter; in png_write_find_filter()
2154 int num_p_filters = (int)png_ptr->num_prev_filters; in png_write_find_filter()
2160 if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS) in png_write_find_filter()
2170 prev_row = png_ptr->prev_row; in png_write_find_filter()
2172 best_row = png_ptr->row_buf; in png_write_find_filter()
2217 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) in png_write_find_filter()
2227 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) in png_write_find_filter()
2229 sumlo = (sumlo * png_ptr->filter_weights[j]) >> in png_write_find_filter()
2231 sumhi = (sumhi * png_ptr->filter_weights[j]) >> in png_write_find_filter()
2240 sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> in png_write_find_filter()
2242 sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> in png_write_find_filter()
2260 for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; in png_write_find_filter()
2270 best_row = png_ptr->sub_row; in png_write_find_filter()
2285 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) in png_write_find_filter()
2294 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) in png_write_find_filter()
2296 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> in png_write_find_filter()
2298 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> in png_write_find_filter()
2303 lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> in png_write_find_filter()
2305 lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> in png_write_find_filter()
2315 for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; in png_write_find_filter()
2334 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) in png_write_find_filter()
2343 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) in png_write_find_filter()
2345 sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >> in png_write_find_filter()
2347 sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >> in png_write_find_filter()
2352 sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> in png_write_find_filter()
2354 sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> in png_write_find_filter()
2367 best_row = png_ptr->sub_row; in png_write_find_filter()
2377 for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, in png_write_find_filter()
2383 best_row = png_ptr->up_row; in png_write_find_filter()
2395 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) in png_write_find_filter()
2404 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) in png_write_find_filter()
2406 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> in png_write_find_filter()
2408 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> in png_write_find_filter()
2413 lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> in png_write_find_filter()
2415 lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> in png_write_find_filter()
2425 for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, in png_write_find_filter()
2437 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) in png_write_find_filter()
2446 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) in png_write_find_filter()
2448 sumlo = (sumlo * png_ptr->filter_weights[j]) >> in png_write_find_filter()
2450 sumhi = (sumhi * png_ptr->filter_weights[j]) >> in png_write_find_filter()
2455 sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> in png_write_find_filter()
2457 sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> in png_write_find_filter()
2470 best_row = png_ptr->up_row; in png_write_find_filter()
2479 for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, in png_write_find_filter()
2489 best_row = png_ptr->avg_row; in png_write_find_filter()
2500 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) in png_write_find_filter()
2509 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG) in png_write_find_filter()
2511 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> in png_write_find_filter()
2513 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> in png_write_find_filter()
2518 lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> in png_write_find_filter()
2520 lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> in png_write_find_filter()
2530 for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, in png_write_find_filter()
2549 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) in png_write_find_filter()
2558 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) in png_write_find_filter()
2560 sumlo = (sumlo * png_ptr->filter_weights[j]) >> in png_write_find_filter()
2562 sumhi = (sumhi * png_ptr->filter_weights[j]) >> in png_write_find_filter()
2567 sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> in png_write_find_filter()
2569 sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> in png_write_find_filter()
2582 best_row = png_ptr->avg_row; in png_write_find_filter()
2591 for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, in png_write_find_filter()
2622 best_row = png_ptr->paeth_row; in png_write_find_filter()
2633 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) in png_write_find_filter()
2642 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) in png_write_find_filter()
2644 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> in png_write_find_filter()
2646 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> in png_write_find_filter()
2651 lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> in png_write_find_filter()
2653 lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> in png_write_find_filter()
2663 for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, in png_write_find_filter()
2714 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) in png_write_find_filter()
2723 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) in png_write_find_filter()
2725 sumlo = (sumlo * png_ptr->filter_weights[j]) >> in png_write_find_filter()
2727 sumhi = (sumhi * png_ptr->filter_weights[j]) >> in png_write_find_filter()
2732 sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> in png_write_find_filter()
2734 sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> in png_write_find_filter()
2746 best_row = png_ptr->paeth_row; in png_write_find_filter()
2752 png_write_filtered_row(png_ptr, best_row); in png_write_find_filter()
2757 if (png_ptr->num_prev_filters > 0) in png_write_find_filter()
2762 png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1]; in png_write_find_filter()
2764 png_ptr->prev_filters[j] = best_row[0]; in png_write_find_filter()
2773 png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row) in png_write_filtered_row() argument
2780 png_ptr->zstream.next_in = filtered_row; in png_write_filtered_row()
2781 png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1; in png_write_filtered_row()
2788 ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); in png_write_filtered_row()
2792 if (png_ptr->zstream.msg != NULL) in png_write_filtered_row()
2793 png_error(png_ptr, png_ptr->zstream.msg); in png_write_filtered_row()
2795 png_error(png_ptr, "zlib error"); in png_write_filtered_row()
2799 if (!(png_ptr->zstream.avail_out)) in png_write_filtered_row()
2802 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); in png_write_filtered_row()
2803 png_ptr->zstream.next_out = png_ptr->zbuf; in png_write_filtered_row()
2804 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; in png_write_filtered_row()
2807 } while (png_ptr->zstream.avail_in); in png_write_filtered_row()
2810 if (png_ptr->prev_row != NULL) in png_write_filtered_row()
2814 tptr = png_ptr->prev_row; in png_write_filtered_row()
2815 png_ptr->prev_row = png_ptr->row_buf; in png_write_filtered_row()
2816 png_ptr->row_buf = tptr; in png_write_filtered_row()
2820 png_write_finish_row(png_ptr); in png_write_filtered_row()
2823 png_ptr->flush_rows++; in png_write_filtered_row()
2825 if (png_ptr->flush_dist > 0 && in png_write_filtered_row()
2826 png_ptr->flush_rows >= png_ptr->flush_dist) in png_write_filtered_row()
2828 png_write_flush(png_ptr); in png_write_filtered_row()