{"id":14665,"url":"https://patchwork.libcamera.org/api/patches/14665/?format=json","web_url":"https://patchwork.libcamera.org/patch/14665/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211119210239.18540-4-laurent.pinchart@ideasonboard.com>","date":"2021-11-19T21:02:37","name":"[libcamera-devel,v2,3/5] ipa: ipu3: agc: Rename currentYGain","commit_ref":"6e02f674578e3c40ab3f140b25422ed195e4fc28","pull_url":null,"state":"accepted","archived":false,"hash":"36fe6f82d55d318cc20023eb703e7d9a66987567","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14665/mbox/","series":[{"id":2738,"url":"https://patchwork.libcamera.org/api/series/2738/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2738","date":"2021-11-19T21:02:34","name":"ipa: ipu3: agc: Misc improvements","version":2,"mbox":"https://patchwork.libcamera.org/series/2738/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14665/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14665/checks/","tags":{},"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 0A73BBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 19 Nov 2021 21:03:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B736460371;\n\tFri, 19 Nov 2021 22:03:12 +0100 (CET)","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 B3BFB6037A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Nov 2021 22:03:06 +0100 (CET)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3C7241C72\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Nov 2021 22:03:06 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"sYr+07cQ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1637355786;\n\tbh=8vyiuE7CMNjXJ1c/+aPG49uEPPJQ7rb6G2kJWawD4Hg=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=sYr+07cQzGzizawq72VGAQ8ZCyaU3jWs+Undwnnuq2uowEWgS7OkhXMveV6Qb4aZq\n\t5Te5YTBnzDOu9hUkkhddjVwpXtlJpbXBM0HTnl+SXpNv3C3fJRVtIFDQRmvmJETX4C\n\tKx/X1H4R6pBOPFHiSIE4+ZNqPL8t5P6EZgZRSrQs=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 19 Nov 2021 23:02:37 +0200","Message-Id":"<20211119210239.18540-4-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.32.0","In-Reply-To":"<20211119210239.18540-1-laurent.pinchart@ideasonboard.com>","References":"<20211119210239.18540-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 3/5] ipa: ipu3: agc: Rename currentYGain","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>"},"content":"The \"current\" prefix in the currentYGain variable name is confusing:\n\n- In Agc::estimateLuminance(), the variable contains the gain to be\n  applied to the image, which is neither a \"current\" gain nor a \"Y\"\n  gain. Rename it to \"gain\".\n\n- In Agc::computeExposure(), the variable contains the gain computed by\n  the relative luminance method, so rename it to \"yGain\".\n\nWhile at it, rename variables to match the libcamera coding style.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/ipu3/algorithms/agc.cpp | 32 ++++++++++++++++----------------\n src/ipa/ipu3/algorithms/agc.h   |  4 ++--\n 2 files changed, 18 insertions(+), 18 deletions(-)","diff":"diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex 9cd2ded501ed..2d196fd63c7e 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -173,9 +173,9 @@ void Agc::filterExposure()\n /**\n  * \\brief Estimate the new exposure and gain values\n  * \\param[inout] frameContext The shared IPA frame Context\n- * \\param[in] currentYGain The gain calculated on the current brightness level\n+ * \\param[in] yGain The gain calculated based on the relative luminance target\n  */\n-void Agc::computeExposure(IPAFrameContext &frameContext, double currentYGain)\n+void Agc::computeExposure(IPAFrameContext &frameContext, double yGain)\n {\n \t/* Get the effective exposure and gain applied on the sensor. */\n \tuint32_t exposure = frameContext.sensor.exposure;\n@@ -189,8 +189,8 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double currentYGain)\n \t */\n \tdouble evGain = kEvGainTarget * knumHistogramBins / iqMean_;\n \n-\tif (evGain < currentYGain)\n-\t\tevGain = currentYGain;\n+\tif (evGain < yGain)\n+\t\tevGain = yGain;\n \n \t/* Consider within 1% of the target as correctly exposed */\n \tif (std::abs(evGain - 1.0) < 0.01)\n@@ -254,7 +254,7 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double currentYGain)\n  * \\param[in] frameContext The shared IPA frame context\n  * \\param[in] grid The grid used to store the statistics in the IPU3\n  * \\param[in] stats The IPU3 statistics and ISP results\n- * \\param[in] currentYGain The gain calculated on the current brightness level\n+ * \\param[in] gain The gain to apply to the frame\n  * \\return The relative luminance\n  *\n  * Luma is the weighted sum of gamma-compressed R′G′B′ components of a color\n@@ -268,7 +268,7 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double currentYGain)\n double Agc::estimateLuminance(IPAFrameContext &frameContext,\n \t\t\t      const ipu3_uapi_grid_config &grid,\n \t\t\t      const ipu3_uapi_stats_3a *stats,\n-\t\t\t      double currentYGain)\n+\t\t\t      double gain)\n {\n \tdouble redSum = 0, greenSum = 0, blueSum = 0;\n \n@@ -281,9 +281,9 @@ double Agc::estimateLuminance(IPAFrameContext &frameContext,\n \t\t\t\t\t&stats->awb_raw_buffer.meta_data[cellPosition]\n \t\t\t\t);\n \n-\t\t\tredSum += cell->R_avg * currentYGain;\n-\t\t\tgreenSum += (cell->Gr_avg + cell->Gb_avg) / 2 * currentYGain;\n-\t\t\tblueSum += cell->B_avg * currentYGain;\n+\t\t\tredSum += cell->R_avg * gain;\n+\t\t\tgreenSum += (cell->Gr_avg + cell->Gb_avg) / 2 * gain;\n+\t\t\tblueSum += cell->B_avg * gain;\n \t\t}\n \t}\n \n@@ -310,7 +310,7 @@ void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n {\n \tmeasureBrightness(stats, context.configuration.grid.bdsGrid);\n \n-\tdouble currentYGain = 1.0;\n+\tdouble yGain = 1.0;\n \tdouble yTarget = kRelativeLuminanceTarget;\n \n \t/*\n@@ -320,18 +320,18 @@ void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n \tfor (unsigned int i = 0; i < 8; i++) {\n \t\tdouble yValue = estimateLuminance(context.frameContext,\n \t\t\t\t\t\t  context.configuration.grid.bdsGrid,\n-\t\t\t\t\t\t  stats, currentYGain);\n-\t\tdouble extra_gain = std::min(10.0, yTarget / (yValue + .001));\n+\t\t\t\t\t\t  stats, yGain);\n+\t\tdouble extraGain = std::min(10.0, yTarget / (yValue + .001));\n \n-\t\tcurrentYGain *= extra_gain;\n+\t\tyGain *= extraGain;\n \t\tLOG(IPU3Agc, Debug) << \"Y value: \" << yValue\n \t\t\t\t    << \", Y target: \" << yTarget\n-\t\t\t\t    << \", gives gain \" << currentYGain;\n-\t\tif (extra_gain < 1.01)\n+\t\t\t\t    << \", gives gain \" << yGain;\n+\t\tif (extraGain < 1.01)\n \t\t\tbreak;\n \t}\n \n-\tcomputeExposure(context.frameContext, currentYGain);\n+\tcomputeExposure(context.frameContext, yGain);\n \tframeCount_++;\n }\n \ndiff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\nindex 943c354a820e..0c868d6737f1 100644\n--- a/src/ipa/ipu3/algorithms/agc.h\n+++ b/src/ipa/ipu3/algorithms/agc.h\n@@ -34,11 +34,11 @@ private:\n \tvoid measureBrightness(const ipu3_uapi_stats_3a *stats,\n \t\t\t       const ipu3_uapi_grid_config &grid);\n \tvoid filterExposure();\n-\tvoid computeExposure(IPAFrameContext &frameContext, double currentYGain);\n+\tvoid computeExposure(IPAFrameContext &frameContext, double yGain);\n \tdouble estimateLuminance(IPAFrameContext &frameContext,\n \t\t\t\t const ipu3_uapi_grid_config &grid,\n \t\t\t\t const ipu3_uapi_stats_3a *stats,\n-\t\t\t\t double currentYGain);\n+\t\t\t\t double gain);\n \n \tuint64_t frameCount_;\n \n","prefixes":["libcamera-devel","v2","3/5"]}