From patchwork Tue May 6 10:58:27 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: 23339 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 AC9A1C3200 for ; Tue, 6 May 2025 10:58:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1084768B38; Tue, 6 May 2025 12:58:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ccu1aeD6"; 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 A8C7668B25 for ; Tue, 6 May 2025 12:58:32 +0200 (CEST) Received: from pb-laptop.local (185.221.141.56.nat.pool.zt.hu [185.221.141.56]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0ECA2E45; Tue, 6 May 2025 12:58:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1746529102; bh=dj5adR4qJg3xcs1fNELkByO/Gzvoxy4uVDa92esQpeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ccu1aeD65izj3oHCWYk+++AteaoAFVbIPEE7FTKpC4qePKBRwxQ31yMQyp8xqoRVT qaflfqVSf61sUyeTssVfR3KTY7GqW7i6fPdoX1QCIW0nd6K/U6ps+fzDv+lntOLe0m IbYSlXYu7giOl+2mxgInSbrgqQD1aJjxxve6d4mo= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Laurent Pinchart Subject: [PATCH v5 4/4] apps: cam: sdl_sink: Support more single-plane formats Date: Tue, 6 May 2025 12:58:27 +0200 Message-ID: <20250506105827.506569-5-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250506105827.506569-1-barnabas.pocze@ideasonboard.com> References: <20250506105827.506569-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" With the newly introduced `SDLTexture1Plane` it is easy to handle any single-plane format that has an SDL equivalent. So use it for more YUV and RGB formats. The mapping of RGB formats is not entirely straightforward because `SDL_PIXELFORMAT_ZZZ...888...` defines a format where the order of the components is endian dependent, while libcamera's `ZZZ...888...` formats are derived from the matching DRM formats, and the RGB formats in question are defined to be little-endian there. So the endian-independent `SDL_PIXELFORMAT_{ZZZ24,ZZZZ32}` are used. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/apps/cam/sdl_sink.cpp | 60 +++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/src/apps/cam/sdl_sink.cpp b/src/apps/cam/sdl_sink.cpp index b295675dc..30cfdf0af 100644 --- a/src/apps/cam/sdl_sink.cpp +++ b/src/apps/cam/sdl_sink.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,46 @@ using namespace libcamera; using namespace std::chrono_literals; +namespace { + +std::optional singlePlaneFormatToSDL(const libcamera::PixelFormat &f) +{ + switch (f) { + case libcamera::formats::RGB888: + return SDL_PIXELFORMAT_BGR24; + case libcamera::formats::BGR888: + return SDL_PIXELFORMAT_RGB24; + case libcamera::formats::RGBA8888: + return SDL_PIXELFORMAT_ABGR32; + case libcamera::formats::ARGB8888: + return SDL_PIXELFORMAT_BGRA32; + case libcamera::formats::BGRA8888: + return SDL_PIXELFORMAT_ARGB32; + case libcamera::formats::ABGR8888: + return SDL_PIXELFORMAT_RGBA32; +#if SDL_VERSION_ATLEAST(2, 29, 1) + case libcamera::formats::RGBX8888: + return SDL_PIXELFORMAT_XBGR32; + case libcamera::formats::XRGB8888: + return SDL_PIXELFORMAT_BGRX32; + case libcamera::formats::BGRX8888: + return SDL_PIXELFORMAT_XRGB32; + case libcamera::formats::XBGR8888: + return SDL_PIXELFORMAT_RGBX32; +#endif + case libcamera::formats::YUYV: + return SDL_PIXELFORMAT_YUY2; + case libcamera::formats::UYVY: + return SDL_PIXELFORMAT_UYVY; + case libcamera::formats::YVYU: + return SDL_PIXELFORMAT_YVYU; + } + + return {}; +} + +} /* namespace */ + SDLSink::SDLSink() : window_(nullptr), renderer_(nullptr), rect_({}), init_(false) @@ -63,25 +104,20 @@ int SDLSink::configure(const libcamera::CameraConfiguration &config) rect_.w = cfg.size.width; rect_.h = cfg.size.height; - switch (cfg.pixelFormat) { + if (auto sdlFormat = singlePlaneFormatToSDL(cfg.pixelFormat)) + texture_ = std::make_unique(rect_, *sdlFormat, cfg.stride); #ifdef HAVE_LIBJPEG - case libcamera::formats::MJPEG: + else if (cfg.pixelFormat == libcamera::formats::MJPEG) texture_ = std::make_unique(rect_); - break; #endif #if SDL_VERSION_ATLEAST(2, 0, 16) - case libcamera::formats::NV12: + else if (cfg.pixelFormat == libcamera::formats::NV12) texture_ = std::make_unique(rect_, cfg.stride); - break; #endif - case libcamera::formats::YUYV: - texture_ = std::make_unique(rect_, SDL_PIXELFORMAT_YUY2, cfg.stride); - break; - default: - std::cerr << "Unsupported pixel format " - << cfg.pixelFormat.toString() << std::endl; + else { + std::cerr << "Unsupported pixel format " << cfg.pixelFormat << std::endl; return -EINVAL; - }; + } return 0; }