From patchwork Mon Jul 20 11:39:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 27386 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 5A183C3264 for ; Mon, 20 Jul 2026 11:39:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9D30167E1F; Mon, 20 Jul 2026 13:39:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=robert.mader@collabora.com header.b="P3ogPoTs"; dkim-atps=neutral Received: from sender4-op-o11.zoho.com (sender4-op-o11.zoho.com [136.143.188.11]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CDA7466122 for ; Mon, 20 Jul 2026 13:39:49 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1784547585; cv=none; d=zohomail.com; s=zohoarc; b=PJKLiaUfdV5Ns2Qg5DpSHd4s1hlqouOC3BGa5TzKemPN8MbINhRRmZuJQNG97G1fMJU7rcHxvbfZYniQcuDUMQ35ckGmCMniuQkH+ZVz6CNJbC6dNAwI+KDi+UCc1VT4cpCr11DBlKIzJsi6yKNwzwCW4h79xxgsM7fWbcFzQO8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784547585; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=BGc2KL47AMbUeUrphPA2fXB/5CWcv52E3dnfUCvcYbc=; b=kuVSPLLGAmW1lbQi1+kWoyHQ5qaRS4xeV2pxVobu5TslkwJKr6o1P1QnyZGogZ/1jubiBIiGsX1lPVXxuz0tHO6ZphwGZ+wS3v9wJ4/A24qc/X3tP/pfIVgNSR25yHHXNd36L28KQj3aO6R0XOs33p5CNbhpZs71przk2xb5hl4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=robert.mader@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1784547585; s=zohomail; d=collabora.com; i=robert.mader@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=BGc2KL47AMbUeUrphPA2fXB/5CWcv52E3dnfUCvcYbc=; b=P3ogPoTs0gUd9hyZ3x5xreQTT8Fr2TZDsNMocOTRJUinIbCjKvAiSYEN7lpVrsS0 TFxcZ1nxSyOPOgoBXb3F3KtnBF+6fvsIkPVk+ZkkpZp5AGU7fFsVwNsfoOkDAlm/1Vi 9ONcCJhb84t0ToiKMsYLVgjcb9QJ1/wWfbW1QZGs= Received: by mx.zohomail.com with SMTPS id 1784547584670848.5064648967673; Mon, 20 Jul 2026 04:39:44 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH v2] libcamera: debayer: Use helpers for strides and frame sizes Date: Mon, 20 Jul 2026 13:39:35 +0200 Message-ID: <20260720113935.52936-1-robert.mader@collabora.com> X-Mailer: git-send-email 2.55.0 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" Clean up some open-coded logic, making the code shorter, more generic and easier to follow. Signed-off-by: Robert Mader --- Changes in v2: - remove bpp docs to fix CI --- src/libcamera/software_isp/debayer.cpp | 3 --- src/libcamera/software_isp/debayer.h | 1 - src/libcamera/software_isp/debayer_cpu.cpp | 29 +++------------------- src/libcamera/software_isp/debayer_cpu.h | 1 - src/libcamera/software_isp/debayer_egl.cpp | 24 ++---------------- src/libcamera/software_isp/debayer_egl.h | 1 - 6 files changed, 5 insertions(+), 54 deletions(-) diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp index 56446f55d..a4854e51b 100644 --- a/src/libcamera/software_isp/debayer.cpp +++ b/src/libcamera/software_isp/debayer.cpp @@ -192,9 +192,6 @@ Debayer::~Debayer() * Defines how the output of the debayer process is laid out in memory. * It includes per-pixel size, stride, and total frame size. * - * \var Debayer::DebayerOutputConfig::bpp - * Bytes used per pixel in the output format. - * * \var Debayer::DebayerOutputConfig::stride * Line stride in bytes for the output frame. * diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h index 28f1b857b..556852260 100644 --- a/src/libcamera/software_isp/debayer.h +++ b/src/libcamera/software_isp/debayer.h @@ -69,7 +69,6 @@ public: }; struct DebayerOutputConfig { - unsigned int bpp; unsigned int stride; unsigned int frameSize; }; diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index 49382b4c2..25e9830c8 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -24,6 +24,7 @@ #include "libcamera/internal/bayer_format.h" #include "libcamera/internal/camera_manager.h" +#include "libcamera/internal/formats.h" #include "libcamera/internal/framebuffer.h" #include "libcamera/internal/global_configuration.h" #include "libcamera/internal/mapped_framebuffer.h" @@ -474,24 +475,6 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf return -EINVAL; } -int DebayerCpu::getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config) -{ - if (outputFormat == formats::RGB888 || outputFormat == formats::BGR888) { - config.bpp = 24; - return 0; - } - - if (outputFormat == formats::XRGB8888 || outputFormat == formats::ARGB8888 || - outputFormat == formats::XBGR8888 || outputFormat == formats::ABGR8888) { - config.bpp = 32; - return 0; - } - - LOG(Debayer, Info) - << "Unsupported output format " << outputFormat.toString(); - return -EINVAL; -} - /* * Check for standard Bayer orders and set xShift_ and swap debayer0/1, so that * a single pair of BGGR debayer functions can be used for all 4 standard orders. @@ -776,15 +759,9 @@ std::vector DebayerCpu::formats(PixelFormat inputFormat) std::tuple DebayerCpu::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) { - DebayerCpu::DebayerOutputConfig config; - - if (getOutputConfig(outputFormat, config) != 0) - return std::make_tuple(0, 0); - /* round up to multiple of 8 for 64 bits alignment */ - unsigned int stride = (size.width * config.bpp / 8 + 7) & ~7; - - return std::make_tuple(stride, stride * size.height); + const PixelFormatInfo &info = PixelFormatInfo::info(outputFormat); + return std::make_tuple(info.stride(size.width, 0, 8), info.frameSize(size, 8)); } void DebayerCpuThread::setupInputMemcpy(const uint8_t *linePointers[]) diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index 5281c65cb..2c88c9e1a 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -121,7 +121,6 @@ private: void debayer12P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]); static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config); - static int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config); int setupStandardBayerOrder(BayerFormat::Order order); int setDebayerFunctions(PixelFormat inputFormat, PixelFormat outputFormat, diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 02651fe87..24faf480d 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -96,20 +96,6 @@ int DebayerEGL::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf return -EINVAL; } -int DebayerEGL::getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config) -{ - if (outputFormat == formats::XRGB8888 || outputFormat == formats::ARGB8888 || - outputFormat == formats::XBGR8888 || outputFormat == formats::ABGR8888) { - config.bpp = 32; - return 0; - } - - LOG(Debayer, Info) - << "Unsupported output format " << outputFormat; - - return -EINVAL; -} - int DebayerEGL::getShaderVariableLocations(void) { attributeVertex_ = glGetAttribLocation(programId_, "vertexIn"); @@ -374,15 +360,9 @@ std::vector DebayerEGL::formats(PixelFormat inputFormat) std::tuple DebayerEGL::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) { - DebayerEGL::DebayerOutputConfig config; - - if (getOutputConfig(outputFormat, config) != 0) - return std::make_tuple(0, 0); - /* Align stride to 256 bytes as a generic GPU memory access alignment */ - unsigned int stride = libcamera::utils::alignUp(size.width * config.bpp / 8, 256); - - return std::make_tuple(stride, stride * size.height); + const PixelFormatInfo &info = PixelFormatInfo::info(outputFormat); + return std::make_tuple(info.stride(size.width, 0, 256), info.frameSize(size, 256)); } uint32_t DebayerEGL::preferredInputStride(const PixelFormat &inputFormat, const Size &size) diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index d6223f3a9..e613639f5 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -63,7 +63,6 @@ public: private: static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config); - static int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config); int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat); int getShaderVariableLocations(); void setShaderVariableValues(eGLImage &eGLImageIn, const DebayerParams ¶ms);