[FFmpeg-devel] [PATCH 04/12] avcodec/sanm: misc fixes
Manuel Lauss
manuel.lauss at gmail.com
Thu Mar 13 13:14:57 EET 2025
- clear the front buffer with color 0 when processing data.
Fixes a lot of Rebel Assault 1 videos and Rebel Assault 2 space
scenes (e.g. 08PLAY.SAN which consists only of codec1/2/21 objects
which only ever touch parts of the buffer).
- for ANIMv1 (Rebel Assault 1): set palette index 0 to all zeroes.
This fixes a lot of stray colors in e.g L1HANGAR.ANM, L2INTRO.ANM,
space scenes.
- Esp in RA1, there are a lot of FRME objects which don't contain
any video data (prebuffering some audio only). Account for that.
Signed-off-by: Manuel Lauss <manuel.lauss at gmail.com>
---
libavcodec/sanm.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 9f656e6ba8..fbb6e7231a 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -515,6 +515,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
ctx->subversion = AV_RL16(avctx->extradata);
for (i = 0; i < PALETTE_SIZE; i++)
ctx->pal[i] = 0xFFU << 24 | AV_RL32(avctx->extradata + 2 + i * 4);
+ if (ctx->subversion < 2)
+ ctx->pal[0] = 0xFFU << 24;
}
return 0;
@@ -1349,6 +1351,8 @@ static int process_xpal(SANMVideoContext *ctx, int size)
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);
+ if (ctx->subversion < 2)
+ ctx->pal[0] = 0xFFU << 24;
}
}
return 0;
@@ -1762,7 +1766,11 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
bytestream2_init(&ctx->gb, pkt->data, pkt->size);
if (!ctx->version) {
- int to_store = 0;
+ int to_store = 0, have_pic = 0;
+
+ /* clear the front buffer */
+ if (ctx->frm0_size)
+ memset(ctx->frm0, 0, ctx->frm0_size);
while (bytestream2_get_bytes_left(&ctx->gb) >= 8) {
uint32_t sig, size;
@@ -1785,12 +1793,15 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
}
for (i = 0; i < PALETTE_SIZE; i++)
ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->gb);
+ if (ctx->subversion < 2)
+ ctx->pal[0] = 0xFFU << 24;
break;
case MKBETAG('F', 'O', 'B', 'J'):
if (size < 16)
return AVERROR_INVALIDDATA;
if (ret = process_frame_obj(ctx))
return ret;
+ have_pic = 1;
break;
case MKBETAG('X', 'P', 'A', 'L'):
if (ret = process_xpal(ctx, size))
@@ -1801,6 +1812,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
break;
case MKBETAG('F', 'T', 'C', 'H'):
memcpy(ctx->frm0, ctx->stored_frame, ctx->buf_size);
+ have_pic = 1;
break;
default:
bytestream2_skip(&ctx->gb, size);
@@ -1815,9 +1827,13 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
}
if (to_store)
memcpy(ctx->stored_frame, ctx->frm0, ctx->buf_size);
- if ((ret = copy_output(ctx, NULL)))
- return ret;
- memcpy(ctx->frame->data[1], ctx->pal, 1024);
+
+ if (have_pic && ctx->have_dimensions) {
+ if ((ret = copy_output(ctx, NULL)))
+ return ret;
+ memcpy(ctx->frame->data[1], ctx->pal, 1024);
+ *got_frame_ptr = 1;
+ }
} else {
SANMFrameHeader header;
@@ -1848,12 +1864,13 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
if ((ret = copy_output(ctx, &header)))
return ret;
+
+ *got_frame_ptr = 1;
+
}
if (ctx->rotate_code)
rotate_bufs(ctx, ctx->rotate_code);
- *got_frame_ptr = 1;
-
return pkt->size;
}
--
2.48.1
More information about the ffmpeg-devel
mailing list