[{"id":18985,"web_url":"https://patchwork.libcamera.org/comment/18985/","msgid":"<YR+6a8PzJP6jAiaF@pendragon.ideasonboard.com>","date":"2021-08-20T14:21:31","subject":"Re: [libcamera-devel] [PATCH v2 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 04:11:03PM +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..0bb462e6 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,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\n\tprocessBrightness(stats, context.configuration.grid.bdsGrid);\n\nThe result is even shorter :-)\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\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..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>","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 7EE63BD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 Aug 2021 14:21:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E387568891;\n\tFri, 20 Aug 2021 16:21:41 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E1C96888E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Aug 2021 16:21:41 +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 88DC88C8;\n\tFri, 20 Aug 2021 16:21:40 +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=\"eVem5uRn\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629469300;\n\tbh=ySZPtdZo/9nHSRnYRdKWCH6TN3MSEGM8xOK/wBUdQBE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=eVem5uRndLY08yostooBs0vUHpdtwMfvjxOtRYxKfaR4G6ko1Clg2TLDzulhEr+Np\n\tl3xD/OkHQ3GtYOwPenflSPg+p/pyIU7yODj8fvk/Oe49fPYMLa/+HqXw4XHDVnVg0Y\n\t++zsMZMV5SlDOO7iQsfps2eJc7waNr86IC/BmUEM=","Date":"Fri, 20 Aug 2021 17:21:31 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<YR+6a8PzJP6jAiaF@pendragon.ideasonboard.com>","References":"<20210820141104.94438-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20210820141104.94438-2-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210820141104.94438-2-jeanmichel.hautbois@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 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>"}}]