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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use Colorspace;
use Error;
use InterpType;
use PixbufFormat;
use PixbufRotation;
use ffi;
use gio;
use glib;
use glib::GString;
use glib::StaticType;
use glib::Value;
use glib::object::IsA;
use glib::object::ObjectType;
use glib::translate::*;
use gobject_ffi;
use std::fmt;
use std::ptr;

glib_wrapper! {
    pub struct Pixbuf(Object<ffi::GdkPixbuf, PixbufClass>) @implements gio::Icon, gio::LoadableIcon;

    match fn {
        get_type => || ffi::gdk_pixbuf_get_type(),
    }
}

impl Pixbuf {
    pub fn new(colorspace: Colorspace, has_alpha: bool, bits_per_sample: i32, width: i32, height: i32) -> Option<Pixbuf> {
        unsafe {
            from_glib_full(ffi::gdk_pixbuf_new(colorspace.to_glib(), has_alpha.to_glib(), bits_per_sample, width, height))
        }
    }

    #[cfg(any(feature = "v2_32", feature = "dox"))]
    pub fn new_from_bytes(data: &glib::Bytes, colorspace: Colorspace, has_alpha: bool, bits_per_sample: i32, width: i32, height: i32, rowstride: i32) -> Pixbuf {
        unsafe {
            from_glib_full(ffi::gdk_pixbuf_new_from_bytes(data.to_glib_none().0, colorspace.to_glib(), has_alpha.to_glib(), bits_per_sample, width, height, rowstride))
        }
    }

    //pub fn new_from_data(data: &[u8], colorspace: Colorspace, has_alpha: bool, bits_per_sample: i32, width: i32, height: i32, rowstride: i32, destroy_fn: Option<Box<dyn FnOnce(&Vec<u8>) + 'static>>) -> Pixbuf {
    //    unsafe { TODO: call ffi::gdk_pixbuf_new_from_data() }
    //}

