From patchwork Fri Nov 8 08:55:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manuel Lauss X-Patchwork-Id: 52633 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:2fe5:b0:4a6:1c7:11b7 with SMTP id kw5csp2029688vqb; Fri, 8 Nov 2024 01:06:12 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV7GjOchuPiMtzuiMNQ/9w/Y3GbVVk4Pz3vn8LI6xH3i9a89qcmMat4oHS7e3MIZInvn/i8EQCyq3bvwyh4Qs2h@gmail.com X-Google-Smtp-Source: AGHT+IFKBpv7Sc4ATaMAJpvoOdN1mbwJvKfvNm7OF6eYBcAtw4O7LikGU2cj4TTiQZKbgTgy9mkl X-Received: by 2002:a17:907:2d8b:b0:a99:f3a5:a310 with SMTP id a640c23a62f3a-a9eefee1e70mr76561866b.4.1731056772149; Fri, 08 Nov 2024 01:06:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731056772; cv=none; d=google.com; s=arc-20240605; b=gqBM+Ty1vauNjITUdzlwsqWhzVxTb9Jsvd27Tp9ZO3M3d85aGaGNKXlMoVgJnmLJN4 Ck+kxvOicEzLRaVzsPWe5oA1krJjm9STsRcTmBNtGw29x3oOkMsEy+Eo3gCShmIIx6v3 VrYZftuH3TlKkZueZ6EtuVzVmIdIr8RBrp8QUvoJbSCcKbeFGdjExrhnMW5EO3CccjOW qrcZu4jKQRq7lVH5okBO+tO7ojSzQFOqBxwuGP4XzyOKyenkTHfs/mFX3TvyGZ98c3hb Ov9Vx0pqwsD4nVRiIHpKvlUTnsHX0mIiVWYKGTNX/T7AygyWPG/ygchy29GXm67d/cv9 QmAQ== 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=YHJVeE/49DvYiPMEebZnc2SZldI7EBrFHzZIx/jQ2xM=; fh=ylA7vB/iA8muFUzvlzUImw+rp2ODCCq9hl3kedSTahY=; b=JbeXrsLJ12y86OlHWQHWPN7pARwqgoqzmyU+Dsilgn2uYhKl+PQPtyjaX9ezq7GC+4 vcJ4ZitfYs7AO616cn2fFlzN/ITTTtR7zA7chhlbYy96jHfM6IR/Z8rbxbRRCpqCOjMX oJoS6CAy9kkj3mw9HkrfSkIsYRlVfS8DuLa5hKx3Ha2n2fBzy9Trh3O9OMLDXFc7JAnd lj++1QpKoP6FaFeECDqrIxxJOVpdmD6u1gFQhnq8v8KJR5JbTbe7++BdSttrc7igRf1S AGaCEh4q14QQEMNirI8LApREKFTm7sfU2JZlsYPqGbX9qxDgSggQiR43RjsQAq4Jw45/ aF2A==; 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=GNDrxPpv; 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 a640c23a62f3a-a9ee0dc1d4dsi206869666b.268.2024.11.08.01.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 01:06:12 -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=GNDrxPpv; 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 B4B0C68DDC2; Fri, 8 Nov 2024 10:55:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 023DD68DBD2 for ; Fri, 8 Nov 2024 10:55:11 +0200 (EET) Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-37d5689eea8so1155965f8f.1 for ; Fri, 08 Nov 2024 00:55:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731056111; x=1731660911; 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=RekrdkHJlXBcEleuBsJ/TyzxoFhCRFU1T2xUvuL0ZPw=; b=GNDrxPpv/MSRZmn3rt2n3Z+n8iCwNYHGNCC7vdMZLf7UO0OsOUMQlm+2y0V2v1OmZs 6XaV0H4F5aW7o/KHfSoN6wvU4yY2D6vrzJUfRAL/JY3++SM8SVL807i3GwCP7Z5bnc/v +hL/qh8fKJxyzi8p3yP7xKgy2Sg91gRPXxCR7DeX2zkTeIucXCScu10r9aC3T6T6lDbz vei2ZjhuRri2E7cXXwaM7PZ12ldK+Ltd0rqrKwYVBcJKFrcExkhUsFyOftcgtitffQyz 3pClVxMkhz3E+4riBMkJpKEFikfcyMugvBN9zBKhbjNNi42VDeBiZYu/EIxh98+F0sO8 GNTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731056111; x=1731660911; 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=RekrdkHJlXBcEleuBsJ/TyzxoFhCRFU1T2xUvuL0ZPw=; b=pMjmQ1I0giAGaer2Bisz5C43nTunwIKOm2w4372VdJ1hgMt7rvCfB3uULtfbyrVeTs EkCanJAkdiyVt1LY/vD2aF789kz6X9W9neAeUZ9gcjisua0s+RnlW31Mod6j5ztEZnQs xHM1LPFFilC2y5epefp6HML0Sz+b+tYG2jdOdFsuNM3KiDlXhyWpj2yS9frr513otCVS //b2K6E3jYiq2iB26KUl5dzrRAMhBhfNNcrdqRKMqIVIDTKLxzFATd0vsmFKNXw5TPyS nPcIOdr5BKF2zErLBRZ5LVXtClgs1Mc6EiopLqGT5hYwQt9+StyDZTUsnS8lTY3th7gS 1aZw== X-Gm-Message-State: AOJu0YyX9vsWMUMH6XO9sC43XOiDA+UA2wlA3+GqMCEXpr974X8B83/S chZerINjeH09Am9Ybdd12p7F7Ld6AfHKKgzR9qNfOHyWwNNFo+BXPAxyeQ== X-Received: by 2002:a05:6000:1f8f:b0:37d:52b5:451e with SMTP id ffacd0b85a97d-381f186fc20mr1591470f8f.33.1731056111079; Fri, 08 Nov 2024 00:55:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 00:55:10 -0800 (PST) From: Manuel Lauss To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Nov 2024 09:55:03 +0100 Message-ID: <20241108085504.351017-2-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 1/2] libavcodec/sanm: add codec47 interpolation table support 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: ErOsuLPGBId0 Some codec47 frames come with an interpolation table: Combining 2 adjacent pixels into a 16bit value, this value can then be used as index into the interpolation table to get a new pixel value. This is used for subcodec 1, which encodes a key- frame at half width and height, and makes these frame less blocky appearing. Signed-off-by: Manuel Lauss --- libavcodec/sanm.c | 67 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c index 8b7c0d9556..022d4b347e 100644 --- a/libavcodec/sanm.c +++ b/libavcodec/sanm.c @@ -291,6 +291,7 @@ typedef struct SANMVideoContext { int8_t p4x4glyphs[NGLYPHS][16]; int8_t p8x8glyphs[NGLYPHS][64]; + uint8_t c47itbl[0x10000]; } SANMVideoContext; typedef struct SANMFrameHeader { @@ -856,6 +857,55 @@ static int process_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *prev1, return 0; } +static void codec47_read_interptable(SANMVideoContext *ctx) +{ + uint8_t *p1, *p2, *itbl = ctx->c47itbl; + int i, j; + + for (i = 0; i < 256; i++) { + p1 = p2 = itbl + i; + for (j = 256 - i; j; j--) { + *p1 = *p2 = bytestream2_get_byte(&ctx->gb); + p1 += 1; + p2 += 256; + } + itbl += 256; + } +} + +static void codec47_comp1(SANMVideoContext *ctx, uint8_t *dst_in, int width, + int height, ptrdiff_t stride) +{ + uint8_t p1, *dst, *itbl = ctx->c47itbl; + uint16_t px; + int i, j; + + dst = dst_in + stride; + for (i = 0; i < height; i += 2) { + p1 = bytestream2_get_byte(&ctx->gb); + *dst++ = p1; + *dst++ = p1; + px = p1; + for (j = 2; j < width; j += 2) { + p1 = bytestream2_get_byte(&ctx->gb); + px = (px << 8) | p1; + *dst++ = itbl[px]; + *dst++ = p1; + } + dst += stride; + } + + memcpy(dst_in, dst_in + stride, width); + dst = dst_in + stride + stride; + for (i = 2; i < height - 1; i += 2) { + for (j = 0; j < width; j++) { + px = (*(dst - stride) << 8) | *(dst + stride); + *dst++ = itbl[px]; + } + dst += stride; + } +} + static int old_codec47(SANMVideoContext *ctx, int top, int left, int width, int height) { @@ -880,8 +930,11 @@ static int old_codec47(SANMVideoContext *ctx, int top, av_log(ctx->avctx, AV_LOG_WARNING, "Decoded size is too large.\n"); } - if (skip & 1) - bytestream2_skip(&ctx->gb, 0x8080); + if (skip & 1) { + if (bytestream2_get_bytes_left(&ctx->gb) < 0x8080) + return AVERROR_INVALIDDATA; + codec47_read_interptable(ctx); + } if (!seq) { ctx->prev_seq = -1; memset(prev1, 0, ctx->height * stride); @@ -900,15 +953,7 @@ static int old_codec47(SANMVideoContext *ctx, int top, case 1: if (bytestream2_get_bytes_left(&ctx->gb) < ((width + 1) >> 1) * ((height + 1) >> 1)) return AVERROR_INVALIDDATA; - for (j = 0; j < height; j += 2) { - for (i = 0; i < width; i += 2) { - dst[i] = - dst[i + 1] = - dst[stride + i] = - dst[stride + i + 1] = bytestream2_get_byteu(&ctx->gb); - } - dst += stride * 2; - } + codec47_comp1(ctx, dst, width, height, stride); break; case 2: if (seq == ctx->prev_seq + 1) {