[libcamera-devel,2/2] libcamera: Add support for RGB565 format

Message ID 20200718143428.1060441-3-niklas.soderlund@ragnatech.se
State Accepted
Commit d9295552b17c72c57357e901cd256bcf66528233
Headers show
Series
  • libcamera: Add support for YVU420 and RGB565
Related show

Commit Message

Niklas Söderlund July 18, 2020, 2:34 p.m. UTC
Add support for RGB565 format.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/libcamera/formats.cpp          | 10 ++++++++++
 src/libcamera/formats.yaml         |  3 +++
 src/libcamera/v4l2_pixelformat.cpp |  1 +
 3 files changed, 14 insertions(+)

Comments

Jacopo Mondi July 20, 2020, 8:03 a.m. UTC | #1
Hi Niklas,

On Sat, Jul 18, 2020 at 04:34:28PM +0200, Niklas Söderlund wrote:
> Add support for RGB565 format.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  src/libcamera/formats.cpp          | 10 ++++++++++
>  src/libcamera/formats.yaml         |  3 +++
>  src/libcamera/v4l2_pixelformat.cpp |  1 +
>  3 files changed, 14 insertions(+)
>
> diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> index 8f9bdafe821b2e69..af3996c954ae1457 100644
> --- a/src/libcamera/formats.cpp
> +++ b/src/libcamera/formats.cpp
> @@ -233,6 +233,16 @@ const PixelFormatInfo pixelFormatInfoInvalid{};
>
>  const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
>  	/* RGB formats. */
> +	{ formats::RGB565, {
> +		.name = "RGB565",
> +		.format = formats::RGB565,
> +		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB565),
> +		.bitsPerPixel = 16,
> +		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> +		.packed = false,
> +		.pixelsPerGroup = 1,
> +		.planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> +	} },
>  	{ formats::BGR888, {
>  		.name = "BGR888",
>  		.format = formats::BGR888,
> diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
> index 6b5f084bb2e4e970..3a69c05fcc04fb93 100644
> --- a/src/libcamera/formats.yaml
> +++ b/src/libcamera/formats.yaml
> @@ -8,6 +8,9 @@ formats:
>    - R8:
>        fourcc: DRM_FORMAT_R8
>
> +  - RGB565:
> +      fourcc: DRM_FORMAT_RGB565
> +
>    - RGB888:
>        fourcc: DRM_FORMAT_RGB888
>    - BGR888:
> diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
> index 1609f8bb6370fa65..9799d389e20b358d 100644
> --- a/src/libcamera/v4l2_pixelformat.cpp
> +++ b/src/libcamera/v4l2_pixelformat.cpp
> @@ -45,6 +45,7 @@ namespace {
>
>  const std::map<V4L2PixelFormat, PixelFormat> vpf2pf{
>  	/* RGB formats. */
> +	{ V4L2PixelFormat(V4L2_PIX_FMT_RGB565), formats::RGB565 },
>  	{ V4L2PixelFormat(V4L2_PIX_FMT_RGB24), formats::BGR888 },

Should RGB5 come after RGB2 ?

That apart
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

>  	{ V4L2PixelFormat(V4L2_PIX_FMT_BGR24), formats::RGB888 },
>  	{ V4L2PixelFormat(V4L2_PIX_FMT_RGBA32), formats::ABGR8888 },
> --
> 2.27.0
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Niklas Söderlund July 20, 2020, 8:20 a.m. UTC | #2
Hi Jacopo,

Thanks for your feedback.

On 2020-07-20 10:03:17 +0200, Jacopo Mondi wrote:
> Hi Niklas,
> 
> On Sat, Jul 18, 2020 at 04:34:28PM +0200, Niklas Söderlund wrote:
> > Add support for RGB565 format.
> >
> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> > ---
> >  src/libcamera/formats.cpp          | 10 ++++++++++
> >  src/libcamera/formats.yaml         |  3 +++
> >  src/libcamera/v4l2_pixelformat.cpp |  1 +
> >  3 files changed, 14 insertions(+)
> >
> > diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> > index 8f9bdafe821b2e69..af3996c954ae1457 100644
> > --- a/src/libcamera/formats.cpp
> > +++ b/src/libcamera/formats.cpp
> > @@ -233,6 +233,16 @@ const PixelFormatInfo pixelFormatInfoInvalid{};
> >
> >  const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	/* RGB formats. */
> > +	{ formats::RGB565, {
> > +		.name = "RGB565",
> > +		.format = formats::RGB565,
> > +		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB565),
> > +		.bitsPerPixel = 16,
> > +		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> > +		.packed = false,
> > +		.pixelsPerGroup = 1,
> > +		.planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> > +	} },
> >  	{ formats::BGR888, {
> >  		.name = "BGR888",
> >  		.format = formats::BGR888,
> > diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
> > index 6b5f084bb2e4e970..3a69c05fcc04fb93 100644
> > --- a/src/libcamera/formats.yaml
> > +++ b/src/libcamera/formats.yaml
> > @@ -8,6 +8,9 @@ formats:
> >    - R8:
> >        fourcc: DRM_FORMAT_R8
> >
> > +  - RGB565:
> > +      fourcc: DRM_FORMAT_RGB565
> > +
> >    - RGB888:
> >        fourcc: DRM_FORMAT_RGB888
> >    - BGR888:
> > diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
> > index 1609f8bb6370fa65..9799d389e20b358d 100644
> > --- a/src/libcamera/v4l2_pixelformat.cpp
> > +++ b/src/libcamera/v4l2_pixelformat.cpp
> > @@ -45,6 +45,7 @@ namespace {
> >
> >  const std::map<V4L2PixelFormat, PixelFormat> vpf2pf{
> >  	/* RGB formats. */
> > +	{ V4L2PixelFormat(V4L2_PIX_FMT_RGB565), formats::RGB565 },
> >  	{ V4L2PixelFormat(V4L2_PIX_FMT_RGB24), formats::BGR888 },
> 
> Should RGB5 come after RGB2 ?

I kept the same sorting order as videodev2.h, I'm open to define a 
different sorting order here tho. What do you think?

> 
> That apart
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> 
> Thanks
>   j
> 
> >  	{ V4L2PixelFormat(V4L2_PIX_FMT_BGR24), formats::RGB888 },
> >  	{ V4L2PixelFormat(V4L2_PIX_FMT_RGBA32), formats::ABGR8888 },
> > --
> > 2.27.0
> >
> > _______________________________________________
> > libcamera-devel mailing list
> > libcamera-devel@lists.libcamera.org
> > https://lists.libcamera.org/listinfo/libcamera-devel
Jacopo Mondi July 20, 2020, 8:37 a.m. UTC | #3
Hi Niklas,

On Mon, Jul 20, 2020 at 10:20:15AM +0200, Niklas Söderlund wrote:
> Hi Jacopo,
>
> Thanks for your feedback.
>
> On 2020-07-20 10:03:17 +0200, Jacopo Mondi wrote:
> > Hi Niklas,
> >
> > On Sat, Jul 18, 2020 at 04:34:28PM +0200, Niklas Söderlund wrote:
> > > Add support for RGB565 format.
> > >
> > > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> > > ---
> > >  src/libcamera/formats.cpp          | 10 ++++++++++
> > >  src/libcamera/formats.yaml         |  3 +++
> > >  src/libcamera/v4l2_pixelformat.cpp |  1 +
> > >  3 files changed, 14 insertions(+)
> > >
> > > diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> > > index 8f9bdafe821b2e69..af3996c954ae1457 100644
> > > --- a/src/libcamera/formats.cpp
> > > +++ b/src/libcamera/formats.cpp
> > > @@ -233,6 +233,16 @@ const PixelFormatInfo pixelFormatInfoInvalid{};
> > >
> > >  const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> > >  	/* RGB formats. */
> > > +	{ formats::RGB565, {
> > > +		.name = "RGB565",
> > > +		.format = formats::RGB565,
> > > +		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB565),
> > > +		.bitsPerPixel = 16,
> > > +		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> > > +		.packed = false,
> > > +		.pixelsPerGroup = 1,
> > > +		.planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
> > > +	} },
> > >  	{ formats::BGR888, {
> > >  		.name = "BGR888",
> > >  		.format = formats::BGR888,
> > > diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
> > > index 6b5f084bb2e4e970..3a69c05fcc04fb93 100644
> > > --- a/src/libcamera/formats.yaml
> > > +++ b/src/libcamera/formats.yaml
> > > @@ -8,6 +8,9 @@ formats:
> > >    - R8:
> > >        fourcc: DRM_FORMAT_R8
> > >
> > > +  - RGB565:
> > > +      fourcc: DRM_FORMAT_RGB565
> > > +
> > >    - RGB888:
> > >        fourcc: DRM_FORMAT_RGB888
> > >    - BGR888:
> > > diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
> > > index 1609f8bb6370fa65..9799d389e20b358d 100644
> > > --- a/src/libcamera/v4l2_pixelformat.cpp
> > > +++ b/src/libcamera/v4l2_pixelformat.cpp
> > > @@ -45,6 +45,7 @@ namespace {
> > >
> > >  const std::map<V4L2PixelFormat, PixelFormat> vpf2pf{
> > >  	/* RGB formats. */
> > > +	{ V4L2PixelFormat(V4L2_PIX_FMT_RGB565), formats::RGB565 },
> > >  	{ V4L2PixelFormat(V4L2_PIX_FMT_RGB24), formats::BGR888 },
> >
> > Should RGB5 come after RGB2 ?
>
> I kept the same sorting order as videodev2.h, I'm open to define a
> different sorting order here tho. What do you think?

I don't see much value in staying aligned to videodev2.h, but as long
as this was intentional I'm fine, really a minor thing. Up to you.

>
> >
> > That apart
> > Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> >
> > Thanks
> >   j
> >
> > >  	{ V4L2PixelFormat(V4L2_PIX_FMT_BGR24), formats::RGB888 },
> > >  	{ V4L2PixelFormat(V4L2_PIX_FMT_RGBA32), formats::ABGR8888 },
> > > --
> > > 2.27.0
> > >
> > > _______________________________________________
> > > libcamera-devel mailing list
> > > libcamera-devel@lists.libcamera.org
> > > https://lists.libcamera.org/listinfo/libcamera-devel
>
> --
> Regards,
> Niklas Söderlund
Kieran Bingham July 20, 2020, 10:52 p.m. UTC | #4
Hi Niklas, Jacopo,

On 20/07/2020 09:37, Jacopo Mondi wrote:
> Hi Niklas,
> 
> On Mon, Jul 20, 2020 at 10:20:15AM +0200, Niklas Söderlund wrote:
>> Hi Jacopo,
>>
>> Thanks for your feedback.
>>
>> On 2020-07-20 10:03:17 +0200, Jacopo Mondi wrote:
>>> Hi Niklas,
>>>
>>> On Sat, Jul 18, 2020 at 04:34:28PM +0200, Niklas Söderlund wrote:
>>>> Add support for RGB565 format.
>>>>
>>>> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
>>>> ---
>>>>  src/libcamera/formats.cpp          | 10 ++++++++++
>>>>  src/libcamera/formats.yaml         |  3 +++
>>>>  src/libcamera/v4l2_pixelformat.cpp |  1 +
>>>>  3 files changed, 14 insertions(+)
>>>>
>>>> diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
>>>> index 8f9bdafe821b2e69..af3996c954ae1457 100644
>>>> --- a/src/libcamera/formats.cpp
>>>> +++ b/src/libcamera/formats.cpp
>>>> @@ -233,6 +233,16 @@ const PixelFormatInfo pixelFormatInfoInvalid{};
>>>>
>>>>  const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
>>>>  	/* RGB formats. */
>>>> +	{ formats::RGB565, {
>>>> +		.name = "RGB565",
>>>> +		.format = formats::RGB565,
>>>> +		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB565),
>>>> +		.bitsPerPixel = 16,
>>>> +		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
>>>> +		.packed = false,
>>>> +		.pixelsPerGroup = 1,
>>>> +		.planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
>>>> +	} },
>>>>  	{ formats::BGR888, {
>>>>  		.name = "BGR888",
>>>>  		.format = formats::BGR888,
>>>> diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
>>>> index 6b5f084bb2e4e970..3a69c05fcc04fb93 100644
>>>> --- a/src/libcamera/formats.yaml
>>>> +++ b/src/libcamera/formats.yaml
>>>> @@ -8,6 +8,9 @@ formats:
>>>>    - R8:
>>>>        fourcc: DRM_FORMAT_R8
>>>>
>>>> +  - RGB565:
>>>> +      fourcc: DRM_FORMAT_RGB565
>>>> +
>>>>    - RGB888:
>>>>        fourcc: DRM_FORMAT_RGB888
>>>>    - BGR888:
>>>> diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
>>>> index 1609f8bb6370fa65..9799d389e20b358d 100644
>>>> --- a/src/libcamera/v4l2_pixelformat.cpp
>>>> +++ b/src/libcamera/v4l2_pixelformat.cpp
>>>> @@ -45,6 +45,7 @@ namespace {
>>>>
>>>>  const std::map<V4L2PixelFormat, PixelFormat> vpf2pf{
>>>>  	/* RGB formats. */
>>>> +	{ V4L2PixelFormat(V4L2_PIX_FMT_RGB565), formats::RGB565 },
>>>>  	{ V4L2PixelFormat(V4L2_PIX_FMT_RGB24), formats::BGR888 },
>>>
>>> Should RGB5 come after RGB2 ?
>>
>> I kept the same sorting order as videodev2.h, I'm open to define a
>> different sorting order here tho. What do you think?
> 
> I don't see much value in staying aligned to videodev2.h, but as long
> as this was intentional I'm fine, really a minor thing. Up to you.

I prefer this sort order actually, as it keeps 565 < 888, and also
16(bit) < 24(bit)...

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

>>
>>>
>>> That apart
>>> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
>>>
>>> Thanks
>>>   j
>>>
>>>>  	{ V4L2PixelFormat(V4L2_PIX_FMT_BGR24), formats::RGB888 },
>>>>  	{ V4L2PixelFormat(V4L2_PIX_FMT_RGBA32), formats::ABGR8888 },
>>>> --
>>>> 2.27.0
>>>>
>>>> _______________________________________________
>>>> libcamera-devel mailing list
>>>> libcamera-devel@lists.libcamera.org
>>>> https://lists.libcamera.org/listinfo/libcamera-devel
>>
>> --
>> Regards,
>> Niklas Söderlund
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
>

Patch

diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
index 8f9bdafe821b2e69..af3996c954ae1457 100644
--- a/src/libcamera/formats.cpp
+++ b/src/libcamera/formats.cpp
@@ -233,6 +233,16 @@  const PixelFormatInfo pixelFormatInfoInvalid{};
 
 const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
 	/* RGB formats. */
+	{ formats::RGB565, {
+		.name = "RGB565",
+		.format = formats::RGB565,
+		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB565),
+		.bitsPerPixel = 16,
+		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
+		.packed = false,
+		.pixelsPerGroup = 1,
+		.planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }},
+	} },
 	{ formats::BGR888, {
 		.name = "BGR888",
 		.format = formats::BGR888,
diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
index 6b5f084bb2e4e970..3a69c05fcc04fb93 100644
--- a/src/libcamera/formats.yaml
+++ b/src/libcamera/formats.yaml
@@ -8,6 +8,9 @@  formats:
   - R8:
       fourcc: DRM_FORMAT_R8
 
+  - RGB565:
+      fourcc: DRM_FORMAT_RGB565
+
   - RGB888:
       fourcc: DRM_FORMAT_RGB888
   - BGR888:
diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
index 1609f8bb6370fa65..9799d389e20b358d 100644
--- a/src/libcamera/v4l2_pixelformat.cpp
+++ b/src/libcamera/v4l2_pixelformat.cpp
@@ -45,6 +45,7 @@  namespace {
 
 const std::map<V4L2PixelFormat, PixelFormat> vpf2pf{
 	/* RGB formats. */
+	{ V4L2PixelFormat(V4L2_PIX_FMT_RGB565), formats::RGB565 },
 	{ V4L2PixelFormat(V4L2_PIX_FMT_RGB24), formats::BGR888 },
 	{ V4L2PixelFormat(V4L2_PIX_FMT_BGR24), formats::RGB888 },
 	{ V4L2PixelFormat(V4L2_PIX_FMT_RGBA32), formats::ABGR8888 },