[{"id":25883,"web_url":"https://patchwork.libcamera.org/comment/25883/","msgid":"<CAHW6GYL6uxVxbMVUq3Lqs+f4D=LLey976=qrXS+WRZpy5-6-Vw@mail.gmail.com>","date":"2022-11-23T14:39:34","subject":"Re: [libcamera-devel] [PATCH v1 5/5] ipa: raspberrypi: Normalise\n\tregion sums to 16-bits","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Naush\n\nThanks for the patch.\n\nOn Tue, 22 Nov 2022 at 11:22, Naushir Patuck via libcamera-devel\n<libcamera-devel@lists.libcamera.org> wrote:\n>\n> The VC4 ISP uses a pipeline bit-depth of 13-bits. The AGC algorithm needs to\n> know this bit-depth when computing the Y value for the image.\n>\n> Instead of hardcoding the VC4 bit-depth in the AGC source code, normalise all\n> region sums to 16-bits when filling the Statistics structure. AWB and ALSC are\n> agonistic about pipline depth, so do not need chaning.\n\nOoh, this line went a bit wrong :)\ns/agonistic/agnostic/   (trying to imagine what an \"agonistic\"\nalgorithm might be!!)\ns/pipline/pipeline/\ns/chaning/changing.\n\nBut apart from that:\n\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n\nThanks!\nDavid\n\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  src/ipa/raspberrypi/controller/rpi/agc.cpp | 10 ++++------\n>  src/ipa/raspberrypi/raspberrypi.cpp        | 21 ++++++++++++++-------\n>  2 files changed, 18 insertions(+), 13 deletions(-)\n>\n> diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> index 79c83e0a9eae..358af8f2544b 100644\n> --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> @@ -28,8 +28,6 @@ LOG_DEFINE_CATEGORY(RPiAgc)\n>\n>  #define NAME \"rpi.agc\"\n>\n> -static constexpr unsigned int PipelineBits = 13; /* seems to be a 13-bit pipeline */\n> -\n>  int AgcMeteringMode::read(const libcamera::YamlObject &params)\n>  {\n>         const YamlObject &yamlWeights = params[\"weights\"];\n> @@ -593,9 +591,9 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,\n>         for (unsigned int i = 0; i < stats->agcRegions.numRegions(); i++) {\n>                 uint32_t counted, uncounted;\n>                 auto s = stats->agcRegions.get(i, counted, uncounted);\n> -               double rAcc = std::min<double>(s.rSum * gain, ((1 << PipelineBits) - 1) * counted);\n> -               double gAcc = std::min<double>(s.gSum * gain, ((1 << PipelineBits) - 1) * counted);\n> -               double bAcc = std::min<double>(s.bSum * gain, ((1 << PipelineBits) - 1) * counted);\n> +               double rAcc = std::min<double>(s.rSum * gain, ((1 << 16) - 1) * counted);\n> +               double gAcc = std::min<double>(s.gSum * gain, ((1 << 16) - 1) * counted);\n> +               double bAcc = std::min<double>(s.bSum * gain, ((1 << 16) - 1) * counted);\n>                 rSum += rAcc * weights[i];\n>                 gSum += gAcc * weights[i];\n>                 bSum += bAcc * weights[i];\n> @@ -608,7 +606,7 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,\n>         double ySum = rSum * awb.gainR * .299 +\n>                       gSum * awb.gainG * .587 +\n>                       bSum * awb.gainB * .114;\n> -       return ySum / pixelSum / (1 << PipelineBits);\n> +       return ySum / pixelSum / (1 << 16);\n>  }\n>\n>  /*\n> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n> index 8fcfa0b3ea50..fcecd60bcf6d 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -1132,19 +1132,26 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co\n>         /* RGB histograms are not used, so do not populate them. */\n>         statistics->yHist = std::move(RPiController::Histogram(stats->hist[0].g_hist, NUM_HISTOGRAM_BINS));\n>\n> +       /*\n> +        * All region sums are based on a 13-bit pipeline bit-depth. Normalise\n> +        * this to 16-bits for the AGC/AWB/ALSC algorithms.\n> +        */\n>         statistics->awbRegions.init(DEFAULT_AWB_REGIONS_X, DEFAULT_AWB_REGIONS_Y);\n>         for (i = 0; i < statistics->awbRegions.numRegions(); i++)\n> -               statistics->awbRegions.set(i, { stats->awb_stats[i].r_sum,\n> -                                               stats->awb_stats[i].g_sum,\n> -                                               stats->awb_stats[i].b_sum },\n> +               statistics->awbRegions.set(i, { stats->awb_stats[i].r_sum << 3,\n> +                                               stats->awb_stats[i].g_sum << 3,\n> +                                               stats->awb_stats[i].b_sum << 3 },\n>                                            stats->awb_stats[i].counted, stats->awb_stats[i].notcounted);\n>\n> -       /* There are only ever 15 regions computed by the firmware, but the HW defines AGC_REGIONS == 16! */\n> +       /*\n> +        * There are only ever 15 regions computed by the firmware due to zoning,\n> +        * but the HW defines AGC_REGIONS == 16!\n> +        */\n>         statistics->agcRegions.init(15);\n>         for (i = 0; i < statistics->agcRegions.numRegions(); i++)\n> -               statistics->agcRegions.set(i, { stats->agc_stats[i].r_sum,\n> -                                               stats->agc_stats[i].g_sum,\n> -                                               stats->agc_stats[i].b_sum },\n> +               statistics->agcRegions.set(i, { stats->agc_stats[i].r_sum << 3,\n> +                                               stats->agc_stats[i].g_sum << 3,\n> +                                               stats->agc_stats[i].b_sum << 3 },\n>                                            stats->agc_stats[i].counted, 0);\n>\n>         statistics->focusRegions.init(4, 3);\n> --\n> 2.25.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 3600BBDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 23 Nov 2022 14:39:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EEF536331C;\n\tWed, 23 Nov 2022 15:39:47 +0100 (CET)","from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com\n\t[IPv6:2607:f8b0:4864:20::1032])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 923AF63311\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Nov 2022 15:39:46 +0100 (CET)","by mail-pj1-x1032.google.com with SMTP id\n\to5-20020a17090a678500b00218cd5a21c9so1992273pjj.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Nov 2022 06:39:46 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1669214388;\n\tbh=DJ+Skx20OxE6LTzdh9+V/ST+JK7GFHEKMmAQTKmAMWY=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=e4RNe4VM1vpSkr1cLArPF4EZ9dp8ePRgikJrdmHFZPQpjc0kCWcZGTdYp9+x5xAhI\n\t8lmYQoLRiICPfA4ezlvZ08AvOVwEuE3XOw3NK7uJ7GIbFu/7LYdCOhN9BFxL5Asx1U\n\t2FeStyBPpZ4Pn6zdU5vpfLpjGPr+xrmDS12sy3VBBIvB47tgIkWyYSLtAAK/zRgx6E\n\tlD+xZt6Mg+blvaUk3sn2TfBsRMM7polE+30Kfa32kz2vI+RjsyRSG2NgthgGL4fg4E\n\tqdJrK5rf3VkfRBUr96HMrfrQST+egiWOiLPj2efM/mn4BC7bvsc86MitPH7UiarKij\n\tQ2qW9a6Iw5sCQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=Jxm67CHsr3VrTtpZdmWas9CnMCnka9jQvjbG62oNfrQ=;\n\tb=NwvjJRz+JRB5J14ioI/ecy4MFKqT0Sb79PVu/de2PIjkxtKEjtVqbd1RrTiEQOcOWR\n\toZDcLKYtmECk1WiMq7m2D0lN8qXm1/k4RYLMfDDrVqooaZhAajgilLU1ol0+03JQOEwo\n\tJI/LcwUW1N5IGLrf4h0sSuvEzs+JSpG70xSCOe/t2Gc1fSqn00wwI7nyVZqx/wMQpDzZ\n\tAORsCpGugRAcLWfHT+5neLHK5sBZnoSiA1dGvq48qGIraZzgzZwvduP8ZIm8BmsUBRI3\n\t5cpz5nI+kIkrWmitZf4MYSW5qp1w/Wce1vw8LHcfVkDwodGmiE7kTqyIX1NHPsEaQLac\n\tIBeg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"NwvjJRz+\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=Jxm67CHsr3VrTtpZdmWas9CnMCnka9jQvjbG62oNfrQ=;\n\tb=6zRG5NkVEFq4va4X372NnzRkoQc8U5PLhuGSJPd8KHl5MPXZzQeAfWOHS97hWRvcT7\n\t6+08hlQN1m1Mqj7KLRP6go7QQ5fe+WjrsPv9Ro2pkXmm6JJHHQvtoupGpKiB25safnji\n\tXPOcWFJdOz5/B3JYJJMkECO8Y/ReN4OQVeb/qoeF51DOOzTj4OsNvi62ETiTe6H+2jOT\n\twLoBzMW1aBzoOlHw4er077KwhkedJgChFlDJAXqftb8CVxEqBoKQXOH7lpZGadfYElUQ\n\tvRGNltNzgt0iQv87OuoDGoHclnCfjDHYs/6cwowtIn5UX+SuXHPGJnat5573/U8pJkHG\n\tPDsA==","X-Gm-Message-State":"ANoB5pnbaZZ+qSQBCPClr8w4PTxhEQ/d5cO9peoJi73ykZdH4/KIOuLs\n\tUGHnpHTUNXMGDMaelqVgEKazYYWwN3e2Y3IOQSHL8A==","X-Google-Smtp-Source":"AA0mqf5ie4P30aY8VDe1rjp7IJw1va6dsV2iWq4lNOCS3+bZ9701Z5fa5lvpZHtBqK9huPUolQ0ef7MdVVbLZaM9C0g=","X-Received":"by 2002:a17:902:b20f:b0:188:d4ea:251f with SMTP id\n\tt15-20020a170902b20f00b00188d4ea251fmr21920307plr.36.1669214385119;\n\tWed, 23 Nov 2022 06:39:45 -0800 (PST)","MIME-Version":"1.0","References":"<20221122112224.31691-1-naush@raspberrypi.com>\n\t<20221122112224.31691-6-naush@raspberrypi.com>","In-Reply-To":"<20221122112224.31691-6-naush@raspberrypi.com>","Date":"Wed, 23 Nov 2022 14:39:34 +0000","Message-ID":"<CAHW6GYL6uxVxbMVUq3Lqs+f4D=LLey976=qrXS+WRZpy5-6-Vw@mail.gmail.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH v1 5/5] ipa: raspberrypi: Normalise\n\tregion sums to 16-bits","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":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]