drm/vc4: Add support for color encoding on YUV planes
authorDave Stevenson <dave.stevenson@raspberrypi.org>
Mon, 24 Jun 2019 01:29:40 +0000 (02:29 +0100)
committerpopcornmix <popcornmix@gmail.com>
Wed, 1 Jul 2020 15:33:01 +0000 (16:33 +0100)
Adds signalling for BT601/709/2020, and limited/full range
(on BT601).

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
drivers/gpu/drm/vc4/vc4_firmware_kms.c
drivers/gpu/drm/vc4/vc_image_types.h

index b97798c..862e89b 100644 (file)
@@ -69,7 +69,7 @@ struct set_plane {
        u8 alpha;
        u8 num_planes;
        u8 is_vu;
-       u8 padding;
+       u8 color_encoding;
 
        u32 planes[4];  /* DMA address of each plane */
 
@@ -456,6 +456,28 @@ static void vc4_plane_atomic_update(struct drm_plane *plane,
                if (num_planes == 3 &&
                    (fb->offsets[2] - fb->offsets[1]) == fb->pitches[1])
                        mb->plane.vc_image_type = VC_IMAGE_YUV420_S;
+
+               switch (state->color_encoding) {
+               default:
+               case DRM_COLOR_YCBCR_BT601:
+                       if (state->color_range == DRM_COLOR_YCBCR_LIMITED_RANGE)
+                               mb->plane.color_encoding =
+                                               VC_IMAGE_YUVINFO_CSC_ITUR_BT601;
+                       else
+                               mb->plane.color_encoding =
+                                               VC_IMAGE_YUVINFO_CSC_JPEG_JFIF;
+                       break;
+               case DRM_COLOR_YCBCR_BT709:
+                       /* Currently no support for a full range BT709 */
+                       mb->plane.color_encoding =
+                                               VC_IMAGE_YUVINFO_CSC_ITUR_BT709;
+                       break;
+               case DRM_COLOR_YCBCR_BT2020:
+                       /* Currently no support for a full range BT2020 */
+                       mb->plane.color_encoding =
+                                       VC_IMAGE_YUVINFO_CSC_REC_2020;
+                       break;
+               }
        } else {
                mb->plane.planes[1] = 0;
                mb->plane.planes[2] = 0;
@@ -644,6 +666,14 @@ static struct drm_plane *vc4_fkms_plane_init(struct drm_device *dev,
        drm_plane_create_alpha_property(plane);
        drm_plane_create_rotation_property(plane, DRM_MODE_ROTATE_0,
                                           SUPPORTED_ROTATIONS);
+       drm_plane_create_color_properties(plane,
+                                         BIT(DRM_COLOR_YCBCR_BT601) |
+                                         BIT(DRM_COLOR_YCBCR_BT709) |
+                                         BIT(DRM_COLOR_YCBCR_BT2020),
+                                         BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
+                                         BIT(DRM_COLOR_YCBCR_FULL_RANGE),
+                                         DRM_COLOR_YCBCR_BT709,
+                                         DRM_COLOR_YCBCR_LIMITED_RANGE);
 
        /*
         * Default frame buffer setup is with FB on -127, and raspistill etc
index 669a70f..0bdffe5 100644 (file)
@@ -4,6 +4,8 @@
  *
  * Values taken from vc_image_types.h released by Broadcom at
  * https://github.com/raspberrypi/userland/blob/master/interface/vctypes/vc_image_types.h
+ * and vc_image_structs.h at
+ * https://github.com/raspberrypi/userland/blob/master/interface/vctypes/vc_image_structs.h
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -141,3 +143,29 @@ enum {
        VC_IMAGE_MAX,     /* bounds for error checking */
        VC_IMAGE_FORCE_ENUM_16BIT = 0xffff,
 };
+
+enum {
+       /* Unknown or unset - defaults to BT601 interstitial */
+       VC_IMAGE_YUVINFO_UNSPECIFIED    = 0,
+
+       /* colour-space conversions data [4 bits] */
+
+       /* ITU-R BT.601-5 [SDTV] (compatible with VideoCore-II) */
+       VC_IMAGE_YUVINFO_CSC_ITUR_BT601      = 1,
+       /* ITU-R BT.709-3 [HDTV] */
+       VC_IMAGE_YUVINFO_CSC_ITUR_BT709      = 2,
+       /* JPEG JFIF */
+       VC_IMAGE_YUVINFO_CSC_JPEG_JFIF       = 3,
+       /* Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
+       VC_IMAGE_YUVINFO_CSC_FCC             = 4,
+       /* Society of Motion Picture and Television Engineers 240M (1999) */
+       VC_IMAGE_YUVINFO_CSC_SMPTE_240M      = 5,
+       /* ITU-R BT.470-2 System M */
+       VC_IMAGE_YUVINFO_CSC_ITUR_BT470_2_M  = 6,
+       /* ITU-R BT.470-2 System B,G */
+       VC_IMAGE_YUVINFO_CSC_ITUR_BT470_2_BG = 7,
+       /* JPEG JFIF, but with 16..255 luma */
+       VC_IMAGE_YUVINFO_CSC_JPEG_JFIF_Y16_255 = 8,
+       /* Rec 2020 */
+       VC_IMAGE_YUVINFO_CSC_REC_2020        = 9,
+};