提交 a8867850 编写于 作者: A Andreas Rheinhardt

avcodec/anm: Don't unnecessarily use context variables

Reviewed-by: NPeter Ross <pross@xvid.org>
Signed-off-by: NAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
上级 45c35022
...@@ -31,13 +31,12 @@ ...@@ -31,13 +31,12 @@
typedef struct AnmContext { typedef struct AnmContext {
AVFrame *frame; AVFrame *frame;
int palette[AVPALETTE_COUNT]; int palette[AVPALETTE_COUNT];
GetByteContext gb;
int x; ///< x coordinate position
} AnmContext; } AnmContext;
static av_cold int decode_init(AVCodecContext *avctx) static av_cold int decode_init(AVCodecContext *avctx)
{ {
AnmContext *s = avctx->priv_data; AnmContext *s = avctx->priv_data;
GetByteContext gb;
int i; int i;
if (avctx->extradata_size < 16 * 8 + 4 * 256) if (avctx->extradata_size < 16 * 8 + 4 * 256)
...@@ -49,10 +48,10 @@ static av_cold int decode_init(AVCodecContext *avctx) ...@@ -49,10 +48,10 @@ static av_cold int decode_init(AVCodecContext *avctx)
if (!s->frame) if (!s->frame)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
bytestream2_init(&s->gb, avctx->extradata, avctx->extradata_size); bytestream2_init(&gb, avctx->extradata, avctx->extradata_size);
bytestream2_skipu(&s->gb, 16 * 8); bytestream2_skipu(&gb, 16 * 8);
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
s->palette[i] = (0xFFU << 24) | bytestream2_get_le32u(&s->gb); s->palette[i] = (0xFFU << 24) | bytestream2_get_le32u(&gb);
return 0; return 0;
} }
...@@ -115,7 +114,8 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -115,7 +114,8 @@ static int decode_frame(AVCodecContext *avctx,
AnmContext *s = avctx->priv_data; AnmContext *s = avctx->priv_data;
const int buf_size = avpkt->size; const int buf_size = avpkt->size;
uint8_t *dst, *dst_end; uint8_t *dst, *dst_end;
int count, ret; GetByteContext gb;
int count, ret, x = 0;
if (buf_size < 7) if (buf_size < 7)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
...@@ -125,37 +125,36 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -125,37 +125,36 @@ static int decode_frame(AVCodecContext *avctx,
dst = s->frame->data[0]; dst = s->frame->data[0];
dst_end = s->frame->data[0] + s->frame->linesize[0]*avctx->height; dst_end = s->frame->data[0] + s->frame->linesize[0]*avctx->height;
bytestream2_init(&s->gb, avpkt->data, buf_size); bytestream2_init(&gb, avpkt->data, buf_size);
if (bytestream2_get_byte(&s->gb) != 0x42) { if (bytestream2_get_byte(&gb) != 0x42) {
avpriv_request_sample(avctx, "Unknown record type"); avpriv_request_sample(avctx, "Unknown record type");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
if (bytestream2_get_byte(&s->gb)) { if (bytestream2_get_byte(&gb)) {
avpriv_request_sample(avctx, "Padding bytes"); avpriv_request_sample(avctx, "Padding bytes");
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
} }
bytestream2_skip(&s->gb, 2); bytestream2_skip(&gb, 2);
s->x = 0;
do { do {
/* if statements are ordered by probability */ /* if statements are ordered by probability */
#define OP(gb, pixel, count) \ #define OP(gb, pixel, count) \
op(&dst, dst_end, (gb), (pixel), (count), &s->x, avctx->width, s->frame->linesize[0]) op(&dst, dst_end, (gb), (pixel), (count), &x, avctx->width, s->frame->linesize[0])
int type = bytestream2_get_byte(&s->gb); int type = bytestream2_get_byte(&gb);
count = type & 0x7F; count = type & 0x7F;
type >>= 7; type >>= 7;
if (count) { if (count) {
if (OP(type ? NULL : &s->gb, -1, count)) break; if (OP(type ? NULL : &gb, -1, count)) break;
} else if (!type) { } else if (!type) {
int pixel; int pixel;
count = bytestream2_get_byte(&s->gb); /* count==0 gives nop */ count = bytestream2_get_byte(&gb); /* count==0 gives nop */
pixel = bytestream2_get_byte(&s->gb); pixel = bytestream2_get_byte(&gb);
if (OP(NULL, pixel, count)) break; if (OP(NULL, pixel, count)) break;
} else { } else {
int pixel; int pixel;
type = bytestream2_get_le16(&s->gb); type = bytestream2_get_le16(&gb);
count = type & 0x3FFF; count = type & 0x3FFF;
type >>= 14; type >>= 14;
if (!count) { if (!count) {
...@@ -167,11 +166,11 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -167,11 +166,11 @@ static int decode_frame(AVCodecContext *avctx,
} }
continue; continue;
} }
pixel = type == 3 ? bytestream2_get_byte(&s->gb) : -1; pixel = type == 3 ? bytestream2_get_byte(&gb) : -1;
if (type == 1) count += 0x4000; if (type == 1) count += 0x4000;
if (OP(type == 2 ? &s->gb : NULL, pixel, count)) break; if (OP(type == 2 ? &gb : NULL, pixel, count)) break;
} }
} while (bytestream2_get_bytes_left(&s->gb) > 0); } while (bytestream2_get_bytes_left(&gb) > 0);
memcpy(s->frame->data[1], s->palette, AVPALETTE_SIZE); memcpy(s->frame->data[1], s->palette, AVPALETTE_SIZE);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册