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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// This file is automatically generated, DO NOT EDIT
//
// To regenerate this file run the `crates/witx-bindgen` command

use core::fmt;
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct WasmedgeImageErrno(u32);
pub const WASMEDGE_IMAGE_ERRNO_SUCCESS: WasmedgeImageErrno = WasmedgeImageErrno(0);
pub const WASMEDGE_IMAGE_ERRNO_FAIL: WasmedgeImageErrno = WasmedgeImageErrno(1);
impl WasmedgeImageErrno {
    pub const fn raw(&self) -> u32 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "SUCCESS",
            1 => "FAIL",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "",
            1 => "",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for WasmedgeImageErrno {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("WasmedgeImageErrno")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl fmt::Display for WasmedgeImageErrno {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{} (error {})", self.name(), self.0)
    }
}

#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
impl std::error::Error for WasmedgeImageErrno {}

#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct WasmedgeImageRawType(u32);
pub const WASMEDGE_IMAGE_RAW_TYPE_RGB8: WasmedgeImageRawType = WasmedgeImageRawType(0);
pub const WASMEDGE_IMAGE_RAW_TYPE_BGR8: WasmedgeImageRawType = WasmedgeImageRawType(1);
pub const WASMEDGE_IMAGE_RAW_TYPE_RGB32F: WasmedgeImageRawType = WasmedgeImageRawType(2);
pub const WASMEDGE_IMAGE_RAW_TYPE_BGR32F: WasmedgeImageRawType = WasmedgeImageRawType(3);
impl WasmedgeImageRawType {
    pub const fn raw(&self) -> u32 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "RGB8",
            1 => "BGR8",
            2 => "RGB32F",
            3 => "BGR32F",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "",
            1 => "",
            2 => "",
            3 => "",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for WasmedgeImageRawType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("WasmedgeImageRawType")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}

pub type ImgBuffer<'a> = &'a [u8];
pub type BufMaxSize = u32;
pub unsafe fn load_jpg(
    input_img_buffer: ImgBuffer<'_>,
    out_width: u32,
    out_height: u32,
    data_type: WasmedgeImageRawType,
    output_buf: *mut u8,
    output_buf_max_size: BufMaxSize,
) -> Result<(), WasmedgeImageErrno> {
    let ret = wasmedge_image::load_jpg(
        input_img_buffer.as_ptr() as i32,
        input_img_buffer.len() as i32,
        out_width as i32,
        out_height as i32,
        data_type.0 as i32,
        output_buf as i32,
        output_buf_max_size as i32,
    );
    match ret {
        0 => Ok(()),
        _ => Err(WasmedgeImageErrno(ret as u32)),
    }
}

pub unsafe fn load_png(
    input_img_buffer: ImgBuffer<'_>,
    out_width: u32,
    out_height: u32,
    data_type: WasmedgeImageRawType,
    output_buf: *mut u8,
    output_buf_max_size: BufMaxSize,
) -> Result<(), WasmedgeImageErrno> {
    let ret = wasmedge_image::load_png(
        input_img_buffer.as_ptr() as i32,
        input_img_buffer.len() as i32,
        out_width as i32,
        out_height as i32,
        data_type.0 as i32,
        output_buf as i32,
        output_buf_max_size as i32,
    );
    match ret {
        0 => Ok(()),
        _ => Err(WasmedgeImageErrno(ret as u32)),
    }
}

pub mod wasmedge_image {
    #[link(wasm_import_module = "wasmedge_image")]
    extern "C" {
        pub fn load_jpg(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
            arg6: i32,
        ) -> i32;
        pub fn load_png(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
            arg6: i32,
        ) -> i32;
    }
}