From patchwork Sun Nov 29 15:24:14 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alain_Cousini=C3=A9?= X-Patchwork-Id: 29102 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 71317C3355 for ; Sun, 29 Nov 2026 15:24:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1B71F6AA47; Sun, 29 Nov 2026 16:24:47 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=laposte.net header.i=@laposte.net header.b="mW2IgxsZ"; dkim-atps=neutral Received: from smtp-outgoing-1601.laposte.net (smtp-outgoing-1601.laposte.net [160.92.124.96]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D5E976AA37 for ; Sun, 29 Nov 2026 16:24:43 +0100 (CET) X-mail-filterd: {"version":"1.9.7", "queueID":"4jcrYQ0cLpz10MQ4", "contextId": "06d2e918-b7d5-46be-b35a-304f37973738"} Received: from outgoing-mail.laposte.net (localhost.localdomain [127.0.0.1]) by mlpnf0120.laposte.net (SMTP Server) with ESMTP id 4jcrYQ0cLpz10MQ4; Sun, 29 Nov 2026 16:24:42 +0100 (CET) X-mail-filterd: {"version":"1.9.7", "queueID":"4jcrYP5fFmz10MQQ", "contextId": "255c20e3-f7cc-46db-a4ae-ce74ae6e5a8d"} X-lpn-mailing: LEGIT X-lpn-spamrating: 36 X-lpn-spamlevel: not-spam Received: from debian.home (m-dj.hd.free.fr [82.67.82.126]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mlpnf0120.laposte.net (SMTP Server) with ESMTPSA id 4jcrYP5fFmz10MQQ; Sun, 29 Nov 2026 16:24:41 +0100 (CET) From: =?utf-8?q?Alain_Cousini=C3=A9?= To: libcamera-devel@lists.libcamera.org, Milan Zamazal Cc: Hans de Goede , Bryan O'Donoghue , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= , Laurent Pinchart , Jai Luthra , =?utf-8?q?Alain_Cousini=C3=A9?= Subject: [PATCH v8 4/6] libcamera: software_isp: Add support for monochrome formats - GPU Date: Sun, 29 Nov 2026 16:24:14 +0100 Message-ID: <20261129152416.174279-5-alain.cousinie@laposte.net> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261129152416.174279-1-alain.cousinie@laposte.net> References: <20261129152416.174279-1-alain.cousinie@laposte.net> MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=laposte.net; s=lpn-wlmd; t=1795965883; bh=dQm4e6X5ZLEqdIk2af92k1NerzH9zOL2CSlJ8jzSmlk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding; b=mW2IgxsZeaSFeLzC6g5xUkHw0wJrT/VVOz7PnlLrAjqF1b1WL8xJ3QobqKeH89gy3cpGEmzh0l6zxm6M2+Nup68QmRiOiCbxVphhh6mvDtEjOsWTYCCKtTQrSYrzd+f4ULg4qiDRg9cuVJEzF2cN+ogxExo3hqxu9smKrtE7mjVU6qUbL6PbSbyoyUCahqVcJso6EVjZ2K8gtRvVoxt07L2AeVXyigqWHOwO+WIB2P1a7rtRM2LLR/R6SSP1AtSs2fdvAkbi0XkO34SEm+KrpMf1R6Mg2Vs3+x0mRvvbPjpwr6RLXsYOtqetnkBLtQfuRWyZMhDaIUlHhq4o5bHsyw==; 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 Select mono.frag for R8, R10, R12 and R16 in DebayerEGL. Unpacked 10, 12 and 16-bit data is sent as a two-channel texture, 8-bit and packed data as a single-channel texture. For packed formats, TEX_WIDTH is the stride in bytes and the shader stride is width_, as for the Bayer shaders. Unlike the CPU, which only uses the 8 most significant bits, the GPU uses the full depth of the pixel. As for the CPU, the pattern size follows the Bayer formats and the statistics. firstRed_ is meaningless for monochrome and set to 0. The CCM is now only sent to the shader if it has a "ccm" input: Bayer shaders do, mono.frag does not. sizes() keeps no border for monochrome. Signed-off-by: Alain CousiniƩ --- src/libcamera/software_isp/debayer_egl.cpp | 88 ++++++++++++++++++++-- 1 file changed, 81 insertions(+), 7 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 33933b11d..fcbc66cd8 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -61,6 +61,21 @@ int DebayerEGL::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf formats::XBGR8888, formats::ABGR8888 }; + if (bayerFormat.order == BayerFormat::Order::MONO) { + if (bayerFormat.packing == BayerFormat::Packing::None) { + config.bpp = (bayerFormat.bitDepth + 7) & ~7; + config.patternSize.width = 2; + config.patternSize.height = 2; + } else if (bayerFormat.packing == BayerFormat::Packing::CSI2) { + config.bpp = bayerFormat.bitDepth; + config.patternSize.width = (bayerFormat.bitDepth == 12) ? 2 : 4; + config.patternSize.height = 2; + } + + config.outputFormats = outputFormats; + return 0; + } + if ((bayerFormat.bitDepth == 8 || bayerFormat.bitDepth == 10) && bayerFormat.packing == BayerFormat::Packing::None && isStandardBayerOrder(bayerFormat.order)) { @@ -172,6 +187,13 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm shaderStridePixels_ = inputConfig_.stride; switch (inputFormat) { + case libcamera::formats::R8: + case libcamera::formats::R10: + case libcamera::formats::R12: + case libcamera::formats::R16: + firstRed_x_ = 0.0; + firstRed_y_ = 0.0; + break; case libcamera::formats::SBGGR8: case libcamera::formats::SBGGR10_CSI2P: case libcamera::formats::SBGGR12_CSI2P: @@ -201,8 +223,56 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm return -EINVAL; }; + BayerFormat bayerFormat = BayerFormat::fromPixelFormat(inputFormat); + /* Shader selection */ switch (inputFormat) { + case libcamera::formats::R8: + fragmentShaderData = mono_frag; + vertexShaderData = identity_vert; + egl_.pushEnv(shaderEnv, "#define INV_MAX_VAL (1.0 / 255.0)"); + egl_.pushEnv(shaderEnv, "#define RAW8"); + break; + case libcamera::formats::R10: + fragmentShaderData = mono_frag; + vertexShaderData = identity_vert; + egl_.pushEnv(shaderEnv, "#define INV_MAX_VAL (1.0 / 1023.0)"); + if (bayerFormat.packing == BayerFormat::Packing::None) { + egl_.pushEnv(shaderEnv, "#define RAW10"); + glFormat_ = GL_RG; + bytesPerPixel_ = 2; + } else { + egl_.pushEnv(shaderEnv, "#define RAW10P"); + egl_.pushEnv(shaderEnv, "#define BLOCK_PIXELS 4.0"); + egl_.pushEnv(shaderEnv, "#define BLOCK_BYTES 5.0"); + egl_.pushEnv(shaderEnv, (std::string("#define TEX_WIDTH ") + std::to_string(inputConfig_.stride) + ".0").c_str()); + shaderStridePixels_ = width_; + } + break; + case libcamera::formats::R12: + fragmentShaderData = mono_frag; + vertexShaderData = identity_vert; + egl_.pushEnv(shaderEnv, "#define INV_MAX_VAL (1.0 / 4095.0)"); + if (bayerFormat.packing == BayerFormat::Packing::None) { + egl_.pushEnv(shaderEnv, "#define RAW12"); + glFormat_ = GL_RG; + bytesPerPixel_ = 2; + } else { + egl_.pushEnv(shaderEnv, "#define RAW12P"); + egl_.pushEnv(shaderEnv, "#define BLOCK_PIXELS 2.0"); + egl_.pushEnv(shaderEnv, "#define BLOCK_BYTES 3.0"); + egl_.pushEnv(shaderEnv, (std::string("#define TEX_WIDTH ") + std::to_string(inputConfig_.stride) + ".0").c_str()); + shaderStridePixels_ = width_; + } + break; + case libcamera::formats::R16: + fragmentShaderData = mono_frag; + vertexShaderData = identity_vert; + egl_.pushEnv(shaderEnv, "#define INV_MAX_VAL (1.0 / 65535.0)"); + egl_.pushEnv(shaderEnv, "#define RAW16"); + glFormat_ = GL_RG; + bytesPerPixel_ = 2; + break; case libcamera::formats::SBGGR8: case libcamera::formats::SGBRG8: case libcamera::formats::SGRBG8: @@ -474,9 +544,11 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara << " textureUniformProjMatrix_ " << textureUniformProjMatrix_; /* 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; + if (ccmUniformDataIn_ != -1) { + Matrix ccm = params.combinedMatrix.transpose(); + glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm.data().data()); + LOG(Debayer, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix; + } if (lscEnabled_ && params.lscLutVersion != lscLutVersion_) { egl_.updateTexture2D(*eglImageLscLookup_, params.lscLut.data()); @@ -723,12 +795,11 @@ void DebayerEGL::stop() SizeRange DebayerEGL::sizes(PixelFormat inputFormat, const Size &inputSize) { Size patternSize = this->patternSize(inputFormat); - unsigned int borderHeight = patternSize.height; - if (patternSize.isNull()) return {}; /* No need for top/bottom border with a pattern height of 2 */ + unsigned int borderHeight = patternSize.height; if (patternSize.height == 2) borderHeight = 0; @@ -743,9 +814,12 @@ SizeRange DebayerEGL::sizes(PixelFormat inputFormat, const Size &inputSize) return {}; } + BayerFormat bayerFormat = BayerFormat::fromPixelFormat(inputFormat); + bool localIsMono = (bayerFormat.order == BayerFormat::Order::MONO); + return SizeRange(Size(patternSize.width, patternSize.height), - Size((inputSize.width - 2 * patternSize.width) & ~(patternSize.width - 1), - (inputSize.height - 2 * borderHeight) & ~(patternSize.height - 1)), + Size((inputSize.width - (localIsMono ? 0 : 2 * patternSize.width)) & ~(patternSize.width - 1), + (inputSize.height - (localIsMono ? 0 : 2 * borderHeight)) & ~(patternSize.height - 1)), patternSize.width, patternSize.height); }