apps: cam: sdl_texture: Support NV21
SDL also supports NV21 with the same `SDL_UpdateNVTexture()`, so add support for it. Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
This commit is contained in:
@@ -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<SDLTextureNV12>(rect_, cfg.stride);
|
||||
texture_ = std::make_unique<SDLTextureNV>(rect_, SDL_PIXELFORMAT_NV12, cfg.stride);
|
||||
else if (cfg.pixelFormat == libcamera::formats::NV21)
|
||||
texture_ = std::make_unique<SDLTextureNV>(rect_, SDL_PIXELFORMAT_NV21, cfg.stride);
|
||||
#endif
|
||||
else {
|
||||
std::cerr << "Unsupported pixel format " << cfg.pixelFormat << std::endl;
|
||||
|
||||
@@ -7,16 +7,23 @@
|
||||
|
||||
#include "sdl_texture_yuv.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
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<const libcamera::Span<const uint8_t>> data)
|
||||
void SDLTextureNV::update(libcamera::Span<const libcamera::Span<const uint8_t>> 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_);
|
||||
}
|
||||
|
||||
@@ -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<const libcamera::Span<const uint8_t>> data) override;
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user