From patchwork Fri Oct 18 16:06:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 21692 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 A0C7CC32FE for ; Fri, 18 Oct 2024 16:06:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5332A6538A; Fri, 18 Oct 2024 18:06:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="U/YDhagi"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D3AD9633C7 for ; Fri, 18 Oct 2024 18:06:44 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:77a0:ddb9:22bf:b8d9]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1C5A521C; Fri, 18 Oct 2024 18:05:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1729267501; bh=lJVBcic6UlnU4cvTpoFO80fKah+GR0BP2eHxCGetaVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U/YDhagiWLROyDoTb0mmPjQAdn74vAPhYXdWT4+gt1Kewr2zyfeHKDIocUGM9MqN3 Z1MYEuFWjSrDm+tp8r2tqRDNZc4v+pNTZrCkTEWOI9zsbL92FpFMY3m+zYiezy5dPJ QXZLz9djMibJwg0ZGsZPAUJnOvpLImrOPOXMUGKs= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham , Laurent Pinchart , Paul Elder Subject: [PATCH v4 1/4] ipa: rkisp1: algorithms: agc: Check for correct stats type Date: Fri, 18 Oct 2024 18:06:30 +0200 Message-ID: <20241018160638.936993-2-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241018160638.936993-1-stefan.klug@ideasonboard.com> References: <20241018160638.936993-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" Sometimes the ISP produces statistics only with a subset of statistic types being valid. It doesn't happen normally, but was observed in the wild. Check for the RKISP1_CIF_ISP_STAT_AUTOEXP bit to prevent using invalid or outdated data. As it doesn't happen regularly add an error message to get notified when it happens. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder --- Changes in v4: - Fix missing fillMetadata introduced in v3. Changes in v3: - Split check for stats and type, to silence messages in raw mode Changes in v2: - Added error message - Made condition more readable - Collected tags --- src/ipa/rkisp1/algorithms/agc.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp index 17d074d9c03e..301b7ec26508 100644 --- a/src/ipa/rkisp1/algorithms/agc.cpp +++ b/src/ipa/rkisp1/algorithms/agc.cpp @@ -402,6 +402,12 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, fillMetadata(context, frameContext, metadata); return; } + + if (!(stats->meas_type & RKISP1_CIF_ISP_STAT_AUTOEXP)) { + fillMetadata(context, frameContext, metadata); + LOG(RkISP1Agc, Error) << "AUTOEXP data is missing in statistics"; + return; + } /* * \todo Verify that the exposure and gain applied by the sensor for @@ -412,7 +418,6 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, */ const rkisp1_cif_isp_stat *params = &stats->params; - ASSERT(stats->meas_type & RKISP1_CIF_ISP_STAT_AUTOEXP); /* The lower 4 bits are fractional and meant to be discarded. */ Histogram hist({ params->hist.hist_bins, context.hw->numHistogramBins }, From patchwork Fri Oct 18 16:06:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 21693 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 63B85C32FE for ; Fri, 18 Oct 2024 16:06:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1472D65391; Fri, 18 Oct 2024 18:06:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qb5EcVtA"; 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 7DD8165390 for ; Fri, 18 Oct 2024 18:06:48 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:77a0:ddb9:22bf:b8d9]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A534021C; Fri, 18 Oct 2024 18:05:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1729267504; bh=bpoarOGtsRZjC2G9WSLK3uGLiW7jU/sVl8mPJoVgMA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qb5EcVtAI+mEI5GN5qUwH784zn6w69qBY8UkCvWY5kaCmM1l8OMSYt3zC6I8oLjQa deBp0b8TMrbJ8h6GDwES773dYHfRkOFr9nqVdPFF9Vco7qXxUBVFe3WEUJmraRS/Ru PV359ErReuFwcEUGrD44m2CfctrLRQWDZk+d4EjU= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham , Laurent Pinchart , Paul Elder Subject: [PATCH v4 2/4] ipa: rkisp1: algorithms: awb: Check for correct stats type Date: Fri, 18 Oct 2024 18:06:31 +0200 Message-ID: <20241018160638.936993-3-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241018160638.936993-1-stefan.klug@ideasonboard.com> References: <20241018160638.936993-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" Sometimes the ISP produces statistics only with a subset of statistic types being valid. It doesn't happen normally, but was observed in the wild. Check for the RKISP1_CIF_ISP_STAT_AWB bit to prevent using invalid or outdated data. As it doesn't happen regularly add an error message to get notified when it happens. For simpler code structure, the ColourTemperature metadata entry gets written unconditionally and overwritten later if needed. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder --- Changes in v2: - Added error message - Made condition more readable - Collected tags --- src/ipa/rkisp1/algorithms/awb.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 955a9ff4a897..b3c00bef9b7e 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -215,6 +215,12 @@ void Awb::process(IPAContext &context, static_cast(frameContext.awb.gains.red), static_cast(frameContext.awb.gains.blue) }); + metadata.set(controls::ColourTemperature, activeState.awb.temperatureK); + + if (!stats || !(stats->meas_type & RKISP1_CIF_ISP_STAT_AWB)) { + LOG(RkISP1Awb, Error) << "AWB data is missing in statistics"; + return; + } if (rgbMode_) { greenMean = awb->awb_mean[0].mean_y_or_g; @@ -270,10 +276,8 @@ void Awb::process(IPAContext &context, * meaningfully calculate gains. Freeze the algorithm in that case. */ if (redMean < kMeanMinThreshold && greenMean < kMeanMinThreshold && - blueMean < kMeanMinThreshold) { - metadata.set(controls::ColourTemperature, activeState.awb.temperatureK); + blueMean < kMeanMinThreshold) return; - } activeState.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean); From patchwork Fri Oct 18 16:06:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 21694 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 2AF72C32FE for ; Fri, 18 Oct 2024 16:06:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D5C2765394; Fri, 18 Oct 2024 18:06:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="PgMzpC8S"; 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 8AAF16538A for ; Fri, 18 Oct 2024 18:06:51 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:77a0:ddb9:22bf:b8d9]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C81D021C; Fri, 18 Oct 2024 18:05:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1729267507; bh=kkl+vFfasWNR2zoP9t8OzWrHjLHX6T7+Hp4tzuJQ9CA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PgMzpC8Sm6AHklIUS0Gx736vg6dxOAs/EcpZjg4ZMEugnInx7o+NbPDV9TUmo0vFZ rcqPnpuQFxzObXO+3m4wIQRhsK3NWf7ECyQGvYCxvYLmIi0O9OciVgr0lNQA6J1vCK BM+/3DPKtBIIvubx3gtUi1IaVX4VmuM0Tm7HAoJk= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham , Laurent Pinchart , Paul Elder Subject: [PATCH v4 3/4] libcamera: controls: Add missing size to control_type Date: Fri, 18 Oct 2024 18:06:32 +0200 Message-ID: <20241018160638.936993-4-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241018160638.936993-1-stefan.klug@ideasonboard.com> References: <20241018160638.936993-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 size member is missing in control_type. This did not do any harm because the only control using the Point type was an array control. As soon as a control-id with a non-array Point control gets defined, the compile fails with: error: size is not a member of libcamera::details::control_type Fixes: 200d535ca85f ("libcamera: controls: Add ControlTypePoint") Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder --- Changes in v2: - Describe the error in commit message - Collected tags --- include/libcamera/controls.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index ca60bbacad17..28fec767fae1 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -101,6 +101,7 @@ struct control_type { template<> struct control_type { static constexpr ControlType value = ControlTypePoint; + static constexpr std::size_t size = 0; }; template From patchwork Fri Oct 18 16:06:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 21695 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 D3599C32FE for ; Fri, 18 Oct 2024 16:06:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7FF9365399; Fri, 18 Oct 2024 18:06:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="T0pDom2R"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 25D2C65396 for ; Fri, 18 Oct 2024 18:06:54 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:77a0:ddb9:22bf:b8d9]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5150721C; Fri, 18 Oct 2024 18:05:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1729267510; bh=ChoflgYzHLwzEK6erfk9LwIgLxPfLPtRhkvqJyf/PZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T0pDom2RgyeNWJKY4vu9oD0u12IwXQqpgmNEO0fmxJmDdKs2nScMWzKak8fnNZmpK pz/lMuOuKbUmvui8v0caYFcl0ltEdiMMwBT8q40uCtH6pgKI5fqXtEvz60ecX6sQYA gNvXVTn8CdIFEPdYXrkJMz8bTkULEPxWilqoWIYI= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham , Laurent Pinchart , Paul Elder Subject: [PATCH v4 4/4] pycamera: Add missing code for ControlTypePoint Date: Fri, 18 Oct 2024 18:06:33 +0200 Message-ID: <20241018160638.936993-5-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241018160638.936993-1-stefan.klug@ideasonboard.com> References: <20241018160638.936993-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 the python bindings ControlTypePoint is not handled in the corresponding conversion functions. Add that. While at it, sort the listings in the same order as the enum in controls.h. Fixes: 200d535ca85f ("libcamera: controls: Add ControlTypePoint") Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder --- Changes in v2: - Collected tags --- src/py/libcamera/py_enums.cpp | 3 ++- src/py/libcamera/py_helpers.cpp | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/py/libcamera/py_enums.cpp b/src/py/libcamera/py_enums.cpp index ca6aeb868cbe..9e75ec1a97b3 100644 --- a/src/py/libcamera/py_enums.cpp +++ b/src/py/libcamera/py_enums.cpp @@ -32,7 +32,8 @@ void init_py_enums(py::module &m) .value("Float", ControlType::ControlTypeFloat) .value("String", ControlType::ControlTypeString) .value("Rectangle", ControlType::ControlTypeRectangle) - .value("Size", ControlType::ControlTypeSize); + .value("Size", ControlType::ControlTypeSize) + .value("Point", ControlType::ControlTypePoint); py::enum_(m, "Orientation") .value("Rotate0", Orientation::Rotate0) diff --git a/src/py/libcamera/py_helpers.cpp b/src/py/libcamera/py_helpers.cpp index 79891ab63862..1ad1d4c1a1cd 100644 --- a/src/py/libcamera/py_helpers.cpp +++ b/src/py/libcamera/py_helpers.cpp @@ -34,6 +34,8 @@ static py::object valueOrTuple(const ControlValue &cv) py::object controlValueToPy(const ControlValue &cv) { switch (cv.type()) { + case ControlTypeNone: + return py::none(); case ControlTypeBool: return valueOrTuple(cv); case ControlTypeByte: @@ -46,14 +48,14 @@ py::object controlValueToPy(const ControlValue &cv) return valueOrTuple(cv); case ControlTypeString: return py::cast(cv.get()); - case ControlTypeRectangle: - return valueOrTuple(cv); case ControlTypeSize: { const Size *v = reinterpret_cast(cv.data().data()); return py::cast(v); } - case ControlTypeNone: - return py::none(); + case ControlTypeRectangle: + return valueOrTuple(cv); + case ControlTypePoint: + return valueOrTuple(cv); default: throw std::runtime_error("Unsupported ControlValue type"); } @@ -73,6 +75,8 @@ static ControlValue controlValueMaybeArray(const py::object &ob) ControlValue pyToControlValue(const py::object &ob, ControlType type) { switch (type) { + case ControlTypeNone: + return ControlValue(); case ControlTypeBool: return ControlValue(ob.cast()); case ControlTypeByte: @@ -89,8 +93,8 @@ ControlValue pyToControlValue(const py::object &ob, ControlType type) return controlValueMaybeArray(ob); case ControlTypeSize: return ControlValue(ob.cast()); - case ControlTypeNone: - return ControlValue(); + case ControlTypePoint: + return controlValueMaybeArray(ob); default: throw std::runtime_error("Control type not implemented"); }