From patchwork Mon Oct 19 12:09:39 2026 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: 28505 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 84F40C3261 for ; Mon, 19 Oct 2026 12:09:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7B81B68E8D; Mon, 19 Oct 2026 14:09:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="kTqd9t+4"; 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 2D2C368E44 for ; Mon, 19 Oct 2026 14:09:43 +0200 (CEST) Received: from pb-laptop.local (185.221.141.235.nat.pool.zt.hu [185.221.141.235]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EAEE4593; Mon, 19 Oct 2026 14:07:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1792411657; bh=bzpCCdfD8jS3OlDWyhDaEVBe2oF7SEOZkwugr858pGE=; h=From:To:Cc:Subject:Date:From; b=kTqd9t+4z5RZk6CJj8o5dSx9PAxFuPlq4Jge6CBIkG/EAMsCjnIrTYriSEfXEaVyZ lAmPFfj1pRPnmWHW9ZjgvlQY8o0AqLhv9eKzZBFo2Zk/bLvanIofhwANfLWiTVOSGG VmKSdrZ4jFNuYlt9yqbCzx+VUG17HxLpatNLyUIk= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Robert Mader , Kieran Bingham Subject: [PATCH v2] apps: cam: sdl_texture: Support YUV420 Date: Mon, 19 Oct 2026 14:09:39 +0200 Message-ID: <20261019120939.111254-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.56.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" Add a new `SDLTexture` derived class that uses `SDL_UpdateYUVTexture()`, and implement the handling of the aforementioned libcamera format. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- tested with: * https://patchwork.libcamera.org/patch/28458/ * rkisp1 * vivid changes in v2: * drop YVU420 because `SDL_UpdateYUVTexture()` always wants the U, V planes in that order, so some kind of swapping would be needed v1: https://patchwork.libcamera.org/patch/28466/ --- src/apps/cam/sdl_sink.cpp | 2 ++ src/apps/cam/sdl_texture_yuv.cpp | 19 +++++++++++++++++++ src/apps/cam/sdl_texture_yuv.h | 7 +++++++ 3 files changed, 28 insertions(+) -- 2.56.0 diff --git a/src/apps/cam/sdl_sink.cpp b/src/apps/cam/sdl_sink.cpp index d16e4dc14c..2d061ad823 100644 --- a/src/apps/cam/sdl_sink.cpp +++ b/src/apps/cam/sdl_sink.cpp @@ -116,6 +116,8 @@ int SDLSink::configure(const libcamera::CameraConfiguration &config) else if (cfg.pixelFormat == libcamera::formats::NV21) texture_ = std::make_unique(rect_, SDL_PIXELFORMAT_NV21, cfg.stride); #endif + else if (cfg.pixelFormat == libcamera::formats::YUV420) + texture_ = std::make_unique(rect_, SDL_PIXELFORMAT_IYUV, cfg.stride); else { std::cerr << "Unsupported pixel format " << cfg.pixelFormat << std::endl; return -EINVAL; diff --git a/src/apps/cam/sdl_texture_yuv.cpp b/src/apps/cam/sdl_texture_yuv.cpp index 42c9d2ddfb..8bfaab5d6a 100644 --- a/src/apps/cam/sdl_texture_yuv.cpp +++ b/src/apps/cam/sdl_texture_yuv.cpp @@ -28,3 +28,22 @@ void SDLTextureNV::update(std::span> data) data[1].data(), stride_); } #endif + +SDLTextureYUV::SDLTextureYUV(const SDL_Rect &rect, uint32_t pixelFormat, unsigned int stride) + : SDLTexture(rect, pixelFormat, stride) +{ + assert(pixelFormat == SDL_PIXELFORMAT_IYUV); +} + +void SDLTextureYUV::update(std::span> data) +{ + assert(data.size() == 3); + assert(data[0].size_bytes() == std::size_t(rect_.h) * std::size_t(stride_)); + assert(data[1].size_bytes() == std::size_t(rect_.h) * std::size_t(stride_) / 4); + assert(data[2].size_bytes() == std::size_t(rect_.h) * std::size_t(stride_) / 4); + + SDL_UpdateYUVTexture(ptr_, nullptr, + data[0].data(), stride_, + data[1].data(), stride_ / 2, + data[2].data(), stride_ / 2); +} diff --git a/src/apps/cam/sdl_texture_yuv.h b/src/apps/cam/sdl_texture_yuv.h index 5a5ac011f7..531e857e0c 100644 --- a/src/apps/cam/sdl_texture_yuv.h +++ b/src/apps/cam/sdl_texture_yuv.h @@ -17,3 +17,10 @@ public: void update(std::span> data) override; }; #endif + +class SDLTextureYUV : public SDLTexture +{ +public: + SDLTextureYUV(const SDL_Rect &rect, uint32_t pixelFormat, unsigned int stride); + void update(std::span> data) override; +};