[{"id":36544,"web_url":"https://patchwork.libcamera.org/comment/36544/","msgid":"<176177248115.2017750.715648752418595544@ping.linuxembedded.co.uk>","date":"2025-10-29T21:14:41","subject":"Re: [PATCH v2 09/13] ipa: rkisp1: cproc: Convert to use Quantized\n\ttypes","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Kieran Bingham (2025-10-29 17:24:34)\n> Convert the Contrast and Saturuation helper functions to a Quantizer\n> type to support maintaining the data.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/ipa/rkisp1/algorithms/cproc.cpp | 36 +++++++++++------------------\n>  src/ipa/rkisp1/ipa_context.h        | 20 +++++++++++-----\n>  2 files changed, 28 insertions(+), 28 deletions(-)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp\n> index d1fff6990d37..4637a824af03 100644\n> --- a/src/ipa/rkisp1/algorithms/cproc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/cproc.cpp\n> @@ -14,6 +14,8 @@\n>  \n>  #include <libcamera/control_ids.h>\n>  \n> +#include \"libipa/quantized.h\"\n> +\n>  /**\n>   * \\file cproc.h\n>   */\n> @@ -39,16 +41,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 +66,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,35 +89,35 @@ 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>                 }\n>  \n> -               LOG(RkISP1CProc, Debug) << \"Set brightness to \" << value;\n> +               LOG(RkISP1CProc, Debug) << \"Set brightness to \" << value.value();\n>         }\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>                 }\n>  \n> -               LOG(RkISP1CProc, Debug) << \"Set contrast to \" << value;\n> +               LOG(RkISP1CProc, Debug) << \"Set contrast to \" << value.value();\n>         }\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>                 }\n>  \n> -               LOG(RkISP1CProc, Debug) << \"Set saturation to \" << value;\n> +               LOG(RkISP1CProc, Debug) << \"Set saturation to \" << value.value();\n>         }\n>  \n>         frameContext.cproc.brightness = cproc.brightness;\n> @@ -148,9 +140,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 f85a130d9c23..0a5fb2769d31 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -8,6 +8,7 @@\n>  \n>  #pragma once\n>  \n> +#include <algorithm>\n\nThis was from when I was adding clamps in here before I had these new\ntrait types - so can be removed now.\n\n>  #include <memory>\n>  \n>  #include <linux/rkisp1-config.h>\n> @@ -27,11 +28,17 @@\n>  #include <libipa/camera_sensor_helper.h>\n>  #include <libipa/fc_queue.h>\n>  #include \"libipa/agc_mean_luminance.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 = Q1_7;\n> +using ContrastQ = UQ1_7;\n> +using SaturationQ = UQ1_7;\n> +\n>  struct IPAHwSettings {\n>         unsigned int numAeCells;\n>         unsigned int numHistogramBins;\n> @@ -115,9 +122,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> @@ -169,9 +176,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> 2.50.1\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 186F6C3259\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 29 Oct 2025 21:14:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4D80D6086F;\n\tWed, 29 Oct 2025 22:14:46 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A3EDB60856\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Oct 2025 22:14:44 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0ECC41E1B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Oct 2025 22:12:54 +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=\"EPKjreAC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761772375;\n\tbh=qP7UUETyhyMyWiZVczYbeQM+Zguh9EZnYkUgAOUFDSE=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=EPKjreACV+jvBuxsZZV01u1cxYo2GbtnFwTtkFMxXxjk6tQ3RWTcpYWDB9+qnQE5M\n\tUfavqyrZI4+DdY4F1/mY9kFmlc+XEqh9tDSV6MCJHmEWO2BpCapKNrnNhxrF53BuXl\n\tyUOEqTWF6ZGokt7K/tIJVE/P51aklf8e+DHVZ7hQ=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251029172439.1513907-10-kieran.bingham@ideasonboard.com>","References":"<20251029172439.1513907-1-kieran.bingham@ideasonboard.com>\n\t<20251029172439.1513907-10-kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v2 09/13] ipa: rkisp1: cproc: Convert to use Quantized\n\ttypes","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Wed, 29 Oct 2025 21:14:41 +0000","Message-ID":"<176177248115.2017750.715648752418595544@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]