[PATCH 2/2] drm: Redefine pixel formats

Ilyes Gouta ilyes.gouta at gmail.com
Wed Nov 16 11:16:31 PST 2011


Hi Ville,

Regarding 3 plane YCbCr, DRM_FORMAT_yuv444 (non sub-sampled YCbCr)
would also be useful.

-Ilyes

On Wed, Nov 16, 2011 at 7:42 PM,  <ville.syrjala at linux.intel.com> wrote:
> From: Ville Syrjälä <ville.syrjala at linux.intel.com>
>
> Name the formats as DRM_FORMAT_X instead of DRM_FOURCC_X. Use consistent
> names, especially for the RGB formats. Component order and byte order are
> now strictly specified for each format.
>
> The RGB format naming follows a convention where the components names
> and sizes are listed from left to right, matching the order within a
> single pixel from most significant bit to least significant bit. Lower
> case letters are used when listing the components to improve
> readablility. I believe this convention matches the one used by pixman.
>
> The YUV format names vary more. For the 4:2:2 packed formats and 2
> plane formats use the fourcc. For the three plane formats the
> name includes the plane order and subsampling information using the
> standard subsampling notation. Some of those also happen to match
> the official fourcc definition.
>
> The fourccs for for all the RGB formats and some of the YUV formats
> I invented myself. The idea was that looking at just the fourcc you
> get some idea what the format is about without having to decode it
> using some external reference.
>
> Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
> ---
>  drivers/gpu/drm/drm_crtc.c           |   18 +++---
>  drivers/gpu/drm/drm_crtc_helper.c    |   39 ++++++++++++--
>  drivers/gpu/drm/i915/intel_display.c |   18 ++++---
>  include/drm/drm_fourcc.h             |   96 ++++++++++++++++++++++++----------
>  4 files changed, 121 insertions(+), 50 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 30a70a4..761f265 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -1918,28 +1918,28 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
>
>        switch (bpp) {
>        case 8:
> -               fmt = DRM_FOURCC_RGB332;
> +               fmt = DRM_FORMAT_r3g3b2;
>                break;
>        case 16:
>                if (depth == 15)
> -                       fmt = DRM_FOURCC_RGB555;
> +                       fmt = DRM_FORMAT_x1r5g5b5;
>                else
> -                       fmt = DRM_FOURCC_RGB565;
> +                       fmt = DRM_FORMAT_r5g6b5;
>                break;
>        case 24:
> -               fmt = DRM_FOURCC_RGB24;
> +               fmt = DRM_FORMAT_r8g8b8;
>                break;
>        case 32:
>                if (depth == 24)
> -                       fmt = DRM_FOURCC_RGB24;
> +                       fmt = DRM_FORMAT_x8r8g8b8;
>                else if (depth == 30)
> -                       fmt = DRM_INTEL_RGB30;
> +                       fmt = DRM_FORMAT_x2r10g10b10;
>                else
> -                       fmt = DRM_FOURCC_RGB32;
> +                       fmt = DRM_FORMAT_a8r8g8b8;
>                break;
>        default:
> -               DRM_ERROR("bad bpp, assuming RGB24 pixel format\n");
> -               fmt = DRM_FOURCC_RGB24;
> +               DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
> +               fmt = DRM_FORMAT_x8r8g8b8;
>                break;
>        }
>
> diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
> index 3e0645c..4ef19d37 100644
> --- a/drivers/gpu/drm/drm_crtc_helper.c
> +++ b/drivers/gpu/drm/drm_crtc_helper.c
> @@ -816,27 +816,54 @@ void drm_helper_get_fb_bpp_depth(uint32_t format, unsigned int *depth,
>                                 int *bpp)
>  {
>        switch (format) {
> -       case DRM_FOURCC_RGB332:
> +       case DRM_FORMAT_r3g3b2:
> +       case DRM_FORMAT_b2g3r3:
>                *depth = 8;
>                *bpp = 8;
>                break;
> -       case DRM_FOURCC_RGB555:
> +       case DRM_FORMAT_x1r5g5b5:
> +       case DRM_FORMAT_x1b5g5r5:
> +       case DRM_FORMAT_r5g5b5x1:
> +       case DRM_FORMAT_b5g5r5x1:
> +       case DRM_FORMAT_a1r5g5b5:
> +       case DRM_FORMAT_a1b5g5r5:
> +       case DRM_FORMAT_r5g5b5a1:
> +       case DRM_FORMAT_b5g5r5a1:
>                *depth = 15;
>                *bpp = 16;
>                break;
> -       case DRM_FOURCC_RGB565:
> +       case DRM_FORMAT_r5g6b5:
> +       case DRM_FORMAT_b5g6r5:
>                *depth = 16;
>                *bpp = 16;
>                break;
> -       case DRM_FOURCC_RGB24:
> +       case DRM_FORMAT_r8g8b8:
> +       case DRM_FORMAT_b8g8r8:
> +               *depth = 24;
> +               *bpp = 24;
> +               break;
> +       case DRM_FORMAT_x8r8g8b8:
> +       case DRM_FORMAT_x8b8g8r8:
> +       case DRM_FORMAT_r8g8b8x8:
> +       case DRM_FORMAT_b8g8r8x8:
>                *depth = 24;
>                *bpp = 32;
>                break;
> -       case DRM_INTEL_RGB30:
> +       case DRM_FORMAT_x2r10g10b10:
> +       case DRM_FORMAT_x2b10g10r10:
> +       case DRM_FORMAT_r10g10b10x2:
> +       case DRM_FORMAT_b10g10r10x2:
> +       case DRM_FORMAT_a2r10g10b10:
> +       case DRM_FORMAT_a2b10g10r10:
> +       case DRM_FORMAT_r10g10b10a2:
> +       case DRM_FORMAT_b10g10r10a2:
>                *depth = 30;
>                *bpp = 32;
>                break;
> -       case DRM_FOURCC_RGB32:
> +       case DRM_FORMAT_a8r8g8b8:
> +       case DRM_FORMAT_a8b8g8r8:
> +       case DRM_FORMAT_r8g8b8a8:
> +       case DRM_FORMAT_b8g8r8a8:
>                *depth = 32;
>                *bpp = 32;
>                break;
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 50ae915..62c224a 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -7585,16 +7585,18 @@ int intel_framebuffer_init(struct drm_device *dev,
>                return -EINVAL;
>
>        switch (mode_cmd->pixel_format) {
> -       case DRM_FOURCC_RGB332:
> -       case DRM_FOURCC_RGB565:
> -       case DRM_FOURCC_RGB24:
> -       case DRM_INTEL_RGB30:
> +       case DRM_FORMAT_r3g3b2:
> +       case DRM_FORMAT_r5g6b5:
> +       case DRM_FORMAT_x8r8g8b8:
> +       case DRM_FORMAT_a8r8g8b8:
> +       case DRM_FORMAT_x2r10g10b10:
> +       case DRM_FORMAT_a2r10g10b10:
>                /* RGB formats are common across chipsets */
>                break;
> -       case DRM_FOURCC_YUYV:
> -       case DRM_FOURCC_UYVY:
> -       case DRM_FOURCC_YVYU:
> -       case DRM_FOURCC_VYUY:
> +       case DRM_FORMAT_yuyv:
> +       case DRM_FORMAT_uyvy:
> +       case DRM_FORMAT_yvyu:
> +       case DRM_FORMAT_vyuy:
>                break;
>        default:
>                DRM_ERROR("unsupported pixel format\n");
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> index 48c3d10..8192275 100644
> --- a/include/drm/drm_fourcc.h
> +++ b/include/drm/drm_fourcc.h
> @@ -24,40 +24,82 @@
>  #ifndef DRM_FOURCC_H
>  #define DRM_FOURCC_H
>
> -/*
> - * We don't use the V4L header because
> - * 1) the fourcc codes are well defined and trivial to construct
> - * 2) we don't want user apps to have to pull in v4l headers just for fourcc
> - * 3) the v4l fourcc codes are mixed up with a bunch of other code and are
> - *    part of the v4l API, so changing them to something linux-generic isn't
> - *    feasible
> - *
> - * So the below includes the fourcc codes used by the DRM and its drivers,
> - * along with potential device specific codes.
> - */
> -
>  #include <linux/types.h>
>
>  #define fourcc_code(a,b,c,d) ((u32)(a) | ((u32)(b) << 8) | \
>                              ((u32)(c) << 16) | ((u32)(d) << 24))
>
> -/* RGB codes */
> -#define DRM_FOURCC_RGB332 fourcc_code('R','G','B','1')
> -#define DRM_FOURCC_RGB555 fourcc_code('R','G','B','O')
> -#define DRM_FOURCC_RGB565 fourcc_code('R','G','B','P')
> -#define DRM_FOURCC_RGB24  fourcc_code('R','G','B','3')
> -#define DRM_FOURCC_RGB32  fourcc_code('R','G','B','4')
> +/* color index */
> +#define DRM_FORMAT_c8          fourcc_code('C','8',' ',' ') /* [7:0] C */
> +
> +/* 8 bpp RGB */
> +#define DRM_FORMAT_r3g3b2      fourcc_code('R','G','B','8') /* [7:0] R:G:B 3:3:2 */
> +#define DRM_FORMAT_b2g3r3      fourcc_code('B','G','R','8') /* [7:0] B:G:R 2:3:3 */
> +
> +/* 16 bpp RGB */
> +#define DRM_FORMAT_x4r4g4b4    fourcc_code('X','R','1','2') /* [15:0] x:R:G:B 4:4:4:4 native endian */
> +#define DRM_FORMAT_x4b4g4r4    fourcc_code('X','B','1','2') /* [15:0] x:B:G:R 4:4:4:4 native endian */
> +#define DRM_FORMAT_r4g4b4x4    fourcc_code('R','X','1','2') /* [15:0] R:G:B:x 4:4:4:4 native endian */
> +#define DRM_FORMAT_b4g4r4x4    fourcc_code('B','X','1','2') /* [15:0] B:G:R:x 4:4:4:4 native endian */
> +
> +#define DRM_FORMAT_x1r5g5b5    fourcc_code('X','R','1','5') /* [15:0] x:R:G:B 1:5:5:5 native endian */
> +#define DRM_FORMAT_x1b5g5r5    fourcc_code('X','B','1','5') /* [15:0] x:B:G:R 1:5:5:5 native endian */
> +#define DRM_FORMAT_r5g5b5x1    fourcc_code('R','X','1','5') /* [15:0] R:G:B:x 5:5:5:1 native endian */
> +#define DRM_FORMAT_b5g5r5x1    fourcc_code('B','X','1','5') /* [15:0] B:G:R:x 5:5:5:1 native endian */
> +
> +#define DRM_FORMAT_a1r5g5b5    fourcc_code('A','R','1','5') /* [15:0] A:R:G:B 1:5:5:5 native endian */
> +#define DRM_FORMAT_a1b5g5r5    fourcc_code('A','B','1','5') /* [15:0] A:B:G:R 1:5:5:5 native endian */
> +#define DRM_FORMAT_r5g5b5a1    fourcc_code('R','A','1','5') /* [15:0] R:G:B:A 5:5:5:1 native endian */
> +#define DRM_FORMAT_b5g5r5a1    fourcc_code('B','A','1','5') /* [15:0] B:G:R:A 5:5:5:1 native endian */
> +
> +#define DRM_FORMAT_r5g6b5      fourcc_code('R','G','1','6') /* [15:0] R:G:B 5:6:5 native endian */
> +#define DRM_FORMAT_b5g6r5      fourcc_code('B','G','1','6') /* [15:0] B:G:R 5:6:5 native endian */
> +
> +/* 24 bpp RGB */
> +#define DRM_FORMAT_r8g8b8      fourcc_code('R','G','2','4') /* [23:0] R:G:B native endian */
> +#define DRM_FORMAT_b8g8r8      fourcc_code('B','G','2','4') /* [23:0] B:G:R native endian */
> +
> +/* 32 bpp RGB */
> +#define DRM_FORMAT_x8r8g8b8    fourcc_code('X','R','2','4') /* [31:0] x:R:G:B 8:8:8:8 native endian */
> +#define DRM_FORMAT_x8b8g8r8    fourcc_code('X','B','2','4') /* [31:0] x:B:G:R 8:8:8:8 native endian */
> +#define DRM_FORMAT_r8g8b8x8    fourcc_code('R','X','2','4') /* [31:0] R:G:B:x 8:8:8:8 native endian */
> +#define DRM_FORMAT_b8g8r8x8    fourcc_code('B','X','2','4') /* [31:0] B:G:R:x 8:8:8:8 native endian */
> +
> +#define DRM_FORMAT_a8r8g8b8    fourcc_code('A','R','2','4') /* [31:0] A:R:G:B 8:8:8:8 native endian */
> +#define DRM_FORMAT_a8b8g8r8    fourcc_code('A','B','2','4') /* [31:0] A:B:G:R 8:8:8:8 native endian */
> +#define DRM_FORMAT_r8g8b8a8    fourcc_code('R','A','2','4') /* [31:0] R:G:B:A 8:8:8:8 native endian */
> +#define DRM_FORMAT_b8g8r8a8    fourcc_code('B','A','2','4') /* [31:0] B:G:R:A 8:8:8:8 native endian */
> +
> +#define DRM_FORMAT_x2r10g10b10 fourcc_code('X','R','3','0') /* [31:0] x:R:G:B 2:10:10:10 native endian */
> +#define DRM_FORMAT_x2b10g10r10 fourcc_code('X','B','3','0') /* [31:0] x:B:G:R 2:10:10:10 native endian */
> +#define DRM_FORMAT_r10g10b10x2 fourcc_code('R','X','3','0') /* [31:0] R:G:B:x 10:10:10:2 native endian */
> +#define DRM_FORMAT_b10g10r10x2 fourcc_code('B','X','3','0') /* [31:0] B:G:R:x 10:10:10:2 native endian */
> +
> +#define DRM_FORMAT_a2r10g10b10 fourcc_code('A','R','3','0') /* [31:0] A:R:G:B 2:10:10:10 native endian */
> +#define DRM_FORMAT_a2b10g10r10 fourcc_code('A','B','3','0') /* [31:0] A:B:G:R 2:10:10:10 native endian */
> +#define DRM_FORMAT_r10g10b10a2 fourcc_code('R','A','3','0') /* [31:0] R:G:B:A 10:10:10:2 native endian */
> +#define DRM_FORMAT_b10g10r10a2 fourcc_code('B','A','3','0') /* [31:0] B:G:R:A 10:10:10:2 native endian */
>
> -#define DRM_FOURCC_BGR24  fourcc_code('B','G','R','3')
> -#define DRM_FOURCC_BGR32  fourcc_code('B','G','R','4')
> +/* packed YCbCr */
> +#define DRM_FORMAT_yuyv                fourcc_code('Y', 'U', 'Y', 'V') /* [31:0] Cr:Y1:Cb:Y0 8:8:8:8 little endian */
> +#define DRM_FORMAT_yvyu                fourcc_code('Y', 'V', 'Y', 'U') /* [31:0] Cb:Y1:Cr:Y0 8:8:8:8 little endian */
> +#define DRM_FORMAT_uyvy                fourcc_code('U', 'Y', 'V', 'Y') /* [31:0] Y1:Cr:Y0:Cb 8:8:8:8 little endian */
> +#define DRM_FORMAT_vyuy                fourcc_code('V', 'Y', 'U', 'Y') /* [31:0] Y1:Cb:Y0:Cr 8:8:8:8 little endian */
>
> -/* YUV codes */
> -#define DRM_FOURCC_YUYV   fourcc_code('Y', 'U', 'Y', 'V')
> -#define DRM_FOURCC_YVYU   fourcc_code('Y', 'V', 'Y', 'U')
> -#define DRM_FOURCC_UYVY   fourcc_code('U', 'Y', 'V', 'Y')
> -#define DRM_FOURCC_VYUY   fourcc_code('V', 'Y', 'U', 'Y')
> +/* 2 plane YCbCr */
> +#define DRM_FORMAT_nv12                fourcc_code('N', 'V', '1', '2') /* Y plane and 2x2 subsampled [15:0] Cr:Cb 8:8 little endian plane */
> +#define DRM_FORMAT_nv21                fourcc_code('N', 'V', '2', '1') /* Y plane and 2x2 subsampled [15:0] Cb:Cr 8:8 little endian plane */
> +#define DRM_FORMAT_nv16                fourcc_code('N', 'V', '1', '6') /* Y plane and 2x1 subsampled [15:0] Cr:Cb 8:8 little endian plane */
> +#define DRM_FORMAT_nv61                fourcc_code('N', 'V', '6', '1') /* Y plane and 2x1 subsampled [15:0] Cb:Cr 8:8 little endian plane */
>
> -/* DRM specific codes */
> -#define DRM_INTEL_RGB30   fourcc_code('R','G','B','0') /* RGB x:10:10:10 */
> +/* 3 plane YCbCr */
> +#define DRM_FORMAT_yuv410      fourcc_code('Y', 'U', 'V', '9') /* Y plane and 4x4 subsampled Cb and Cr planes */
> +#define DRM_FORMAT_yvu410      fourcc_code('Y', 'V', 'U', '9') /* Y plane and 4x4 subsampled Cr and Cb planes */
> +#define DRM_FORMAT_yuv411      fourcc_code('Y', 'U', '1', '1') /* Y plane and 4x1 subsampled Cb and Cr planes */
> +#define DRM_FORMAT_yvu411      fourcc_code('Y', 'V', '1', '1') /* Y plane and 4x1 subsampled Cr and Cb planes */
> +#define DRM_FORMAT_yuv420      fourcc_code('Y', 'U', '1', '2') /* Y plane and 2x2 subsampled Cb and Cr planes */
> +#define DRM_FORMAT_yvu420      fourcc_code('Y', 'V', '1', '2') /* Y plane and 2x2 subsampled Cr and Cb planes */
> +#define DRM_FORMAT_yuv422      fourcc_code('Y', 'U', '1', '6') /* Y plane and 2x1 subsampled Cb and Cr planes */
> +#define DRM_FORMAT_yvu422      fourcc_code('Y', 'V', '1', '6') /* Y plane and 2x1 subsampled Cr and Cb planes */
>
>  #endif /* DRM_FOURCC_H */
> --
> 1.7.3.4
>
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
>


More information about the dri-devel mailing list