mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-03 04:52:28 +00:00
video: Fix non-default usage of gst_video_sink_center_rect
Make sure we take into account non-0 x/y destination rectangles
This commit is contained in:
parent
c77a21b1fa
commit
ff57f69134
2 changed files with 68 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -2277,6 +2277,65 @@ GST_START_TEST (test_video_transfer)
|
|||
|
||||
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;
|
||||
|
||||
void test_overlay_blend_rect (gint x, gint y, gint width, gint height,
|
||||
GstVideoFrame * video_frame);
|
||||
void test_overlay_blend_rect_verify (gint x, gint y, gint width,
|
||||
|
@ -2470,6 +2529,7 @@ video_suite (void)
|
|||
tcase_add_test (tc_chain, test_video_size_convert);
|
||||
tcase_add_test (tc_chain, test_video_transfer);
|
||||
tcase_add_test (tc_chain, test_overlay_blend);
|
||||
tcase_add_test (tc_chain, test_video_center_rect);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue