From patchwork Thu Oct 23 14:51:39 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: 24763 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 11248C3259 for ; Thu, 23 Oct 2025 14:51:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A4CE860865; Thu, 23 Oct 2025 16:51:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="u9OT4BQa"; 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 DF2E36080F for ; Thu, 23 Oct 2025 16:51:42 +0200 (CEST) Received: from pb-laptop.local (185.221.141.231.nat.pool.zt.hu [185.221.141.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EBAFC591 for ; Thu, 23 Oct 2025 16:49:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761230998; bh=b9n1HKHgfMtNk3fwihAZ+MZFd4u7OzRyUZuq0+/h50s=; h=From:To:Subject:Date:From; b=u9OT4BQa9bugQegn+9rp4affIORSUXPFOlx1akBuaf7EOXQQoBPmdcIwsgaxxcQ9d MjtLdRx6oDuzPj2IiUBRHIYMa50A/e9HU5LQYlfwRtbT1C06roS0dZLJIqs+rMDIID gH/sC1qXwZRUEPtVVqtE6CWKc6fJKDzK+WOzqNd4= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v1] apps: cam: sdl_texture: Support NV21 Date: Thu, 23 Oct 2025 16:51:39 +0200 Message-ID: <20251023145139.1085153-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.51.1.dirty 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" SDL also supports NV21 with the same `SDL_UpdateNVTexture()`, so add support for it. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- src/apps/cam/sdl_sink.cpp | 4 +++- src/apps/cam/sdl_texture_yuv.cpp | 13 +++++++++---- src/apps/cam/sdl_texture_yuv.h | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/apps/cam/sdl_sink.cpp b/src/apps/cam/sdl_sink.cpp index 30cfdf0af..17a9e04b5 100644 --- a/src/apps/cam/sdl_sink.cpp +++ b/src/apps/cam/sdl_sink.cpp @@ -112,7 +112,9 @@ int SDLSink::configure(const libcamera::CameraConfiguration &config) #endif #if SDL_VERSION_ATLEAST(2, 0, 16) else if (cfg.pixelFormat == libcamera::formats::NV12) - texture_ = std::make_unique(rect_, cfg.stride); + texture_ = std::make_unique(rect_, SDL_PIXELFORMAT_NV12, cfg.stride); + else if (cfg.pixelFormat == libcamera::formats::NV21) + texture_ = std::make_unique(rect_, SDL_PIXELFORMAT_NV21, cfg.stride); #endif else { std::cerr << "Unsupported pixel format " << cfg.pixelFormat << std::endl; diff --git a/src/apps/cam/sdl_texture_yuv.cpp b/src/apps/cam/sdl_texture_yuv.cpp index bed297d28..40d1a3ae9 100644 --- a/src/apps/cam/sdl_texture_yuv.cpp +++ b/src/apps/cam/sdl_texture_yuv.cpp @@ -7,16 +7,21 @@ #include "sdl_texture_yuv.h" -using namespace libcamera; +#include #if SDL_VERSION_ATLEAST(2, 0, 16) -SDLTextureNV12::SDLTextureNV12(const SDL_Rect &rect, unsigned int stride) - : SDLTexture(rect, SDL_PIXELFORMAT_NV12, stride) +SDLTextureNV::SDLTextureNV(const SDL_Rect &rect, uint32_t pixelFormat, unsigned int stride) + : SDLTexture(rect, pixelFormat, stride) { + assert(pixelFormat == SDL_PIXELFORMAT_NV12 || pixelFormat == SDL_PIXELFORMAT_NV21); } -void SDLTextureNV12::update(libcamera::Span> data) +void SDLTextureNV::update(libcamera::Span> data) { + assert(data.size() == 2); + 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_) / 2); + SDL_UpdateNVTexture(ptr_, nullptr, data[0].data(), stride_, data[1].data(), stride_); } diff --git a/src/apps/cam/sdl_texture_yuv.h b/src/apps/cam/sdl_texture_yuv.h index c271f901b..8e73506d1 100644 --- a/src/apps/cam/sdl_texture_yuv.h +++ b/src/apps/cam/sdl_texture_yuv.h @@ -10,10 +10,10 @@ #include "sdl_texture.h" #if SDL_VERSION_ATLEAST(2, 0, 16) -class SDLTextureNV12 : public SDLTexture +class SDLTextureNV final : public SDLTexture { public: - SDLTextureNV12(const SDL_Rect &rect, unsigned int stride); + SDLTextureNV(const SDL_Rect &rect, uint32_t pixelFormat, unsigned int stride); void update(libcamera::Span> data) override; }; #endif