[v1,1/2] libcamera: formats: Add RGB48 formats
diff mbox series

Message ID 20240215132710.810-2-naush@raspberrypi.com
State Superseded
Headers show
Series
  • Raspberry Pi: PiSP image formats
Related show

Commit Message

Naushir Patuck Feb. 15, 2024, 1:27 p.m. UTC
Add support for 16-bps (48-bpp) RGB output formats. These new formats
are define for the RGB and BGR ordering.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
---
 include/linux/drm_fourcc.h         |  4 ++++
 include/linux/videodev2.h          |  4 ++++
 src/libcamera/formats.cpp          | 20 ++++++++++++++++++++
 src/libcamera/formats.yaml         |  5 +++++
 src/libcamera/v4l2_pixelformat.cpp |  4 ++++
 5 files changed, 37 insertions(+)

Comments

Jacopo Mondi Feb. 16, 2024, 11:35 a.m. UTC | #1
Hi Naush

On Thu, Feb 15, 2024 at 01:27:09PM +0000, Naushir Patuck wrote:
> Add support for 16-bps (48-bpp) RGB output formats. These new formats
> are define for the RGB and BGR ordering.
>
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> ---
>  include/linux/drm_fourcc.h         |  4 ++++
>  include/linux/videodev2.h          |  4 ++++
>  src/libcamera/formats.cpp          | 20 ++++++++++++++++++++
>  src/libcamera/formats.yaml         |  5 +++++
>  src/libcamera/v4l2_pixelformat.cpp |  4 ++++
>  5 files changed, 37 insertions(+)
>
> diff --git a/include/linux/drm_fourcc.h b/include/linux/drm_fourcc.h
> index d6c83d9c49f4..4ee421b95730 100644
> --- a/include/linux/drm_fourcc.h
> +++ b/include/linux/drm_fourcc.h
> @@ -210,6 +210,10 @@ extern "C" {
>  #define DRM_FORMAT_RGBA1010102	fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
>  #define DRM_FORMAT_BGRA1010102	fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
>
> +/* 48 bpp RGB */
> +#define DRM_FORMAT_RGB161616	fourcc_code('R', 'G', '4', '8') /* [48:0] R:G:B 16:16:16 little endian */
> +#define DRM_FORMAT_BGR161616	fourcc_code('B', 'G', '4', '8') /* [48:0] R:G:B 16:16:16 little endian */
> +
>  /* 64 bpp RGB */
>  #define DRM_FORMAT_XRGB16161616	fourcc_code('X', 'R', '4', '8') /* [63:0] x:R:G:B 16:16:16:16 little endian */
>  #define DRM_FORMAT_XBGR16161616	fourcc_code('X', 'B', '4', '8') /* [63:0] x:B:G:R 16:16:16:16 little endian */
> diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
> index 7e556911c9e1..ba48d2c89726 100644
> --- a/include/linux/videodev2.h
> +++ b/include/linux/videodev2.h
> @@ -557,6 +557,10 @@ struct v4l2_pix_format {
>  #define V4L2_PIX_FMT_BGR48_12    v4l2_fourcc('B', '3', '1', '2') /* 48  BGR 12-bit per component */
>  #define V4L2_PIX_FMT_ABGR64_12   v4l2_fourcc('B', '4', '1', '2') /* 64  BGRA 12-bit per component */
>
> +/* RGB formats (6 bytes per pixel) */
> +#define V4L2_PIX_FMT_BGR48 v4l2_fourcc('B', 'G', 'R', '6') /* 16  BGR-16-16-16 */
> +#define V4L2_PIX_FMT_RGB48 v4l2_fourcc('R', 'G', 'B', '6') /* 16  RGB-16-16-16 */
> +
>  /* Grey formats */
>  #define V4L2_PIX_FMT_GREY    v4l2_fourcc('G', 'R', 'E', 'Y') /*  8  Greyscale     */
>  #define V4L2_PIX_FMT_Y4      v4l2_fourcc('Y', '0', '4', ' ') /*  4  Greyscale     */
> diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> index 8a606a7c37f1..a674f4179cc8 100644
> --- a/src/libcamera/formats.cpp
> +++ b/src/libcamera/formats.cpp
> @@ -270,6 +270,26 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
>  		.pixelsPerGroup = 1,
>  		.planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }},
>  	} },
> +	{ formats::BGR161616, {
> +		.name = "BGR161616",
> +		.format = formats::BGR161616,
> +		.v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_RGB48), },
> +		.bitsPerPixel = 48,
> +		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> +		.packed = false,
> +		.pixelsPerGroup = 1,
> +		.planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> +	} },
> +	{ formats::RGB161616, {
> +		.name = "RGB161616",
> +		.format = formats::RGB161616,
> +		.v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_BGR48), },
> +		.bitsPerPixel = 24,

Shouldn't this be 48 as well ?

