From patchwork Mon Dec 11 01:35:09 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: 45033 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp2651770pzf; Sun, 10 Dec 2023 17:45:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSU9Vh5aZlAhnmLYiiGhyp+4mzUyPdiZ2SezMGwcMr4xZ7DqIQuUsnideZlwY8X6ygRPh3 X-Received: by 2002:a05:600c:3556:b0:40b:5e21:bdb4 with SMTP id i22-20020a05600c355600b0040b5e21bdb4mr1685462wmq.67.1702259143684; Sun, 10 Dec 2023 17:45:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702259143; cv=none; d=google.com; s=arc-20160816; b=uy9+baBJMXdCxQQPcielsnISmFz52/IwU7bPIgGAondU63HHfRkFTYvYG/ZnvRd41k Dez4pLrK80eUxPsfUDXyD7hXWJ6d9JHhymTWTeGOHA/S/zCO6VFO+4NaY54hdA8pu6xY Rg+FpHRgHQPfsEID1XdBFWgfdj08GLGcd692ar1EGpAr+G8VIX8tyC5iAyJpV5w0KSU/ 3EJeFIP9obNBdPOuwTereFeitnyBdJ1fpn90qm+IwcPp/82Xi/2Xyvd8ntYYYL55adzK Um80ADB6xFRCJc36GC8f1KP5TxEXudVRlW0scQNgaPIa/uBI6wxTSWquj0j2hyH/ELNT tmnA== 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=tn15HEkMq5zPdfubX3dTUocK0bnwYh1SSKgJ3ohrMFc=; fh=Jgo3TCyoG8OdFLqA8BuM7Wbf1w27210JU6p+E8x39/M=; b=LvvSCfjPMYexlVFXqAeaKk1+p3fVC1oCPrX3bGazNYPcsE4UD57ENTURL/0V/jNKWw wLe25DH1Ax3W81GFb4vHsGyleWUedfsBA2kzCJNMBa/n03RZStaCpJ/MmfMIm33QDwaX Vi1YUyTUxPe7bzzhH2NVOs+2EYgFBCRcehT49lCeNnubfW9lqis0JEUCcmfeOpHRF65s QRG3MmJSbOSqwRm7HWOmeXORiEMJZIZAuzyOsT8xkA1WGMt4aUT2ZcWfhrGrxs2bi2/Q vI/l2lap8blBACAaqoZ0WsZ0SHsJP2vTM78twtKT1f59nFnU81ML6FIkudvSAvSMeyB7 F04w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=rCp2LyvA; 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 z17-20020a1709067e5100b00a1e27e584casi3001253ejr.281.2023.12.10.17.45.43; Sun, 10 Dec 2023 17:45:43 -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=rCp2LyvA; 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 3527468D1A1; Mon, 11 Dec 2023 03:44:58 +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 77DB268D15C 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=TcnUQHN3vojWettb5naG2TJJg8kyEbR0v4LfwT3DHeg=; b=rCp2LyvAkoktS+2Bi+4p/+QHNt32w/ymCs9RQXaQz+G0qnAiFjqLxOcihZfth8whIoFtyr PPMxrf0SNnXB2P7vbB9dB67kOLZy/8IxntOslDU1B2Gn5pPEiHUdYwsELqKy4cpF2TCrrC cdYjd6gDXr/dBkU1c+i7qTohgVZh3Cw= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id df03006b; 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:09 +0100 Message-ID: <20231211014429.1841681-9-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 08/35] avcodec/proresenc_kostya: save a few operations in DC encoding 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: 3Lh1a9FWBIp+ This matches the logic from proresenc_anatoliy. --- libavcodec/proresenc_kostya.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c index f883ab550b..2d45f9a685 100644 --- a/libavcodec/proresenc_kostya.c +++ b/libavcodec/proresenc_kostya.c @@ -135,13 +135,6 @@ static const uint8_t prores_quant_matrices[][64] = { }, }; -static const uint8_t prores_dc_codebook[4] = { - 0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0 - 0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0 - 0x4D, // rice_order = 2, exp_golomb_order = 3, switch_bits = 1 - 0x70 // rice_order = 3, exp_golomb_order = 4, switch_bits = 0 -}; - #define NUM_MB_LIMITS 4 static const int prores_mb_limits[NUM_MB_LIMITS] = { 1620, // up to 720x576 @@ -416,7 +409,7 @@ static void encode_dcs(PutBitContext *pb, int16_t *blocks, int blocks_per_slice, int scale) { int i; - int codebook = 3, code, dc, prev_dc, delta, sign, new_sign; + int codebook = 5, code, dc, prev_dc, delta, sign, new_sign; prev_dc = (blocks[0] - 0x4000) / scale; encode_vlc_codeword(pb, FIRST_DC_CB, MAKE_CODE(prev_dc)); @@ -429,9 +422,8 @@ static void encode_dcs(PutBitContext *pb, int16_t *blocks, new_sign = GET_SIGN(delta); delta = (delta ^ sign) - sign; code = MAKE_CODE(delta); - encode_vlc_codeword(pb, prores_dc_codebook[codebook], code); - codebook = (code + (code & 1)) >> 1; - codebook = FFMIN(codebook, 3); + encode_vlc_codeword(pb, ff_prores_dc_codebook[codebook], code); + codebook = FFMIN(code, 6); sign = new_sign; prev_dc = dc; } @@ -650,7 +642,7 @@ static int estimate_dcs(int *error, int16_t *blocks, int blocks_per_slice, int scale) { int i; - int codebook = 3, code, dc, prev_dc, delta, sign, new_sign; + int codebook = 5, code, dc, prev_dc, delta, sign, new_sign; int bits; prev_dc = (blocks[0] - 0x4000) / scale; @@ -666,9 +658,8 @@ static int estimate_dcs(int *error, int16_t *blocks, int blocks_per_slice, new_sign = GET_SIGN(delta); delta = (delta ^ sign) - sign; code = MAKE_CODE(delta); - bits += estimate_vlc(prores_dc_codebook[codebook], code); - codebook = (code + (code & 1)) >> 1; - codebook = FFMIN(codebook, 3); + bits += estimate_vlc(ff_prores_dc_codebook[codebook], code); + codebook = FFMIN(code, 6); sign = new_sign; prev_dc = dc; }