[FFmpeg-devel] [PATCH 11/12] avcodec/sanm: change GetByteContext member to pointer
Manuel Lauss
manuel.lauss at gmail.com
Thu Mar 13 13:15:04 EET 2025
In order do properly support the ANIM STOR/FTCH system, the FTCH
must replay a stored FOBJ and change the SANMContext's "GetByteContext"
member temporarily.
Signed-off-by: Manuel Lauss <manuel.lauss at gmail.com>
---
libavcodec/sanm.c | 394 +++++++++++++++++++++++-----------------------
1 file changed, 198 insertions(+), 196 deletions(-)
diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index a8a3e04156..207db4a8fb 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -262,7 +262,7 @@ static const int8_t c37_mv[] = {
typedef struct SANMVideoContext {
AVCodecContext *avctx;
- GetByteContext gb;
+ GetByteContext *gb;
int version, subversion, have_dimensions;
uint32_t pal[PALETTE_SIZE];
@@ -606,11 +606,11 @@ static int codec4_load_tiles(SANMVideoContext *ctx, uint16_t param2, uint8_t clr
if (param2 > 256)
return AVERROR_INVALIDDATA;
- if (bytestream2_get_bytes_left(&ctx->gb) < loop)
+ if (bytestream2_get_bytes_left(ctx->gb) < loop)
return AVERROR_INVALIDDATA;
while (loop--) {
- c = bytestream2_get_byteu(&ctx->gb);
+ c = bytestream2_get_byteu(ctx->gb);
*dst++ = (c >> 4) + clr;
*dst++ = (c & 0xf) + clr;
}
@@ -702,9 +702,9 @@ static int old_codec4(SANMVideoContext *ctx, int left, int top, int w, int h,
pxoff = j + left + ((top + i) * p);
if (param2 > 0) {
if (bits == 0) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- mask = bytestream2_get_byteu(&ctx->gb);
+ mask = bytestream2_get_byteu(ctx->gb);
bits = 8;
}
bit = !!(mask & 0x80);
@@ -714,9 +714,9 @@ static int old_codec4(SANMVideoContext *ctx, int left, int top, int w, int h,
bit = 0;
}
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- idx = bytestream2_get_byteu(&ctx->gb);
+ idx = bytestream2_get_byteu(ctx->gb);
if ((bit == 0) && (idx == 0x80) && (codec != 5))
continue;
@@ -761,18 +761,18 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t *dst, const int out_size)
int opcode, color, run_len, left = out_size;
while (left > 0) {
- opcode = bytestream2_get_byte(&ctx->gb);
+ opcode = bytestream2_get_byte(ctx->gb);
run_len = (opcode >> 1) + 1;
- if (run_len > left || bytestream2_get_bytes_left(&ctx->gb) <= 0)
+ if (run_len > left || bytestream2_get_bytes_left(ctx->gb) <= 0)
return AVERROR_INVALIDDATA;
if (opcode & 1) {
- color = bytestream2_get_byte(&ctx->gb);
+ color = bytestream2_get_byte(ctx->gb);
memset(dst, color, run_len);
} else {
- if (bytestream2_get_bytes_left(&ctx->gb) < run_len)
+ if (bytestream2_get_bytes_left(ctx->gb) < run_len)
return AVERROR_INVALIDDATA;
- bytestream2_get_bufferu(&ctx->gb, dst, run_len);
+ bytestream2_get_bufferu(ctx->gb, dst, run_len);
}
dst += run_len;
@@ -795,30 +795,30 @@ static int old_codec23(SANMVideoContext *ctx, int top, int left, int width,
for (i = 0; i < 256; i++)
lut[i] = (i + param + 0xd0) & 0xff;
} else if (param2 == 256) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 256)
+ if (bytestream2_get_bytes_left(ctx->gb) < 256)
return AVERROR_INVALIDDATA;
- bytestream2_get_bufferu(&ctx->gb, ctx->c23lut, 256);
+ bytestream2_get_bufferu(ctx->gb, ctx->c23lut, 256);
} else if (param2 < 256) {
for (i = 0; i < 256; i++)
lut[i] = (i + param2) & 0xff;
} else {
memcpy(lut, ctx->c23lut, 256);
}
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return 0; /* some c23 frames just set up the LUT */
dst = (uint8_t *)ctx->frm0;
for (i = 0; i < height; i++) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+ if (bytestream2_get_bytes_left(ctx->gb) < 2)
return 0;
pxoff = left + ((top + i) * ctx->pitch);
- k = bytestream2_get_le16u(&ctx->gb);
+ k = bytestream2_get_le16u(ctx->gb);
sk = 1;
pc = 0;
while (k > 0 && pc <= width) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- j = bytestream2_get_byteu(&ctx->gb);
+ j = bytestream2_get_byteu(ctx->gb);
if (sk) {
pxoff += j;
pc += j;
@@ -847,25 +847,25 @@ static int old_codec21(SANMVideoContext *ctx, int top, int left, int width,
dst = (uint8_t *)ctx->frm0;
for (i = 0; i < height; i++) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+ if (bytestream2_get_bytes_left(ctx->gb) < 2)
return 0;
pxoff = left + ((top + i) * ctx->pitch);
- k = bytestream2_get_le16u(&ctx->gb);
+ k = bytestream2_get_le16u(ctx->gb);
sk = 1;
pc = 0;
while (k > 0 && pc <= width) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+ if (bytestream2_get_bytes_left(ctx->gb) < 2)
return AVERROR_INVALIDDATA;
- j = bytestream2_get_le16u(&ctx->gb);
+ j = bytestream2_get_le16u(ctx->gb);
k -= 2;
if (sk) {
pxoff += j;
pc += j;
} else {
- if (bytestream2_get_bytes_left(&ctx->gb) < (j + 1))
+ if (bytestream2_get_bytes_left(ctx->gb) < (j + 1))
return AVERROR_INVALIDDATA;
do {
- c = bytestream2_get_byteu(&ctx->gb);
+ c = bytestream2_get_byteu(ctx->gb);
if (pxoff >=0 && pxoff < maxpxo) {
*(dst + pxoff) = c;
}
@@ -889,22 +889,22 @@ static int old_codec1(SANMVideoContext *ctx, int top,
uint8_t *dst = (uint8_t *)ctx->frm0;
for (i = 0; i < height; i++) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+ if (bytestream2_get_bytes_left(ctx->gb) < 2)
return AVERROR_INVALIDDATA;
- len = bytestream2_get_le16u(&ctx->gb);
- end = bytestream2_tell(&ctx->gb) + len;
+ len = bytestream2_get_le16u(ctx->gb);
+ end = bytestream2_tell(ctx->gb) + len;
pxoff = left + ((top + i) * ctx->pitch);
- while (bytestream2_tell(&ctx->gb) < end) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+ while (bytestream2_tell(ctx->gb) < end) {
+ if (bytestream2_get_bytes_left(ctx->gb) < 2)
return AVERROR_INVALIDDATA;
- code = bytestream2_get_byteu(&ctx->gb);
+ code = bytestream2_get_byteu(ctx->gb);
flag = code & 1;
code = (code >> 1) + 1;
if (flag) {
- val = bytestream2_get_byteu(&ctx->gb);
+ val = bytestream2_get_byteu(ctx->gb);
if (val || opaque) {
for (j = 0; j < code; j++) {
if (pxoff >= 0 && pxoff < maxpxo)
@@ -915,10 +915,10 @@ static int old_codec1(SANMVideoContext *ctx, int top,
pxoff += code;
}
} else {
- if (bytestream2_get_bytes_left(&ctx->gb) < code)
+ if (bytestream2_get_bytes_left(ctx->gb) < code)
return AVERROR_INVALIDDATA;
for (j = 0; j < code; j++) {
- val = bytestream2_get_byteu(&ctx->gb);
+ val = bytestream2_get_byteu(ctx->gb);
if ((pxoff >= 0) && (pxoff < maxpxo) && (val || opaque))
*(dst + pxoff) = val;
pxoff++;
@@ -937,10 +937,10 @@ static int old_codec2(SANMVideoContext *ctx, int top,
uint8_t *dst = (uint8_t *)ctx->frm0, col;
int16_t xpos = left, ypos = top;
- while (bytestream2_get_bytes_left(&ctx->gb) > 3) {
- xpos += bytestream2_get_le16u(&ctx->gb);
- ypos += bytestream2_get_byteu(&ctx->gb);
- col = bytestream2_get_byteu(&ctx->gb);
+ while (bytestream2_get_bytes_left(ctx->gb) > 3) {
+ xpos += bytestream2_get_le16u(ctx->gb);
+ ypos += bytestream2_get_byteu(ctx->gb);
+ col = bytestream2_get_byteu(ctx->gb);
if (xpos >= 0 && ypos >= 0 &&
xpos < ctx->width && ypos < ctx->height) {
*(dst + xpos + ypos * ctx->pitch) = col;
@@ -974,15 +974,15 @@ static int old_codec37(SANMVideoContext *ctx, int width, int height)
ptrdiff_t stride = ctx->pitch;
uint8_t *dst, *prev;
int skip_run = 0;
- int compr = bytestream2_get_byte(&ctx->gb);
- int mvoff = bytestream2_get_byte(&ctx->gb);
- int seq = bytestream2_get_le16(&ctx->gb);
- uint32_t decoded_size = bytestream2_get_le32(&ctx->gb);
+ int compr = bytestream2_get_byte(ctx->gb);
+ int mvoff = bytestream2_get_byte(ctx->gb);
+ int seq = bytestream2_get_le16(ctx->gb);
+ uint32_t decoded_size = bytestream2_get_le32(ctx->gb);
int flags;
- bytestream2_skip(&ctx->gb, 4);
- flags = bytestream2_get_byte(&ctx->gb);
- bytestream2_skip(&ctx->gb, 3);
+ bytestream2_skip(ctx->gb, 4);
+ flags = bytestream2_get_byte(ctx->gb);
+ bytestream2_skip(ctx->gb, 3);
if (decoded_size > ctx->height * stride) {
decoded_size = ctx->height * stride;
@@ -1006,7 +1006,7 @@ static int old_codec37(SANMVideoContext *ctx, int width, int height)
switch (compr) {
case 0:
for (i = 0; i < height; i++) {
- bytestream2_get_buffer(&ctx->gb, dst, width);
+ bytestream2_get_buffer(ctx->gb, dst, width);
dst += stride;
}
memset(ctx->frm2, 0, ctx->height * stride);
@@ -1019,9 +1019,9 @@ static int old_codec37(SANMVideoContext *ctx, int width, int height)
for (j = 0; j < height; j += 4) {
for (i = 0; i < width; i += 4) {
if (len < 0) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- code = bytestream2_get_byte(&ctx->gb);
+ code = bytestream2_get_byte(ctx->gb);
len = code >> 1;
run = code & 1;
skip = 0;
@@ -1030,29 +1030,29 @@ static int old_codec37(SANMVideoContext *ctx, int width, int height)
}
if (!skip) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- code = bytestream2_get_byte(&ctx->gb);
+ code = bytestream2_get_byte(ctx->gb);
if (code == 0xff) {
len--;
for (k = 0; k < 4; k++) {
for (l = 0; l < 4; l++) {
if (len < 0) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- code = bytestream2_get_byte(&ctx->gb);
+ code = bytestream2_get_byte(ctx->gb);
len = code >> 1;
run = code & 1;
if (run) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- code = bytestream2_get_byte(&ctx->gb);
+ code = bytestream2_get_byte(ctx->gb);
}
}
if (!run) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- code = bytestream2_get_byte(&ctx->gb);
+ code = bytestream2_get_byte(ctx->gb);
}
*(dst + i + (k * stride) + l) = code;
len--;
@@ -1087,23 +1087,23 @@ static int old_codec37(SANMVideoContext *ctx, int width, int height)
copy_block4(dst + i, prev + i, stride, stride, 4);
continue;
}
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- code = bytestream2_get_byteu(&ctx->gb);
+ code = bytestream2_get_byteu(ctx->gb);
if (code == 0xFF) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 16)
+ if (bytestream2_get_bytes_left(ctx->gb) < 16)
return AVERROR_INVALIDDATA;
for (k = 0; k < 4; k++)
- bytestream2_get_bufferu(&ctx->gb, dst + i + k * stride, 4);
+ bytestream2_get_bufferu(ctx->gb, dst + i + k * stride, 4);
} else if ((flags & 4) && (code == 0xFE)) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 4)
+ if (bytestream2_get_bytes_left(ctx->gb) < 4)
return AVERROR_INVALIDDATA;
for (k = 0; k < 4; k++)
- memset(dst + i + k * stride, bytestream2_get_byteu(&ctx->gb), 4);
+ memset(dst + i + k * stride, bytestream2_get_byteu(ctx->gb), 4);
} else if ((flags & 4) && (code == 0xFD)) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- t = bytestream2_get_byteu(&ctx->gb);
+ t = bytestream2_get_byteu(ctx->gb);
for (k = 0; k < 4; k++)
memset(dst + i + k * stride, t, 4);
} else {
@@ -1113,7 +1113,7 @@ static int old_codec37(SANMVideoContext *ctx, int width, int height)
ctx->height, stride, i + mx, j + my);
if ((compr == 4) && (code == 0))
- skip_run = bytestream2_get_byteu(&ctx->gb);
+ skip_run = bytestream2_get_byteu(ctx->gb);
}
}
dst += stride * 4;
@@ -1137,20 +1137,20 @@ static int process_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *prev1,
uint8_t colors[2];
int8_t *pglyph;
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- code = bytestream2_get_byteu(&ctx->gb);
+ code = bytestream2_get_byteu(ctx->gb);
if (code >= 0xF8) {
switch (code) {
case 0xFF:
if (size == 2) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 4)
+ if (bytestream2_get_bytes_left(ctx->gb) < 4)
return AVERROR_INVALIDDATA;
- dst[0] = bytestream2_get_byteu(&ctx->gb);
- dst[1] = bytestream2_get_byteu(&ctx->gb);
- dst[0 + stride] = bytestream2_get_byteu(&ctx->gb);
- dst[1 + stride] = bytestream2_get_byteu(&ctx->gb);
+ dst[0] = bytestream2_get_byteu(ctx->gb);
+ dst[1] = bytestream2_get_byteu(ctx->gb);
+ dst[0 + stride] = bytestream2_get_byteu(ctx->gb);
+ dst[1 + stride] = bytestream2_get_byteu(ctx->gb);
} else {
size >>= 1;
if (process_block(ctx, dst, prev1, prev2, stride, tbl, size))
@@ -1169,20 +1169,20 @@ static int process_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *prev1,
}
break;
case 0xFE:
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- t = bytestream2_get_byteu(&ctx->gb);
+ t = bytestream2_get_byteu(ctx->gb);
for (k = 0; k < size; k++)
memset(dst + k * stride, t, size);
break;
case 0xFD:
- if (bytestream2_get_bytes_left(&ctx->gb) < 3)
+ if (bytestream2_get_bytes_left(ctx->gb) < 3)
return AVERROR_INVALIDDATA;
- code = bytestream2_get_byteu(&ctx->gb);
+ code = bytestream2_get_byteu(ctx->gb);
pglyph = (size == 8) ? ctx->p8x8glyphs[code] : ctx->p4x4glyphs[code];
- bytestream2_get_bufferu(&ctx->gb, colors, 2);
+ bytestream2_get_bufferu(ctx->gb, colors, 2);
for (k = 0; k < size; k++)
for (t = 0; t < size; t++)
@@ -1193,10 +1193,10 @@ static int process_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *prev1,
memcpy(dst + k * stride, prev1 + k * stride, size);
break;
default:
- k = bytestream2_tell(&ctx->gb);
- bytestream2_seek(&ctx->gb, tbl + (code & 7), SEEK_SET);
- t = bytestream2_get_byte(&ctx->gb);
- bytestream2_seek(&ctx->gb, k, SEEK_SET);
+ k = bytestream2_tell(ctx->gb);
+ bytestream2_seek(ctx->gb, tbl + (code & 7), SEEK_SET);
+ t = bytestream2_get_byte(ctx->gb);
+ bytestream2_seek(ctx->gb, k, SEEK_SET);
for (k = 0; k < size; k++)
memset(dst + k * stride, t, size);
}
@@ -1228,7 +1228,7 @@ static void codec47_read_interptable(SANMVideoContext *ctx)
for (i = 0; i < 256; i++) {
p1 = p2 = itbl + i;
for (j = 256 - i; j; j--) {
- *p1 = *p2 = bytestream2_get_byte(&ctx->gb);
+ *p1 = *p2 = bytestream2_get_byte(ctx->gb);
p1 += 1;
p2 += 256;
}
@@ -1245,12 +1245,12 @@ static void codec47_comp1(SANMVideoContext *ctx, uint8_t *dst_in, int width,
dst = dst_in + stride;
for (i = 0; i < height; i += 2) {
- p1 = bytestream2_get_byte(&ctx->gb);
+ p1 = bytestream2_get_byte(ctx->gb);
*dst++ = p1;
*dst++ = p1;
px = p1;
for (j = 2; j < width; j += 2) {
- p1 = bytestream2_get_byte(&ctx->gb);
+ p1 = bytestream2_get_byte(ctx->gb);
px = (px << 8) | p1;
*dst++ = itbl[px];
*dst++ = p1;
@@ -1278,17 +1278,17 @@ static int old_codec47(SANMVideoContext *ctx, int width, int height)
uint8_t *prev1 = (uint8_t *)ctx->frm1;
uint8_t *prev2 = (uint8_t *)ctx->frm2;
uint8_t auxcol[2];
- int tbl_pos = bytestream2_tell(&ctx->gb);
- int seq = bytestream2_get_le16(&ctx->gb);
- int compr = bytestream2_get_byte(&ctx->gb);
- int new_rot = bytestream2_get_byte(&ctx->gb);
- int skip = bytestream2_get_byte(&ctx->gb);
-
- bytestream2_skip(&ctx->gb, 7);
- auxcol[0] = bytestream2_get_byteu(&ctx->gb);
- auxcol[1] = bytestream2_get_byteu(&ctx->gb);
- decoded_size = bytestream2_get_le32(&ctx->gb);
- bytestream2_skip(&ctx->gb, 8);
+ int tbl_pos = bytestream2_tell(ctx->gb);
+ int seq = bytestream2_get_le16(ctx->gb);
+ int compr = bytestream2_get_byte(ctx->gb);
+ int new_rot = bytestream2_get_byte(ctx->gb);
+ int skip = bytestream2_get_byte(ctx->gb);
+
+ bytestream2_skip(ctx->gb, 7);
+ auxcol[0] = bytestream2_get_byteu(ctx->gb);
+ auxcol[1] = bytestream2_get_byteu(ctx->gb);
+ decoded_size = bytestream2_get_le32(ctx->gb);
+ bytestream2_skip(ctx->gb, 8);
if (decoded_size > ctx->height * stride) {
decoded_size = ctx->height * stride;
@@ -1296,7 +1296,7 @@ static int old_codec47(SANMVideoContext *ctx, int width, int height)
}
if (skip & 1) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 0x8080)
+ if (bytestream2_get_bytes_left(ctx->gb) < 0x8080)
return AVERROR_INVALIDDATA;
codec47_read_interptable(ctx);
}
@@ -1308,15 +1308,15 @@ static int old_codec47(SANMVideoContext *ctx, int width, int height)
switch (compr) {
case 0:
- if (bytestream2_get_bytes_left(&ctx->gb) < width * height)
+ if (bytestream2_get_bytes_left(ctx->gb) < width * height)
return AVERROR_INVALIDDATA;
for (j = 0; j < height; j++) {
- bytestream2_get_bufferu(&ctx->gb, dst, width);
+ bytestream2_get_bufferu(ctx->gb, dst, width);
dst += stride;
}
break;
case 1:
- if (bytestream2_get_bytes_left(&ctx->gb) < ((width + 1) >> 1) * ((height + 1) >> 1))
+ if (bytestream2_get_bytes_left(ctx->gb) < ((width + 1) >> 1) * ((height + 1) >> 1))
return AVERROR_INVALIDDATA;
codec47_comp1(ctx, dst, width, height, stride);
break;
@@ -1381,24 +1381,24 @@ static int codec48_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *db,
int16_t mvofs;
uint32_t ofs;
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return 1;
- opc = bytestream2_get_byteu(&ctx->gb);
+ opc = bytestream2_get_byteu(ctx->gb);
switch (opc) {
case 0xFF: // 1x1 -> 8x8 block scale
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return 1;
- opc = bytestream2_get_byteu(&ctx->gb);
+ opc = bytestream2_get_byteu(ctx->gb);
for (i = 0; i < 16; i++)
sb[i] = opc;
c48_4to8(dst, sb, w);
break;
case 0xFE: // 1x 8x8 copy from deltabuf, 16bit mv from source
- if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+ if (bytestream2_get_bytes_left(ctx->gb) < 2)
return 1;
- mvofs = bytestream2_get_le16(&ctx->gb);
+ mvofs = bytestream2_get_le16(ctx->gb);
for (i = 0; i < 8; i++) {
ofs = w * i;
for (k = 0; k < 8; k++)
@@ -1406,12 +1406,12 @@ static int codec48_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *db,
}
break;
case 0xFD: // 2x2 -> 8x8 block scale
- if (bytestream2_get_bytes_left(&ctx->gb) < 4)
+ if (bytestream2_get_bytes_left(ctx->gb) < 4)
return 1;
- sb[ 5] = bytestream2_get_byteu(&ctx->gb);
- sb[ 7] = bytestream2_get_byteu(&ctx->gb);
- sb[13] = bytestream2_get_byteu(&ctx->gb);
- sb[15] = bytestream2_get_byteu(&ctx->gb);
+ sb[ 5] = bytestream2_get_byteu(ctx->gb);
+ sb[ 7] = bytestream2_get_byteu(ctx->gb);
+ sb[13] = bytestream2_get_byteu(ctx->gb);
+ sb[15] = bytestream2_get_byteu(ctx->gb);
sb[0] = sb[1] = sb[4] = sb[5];
sb[2] = sb[3] = sb[6] = sb[7];
@@ -1420,11 +1420,11 @@ static int codec48_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *db,
c48_4to8(dst, sb, w);
break;
case 0xFC: // 4x copy 4x4 block, per-block c37_mv from source
- if (bytestream2_get_bytes_left(&ctx->gb) < 4)
+ if (bytestream2_get_bytes_left(ctx->gb) < 4)
return 1;
for (i = 0; i < 8; i += 4) {
for (k = 0; k < 8; k += 4) {
- opc = bytestream2_get_byteu(&ctx->gb);
+ opc = bytestream2_get_byteu(ctx->gb);
mvofs = c37_mv[opc * 2] + (c37_mv[opc * 2 + 1] * w);
for (j = 0; j < 4; j++) {
ofs = (w * (j + i)) + k;
@@ -1435,11 +1435,11 @@ static int codec48_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *db,
}
break;
case 0xFB: // Copy 4x 4x4 blocks, per-block mv from source
- if (bytestream2_get_bytes_left(&ctx->gb) < 8)
+ if (bytestream2_get_bytes_left(ctx->gb) < 8)
return 1;
for (i = 0; i < 8; i += 4) {
for (k = 0; k < 8; k += 4) {
- mvofs = bytestream2_get_le16(&ctx->gb);
+ mvofs = bytestream2_get_le16(ctx->gb);
for (j = 0; j < 4; j++) {
ofs = (w * (j + i)) + k;
for (l = 0; l < 4; l++)
@@ -1449,18 +1449,18 @@ static int codec48_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *db,
}
break;
case 0xFA: // scale 4x4 input block to 8x8 dest block
- if (bytestream2_get_bytes_left(&ctx->gb) < 16)
+ if (bytestream2_get_bytes_left(ctx->gb) < 16)
return 1;
- bytestream2_get_bufferu(&ctx->gb, sb, 16);
+ bytestream2_get_bufferu(ctx->gb, sb, 16);
c48_4to8(dst, sb, w);
break;
case 0xF9: // 16x 2x2 copy from delta, per-block c37_mv from source
- if (bytestream2_get_bytes_left(&ctx->gb) < 16)
+ if (bytestream2_get_bytes_left(ctx->gb) < 16)
return 1;
for (i = 0; i < 8; i += 2) {
for (j = 0; j < 8; j += 2) {
ofs = (w * i) + j;
- opc = bytestream2_get_byteu(&ctx->gb);
+ opc = bytestream2_get_byteu(ctx->gb);
mvofs = c37_mv[opc * 2] + (c37_mv[opc * 2 + 1] * w);
for (l = 0; l < 2; l++) {
*(dst + ofs + l + 0) = *(db + ofs + l + 0 + mvofs);
@@ -1470,12 +1470,12 @@ static int codec48_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *db,
}
break;
case 0xF8: // 16x 2x2 blocks copy, 16bit mv from source
- if (bytestream2_get_bytes_left(&ctx->gb) < 32)
+ if (bytestream2_get_bytes_left(ctx->gb) < 32)
return 1;
for (i = 0; i < 8; i += 2) {
for (j = 0; j < 8; j += 2) {
ofs = w * i + j;
- mvofs = bytestream2_get_le16(&ctx->gb);
+ mvofs = bytestream2_get_le16(ctx->gb);
for (l = 0; l < 2; l++) {
*(dst + ofs + l + 0) = *(db + ofs + l + 0 + mvofs);
*(dst + ofs + l + w) = *(db + ofs + l + w + mvofs);
@@ -1484,12 +1484,12 @@ static int codec48_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *db,
}
break;
case 0xF7: // copy 8x8 block from src to dest
- if (bytestream2_get_bytes_left(&ctx->gb) < 64)
+ if (bytestream2_get_bytes_left(ctx->gb) < 64)
return 1;
for (i = 0; i < 8; i++) {
ofs = i * w;
for (l = 0; l < 8; l++)
- *(dst + ofs + l) = bytestream2_get_byteu(&ctx->gb);
+ *(dst + ofs + l) = bytestream2_get_byteu(ctx->gb);
}
break;
default: // copy 8x8 block from prev, c37_mv from source
@@ -1507,10 +1507,10 @@ static int codec48_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *db,
static int old_codec48(SANMVideoContext *ctx, int width, int height)
{
uint8_t *dst, *prev;
- int compr = bytestream2_get_byte(&ctx->gb);
- int mvidx = bytestream2_get_byte(&ctx->gb);
- int seq = bytestream2_get_le16(&ctx->gb);
- uint32_t decoded_size = bytestream2_get_le32(&ctx->gb);
+ int compr = bytestream2_get_byte(ctx->gb);
+ int mvidx = bytestream2_get_byte(ctx->gb);
+ int seq = bytestream2_get_le16(ctx->gb);
+ uint32_t decoded_size = bytestream2_get_le32(ctx->gb);
int i, j, flags;
// all codec48 videos use 1, but just to be safe...
@@ -1519,12 +1519,12 @@ static int old_codec48(SANMVideoContext *ctx, int width, int height)
return AVERROR_INVALIDDATA;
}
- bytestream2_skip(&ctx->gb, 4);
- flags = bytestream2_get_byte(&ctx->gb);
- bytestream2_skip(&ctx->gb, 3);
+ bytestream2_skip(ctx->gb, 4);
+ flags = bytestream2_get_byte(ctx->gb);
+ bytestream2_skip(ctx->gb, 3);
if (flags & 8) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 0x8080)
+ if (bytestream2_get_bytes_left(ctx->gb) < 0x8080)
return AVERROR_INVALIDDATA;
codec47_read_interptable(ctx);
}
@@ -1539,10 +1539,10 @@ static int old_codec48(SANMVideoContext *ctx, int width, int height)
switch (compr) {
case 0:
- if (bytestream2_get_bytes_left(&ctx->gb) < width * height)
+ if (bytestream2_get_bytes_left(ctx->gb) < width * height)
return AVERROR_INVALIDDATA;
for (j = 0; j < height; j++) {
- bytestream2_get_bufferu(&ctx->gb, dst, width);
+ bytestream2_get_bufferu(ctx->gb, dst, width);
dst += width;
}
break;
@@ -1563,7 +1563,7 @@ static int old_codec48(SANMVideoContext *ctx, int width, int height)
}
break;
case 5:
- if (bytestream2_get_bytes_left(&ctx->gb) < ((width + 1) >> 1) * ((height + 1) >> 1))
+ if (bytestream2_get_bytes_left(ctx->gb) < ((width + 1) >> 1) * ((height + 1) >> 1))
return AVERROR_INVALIDDATA;
codec47_comp1(ctx, dst, width, height, width);
break;
@@ -1581,14 +1581,14 @@ static int old_codec48(SANMVideoContext *ctx, int width, int height)
static int process_frame_obj(SANMVideoContext *ctx)
{
uint16_t parm2;
- uint8_t codec = bytestream2_get_byteu(&ctx->gb);
- uint8_t param = bytestream2_get_byteu(&ctx->gb);
- int16_t left = bytestream2_get_le16u(&ctx->gb);
- int16_t top = bytestream2_get_le16u(&ctx->gb);
- uint16_t w = bytestream2_get_le16u(&ctx->gb);
- uint16_t h = bytestream2_get_le16u(&ctx->gb);
- bytestream2_skip(&ctx->gb, 2);
- parm2 = bytestream2_get_le16u(&ctx->gb);
+ uint8_t codec = bytestream2_get_byteu(ctx->gb);
+ uint8_t param = bytestream2_get_byteu(ctx->gb);
+ int16_t left = bytestream2_get_le16u(ctx->gb);
+ int16_t top = bytestream2_get_le16u(ctx->gb);
+ uint16_t w = bytestream2_get_le16u(ctx->gb);
+ uint16_t h = bytestream2_get_le16u(ctx->gb);
+ bytestream2_skip(ctx->gb, 2);
+ parm2 = bytestream2_get_le16u(ctx->gb);
if (w < 1 || h < 1 || w > 800 || h > 600 || left > 800 || top > 600) {
av_log(ctx->avctx, AV_LOG_WARNING,
@@ -1679,8 +1679,8 @@ static int process_xpal(SANMVideoContext *ctx, int size)
uint8_t c[3];
int i, j;
- bytestream2_skip(&ctx->gb, 2);
- cmd = bytestream2_get_be16(&ctx->gb);
+ bytestream2_skip(ctx->gb, 2);
+ cmd = bytestream2_get_be16(ctx->gb);
if (cmd == 1) {
for (i = 0; i < PALETTE_DELTA; i += 3) {
@@ -1700,11 +1700,11 @@ static int process_xpal(SANMVideoContext *ctx, int size)
return AVERROR_INVALIDDATA;
}
for (i = 0; i < PALETTE_DELTA; i++)
- dp[i] = bytestream2_get_le16u(&ctx->gb);
+ dp[i] = bytestream2_get_le16u(ctx->gb);
if (size >= PALETTE_DELTA * 2 + 4 + PALETTE_SIZE * 3) {
for (i = 0; i < PALETTE_SIZE; i++)
- ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->gb);
+ ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24u(ctx->gb);
if (ctx->subversion < 2)
ctx->pal[0] = 0xFFU << 24;
}
@@ -1717,13 +1717,13 @@ static int decode_0(SANMVideoContext *ctx)
uint16_t *frm = ctx->frm0;
int x, y;
- if (bytestream2_get_bytes_left(&ctx->gb) < ctx->width * ctx->height * 2) {
+ if (bytestream2_get_bytes_left(ctx->gb) < ctx->width * ctx->height * 2) {
av_log(ctx->avctx, AV_LOG_ERROR, "Insufficient data for raw frame.\n");
return AVERROR_INVALIDDATA;
}
for (y = 0; y < ctx->height; y++) {
for (x = 0; x < ctx->width; x++)
- frm[x] = bytestream2_get_le16u(&ctx->gb);
+ frm[x] = bytestream2_get_le16u(ctx->gb);
frm += ctx->pitch;
}
return 0;
@@ -1793,10 +1793,10 @@ static int opcode_0xf7(SANMVideoContext *ctx, int cx, int cy, int block_size, pt
if (block_size == 2) {
uint32_t indices;
- if (bytestream2_get_bytes_left(&ctx->gb) < 4)
+ if (bytestream2_get_bytes_left(ctx->gb) < 4)
return AVERROR_INVALIDDATA;
- indices = bytestream2_get_le32u(&ctx->gb);
+ indices = bytestream2_get_le32u(ctx->gb);
dst[0] = ctx->codebook[indices & 0xFF];
indices >>= 8;
dst[1] = ctx->codebook[indices & 0xFF];
@@ -1808,12 +1808,12 @@ static int opcode_0xf7(SANMVideoContext *ctx, int cx, int cy, int block_size, pt
uint16_t fgcolor, bgcolor;
int glyph;
- if (bytestream2_get_bytes_left(&ctx->gb) < 3)
+ if (bytestream2_get_bytes_left(ctx->gb) < 3)
return AVERROR_INVALIDDATA;
- glyph = bytestream2_get_byteu(&ctx->gb);
- bgcolor = ctx->codebook[bytestream2_get_byteu(&ctx->gb)];
- fgcolor = ctx->codebook[bytestream2_get_byteu(&ctx->gb)];
+ glyph = bytestream2_get_byteu(ctx->gb);
+ bgcolor = ctx->codebook[bytestream2_get_byteu(ctx->gb)];
+ fgcolor = ctx->codebook[bytestream2_get_byteu(ctx->gb)];
draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
}
@@ -1825,23 +1825,23 @@ static int opcode_0xf8(SANMVideoContext *ctx, int cx, int cy, int block_size, pt
uint16_t *dst = ctx->frm0 + cx + cy * ctx->pitch;
if (block_size == 2) {
- if (bytestream2_get_bytes_left(&ctx->gb) < 8)
+ if (bytestream2_get_bytes_left(ctx->gb) < 8)
return AVERROR_INVALIDDATA;
- dst[0] = bytestream2_get_le16u(&ctx->gb);
- dst[1] = bytestream2_get_le16u(&ctx->gb);
- dst[pitch] = bytestream2_get_le16u(&ctx->gb);
- dst[pitch + 1] = bytestream2_get_le16u(&ctx->gb);
+ dst[0] = bytestream2_get_le16u(ctx->gb);
+ dst[1] = bytestream2_get_le16u(ctx->gb);
+ dst[pitch] = bytestream2_get_le16u(ctx->gb);
+ dst[pitch + 1] = bytestream2_get_le16u(ctx->gb);
} else {
uint16_t fgcolor, bgcolor;
int glyph;
- if (bytestream2_get_bytes_left(&ctx->gb) < 5)
+ if (bytestream2_get_bytes_left(ctx->gb) < 5)
return AVERROR_INVALIDDATA;
- glyph = bytestream2_get_byteu(&ctx->gb);
- bgcolor = bytestream2_get_le16u(&ctx->gb);
- fgcolor = bytestream2_get_le16u(&ctx->gb);
+ glyph = bytestream2_get_byteu(ctx->gb);
+ bgcolor = bytestream2_get_le16u(ctx->gb);
+ fgcolor = bytestream2_get_le16u(ctx->gb);
draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
}
@@ -1869,10 +1869,10 @@ static int codec2subblock(SANMVideoContext *ctx, int cx, int cy, int blk_size)
int16_t mx, my, index;
int opcode;
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
- opcode = bytestream2_get_byteu(&ctx->gb);
+ opcode = bytestream2_get_byteu(ctx->gb);
switch (opcode) {
default:
@@ -1886,9 +1886,9 @@ static int codec2subblock(SANMVideoContext *ctx, int cx, int cy, int blk_size)
}
break;
case 0xF5:
- if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+ if (bytestream2_get_bytes_left(ctx->gb) < 2)
return AVERROR_INVALIDDATA;
- index = bytestream2_get_le16u(&ctx->gb);
+ index = bytestream2_get_le16u(ctx->gb);
mx = index % ctx->width;
my = index / ctx->width;
@@ -1919,16 +1919,16 @@ static int codec2subblock(SANMVideoContext *ctx, int cx, int cy, int blk_size)
ctx->small_codebook[opcode - 0xf9], blk_size, ctx->pitch);
break;
case 0xFD:
- if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+ if (bytestream2_get_bytes_left(ctx->gb) < 1)
return AVERROR_INVALIDDATA;
fill_block(ctx->frm0 + cx + cy * ctx->pitch,
- ctx->codebook[bytestream2_get_byteu(&ctx->gb)], blk_size, ctx->pitch);
+ ctx->codebook[bytestream2_get_byteu(ctx->gb)], blk_size, ctx->pitch);
break;
case 0xFE:
- if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+ if (bytestream2_get_bytes_left(ctx->gb) < 2)
return AVERROR_INVALIDDATA;
fill_block(ctx->frm0 + cx + cy * ctx->pitch,
- bytestream2_get_le16u(&ctx->gb), blk_size, ctx->pitch);
+ bytestream2_get_le16u(ctx->gb), blk_size, ctx->pitch);
break;
case 0xFF:
if (blk_size == 2) {
@@ -2001,12 +2001,12 @@ static int decode_6(SANMVideoContext *ctx)
int npixels = ctx->npixels;
uint16_t *frm = ctx->frm0;
- if (bytestream2_get_bytes_left(&ctx->gb) < npixels) {
+ if (bytestream2_get_bytes_left(ctx->gb) < npixels) {
av_log(ctx->avctx, AV_LOG_ERROR, "Insufficient data for frame.\n");
return AVERROR_INVALIDDATA;
}
while (npixels--)
- *frm++ = ctx->codebook[bytestream2_get_byteu(&ctx->gb)];
+ *frm++ = ctx->codebook[bytestream2_get_byteu(ctx->gb)];
return 0;
}
@@ -2044,38 +2044,38 @@ static int read_frame_header(SANMVideoContext *ctx, SANMFrameHeader *hdr)
{
int i, ret;
- if ((ret = bytestream2_get_bytes_left(&ctx->gb)) < 560) {
+ if ((ret = bytestream2_get_bytes_left(ctx->gb)) < 560) {
av_log(ctx->avctx, AV_LOG_ERROR, "Input frame too short (%d bytes).\n",
ret);
return AVERROR_INVALIDDATA;
}
- bytestream2_skip(&ctx->gb, 8); // skip pad
+ bytestream2_skip(ctx->gb, 8); // skip pad
- hdr->width = bytestream2_get_le32u(&ctx->gb);
- hdr->height = bytestream2_get_le32u(&ctx->gb);
+ hdr->width = bytestream2_get_le32u(ctx->gb);
+ hdr->height = bytestream2_get_le32u(ctx->gb);
if (hdr->width != ctx->width || hdr->height != ctx->height) {
avpriv_report_missing_feature(ctx->avctx, "Variable size frames");
return AVERROR_PATCHWELCOME;
}
- hdr->seq_num = bytestream2_get_le16u(&ctx->gb);
- hdr->codec = bytestream2_get_byteu(&ctx->gb);
- hdr->rotate_code = bytestream2_get_byteu(&ctx->gb);
+ hdr->seq_num = bytestream2_get_le16u(ctx->gb);
+ hdr->codec = bytestream2_get_byteu(ctx->gb);
+ hdr->rotate_code = bytestream2_get_byteu(ctx->gb);
- bytestream2_skip(&ctx->gb, 4); // skip pad
+ bytestream2_skip(ctx->gb, 4); // skip pad
for (i = 0; i < 4; i++)
- ctx->small_codebook[i] = bytestream2_get_le16u(&ctx->gb);
- hdr->bg_color = bytestream2_get_le16u(&ctx->gb);
+ ctx->small_codebook[i] = bytestream2_get_le16u(ctx->gb);
+ hdr->bg_color = bytestream2_get_le16u(ctx->gb);
- bytestream2_skip(&ctx->gb, 2); // skip pad
+ bytestream2_skip(ctx->gb, 2); // skip pad
- hdr->rle_output_size = bytestream2_get_le32u(&ctx->gb);
+ hdr->rle_output_size = bytestream2_get_le32u(ctx->gb);
for (i = 0; i < 256; i++)
- ctx->codebook[i] = bytestream2_get_le16u(&ctx->gb);
+ ctx->codebook[i] = bytestream2_get_le16u(ctx->gb);
- bytestream2_skip(&ctx->gb, 8); // skip pad
+ bytestream2_skip(ctx->gb, 8); // skip pad
return 0;
}
@@ -2114,10 +2114,12 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
int *got_frame_ptr, AVPacket *pkt)
{
SANMVideoContext *ctx = avctx->priv_data;
+ GetByteContext gb;
int i, ret;
ctx->frame = frame;
- bytestream2_init(&ctx->gb, pkt->data, pkt->size);
+ bytestream2_init(&gb, pkt->data, pkt->size);
+ ctx->gb = &gb;
if (!ctx->version) {
int to_store = 0, have_pic = 0;
@@ -2126,15 +2128,15 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
if (ctx->frm0_size)
memset(ctx->frm0, 0, ctx->frm0_size);
- while (bytestream2_get_bytes_left(&ctx->gb) >= 8) {
+ while (bytestream2_get_bytes_left(ctx->gb) >= 8) {
uint32_t sig, size;
int pos;
- sig = bytestream2_get_be32u(&ctx->gb);
- size = bytestream2_get_be32u(&ctx->gb);
- pos = bytestream2_tell(&ctx->gb);
+ sig = bytestream2_get_be32u(ctx->gb);
+ size = bytestream2_get_be32u(ctx->gb);
+ pos = bytestream2_tell(ctx->gb);
- if (bytestream2_get_bytes_left(&ctx->gb) < size) {
+ if (bytestream2_get_bytes_left(ctx->gb) < size) {
av_log(avctx, AV_LOG_ERROR, "Incorrect chunk size %"PRIu32".\n", size);
break;
}
@@ -2146,7 +2148,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
return AVERROR_INVALIDDATA;
}
for (i = 0; i < PALETTE_SIZE; i++)
- ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->gb);
+ ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24u(ctx->gb);
if (ctx->subversion < 2)
ctx->pal[0] = 0xFFU << 24;
break;
@@ -2169,15 +2171,15 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
have_pic = 1;
break;
default:
- bytestream2_skip(&ctx->gb, size);
+ bytestream2_skip(ctx->gb, size);
av_log(avctx, AV_LOG_DEBUG,
"Unknown/unsupported chunk %"PRIx32".\n", sig);
break;
}
- bytestream2_seek(&ctx->gb, pos + size, SEEK_SET);
+ bytestream2_seek(ctx->gb, pos + size, SEEK_SET);
if (size & 1)
- bytestream2_skip(&ctx->gb, 1);
+ bytestream2_skip(ctx->gb, 1);
}
if (to_store)
memcpy(ctx->stored_frame, ctx->frm0, ctx->buf_size);
--
2.48.1
More information about the ffmpeg-devel
mailing list