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

Message ID ZXBUSx4+6EVqyWnp@duo.ucw.cz
State Superseded
Headers show
Series
  • [libcamera-devel] cam: Support RGB888 texture in sdl sink
Related show

Commit Message

Pavel Machek Dec. 6, 2023, 11 a.m. UTC
Lightly tested; this is useful for SoftISP testing. I get wrong
red/blue swapped, but that may be due to my SoftISP hacks.
    
Signed-off-by: Pavel Machek <pavel@ucw.cz>

Comments

Kieran Bingham Dec. 6, 2023, 11:21 a.m. UTC | #1
Quoting Pavel Machek via libcamera-devel (2023-12-06 11:00:27)
>     
> Lightly tested; this is useful for SoftISP testing. I get wrong
> red/blue swapped, but that may be due to my SoftISP hacks.
>     
> Signed-off-by: Pavel Machek <pavel@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:

I haven't confirmed, but I would bet if you have RB swaps, then you
should probably map SDL RGB888 to libcamera BGR888, and libcamera RGB888
to SDL BGR888.

DRM RGB formats are specified differently to V4L2 formats. libcamera
uses the DRM specification.

> +               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..c4c4144b 100644
> --- a/src/apps/cam/sdl_texture_yuv.cpp
> +++ b/src/apps/cam/sdl_texture_yuv.cpp
> @@ -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_RGB24, 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.
Pavel Machek Dec. 6, 2023, 11:56 a.m. UTC | #2
Hi!

> > Lightly tested; this is useful for SoftISP testing. I get wrong
> > red/blue swapped, but that may be due to my SoftISP hacks.
> >     
> > Signed-off-by: Pavel Machek <pavel@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:
> 
> I haven't confirmed, but I would bet if you have RB swaps, then you
> should probably map SDL RGB888 to libcamera BGR888, and libcamera RGB888
> to SDL BGR888.
> 
> DRM RGB formats are specified differently to V4L2 formats. libcamera
> uses the DRM specification.

Thanks a lot. This stuff is quite confusing :-(.

Best regards,
								Pavel
Pavel Machek Dec. 12, 2023, 5:35 p.m. UTC | #3
Hi!

> > Lightly tested; this is useful for SoftISP testing. I get wrong
> > red/blue swapped, but that may be due to my SoftISP hacks.
> >     
> > Signed-off-by: Pavel Machek <pavel@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:
> 
> I haven't confirmed, but I would bet if you have RB swaps, then you
> should probably map SDL RGB888 to libcamera BGR888, and libcamera RGB888
> to SDL BGR888.
> 
> DRM RGB formats are specified differently to V4L2 formats. libcamera
> uses the DRM specification.

Thank you, fixed, and now I have good colors, v2 will follow.

Best regards,
								Pavel

Patch
diff mbox series

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..c4c4144b 100644
--- a/src/apps/cam/sdl_texture_yuv.cpp
+++ b/src/apps/cam/sdl_texture_yuv.cpp
@@ -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_RGB24, 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;
+};