[FFmpeg-devel] [PATCH 6/9] avcodec/sanm: misc fixes

Manuel Lauss manuel.lauss at gmail.com
Tue Mar 11 17:03:38 EET 2025


- clear the front buffer with color 0 when a new frame starts.
  Fixes a lot of Rebel Assault 1 videos and Rebel Assault 2 space
  scenes (e.g. 08PLAY.SAN which consists only of codec1+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 unwanted colors in e.g L1HANGAR.ANM, L2INTRO.ANM,
  a space scenes.

Signed-off-by: Manuel Lauss <manuel.lauss at gmail.com>
---
 libavcodec/sanm.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 310b1a429b..efed31b70c 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -1350,6 +1350,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] = 0;
         }
     }
     return 0;
@@ -1765,6 +1767,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if (!ctx->version) {
         int to_store = 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;
             int pos;
@@ -1786,6 +1792,8 @@ 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] = 0;
                 break;
             case MKBETAG('F', 'O', 'B', 'J'):
                 if (size < 16)
-- 
2.48.1



More information about the ffmpeg-devel mailing list