[{"id":26795,"web_url":"https://patchwork.libcamera.org/comment/26795/","msgid":"<168009080150.2652754.11196602694843384985@Monstersaurus>","date":"2023-03-29T11:53:21","subject":"Re: [libcamera-devel] [PATCH v2 08/10] ipa: raspberrypi: Generalise\n\tthe agc algorithm","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck via libcamera-devel (2023-03-27 13:20:28)\n> Remove any hard-coded assumptions about the target hardware platform\n> from the AGC algorithm. Instead, use the \"target\" string provided by\n> the camera tuning config and generalised statistics structures to\n> determing parameters such as grid and region sizes.\n> \n> This change replaces all hard-coded arrays with equivalent std::vector\n> types.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  src/ipa/raspberrypi/controller/rpi/agc.cpp | 20 +++++++++++++-------\n>  src/ipa/raspberrypi/controller/rpi/agc.h   |  9 +--------\n>  2 files changed, 14 insertions(+), 15 deletions(-)\n> \n> diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> index 4ea0dd41e66c..fb96bb556e84 100644\n> --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> @@ -31,17 +31,12 @@ LOG_DEFINE_CATEGORY(RPiAgc)\n>  int AgcMeteringMode::read(const libcamera::YamlObject &params)\n>  {\n>         const YamlObject &yamlWeights = params[\"weights\"];\n> -       if (yamlWeights.size() != AgcStatsSize) {\n> -               LOG(RPiAgc, Error) << \"AgcMeteringMode: Incorrect number of weights\";\n> -               return -EINVAL;\n> -       }\n>  \n> -       unsigned int num = 0;\n>         for (const auto &p : yamlWeights.asList()) {\n>                 auto value = p.get<double>();\n>                 if (!value)\n>                         return -EINVAL;\n> -               weights[num++] = *value;\n> +               weights.push_back(*value);\n>         }\n>  \n>         return 0;\n> @@ -249,6 +244,14 @@ int Agc::read(const libcamera::YamlObject &params)\n>         if (ret)\n>                 return ret;\n>  \n> +       const Size &size = getHardwareConfig().agcZoneWeights;\n> +       for (auto const &modes : config_.meteringModes) {\n> +               if (modes.second.weights.size() != size.width * size.height) {\n> +                       LOG(RPiAgc, Error) << \"AgcMeteringMode: Incorrect number of weights\";\n> +                       return -EINVAL;\n> +               }\n> +       }\n> +\n>         /*\n>          * Set the config's defaults (which are the first ones it read) as our\n>          * current modes, until someone changes them.  (they're all known to\n> @@ -582,9 +585,12 @@ void Agc::fetchAwbStatus(Metadata *imageMetadata)\n>  }\n>  \n>  static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,\n> -                             double weights[], double gain)\n> +                             std::vector<double> &weights, double gain)\n>  {\n>         constexpr uint64_t maxVal = 1 << Statistics::NormalisationFactorPow2;\n> +\n> +       ASSERT(weights.size() == stats->agcRegions.numRegions());\n> +\n>         /*\n>          * Note how the calculation below means that equal weights give you\n>          * \"average\" metering (i.e. all pixels equally important).\n> diff --git a/src/ipa/raspberrypi/controller/rpi/agc.h b/src/ipa/raspberrypi/controller/rpi/agc.h\n> index f04896ca25ad..d11a49c9cd85 100644\n> --- a/src/ipa/raspberrypi/controller/rpi/agc.h\n> +++ b/src/ipa/raspberrypi/controller/rpi/agc.h\n> @@ -17,17 +17,10 @@\n>  \n>  /* This is our implementation of AGC. */\n>  \n> -/*\n> - * This is the number actually set up by the firmware, not the maximum possible\n> - * number (which is 16).\n> - */\n> -\n> -constexpr unsigned int AgcStatsSize = 15;\n> -\n>  namespace RPiController {\n>  \n>  struct AgcMeteringMode {\n> -       double weights[AgcStatsSize];\n> +       std::vector<double> weights;\n>         int read(const libcamera::YamlObject &params);\n>  };\n>  \n> -- \n> 2.34.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 9EB75C0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 29 Mar 2023 11:53:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E86046271E;\n\tWed, 29 Mar 2023 13:53:25 +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 339BD626DB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Mar 2023 13:53:24 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net\n\t[82.37.23.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AFB5AAD0;\n\tWed, 29 Mar 2023 13:53:23 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1680090805;\n\tbh=HAwyiAMsSzytQK+7+m5z7A4bE1az/7fGI+Au/ITf95M=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=FLc3uJcaO4ks3GHREbIJ4wV66MDKA5qzhRotbsnz6SxhvFbL/9izrWxSZvMknMX0W\n\tX/Ga2Vt2F8fN8sBgUmieHYqdrZHtjuOA9TxR79fNG7N/dT6rQ7TjXHzXhqer2fpLL4\n\tgm27to19749UbQNGow/SE/EDulx/1VtwS1pD5xFWtRBwLcqUvOhkkXmJtRHjv0zmCU\n\tLyPt8gaM4xDnDFh/0s+cs+4UWUqJEEwlim/UrSdr5CL0ItdWhgKfESCwpxTJ+lx49p\n\tdcK9VdcL5KHj4XTxkB02BYt6suuk82rjZYLe81gN6WLcjDcDvmKfwEA0U+R7IHab8c\n\ti2cUzFi8Vwrag==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1680090803;\n\tbh=HAwyiAMsSzytQK+7+m5z7A4bE1az/7fGI+Au/ITf95M=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=KMGd80hdez49I3uRy21SF6ZpZAzdiPE4kKoOyufjjkFkbXbFd30h2DrBnTKF3gKYo\n\t0dt20HKf3L6ERdts69IsjWhxhgudhxUDER+Kr37faRDUrOB6nbtJTmXZ2F+SIaqZaG\n\tyJzMwUuwPtSyUoNTke0NcRpd9+h/5+8z4/qyB4Cg="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"KMGd80hd\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20230327122030.11756-9-naush@raspberrypi.com>","References":"<20230327122030.11756-1-naush@raspberrypi.com>\n\t<20230327122030.11756-9-naush@raspberrypi.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 29 Mar 2023 12:53:21 +0100","Message-ID":"<168009080150.2652754.11196602694843384985@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v2 08/10] ipa: raspberrypi: Generalise\n\tthe agc algorithm","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]