diff --git a/src/apps/cam/sdl_sink.cpp b/src/apps/cam/sdl_sink.cpp index 30cfdf0a..17a9e04b 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 bed297d2..9062a034 100644 --- a/src/apps/cam/sdl_texture_yuv.cpp +++ b/src/apps/cam/sdl_texture_yuv.cpp @@ -7,16 +7,23 @@ #include "sdl_texture_yuv.h" +#include + using namespace libcamera; #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 c271f901..a91658b3 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 : 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