From patchwork Thu Nov 13 12:24:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 25027 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 980C1C3335 for ; Thu, 13 Nov 2025 12:25:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 50D9660AC5; Thu, 13 Nov 2025 13:25:13 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="eq9P/5HJ"; 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 BC20A60AAB for ; Thu, 13 Nov 2025 13:24:57 +0100 (CET) Received: from Monstersaurus.infra.iob (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9BE0B1E50; Thu, 13 Nov 2025 13:22:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1763036577; bh=11NGk4twi7/nEJk6qwM5ezpjN7Ria1pq2NmQA/MBX98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eq9P/5HJiJpgKyUSRkJKACLUJeLrGCNYPEA8ryhnw44io54LvqyUC82U0ON4JAT12 xKUXlA6gkZk+OQQtIWTvYURINDiI3JG7c6h+ba9BZsvu+Vbb13bIMZiHzv6gBP35XU qJ7e4WEFyHm7BSTn7T+ukDFihNEMhpOHsZOxPeEk= From: Kieran Bingham To: libcamera devel Cc: Kieran Bingham Subject: [PATCH v3 14/14] DNI: test: libipa: fixedpoint: Validate extra types Date: Thu, 13 Nov 2025 12:24:49 +0000 Message-ID: <20251113122450.287633-15-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251113122450.287633-1-kieran.bingham@ideasonboard.com> References: <20251113122450.287633-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 7d1aeebc06da..94930d77668d 100644 --- a/test/ipa/libipa/fixedpoint.cpp +++ b/test/ipa/libipa/fixedpoint.cpp @@ -252,6 +252,71 @@ protected: return fails ? TestFail : TestPass; } + struct BrightnessTraits { + using QuantizedType = int8_t; + static constexpr QuantizedType fromFloat(float v) + { + int quantized = std::lround(v * 128.0f); + return static_cast(std::clamp(quantized, -128, 127)); + } + static float toFloat(QuantizedType v) + { + return static_cast(v) / 128.0f; + } + }; + + using BrightnessQOriginal = Quantized; + + struct ContrastSaturationTraits { + using QuantizedType = uint8_t; + static constexpr QuantizedType fromFloat(float v) + { + int quantized = std::lround(v * 128.0f); + return static_cast(std::clamp(quantized, 0, 255)); + } + static float toFloat(QuantizedType 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; @@ -266,6 +331,9 @@ protected: if (testScaledFixedPointQuantizers() != TestPass) fails++; + if (testCprocFixedPointConversion() != TestPass) + fails++; + return fails ? TestFail : TestPass; } };