From 6c49a7f60483edfaf95dd929dfcc258fea3d63f3 Mon Sep 17 00:00:00 2001 From: Evgenii Pashkin Date: Sun, 17 Dec 2017 21:22:29 +0300 Subject: [PATCH 1/8] Update gir submodule --- gir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gir b/gir index d8a605da..5a68ad02 160000 --- a/gir +++ b/gir @@ -1 +1 @@ -Subproject commit d8a605dac3e852567379aa39a508b58b01aeb458 +Subproject commit 5a68ad0235b09ebc76ae76500d70e4206dde3c23 From 96b96b032876147e7d35fc54a57834f2bd57bd4f Mon Sep 17 00:00:00 2001 From: Evgenii Pashkin Date: Sun, 17 Dec 2017 20:28:38 +0300 Subject: [PATCH 2/8] Remove manual functions for Pixbuf --- Gir.toml | 86 ++------------------------------------------------- src/pixbuf.rs | 76 +-------------------------------------------- 2 files changed, 4 insertions(+), 158 deletions(-) diff --git a/Gir.toml b/Gir.toml index 67209458..2e49cca4 100644 --- a/Gir.toml +++ b/Gir.toml @@ -28,97 +28,17 @@ manual = [ [[object]] name = "GdkPixbuf.Pixbuf" status = "generate" - [[object.function]] - name = "add_alpha" - #const self - ignore = true - [[object.function]] - name = "composite" - #const self - ignore = true - [[object.function]] - name = "composite_color" - #const self - ignore = true - [[object.function]] - name = "composite_color_simple" - #const self - ignore = true - [[object.function]] - name = "copy" - #const self - ignore = true - [[object.function]] - name = "copy_area" - #const self - ignore = true - [[object.function]] - name = "flip" - #const self - ignore = true - [[object.function]] - name = "get_bits_per_sample" - #as property: const self - ignore = true - [[object.function]] - name = "get_byte_length" - #const self - ignore = true - [[object.function]] - name = "get_colorspace" - #as property: const self - ignore = true - [[object.function]] - name = "get_has_alpha" - #as property: const self - ignore = true - [[object.function]] - name = "get_height" - #as property: const self - ignore = true - [[object.function]] - name = "get_n_channels" - #as property: const self - ignore = true [[object.function]] name = "get_pixels" - #const self + #manual array without length ignore = true [[object.function]] name = "get_pixels_with_length" - #const self - ignore = true - [[object.function]] - name = "get_rowstride" - #as property: const self - ignore = true - [[object.function]] - name = "get_width" - #as property: const self + #manual as get_pixels ignore = true [[object.function]] name = "read_pixels" - #const self - ignore = true - [[object.function]] - name = "read_pixel_bytes" - #const self - ignore = true - [[object.function]] - name = "rotate_simple" - #const self - ignore = true - [[object.function]] - name = "saturate_and_pixelate" - #const self - ignore = true - [[object.function]] - name = "scale" - #const self - ignore = true - [[object.function]] - name = "scale_simple" - #const self + #unimplementable, use get_pixels instead ignore = true [[object.function]] name = "new_from_file" diff --git a/src/pixbuf.rs b/src/pixbuf.rs index 45a4822e..eb9a4420 100644 --- a/src/pixbuf.rs +++ b/src/pixbuf.rs @@ -12,8 +12,8 @@ use ffi; use { Colorspace, - InterpType, Pixbuf, + PixbufExt, }; impl Pixbuf { @@ -91,79 +91,12 @@ impl Pixbuf { } } - pub fn get_colorspace(&self) -> Colorspace { - unsafe { from_glib(ffi::gdk_pixbuf_get_colorspace(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_has_alpha(&self) -> bool { - unsafe { from_glib(ffi::gdk_pixbuf_get_has_alpha(self.to_glib_none().0)) } - } - - pub fn get_bits_per_sample(&self) -> i32 { - unsafe { ffi::gdk_pixbuf_get_bits_per_sample(self.to_glib_none().0) } - } - pub unsafe fn get_pixels(&self) -> &mut [u8] { let mut len = 0; let ptr = ffi::gdk_pixbuf_get_pixels_with_length(self.to_glib_none().0, &mut len); slice::from_raw_parts_mut(ptr, len as usize) } - pub fn get_width(&self) -> i32 { - unsafe { ffi::gdk_pixbuf_get_width(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_rowstride(&self) -> i32 { - unsafe { ffi::gdk_pixbuf_get_rowstride(self.to_glib_none().0) } - } - - pub fn get_byte_length(&self) -> usize { - unsafe { ffi::gdk_pixbuf_get_byte_length(self.to_glib_none().0) as usize } - } - - pub fn scale_simple(&self, dest_width: i32, dest_height: i32, interp_type: InterpType) - -> Result { - unsafe { - Option::from_glib_full(ffi::gdk_pixbuf_scale_simple(self.to_glib_none().0, dest_width, - dest_height, interp_type.to_glib())).ok_or(()) - } - } - - 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 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 flip(&self, horizontal: bool) -> Result { - unsafe { - Option::from_glib_full((ffi::gdk_pixbuf_flip(self.to_glib_none().0, - horizontal.to_glib()))).ok_or(()) - } - } - pub fn put_pixel(&self, x: i32, y: i32, red: u8, green: u8, blue: u8, alpha: u8) { unsafe { let n_channels = self.get_n_channels(); @@ -177,11 +110,4 @@ impl Pixbuf { pixels[pos + 3] = alpha; } } - - pub fn copy(&self) -> Pixbuf { - unsafe { - let copy = ffi::gdk_pixbuf_copy(self.to_glib_none().0); - FromGlibPtrFull::from_glib_full(copy) - } - } } From 59e6cd86019ea6d984091cc5436b6d1a13be889a Mon Sep 17 00:00:00 2001 From: Evgenii Pashkin Date: Sun, 17 Dec 2017 20:43:38 +0300 Subject: [PATCH 3/8] Fix PixbufFormat muttable self for getters and checkers --- Gir.toml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Gir.toml b/Gir.toml index 2e49cca4..a0e3a21f 100644 --- a/Gir.toml +++ b/Gir.toml @@ -11,7 +11,6 @@ generate = [ "GdkPixbuf.InterpType", "GdkPixbuf.PixbufAlphaMode", "GdkPixbuf.PixbufError", - "GdkPixbuf.PixbufFormat", "GdkPixbuf.PixbufLoader", "GdkPixbuf.PixbufRotation", "GdkPixbuf.PixbufSimpleAnim", @@ -52,3 +51,17 @@ status = "generate" name = "new_from_file_at_scale" #manual is_windows_utf8 ignore = true + +[[object]] +name = "GdkPixbuf.PixbufFormat" +status = "generate" + [[object.function]] + pattern = "get_.+" + [[object.function.parameter]] + name = "format" + const = true + [[object.function]] + pattern = "is_.+" + [[object.function.parameter]] + name = "format" + const = true From f7bb0e1347edd600dcc461134fb1a0f73e28377d Mon Sep 17 00:00:00 2001 From: Evgenii Pashkin Date: Sun, 17 Dec 2017 20:55:43 +0300 Subject: [PATCH 4/8] Generate Pixbuf steam functions --- Gir.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Gir.toml b/Gir.toml index a0e3a21f..f9b4e24e 100644 --- a/Gir.toml +++ b/Gir.toml @@ -21,7 +21,10 @@ manual = [ "GdkPixbuf.PixbufAnimationIter", "GLib.Bytes", "GLib.Error", + "Gio.AsyncReadyCallback", "Gio.Cancellable", + "Gio.InputStream", + "Gio.OutputStream", ] [[object]] From a962e786a90d3bff925a6cb666cc9c9186ba7b0d Mon Sep 17 00:00:00 2001 From: Evgenii Pashkin Date: Sun, 17 Dec 2017 22:53:02 +0300 Subject: [PATCH 5/8] Fix async functions --- Gir.toml | 16 +++++++++ src/pixbuf.rs | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/Gir.toml b/Gir.toml index f9b4e24e..1ffdb9ba 100644 --- a/Gir.toml +++ b/Gir.toml @@ -54,6 +54,22 @@ status = "generate" name = "new_from_file_at_scale" #manual is_windows_utf8 ignore = true + [[object.function]] + name = "new_from_stream_async" + # wrong async return + ignore = true + [[object.function]] + name = "new_from_stream_at_scale_async" + # wrong return and don't generated + ignore = true + [[object.function]] + name = "get_file_info" + # wrong return + ignore = true + [[object.function]] + name = "get_file_info_async" + # wrong async return + ignore = true [[object]] name = "GdkPixbuf.PixbufFormat" diff --git a/src/pixbuf.rs b/src/pixbuf.rs index eb9a4420..ed0c94a1 100644 --- a/src/pixbuf.rs +++ b/src/pixbuf.rs @@ -6,14 +6,20 @@ use std::mem; use std::ptr; use std::slice; use libc::{c_void, c_uchar}; +use glib::object::IsA; use glib::translate::*; use glib::Error; +use gio; use ffi; +use glib_ffi; +use gobject_ffi; +use gio_ffi; use { Colorspace, Pixbuf, PixbufExt, + PixbufFormat, }; impl Pixbuf { @@ -91,6 +97,52 @@ impl Pixbuf { } } + pub fn new_from_stream_async<'a, P: IsA, Q: Into>, R: FnOnce(Result) + Send + 'static>(stream: &P, cancellable: Q, callback: R) { + let cancellable = cancellable.into(); + let cancellable = cancellable.to_glib_none(); + let user_data: Box> = Box::new(Box::new(callback)); + unsafe extern "C" fn new_from_stream_async_trampoline) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut gio_ffi::GAsyncResult, user_data: glib_ffi::gpointer) + { + callback_guard!(); + let mut error = ptr::null_mut(); + let ptr = ffi::gdk_pixbuf_new_from_stream_finish(res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ptr)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box> = Box::from_raw(user_data as *mut _); + callback(result); + } + let callback = new_from_stream_async_trampoline::; + unsafe { + ffi::gdk_pixbuf_new_from_stream_async(stream.to_glib_none().0, cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _); + } + } + + pub fn new_from_stream_at_scale_async<'a, P: IsA, Q: Into>, R: FnOnce(Result) + Send + 'static>(stream: &P, width: i32, height: i32, preserve_aspect_ratio: bool, cancellable: Q, callback: R) { + let cancellable = cancellable.into(); + let cancellable = cancellable.to_glib_none(); + let user_data: Box> = Box::new(Box::new(callback)); + unsafe extern "C" fn new_from_stream_at_scale_async_trampoline) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut gio_ffi::GAsyncResult, user_data: glib_ffi::gpointer) + { + callback_guard!(); + let mut error = ptr::null_mut(); + let ptr = ffi::gdk_pixbuf_new_from_stream_finish(res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ptr)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box> = Box::from_raw(user_data as *mut _); + callback(result); + } + let callback = new_from_stream_at_scale_async_trampoline::; + unsafe { + ffi::gdk_pixbuf_new_from_stream_at_scale_async(stream.to_glib_none().0, width, height, preserve_aspect_ratio.to_glib(), cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _); + } + } + pub unsafe fn get_pixels(&self) -> &mut [u8] { let mut len = 0; let ptr = ffi::gdk_pixbuf_get_pixels_with_length(self.to_glib_none().0, &mut len); @@ -110,4 +162,45 @@ impl Pixbuf { pixels[pos + 3] = alpha; } } + + pub fn get_file_info(filename: &str) -> Option<(PixbufFormat, i32, i32)> { + unsafe { + let mut width = mem::uninitialized(); + let mut height = mem::uninitialized(); + let ret = ffi::gdk_pixbuf_get_file_info(filename.to_glib_none().0, &mut width, &mut height); + if !ret.is_null() { + Some((from_glib_none(ret), width, height)) + } else { + None + } + } + } + + #[cfg(any(feature = "v2_32", feature = "dox"))] + pub fn get_file_info_async<'a, P: Into>, Q: FnOnce(Result, Error>) + Send + 'static>(filename: &str, cancellable: P, callback: Q) { + let cancellable = cancellable.into(); + let cancellable = cancellable.to_glib_none(); + let user_data: Box> = Box::new(Box::new(callback)); + unsafe extern "C" fn get_file_info_async_trampoline, Error>) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut gio_ffi::GAsyncResult, user_data: glib_ffi::gpointer) + { + callback_guard!(); + let mut error = ptr::null_mut(); + let mut width = mem::uninitialized(); + let mut height = mem::uninitialized(); + let ret = ffi::gdk_pixbuf_get_file_info_finish(res, &mut width, &mut height, &mut error); + let result = if !error.is_null() { + Err(from_glib_full(error)) + } else if ret.is_null() { + Ok(None) + } else { + Ok(Some((from_glib_none(ret), width, height))) + }; + let callback: Box> = Box::from_raw(user_data as *mut _); + callback(result); + } + let callback = get_file_info_async_trampoline::; + unsafe { + ffi::gdk_pixbuf_get_file_info_async(filename.to_glib_none().0, cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _); + } + } } From bad7e465d9322471590e4ab22a3b78426f490062 Mon Sep 17 00:00:00 2001 From: Evgenii Pashkin Date: Sun, 17 Dec 2017 21:01:23 +0300 Subject: [PATCH 6/8] Regen --- src/auto/enums.rs | 2 +- src/auto/flags.rs | 2 +- src/auto/mod.rs | 2 +- src/auto/pixbuf.rs | 320 ++++++++++++++++++++------------- src/auto/pixbuf_format.rs | 38 ++-- src/auto/pixbuf_loader.rs | 2 +- src/auto/pixbuf_simple_anim.rs | 2 +- 7 files changed, 219 insertions(+), 149 deletions(-) diff --git a/src/auto/enums.rs b/src/auto/enums.rs index 43278619..2927d9f7 100644 --- a/src/auto/enums.rs +++ b/src/auto/enums.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (d8a605d) from gir-files (469db10) +// This file was generated by gir (5a68ad0) from gir-files (469db10) // DO NOT EDIT use ffi; diff --git a/src/auto/flags.rs b/src/auto/flags.rs index f768a764..4abfb431 100644 --- a/src/auto/flags.rs +++ b/src/auto/flags.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (d8a605d) from gir-files (469db10) +// This file was generated by gir (5a68ad0) from gir-files (469db10) // DO NOT EDIT use ffi; diff --git a/src/auto/mod.rs b/src/auto/mod.rs index c11a35f2..c5ed961c 100644 --- a/src/auto/mod.rs +++ b/src/auto/mod.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (d8a605d) from gir-files (469db10) +// This file was generated by gir (5a68ad0) from gir-files (469db10) // DO NOT EDIT mod pixbuf; diff --git a/src/auto/pixbuf.rs b/src/auto/pixbuf.rs index e584ec5e..46b11086 100644 --- a/src/auto/pixbuf.rs +++ b/src/auto/pixbuf.rs @@ -1,13 +1,14 @@ -// This file was generated by gir (d8a605d) from gir-files (469db10) +// This file was generated by gir (5a68ad0) from gir-files (469db10) // DO NOT EDIT use Colorspace; use Error; +use InterpType; use PixbufFormat; +use PixbufRotation; use ffi; -#[cfg(any(feature = "v2_32", feature = "dox"))] use gio; -#[cfg(any(feature = "v2_32", feature = "dox"))] +#[cfg(any(feature = "v2_36", feature = "dox"))] use gio_ffi; use glib; use glib::StaticType; @@ -75,90 +76,98 @@ impl Pixbuf { } } - //pub fn new_from_stream<'a, P: IsA, Q: Into>>(stream: &P, cancellable: Q) -> Result { - // unsafe { TODO: call ffi::gdk_pixbuf_new_from_stream() } - //} - - //pub fn new_from_stream_at_scale<'a, P: IsA, Q: Into>>(stream: &P, width: i32, height: i32, preserve_aspect_ratio: bool, cancellable: Q) -> Result { - // unsafe { TODO: call ffi::gdk_pixbuf_new_from_stream_at_scale() } - //} - - pub fn new_from_xpm_data(data: &[&str]) -> Pixbuf { + pub fn new_from_stream<'a, P: IsA, Q: Into>>(stream: &P, cancellable: Q) -> Result { + let cancellable = cancellable.into(); + let cancellable = cancellable.to_glib_none(); unsafe { - from_glib_full(ffi::gdk_pixbuf_new_from_xpm_data(data.to_glib_none().0)) + let mut error = ptr::null_mut(); + let ret = ffi::gdk_pixbuf_new_from_stream(stream.to_glib_none().0, cancellable.0, &mut error); + if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) } } } - //pub fn from_pixdata(pixdata: /*Ignored*/&Pixdata, copy_pixels: bool) -> Result { - // unsafe { TODO: call ffi::gdk_pixbuf_from_pixdata() } - //} - - pub fn get_file_info(filename: &str) -> (Option, i32, i32) { + pub fn new_from_stream_at_scale<'a, P: IsA, Q: Into>>(stream: &P, width: i32, height: i32, preserve_aspect_ratio: bool, cancellable: Q) -> Result { + let cancellable = cancellable.into(); + let cancellable = cancellable.to_glib_none(); unsafe { - let mut width = mem::uninitialized(); - let mut height = mem::uninitialized(); - let ret = from_glib_none(ffi::gdk_pixbuf_get_file_info(filename.to_glib_none().0, &mut width, &mut height)); - (ret, width, height) + let mut error = ptr::null_mut(); + let ret = ffi::gdk_pixbuf_new_from_stream_at_scale(stream.to_glib_none().0, width, height, preserve_aspect_ratio.to_glib(), cancellable.0, &mut error); + if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) } } } - #[cfg(any(feature = "v2_32", feature = "dox"))] - pub fn get_file_info_async<'a, P: Into>, Q: Fn(Result<(i32, i32), Error>) + Send + Sync + 'static>(filename: &str, cancellable: P, callback: Q) { - let cancellable = cancellable.into(); - let cancellable = cancellable.to_glib_none(); - let user_data: Box) + Send + Sync + 'static>> = Box::new(Box::new(callback)); - extern "C" fn get_file_info_async_trampoline(_source_object: *mut gobject_ffi::GObject, res: *mut gio_ffi::GAsyncResult, user_data: glib_ffi::gpointer) - { - callback_guard!(); - unsafe { - let mut error = ptr::null_mut(); - let mut width = mem::uninitialized(); - let mut height = mem::uninitialized(); - let _ = ffi::gdk_pixbuf_get_file_info_finish(res, &mut width, &mut height, &mut error); - let result = if error.is_null() { Ok((width, height)) } else { Err(from_glib_full(error)) }; - let callback: &&(Fn(Result<(i32, i32), Error>) + Send + Sync + 'static) = transmute(user_data); - callback(result); - } - } - let callback = get_file_info_async_trampoline; + pub fn new_from_xpm_data(data: &[&str]) -> Pixbuf { unsafe { - ffi::gdk_pixbuf_get_file_info_async(filename.to_glib_none().0, cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _); + from_glib_full(ffi::gdk_pixbuf_new_from_xpm_data(data.to_glib_none().0)) } } + //pub fn from_pixdata(pixdata: /*Ignored*/&Pixdata, copy_pixels: bool) -> Result { + // unsafe { TODO: call ffi::gdk_pixbuf_from_pixdata() } + //} + pub fn get_formats() -> Vec { unsafe { FromGlibPtrContainer::from_glib_container(ffi::gdk_pixbuf_get_formats()) } } - - //pub fn new_from_stream_async<'a, P: IsA, Q: Into>, R: Fn(Result<(), Error>) + Send + Sync + 'static>(stream: &P, cancellable: Q, callback: R) { - // unsafe { TODO: call ffi::gdk_pixbuf_new_from_stream_async() } - //} - - //pub fn new_from_stream_at_scale_async<'a, P: IsA, Q: Into>, R: /*Ignored*/gio::AsyncReadyCallback>(stream: &P, width: i32, height: i32, preserve_aspect_ratio: bool, cancellable: Q, callback: R) { - // unsafe { TODO: call ffi::gdk_pixbuf_new_from_stream_at_scale_async() } - //} } pub trait PixbufExt { + fn add_alpha(&self, substitute_color: bool, r: u8, g: u8, b: u8) -> Option; + fn apply_embedded_orientation(&self) -> Option; + 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); + + 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); + + 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; + + fn copy(&self) -> Option; + + fn copy_area(&self, src_x: i32, src_y: i32, width: i32, height: i32, dest_pixbuf: &Pixbuf, dest_x: i32, dest_y: i32); + #[cfg(any(feature = "v2_36", feature = "dox"))] fn copy_options(&self, dest_pixbuf: &Pixbuf) -> bool; fn fill(&self, pixel: u32); + fn flip(&self, horizontal: bool) -> Option; + + fn get_bits_per_sample(&self) -> i32; + + fn get_byte_length(&self) -> usize; + + fn get_colorspace(&self) -> Colorspace; + + fn get_has_alpha(&self) -> bool; + + fn get_height(&self) -> i32; + + fn get_n_channels(&self) -> i32; + fn get_option(&self, key: &str) -> Option; //#[cfg(any(feature = "v2_32", feature = "dox"))] //fn get_options(&self) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }; + fn get_rowstride(&self) -> i32; + + fn get_width(&self) -> i32; + fn new_subpixbuf(&self, src_x: i32, src_y: i32, width: i32, height: i32) -> Option; + #[cfg(any(feature = "v2_32", feature = "dox"))] + fn read_pixel_bytes(&self) -> Option; + #[cfg(any(feature = "v2_36", feature = "dox"))] fn remove_option(&self, key: &str) -> bool; + fn rotate_simple(&self, angle: PixbufRotation) -> Option; + + fn saturate_and_pixelate(&self, dest: &Pixbuf, saturation: f32, pixelate: bool); + //fn save<'a, P: Into>>(&self, filename: &str, type_: &str, error: P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool; //fn save_to_buffer<'a, P: Into>>(&self, type_: &str, error: P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Option>; @@ -169,38 +178,28 @@ pub trait PixbufExt { //fn save_to_callbackv>>(&self, save_func: /*Unknown conversion*//*Unimplemented*/PixbufSaveFunc, user_data: P, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result<(), Error>; - //fn save_to_stream<'a, 'b, P: IsA, Q: Into>, R: Into>>(&self, stream: &P, type_: &str, cancellable: Q, error: R, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool; + //fn save_to_stream<'a, 'b, P: IsA, Q: Into>, R: Into>>(&self, stream: &P, type_: &str, cancellable: Q, error: R, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool; - //fn save_to_stream_async<'a, P: IsA, Q: Into>, R: Fn(Result<(), Error>) + Send + Sync + 'static>(&self, stream: &P, type_: &str, cancellable: Q, callback: R, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs); + //fn save_to_stream_async<'a, P: IsA, Q: Into>, R: FnOnce(Result<(), Error>) + Send + 'static>(&self, stream: &P, type_: &str, cancellable: Q, callback: R, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs); - //#[cfg(any(feature = "v2_36", feature = "dox"))] - //fn save_to_streamv<'a, P: IsA, Q: Into>>(&self, stream: &P, type_: &str, option_keys: &[&str], option_values: &[&str], cancellable: Q) -> Result<(), Error>; + #[cfg(any(feature = "v2_36", feature = "dox"))] + fn save_to_streamv<'a, P: IsA, Q: Into>>(&self, stream: &P, type_: &str, option_keys: &[&str], option_values: &[&str], cancellable: Q) -> Result<(), Error>; //#[cfg(any(feature = "v2_36", feature = "dox"))] - //fn save_to_streamv_async<'a, P: IsA, Q: Into>, R: /*Ignored*/gio::AsyncReadyCallback>(&self, stream: &P, type_: &str, option_keys: &[&str], option_values: &[&str], cancellable: Q, callback: R); + //fn save_to_streamv_async<'a, P: IsA, Q: Into>, R: /*Unimplemented*/gio::AsyncReadyCallback>(&self, stream: &P, type_: &str, option_keys: &[&str], option_values: &[&str], cancellable: Q, callback: R); fn savev(&self, filename: &str, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result<(), Error>; - fn set_option(&self, key: &str, value: &str) -> bool; - - fn get_property_bits_per_sample(&self) -> i32; - - fn get_property_colorspace(&self) -> Colorspace; + 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); - fn get_property_has_alpha(&self) -> bool; + fn scale_simple(&self, dest_width: i32, dest_height: i32, interp_type: InterpType) -> Option; - fn get_property_height(&self) -> i32; - - fn get_property_n_channels(&self) -> i32; + fn set_option(&self, key: &str, value: &str) -> bool; fn get_property_pixel_bytes(&self) -> Option; //fn get_property_pixels(&self) -> /*Unimplemented*/Fundamental: Pointer; - fn get_property_rowstride(&self) -> i32; - - fn get_property_width(&self) -> i32; - fn connect_property_bits_per_sample_notify(&self, f: F) -> SignalHandlerId; fn connect_property_colorspace_notify(&self, f: F) -> SignalHandlerId; @@ -221,12 +220,48 @@ pub trait PixbufExt { } impl + IsA> PixbufExt for O { + fn add_alpha(&self, substitute_color: bool, r: u8, g: u8, b: u8) -> Option { + unsafe { + from_glib_full(ffi::gdk_pixbuf_add_alpha(const_override(self.to_glib_none().0), substitute_color.to_glib(), r, g, b)) + } + } + fn apply_embedded_orientation(&self) -> Option { unsafe { from_glib_full(ffi::gdk_pixbuf_apply_embedded_orientation(self.to_glib_none().0)) } } + 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(const_override(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); + } + } + + 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(const_override(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); + } + } + + 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 { + unsafe { + from_glib_full(ffi::gdk_pixbuf_composite_color_simple(const_override(self.to_glib_none().0), dest_width, dest_height, interp_type.to_glib(), overall_alpha, check_size, color1, color2)) + } + } + + fn copy(&self) -> Option { + unsafe { + from_glib_full(ffi::gdk_pixbuf_copy(const_override(self.to_glib_none().0))) + } + } + + 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(const_override(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"))] fn copy_options(&self, dest_pixbuf: &Pixbuf) -> bool { unsafe { @@ -240,6 +275,48 @@ impl + IsA> PixbufExt for O { } } + fn flip(&self, horizontal: bool) -> Option { + unsafe { + from_glib_full(ffi::gdk_pixbuf_flip(const_override(self.to_glib_none().0), horizontal.to_glib())) + } + } + + fn get_bits_per_sample(&self) -> i32 { + unsafe { + ffi::gdk_pixbuf_get_bits_per_sample(const_override(self.to_glib_none().0)) + } + } + + fn get_byte_length(&self) -> usize { + unsafe { + ffi::gdk_pixbuf_get_byte_length(const_override(self.to_glib_none().0)) + } + } + + fn get_colorspace(&self) -> Colorspace { + unsafe { + from_glib(ffi::gdk_pixbuf_get_colorspace(const_override(self.to_glib_none().0))) + } + } + + fn get_has_alpha(&self) -> bool { + unsafe { + from_glib(ffi::gdk_pixbuf_get_has_alpha(const_override(self.to_glib_none().0))) + } + } + + fn get_height(&self) -> i32 { + unsafe { + ffi::gdk_pixbuf_get_height(const_override(self.to_glib_none().0)) + } + } + + fn get_n_channels(&self) -> i32 { + unsafe { + ffi::gdk_pixbuf_get_n_channels(const_override(self.to_glib_none().0)) + } + } + fn get_option(&self, key: &str) -> Option { unsafe { from_glib_none(ffi::gdk_pixbuf_get_option(self.to_glib_none().0, key.to_glib_none().0)) @@ -251,12 +328,31 @@ impl + IsA> PixbufExt for O { // unsafe { TODO: call ffi::gdk_pixbuf_get_options() } //} + fn get_rowstride(&self) -> i32 { + unsafe { + ffi::gdk_pixbuf_get_rowstride(const_override(self.to_glib_none().0)) + } + } + + fn get_width(&self) -> i32 { + unsafe { + ffi::gdk_pixbuf_get_width(const_override(self.to_glib_none().0)) + } + } + fn new_subpixbuf(&self, src_x: i32, src_y: i32, width: i32, height: i32) -> Option { 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"))] + fn read_pixel_bytes(&self) -> Option { + unsafe { + from_glib_full(ffi::gdk_pixbuf_read_pixel_bytes(const_override(self.to_glib_none().0))) + } + } + #[cfg(any(feature = "v2_36", feature = "dox"))] fn remove_option(&self, key: &str) -> bool { unsafe { @@ -264,6 +360,18 @@ impl + IsA> PixbufExt for O { } } + fn rotate_simple(&self, angle: PixbufRotation) -> Option { + unsafe { + from_glib_full(ffi::gdk_pixbuf_rotate_simple(const_override(self.to_glib_none().0), angle.to_glib())) + } + } + + fn saturate_and_pixelate(&self, dest: &Pixbuf, saturation: f32, pixelate: bool) { + unsafe { + ffi::gdk_pixbuf_saturate_and_pixelate(const_override(self.to_glib_none().0), dest.to_glib_none().0, saturation, pixelate.to_glib()); + } + } + //fn save<'a, P: Into>>(&self, filename: &str, type_: &str, error: P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool { // unsafe { TODO: call ffi::gdk_pixbuf_save() } //} @@ -290,21 +398,27 @@ impl + IsA> PixbufExt for O { // unsafe { TODO: call ffi::gdk_pixbuf_save_to_callbackv() } //} - //fn save_to_stream<'a, 'b, P: IsA, Q: Into>, R: Into>>(&self, stream: &P, type_: &str, cancellable: Q, error: R, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool { + //fn save_to_stream<'a, 'b, P: IsA, Q: Into>, R: Into>>(&self, stream: &P, type_: &str, cancellable: Q, error: R, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool { // unsafe { TODO: call ffi::gdk_pixbuf_save_to_stream() } //} - //fn save_to_stream_async<'a, P: IsA, Q: Into>, R: Fn(Result<(), Error>) + Send + Sync + 'static>(&self, stream: &P, type_: &str, cancellable: Q, callback: R, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) { + //fn save_to_stream_async<'a, P: IsA, Q: Into>, R: FnOnce(Result<(), Error>) + Send + 'static>(&self, stream: &P, type_: &str, cancellable: Q, callback: R, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) { // unsafe { TODO: call ffi::gdk_pixbuf_save_to_stream_async() } //} - //#[cfg(any(feature = "v2_36", feature = "dox"))] - //fn save_to_streamv<'a, P: IsA, Q: Into>>(&self, stream: &P, type_: &str, option_keys: &[&str], option_values: &[&str], cancellable: Q) -> Result<(), Error> { - // unsafe { TODO: call ffi::gdk_pixbuf_save_to_streamv() } - //} + #[cfg(any(feature = "v2_36", feature = "dox"))] + fn save_to_streamv<'a, P: IsA, Q: Into>>(&self, stream: &P, type_: &str, option_keys: &[&str], option_values: &[&str], cancellable: Q) -> Result<(), Error> { + let cancellable = cancellable.into(); + let cancellable = cancellable.to_glib_none(); + unsafe { + let mut error = ptr::null_mut(); + let _ = ffi::gdk_pixbuf_save_to_streamv(self.to_glib_none().0, stream.to_glib_none().0, type_.to_glib_none().0, option_keys.to_glib_none().0, option_values.to_glib_none().0, cancellable.0, &mut error); + if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } + } + } //#[cfg(any(feature = "v2_36", feature = "dox"))] - //fn save_to_streamv_async<'a, P: IsA, Q: Into>, R: /*Ignored*/gio::AsyncReadyCallback>(&self, stream: &P, type_: &str, option_keys: &[&str], option_values: &[&str], cancellable: Q, callback: R) { + //fn save_to_streamv_async<'a, P: IsA, Q: Into>, R: /*Unimplemented*/gio::AsyncReadyCallback>(&self, stream: &P, type_: &str, option_keys: &[&str], option_values: &[&str], cancellable: Q, callback: R) { // unsafe { TODO: call ffi::gdk_pixbuf_save_to_streamv_async() } //} @@ -316,49 +430,21 @@ impl + IsA> PixbufExt for O { } } - fn set_option(&self, key: &str, value: &str) -> bool { + 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 { - from_glib(ffi::gdk_pixbuf_set_option(self.to_glib_none().0, key.to_glib_none().0, value.to_glib_none().0)) + ffi::gdk_pixbuf_scale(const_override(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()); } } - fn get_property_bits_per_sample(&self) -> i32 { + fn scale_simple(&self, dest_width: i32, dest_height: i32, interp_type: InterpType) -> Option { unsafe { - let mut value = Value::from_type(::static_type()); - gobject_ffi::g_object_get_property(self.to_glib_none().0, "bits-per-sample".to_glib_none().0, value.to_glib_none_mut().0); - value.get().unwrap() + from_glib_full(ffi::gdk_pixbuf_scale_simple(const_override(self.to_glib_none().0), dest_width, dest_height, interp_type.to_glib())) } } - fn get_property_colorspace(&self) -> Colorspace { - unsafe { - let mut value = Value::from_type(::static_type()); - gobject_ffi::g_object_get_property(self.to_glib_none().0, "colorspace".to_glib_none().0, value.to_glib_none_mut().0); - value.get().unwrap() - } - } - - fn get_property_has_alpha(&self) -> bool { - unsafe { - let mut value = Value::from_type(::static_type()); - gobject_ffi::g_object_get_property(self.to_glib_none().0, "has-alpha".to_glib_none().0, value.to_glib_none_mut().0); - value.get().unwrap() - } - } - - fn get_property_height(&self) -> i32 { - unsafe { - let mut value = Value::from_type(::static_type()); - gobject_ffi::g_object_get_property(self.to_glib_none().0, "height".to_glib_none().0, value.to_glib_none_mut().0); - value.get().unwrap() - } - } - - fn get_property_n_channels(&self) -> i32 { + fn set_option(&self, key: &str, value: &str) -> bool { unsafe { - let mut value = Value::from_type(::static_type()); - gobject_ffi::g_object_get_property(self.to_glib_none().0, "n-channels".to_glib_none().0, value.to_glib_none_mut().0); - value.get().unwrap() + from_glib(ffi::gdk_pixbuf_set_option(self.to_glib_none().0, key.to_glib_none().0, value.to_glib_none().0)) } } @@ -378,22 +464,6 @@ impl + IsA> PixbufExt for O { // } //} - fn get_property_rowstride(&self) -> i32 { - unsafe { - let mut value = Value::from_type(::static_type()); - gobject_ffi::g_object_get_property(self.to_glib_none().0, "rowstride".to_glib_none().0, value.to_glib_none_mut().0); - value.get().unwrap() - } - } - - fn get_property_width(&self) -> i32 { - unsafe { - let mut value = Value::from_type(::static_type()); - gobject_ffi::g_object_get_property(self.to_glib_none().0, "width".to_glib_none().0, value.to_glib_none_mut().0); - value.get().unwrap() - } - } - fn connect_property_bits_per_sample_notify(&self, f: F) -> SignalHandlerId { unsafe { let f: Box_> = Box_::new(Box_::new(f)); diff --git a/src/auto/pixbuf_format.rs b/src/auto/pixbuf_format.rs index 622198ae..09c75549 100644 --- a/src/auto/pixbuf_format.rs +++ b/src/auto/pixbuf_format.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (d8a605d) from gir-files (469db10) +// This file was generated by gir (5a68ad0) from gir-files (469db10) // DO NOT EDIT use ffi; @@ -19,58 +19,58 @@ glib_wrapper! { } impl PixbufFormat { - pub fn get_description(&mut self) -> Option { + pub fn get_description(&self) -> Option { unsafe { - from_glib_full(ffi::gdk_pixbuf_format_get_description(self.to_glib_none_mut().0)) + from_glib_full(ffi::gdk_pixbuf_format_get_description(mut_override(self.to_glib_none().0))) } } - pub fn get_extensions(&mut self) -> Vec { + pub fn get_extensions(&self) -> Vec { unsafe { - FromGlibPtrContainer::from_glib_full(ffi::gdk_pixbuf_format_get_extensions(self.to_glib_none_mut().0)) + FromGlibPtrContainer::from_glib_full(ffi::gdk_pixbuf_format_get_extensions(mut_override(self.to_glib_none().0))) } } - pub fn get_license(&mut self) -> Option { + pub fn get_license(&self) -> Option { unsafe { - from_glib_full(ffi::gdk_pixbuf_format_get_license(self.to_glib_none_mut().0)) + from_glib_full(ffi::gdk_pixbuf_format_get_license(mut_override(self.to_glib_none().0))) } } - pub fn get_mime_types(&mut self) -> Vec { + pub fn get_mime_types(&self) -> Vec { unsafe { - FromGlibPtrContainer::from_glib_full(ffi::gdk_pixbuf_format_get_mime_types(self.to_glib_none_mut().0)) + FromGlibPtrContainer::from_glib_full(ffi::gdk_pixbuf_format_get_mime_types(mut_override(self.to_glib_none().0))) } } - pub fn get_name(&mut self) -> Option { + pub fn get_name(&self) -> Option { unsafe { - from_glib_full(ffi::gdk_pixbuf_format_get_name(self.to_glib_none_mut().0)) + from_glib_full(ffi::gdk_pixbuf_format_get_name(mut_override(self.to_glib_none().0))) } } - pub fn is_disabled(&mut self) -> bool { + pub fn is_disabled(&self) -> bool { unsafe { - from_glib(ffi::gdk_pixbuf_format_is_disabled(self.to_glib_none_mut().0)) + from_glib(ffi::gdk_pixbuf_format_is_disabled(mut_override(self.to_glib_none().0))) } } #[cfg(any(feature = "v2_36", feature = "dox"))] - pub fn is_save_option_supported(&mut self, option_key: &str) -> bool { + pub fn is_save_option_supported(&self, option_key: &str) -> bool { unsafe { - from_glib(ffi::gdk_pixbuf_format_is_save_option_supported(self.to_glib_none_mut().0, option_key.to_glib_none().0)) + from_glib(ffi::gdk_pixbuf_format_is_save_option_supported(mut_override(self.to_glib_none().0), option_key.to_glib_none().0)) } } - pub fn is_scalable(&mut self) -> bool { + pub fn is_scalable(&self) -> bool { unsafe { - from_glib(ffi::gdk_pixbuf_format_is_scalable(self.to_glib_none_mut().0)) + from_glib(ffi::gdk_pixbuf_format_is_scalable(mut_override(self.to_glib_none().0))) } } - pub fn is_writable(&mut self) -> bool { + pub fn is_writable(&self) -> bool { unsafe { - from_glib(ffi::gdk_pixbuf_format_is_writable(self.to_glib_none_mut().0)) + from_glib(ffi::gdk_pixbuf_format_is_writable(mut_override(self.to_glib_none().0))) } } diff --git a/src/auto/pixbuf_loader.rs b/src/auto/pixbuf_loader.rs index f0152885..8f20c2cc 100644 --- a/src/auto/pixbuf_loader.rs +++ b/src/auto/pixbuf_loader.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (d8a605d) from gir-files (469db10) +// This file was generated by gir (5a68ad0) from gir-files (469db10) // DO NOT EDIT use Error; diff --git a/src/auto/pixbuf_simple_anim.rs b/src/auto/pixbuf_simple_anim.rs index 995726f3..27d0530a 100644 --- a/src/auto/pixbuf_simple_anim.rs +++ b/src/auto/pixbuf_simple_anim.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (d8a605d) from gir-files (469db10) +// This file was generated by gir (5a68ad0) from gir-files (469db10) // DO NOT EDIT use Pixbuf; From 6198488df3441ab6570bac38d732a6c799fcc84c Mon Sep 17 00:00:00 2001 From: Evgenii Pashkin Date: Sat, 30 Dec 2017 06:46:45 +0300 Subject: [PATCH 7/8] Use AsRef for filenames --- src/animation.rs | 5 +++-- src/pixbuf.rs | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/animation.rs b/src/animation.rs index 4ee3e98d..cac0528f 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -3,6 +3,7 @@ // Licensed under the MIT license, see the LICENSE file or use std::mem; +use std::path::Path; use std::ptr; use glib::{Error, TimeVal}; use glib::object::IsA; @@ -53,7 +54,7 @@ glib_wrapper! { } impl PixbufAnimation { - pub fn new_from_file(file: &str) -> Result { + pub fn new_from_file>(file: T) -> Result { #[cfg(windows)] use ffi::gdk_pixbuf_animation_new_from_file_utf8 as gdk_pixbuf_animation_new_from_file; @@ -62,7 +63,7 @@ impl PixbufAnimation { unsafe { let mut error = ptr::null_mut(); - let ptr = gdk_pixbuf_animation_new_from_file(file.to_glib_none().0, &mut error); + let ptr = gdk_pixbuf_animation_new_from_file(file.as_ref().to_glib_none().0, &mut error); if error.is_null() { Ok(from_glib_full(ptr)) } else { diff --git a/src/pixbuf.rs b/src/pixbuf.rs index ed0c94a1..821738c4 100644 --- a/src/pixbuf.rs +++ b/src/pixbuf.rs @@ -3,6 +3,7 @@ // Licensed under the MIT license, see the LICENSE file or use std::mem; +use std::path::Path; use std::ptr; use std::slice; use libc::{c_void, c_uchar}; @@ -42,7 +43,7 @@ impl Pixbuf { } } - pub fn new_from_file(filename: &str) -> Result { + pub fn new_from_file>(filename: T) -> Result { #[cfg(windows)] use ffi::gdk_pixbuf_new_from_file_utf8 as gdk_pixbuf_new_from_file; #[cfg(not(windows))] @@ -50,7 +51,7 @@ impl Pixbuf { unsafe { let mut error = ptr::null_mut(); - let ptr = gdk_pixbuf_new_from_file(filename.to_glib_none().0, &mut error); + let ptr = gdk_pixbuf_new_from_file(filename.as_ref().to_glib_none().0, &mut error); if error.is_null() { Ok(from_glib_full(ptr)) } else { @@ -59,7 +60,7 @@ impl Pixbuf { } } - pub fn new_from_file_at_size(filename: &str, width: i32, height: i32) -> Result { + pub fn new_from_file_at_size>(filename: T, width: i32, height: i32) -> Result { #[cfg(windows)] use ffi::gdk_pixbuf_new_from_file_at_size_utf8 as gdk_pixbuf_new_from_file_at_size; @@ -68,7 +69,7 @@ impl Pixbuf { unsafe { let mut error = ptr::null_mut(); - let ptr = gdk_pixbuf_new_from_file_at_size(filename.to_glib_none().0, width, height, + let ptr = gdk_pixbuf_new_from_file_at_size(filename.as_ref().to_glib_none().0, width, height, &mut error); if error.is_null() { Ok(from_glib_full(ptr)) @@ -78,7 +79,7 @@ impl Pixbuf { } } - pub fn new_from_file_at_scale(filename: &str, width: i32, height: i32, preserve_aspect_ratio: bool) -> Result { + pub fn new_from_file_at_scale>(filename: T, width: i32, height: i32, preserve_aspect_ratio: bool) -> Result { #[cfg(windows)] use ffi::gdk_pixbuf_new_from_file_at_scale_utf8 as gdk_pixbuf_new_from_file_at_scale; @@ -87,7 +88,7 @@ impl Pixbuf { unsafe { let mut error = ptr::null_mut(); - let ptr = gdk_pixbuf_new_from_file_at_scale(filename.to_glib_none().0, width, height, + let ptr = gdk_pixbuf_new_from_file_at_scale(filename.as_ref().to_glib_none().0, width, height, preserve_aspect_ratio.to_glib(), &mut error); if error.is_null() { Ok(from_glib_full(ptr)) @@ -163,11 +164,11 @@ impl Pixbuf { } } - pub fn get_file_info(filename: &str) -> Option<(PixbufFormat, i32, i32)> { + pub fn get_file_info>(filename: T) -> Option<(PixbufFormat, i32, i32)> { unsafe { let mut width = mem::uninitialized(); let mut height = mem::uninitialized(); - let ret = ffi::gdk_pixbuf_get_file_info(filename.to_glib_none().0, &mut width, &mut height); + let ret = ffi::gdk_pixbuf_get_file_info(filename.as_ref().to_glib_none().0, &mut width, &mut height); if !ret.is_null() { Some((from_glib_none(ret), width, height)) } else { @@ -177,7 +178,7 @@ impl Pixbuf { } #[cfg(any(feature = "v2_32", feature = "dox"))] - pub fn get_file_info_async<'a, P: Into>, Q: FnOnce(Result, Error>) + Send + 'static>(filename: &str, cancellable: P, callback: Q) { + pub fn get_file_info_async<'a, P: Into>, Q: FnOnce(Result, Error>) + Send + 'static, T: AsRef>(filename: T, cancellable: P, callback: Q) { let cancellable = cancellable.into(); let cancellable = cancellable.to_glib_none(); let user_data: Box> = Box::new(Box::new(callback)); @@ -200,7 +201,7 @@ impl Pixbuf { } let callback = get_file_info_async_trampoline::; unsafe { - ffi::gdk_pixbuf_get_file_info_async(filename.to_glib_none().0, cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _); + ffi::gdk_pixbuf_get_file_info_async(filename.as_ref().to_glib_none().0, cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _); } } } From 4b8383d55dd6cf92cb7ca9726ee789319536c42b Mon Sep 17 00:00:00 2001 From: Evgenii Pashkin Date: Sat, 30 Dec 2017 08:13:17 +0300 Subject: [PATCH 8/8] Implement safer version save* --- Gir.toml | 12 ++++++++++++ src/auto/pixbuf.rs | 36 ------------------------------------ src/pixbuf.rs | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 36 deletions(-) diff --git a/Gir.toml b/Gir.toml index 1ffdb9ba..582ef544 100644 --- a/Gir.toml +++ b/Gir.toml @@ -70,6 +70,18 @@ status = "generate" name = "get_file_info_async" # wrong async return ignore = true + [[object.function]] + name = "save_to_bufferv" + # manual complex param + ignore = true + [[object.function]] + name = "save_to_streamv" + # manual complex param + ignore = true + [[object.function]] + name = "savev" + # manual complex param + ignore = true [[object]] name = "GdkPixbuf.PixbufFormat" diff --git a/src/auto/pixbuf.rs b/src/auto/pixbuf.rs index 46b11086..d339ffea 100644 --- a/src/auto/pixbuf.rs +++ b/src/auto/pixbuf.rs @@ -172,8 +172,6 @@ pub trait PixbufExt { //fn save_to_buffer<'a, P: Into>>(&self, type_: &str, error: P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Option>; - fn save_to_bufferv(&self, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result, Error>; - //fn save_to_callback<'a, P: Into>, Q: Into>>(&self, save_func: /*Unknown conversion*//*Unimplemented*/PixbufSaveFunc, user_data: P, type_: &str, error: Q, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool; //fn save_to_callbackv>>(&self, save_func: /*Unknown conversion*//*Unimplemented*/PixbufSaveFunc, user_data: P, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result<(), Error>; @@ -182,14 +180,9 @@ pub trait PixbufExt { //fn save_to_stream_async<'a, P: IsA, Q: Into>, R: FnOnce(Result<(), Error>) + Send + 'static>(&self, stream: &P, type_: &str, cancellable: Q, callback: R, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs); - #[cfg(any(feature = "v2_36", feature = "dox"))] - fn save_to_streamv<'a, P: IsA, Q: Into>>(&self, stream: &P, type_: &str, option_keys: &[&str], option_values: &[&str], cancellable: Q) -> Result<(), Error>; - //#[cfg(any(feature = "v2_36", feature = "dox"))] //fn save_to_streamv_async<'a, P: IsA, Q: Into>, R: /*Unimplemented*/gio::AsyncReadyCallback>(&self, stream: &P, type_: &str, option_keys: &[&str], option_values: &[&str], cancellable: Q, callback: R); - fn savev(&self, filename: &str, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result<(), Error>; - 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); fn scale_simple(&self, dest_width: i32, dest_height: i32, interp_type: InterpType) -> Option; @@ -380,16 +373,6 @@ impl + IsA> PixbufExt for O { // unsafe { TODO: call ffi::gdk_pixbuf_save_to_buffer() } //} - fn save_to_bufferv(&self, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result, Error> { - unsafe { - let mut buffer = ptr::null_mut(); - let mut buffer_size = mem::uninitialized(); - let mut error = ptr::null_mut(); - let _ = ffi::gdk_pixbuf_save_to_bufferv(self.to_glib_none().0, &mut buffer, &mut buffer_size, type_.to_glib_none().0, option_keys.to_glib_none().0, option_values.to_glib_none().0, &mut error); - if error.is_null() { Ok(FromGlibContainer::from_glib_full_num(buffer, buffer_size as usize)) } else { Err(from_glib_full(error)) } - } - } - //fn save_to_callback<'a, P: Into>, Q: Into>>(&self, save_func: /*Unknown conversion*//*Unimplemented*/PixbufSaveFunc, user_data: P, type_: &str, error: Q, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool { // unsafe { TODO: call ffi::gdk_pixbuf_save_to_callback() } //} @@ -406,30 +389,11 @@ impl + IsA> PixbufExt for O { // unsafe { TODO: call ffi::gdk_pixbuf_save_to_stream_async() } //} - #[cfg(any(feature = "v2_36", feature = "dox"))] - fn save_to_streamv<'a, P: IsA, Q: Into>>(&self, stream: &P, type_: &str, option_keys: &[&str], option_values: &[&str], cancellable: Q) -> Result<(), Error> { - let cancellable = cancellable.into(); - let cancellable = cancellable.to_glib_none(); - unsafe { - let mut error = ptr::null_mut(); - let _ = ffi::gdk_pixbuf_save_to_streamv(self.to_glib_none().0, stream.to_glib_none().0, type_.to_glib_none().0, option_keys.to_glib_none().0, option_values.to_glib_none().0, cancellable.0, &mut error); - if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } - } - } - //#[cfg(any(feature = "v2_36", feature = "dox"))] //fn save_to_streamv_async<'a, P: IsA, Q: Into>, R: /*Unimplemented*/gio::AsyncReadyCallback>(&self, stream: &P, type_: &str, option_keys: &[&str], option_values: &[&str], cancellable: Q, callback: R) { // unsafe { TODO: call ffi::gdk_pixbuf_save_to_streamv_async() } //} - fn savev(&self, filename: &str, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result<(), Error> { - unsafe { - let mut error = ptr::null_mut(); - let _ = ffi::gdk_pixbuf_savev(self.to_glib_none().0, filename.to_glib_none().0, type_.to_glib_none().0, option_keys.to_glib_none().0, option_values.to_glib_none().0, &mut error); - if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } - } - } - 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(const_override(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()); diff --git a/src/pixbuf.rs b/src/pixbuf.rs index 821738c4..22d783a8 100644 --- a/src/pixbuf.rs +++ b/src/pixbuf.rs @@ -204,4 +204,39 @@ impl Pixbuf { ffi::gdk_pixbuf_get_file_info_async(filename.as_ref().to_glib_none().0, cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _); } } + + pub fn save_to_bufferv(&self, type_: &str, options: &[(&str, &str)]) -> Result, Error> { + unsafe { + let mut buffer = ptr::null_mut(); + let mut buffer_size = mem::uninitialized(); + let mut error = ptr::null_mut(); + let option_keys: Vec<&str> = options.iter().map(|o| o.0).collect(); + let option_values: Vec<&str> = options.iter().map(|o| o.1).collect(); + let _ = ffi::gdk_pixbuf_save_to_bufferv(self.to_glib_none().0, &mut buffer, &mut buffer_size, type_.to_glib_none().0, option_keys.to_glib_none().0, option_values.to_glib_none().0, &mut error); + if error.is_null() { Ok(FromGlibContainer::from_glib_full_num(buffer, buffer_size as usize)) } else { Err(from_glib_full(error)) } + } + } + + #[cfg(any(feature = "v2_36", feature = "dox"))] + pub fn save_to_streamv<'a, P: IsA, Q: Into>>(&self, stream: &P, type_: &str, options: &[(&str, &str)], cancellable: Q) -> Result<(), Error> { + let cancellable = cancellable.into(); + let cancellable = cancellable.to_glib_none(); + unsafe { + let mut error = ptr::null_mut(); + let option_keys: Vec<&str> = options.iter().map(|o| o.0).collect(); + let option_values: Vec<&str> = options.iter().map(|o| o.1).collect(); + let _ = ffi::gdk_pixbuf_save_to_streamv(self.to_glib_none().0, stream.to_glib_none().0, type_.to_glib_none().0, option_keys.to_glib_none().0, option_values.to_glib_none().0, cancellable.0, &mut error); + if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } + } + } + + pub fn savev>(&self, filename: T, type_: &str, options: &[(&str, &str)]) -> Result<(), Error> { + unsafe { + let mut error = ptr::null_mut(); + let option_keys: Vec<&str> = options.iter().map(|o| o.0).collect(); + let option_values: Vec<&str> = options.iter().map(|o| o.1).collect(); + let _ = ffi::gdk_pixbuf_savev(self.to_glib_none().0, filename.as_ref().to_glib_none().0, type_.to_glib_none().0, option_keys.to_glib_none().0, option_values.to_glib_none().0, &mut error); + if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } + } + } }