babl/
object.rs

1/// # Safety
2///
3/// The trait is only meant to be implemented internally by Babl types
4pub unsafe trait ObjectType {
5    #[allow(clippy::missing_safety_doc)]
6    unsafe fn from_raw_full(ptr: *const ::ffi::Babl) -> Self;
7    #[allow(clippy::missing_safety_doc)]
8    unsafe fn inner(&self) -> *const ::ffi::Babl;
9
10    #[doc(alias = "get_name")]
11    #[doc(alias = "babl_get_name")]
12    fn name(&self) -> String {
13        unsafe {
14            std::ffi::CStr::from_ptr(ffi::babl_get_name(self.inner()))
15                .to_string_lossy()
16                .into()
17        }
18    }
19
20    #[doc(alias = "babl_introspect")]
21    fn introspect(&self) {
22        unsafe { ffi::babl_introspect(self.inner()) }
23    }
24}
25
26macro_rules! define_object {
27    ($rust_type:ident) => {
28        #[derive(Debug)]
29        pub struct $rust_type(*const ffi::Babl);
30
31        unsafe impl crate::ObjectType for $rust_type {
32            unsafe fn from_raw_full(ptr: *const ffi::Babl) -> Self {
33                assert!(!ptr.is_null());
34                Self(ptr)
35            }
36
37            unsafe fn inner(&self) -> *const ffi::Babl {
38                self.0
39            }
40        }
41    };
42}
43
44/*#[derive(Debug)]
45pub struct Object(*const ffi::Babl);
46
47impl Object {
48
49
50    /* Palette */
51
52    pub fn new_palette(
53        name: &str,
54        format_u8: &mut Object,
55        format_u8_with_alpha: &mut Object,
56    ) -> Self {
57        unsafe {
58            let c_name = CString::new(name).unwrap();
59            Self::from_raw_full(ffi::babl_new_palette(
60                c_name.as_ptr() as *const i8,
61                &mut format_u8.0,
62                &mut format_u8_with_alpha.0,
63            ))
64        }
65    }
66
67    pub fn palette_reset(babl: &Object) {
68        unsafe { ffi::babl_palette_reset(babl.0) }
69    }
70
71    /* Conversion */
72    pub fn conversion_get_source_space(conversion: &Object) -> Self {
73        unsafe { Self::from_raw_full(ffi::babl_conversion_get_source_space(conversion.0)) }
74    }
75
76    pub fn conversion_get_destination_space(conversion: &Object) -> Self {
77        unsafe { Self::from_raw_full(ffi::babl_conversion_get_destination_space(conversion.0)) }
78    }
79}
80*/