From patchwork Thu Oct 15 22:05:31 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: 28466 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 BD17FBDCB6 for ; Thu, 15 Oct 2026 22:05:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 76ABD68E1A; Fri, 16 Oct 2026 00:05:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="h4yLabBK"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 726A5689BE for ; Fri, 16 Oct 2026 00:05:34 +0200 (CEST) Received: from pb-laptop.local (2A0011100230E2D19A2791CD962A4BEB.mobile.pool.telekom.hu [IPv6:2a00:1110:230:e2d1:9a27:91cd:962a:4beb]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DE53ABC; Fri, 16 Oct 2026 00:03:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1792101811; bh=uD5mSj6q/NnMjNe9paVRJjuVzUDwgq0PjpJXSFFUjcc=; h=From:To:Cc:Subject:Date:From; b=h4yLabBK3j/oDqWYeCQNZE/OfX/usYPZoKaWBvjSKjHtpuq7SPFnwDhNPqiU/a0Ns bqGgH35blOTErvuEyJouF/vqVA3yZqBxH8YktHBTNQO5XecRjAXrkZ4JuXxpBoTNE9 M8ypKdCRRN2w78ZLleDN/xnv3anNfykyVC8LQ6o4= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH v1] apps: cam: sdl_texture: Support YUV420, YVU420 Date: Fri, 16 Oct 2026 00:05:31 +0200 Message-ID: <20261015220531.322009-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 two libcamera formats. Signed-off-by: Barnabás Pőcze --- Inspired and tested only with https://patchwork.libcamera.org/patch/28458/ --- src/apps/cam/sdl_sink.cpp | 4 ++++ src/apps/cam/sdl_texture_yuv.cpp | 19 +++++++++++++++++++ src/apps/cam/sdl_texture_yuv.h | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/src/apps/cam/sdl_sink.cpp b/src/apps/cam/sdl_sink.cpp index d16e4dc14c..8184933eaf 100644 --- a/src/apps/cam/sdl_sink.cpp +++ b/src/apps/cam/sdl_sink.cpp @@ -116,6 +116,10 @@ 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 if (cfg.pixelFormat == libcamera::formats::YVU420) + texture_ = std::make_unique(rect_, SDL_PIXELFORMAT_YV12, 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..6b166f01b9 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 || pixelFormat == SDL_PIXELFORMAT_YV12); +} + +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; +};