[libcamera-devel] cam: Support RGB888 texture in sdl sink

Kieran Bingham kieran.bingham at ideasonboard.com
Fri Dec 15 15:39:18 CET 2023


Quoting Pavel Machek (2023-12-12 17:36:30)
>     
> Briefly tested on PinePhone, it is useful for SoftISP testing.

Commit messages should ideally describe the code change. Perhaps:

"""
SDL Supports SDL_PIXELFORMAT_BGR24 which maps directly to the libcamera
pixelformat RGB888.

Add this to enable rendering RGB single planar image formats with SDL.
"""

I would suggest this could be tested with VIMC which can produce both
RGB888 and BGR888 as far as I can recall.

And probably both formats should be tested and added. (with the commit
message reflecting both formats then)


>     
> Signed-off-by: Pavel Machek <pavel at ucw.cz>
> 
> diff --git a/src/apps/cam/sdl_sink.cpp b/src/apps/cam/sdl_sink.cpp
> index a2f4abc1..105fa781 100644
> --- a/src/apps/cam/sdl_sink.cpp
> +++ b/src/apps/cam/sdl_sink.cpp
> @@ -76,6 +76,9 @@ int SDLSink::configure(const libcamera::CameraConfiguration &config)
>         case libcamera::formats::YUYV:
>                 texture_ = std::make_unique<SDLTextureYUYV>(rect_, cfg.stride);
>                 break;
> +       case libcamera::formats::RGB888:
> +               texture_ = std::make_unique<SDLTextureRGB888>(rect_, cfg.stride);
> +               break;
>         default:
>                 std::cerr << "Unsupported pixel format "
>                           << cfg.pixelFormat.toString() << std::endl;
> diff --git a/src/apps/cam/sdl_texture_yuv.cpp b/src/apps/cam/sdl_texture_yuv.cpp
> index b29c3b93..bb066540 100644
> --- a/src/apps/cam/sdl_texture_yuv.cpp
> +++ b/src/apps/cam/sdl_texture_yuv.cpp

I don't think RGB888 should be within  texture_yuy.cpp file though.

Either we break out to sdl_texture_rgb.cpp (and perhaps add both RGB888
and BGR888 to get started) or we should rename sdl_texture_yuv to
something more appropriate.



> @@ -31,3 +31,13 @@ void SDLTextureYUYV::update(const std::vector<libcamera::Span<const uint8_t>> &d
>  {
>         SDL_UpdateTexture(ptr_, &rect_, data[0].data(), stride_);
>  }
> +
> +SDLTextureRGB888::SDLTextureRGB888(const SDL_Rect &rect, unsigned int stride)
> +       : SDLTexture(rect, SDL_PIXELFORMAT_BGR24, stride)
> +{
> +}
> +
> +void SDLTextureRGB888::update(const std::vector<libcamera::Span<const uint8_t>> &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 310e4e50..0df6b445 100644
> --- a/src/apps/cam/sdl_texture_yuv.h
> +++ b/src/apps/cam/sdl_texture_yuv.h
> @@ -24,3 +24,10 @@ public:
>         SDLTextureYUYV(const SDL_Rect &rect, unsigned int stride);
>         void update(const std::vector<libcamera::Span<const uint8_t>> &data) override;
>  };
> +
> +class SDLTextureRGB888 : public SDLTexture
> +{
> +public:
> +       SDLTextureRGB888(const SDL_Rect &rect, unsigned int stride);
> +       void update(const std::vector<libcamera::Span<const uint8_t>> &data) override;
> +};
> 
> -- 
> People of Russia, stop Putin before his war on Ukraine escalates.


More information about the libcamera-devel mailing list