Skip to main content

libglycin_rebind/auto/
image.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files
4// DO NOT EDIT
5
6use std::boxed::Box as Box_;
7use std::pin::Pin;
8
9use glib::prelude::*;
10use glib::translate::*;
11
12use crate::{Frame, FrameRequest, ffi};
13
14glib::wrapper! {
15    #[doc(alias = "GlyImage")]
16    pub struct Image(Object<ffi::GlyImage, ffi::GlyImageClass>);
17
18    match fn {
19        type_ => || ffi::gly_image_get_type(),
20    }
21}
22
23impl Image {
24    #[doc(alias = "gly_image_get_height")]
25    #[doc(alias = "get_height")]
26    pub fn height(&self) -> u32 {
27        unsafe { ffi::gly_image_get_height(self.to_glib_none().0) }
28    }
29
30    #[doc(alias = "gly_image_get_metadata_key_value")]
31    #[doc(alias = "get_metadata_key_value")]
32    pub fn metadata_key_value(&self, key: &str) -> Option<glib::GString> {
33        unsafe {
34            from_glib_full(ffi::gly_image_get_metadata_key_value(
35                self.to_glib_none().0,
36                key.to_glib_none().0,
37            ))
38        }
39    }
40
41    #[doc(alias = "gly_image_get_metadata_keys")]
42    #[doc(alias = "get_metadata_keys")]
43    pub fn metadata_keys(&self) -> Vec<glib::GString> {
44        unsafe {
45            FromGlibPtrContainer::from_glib_full(ffi::gly_image_get_metadata_keys(
46                self.to_glib_none().0,
47            ))
48        }
49    }
50
51    #[doc(alias = "gly_image_get_mime_type")]
52    #[doc(alias = "get_mime_type")]
53    pub fn mime_type(&self) -> glib::GString {
54        unsafe { from_glib_none(ffi::gly_image_get_mime_type(self.to_glib_none().0)) }
55    }
56
57    #[doc(alias = "gly_image_get_specific_frame")]
58    #[doc(alias = "get_specific_frame")]
59    pub fn specific_frame(&self, frame_request: &FrameRequest) -> Result<Frame, glib::Error> {
60        unsafe {
61            let mut error = std::ptr::null_mut();
62            let ret = ffi::gly_image_get_specific_frame(
63                self.to_glib_none().0,
64                frame_request.to_glib_none().0,
65                &mut error,
66            );
67            if error.is_null() {
68                Ok(from_glib_full(ret))
69            } else {
70                Err(from_glib_full(error))
71            }
72        }
73    }
74
75    #[doc(alias = "gly_image_get_specific_frame_async")]
76    #[doc(alias = "get_specific_frame_async")]
77    pub fn specific_frame_async<P: FnOnce(Result<Frame, glib::Error>) + 'static>(
78        &self,
79        frame_request: &FrameRequest,
80        cancellable: Option<&impl IsA<gio::Cancellable>>,
81        callback: P,
82    ) {
83        let main_context = glib::MainContext::ref_thread_default();
84        let is_main_context_owner = main_context.is_owner();
85        let has_acquired_main_context = (!is_main_context_owner)
86            .then(|| main_context.acquire().ok())
87            .flatten();
88        assert!(
89            is_main_context_owner || has_acquired_main_context.is_some(),
90            "Async operations only allowed if the thread is owning the MainContext"
91        );
92
93        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
94            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
95        unsafe extern "C" fn specific_frame_async_trampoline<
96            P: FnOnce(Result<Frame, glib::Error>) + 'static,
97        >(
98            _source_object: *mut glib::gobject_ffi::GObject,
99            res: *mut gio::ffi::GAsyncResult,
100            user_data: glib::ffi::gpointer,
101        ) {
102            unsafe {
103                let mut error = std::ptr::null_mut();
104                let ret = ffi::gly_image_get_specific_frame_finish(
105                    _source_object as *mut _,
106                    res,
107                    &mut error,
108                );
109                let result = if error.is_null() {
110                    Ok(from_glib_full(ret))
111                } else {
112                    Err(from_glib_full(error))
113                };
114                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
115                    Box_::from_raw(user_data as *mut _);
116                let callback: P = callback.into_inner();
117                callback(result);
118            }
119        }
120        let callback = specific_frame_async_trampoline::<P>;
121        unsafe {
122            ffi::gly_image_get_specific_frame_async(
123                self.to_glib_none().0,
124                frame_request.to_glib_none().0,
125                cancellable.map(|p| p.as_ref()).to_glib_none().0,
126                Some(callback),
127                Box_::into_raw(user_data) as *mut _,
128            );
129        }
130    }
131
132    pub fn specific_frame_future(
133        &self,
134        frame_request: &FrameRequest,
135    ) -> Pin<Box_<dyn std::future::Future<Output = Result<Frame, glib::Error>> + 'static>> {
136        let frame_request = frame_request.clone();
137        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
138            obj.specific_frame_async(&frame_request, Some(cancellable), move |res| {
139                send.resolve(res);
140            });
141        }))
142    }
143
144    #[doc(alias = "gly_image_get_transformation_orientation")]
145    #[doc(alias = "get_transformation_orientation")]
146    pub fn transformation_orientation(&self) -> u16 {
147        unsafe { ffi::gly_image_get_transformation_orientation(self.to_glib_none().0) }
148    }
149
150    #[doc(alias = "gly_image_get_width")]
151    #[doc(alias = "get_width")]
152    pub fn width(&self) -> u32 {
153        unsafe { ffi::gly_image_get_width(self.to_glib_none().0) }
154    }
155
156    #[doc(alias = "gly_image_next_frame")]
157    pub fn next_frame(&self) -> Result<Frame, glib::Error> {
158        unsafe {
159            let mut error = std::ptr::null_mut();
160            let ret = ffi::gly_image_next_frame(self.to_glib_none().0, &mut error);
161            if error.is_null() {
162                Ok(from_glib_full(ret))
163            } else {
164                Err(from_glib_full(error))
165            }
166        }
167    }
168
169    #[doc(alias = "gly_image_next_frame_async")]
170    pub fn next_frame_async<P: FnOnce(Result<Frame, glib::Error>) + 'static>(
171        &self,
172        cancellable: Option<&impl IsA<gio::Cancellable>>,
173        callback: P,
174    ) {
175        let main_context = glib::MainContext::ref_thread_default();
176        let is_main_context_owner = main_context.is_owner();
177        let has_acquired_main_context = (!is_main_context_owner)
178            .then(|| main_context.acquire().ok())
179            .flatten();
180        assert!(
181            is_main_context_owner || has_acquired_main_context.is_some(),
182            "Async operations only allowed if the thread is owning the MainContext"
183        );
184
185        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
186            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
187        unsafe extern "C" fn next_frame_async_trampoline<
188            P: FnOnce(Result<Frame, glib::Error>) + 'static,
189        >(
190            _source_object: *mut glib::gobject_ffi::GObject,
191            res: *mut gio::ffi::GAsyncResult,
192            user_data: glib::ffi::gpointer,
193        ) {
194            unsafe {
195                let mut error = std::ptr::null_mut();
196                let ret =
197                    ffi::gly_image_next_frame_finish(_source_object as *mut _, res, &mut error);
198                let result = if error.is_null() {
199                    Ok(from_glib_full(ret))
200                } else {
201                    Err(from_glib_full(error))
202                };
203                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
204                    Box_::from_raw(user_data as *mut _);
205                let callback: P = callback.into_inner();
206                callback(result);
207            }
208        }
209        let callback = next_frame_async_trampoline::<P>;
210        unsafe {
211            ffi::gly_image_next_frame_async(
212                self.to_glib_none().0,
213                cancellable.map(|p| p.as_ref()).to_glib_none().0,
214                Some(callback),
215                Box_::into_raw(user_data) as *mut _,
216            );
217        }
218    }
219
220    pub fn next_frame_future(
221        &self,
222    ) -> Pin<Box_<dyn std::future::Future<Output = Result<Frame, glib::Error>> + 'static>> {
223        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
224            obj.next_frame_async(Some(cancellable), move |res| {
225                send.resolve(res);
226            });
227        }))
228    }
229}
230
231unsafe impl Send for Image {}
232unsafe impl Sync for Image {}