diff options
author | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2010-03-15 13:40:38 +0100 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2010-03-15 13:41:56 +0100 |
commit | a7a0afa5c4f9a98631b639998bbb3be91b00f978 (patch) | |
tree | 4bc9a488a9824dc9b9e4ea116f6774a25dc6117a /ext/cairo | |
parent | ba6dbaecfc4beb7d9749cb613defcf6c4c05e522 (diff) |
cairotextoverlay: Don't render text outside the frame boundaries
Fixes bug #611986.
Diffstat (limited to 'ext/cairo')
-rw-r--r-- | ext/cairo/gsttextoverlay.c | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/ext/cairo/gsttextoverlay.c b/ext/cairo/gsttextoverlay.c index 6bdd6fd9e..bceb5fe70 100644 --- a/ext/cairo/gsttextoverlay.c +++ b/ext/cairo/gsttextoverlay.c @@ -665,41 +665,46 @@ gst_text_overlay_shade_y (GstCairoTextOverlay * overlay, guchar * dest, static inline void gst_text_overlay_blit_1 (GstCairoTextOverlay * overlay, guchar * dest, - guchar * text_image, gint val, guint dest_stride) + guchar * text_image, gint val, guint dest_stride, gint y0) { gint i, j; gint x, a, y; - gint y0 = 0; + gint y1; y = val; + y0 = MIN (y0, overlay->height); + y1 = MIN (y0 + overlay->font_height, overlay->height); - for (i = 0; i < overlay->font_height; i++) { + for (i = y0; i < y1; i++) { for (j = 0; j < overlay->width; j++) { - x = dest[(i + y0) * dest_stride + j]; - a = text_image[4 * (i * overlay->width + j) + 1]; - dest[(i + y0) * dest_stride + j] = (y * a + x * (255 - a)) / 255; + x = dest[i * dest_stride + j]; + a = text_image[4 * ((i - y0) * overlay->width + j) + 1]; + dest[i * dest_stride + j] = (y * a + x * (255 - a)) / 255; } } } static inline void gst_text_overlay_blit_sub2x2 (GstCairoTextOverlay * overlay, guchar * dest, - guchar * text_image, gint val, guint dest_stride) + guchar * text_image, gint val, guint dest_stride, gint y0) { gint i, j; gint x, a, y; - gint y0 = 0; + gint y1; + + y0 = MIN (y0, overlay->height); + y1 = MIN (y0 + overlay->font_height, overlay->height); y = val; - for (i = 0; i < overlay->font_height; i += 2) { + for (i = y0; i < y1; i += 2) { for (j = 0; j < overlay->width; j += 2) { - x = dest[(i / 2 + y0) * dest_stride + j / 2]; - a = (text_image[4 * (i * overlay->width + j) + 1] + - text_image[4 * (i * overlay->width + j + 1) + 1] + - text_image[4 * ((i + 1) * overlay->width + j) + 1] + - text_image[4 * ((i + 1) * overlay->width + j + 1) + 1] + 2) / 4; - dest[(i / 2 + y0) * dest_stride + j / 2] = (y * a + x * (255 - a)) / 255; + x = dest[(i / 2) * dest_stride + j / 2]; + a = (text_image[4 * ((i - y0) * overlay->width + j) + 1] + + text_image[4 * ((i - y0) * overlay->width + j + 1) + 1] + + text_image[4 * ((i - y0 + 1) * overlay->width + j) + 1] + + text_image[4 * ((i - y0 + 1) * overlay->width + j + 1) + 1] + 2) / 4; + dest[(i / 2) * dest_stride + j / 2] = (y * a + x * (255 - a)) / 255; } } } @@ -745,25 +750,25 @@ gst_text_overlay_push_frame (GstCairoTextOverlay * overlay, /* blit outline text on video image */ gst_text_overlay_blit_1 (overlay, - y + (ypos / 1) * I420_Y_ROWSTRIDE (overlay->width), - overlay->text_outline_image, 0, I420_Y_ROWSTRIDE (overlay->width)); - gst_text_overlay_blit_sub2x2 (overlay, - u + (ypos / 2) * I420_U_ROWSTRIDE (overlay->width), - overlay->text_outline_image, 128, I420_U_ROWSTRIDE (overlay->width)); + y, + overlay->text_outline_image, 0, I420_Y_ROWSTRIDE (overlay->width), ypos); gst_text_overlay_blit_sub2x2 (overlay, - v + (ypos / 2) * I420_V_ROWSTRIDE (overlay->width), - overlay->text_outline_image, 128, I420_V_ROWSTRIDE (overlay->width)); + u, + overlay->text_outline_image, 128, I420_U_ROWSTRIDE (overlay->width), + ypos); + gst_text_overlay_blit_sub2x2 (overlay, v, overlay->text_outline_image, 128, + I420_V_ROWSTRIDE (overlay->width), ypos); /* blit text on video image */ gst_text_overlay_blit_1 (overlay, - y + (ypos / 1) * I420_Y_ROWSTRIDE (overlay->width), - overlay->text_fill_image, 255, I420_Y_ROWSTRIDE (overlay->width)); + y, + overlay->text_fill_image, 255, I420_Y_ROWSTRIDE (overlay->width), ypos); gst_text_overlay_blit_sub2x2 (overlay, - u + (ypos / 2) * I420_U_ROWSTRIDE (overlay->width), - overlay->text_fill_image, 128, I420_U_ROWSTRIDE (overlay->width)); + u, + overlay->text_fill_image, 128, I420_U_ROWSTRIDE (overlay->width), ypos); gst_text_overlay_blit_sub2x2 (overlay, - v + (ypos / 2) * I420_V_ROWSTRIDE (overlay->width), - overlay->text_fill_image, 128, I420_V_ROWSTRIDE (overlay->width)); + v, + overlay->text_fill_image, 128, I420_V_ROWSTRIDE (overlay->width), ypos); return gst_pad_push (overlay->srcpad, video_frame); } |