> +		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> +		.packed = false,
> +		.pixelsPerGroup = 1,
> +		.planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> +	} },
>
>  	/* YUV packed formats. */
>  	{ formats::YUYV, {
> diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
> index d8a379923b56..bde2cc803b98 100644
> --- a/src/libcamera/formats.yaml
> +++ b/src/libcamera/formats.yaml
> @@ -43,6 +43,11 @@ formats:
>    - BGRA8888:
>        fourcc: DRM_FORMAT_BGRA8888
>
> +  - RGB161616:
> +      fourcc: DRM_FORMAT_RGB161616
> +  - BGR161616:
> +      fourcc: DRM_FORMAT_BGR161616
> +
>    - YUYV:
>        fourcc: DRM_FORMAT_YUYV
>    - YVYU:
> diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
> index 731dc10f1d73..efb6f2940235 100644
> --- a/src/libcamera/v4l2_pixelformat.cpp
> +++ b/src/libcamera/v4l2_pixelformat.cpp
> @@ -71,6 +71,10 @@ const std::map<V4L2PixelFormat, V4L2PixelFormat::Info> vpf2pf{
>  		{ formats::BGRA8888, "32-bit ARGB 8-8-8-8" } },
>  	{ V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),
>  		{ formats::RGBA8888, "32-bit ABGR 8-8-8-8" } },
> +	{ V4L2PixelFormat(V4L2_PIX_FMT_RGB48),
> +		{ formats::BGR161616, "48-bit RGB 16-16-16" } },
> +	{ V4L2PixelFormat(V4L2_PIX_FMT_BGR48),
> +		{ formats::RGB161616, "48-bit BGR 16-16-16" } },
>
>  	/* YUV packed formats. */
>  	{ V4L2PixelFormat(V4L2_PIX_FMT_YUYV),
> --
> 2.34.1
>
Naushir Patuck Feb. 16, 2024, 12:16 p.m. UTC | #2
On Fri, 16 Feb 2024 at 11:35, Jacopo Mondi
<jacopo.mondi@ideasonboard.com> wrote:
>
> Hi Naush
>
> On Thu, Feb 15, 2024 at 01:27:09PM +0000, Naushir Patuck wrote:
> > Add support for 16-bps (48-bpp) RGB output formats. These new formats
> > are define for the RGB and BGR ordering.
> >
> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> > ---
> >  include/linux/drm_fourcc.h         |  4 ++++
> >  include/linux/videodev2.h          |  4 ++++
> >  src/libcamera/formats.cpp          | 20 ++++++++++++++++++++
> >  src/libcamera/formats.yaml         |  5 +++++
> >  src/libcamera/v4l2_pixelformat.cpp |  4 ++++
> >  5 files changed, 37 insertions(+)
> >
> > diff --git a/include/linux/drm_fourcc.h b/include/linux/drm_fourcc.h
> > index d6c83d9c49f4..4ee421b95730 100644
> > --- a/include/linux/drm_fourcc.h
> > +++ b/include/linux/drm_fourcc.h
> > @@ -210,6 +210,10 @@ extern "C" {
> >  #define DRM_FORMAT_RGBA1010102       fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
> >  #define DRM_FORMAT_BGRA1010102       fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
> >
> > +/* 48 bpp RGB */
> > +#define DRM_FORMAT_RGB161616 fourcc_code('R', 'G', '4', '8') /* [48:0] R:G:B 16:16:16 little endian */
> > +#define DRM_FORMAT_BGR161616 fourcc_code('B', 'G', '4', '8') /* [48:0] R:G:B 16:16:16 little endian */
> > +
> >  /* 64 bpp RGB */
> >  #define DRM_FORMAT_XRGB16161616      fourcc_code('X', 'R', '4', '8') /* [63:0] x:R:G:B 16:16:16:16 little endian */
> >  #define DRM_FORMAT_XBGR16161616      fourcc_code('X', 'B', '4', '8') /* [63:0] x:B:G:R 16:16:16:16 little endian */
> > diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
> > index 7e556911c9e1..ba48d2c89726 100644
> > --- a/include/linux/videodev2.h
> > +++ b/include/linux/videodev2.h
> > @@ -557,6 +557,10 @@ struct v4l2_pix_format {
> >  #define V4L2_PIX_FMT_BGR48_12    v4l2_fourcc('B', '3', '1', '2') /* 48  BGR 12-bit per component */
> >  #define V4L2_PIX_FMT_ABGR64_12   v4l2_fourcc('B', '4', '1', '2') /* 64  BGRA 12-bit per component */
> >
> > +/* RGB formats (6 bytes per pixel) */
> > +#define V4L2_PIX_FMT_BGR48 v4l2_fourcc('B', 'G', 'R', '6') /* 16  BGR-16-16-16 */
> > +#define V4L2_PIX_FMT_RGB48 v4l2_fourcc('R', 'G', 'B', '6') /* 16  RGB-16-16-16 */
> > +
> >  /* Grey formats */
> >  #define V4L2_PIX_FMT_GREY    v4l2_fourcc('G', 'R', 'E', 'Y') /*  8  Greyscale     */
> >  #define V4L2_PIX_FMT_Y4      v4l2_fourcc('Y', '0', '4', ' ') /*  4  Greyscale     */
> > diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> > index 8a606a7c37f1..a674f4179cc8 100644
> > --- a/src/libcamera/formats.cpp
> > +++ b/src/libcamera/formats.cpp
> > @@ -270,6 +270,26 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >               .pixelsPerGroup = 1,
> >               .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }},
> >       } },
> > +     { formats::BGR161616, {
> > +             .name = "BGR161616",
> > +             .format = formats::BGR161616,
> > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_RGB48), },
> > +             .bitsPerPixel = 48,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> > +             .packed = false,
> > +             .pixelsPerGroup = 1,
> > +             .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::RGB161616, {
> > +             .name = "RGB161616",
> > +             .format = formats::RGB161616,
> > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_BGR48), },
> > +             .bitsPerPixel = 24,
>
> Shouldn't this be 48 as well ?

