summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Hervey <bilboed@bilboed.com>2014-12-15 14:10:17 +0100
committerEdward Hervey <bilboed@bilboed.com>2014-12-15 14:25:38 +0100
commit899461d722e45f591eeddf33c405677170d63de4 (patch)
tree1639cb80e9ff1ee4e7e5f4f0a53139a9c0a5cd4b
parent7196edf244f98ec0b90ba6b9af4dc880c764d10b (diff)
video: Fix non-default usage of gst_video_sink_center_rect
Make sure we take into account non-0 x/y destination rectangles
-rw-r--r--gst-libs/gst/video/gstvideosink.c16
-rw-r--r--tests/check/libs/video.c61
2 files changed, 69 insertions, 8 deletions
diff --git a/gst-libs/gst/video/gstvideosink.c b/gst-libs/gst/video/gstvideosink.c
index 47045933a..26b7df21c 100644
--- a/gst-libs/gst/video/gstvideosink.c
+++ b/gst-libs/gst/video/gstvideosink.c
@@ -87,8 +87,8 @@ gst_video_sink_center_rect (GstVideoRectangle src, GstVideoRectangle dst,
if (!scaling) {
result->w = MIN (src.w, dst.w);
result->h = MIN (src.h, dst.h);
- result->x = (dst.w - result->w) / 2;
- result->y = (dst.h - result->h) / 2;
+ result->x = dst.x + (dst.w - result->w) / 2;
+ result->y = dst.y + (dst.h - result->h) / 2;
} else {
gdouble src_ratio, dst_ratio;
@@ -98,16 +98,16 @@ gst_video_sink_center_rect (GstVideoRectangle src, GstVideoRectangle dst,
if (src_ratio > dst_ratio) {
result->w = dst.w;
result->h = dst.w / src_ratio;
- result->x = 0;
- result->y = (dst.h - result->h) / 2;
+ result->x = dst.x;
+ result->y = dst.y + (dst.h - result->h) / 2;
} else if (src_ratio < dst_ratio) {
result->w = dst.h * src_ratio;
result->h = dst.h;
- result->x = (dst.w - result->w) / 2;
- result->y = 0;
+ result->x = dst.x + (dst.w - result->w) / 2;
+ result->y = dst.y;
} else {
- result->x = 0;
- result->y = 0;
+ result->x = dst.x;
+ result->y = dst.y;
result->w = dst.w;
result->h = dst.h;
}
diff --git a/tests/check/libs/video.c b/tests/check/libs/video.c
index d7cac0673..b8e5ba084 100644
--- a/tests/check/libs/video.c
+++ b/tests/check/libs/video.c
@@ -1693,6 +1693,66 @@ GST_START_TEST (test_overlay_composition_global_alpha)
GST_END_TEST;
+
+GST_START_TEST (test_video_center_rect)
+{
+ GstVideoRectangle src, dest, result, expected;
+
+#define NEW_RECT(x,y,w,h) ((GstVideoRectangle) {x,y,w,h})
+#define CHECK_RECT(res, exp) \
+ fail_unless_equals_int(exp.x, res.x);\
+ fail_unless_equals_int(exp.y, res.y);\
+ fail_unless_equals_int(exp.w, res.w);\
+ fail_unless_equals_int(exp.h, res.h);
+
+ /* 1:1 Aspect Ratio */
+ src = NEW_RECT (0, 0, 100, 100);
+ dest = NEW_RECT (0, 0, 100, 100);
+ expected = NEW_RECT (0, 0, 100, 100);
+ gst_video_sink_center_rect (src, dest, &result, TRUE);
+ CHECK_RECT (result, expected);
+
+ src = NEW_RECT (0, 0, 100, 100);
+ dest = NEW_RECT (0, 0, 50, 50);
+ expected = NEW_RECT (0, 0, 50, 50);
+ gst_video_sink_center_rect (src, dest, &result, TRUE);
+ CHECK_RECT (result, expected);
+
+ src = NEW_RECT (0, 0, 100, 100);
+ dest = NEW_RECT (50, 50, 100, 100);
+ expected = NEW_RECT (50, 50, 100, 100);
+ gst_video_sink_center_rect (src, dest, &result, TRUE);
+ CHECK_RECT (result, expected);
+
+ /* Aspect ratio scaling (tall) */
+ src = NEW_RECT (0, 0, 50, 100);
+ dest = NEW_RECT (0, 0, 50, 50);
+ expected = NEW_RECT (12, 0, 25, 50);
+ gst_video_sink_center_rect (src, dest, &result, TRUE);
+ CHECK_RECT (result, expected);
+
+ src = NEW_RECT (0, 0, 50, 100);
+ dest = NEW_RECT (50, 50, 50, 50);
+ expected = NEW_RECT (62, 50, 25, 50);
+ gst_video_sink_center_rect (src, dest, &result, TRUE);
+ CHECK_RECT (result, expected);
+
+ /* Aspect ratio scaling (wide) */
+ src = NEW_RECT (0, 0, 100, 50);
+ dest = NEW_RECT (0, 0, 50, 50);
+ expected = NEW_RECT (0, 12, 50, 25);
+ gst_video_sink_center_rect (src, dest, &result, TRUE);
+ CHECK_RECT (result, expected);
+
+ src = NEW_RECT (0, 0, 100, 50);
+ dest = NEW_RECT (50, 50, 50, 50);
+ expected = NEW_RECT (50, 62, 50, 25);
+ gst_video_sink_center_rect (src, dest, &result, TRUE);
+ CHECK_RECT (result, expected);
+}
+
+GST_END_TEST;
+
static Suite *
video_suite (void)
{
@@ -1714,6 +1774,7 @@ video_suite (void)
tcase_add_test (tc_chain, test_overlay_composition);
tcase_add_test (tc_chain, test_overlay_composition_premultiplied_alpha);
tcase_add_test (tc_chain, test_overlay_composition_global_alpha);
+ tcase_add_test (tc_chain, test_video_center_rect);
return s;
}