@@ -116,6 +116,10 @@ int SDLSink::configure(const libcamera::CameraConfiguration &config)
else if (cfg.pixelFormat == libcamera::formats::NV21)
texture_ = std::make_unique<SDLTextureNV>(rect_, SDL_PIXELFORMAT_NV21, cfg.stride);
#endif
+ else if (cfg.pixelFormat == libcamera::formats::YUV420)
+ texture_ = std::make_unique<SDLTextureYUV>(rect_, SDL_PIXELFORMAT_IYUV, cfg.stride);
+ else if (cfg.pixelFormat == libcamera::formats::YVU420)
+ texture_ = std::make_unique<SDLTextureYUV>(rect_, SDL_PIXELFORMAT_YV12, cfg.stride);
else {
std::cerr << "Unsupported pixel format " << cfg.pixelFormat << std::endl;
return -EINVAL;
@@ -28,3 +28,22 @@ void SDLTextureNV::update(std::span<const std::span<const uint8_t>> 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<const std::span<const uint8_t>> 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);
+}
@@ -17,3 +17,10 @@ public:
void update(std::span<const std::span<const uint8_t>> data) override;
};
#endif
+
+class SDLTextureYUV : public SDLTexture
+{
+public:
+ SDLTextureYUV(const SDL_Rect &rect, uint32_t pixelFormat, unsigned int stride);
+ void update(std::span<const std::span<const uint8_t>> data) override;
+};
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 <barnabas.pocze@ideasonboard.com> --- 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(+)