[{"id":36545,"web_url":"https://patchwork.libcamera.org/comment/36545/","msgid":"<176177294873.2017750.5096577046906989535@ping.linuxembedded.co.uk>","date":"2025-10-29T21:22:28","subject":"Re: [PATCH v2 12/13] ipa: rkisp1: cproc: Provide a Hue control","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:37)\n> The RKISP1 supports a configurable Hue as part of the colour processing\n> unit (cproc).\n> \n> This is implemented as a phase shift of the chrominance values between\n> -90 and +87.188 degrees according to the datasheet however the type\n> itself would imply that this is a range between -90 and 89.2969.\n> \n> Implement the new control converting to the hardware scale accordingly\n> and report the applied control in the completed request metadata.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/ipa/rkisp1/algorithms/cproc.cpp | 18 ++++++++++++++++++\n>  src/ipa/rkisp1/ipa_context.h        |  3 +++\n>  2 files changed, 21 insertions(+)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp\n> index 7475e6c1b609..5389882c1685 100644\n> --- a/src/ipa/rkisp1/algorithms/cproc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/cproc.cpp\n> @@ -39,6 +39,7 @@ namespace {\n>  \n>  constexpr float kDefaultBrightness = 0.0f;\n>  constexpr float kDefaultContrast = 1.0f;\n> +constexpr float kDefaultHue = 0.0f;\n>  constexpr float kDefaultSaturation = 1.0f;\n>  \n>  } /* namespace */\n> @@ -53,6 +54,8 @@ int ColorProcessing::init(IPAContext &context,\n>  \n>         cmap[&controls::Brightness] = ControlInfo(-1.0f, 0.993f, kDefaultBrightness);\n>         cmap[&controls::Contrast] = ControlInfo(0.0f, 1.993f, kDefaultContrast);\n> +       cmap[&controls::Hue] = ControlInfo(HueQ::TraitsType::min,\n> +                                          HueQ::TraitsType::max, kDefaultHue);\n\nI've only used this style on the Hue addition because I want to know if\nit is more generally preferred to pass through the type min/max or\ndefine them like in Brightness/Contrast/Saturation.\n\nI think setting the control info from the range of the HueQ is quite\ngood - but then obfuscates the values here in the code a little. Still\nthey could be commented with the expected values perhaps.\n\nI also wonder about adding\n\n <typename Traits>\n struct Quantized {\n+   Traits::quantized_type min = Traits::min;\n+   Traist::quantized_type max = Traits::max;\n ...\n }\n\nBut that would impose / force all Traits to set / define a min/max - and\nI'm not sure if we would want to do that for gain code conversions\n(generically). Maybe we could ... but I think we read min/max from the\ndriver so we couldn't do that constexpr.\n\n\n>         cmap[&controls::Saturation] = ControlInfo(0.0f, 1.993f, kDefaultSaturation);\n>  \n>         return 0;\n> @@ -68,6 +71,7 @@ int ColorProcessing::configure(IPAContext &context,\n>  \n>         cproc.brightness = BrightnessQ(kDefaultBrightness);\n>         cproc.contrast = ContrastQ(kDefaultContrast);\n> +       cproc.hue = HueQ(kDefaultHue);\n>         cproc.saturation = SaturationQ(kDefaultSaturation);\n>  \n>         return 0;\n> @@ -109,6 +113,17 @@ void ColorProcessing::queueRequest(IPAContext &context,\n>                 LOG(RkISP1CProc, Debug) << \"Set contrast to \" << value.value();\n>         }\n>  \n> +       const auto &hue = controls.get(controls::Hue);\n> +       if (hue) {\n> +               HueQ value = *hue;\n> +               if (cproc.hue != value) {\n> +                       cproc.hue = value;\n> +                       update = true;\n> +               }\n> +\n> +               LOG(RkISP1CProc, Debug) << \"Set hue to \" << value.value();\n> +       }\n> +\n>         const auto saturation = controls.get(controls::Saturation);\n>         if (saturation) {\n>                 SaturationQ value = *saturation;\n> @@ -122,6 +137,7 @@ void ColorProcessing::queueRequest(IPAContext &context,\n>  \n>         frameContext.cproc.brightness = cproc.brightness;\n>         frameContext.cproc.contrast = cproc.contrast;\n> +       frameContext.cproc.hue = cproc.hue;\n>         frameContext.cproc.saturation = cproc.saturation;\n>         frameContext.cproc.update = update;\n>  }\n> @@ -142,6 +158,7 @@ void ColorProcessing::prepare([[maybe_unused]] IPAContext &context,\n>         config.setEnabled(true);\n>         config->brightness = frameContext.cproc.brightness.quantized();\n>         config->contrast = frameContext.cproc.contrast.quantized();\n> +       config->hue = frameContext.cproc.hue.quantized();\n>         config->sat = frameContext.cproc.saturation.quantized();\n>  }\n>  \n> @@ -154,6 +171,7 @@ void ColorProcessing::process([[maybe_unused]] IPAContext &context, [[maybe_unus\n>  {\n>         metadata.set(controls::Brightness, frameContext.cproc.brightness.value());\n>         metadata.set(controls::Contrast, frameContext.cproc.contrast.value());\n> +       metadata.set(controls::Hue, frameContext.cproc.hue.value());\n>         metadata.set(controls::Saturation, frameContext.cproc.saturation.value());\n>  }\n>  \n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index 0a5fb2769d31..a4badbfc0c36 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -37,6 +37,7 @@ namespace ipa::rkisp1 {\n>  /* Fixed point types used by CPROC */\n>  using BrightnessQ = Q1_7;\n>  using ContrastQ = UQ1_7;\n> +using HueQ = Quantized<ScaledFixedPointQTraits<Q1_7::TraitsType, 90>>;\n>  using SaturationQ = UQ1_7;\n>  \n>  struct IPAHwSettings {\n> @@ -124,6 +125,7 @@ struct IPAActiveState {\n>         struct {\n>                 BrightnessQ brightness;\n>                 ContrastQ contrast;\n> +               HueQ hue;\n>                 SaturationQ saturation;\n>         } cproc;\n>  \n> @@ -178,6 +180,7 @@ struct IPAFrameContext : public FrameContext {\n>         struct {\n>                 BrightnessQ brightness;\n>                 ContrastQ contrast;\n> +               HueQ hue;\n>                 SaturationQ saturation;\n>  \n>                 bool update;\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 5F637BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 29 Oct 2025 21:22:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 64D83608BD;\n\tWed, 29 Oct 2025 22:22:33 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B165160856\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Oct 2025 22:22:31 +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 2F0CCBCA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Oct 2025 22:20:42 +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=\"ayaWcI9t\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761772842;\n\tbh=2UYAgvR6cP/JMWKAbXkml/+Jfg7aRASqeLlVb5z59Uw=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=ayaWcI9taNN5Y/bqfUWDlf3H7yoay0Un9/H5aSWFvUvEoKb1J3R/tt3YMSTQFxykO\n\tLgy3Cgv2PKTzgzr6Xa/mjq1pUCcYqvlQwcNZMKBmpOv+aBIPOlG3bVrrIPNWBbwkCV\n\tTThhPzO7EQd+LX6VD6D/OzUdkOUwC5Sra4Ic7NUc=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251029172439.1513907-13-kieran.bingham@ideasonboard.com>","References":"<20251029172439.1513907-1-kieran.bingham@ideasonboard.com>\n\t<20251029172439.1513907-13-kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v2 12/13] ipa: rkisp1: cproc: Provide a Hue control","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Wed, 29 Oct 2025 21:22:28 +0000","Message-ID":"<176177294873.2017750.5096577046906989535@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>"}}]