Re: [PATCH v3 4/9] platform/raspberrypi: vchiq-mmal: Support bayer and gray formats
From: Dave Stevenson
Date: Thu Sep 10 2026 - 12:59:00 EST
Hi Paul and Jai
On Thu, 10 Sept 2026 at 15:18, Jai Luthra <jai.luthra@xxxxxxxxxxxxxxxx> wrote:
>
> Hi Paul,
>
> Thank you for your review.
>
> Quoting Paul Elder (2026-08-31 12:00:09)
> > Quoting Jai Luthra (2026-07-17 20:04:19)
> > > Raw camera sensors often send data as packed or unpacked bayer and gray
> > > formats, which needs to be processed by the ISP.
> > >
> > > Add macros to support bayer and gray format FOURCCs in the MMAL layer.
> > >
> > > Signed-off-by: Jai Luthra <jai.luthra@xxxxxxxxxxxxxxxx>
> > > ---
> > > include/linux/raspberrypi/mmal-encodings.h | 64 ++++++++++++++++++++++++++++++
> > > 1 file changed, 64 insertions(+)
> > >
> > > diff --git a/include/linux/raspberrypi/mmal-encodings.h b/include/linux/raspberrypi/mmal-encodings.h
> > > index eadf2e981408..1e13ebbaebf6 100644
> > > --- a/include/linux/raspberrypi/mmal-encodings.h
> > > +++ b/include/linux/raspberrypi/mmal-encodings.h
> > > @@ -69,6 +69,70 @@
> > > */
> > > #define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
> > >
> > > +/**
> > > + * Bayer formats
> > > + * FourCC values copied from V4L2 where defined.
> >
> > Is this matching a requirement? I've noticed that 12-bit packed and SBGGR16
> > don't match the v4l2 fourcc, but the ones that you defined are nicer.
No requirement.
That comment comes from 2015 / 2017 when the firmware support was
being added/extended, and V4L2 was handy to copy where applicable.
https://github.com/raspberrypi/userland/blame/master/interface/mmal/mmal_encodings.h#L110
(10 years ago! I've been doing this job too long!)
> I believe these are what the VC4 firmware expects as the fourcc values. I
> don't know the historic reason why these were chosen, but we do use
> standard v4l2 fourcc here when dealing with userspace applications.
>
> I don't know if it's worth it to change these to match V4L2 fourcc,
> especially because we want to avoid breaking changes to the firmware.
I'm not intending to make any changes to the firmware for ISP support
as it would create a breaking change and a world of pain.
Drop the comment.
These defines are for the MMAL API, and that is to all intents and
purposes fixed now. Similarities to V4L2 are just similarities.
Dave
> Thanks,
> Jai
>
> >
> > Paul
> >
> > > + */
> > > +/* 8 bit per pixel Bayer formats. */
> > > +#define MMAL_ENCODING_BAYER_SBGGR8 MMAL_FOURCC('B', 'A', '8', '1')
> > > +#define MMAL_ENCODING_BAYER_SGBRG8 MMAL_FOURCC('G', 'B', 'R', 'G')
> > > +#define MMAL_ENCODING_BAYER_SGRBG8 MMAL_FOURCC('G', 'R', 'B', 'G')
> > > +#define MMAL_ENCODING_BAYER_SRGGB8 MMAL_FOURCC('R', 'G', 'G', 'B')
> > > +
> > > +/* 10 bit per pixel packed Bayer formats. */
> > > +#define MMAL_ENCODING_BAYER_SBGGR10P MMAL_FOURCC('p', 'B', 'A', 'A')
> > > +#define MMAL_ENCODING_BAYER_SGRBG10P MMAL_FOURCC('p', 'g', 'A', 'A')
> > > +#define MMAL_ENCODING_BAYER_SGBRG10P MMAL_FOURCC('p', 'G', 'A', 'A')
> > > +#define MMAL_ENCODING_BAYER_SRGGB10P MMAL_FOURCC('p', 'R', 'A', 'A')
> > > +
> > > +/* 12 bit per pixel packed Bayer formats. */
> > > +#define MMAL_ENCODING_BAYER_SBGGR12P MMAL_FOURCC('p', 'B', '1', '2')
> > > +#define MMAL_ENCODING_BAYER_SGRBG12P MMAL_FOURCC('p', 'g', '1', '2')
> > > +#define MMAL_ENCODING_BAYER_SGBRG12P MMAL_FOURCC('p', 'G', '1', '2')
> > > +#define MMAL_ENCODING_BAYER_SRGGB12P MMAL_FOURCC('p', 'R', '1', '2')
> > > +
> > > +/* 14 bit per pixel packed Bayer formats. */
> > > +#define MMAL_ENCODING_BAYER_SBGGR14P MMAL_FOURCC('p', 'B', 'E', 'E')
> > > +#define MMAL_ENCODING_BAYER_SGBRG14P MMAL_FOURCC('p', 'G', 'E', 'E')
> > > +#define MMAL_ENCODING_BAYER_SGRBG14P MMAL_FOURCC('p', 'g', 'E', 'E')
> > > +#define MMAL_ENCODING_BAYER_SRGGB14P MMAL_FOURCC('p', 'R', 'E', 'E')
> > > +
> > > +/* 16 bit per pixel Bayer formats. */
> > > +#define MMAL_ENCODING_BAYER_SBGGR16 MMAL_FOURCC('B', 'G', '1', '6')
> > > +#define MMAL_ENCODING_BAYER_SGBRG16 MMAL_FOURCC('G', 'B', '1', '6')
> > > +#define MMAL_ENCODING_BAYER_SGRBG16 MMAL_FOURCC('G', 'R', '1', '6')
> > > +#define MMAL_ENCODING_BAYER_SRGGB16 MMAL_FOURCC('R', 'G', '1', '6')
> > > +
> > > +/* 10 bit per pixel unpacked (16bit) Bayer formats. */
> > > +#define MMAL_ENCODING_BAYER_SBGGR10 MMAL_FOURCC('B', 'G', '1', '0')
> > > +#define MMAL_ENCODING_BAYER_SGRBG10 MMAL_FOURCC('B', 'A', '1', '0')
> > > +#define MMAL_ENCODING_BAYER_SGBRG10 MMAL_FOURCC('G', 'B', '1', '0')
> > > +#define MMAL_ENCODING_BAYER_SRGGB10 MMAL_FOURCC('R', 'G', '1', '0')
> > > +
> > > +/* 12 bit per pixel unpacked (16bit) Bayer formats */
> > > +#define MMAL_ENCODING_BAYER_SBGGR12 MMAL_FOURCC('B', 'G', '1', '2')
> > > +#define MMAL_ENCODING_BAYER_SGRBG12 MMAL_FOURCC('B', 'A', '1', '2')
> > > +#define MMAL_ENCODING_BAYER_SGBRG12 MMAL_FOURCC('G', 'B', '1', '2')
> > > +#define MMAL_ENCODING_BAYER_SRGGB12 MMAL_FOURCC('R', 'G', '1', '2')
> > > +
> > > +/* 14 bit per pixel unpacked (16bit) Bayer formats */
> > > +#define MMAL_ENCODING_BAYER_SBGGR14 MMAL_FOURCC('B', 'G', '1', '4')
> > > +#define MMAL_ENCODING_BAYER_SGBRG14 MMAL_FOURCC('G', 'B', '1', '4')
> > > +#define MMAL_ENCODING_BAYER_SGRBG14 MMAL_FOURCC('G', 'R', '1', '4')
> > > +#define MMAL_ENCODING_BAYER_SRGGB14 MMAL_FOURCC('R', 'G', '1', '4')
> > > +
> > > +/* MIPI packed monochrome images */
> > > +#define MMAL_ENCODING_GREY MMAL_FOURCC('G', 'R', 'E', 'Y')
> > > +#define MMAL_ENCODING_Y10P MMAL_FOURCC('Y', '1', '0', 'P')
> > > +#define MMAL_ENCODING_Y12P MMAL_FOURCC('Y', '1', '2', 'P')
> > > +#define MMAL_ENCODING_Y14P MMAL_FOURCC('Y', '1', '4', 'P')
> > > +#define MMAL_ENCODING_Y16 MMAL_FOURCC('Y', '1', '6', ' ')
> > > +
> > > +/* Unpacked monochrome formats (16bit per sample, but only N LSBs used) */
> > > +#define MMAL_ENCODING_Y10 MMAL_FOURCC('Y', '1', '0', ' ')
> > > +#define MMAL_ENCODING_Y12 MMAL_FOURCC('Y', '1', '2', ' ')
> > > +#define MMAL_ENCODING_Y14 MMAL_FOURCC('Y', '1', '4', ' ')
> > > +
> > > /** An EGL image handle
> > > */
> > > #define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
> > >
> > > --
> > > 2.54.0
> > >
> > >