From patchwork Mon Dec 11 01:35:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 45032 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp2651709pzf; Sun, 10 Dec 2023 17:45:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvd2TTpd+Drif6HXjD1IcoPeYXGqtNdakCXn5ozK5QVq3lGyECQLsGkaM+886D2B2nuMzJ X-Received: by 2002:a17:907:270f:b0:a1e:a558:748c with SMTP id w15-20020a170907270f00b00a1ea558748cmr4293684ejk.18.1702259135191; Sun, 10 Dec 2023 17:45:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702259135; cv=none; d=google.com; s=arc-20160816; b=PF292sGYMLEDFDRjitj0S8xNPO+tgUTilvH50W5Yj8rDW76xkIT05MNYnF/xTh/mXl UUZ/CY3NKPmAG7ZkG6WnjeIZS4ZrmFCS8xMhIaw1XTfziWfjGFRIVybyTvaXGsVij49Q Vsp/hdiV6fj9N46ti6ThaedN3fqyfpLWlB00x2rlsC+xU744XY/yEhhs1dKbqE4WCbWI UtJ9KutfpP9R2dT6CnVs/rQxZgzOHLADnwRoz1pvwyJ0LegIQGn27+EW58jUkokcmaJ8 VNZIWesmHpWaUEJ2uvHK7sP8/qaiTq/Nng+py8HzBvOp0D3fQf/GN4p5ISUvoI8P7LhO h/XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=u7CzGLsiq0e6/7Dtrzu1GOt6l7r9OjyFWo0miBuuOQI=; fh=Jgo3TCyoG8OdFLqA8BuM7Wbf1w27210JU6p+E8x39/M=; b=dcK1uexJ8Uq+Ga73zOntrjaKaHkvRuUDOC9omTQPCZd0rugHShDJfjW0qyTu1fkerR jaf5x+8TVkJIxMOmtgG36KmT/kcjdIolVQ5cV4ye2iuyYb3C7iHGcJh/r5LR6GKRyI2P L7+xfcsI/huA7AdGJncZyF0SWKxyFd3oSFPXyoXUMzEXdtX2vhxH1hgjrqw21nGoGrh9 +W50y4Okrdvvd4+KdqdtOm3bHlVCwwCMC4uOz8mhEXjSOGiwOl76dsW6NrH5FjJpw1ey 7A+sJ10wts9QJ6RZfCvCUWIgcNHl41f8ZifRjXRsc8AFukF767S1gMvY/0ZguQGjJR6z 3IvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b="DizY/7Hv"; 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=NONE dis=NONE) header.from=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c22-20020a170906695600b00a1da2f7c1dcsi3221857ejs.359.2023.12.10.17.45.34; Sun, 10 Dec 2023 17:45:35 -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=@pkh.me header.s=selector1 header.b="DizY/7Hv"; 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=NONE dis=NONE) header.from=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2789568D16A; Mon, 11 Dec 2023 03:44:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 738D968D14F for ; Mon, 11 Dec 2023 03:44:50 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1702259075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G/1WDgcIIqwm0zm9Ty7gic5tFUM3whHMLHF+QkKVvx0=; b=DizY/7HvApTRU/P6npmSub/X5ItboueLvmGQ8WItULsPN8H9hXmnaP+DUdtLdLo4OylMns q+maMXmYNn5LVb9sNw11Ns8f3zIA5bDu/4qn4GuTNqI7k4kLrPQCtRglktGjrC/RBHvJ4A /GCwMDGT7Y/XJZDHFaImi3bpUU6Fm+U= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id 6a62d949; Mon, 11 Dec 2023 01:44:35 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 11 Dec 2023 02:35:06 +0100 Message-ID: <20231211014429.1841681-6-u@pkh.me> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231211014429.1841681-1-u@pkh.me> References: <20231211014429.1841681-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/35] avcodec/proresenc_kostya: remove one LUT indirection for run/level to codebook mapping 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 7e6EXO6iIDUI This is following the same logic as proresenc_anatoliy. --- libavcodec/proresenc_kostya.c | 47 +++++++++++------------------------ 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c index 6e1d5a0cef..f883ab550b 100644 --- a/libavcodec/proresenc_kostya.c +++ b/libavcodec/proresenc_kostya.c @@ -142,25 +142,6 @@ static const uint8_t prores_dc_codebook[4] = { 0x70 // rice_order = 3, exp_golomb_order = 4, switch_bits = 0 }; -static const uint8_t prores_ac_codebook[7] = { - 0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0 - 0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0 - 0x4C, // rice_order = 2, exp_golomb_order = 3, switch_bits = 0 - 0x05, // rice_order = 0, exp_golomb_order = 1, switch_bits = 1 - 0x29, // rice_order = 1, exp_golomb_order = 2, switch_bits = 1 - 0x06, // rice_order = 0, exp_golomb_order = 1, switch_bits = 2 - 0x0A, // rice_order = 0, exp_golomb_order = 2, switch_bits = 2 -}; - -/** - * Lookup tables for adaptive switching between codebooks - * according with previous run/level value. - */ -static const uint8_t prores_run_to_cb_index[16] = - { 5, 5, 3, 3, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 2 }; - -static const uint8_t prores_lev_to_cb_index[10] = { 0, 6, 3, 5, 0, 1, 1, 1, 1, 2 }; - #define NUM_MB_LIMITS 4 static const int prores_mb_limits[NUM_MB_LIMITS] = { 1620, // up to 720x576 @@ -461,12 +442,12 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, const uint8_t *scan, const int16_t *qmat) { int idx, i; - int run, level, run_cb, lev_cb; + int prev_run = 4; + int prev_level = 2; + int run, level; int max_coeffs, abs_level; max_coeffs = blocks_per_slice << 6; - run_cb = prores_run_to_cb_index[4]; - lev_cb = prores_lev_to_cb_index[2]; run = 0; for (i = 1; i < 64; i++) { @@ -474,13 +455,13 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, level = blocks[idx] / qmat[scan[i]]; if (level) { abs_level = FFABS(level); - encode_vlc_codeword(pb, prores_ac_codebook[run_cb], run); - encode_vlc_codeword(pb, prores_ac_codebook[lev_cb], + encode_vlc_codeword(pb, ff_prores_run_to_cb[prev_run], run); + encode_vlc_codeword(pb, ff_prores_lev_to_cb[prev_level], abs_level - 1); put_sbits(pb, 1, GET_SIGN(level)); - run_cb = prores_run_to_cb_index[FFMIN(run, 15)]; - lev_cb = prores_lev_to_cb_index[FFMIN(abs_level, 9)]; + prev_run = FFMIN(run, 15); + prev_level = FFMIN(abs_level, 9); run = 0; } else { run++; @@ -699,13 +680,13 @@ static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice, const uint8_t *scan, const int16_t *qmat) { int idx, i; - int run, level, run_cb, lev_cb; + int prev_run = 4; + int prev_level = 2; + int run, level; int max_coeffs, abs_level; int bits = 0; max_coeffs = blocks_per_slice << 6; - run_cb = prores_run_to_cb_index[4]; - lev_cb = prores_lev_to_cb_index[2]; run = 0; for (i = 1; i < 64; i++) { @@ -714,12 +695,12 @@ static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice, *error += FFABS(blocks[idx]) % qmat[scan[i]]; if (level) { abs_level = FFABS(level); - bits += estimate_vlc(prores_ac_codebook[run_cb], run); - bits += estimate_vlc(prores_ac_codebook[lev_cb], + bits += estimate_vlc(ff_prores_run_to_cb[prev_run], run); + bits += estimate_vlc(ff_prores_lev_to_cb[prev_level], abs_level - 1) + 1; - run_cb = prores_run_to_cb_index[FFMIN(run, 15)]; - lev_cb = prores_lev_to_cb_index[FFMIN(abs_level, 9)]; + prev_run = FFMIN(run, 15); + prev_level = FFMIN(abs_level, 9); run = 0; } else { run++;