[{"id":32897,"web_url":"https://patchwork.libcamera.org/comment/32897/","msgid":"<20241220102033.GE8313@pendragon.ideasonboard.com>","date":"2024-12-20T10:20:33","subject":"Re: [PATCH v3 2/2] ipa: rkisp1: Add Lux algorithm module","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Wed, Dec 18, 2024 at 04:46:01PM +0900, Paul Elder wrote:\n> Add a lux algorithm module to rkisp1 IPA for estimating the lux level of\n> an image. This is reported in metadata, as well as saved in the frame\n> context so that other algorithms (mainly AGC) can use its value. It does\n> not set any controls.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> Changes in v3:\n> - remove unnecessary includes\n> - replace ipa::Lux::bitSize() with ipa::Lux::Lux()\n> - move frameContext.agc.lux to frameContext.lux.lux\n> \n> Changes in v2:\n> - fix bitrot\n> - fixes corresponding to changes in the previous patch\n> ---\n>  src/ipa/rkisp1/algorithms/lux.cpp     | 80 +++++++++++++++++++++++++++\n>  src/ipa/rkisp1/algorithms/lux.h       | 36 ++++++++++++\n>  src/ipa/rkisp1/algorithms/meson.build |  1 +\n>  src/ipa/rkisp1/ipa_context.h          |  4 ++\n>  4 files changed, 121 insertions(+)\n>  create mode 100644 src/ipa/rkisp1/algorithms/lux.cpp\n>  create mode 100644 src/ipa/rkisp1/algorithms/lux.h\n> \n> diff --git a/src/ipa/rkisp1/algorithms/lux.cpp b/src/ipa/rkisp1/algorithms/lux.cpp\n> new file mode 100644\n> index 000000000000..a1e3f36b75cb\n> --- /dev/null\n> +++ b/src/ipa/rkisp1/algorithms/lux.cpp\n> @@ -0,0 +1,80 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2024, Ideas On Board\n> + *\n> + * lux.cpp - RkISP1 Lux control\n> + */\n> +\n> +#include \"lux.h\"\n> +\n> +#include <libcamera/base/log.h>\n> +\n> +#include <libcamera/control_ids.h>\n> +\n> +#include \"libipa/histogram.h\"\n> +#include \"libipa/lux.h\"\n> +\n> +/**\n> + * \\file lux.h\n> + */\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::rkisp1::algorithms {\n> +\n> +/**\n> + * \\class Lux\n> + * \\brief RkISP1 Lux control\n> + *\n> + * The Lux algorithm is responsible for estimating the lux level of the image.\n> + * It doesn't take or generate any controls, but it provides a lux level for\n> + * other algorithms (such as AGC) to use.\n> + */\n> +\n> +/**\n> + * \\brief Construct an rkisp1 Lux algo module\n> + *\n> + * The Lux helper is initialized to 65535 as that is the max bin count on the\n> + * rkisp1.\n> + */\n> +Lux::Lux()\n> +\t: lux_(65535)\n> +{\n> +}\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::init\n> + */\n> +int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)\n> +{\n> +\treturn lux_.parseTuningData(tuningData);\n> +}\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::process\n> + */\n> +void Lux::process(IPAContext &context,\n> +\t\t  [[maybe_unused]] const uint32_t frame,\n> +\t\t  IPAFrameContext &frameContext,\n> +\t\t  const rkisp1_stat_buffer *stats,\n> +\t\t  ControlList &metadata)\n> +{\n> +\tutils::Duration exposureTime = context.configuration.sensor.lineDuration\n> +\t\t\t\t       * frameContext.sensor.exposure;\n\nAlign * with =.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\tdouble gain = frameContext.sensor.gain;\n> +\n> +\t/* \\todo Deduplicate the histogram calculation from AGC */\n> +\tconst rkisp1_cif_isp_stat *params = &stats->params;\n> +\tHistogram yHist({ params->hist.hist_bins, context.hw->numHistogramBins },\n> +\t\t\t[](uint32_t x) { return x >> 4; });\n> +\n> +\tdouble lux = lux_.estimateLux(exposureTime, gain, 1.0, yHist);\n> +\tframeContext.lux.lux = lux;\n> +\tmetadata.set(controls::Lux, lux);\n> +}\n> +\n> +REGISTER_IPA_ALGORITHM(Lux, \"Lux\")\n> +\n> +} /* namespace ipa::rkisp1::algorithms */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/rkisp1/algorithms/lux.h b/src/ipa/rkisp1/algorithms/lux.h\n> new file mode 100644\n> index 000000000000..8a90de55b8ff\n> --- /dev/null\n> +++ b/src/ipa/rkisp1/algorithms/lux.h\n> @@ -0,0 +1,36 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2024, Ideas On Board\n> + *\n> + * lux.h - RkISP1 Lux control\n> + */\n> +\n> +#pragma once\n> +\n> +#include <sys/types.h>\n> +\n> +#include \"libipa/lux.h\"\n> +\n> +#include \"algorithm.h\"\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::rkisp1::algorithms {\n> +\n> +class Lux : public Algorithm\n> +{\n> +public:\n> +\tLux();\n> +\n> +\tint init(IPAContext &context, const YamlObject &tuningData) override;\n> +\tvoid process(IPAContext &context, const uint32_t frame,\n> +\t\t     IPAFrameContext &frameContext,\n> +\t\t     const rkisp1_stat_buffer *stats,\n> +\t\t     ControlList &metadata) override;\n> +\n> +private:\n> +\tipa::Lux lux_;\n> +};\n> +\n> +} /* namespace ipa::rkisp1::algorithms */\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build\n> index 1734a6675f78..c66b0b70b82f 100644\n> --- a/src/ipa/rkisp1/algorithms/meson.build\n> +++ b/src/ipa/rkisp1/algorithms/meson.build\n> @@ -12,4 +12,5 @@ rkisp1_ipa_algorithms = files([\n>      'goc.cpp',\n>      'gsl.cpp',\n>      'lsc.cpp',\n> +    'lux.cpp',\n>  ])\n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index deb8c196f1b8..65ba45151611 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -168,6 +168,10 @@ struct IPAFrameContext : public FrameContext {\n>  \tstruct {\n>  \t\tMatrix<float, 3, 3> ccm;\n>  \t} ccm;\n> +\n> +\tstruct {\n> +\t\tdouble lux;\n> +\t} lux;\n>  };\n>  \n>  struct IPAContext {","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 8C32BC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 Dec 2024 10:20:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4E28268492;\n\tFri, 20 Dec 2024 11:20:42 +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 95E1E62C8A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Dec 2024 11:20:39 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2C4957E2;\n\tFri, 20 Dec 2024 11:20:00 +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=\"lST0UUdk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734690000;\n\tbh=mBA3rh/maK+SZVHiGrXjLG4k/wKPUQT5pL1wH94hhZc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=lST0UUdkOcKbQdN8+PrMpFFWliXLc8WpJigNiJBVIouOcGZvqrXd6KT953VuW0xnI\n\tf/Iqq/DRjTa2TS12nNWPQhaKbuTYg+Sa/P5Gf+eJd8btN+b+UPHLcw9EPV7FrmskgE\n\task9ROyIpqtiZObfHY/ngfDi0QStTYDaqd9UtT+0=","Date":"Fri, 20 Dec 2024 12:20:33 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, stefan.klug@ideasonboard.com,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v3 2/2] ipa: rkisp1: Add Lux algorithm module","Message-ID":"<20241220102033.GE8313@pendragon.ideasonboard.com>","References":"<20241218074601.3552093-1-paul.elder@ideasonboard.com>\n\t<20241218074601.3552093-3-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20241218074601.3552093-3-paul.elder@ideasonboard.com>","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>"}},{"id":32903,"web_url":"https://patchwork.libcamera.org/comment/32903/","msgid":"<c1f872e1e560ea0b506ab0bf1af20d367b014507.camel@ideasonboard.com>","date":"2024-12-20T16:13:51","subject":"Re: [PATCH v3 2/2] ipa: rkisp1: Add Lux algorithm module","submitter":{"id":215,"url":"https://patchwork.libcamera.org/api/people/215/","name":"Isaac Scott","email":"isaac.scott@ideasonboard.com"},"content":"On Wed, 2024-12-18 at 16:46 +0900, Paul Elder wrote:\n> Add a lux algorithm module to rkisp1 IPA for estimating the lux level\n> of\n> an image. This is reported in metadata, as well as saved in the frame\n> context so that other algorithms (mainly AGC) can use its value. It\n> does\n> not set any controls.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> Changes in v3:\n> - remove unnecessary includes\n> - replace ipa::Lux::bitSize() with ipa::Lux::Lux()\n> - move frameContext.agc.lux to frameContext.lux.lux\n> \n> Changes in v2:\n> - fix bitrot\n> - fixes corresponding to changes in the previous patch\n> ---\n>  src/ipa/rkisp1/algorithms/lux.cpp     | 80\n> +++++++++++++++++++++++++++\n>  src/ipa/rkisp1/algorithms/lux.h       | 36 ++++++++++++\n>  src/ipa/rkisp1/algorithms/meson.build |  1 +\n>  src/ipa/rkisp1/ipa_context.h          |  4 ++\n>  4 files changed, 121 insertions(+)\n>  create mode 100644 src/ipa/rkisp1/algorithms/lux.cpp\n>  create mode 100644 src/ipa/rkisp1/algorithms/lux.h\n> \n> diff --git a/src/ipa/rkisp1/algorithms/lux.cpp\n> b/src/ipa/rkisp1/algorithms/lux.cpp\n> new file mode 100644\n> index 000000000000..a1e3f36b75cb\n> --- /dev/null\n> +++ b/src/ipa/rkisp1/algorithms/lux.cpp\n> @@ -0,0 +1,80 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2024, Ideas On Board\n> + *\n> + * lux.cpp - RkISP1 Lux control\n> + */\n> +\n\nReviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n\n> +#include \"lux.h\"\n> +\n> +#include <libcamera/base/log.h>\n> +\n> +#include <libcamera/control_ids.h>\n> +\n> +#include \"libipa/histogram.h\"\n> +#include \"libipa/lux.h\"\n> +\n> +/**\n> + * \\file lux.h\n> + */\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::rkisp1::algorithms {\n> +\n> +/**\n> + * \\class Lux\n> + * \\brief RkISP1 Lux control\n> + *\n> + * The Lux algorithm is responsible for estimating the lux level of\n> the image.\n> + * It doesn't take or generate any controls, but it provides a lux\n> level for\n> + * other algorithms (such as AGC) to use.\n> + */\n> +\n> +/**\n> + * \\brief Construct an rkisp1 Lux algo module\n> + *\n> + * The Lux helper is initialized to 65535 as that is the max bin\n> count on the\n> + * rkisp1.\n> + */\n> +Lux::Lux()\n> +\t: lux_(65535)\n> +{\n> +}\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::init\n> + */\n> +int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject\n> &tuningData)\n> +{\n> +\treturn lux_.parseTuningData(tuningData);\n> +}\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::process\n> + */\n> +void Lux::process(IPAContext &context,\n> +\t\t  [[maybe_unused]] const uint32_t frame,\n> +\t\t  IPAFrameContext &frameContext,\n> +\t\t  const rkisp1_stat_buffer *stats,\n> +\t\t  ControlList &metadata)\n> +{\n> +\tutils::Duration exposureTime =\n> context.configuration.sensor.lineDuration\n> +\t\t\t\t       *\n> frameContext.sensor.exposure;\n> +\tdouble gain = frameContext.sensor.gain;\n> +\n> +\t/* \\todo Deduplicate the histogram calculation from AGC */\n> +\tconst rkisp1_cif_isp_stat *params = &stats->params;\n> +\tHistogram yHist({ params->hist.hist_bins, context.hw-\n> >numHistogramBins },\n> +\t\t\t[](uint32_t x) { return x >> 4; });\n> +\n> +\tdouble lux = lux_.estimateLux(exposureTime, gain, 1.0,\n> yHist);\n> +\tframeContext.lux.lux = lux;\n> +\tmetadata.set(controls::Lux, lux);\n> +}\n> +\n> +REGISTER_IPA_ALGORITHM(Lux, \"Lux\")\n> +\n> +} /* namespace ipa::rkisp1::algorithms */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/rkisp1/algorithms/lux.h\n> b/src/ipa/rkisp1/algorithms/lux.h\n> new file mode 100644\n> index 000000000000..8a90de55b8ff\n> --- /dev/null\n> +++ b/src/ipa/rkisp1/algorithms/lux.h\n> @@ -0,0 +1,36 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2024, Ideas On Board\n> + *\n> + * lux.h - RkISP1 Lux control\n> + */\n> +\n> +#pragma once\n> +\n> +#include <sys/types.h>\n> +\n> +#include \"libipa/lux.h\"\n> +\n> +#include \"algorithm.h\"\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::rkisp1::algorithms {\n> +\n> +class Lux : public Algorithm\n> +{\n> +public:\n> +\tLux();\n> +\n> +\tint init(IPAContext &context, const YamlObject &tuningData)\n> override;\n> +\tvoid process(IPAContext &context, const uint32_t frame,\n> +\t\t     IPAFrameContext &frameContext,\n> +\t\t     const rkisp1_stat_buffer *stats,\n> +\t\t     ControlList &metadata) override;\n> +\n> +private:\n> +\tipa::Lux lux_;\n> +};\n> +\n> +} /* namespace ipa::rkisp1::algorithms */\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/rkisp1/algorithms/meson.build\n> b/src/ipa/rkisp1/algorithms/meson.build\n> index 1734a6675f78..c66b0b70b82f 100644\n> --- a/src/ipa/rkisp1/algorithms/meson.build\n> +++ b/src/ipa/rkisp1/algorithms/meson.build\n> @@ -12,4 +12,5 @@ rkisp1_ipa_algorithms = files([\n>      'goc.cpp',\n>      'gsl.cpp',\n>      'lsc.cpp',\n> +    'lux.cpp',\n>  ])\n> diff --git a/src/ipa/rkisp1/ipa_context.h\n> b/src/ipa/rkisp1/ipa_context.h\n> index deb8c196f1b8..65ba45151611 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -168,6 +168,10 @@ struct IPAFrameContext : public FrameContext {\n>  \tstruct {\n>  \t\tMatrix<float, 3, 3> ccm;\n>  \t} ccm;\n> +\n> +\tstruct {\n> +\t\tdouble lux;\n> +\t} lux;\n>  };\n>  \n>  struct IPAContext {","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 CECA7C3274\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 Dec 2024 16:13:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E781E684A6;\n\tFri, 20 Dec 2024 17:13:56 +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 6703E6849F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Dec 2024 17:13:55 +0100 (CET)","from isaac-ThinkPad-T16-Gen-2.lan\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 9C952B2B;\n\tFri, 20 Dec 2024 17:13:15 +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=\"oiwINyeS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734711195;\n\tbh=v2UguUyyxNt7nUtHBp1vF11oEMa5PfL3gJeIcCLHgfs=;\n\th=Subject:From:To:Cc:Date:In-Reply-To:References:From;\n\tb=oiwINyeS7bQNf8iaghcJCLzGSGqLZQQgmEYtuU1Sbyb0UTvQ4gP7eGosdq3cehH6+\n\tpcu3FBfK0PLPALpk1aflSuq5FgDca0mH4VTTcnM3pU1J98VmzycS9iwFM7yJfQOyWJ\n\to8pHzaBtT3zXV6qauguBmdSkFQkK0/rQ0m8x+/sk=","Message-ID":"<c1f872e1e560ea0b506ab0bf1af20d367b014507.camel@ideasonboard.com>","Subject":"Re: [PATCH v3 2/2] ipa: rkisp1: Add Lux algorithm module","From":"Isaac Scott <isaac.scott@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>, \n\tlibcamera-devel@lists.libcamera.org, laurent.pinchart@ideasonboard.com,\n\tstefan.klug@ideasonboard.com","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Date":"Fri, 20 Dec 2024 16:13:51 +0000","In-Reply-To":"<20241218074601.3552093-3-paul.elder@ideasonboard.com>","References":"<20241218074601.3552093-1-paul.elder@ideasonboard.com>\n\t<20241218074601.3552093-3-paul.elder@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","User-Agent":"Evolution 3.54.2 (by Flathub.org) ","MIME-Version":"1.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>"}}]