From patchwork Fri Feb 23 15:59:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 19529 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 08A70C3263 for ; Fri, 23 Feb 2024 16:00:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A73D662809; Fri, 23 Feb 2024 17:00:00 +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="vwEALkPr"; 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 92F0F627FD for ; Fri, 23 Feb 2024 16:59:58 +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 43C00D52; 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=Q+1zVWXDyXRmHJN4cxUi7LV29DDCPHUqyyn7SxehJAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vwEALkPrlG7xB6rK49ybKlRrldHEvVM/5mwJMGcfeAuqG8aZ+ItvLVUAXVIZvFs7/ Ps2pUeJGg0HhS1LpeA8iOYgIrgWf8JIVGPnMtQUfxgefwBW042nK+9dnB1LXuh5mcJ /zHVSCgPkctPjUGQiqClx56WKcJZoYdzz1sxONwg= From: Kieran Bingham To: libcamera devel Subject: [PATCH 1/3] ipa: libipa: Allow retrieving the name of a CameraSensorHelperFactory Date: Fri, 23 Feb 2024 15:59:52 +0000 Message-Id: <20240223155954.4139705-2-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" Support the test suite iterating the factories by exposing a const retriever of the factory name. --- An alternative here is to just allow direct access to the createInstance() from the test too, without having to re-search all of the factories each time. But I felt this was less of a de-restriction of the existing interfaces. Signed-off-by: Kieran Bingham --- src/ipa/libipa/camera_sensor_helper.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h index 3ea1806cb1fd..dcdbe82b7ac9 100644 --- a/src/ipa/libipa/camera_sensor_helper.h +++ b/src/ipa/libipa/camera_sensor_helper.h @@ -68,6 +68,8 @@ public: static std::vector &factories(); + const std::string &name() const { return name_; }; + private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactoryBase) From patchwork Fri Feb 23 15:59:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 19530 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 329F1BD80A 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 3811B62835; Fri, 23 Feb 2024 17:00:01 +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="WougIg0m"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CBE0361CA1 for ; Fri, 23 Feb 2024 16:59:58 +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 7A1AEFF1; 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=M1BJxsefQk31tFj5FM4OIHvyizXIEYug3nhJCQZkPrE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WougIg0myKzjYr1r+djfXFOocfGYpMjFkwE6R6FB8NfXI056XpVzNnY/larQ4YCMu wWxx8DawMFVIpuK8mOqCW4lrCZFV8+TkKuFtJJ1J7M2LYsPq5/TLTGdfxIm/73atFd S0oyBp9wMfMxQuvJEpWutzM+eXtgkSBajY+tn9KE= From: Kieran Bingham To: libcamera devel Subject: [RFC PATCH 2/3] test: ipa: libipa: Add CameraSensorHelper Gain Model tests Date: Fri, 23 Feb 2024 15:59:53 +0000 Message-Id: <20240223155954.4139705-3-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" Introduce a test that validates conversion of the gain model in each CameraSensorHelper. It should be expected that if a gainCode produces a given gain value, then converting that gain back should produce the same result. This test fails on the following CameraSensorHelpers: - imx219 imx258 imx283 imx290 imx296 imx327 imx335 imx477 Signed-off-by: Kieran Bingham --- This test also fails on the ar0521 helper as that has a defined code limit of '63', which the test does not yet have a way to infer. Adding a 'maxCode' helper to the base class may be the way to go here, and would also let us define a maximum value for other helpers directly. test/ipa/camera_sensor_helper.cpp | 69 +++++++++++++++++++++++++++++++ test/ipa/meson.build | 1 + 2 files changed, 70 insertions(+) create mode 100644 test/ipa/camera_sensor_helper.cpp diff --git a/test/ipa/camera_sensor_helper.cpp b/test/ipa/camera_sensor_helper.cpp new file mode 100644 index 000000000000..2d37628f87c4 --- /dev/null +++ b/test/ipa/camera_sensor_helper.cpp @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2024, Ideas on Board Oy. + */ + +#include "libipa/camera_sensor_helper.h" + +#include +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; +using namespace libcamera::ipa; + +class CameraSensorHelperTest : public Test +{ +protected: + int testGainModel(std::string model) + { + int ret = TestPass; + + std::unique_ptr camHelper_; + + camHelper_ = CameraSensorHelperFactoryBase::create(model); + if (!camHelper_) { + std::cout + << "Failed to create camera sensor helper for " + << model; + return TestFail; + } + + for (unsigned int i = 0; i < 240; i++) { + float gain = camHelper_->gain(i); + uint32_t gainCode = camHelper_->gainCode(gain); + + if (i != gainCode) { + std::cout << model << ": Gain conversions failed: " + << i << " : " << gain << " : " + << gainCode << std::endl; + + ret = TestFail; + } + }; + + return ret; + } + + int run() override + { + unsigned int failures = 0; + + std::vector factories; + + for (auto factory : CameraSensorHelperFactoryBase::factories()) { + const std::string &model = factory->name(); + + cout << "Testing CameraSensorHelper for " << model << endl; + + if (testGainModel(factory->name()) == TestFail) + failures++; + } + + return failures ? TestFail : TestPass; + } +}; + +TEST_REGISTER(CameraSensorHelperTest) diff --git a/test/ipa/meson.build b/test/ipa/meson.build index 180b0da0a51a..c99385a7cb8b 100644 --- a/test/ipa/meson.build +++ b/test/ipa/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 ipa_test = [ + {'name': 'camera_sensor_helper', 'sources': ['camera_sensor_helper.cpp']}, {'name': 'ipa_module_test', 'sources': ['ipa_module_test.cpp']}, {'name': 'ipa_interface_test', 'sources': ['ipa_interface_test.cpp']}, ] 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);