[{"id":18979,"web_url":"https://patchwork.libcamera.org/comment/18979/","msgid":"<YR+pAzzwM24fxQPT@pendragon.ideasonboard.com>","date":"2021-08-20T13:07:15","subject":"Re: [libcamera-devel] [PATCH v1 1/2] ipa: ipu3: agc: remove local\n\tstorage of the grid","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jean-Michel,\n\nThank you for the patch.\n\nOn Fri, Aug 20, 2021 at 02:11:48PM +0200, 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> ---\n>  src/ipa/ipu3/algorithms/agc.cpp | 29 +++++++++++++++--------------\n>  src/ipa/ipu3/algorithms/agc.h   |  5 ++---\n>  2 files changed, 17 insertions(+), 17 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index e4598b2e..f51c08d8 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    struct ipu3_uapi_grid_config &grid)\n\nThis should be const.\n\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,8 @@ 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> +\tstruct ipu3_uapi_grid_config grid = context.configuration.grid.bdsGrid;\n> +\tprocessBrightness(stats, grid);\n\nWhy do you need to make a copy of the grid ?\n\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..74ef0299 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       struct 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>","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 5E1E8BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 Aug 2021 13:07:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E8C5F68891;\n\tFri, 20 Aug 2021 15:07:26 +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 1CCEB68891\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Aug 2021 15:07:25 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 849338C8;\n\tFri, 20 Aug 2021 15:07:24 +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=\"QtrSGPk0\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629464844;\n\tbh=xhDfXgSMa/jfC1CMClBuoQ1APKu/Puwishl7xNZxk2A=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=QtrSGPk00yHqRO2e9iczh9JsvKvsVD0KrmV2c8xBTRRR1BymjmV/xOhvHYBIoxjLr\n\tJtk4LYJV+8p4CfpR3vgZ7XAeOrbJsfQjw81vhSmRcrOMYPkEMsrYOwenlUOyj4WM23\n\twmIF7sBAaGk3TLRk7rzLFfCsLRrHnwdmQ8rh5fkM=","Date":"Fri, 20 Aug 2021 16:07:15 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<YR+pAzzwM24fxQPT@pendragon.ideasonboard.com>","References":"<20210820121149.85859-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20210820121149.85859-2-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210820121149.85859-2-jeanmichel.hautbois@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v1 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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]