Yes it should! Will fix this.

>
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> > +             .packed = false,
> > +             .pixelsPerGroup = 1,
> > +             .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> >
> >       /* YUV packed formats. */
> >       { formats::YUYV, {
> > diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
> > index d8a379923b56..bde2cc803b98 100644
> > --- a/src/libcamera/formats.yaml
> > +++ b/src/libcamera/formats.yaml
> > @@ -43,6 +43,11 @@ formats:
> >    - BGRA8888:
> >        fourcc: DRM_FORMAT_BGRA8888
> >
> > +  - RGB161616:
> > +      fourcc: DRM_FORMAT_RGB161616
> > +  - BGR161616:
> > +      fourcc: DRM_FORMAT_BGR161616
> > +
> >    - YUYV:
> >        fourcc: DRM_FORMAT_YUYV
> >    - YVYU:
> > diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
> > index 731dc10f1d73..efb6f2940235 100644
> > --- a/src/libcamera/v4l2_pixelformat.cpp
> > +++ b/src/libcamera/v4l2_pixelformat.cpp
> > @@ -71,6 +71,10 @@ const std::map<V4L2PixelFormat, V4L2PixelFormat::Info> vpf2pf{
> >               { formats::BGRA8888, "32-bit ARGB 8-8-8-8" } },
> >       { V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),
> >               { formats::RGBA8888, "32-bit ABGR 8-8-8-8" } },
> > +     { V4L2PixelFormat(V4L2_PIX_FMT_RGB48),
> > +             { formats::BGR161616, "48-bit RGB 16-16-16" } },
> > +     { V4L2PixelFormat(V4L2_PIX_FMT_BGR48),
> > +             { formats::RGB161616, "48-bit BGR 16-16-16" } },
> >
> >       /* YUV packed formats. */
> >       { V4L2PixelFormat(V4L2_PIX_FMT_YUYV),
> > --
> > 2.34.1
> >
Jacopo Mondi Feb. 23, 2024, 8:44 a.m. UTC | #3
Hi Naush
  I was about to propose I could take this one in and fix the above
16/48 typo when applying, but then I wondered

On Fri, Feb 16, 2024 at 12:16:38PM +0000, Naushir Patuck wrote:
> On Fri, 16 Feb 2024 at 11:35, Jacopo Mondi
> <jacopo.mondi@ideasonboard.com> wrote:
> >
> > Hi Naush
> >
> > On Thu, Feb 15, 2024 at 01:27:09PM +0000, Naushir Patuck wrote:
> > > Add support for 16-bps (48-bpp) RGB output formats. These new formats
> > > are define for the RGB and BGR ordering.
> > >
> > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> > > ---
> > >  include/linux/drm_fourcc.h         |  4 ++++
> > >  include/linux/videodev2.h          |  4 ++++
> > >  src/libcamera/formats.cpp          | 20 ++++++++++++++++++++
> > >  src/libcamera/formats.yaml         |  5 +++++
> > >  src/libcamera/v4l2_pixelformat.cpp |  4 ++++
> > >  5 files changed, 37 insertions(+)
> > >
> > > diff --git a/include/linux/drm_fourcc.h b/include/linux/drm_fourcc.h
> > > index d6c83d9c49f4..4ee421b95730 100644
> > > --- a/include/linux/drm_fourcc.h
> > > +++ b/include/linux/drm_fourcc.h
> > > @@ -210,6 +210,10 @@ extern "C" {
> > >  #define DRM_FORMAT_RGBA1010102       fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
> > >  #define DRM_FORMAT_BGRA1010102       fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
> > >
> > > +/* 48 bpp RGB */
> > > +#define DRM_FORMAT_RGB161616 fourcc_code('R', 'G', '4', '8') /* [48:0] R:G:B 16:16:16 little endian */
> > > +#define DRM_FORMAT_BGR161616 fourcc_code('B', 'G', '4', '8') /* [48:0] R:G:B 16:16:16 little endian */
                                                                              B:G:R ?
> > > +

Should this be sent to DRM first ?

> > >  /* 64 bpp RGB */
> > >  #define DRM_FORMAT_XRGB16161616      fourcc_code('X', 'R', '4', '8') /* [63:0] x:R:G:B 16:16:16:16 little endian */
> > >  #define DRM_FORMAT_XBGR16161616      fourcc_code('X', 'B', '4', '8') /* [63:0] x:B:G:R 16:16:16:16 little endian */
> > > diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
> > > index 7e556911c9e1..ba48d2c89726 100644
> > > --- a/include/linux/videodev2.h
> > > +++ b/include/linux/videodev2.h
> > > @@ -557,6 +557,10 @@ struct v4l2_pix_format {
> > >  #define V4L2_PIX_FMT_BGR48_12    v4l2_fourcc('B', '3', '1', '2') /* 48  BGR 12-bit per component */
> > >  #define V4L2_PIX_FMT_ABGR64_12   v4l2_fourcc('B', '4', '1', '2') /* 64  BGRA 12-bit per component */
> > >
> > > +/* RGB formats (6 bytes per pixel) */
> > > +#define V4L2_PIX_FMT_BGR48 v4l2_fourcc('B', 'G', 'R', '6') /* 16  BGR-16-16-16 */
> > > +#define V4L2_PIX_FMT_RGB48 v4l2_fourcc('R', 'G', 'B', '6') /* 16  RGB-16-16-16 */
> > > +
> > >  /* Grey formats */
> > >  #define V4L2_PIX_FMT_GREY    v4l2_fourcc('G', 'R', 'E', 'Y') /*  8  Greyscale     */
> > >  #define V4L2_PIX_FMT_Y4      v4l2_fourcc('Y', '0', '4', ' ') /*  4  Greyscale     */
> > > diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> > > index 8a606a7c37f1..a674f4179cc8 100644
> > > --- a/src/libcamera/formats.cpp
> > > +++ b/src/libcamera/formats.cpp
> > > @@ -270,6 +270,26 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> > >               .pixelsPerGroup = 1,
> > >               .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }},
> > >       } },
> > > +     { formats::BGR161616, {
> > > +             .name = "BGR161616",
> > > +             .format = formats::BGR161616,
> > > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_RGB48), },
> > > +             .bitsPerPixel = 48,
> > > +             .colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> > > +             .packed = false,
> > > +             .pixelsPerGroup = 1,
> > > +             .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> > > +     } },
> > > +     { formats::RGB161616, {
> > > +             .name = "RGB161616",
> > > +             .format = formats::RGB161616,
> > > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_BGR48), },
> > > +             .bitsPerPixel = 24,
> >
> > Shouldn't this be 48 as well ?
>
> Yes it should! Will fix this.
>
> >
> > > +             .colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> > > +             .packed = false,
> > > +             .pixelsPerGroup = 1,
> > > +             .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> > > +     } },
> > >
> > >       /* YUV packed formats. */
> > >       { formats::YUYV, {
> > > diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
> > > index d8a379923b56..bde2cc803b98 100644
> > > --- a/src/libcamera/formats.yaml
> > > +++ b/src/libcamera/formats.yaml
> > > @@ -43,6 +43,11 @@ formats:
> > >    - BGRA8888:
> > >        fourcc: DRM_FORMAT_BGRA8888
> > >
> > > +  - RGB161616:
> > > +      fourcc: DRM_FORMAT_RGB161616
> > > +  - BGR161616:
> > > +      fourcc: DRM_FORMAT_BGR161616
> > > +
> > >    - YUYV:
> > >        fourcc: DRM_FORMAT_YUYV
> > >    - YVYU:
> > > diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
> > > index 731dc10f1d73..efb6f2940235 100644
> > > --- a/src/libcamera/v4l2_pixelformat.cpp
> > > +++ b/src/libcamera/v4l2_pixelformat.cpp
> > > @@ -71,6 +71,10 @@ const std::map<V4L2PixelFormat, V4L2PixelFormat::Info> vpf2pf{
> > >               { formats::BGRA8888, "32-bit ARGB 8-8-8-8" } },
> > >       { V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),
> > >               { formats::RGBA8888, "32-bit ABGR 8-8-8-8" } },
> > > +     { V4L2PixelFormat(V4L2_PIX_FMT_RGB48),
> > > +             { formats::BGR161616, "48-bit RGB 16-16-16" } },
> > > +     { V4L2PixelFormat(V4L2_PIX_FMT_BGR48),
> > > +             { formats::RGB161616, "48-bit BGR 16-16-16" } },
> > >
> > >       /* YUV packed formats. */
> > >       { V4L2PixelFormat(V4L2_PIX_FMT_YUYV),
> > > --
> > > 2.34.1
> > >
Laurent Pinchart Feb. 23, 2024, 10:48 a.m. UTC | #4
On Fri, Feb 23, 2024 at 09:44:22AM +0100, Jacopo Mondi wrote:
> Hi Naush
>   I was about to propose I could take this one in and fix the above
> 16/48 typo when applying, but then I wondered
> 
> On Fri, Feb 16, 2024 at 12:16:38PM +0000, Naushir Patuck wrote:
> > On Fri, 16 Feb 2024 at 11:35, Jacopo Mondi wrote:
> > > On Thu, Feb 15, 2024 at 01:27:09PM +0000, Naushir Patuck wrote:
> > > > Add support for 16-bps (48-bpp) RGB output formats. These new formats
> > > > are define for the RGB and BGR ordering.
> > > >
> > > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> > > > ---
> > > >  include/linux/drm_fourcc.h         |  4 ++++
> > > >  include/linux/videodev2.h          |  4 ++++
> > > >  src/libcamera/formats.cpp          | 20 ++++++++++++++++++++
> > > >  src/libcamera/formats.yaml         |  5 +++++
> > > >  src/libcamera/v4l2_pixelformat.cpp |  4 ++++
> > > >  5 files changed, 37 insertions(+)
> > > >
> > > > diff --git a/include/linux/drm_fourcc.h b/include/linux/drm_fourcc.h
> > > > index d6c83d9c49f4..4ee421b95730 100644
> > > > --- a/include/linux/drm_fourcc.h
> > > > +++ b/include/linux/drm_fourcc.h
> > > > @@ -210,6 +210,10 @@ extern "C" {
> > > >  #define DRM_FORMAT_RGBA1010102       fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
> > > >  #define DRM_FORMAT_BGRA1010102       fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
> > > >
> > > > +/* 48 bpp RGB */
> > > > +#define DRM_FORMAT_RGB161616 fourcc_code('R', 'G', '4', '8') /* [48:0] R:G:B 16:16:16 little endian */
> > > > +#define DRM_FORMAT_BGR161616 fourcc_code('B', 'G', '4', '8') /* [48:0] R:G:B 16:16:16 little endian */
>                                                                               B:G:R ?
> > > > +
> 
> Should this be sent to DRM first ?

Yes please :-) We don't want to depart more than we have already from
drm_fourcc.h (and the existing diff will need to be handled at some
point).

> > > >  /* 64 bpp RGB */
> > > >  #define DRM_FORMAT_XRGB16161616      fourcc_code('X', 'R', '4', '8') /* [63:0] x:R:G:B 16:16:16:16 little endian */
> > > >  #define DRM_FORMAT_XBGR16161616      fourcc_code('X', 'B', '4', '8') /* [63:0] x:B:G:R 16:16:16:16 little endian */
> > > > diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
> > > > index 7e556911c9e1..ba48d2c89726 100644
> > > > --- a/include/linux/videodev2.h
> > > > +++ b/include/linux/videodev2.h
> > > > @@ -557,6 +557,10 @@ struct v4l2_pix_format {
> > > >  #define V4L2_PIX_FMT_BGR48_12    v4l2_fourcc('B', '3', '1', '2') /* 48  BGR 12-bit per component */
> > > >  #define V4L2_PIX_FMT_ABGR64_12   v4l2_fourcc('B', '4', '1', '2') /* 64  BGRA 12-bit per component */
> > > >
> > > > +/* RGB formats (6 bytes per pixel) */
> > > > +#define V4L2_PIX_FMT_BGR48 v4l2_fourcc('B', 'G', 'R', '6') /* 16  BGR-16-16-16 */
> > > > +#define V4L2_PIX_FMT_RGB48 v4l2_fourcc('R', 'G', 'B', '6') /* 16  RGB-16-16-16 */
> > > > +
> > > >  /* Grey formats */
> > > >  #define V4L2_PIX_FMT_GREY    v4l2_fourcc('G', 'R', 'E', 'Y') /*  8  Greyscale     */
> > > >  #define V4L2_PIX_FMT_Y4      v4l2_fourcc('Y', '0', '4', ' ') /*  4  Greyscale     */
> > > > diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> > > > index 8a606a7c37f1..a674f4179cc8 100644
> > > > --- a/src/libcamera/formats.cpp
> > > > +++ b/src/libcamera/formats.cpp
> > > > @@ -270,6 +270,26 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> > > >               .pixelsPerGroup = 1,
> > > >               .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }},
> > > >       } },
> > > > +     { formats::BGR161616, {
> > > > +             .name = "BGR161616",
> > > > +             .format = formats::BGR161616,
> > > > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_RGB48), },
> > > > +             .bitsPerPixel = 48,
> > > > +             .colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> > > > +             .packed = false,
> > > > +             .pixelsPerGroup = 1,
> > > > +             .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> > > > +     } },
> > > > +     { formats::RGB161616, {
> > > > +             .name = "RGB161616",
> > > > +             .format = formats::RGB161616,
> > > > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_BGR48), },
> > > > +             .bitsPerPixel = 24,
> > >
> > > Shouldn't this be 48 as well ?
> >
> > Yes it should! Will fix this.
> >
> > >
> > > > +             .colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> > > > +             .packed = false,
> > > > +             .pixelsPerGroup = 1,
> > > > +             .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> > > > +     } },
> > > >
> > > >       /* YUV packed formats. */
> > > >       { formats::YUYV, {
> > > > diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
> > > > index d8a379923b56..bde2cc803b98 100644
> > > > --- a/src/libcamera/formats.yaml
> > > > +++ b/src/libcamera/formats.yaml
> > > > @@ -43,6 +43,11 @@ formats:
> > > >    - BGRA8888:
> > > >        fourcc: DRM_FORMAT_BGRA8888
> > > >
> > > > +  - RGB161616:
> > > > +      fourcc: DRM_FORMAT_RGB161616
> > > > +  - BGR161616:
> > > > +      fourcc: DRM_FORMAT_BGR161616
> > > > +
> > > >    - YUYV:
> > > >        fourcc: DRM_FORMAT_YUYV
> > > >    - YVYU:
> > > > diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
> > > > index 731dc10f1d73..efb6f2940235 100644
> > > > --- a/src/libcamera/v4l2_pixelformat.cpp
> > > > +++ b/src/libcamera/v4l2_pixelformat.cpp
> > > > @@ -71,6 +71,10 @@ const std::map<V4L2PixelFormat, V4L2PixelFormat::Info> vpf2pf{
> > > >               { formats::BGRA8888, "32-bit ARGB 8-8-8-8" } },
> > > >       { V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),
> > > >               { formats::RGBA8888, "32-bit ABGR 8-8-8-8" } },
> > > > +     { V4L2PixelFormat(V4L2_PIX_FMT_RGB48),
> > > > +             { formats::BGR161616, "48-bit RGB 16-16-16" } },
> > > > +     { V4L2PixelFormat(V4L2_PIX_FMT_BGR48),
> > > > +             { formats::RGB161616, "48-bit BGR 16-16-16" } },
> > > >
> > > >       /* YUV packed formats. */
> > > >       { V4L2PixelFormat(V4L2_PIX_FMT_YUYV),
Naushir Patuck Feb. 26, 2024, 9:09 a.m. UTC | #5
On Fri, 23 Feb 2024 at 10:48, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> On Fri, Feb 23, 2024 at 09:44:22AM +0100, Jacopo Mondi wrote:
> > Hi Naush
> >   I was about to propose I could take this one in and fix the above
> > 16/48 typo when applying, but then I wondered
> >
> > On Fri, Feb 16, 2024 at 12:16:38PM +0000, Naushir Patuck wrote:
> > > On Fri, 16 Feb 2024 at 11:35, Jacopo Mondi wrote:
> > > > On Thu, Feb 15, 2024 at 01:27:09PM +0000, Naushir Patuck wrote:
> > > > > Add support for 16-bps (48-bpp) RGB output formats. These new formats
> > > > > are define for the RGB and BGR ordering.
> > > > >
> > > > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> > > > > ---
> > > > >  include/linux/drm_fourcc.h         |  4 ++++
> > > > >  include/linux/videodev2.h          |  4 ++++
> > > > >  src/libcamera/formats.cpp          | 20 ++++++++++++++++++++
> > > > >  src/libcamera/formats.yaml         |  5 +++++
> > > > >  src/libcamera/v4l2_pixelformat.cpp |  4 ++++
> > > > >  5 files changed, 37 insertions(+)
> > > > >
> > > > > diff --git a/include/linux/drm_fourcc.h b/include/linux/drm_fourcc.h
> > > > > index d6c83d9c49f4..4ee421b95730 100644
> > > > > --- a/include/linux/drm_fourcc.h
> > > > > +++ b/include/linux/drm_fourcc.h
> > > > > @@ -210,6 +210,10 @@ extern "C" {
> > > > >  #define DRM_FORMAT_RGBA1010102       fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
> > > > >  #define DRM_FORMAT_BGRA1010102       fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
> > > > >
> > > > > +/* 48 bpp RGB */
> > > > > +#define DRM_FORMAT_RGB161616 fourcc_code('R', 'G', '4', '8') /* [48:0] R:G:B 16:16:16 little endian */
> > > > > +#define DRM_FORMAT_BGR161616 fourcc_code('B', 'G', '4', '8') /* [48:0] R:G:B 16:16:16 little endian */
> >                                                                               B:G:R ?
> > > > > +
> >
> > Should this be sent to DRM first ?
>
> Yes please :-) We don't want to depart more than we have already from
> drm_fourcc.h (and the existing diff will need to be handled at some
> point).

Oops, sorry, I thought this had already been done!
Yes, this should wait until the changes are sent to the DRM ML first.

>
> > > > >  /* 64 bpp RGB */
> > > > >  #define DRM_FORMAT_XRGB16161616      fourcc_code('X', 'R', '4', '8') /* [63:0] x:R:G:B 16:16:16:16 little endian */
> > > > >  #define DRM_FORMAT_XBGR16161616      fourcc_code('X', 'B', '4', '8') /* [63:0] x:B:G:R 16:16:16:16 little endian */
> > > > > diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
> > > > > index 7e556911c9e1..ba48d2c89726 100644
> > > > > --- a/include/linux/videodev2.h
> > > > > +++ b/include/linux/videodev2.h
> > > > > @@ -557,6 +557,10 @@ struct v4l2_pix_format {
> > > > >  #define V4L2_PIX_FMT_BGR48_12    v4l2_fourcc('B', '3', '1', '2') /* 48  BGR 12-bit per component */
> > > > >  #define V4L2_PIX_FMT_ABGR64_12   v4l2_fourcc('B', '4', '1', '2') /* 64  BGRA 12-bit per component */
> > > > >
> > > > > +/* RGB formats (6 bytes per pixel) */
> > > > > +#define V4L2_PIX_FMT_BGR48 v4l2_fourcc('B', 'G', 'R', '6') /* 16  BGR-16-16-16 */
> > > > > +#define V4L2_PIX_FMT_RGB48 v4l2_fourcc('R', 'G', 'B', '6') /* 16  RGB-16-16-16 */
> > > > > +
> > > > >  /* Grey formats */
> > > > >  #define V4L2_PIX_FMT_GREY    v4l2_fourcc('G', 'R', 'E', 'Y') /*  8  Greyscale     */
> > > > >  #define V4L2_PIX_FMT_Y4      v4l2_fourcc('Y', '0', '4', ' ') /*  4  Greyscale     */
> > > > > diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> > > > > index 8a606a7c37f1..a674f4179cc8 100644
> > > > > --- a/src/libcamera/formats.cpp
> > > > > +++ b/src/libcamera/formats.cpp
> > > > > @@ -270,6 +270,26 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> > > > >               .pixelsPerGroup = 1,
> > > > >               .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }},
> > > > >       } },
> > > > > +     { formats::BGR161616, {
> > > > > +             .name = "BGR161616",
> > > > > +             .format = formats::BGR161616,
> > > > > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_RGB48), },
> > > > > +             .bitsPerPixel = 48,
> > > > > +             .colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> > > > > +             .packed = false,
> > > > > +             .pixelsPerGroup = 1,
> > > > > +             .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> > > > > +     } },
> > > > > +     { formats::RGB161616, {
> > > > > +             .name = "RGB161616",
> > > > > +             .format = formats::RGB161616,
> > > > > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_BGR48), },
> > > > > +             .bitsPerPixel = 24,
> > > >
> > > > Shouldn't this be 48 as well ?
> > >
> > > Yes it should! Will fix this.
> > >
> > > >
> > > > > +             .colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> > > > > +             .packed = false,
> > > > > +             .pixelsPerGroup = 1,
> > > > > +             .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> > > > > +     } },
> > > > >
> > > > >       /* YUV packed formats. */
> > > > >       { formats::YUYV, {
> > > > > diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
> > > > > index d8a379923b56..bde2cc803b98 100644
> > > > > --- a/src/libcamera/formats.yaml
> > > > > +++ b/src/libcamera/formats.yaml
> > > > > @@ -43,6 +43,11 @@ formats:
> > > > >    - BGRA8888:
> > > > >        fourcc: DRM_FORMAT_BGRA8888
> > > > >
> > > > > +  - RGB161616:
> > > > > +      fourcc: DRM_FORMAT_RGB161616
> > > > > +  - BGR161616:
> > > > > +      fourcc: DRM_FORMAT_BGR161616
> > > > > +
> > > > >    - YUYV:
> > > > >        fourcc: DRM_FORMAT_YUYV
> > > > >    - YVYU:
> > > > > diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
> > > > > index 731dc10f1d73..efb6f2940235 100644
> > > > > --- a/src/libcamera/v4l2_pixelformat.cpp
> > > > > +++ b/src/libcamera/v4l2_pixelformat.cpp
> > > > > @@ -71,6 +71,10 @@ const std::map<V4L2PixelFormat, V4L2PixelFormat::Info> vpf2pf{
> > > > >               { formats::BGRA8888, "32-bit ARGB 8-8-8-8" } },
> > > > >       { V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),
> > > > >               { formats::RGBA8888, "32-bit ABGR 8-8-8-8" } },
> > > > > +     { V4L2PixelFormat(V4L2_PIX_FMT_RGB48),
> > > > > +             { formats::BGR161616, "48-bit RGB 16-16-16" } },
> > > > > +     { V4L2PixelFormat(V4L2_PIX_FMT_BGR48),
> > > > > +             { formats::RGB161616, "48-bit BGR 16-16-16" } },
> > > > >
> > > > >       /* YUV packed formats. */
> > > > >       { V4L2PixelFormat(V4L2_PIX_FMT_YUYV),
>
> --
> Regards,
>
> Laurent Pinchart

Patch
diff mbox series

diff --git a/include/linux/drm_fourcc.h b/include/linux/drm_fourcc.h
index d6c83d9c49f4..4ee421b95730 100644
--- a/include/linux/drm_fourcc.h
+++ b/include/linux/drm_fourcc.h
@@ -210,6 +210,10 @@  extern "C" {
 #define DRM_FORMAT_RGBA1010102	fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
 #define DRM_FORMAT_BGRA1010102	fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
 
+/* 48 bpp RGB */
+#define DRM_FORMAT_RGB161616	fourcc_code('R', 'G', '4', '8') /* [48:0] R:G:B 16:16:16 little endian */
+#define DRM_FORMAT_BGR161616	fourcc_code('B', 'G', '4', '8') /* [48:0] R:G:B 16:16:16 little endian */
+
 /* 64 bpp RGB */
 #define DRM_FORMAT_XRGB16161616	fourcc_code('X', 'R', '4', '8') /* [63:0] x:R:G:B 16:16:16:16 little endian */
 #define DRM_FORMAT_XBGR16161616	fourcc_code('X', 'B', '4', '8') /* [63:0] x:B:G:R 16:16:16:16 little endian */
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index 7e556911c9e1..ba48d2c89726 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -557,6 +557,10 @@  struct v4l2_pix_format {
 #define V4L2_PIX_FMT_BGR48_12    v4l2_fourcc('B', '3', '1', '2') /* 48  BGR 12-bit per component */
 #define V4L2_PIX_FMT_ABGR64_12   v4l2_fourcc('B', '4', '1', '2') /* 64  BGRA 12-bit per component */
 
+/* RGB formats (6 bytes per pixel) */
+#define V4L2_PIX_FMT_BGR48 v4l2_fourcc('B', 'G', 'R', '6') /* 16  BGR-16-16-16 */
+#define V4L2_PIX_FMT_RGB48 v4l2_fourcc('R', 'G', 'B', '6') /* 16  RGB-16-16-16 */
+
 /* Grey formats */
 #define V4L2_PIX_FMT_GREY    v4l2_fourcc('G', 'R', 'E', 'Y') /*  8  Greyscale     */
 #define V4L2_PIX_FMT_Y4      v4l2_fourcc('Y', '0', '4', ' ') /*  4  Greyscale     */
diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
index 8a606a7c37f1..a674f4179cc8 100644
--- a/src/libcamera/formats.cpp
+++ b/src/libcamera/formats.cpp
@@ -270,6 +270,26 @@  const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
 		.pixelsPerGroup = 1,
 		.planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }},
 	} },
