From patchwork Sun Sep 13 15:31:04 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 28235 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 A22DDC3200 for ; Sun, 13 Sep 2026 15:31:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1382968681; Sun, 13 Sep 2026 17:31:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="wdI2hJZJ"; 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 98D0368679 for ; Sun, 13 Sep 2026 17:31:08 +0200 (CEST) Received: from killaraus.ideasonboard.com (2001-14ba-70f3-e800--a06.rev.dnainternet.fi [IPv6:2001:14ba:70f3:e800::a06]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4089D1587; Sun, 13 Sep 2026 17:29:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789313369; bh=3Pz9gahAIxto2qeHKxGUOOS0KFVOFYtYWvatlQj3Sl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wdI2hJZJhmUSu1Vk7PA91hwKr/2IUk/JYLSREZjarWmXjmz+5X2omPIjyb7ShYizN y3n1mZP2Vr7Fx7YWhm8GFJ0OJMP86ThaBxSneyNXwGq/6VoyuOhXHsoy8A8xLTMw79 HguRO6CxA9y+c4C6to1uyQRSvN81Htps4uG9+fmw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH 1/2] libcamera: matrix: Add a transpose() function Date: Sun, 13 Sep 2026 18:31:04 +0300 Message-ID: <20260913153105.2478177-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260913153105.2478177-1-laurent.pinchart@ideasonboard.com> References: <20260913153105.2478177-1-laurent.pinchart@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 Matrix class has a member function to invert a matrix, but no function to transpose it. We already have one open-coded transpose operation in the software ISP implementation, and more would likely be added. Add a transpose() member function to the Matrix class to cover this need. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/matrix.h | 12 ++++++++++++ src/libcamera/matrix.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h index f74cda103c72..f563c9cd3a42 100644 --- a/include/libcamera/internal/matrix.h +++ b/include/libcamera/internal/matrix.h @@ -24,6 +24,9 @@ LOG_DECLARE_CATEGORY(Matrix) template bool matrixInvert(std::span dataIn, std::span dataOut, unsigned int dim, std::span scratchBuffer, std::span swapBuffer); +template +void matrixTranspose(std::span dataIn, std::span dataOut, + unsigned int rows, unsigned int cols); #endif /* __DOXYGEN__ */ template @@ -115,6 +118,15 @@ public: return inverse; } + Matrix transpose() const + { + Matrix transposed; + matrixTranspose(std::span(data_), + std::span(transposed.data_), + Rows, Cols); + return transposed; + } + private: /* * \todo The initializer is only necessary for the constructor to be diff --git a/src/libcamera/matrix.cpp b/src/libcamera/matrix.cpp index 9cb0885b3b54..b0cb073423c6 100644 --- a/src/libcamera/matrix.cpp +++ b/src/libcamera/matrix.cpp @@ -107,6 +107,16 @@ LOG_DEFINE_CATEGORY(Matrix) * \return The inverse of the matrix */ +/** + * \fn Matrix::transpose() const + * \brief Compute the transpose of the matrix + * + * This function computes the transpose of the matrix. It is only implemented + * for matrices of float and double types. + * + * \return The transpose of the matrix + */ + /** * \fn Matrix::operator[](size_t i) * \copydoc Matrix::operator[](size_t i) const @@ -309,6 +319,23 @@ template bool matrixInvert(std::span data, std::span scratchBuffer, std::span swapBuffer); +template +void matrixTranspose(std::span dataIn, std::span dataOut, + unsigned int rows, unsigned int cols) +{ + for (unsigned int row = 0; row < rows; ++row) { + for (unsigned int col = 0; col < cols; ++col) + dataOut[col * rows + row] = dataIn[row * cols + col]; + } +} + +template void matrixTranspose(std::span dataIn, + std::span dataOut, + unsigned int rows, unsigned int cols); +template void matrixTranspose(std::span dataIn, + std::span dataOut, + unsigned int rows, unsigned int cols); + /* * The value node shall be a list of numerical values. Its size shall be equal * to the product of the number of rows and columns of the matrix (Rows x From patchwork Sun Sep 13 15:31:05 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 28236 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 3202CC3200 for ; Sun, 13 Sep 2026 15:31:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CC8C668687; Sun, 13 Sep 2026 17:31:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="mpIIwhS5"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F1F3D68679 for ; Sun, 13 Sep 2026 17:31:09 +0200 (CEST) Received: from killaraus.ideasonboard.com (2001-14ba-70f3-e800--a06.rev.dnainternet.fi [IPv6:2001:14ba:70f3:e800::a06]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 82D3015BF; Sun, 13 Sep 2026 17:29:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789313370; bh=6eXWSyxS2FoISF87xLf/Yq0CYVYcWE+4m8H8qSUc8x0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mpIIwhS5MgYzdKdtjUSvbV8MYLATEHEQgs0pO8HpASMozumMPw1B+lWUEGwmpvTdr dsXFxNfswnvGjA5k3PV/FyrY297Mdixo3PSsnUDT8c4hfoX7PNfkCr8dMUvbyXKkno 3TdWqH3JWffNlQJOtIBDlA2vYgN3kdkbk+W25XDM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH 2/2] libcamera: software_isp: debayer_egl: Use Matrix::transpose() Date: Sun, 13 Sep 2026 18:31:05 +0300 Message-ID: <20260913153105.2478177-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260913153105.2478177-1-laurent.pinchart@ideasonboard.com> References: <20260913153105.2478177-1-laurent.pinchart@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" Replace the manual matrix transposition code with a call to Matrix::transpose(). Signed-off-by: Laurent Pinchart --- src/libcamera/software_isp/debayer_egl.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 3536b5c51ffa..4477c928342f 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -460,21 +460,10 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara << " textureUniformStep_.y " << Step[1] << " textureUniformStrideFactor_ " << Stride << " textureUniformProjMatrix_ " << textureUniformProjMatrix_; - /* - * Pre-transpose matrix for GLES 2.0 - */ - GLfloat ccm[9] = { - params.combinedMatrix[0][0], - params.combinedMatrix[1][0], - params.combinedMatrix[2][0], - params.combinedMatrix[0][1], - params.combinedMatrix[1][1], - params.combinedMatrix[2][1], - params.combinedMatrix[0][2], - params.combinedMatrix[1][2], - params.combinedMatrix[2][2], - }; - glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm); + + /* Pre-transpose matrix for GLES 2.0. */ + Matrix ccm = params.combinedMatrix.transpose(); + glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm.data().data()); LOG(Debayer, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix; /*