1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/// # Safety
///
/// The trait is only meant to be implemented internally by Babl types
pub unsafe trait ObjectType {
    #[allow(clippy::missing_safety_doc)]
    unsafe fn from_raw_full(ptr: *const ::ffi::Babl) -> Self;
    #[allow(clippy::missing_safety_doc)]
    unsafe fn inner(&self) -> *const ::ffi::Babl;

    #[doc(alias = "get_name")]
    #[doc(alias = "babl_get_name")]
    fn name(&self) -> String {
        unsafe {
            std::ffi::CStr::from_ptr(ffi::babl_get_name(self.inner()))
                .to_string_lossy()
                .into()
        }
    }

    #[doc(alias = "babl_introspect")]
    fn introspect(&self) {
        unsafe { ffi::babl_introspect(self.inner()) }
    }
}

macro_rules! define_object {
    ($rust_type:ident) => {
        #[derive(Debug)]
        pub struct $rust_type(*const ffi::Babl);

        unsafe impl crate::ObjectType for $rust_type {
            unsafe fn from_raw_full(ptr: *const ffi::Babl) -> Self {
                assert!(!ptr.is_null());
                Self(ptr)
            }

            unsafe fn inner(&self) -> *const ffi::Babl {
                self.0
            }
        }
    };
}

/*#[derive(Debug)]
pub struct Object(*const ffi::Babl);

impl Object {


    /* Palette */

    pub fn new_palette(
        name: &str,
        format_u8: &mut Object,
        format_u8_with_alpha: &mut Object,
    ) -> Self {
        unsafe {
            let c_name = CString::new(name).unwrap();
            Self::from_raw_full(ffi::babl_new_palette(
                c_name.as_ptr() as *const i8,
                &mut format_u8.0,
                &mut format_u8_with_alpha.0,
            ))
        }
    }

    pub fn palette_reset(babl: &Object) {
        unsafe { ffi::babl_palette_reset(babl.0) }
    }

    /* Conversion */
    pub fn conversion_get_source_space(conversion: &Object) -> Self {
        unsafe { Self::from_raw_full(ffi::babl_conversion_get_source_space(conversion.0)) }
    }

    pub fn conversion_get_destination_space(conversion: &Object) -> Self {
        unsafe { Self::from_raw_full(ffi::babl_conversion_get_destination_space(conversion.0)) }
    }
}
*/