From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id DABC44D0D7 for ; Mon, 17 Feb 2025 13:26:01 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 97B6C68BFFA; Mon, 17 Feb 2025 15:25:35 +0200 (EET) Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 674CC68BBD3 for ; Mon, 17 Feb 2025 15:25:28 +0200 (EET) Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5deb1266031so7626523a12.2 for ; Mon, 17 Feb 2025 05:25:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739798728; x=1740403528; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wxJIKEVci9DH4rFlcNC0yHwVtjt0sFhL+NTw68Dgx2M=; b=lmfv96vTfl6O5lan2WbXwp2HbCuanokR5ApDzats4GQZ9o2o880kgUce22HjuOmN3r +AK6H9oTg0X+CvWiRl/MR7BEgnd13HwKWxhokMYQ3ByHdgwA3mxXt/8b12D9hGZbhziW XdHiQFc0iR7o5qNlB+Le+FpK2G9iswp29TsUMhzlP3cuBPI21boGcZihhGDkVnulrOOu ZJzKYuBsuaw4VUEqOJxqQiAGi6AoKnJXkvfrAOgYdhGjekfcONd+UQMETfjRfvhvNh8K ffXdEFFOWD9jcYKfSFoByS7i/ylTNYdMuo+vMi6UNKnLWDABNu49CcvqDv6hNd/uVSZk HW8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739798728; x=1740403528; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wxJIKEVci9DH4rFlcNC0yHwVtjt0sFhL+NTw68Dgx2M=; b=lLhrtWk5+3oPJvCP6StK2eEUD6vywofv/J1oB8hpkb9Jdk5WfEFh9+5WHr9iVwpybR 9iKTnhrSoNoNo/P2eIFHKQyoSFFmA3bSQbt9hzh+ldWHjWgqZNDxBUzv04JugFpsOXqM Vf4zO31Tz5fHz1Jtx4Cq88z2BE+4vYZFD2db4kjbOEOyd6AVYEX5cmMf2MgOHc0GJoKx JR3ocl8wVX3X0PfUdNJL3eaJyXFNCk/W9SyIoKxyAP5y16k7K0u0bu1WmO6rpBPhGKdC wq1I0IoDW7+npS31aabrML5PUSAatZbjN23dhvrkJ2OJYB0p1N4VseAZjzkzv1FauXiB SBbQ== X-Gm-Message-State: AOJu0Yw+TAb5yeLW8hhp/YZ6U+tQfpWJ0VwtN7YvcqIJF8vNnwXi6qMn +lGtVEe3b3jlhrSn8+DGcU/I+j0tPpwaQMvCIPNfxIpZqzlJKr8bOaE+gw== X-Gm-Gg: ASbGncvp7wnOdQTUl3ue3UeAHaY/xV75ijb+zG0sSyCDZlbp8ZI/t81z5FSDIxUXf5f DP1WaT6HQfaWC+WXBpERuRohC4QLnvz4ZURHj+jim1TpysNUiIO7vr9yBMUaDwP2kbn5Azl16gH n6b8x8kgW/ntdyVEOJ+lhyDE8bTuTzCKfciQhrdO6qzqSlQYPGsft1tN0Wy8Hy6yBSuQSvmMBZi FzSyDkgTHsqGOQLdJPnYPCbry9MjNmmLBmnfGI2bX5Myw47AHVCFSIacW1D9e3ezaPki6hnrDzh p45shDCXMwPae1Z6BAhU3DikeVEyUBSJJE0PuKS2KO2IaP1QUGzIBwAgPEKUZbcBRSa1OXWrGBK RRde4oLQ2/ZJe4zgiQIswzey2Pw== X-Google-Smtp-Source: AGHT+IHio6gDLsadoKMjvaXc/W8Lse/Qp3iOwdCb40h1GSOY5Wau/n9ix8ZHxWqPCFh+K+i64G3M/Q== X-Received: by 2002:a05:6402:13cb:b0:5de:a7db:3a7c with SMTP id 4fb4d7f45d1cf-5e03610c9bamr9091901a12.17.1739798727428; Mon, 17 Feb 2025 05:25:27 -0800 (PST) Received: from flagship3.deu.mlau.at (p200300c0271f29004c5623f045c27bca.dip0.t-ipconnect.de. [2003:c0:271f:2900:4c56:23f0:45c2:7bca]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dece1c46b3sm7283436a12.21.2025.02.17.05.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 05:25:26 -0800 (PST) From: Manuel Lauss To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Feb 2025 14:25:22 +0100 Message-ID: <20250217132522.829177-3-manuel.lauss@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250217132522.829177-1-manuel.lauss@gmail.com> References: <20250217132522.829177-1-manuel.lauss@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 3/3] avcodec/sanm: add smush codec23 decoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Manuel Lauss Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: This codec alternatingly skips and changes existing pixels. A second 16bit parameter in the FOBJ header indicates how to do the pixel changes: either by specifying a LUT in the codec datastream or by adding a constant value to the pixel. Signed-off-by: Manuel Lauss --- v3: updates due to changes in patch 2 v2: no changes. Videos showing the before/after state (Rebel Assault II LEV09/09PLAY.SAN file) http://mlau.at/ffmpeg_c23_before.mp4 http://mlau.at/ffmpeg_c23_after.mp4 notice the blue transparent forcefields. libavcodec/sanm.c | 62 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c index 5ea742c997..cdc67df0cb 100644 --- a/libavcodec/sanm.c +++ b/libavcodec/sanm.c @@ -292,6 +292,7 @@ typedef struct SANMVideoContext { int8_t p4x4glyphs[NGLYPHS][16]; int8_t p8x8glyphs[NGLYPHS][64]; uint8_t c47itbl[0x10000]; + uint8_t c23lut[256]; } SANMVideoContext; typedef struct SANMFrameHeader { @@ -555,6 +556,58 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t *dst, const int out_size) return 0; } +static int old_codec23(SANMVideoContext *ctx, int top, int left, int width, + int height, uint8_t param, uint16_t param2) +{ + const uint32_t maxpxo = ctx->width * ctx->pitch; + uint8_t *dst, lut[256], c; + int i, j, k, pc, sk; + int32_t pxoff; + + if (param2 == 256) { + if (bytestream2_get_bytes_left(&ctx->gb) < 256) + return AVERROR_INVALIDDATA; + 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) + 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) + return 0; + pxoff = left + ((top + i) * ctx->pitch); + k = bytestream2_get_le16u(&ctx->gb); + sk = 1; + pc = 0; + while (k > 0 && pc <= width) { + if (bytestream2_get_bytes_left(&ctx->gb) < 1) + return AVERROR_INVALIDDATA; + j = bytestream2_get_byteu(&ctx->gb); + if (sk) { + pxoff += j; + pc += j; + } else { + while (j--) { + if (pxoff >=0 && pxoff < maxpxo) { + c = *(dst + pxoff); + *(dst + pxoff) = lut[c]; + } + pxoff++; + pc++; + } + } + sk ^= 1; + } + } + return 0; +} + static int old_codec1(SANMVideoContext *ctx, int top, int left, int width, int height) { @@ -1237,11 +1290,15 @@ static int old_codec48(SANMVideoContext *ctx, int width, int height) static int process_frame_obj(SANMVideoContext *ctx) { - uint16_t codec = bytestream2_get_le16u(&ctx->gb); + uint16_t parm2; + uint8_t codec = bytestream2_get_byteu(&ctx->gb); + uint8_t param = bytestream2_get_byteu(&ctx->gb); int16_t left = bytestream2_get_le16(&ctx->gb); int16_t top = bytestream2_get_le16(&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 || !h) { av_log(ctx->avctx, AV_LOG_ERROR, "Dimensions are invalid.\n"); @@ -1260,12 +1317,13 @@ static int process_frame_obj(SANMVideoContext *ctx) return AVERROR(ENOMEM); } } - bytestream2_skip(&ctx->gb, 4); switch (codec) { case 1: case 3: return old_codec1(ctx, top, left, w, h); + case 23: + return old_codec23(ctx, top, left, w, h, param, parm2); case 37: return old_codec37(ctx, top, left, w, h); case 47: -- 2.48.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-request@ffmpeg.org with subject "unsubscribe".