diff options
author | Donny Yang <work@kota.moe> | 2015-03-29 11:05:43 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2015-03-29 18:30:30 +0200 |
commit | 9573737dfbe530158b7ecf7a3acbe9971c20cb0e (patch) | |
tree | ec7e66a191a96ae5985591fae84fe55d233edb6a | |
parent | e7ba79dc4e39b6632558df8a62c187f1c2ad9b8a (diff) | |
download | ffmpeg-9573737dfbe530158b7ecf7a3acbe9971c20cb0e.tar.gz |
png: Only init zlib once
Signed-off-by: Donny Yang <work@kota.moe>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavcodec/pngenc.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index c036fcb1ec..8fff0f3356 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -299,7 +299,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, int y, len, row_size, ret; int pass_row_size, enc_row_size; int64_t max_packet_size; - int compression_level; uint8_t *ptr, *top, *crow_buf, *crow; uint8_t *crow_base = NULL; uint8_t *progressive_buf = NULL; @@ -307,17 +306,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, row_size = (avctx->width * s->bits_per_pixel + 7) >> 3; - s->zstream.zalloc = ff_png_zalloc; - s->zstream.zfree = ff_png_zfree; - s->zstream.opaque = NULL; - compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT - ? Z_DEFAULT_COMPRESSION - : av_clip(avctx->compression_level, 0, 9); - ret = deflateInit2(&s->zstream, compression_level, - Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY); - if (ret != Z_OK) - return -1; - enc_row_size = deflateBound(&s->zstream, row_size); max_packet_size = avctx->height * (int64_t)(enc_row_size + ((enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) * 12) @@ -475,13 +463,14 @@ the_end: av_freep(&crow_base); av_freep(&progressive_buf); av_freep(&top_buf); - deflateEnd(&s->zstream); + deflateReset(&s->zstream); return ret; } static av_cold int png_enc_init(AVCodecContext *avctx) { PNGEncContext *s = avctx->priv_data; + int compression_level; switch (avctx->pix_fmt) { case AV_PIX_FMT_RGBA: @@ -569,11 +558,23 @@ static av_cold int png_enc_init(AVCodecContext *avctx) } s->bits_per_pixel = ff_png_get_nb_channels(s->color_type) * s->bit_depth; + s->zstream.zalloc = ff_png_zalloc; + s->zstream.zfree = ff_png_zfree; + s->zstream.opaque = NULL; + compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT + ? Z_DEFAULT_COMPRESSION + : av_clip(avctx->compression_level, 0, 9); + if (deflateInit2(&s->zstream, compression_level, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY) != Z_OK) + return -1; + return 0; } static av_cold int png_enc_close(AVCodecContext *avctx) { + PNGEncContext *s = avctx->priv_data; + + deflateEnd(&s->zstream); av_frame_free(&avctx->coded_frame); return 0; } |