diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-11-17 12:02:09 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-11-17 12:06:34 +0100 |
commit | 3ea168edeb7a20eae1fccf7da66ac7b8c8c791ba (patch) | |
tree | 4e167e434117d6f13a92fc7a2a7356108c273816 /libavcodec/tiffenc.c | |
parent | 85b7b0c519f8d9491b4c0340329a605cc97c8984 (diff) | |
parent | 45bde93eefa78c1bdb0936109fbd2e2fb27fbfe7 (diff) | |
download | ffmpeg-3ea168edeb7a20eae1fccf7da66ac7b8c8c791ba.tar.gz |
Merge commit '45bde93eefa78c1bdb0936109fbd2e2fb27fbfe7'
* commit '45bde93eefa78c1bdb0936109fbd2e2fb27fbfe7':
sunrastenc: use the AVFrame API properly.
targaenc: use the AVFrame API properly.
tiffenc: use the AVFrame API properly.
pngenc: use the AVFrame API properly.
Conflicts:
libavcodec/pngenc.c
libavcodec/sunrastenc.c
libavcodec/targaenc.c
libavcodec/tiffenc.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/tiffenc.c')
-rw-r--r-- | libavcodec/tiffenc.c | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c index f5d04eaf2b..7b1e5104bd 100644 --- a/libavcodec/tiffenc.c +++ b/libavcodec/tiffenc.c @@ -52,7 +52,6 @@ static const uint8_t type_sizes2[14] = { typedef struct TiffEncoderContext { AVClass *class; ///< for private options AVCodecContext *avctx; - AVFrame picture; int width; ///< picture width int height; ///< picture height @@ -195,9 +194,9 @@ static int encode_strip(TiffEncoderContext *s, const int8_t *src, } } -static void pack_yuv(TiffEncoderContext *s, uint8_t *dst, int lnum) +static void pack_yuv(TiffEncoderContext *s, const AVFrame *p, + uint8_t *dst, int lnum) { - AVFrame *p = &s->picture; int i, j, k; int w = (s->width - 1) / s->subsampling[0] + 1; uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]]; @@ -223,24 +222,12 @@ static void pack_yuv(TiffEncoderContext *s, uint8_t *dst, int lnum) } } -static av_cold int encode_init(AVCodecContext *avctx) -{ - TiffEncoderContext *s = avctx->priv_data; - - avctx->coded_frame = &s->picture; - avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; - avctx->coded_frame->key_frame = 1; - s->avctx = avctx; - - return 0; -} - static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); TiffEncoderContext *s = avctx->priv_data; - AVFrame *const p = &s->picture; + const AVFrame *const p = pict; int i; uint8_t *ptr; uint8_t *offset; @@ -252,8 +239,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, int is_yuv = 0, alpha = 0; int shift_h, shift_v; - *p = *pict; - s->width = avctx->width; s->height = avctx->height; s->subsampling[0] = 1; @@ -373,7 +358,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, zn = 0; for (j = 0; j < s->rps; j++) { if (is_yuv) { - pack_yuv(s, s->yuv_line, j); + pack_yuv(s, p, s->yuv_line, j); memcpy(zbuf + zn, s->yuv_line, bytes_per_row); j += s->subsampling[1] - 1; } else @@ -409,7 +394,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, s->strip_offsets[i / s->rps] = ptr - pkt->data; } if (is_yuv) { - pack_yuv(s, s->yuv_line, i); + pack_yuv(s, p, s->yuv_line, i); ret = encode_strip(s, s->yuv_line, ptr, bytes_per_row, s->compr); i += s->subsampling[1] - 1; } else @@ -497,10 +482,26 @@ fail: return ret < 0 ? ret : 0; } +static av_cold int encode_init(AVCodecContext *avctx) +{ + TiffEncoderContext *s = avctx->priv_data; + + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); + + avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + avctx->coded_frame->key_frame = 1; + s->avctx = avctx; + + return 0; +} + static av_cold int encode_close(AVCodecContext *avctx) { TiffEncoderContext *s = avctx->priv_data; + av_frame_free(&avctx->coded_frame); av_freep(&s->strip_sizes); av_freep(&s->strip_offsets); av_freep(&s->yuv_line); @@ -536,8 +537,8 @@ AVCodec ff_tiff_encoder = { .id = AV_CODEC_ID_TIFF, .priv_data_size = sizeof(TiffEncoderContext), .init = encode_init, - .encode2 = encode_frame, .close = encode_close, + .encode2 = encode_frame, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB24, AV_PIX_FMT_PAL8, AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A, AV_PIX_FMT_GRAY16LE, |