gstreamer_video/
video_rectangle.rs

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