diff options
author | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2012-01-22 00:12:34 +0100 |
---|---|---|
committer | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2012-01-22 14:41:15 +0100 |
commit | b4ec645f471faa5142ce492e39c7527eddda46de (patch) | |
tree | f3b8cdf0ef37be64d05e70d22707f4ec571a9602 /libavcodec | |
parent | b64b1608d8e202ae815bc7c5ee2b89f0255c2db3 (diff) | |
download | ffmpeg-b4ec645f471faa5142ce492e39c7527eddda46de.tar.gz |
Extract some duplicated code.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/fraps.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/libavcodec/fraps.c b/libavcodec/fraps.c index c3e73f4ca1..db0e85fd6a 100644 --- a/libavcodec/fraps.c +++ b/libavcodec/fraps.c @@ -155,6 +155,20 @@ static int decode_frame(AVCodecContext *avctx, buf += header_size; + avctx->pix_fmt = version & 1 ? PIX_FMT_BGR24 : PIX_FMT_YUVJ420P; + + if (version < 2) { + unsigned needed_size = avctx->width*avctx->height*3; + if (version == 0) needed_size /= 2; + needed_size += header_size; + if (buf_size != needed_size && buf_size != header_size) { + av_log(avctx, AV_LOG_ERROR, + "Invalid frame length %d (should be %d)\n", + buf_size, needed_size); + return -1; + } + } + f->pict_type = AV_PICTURE_TYPE_I; f->key_frame = 1; f->reference = 3; @@ -166,16 +180,6 @@ static int decode_frame(AVCodecContext *avctx, case 0: default: /* Fraps v0 is a reordered YUV420 */ - avctx->pix_fmt = PIX_FMT_YUVJ420P; - - if ( buf_size != avctx->width*avctx->height*3/2+header_size && - buf_size != header_size ) { - av_log(avctx, AV_LOG_ERROR, - "Invalid frame length %d (should be %d)\n", - buf_size, avctx->width*avctx->height*3/2+header_size); - return -1; - } - if ( (avctx->width % 8) != 0 || (avctx->height % 2) != 0 ) { av_log(avctx, AV_LOG_ERROR, "Invalid frame size %dx%d\n", avctx->width, avctx->height); @@ -211,16 +215,6 @@ static int decode_frame(AVCodecContext *avctx, case 1: /* Fraps v1 is an upside-down BGR24 */ - avctx->pix_fmt = PIX_FMT_BGR24; - - if ( buf_size != avctx->width*avctx->height*3+header_size && - buf_size != header_size ) { - av_log(avctx, AV_LOG_ERROR, - "Invalid frame length %d (should be %d)\n", - buf_size, avctx->width*avctx->height*3+header_size); - return -1; - } - if (avctx->reget_buffer(avctx, f)) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return -1; @@ -243,7 +237,6 @@ static int decode_frame(AVCodecContext *avctx, * Fraps v2 is Huffman-coded YUV420 planes * Fraps v4 is virtually the same */ - avctx->pix_fmt = PIX_FMT_YUVJ420P; if (avctx->reget_buffer(avctx, f)) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return -1; @@ -281,7 +274,6 @@ static int decode_frame(AVCodecContext *avctx, case 3: case 5: /* Virtually the same as version 4, but is for RGB24 */ - avctx->pix_fmt = PIX_FMT_BGR24; if (avctx->reget_buffer(avctx, f)) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return -1; |