From patchwork Fri Nov 8 08:55:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manuel Lauss X-Patchwork-Id: 52632 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:2fe5:b0:4a6:1c7:11b7 with SMTP id kw5csp2023985vqb; Fri, 8 Nov 2024 00:55:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUtw4md/RfGd12gYSblm3sAZu0L24hzE2w89AmAiQYs4IOSiGAtjNJ7JiyJ478/VvivxJDfrcL4N6KBXlIvizAI@gmail.com X-Google-Smtp-Source: AGHT+IFdUctaoelB1PNyJ+XJ0a+LOhYO8jODMdYnzadYzbQhfDyF0Z0cAbAoA8kUZL7RWHQKMcBt X-Received: by 2002:ac2:4c53:0:b0:539:f67b:b859 with SMTP id 2adb3069b0e04-53d8627d4d8mr219247e87.4.1731056150287; Fri, 08 Nov 2024 00:55:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731056150; cv=none; d=google.com; s=arc-20240605; b=hwZnrdh57RBwII8WzLSTzeBGmw78mheIQW24+a2Y8X+aEHZriA6Ldp6hdYZrYVpwj/ yKBTcOvc1i4fpPWQRLbZ/6WiN3WkKJdZ3CD7/d2QN77AksAwwxqmObTsay6IWB1nIkQk tayQlV3AGEFipxRZpCOKJgWiN0tzRmDNWKrQLYd0Sw0bRYDxCJzgAv5KJPs+c8wyWCpj NDwu6bg/89yqOsc+lDKeoivyoL9S8amMqAqoVUnwP0jkk5qkn5b00uNdAY+hvZocfcgm /FLUf3WojYuFbj8NKY3aSqeatTfx5gRtN6uP+1SzH8QNxg0oVOO0+xoW5+fN5xwPPQ9Y wX1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=bSJHdfSUwqNW8Q5Zs8bBDNfCqG5ro3F3drQetulGe7E=; fh=ylA7vB/iA8muFUzvlzUImw+rp2ODCCq9hl3kedSTahY=; b=JUEc/s3HiJ39RaPi5jVGSVYHrHC6LZLF2wOoqu4BiLKpLdmjhiBCuRGXfAB0COjyUE nPWq/wqy4GsumEh6bFKbeViiEd/OzFwN/qrrplSTRMyHNJ56yCOlWMhppMzGRVAyORPL 4L+gMtXM5SgRSnBDRy233m95IAtWUbx9DmOOPm0i861j5QKV2AAje0gkglOkeaeoOXbp p6B/rlWknsXcpshVg9eL7Ou+scWdb3/bkbzqk0jFWuAQCb7ChrCgJy2m8SLOHAMRwckK PRACuTMXSA77BQiicCsaEUqMaEyOoa4gLnPgStn9h/PjxDoRCLGXjiLWXvoeA/ZDY3GO u3Ww==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=f9I5X6kz; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTPS id 2adb3069b0e04-53d8268a2bbsi1276070e87.125.2024.11.08.00.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 00:55:50 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=f9I5X6kz; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D8D9168DB1B; Fri, 8 Nov 2024 10:55:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D21CC68DBAF for ; Fri, 8 Nov 2024 10:55:12 +0200 (EET) Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-43155afca99so16923755e9.1 for ; Fri, 08 Nov 2024 00:55:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731056112; x=1731660912; 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=ISOQLHSJyo3by0yoci9VMT9B8Kwb1v7sgbL7CAMZi+A=; b=f9I5X6kzd+YUkgwcIljUnPPRaNl9XHLu/ISAcKFKudoyZThfNcZSHCAXFWl1kvE3o+ SFH4HV2ov8rf7qfILHpRykFLkn31UH6L0k4ZuhcP7vAMyUUTe3vOODJMcL+wK8iSiDHu KUpkzk1wikJvcSm+XdU54A/vWTRL65KWElJDDPnl5iDTFMNND/y1kblLtMzoSEHNpeWt /R3rEIQsFOEvUaCftmXH21vGraf7ivxgLf8jVrrbnktarfiFIaGormFkc946bHaHYEWB zB+leZle0andxXd6fTahqDuvJlOzzBIOFP0Yrt1MRPHRp+81X2/BZPqLPBDHGiEcV87H R9NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731056112; x=1731660912; 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=ISOQLHSJyo3by0yoci9VMT9B8Kwb1v7sgbL7CAMZi+A=; b=E5AvCaYV0fE1VtJfxr7sXIfM5euqxWb+Wyx9/lDEdQzw1EGv9BapQK8jIM0wc2DHmf gyA+i0oIl7bzia7oBKpQTXD3JrMbj0sJxdMA+IlBum7G9OkyyfNd6l9ufisG+rvvDe4s wvfn7zP1rwMzcvWzjnk6uj4IbNNKQoO8aYt7Bft4lG8KuKp3/t97bk8Hnba7xQCFEXD1 +KvLISE3+3mLKLuJ9HxkYHa/duwMQKDb+FDyTIcYdNun8JAplu2UnJeLGAYNq54hy3SA M4FsabDL7D0T/fgTTxc4ri71M+iCao5r2YMAAfIGp+v/aj34WoOcz9RyjlEOOY1cJCu9 z/pw== X-Gm-Message-State: AOJu0Yz5/CLpeHl06LJMvCaTU8tDl2BZ6TWGwfovlzHxzyrpA1Z+LZGJ P+81+rgKxv1ev+VLomCC/UNVjfhRkzehLsAOJnBXg/aXaLTMZII5DbxVeA== X-Received: by 2002:a05:600c:4fc3:b0:42c:baf1:4c7 with SMTP id 5b1f17b1804b1-432b6858e60mr20005345e9.4.1731056112022; Fri, 08 Nov 2024 00:55:12 -0800 (PST) Received: from flagship3.deu.mlau.at (p200300c0270310006fc1140db6601414.dip0.t-ipconnect.de. [2003:c0:2703:1000:6fc1:140d:b660:1414]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381ed987d95sm4002722f8f.44.2024.11.08.00.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 00:55:11 -0800 (PST) From: Manuel Lauss To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Nov 2024 09:55:04 +0100 Message-ID: <20241108085504.351017-3-manuel.lauss@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241108085504.351017-1-manuel.lauss@gmail.com> References: <20241108085504.351017-1-manuel.lauss@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] libavcodec/sanm: fix XPAL handling 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: bMGRGDr+QMc9 Outlaws' RAE.SAN file did not properly fade out in certain scenes, but simply turned to black as soon as the first XPAL chunk with the apply command was encountered. Signed-off-by: Manuel Lauss --- libavcodec/sanm.c | 69 ++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c index 022d4b347e..936746ace4 100644 --- a/libavcodec/sanm.c +++ b/libavcodec/sanm.c @@ -1033,6 +1033,45 @@ static int process_frame_obj(SANMVideoContext *ctx) } } +static int process_xpal(SANMVideoContext *ctx, int size) +{ + int16_t *dp = ctx->delta_pal; + uint32_t *pal = ctx->pal; + uint16_t cmd; + uint8_t c[3]; + int i, j; + + bytestream2_skip(&ctx->gb, 2); + cmd = bytestream2_get_be16(&ctx->gb); + + if (cmd == 1) { + for (i = 0; i < PALETTE_DELTA; i += 3) { + c[0] = (*pal >> 16) & 0xFF; + c[1] = (*pal >> 8) & 0xFF; + c[2] = (*pal >> 0) & 0xFF; + for (j = 0; j < 3; j++) { + int cl = (c[j] * 129) + *dp++; + c[j] = av_clip_uint8(cl / 128) & 0xFF; + } + *pal++ = 0xFFU << 24 | c[0] << 16 | c[1] << 8 | c[2]; + } + } else if (cmd == 2) { + if (size < PALETTE_DELTA * 2 + 4) { + av_log(ctx->avctx, AV_LOG_ERROR, + "Incorrect palette change block size %"PRIu32".\n", size); + return AVERROR_INVALIDDATA; + } + for (i = 0; i < PALETTE_DELTA; i++) + dp[i] = bytestream2_get_le16u(&ctx->gb); + + 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); + } + } + return 0; +} + static int decode_0(SANMVideoContext *ctx) { uint16_t *frm = ctx->frm0; @@ -1472,34 +1511,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame, return ret; break; case MKBETAG('X', 'P', 'A', 'L'): - if (size == 6 || size == 4) { - uint8_t tmp[3]; - int j; - - for (i = 0; i < PALETTE_SIZE; i++) { - for (j = 0; j < 3; j++) { - int t = (ctx->pal[i] >> (16 - j * 8)) & 0xFF; - tmp[j] = av_clip_uint8((t * 129 + ctx->delta_pal[i * 3 + j]) >> 7); - } - ctx->pal[i] = 0xFFU << 24 | AV_RB24(tmp); - } - } else { - if (size < PALETTE_DELTA * 2 + 4) { - av_log(avctx, AV_LOG_ERROR, - "Incorrect palette change block size %"PRIu32".\n", - size); - return AVERROR_INVALIDDATA; - } - bytestream2_skipu(&ctx->gb, 4); - for (i = 0; i < PALETTE_DELTA; i++) - ctx->delta_pal[i] = bytestream2_get_le16u(&ctx->gb); - if (size >= PALETTE_DELTA * 5 + 4) { - for (i = 0; i < PALETTE_SIZE; i++) - ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->gb); - } else { - memset(ctx->pal, 0, sizeof(ctx->pal)); - } - } + if (ret = process_xpal(ctx, size)) + return ret; break; case MKBETAG('S', 'T', 'O', 'R'): to_store = 1;