From patchwork Fri Nov 19 21:02:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 14665 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0A73BBF415 for ; Fri, 19 Nov 2021 21:03:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B736460371; Fri, 19 Nov 2021 22:03:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sYr+07cQ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B3BFB6037A for ; Fri, 19 Nov 2021 22:03:06 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3C7241C72 for ; Fri, 19 Nov 2021 22:03:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1637355786; bh=8vyiuE7CMNjXJ1c/+aPG49uEPPJQ7rb6G2kJWawD4Hg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sYr+07cQzGzizawq72VGAQ8ZCyaU3jWs+Undwnnuq2uowEWgS7OkhXMveV6Qb4aZq 5Te5YTBnzDOu9hUkkhddjVwpXtlJpbXBM0HTnl+SXpNv3C3fJRVtIFDQRmvmJETX4C Kx/X1H4R6pBOPFHiSIE4+ZNqPL8t5P6EZgZRSrQs= From: Laurent Pinchart 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 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The "current" prefix in the currentYGain variable name is confusing: - In Agc::estimateLuminance(), the variable contains the gain to be applied to the image, which is neither a "current" gain nor a "Y" gain. Rename it to "gain". - In Agc::computeExposure(), the variable contains the gain computed by the relative luminance method, so rename it to "yGain". While at it, rename variables to match the libcamera coding style. Signed-off-by: Laurent Pinchart Reviewed-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham --- src/ipa/ipu3/algorithms/agc.cpp | 32 ++++++++++++++++---------------- src/ipa/ipu3/algorithms/agc.h | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 9cd2ded501ed..2d196fd63c7e 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -173,9 +173,9 @@ void Agc::filterExposure() /** * \brief Estimate the new exposure and gain values * \param[inout] frameContext The shared IPA frame Context - * \param[in] currentYGain The gain calculated on the current brightness level + * \param[in] yGain The gain calculated based on the relative luminance target */ -void Agc::computeExposure(IPAFrameContext &frameContext, double currentYGain) +void Agc::computeExposure(IPAFrameContext &frameContext, double yGain) { /* Get the effective exposure and gain applied on the sensor. */ uint32_t exposure = frameContext.sensor.exposure; @@ -189,8 +189,8 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double currentYGain) */ double evGain = kEvGainTarget * knumHistogramBins / iqMean_; - if (evGain < currentYGain) - evGain = currentYGain; + if (evGain < yGain) + evGain = yGain; /* Consider within 1% of the target as correctly exposed */ if (std::abs(evGain - 1.0) < 0.01) @@ -254,7 +254,7 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double currentYGain) * \param[in] frameContext The shared IPA frame context * \param[in] grid The grid used to store the statistics in the IPU3 * \param[in] stats The IPU3 statistics and ISP results - * \param[in] currentYGain The gain calculated on the current brightness level + * \param[in] gain The gain to apply to the frame * \return The relative luminance * * Luma is the weighted sum of gamma-compressed R′G′B′ components of a color @@ -268,7 +268,7 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double currentYGain) double Agc::estimateLuminance(IPAFrameContext &frameContext, const ipu3_uapi_grid_config &grid, const ipu3_uapi_stats_3a *stats, - double currentYGain) + double gain) { double redSum = 0, greenSum = 0, blueSum = 0; @@ -281,9 +281,9 @@ double Agc::estimateLuminance(IPAFrameContext &frameContext, &stats->awb_raw_buffer.meta_data[cellPosition] ); - redSum += cell->R_avg * currentYGain; - greenSum += (cell->Gr_avg + cell->Gb_avg) / 2 * currentYGain; - blueSum += cell->B_avg * currentYGain; + redSum += cell->R_avg * gain; + greenSum += (cell->Gr_avg + cell->Gb_avg) / 2 * gain; + blueSum += cell->B_avg * gain; } } @@ -310,7 +310,7 @@ void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) { measureBrightness(stats, context.configuration.grid.bdsGrid); - double currentYGain = 1.0; + double yGain = 1.0; double yTarget = kRelativeLuminanceTarget; /* @@ -320,18 +320,18 @@ void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) for (unsigned int i = 0; i < 8; i++) { double yValue = estimateLuminance(context.frameContext, context.configuration.grid.bdsGrid, - stats, currentYGain); - double extra_gain = std::min(10.0, yTarget / (yValue + .001)); + stats, yGain); + double extraGain = std::min(10.0, yTarget / (yValue + .001)); - currentYGain *= extra_gain; + yGain *= extraGain; LOG(IPU3Agc, Debug) << "Y value: " << yValue << ", Y target: " << yTarget - << ", gives gain " << currentYGain; - if (extra_gain < 1.01) + << ", gives gain " << yGain; + if (extraGain < 1.01) break; } - computeExposure(context.frameContext, currentYGain); + computeExposure(context.frameContext, yGain); frameCount_++; } diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h index 943c354a820e..0c868d6737f1 100644 --- a/src/ipa/ipu3/algorithms/agc.h +++ b/src/ipa/ipu3/algorithms/agc.h @@ -34,11 +34,11 @@ private: void measureBrightness(const ipu3_uapi_stats_3a *stats, const ipu3_uapi_grid_config &grid); void filterExposure(); - void computeExposure(IPAFrameContext &frameContext, double currentYGain); + void computeExposure(IPAFrameContext &frameContext, double yGain); double estimateLuminance(IPAFrameContext &frameContext, const ipu3_uapi_grid_config &grid, const ipu3_uapi_stats_3a *stats, - double currentYGain); + double gain); uint64_t frameCount_;