From patchwork Wed Jan 14 17:39:06 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 25802 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 00CD4BDCBF for ; Wed, 14 Jan 2026 17:39:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F361761FCC; Wed, 14 Jan 2026 18:39:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DzP2ExmS"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2AB9361FB9 for ; Wed, 14 Jan 2026 18:39:24 +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 37C411FBC; Wed, 14 Jan 2026 18:38:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1768412337; bh=gwN59Dyyn2xEyZ0BFhQmLYiKsf3fQWuQH3iGbipALMA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DzP2ExmSHsE/FLlgDdiSPkpzsyw5QV7SNk7ljt4VIPraZQ6v8Ipzwu1XC3s0fsgwV ZutxW4vImwsWOsJbED/V4euXCaYdNlQ/5Y8qJgASqZgzW0xV05JINyjDRY9g65CSGA H1iQh+ax4Z4rIWpb8pAN24+inbH9PLJjAwNxduyc= From: Kieran Bingham To: libcamera devel Cc: Kieran Bingham , Isaac Scott , Laurent Pinchart Subject: [PATCH v5 06/16] ipa: rkisp1: cproc: Convert to use Quantized types Date: Wed, 14 Jan 2026 17:39:06 +0000 Message-ID: <20260114173918.1744023-7-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260114173918.1744023-1-kieran.bingham@ideasonboard.com> References: <20260114173918.1744023-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" Convert the Brightness, Contrast and Saturation helper functions to a Quantizer type to support maintaining the data. While modifying the include blocks of the ipa_context.h, also fix the include style for libipa components. Reviewed-by: Isaac Scott Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- v3: - Don't add into ipa_context.h anymore v5: - Use full string of quantised in debug log - Fix libipa include style - Fix commit message to mention brightness and typo in saturation Signed-off-by: Kieran Bingham --- src/ipa/rkisp1/algorithms/cproc.cpp | 28 +++++++++------------------- src/ipa/rkisp1/ipa_context.h | 23 +++++++++++++++-------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp index d1fff6990d37..4374c08c2a4f 100644 --- a/src/ipa/rkisp1/algorithms/cproc.cpp +++ b/src/ipa/rkisp1/algorithms/cproc.cpp @@ -39,16 +39,6 @@ constexpr float kDefaultBrightness = 0.0f; constexpr float kDefaultContrast = 1.0f; constexpr float kDefaultSaturation = 1.0f; -int convertBrightness(const float v) -{ - return std::clamp(std::lround(v * 128), -128, 127); -} - -int convertContrastOrSaturation(const float v) -{ - return std::clamp(std::lround(v * 128), 0, 255); -} - } /* namespace */ /** @@ -74,9 +64,9 @@ int ColorProcessing::configure(IPAContext &context, { auto &cproc = context.activeState.cproc; - cproc.brightness = convertBrightness(kDefaultBrightness); - cproc.contrast = convertContrastOrSaturation(kDefaultContrast); - cproc.saturation = convertContrastOrSaturation(kDefaultSaturation); + cproc.brightness = BrightnessQ(kDefaultBrightness); + cproc.contrast = ContrastQ(kDefaultContrast); + cproc.saturation = SaturationQ(kDefaultSaturation); return 0; } @@ -97,7 +87,7 @@ void ColorProcessing::queueRequest(IPAContext &context, const auto &brightness = controls.get(controls::Brightness); if (brightness) { - int value = convertBrightness(*brightness); + BrightnessQ value = *brightness; if (cproc.brightness != value) { cproc.brightness = value; update = true; @@ -108,7 +98,7 @@ void ColorProcessing::queueRequest(IPAContext &context, const auto &contrast = controls.get(controls::Contrast); if (contrast) { - int value = convertContrastOrSaturation(*contrast); + ContrastQ value = *contrast; if (cproc.contrast != value) { cproc.contrast = value; update = true; @@ -119,7 +109,7 @@ void ColorProcessing::queueRequest(IPAContext &context, const auto saturation = controls.get(controls::Saturation); if (saturation) { - int value = convertContrastOrSaturation(*saturation); + SaturationQ value = *saturation; if (cproc.saturation != value) { cproc.saturation = value; update = true; @@ -148,9 +138,9 @@ void ColorProcessing::prepare([[maybe_unused]] IPAContext &context, auto config = params->block(); config.setEnabled(true); - config->brightness = frameContext.cproc.brightness; - config->contrast = frameContext.cproc.contrast; - config->sat = frameContext.cproc.saturation; + config->brightness = frameContext.cproc.brightness.quantized(); + config->contrast = frameContext.cproc.contrast.quantized(); + config->sat = frameContext.cproc.saturation.quantized(); } REGISTER_IPA_ALGORITHM(ColorProcessing, "ColorProcessing") diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index b257cee55379..cdb9a17b5adc 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -24,14 +24,20 @@ #include "libcamera/internal/matrix.h" #include "libcamera/internal/vector.h" -#include -#include #include "libipa/agc_mean_luminance.h" +#include "libipa/camera_sensor_helper.h" +#include "libipa/fc_queue.h" +#include "libipa/fixedpoint.h" namespace libcamera { namespace ipa::rkisp1 { +/* Fixed point types used by CPROC */ +using BrightnessQ = Q<1, 7>; +using ContrastQ = UQ<1, 7>; +using SaturationQ = UQ<1, 7>; + struct IPAHwSettings { unsigned int numAeCells; unsigned int numHistogramBins; @@ -115,9 +121,9 @@ struct IPAActiveState { } ccm; struct { - int8_t brightness; - uint8_t contrast; - uint8_t saturation; + BrightnessQ brightness; + ContrastQ contrast; + SaturationQ saturation; } cproc; struct { @@ -173,9 +179,10 @@ struct IPAFrameContext : public FrameContext { } awb; struct { - int8_t brightness; - uint8_t contrast; - uint8_t saturation; + BrightnessQ brightness; + ContrastQ contrast; + SaturationQ saturation; + bool update; } cproc;