+	{ formats::BGR161616, {
+		.name = "BGR161616",
+		.format = formats::BGR161616,
+		.v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_RGB48), },
+		.bitsPerPixel = 48,
+		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
+		.packed = false,
+		.pixelsPerGroup = 1,
+		.planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
+	} },
+	{ formats::RGB161616, {
+		.name = "RGB161616",
+		.format = formats::RGB161616,
+		.v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_BGR48), },
+		.bitsPerPixel = 24,
+		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
+		.packed = false,
+		.pixelsPerGroup = 1,
+		.planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
+	} },
 
 	/* YUV packed formats. */
 	{ formats::YUYV, {
diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
index d8a379923b56..bde2cc803b98 100644
--- a/src/libcamera/formats.yaml
+++ b/src/libcamera/formats.yaml
@@ -43,6 +43,11 @@  formats:
   - BGRA8888:
       fourcc: DRM_FORMAT_BGRA8888
 
+  - RGB161616:
+      fourcc: DRM_FORMAT_RGB161616
+  - BGR161616:
+      fourcc: DRM_FORMAT_BGR161616
+
   - YUYV:
       fourcc: DRM_FORMAT_YUYV
   - YVYU:
diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
index 731dc10f1d73..efb6f2940235 100644
--- a/src/libcamera/v4l2_pixelformat.cpp
+++ b/src/libcamera/v4l2_pixelformat.cpp
@@ -71,6 +71,10 @@  const std::map<V4L2PixelFormat, V4L2PixelFormat::Info> vpf2pf{
 		{ formats::BGRA8888, "32-bit ARGB 8-8-8-8" } },
 	{ V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),
 		{ formats::RGBA8888, "32-bit ABGR 8-8-8-8" } },
+	{ V4L2PixelFormat(V4L2_PIX_FMT_RGB48),
+		{ formats::BGR161616, "48-bit RGB 16-16-16" } },
+	{ V4L2PixelFormat(V4L2_PIX_FMT_BGR48),
+		{ formats::RGB161616, "48-bit BGR 16-16-16" } },
 
 	/* YUV packed formats. */
 	{ V4L2PixelFormat(V4L2_PIX_FMT_YUYV),