From patchwork Mon Feb 17 10:01:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22787 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 73177C327D for ; Mon, 17 Feb 2025 10:02:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 42D9768663; Mon, 17 Feb 2025 11:02:14 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TmLzEGyF"; 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 A2B306865D for ; Mon, 17 Feb 2025 11:02:10 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b47f:e20a:c4c7:ece1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6A2DD842; Mon, 17 Feb 2025 11:00:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1739786449; bh=WCk5oVZh9C/d253FiUEnwgsIeMWChDAfaXQvY65px74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TmLzEGyFX7ofZ7BiQknRM3Sqok5VFt01EcnOgpJ1OuG669u5ZdbI2VarxcXDqGOZY H20UNXIXlzvyogmV65bScuQJUB+c5kMVVYdJCyNSC11A37vepz+Ck6bjc0Gj+UFxQq UBkUHpwhy1jD6B+AlTGDKDKdTADqtPyr/j9tzR48= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 01/10] libcamera: matrix: Add cast function Date: Mon, 17 Feb 2025 11:01:42 +0100 Message-ID: <20250217100203.297894-2-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217100203.297894-1-stefan.klug@ideasonboard.com> References: <20250217100203.297894-1-stefan.klug@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 libcamera code base uses matrices and vectors of type float and double. Add a cast function to easily convert between different underlying types. Signed-off-by: Stefan Klug --- include/libcamera/internal/matrix.h | 11 +++++++++++ src/libcamera/matrix.cpp | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h index a055e6926c94..ca81dcda93c4 100644 --- a/include/libcamera/internal/matrix.h +++ b/include/libcamera/internal/matrix.h @@ -90,6 +90,17 @@ public: return *this; } + template + Matrix cast() const + { + Matrix ret; + for (unsigned int i = 0; i < Rows; i++) + for (unsigned int j = 0; j < Cols; j++) + ret[i][j] = static_cast((*this)[i][j]); + + return ret; + } + private: std::array data_; }; diff --git a/src/libcamera/matrix.cpp b/src/libcamera/matrix.cpp index e7e027225666..91a3f16405a3 100644 --- a/src/libcamera/matrix.cpp +++ b/src/libcamera/matrix.cpp @@ -77,6 +77,16 @@ LOG_DEFINE_CATEGORY(Matrix) * \return Row \a i from the matrix, as a Span */ +/** + * \fn template Matrix Matrix::cast() const + * \brief Cast the matrix to a different type + * + * This function returns a new matrix with the same size and values but a + * different type. + * + * \return The new matrix + */ + /** * \fn Matrix::operator[](size_t i) * \copydoc Matrix::operator[](size_t i) const From patchwork Mon Feb 17 10:01:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22788 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 EEEE6C327D for ; Mon, 17 Feb 2025 10:02:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7D3736866D; Mon, 17 Feb 2025 11:02:19 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="P0SYrnt/"; 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 9A84668665 for ; Mon, 17 Feb 2025 11:02:13 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b47f:e20a:c4c7:ece1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3DD24E29; Mon, 17 Feb 2025 11:00:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1739786452; bh=918sfwA7Mb+3uVAMU/CSzykUjmZSib/6jaJgceZLH1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P0SYrnt/sAQ+eoMPsIDcf5VFZFKJPJdfieToHktL+peZ72ZM7mdUc+IG7J4rw90Tc UwXOQUDVTt7m2IbuKfCkNmdImua00ja4jrMwx/1oxvPDfYcqcXRWXaHl9LqeBNEjK6 Zor6f7m0heF77ifL0ANUEStW9pSgetPhQKMtxfk4= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 02/10] libcamera: vector: Add cast function Date: Mon, 17 Feb 2025 11:01:43 +0100 Message-ID: <20250217100203.297894-3-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217100203.297894-1-stefan.klug@ideasonboard.com> References: <20250217100203.297894-1-stefan.klug@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 libcamera code base uses matrices and vectors of type float and double. Add a cast function to easily convert between different underlying types. Signed-off-by: Stefan Klug --- include/libcamera/internal/vector.h | 9 +++++++++ src/libcamera/vector.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h index a67a09474204..c8f9a8c412f2 100644 --- a/include/libcamera/internal/vector.h +++ b/include/libcamera/internal/vector.h @@ -243,6 +243,15 @@ public: return std::accumulate(data_.begin(), data_.end(), R{}); } + template + Vector cast() const + { + Vector ret; + for (unsigned int i = 0; i < Rows; i++) + ret[i] = static_cast(data_[i]); + return ret; + } + private: template static constexpr Vector apply(const Vector &lhs, const Vector &rhs, BinaryOp op) diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp index 85ca2208245a..57dcef8bf3d8 100644 --- a/src/libcamera/vector.cpp +++ b/src/libcamera/vector.cpp @@ -202,6 +202,16 @@ LOG_DEFINE_CATEGORY(Vector) * \return The element-wise maximum of this vector and \a scalar */ +/** + * \fn template Vector Vector::cast() const + * \brief Cast the vector to a different type + * + * This function returns a new vector with the same size and values but a + * different type. + * + * \return The new vector + */ + /** * \fn Vector::dot(const Vector &other) const * \brief Compute the dot product From patchwork Mon Feb 17 10:01:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22789 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 CBC62C327D for ; Mon, 17 Feb 2025 10:02:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2A4976866C; Mon, 17 Feb 2025 11:02:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sH+plZlR"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6A58D68661 for ; Mon, 17 Feb 2025 11:02:16 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b47f:e20a:c4c7:ece1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 275FDE29; Mon, 17 Feb 2025 11:00:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1739786455; bh=Prka8/qby0xM9wSgS3e77LXT7u3uW8O5pulkE87B6A8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sH+plZlRUQK5aOQ4lAQf0M2oyEqqByjiJQuuWHoKR9LbMrKIrtmcBn81QaSBzEN15 CxyZ6ukWsDHL41o3ABkbTpqetokb1831rPgjsCJn6w3ECjkp2daA7JPBCs0sPXHZhJ wzoJR5JZumi/zzq+S1+FOnv6K4xbH6LyOM9C0fVo= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 03/10] libcamera: matrix: Add inverse() function Date: Mon, 17 Feb 2025 11:01:44 +0100 Message-ID: <20250217100203.297894-4-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217100203.297894-1-stefan.klug@ideasonboard.com> References: <20250217100203.297894-1-stefan.klug@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" For calculations in upcoming algorithm patches, the inverse of a matrix is required. Add an implementation of the inverse() function for 3x3 matrices. Signed-off-by: Stefan Klug --- include/libcamera/internal/matrix.h | 24 ++++++++++++++++++++++++ src/libcamera/matrix.cpp | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h index ca81dcda93c4..053336e9cfa4 100644 --- a/include/libcamera/internal/matrix.h +++ b/include/libcamera/internal/matrix.h @@ -90,6 +90,30 @@ public: return *this; } + Matrix inverse() const + { + static_assert(Rows == 3 && Cols == 3, "Matrix must be 3x3"); + + const auto &m = *this; + double det = m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2]) - + m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0]) + + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]); + + double invdet = 1 / det; + + Matrix ret; + ret[0][0] = (m[1][1] * m[2][2] - m[2][1] * m[1][2]) * invdet; + ret[0][1] = (m[0][2] * m[2][1] - m[0][1] * m[2][2]) * invdet; + ret[0][2] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) * invdet; + ret[1][0] = (m[1][2] * m[2][0] - m[1][0] * m[2][2]) * invdet; + ret[1][1] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) * invdet; + ret[1][2] = (m[1][0] * m[0][2] - m[0][0] * m[1][2]) * invdet; + ret[2][0] = (m[1][0] * m[2][1] - m[2][0] * m[1][1]) * invdet; + ret[2][1] = (m[2][0] * m[0][1] - m[0][0] * m[2][1]) * invdet; + ret[2][2] = (m[0][0] * m[1][1] - m[1][0] * m[0][1]) * invdet; + return ret; + } + template Matrix cast() const { diff --git a/src/libcamera/matrix.cpp b/src/libcamera/matrix.cpp index 91a3f16405a3..b17a1938f1ba 100644 --- a/src/libcamera/matrix.cpp +++ b/src/libcamera/matrix.cpp @@ -77,6 +77,16 @@ LOG_DEFINE_CATEGORY(Matrix) * \return Row \a i from the matrix, as a Span */ +/** + * \fn Matrix::inverse() const + * \brief Compute the inverse of the matrix + * + * This function computes the inverse of the matrix. It is only implemented for + * 3x3 matrices. + * + * \return The inverse of the matrix + */ + /** * \fn template Matrix Matrix::cast() const * \brief Cast the matrix to a different type From patchwork Mon Feb 17 10:01:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22790 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 237D2C327D for ; Mon, 17 Feb 2025 10:02:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A8E0968673; Mon, 17 Feb 2025 11:02:25 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Aj81ANCs"; 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 361396866B for ; Mon, 17 Feb 2025 11:02:19 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b47f:e20a:c4c7:ece1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F1F7A842; Mon, 17 Feb 2025 11:00:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1739786458; bh=Joq1eQL/Prjqoq7XSKLWjPq1On6oyzRirl6eiup8ERM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Aj81ANCshS5qcRg+kLOIVrQ3c9YJ3pKpU8zp7rWJLCitoUg6HY9rLaph+/RMutYzh w30mU7RPUaxvkFpgTVxpTprJKShqLHv5o9rHBfPgG9vuOnkyjOjcp5pHO66f8uIGS2 ePn3IzzPa9cuxdvUQpQkg3v0hjc9n51II6Z1UxfQ= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 04/10] ipa: rkisp1: Refactor automatic/manual structure in IPAActiveState Date: Mon, 17 Feb 2025 11:01:45 +0100 Message-ID: <20250217100203.297894-5-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217100203.297894-1-stefan.klug@ideasonboard.com> References: <20250217100203.297894-1-stefan.klug@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" Swap gains and automatic/manual in the IPAActiveState structure. This is in preparation to adding another member, which is easier in this structure. This is also in sync with how it is modeled in agc. This patch contains no functional changes. Signed-off-by: Stefan Klug --- src/ipa/rkisp1/algorithms/awb.cpp | 24 ++++++++++++------------ src/ipa/rkisp1/ipa_context.h | 9 ++++++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index cffaa06a22c1..147277c98bb2 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -74,8 +74,8 @@ int Awb::init(IPAContext &context, const YamlObject &tuningData) int Awb::configure(IPAContext &context, const IPACameraSensorInfo &configInfo) { - context.activeState.awb.gains.manual = RGB{ 1.0 }; - context.activeState.awb.gains.automatic = RGB{ 1.0 }; + context.activeState.awb.manual.gains = RGB{ 1.0 }; + context.activeState.awb.automatic.gains = RGB{ 1.0 }; context.activeState.awb.autoEnabled = true; context.activeState.awb.temperatureK = kDefaultColourTemperature; @@ -120,8 +120,8 @@ void Awb::queueRequest(IPAContext &context, const auto &colourTemperature = controls.get(controls::ColourTemperature); bool update = false; if (colourGains) { - awb.gains.manual.r() = (*colourGains)[0]; - awb.gains.manual.b() = (*colourGains)[1]; + awb.manual.gains.r() = (*colourGains)[0]; + awb.manual.gains.b() = (*colourGains)[1]; /* * \todo: Colour temperature reported in metadata is now * incorrect, as we can't deduce the temperature from the gains. @@ -130,17 +130,17 @@ void Awb::queueRequest(IPAContext &context, update = true; } else if (colourTemperature && colourGainCurve_) { const auto &gains = colourGainCurve_->getInterpolated(*colourTemperature); - awb.gains.manual.r() = gains[0]; - awb.gains.manual.b() = gains[1]; + awb.manual.gains.r() = gains[0]; + awb.manual.gains.b() = gains[1]; awb.temperatureK = *colourTemperature; update = true; } if (update) LOG(RkISP1Awb, Debug) - << "Set colour gains to " << awb.gains.manual; + << "Set colour gains to " << awb.manual.gains; - frameContext.awb.gains = awb.gains.manual; + frameContext.awb.gains = awb.manual.gains; frameContext.awb.temperatureK = awb.temperatureK; } @@ -155,7 +155,7 @@ void Awb::prepare(IPAContext &context, const uint32_t frame, * most up-to-date automatic values we can read. */ if (frameContext.awb.autoEnabled) { - frameContext.awb.gains = context.activeState.awb.gains.automatic; + frameContext.awb.gains = context.activeState.awb.automatic.gains; frameContext.awb.temperatureK = context.activeState.awb.temperatureK; } @@ -332,14 +332,14 @@ void Awb::process(IPAContext &context, /* Filter the values to avoid oscillations. */ double speed = 0.2; - gains = gains * speed + activeState.awb.gains.automatic * (1 - speed); + gains = gains * speed + activeState.awb.automatic.gains * (1 - speed); - activeState.awb.gains.automatic = gains; + activeState.awb.automatic.gains = gains; LOG(RkISP1Awb, Debug) << std::showpoint << "Means " << rgbMeans << ", gains " - << activeState.awb.gains.automatic << ", temp " + << activeState.awb.automatic.gains << ", temp " << activeState.awb.temperatureK << "K"; } diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index c765b928a55f..1a374c96cd1a 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -89,9 +89,12 @@ struct IPAActiveState { struct { struct { - RGB manual; - RGB automatic; - } gains; + RGB gains; + } manual; + + struct { + RGB gains; + } automatic; unsigned int temperatureK; bool autoEnabled; From patchwork Mon Feb 17 10:01:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22791 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 9FB04C327D for ; Mon, 17 Feb 2025 10:02:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2970668672; Mon, 17 Feb 2025 11:02:27 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="g/UtrzjL"; 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 7F1F76866D for ; Mon, 17 Feb 2025 11:02:22 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b47f:e20a:c4c7:ece1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 29FF61047; Mon, 17 Feb 2025 11:01:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1739786461; bh=JdIl4wlXsMPCM3woaquK6SUw9P/ZoTfxyxj/KKBuetI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g/UtrzjLdaaUgHvj+F3rAUTeR6SnlwFzPJJKEi6An2b6LipkeZ4zPQbjKs5Vwgjp5 hX3AWttXqiMsFpsyTTsgxDLGaqsNITX+jeKch0uxenFRmgrxNYD7UjIHx9NsZLJyL+ IKjoi5tyPSHrKhBfo3DvN155aAW6hvdMMPoaLfZk= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 05/10] ipa: rkisp: ccm/lsc: Fix CCM/LSC based on manual color temperature Date: Mon, 17 Feb 2025 11:01:46 +0100 Message-ID: <20250217100203.297894-6-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217100203.297894-1-stefan.klug@ideasonboard.com> References: <20250217100203.297894-1-stefan.klug@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" In RkISP1Awb::process(), the color temperature in the active state is updated unconditionally. The CCM/LSC algorithms use that value in prepare() to update the CCM/LSC which is not correct if the color temperature was specified manually and leads to visible flicker even when AwbEnable is set to false. To fix that, track the auto and manual color temperature separately in active state. In Awb::prepare() the current frame context is updated with the corresponding value from active state. Change the algorithms to fetch the color temperature from the frame context instead of the active state in prepare(). Fixes: 02308809548d ("ipa: rkisp1: awb: Implement ColourTemperature control") Signed-off-by: Stefan Klug --- src/ipa/rkisp1/algorithms/awb.cpp | 16 +++++++++------- src/ipa/rkisp1/algorithms/ccm.cpp | 2 +- src/ipa/rkisp1/algorithms/lsc.cpp | 6 +++--- src/ipa/rkisp1/ipa_context.h | 3 ++- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 147277c98bb2..683a08c943fa 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -77,7 +77,8 @@ int Awb::configure(IPAContext &context, context.activeState.awb.manual.gains = RGB{ 1.0 }; context.activeState.awb.automatic.gains = RGB{ 1.0 }; context.activeState.awb.autoEnabled = true; - context.activeState.awb.temperatureK = kDefaultColourTemperature; + context.activeState.awb.manual.temperatureK = kDefaultColourTemperature; + context.activeState.awb.automatic.temperatureK = kDefaultColourTemperature; /* * Define the measurement window for AWB as a centered rectangle @@ -132,7 +133,7 @@ void Awb::queueRequest(IPAContext &context, const auto &gains = colourGainCurve_->getInterpolated(*colourTemperature); awb.manual.gains.r() = gains[0]; awb.manual.gains.b() = gains[1]; - awb.temperatureK = *colourTemperature; + awb.manual.temperatureK = *colourTemperature; update = true; } @@ -141,7 +142,7 @@ void Awb::queueRequest(IPAContext &context, << "Set colour gains to " << awb.manual.gains; frameContext.awb.gains = awb.manual.gains; - frameContext.awb.temperatureK = awb.temperatureK; + frameContext.awb.temperatureK = awb.manual.temperatureK; } /** @@ -155,8 +156,9 @@ void Awb::prepare(IPAContext &context, const uint32_t frame, * most up-to-date automatic values we can read. */ if (frameContext.awb.autoEnabled) { - frameContext.awb.gains = context.activeState.awb.automatic.gains; - frameContext.awb.temperatureK = context.activeState.awb.temperatureK; + auto &awb = context.activeState.awb; + frameContext.awb.gains = awb.automatic.gains; + frameContext.awb.temperatureK = awb.automatic.temperatureK; } auto gainConfig = params->block(); @@ -309,7 +311,7 @@ void Awb::process(IPAContext &context, rgbMeans.b() < kMeanMinThreshold) return; - activeState.awb.temperatureK = estimateCCT(rgbMeans); + activeState.awb.automatic.temperatureK = estimateCCT(rgbMeans); /* * Estimate the red and blue gains to apply in a grey world. The green @@ -340,7 +342,7 @@ void Awb::process(IPAContext &context, << std::showpoint << "Means " << rgbMeans << ", gains " << activeState.awb.automatic.gains << ", temp " - << activeState.awb.temperatureK << "K"; + << activeState.awb.automatic.temperatureK << "K"; } REGISTER_IPA_ALGORITHM(Awb, "Awb") diff --git a/src/ipa/rkisp1/algorithms/ccm.cpp b/src/ipa/rkisp1/algorithms/ccm.cpp index eb8ca39e56a8..2e5e91006b55 100644 --- a/src/ipa/rkisp1/algorithms/ccm.cpp +++ b/src/ipa/rkisp1/algorithms/ccm.cpp @@ -88,7 +88,7 @@ void Ccm::setParameters(struct rkisp1_cif_isp_ctk_config &config, void Ccm::prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, RkISP1Params *params) { - uint32_t ct = context.activeState.awb.temperatureK; + uint32_t ct = frameContext.awb.temperatureK; /* * \todo The colour temperature will likely be noisy, add filtering to diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp index e47aa2f0727e..e7301bfec863 100644 --- a/src/ipa/rkisp1/algorithms/lsc.cpp +++ b/src/ipa/rkisp1/algorithms/lsc.cpp @@ -404,12 +404,12 @@ void LensShadingCorrection::copyTable(rkisp1_cif_isp_lsc_config &config, /** * \copydoc libcamera::ipa::Algorithm::prepare */ -void LensShadingCorrection::prepare(IPAContext &context, +void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] const uint32_t frame, - [[maybe_unused]] IPAFrameContext &frameContext, + IPAFrameContext &frameContext, RkISP1Params *params) { - uint32_t ct = context.activeState.awb.temperatureK; + uint32_t ct = frameContext.awb.temperatureK; if (std::abs(static_cast(ct) - static_cast(lastAppliedCt_)) < kColourTemperatureChangeThreshhold) return; diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index 1a374c96cd1a..b50370cd9daa 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -90,13 +90,14 @@ struct IPAActiveState { struct { struct { RGB gains; + unsigned int temperatureK; } manual; struct { RGB gains; + unsigned int temperatureK; } automatic; - unsigned int temperatureK; bool autoEnabled; } awb; From patchwork Mon Feb 17 10:01:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22792 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 4B046C327D for ; Mon, 17 Feb 2025 10:02:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9393C68676; Mon, 17 Feb 2025 11:02:28 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RxL8wcNA"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BFC7B68669 for ; Mon, 17 Feb 2025 11:02:24 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b47f:e20a:c4c7:ece1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7FC201047; Mon, 17 Feb 2025 11:01:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1739786463; bh=jG0g7FmqHVXYAk5uPpol5L1i8FG8s83Bz552qvCsgrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RxL8wcNAZAfuSelds4WlSGNziGJDtMdgibDYYZLFTs4XIUVHYzW9Jt30M7TWdoOS1 /Jnhdgyx2TwlwpgF1O7kfplCFs34K1TshOyvf8UKEs+S198EnO+8bPWWmwa5tp7JrL Ko+LMNha8nbmSLZE0BqWNM61lVZBSWkQfmlS1KFo= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 06/10] ipa: rkisp1: awb: Use gains from color temperature curve Date: Mon, 17 Feb 2025 11:01:47 +0100 Message-ID: <20250217100203.297894-7-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217100203.297894-1-stefan.klug@ideasonboard.com> References: <20250217100203.297894-1-stefan.klug@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" Use the color gains for white balance if calibrated light sources are contained in the tuning file. The results are generally better especially when large uniformly colored objects are in the scene. Pure grey world model is still available by removing the color gains from the tuning file. Signed-off-by: Stefan Klug --- src/ipa/rkisp1/algorithms/awb.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 683a08c943fa..9244a1e64f41 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -159,6 +159,15 @@ void Awb::prepare(IPAContext &context, const uint32_t frame, auto &awb = context.activeState.awb; frameContext.awb.gains = awb.automatic.gains; frameContext.awb.temperatureK = awb.automatic.temperatureK; + if (colourGainCurve_) { + const auto &gains = colourGainCurve_->getInterpolated( + awb.automatic.temperatureK); + frameContext.awb.gains.r() = gains[0]; + frameContext.awb.gains.g() = 1.0; + frameContext.awb.gains.b() = gains[1]; + } else { + frameContext.awb.gains = awb.automatic.gains; + } } auto gainConfig = params->block(); From patchwork Mon Feb 17 10:01:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22793 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 47F32C327D for ; Mon, 17 Feb 2025 10:02:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0579568674; Mon, 17 Feb 2025 11:02:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="d4/hMwM7"; 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 D165A6866C for ; Mon, 17 Feb 2025 11:02:27 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b47f:e20a:c4c7:ece1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 89F0A1047; Mon, 17 Feb 2025 11:01:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1739786466; bh=Ev7zgdYMk1QUM3ZHUsPzzLl+Q5H2fFyX75+sOBob7fU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d4/hMwM7uUwJ8C2gdEmsVTNB5xUAP5bAAxp2VS42ORLutQNjzXwzUMW5YptYN/fY5 giB3y6HqrG8WIE/HjrqrYHBDeC5cSBuB02e9IKj+ARAp9mryS4cdQjF1s17cxO8hXR DgzT0rNnhuMh3N/iEOOPb09ie8jlfsO3Mc6G1lgM= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 07/10] ipa: rkisp1: Damp color temperature regulation Date: Mon, 17 Feb 2025 11:01:48 +0100 Message-ID: <20250217100203.297894-8-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217100203.297894-1-stefan.klug@ideasonboard.com> References: <20250217100203.297894-1-stefan.klug@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" Damp the regulation of the color temperature with the same factor as the gains. Not damping the color temperature leads to visible flicker, as the CCM changes too much. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham --- src/ipa/rkisp1/algorithms/awb.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 9244a1e64f41..347d38d226b4 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -320,8 +320,6 @@ void Awb::process(IPAContext &context, rgbMeans.b() < kMeanMinThreshold) return; - activeState.awb.automatic.temperatureK = estimateCCT(rgbMeans); - /* * Estimate the red and blue gains to apply in a grey world. The green * gain is hardcoded to 1.0. Avoid divisions by zero by clamping the @@ -343,8 +341,11 @@ void Awb::process(IPAContext &context, /* Filter the values to avoid oscillations. */ double speed = 0.2; + double ct = estimateCCT(rgbMeans); + ct = ct * speed + activeState.awb.automatic.temperatureK * (1 - speed); gains = gains * speed + activeState.awb.automatic.gains * (1 - speed); + activeState.awb.automatic.temperatureK = static_cast(ct); activeState.awb.automatic.gains = gains; LOG(RkISP1Awb, Debug) From patchwork Mon Feb 17 10:01:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22794 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 EF0C4C327D for ; Mon, 17 Feb 2025 10:02:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4336C6867F; Mon, 17 Feb 2025 11:02:34 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="pJmE7BRe"; 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 16A0B68676 for ; Mon, 17 Feb 2025 11:02:31 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b47f:e20a:c4c7:ece1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 68129122C; Mon, 17 Feb 2025 11:01:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1739786469; bh=UyTYmg3epLgbAw/bGgeu9bXSA40/OfnEkbgBBHJWBP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pJmE7BReNn6dvYBt0UcMN0yuD4KzDGcXYtn4oGM23YU5E4dZGx8ruL48H7nDf9Z8/ wq/8TgzL+aj5B764aNyMX0D6I3CMjjLThy3vRWRnhTM97kS0BlOYnr5GFzeldYLHk+ CkL70pMQJb5HfwdnSb5tfg0HL975Ru10xtkLkcy8= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 08/10] ipa: rkisp: awb: Set rgb mean limits to 180 Date: Mon, 17 Feb 2025 11:01:49 +0100 Message-ID: <20250217100203.297894-9-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217100203.297894-1-stefan.klug@ideasonboard.com> References: <20250217100203.297894-1-stefan.klug@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" Set the mean limits to 180 to get reasonably good results from the rgb estimations. This is only for internal development as there is no code path to enable rgb estimations at runtime. Signed-off-by: Stefan Klug --- src/ipa/rkisp1/algorithms/awb.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 347d38d226b4..12934771c69c 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -201,9 +201,9 @@ void Awb::prepare(IPAContext &context, const uint32_t frame, * awb_ref_cr, awb_min_y and awb_ref_cb respectively. The other * values are not used, set them to 0. */ - awbConfig->awb_ref_cr = 250; - awbConfig->min_y = 250; - awbConfig->awb_ref_cb = 250; + awbConfig->awb_ref_cr = 180; + awbConfig->min_y = 180; + awbConfig->awb_ref_cb = 180; awbConfig->max_y = 0; awbConfig->min_c = 0; From patchwork Mon Feb 17 10:01:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22795 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 2A890C327D for ; Mon, 17 Feb 2025 10:02:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D58F368680; Mon, 17 Feb 2025 11:02:38 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HvfqKpPk"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 14BBB6867E for ; Mon, 17 Feb 2025 11:02:33 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b47f:e20a:c4c7:ece1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A96F4842; Mon, 17 Feb 2025 11:01:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1739786472; bh=2TV5LHpoYSbm2dW3u7AWZzvpdbmHFAFImM/UHfEq1GU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HvfqKpPkA/8cxepltPlqByrM4oIBSajRPGkisauGe791BvZ9GsTx9nzU0Wgw4XC5X H+AFWe76TdYFnHXlFNagOhrA9vPRTZv0eKKxfEHFentHwaLlEv4uBS+O47vFCQvwu2 Y/UF57hP9DtfgW/gor2KwBsF5Ltm4hrUxvU8RWNs= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 09/10] ipa: rkisp1: awb: Take the CCM into account for the AWB gains calculation Date: Mon, 17 Feb 2025 11:01:50 +0100 Message-ID: <20250217100203.297894-10-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217100203.297894-1-stefan.klug@ideasonboard.com> References: <20250217100203.297894-1-stefan.klug@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" Apparently AWB measurements are taken after the CCM. So the estimated colour temperature and the corresponding CCM also lead to changed rgbMeans. This is another source of oscillations. Fix that by applying the inverse transform on the rgbMeans. Signed-off-by: Stefan Klug --- src/ipa/rkisp1/algorithms/awb.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 12934771c69c..66e6aecedc4c 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -305,6 +305,8 @@ void Awb::process(IPAContext &context, rgbMeans = rgbMeans.max(0.0); } + rgbMeans = frameContext.ccm.ccm.cast().inverse() * rgbMeans; + /* * The ISP computes the AWB means after applying the colour gains, * divide by the gains that were used to get the raw means from the From patchwork Mon Feb 17 10:01:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22796 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 04C55C32A2 for ; Mon, 17 Feb 2025 10:02:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 92AC168683; Mon, 17 Feb 2025 11:02:39 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="t7UU0c9y"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 588A56867B for ; Mon, 17 Feb 2025 11:02:36 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b47f:e20a:c4c7:ece1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 07F8D11E9; Mon, 17 Feb 2025 11:01:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1739786475; bh=W1dgfgNDzGkCyu/+G5U/h/Hyu964ZmBC5f9BvphT/Ss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t7UU0c9y+yAWABi0teAkk4sQnnoBsFK5IXmn7tAKZQT8Tyq31fS77MOn2I3QTuMTY JJuA0RdJkKBOi6PB/b7oIZS05Ai11XobBieQYrbmbda6wDlIxdNtBVHre62a8Xicd/ A1AuQ8xcT3B3508TlEAvBhvp0EZxtKKiPSp2q2Hg= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 10/10] ipa: rkisp1: awb: Avoid division by zero Date: Mon, 17 Feb 2025 11:01:51 +0100 Message-ID: <20250217100203.297894-11-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217100203.297894-1-stefan.klug@ideasonboard.com> References: <20250217100203.297894-1-stefan.klug@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" As the gains can also be specified manually, the regulation can run into numeric instabilities by dividing by near zero. Mitigate that by applying a small minium value. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham --- src/ipa/rkisp1/algorithms/awb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 66e6aecedc4c..6315d2adaad9 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -310,9 +310,9 @@ void Awb::process(IPAContext &context, /* * The ISP computes the AWB means after applying the colour gains, * divide by the gains that were used to get the raw means from the - * sensor. + * sensor. Apply a minimum value to avoid divisions by near-zero. */ - rgbMeans /= frameContext.awb.gains; + rgbMeans /= frameContext.awb.gains.max(0.01); /* * If the means are too small we don't have enough information to