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 C699445E59 for ; Tue, 9 Jan 2024 23:08:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8F80568CCBF; Wed, 10 Jan 2024 01:08:53 +0200 (EET) Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 58F9568CA71 for ; Wed, 10 Jan 2024 01:08:46 +0200 (EET) Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a294295dda3so402217666b.0 for ; Tue, 09 Jan 2024 15:08:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704841725; x=1705446525; darn=ffmpeg.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:mail-followup-to :message-id:subject:to:from:date:from:to:cc:subject:date:message-id :reply-to; bh=cnF6GRecz2HZm6t3xYpZ69GPc8hhu+Hu+WbqK+Z6dNI=; b=Y2igWsL1cFZZWBcc07e7aR6DMRX+Ival/ONWLQlwd8Tk79szL7MeDRRoXW0LYphUdM A0LHdrRJGpsytJsgG1aXLEJGgjckAZXsoB+jbO/dwVJjCs3OkFeWagwWdVUy4Szp/m8O Zs/jPXvL2fC6v4u7rbZ+CgDxeQrDT+EHk5yTDfU79W9EOu58UycyhLbzv4qXjTbcHygw Nrdf15ZmCwjNioz/tiJpGcPfrQqaSqcmDd/sde52L6+Gc5XIgRwjnadG6N2gdPc1avCU +ehmTbAdoXm82TTluZgm2lGtZGtX6qc36qn3Yk5fjVe8bvNRs3koqT4WF76JkvRz90vV 9uMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704841725; x=1705446525; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:mail-followup-to :message-id:subject:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cnF6GRecz2HZm6t3xYpZ69GPc8hhu+Hu+WbqK+Z6dNI=; b=qJcA2Dxmbe1DSRBeDHJBwzwtqcHbJ0PNQTm843vRdkAUzWsXxepFPmqTLMszSFSKqI A1olltQ2/g+MKDQ2HoboilKcJGpQwayJOZ9XG0oLGxpHkD/HoNtmmerOgAO+rqDN260f UVHdw1MCAY/QYfFauo/8H6GfMVTgf4COhjd6PR6L/xJmqttl8gLLA2Hk47IS5DxzVffD bGmvBVDgKBtSDAoiLNx9gTFgrHJfwfkIkc/B8hZYKoT047hyd+nZ4CQANqGabTNfJ0tW CyiPgaiS6Wc0nc/4c+wAxWs2hTF1vOnfRQXGuYk8S6eiAgPSBWlnrxA3hqOssWWPSn9M xXMQ== X-Gm-Message-State: AOJu0YwVUx13a308HtcqA3WZO1mDpzLJ+yGLtU6SJ2I9DDdJqyWiUmEm QW2TlMncuPX1j3Fs9GElEjtCWQsp2aY= X-Google-Smtp-Source: AGHT+IEDRWoiASeerAFcw0DOoaLWVMDQfOue2+Twe6in5Baj6ACptISXCy3tJ0USP2sXNvKqepAF9Q== X-Received: by 2002:a17:906:39c1:b0:a28:c06d:2e12 with SMTP id i1-20020a17090639c100b00a28c06d2e12mr47614eje.21.1704841724720; Tue, 09 Jan 2024 15:08:44 -0800 (PST) Received: from mariano (dynamic-adsl-84-220-189-10.clienti.tiscali.it. [84.220.189.10]) by smtp.gmail.com with ESMTPSA id gf24-20020a170906e21800b00a27741ca951sm1485063ejb.108.2024.01.09.15.08.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 15:08:44 -0800 (PST) Received: by mariano (Postfix, from userid 1000) id 7620FBFCDC; Wed, 10 Jan 2024 00:08:42 +0100 (CET) Date: Wed, 10 Jan 2024 00:08:42 +0100 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches References: <20231211014429.1841681-1-u@pkh.me> <20231211014429.1841681-28-u@pkh.me> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.1.4 (2021-12-11) Subject: Re: [FFmpeg-devel] [PATCH 27/35] avcodec/proresenc_anatoliy: remove TO_GOLOMB2() 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 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: quoted-printable Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On date Monday 2024-01-08 00:00:37 +0100, Cl=E9ment B=BDsch wrote: > On Sun, Dec 24, 2023 at 12:43:32AM +0100, Stefano Sabatini wrote: > > On date Monday 2023-12-11 02:35:28 +0100, Cl=E9ment B=BDsch wrote: > > > A few cosmetics aside, this makes the function identical to the one w= ith > > > the same name in proresenc_kostya. > > > --- > > > libavcodec/proresenc_anatoliy.c | 6 ++---- > > > 1 file changed, 2 insertions(+), 4 deletions(-) > > > = > > > diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_a= natoliy.c > > > index bdf7bface4..aed5c68b1b 100644 > > > --- a/libavcodec/proresenc_anatoliy.c > > > +++ b/libavcodec/proresenc_anatoliy.c > > > @@ -257,7 +257,6 @@ static void encode_vlc_codeword(PutBitContext *pb= , unsigned codebook, int val) > > > = > > > #define GET_SIGN(x) ((x) >> 31) > > > #define MAKE_CODE(x) (((x) * 2) ^ GET_SIGN(x)) > > > -#define TO_GOLOMB2(val,sign) ((val)=3D=3D0 ? 0 : ((val) << 1) + (sig= n)) > > > = > > > static av_always_inline int get_level(int val) > > > { > > > @@ -271,7 +270,6 @@ static void encode_dcs(PutBitContext *pb, int16_t= *blocks, > > > { > > > int i; > > > int codebook =3D 5, code, dc, prev_dc, delta, sign, new_sign; > > > - int diff_sign; > > > = > > > prev_dc =3D (blocks[0] - 0x4000) / scale; > > > encode_vlc_codeword(pb, FIRST_DC_CB, MAKE_CODE(prev_dc)); > > > @@ -282,8 +280,8 @@ static void encode_dcs(PutBitContext *pb, int16_t= *blocks, > > > dc =3D (blocks[0] - 0x4000) / scale; > > > delta =3D dc - prev_dc; > > > new_sign =3D GET_SIGN(delta); > > = > > > - diff_sign =3D new_sign ^ sign; > > > - code =3D TO_GOLOMB2(get_level(delta), diff_sign); > > > + delta =3D (delta ^ sign) - sign; > > > + code =3D MAKE_CODE(delta); > > = > > These don't look equivalent, > > = > > MAKE_CODE((delta ^ sign) - sign) is equivalent to > > TO_GOLOMB2(get_level(delta), sign) > > = > > not to > > TO_GOLOMB2(get_level(delta), diff_sign) > = > OK so this one is a bit tricky. > = > Let's start from the specs, which states that the signed integer to symbol > (code) mapping should be: > = > 2|n| if n>=3D0 > 2|n|-1 if n<0 > = > We also know that n>>31 is -1 if n < 0, and 0 if n>=3D0, which means the > above condition can be simplified to: > = > 2|n| + (n>>31) > = > With prores_aw we have: > = > s =3D -1 if different sign, 0 otherwise > 2|n| + s > = > Because: > - get_level() is an absolute function=B9 > - the val=3D=3D0 case doesn't matter because in this case s will also be 0 > = > In prores_ks we have: > = > n'=3D-n if different sign, n otherwise > (2n')^sign(n') <=3D> 2|n'|-(n'>>31) > = > So basically, aw does use the comparison with the previous delta and > encodes it accordingly, while ks decides to swap the sign of n according > to that previous delta, then encode it using its new sign. > = > I wouldn't mind a third pair of eyes on the matter, but these look > equivalent to me. > = > Note that in practice I also tried to encode a bunch of frames from > testsrc2 with and without the patch, and they are bit identical. Thanks for the detailed explanation, I think it's safe to push especially considering that there are no output changes. _______________________________________________ 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".