On Mon, 13 Jan 2025, Manuel Lauss wrote:

codec37 operates on 2 buffers, which must be considered private to
the codec and must therefore not be changed by subsequent FOBJs.

Let codec37 therefore operate on frm1/2 instead of frm0/2, but copy
the decoded image to frm0 where other codecs operate on.

Fixes artifacts encountered in Full Throttle "dazed.san" and also
in a lot of Rebel Assault II gameplay videos: these videos consist of
frames with an initial codec37 FOBJ image to set the stage, and
optional codec1-23 FOBJs overlaid on top of that image.

Signed-off-by: Manuel Lauss <manuel.la...@gmail.com>
---
Applies on top of my previous patch "avcodec/sanm: simplify codec37 subcodec 3/4 
path"

libavcodec/sanm.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 51b8a2f54c..5bbfd5de8c 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -645,10 +645,13 @@ static int old_codec37(SANMVideoContext *ctx, int top,

    ctx->rotate_code = 0;

-    if (((seq & 1) || !(flags & 1)) && (compr && compr != 2))
-        rotate_bufs(ctx, 1);
+    if (((seq & 1) || !(flags & 1)) && (compr && compr != 2)) {
+        void *tmp = ctx->frm1;
+        ctx->frm1 = ctx->frm2;
+        ctx->frm2 = tmp;

FFSWAP?

Thanks,
Marton

+    }

-    dst  = ((uint8_t*)ctx->frm0) + left + top * stride;
+    dst  = ((uint8_t*)ctx->frm1) + left + top * stride;
    prev = ((uint8_t*)ctx->frm2) + left + top * stride;

    if (mvoff > 2) {
@@ -662,7 +665,6 @@ static int old_codec37(SANMVideoContext *ctx, int top,
            bytestream2_get_buffer(&ctx->gb, dst, width);
            dst += stride;
        }
-        memset(ctx->frm1, 0, ctx->height * stride);
        memset(ctx->frm2, 0, ctx->height * stride);
        break;
    case 1:
@@ -729,7 +731,6 @@ static int old_codec37(SANMVideoContext *ctx, int top,
    case 2:
        if (rle_decode(ctx, dst, decoded_size))
            return AVERROR_INVALIDDATA;
-        memset(ctx->frm1, 0, ctx->frm1_size);
        memset(ctx->frm2, 0, ctx->frm2_size);
        break;
    case 3:
@@ -783,6 +784,7 @@ static int old_codec37(SANMVideoContext *ctx, int top,
        return AVERROR_PATCHWELCOME;
    }

+    memcpy(ctx->frm0, ctx->frm1, ctx->buf_size);
    return 0;
}

--
2.47.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to