[RFC][PATCH 7/7] drm: Add CSC helper stuff

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


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

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

diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index 490b7bc..b06465c 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -1482,3 +1482,51 @@ int drm_calc_vscale(struct drm_region *src, struct drm_region *dst,
 	return vscale;
 }
 EXPORT_SYMBOL(drm_calc_vscale);
+
+/**
+ * drm_chroma_phase_offsets - calculate the chroma phase offsets
+ * @ret_xoff: returned horizontal offset (16.16)
+ * @ret_yoff: returned vertical offset (16.16)
+ * @hsub: horizontal chroma subsampling factor
+ * @vsub: vertical chroma subsampling factor
+ * @chroma: chroma siting information (@drm_chroma_siting)
+ * @second_chroma_plane: first or second chroma plane?
+ *
+ * Calculates the phase offset between chroma and luma pixel centers,
+ * based on infromation provided in @chroma, @hsub, @vsub, and
+ * @second_chroma_plane.
+ *
+ * RETURNS:
+ * The chroma phase offsets in 16.16 format. The returned
+ * phase offsets are in chroma (ie. subsampled) coordinate space.
+ */
+void drm_chroma_phase_offsets(int *ret_xoff, int *ret_yoff,
+			      int hsub, int vsub,
+			      enum drm_chroma_siting chroma,
+			      bool second_chroma_plane)
+{
+	*ret_xoff = 0;
+	*ret_yoff = 0;
+
+	switch (chroma & 0x3) {
+	case DRM_CHROMA_SITING_HORZ_LEFT:
+		break;
+	case DRM_CHROMA_SITING_HORZ_CENTER:
+		*ret_xoff -= (hsub - 1) * 0x8000 / hsub;
+		break;
+	}
+
+	switch (chroma & 0xc0) {
+	case DRM_CHROMA_SITING_VERT_TOP:
+		break;
+	case DRM_CHROMA_SITING_VERT_CENTER:
+		*ret_yoff -= (vsub - 1) * 0x8000 / vsub;
+		break;
+	}
+
+	/* Chroma planes out of phase by 0.5 chroma lines? */
+	if (second_chroma_plane &&
+	    (chroma & DRM_CHROMA_SITING_MISALIGNED_PLANES))
+		*ret_yoff -= 0x8000;
+}
+EXPORT_SYMBOL(drm_chroma_phase_offsets);
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 736d68d..55ff998 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -903,4 +903,59 @@ extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
 				      void *data, struct drm_file *file_priv);
 
+/**
+ * drm_csc_range - indicates the valid range for color values
+ * @DRM_CSC_RANGE_UNKNOWN: not specified, implementation defined result
+ * @DRM_CSC_RANGE_MPEG: "MPEG" range (16-235 for Y, 16-240 for Cb/Cr)
+ * @DRM_CSC_RANGE_JPEG: "JPEG" or full range (0-255 for Y/Cb/Cr)
+ */
+enum drm_csc_range {
+	DRM_CSC_RANGE_UNKNOWN = 0x0,
+
+	DRM_CSC_RANGE_MPEG    = 0x1,
+	DRM_CSC_RANGE_JPEG    = 0x2,
+};
+
+/**
+ * drm_csc_matrix - specifies the color space conversion matrix
+ * @DRM_CSC_MATRIX_UNKNOWN: not specified, implementation defined result
+ * @DRM_CSC_MATRIX_BT601: ITU-R BT.601
+ * @DRM_CSC_MATRIX_BT709: ITU-R BT.709
+ */
+enum drm_csc_matrix {
+	DRM_CSC_MATRIX_UNKNOWN = 0x0,
+
+	DRM_CSC_MATRIX_BT601   = 0x1,
+	DRM_CSC_MATRIX_BT709   = 0x2,
+};
+
+/**
+ * drm_chroma_siting - chroma siting information
+ * @DRM_CHROMA_SITING_UNKNOWN: not specified, implementation defined result
+ * @DRM_CHROMA_SITING_HORZ_LEFT: horizontally co-sited with the left luma sample
+ * @DRM_CHROMA_SITING_HORZ_CENTER: horizontally interstitially sited with luma samples
+ * @DRM_CHROMA_SITING_VERT_TOP: vertically co-sited with the top luma sample
+ * @DRM_CHROMA_SITING_VERT_CENTER: vertically interstitially sited with luma samples
+ * @DRM_CHROMA_SITING_MISALIGNED_PLANES: chroma planes out of phase with each other by 0.5 lines
+ * @DRM_CHROMA_SITING_MPEG1: chroma siting convention used in MPEG1
+ * @DRM_CHROMA_SITING_MPEG2: chroma siting convention used in MPEG2
+ * @DRM_CHROMA_SITING_DV: chroma siting convention used in DV
+ */
+enum drm_chroma_siting {
+	DRM_CHROMA_SITING_UNKNOWN     = 0x0,
+
+	DRM_CHROMA_SITING_HORZ_LEFT   = 0x1,
+	DRM_CHROMA_SITING_HORZ_CENTER = 0x2,
+
+	DRM_CHROMA_SITING_VERT_TOP    = 0x4,
+	DRM_CHROMA_SITING_VERT_CENTER = 0x8,
+
+	DRM_CHROMA_SITING_MISALIGNED_PLANES = 0x10,
+
+	/* typical configurations */
+	DRM_CHROMA_SITING_MPEG1 = DRM_CHROMA_SITING_HORZ_CENTER | DRM_CHROMA_SITING_VERT_CENTER,
+	DRM_CHROMA_SITING_MPEG2 = DRM_CHROMA_SITING_HORZ_LEFT | DRM_CHROMA_SITING_VERT_CENTER,
+	DRM_CHROMA_SITING_DV    = DRM_CHROMA_SITING_HORZ_LEFT | DRM_CHROMA_SITING_VERT_TOP | DRM_CHROMA_SITING_MISALIGNED_PLANES,
+};
+
 #endif /* __DRM_CRTC_H__ */
diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
index e23aa02..7541f96 100644
--- a/include/drm/drm_crtc_helper.h
+++ b/include/drm/drm_crtc_helper.h
@@ -182,4 +182,9 @@ extern int drm_calc_hscale(struct drm_region *src, struct drm_region *dst,
 extern int drm_calc_vscale(struct drm_region *src, struct drm_region *dst,
 			   int min_vscale, int max_vscale);
 
+extern void drm_chroma_phase_offsets(int *ret_xoff, int *ret_yoff,
+				     int hsub, int vsub,
+				     enum drm_chroma_siting chroma,
+				     bool second_chroma_plane);
+
 #endif
-- 
1.7.3.4



More information about the dri-devel mailing list