From patchwork Wed Dec 10 00:31:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 25405 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 C91BCBD1F1 for ; Wed, 10 Dec 2025 00:32:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8691D61449; Wed, 10 Dec 2025 01:32:23 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Fokd8gJp"; dkim-atps=neutral Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C59F161431 for ; Wed, 10 Dec 2025 01:32:21 +0100 (CET) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-3437af8444cso5652153a91.2 for ; Tue, 09 Dec 2025 16:32:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1765326740; x=1765931540; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uNA5N28ijjnRUrjL2lur7P+7SWkYcDAcfVtdT1cafQs=; b=Fokd8gJpYvQr3TU0Wd66kUYqus3CqOO+txm71xynUirGMXDkaXk1W7+y0dcNQ+AX1/ PxzJV1VxDPDOs6Rz8gRr/P8oh4d3nbdG0wRO5pXSocYyJMAfrkQ+PhBNzMHK/Xv52SWV nk5XYVp4ndiSKnSAenA42/u80UVaGxHK3D+MrAGcffdTLGMJf/LulnLMRwVYAyNnc730 s3M5xZpmtHVODDpvenjwVVrozZjlxyAYnnW5tGhWZSWuWJM79Zznh5U64ObywDFXZguk qOzctj1OJbTQqdJMb8piKWu9weU1s9qn7SD17fnsMDrUy4ZN9ZiRjf8nD9sXtv7l+7q+ 7frg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765326740; x=1765931540; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uNA5N28ijjnRUrjL2lur7P+7SWkYcDAcfVtdT1cafQs=; b=BsD6OvSNwLCbBrauyyXJ1DfLg9ueh7JSwQnZbor+5XeGxpzDwmdZ2RAIs8UiPdcCol SHlrQEAYCA32SJd/++M4TqK3p/tMsfR85QwdC/VXYR8NO997dC1AvWPemMDhYbfWANCe 8rSfl/XIR2RKUWMtJWQhmUdNO26CagIwAGGO9nBprZso1z3hLk0UX8K54bMArRjmUITg xNrnV9BE0z0x5Oq3WPzGsGMdHow3ghHyGrza8Nw/refKQX88qpJdvp+ZY7ZeucsjOAlE EbYnh1h4kIDiVBnGtWeOdCOVn0aIbO602BhWkPYvuMB9iNQOi+Qc5yqdoGAYiU8EtJAk /dEw== X-Gm-Message-State: AOJu0YxsfjTvKVK7m3xn4rNtUyryfZPk048i0D7WGV0zLpwNE3oDEIYT 1D0+i8cAJhPrDXwJJvON0tqLqB5UA8/M/XmLhcwEmsZYAqPqGfivOecj7dkNI6qOvnoaWwMwPsy 1nEjW X-Gm-Gg: AY/fxX4hobuijqWylieC1RdWybNP1XpAFdz92LC/opQtX4NUN8mlFb6ij071XzfPMWv qxjn/KLykHudkG1LCLRqQQBiGgxOowkYTOoRcwTNe5VwUwW8HgMs/TY9VQcYOO7/fl/N4w86d9x n2IfzxlRpr63821WCxO1HfWGXYZwenGPUyy2lpw6FYiW5SLp6j/Jbusom6l8SNFmDmE4uLOMTeq iE+cT47GW9AeAp4r8J0DR9MZzRB/48x3u4tZm6GwSwEQr2RJo6J+9v/YoaN72H/yapbMlX86zTS j2xOx2wKONnWL0vWhANEZYRMTOg6Sy9TThB8UzPftic5BBwH+rrf5ZjBPWaGj9FAwN5UOXwSLCf 8CPiaQIq1gAvVGuXxNnQpIyy7NMSom9MQ1qcGLCP5utg3Mh6qrsyc0WP34L18/GxeY0O1j2xXkM XW/Bo0sRbB8m51ml0mwFibmivmBMMMl/UO0wo+bxqOFsa9UHTq/NIRee6y7qnGkJQY X-Google-Smtp-Source: AGHT+IHFSqHo3G6LfFmF5pBWolbgfn3289sJKSlcTdun/KmTG0R0kJlhyVme83RQk05OAf4rOLd7Jw== X-Received: by 2002:a17:90a:d44d:b0:341:8ca8:ae64 with SMTP id 98e67ed59e1d1-34a7289e773mr495612a91.35.1765326739967; Tue, 09 Dec 2025 16:32:19 -0800 (PST) Received: from inspiron14p-linux (p96936b06.osaknt01.ap.so-net.ne.jp. [150.147.107.6]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34a70427ea6sm566580a91.3.2025.12.09.16.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Dec 2025 16:32:19 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Kieran Bingham , Milan Zamazal Subject: [PATCH v4 09/20] libcamera: software_isp: Move useful items from DebayerCpu to Debayer base class Date: Wed, 10 Dec 2025 00:31:26 +0000 Message-ID: <20251210003139.43606-10-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251210003139.43606-1-bryan.odonoghue@linaro.org> References: <20251210003139.43606-1-bryan.odonoghue@linaro.org> 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 DebayerCpu class has a number of variables, embedded structures and methods which are useful to DebayerGpu implementation. Move relevant variables and methods to base class. Since we want to call setParams() from the GPUISP and reuse the code in the existing CPUISP as a first step, we need to move all of the dependent variables in DebayerCPU to the Debayer base class including LookupTable and redCcm_. The DebayerEGL class will ultimately be able to consume both the CCM and non-CCM data. Reviewed-by: Kieran Bingham Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/debayer.cpp | 149 +++++++++++++++++++++ src/libcamera/software_isp/debayer.h | 35 ++++- src/libcamera/software_isp/debayer_cpu.cpp | 2 +- src/libcamera/software_isp/debayer_cpu.h | 41 +----- 4 files changed, 185 insertions(+), 42 deletions(-) diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp index e9e18c488..1e3f08673 100644 --- a/src/libcamera/software_isp/debayer.cpp +++ b/src/libcamera/software_isp/debayer.cpp @@ -18,6 +18,12 @@ namespace libcamera { * \brief Struct to hold the debayer parameters. */ +/** + * \fn Debayer::Debayer(const GlobalConfiguration &configuration) + * \brief Construct a Debayer object + * \param[in] configuration Global configuration reference + */ + /** * \var DebayerParams::kRGBLookupSize * \brief Size of a color lookup table @@ -167,6 +173,24 @@ Debayer::~Debayer() */ /** + * \fn const SharedFD &Debayer::getStatsFD() + * \brief Get the file descriptor for the statistics. + * + * This file descriptor provides access to the output statistics buffer + * associated with the current debayering process. + * + * \return The file descriptor pointing to the statistics data. + */ + +/** + * \fn unsigned int Debayer::frameSize() + * \brief Get the output frame size. + * + * \return The total output frame size in bytes as configured for the + * current stream. + */ + + /** * \var Signal Debayer::inputBufferReady * \brief Signals when the input buffer is ready */ @@ -176,4 +200,129 @@ Debayer::~Debayer() * \brief Signals when the output buffer is ready */ +/** + * \struct Debayer::DebayerInputConfig + * \brief Structure describing the incoming Bayer parameters. + * + * The DebayerInputConfig structure defines the characteristics of the raw + * Bayer frame being processed, including: + * - The Bayer pattern dimensions (\ref patternSize) + * - Memory layout parameters such as stride and bytes per pixel (\ref bpp) + * - A list of supported output pixel formats. + * + * \var Debayer::DebayerInputConfig::patternSize + * Size of the Bayer pattern in pixels. For standard Bayer formats such as + * BGGR, GRBG, GBRG, and RGGB, this is typically 2×2 pixels. + * + * \var Debayer::DebayerInputConfig::bpp + * Number of bytes used per pixel in memory. This reflects storage size, + * not precision. + * + * \var Debayer::DebayerInputConfig::stride + * Line stride in bytes for the Bayer input frame. + * + * \var Debayer::DebayerInputConfig::outputFormats + * List of pixel formats supported as output for this input configuration. + */ + +/** + * \struct Debayer::DebayerOutputConfig + * \brief Structure describing the output frame configuration. + * + * 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. + * + * \var Debayer::DebayerOutputConfig::frameSize + * Total frame size in bytes for the output buffer. + */ + +/** + * \var Debayer::inputConfig_ + * \brief Input configuration parameters for the current debayer operation. + * + * Holds metadata describing the incoming Bayer image layout, including + * pattern size, bytes per pixel, stride, and supported output formats. + * Populated during configuration. + */ + +/** + * \var Debayer::outputConfig_ + * \brief Output configuration data for the debayered frame. + * + * Contains bytes per pixel, stride, and total frame size for the + * output image buffer. Set during stream configuration. + */ + +/** + * \var Debayer::red_ + * \brief Lookup table for red channel gain and correction values. + * + * This table provides precomputed per-pixel or per-intensity + * correction values for the red color channel used during debayering. + */ + +/** + * \var Debayer::green_ + * \brief Lookup table for green channel gain and correction values. + * + * This table provides precomputed per-pixel or per-intensity + * correction values for the green color channel used during debayering. + */ + +/** + * \var Debayer::blue_ + * \brief Lookup table for blue channel gain and correction values. + * + * This table provides precomputed per-pixel or per-intensity + * correction values for the blue color channel used during debayering. + */ + +/** + * \var Debayer::redCcm_ + * \brief Red channel Color Correction Matrix (CCM) lookup table. + * + * Contains coefficients for green channel color correction. + */ + +/** + * \var Debayer::greenCcm_ + * \brief Green channel Color Correction Matrix (CCM) lookup table. + * + * Contains coefficients for green channel color correction. + */ + +/** + * \var Debayer::blueCcm_ + * \brief Blue channel Color Correction Matrix (CCM) lookup table. + * + * Contains coefficients for blue channel color correction. + */ + +/** + * \var Debayer::gammaLut_ + * \brief Gamma correction lookup table. + */ + +/** + * \var Debayer::swapRedBlueGains_ + * \brief Flag indicating whether red and blue channel gains should be swapped. + * + * Used when the Bayer pattern order indicates that red/blue color channels are + * reversed. + */ + +/** + * \var Debayer::bench_ + * \brief Benchmarking utility instance for performance measurements. + * + * Used internally to track timing and performance metrics during + * debayer processing. + */ + } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h index ba033d440..b562985a6 100644 --- a/src/libcamera/software_isp/debayer.h +++ b/src/libcamera/software_isp/debayer.h @@ -14,11 +14,14 @@ #include #include +#include #include #include #include +#include "libcamera/internal/global_configuration.h" +#include "libcamera/internal/software_isp/benchmark.h" #include "libcamera/internal/software_isp/debayer_params.h" namespace libcamera { @@ -27,9 +30,10 @@ class FrameBuffer; LOG_DECLARE_CATEGORY(Debayer) -class Debayer +class Debayer : public Object { public: + Debayer (const GlobalConfiguration &configuration) : bench_(configuration) {}; virtual ~Debayer() = 0; virtual int configure(const StreamConfiguration &inputCfg, @@ -45,9 +49,38 @@ public: virtual SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) = 0; + virtual const SharedFD &getStatsFD() = 0; + + unsigned int frameSize() { return outputConfig_.frameSize; } + Signal inputBufferReady; Signal outputBufferReady; + struct DebayerInputConfig { + Size patternSize; + unsigned int bpp; + unsigned int stride; + std::vector outputFormats; + }; + + struct DebayerOutputConfig { + unsigned int bpp; + unsigned int stride; + unsigned int frameSize; + }; + + DebayerInputConfig inputConfig_; + DebayerOutputConfig outputConfig_; + DebayerParams::LookupTable red_; + DebayerParams::LookupTable green_; + DebayerParams::LookupTable blue_; + DebayerParams::CcmLookupTable redCcm_; + DebayerParams::CcmLookupTable greenCcm_; + DebayerParams::CcmLookupTable blueCcm_; + DebayerParams::LookupTable gammaLut_; + bool swapRedBlueGains_; + Benchmark bench_; + private: virtual Size patternSize(PixelFormat inputFormat) = 0; }; diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index b92c6a904..e55599f09 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -42,7 +42,7 @@ namespace libcamera { * \param[in] configuration The global configuration */ DebayerCpu::DebayerCpu(std::unique_ptr stats, const GlobalConfiguration &configuration) - : stats_(std::move(stats)), bench_(configuration) + : Debayer(configuration), stats_(std::move(stats)) { /* * Reading from uncached buffers may be very slow. diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index aff32491e..ecc4f9dd0 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -17,16 +17,14 @@ #include -#include "libcamera/internal/software_isp/benchmark.h" #include "libcamera/internal/bayer_format.h" -#include "libcamera/internal/global_configuration.h" #include "libcamera/internal/software_isp/swstats_cpu.h" #include "debayer.h" namespace libcamera { -class DebayerCpu : public Debayer, public Object +class DebayerCpu : public Debayer { public: DebayerCpu(std::unique_ptr stats, const GlobalConfiguration &configuration); @@ -41,21 +39,8 @@ public: strideAndFrameSize(const PixelFormat &outputFormat, const Size &size); void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params); SizeRange sizes(PixelFormat inputFormat, const Size &inputSize); - - /** - * \brief Get the file descriptor for the statistics - * - * \return the file descriptor pointing to the statistics - */ const SharedFD &getStatsFD() { return stats_->getStatsFD(); } - /** - * \brief Get the output frame size - * - * \return The output frame size - */ - unsigned int frameSize() { return outputConfig_.frameSize; } - private: /** * \brief Called to debayer 1 line of Bayer input data to output format @@ -112,19 +97,6 @@ private: template void debayer10P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]); - struct DebayerInputConfig { - Size patternSize; - unsigned int bpp; /* Memory used per pixel, not precision */ - unsigned int stride; - std::vector outputFormats; - }; - - struct DebayerOutputConfig { - unsigned int bpp; /* Memory used per pixel, not precision */ - unsigned int stride; - unsigned int frameSize; - }; - int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config); int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config); int setupStandardBayerOrder(BayerFormat::Order order); @@ -140,20 +112,11 @@ private: /* Max. supported Bayer pattern height is 4, debayering this requires 5 lines */ static constexpr unsigned int kMaxLineBuffers = 5; - DebayerParams::LookupTable red_; - DebayerParams::LookupTable green_; - DebayerParams::LookupTable blue_; - DebayerParams::CcmLookupTable redCcm_; - DebayerParams::CcmLookupTable greenCcm_; - DebayerParams::CcmLookupTable blueCcm_; - DebayerParams::LookupTable gammaLut_; debayerFn debayer0_; debayerFn debayer1_; debayerFn debayer2_; debayerFn debayer3_; Rectangle window_; - DebayerInputConfig inputConfig_; - DebayerOutputConfig outputConfig_; std::unique_ptr stats_; std::vector lineBuffers_[kMaxLineBuffers]; unsigned int lineBufferLength_; @@ -161,8 +124,6 @@ private: unsigned int lineBufferIndex_; unsigned int xShift_; /* Offset of 0/1 applied to window_.x */ bool enableInputMemcpy_; - bool swapRedBlueGains_; - Benchmark bench_; }; } /* namespace libcamera */