From patchwork Mon Dec 11 01:35:13 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: 45037 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp2651975pzf; Sun, 10 Dec 2023 17:46:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFoH0WJVwBy9ZazQMIHV247vMrOsXxHJw1DWJ8LK7hWfe3gX3j9Nx4Q+OOh02lE4VbHU+EZ X-Received: by 2002:a50:9e6b:0:b0:54b:5a7:143c with SMTP id z98-20020a509e6b000000b0054b05a7143cmr2629855ede.3.1702259178199; Sun, 10 Dec 2023 17:46:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702259178; cv=none; d=google.com; s=arc-20160816; b=ajtKuMk6OxOm3UYBSGUX3R+JBY6Y53U1Dc4dvLOlekuN7+0nplOe9dKMvOjo7bK01b sBrUFvJEj4oFlKWAUFqUGQh5LzQgoRjtigtz7ClhcuDrRv5sFtJH5nkZG1mO2CxWMQ8G liGfONsAeEJbK8pUiDsdcnWItAY/uKcqtW/0ifahF7al9YcWl9Uey+FUuNNaDeGNcuty IVXcBT9Fq/Gyf5D7BqcPcWL7cWlhBKAfFdcKOIB/c05qOZ1Jth1RABraiBA4sJHpO7cM F06AwUnWK/3mwkYVKpy7h6nlhMdl9WoJk1IURuR+QcubUtwfbDhd3NKSCkCFtI0Ex9Mh eCzQ== 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=D8BfFmZS5xw5U0LpfOBdfnmOY46oieAIcAcut9E4Wh0=; fh=Jgo3TCyoG8OdFLqA8BuM7Wbf1w27210JU6p+E8x39/M=; b=DzQmqwWUTqjtatVh3/3qV2XA+WKe3rtTITpH77qKS/1q2XkdA2JYjuEsBCds28GfI2 3tLm4lKgt73jNN6HzPu2i6FrBzC10EulFndwGAt9o96z3P9cx0lAii+jIycvCoJQ9vXW fL08xd+DazFOKJAM63Yx2WpngKNng2KDLDNdhSucI8VrGRHI2ipbRcYsKe7n0zfQmLt8 VF1z3Kdcke/e6bhdsanVNQIJEflO2+2MTncsCIpQ0IvYJgg2FCDsynAioHm6uis0ns1/ CMjBjPuRp/myKvWP5oVjuLU6//Zq08VHGM4Fwti+B5xgC/sEB102G3qBVDnfPBGucQQZ 5tfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=iqDB9WJj; 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 t25-20020a50c259000000b00550e9b850aesi1595320edf.143.2023.12.10.17.46.17; Sun, 10 Dec 2023 17:46:18 -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=iqDB9WJj; 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 B748468D16B; Mon, 11 Dec 2023 03:45:01 +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 CD5D768D164 for ; Mon, 11 Dec 2023 03:44:55 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1702259076; 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=ZLdH8urkpKGi7POPzIMiviV357+1+ySAY6iXJECUAXA=; b=iqDB9WJjtoysDYthzFVtpFn2wqxTLMsndjXrOVrzQQBv3PCI6cx6wch2jJFj052k56KfI8 /+x1Te9WicwpTzMtz/QvkQrCBWL23RD4BDiQY31fvVdky6kqHfoR2H67nswPw3y+RPzN1a MMc4LQ6ltRUl5R+r0R2GUjk/utpASYo= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id 6b3559ca; Mon, 11 Dec 2023 01:44:36 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 11 Dec 2023 02:35:13 +0100 Message-ID: <20231211014429.1841681-13-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 12/35] avcodec/proresenc_anatoliy: shuffle encode_codeword() code to match Kostya encoder 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: S0v/ufM8Godt Code is functionally identical, it's just rename of variables, cosmetics and branch logic shuffling. --- libavcodec/proresenc_anatoliy.c | 45 +++++++++++++++++---------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c index 804ff6ddf7..c7e43fc88c 100644 --- a/libavcodec/proresenc_anatoliy.c +++ b/libavcodec/proresenc_anatoliy.c @@ -226,31 +226,32 @@ static int int_from_list_or_default(void *ctx, const char *val_name, int val, return default_value; } -static void encode_codeword(PutBitContext *pb, int val, int codebook) +static void encode_codeword(PutBitContext *pb, int val, unsigned codebook) { - unsigned int rice_order, exp_order, switch_bits, first_exp, exp, zeros; - - /* number of bits to switch between rice and exp golomb */ - switch_bits = codebook & 3; - rice_order = codebook >> 5; - exp_order = (codebook >> 2) & 7; - - first_exp = ((switch_bits + 1) << rice_order); - - if (val >= first_exp) { /* exp golomb */ - val -= first_exp; - val += (1 << exp_order); - exp = av_log2(val); - zeros = exp - exp_order + switch_bits + 1; - put_bits(pb, zeros, 0); - put_bits(pb, exp + 1, val); - } else if (rice_order) { - put_bits(pb, (val >> rice_order), 0); - put_bits(pb, 1, 1); - put_sbits(pb, rice_order, val); + unsigned int rice_order, exp_order, switch_bits, switch_val; + int exponent; + + /* number of prefix bits to switch between Rice and expGolomb */ + switch_bits = (codebook & 3) + 1; + rice_order = codebook >> 5; /* rice code order */ + exp_order = (codebook >> 2) & 7; /* exp golomb code order */ + + switch_val = switch_bits << rice_order; + + if (val >= switch_val) { + val -= switch_val - (1 << exp_order); + exponent = av_log2(val); + + put_bits(pb, exponent - exp_order + switch_bits, 0); + put_bits(pb, exponent + 1, val); } else { - put_bits(pb, val, 0); + exponent = val >> rice_order; + + if (exponent) + put_bits(pb, exponent, 0); put_bits(pb, 1, 1); + if (rice_order) + put_sbits(pb, rice_order, val); } }