From e76c252ac4800c9b7998405c33c7165eebe022f3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ville=20Syrj=C3=A4l=C3=A4?= Date: Thu, 15 Dec 2011 00:12:01 +0200 Subject: [PATCH] drm: Add drm_chroma_phase_offsets() utility function MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This function is is there to help driver writers. Signed-off-by: Ville Syrjälä Acked-by: Pauli Nieminen Reviewed-by: Jani Nikula Signed-off-by: Kirill A. Shutemov --- drivers/gpu/drm/drm_crtc_helper.c | 47 +++++++++++++++++++++++++++++++++++++++ include/drm/drm_crtc_helper.h | 3 +++ 2 files changed, 50 insertions(+) diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c index 52dacc5..836e2ae 100644 --- a/drivers/gpu/drm/drm_crtc_helper.c +++ b/drivers/gpu/drm/drm_crtc_helper.c @@ -1523,3 +1523,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 156aa10..128c5b7 100644 --- a/include/drm/drm_crtc_helper.h +++ b/include/drm/drm_crtc_helper.h @@ -182,5 +182,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 -- 2.7.4