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 ESMTPS id CF9E643D68 for ; Sat, 18 Jan 2025 20:19:59 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B889868B2F9; Sat, 18 Jan 2025 22:19:55 +0200 (EET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8B8DC68AFA8 for ; Sat, 18 Jan 2025 22:19:48 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id A331940003 for ; Sat, 18 Jan 2025 20:19:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1737231587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=UWYElyd60GGTnre70RqCY00dscyXTttwdQrCDglmu/c=; b=VEjKAwdKmJOGiBy6AbrykJjFDdr+KZneGo1u0nhiVBj5LbqPOdNfETNJPm5KGINEGqsGcZ 0tNwcl+Re2NHxnMAQ6isBvvQPkmStw7yJlvRnGqxr708k7HQT31H04qPJKBEknCtIlnmwc w8WbCV20gSqlZQqyvyGZ1VGFYNW1KMVXolekYrQqR6qgJwglidY9X+v66MlZLAs3NXC2Fo VbPy3YCejgbx5tjpqnl4Jk63UNHRVtDogO1qyn+dmFDBRZIB2p08xH0F/DLa6amklXTEAD eKRMMVJBHzIPGP4iWYCPzUup2gbdQbKB3LEMS6u+iUIRn+aKkYjAW0dZjXesyQ== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 18 Jan 2025 21:19:45 +0100 Message-ID: <20250118201946.2389042-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/ffv1: flip half of float16 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="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: float16 is a sign bit followed by "positive is larger" exponent and mantisse that way the up direction changes between negative and positive numbers flipping the exponent and mantisse for positive numbers gives a compression gain of 0.5% for both RCT and noRCT modes using the ACES_OT_VWG_SampleFrames testset Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer --- libavcodec/ffv1dec_template.c | 10 ++++++++++ libavcodec/ffv1enc_template.c | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index e983d1ba648..0be17b54bbb 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -185,6 +185,16 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc, b += g; r += g; } + if (f->flt) { + if (!(r&0x8000)) + r ^= 0x7FFF; + if (!(g&0x8000)) + g ^= 0x7FFF; + if (!(b&0x8000)) + b ^= 0x7FFF; + if (transparency && !(a&0x8000)) + a ^= 0x7FFF; + } if (lbd) *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + ((unsigned)g<<8) + ((unsigned)r<<16) + ((unsigned)a<<24); diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index bc14926ab95..4d20cb93627 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -180,6 +180,17 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc, r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y)); } + if (f->flt) { + if (!(r&0x8000)) + r ^= 0x7FFF; + if (!(g&0x8000)) + g ^= 0x7FFF; + if (!(b&0x8000)) + b ^= 0x7FFF; + if (transparency && !(a&0x8000)) + a ^= 0x7FFF; + } + if (sc->slice_coding_mode != 1) { b -= g; r -= g; -- 2.48.1 _______________________________________________ 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".