From patchwork Fri Feb 23 15:59:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 19531 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id EB851C32C3 for ; Fri, 23 Feb 2024 16:00:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E427E62866; Fri, 23 Feb 2024 17:00:02 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TVUBMTq1"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 23D7E62816 for ; Fri, 23 Feb 2024 16:59:59 +0100 (CET) Received: from Monstersaurus.local (aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net [82.37.23.78]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AF9FD2E7; Fri, 23 Feb 2024 16:59:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1708703989; bh=Y3YxmmeF46WG/5fwXqKKqRGzQJss5z0d9THRQASv5KY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TVUBMTq1MC1GjEyytvg1BstwwaNUSmwz8Gf0/giYRzx/5equ392c0lQcCLEKKf4xp 1Z8IzPIwUzgBJiOzDRlJpFkksipB9QqeybKA9A1gM3fOfQgtl8ZUtRUb2tc2nJB1o5 c9MOH/ysezITDgcmMJ7zhT2k85wbwIR+1qj1UZyA= From: Kieran Bingham To: libcamera devel Subject: [PATCH 3/3] libipa: camera_sensor_helper: Fix rounding of gainCode Date: Fri, 23 Feb 2024 15:59:54 +0000 Message-Id: <20240223155954.4139705-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223155954.4139705-1-kieran.bingham@ideasonboard.com> References: <20240223155954.4139705-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The implementation of gainCode for both Exponential and Linear gain models does not generate a gainCode that matches the result of the reverse operation. This can be seen by converting sequential gainCodes to a gain and converting that back to the gainCode. The values do not translate back due to rounding errors. Correct the rounding error and ensure that gainCode translation produces accurate bi-directional conversions from the perspective of the gainCode. This fixes the IMX290, IMX296, IMX327 and IMX335 which use the Exponential gain model helpers, as well as IMX219 IMX258 and IMX477 which use the Linear gain model helpers. Signed-off-by: Kieran Bingham --- src/ipa/libipa/camera_sensor_helper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index a925b37b9f7c..39e10d86a2c7 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -64,13 +64,13 @@ uint32_t CameraSensorHelper::gainCode(double gain) const case AnalogueGainLinear: ASSERT(k.linear.m0 == 0 || k.linear.m1 == 0); - return (k.linear.c0 - k.linear.c1 * gain) / - (k.linear.m1 * gain - k.linear.m0); + return std::round((k.linear.c0 - k.linear.c1 * gain) / + (k.linear.m1 * gain - k.linear.m0)); case AnalogueGainExponential: ASSERT(k.exp.a != 0 && k.exp.m != 0); - return std::log2(gain / k.exp.a) / k.exp.m; + return std::round(std::log2(gain / k.exp.a) / k.exp.m); default: ASSERT(false);