1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{marker::PhantomData, mem};
4
5use glib::translate::IntoGlib;
6
7#[repr(C)]
8#[derive(Clone, Debug, Eq, PartialEq, Hash)]
9pub struct VideoRectangle {
10 pub x: i32,
11 pub y: i32,
12 pub w: i32,
13 pub h: i32,
14}
15
16impl VideoRectangle {
17 #[inline]
18 pub fn new(x: i32, y: i32, w: i32, h: i32) -> Self {
19 skip_assert_initialized!();
20 Self { x, y, w, h }
21 }
22}
23
24pub fn center_video_rectangle(
25 src: &VideoRectangle,
26 dst: &VideoRectangle,
27 scale: bool,
28) -> VideoRectangle {
29 skip_assert_initialized!();
30 let mut result = ffi::GstVideoRectangle {
31 x: 0,
32 y: 0,
33 w: 0,
34 h: 0,
35 };
36 let src_rect = ffi::GstVideoRectangle {
37 x: src.x,
38 y: src.y,
39 w: src.w,
40 h: src.h,
41 };
42 let dst_rect = ffi::GstVideoRectangle {
43 x: dst.x,
44 y: dst.y,
45 w: dst.w,
46 h: dst.h,
47 };
48 unsafe {
49 ffi::gst_video_sink_center_rect(src_rect, dst_rect, &mut result, scale.into_glib());
50 }
51 VideoRectangle::new(result.x, result.y, result.w, result.h)
52}
53
54#[doc(hidden)]
55impl glib::translate::Uninitialized for VideoRectangle {
56 #[inline]
57 unsafe fn uninitialized() -> Self {
58 mem::zeroed()
59 }
60}
61
62#[doc(hidden)]
63impl<'a> glib::translate::ToGlibPtrMut<'a, *mut ffi::GstVideoRectangle> for VideoRectangle {
64 type Storage = PhantomData<&'a mut Self>;
65
66 #[inline]
67 fn to_glib_none_mut(
68 &'a mut self,
69 ) -> glib::translate::StashMut<*mut ffi::GstVideoRectangle, Self> {
70 glib::translate::StashMut(self as *mut _ as *mut _, PhantomData)
71 }
72}
73