From patchwork Fri Jun 13 10:09:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23557 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 4106FBDE6B for ; Fri, 13 Jun 2025 10:10:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9A1FA68DC2; Fri, 13 Jun 2025 12:10:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="FJ8owSot"; 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 5B70368DC2 for ; Fri, 13 Jun 2025 12:10:06 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:37bc:6352:9b26:2f94]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 93F7DED; Fri, 13 Jun 2025 12:09:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1749809396; bh=bnwYQ2ouadNBlVO+t9nIbUtzf7z3iToY/oARe4JhTis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FJ8owSotn3+lf/1t4kWDZaUa2YOHxBs+4On5hSXTR68w0t1308dmrI5OELI55l9ji bDkqofoM3FHyzVFpLZTFccplOSOVCU1jvr3qBFzV8opwl8wfjmKbno93SFn+dFt1Cv pasVASAxzg/P2ri4zG2N/3zozAy6lc/qTiMq5TWI= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham Subject: [PATCH v2 1/4] test: ipa: Add basic Pwl test Date: Fri, 13 Jun 2025 12:09:36 +0200 Message-ID: <20250613100947.589875-2-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250613100947.589875-1-stefan.klug@ideasonboard.com> References: <20250613100947.589875-1-stefan.klug@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" Add a basic test for the Pwl class. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham --- Changes in v2: - Changed test to also test extrapolation --- test/ipa/libipa/meson.build | 1 + test/ipa/libipa/pwl.cpp | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 test/ipa/libipa/pwl.cpp diff --git a/test/ipa/libipa/meson.build b/test/ipa/libipa/meson.build index 8c63ebd8e2f7..b2cc4b7461c1 100644 --- a/test/ipa/libipa/meson.build +++ b/test/ipa/libipa/meson.build @@ -4,6 +4,7 @@ libipa_test = [ {'name': 'fixedpoint', 'sources': ['fixedpoint.cpp']}, {'name': 'histogram', 'sources': ['histogram.cpp']}, {'name': 'interpolator', 'sources': ['interpolator.cpp']}, + {'name': 'pwl', 'sources': ['pwl.cpp']}, ] foreach test : libipa_test diff --git a/test/ipa/libipa/pwl.cpp b/test/ipa/libipa/pwl.cpp new file mode 100644 index 000000000000..d41a290a0e84 --- /dev/null +++ b/test/ipa/libipa/pwl.cpp @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2025, Ideas on Board Oy + * + * PWL tests + */ + +#include "../src/ipa/libipa/pwl.h" + +#include +#include +#include +#include +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; +using namespace ipa; + +#define ASSERT_EQ(a, b) \ + if ((a) != (b)) { \ + std::cout << #a " != " #b " (" << a << " ," << b << ")" \ + << std::endl; \ + return TestFail; \ + } + +class PwlTest : public Test +{ +protected: + int run() + { + Pwl pwl; + pwl.append(0, 0); + pwl.append(1, 1); + + ASSERT_EQ(pwl.eval(-1), -1); + ASSERT_EQ(pwl.eval(0), 0); + ASSERT_EQ(pwl.eval(0.5), 0.5); + ASSERT_EQ(pwl.eval(1), 1); + ASSERT_EQ(pwl.eval(2), 2); + + ASSERT_EQ(pwl.size(), 2); + + return TestPass; + } +}; + +TEST_REGISTER(PwlTest) From patchwork Fri Jun 13 10:09:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23558 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 83C4BBDE6B for ; Fri, 13 Jun 2025 10:10:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C5E0468DC4; Fri, 13 Jun 2025 12:10:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SY58bHMD"; 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 CC3FE68DBD for ; Fri, 13 Jun 2025 12:10:08 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:37bc:6352:9b26:2f94]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 741DC56D; Fri, 13 Jun 2025 12:09:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1749809399; bh=5DiqzN8HEsFS9cHqGWYTO0rnQSzdPwpkQLvhfXtqJog=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SY58bHMDsMPV5tyQIMUJ9BA4H2XfWmtVzX03NuiBpL1411kNjTH41XzDBgjRDvH0e LrNV2QTCgE/v+zLJp8/vQ/YEYlBiqCkfE6r3IUKaAojtKWY/vMOcaL5SyCpJIot+JE 0h2p5PmRSd2g9ijwGdnSlIe7SMrwWxQbsGIk5czY= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2 2/4] libipa: pwl: Improve documentation Date: Fri, 13 Jun 2025 12:09:37 +0200 Message-ID: <20250613100947.589875-3-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250613100947.589875-1-stefan.klug@ideasonboard.com> References: <20250613100947.589875-1-stefan.klug@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" If a Pwl is evaluated outside of the domain, it gets extrapolated linearly. Fix the documentation as it states otherwise. Signed-off-by: Stefan Klug --- src/ipa/libipa/pwl.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp index 3fa005ba92df..3d2188170d83 100644 --- a/src/ipa/libipa/pwl.cpp +++ b/src/ipa/libipa/pwl.cpp @@ -35,14 +35,13 @@ namespace ipa { * * https://en.wikipedia.org/wiki/Piecewise_linear_function * - * A consequence of the Pwl class being defined by knots instead of linear - * functions is that the values of the piecewise linear function past the ends - * of the function are constants as opposed to linear functions. In a - * mathematical piecewise linear function that is defined by multiple linear - * functions, the ends of the function are also linear functions and hence grow - * to infinity (or negative infinity). However, since this Pwl class is defined - * by knots, the y-value of the leftmost and rightmost knots will hold for all - * x values to negative infinity and positive infinity, respectively. + * Outside the domain of the piecewise linear function the closest segment is + * extrapolated linearly. If one wants to ensure that the returned values stay + * within the range of the pwl, the input can be clamped: + * + * \code{.cpp} + * pwl.eval(pwl.domain().clip(x)) + * \endcode */ /** From patchwork Fri Jun 13 10:09:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23559 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 21C81BDE6B for ; Fri, 13 Jun 2025 10:10:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9021B68DC7; Fri, 13 Jun 2025 12:10:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ndDLRsL1"; 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 9E05868DC3 for ; Fri, 13 Jun 2025 12:10:12 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:37bc:6352:9b26:2f94]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 4E08F56D; Fri, 13 Jun 2025 12:10:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1749809403; bh=ulq+YLUIGfWaIQjjeAz+yVVdBZ7kRa/LyZPLVKOxARY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ndDLRsL1TNZ9pMkY4SSJ+lCiUr3J1hA2ye/ro3oP2ePSNjJ0srRZOCbF3hyiG2gaA zUPJXqqsJEMYuUEEi0VF+sRXV0S5v+MfRMih5pzkXA0ZLJJ274ltlwXVx+qJbhA4HK /Ee8pGYH4CXOU6mlpYZM7fyQUkbv9kuzXGgl/ws8= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham Subject: [PATCH v2 3/4] test: ipa: Add failing test for single point Pwl Date: Fri, 13 Jun 2025 12:09:38 +0200 Message-ID: <20250613100947.589875-4-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250613100947.589875-1-stefan.klug@ideasonboard.com> References: <20250613100947.589875-1-stefan.klug@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" Sometimes it is useful to have a Pwl with only a single point defined. A practical use case is tuning files with only a single entry for Pwl related parameters, where the expectation is that this entry just gets used. Add a failing test case for such a single point Pwl. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham --- test/ipa/libipa/meson.build | 2 +- test/ipa/libipa/pwl.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/ipa/libipa/meson.build b/test/ipa/libipa/meson.build index b2cc4b7461c1..c553366a7934 100644 --- a/test/ipa/libipa/meson.build +++ b/test/ipa/libipa/meson.build @@ -4,7 +4,7 @@ libipa_test = [ {'name': 'fixedpoint', 'sources': ['fixedpoint.cpp']}, {'name': 'histogram', 'sources': ['histogram.cpp']}, {'name': 'interpolator', 'sources': ['interpolator.cpp']}, - {'name': 'pwl', 'sources': ['pwl.cpp']}, + {'name': 'pwl', 'sources': ['pwl.cpp'], 'should_fail': true }, ] foreach test : libipa_test diff --git a/test/ipa/libipa/pwl.cpp b/test/ipa/libipa/pwl.cpp index d41a290a0e84..6640b1ab9f36 100644 --- a/test/ipa/libipa/pwl.cpp +++ b/test/ipa/libipa/pwl.cpp @@ -43,6 +43,13 @@ protected: ASSERT_EQ(pwl.size(), 2); + /* Test degenerate PWL. */ + pwl.clear(); + pwl.append(1, 1); + ASSERT_EQ(pwl.eval(0), 1); + ASSERT_EQ(pwl.eval(1), 1); + ASSERT_EQ(pwl.eval(2), 1); + return TestPass; } }; From patchwork Fri Jun 13 10:09:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23560 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 5B980BDE6B for ; Fri, 13 Jun 2025 10:10:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 16BB968DC3; Fri, 13 Jun 2025 12:10:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BchVZ5Ls"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E081968DBD for ; Fri, 13 Jun 2025 12:10:15 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:37bc:6352:9b26:2f94]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 8C40416C5; Fri, 13 Jun 2025 12:10:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1749809406; bh=I2A0lR6CeaffCi2hrOyhn/4aS2n5HD5H4EIKhhY3lEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BchVZ5LsF+4+pNTtRQRLFQoBvx3jH+7i8LvYQKm+NqzxHA3U/UAyVJm2hq1v0dvHg DkFQLLG5Izxtz6wSyRn8HzFWfgqw3LdoycZw4Q/+YjtermYiAHdtbSoDyv9QTw1okN ccZAUHmj/xzng3NFBN8ZhTQliVuZ6EWVRt8Ort8U= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2 4/4] libipa: pwl: Fix single point Pwl Date: Fri, 13 Jun 2025 12:09:39 +0200 Message-ID: <20250613100947.589875-5-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250613100947.589875-1-stefan.klug@ideasonboard.com> References: <20250613100947.589875-1-stefan.klug@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" Fix the eval() function for Pwls that contain only a single point. Remove the shouldi_fail from the corresponding test case. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham --- src/ipa/libipa/pwl.cpp | 4 ++++ test/ipa/libipa/meson.build | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp index 3d2188170d83..69a9334112e8 100644 --- a/src/ipa/libipa/pwl.cpp +++ b/src/ipa/libipa/pwl.cpp @@ -210,6 +210,10 @@ double Pwl::eval(double x, int *span, bool updateSpan) const : points_.size() / 2 - 1); if (span && updateSpan) *span = index; + + if (points_.size() == 1) + return points_[0].y(); + return points_[index].y() + (x - points_[index].x()) * (points_[index + 1].y() - points_[index].y()) / (points_[index + 1].x() - points_[index].x()); diff --git a/test/ipa/libipa/meson.build b/test/ipa/libipa/meson.build index c553366a7934..2070bed70222 100644 --- a/test/ipa/libipa/meson.build +++ b/test/ipa/libipa/meson.build @@ -4,7 +4,7 @@ libipa_test = [ {'name': 'fixedpoint', 'sources': ['fixedpoint.cpp']}, {'name': 'histogram', 'sources': ['histogram.cpp']}, {'name': 'interpolator', 'sources': ['interpolator.cpp']}, - {'name': 'pwl', 'sources': ['pwl.cpp'], 'should_fail': true }, + {'name': 'pwl', 'sources': ['pwl.cpp'] }, ] foreach test : libipa_test