2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-12-26 16:55:53 +00:00
|
|
|
|
2021-04-27 15:15:46 +00:00
|
|
|
use glib::translate::IntoGlib;
|
2017-12-26 16:55:53 +00:00
|
|
|
|
2018-01-03 15:36:44 +00:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
2017-12-26 16:55:53 +00:00
|
|
|
pub struct VideoRectangle {
|
|
|
|
pub x: i32,
|
|
|
|
pub y: i32,
|
|
|
|
pub w: i32,
|
|
|
|
pub h: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl VideoRectangle {
|
|
|
|
pub fn new(x: i32, y: i32, w: i32, h: i32) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2021-04-29 20:49:40 +00:00
|
|
|
Self { x, y, w, h }
|
2017-12-26 16:55:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-26 17:18:13 +00:00
|
|
|
pub fn center_video_rectangle(
|
2018-01-03 15:36:44 +00:00
|
|
|
src: &VideoRectangle,
|
|
|
|
dst: &VideoRectangle,
|
2017-12-26 17:18:13 +00:00
|
|
|
scale: bool,
|
|
|
|
) -> VideoRectangle {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2020-11-22 09:53:17 +00:00
|
|
|
let mut result = ffi::GstVideoRectangle {
|
2017-12-26 17:18:13 +00:00
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
w: 0,
|
|
|
|
h: 0,
|
|
|
|
};
|
2020-11-22 09:53:17 +00:00
|
|
|
let src_rect = ffi::GstVideoRectangle {
|
2017-12-26 17:18:13 +00:00
|
|
|
x: src.x,
|
|
|
|
y: src.y,
|
|
|
|
w: src.w,
|
|
|
|
h: src.h,
|
|
|
|
};
|
2020-11-22 09:53:17 +00:00
|
|
|
let dst_rect = ffi::GstVideoRectangle {
|
2017-12-26 17:18:13 +00:00
|
|
|
x: dst.x,
|
|
|
|
y: dst.y,
|
|
|
|
w: dst.w,
|
|
|
|
h: dst.h,
|
|
|
|
};
|
2017-12-26 16:55:53 +00:00
|
|
|
unsafe {
|
2021-04-27 15:15:46 +00:00
|
|
|
ffi::gst_video_sink_center_rect(src_rect, dst_rect, &mut result, scale.into_glib());
|
2017-12-26 16:55:53 +00:00
|
|
|
}
|
|
|
|
VideoRectangle::new(result.x, result.y, result.w, result.h)
|
|
|
|
}
|