    #[cfg_attr(feature = "v2_32", deprecated)]
    pub fn new_from_inline(data: &[u8], copy_pixels: bool) -> Result<Pixbuf, Error> {
        let data_length = data.len() as i32;
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::gdk_pixbuf_new_from_inline(data_length, data.to_glib_none().0, copy_pixels.to_glib(), &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    pub fn new_from_resource(resource_path: &str) -> Result<Pixbuf, Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::gdk_pixbuf_new_from_resource(resource_path.to_glib_none().0, &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    pub fn new_from_resource_at_scale(resource_path: &str, width: i32, height: i32, preserve_aspect_ratio: bool) -> Result<Pixbuf, Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::gdk_pixbuf_new_from_resource_at_scale(resource_path.to_glib_none().0, width, height, preserve_aspect_ratio.to_glib(), &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    pub fn new_from_stream<'a, P: IsA<gio::InputStream>, Q: IsA<gio::Cancellable> + 'a, R: Into<Option<&'a Q>>>(stream: &P, cancellable: R) -> Result<Pixbuf, Error> {
        let cancellable = cancellable.into();
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::gdk_pixbuf_new_from_stream(stream.as_ref().to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    pub fn new_from_stream_at_scale<'a, P: IsA<gio::InputStream>, Q: IsA<gio::Cancellable> + 'a, R: Into<Option<&'a Q>>>(stream: &P, width: i32, height: i32, preserve_aspect_ratio: bool, cancellable: R) -> Result<Pixbuf, Error> {
        let cancellable = cancellable.into();
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::gdk_pixbuf_new_from_stream_at_scale(stream.as_ref().to_glib_none().0, width, height, preserve_aspect_ratio.to_glib(), cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    pub fn new_from_xpm_data(data: &[&str]) -> Pixbuf {
        unsafe {
            from_glib_full(ffi::gdk_pixbuf_new_from_xpm_data(data.to_glib_none().0))
        }
    }

    pub fn add_alpha(&self, substitute_color: bool, r: u8, g: u8, b: u8) -> Option<Pixbuf> {
        unsafe {
            from_glib_full(ffi::gdk_pixbuf_add_alpha(self.to_glib_none().0, substitute_color.to_glib(), r, g, b))
        }
    }

    pub fn apply_embedded_orientation(&self) -> Option<Pixbuf> {
        unsafe {
            from_glib_full(ffi::gdk_pixbuf_apply_embedded_orientation(self.to_glib_none().0))
        }
    }

    pub fn composite(&self, dest: &Pixbuf, dest_x: i32, dest_y: i32, dest_width: i32, dest_height: i32, offset_x: f64, offset_y: f64, scale_x: f64, scale_y: f64, interp_type: InterpType, overall_alpha: i32) {
        unsafe {
            ffi::gdk_pixbuf_composite(self.to_glib_none().0, dest.to_glib_none().0, dest_x, dest_y, dest_width, dest_height, offset_x, offset_y, scale_x, scale_y, interp_type.to_glib(), overall_alpha);
        }
    }

    pub fn composite_color(&self, dest: &Pixbuf, dest_x: i32, dest_y: i32, dest_width: i32, dest_height: i32, offset_x: f64, offset_y: f64, scale_x: f64, scale_y: f64, interp_type: InterpType, overall_alpha: i32, check_x: i32, check_y: i32, check_size: i32, color1: u32, color2: u32) {
        unsafe {
            ffi::gdk_pixbuf_composite_color(self.to_glib_none().0, dest.to_glib_none().0, dest_x, dest_y, dest_width, dest_height, offset_x, offset_y, scale_x, scale_y, interp_type.to_glib(), overall_alpha, check_x, check_y, check_size, color1, color2);
        }
    }

    pub fn composite_color_simple(&self, dest_width: i32, dest_height: i32, interp_type: InterpType, overall_alpha: i32, check_size: i32, color1: u32, color2: u32) -> Option<Pixbuf> {
        unsafe {
            from_glib_full(ffi::gdk_pixbuf_composite_color_simple(self.to_glib_none().0, dest_width, dest_height, interp_type.to_glib(), overall_alpha, check_size, color1, color2))
        }
    }

    pub fn copy(&self) -> Option<Pixbuf> {
        unsafe {
            from_glib_full(ffi::gdk_pixbuf_copy(self.to_glib_none().0))
        }
    }

    pub fn copy_area(&self, src_x: i32, src_y: i32, width: i32, height: i32, dest_pixbuf: &Pixbuf, dest_x: i32, dest_y: i32) {
        unsafe {
            ffi::gdk_pixbuf_copy_area(self.to_glib_none().0, src_x, src_y, width, height, dest_pixbuf.to_glib_none().0, dest_x, dest_y);
        }
    }

    #[cfg(any(feature = "v2_36", feature = "dox"))]
    pub fn copy_options(&self, dest_pixbuf: &Pixbuf) -> bool {
        unsafe {
            from_glib(ffi::gdk_pixbuf_copy_options(self.to_glib_none().0, dest_pixbuf.to_glib_none().0))
        }
    }

    pub fn fill(&self, pixel: u32) {
        unsafe {
            ffi::gdk_pixbuf_fill(self.to_glib_none().0, pixel);
        }
    }

    pub fn flip(&self, horizontal: bool) -> Option<Pixbuf> {
        unsafe {
            from_glib_full(ffi::gdk_pixbuf_flip(self.to_glib_none().0, horizontal.to_glib()))
        }
    }

    pub fn get_bits_per_sample(&self) -> i32 {
        unsafe {
            ffi::gdk_pixbuf_get_bits_per_sample(self.to_glib_none().0)
        }
    }

    pub fn get_byte_length(&self) -> usize {
        unsafe {
            ffi::gdk_pixbuf_get_byte_length(self.to_glib_none().0)
        }
    }

    pub fn get_colorspace(&self) -> Colorspace {
        unsafe {
            from_glib(ffi::gdk_pixbuf_get_colorspace(self.to_glib_none().0))
        }
    }

    pub fn get_has_alpha(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_pixbuf_get_has_alpha(self.to_glib_none().0))
        }
    }

    pub fn get_height(&self) -> i32 {
        unsafe {
            ffi::gdk_pixbuf_get_height(self.to_glib_none().0)
        }
    }

    pub fn get_n_channels(&self) -> i32 {
        unsafe {
            ffi::gdk_pixbuf_get_n_channels(self.to_glib_none().0)
        }
    }

    pub fn get_option(&self, key: &str) -> Option<GString> {
        unsafe {
            from_glib_none(ffi::gdk_pixbuf_get_option(self.to_glib_none().0, key.to_glib_none().0))
        }
    }

    //#[cfg(any(feature = "v2_32", feature = "dox"))]
    //pub fn get_options(&self) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 } {
    //    unsafe { TODO: call ffi::gdk_pixbuf_get_options() }
    //}

    pub fn get_rowstride(&self) -> i32 {
        unsafe {
            ffi::gdk_pixbuf_get_rowstride(self.to_glib_none().0)
        }
    }

    pub fn get_width(&self) -> i32 {
        unsafe {
            ffi::gdk_pixbuf_get_width(self.to_glib_none().0)
        }
    }

    pub fn new_subpixbuf(&self, src_x: i32, src_y: i32, width: i32, height: i32) -> Option<Pixbuf> {
        unsafe {
            from_glib_full(ffi::gdk_pixbuf_new_subpixbuf(self.to_glib_none().0, src_x, src_y, width, height))
        }
    }

    #[cfg(any(feature = "v2_32", feature = "dox"))]
    pub fn read_pixel_bytes(&self) -> Option<glib::Bytes> {
        unsafe {
            from_glib_full(ffi::gdk_pixbuf_read_pixel_bytes(self.to_glib_none().0))
        }
    }

    #[cfg(any(feature = "v2_36", feature = "dox"))]
    pub fn remove_option(&self, key: &str) -> bool {
        unsafe {
            from_glib(ffi::gdk_pixbuf_remove_option(self.to_glib_none().0, key.to_glib_none().0))
        }
    }

    pub fn rotate_simple(&self, angle: PixbufRotation) -> Option<Pixbuf> {
        unsafe {
            from_glib_full(ffi::gdk_pixbuf_rotate_simple(self.to_glib_none().0, angle.to_glib()))
        }
    }

    pub fn saturate_and_pixelate(&self, dest: &Pixbuf, saturation: f32, pixelate: bool) {
        unsafe {
            ffi::gdk_pixbuf_saturate_and_pixelate(self.to_glib_none().0, dest.to_glib_none().0, saturation, pixelate.to_glib());
        }
    }

    //pub fn save<'a, P: AsRef<std::path::Path>, Q: Into<Option<&'a Error>>>(&self, filename: P, type_: &str, error: Q, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool {
    //    unsafe { TODO: call ffi::gdk_pixbuf_save() }
    //}

    //pub fn save_to_buffer<'a, P: Into<Option<&'a Error>>>(&self, type_: &str, error: P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Option<Vec<u8>> {
    //    unsafe { TODO: call ffi::gdk_pixbuf_save_to_buffer() }
    //}

    //pub fn save_to_callback<'a, P: FnMut(&Vec<u8>, usize, &Error) -> bool, Q: Into<Option<&'a Error>>>(&self, save_func: P, type_: &str, error: Q, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool {
    //    unsafe { TODO: call ffi::gdk_pixbuf_save_to_callback() }
    //}

    //pub fn save_to_callbackv<P: FnMut(&Vec<u8>, usize, &Error) -> bool>(&self, save_func: P, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result<(), Error> {
    //    unsafe { TODO: call ffi::gdk_pixbuf_save_to_callbackv() }
    //}

    //pub fn save_to_stream<'a, 'b, P: IsA<gio::OutputStream>, Q: IsA<gio::Cancellable> + 'a, R: Into<Option<&'a Q>>, S: Into<Option<&'b Error>>>(&self, stream: &P, type_: &str, cancellable: R, error: S, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool {
    //    unsafe { TODO: call ffi::gdk_pixbuf_save_to_stream() }
    //}

    //pub fn save_to_stream_async<'a, P: IsA<gio::OutputStream>, Q: IsA<gio::Cancellable> + 'a, R: Into<Option<&'a Q>>, S: FnOnce(Result<(), Error>) + Send + 'static>(&self, stream: &P, type_: &str, cancellable: R, callback: S, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
    //    unsafe { TODO: call ffi::gdk_pixbuf_save_to_stream_async() }
    //}

    //#[cfg(feature = "futures")]
    //pub fn save_to_stream_async_future<P: IsA<gio::OutputStream> + Clone + 'static>(&self, stream: &P, type_: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Box_<futures_core::Future<Item = (Self, ()), Error = (Self, Error)>> where Self: Sized + Clone {
        //use gio::GioFuture;
        //use fragile::Fragile;

        //let stream = stream.clone();
        //let type_ = String::from(type_);
        //GioFuture::new(self, move |obj, send| {
        //    let cancellable = gio::Cancellable::new();
        //    let send = Fragile::new(send);
        //    let obj_clone = Fragile::new(obj.clone());
        //    obj.save_to_stream_async(
        //         &stream,
        //         &type_,
        //         Some(&cancellable),
        //         ,
        //         move |res| {
        //             let obj = obj_clone.into_inner();
        //             let res = res.map(|v| (obj.clone(), v)).map_err(|v| (obj.clone(), v));
        //             let _ = send.into_inner().send(res);
        //         },
        //    );

        //    cancellable
        //})
    //}

    pub fn scale(&self, dest: &Pixbuf, dest_x: i32, dest_y: i32, dest_width: i32, dest_height: i32, offset_x: f64, offset_y: f64, scale_x: f64, scale_y: f64, interp_type: InterpType) {
        unsafe {
            ffi::gdk_pixbuf_scale(self.to_glib_none().0, dest.to_glib_none().0, dest_x, dest_y, dest_width, dest_height, offset_x, offset_y, scale_x, scale_y, interp_type.to_glib());
        }
    }

    pub fn scale_simple(&self, dest_width: i32, dest_height: i32, interp_type: InterpType) -> Option<Pixbuf> {
        unsafe {
            from_glib_full(ffi::gdk_pixbuf_scale_simple(self.to_glib_none().0, dest_width, dest_height, interp_type.to_glib()))
        }
    }

    pub fn set_option(&self, key: &str, value: &str) -> bool {
        unsafe {
            from_glib(ffi::gdk_pixbuf_set_option(self.to_glib_none().0, key.to_glib_none().0, value.to_glib_none().0))
        }
    }

    pub fn get_property_pixel_bytes(&self) -> Option<glib::Bytes> {
        unsafe {
            let mut value = Value::from_type(<glib::Bytes as StaticType>::static_type());
            gobject_ffi::g_object_get_property(self.as_ptr() as *mut gobject_ffi::GObject, b"pixel-bytes\0".as_ptr() as *const _, value.to_glib_none_mut().0);
            value.get()
        }
    }

    //pub fn get_property_pixels(&self) -> /*Unimplemented*/Fundamental: Pointer {
    //    unsafe {
    //        let mut value = Value::from_type(</*Unknown type*/ as StaticType>::static_type());
    //        gobject_ffi::g_object_get_property(self.as_ptr() as *mut gobject_ffi::GObject, b"pixels\0".as_ptr() as *const _, value.to_glib_none_mut().0);
    //        value.get().unwrap()
    //    }
    //}

    #[cfg(any(feature = "v2_36_8", feature = "dox"))]
    pub fn calculate_rowstride(colorspace: Colorspace, has_alpha: bool, bits_per_sample: i32, width: i32, height: i32) -> i32 {
        unsafe {
            ffi::gdk_pixbuf_calculate_rowstride(colorspace.to_glib(), has_alpha.to_glib(), bits_per_sample, width, height)
        }
    }

    pub fn get_formats() -> Vec<PixbufFormat> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gdk_pixbuf_get_formats())
        }
    }
}

impl fmt::Display for Pixbuf {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Pixbuf")
    }
}