From patchwork Wed Apr 30 07:58:46 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: 23302 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 87DC5BE08B for ; Wed, 30 Apr 2025 07:58:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 183E868AD9; Wed, 30 Apr 2025 09:58:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cB6CvJut"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7FA7F68AD0 for ; Wed, 30 Apr 2025 09:58:53 +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 089A9836; Wed, 30 Apr 2025 09:58:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745999927; bh=RCWG7i9GPEl2qmDGcql7Z1mEHfnplbrtCm86A44Nv9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cB6CvJutOZ/Lp5Uxg8KIj+asWfUlsDDzjmAjFrRrdvfG0ok+W8FQiyJHjEd4kjuaB 2xlGF9fQClqEpHK0qxLBQGVGKy4NAAuk4NZLjaweD6z+EyDA1isjq2syxOFT9aOh+F a8GZ+jmmt9He6fIu2fnenOJenB4llUSKEczvcUVE= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Laurent Pinchart , Kieran Bingham Subject: [PATCH v4 1/4] apps: cam: sdl_texture: Take list of buffers in span Date: Wed, 30 Apr 2025 09:58:46 +0200 Message-ID: <20250430075849.2790398-2-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250430075849.2790398-1-barnabas.pocze@ideasonboard.com> References: <20250430075849.2790398-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" A non-owning span is sufficient, so use that instead of a vector. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/apps/cam/sdl_texture.h | 4 ++-- src/apps/cam/sdl_texture_mjpg.cpp | 2 +- src/apps/cam/sdl_texture_mjpg.h | 2 +- src/apps/cam/sdl_texture_yuv.cpp | 4 ++-- src/apps/cam/sdl_texture_yuv.h | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/apps/cam/sdl_texture.h b/src/apps/cam/sdl_texture.h index 990f83b6e..39e1c7b38 100644 --- a/src/apps/cam/sdl_texture.h +++ b/src/apps/cam/sdl_texture.h @@ -7,7 +7,7 @@ #pragma once -#include +#include #include @@ -19,7 +19,7 @@ public: SDLTexture(const SDL_Rect &rect, uint32_t pixelFormat, const int stride); virtual ~SDLTexture(); int create(SDL_Renderer *renderer); - virtual void update(const std::vector> &data) = 0; + virtual void update(libcamera::Span> data) = 0; SDL_Texture *get() const { return ptr_; } protected: diff --git a/src/apps/cam/sdl_texture_mjpg.cpp b/src/apps/cam/sdl_texture_mjpg.cpp index cace18fc6..ca49a1142 100644 --- a/src/apps/cam/sdl_texture_mjpg.cpp +++ b/src/apps/cam/sdl_texture_mjpg.cpp @@ -76,7 +76,7 @@ int SDLTextureMJPG::decompress(Span data) return 0; } -void SDLTextureMJPG::update(const std::vector> &data) +void SDLTextureMJPG::update(libcamera::Span> data) { decompress(data[0]); SDL_UpdateTexture(ptr_, nullptr, rgb_.get(), stride_); diff --git a/src/apps/cam/sdl_texture_mjpg.h b/src/apps/cam/sdl_texture_mjpg.h index 37bed5f0e..be8a55fe7 100644 --- a/src/apps/cam/sdl_texture_mjpg.h +++ b/src/apps/cam/sdl_texture_mjpg.h @@ -14,7 +14,7 @@ class SDLTextureMJPG : public SDLTexture public: SDLTextureMJPG(const SDL_Rect &rect); - void update(const std::vector> &data) override; + void update(libcamera::Span> data) override; private: int decompress(libcamera::Span data); diff --git a/src/apps/cam/sdl_texture_yuv.cpp b/src/apps/cam/sdl_texture_yuv.cpp index 480d7a379..80a5ec05d 100644 --- a/src/apps/cam/sdl_texture_yuv.cpp +++ b/src/apps/cam/sdl_texture_yuv.cpp @@ -15,7 +15,7 @@ SDLTextureNV12::SDLTextureNV12(const SDL_Rect &rect, unsigned int stride) { } -void SDLTextureNV12::update(const std::vector> &data) +void SDLTextureNV12::update(libcamera::Span> data) { SDL_UpdateNVTexture(ptr_, &rect_, data[0].data(), stride_, data[1].data(), stride_); @@ -27,7 +27,7 @@ SDLTextureYUYV::SDLTextureYUYV(const SDL_Rect &rect, unsigned int stride) { } -void SDLTextureYUYV::update(const std::vector> &data) +void SDLTextureYUYV::update(libcamera::Span> data) { SDL_UpdateTexture(ptr_, &rect_, data[0].data(), stride_); } diff --git a/src/apps/cam/sdl_texture_yuv.h b/src/apps/cam/sdl_texture_yuv.h index 29c756e77..db877f503 100644 --- a/src/apps/cam/sdl_texture_yuv.h +++ b/src/apps/cam/sdl_texture_yuv.h @@ -14,7 +14,7 @@ class SDLTextureNV12 : public SDLTexture { public: SDLTextureNV12(const SDL_Rect &rect, unsigned int stride); - void update(const std::vector> &data) override; + void update(libcamera::Span> data) override; }; #endif @@ -22,5 +22,5 @@ class SDLTextureYUYV : public SDLTexture { public: SDLTextureYUYV(const SDL_Rect &rect, unsigned int stride); - void update(const std::vector> &data) override; + void update(libcamera::Span> data) override; }; From patchwork Wed Apr 30 07:58:47 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: 23303 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 B4105BE08B for ; Wed, 30 Apr 2025 07:59:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0072D68AD5; Wed, 30 Apr 2025 09:58:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JUB/NyGr"; 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 AF547617DE for ; Wed, 30 Apr 2025 09:58:53 +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 5AF4F1196; Wed, 30 Apr 2025 09:58:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745999927; bh=7bTcM2mriVp85165ZMVr91wnqeD7M//VtRJQROS3rok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JUB/NyGrPPkBMltYqXNvP9OzUsGAA3MdEKlqHTenUGemkXkFegfzPa+Eg3jGmXYQw zgqYy8ORx8sBLOUBGwh5OLAHgVbu2im3EFCtpb30BJx2radHfJcEiicA2FoPVHmj6B d+q/bupZMw+HuT5tKuCmCf/2svbylim/NSnbKDQo= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Laurent Pinchart Subject: [PATCH v4 2/4] apps: cam: sdl_texture: Drop `&rect_` from `SDL_Update{NV, }Texture()` call Date: Wed, 30 Apr 2025 09:58:47 +0200 Message-ID: <20250430075849.2790398-3-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250430075849.2790398-1-barnabas.pocze@ideasonboard.com> References: <20250430075849.2790398-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" If the entire texture is to be updated, there is no need to specify the target area explicitly. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/apps/cam/sdl_texture_yuv.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/cam/sdl_texture_yuv.cpp b/src/apps/cam/sdl_texture_yuv.cpp index 80a5ec05d..7e2ce3f49 100644 --- a/src/apps/cam/sdl_texture_yuv.cpp +++ b/src/apps/cam/sdl_texture_yuv.cpp @@ -17,7 +17,7 @@ SDLTextureNV12::SDLTextureNV12(const SDL_Rect &rect, unsigned int stride) void SDLTextureNV12::update(libcamera::Span> data) { - SDL_UpdateNVTexture(ptr_, &rect_, data[0].data(), stride_, + SDL_UpdateNVTexture(ptr_, nullptr, data[0].data(), stride_, data[1].data(), stride_); } #endif @@ -29,5 +29,5 @@ SDLTextureYUYV::SDLTextureYUYV(const SDL_Rect &rect, unsigned int stride) void SDLTextureYUYV::update(libcamera::Span> data) { - SDL_UpdateTexture(ptr_, &rect_, data[0].data(), stride_); + SDL_UpdateTexture(ptr_, nullptr, data[0].data(), stride_); } From patchwork Wed Apr 30 07:58:48 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: 23304 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 C3E27BE08B for ; Wed, 30 Apr 2025 07:59:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0BFC168B29; Wed, 30 Apr 2025 09:59:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tJpgiLpu"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F228D68AD5 for ; Wed, 30 Apr 2025 09:58:53 +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 AECD2725; Wed, 30 Apr 2025 09:58:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745999927; bh=oNFT4aL+GvpAwoE50WzPZTbNAO0+59J28ELcz8A4KrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tJpgiLpuuTyMmdU4XZdJbyiT4EnJZHEoncrWHDizNb7nkCJXgziWkNvljdejXx3D3 skF7IjFYBRPvRHydfo5ydw6jFT6v/EH34fTDY0RUn/Cuab5MSXpD2fNNBvq9LdCsOz zquCChqOEDPHv8akzRr03wKM3sjlaEIDGqVhlc38= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Laurent Pinchart Subject: [PATCH v4 3/4] apps: cam: sdl_texture: Add `SDLTexture1Plane` Date: Wed, 30 Apr 2025 09:58:48 +0200 Message-ID: <20250430075849.2790398-4-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250430075849.2790398-1-barnabas.pocze@ideasonboard.com> References: <20250430075849.2790398-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; -}; From patchwork Wed Apr 30 07:58:49 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: 23305 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 763FFBE08B for ; Wed, 30 Apr 2025 07:59:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1BFD468B24; Wed, 30 Apr 2025 09:59:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sEi347Mx"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4D05568AD6 for ; Wed, 30 Apr 2025 09:58:54 +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 0C8D211AA; Wed, 30 Apr 2025 09:58:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745999928; bh=PdhpGN0EbYbRTlfTsxOEjIHGd4oq148CYcVEwNlvA+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sEi347MxiKJYrK18XchZX3ZoSs2EtzHJ4oSmd9pTcWer9nVDhbgTbNV44n1D7fViT chdRv7heDulWVd2kMnjFQaCQvft9woEhRORs8GmeNWwo2vL4zkpmne5hyHLjZfJH3U NHetDfU4OmLkHhu69dZW5Kl3g1HoLQUPfO9XFd1I= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Laurent Pinchart Subject: [PATCH v4 4/4] apps: cam: sdl_sink: Support more single-plane formats Date: Wed, 30 Apr 2025 09:58:49 +0200 Message-ID: <20250430075849.2790398-5-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250430075849.2790398-1-barnabas.pocze@ideasonboard.com> References: <20250430075849.2790398-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 | 58 +++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/src/apps/cam/sdl_sink.cpp b/src/apps/cam/sdl_sink.cpp index b295675dc..15087ec7a 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,44 @@ 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::ARGB8888: + return SDL_PIXELFORMAT_BGRA32; + case libcamera::formats::XRGB8888: + return SDL_PIXELFORMAT_BGRX32; + case libcamera::formats::RGBA8888: + return SDL_PIXELFORMAT_ABGR32; + case libcamera::formats::RGBX8888: + return SDL_PIXELFORMAT_XBGR32; + case libcamera::formats::ABGR8888: + return SDL_PIXELFORMAT_RGBA32; + case libcamera::formats::XBGR8888: + return SDL_PIXELFORMAT_RGBX32; + case libcamera::formats::BGRA8888: + return SDL_PIXELFORMAT_ARGB32; + case libcamera::formats::BGRX8888: + return SDL_PIXELFORMAT_XRGB32; + 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 +102,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; }