[PATCH 1/1] libcamera: Add formats introduced by MTK platform

Cheng-Hao Yang chenghaoyang at chromium.org
Mon Sep 30 11:10:51 CEST 2024


Thanks Laurent and Nicolas for the comments.

Let's revisit this when the formats are submitted in Linux Kernel.
Seems that we need to wait for a couple of months, as there are
other works ahead...

BR,
Harvey

On Tue, Sep 24, 2024 at 2:21 AM Nicolas Dufresne <nicolas at ndufresne.ca> wrote:
>
> Hi,
>
> Le lundi 23 septembre 2024 à 09:08 +0000, Harvey Yang a écrit :
> > From: Han-Lin Chen <hanlinchen at chromium.org>
> >
> > The patch adds the following formats.
> >
> >   - GREY
> >   - SBGGR10_MTISP
> >   - SGBRG10_MTISP
> >   - SGRBG10_MTISP
> >   - SRGGB10_MTISP
> >   - NV12_10P_MTISP
> >   - NV12_12P_MTISP
> >   - MTFP_MTISP
> >   - MTFA_MTISP
> >   - MTFF_MTISP
> >   - MTFD_MTISP
> >   - MTFS_MTISP
> >   - MTFR_MTISP
> >   - MTSR_MTISP
> >   - WARP2P_MTISP
> >   - Y8_MTISP
> >   - Y16_MTISP
> >   - Y32_MTISP
> >
> > Signed-off-by: Han-Lin Chen <hanlinchen at chromium.org>
> > Co-developed-by: Xing Gu <xinggu at chromium.org>
> > Co-developed-by: Harvey Yang <chenghaoyang at chromium.org>
> > ---
> >  include/linux/drm_fourcc.h |  26 +++++
> >  include/linux/videodev2.h  |  22 ++++
> >  src/libcamera/formats.cpp  | 203 +++++++++++++++++++++++++++++++++++++
> >  src/libcamera/formats.yaml |  38 +++++++
> >  4 files changed, 289 insertions(+)
> >
> > diff --git a/include/linux/drm_fourcc.h b/include/linux/drm_fourcc.h
> > index db679877..ca00a3c7 100644
> > --- a/include/linux/drm_fourcc.h
> > +++ b/include/linux/drm_fourcc.h
> > @@ -466,6 +466,32 @@ extern "C" {
> >  #define DRM_FORMAT_SGBRG16   fourcc_code('G', 'B', '1', '6')
> >  #define DRM_FORMAT_SBGGR16   fourcc_code('B', 'Y', 'R', '2')
> >
> > +/* MTK extention */
> > +
> > +#define DRM_FORMAT_MTISP_SBGGR10 fourcc_code('M', 'B', 'B', 'A')
> > +#define DRM_FORMAT_MTISP_SGBRG10 fourcc_code('M', 'B', 'G', 'A')
> > +#define DRM_FORMAT_MTISP_SGRBG10 fourcc_code('M', 'B', 'g', 'A')
> > +#define DRM_FORMAT_MTISP_SRGGB10 fourcc_code('M', 'B', 'R', 'A')
> > +
> > +#define DRM_FORMAT_MTISP_NV12_10P fourcc_code('1', '2', 'A', 'P')
> > +#define DRM_FORMAT_MTISP_NV12_12P fourcc_code('1', '2', 'C', 'P')
>
> Just to share my own mistake in other project, the 12 in NV12 means 12bits per
> pixels. With the logic, packed 10bit with 4:2:0 subsampling would be NV15, and
> 12bit would be NV18. I'm not staying NV notation scale very well, since you can
> make up some clash easily, but this was 20 years ago the logic, and matching
> NV12 and 10bit makes little a sense (sorry GStreamer project, I try and do
> better next time).
>
> Note that if this is effectively NV15 with Meditek tiling (Y 16x32 | 16x16
> CbCr), then modifier it should be.
>
> Nicolas
>
> p.s. when upstreaming formats, never try to hide what they are, your patch will
> always be rejected upstream. Split them up, document what they truly are. In
> general, appart from compression, everything else should be clear with no
> ambiguity. The reason is simple, vendors actually share some formats without
> actually knowing.
>
> > +
> > +#define DRM_FORMAT_GREY fourcc_code('G', 'R', 'E', 'Y')
> > +
> > +#define DRM_FORMAT_MTISP_PARAMS fourcc_code('M', 'T', 'f', 'p')
> > +#define DRM_FORMAT_MTISP_3A fourcc_code('M', 'T', 'f', 'a')
> > +#define DRM_FORMAT_MTISP_AF fourcc_code('M', 'T', 'f', 'f')
> > +
> > +#define DRM_FORMAT_MTISP_DESC fourcc_code('M', 'T', 'f', 'd')
> > +#define DRM_FORMAT_MTISP_SD fourcc_code('M', 'T', 'f', 's')
> > +#define DRM_FORMAT_MTISP_DESC_NORM fourcc_code('M', 'T', 'f', 'r')
> > +#define DRM_FORMAT_MTISP_SDNORM fourcc_code('M', 'T', 's', 'r')
> > +
> > +#define DRM_FORMAT_MTISP_WARP2P fourcc_code('M', 'W', '2', 'P')
> > +#define DRM_FORMAT_MTISP_Y8 fourcc_code('M', 'T', '0', '8')
> > +#define DRM_FORMAT_MTISP_Y16 fourcc_code('M', 'T', '1', '6')
> > +#define DRM_FORMAT_MTISP_Y32 fourcc_code('M', 'T', '3', '2')
> > +
> >  /*
> >   * Format Modifiers:
> >   *
> > diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
> > index 3829c0b6..2cee0b86 100644
> > --- a/include/linux/videodev2.h
> > +++ b/include/linux/videodev2.h
> > @@ -789,6 +789,28 @@ struct v4l2_pix_format {
> >  #define V4L2_PIX_FMT_IPU3_SGRBG10    v4l2_fourcc('i', 'p', '3', 'G') /* IPU3 packed 10-bit GRBG bayer */
> >  #define V4L2_PIX_FMT_IPU3_SRGGB10    v4l2_fourcc('i', 'p', '3', 'r') /* IPU3 packed 10-bit RGGB bayer */
> >
> > +#define V4L2_PIX_FMT_MTISP_SBGGR10 v4l2_fourcc('M', 'B', 'B', 'A')
> > +#define V4L2_PIX_FMT_MTISP_SGBRG10 v4l2_fourcc('M', 'B', 'G', 'A')
> > +#define V4L2_PIX_FMT_MTISP_SGRBG10 v4l2_fourcc('M', 'B', 'g', 'A')
> > +#define V4L2_PIX_FMT_MTISP_SRGGB10 v4l2_fourcc('M', 'B', 'R', 'A')
> > +
> > +#define V4L2_PIX_FMT_MTISP_NV12_10P v4l2_fourcc('1', '2', 'A', 'P') /* Y/CbCr 4:2:0 10 bits packed */
> > +#define V4L2_PIX_FMT_MTISP_NV12_12P v4l2_fourcc('1', '2', 'C', 'P') /* Y/CbCr 4:2:0 12 bits packed */
> > +
> > +#define V4L2_META_FMT_MTISP_PARAMS v4l2_fourcc('M', 'T', 'f', 'p')
> > +#define V4L2_META_FMT_MTISP_3A v4l2_fourcc('M', 'T', 'f', 'a')
> > +#define V4L2_META_FMT_MTISP_AF v4l2_fourcc('M', 'T', 'f', 'f')
> > +
> > +#define V4L2_META_FMT_MTISP_DESC v4l2_fourcc('M', 'T', 'f', 'd')
> > +#define V4L2_META_FMT_MTISP_SD v4l2_fourcc('M', 'T', 'f', 's')
> > +#define V4L2_META_FMT_MTISP_DESCNORM v4l2_fourcc('M', 'T', 'f', 'r')
> > +#define V4L2_META_FMT_MTISP_SDNORM v4l2_fourcc('M', 'T', 's', 'r')
> > +
> > +#define V4L2_PIX_FMT_WARP2P v4l2_fourcc('M', 'W', '2', 'P')
> > +#define V4L2_PIX_FMT_MTISP_Y8 v4l2_fourcc('M', 'T', '0', '8')
> > +#define V4L2_PIX_FMT_MTISP_Y16 v4l2_fourcc('M', 'T', '1', '6')
> > +#define V4L2_PIX_FMT_MTISP_Y32 v4l2_fourcc('M', 'T', '3', '2')
> > +
> >  /* Raspberry Pi PiSP compressed formats. */
> >  #define V4L2_PIX_FMT_PISP_COMP1_RGGB v4l2_fourcc('P', 'C', '1', 'R') /* PiSP 8-bit mode 1 compressed RGGB bayer */
> >  #define V4L2_PIX_FMT_PISP_COMP1_GRBG v4l2_fourcc('P', 'C', '1', 'G') /* PiSP 8-bit mode 1 compressed GRBG bayer */
> > diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> > index dbefb094..53ce4e7d 100644
> > --- a/src/libcamera/formats.cpp
> > +++ b/src/libcamera/formats.cpp
> > @@ -506,6 +506,16 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >               .pixelsPerGroup = 1,
> >               .planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }},
> >       } },
> > +     { formats::GREY, {
> > +             .name = "GREY",
> > +             .format = formats::R8,
> > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_GREY), },
> > +             .bitsPerPixel = 8,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = false,
> > +             .pixelsPerGroup = 1,
> > +             .planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> >       { formats::R10, {
> >               .name = "R10",
> >               .format = formats::R10,
> > @@ -969,6 +979,199 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >               .pixelsPerGroup = 2,
> >               .planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }},
> >       } },
> > +     { formats::SBGGR10_MTISP, {
> > +             .name = "SBGGR10_MTISP",
> > +             .format = formats::SBGGR10_MTISP,
> > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_MTISP_SBGGR10), },
> > +             .bitsPerPixel = 10,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> > +             .packed = true,
> > +             .pixelsPerGroup = 64,
> > +             .planes = {{ { 80, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::SGBRG10_MTISP, {
> > +             .name = "SGBRG10_MTISP",
> > +             .format = formats::SGBRG10_MTISP,
> > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_MTISP_SGBRG10), },
> > +             .bitsPerPixel = 10,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> > +             .packed = true,
> > +             .pixelsPerGroup = 64,
> > +             .planes = {{ { 80, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::SGRBG10_MTISP, {
> > +             .name = "SGRBG10_MTISP",
> > +             .format = formats::SGRBG10_MTISP,
> > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_MTISP_SGRBG10), },
> > +             .bitsPerPixel = 10,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> > +             .packed = true,
> > +             .pixelsPerGroup = 64,
> > +             .planes = {{ { 80, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::SRGGB10_MTISP, {
> > +             .name = "SRGGB10_MTISP",
> > +             .format = formats::SRGGB10_MTISP,
> > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_MTISP_SRGGB10), },
> > +             .bitsPerPixel = 10,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> > +             .packed = true,
> > +             .pixelsPerGroup = 64,
> > +             .planes = {{ { 80, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::NV12_10P_MTISP, {
> > +             .name = "NV12_10P_MTISP",
> > +             .format = formats::NV12_10P_MTISP,
> > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_MTISP_NV12_10P), },
> > +             .bitsPerPixel = 15,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = true,
> > +             .pixelsPerGroup = 64,
> > +             .planes = {{ { 80, 1 }, { 80, 2 }, { 0, 0 } }},
> > +     } },
> > +     { formats::NV12_12P_MTISP, {
> > +             .name = "NV12_12P_MTISP",
> > +             .format = formats::NV12_12P_MTISP,
> > +             .v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_MTISP_NV12_12P), },
> > +             .bitsPerPixel = 12,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = true,
> > +             .pixelsPerGroup = 64,
> > +             .planes = {{ { 96, 1 }, { 96, 2 }, { 0, 0 } }},
> > +     } },
> > +     { formats::MTFP_MTISP, {
> > +             .name = "MTFP_MTISP",
> > +             .format = formats::MTFP_MTISP,
> > +             .v4l2Formats = {
> > +                     V4L2PixelFormat(V4L2_META_FMT_MTISP_PARAMS),
> > +             },
> > +             .bitsPerPixel = 0,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = false,
> > +             .pixelsPerGroup = 1,
> > +             .planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::MTFA_MTISP, {
> > +             .name = "MTFA_MTISP",
> > +             .format = formats::MTFA_MTISP,
> > +             .v4l2Formats = {
> > +                     V4L2PixelFormat(V4L2_META_FMT_MTISP_3A),
> > +             },
> > +             .bitsPerPixel = 0,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = false,
> > +             .pixelsPerGroup = 1,
> > +             .planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::MTFF_MTISP, {
> > +             .name = "MTFF_MTISP",
> > +             .format = formats::MTFF_MTISP,
> > +             .v4l2Formats = {
> > +                     V4L2PixelFormat(V4L2_META_FMT_MTISP_AF),
> > +             },
> > +             .bitsPerPixel = 0,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = false,
> > +             .pixelsPerGroup = 1,
> > +             .planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::MTFD_MTISP, {
> > +             .name = "MTFD_MTISP",
> > +             .format = formats::MTFD_MTISP,
> > +             .v4l2Formats = {
> > +                     V4L2PixelFormat(V4L2_META_FMT_MTISP_DESC),
> > +             },
> > +             .bitsPerPixel = 8,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = false,
> > +             .pixelsPerGroup = 8,
> > +             .planes = {{ { 8, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::MTFS_MTISP, {
> > +             .name = "MTFS_MTISP",
> > +             .format = formats::MTFS_MTISP,
> > +             .v4l2Formats = {
> > +                     V4L2PixelFormat(V4L2_META_FMT_MTISP_SD),
> > +             },
> > +             .bitsPerPixel = 8,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = false,
> > +             .pixelsPerGroup = 8,
> > +             .planes = {{ { 8, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::MTFR_MTISP, {
> > +             .name = "MTFR_MTISP",
> > +             .format = formats::MTFR_MTISP,
> > +             .v4l2Formats = {
> > +                     V4L2PixelFormat(V4L2_META_FMT_MTISP_DESCNORM),
> > +             },
> > +             .bitsPerPixel = 0,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = false,
> > +             .pixelsPerGroup = 1,
> > +             .planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::MTSR_MTISP, {
> > +             .name = "MTSR_MTISP",
> > +             .format = formats::MTSR_MTISP,
> > +             .v4l2Formats = {
> > +                     V4L2PixelFormat(V4L2_META_FMT_MTISP_SDNORM),
> > +             },
> > +             .bitsPerPixel = 0,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = false,
> > +             .pixelsPerGroup = 1,
> > +             .planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::WARP2P_MTISP, {
> > +             .name = "WARP2P_MTISP",
> > +             .format = formats::WARP2P_MTISP,
> > +             .v4l2Formats = {
> > +                     V4L2PixelFormat(V4L2_PIX_FMT_WARP2P),
> > +             },
> > +             .bitsPerPixel = 32,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = false,
> > +             .pixelsPerGroup = 2,
> > +             .planes = {{ { 8, 1 }, { 8, 1 }, { 0, 0 } }},
> > +     } },
> > +     { formats::Y8_MTISP, {
> > +             .name = "Y8_MTISP",
> > +             .format = formats::Y8_MTISP,
> > +             .v4l2Formats = {
> > +                     V4L2PixelFormat(V4L2_PIX_FMT_MTISP_Y8),
> > +             },
> > +             .bitsPerPixel = 8,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = false,
> > +             .pixelsPerGroup = 1,
> > +             .planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::Y16_MTISP, {
> > +             .name = "Y16_MTISP",
> > +             .format = formats::Y16_MTISP,
> > +             .v4l2Formats = {
> > +                     V4L2PixelFormat(V4L2_PIX_FMT_MTISP_Y16),
> > +             },
> > +             .bitsPerPixel = 16,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = false,
> > +             .pixelsPerGroup = 1,
> > +             .planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +     { formats::Y32_MTISP, {
> > +             .name = "Y32_MTISP",
> > +             .format = formats::Y32_MTISP,
> > +             .v4l2Formats = {
> > +                     V4L2PixelFormat(V4L2_PIX_FMT_MTISP_Y32),
> > +             },
> > +             .bitsPerPixel = 32,
> > +             .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> > +             .packed = false,
> > +             .pixelsPerGroup = 1,
> > +             .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }},
> > +     } },
> > +
> >       /* Compressed formats. */
> >       { formats::MJPEG, {
> >               .name = "MJPEG",
> > diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
> > index 2d54d391..8c72d706 100644
> > --- a/src/libcamera/formats.yaml
> > +++ b/src/libcamera/formats.yaml
> > @@ -209,4 +209,42 @@ formats:
> >    - MONO_PISP_COMP1:
> >        fourcc: DRM_FORMAT_R16
> >        mod: PISP_FORMAT_MOD_COMPRESS_MODE1
> > +
> > +  - GREY:
> > +      fourcc: DRM_FORMAT_GREY
> > +  - SBGGR10_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_SBGGR10
> > +  - SGBRG10_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_SGBRG10
> > +  - SGRBG10_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_SGRBG10
> > +  - SRGGB10_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_SRGGB10
> > +  - NV12_10P_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_NV12_10P
> > +  - NV12_12P_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_NV12_12P
> > +  - MTFP_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_PARAMS
> > +  - MTFA_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_3A
> > +  - MTFF_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_AF
> > +  - MTFD_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_DESC
> > +  - MTFS_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_SD
> > +  - MTFR_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_DESC_NORM
> > +  - MTSR_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_SDNORM
> > +  - WARP2P_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_WARP2P
> > +  - Y8_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_Y8
> > +  - Y16_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_Y16
> > +  - Y32_MTISP:
> > +      fourcc: DRM_FORMAT_MTISP_Y32
> > +
> >  ...
>


More information about the libcamera-devel mailing list