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 ESMTP id AD20445A50 for ; Mon, 11 Dec 2023 01:45:32 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E8ED068D183; Mon, 11 Dec 2023 03:44:56 +0200 (EET) 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?q?Cl=C3=A9ment=20B=C5=93sch?= 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?q?Cl=C3=A9ment=20B=C5=93sch?= 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 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++; -- 2.43.0 _______________________________________________ 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".