[RFC PATCH 8/8] drm: Add drm_chroma_phase_offsets() utility function

ville.syrjala at linux.intel.com ville.syrjala at linux.intel.com
Mon Dec 19 14:33:31 PST 2011


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

This function is is there to help driver writers.

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

diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index 0153187..341f05c 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -1479,3 +1479,50 @@ void drm_plane_opts_defaults(struct drm_plane_opts *opts)
 	opts->const_alpha = 0xffff;
 }
 EXPORT_SYMBOL(drm_plane_opts_defaults);
+
+/**
+ * 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
+ * @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, uint8_t chroma_siting,
+			      bool second_chroma_plane)
+{
+	*ret_xoff = 0;
+	*ret_yoff = 0;
+
+	switch (chroma_siting & 0x3) {
+	case DRM_CHROMA_SITING_HORZ_LEFT:
+		break;
+	case DRM_CHROMA_SITING_HORZ_CENTER:
+		*ret_xoff -= (hsub - 1) * 0x8000 / hsub;
+		break;
+	}
+
+	switch (chroma_siting & 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_siting & DRM_CHROMA_SITING_MISALIGNED_PLANES))
+		*ret_yoff -= 0x8000;
+}
+EXPORT_SYMBOL(drm_chroma_phase_offsets);
diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
index e4946a5..58881f6 100644
--- a/include/drm/drm_crtc_helper.h
+++ b/include/drm/drm_crtc_helper.h
@@ -180,5 +180,8 @@ 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_plane_opts_defaults(struct drm_plane_opts *opts);
+extern void drm_chroma_phase_offsets(int *ret_xoff, int *ret_yoff,
+				     int hsub, int vsub, uint8_t chroma_siting,
+				     bool second_chroma_plane);
 
 #endif
-- 
1.7.3.4



More information about the dri-devel mailing list