From 54f4aa28c227825e48fd7940b3566630a10cffe9 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Mon, 30 Aug 2010 14:59:22 -0500 Subject: [PATCH] textoverlay: fix Cb/Cr inversion for colored text overlays In case of odd values for xpos or ypos, the division by two in CbCr plane would result in an off-by-one error, which in the case of NV12, NV21, or UYVY would cause inversion of blue and red colors. (And would be not so easily noticed for I420 as it would just cause the chroma to be offset slightly from the luma.) This patch also fixes a silly typo from the earlier patch which added NV12 support that broke UYVY support. --- ext/pango/gsttextoverlay.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ext/pango/gsttextoverlay.c b/ext/pango/gsttextoverlay.c index df5701f..aa492e9 100644 --- a/ext/pango/gsttextoverlay.c +++ b/ext/pango/gsttextoverlay.c @@ -186,7 +186,7 @@ static GstStaticPadTemplate src_template_factory = GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx ";" - GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_YUV ("{I420, UYUV, NV12, NV21}")) + GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_YUV ("{I420, UYVY, NV12, NV21}")) ); static GstStaticPadTemplate video_sink_template_factory = @@ -194,7 +194,7 @@ static GstStaticPadTemplate video_sink_template_factory = GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx ";" - GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_YUV ("{I420, UYUV, NV12, NV21}")) + GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_YUV ("{I420, UYVY, NV12, NV21}")) ); static GstStaticPadTemplate text_sink_template_factory = @@ -1450,6 +1450,12 @@ gst_text_overlay_blit_NV12_NV21 (GstTextOverlay * overlay, int u_offset, v_offset; int h, w; + /* because U/V is 2x2 subsampled, we need to round, either up or down, + * to a boundary of integer number of U/V pixels: + */ + xpos = GST_ROUND_UP_2 (xpos); + ypos = GST_ROUND_UP_2 (ypos); + w = overlay->width; h = overlay->height; @@ -1473,6 +1479,12 @@ gst_text_overlay_blit_I420 (GstTextOverlay * overlay, int u_offset, v_offset; int h, w; + /* because U/V is 2x2 subsampled, we need to round, either up or down, + * to a boundary of integer number of U/V pixels: + */ + xpos = GST_ROUND_UP_2 (xpos); + ypos = GST_ROUND_UP_2 (ypos); + w = overlay->width; h = overlay->height; @@ -1502,6 +1514,11 @@ gst_text_overlay_blit_UYVY (GstTextOverlay * overlay, int h, w; guchar *pimage, *dest; + /* because U/V is 2x horizontally subsampled, we need to round to a + * boundary of integer number of U/V pixels in x dimension: + */ + xpos = GST_ROUND_UP_2 (xpos); + w = overlay->image_width - 2; h = overlay->image_height - 2; -- 2.7.4