[{"id":29444,"web_url":"https://patchwork.libcamera.org/comment/29444/","msgid":"<ZjtWIc8ANseSgTqU@pyrite.rasen.tech>","date":"2024-05-08T10:38:25","subject":"Re: [PATCH v3] ipa: libipa: histogram: Add transform parameter to\n\tconstructor","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Wed, May 08, 2024 at 07:35:46PM +0900, Paul Elder wrote:\n> Add a parameter to the histogram constructor that takes a transformation\n> function to apply to all the bins upon construction.\n> \n> This is necessary notably for the rkisp1, as the values reported from\n> the hardware are 20 bits where the upper 16-bits are meaningful integer\n> values and the lower 4 bits are fractional and meant to be discarded. As\n> adding a right-shift parameter is probably too specialized, a generic\n> function is added as a parameter instead.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\nOops, I forgot to pull in Kieran's and Dan's rb tags.\n\n\nPaul\n\n> \n> ---\n> Changes in v3:\n> - make the transform function a template parameter, and optimize the\n>   constructor\n> \n> This used to be \"ipa: libipa: histogram: Add rshift parameter to\n> constructor\"\n> \n> Changes in v2:\n> - change rshift parameter to a function parameter\n> ---\n>  src/ipa/libipa/histogram.cpp |  8 +-------\n>  src/ipa/libipa/histogram.h   | 14 ++++++++++++--\n>  2 files changed, 13 insertions(+), 9 deletions(-)\n> \n> diff --git a/src/ipa/libipa/histogram.cpp b/src/ipa/libipa/histogram.cpp\n> index c1aac59b..628e3755 100644\n> --- a/src/ipa/libipa/histogram.cpp\n> +++ b/src/ipa/libipa/histogram.cpp\n> @@ -40,14 +40,8 @@ namespace ipa {\n>  /**\n>   * \\brief Create a cumulative histogram\n>   * \\param[in] data A pre-sorted histogram to be passed\n> + * \\param[in] transform The transformation function to apply to every bin\n>   */\n> -Histogram::Histogram(Span<const uint32_t> data)\n> -{\n> -\tcumulative_.reserve(data.size());\n> -\tcumulative_.push_back(0);\n> -\tfor (const uint32_t &value : data)\n> -\t\tcumulative_.push_back(cumulative_.back() + value);\n> -}\n>  \n>  /**\n>   * \\fn Histogram::bins()\n> diff --git a/src/ipa/libipa/histogram.h b/src/ipa/libipa/histogram.h\n> index 54bb2a19..26326125 100644\n> --- a/src/ipa/libipa/histogram.h\n> +++ b/src/ipa/libipa/histogram.h\n> @@ -10,10 +10,10 @@\n>  #include <assert.h>\n>  #include <limits.h>\n>  #include <stdint.h>\n> -\n>  #include <vector>\n>  \n>  #include <libcamera/base/span.h>\n> +#include <libcamera/base/utils.h>\n>  \n>  namespace libcamera {\n>  \n> @@ -23,7 +23,17 @@ class Histogram\n>  {\n>  public:\n>  \tHistogram() { cumulative_.push_back(0); }\n> -\tHistogram(Span<const uint32_t> data);\n> +\n> +\ttemplate<typename Transform>\n> +\tHistogram(Span<const uint32_t> data,\n> +\t\t  Transform transform = [](uint32_t x) { return x; })\n> +\t{\n> +\t\tcumulative_.resize(data.size() + 1);\n> +\t\tcumulative_[0] = 0;\n> +\t\tfor (const auto &[i, value] : utils::enumerate(data))\n> +\t\t\tcumulative_[i + 1] = cumulative_[i] + transform(value);\n> +\t}\n> +\n>  \tsize_t bins() const { return cumulative_.size() - 1; }\n>  \tuint64_t total() const { return cumulative_[cumulative_.size() - 1]; }\n>  \tuint64_t cumulativeFrequency(double bin) const;\n> -- \n> 2.39.2\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 538C8C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  8 May 2024 10:38:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6195663439;\n\tWed,  8 May 2024 12:38:33 +0200 (CEST)","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 23A9661A73\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 May 2024 12:38:32 +0200 (CEST)","from pyrite.rasen.tech (h175-177-049-156.catv02.itscom.jp\n\t[175.177.49.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A1D1DB0B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 May 2024 12:38:28 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Sgxzcsgf\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1715164709;\n\tbh=FzN9sOSgocSSfcKfVcD81cPvpOki6kE12ay+zr5GxhQ=;\n\th=Date:From:To:Subject:References:In-Reply-To:From;\n\tb=Sgxzcsgf6uhu37Yg3soeRLzSfAXtUD5yUlk2KWau3N9GuYFlZotZMz6C5nxLerdV9\n\tK7yJWEv5NG7ugKKYppWeZL5iV+woaWSTDqukXch+PW4H2flKHoTq46KAvZ4z6V83Yw\n\t1a3iIDpUYDupQgrZF3d3bfibpCkPfJxt508P5TCY=","Date":"Wed, 8 May 2024 19:38:25 +0900","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v3] ipa: libipa: histogram: Add transform parameter to\n\tconstructor","Message-ID":"<ZjtWIc8ANseSgTqU@pyrite.rasen.tech>","References":"<20240508103546.693219-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20240508103546.693219-1-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":29447,"web_url":"https://patchwork.libcamera.org/comment/29447/","msgid":"<bZoccajlABUKFwCXuEnOI92YqrJd0bTAzFSjyGdX62vCAR78Z-MeiLSdIGaYufJzvOU9VzUFA0u9irYqtk2EGyILd_egrJSCQFAaAqXGROo=@protonmail.com>","date":"2024-05-08T13:08:31","subject":"Re: [PATCH v3] ipa: libipa: histogram: Add transform parameter to\n\tconstructor","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/people/133/","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"content":"Hi\n\n\n2024. május 8., szerda 12:35 keltezéssel, Paul Elder <paul.elder@ideasonboard.com> írta:\n\n> Add a parameter to the histogram constructor that takes a transformation\n> function to apply to all the bins upon construction.\n> \n> This is necessary notably for the rkisp1, as the values reported from\n> the hardware are 20 bits where the upper 16-bits are meaningful integer\n> values and the lower 4 bits are fractional and meant to be discarded. As\n> adding a right-shift parameter is probably too specialized, a generic\n> function is added as a parameter instead.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> \n> [...]\n> diff --git a/src/ipa/libipa/histogram.h b/src/ipa/libipa/histogram.h\n> index 54bb2a19..26326125 100644\n> --- a/src/ipa/libipa/histogram.h\n> +++ b/src/ipa/libipa/histogram.h\n> @@ -10,10 +10,10 @@\n>  #include <assert.h>\n>  #include <limits.h>\n>  #include <stdint.h>\n> -\n>  #include <vector>\n> \n>  #include <libcamera/base/span.h>\n> +#include <libcamera/base/utils.h>\n> \n>  namespace libcamera {\n> \n> @@ -23,7 +23,17 @@ class Histogram\n>  {\n>  public:\n>  \tHistogram() { cumulative_.push_back(0); }\n> -\tHistogram(Span<const uint32_t> data);\n> +\n> +\ttemplate<typename Transform>\n> +\tHistogram(Span<const uint32_t> data,\n> +\t\t  Transform transform = [](uint32_t x) { return x; })\n> +\t{\n> +\t\tcumulative_.resize(data.size() + 1);\n> +\t\tcumulative_[0] = 0;\n> +\t\tfor (const auto &[i, value] : utils::enumerate(data))\n> +\t\t\tcumulative_[i + 1] = cumulative_[i] + transform(value);\n> +\t}\n\nAs far as I am aware this won't compile if called with just a single argument.\n\nYou can solve that by adding another constructor, like this:\n\n  Histogram(Span<const uint32_t> data)\n    : Histogram(data, [](uint32_t x) { return x; })\n  { }\n\nand removing the default argument from the other.\n\n\n> [...]\n\n\nRegards,\nBarnabás Pőcze","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 9F848C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  8 May 2024 13:08:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0DB7D63437;\n\tWed,  8 May 2024 15:08:39 +0200 (CEST)","from mail-40133.protonmail.ch (mail-40133.protonmail.ch\n\t[185.70.40.133])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 344F661A73\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 May 2024 15:08:38 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"WdjGRmyR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1715173717; x=1715432917;\n\tbh=FlA2SUP8a/u/gmw7w/TbgEsDEeONoOGsqtIH7Y1k1zA=;\n\th=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References:\n\tFeedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:\n\tMessage-ID:BIMI-Selector;\n\tb=WdjGRmyRlSx/KyzDZRaP8tAjtdQHycRhQk+BtPoYMBG9r67tEQH1Rra4muPK/ki8o\n\tZ3bPBMWm/hzxtItIKrrAWDMDfF9mvoSRHIgbowtTUoeGOQO9FOjNMp6+XQigpoZ4hP\n\tM12c73EC8Q1ptGHLpJ9yiFtSJ871qgOwjBVmYVoch00s8llQkApCvvH3WaoVtwPtKY\n\tt7H4IUSdpPXyB3bNcFdA+4c6V38DuI6kj+0lFyzRtwUKgmoR6OVsefSv1zHDNZr5Gn\n\tpP5HO6WOLb7d+xdcCCT6VHACj/+ekU6cbqOBivril5BnoZ/9kk9l5kglVmPinOfKE1\n\t2dARXFcIaEXyQ==","Date":"Wed, 08 May 2024 13:08:31 +0000","To":"Paul Elder <paul.elder@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v3] ipa: libipa: histogram: Add transform parameter to\n\tconstructor","Message-ID":"<bZoccajlABUKFwCXuEnOI92YqrJd0bTAzFSjyGdX62vCAR78Z-MeiLSdIGaYufJzvOU9VzUFA0u9irYqtk2EGyILd_egrJSCQFAaAqXGROo=@protonmail.com>","In-Reply-To":"<20240508103546.693219-1-paul.elder@ideasonboard.com>","References":"<20240508103546.693219-1-paul.elder@ideasonboard.com>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"0995a1100e5908dcf6653be0fbcf1e5dff9a68a1","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","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":29453,"web_url":"https://patchwork.libcamera.org/comment/29453/","msgid":"<ZjuSj-fR-ctf4a1g@pyrite.rasen.tech>","date":"2024-05-08T14:56:15","subject":"Re: [PATCH v3] ipa: libipa: histogram: Add transform parameter to\n\tconstructor","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Wed, May 08, 2024 at 01:08:31PM +0000, Barnabás Pőcze wrote:\n> Hi\n> \n> \n> 2024. május 8., szerda 12:35 keltezéssel, Paul Elder <paul.elder@ideasonboard.com> írta:\n> \n> > Add a parameter to the histogram constructor that takes a transformation\n> > function to apply to all the bins upon construction.\n> > \n> > This is necessary notably for the rkisp1, as the values reported from\n> > the hardware are 20 bits where the upper 16-bits are meaningful integer\n> > values and the lower 4 bits are fractional and meant to be discarded. As\n> > adding a right-shift parameter is probably too specialized, a generic\n> > function is added as a parameter instead.\n> > \n> > Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> > \n> > [...]\n> > diff --git a/src/ipa/libipa/histogram.h b/src/ipa/libipa/histogram.h\n> > index 54bb2a19..26326125 100644\n> > --- a/src/ipa/libipa/histogram.h\n> > +++ b/src/ipa/libipa/histogram.h\n> > @@ -10,10 +10,10 @@\n> >  #include <assert.h>\n> >  #include <limits.h>\n> >  #include <stdint.h>\n> > -\n> >  #include <vector>\n> > \n> >  #include <libcamera/base/span.h>\n> > +#include <libcamera/base/utils.h>\n> > \n> >  namespace libcamera {\n> > \n> > @@ -23,7 +23,17 @@ class Histogram\n> >  {\n> >  public:\n> >  \tHistogram() { cumulative_.push_back(0); }\n> > -\tHistogram(Span<const uint32_t> data);\n> > +\n> > +\ttemplate<typename Transform>\n> > +\tHistogram(Span<const uint32_t> data,\n> > +\t\t  Transform transform = [](uint32_t x) { return x; })\n> > +\t{\n> > +\t\tcumulative_.resize(data.size() + 1);\n> > +\t\tcumulative_[0] = 0;\n> > +\t\tfor (const auto &[i, value] : utils::enumerate(data))\n> > +\t\t\tcumulative_[i + 1] = cumulative_[i] + transform(value);\n> > +\t}\n> \n> As far as I am aware this won't compile if called with just a single argument.\n> \n> You can solve that by adding another constructor, like this:\n> \n>   Histogram(Span<const uint32_t> data)\n>     : Histogram(data, [](uint32_t x) { return x; })\n>   { }\n\nYeeep I realized that soon after...\n\nNew version incoming!\n\n\nPaul\n\n> \n> and removing the default argument from the other.\n> \n> \n> > [...]\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 56657C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  8 May 2024 14:56:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 307C262C9F;\n\tWed,  8 May 2024 16:56:24 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D0D0562C9F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 May 2024 16:56:21 +0200 (CEST)","from pyrite.rasen.tech (h175-177-049-156.catv02.itscom.jp\n\t[175.177.49.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D0588B0B;\n\tWed,  8 May 2024 16:56:17 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"cDXTjQgz\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1715180178;\n\tbh=WWXBhmLdtBQNfIqqE3esIMWJ59sGEzYd5zv60ITPVcU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=cDXTjQgzDkf1HDwX36wnb18mR2LkS2iigc5UpH+khWx89UJg2ET3n2RfuCPArhBRs\n\tLthzuoSvsvXWC5X8bKgbReLML1IkifbVEHCajuQcib6V/nHqKbUXT7mIpkgTNqaCDY\n\tTJ07Tf5naMtu0PTGEbd499S3GqFoDfHVmXh4GoH4=","Date":"Wed, 8 May 2024 23:56:15 +0900","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v3] ipa: libipa: histogram: Add transform parameter to\n\tconstructor","Message-ID":"<ZjuSj-fR-ctf4a1g@pyrite.rasen.tech>","References":"<20240508103546.693219-1-paul.elder@ideasonboard.com>\n\t<bZoccajlABUKFwCXuEnOI92YqrJd0bTAzFSjyGdX62vCAR78Z-MeiLSdIGaYufJzvOU9VzUFA0u9irYqtk2EGyILd_egrJSCQFAaAqXGROo=@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<bZoccajlABUKFwCXuEnOI92YqrJd0bTAzFSjyGdX62vCAR78Z-MeiLSdIGaYufJzvOU9VzUFA0u9irYqtk2EGyILd_egrJSCQFAaAqXGROo=@protonmail.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>"}}]