From patchwork Sun Feb 2 23:27:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 22720 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 46FB6C32DF for ; Sun, 2 Feb 2025 23:27:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7963961876; Mon, 3 Feb 2025 00:27:45 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="W7myPJDp"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1485A61876 for ; Mon, 3 Feb 2025 00:27:43 +0100 (CET) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D6E37227; Mon, 3 Feb 2025 00:26:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1738538792; bh=sBjcKNTQzb9qUvmdoEZ6AKEQtcR40/fKT0p/WtzHA3I=; h=From:To:Cc:Subject:Date:From; b=W7myPJDpKY0APMwexfjNO2oUm+Pb5G5RlcZqhGaxBFuuS3VhlKPhQgWROu592R6Zk /KNL/d05gB9iUsOCCz23eYDzrshVI4E/yuudoPmiZ/VD2ryOv87ri9gv8lC4amJrJh mnY31DJYO3V7CvdLlEpsTf/p2n9S8C4YNR1ztdVI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [PATCH v2] libcamera: matrix: Add read-only accessor to internal data Date: Mon, 3 Feb 2025 01:27:39 +0200 Message-ID: <20250202232739.31548-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.3 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 a data() function to the Matrix class to access the internal data. This is useful for code that needs to use the matrix contents as a linear array, as shown by the RkISP1::Ccm::process() function that needs to copy the matrix data to a local variable. Simplify that function by using the new accessor. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Milan Zamazal --- Changes since v1: - Expand function documentation --- include/libcamera/internal/matrix.h | 2 ++ src/ipa/rkisp1/algorithms/ccm.cpp | 7 +------ src/libcamera/matrix.cpp | 11 +++++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) base-commit: 9bc8b6a573a63b8c9f5588cdea6da5ae71abd138 -- Regards, Laurent Pinchart diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h index 7a71028c473a..a055e6926c94 100644 --- a/include/libcamera/internal/matrix.h +++ b/include/libcamera/internal/matrix.h @@ -66,6 +66,8 @@ public: return out.str(); } + Span data() const { return data_; } + Span operator[](size_t i) const { return Span{ &data_.data()[i * Cols], Cols }; diff --git a/src/ipa/rkisp1/algorithms/ccm.cpp b/src/ipa/rkisp1/algorithms/ccm.cpp index e2b5cf4d313e..eb8ca39e56a8 100644 --- a/src/ipa/rkisp1/algorithms/ccm.cpp +++ b/src/ipa/rkisp1/algorithms/ccm.cpp @@ -120,12 +120,7 @@ void Ccm::process([[maybe_unused]] IPAContext &context, [[maybe_unused]] const rkisp1_stat_buffer *stats, ControlList &metadata) { - float m[9]; - for (unsigned int i = 0; i < 3; i++) { - for (unsigned int j = 0; j < 3; j++) - m[i * 3 + j] = frameContext.ccm.ccm[i][j]; - } - metadata.set(controls::ColourCorrectionMatrix, m); + metadata.set(controls::ColourCorrectionMatrix, frameContext.ccm.ccm.data()); } REGISTER_IPA_ALGORITHM(Ccm, "Ccm") diff --git a/src/libcamera/matrix.cpp b/src/libcamera/matrix.cpp index 4d95a19bfbb9..e7e027225666 100644 --- a/src/libcamera/matrix.cpp +++ b/src/libcamera/matrix.cpp @@ -52,6 +52,17 @@ LOG_DEFINE_CATEGORY(Matrix) * \return A string describing the matrix */ +/** + * \fn Matrix::data() + * \brief Access the matrix data as a linear array + * + * Access the contents of the matrix as a one-dimensional linear array of + * values in row-major order. The size of the array is equal to the product of + * the number of rows and columns of the matrix (Rows x Cols). + * + * \return A span referencing the matrix data as a linear array + */ + /** * \fn Span Matrix::operator[](size_t i) const * \brief Index to a row in the matrix