gdk-pixbuf-0.14.0/.cargo_vcs_info.json0000644000000001120000000000100131500ustar { "git": { "sha1": "8708ff7604ba3ec0a936451e5ac0e94c0764d001" } } gdk-pixbuf-0.14.0/COPYRIGHT000064400000000000000000000012130072674642500132660ustar 00000000000000The gtk-rs Project is licensed under the MIT license, see the LICENSE file or . Copyrights in the gtk-rs Project project are retained by their contributors. No copyright assignment is required to contribute to the gtk-rs Project project. For full authorship information, see the version control history. This project provides interoperability with various GNOME libraries but doesn't distribute any parts of them. Distributing compiled libraries and executables that link to those libraries may be subject to terms of the GNU LGPL or other licenses. For more information check the license of each GNOME library. gdk-pixbuf-0.14.0/Cargo.toml0000644000000025740000000000100111640ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "gdk-pixbuf" version = "0.14.0" authors = ["The gtk-rs Project Developers"] exclude = ["gir-files/*"] description = "Rust bindings for the GdkPixbuf library" homepage = "https://gtk-rs.org/" documentation = "https://gtk-rs.org/gtk-rs-core/stable/latest/docs/gdk_pixbuf/" readme = "README.md" keywords = ["gdk-pixbuf", "gtk-rs", "gnome"] license = "MIT" repository = "https://github.com/gtk-rs/gtk-rs-core" [package.metadata.docs.rs] features = ["dox"] [lib] name = "gdk_pixbuf" [dependencies.ffi] version = "0.14.0" package = "gdk-pixbuf-sys" [dependencies.gio] version = "0.14.0" [dependencies.glib] version = "0.14.0" [dependencies.libc] version = "0.2" [dev-dependencies.gir-format-check] version = "^0.1" [features] dox = ["glib/dox", "ffi/dox"] v2_36 = ["ffi/v2_36"] v2_36_8 = ["v2_36", "ffi/v2_36_8"] v2_40 = ["v2_36_8", "ffi/v2_40"] gdk-pixbuf-0.14.0/Cargo.toml.orig000064400000000000000000000014560072674642500146730ustar 00000000000000[package] name = "gdk-pixbuf" license = "MIT" homepage = "https://gtk-rs.org/" authors = ["The gtk-rs Project Developers"] keywords = ["gdk-pixbuf", "gtk-rs", "gnome"] readme = "README.md" documentation = "https://gtk-rs.org/gtk-rs-core/stable/latest/docs/gdk_pixbuf/" version = "0.14.0" description = "Rust bindings for the GdkPixbuf library" repository = "https://github.com/gtk-rs/gtk-rs-core" exclude = [ "gir-files/*", ] edition = "2018" [lib] name = "gdk_pixbuf" [features] v2_36 = ["ffi/v2_36"] v2_36_8 = ["v2_36", "ffi/v2_36_8"] v2_40 = ["v2_36_8", "ffi/v2_40"] dox = ["glib/dox", "ffi/dox"] [package.metadata.docs.rs] features = ["dox"] [dependencies] libc = "0.2" ffi = {package = "gdk-pixbuf-sys", version = "0.14.0"} glib = "0.14.0" gio = "0.14.0" [dev-dependencies] gir-format-check = "^0.1" gdk-pixbuf-0.14.0/Gir.toml000064400000000000000000000054170072674642500134230ustar 00000000000000[options] girs_directories = ["../gir-files"] library = "GdkPixbuf" version = "2.0" min_cfg_version = "2.32" target_path = "." work_mode = "normal" single_version_file = true deprecate_by_min_version = true generate = [ "GdkPixbuf.Colorspace", "GdkPixbuf.InterpType", "GdkPixbuf.PixbufAlphaMode", "GdkPixbuf.PixbufError", "GdkPixbuf.PixbufLoader", "GdkPixbuf.PixbufRotation", "GdkPixbuf.PixbufSimpleAnim", ] manual = [ "GdkPixbuf.PixbufAnimationIter", "Gio.AsyncReadyCallback", "Gio.Cancellable", "Gio.Icon", "Gio.InputStream", "Gio.LoadableIcon", "Gio.OutputStream", "GLib.Bytes", "GLib.Error", ] [[object]] name = "GdkPixbuf.Pixbuf" status = "generate" [[object.function]] name = "get_pixels" #manual array without length manual = true [[object.function]] name = "get_pixels_with_length" #manual as get_pixels ignore = true [[object.function]] name = "read_pixels" #unimplementable, use get_pixels instead ignore = true [[object.function]] name = "new_from_file" #manual is_windows_utf8 manual = true [[object.function]] name = "new" [object.function.return] nullable = true [[object.function]] name = "new_from_file_at_size" #manual is_windows_utf8 manual = true [[object.function]] name = "new_from_file_at_scale" #manual is_windows_utf8 manual = true [[object.function]] name = "new_from_stream_async" # wrong async return manual = true [[object.function]] name = "new_from_stream_at_scale_async" # wrong return and don't generated manual = true [[object.function]] name = "get_file_info" # wrong return manual = true [[object.function]] name = "get_file_info_async" # wrong async return manual = true [[object.function]] name = "save_to_bufferv" # manual complex param manual = true [[object.function]] name = "save_to_streamv" # manual complex param manual = true [[object.function]] name = "savev" # manual complex param manual = true [[object.function]] name = "save_to_streamv_async" # manual complex param manual = true [[object]] name = "GdkPixbuf.PixbufAnimation" status = "generate" [[object.function]] name = "get_iter" # TimeVal misses memory management functions manual = true [[object.function]] name = "new_from_stream_async" constructor = 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 gdk-pixbuf-0.14.0/LICENSE000064400000000000000000000020000072674642500127730ustar 00000000000000Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gdk-pixbuf-0.14.0/README.md000064400000000000000000000023630072674642500132610ustar 00000000000000# gdk-pixbuf __Rust__ bindings and wrappers for __Gdk-Pixbuf__, part of [gtk-rs-core](https://github.com/gtk-rs/gtk-rs-core). ## Minimum supported Rust version Currently, the minimum supported Rust version is `1.51.0`. ## Documentation * [Rust API - Stable](https://gtk-rs.org/gtk-rs-core/stable/latest/docs/gdk_pixbuf/) * [Rust API - Development](https://gtk-rs.org/gtk-rs-core/git/docs/gdk_pixbuf) * [C API](https://developer.gnome.org/gdk-pixbuf/stable/) * [GTK Installation instructions](https://www.gtk.org/docs/installations/) ## Using We recommend using [crates from crates.io](https://crates.io/keywords/gtk-rs), as [demonstrated here](https://gtk-rs.org/#using). If you want to track the bleeding edge, use the git dependency instead: ```toml [dependencies] gdk-pixbuf = { git = "https://github.com/gtk-rs/gtk-rs-core.git", package = "gdk-pixbuf" } ``` Avoid mixing versioned and git crates like this: ```toml # This will not compile [dependencies] gdk-pixbuf = "0.13" gdk-pixbuf = { git = "https://github.com/gtk-rs/gtk-rs-core.git", package = "gdk-pixbuf" } ``` ### See Also * [glib](https://crates.io/crates/glib) * [gio](https://crates.io/crates/gio) ## License __gdk-pixbuf__ is available under the MIT License, please refer to it. gdk-pixbuf-0.14.0/src/auto/enums.rs000064400000000000000000000333740072674642500152440ustar 00000000000000// 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 glib::error::ErrorDomain; use glib::translate::*; use glib::value::FromValue; use glib::value::ToValue; use glib::Quark; use glib::StaticType; use glib::Type; use std::fmt; #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] #[doc(alias = "GdkColorspace")] pub enum Colorspace { #[doc(alias = "GDK_COLORSPACE_RGB")] Rgb, #[doc(hidden)] __Unknown(i32), } impl fmt::Display for Colorspace { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "Colorspace::{}", match *self { Self::Rgb => "Rgb", _ => "Unknown", } ) } } #[doc(hidden)] impl IntoGlib for Colorspace { type GlibType = ffi::GdkColorspace; fn into_glib(self) -> ffi::GdkColorspace { match self { Self::Rgb => ffi::GDK_COLORSPACE_RGB, Self::__Unknown(value) => value, } } } #[doc(hidden)] impl FromGlib for Colorspace { unsafe fn from_glib(value: ffi::GdkColorspace) -> Self { match value { ffi::GDK_COLORSPACE_RGB => Self::Rgb, value => Self::__Unknown(value), } } } impl StaticType for Colorspace { fn static_type() -> Type { unsafe { from_glib(ffi::gdk_colorspace_get_type()) } } } impl glib::value::ValueType for Colorspace { type Type = Self; } unsafe impl<'a> FromValue<'a> for Colorspace { type Checker = glib::value::GenericValueTypeChecker; unsafe fn from_value(value: &'a glib::Value) -> Self { from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0)) } } impl ToValue for Colorspace { fn to_value(&self) -> glib::Value { let mut value = glib::Value::for_value_type::(); unsafe { glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()); } value } fn value_type(&self) -> glib::Type { Self::static_type() } } #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] #[doc(alias = "GdkInterpType")] pub enum InterpType { #[doc(alias = "GDK_INTERP_NEAREST")] Nearest, #[doc(alias = "GDK_INTERP_TILES")] Tiles, #[doc(alias = "GDK_INTERP_BILINEAR")] Bilinear, #[doc(alias = "GDK_INTERP_HYPER")] Hyper, #[doc(hidden)] __Unknown(i32), } impl fmt::Display for InterpType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "InterpType::{}", match *self { Self::Nearest => "Nearest", Self::Tiles => "Tiles", Self::Bilinear => "Bilinear", Self::Hyper => "Hyper", _ => "Unknown", } ) } } #[doc(hidden)] impl IntoGlib for InterpType { type GlibType = ffi::GdkInterpType; fn into_glib(self) -> ffi::GdkInterpType { match self { Self::Nearest => ffi::GDK_INTERP_NEAREST, Self::Tiles => ffi::GDK_INTERP_TILES, Self::Bilinear => ffi::GDK_INTERP_BILINEAR, Self::Hyper => ffi::GDK_INTERP_HYPER, Self::__Unknown(value) => value, } } } #[doc(hidden)] impl FromGlib for InterpType { unsafe fn from_glib(value: ffi::GdkInterpType) -> Self { match value { ffi::GDK_INTERP_NEAREST => Self::Nearest, ffi::GDK_INTERP_TILES => Self::Tiles, ffi::GDK_INTERP_BILINEAR => Self::Bilinear, ffi::GDK_INTERP_HYPER => Self::Hyper, value => Self::__Unknown(value), } } } impl StaticType for InterpType { fn static_type() -> Type { unsafe { from_glib(ffi::gdk_interp_type_get_type()) } } } impl glib::value::ValueType for InterpType { type Type = Self; } unsafe impl<'a> FromValue<'a> for InterpType { type Checker = glib::value::GenericValueTypeChecker; unsafe fn from_value(value: &'a glib::Value) -> Self { from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0)) } } impl ToValue for InterpType { fn to_value(&self) -> glib::Value { let mut value = glib::Value::for_value_type::(); unsafe { glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()); } value } fn value_type(&self) -> glib::Type { Self::static_type() } } #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] #[doc(alias = "GdkPixbufAlphaMode")] pub enum PixbufAlphaMode { #[doc(alias = "GDK_PIXBUF_ALPHA_BILEVEL")] Bilevel, #[doc(alias = "GDK_PIXBUF_ALPHA_FULL")] Full, #[doc(hidden)] __Unknown(i32), } impl fmt::Display for PixbufAlphaMode { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "PixbufAlphaMode::{}", match *self { Self::Bilevel => "Bilevel", Self::Full => "Full", _ => "Unknown", } ) } } #[doc(hidden)] impl IntoGlib for PixbufAlphaMode { type GlibType = ffi::GdkPixbufAlphaMode; fn into_glib(self) -> ffi::GdkPixbufAlphaMode { match self { Self::Bilevel => ffi::GDK_PIXBUF_ALPHA_BILEVEL, Self::Full => ffi::GDK_PIXBUF_ALPHA_FULL, Self::__Unknown(value) => value, } } } #[doc(hidden)] impl FromGlib for PixbufAlphaMode { unsafe fn from_glib(value: ffi::GdkPixbufAlphaMode) -> Self { match value { ffi::GDK_PIXBUF_ALPHA_BILEVEL => Self::Bilevel, ffi::GDK_PIXBUF_ALPHA_FULL => Self::Full, value => Self::__Unknown(value), } } } impl StaticType for PixbufAlphaMode { fn static_type() -> Type { unsafe { from_glib(ffi::gdk_pixbuf_alpha_mode_get_type()) } } } impl glib::value::ValueType for PixbufAlphaMode { type Type = Self; } unsafe impl<'a> FromValue<'a> for PixbufAlphaMode { type Checker = glib::value::GenericValueTypeChecker; unsafe fn from_value(value: &'a glib::Value) -> Self { from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0)) } } impl ToValue for PixbufAlphaMode { fn to_value(&self) -> glib::Value { let mut value = glib::Value::for_value_type::(); unsafe { glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()); } value } fn value_type(&self) -> glib::Type { Self::static_type() } } #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] #[doc(alias = "GdkPixbufError")] pub enum PixbufError { #[doc(alias = "GDK_PIXBUF_ERROR_CORRUPT_IMAGE")] CorruptImage, #[doc(alias = "GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY")] InsufficientMemory, #[doc(alias = "GDK_PIXBUF_ERROR_BAD_OPTION")] BadOption, #[doc(alias = "GDK_PIXBUF_ERROR_UNKNOWN_TYPE")] UnknownType, #[doc(alias = "GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION")] UnsupportedOperation, #[doc(alias = "GDK_PIXBUF_ERROR_FAILED")] Failed, #[doc(alias = "GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION")] IncompleteAnimation, #[doc(hidden)] __Unknown(i32), } impl fmt::Display for PixbufError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "PixbufError::{}", match *self { Self::CorruptImage => "CorruptImage", Self::InsufficientMemory => "InsufficientMemory", Self::BadOption => "BadOption", Self::UnknownType => "UnknownType", Self::UnsupportedOperation => "UnsupportedOperation", Self::Failed => "Failed", Self::IncompleteAnimation => "IncompleteAnimation", _ => "Unknown", } ) } } #[doc(hidden)] impl IntoGlib for PixbufError { type GlibType = ffi::GdkPixbufError; fn into_glib(self) -> ffi::GdkPixbufError { match self { Self::CorruptImage => ffi::GDK_PIXBUF_ERROR_CORRUPT_IMAGE, Self::InsufficientMemory => ffi::GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY, Self::BadOption => ffi::GDK_PIXBUF_ERROR_BAD_OPTION, Self::UnknownType => ffi::GDK_PIXBUF_ERROR_UNKNOWN_TYPE, Self::UnsupportedOperation => ffi::GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION, Self::Failed => ffi::GDK_PIXBUF_ERROR_FAILED, Self::IncompleteAnimation => ffi::GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION, Self::__Unknown(value) => value, } } } #[doc(hidden)] impl FromGlib for PixbufError { unsafe fn from_glib(value: ffi::GdkPixbufError) -> Self { match value { ffi::GDK_PIXBUF_ERROR_CORRUPT_IMAGE => Self::CorruptImage, ffi::GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY => Self::InsufficientMemory, ffi::GDK_PIXBUF_ERROR_BAD_OPTION => Self::BadOption, ffi::GDK_PIXBUF_ERROR_UNKNOWN_TYPE => Self::UnknownType, ffi::GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION => Self::UnsupportedOperation, ffi::GDK_PIXBUF_ERROR_FAILED => Self::Failed, ffi::GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION => Self::IncompleteAnimation, value => Self::__Unknown(value), } } } impl ErrorDomain for PixbufError { fn domain() -> Quark { unsafe { from_glib(ffi::gdk_pixbuf_error_quark()) } } fn code(self) -> i32 { self.into_glib() } fn from(code: i32) -> Option { match code { ffi::GDK_PIXBUF_ERROR_CORRUPT_IMAGE => Some(Self::CorruptImage), ffi::GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY => Some(Self::InsufficientMemory), ffi::GDK_PIXBUF_ERROR_BAD_OPTION => Some(Self::BadOption), ffi::GDK_PIXBUF_ERROR_UNKNOWN_TYPE => Some(Self::UnknownType), ffi::GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION => Some(Self::UnsupportedOperation), ffi::GDK_PIXBUF_ERROR_FAILED => Some(Self::Failed), ffi::GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION => Some(Self::IncompleteAnimation), _ => Some(Self::Failed), } } } impl StaticType for PixbufError { fn static_type() -> Type { unsafe { from_glib(ffi::gdk_pixbuf_error_get_type()) } } } impl glib::value::ValueType for PixbufError { type Type = Self; } unsafe impl<'a> FromValue<'a> for PixbufError { type Checker = glib::value::GenericValueTypeChecker; unsafe fn from_value(value: &'a glib::Value) -> Self { from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0)) } } impl ToValue for PixbufError { fn to_value(&self) -> glib::Value { let mut value = glib::Value::for_value_type::(); unsafe { glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()); } value } fn value_type(&self) -> glib::Type { Self::static_type() } } #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] #[doc(alias = "GdkPixbufRotation")] pub enum PixbufRotation { #[doc(alias = "GDK_PIXBUF_ROTATE_NONE")] None, #[doc(alias = "GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE")] Counterclockwise, #[doc(alias = "GDK_PIXBUF_ROTATE_UPSIDEDOWN")] Upsidedown, #[doc(alias = "GDK_PIXBUF_ROTATE_CLOCKWISE")] Clockwise, #[doc(hidden)] __Unknown(i32), } impl fmt::Display for PixbufRotation { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "PixbufRotation::{}", match *self { Self::None => "None", Self::Counterclockwise => "Counterclockwise", Self::Upsidedown => "Upsidedown", Self::Clockwise => "Clockwise", _ => "Unknown", } ) } } #[doc(hidden)] impl IntoGlib for PixbufRotation { type GlibType = ffi::GdkPixbufRotation; fn into_glib(self) -> ffi::GdkPixbufRotation { match self { Self::None => ffi::GDK_PIXBUF_ROTATE_NONE, Self::Counterclockwise => ffi::GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE, Self::Upsidedown => ffi::GDK_PIXBUF_ROTATE_UPSIDEDOWN, Self::Clockwise => ffi::GDK_PIXBUF_ROTATE_CLOCKWISE, Self::__Unknown(value) => value, } } } #[doc(hidden)] impl FromGlib for PixbufRotation { unsafe fn from_glib(value: ffi::GdkPixbufRotation) -> Self { match value { ffi::GDK_PIXBUF_ROTATE_NONE => Self::None, ffi::GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE => Self::Counterclockwise, ffi::GDK_PIXBUF_ROTATE_UPSIDEDOWN => Self::Upsidedown, ffi::GDK_PIXBUF_ROTATE_CLOCKWISE => Self::Clockwise, value => Self::__Unknown(value), } } } impl StaticType for PixbufRotation { fn static_type() -> Type { unsafe { from_glib(ffi::gdk_pixbuf_rotation_get_type()) } } } impl glib::value::ValueType for PixbufRotation { type Type = Self; } unsafe impl<'a> FromValue<'a> for PixbufRotation { type Checker = glib::value::GenericValueTypeChecker; unsafe fn from_value(value: &'a glib::Value) -> Self { from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0)) } } impl ToValue for PixbufRotation { fn to_value(&self) -> glib::Value { let mut value = glib::Value::for_value_type::(); unsafe { glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()); } value } fn value_type(&self) -> glib::Type { Self::static_type() } } gdk-pixbuf-0.14.0/src/auto/mod.rs000064400000000000000000000015000072674642500146560ustar 00000000000000// 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 mod pixbuf; pub use self::pixbuf::Pixbuf; mod pixbuf_animation; pub use self::pixbuf_animation::{PixbufAnimation, NONE_PIXBUF_ANIMATION}; mod pixbuf_loader; pub use self::pixbuf_loader::{PixbufLoader, NONE_PIXBUF_LOADER}; mod pixbuf_simple_anim; pub use self::pixbuf_simple_anim::PixbufSimpleAnim; mod pixbuf_format; pub use self::pixbuf_format::PixbufFormat; mod enums; pub use self::enums::Colorspace; pub use self::enums::InterpType; pub use self::enums::PixbufAlphaMode; pub use self::enums::PixbufError; pub use self::enums::PixbufRotation; #[doc(hidden)] pub mod traits { pub use super::pixbuf_animation::PixbufAnimationExt; pub use super::pixbuf_loader::PixbufLoaderExt; } gdk-pixbuf-0.14.0/src/auto/pixbuf.rs000064400000000000000000000472250072674642500154120ustar 00000000000000// 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 crate::Colorspace; use crate::InterpType; use crate::PixbufFormat; use crate::PixbufRotation; use glib::object::IsA; use glib::object::ObjectType as ObjectType_; use glib::translate::*; use glib::StaticType; use std::fmt; use std::ptr; glib::wrapper! { #[doc(alias = "GdkPixbuf")] pub struct Pixbuf(Object) @implements gio::Icon, gio::LoadableIcon; match fn { type_ => || ffi::gdk_pixbuf_get_type(), } } impl Pixbuf { #[doc(alias = "gdk_pixbuf_new")] pub fn new( colorspace: Colorspace, has_alpha: bool, bits_per_sample: i32, width: i32, height: i32, ) -> Option { unsafe { from_glib_full(ffi::gdk_pixbuf_new( colorspace.into_glib(), has_alpha.into_glib(), bits_per_sample, width, height, )) } } #[doc(alias = "gdk_pixbuf_new_from_bytes")] #[doc(alias = "new_from_bytes")] pub fn 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.into_glib(), has_alpha.into_glib(), bits_per_sample, width, height, rowstride, )) } } //#[doc(alias = "gdk_pixbuf_new_from_data")] //#[doc(alias = "new_from_data")] //pub fn from_data(data: &[u8], colorspace: Colorspace, has_alpha: bool, bits_per_sample: i32, width: i32, height: i32, rowstride: i32, destroy_fn: Option) + 'static>>) -> Pixbuf { // unsafe { TODO: call ffi:gdk_pixbuf_new_from_data() } //} #[doc(alias = "gdk_pixbuf_new_from_resource")] #[doc(alias = "new_from_resource")] pub fn from_resource(resource_path: &str) -> Result { 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)) } } } #[doc(alias = "gdk_pixbuf_new_from_resource_at_scale")] #[doc(alias = "new_from_resource_at_scale")] pub fn from_resource_at_scale( resource_path: &str, width: i32, height: i32, preserve_aspect_ratio: bool, ) -> Result { 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.into_glib(), &mut error, ); if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) } } } #[doc(alias = "gdk_pixbuf_new_from_stream")] #[doc(alias = "new_from_stream")] pub fn from_stream, Q: IsA>( stream: &P, cancellable: Option<&Q>, ) -> Result { 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)) } } } #[doc(alias = "gdk_pixbuf_new_from_stream_at_scale")] #[doc(alias = "new_from_stream_at_scale")] pub fn from_stream_at_scale, Q: IsA>( stream: &P, width: i32, height: i32, preserve_aspect_ratio: bool, cancellable: Option<&Q>, ) -> Result { 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.into_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)) } } } #[doc(alias = "gdk_pixbuf_new_from_xpm_data")] #[doc(alias = "new_from_xpm_data")] pub fn from_xpm_data(data: &[&str]) -> Pixbuf { unsafe { from_glib_full(ffi::gdk_pixbuf_new_from_xpm_data(data.to_glib_none().0)) } } #[doc(alias = "gdk_pixbuf_add_alpha")] pub fn add_alpha(&self, substitute_color: bool, r: u8, g: u8, b: u8) -> Option { unsafe { from_glib_full(ffi::gdk_pixbuf_add_alpha( self.to_glib_none().0, substitute_color.into_glib(), r, g, b, )) } } #[doc(alias = "gdk_pixbuf_apply_embedded_orientation")] pub fn apply_embedded_orientation(&self) -> Option { unsafe { from_glib_full(ffi::gdk_pixbuf_apply_embedded_orientation( self.to_glib_none().0, )) } } #[doc(alias = "gdk_pixbuf_composite")] 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.into_glib(), overall_alpha, ); } } #[doc(alias = "gdk_pixbuf_composite_color")] 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.into_glib(), overall_alpha, check_x, check_y, check_size, color1, color2, ); } } #[doc(alias = "gdk_pixbuf_composite_color_simple")] 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 { unsafe { from_glib_full(ffi::gdk_pixbuf_composite_color_simple( self.to_glib_none().0, dest_width, dest_height, interp_type.into_glib(), overall_alpha, check_size, color1, color2, )) } } #[doc(alias = "gdk_pixbuf_copy")] pub fn copy(&self) -> Option { unsafe { from_glib_full(ffi::gdk_pixbuf_copy(self.to_glib_none().0)) } } #[doc(alias = "gdk_pixbuf_copy_area")] 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"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_36")))] #[doc(alias = "gdk_pixbuf_copy_options")] 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, )) } } #[doc(alias = "gdk_pixbuf_fill")] pub fn fill(&self, pixel: u32) { unsafe { ffi::gdk_pixbuf_fill(self.to_glib_none().0, pixel); } } #[doc(alias = "gdk_pixbuf_flip")] pub fn flip(&self, horizontal: bool) -> Option { unsafe { from_glib_full(ffi::gdk_pixbuf_flip( self.to_glib_none().0, horizontal.into_glib(), )) } } #[doc(alias = "gdk_pixbuf_get_bits_per_sample")] #[doc(alias = "get_bits_per_sample")] pub fn bits_per_sample(&self) -> i32 { unsafe { ffi::gdk_pixbuf_get_bits_per_sample(self.to_glib_none().0) } } #[doc(alias = "gdk_pixbuf_get_byte_length")] #[doc(alias = "get_byte_length")] pub fn byte_length(&self) -> usize { unsafe { ffi::gdk_pixbuf_get_byte_length(self.to_glib_none().0) } } #[doc(alias = "gdk_pixbuf_get_colorspace")] #[doc(alias = "get_colorspace")] pub fn colorspace(&self) -> Colorspace { unsafe { from_glib(ffi::gdk_pixbuf_get_colorspace(self.to_glib_none().0)) } } #[doc(alias = "gdk_pixbuf_get_has_alpha")] #[doc(alias = "get_has_alpha")] pub fn has_alpha(&self) -> bool { unsafe { from_glib(ffi::gdk_pixbuf_get_has_alpha(self.to_glib_none().0)) } } #[doc(alias = "gdk_pixbuf_get_height")] #[doc(alias = "get_height")] pub fn height(&self) -> i32 { unsafe { ffi::gdk_pixbuf_get_height(self.to_glib_none().0) } } #[doc(alias = "gdk_pixbuf_get_n_channels")] #[doc(alias = "get_n_channels")] pub fn n_channels(&self) -> i32 { unsafe { ffi::gdk_pixbuf_get_n_channels(self.to_glib_none().0) } } #[doc(alias = "gdk_pixbuf_get_option")] #[doc(alias = "get_option")] pub fn option(&self, key: &str) -> Option { unsafe { from_glib_none(ffi::gdk_pixbuf_get_option( self.to_glib_none().0, key.to_glib_none().0, )) } } //#[doc(alias = "gdk_pixbuf_get_options")] //#[doc(alias = "get_options")] //pub fn 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() } //} #[doc(alias = "gdk_pixbuf_get_rowstride")] #[doc(alias = "get_rowstride")] pub fn rowstride(&self) -> i32 { unsafe { ffi::gdk_pixbuf_get_rowstride(self.to_glib_none().0) } } #[doc(alias = "gdk_pixbuf_get_width")] #[doc(alias = "get_width")] pub fn width(&self) -> i32 { unsafe { ffi::gdk_pixbuf_get_width(self.to_glib_none().0) } } #[doc(alias = "gdk_pixbuf_new_subpixbuf")] pub 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, )) } } #[doc(alias = "gdk_pixbuf_read_pixel_bytes")] pub fn read_pixel_bytes(&self) -> Option { unsafe { from_glib_full(ffi::gdk_pixbuf_read_pixel_bytes(self.to_glib_none().0)) } } #[cfg(any(feature = "v2_36", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_36")))] #[doc(alias = "gdk_pixbuf_remove_option")] 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, )) } } #[doc(alias = "gdk_pixbuf_rotate_simple")] pub fn rotate_simple(&self, angle: PixbufRotation) -> Option { unsafe { from_glib_full(ffi::gdk_pixbuf_rotate_simple( self.to_glib_none().0, angle.into_glib(), )) } } #[doc(alias = "gdk_pixbuf_saturate_and_pixelate")] 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.into_glib(), ); } } //#[doc(alias = "gdk_pixbuf_save")] //pub fn save>(&self, filename: P, type_: &str, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool { // unsafe { TODO: call ffi:gdk_pixbuf_save() } //} //#[doc(alias = "gdk_pixbuf_save_to_buffer")] //pub fn save_to_buffer(&self, type_: &str, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Option> { // unsafe { TODO: call ffi:gdk_pixbuf_save_to_buffer() } //} //#[doc(alias = "gdk_pixbuf_save_to_callback")] //pub fn save_to_callback, usize, &glib::Error) -> bool>(&self, save_func: P, type_: &str, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool { // unsafe { TODO: call ffi:gdk_pixbuf_save_to_callback() } //} //#[doc(alias = "gdk_pixbuf_save_to_callbackv")] //pub fn save_to_callbackv, usize, &glib::Error) -> bool>(&self, save_func: P, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result<(), glib::Error> { // unsafe { TODO: call ffi:gdk_pixbuf_save_to_callbackv() } //} //#[doc(alias = "gdk_pixbuf_save_to_stream")] //pub fn save_to_stream, Q: IsA>(&self, stream: &P, type_: &str, cancellable: Option<&Q>, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool { // unsafe { TODO: call ffi:gdk_pixbuf_save_to_stream() } //} //#[doc(alias = "gdk_pixbuf_save_to_stream_async")] //pub fn save_to_stream_async, Q: IsA, R: FnOnce(Result<(), glib::Error>) + Send + 'static>(&self, stream: &P, type_: &str, cancellable: Option<&Q>, callback: R, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) { // unsafe { TODO: call ffi:gdk_pixbuf_save_to_stream_async() } //} // //pub fn save_to_stream_async_future + Clone + 'static>(&self, stream: &P, type_: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Pin> + 'static>> { //let stream = stream.clone(); //let type_ = String::from(type_); //Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { // obj.save_to_stream_async( // &stream, // &type_, // Some(cancellable), // , // move |res| { // send.resolve(res); // }, // ); //})) //} #[doc(alias = "gdk_pixbuf_scale")] 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.into_glib(), ); } } #[doc(alias = "gdk_pixbuf_scale_simple")] pub fn scale_simple( &self, dest_width: i32, dest_height: i32, interp_type: InterpType, ) -> Option { unsafe { from_glib_full(ffi::gdk_pixbuf_scale_simple( self.to_glib_none().0, dest_width, dest_height, interp_type.into_glib(), )) } } #[doc(alias = "gdk_pixbuf_set_option")] 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, )) } } #[doc(alias = "pixel-bytes")] pub fn pixel_bytes(&self) -> Option { unsafe { let mut value = glib::Value::from_type(::static_type()); glib::gobject_ffi::g_object_get_property( self.as_ptr() as *mut glib::gobject_ffi::GObject, b"pixel-bytes\0".as_ptr() as *const _, value.to_glib_none_mut().0, ); value .get() .expect("Return Value for property `pixel-bytes` getter") } } #[cfg(any(feature = "v2_36_8", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_36_8")))] #[doc(alias = "gdk_pixbuf_calculate_rowstride")] 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.into_glib(), has_alpha.into_glib(), bits_per_sample, width, height, ) } } #[doc(alias = "gdk_pixbuf_get_formats")] #[doc(alias = "get_formats")] pub fn formats() -> Vec { unsafe { FromGlibPtrContainer::from_glib_container(ffi::gdk_pixbuf_get_formats()) } } #[cfg(any(feature = "v2_40", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_40")))] #[doc(alias = "gdk_pixbuf_init_modules")] pub fn init_modules(path: &str) -> Result<(), glib::Error> { unsafe { let mut error = ptr::null_mut(); let _ = ffi::gdk_pixbuf_init_modules(path.to_glib_none().0, &mut error); if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } } } } impl fmt::Display for Pixbuf { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("Pixbuf") } } gdk-pixbuf-0.14.0/src/auto/pixbuf_animation.rs000064400000000000000000000133750072674642500174500ustar 00000000000000// 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 crate::Pixbuf; use glib::object::IsA; use glib::translate::*; use std::boxed::Box as Box_; use std::fmt; use std::pin::Pin; use std::ptr; glib::wrapper! { #[doc(alias = "GdkPixbufAnimation")] pub struct PixbufAnimation(Object); match fn { type_ => || ffi::gdk_pixbuf_animation_get_type(), } } impl PixbufAnimation { #[doc(alias = "gdk_pixbuf_animation_new_from_file")] #[doc(alias = "new_from_file")] pub fn from_file>( filename: P, ) -> Result { unsafe { let mut error = ptr::null_mut(); let ret = ffi::gdk_pixbuf_animation_new_from_file( filename.as_ref().to_glib_none().0, &mut error, ); if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) } } } #[doc(alias = "gdk_pixbuf_animation_new_from_resource")] #[doc(alias = "new_from_resource")] pub fn from_resource(resource_path: &str) -> Result { unsafe { let mut error = ptr::null_mut(); let ret = ffi::gdk_pixbuf_animation_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)) } } } #[doc(alias = "gdk_pixbuf_animation_new_from_stream")] #[doc(alias = "new_from_stream")] pub fn from_stream, Q: IsA>( stream: &P, cancellable: Option<&Q>, ) -> Result { unsafe { let mut error = ptr::null_mut(); let ret = ffi::gdk_pixbuf_animation_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)) } } } #[doc(alias = "gdk_pixbuf_animation_new_from_stream_async")] #[doc(alias = "new_from_stream_async")] pub fn from_stream_async< P: IsA, Q: IsA, R: FnOnce(Result) + Send + 'static, >( stream: &P, cancellable: Option<&Q>, callback: R, ) { let user_data: Box_ = Box_::new(callback); unsafe extern "C" fn from_stream_async_trampoline< R: FnOnce(Result) + Send + 'static, >( _source_object: *mut glib::gobject_ffi::GObject, res: *mut gio::ffi::GAsyncResult, user_data: glib::ffi::gpointer, ) { let mut error = ptr::null_mut(); let ret = ffi::gdk_pixbuf_animation_new_from_stream_finish(res, &mut error); let result = if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }; let callback: Box_ = Box_::from_raw(user_data as *mut _); callback(result); } let callback = from_stream_async_trampoline::; unsafe { ffi::gdk_pixbuf_animation_new_from_stream_async( stream.as_ref().to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, Some(callback), Box_::into_raw(user_data) as *mut _, ); } } pub fn from_stream_async_future + Clone + 'static>( stream: &P, ) -> Pin> + 'static>> { let stream = stream.clone(); Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { Self::from_stream_async(&stream, Some(cancellable), move |res| { send.resolve(res); }); })) } } pub const NONE_PIXBUF_ANIMATION: Option<&PixbufAnimation> = None; pub trait PixbufAnimationExt: 'static { #[doc(alias = "gdk_pixbuf_animation_get_height")] #[doc(alias = "get_height")] fn height(&self) -> i32; #[doc(alias = "gdk_pixbuf_animation_get_static_image")] #[doc(alias = "get_static_image")] fn static_image(&self) -> Option; #[doc(alias = "gdk_pixbuf_animation_get_width")] #[doc(alias = "get_width")] fn width(&self) -> i32; #[doc(alias = "gdk_pixbuf_animation_is_static_image")] fn is_static_image(&self) -> bool; } impl> PixbufAnimationExt for O { fn height(&self) -> i32 { unsafe { ffi::gdk_pixbuf_animation_get_height(self.as_ref().to_glib_none().0) } } fn static_image(&self) -> Option { unsafe { from_glib_none(ffi::gdk_pixbuf_animation_get_static_image( self.as_ref().to_glib_none().0, )) } } fn width(&self) -> i32 { unsafe { ffi::gdk_pixbuf_animation_get_width(self.as_ref().to_glib_none().0) } } fn is_static_image(&self) -> bool { unsafe { from_glib(ffi::gdk_pixbuf_animation_is_static_image( self.as_ref().to_glib_none().0, )) } } } impl fmt::Display for PixbufAnimation { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("PixbufAnimation") } } gdk-pixbuf-0.14.0/src/auto/pixbuf_format.rs000064400000000000000000000067460072674642500167650ustar 00000000000000// 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 glib::translate::*; glib::wrapper! { #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct PixbufFormat(Boxed); match fn { copy => |ptr| ffi::gdk_pixbuf_format_copy(ptr), free => |ptr| ffi::gdk_pixbuf_format_free(ptr), type_ => || ffi::gdk_pixbuf_format_get_type(), } } impl PixbufFormat { #[doc(alias = "gdk_pixbuf_format_get_description")] #[doc(alias = "get_description")] pub fn description(&self) -> Option { unsafe { from_glib_full(ffi::gdk_pixbuf_format_get_description(mut_override( self.to_glib_none().0, ))) } } #[doc(alias = "gdk_pixbuf_format_get_extensions")] #[doc(alias = "get_extensions")] pub fn extensions(&self) -> Vec { unsafe { FromGlibPtrContainer::from_glib_full(ffi::gdk_pixbuf_format_get_extensions( mut_override(self.to_glib_none().0), )) } } #[doc(alias = "gdk_pixbuf_format_get_license")] #[doc(alias = "get_license")] pub fn license(&self) -> Option { unsafe { from_glib_full(ffi::gdk_pixbuf_format_get_license(mut_override( self.to_glib_none().0, ))) } } #[doc(alias = "gdk_pixbuf_format_get_mime_types")] #[doc(alias = "get_mime_types")] pub fn mime_types(&self) -> Vec { unsafe { FromGlibPtrContainer::from_glib_full(ffi::gdk_pixbuf_format_get_mime_types( mut_override(self.to_glib_none().0), )) } } #[doc(alias = "gdk_pixbuf_format_get_name")] #[doc(alias = "get_name")] pub fn name(&self) -> Option { unsafe { from_glib_full(ffi::gdk_pixbuf_format_get_name(mut_override( self.to_glib_none().0, ))) } } #[doc(alias = "gdk_pixbuf_format_is_disabled")] pub fn is_disabled(&self) -> bool { unsafe { from_glib(ffi::gdk_pixbuf_format_is_disabled(mut_override( self.to_glib_none().0, ))) } } #[cfg(any(feature = "v2_36", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_36")))] #[doc(alias = "gdk_pixbuf_format_is_save_option_supported")] pub fn is_save_option_supported(&self, option_key: &str) -> bool { unsafe { from_glib(ffi::gdk_pixbuf_format_is_save_option_supported( mut_override(self.to_glib_none().0), option_key.to_glib_none().0, )) } } #[doc(alias = "gdk_pixbuf_format_is_scalable")] pub fn is_scalable(&self) -> bool { unsafe { from_glib(ffi::gdk_pixbuf_format_is_scalable(mut_override( self.to_glib_none().0, ))) } } #[doc(alias = "gdk_pixbuf_format_is_writable")] pub fn is_writable(&self) -> bool { unsafe { from_glib(ffi::gdk_pixbuf_format_is_writable(mut_override( self.to_glib_none().0, ))) } } #[doc(alias = "gdk_pixbuf_format_set_disabled")] pub fn set_disabled(&mut self, disabled: bool) { unsafe { ffi::gdk_pixbuf_format_set_disabled(self.to_glib_none_mut().0, disabled.into_glib()); } } } gdk-pixbuf-0.14.0/src/auto/pixbuf_loader.rs000064400000000000000000000223460072674642500167350ustar 00000000000000// 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 crate::Pixbuf; use crate::PixbufAnimation; use crate::PixbufFormat; use glib::object::Cast; use glib::object::IsA; use glib::signal::connect_raw; use glib::signal::SignalHandlerId; use glib::translate::*; use std::boxed::Box as Box_; use std::fmt; use std::mem::transmute; use std::ptr; glib::wrapper! { #[doc(alias = "GdkPixbufLoader")] pub struct PixbufLoader(Object); match fn { type_ => || ffi::gdk_pixbuf_loader_get_type(), } } impl PixbufLoader { #[doc(alias = "gdk_pixbuf_loader_new")] pub fn new() -> PixbufLoader { unsafe { from_glib_full(ffi::gdk_pixbuf_loader_new()) } } #[doc(alias = "gdk_pixbuf_loader_new_with_mime_type")] #[doc(alias = "new_with_mime_type")] pub fn with_mime_type(mime_type: &str) -> Result { unsafe { let mut error = ptr::null_mut(); let ret = ffi::gdk_pixbuf_loader_new_with_mime_type(mime_type.to_glib_none().0, &mut error); if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) } } } #[doc(alias = "gdk_pixbuf_loader_new_with_type")] #[doc(alias = "new_with_type")] pub fn with_type(image_type: &str) -> Result { unsafe { let mut error = ptr::null_mut(); let ret = ffi::gdk_pixbuf_loader_new_with_type(image_type.to_glib_none().0, &mut error); if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) } } } } impl Default for PixbufLoader { fn default() -> Self { Self::new() } } pub const NONE_PIXBUF_LOADER: Option<&PixbufLoader> = None; pub trait PixbufLoaderExt: 'static { #[doc(alias = "gdk_pixbuf_loader_close")] fn close(&self) -> Result<(), glib::Error>; #[doc(alias = "gdk_pixbuf_loader_get_animation")] #[doc(alias = "get_animation")] fn animation(&self) -> Option; #[doc(alias = "gdk_pixbuf_loader_get_format")] #[doc(alias = "get_format")] fn format(&self) -> Option; #[doc(alias = "gdk_pixbuf_loader_get_pixbuf")] #[doc(alias = "get_pixbuf")] fn pixbuf(&self) -> Option; #[doc(alias = "gdk_pixbuf_loader_set_size")] fn set_size(&self, width: i32, height: i32); #[doc(alias = "gdk_pixbuf_loader_write")] fn write(&self, buf: &[u8]) -> Result<(), glib::Error>; #[doc(alias = "gdk_pixbuf_loader_write_bytes")] fn write_bytes(&self, buffer: &glib::Bytes) -> Result<(), glib::Error>; #[doc(alias = "area-prepared")] fn connect_area_prepared(&self, f: F) -> SignalHandlerId; #[doc(alias = "area-updated")] fn connect_area_updated( &self, f: F, ) -> SignalHandlerId; #[doc(alias = "closed")] fn connect_closed(&self, f: F) -> SignalHandlerId; #[doc(alias = "size-prepared")] fn connect_size_prepared(&self, f: F) -> SignalHandlerId; } impl> PixbufLoaderExt for O { fn close(&self) -> Result<(), glib::Error> { unsafe { let mut error = ptr::null_mut(); let _ = ffi::gdk_pixbuf_loader_close(self.as_ref().to_glib_none().0, &mut error); if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } } } fn animation(&self) -> Option { unsafe { from_glib_none(ffi::gdk_pixbuf_loader_get_animation( self.as_ref().to_glib_none().0, )) } } fn format(&self) -> Option { unsafe { from_glib_none(ffi::gdk_pixbuf_loader_get_format( self.as_ref().to_glib_none().0, )) } } fn pixbuf(&self) -> Option { unsafe { from_glib_none(ffi::gdk_pixbuf_loader_get_pixbuf( self.as_ref().to_glib_none().0, )) } } fn set_size(&self, width: i32, height: i32) { unsafe { ffi::gdk_pixbuf_loader_set_size(self.as_ref().to_glib_none().0, width, height); } } fn write(&self, buf: &[u8]) -> Result<(), glib::Error> { let count = buf.len() as usize; unsafe { let mut error = ptr::null_mut(); let _ = ffi::gdk_pixbuf_loader_write( self.as_ref().to_glib_none().0, buf.to_glib_none().0, count, &mut error, ); if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } } } fn write_bytes(&self, buffer: &glib::Bytes) -> Result<(), glib::Error> { unsafe { let mut error = ptr::null_mut(); let _ = ffi::gdk_pixbuf_loader_write_bytes( self.as_ref().to_glib_none().0, buffer.to_glib_none().0, &mut error, ); if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } } } fn connect_area_prepared(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn area_prepared_trampoline, F: Fn(&P) + 'static>( this: *mut ffi::GdkPixbufLoader, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f(PixbufLoader::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"area-prepared\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( area_prepared_trampoline:: as *const (), )), Box_::into_raw(f), ) } } fn connect_area_updated( &self, f: F, ) -> SignalHandlerId { unsafe extern "C" fn area_updated_trampoline< P: IsA, F: Fn(&P, i32, i32, i32, i32) + 'static, >( this: *mut ffi::GdkPixbufLoader, x: libc::c_int, y: libc::c_int, width: libc::c_int, height: libc::c_int, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f( PixbufLoader::from_glib_borrow(this).unsafe_cast_ref(), x, y, width, height, ) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"area-updated\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( area_updated_trampoline:: as *const (), )), Box_::into_raw(f), ) } } fn connect_closed(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn closed_trampoline, F: Fn(&P) + 'static>( this: *mut ffi::GdkPixbufLoader, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f(PixbufLoader::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"closed\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( closed_trampoline:: as *const (), )), Box_::into_raw(f), ) } } fn connect_size_prepared(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn size_prepared_trampoline< P: IsA, F: Fn(&P, i32, i32) + 'static, >( this: *mut ffi::GdkPixbufLoader, width: libc::c_int, height: libc::c_int, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f( PixbufLoader::from_glib_borrow(this).unsafe_cast_ref(), width, height, ) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"size-prepared\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( size_prepared_trampoline:: as *const (), )), Box_::into_raw(f), ) } } } impl fmt::Display for PixbufLoader { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("PixbufLoader") } } gdk-pixbuf-0.14.0/src/auto/pixbuf_simple_anim.rs000064400000000000000000000047710072674642500177660ustar 00000000000000// 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 crate::Pixbuf; use crate::PixbufAnimation; use glib::object::ObjectType as ObjectType_; use glib::signal::connect_raw; use glib::signal::SignalHandlerId; use glib::translate::*; use std::boxed::Box as Box_; use std::fmt; use std::mem::transmute; glib::wrapper! { #[doc(alias = "GdkPixbufSimpleAnim")] pub struct PixbufSimpleAnim(Object) @extends PixbufAnimation; match fn { type_ => || ffi::gdk_pixbuf_simple_anim_get_type(), } } impl PixbufSimpleAnim { #[doc(alias = "gdk_pixbuf_simple_anim_new")] pub fn new(width: i32, height: i32, rate: f32) -> PixbufSimpleAnim { unsafe { from_glib_full(ffi::gdk_pixbuf_simple_anim_new(width, height, rate)) } } #[doc(alias = "gdk_pixbuf_simple_anim_add_frame")] pub fn add_frame(&self, pixbuf: &Pixbuf) { unsafe { ffi::gdk_pixbuf_simple_anim_add_frame(self.to_glib_none().0, pixbuf.to_glib_none().0); } } #[doc(alias = "gdk_pixbuf_simple_anim_get_loop")] #[doc(alias = "get_loop")] pub fn is_loop(&self) -> bool { unsafe { from_glib(ffi::gdk_pixbuf_simple_anim_get_loop(self.to_glib_none().0)) } } #[doc(alias = "gdk_pixbuf_simple_anim_set_loop")] pub fn set_loop(&self, loop_: bool) { unsafe { ffi::gdk_pixbuf_simple_anim_set_loop(self.to_glib_none().0, loop_.into_glib()); } } #[doc(alias = "loop")] pub fn connect_loop_notify(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn notify_loop_trampoline( this: *mut ffi::GdkPixbufSimpleAnim, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f(&from_glib_borrow(this)) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"notify::loop\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( notify_loop_trampoline:: as *const (), )), Box_::into_raw(f), ) } } } impl fmt::Display for PixbufSimpleAnim { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("PixbufSimpleAnim") } } gdk-pixbuf-0.14.0/src/auto/versions.txt000064400000000000000000000001720072674642500161460ustar 00000000000000Generated by gir (https://github.com/gtk-rs/gir @ 6ed30fc) from gir-files (https://github.com/gtk-rs/gir-files @ 7d95377) gdk-pixbuf-0.14.0/src/lib.rs000064400000000000000000000012410072674642500136770ustar 00000000000000// Take a look at the license at the top of the repository in the LICENSE file. //! # Rust GDK-PixBuf bindings //! //! This library contains safe Rust bindings for [GDK-PixBuf](https://docs.gtk.org/gdk-pixbuf). //! It is a part of [gtk-rs](https://gtk-rs.org/). //! //! GDK-PixBuf 2.32 is the lowest supported version for the underlying library. #![cfg_attr(feature = "dox", feature(doc_cfg))] pub use ffi; pub use gio; pub use glib; #[allow(clippy::too_many_arguments)] #[allow(unused_imports)] mod auto; mod pixbuf; mod pixbuf_animation; mod pixbuf_animation_iter; pub mod prelude; pub use crate::auto::*; pub use self::pixbuf_animation_iter::PixbufAnimationIter; gdk-pixbuf-0.14.0/src/pixbuf.rs000064400000000000000000000475250072674642500144450ustar 00000000000000// Take a look at the license at the top of the repository in the LICENSE file. use glib::object::IsA; use glib::translate::*; use glib::Error; use libc::{c_uchar, c_void}; use std::io::Read; use std::mem; use std::path::Path; use std::pin::Pin; use std::ptr; use std::slice; use std::future::Future; use crate::{Colorspace, Pixbuf, PixbufFormat}; impl Pixbuf { #[doc(alias = "gdk_pixbuf_new_from_data")] pub fn from_mut_slice>( data: T, colorspace: Colorspace, has_alpha: bool, bits_per_sample: i32, width: i32, height: i32, row_stride: i32, ) -> Pixbuf { unsafe extern "C" fn destroy>(_: *mut c_uchar, data: *mut c_void) { let _data: Box = Box::from_raw(data as *mut T); // the data will be destroyed now } assert!(width > 0, "width must be greater than 0"); assert!(height > 0, "height must be greater than 0"); assert!(row_stride > 0, "row_stride must be greater than 0"); assert!( bits_per_sample == 8, "bits_per_sample == 8 is the only supported value" ); let width = width as usize; let height = height as usize; let row_stride = row_stride as usize; let bits_per_sample = bits_per_sample as usize; let n_channels = if has_alpha { 4 } else { 3 }; let last_row_len = width * ((n_channels * bits_per_sample + 7) / 8); let mut data: Box = Box::new(data); let ptr = { let data: &mut [u8] = (*data).as_mut(); assert!( data.len() >= ((height - 1) * row_stride + last_row_len) as usize, "data.len() must fit the width, height, and row_stride" ); data.as_mut_ptr() }; unsafe { from_glib_full(ffi::gdk_pixbuf_new_from_data( ptr, colorspace.into_glib(), has_alpha.into_glib(), bits_per_sample as i32, width as i32, height as i32, row_stride as i32, Some(destroy::), Box::into_raw(data) as *mut _, )) } } // rustdoc-stripper-ignore-next /// Creates a `Pixbuf` from a type implementing `Read` (like `File`). /// /// ```no_run /// use std::fs::File; /// use gdk_pixbuf::Pixbuf; /// /// let f = File::open("some_file.png").expect("failed to open image"); /// let pixbuf = Pixbuf::from_read(f).expect("failed to load image"); /// ``` pub fn from_read(r: R) -> Result { Pixbuf::from_stream(&gio::ReadInputStream::new(r), None::<&gio::Cancellable>) } #[doc(alias = "gdk_pixbuf_new_from_file")] #[doc(alias = "gdk_pixbuf_new_from_file_utf8")] pub fn from_file>(filename: T) -> Result { #[cfg(not(windows))] use ffi::gdk_pixbuf_new_from_file; #[cfg(windows)] use ffi::gdk_pixbuf_new_from_file_utf8 as gdk_pixbuf_new_from_file; unsafe { let mut error = ptr::null_mut(); 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 { Err(from_glib_full(error)) } } } #[doc(alias = "gdk_pixbuf_new_from_file_at_size")] #[doc(alias = "gdk_pixbuf_new_from_file_at_size_utf8")] pub fn from_file_at_size>( filename: T, width: i32, height: i32, ) -> Result { #[cfg(not(windows))] use ffi::gdk_pixbuf_new_from_file_at_size; #[cfg(windows)] use ffi::gdk_pixbuf_new_from_file_at_size_utf8 as gdk_pixbuf_new_from_file_at_size; unsafe { let mut error = ptr::null_mut(); 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)) } else { Err(from_glib_full(error)) } } } #[doc(alias = "gdk_pixbuf_new_from_file_at_scale")] #[doc(alias = "gdk_pixbuf_new_from_file_at_scale_utf8")] pub fn from_file_at_scale>( filename: T, width: i32, height: i32, preserve_aspect_ratio: bool, ) -> Result { #[cfg(not(windows))] use ffi::gdk_pixbuf_new_from_file_at_scale; #[cfg(windows)] use ffi::gdk_pixbuf_new_from_file_at_scale_utf8 as gdk_pixbuf_new_from_file_at_scale; unsafe { let mut error = ptr::null_mut(); let ptr = gdk_pixbuf_new_from_file_at_scale( filename.as_ref().to_glib_none().0, width, height, preserve_aspect_ratio.into_glib(), &mut error, ); if error.is_null() { Ok(from_glib_full(ptr)) } else { Err(from_glib_full(error)) } } } #[doc(alias = "gdk_pixbuf_new_from_stream_async")] pub fn from_stream_async< P: IsA, Q: IsA, R: FnOnce(Result) + Send + 'static, >( stream: &P, cancellable: Option<&Q>, callback: R, ) { let cancellable = cancellable.map(|p| p.as_ref()); let user_data: Box = Box::new(callback); unsafe extern "C" fn from_stream_async_trampoline< R: FnOnce(Result) + Send + 'static, >( _source_object: *mut glib::gobject_ffi::GObject, res: *mut gio::ffi::GAsyncResult, user_data: glib::ffi::gpointer, ) { 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 = from_stream_async_trampoline::; unsafe { ffi::gdk_pixbuf_new_from_stream_async( stream.as_ref().to_glib_none().0, cancellable.to_glib_none().0, Some(callback), Box::into_raw(user_data) as *mut _, ); } } pub fn from_stream_async_future + Clone + 'static>( stream: &P, ) -> Pin> + 'static>> { let stream = stream.clone(); Box::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { Self::from_stream_async(&stream, Some(cancellable), move |res| { send.resolve(res); }); })) } #[doc(alias = "gdk_pixbuf_new_from_stream_at_scale_async")] pub fn from_stream_at_scale_async< P: IsA, Q: IsA, R: FnOnce(Result) + Send + 'static, >( stream: &P, width: i32, height: i32, preserve_aspect_ratio: bool, cancellable: Option<&Q>, callback: R, ) { let cancellable = cancellable.map(|p| p.as_ref()); let user_data: Box = Box::new(callback); unsafe extern "C" fn from_stream_at_scale_async_trampoline< R: FnOnce(Result) + Send + 'static, >( _source_object: *mut glib::gobject_ffi::GObject, res: *mut gio::ffi::GAsyncResult, user_data: glib::ffi::gpointer, ) { 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 = from_stream_at_scale_async_trampoline::; unsafe { ffi::gdk_pixbuf_new_from_stream_at_scale_async( stream.as_ref().to_glib_none().0, width, height, preserve_aspect_ratio.into_glib(), cancellable.to_glib_none().0, Some(callback), Box::into_raw(user_data) as *mut _, ); } } pub fn from_stream_at_scale_async_future + Clone + 'static>( stream: &P, width: i32, height: i32, preserve_aspect_ratio: bool, ) -> Pin> + 'static>> { let stream = stream.clone(); Box::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { Self::from_stream_at_scale_async( &stream, width, height, preserve_aspect_ratio, Some(cancellable), move |res| { send.resolve(res); }, ); })) } #[allow(clippy::mut_from_ref)] #[allow(clippy::missing_safety_doc)] #[doc(alias = "gdk_pixbuf_get_pixels_with_length")] #[doc(alias = "get_pixels")] pub unsafe fn 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 put_pixel(&self, x: u32, y: u32, red: u8, green: u8, blue: u8, alpha: u8) { assert!( x < self.width() as u32, "x must be less than the pixbuf's width" ); assert!( y < self.height() as u32, "y must be less than the pixbuf's height" ); unsafe { let x = x as usize; let y = y as usize; let n_channels = self.n_channels() as usize; assert!(n_channels == 3 || n_channels == 4); let rowstride = self.rowstride() as usize; let pixels = self.pixels(); let pos = y * rowstride + x * n_channels; pixels[pos] = red; pixels[pos + 1] = green; pixels[pos + 2] = blue; if n_channels == 4 { pixels[pos + 3] = alpha; } } } #[doc(alias = "gdk_pixbuf_get_file_info")] #[doc(alias = "get_file_info")] pub fn file_info>(filename: T) -> Option<(PixbufFormat, i32, i32)> { unsafe { let mut width = mem::MaybeUninit::uninit(); let mut height = mem::MaybeUninit::uninit(); let ret = ffi::gdk_pixbuf_get_file_info( filename.as_ref().to_glib_none().0, width.as_mut_ptr(), height.as_mut_ptr(), ); if !ret.is_null() { Some(( from_glib_none(ret), width.assume_init(), height.assume_init(), )) } else { None } } } #[doc(alias = "gdk_pixbuf_get_file_info_async")] #[doc(alias = "get_file_info_async")] pub fn file_info_async< P: IsA, Q: FnOnce(Result, Error>) + Send + 'static, T: AsRef, >( filename: T, cancellable: Option<&P>, callback: Q, ) { let cancellable = cancellable.map(|p| p.as_ref()); let user_data: Box = Box::new(callback); unsafe extern "C" fn get_file_info_async_trampoline< Q: FnOnce(Result, Error>) + Send + 'static, >( _source_object: *mut glib::gobject_ffi::GObject, res: *mut gio::ffi::GAsyncResult, user_data: glib::ffi::gpointer, ) { let mut error = ptr::null_mut(); let mut width = mem::MaybeUninit::uninit(); let mut height = mem::MaybeUninit::uninit(); let ret = ffi::gdk_pixbuf_get_file_info_finish( res, width.as_mut_ptr(), height.as_mut_ptr(), &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.assume_init(), height.assume_init(), ))) }; 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.as_ref().to_glib_none().0, cancellable.to_glib_none().0, Some(callback), Box::into_raw(user_data) as *mut _, ); } } #[allow(clippy::type_complexity)] #[doc(alias = "get_file_info_async_future")] pub fn file_info_async_future + Clone + 'static>( filename: T, ) -> Pin, Error>> + 'static>> { Box::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { Self::file_info_async(filename, Some(cancellable), move |res| { send.resolve(res); }); })) } #[doc(alias = "gdk_pixbuf_save_to_bufferv")] 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::MaybeUninit::uninit(); 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, buffer_size.as_mut_ptr(), 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.assume_init() as usize, )) } else { Err(from_glib_full(error)) } } } #[cfg(any(feature = "v2_36", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_36")))] #[doc(alias = "gdk_pixbuf_save_to_streamv")] pub fn save_to_streamv, Q: IsA>( &self, stream: &P, type_: &str, options: &[(&str, &str)], cancellable: Option<&Q>, ) -> Result<(), Error> { let cancellable = cancellable.map(|p| p.as_ref()); 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.as_ref().to_glib_none().0, type_.to_glib_none().0, option_keys.to_glib_none().0, option_values.to_glib_none().0, cancellable.to_glib_none().0, &mut error, ); if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } } } #[cfg(any(feature = "v2_36", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_36")))] #[doc(alias = "gdk_pixbuf_save_to_streamv_async")] pub fn save_to_streamv_async< P: IsA, Q: IsA, R: FnOnce(Result<(), Error>) + Send + 'static, >( &self, stream: &P, type_: &str, options: &[(&str, &str)], cancellable: Option<&Q>, callback: R, ) { let cancellable = cancellable.map(|p| p.as_ref()); let user_data: Box = Box::new(callback); unsafe extern "C" fn save_to_streamv_async_trampoline< R: FnOnce(Result<(), Error>) + Send + 'static, >( _source_object: *mut glib::gobject_ffi::GObject, res: *mut gio::ffi::GAsyncResult, user_data: glib::ffi::gpointer, ) { let mut error = ptr::null_mut(); let _ = ffi::gdk_pixbuf_save_to_stream_finish(res, &mut error); let result = if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }; let callback: Box = Box::from_raw(user_data as *mut _); callback(result); } let callback = save_to_streamv_async_trampoline::; unsafe { let option_keys: Vec<&str> = options.iter().map(|o| o.0).collect(); let option_values: Vec<&str> = options.iter().map(|o| o.1).collect(); ffi::gdk_pixbuf_save_to_streamv_async( self.to_glib_none().0, stream.as_ref().to_glib_none().0, type_.to_glib_none().0, option_keys.to_glib_none().0, option_values.to_glib_none().0, cancellable.to_glib_none().0, Some(callback), Box::into_raw(user_data) as *mut _, ); } } #[cfg(any(feature = "v2_36", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_36")))] pub fn save_to_streamv_async_future + Clone + 'static>( &self, stream: &P, type_: &str, options: &[(&str, &str)], ) -> Pin> + 'static>> { let stream = stream.clone(); let type_ = String::from(type_); let options = options .iter() .map(|&(k, v)| (String::from(k), String::from(v))) .collect::>(); Box::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { let options = options .iter() .map(|&(ref k, ref v)| (k.as_str(), v.as_str())) .collect::>(); obj.save_to_streamv_async( &stream, &type_, options.as_slice(), Some(cancellable), move |res| { send.resolve(res); }, ); })) } #[doc(alias = "gdk_pixbuf_savev")] 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)) } } } } gdk-pixbuf-0.14.0/src/pixbuf_animation.rs000064400000000000000000000023150072674642500164700ustar 00000000000000// Take a look at the license at the top of the repository in the LICENSE file. use crate::PixbufAnimation; use crate::PixbufAnimationIter; use glib::object::IsA; use glib::translate::*; use std::ptr; use std::time::SystemTime; pub trait PixbufAnimationExtManual { #[doc(alias = "gdk_pixbuf_animation_get_iter")] #[doc(alias = "get_iter")] fn iter(&self, start_time: Option) -> PixbufAnimationIter; } impl> PixbufAnimationExtManual for T { fn iter(&self, start_time: Option) -> PixbufAnimationIter { let start_time = start_time.map(|s| { let diff = s .duration_since(SystemTime::UNIX_EPOCH) .expect("failed to convert time"); glib::ffi::GTimeVal { tv_sec: diff.as_secs() as _, tv_usec: diff.subsec_micros() as _, } }); unsafe { from_glib_full(ffi::gdk_pixbuf_animation_get_iter( self.as_ref().to_glib_none().0, start_time .as_ref() .map(|t| t as *const glib::ffi::GTimeVal) .unwrap_or(ptr::null()), )) } } } gdk-pixbuf-0.14.0/src/pixbuf_animation_iter.rs000064400000000000000000000033660072674642500175220ustar 00000000000000// Take a look at the license at the top of the repository in the LICENSE file. use super::Pixbuf; use glib::translate::*; use std::time::SystemTime; glib::wrapper! { #[doc(alias = "GdkPixbufAnimationIter")] pub struct PixbufAnimationIter(Object); match fn { type_ => || ffi::gdk_pixbuf_animation_iter_get_type(), } } impl PixbufAnimationIter { #[doc(alias = "gdk_pixbuf_animation_iter_advance")] pub fn advance(&self, start_time: SystemTime) -> bool { let diff = start_time .duration_since(SystemTime::UNIX_EPOCH) .expect("failed to convert time"); unsafe { from_glib(ffi::gdk_pixbuf_animation_iter_advance( self.to_glib_none().0, &glib::ffi::GTimeVal { tv_sec: diff.as_secs() as _, tv_usec: diff.subsec_micros() as _, }, )) } } #[doc(alias = "gdk_pixbuf_animation_iter_get_pixbuf")] #[doc(alias = "get_pixbuf")] pub fn pixbuf(&self) -> Pixbuf { unsafe { from_glib_none(ffi::gdk_pixbuf_animation_iter_get_pixbuf( self.to_glib_none().0, )) } } #[doc(alias = "gdk_pixbuf_animation_iter_get_delay_time")] #[doc(alias = "get_delay_time")] pub fn delay_time(&self) -> i32 { unsafe { ffi::gdk_pixbuf_animation_iter_get_delay_time(self.to_glib_none().0) } } #[doc(alias = "gdk_pixbuf_animation_iter_on_currently_loading_frame")] pub fn on_currently_loading_frame(&self) -> bool { unsafe { from_glib(ffi::gdk_pixbuf_animation_iter_on_currently_loading_frame( self.to_glib_none().0, )) } } } gdk-pixbuf-0.14.0/src/prelude.rs000064400000000000000000000004460072674642500145770ustar 00000000000000// Take a look at the license at the top of the repository in the LICENSE file. //! Traits inteded for blanket imports. pub use crate::auto::traits::*; pub use crate::pixbuf_animation::PixbufAnimationExtManual; #[doc(hidden)] pub use gio::prelude::*; #[doc(hidden)] pub use glib::prelude::*; gdk-pixbuf-0.14.0/tests/check_gir.rs000064400000000000000000000003640072674642500154270ustar 00000000000000// Take a look at the license at the top of the repository in the LICENSE file. #[test] fn check_gir_file() { let res = gir_format_check::check_gir_file("Gir.toml"); println!("{}", res.to_string()); assert_eq!(res.nb_errors, 0); } gdk-pixbuf-0.14.0/tests/overflow.rs000064400000000000000000000052320072674642500153530ustar 00000000000000use gdk_pixbuf::*; #[test] #[cfg(target_pointer_width = "64")] fn put_pixel_doesnt_overflow() { // Only test this on 64-bit boxes; otherwise we can't even // allocate a pixbuf this big. let pixbuf = Pixbuf::new(Colorspace::Rgb, true, 8, 21000, 29700).unwrap(); // debug build: thread 'put_pixel_doesnt_overflow' panicked at // 'attempt to multiply with overflow', src/pixbuf.rs:274:24 // // release build: thread 'put_pixel_doesnt_overflow' panicked at // 'index out of bounds: the len is 2494800000 but the index is // 18446744071598664320', src/pixbuf.rs:276:13 pixbuf.put_pixel(20000, 26000, 255, 255, 255, 255); } #[test] #[cfg(target_pointer_width = "64")] fn new_from_mut_slice_doesnt_overflow() { // Only test this on 64-bit boxes; otherwise we can't even // allocate a pixbuf this big. // Plus 5 to test that new_from_mut_slice() can ignore trailing data past the last row let data = vec![0u8; 21000 * 4 * 29700 + 5]; // debug build: thread 'new_from_mut_slice_doesnt_overflow' // panicked at 'attempt to multiply with overflow', // /home/federico/src/gtk-rs/gdk-pixbuf/src/pixbuf.rs:50:36 // // release build: thread 'new_from_mut_slice_doesnt_overflow' // panicked at 'assertion failed: data.len() == ((height - 1) * // row_stride + last_row_len) as usize', src/pixbuf.rs:50:13 let _pixbuf = Pixbuf::from_mut_slice(data, Colorspace::Rgb, true, 8, 21000, 29700, 21000 * 4); } #[test] #[should_panic] fn put_pixel_out_of_bounds_x_should_panic() { let pixbuf = Pixbuf::new(Colorspace::Rgb, true, 8, 100, 200).unwrap(); pixbuf.put_pixel(100, 0, 0, 0, 0, 0); } #[test] #[should_panic] fn put_pixel_out_of_bounds_y_should_panic() { let pixbuf = Pixbuf::new(Colorspace::Rgb, true, 8, 100, 200).unwrap(); pixbuf.put_pixel(0, 200, 0, 0, 0, 0); } #[test] #[should_panic] fn too_small_slice_should_panic() { let data = vec![0u8; 100 * 99 * 4]; Pixbuf::from_mut_slice(data, Colorspace::Rgb, true, 8, 100, 100, 100 * 4); } #[test] fn last_row_with_incomplete_rowstride_works() { // 1-pixel wide, RGB, 3 32-bit rows, no extra padding byte on the fourth row let data = vec![0u8; 4 * 3 + 3]; Pixbuf::from_mut_slice(data, Colorspace::Rgb, false, 8, 1, 4, 4); } #[test] fn last_row_with_full_rowstride_works() { // 1-pixel wide, RGB, 4 32-bit rows let data = vec![0u8; 4 * 4]; Pixbuf::from_mut_slice(data, Colorspace::Rgb, false, 8, 1, 4, 4); } #[test] fn extra_data_after_last_row_works() { // 1-pixel wide, RGB, 4 32-bit rows, plus some extra space let data = vec![0u8; 4 * 4 + 42]; Pixbuf::from_mut_slice(data, Colorspace::Rgb, false, 8, 1, 4, 4); }