[RFC][PATCH 3/7] drm: Add drm_format_{horz, vert}_chroma_subsampling() utility functions

ville.syrjala at linux.intel.com ville.syrjala at linux.intel.com
Fri Nov 11 09:07:15 PST 2011


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

These functions return the chroma subsampling factors for the specified
pixel format.

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 drivers/gpu/drm/drm_crtc_helper.c |   67 +++++++++++++++++++++++++++++++++++++
 include/drm/drm_crtc_helper.h     |    2 +
 2 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index 7c5c516..1528068 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -1087,3 +1087,70 @@ int drm_format_plane_cpp(uint32_t format, int plane)
 	}
 }
 EXPORT_SYMBOL(drm_format_plane_cpp);
+
+/**
+ * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
+ * @format: pixel format (V4L2_PIX_FMT_*)
+ *
+ * See linux/videodev2.h for valid values of @format.
+ *
+ * RETURNS:
+ * The horizontal chroma subsampling factor for the
+ * specified pixel format.
+ */
+int drm_format_horz_chroma_subsampling(uint32_t format)
+{
+	/* FIXME add all subsampled formats. */
+
+	switch (format) {
+	case V4L2_PIX_FMT_Y41P:
+	case V4L2_PIX_FMT_YUV411P:
+	case V4L2_PIX_FMT_YUV410:
+	case V4L2_PIX_FMT_YVU410:
+		return 4;
+	case V4L2_PIX_FMT_YUYV:
+	case V4L2_PIX_FMT_YVYU:
+	case V4L2_PIX_FMT_UYVY:
+	case V4L2_PIX_FMT_VYUY:
+	case V4L2_PIX_FMT_YUV422P:
+	case V4L2_PIX_FMT_YUV420:
+	case V4L2_PIX_FMT_YVU420:
+	case V4L2_PIX_FMT_NV12:
+	case V4L2_PIX_FMT_NV21:
+	case V4L2_PIX_FMT_NV16:
+	case V4L2_PIX_FMT_NV61:
+		return 2;
+	default:
+		return 1;
+	}
+}
+EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
+
+/**
+ * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
+ * @format: pixel format (V4L2_PIX_FMT_*)
+ *
+ * See linux/videodev2.h for valid values of @format.
+ *
+ * RETURNS:
+ * The vertical chroma subsampling factor for the
+ * specified pixel format.
+ */
+int drm_format_vert_chroma_subsampling(uint32_t format)
+{
+	/* FIXME add all subsampled formats. */
+
+	switch (format) {
+	case V4L2_PIX_FMT_YUV410:
+	case V4L2_PIX_FMT_YVU410:
+		return 4;
+	case V4L2_PIX_FMT_YUV420:
+	case V4L2_PIX_FMT_YVU420:
+	case V4L2_PIX_FMT_NV12:
+	case V4L2_PIX_FMT_NV21:
+		return 2;
+	default:
+		return 1;
+	}
+}
+EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
index 9996643..25d46b8 100644
--- a/include/drm/drm_crtc_helper.h
+++ b/include/drm/drm_crtc_helper.h
@@ -149,5 +149,7 @@ extern void drm_kms_helper_poll_enable(struct drm_device *dev);
 
 extern int drm_format_num_planes(uint32_t format);
 extern int drm_format_plane_cpp(uint32_t format, int plane);
+extern int drm_format_horz_chroma_subsampling(uint32_t format);
+extern int drm_format_vert_chroma_subsampling(uint32_t format);
 
 #endif
-- 
1.7.3.4



More information about the dri-devel mailing list