[{"id":38225,"web_url":"https://patchwork.libcamera.org/comment/38225/","msgid":"<177149120047.607498.18264734435110416501@neptunite.rasen.tech>","date":"2026-02-19T08:53:20","subject":"Re: [PATCH v7 06/15] ipa: rkisp1: cproc: Convert to use Quantized\n\ttypes","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Quoting Kieran Bingham (2026-02-14 01:57:45)\n> Convert the Brightness, Contrast and Saturation helper functions to a\n> Quantizer type to support maintaining the data.\n> \n> While modifying the include blocks of the ipa_context.h, also fix the\n> include style for libipa components.\n> \n> Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> \n> ---\n> v3:\n> - Don't add <algorithm> into ipa_context.h anymore\n> \n> v5:\n> - Use full string of quantised in debug log\n> - Fix libipa include style\n> - Fix commit message to mention brightness and typo in saturation\n> ---\n>  src/ipa/rkisp1/algorithms/cproc.cpp | 28 +++++++++-------------------\n>  src/ipa/rkisp1/ipa_context.h        | 23 +++++++++++++++--------\n>  2 files changed, 24 insertions(+), 27 deletions(-)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp\n> index d1fff6990d37..4374c08c2a4f 100644\n> --- a/src/ipa/rkisp1/algorithms/cproc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/cproc.cpp\n> @@ -39,16 +39,6 @@ constexpr float kDefaultBrightness = 0.0f;\n>  constexpr float kDefaultContrast = 1.0f;\n>  constexpr float kDefaultSaturation = 1.0f;\n>  \n> -int convertBrightness(const float v)\n> -{\n> -       return std::clamp<int>(std::lround(v * 128), -128, 127);\n> -}\n> -\n> -int convertContrastOrSaturation(const float v)\n> -{\n> -       return std::clamp<int>(std::lround(v * 128), 0, 255);\n> -}\n> -\n>  } /* namespace */\n>  \n>  /**\n> @@ -74,9 +64,9 @@ int ColorProcessing::configure(IPAContext &context,\n>  {\n>         auto &cproc = context.activeState.cproc;\n>  \n> -       cproc.brightness = convertBrightness(kDefaultBrightness);\n> -       cproc.contrast = convertContrastOrSaturation(kDefaultContrast);\n> -       cproc.saturation = convertContrastOrSaturation(kDefaultSaturation);\n> +       cproc.brightness = BrightnessQ(kDefaultBrightness);\n> +       cproc.contrast = ContrastQ(kDefaultContrast);\n> +       cproc.saturation = SaturationQ(kDefaultSaturation);\n>  \n>         return 0;\n>  }\n> @@ -97,7 +87,7 @@ void ColorProcessing::queueRequest(IPAContext &context,\n>  \n>         const auto &brightness = controls.get(controls::Brightness);\n>         if (brightness) {\n> -               int value = convertBrightness(*brightness);\n> +               BrightnessQ value = *brightness;\n>                 if (cproc.brightness != value) {\n>                         cproc.brightness = value;\n>                         update = true;\n> @@ -108,7 +98,7 @@ void ColorProcessing::queueRequest(IPAContext &context,\n>  \n>         const auto &contrast = controls.get(controls::Contrast);\n>         if (contrast) {\n> -               int value = convertContrastOrSaturation(*contrast);\n> +               ContrastQ value = *contrast;\n>                 if (cproc.contrast != value) {\n>                         cproc.contrast = value;\n>                         update = true;\n> @@ -119,7 +109,7 @@ void ColorProcessing::queueRequest(IPAContext &context,\n>  \n>         const auto saturation = controls.get(controls::Saturation);\n>         if (saturation) {\n> -               int value = convertContrastOrSaturation(*saturation);\n> +               SaturationQ value = *saturation;\n>                 if (cproc.saturation != value) {\n>                         cproc.saturation = value;\n>                         update = true;\n> @@ -148,9 +138,9 @@ void ColorProcessing::prepare([[maybe_unused]] IPAContext &context,\n>  \n>         auto config = params->block<BlockType::Cproc>();\n>         config.setEnabled(true);\n> -       config->brightness = frameContext.cproc.brightness;\n> -       config->contrast = frameContext.cproc.contrast;\n> -       config->sat = frameContext.cproc.saturation;\n> +       config->brightness = frameContext.cproc.brightness.quantized();\n> +       config->contrast = frameContext.cproc.contrast.quantized();\n> +       config->sat = frameContext.cproc.saturation.quantized();\n>  }\n>  \n>  REGISTER_IPA_ALGORITHM(ColorProcessing, \"ColorProcessing\")\n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index fa748811be74..cca5e281c732 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -24,14 +24,20 @@\n>  #include \"libcamera/internal/matrix.h\"\n>  #include \"libcamera/internal/vector.h\"\n>  \n> -#include <libipa/camera_sensor_helper.h>\n> -#include <libipa/fc_queue.h>\n>  #include \"libipa/agc_mean_luminance.h\"\n> +#include \"libipa/camera_sensor_helper.h\"\n> +#include \"libipa/fc_queue.h\"\n> +#include \"libipa/fixedpoint.h\"\n>  \n>  namespace libcamera {\n>  \n>  namespace ipa::rkisp1 {\n>  \n> +/* Fixed point types used by CPROC */\n> +using BrightnessQ = Q<1, 7>;\n> +using ContrastQ = UQ<1, 7>;\n> +using SaturationQ = UQ<1, 7>;\n> +\n>  struct IPAHwSettings {\n>         unsigned int numAeCells;\n>         unsigned int numHistogramBins;\n> @@ -111,9 +117,9 @@ struct IPAActiveState {\n>         } ccm;\n>  \n>         struct {\n> -               int8_t brightness;\n> -               uint8_t contrast;\n> -               uint8_t saturation;\n> +               BrightnessQ brightness;\n> +               ContrastQ contrast;\n> +               SaturationQ saturation;\n>         } cproc;\n>  \n>         struct {\n> @@ -173,9 +179,10 @@ struct IPAFrameContext : public FrameContext {\n>         } awb;\n>  \n>         struct {\n> -               int8_t brightness;\n> -               uint8_t contrast;\n> -               uint8_t saturation;\n> +               BrightnessQ brightness;\n> +               ContrastQ contrast;\n> +               SaturationQ saturation;\n> +\n>                 bool update;\n>         } cproc;\n>  \n> \n> -- \n> 2.52.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 95ED0C31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 19 Feb 2026 08:53:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D6C556222C;\n\tThu, 19 Feb 2026 09:53:28 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9158062010\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Feb 2026 09:53:26 +0100 (CET)","from neptunite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:3150:3f17:6415:4c60])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 15B0D379;\n\tThu, 19 Feb 2026 09:52:32 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"eWTasVmU\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1771491153;\n\tbh=54Tj0VyEGtxreUQkpLHpSv4zUofwx90WlyrC5FPYlIg=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=eWTasVmUvHZg7wtEnO7M5tYSCCtCoyBvZFOEgWv2o1JhVS6UCoIFz7Xl8m6WGZRJL\n\tPChshHd9ax/q0eEbcJok0xSswjDU1VpFgcM8kErN241433111hne2vidfkLBe/ziy1\n\tZNG4iBKcbLWL0PFMLoxp3Zow0Ss0oIDw4mQ0CAgo=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20260213-kbingham-quantizers-v7-6-1626b9aaabf1@ideasonboard.com>","References":"<20260213-kbingham-quantizers-v7-0-1626b9aaabf1@ideasonboard.com>\n\t<20260213-kbingham-quantizers-v7-6-1626b9aaabf1@ideasonboard.com>","Subject":"Re: [PATCH v7 06/15] ipa: rkisp1: cproc: Convert to use Quantized\n\ttypes","From":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tIsaac Scott <isaac.scott@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 19 Feb 2026 17:53:20 +0900","Message-ID":"<177149120047.607498.18264734435110416501@neptunite.rasen.tech>","User-Agent":"alot/0.0.0","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]