From patchwork Wed Oct 29 17:24:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 24902 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 BA81BC3335 for ; Wed, 29 Oct 2025 17:25:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 63F9B608CA; Wed, 29 Oct 2025 18:25:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DQ+7QCV6"; 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 94E6F608C8 for ; Wed, 29 Oct 2025 18:24:49 +0100 (CET) Received: from Monstersaurus.hippo-penny.ts.net (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3C1004E45; Wed, 29 Oct 2025 18:23:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761758580; bh=zUiPKTtmmpRi8Hr6zoav5cWPwz3HCSmysAqavYZInCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DQ+7QCV6j6WoViQO6JF9aKTjP8eEtM/dYfIKXapOYuOqs9jnxOaj/1fQELCIhKGkb LJc4t5dLWqNnPG9hCDuewW7T02bVjJnRu6IeBfk1bn5p/yJ9S3zl5tJlF+xFPETRdz em1YLZKCIDoefQq1e4z3MrvSvCCv0ez8zssCiFSQ= From: Kieran Bingham To: libcamera devel Cc: Kieran Bingham Subject: [PATCH v2 13/13] DNI: test: libipa: fixedpoint: Validate extra types Date: Wed, 29 Oct 2025 17:24:38 +0000 Message-ID: <20251029172439.1513907-14-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251029172439.1513907-1-kieran.bingham@ideasonboard.com> References: <20251029172439.1513907-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" Check that the Cproc manual types can be directly served by the new fixed point types. DNI: This patch is just here to validate that my conversions are using the right types and work as the original code did. I don't expect this one to be merged. Signed-off-by: Kieran Bingham --- test/ipa/libipa/fixedpoint.cpp | 68 ++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp index f8be1e4bf70f..ffab9638fa29 100644 --- a/test/ipa/libipa/fixedpoint.cpp +++ b/test/ipa/libipa/fixedpoint.cpp @@ -247,6 +247,71 @@ protected: return fails ? TestFail : TestPass; } + struct BrightnessTraits { + using quantized_type = int8_t; + static constexpr quantized_type fromFloat(float v) + { + int quantized = std::lround(v * 128.0f); + return static_cast(std::clamp(quantized, -128, 127)); + } + static float toFloat(quantized_type v) + { + return static_cast(v) / 128.0f; + } + }; + + using BrightnessQOriginal = Quantized; + + struct ContrastSaturationTraits { + using quantized_type = uint8_t; + static constexpr quantized_type fromFloat(float v) + { + int quantized = std::lround(v * 128.0f); + return static_cast(std::clamp(quantized, 0, 255)); + } + static float toFloat(quantized_type v) + { + return static_cast(v) / 128.0f; + } + }; + + using ContrastQOriginal = Quantized; + + /* FixedPoint equivalents to validate */ + using BrightnessQ = Quantized>; + using ContrastQ = Quantized>; + + template + int testTwoIdenticalTypes(float v) + { + T1 a(v); + T2 b(v); + + std::cout << " Checking " << a.toString() + << " == " << b.toString() + << std::endl; + + /* 0/false success, 1/true fail */ + return (a.quantized() != b.quantized()); + } + + int testCprocFixedPointConversion() + { + unsigned int fails = 0; + + std::cout << std::endl + << "CPROC Fixed-Point Quantizer conversion tests:" + << std::endl; + + fails += testTwoIdenticalTypes(BrightnessQ::TraitsType::min); + fails += testTwoIdenticalTypes(BrightnessQ::TraitsType::max); + + fails += testTwoIdenticalTypes(ContrastQ::TraitsType::min); + fails += testTwoIdenticalTypes(ContrastQ::TraitsType::max); + + return fails ? TestFail : TestPass; + } + int run() { unsigned int fails = 0; @@ -261,6 +326,9 @@ protected: if (testScaledFixedPointQuantizers() != TestPass) fails++; + if (testCprocFixedPointConversion() != TestPass) + fails++; + return fails ? TestFail : TestPass; } };