From patchwork Wed Mar 26 08:00:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 23031 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 19D1AC323E for ; Wed, 26 Mar 2025 08:00:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C08C268951; Wed, 26 Mar 2025 09:00:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="juz7gufD"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 14AB768951 for ; Wed, 26 Mar 2025 09:00:50 +0100 (CET) Received: from neptunite.flets-east.jp (unknown [IPv6:2404:7a81:160:2100:7402:917d:ea0c:6d4c]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 224C23A4; Wed, 26 Mar 2025 08:59:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1742975942; bh=xflUdtGNRSQk3YX26MXTAQ20Q9y4NH0GeFwii+zNx74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=juz7gufDvKLDfUTNTncvjzM1WrDJg00l6J1nkTlzib/JX58LyvwEOZ3FT588884Pq cyQrvrO9i+W57n/nSj+38+KKQYgQKXzkETnir94c/VZ7m2/tLjHuFEp/ay0uwRVRh+ rSNILWghfcAVo6gtAu7dxtkSgKXgEvg1R7Qg+KyI= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Paul Elder Subject: [PATCH v2 3/3] libipa: camera_sensor_helper: Fix rounding of gainCode Date: Wed, 26 Mar 2025 17:00:33 +0900 Message-ID: <20250326080034.1733385-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250326080034.1733385-1-paul.elder@ideasonboard.com> References: <20250326080034.1733385-1-paul.elder@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" From: Kieran Bingham 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 Signed-off-by: Paul Elder --- Changes in v2: - recover from bitrot --- 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 7c66cd57d685..5645dd14fda3 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -90,12 +90,12 @@ uint32_t CameraSensorHelper::gainCode(double gain) const if (auto *l = std::get_if(&gain_)) { ASSERT(l->m0 == 0 || l->m1 == 0); - return (l->c0 - l->c1 * gain) / - (l->m1 * gain - l->m0); + return std::round((l->c0 - l->c1 * gain) / + (l->m1 * gain - l->m0)); } else if (auto *e = std::get_if(&gain_)) { ASSERT(e->a != 0 && e->m != 0); - return std::log2(gain / e->a) / e->m; + return std::round(std::log2(gain / e->a) / e->m); } else { ASSERT(false); return 0;