From patchwork Mon Apr 28 08:44:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 23270 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 7542DC331E for ; Mon, 28 Apr 2025 08:44:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8480768AD7; Mon, 28 Apr 2025 10:44:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="k3I0zg4T"; 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 CDC7168AD0 for ; Mon, 28 Apr 2025 10:44:22 +0200 (CEST) Received: from pb-laptop.local (185.221.141.190.nat.pool.zt.hu [185.221.141.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EC2ED7E6; Mon, 28 Apr 2025 10:44:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745829858; bh=oNFT4aL+GvpAwoE50WzPZTbNAO0+59J28ELcz8A4KrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k3I0zg4Tsf56mUz//8YRdXFq1htgeidYPqoP/ou1PROmB6IwO/Bw5rRPez5kg+gNm xKknTS95+AyGovT+rzq+20SOfj0fJStOJh8zxVbM81mJmYy5g1/CVz8HBY62094uiv 9Tv5cHHULBiXkbQW4PW6LL7iRwwsGPk55Z+8RWoA= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Laurent Pinchart Subject: [PATCH v3 3/4] apps: cam: sdl_texture: Add `SDLTexture1Plane` Date: Mon, 28 Apr 2025 10:44:17 +0200 Message-ID: <20250428084418.1251085-4-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250428084418.1251085-1-barnabas.pocze@ideasonboard.com> References: <20250428084418.1251085-1-barnabas.pocze@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" `SDLTextureYUYV` uses `SDL_PIXELFORMAT_YUY2`, which is a single plane format. To support other single plane formats, replace `SDLTextureYUYV` with `SDLTexture1Plane` that can be instantiated with an arbitrary SDL pixel format and that uses `SDL_UpdateTexture()` to update the texture using exactly a single plane. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/apps/cam/meson.build | 1 + src/apps/cam/sdl_sink.cpp | 3 ++- src/apps/cam/sdl_texture_1plane.cpp | 17 +++++++++++++++++ src/apps/cam/sdl_texture_1plane.h | 18 ++++++++++++++++++ src/apps/cam/sdl_texture_yuv.cpp | 10 ---------- src/apps/cam/sdl_texture_yuv.h | 7 ------- 6 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 src/apps/cam/sdl_texture_1plane.cpp create mode 100644 src/apps/cam/sdl_texture_1plane.h diff --git a/src/apps/cam/meson.build b/src/apps/cam/meson.build index c70ca3cd2..2833c86e9 100644 --- a/src/apps/cam/meson.build +++ b/src/apps/cam/meson.build @@ -34,6 +34,7 @@ if libsdl2.found() cam_sources += files([ 'sdl_sink.cpp', 'sdl_texture.cpp', + 'sdl_texture_1plane.cpp', 'sdl_texture_yuv.cpp', ]) diff --git a/src/apps/cam/sdl_sink.cpp b/src/apps/cam/sdl_sink.cpp index 8355dd5ed..b295675dc 100644 --- a/src/apps/cam/sdl_sink.cpp +++ b/src/apps/cam/sdl_sink.cpp @@ -22,6 +22,7 @@ #include "../common/event_loop.h" #include "../common/image.h" +#include "sdl_texture_1plane.h" #ifdef HAVE_LIBJPEG #include "sdl_texture_mjpg.h" #endif @@ -74,7 +75,7 @@ int SDLSink::configure(const libcamera::CameraConfiguration &config) break; #endif case libcamera::formats::YUYV: - texture_ = std::make_unique(rect_, cfg.stride); + texture_ = std::make_unique(rect_, SDL_PIXELFORMAT_YUY2, cfg.stride); break; default: std::cerr << "Unsupported pixel format " diff --git a/src/apps/cam/sdl_texture_1plane.cpp b/src/apps/cam/sdl_texture_1plane.cpp new file mode 100644 index 000000000..b97015bc1 --- /dev/null +++ b/src/apps/cam/sdl_texture_1plane.cpp @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2025, Ideas on Board Oy + * + * SDL single plane textures + */ + +#include "sdl_texture_1plane.h" + +#include + +void SDLTexture1Plane::update(libcamera::Span> data) +{ + assert(data.size() == 1); + assert(data[0].size_bytes() == std::size_t(rect_.h) * std::size_t(stride_)); + SDL_UpdateTexture(ptr_, nullptr, data[0].data(), stride_); +} diff --git a/src/apps/cam/sdl_texture_1plane.h b/src/apps/cam/sdl_texture_1plane.h new file mode 100644 index 000000000..795e1fa4f --- /dev/null +++ b/src/apps/cam/sdl_texture_1plane.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2025, Ideas on Board Oy + * + * SDL single plane textures + */ + +#pragma once + +#include "sdl_texture.h" + +class SDLTexture1Plane final : public SDLTexture +{ +public: + using SDLTexture::SDLTexture; + + void update(libcamera::Span> data) override; +}; diff --git a/src/apps/cam/sdl_texture_yuv.cpp b/src/apps/cam/sdl_texture_yuv.cpp index 7e2ce3f49..bed297d28 100644 --- a/src/apps/cam/sdl_texture_yuv.cpp +++ b/src/apps/cam/sdl_texture_yuv.cpp @@ -21,13 +21,3 @@ void SDLTextureNV12::update(libcamera::Span data[1].data(), stride_); } #endif - -SDLTextureYUYV::SDLTextureYUYV(const SDL_Rect &rect, unsigned int stride) - : SDLTexture(rect, SDL_PIXELFORMAT_YUY2, stride) -{ -} - -void SDLTextureYUYV::update(libcamera::Span> data) -{ - SDL_UpdateTexture(ptr_, nullptr, data[0].data(), stride_); -} diff --git a/src/apps/cam/sdl_texture_yuv.h b/src/apps/cam/sdl_texture_yuv.h index db877f503..c271f901b 100644 --- a/src/apps/cam/sdl_texture_yuv.h +++ b/src/apps/cam/sdl_texture_yuv.h @@ -17,10 +17,3 @@ public: void update(libcamera::Span> data) override; }; #endif - -class SDLTextureYUYV : public SDLTexture -{ -public: - SDLTextureYUYV(const SDL_Rect &rect, unsigned int stride); - void update(libcamera::Span> data) override; -};