[FFmpeg-devel] [PATCH v2 05/13] avcodec/sanm: fix codec3

Manuel Lauss manuel.lauss at gmail.com
Sat Mar 15 11:32:12 EET 2025


codec3 is codec1 which writes zero values instead of skipping them.
This fixes a lot of RA1 videos.

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

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 069bc0400a..0c8ca73508 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -558,7 +558,7 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t *dst, const int out_size)
 }
 
 static int old_codec1(SANMVideoContext *ctx, int top,
-                      int left, int width, int height)
+                      int left, int width, int height, int opaque)
 {
     int i, j, len, flag, code, val, end, pxoff;
     const int maxpxo = ctx->height * ctx->pitch;
@@ -581,7 +581,7 @@ static int old_codec1(SANMVideoContext *ctx, int top,
             code = (code >> 1) + 1;
             if (flag) {
                 val = bytestream2_get_byteu(&ctx->gb);
-                if (val) {
+                if (val || opaque) {
                     for (j = 0; j < code; j++) {
                         if (pxoff >= 0 && pxoff < maxpxo)
                             *(dst + pxoff) = val;
@@ -595,7 +595,7 @@ static int old_codec1(SANMVideoContext *ctx, int top,
                     return AVERROR_INVALIDDATA;
                 for (j = 0; j < code; j++) {
                     val = bytestream2_get_byteu(&ctx->gb);
-                    if ((pxoff >= 0) && (pxoff < maxpxo) && val)
+                    if ((pxoff >= 0) && (pxoff < maxpxo) && (val || opaque))
                         *(dst + pxoff) = val;
                     pxoff++;
                 }
@@ -1312,7 +1312,7 @@ static int process_frame_obj(SANMVideoContext *ctx)
     switch (codec) {
     case 1:
     case 3:
-        return old_codec1(ctx, top, left, w, h);
+        return old_codec1(ctx, top, left, w, h, codec == 3);
     case 37:
         return old_codec37(ctx, w, h);
     case 47:
-- 
2.48.1



More information about the ffmpeg-devel mailing list