From patchwork Thu Feb 19 15:05:03 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 26200 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 8F079C0DA4 for ; Thu, 19 Feb 2026 15:05:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 419D36226A; Thu, 19 Feb 2026 16:05:15 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="uq386DdE"; 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 6482D62254 for ; Thu, 19 Feb 2026 16:05:09 +0100 (CET) Received: from ping.linuxembedded.co.uk (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B6043F52; Thu, 19 Feb 2026 16:04:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1771513455; bh=f1zkzThiM9e+EqzOBESZJHTkIUbFBF32VPJtpPWPfvc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=uq386DdEyXRwa4t/57GM01ZEfLmrutyB/zZHyjqYEMtA9h7keVehd0LTDFkspOer/ NDDq7gPQYCGzPN1bEkij7MrlqOVUiEfsMvXBQCz8R+JkQN6p3LGYyCGiQLsTLUsIsh L2G2f7B8oXkRPN5Y5MEDZMm2YKnEgPSjiuIeXviw= From: Kieran Bingham Date: Thu, 19 Feb 2026 15:05:03 +0000 Subject: [PATCH v8 02/15] test: libipa: Add tests for Quantized types MIME-Version: 1.0 Message-Id: <20260219-kbingham-quantizers-v8-2-2b6ff68ead26@ideasonboard.com> References: <20260219-kbingham-quantizers-v8-0-2b6ff68ead26@ideasonboard.com> In-Reply-To: <20260219-kbingham-quantizers-v8-0-2b6ff68ead26@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Isaac Scott , Paul Elder , Laurent Pinchart , Stefan Klug X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1771513507; l=4765; i=kieran.bingham@ideasonboard.com; s=20260207; h=from:subject:message-id; bh=f1zkzThiM9e+EqzOBESZJHTkIUbFBF32VPJtpPWPfvc=; b=9oh/u9y+TbIaWTFeWHauEPkyZNwXU5kXbkeBMFtJhg5kjh3Fdv3I/0BVLszuyWY/sH9PmoeOF MurqUDqJILMAKXxx3CIjoSy9OHS5wm2uRwwrxiBN1HNQ7MSWx9pHwBj X-Developer-Key: i=kieran.bingham@ideasonboard.com; a=ed25519; pk=FVXKN7YuwHc6UtbRUeTMAmranfsQomA+vnilfglWdaY= 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" Provide use case tests for the Quantized types to ensure construction and usages are consistent and work as expected. Reviewed-by: Isaac Scott Reviewed-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Stefan Klug Signed-off-by: Kieran Bingham --- v8: - Only use uint8_t - Don't output on success --- test/ipa/libipa/meson.build | 1 + test/ipa/libipa/quantized.cpp | 145 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) diff --git a/test/ipa/libipa/meson.build b/test/ipa/libipa/meson.build index 2070bed70222..c3e255871f4f 100644 --- a/test/ipa/libipa/meson.build +++ b/test/ipa/libipa/meson.build @@ -5,6 +5,7 @@ libipa_test = [ {'name': 'histogram', 'sources': ['histogram.cpp']}, {'name': 'interpolator', 'sources': ['interpolator.cpp']}, {'name': 'pwl', 'sources': ['pwl.cpp'] }, + {'name': 'quantized', 'sources': ['quantized.cpp']}, ] foreach test : libipa_test diff --git a/test/ipa/libipa/quantized.cpp b/test/ipa/libipa/quantized.cpp new file mode 100644 index 000000000000..f138597f273d --- /dev/null +++ b/test/ipa/libipa/quantized.cpp @@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2026, Ideas on Board + * + * Dual Type and Quantizer tests + */ + +#include "../src/ipa/libipa/quantized.h" + +#include +#include +#include +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; +using namespace ipa; + +struct BrightnessHueTraits { + using QuantizedType = uint8_t; + static QuantizedType fromFloat(float v) + { + int quantized = std::lround(v * 128.0f); + return std::clamp(quantized, -128, 127); + } + static float toFloat(QuantizedType v) + { + return static_cast(v) / 128.0f; + } +}; + +using BrightnessHueQuantizer = Quantized; + +struct ContrastSaturationTraits { + using QuantizedType = uint8_t; + static QuantizedType fromFloat(float v) + { + int quantized = std::lround(v * 128.0f); + return std::clamp(quantized, 0, 255); + } + static float toFloat(QuantizedType v) + { + return static_cast(v) / 128.0f; + } +}; + +using ContrastSaturationQuantizer = Quantized; + +using BrightnessQ = BrightnessHueQuantizer; +using HueQ = BrightnessHueQuantizer; +using ContrastQ = ContrastSaturationQuantizer; +using SaturationQ = ContrastSaturationQuantizer; + +class QuantizedTest : public Test +{ +protected: + int run() + { + /* Test construction from float */ + { + BrightnessQ b(0.5f); + if (b.quantized() != 64 || std::abs(b.value() - 0.5f) > 0.01f) + return TestFail; + } + + /* Test construction from T */ + { + ContrastQ c(uint8_t(128)); + if (c.quantized() != 128 || std::abs(c.value() - 1.0f) > 0.01f) + return TestFail; + } + + /* + * Only construction from the exact storage type or a float + * is permitted. + */ + static_assert(!std::is_constructible_v); + static_assert(!std::is_constructible_v); + static_assert(!std::is_constructible_v); + static_assert(!std::is_constructible_v); + static_assert(!std::is_constructible_v); + static_assert(!std::is_constructible_v); + + /* Test equality */ + { + BrightnessQ b1(0.5f), b2(uint8_t(64)); + if (!(b1 == b2)) + return TestFail; + } + + /* Test inequality */ + { + BrightnessQ b1(0.5f), b2(-0.5f); + if (!(b1 != b2)) + return TestFail; + } + + /* Test copying */ + { + BrightnessQ b1(0.25f); + BrightnessQ b2 = b1; + if (!(b1 == b2)) + return TestFail; + } + + /* Test assignment */ + { + ContrastQ c1(1.5f); + ContrastQ c2(0.0f); + c2 = c1; + if (!(c1 == c2)) + return TestFail; + } + + /* + * Test construction from different floats mapping to same + * quantized value + */ + { + /* Two floats that have the same quantized value. */ + const float f1 = 1.007f; + const float f2 = 1.008f; + + ContrastQ c1(f1); + ContrastQ c2(f2); + + /* Quantized values must match */ + if (!(c1.quantized() == c2.quantized())) + return TestFail; + + /* Float values must now match */ + if (!(c1.value() == c2.value())) + return TestFail; + + if (!(c1 == c2)) + return TestFail; + } + + return TestPass; + } +}; + +TEST_REGISTER(QuantizedTest)