summaryrefslogtreecommitdiff
blob: 8c0c423a48aa2289b45ce87766c813faf5b90087 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
From 8cd575c6c2f46464d7704e07102a648bba08a6c6 Mon Sep 17 00:00:00 2001
From: Rob Clark <rob@ti.com>
Date: Mon, 23 Aug 2010 14:01:14 -0500
Subject: [PATCH 18/24] textoverlay: add stride support

---
 ext/pango/gsttextoverlay.c |   37 +++++++++++++++++++++++++------------
 ext/pango/gsttextoverlay.h |    1 +
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/ext/pango/gsttextoverlay.c b/ext/pango/gsttextoverlay.c
index 915a59c..1bf3638 100644
--- a/ext/pango/gsttextoverlay.c
+++ b/ext/pango/gsttextoverlay.c
@@ -187,7 +187,7 @@ static GstStaticPadTemplate src_template_factory =
     GST_PAD_ALWAYS,
     GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx ";"
         GST_VIDEO_CAPS_xRGB ";"
-        GST_VIDEO_CAPS_YUV ("{AYUV, I420, UYVY, NV12, NV21}"))
+        GST_VIDEO_CAPS_YUV_STRIDED ("{AYUV, I420, UYVY, NV12, NV21}", "[0, max]"))
     );
 
 static GstStaticPadTemplate video_sink_template_factory =
@@ -196,7 +196,7 @@ static GstStaticPadTemplate video_sink_template_factory =
     GST_PAD_ALWAYS,
     GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx ";"
         GST_VIDEO_CAPS_xRGB ";"
-        GST_VIDEO_CAPS_YUV ("{AYUV, I420, UYVY, NV12, NV21}"))
+        GST_VIDEO_CAPS_YUV_STRIDED ("{AYUV, I420, UYVY, NV12, NV21}", "[0, max]"))
     );
 
 static GstStaticPadTemplate text_sink_template_factory =
@@ -724,12 +724,13 @@ gst_text_overlay_setcaps (GstPad * pad, GstCaps * caps)
 
   overlay->width = 0;
   overlay->height = 0;
+  overlay->rowstride = 0;
   structure = gst_caps_get_structure (caps, 0);
   fps = gst_structure_get_value (structure, "framerate");
 
   if (fps
-      && gst_video_format_parse_caps (caps, &overlay->format, &overlay->width,
-          &overlay->height)) {
+      && gst_video_format_parse_caps_strided (caps, &overlay->format, &overlay->width,
+          &overlay->height, &overlay->rowstride)) {
     ret = gst_pad_set_caps (overlay->srcpad, caps);
   }
 
@@ -1364,14 +1365,21 @@ gst_text_overlay_render_pangocairo (GstTextOverlay * overlay,
 #define BOX_XPAD         6
 #define BOX_YPAD         6
 
+static gint
+gst_text_overlay_get_stride (GstTextOverlay * overlay, gint component)
+{
+  if (overlay->rowstride)
+    return overlay->rowstride;
+  return gst_video_format_get_row_stride (overlay->format, 0, overlay->width);
+}
+
 static inline void
 gst_text_overlay_shade_planar_Y (GstTextOverlay * overlay, guchar * dest,
     gint x0, gint x1, gint y0, gint y1)
 {
   gint i, j, dest_stride;
 
-  dest_stride = gst_video_format_get_row_stride (overlay->format, 0,
-      overlay->width);
+  dest_stride = gst_text_overlay_get_stride (overlay, 0);
 
   x0 = CLAMP (x0 - BOX_XPAD, 0, overlay->width);
   x1 = CLAMP (x1 + BOX_XPAD, 0, overlay->width);
@@ -1436,7 +1444,9 @@ static inline void
 gst_text_overlay_shade_xRGB (GstTextOverlay * overlay, guchar * dest,
     gint x0, gint x1, gint y0, gint y1)
 {
-  gint i, j;
+  gint i, j, dest_stride;
+
+  dest_stride = gst_text_overlay_get_stride (overlay, 0);
 
   x0 = CLAMP (x0 - BOX_XPAD, 0, overlay->width);
   x1 = CLAMP (x1 + BOX_XPAD, 0, overlay->width);
@@ -1448,7 +1458,7 @@ gst_text_overlay_shade_xRGB (GstTextOverlay * overlay, guchar * dest,
     for (j = x0; j < x1; j++) {
       gint y, y_pos, k;
 
-      y_pos = (i * 4 * overlay->width) + j * 4;
+      y_pos = (i * dest_stride) + j * 4;
       for (k = 0; k < 4; k++) {
         y = dest[y_pos + k] + overlay->shading_value;
         dest[y_pos + k] = CLAMP (y, 0, 255);
@@ -1480,10 +1490,10 @@ gst_text_overlay_blit_NV12_NV21 (GstTextOverlay * overlay,
   w = overlay->width;
   h = overlay->height;
 
-  y_stride = gst_video_format_get_row_stride (overlay->format, 0, w);
-  uv_stride = gst_video_format_get_row_stride (overlay->format, 1, w);
-  u_offset = gst_video_format_get_component_offset (overlay->format, 1, w, h);
-  v_offset = gst_video_format_get_component_offset (overlay->format, 2, w, h);
+  y_stride = gst_text_overlay_get_stride (overlay, 0);
+  uv_stride = gst_text_overlay_get_stride (overlay, 1);
+  u_offset = gst_video_format_get_component_offset (overlay->format, 1, y_stride, h);
+  v_offset = gst_video_format_get_component_offset (overlay->format, 2, y_stride, h);
 
   gst_text_overlay_blit_1 (overlay, yuv_pixels, xpos, ypos, overlay->text_image,
       y_stride);
@@ -1509,6 +1519,9 @@ gst_text_overlay_blit_I420 (GstTextOverlay * overlay,
   w = overlay->width;
   h = overlay->height;
 
+  /* XXX this is not updated for rowstride.. but rowstride could be
+   * ambiguous for I420.. is the U and V plane rowstride or rowstride/2?
+   */
   y_stride = gst_video_format_get_row_stride (GST_VIDEO_FORMAT_I420, 0, w);
   u_stride = gst_video_format_get_row_stride (GST_VIDEO_FORMAT_I420, 1, w);
   v_stride = gst_video_format_get_row_stride (GST_VIDEO_FORMAT_I420, 2, w);
diff --git a/ext/pango/gsttextoverlay.h b/ext/pango/gsttextoverlay.h
index 5fddf3a..bc2940b 100644
--- a/ext/pango/gsttextoverlay.h
+++ b/ext/pango/gsttextoverlay.h
@@ -112,6 +112,7 @@ struct _GstTextOverlay {
 
     gint                     width;
     gint                     height;
+    gint                     rowstride;
     gint                     fps_n;
     gint                     fps_d;
     GstVideoFormat           format;
-- 
1.7.1