From patchwork Tue Mar 19 10:54:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 19738 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 3CA95C3274 for ; Tue, 19 Mar 2024 10:54:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CE86262CAD; Tue, 19 Mar 2024 11:54:31 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="IwkxVIf/"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BF65A62CA4 for ; Tue, 19 Mar 2024 11:54:29 +0100 (CET) Received: from pyrite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp [175.177.49.156]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 37880F02; Tue, 19 Mar 2024 11:54:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1710845643; bh=qVvoVGoHabeb9SJcBGwBh3Ew6mdH5XghgO5gs5yTtmM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IwkxVIf/X6qyLpXelV+F3mD0i/M17wh6khjMqwt8Uf9qTq1BCpSDSZabWG2foNMA8 b6f/m9ZKjmK7pLmYlM4uud/Ej7uSKgQDT8Vr2wj3Bkg9NLG+4r5CrR/Yw80aFsLNcn YUKIdAcmytvmLtMKn8zC+hJ5RReZwCICYvJ5h1pk= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder Subject: [PATCH 1/2] ipa: libipa: histogram: Add rshift parameter to constructor Date: Tue, 19 Mar 2024 19:54:02 +0900 Message-Id: <20240319105403.4045592-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240319105403.4045592-1-paul.elder@ideasonboard.com> References: <20240319105403.4045592-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 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" Add an parameter for right-shifting the values during construction of the histogram. This is necessary notably for the rkisp1, as the values reported from the hardware are 20 bits where the upper 16-bits are meaningful integer values and the lower 4 bits are fractional and meant to be discarded. Signed-off-by: Paul Elder --- src/ipa/libipa/histogram.cpp | 5 +++-- src/ipa/libipa/histogram.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ipa/libipa/histogram.cpp b/src/ipa/libipa/histogram.cpp index 6b5cde8e..5cfbb720 100644 --- a/src/ipa/libipa/histogram.cpp +++ b/src/ipa/libipa/histogram.cpp @@ -31,13 +31,14 @@ namespace ipa { /** * \brief Create a cumulative histogram * \param[in] data A pre-sorted histogram to be passed + * \param[in] rshift Number of bits to right shift the values by */ -Histogram::Histogram(Span data) +Histogram::Histogram(Span data, uint8_t rshift) { cumulative_.reserve(data.size()); cumulative_.push_back(0); for (const uint32_t &value : data) - cumulative_.push_back(cumulative_.back() + value); + cumulative_.push_back(cumulative_.back() + (value >> rshift)); } /** diff --git a/src/ipa/libipa/histogram.h b/src/ipa/libipa/histogram.h index 05bb4b80..a82e623e 100644 --- a/src/ipa/libipa/histogram.h +++ b/src/ipa/libipa/histogram.h @@ -22,7 +22,7 @@ namespace ipa { class Histogram { public: - Histogram(Span data); + Histogram(Span data, uint8_t rshift = 0); size_t bins() const { return cumulative_.size() - 1; } uint64_t total() const { return cumulative_[cumulative_.size() - 1]; } uint64_t cumulativeFrequency(double bin) const; From patchwork Tue Mar 19 10:54:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 19739 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 3FEADBD160 for ; Tue, 19 Mar 2024 10:54:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 73DBA62CA8; Tue, 19 Mar 2024 11:54:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Ji/KpOHd"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7FD0B61C61 for ; Tue, 19 Mar 2024 11:54:31 +0100 (CET) Received: from pyrite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp [175.177.49.156]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D3C3216F9; Tue, 19 Mar 2024 11:54:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1710845644; bh=hmyiyluaTru7FETWqIyVy4DT/sC1/kVnyoXatr5Jqy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ji/KpOHdFiwNib1sNbKBxgf9sX36tZFzc5TcLi+LXd2WdMv+odv106P5SEEOJuG+n pmH5WasDG8/FqdAeBcVkEIO/e15Looxq9jtGpT8jmg+f3a7h1E22dJSYcdSjLfmaGU hV0dmRtp5O13CqzmV3rU8gBMFZ0Yf7fOSVhIri3M= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder Subject: [PATCH 2/2] ipa: rkisp1: agc: Fix histogram construction Date: Tue, 19 Mar 2024 19:54:03 +0900 Message-Id: <20240319105403.4045592-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240319105403.4045592-1-paul.elder@ideasonboard.com> References: <20240319105403.4045592-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 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 histogram reported by the rkisp1 hardware is 20 bits, where the upper 16 bits are meaningful integer data and the lower 4 bits are fractional and meant to be discarded. Remove these 4 bits when constructing the histogram. Signed-off-by: Paul Elder --- src/ipa/rkisp1/algorithms/agc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp index 47a6f7b2..278903a5 100644 --- a/src/ipa/rkisp1/algorithms/agc.cpp +++ b/src/ipa/rkisp1/algorithms/agc.cpp @@ -352,7 +352,7 @@ double Agc::estimateLuminance(Span expMeans, double gain) */ double Agc::measureBrightness(Span hist) const { - Histogram histogram{ hist }; + Histogram histogram{ hist, 4 }; /* Estimate the quantile mean of the top 2% of the histogram. */ return histogram.interQuantileMean(0.98, 1.0); }