[{"id":18999,"web_url":"https://patchwork.libcamera.org/comment/18999/","msgid":"<bbcfc8ca-1521-8980-2cd4-d25802b4e4cf@ideasonboard.com>","date":"2021-08-23T08:59:58","subject":"Re: [libcamera-devel] [PATCH v3 1/2] ipa: ipu3: agc: remove local\n\tstorage of the grid","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi JM,\n\nOn 20/08/2021 17:00, Jean-Michel Hautbois wrote:\n> The IPASessionConfiguration now has the grid configuration stored. Use\n> it at process() call in AGC and pass it as a reference to the private\n> functions when needed.\n> \n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  src/ipa/ipu3/algorithms/agc.cpp | 28 ++++++++++++++--------------\n>  src/ipa/ipu3/algorithms/agc.h   |  5 ++---\n>  2 files changed, 16 insertions(+), 17 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index e4598b2e..5ff50f4a 100644\n> --- a/src/ipa/ipu3/algorithms/agc.cpp\n> +++ b/src/ipa/ipu3/algorithms/agc.cpp\n> @@ -57,10 +57,9 @@ Agc::Agc()\n>  {\n>  }\n>  \n> -int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n> +int Agc::configure([[maybe_unused]] IPAContext &context,\n> +\t\t   const IPAConfigInfo &configInfo)\n>  {\n> -\taeGrid_ = context.configuration.grid.bdsGrid;\n> -\n>  \tlineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n>  \t\t      / configInfo.sensorInfo.pixelRate;\n>  \tmaxExposureTime_ = kMaxExposure * lineDuration_;\n> @@ -68,7 +67,8 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>  \treturn 0;\n>  }\n>  \n> -void Agc::processBrightness(const ipu3_uapi_stats_3a *stats)\n> +void Agc::processBrightness(const ipu3_uapi_stats_3a *stats,\n> +\t\t\t    const ipu3_uapi_grid_config &grid)\n>  {\n>  \tconst struct ipu3_uapi_grid_config statsAeGrid = stats->stats_4a_config.awb_config.grid;\n>  \tRectangle aeRegion = { statsAeGrid.x_start,\n> @@ -76,19 +76,19 @@ void Agc::processBrightness(const ipu3_uapi_stats_3a *stats)\n>  \t\t\t       static_cast<unsigned int>(statsAeGrid.x_end - statsAeGrid.x_start) + 1,\n>  \t\t\t       static_cast<unsigned int>(statsAeGrid.y_end - statsAeGrid.y_start) + 1 };\n>  \tPoint topleft = aeRegion.topLeft();\n> -\tint topleftX = topleft.x >> aeGrid_.block_width_log2;\n> -\tint topleftY = topleft.y >> aeGrid_.block_height_log2;\n> +\tint topleftX = topleft.x >> grid.block_width_log2;\n> +\tint topleftY = topleft.y >> grid.block_height_log2;\n>  \n>  \t/* Align to the grid cell width and height */\n> -\tuint32_t startX = topleftX << aeGrid_.block_width_log2;\n> -\tuint32_t startY = topleftY * aeGrid_.width << aeGrid_.block_width_log2;\n> -\tuint32_t endX = (startX + (aeRegion.size().width >> aeGrid_.block_width_log2)) << aeGrid_.block_width_log2;\n> +\tuint32_t startX = topleftX << grid.block_width_log2;\n> +\tuint32_t startY = topleftY * grid.width << grid.block_width_log2;\n> +\tuint32_t endX = (startX + (aeRegion.size().width >> grid.block_width_log2)) << grid.block_width_log2;\n>  \tuint32_t i, j;\n>  \tuint32_t count = 0;\n>  \n>  \tuint32_t hist[knumHistogramBins] = { 0 };\n>  \tfor (j = topleftY;\n> -\t     j < topleftY + (aeRegion.size().height >> aeGrid_.block_height_log2);\n> +\t     j < topleftY + (aeRegion.size().height >> grid.block_height_log2);\n>  \t     j++) {\n>  \t\tfor (i = startX + startY; i < endX + startY; i += kCellSize) {\n>  \t\t\t/*\n> @@ -96,9 +96,9 @@ void Agc::processBrightness(const ipu3_uapi_stats_3a *stats)\n>  \t\t\t * We observed a bit shift which makes the value 160 to be 32 in the stats grid.\n>  \t\t\t * Use the one passed at init time.\n>  \t\t\t */\n> -\t\t\tif (stats->awb_raw_buffer.meta_data[i + 4 + j * aeGrid_.width] == 0) {\n> -\t\t\t\tuint8_t Gr = stats->awb_raw_buffer.meta_data[i + 0 + j * aeGrid_.width];\n> -\t\t\t\tuint8_t Gb = stats->awb_raw_buffer.meta_data[i + 3 + j * aeGrid_.width];\n> +\t\t\tif (stats->awb_raw_buffer.meta_data[i + 4 + j * grid.width] == 0) {\n> +\t\t\t\tuint8_t Gr = stats->awb_raw_buffer.meta_data[i + 0 + j * grid.width];\n> +\t\t\t\tuint8_t Gb = stats->awb_raw_buffer.meta_data[i + 3 + j * grid.width];\n>  \t\t\t\thist[(Gr + Gb) / 2]++;\n>  \t\t\t\tcount++;\n>  \t\t\t}\n> @@ -190,7 +190,7 @@ void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n>  {\n>  \tuint32_t &exposure = context.frameContext.agc.exposure;\n>  \tdouble &gain = context.frameContext.agc.gain;\n> -\tprocessBrightness(stats);\n> +\tprocessBrightness(stats, context.configuration.grid.bdsGrid);\n>  \tlockExposureGain(exposure, gain);\n>  \tframeCount_++;\n>  }\n> diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\n> index 1739d2fd..e36797d3 100644\n> --- a/src/ipa/ipu3/algorithms/agc.h\n> +++ b/src/ipa/ipu3/algorithms/agc.h\n> @@ -33,12 +33,11 @@ public:\n>  \tvoid process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override;\n>  \n>  private:\n> -\tvoid processBrightness(const ipu3_uapi_stats_3a *stats);\n> +\tvoid processBrightness(const ipu3_uapi_stats_3a *stats,\n> +\t\t\t       const ipu3_uapi_grid_config &grid);\n>  \tvoid filterExposure();\n>  \tvoid lockExposureGain(uint32_t &exposure, double &gain);\n>  \n> -\tstruct ipu3_uapi_grid_config aeGrid_;\n> -\n>  \tuint64_t frameCount_;\n>  \tuint64_t lastFrame_;\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 78626BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Aug 2021 09:00:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CF827688A6;\n\tMon, 23 Aug 2021 11:00:03 +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 A35F868891\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 11:00:01 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1735C2A5;\n\tMon, 23 Aug 2021 11:00:01 +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=\"hyxauyAy\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629709201;\n\tbh=O+7oEzqGkJoDuLJul1pFMNFUKVU2yHBor8VNftKL3gk=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=hyxauyAymh9vKtGzhEvTGG0oIrG729nyHmnO6StzPtBgdgm7r+EiUOzr0GzNZzOqY\n\tZh1R7XrvnGR9z6e7x3/+2Psd4TJvfzRzgQz4QwcitJnJ0d5I2oVHMZ4g5gRTDV8TVW\n\tUO+wospCLepi+6fIVvpNAQOoF8jRnEs+/oaB30vA=","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20210820160028.104265-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20210820160028.104265-2-jeanmichel.hautbois@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<bbcfc8ca-1521-8980-2cd4-d25802b4e4cf@ideasonboard.com>","Date":"Mon, 23 Aug 2021 09:59:58 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.11.0","MIME-Version":"1.0","In-Reply-To":"<20210820160028.104265-2-jeanmichel.hautbois@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v3 1/2] ipa: ipu3: agc: remove local\n\tstorage of the grid","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>"}}]