├── .github └── FUNDING.yml ├── .gitignore ├── .gitmodules ├── .travis.yml ├── COPYRIGHT ├── Cargo.toml ├── Gir.toml ├── LICENSE ├── Makefile ├── README.md ├── appveyor.yml ├── build.rs ├── src ├── auto │ ├── enums.rs │ ├── mod.rs │ ├── pixbuf.rs │ ├── pixbuf_animation.rs │ ├── pixbuf_format.rs │ ├── pixbuf_loader.rs │ ├── pixbuf_simple_anim.rs │ └── versions.txt ├── lib.rs ├── pixbuf.rs ├── pixbuf_animation.rs ├── pixbuf_animation_iter.rs └── prelude.rs └── tests ├── check_gir.rs └── overflow.rs /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | open_collective: gtk-rs 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Cargo.lock 2 | target/ 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "gir"] 2 | path = gir 3 | url = https://github.com/gtk-rs/gir.git 4 | [submodule "gir-files"] 5 | path = gir-files 6 | url = https://github.com/gtk-rs/gir-files.git 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: xenial 2 | language: rust 3 | os: 4 | - linux 5 | - osx 6 | rust: 7 | - nightly 8 | - beta 9 | - stable 10 | - 1.40.0 11 | env: 12 | - GTK=3.14 FEATURES= 13 | - GTK=3.24 FEATURES=v2_32 14 | jobs: 15 | exclude: 16 | - os: osx 17 | env: GTK=3.24 FEATURES=v2_32 18 | 19 | addons: 20 | apt: 21 | packages: 22 | - libgtk-3-dev 23 | - libmount-dev 24 | 25 | before_install: 26 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi 27 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew unlink python@2; fi 28 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install gtk+3 cairo atk; fi 29 | 30 | script: 31 | - rustc --version 32 | - if [ "$TRAVIS_RUST_VERSION" == "stable" ] && [ "$GTK" == "3.14" ]; then 33 | rustup component add rustfmt; 34 | make regen_check; 35 | fi 36 | - cargo doc --features "dox,embed-lgpl-docs" 37 | - cargo test --features "$FEATURES,embed-lgpl-docs" 38 | # catch any sneaked in lgpl docs 39 | - cargo build --features "$FEATURES,purge-lgpl-docs" --jobs 1 40 | - git diff -R --exit-code 41 | - rustc --version 42 | - mkdir .cargo 43 | - echo 'paths = ["."]' > .cargo/config 44 | - git clone -q --depth 50 -b pending https://github.com/gtk-rs/examples _examples 45 | - cd _examples 46 | - ./build_travis.sh 47 | - if [ "$TRAVIS_RUST_VERSION" == "stable" ] && [ "$GTK" == "3.14" ]; then 48 | cd ..; 49 | git clone https://github.com/gtk-rs/checker; 50 | cd checker && cargo build --release; 51 | cd .. && ./checker/target/release/checker .; 52 | fi 53 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | The Gtk-rs Project is copyright 2013-2016, The Gtk-rs Project Developers: 2 | 3 | Adam Crume 4 | Adolfo Ochagavía 5 | Andre Bogus 6 | Anton Konjahin 7 | Arne Dussin 8 | Boden Garman 9 | Brian Kropf 10 | Bryant Mairs 11 | Chris Greenaway 12 | Chris Palmer 13 | Corey Farwell 14 | Daniel Zalevskiy 15 | David Li 16 | Edward Shaw 17 | Edward Yang 18 | Esption 19 | Evgenii Pashkin 20 | Geoffrey French 21 | Gleb Kozyrev 22 | Glenn Watson 23 | Google Inc. 24 | Guillaume Gomez 25 | Gulshan Singh 26 | Jakob Gillich 27 | James Shepherdson 28 | Jeremy Letang 29 | John Vrbanac 30 | kennytm 31 | Laurence Tratt 32 | Lionel Flandrin 33 | Lucas Werkmeister 34 | Lukas Diekmann 35 | Mathijs Henquet 36 | Maxwell Koo 37 | mitaa 38 | Nick Herman 39 | Nicolas Koch 40 | Oliver Schneider 41 | Ömer Sinan Ağacan 42 | Ralph Giles 43 | Paul Dennis 44 | Paul Hendry 45 | Philipp Brüschweiler 46 | Raphael Nestler 47 | Robertas 48 | Romain Gauthier 49 | S.J.R. van Schaik 50 | Sebastian Schulze 51 | Silvio Fricke 52 | Simon Sapin 53 | Steve Klabnik 54 | Tobias Bales 55 | trolleyman 56 | Umur Gedik 57 | UrKr 58 | Vojtech Kral 59 | Zach Oakes 60 | Zach Ploskey 61 | 62 | The Gtk-rs Project is licensed under the MIT license, see the LICENSE file 63 | or . 64 | 65 | This project provides interoperability with various GNOME libraries but doesn't 66 | distribute any parts of them. Distributing compiled libraries and executables 67 | that link to those libraries may be subject to terms of the GNU LGPL, see the 68 | LGPL file. 69 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gdk-pixbuf" 3 | license = "MIT" 4 | homepage = "https://gtk-rs.org/" 5 | authors = ["The Gtk-rs Project Developers"] 6 | keywords = ["gdk-pixbuf", "gtk-rs", "gnome"] 7 | readme = "README.md" 8 | documentation = "https://gtk-rs.org/docs/gdk_pixbuf/" 9 | version = "0.9.0" 10 | description = "Rust bindings for the GdkPixbuf library" 11 | repository = "https://github.com/gtk-rs/gdk-pixbuf" 12 | build = "build.rs" 13 | exclude = [ 14 | "gir-files/*", 15 | ] 16 | 17 | [badges] 18 | appveyor = { repository = "GuillaumeGomez/gdk-pixbuf", service = "github" } 19 | travis-ci = { repository = "gtk-rs/gdk-pixbuf" } 20 | 21 | [lib] 22 | name = "gdk_pixbuf" 23 | 24 | [features] 25 | v2_32 = ["gdk-pixbuf-sys/v2_32"] 26 | v2_36 = ["v2_32", "gdk-pixbuf-sys/v2_36"] 27 | v2_36_8 = ["v2_36", "gdk-pixbuf-sys/v2_36_8"] 28 | v2_40 = ["v2_36_8", "gdk-pixbuf-sys/v2_40"] 29 | dox = ["glib/dox", "gdk-pixbuf-sys/dox"] 30 | purge-lgpl-docs = ["gtk-rs-lgpl-docs"] 31 | embed-lgpl-docs = ["gtk-rs-lgpl-docs"] 32 | 33 | [package.metadata.docs.rs] 34 | features = ["dox", "embed-lgpl-docs"] 35 | 36 | [build-dependencies.gtk-rs-lgpl-docs] 37 | version = "0.1" 38 | optional = true 39 | git = "https://github.com/gtk-rs/lgpl-docs" 40 | 41 | [dependencies] 42 | libc = "0.2" 43 | gdk-pixbuf-sys = { git = "https://github.com/gtk-rs/sys" } 44 | glib = { git = "https://github.com/gtk-rs/glib" } 45 | glib-sys = { git = "https://github.com/gtk-rs/sys" } 46 | gobject-sys = { git = "https://github.com/gtk-rs/sys" } 47 | gio-sys = { git = "https://github.com/gtk-rs/sys" } 48 | gio = { git = "https://github.com/gtk-rs/gio" } 49 | 50 | [dev-dependencies] 51 | gir-format-check = "^0.1" 52 | -------------------------------------------------------------------------------- /Gir.toml: -------------------------------------------------------------------------------- 1 | [options] 2 | girs_dir = "gir-files" 3 | library = "GdkPixbuf" 4 | version = "2.0" 5 | min_cfg_version = "2.30" 6 | target_path = "." 7 | work_mode = "normal" 8 | single_version_file = true 9 | deprecate_by_min_version = true 10 | 11 | generate = [ 12 | "GdkPixbuf.Colorspace", 13 | "GdkPixbuf.InterpType", 14 | "GdkPixbuf.PixbufAlphaMode", 15 | "GdkPixbuf.PixbufError", 16 | "GdkPixbuf.PixbufLoader", 17 | "GdkPixbuf.PixbufRotation", 18 | "GdkPixbuf.PixbufSimpleAnim", 19 | ] 20 | 21 | manual = [ 22 | "GdkPixbuf.PixbufAnimationIter", 23 | "Gio.AsyncReadyCallback", 24 | "Gio.Cancellable", 25 | "Gio.Icon", 26 | "Gio.InputStream", 27 | "Gio.LoadableIcon", 28 | "Gio.OutputStream", 29 | "GLib.Bytes", 30 | "GLib.Error", 31 | ] 32 | 33 | [[object]] 34 | name = "GdkPixbuf.Pixbuf" 35 | status = "generate" 36 | [[object.function]] 37 | name = "get_pixels" 38 | #manual array without length 39 | ignore = true 40 | [[object.function]] 41 | name = "get_pixels_with_length" 42 | #manual as get_pixels 43 | ignore = true 44 | [[object.function]] 45 | name = "read_pixels" 46 | #unimplementable, use get_pixels instead 47 | ignore = true 48 | [[object.function]] 49 | name = "new_from_file" 50 | #manual is_windows_utf8 51 | ignore = true 52 | [[object.function]] 53 | name = "new" 54 | [object.function.return] 55 | nullable = true 56 | [[object.function]] 57 | name = "new_from_file_at_size" 58 | #manual is_windows_utf8 59 | ignore = true 60 | [[object.function]] 61 | name = "new_from_file_at_scale" 62 | #manual is_windows_utf8 63 | ignore = true 64 | [[object.function]] 65 | name = "new_from_stream_async" 66 | # wrong async return 67 | ignore = true 68 | [[object.function]] 69 | name = "new_from_stream_at_scale_async" 70 | # wrong return and don't generated 71 | ignore = true 72 | [[object.function]] 73 | name = "get_file_info" 74 | # wrong return 75 | ignore = true 76 | [[object.function]] 77 | name = "get_file_info_async" 78 | # wrong async return 79 | ignore = true 80 | [[object.function]] 81 | name = "save_to_bufferv" 82 | # manual complex param 83 | ignore = true 84 | [[object.function]] 85 | name = "save_to_streamv" 86 | # manual complex param 87 | ignore = true 88 | [[object.function]] 89 | name = "savev" 90 | # manual complex param 91 | ignore = true 92 | [[object.function]] 93 | name = "save_to_streamv_async" 94 | # manual complex param 95 | ignore = true 96 | 97 | [[object]] 98 | name = "GdkPixbuf.PixbufAnimation" 99 | status = "generate" 100 | [[object.function]] 101 | name = "get_iter" 102 | # TimeVal misses memory management functions 103 | ignore = true 104 | 105 | [[object]] 106 | name = "GdkPixbuf.PixbufFormat" 107 | status = "generate" 108 | [[object.function]] 109 | pattern = "get_.+" 110 | [[object.function.parameter]] 111 | name = "format" 112 | const = true 113 | [[object.function]] 114 | pattern = "is_.+" 115 | [[object.function.parameter]] 116 | name = "format" 117 | const = true 118 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | GIR = gir/target/bin/gir 2 | GIR_SRC = gir/Cargo.toml gir/Cargo.lock gir/build.rs $(shell find gir/src -name '*.rs') 3 | GIR_FILES = gir-files/Gtk-3.0.gir 4 | 5 | # Run `gir` generating the bindings 6 | gir : src/auto/mod.rs 7 | cargo fmt 8 | 9 | doc: $(GIR) $(GIR_FILES) 10 | $(GIR) -m doc -c Gir.toml 11 | 12 | not_bound: $(GIR) $(GIR_FILES) 13 | $(GIR) -m not_bound -c Gir.toml 14 | 15 | regen_check: $(GIR) $(GIR_FILES) 16 | rm src/auto/* 17 | $(GIR) -c Gir.toml 18 | cargo fmt 19 | git diff -R --exit-code 20 | 21 | src/auto/mod.rs : Gir.toml $(GIR) $(GIR_FILES) 22 | $(GIR) -c Gir.toml 23 | 24 | $(GIR) : $(GIR_SRC) 25 | rm -f gir/target/bin/gir 26 | cargo install --path gir --root gir/target 27 | rm -f gir/target/.crates.toml 28 | 29 | $(GIR_SRC) $(GIR_FILES) : 30 | git submodule update --init 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gdk-pixbuf [![Build Status](https://travis-ci.org/gtk-rs/gdk-pixbuf.png?branch=master)](https://travis-ci.org/gtk-rs/gdk-pixbuf) [![Build status](https://ci.appveyor.com/api/projects/status/5gcteolq1p274tue?svg=true)](https://ci.appveyor.com/project/GuillaumeGomez/gdk-pixbuf) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gtk-rs/gtk) 2 | 3 | Gdk-Pixbuf bindings for Rust. 4 | 5 | - [Gtk-rs project site](https://gtk-rs.org/) 6 | 7 | - [Online documentation](https://gtk-rs.org/docs-src/) 8 | 9 | - [Readme](https://github.com/gtk-rs/gtk/blob/master/README.md) in our 10 | [main repo](https://github.com/gtk-rs/gtk) 11 | 12 | ## License 13 | 14 | MIT 15 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | matrix: 3 | - RUST: stable 4 | BITS: 32 5 | - RUST: stable 6 | BITS: 64 7 | 8 | install: 9 | - IF "%BITS%" == "32" SET ARCH=i686 10 | - IF "%BITS%" == "64" SET ARCH=x86_64 11 | - curl -sSf -o rustup-init.exe https://win.rustup.rs 12 | - rustup-init.exe --default-host "%ARCH%-pc-windows-gnu" --default-toolchain %RUST% -y 13 | - SET PATH=C:\Users\appveyor\.cargo\bin;C:\msys64\mingw%BITS%\bin;%PATH%;C:\msys64\usr\bin 14 | - rustc -Vv 15 | - cargo -Vv 16 | - pacman --noconfirm -S mingw-w64-%ARCH%-gtk3 17 | 18 | build_script: 19 | - cargo doc --features "dox" 20 | - cargo test 21 | - cargo test --features v2_36_8 22 | - mkdir .cargo 23 | - echo paths = ["."] > .cargo\config 24 | - git clone -q --depth 50 -b pending https://github.com/gtk-rs/examples _examples 25 | - cd _examples 26 | - cargo build 27 | - cargo build --features gtk_3_24 28 | 29 | test: false 30 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | manage_docs(); 3 | } 4 | 5 | #[cfg(all( 6 | any(feature = "embed-lgpl-docs", feature = "purge-lgpl-docs"), 7 | not(all(feature = "embed-lgpl-docs", feature = "purge-lgpl-docs")) 8 | ))] 9 | fn manage_docs() { 10 | extern crate lgpl_docs; 11 | const PATH: &'static str = "src"; 12 | const IGNORES: &'static [&'static str] = &["prelude.rs"]; 13 | lgpl_docs::purge(PATH, IGNORES); 14 | if cfg!(feature = "embed-lgpl-docs") { 15 | lgpl_docs::embed(lgpl_docs::Library::GdkPixbuf, PATH, IGNORES); 16 | } 17 | } 18 | 19 | #[cfg(any( 20 | all(feature = "embed-lgpl-docs", feature = "purge-lgpl-docs"), 21 | not(any(feature = "embed-lgpl-docs", feature = "purge-lgpl-docs")) 22 | ))] 23 | fn manage_docs() {} 24 | -------------------------------------------------------------------------------- /src/auto/enums.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gdk_pixbuf_sys; 6 | use glib::error::ErrorDomain; 7 | use glib::translate::*; 8 | use glib::value::FromValue; 9 | use glib::value::FromValueOptional; 10 | use glib::value::SetValue; 11 | use glib::value::Value; 12 | use glib::Quark; 13 | use glib::StaticType; 14 | use glib::Type; 15 | use gobject_sys; 16 | use std::fmt; 17 | 18 | #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] 19 | #[non_exhaustive] 20 | pub enum Colorspace { 21 | Rgb, 22 | #[doc(hidden)] 23 | __Unknown(i32), 24 | } 25 | 26 | impl fmt::Display for Colorspace { 27 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 28 | write!( 29 | f, 30 | "Colorspace::{}", 31 | match *self { 32 | Colorspace::Rgb => "Rgb", 33 | _ => "Unknown", 34 | } 35 | ) 36 | } 37 | } 38 | 39 | #[doc(hidden)] 40 | impl ToGlib for Colorspace { 41 | type GlibType = gdk_pixbuf_sys::GdkColorspace; 42 | 43 | fn to_glib(&self) -> gdk_pixbuf_sys::GdkColorspace { 44 | match *self { 45 | Colorspace::Rgb => gdk_pixbuf_sys::GDK_COLORSPACE_RGB, 46 | Colorspace::__Unknown(value) => value, 47 | } 48 | } 49 | } 50 | 51 | #[doc(hidden)] 52 | impl FromGlib for Colorspace { 53 | fn from_glib(value: gdk_pixbuf_sys::GdkColorspace) -> Self { 54 | match value { 55 | 0 => Colorspace::Rgb, 56 | value => Colorspace::__Unknown(value), 57 | } 58 | } 59 | } 60 | 61 | impl StaticType for Colorspace { 62 | fn static_type() -> Type { 63 | unsafe { from_glib(gdk_pixbuf_sys::gdk_colorspace_get_type()) } 64 | } 65 | } 66 | 67 | impl<'a> FromValueOptional<'a> for Colorspace { 68 | unsafe fn from_value_optional(value: &Value) -> Option { 69 | Some(FromValue::from_value(value)) 70 | } 71 | } 72 | 73 | impl<'a> FromValue<'a> for Colorspace { 74 | unsafe fn from_value(value: &Value) -> Self { 75 | from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) 76 | } 77 | } 78 | 79 | impl SetValue for Colorspace { 80 | unsafe fn set_value(value: &mut Value, this: &Self) { 81 | gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) 82 | } 83 | } 84 | 85 | #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] 86 | #[non_exhaustive] 87 | pub enum InterpType { 88 | Nearest, 89 | Tiles, 90 | Bilinear, 91 | Hyper, 92 | #[doc(hidden)] 93 | __Unknown(i32), 94 | } 95 | 96 | impl fmt::Display for InterpType { 97 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 98 | write!( 99 | f, 100 | "InterpType::{}", 101 | match *self { 102 | InterpType::Nearest => "Nearest", 103 | InterpType::Tiles => "Tiles", 104 | InterpType::Bilinear => "Bilinear", 105 | InterpType::Hyper => "Hyper", 106 | _ => "Unknown", 107 | } 108 | ) 109 | } 110 | } 111 | 112 | #[doc(hidden)] 113 | impl ToGlib for InterpType { 114 | type GlibType = gdk_pixbuf_sys::GdkInterpType; 115 | 116 | fn to_glib(&self) -> gdk_pixbuf_sys::GdkInterpType { 117 | match *self { 118 | InterpType::Nearest => gdk_pixbuf_sys::GDK_INTERP_NEAREST, 119 | InterpType::Tiles => gdk_pixbuf_sys::GDK_INTERP_TILES, 120 | InterpType::Bilinear => gdk_pixbuf_sys::GDK_INTERP_BILINEAR, 121 | InterpType::Hyper => gdk_pixbuf_sys::GDK_INTERP_HYPER, 122 | InterpType::__Unknown(value) => value, 123 | } 124 | } 125 | } 126 | 127 | #[doc(hidden)] 128 | impl FromGlib for InterpType { 129 | fn from_glib(value: gdk_pixbuf_sys::GdkInterpType) -> Self { 130 | match value { 131 | 0 => InterpType::Nearest, 132 | 1 => InterpType::Tiles, 133 | 2 => InterpType::Bilinear, 134 | 3 => InterpType::Hyper, 135 | value => InterpType::__Unknown(value), 136 | } 137 | } 138 | } 139 | 140 | impl StaticType for InterpType { 141 | fn static_type() -> Type { 142 | unsafe { from_glib(gdk_pixbuf_sys::gdk_interp_type_get_type()) } 143 | } 144 | } 145 | 146 | impl<'a> FromValueOptional<'a> for InterpType { 147 | unsafe fn from_value_optional(value: &Value) -> Option { 148 | Some(FromValue::from_value(value)) 149 | } 150 | } 151 | 152 | impl<'a> FromValue<'a> for InterpType { 153 | unsafe fn from_value(value: &Value) -> Self { 154 | from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) 155 | } 156 | } 157 | 158 | impl SetValue for InterpType { 159 | unsafe fn set_value(value: &mut Value, this: &Self) { 160 | gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) 161 | } 162 | } 163 | 164 | #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] 165 | #[non_exhaustive] 166 | pub enum PixbufAlphaMode { 167 | Bilevel, 168 | Full, 169 | #[doc(hidden)] 170 | __Unknown(i32), 171 | } 172 | 173 | impl fmt::Display for PixbufAlphaMode { 174 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 175 | write!( 176 | f, 177 | "PixbufAlphaMode::{}", 178 | match *self { 179 | PixbufAlphaMode::Bilevel => "Bilevel", 180 | PixbufAlphaMode::Full => "Full", 181 | _ => "Unknown", 182 | } 183 | ) 184 | } 185 | } 186 | 187 | #[doc(hidden)] 188 | impl ToGlib for PixbufAlphaMode { 189 | type GlibType = gdk_pixbuf_sys::GdkPixbufAlphaMode; 190 | 191 | fn to_glib(&self) -> gdk_pixbuf_sys::GdkPixbufAlphaMode { 192 | match *self { 193 | PixbufAlphaMode::Bilevel => gdk_pixbuf_sys::GDK_PIXBUF_ALPHA_BILEVEL, 194 | PixbufAlphaMode::Full => gdk_pixbuf_sys::GDK_PIXBUF_ALPHA_FULL, 195 | PixbufAlphaMode::__Unknown(value) => value, 196 | } 197 | } 198 | } 199 | 200 | #[doc(hidden)] 201 | impl FromGlib for PixbufAlphaMode { 202 | fn from_glib(value: gdk_pixbuf_sys::GdkPixbufAlphaMode) -> Self { 203 | match value { 204 | 0 => PixbufAlphaMode::Bilevel, 205 | 1 => PixbufAlphaMode::Full, 206 | value => PixbufAlphaMode::__Unknown(value), 207 | } 208 | } 209 | } 210 | 211 | impl StaticType for PixbufAlphaMode { 212 | fn static_type() -> Type { 213 | unsafe { from_glib(gdk_pixbuf_sys::gdk_pixbuf_alpha_mode_get_type()) } 214 | } 215 | } 216 | 217 | impl<'a> FromValueOptional<'a> for PixbufAlphaMode { 218 | unsafe fn from_value_optional(value: &Value) -> Option { 219 | Some(FromValue::from_value(value)) 220 | } 221 | } 222 | 223 | impl<'a> FromValue<'a> for PixbufAlphaMode { 224 | unsafe fn from_value(value: &Value) -> Self { 225 | from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) 226 | } 227 | } 228 | 229 | impl SetValue for PixbufAlphaMode { 230 | unsafe fn set_value(value: &mut Value, this: &Self) { 231 | gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) 232 | } 233 | } 234 | 235 | #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] 236 | #[non_exhaustive] 237 | pub enum PixbufError { 238 | CorruptImage, 239 | InsufficientMemory, 240 | BadOption, 241 | UnknownType, 242 | UnsupportedOperation, 243 | Failed, 244 | IncompleteAnimation, 245 | #[doc(hidden)] 246 | __Unknown(i32), 247 | } 248 | 249 | impl fmt::Display for PixbufError { 250 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 251 | write!( 252 | f, 253 | "PixbufError::{}", 254 | match *self { 255 | PixbufError::CorruptImage => "CorruptImage", 256 | PixbufError::InsufficientMemory => "InsufficientMemory", 257 | PixbufError::BadOption => "BadOption", 258 | PixbufError::UnknownType => "UnknownType", 259 | PixbufError::UnsupportedOperation => "UnsupportedOperation", 260 | PixbufError::Failed => "Failed", 261 | PixbufError::IncompleteAnimation => "IncompleteAnimation", 262 | _ => "Unknown", 263 | } 264 | ) 265 | } 266 | } 267 | 268 | #[doc(hidden)] 269 | impl ToGlib for PixbufError { 270 | type GlibType = gdk_pixbuf_sys::GdkPixbufError; 271 | 272 | fn to_glib(&self) -> gdk_pixbuf_sys::GdkPixbufError { 273 | match *self { 274 | PixbufError::CorruptImage => gdk_pixbuf_sys::GDK_PIXBUF_ERROR_CORRUPT_IMAGE, 275 | PixbufError::InsufficientMemory => gdk_pixbuf_sys::GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY, 276 | PixbufError::BadOption => gdk_pixbuf_sys::GDK_PIXBUF_ERROR_BAD_OPTION, 277 | PixbufError::UnknownType => gdk_pixbuf_sys::GDK_PIXBUF_ERROR_UNKNOWN_TYPE, 278 | PixbufError::UnsupportedOperation => { 279 | gdk_pixbuf_sys::GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION 280 | } 281 | PixbufError::Failed => gdk_pixbuf_sys::GDK_PIXBUF_ERROR_FAILED, 282 | PixbufError::IncompleteAnimation => { 283 | gdk_pixbuf_sys::GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION 284 | } 285 | PixbufError::__Unknown(value) => value, 286 | } 287 | } 288 | } 289 | 290 | #[doc(hidden)] 291 | impl FromGlib for PixbufError { 292 | fn from_glib(value: gdk_pixbuf_sys::GdkPixbufError) -> Self { 293 | match value { 294 | 0 => PixbufError::CorruptImage, 295 | 1 => PixbufError::InsufficientMemory, 296 | 2 => PixbufError::BadOption, 297 | 3 => PixbufError::UnknownType, 298 | 4 => PixbufError::UnsupportedOperation, 299 | 5 => PixbufError::Failed, 300 | 6 => PixbufError::IncompleteAnimation, 301 | value => PixbufError::__Unknown(value), 302 | } 303 | } 304 | } 305 | 306 | impl ErrorDomain for PixbufError { 307 | fn domain() -> Quark { 308 | unsafe { from_glib(gdk_pixbuf_sys::gdk_pixbuf_error_quark()) } 309 | } 310 | 311 | fn code(self) -> i32 { 312 | self.to_glib() 313 | } 314 | 315 | fn from(code: i32) -> Option { 316 | match code { 317 | 0 => Some(PixbufError::CorruptImage), 318 | 1 => Some(PixbufError::InsufficientMemory), 319 | 2 => Some(PixbufError::BadOption), 320 | 3 => Some(PixbufError::UnknownType), 321 | 4 => Some(PixbufError::UnsupportedOperation), 322 | 5 => Some(PixbufError::Failed), 323 | 6 => Some(PixbufError::IncompleteAnimation), 324 | _ => Some(PixbufError::Failed), 325 | } 326 | } 327 | } 328 | 329 | impl StaticType for PixbufError { 330 | fn static_type() -> Type { 331 | unsafe { from_glib(gdk_pixbuf_sys::gdk_pixbuf_error_get_type()) } 332 | } 333 | } 334 | 335 | impl<'a> FromValueOptional<'a> for PixbufError { 336 | unsafe fn from_value_optional(value: &Value) -> Option { 337 | Some(FromValue::from_value(value)) 338 | } 339 | } 340 | 341 | impl<'a> FromValue<'a> for PixbufError { 342 | unsafe fn from_value(value: &Value) -> Self { 343 | from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) 344 | } 345 | } 346 | 347 | impl SetValue for PixbufError { 348 | unsafe fn set_value(value: &mut Value, this: &Self) { 349 | gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) 350 | } 351 | } 352 | 353 | #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] 354 | #[non_exhaustive] 355 | pub enum PixbufRotation { 356 | None, 357 | Counterclockwise, 358 | Upsidedown, 359 | Clockwise, 360 | #[doc(hidden)] 361 | __Unknown(i32), 362 | } 363 | 364 | impl fmt::Display for PixbufRotation { 365 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 366 | write!( 367 | f, 368 | "PixbufRotation::{}", 369 | match *self { 370 | PixbufRotation::None => "None", 371 | PixbufRotation::Counterclockwise => "Counterclockwise", 372 | PixbufRotation::Upsidedown => "Upsidedown", 373 | PixbufRotation::Clockwise => "Clockwise", 374 | _ => "Unknown", 375 | } 376 | ) 377 | } 378 | } 379 | 380 | #[doc(hidden)] 381 | impl ToGlib for PixbufRotation { 382 | type GlibType = gdk_pixbuf_sys::GdkPixbufRotation; 383 | 384 | fn to_glib(&self) -> gdk_pixbuf_sys::GdkPixbufRotation { 385 | match *self { 386 | PixbufRotation::None => gdk_pixbuf_sys::GDK_PIXBUF_ROTATE_NONE, 387 | PixbufRotation::Counterclockwise => gdk_pixbuf_sys::GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE, 388 | PixbufRotation::Upsidedown => gdk_pixbuf_sys::GDK_PIXBUF_ROTATE_UPSIDEDOWN, 389 | PixbufRotation::Clockwise => gdk_pixbuf_sys::GDK_PIXBUF_ROTATE_CLOCKWISE, 390 | PixbufRotation::__Unknown(value) => value, 391 | } 392 | } 393 | } 394 | 395 | #[doc(hidden)] 396 | impl FromGlib for PixbufRotation { 397 | fn from_glib(value: gdk_pixbuf_sys::GdkPixbufRotation) -> Self { 398 | match value { 399 | 0 => PixbufRotation::None, 400 | 90 => PixbufRotation::Counterclockwise, 401 | 180 => PixbufRotation::Upsidedown, 402 | 270 => PixbufRotation::Clockwise, 403 | value => PixbufRotation::__Unknown(value), 404 | } 405 | } 406 | } 407 | 408 | impl StaticType for PixbufRotation { 409 | fn static_type() -> Type { 410 | unsafe { from_glib(gdk_pixbuf_sys::gdk_pixbuf_rotation_get_type()) } 411 | } 412 | } 413 | 414 | impl<'a> FromValueOptional<'a> for PixbufRotation { 415 | unsafe fn from_value_optional(value: &Value) -> Option { 416 | Some(FromValue::from_value(value)) 417 | } 418 | } 419 | 420 | impl<'a> FromValue<'a> for PixbufRotation { 421 | unsafe fn from_value(value: &Value) -> Self { 422 | from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) 423 | } 424 | } 425 | 426 | impl SetValue for PixbufRotation { 427 | unsafe fn set_value(value: &mut Value, this: &Self) { 428 | gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) 429 | } 430 | } 431 | -------------------------------------------------------------------------------- /src/auto/mod.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | mod pixbuf; 6 | pub use self::pixbuf::{Pixbuf, PixbufClass}; 7 | 8 | mod pixbuf_animation; 9 | pub use self::pixbuf_animation::PixbufAnimationExt; 10 | pub use self::pixbuf_animation::{PixbufAnimation, PixbufAnimationClass, NONE_PIXBUF_ANIMATION}; 11 | 12 | mod pixbuf_loader; 13 | pub use self::pixbuf_loader::PixbufLoaderExt; 14 | pub use self::pixbuf_loader::{PixbufLoader, PixbufLoaderClass, NONE_PIXBUF_LOADER}; 15 | 16 | mod pixbuf_simple_anim; 17 | pub use self::pixbuf_simple_anim::{PixbufSimpleAnim, PixbufSimpleAnimClass}; 18 | 19 | mod pixbuf_format; 20 | pub use self::pixbuf_format::PixbufFormat; 21 | 22 | mod enums; 23 | pub use self::enums::Colorspace; 24 | pub use self::enums::InterpType; 25 | pub use self::enums::PixbufAlphaMode; 26 | pub use self::enums::PixbufError; 27 | pub use self::enums::PixbufRotation; 28 | 29 | #[doc(hidden)] 30 | pub mod traits { 31 | pub use super::PixbufAnimationExt; 32 | pub use super::PixbufLoaderExt; 33 | } 34 | -------------------------------------------------------------------------------- /src/auto/pixbuf.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gdk_pixbuf_sys; 6 | use gio; 7 | use glib; 8 | use glib::object::IsA; 9 | use glib::object::ObjectType as ObjectType_; 10 | use glib::translate::*; 11 | use glib::GString; 12 | use glib::StaticType; 13 | use glib::Value; 14 | use gobject_sys; 15 | use std::fmt; 16 | use std::ptr; 17 | use Colorspace; 18 | use InterpType; 19 | use PixbufFormat; 20 | use PixbufRotation; 21 | 22 | glib_wrapper! { 23 | pub struct Pixbuf(Object) @implements gio::Icon, gio::LoadableIcon; 24 | 25 | match fn { 26 | get_type => || gdk_pixbuf_sys::gdk_pixbuf_get_type(), 27 | } 28 | } 29 | 30 | impl Pixbuf { 31 | pub fn new( 32 | colorspace: Colorspace, 33 | has_alpha: bool, 34 | bits_per_sample: i32, 35 | width: i32, 36 | height: i32, 37 | ) -> Option { 38 | unsafe { 39 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_new( 40 | colorspace.to_glib(), 41 | has_alpha.to_glib(), 42 | bits_per_sample, 43 | width, 44 | height, 45 | )) 46 | } 47 | } 48 | 49 | #[cfg(any(feature = "v2_32", feature = "dox"))] 50 | pub fn from_bytes( 51 | data: &glib::Bytes, 52 | colorspace: Colorspace, 53 | has_alpha: bool, 54 | bits_per_sample: i32, 55 | width: i32, 56 | height: i32, 57 | rowstride: i32, 58 | ) -> Pixbuf { 59 | unsafe { 60 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_new_from_bytes( 61 | data.to_glib_none().0, 62 | colorspace.to_glib(), 63 | has_alpha.to_glib(), 64 | bits_per_sample, 65 | width, 66 | height, 67 | rowstride, 68 | )) 69 | } 70 | } 71 | 72 | //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 { 73 | // unsafe { TODO: call gdk_pixbuf_sys:gdk_pixbuf_new_from_data() } 74 | //} 75 | 76 | #[cfg_attr(feature = "v2_32", deprecated)] 77 | pub fn from_inline(data: &[u8], copy_pixels: bool) -> Result { 78 | let data_length = data.len() as i32; 79 | unsafe { 80 | let mut error = ptr::null_mut(); 81 | let ret = gdk_pixbuf_sys::gdk_pixbuf_new_from_inline( 82 | data_length, 83 | data.to_glib_none().0, 84 | copy_pixels.to_glib(), 85 | &mut error, 86 | ); 87 | if error.is_null() { 88 | Ok(from_glib_full(ret)) 89 | } else { 90 | Err(from_glib_full(error)) 91 | } 92 | } 93 | } 94 | 95 | pub fn from_resource(resource_path: &str) -> Result { 96 | unsafe { 97 | let mut error = ptr::null_mut(); 98 | let ret = gdk_pixbuf_sys::gdk_pixbuf_new_from_resource( 99 | resource_path.to_glib_none().0, 100 | &mut error, 101 | ); 102 | if error.is_null() { 103 | Ok(from_glib_full(ret)) 104 | } else { 105 | Err(from_glib_full(error)) 106 | } 107 | } 108 | } 109 | 110 | pub fn from_resource_at_scale( 111 | resource_path: &str, 112 | width: i32, 113 | height: i32, 114 | preserve_aspect_ratio: bool, 115 | ) -> Result { 116 | unsafe { 117 | let mut error = ptr::null_mut(); 118 | let ret = gdk_pixbuf_sys::gdk_pixbuf_new_from_resource_at_scale( 119 | resource_path.to_glib_none().0, 120 | width, 121 | height, 122 | preserve_aspect_ratio.to_glib(), 123 | &mut error, 124 | ); 125 | if error.is_null() { 126 | Ok(from_glib_full(ret)) 127 | } else { 128 | Err(from_glib_full(error)) 129 | } 130 | } 131 | } 132 | 133 | pub fn from_stream, Q: IsA>( 134 | stream: &P, 135 | cancellable: Option<&Q>, 136 | ) -> Result { 137 | unsafe { 138 | let mut error = ptr::null_mut(); 139 | let ret = gdk_pixbuf_sys::gdk_pixbuf_new_from_stream( 140 | stream.as_ref().to_glib_none().0, 141 | cancellable.map(|p| p.as_ref()).to_glib_none().0, 142 | &mut error, 143 | ); 144 | if error.is_null() { 145 | Ok(from_glib_full(ret)) 146 | } else { 147 | Err(from_glib_full(error)) 148 | } 149 | } 150 | } 151 | 152 | pub fn from_stream_at_scale, Q: IsA>( 153 | stream: &P, 154 | width: i32, 155 | height: i32, 156 | preserve_aspect_ratio: bool, 157 | cancellable: Option<&Q>, 158 | ) -> Result { 159 | unsafe { 160 | let mut error = ptr::null_mut(); 161 | let ret = gdk_pixbuf_sys::gdk_pixbuf_new_from_stream_at_scale( 162 | stream.as_ref().to_glib_none().0, 163 | width, 164 | height, 165 | preserve_aspect_ratio.to_glib(), 166 | cancellable.map(|p| p.as_ref()).to_glib_none().0, 167 | &mut error, 168 | ); 169 | if error.is_null() { 170 | Ok(from_glib_full(ret)) 171 | } else { 172 | Err(from_glib_full(error)) 173 | } 174 | } 175 | } 176 | 177 | pub fn from_xpm_data(data: &[&str]) -> Pixbuf { 178 | unsafe { 179 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_new_from_xpm_data( 180 | data.to_glib_none().0, 181 | )) 182 | } 183 | } 184 | 185 | pub fn add_alpha(&self, substitute_color: bool, r: u8, g: u8, b: u8) -> Option { 186 | unsafe { 187 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_add_alpha( 188 | self.to_glib_none().0, 189 | substitute_color.to_glib(), 190 | r, 191 | g, 192 | b, 193 | )) 194 | } 195 | } 196 | 197 | pub fn apply_embedded_orientation(&self) -> Option { 198 | unsafe { 199 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_apply_embedded_orientation( 200 | self.to_glib_none().0, 201 | )) 202 | } 203 | } 204 | 205 | pub fn composite( 206 | &self, 207 | dest: &Pixbuf, 208 | dest_x: i32, 209 | dest_y: i32, 210 | dest_width: i32, 211 | dest_height: i32, 212 | offset_x: f64, 213 | offset_y: f64, 214 | scale_x: f64, 215 | scale_y: f64, 216 | interp_type: InterpType, 217 | overall_alpha: i32, 218 | ) { 219 | unsafe { 220 | gdk_pixbuf_sys::gdk_pixbuf_composite( 221 | self.to_glib_none().0, 222 | dest.to_glib_none().0, 223 | dest_x, 224 | dest_y, 225 | dest_width, 226 | dest_height, 227 | offset_x, 228 | offset_y, 229 | scale_x, 230 | scale_y, 231 | interp_type.to_glib(), 232 | overall_alpha, 233 | ); 234 | } 235 | } 236 | 237 | pub fn composite_color( 238 | &self, 239 | dest: &Pixbuf, 240 | dest_x: i32, 241 | dest_y: i32, 242 | dest_width: i32, 243 | dest_height: i32, 244 | offset_x: f64, 245 | offset_y: f64, 246 | scale_x: f64, 247 | scale_y: f64, 248 | interp_type: InterpType, 249 | overall_alpha: i32, 250 | check_x: i32, 251 | check_y: i32, 252 | check_size: i32, 253 | color1: u32, 254 | color2: u32, 255 | ) { 256 | unsafe { 257 | gdk_pixbuf_sys::gdk_pixbuf_composite_color( 258 | self.to_glib_none().0, 259 | dest.to_glib_none().0, 260 | dest_x, 261 | dest_y, 262 | dest_width, 263 | dest_height, 264 | offset_x, 265 | offset_y, 266 | scale_x, 267 | scale_y, 268 | interp_type.to_glib(), 269 | overall_alpha, 270 | check_x, 271 | check_y, 272 | check_size, 273 | color1, 274 | color2, 275 | ); 276 | } 277 | } 278 | 279 | pub fn composite_color_simple( 280 | &self, 281 | dest_width: i32, 282 | dest_height: i32, 283 | interp_type: InterpType, 284 | overall_alpha: i32, 285 | check_size: i32, 286 | color1: u32, 287 | color2: u32, 288 | ) -> Option { 289 | unsafe { 290 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_composite_color_simple( 291 | self.to_glib_none().0, 292 | dest_width, 293 | dest_height, 294 | interp_type.to_glib(), 295 | overall_alpha, 296 | check_size, 297 | color1, 298 | color2, 299 | )) 300 | } 301 | } 302 | 303 | pub fn copy(&self) -> Option { 304 | unsafe { from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_copy(self.to_glib_none().0)) } 305 | } 306 | 307 | pub fn copy_area( 308 | &self, 309 | src_x: i32, 310 | src_y: i32, 311 | width: i32, 312 | height: i32, 313 | dest_pixbuf: &Pixbuf, 314 | dest_x: i32, 315 | dest_y: i32, 316 | ) { 317 | unsafe { 318 | gdk_pixbuf_sys::gdk_pixbuf_copy_area( 319 | self.to_glib_none().0, 320 | src_x, 321 | src_y, 322 | width, 323 | height, 324 | dest_pixbuf.to_glib_none().0, 325 | dest_x, 326 | dest_y, 327 | ); 328 | } 329 | } 330 | 331 | #[cfg(any(feature = "v2_36", feature = "dox"))] 332 | pub fn copy_options(&self, dest_pixbuf: &Pixbuf) -> bool { 333 | unsafe { 334 | from_glib(gdk_pixbuf_sys::gdk_pixbuf_copy_options( 335 | self.to_glib_none().0, 336 | dest_pixbuf.to_glib_none().0, 337 | )) 338 | } 339 | } 340 | 341 | pub fn fill(&self, pixel: u32) { 342 | unsafe { 343 | gdk_pixbuf_sys::gdk_pixbuf_fill(self.to_glib_none().0, pixel); 344 | } 345 | } 346 | 347 | pub fn flip(&self, horizontal: bool) -> Option { 348 | unsafe { 349 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_flip( 350 | self.to_glib_none().0, 351 | horizontal.to_glib(), 352 | )) 353 | } 354 | } 355 | 356 | pub fn get_bits_per_sample(&self) -> i32 { 357 | unsafe { gdk_pixbuf_sys::gdk_pixbuf_get_bits_per_sample(self.to_glib_none().0) } 358 | } 359 | 360 | pub fn get_byte_length(&self) -> usize { 361 | unsafe { gdk_pixbuf_sys::gdk_pixbuf_get_byte_length(self.to_glib_none().0) } 362 | } 363 | 364 | pub fn get_colorspace(&self) -> Colorspace { 365 | unsafe { 366 | from_glib(gdk_pixbuf_sys::gdk_pixbuf_get_colorspace( 367 | self.to_glib_none().0, 368 | )) 369 | } 370 | } 371 | 372 | pub fn get_has_alpha(&self) -> bool { 373 | unsafe { 374 | from_glib(gdk_pixbuf_sys::gdk_pixbuf_get_has_alpha( 375 | self.to_glib_none().0, 376 | )) 377 | } 378 | } 379 | 380 | pub fn get_height(&self) -> i32 { 381 | unsafe { gdk_pixbuf_sys::gdk_pixbuf_get_height(self.to_glib_none().0) } 382 | } 383 | 384 | pub fn get_n_channels(&self) -> i32 { 385 | unsafe { gdk_pixbuf_sys::gdk_pixbuf_get_n_channels(self.to_glib_none().0) } 386 | } 387 | 388 | pub fn get_option(&self, key: &str) -> Option { 389 | unsafe { 390 | from_glib_none(gdk_pixbuf_sys::gdk_pixbuf_get_option( 391 | self.to_glib_none().0, 392 | key.to_glib_none().0, 393 | )) 394 | } 395 | } 396 | 397 | //#[cfg(any(feature = "v2_32", feature = "dox"))] 398 | //pub fn get_options(&self) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 } { 399 | // unsafe { TODO: call gdk_pixbuf_sys:gdk_pixbuf_get_options() } 400 | //} 401 | 402 | pub fn get_rowstride(&self) -> i32 { 403 | unsafe { gdk_pixbuf_sys::gdk_pixbuf_get_rowstride(self.to_glib_none().0) } 404 | } 405 | 406 | pub fn get_width(&self) -> i32 { 407 | unsafe { gdk_pixbuf_sys::gdk_pixbuf_get_width(self.to_glib_none().0) } 408 | } 409 | 410 | pub fn new_subpixbuf(&self, src_x: i32, src_y: i32, width: i32, height: i32) -> Option { 411 | unsafe { 412 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_new_subpixbuf( 413 | self.to_glib_none().0, 414 | src_x, 415 | src_y, 416 | width, 417 | height, 418 | )) 419 | } 420 | } 421 | 422 | #[cfg(any(feature = "v2_32", feature = "dox"))] 423 | pub fn read_pixel_bytes(&self) -> Option { 424 | unsafe { 425 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_read_pixel_bytes( 426 | self.to_glib_none().0, 427 | )) 428 | } 429 | } 430 | 431 | #[cfg(any(feature = "v2_36", feature = "dox"))] 432 | pub fn remove_option(&self, key: &str) -> bool { 433 | unsafe { 434 | from_glib(gdk_pixbuf_sys::gdk_pixbuf_remove_option( 435 | self.to_glib_none().0, 436 | key.to_glib_none().0, 437 | )) 438 | } 439 | } 440 | 441 | pub fn rotate_simple(&self, angle: PixbufRotation) -> Option { 442 | unsafe { 443 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_rotate_simple( 444 | self.to_glib_none().0, 445 | angle.to_glib(), 446 | )) 447 | } 448 | } 449 | 450 | pub fn saturate_and_pixelate(&self, dest: &Pixbuf, saturation: f32, pixelate: bool) { 451 | unsafe { 452 | gdk_pixbuf_sys::gdk_pixbuf_saturate_and_pixelate( 453 | self.to_glib_none().0, 454 | dest.to_glib_none().0, 455 | saturation, 456 | pixelate.to_glib(), 457 | ); 458 | } 459 | } 460 | 461 | //pub fn save>(&self, filename: P, type_: &str, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool { 462 | // unsafe { TODO: call gdk_pixbuf_sys:gdk_pixbuf_save() } 463 | //} 464 | 465 | //pub fn save_to_buffer(&self, type_: &str, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Option> { 466 | // unsafe { TODO: call gdk_pixbuf_sys:gdk_pixbuf_save_to_buffer() } 467 | //} 468 | 469 | //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 { 470 | // unsafe { TODO: call gdk_pixbuf_sys:gdk_pixbuf_save_to_callback() } 471 | //} 472 | 473 | //pub fn save_to_callbackv, usize, &glib::Error) -> bool>(&self, save_func: P, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result<(), glib::Error> { 474 | // unsafe { TODO: call gdk_pixbuf_sys:gdk_pixbuf_save_to_callbackv() } 475 | //} 476 | 477 | //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 { 478 | // unsafe { TODO: call gdk_pixbuf_sys:gdk_pixbuf_save_to_stream() } 479 | //} 480 | 481 | //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) { 482 | // unsafe { TODO: call gdk_pixbuf_sys:gdk_pixbuf_save_to_stream_async() } 483 | //} 484 | 485 | // 486 | //pub fn save_to_stream_async_future + Clone + 'static>(&self, stream: &P, type_: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Pin> + 'static>> { 487 | 488 | //let stream = stream.clone(); 489 | //let type_ = String::from(type_); 490 | //Box_::pin(gio::GioFuture::new(self, move |obj, send| { 491 | // let cancellable = gio::Cancellable::new(); 492 | // obj.save_to_stream_async( 493 | // &stream, 494 | // &type_, 495 | // Some(&cancellable), 496 | // , 497 | // move |res| { 498 | // send.resolve(res); 499 | // }, 500 | // ); 501 | 502 | // cancellable 503 | //})) 504 | //} 505 | 506 | pub fn scale( 507 | &self, 508 | dest: &Pixbuf, 509 | dest_x: i32, 510 | dest_y: i32, 511 | dest_width: i32, 512 | dest_height: i32, 513 | offset_x: f64, 514 | offset_y: f64, 515 | scale_x: f64, 516 | scale_y: f64, 517 | interp_type: InterpType, 518 | ) { 519 | unsafe { 520 | gdk_pixbuf_sys::gdk_pixbuf_scale( 521 | self.to_glib_none().0, 522 | dest.to_glib_none().0, 523 | dest_x, 524 | dest_y, 525 | dest_width, 526 | dest_height, 527 | offset_x, 528 | offset_y, 529 | scale_x, 530 | scale_y, 531 | interp_type.to_glib(), 532 | ); 533 | } 534 | } 535 | 536 | pub fn scale_simple( 537 | &self, 538 | dest_width: i32, 539 | dest_height: i32, 540 | interp_type: InterpType, 541 | ) -> Option { 542 | unsafe { 543 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_scale_simple( 544 | self.to_glib_none().0, 545 | dest_width, 546 | dest_height, 547 | interp_type.to_glib(), 548 | )) 549 | } 550 | } 551 | 552 | pub fn set_option(&self, key: &str, value: &str) -> bool { 553 | unsafe { 554 | from_glib(gdk_pixbuf_sys::gdk_pixbuf_set_option( 555 | self.to_glib_none().0, 556 | key.to_glib_none().0, 557 | value.to_glib_none().0, 558 | )) 559 | } 560 | } 561 | 562 | pub fn get_property_pixel_bytes(&self) -> Option { 563 | unsafe { 564 | let mut value = Value::from_type(::static_type()); 565 | gobject_sys::g_object_get_property( 566 | self.as_ptr() as *mut gobject_sys::GObject, 567 | b"pixel-bytes\0".as_ptr() as *const _, 568 | value.to_glib_none_mut().0, 569 | ); 570 | value 571 | .get() 572 | .expect("Return Value for property `pixel-bytes` getter") 573 | } 574 | } 575 | 576 | //pub fn get_property_pixels(&self) -> /*Unimplemented*/Fundamental: Pointer { 577 | // unsafe { 578 | // let mut value = Value::from_type(::static_type()); 579 | // gobject_sys::g_object_get_property(self.as_ptr() as *mut gobject_sys::GObject, b"pixels\0".as_ptr() as *const _, value.to_glib_none_mut().0); 580 | // value.get().expect("Return Value for property `pixels` getter").unwrap() 581 | // } 582 | //} 583 | 584 | #[cfg(any(feature = "v2_36_8", feature = "dox"))] 585 | pub fn calculate_rowstride( 586 | colorspace: Colorspace, 587 | has_alpha: bool, 588 | bits_per_sample: i32, 589 | width: i32, 590 | height: i32, 591 | ) -> i32 { 592 | unsafe { 593 | gdk_pixbuf_sys::gdk_pixbuf_calculate_rowstride( 594 | colorspace.to_glib(), 595 | has_alpha.to_glib(), 596 | bits_per_sample, 597 | width, 598 | height, 599 | ) 600 | } 601 | } 602 | 603 | pub fn get_formats() -> Vec { 604 | unsafe { 605 | FromGlibPtrContainer::from_glib_container(gdk_pixbuf_sys::gdk_pixbuf_get_formats()) 606 | } 607 | } 608 | 609 | #[cfg(any(feature = "v2_40", feature = "dox"))] 610 | pub fn init_modules(path: &str) -> Result<(), glib::Error> { 611 | unsafe { 612 | let mut error = ptr::null_mut(); 613 | let _ = gdk_pixbuf_sys::gdk_pixbuf_init_modules(path.to_glib_none().0, &mut error); 614 | if error.is_null() { 615 | Ok(()) 616 | } else { 617 | Err(from_glib_full(error)) 618 | } 619 | } 620 | } 621 | } 622 | 623 | impl fmt::Display for Pixbuf { 624 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 625 | write!(f, "Pixbuf") 626 | } 627 | } 628 | -------------------------------------------------------------------------------- /src/auto/pixbuf_animation.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gdk_pixbuf_sys; 6 | use gio; 7 | use gio_sys; 8 | use glib; 9 | use glib::object::IsA; 10 | use glib::translate::*; 11 | use glib_sys; 12 | use gobject_sys; 13 | use std; 14 | use std::boxed::Box as Box_; 15 | use std::fmt; 16 | use std::pin::Pin; 17 | use std::ptr; 18 | use Pixbuf; 19 | 20 | glib_wrapper! { 21 | pub struct PixbufAnimation(Object); 22 | 23 | match fn { 24 | get_type => || gdk_pixbuf_sys::gdk_pixbuf_animation_get_type(), 25 | } 26 | } 27 | 28 | impl PixbufAnimation { 29 | pub fn from_file>( 30 | filename: P, 31 | ) -> Result { 32 | unsafe { 33 | let mut error = ptr::null_mut(); 34 | let ret = gdk_pixbuf_sys::gdk_pixbuf_animation_new_from_file( 35 | filename.as_ref().to_glib_none().0, 36 | &mut error, 37 | ); 38 | if error.is_null() { 39 | Ok(from_glib_full(ret)) 40 | } else { 41 | Err(from_glib_full(error)) 42 | } 43 | } 44 | } 45 | 46 | pub fn from_resource(resource_path: &str) -> Result { 47 | unsafe { 48 | let mut error = ptr::null_mut(); 49 | let ret = gdk_pixbuf_sys::gdk_pixbuf_animation_new_from_resource( 50 | resource_path.to_glib_none().0, 51 | &mut error, 52 | ); 53 | if error.is_null() { 54 | Ok(from_glib_full(ret)) 55 | } else { 56 | Err(from_glib_full(error)) 57 | } 58 | } 59 | } 60 | 61 | pub fn from_stream, Q: IsA>( 62 | stream: &P, 63 | cancellable: Option<&Q>, 64 | ) -> Result { 65 | unsafe { 66 | let mut error = ptr::null_mut(); 67 | let ret = gdk_pixbuf_sys::gdk_pixbuf_animation_new_from_stream( 68 | stream.as_ref().to_glib_none().0, 69 | cancellable.map(|p| p.as_ref()).to_glib_none().0, 70 | &mut error, 71 | ); 72 | if error.is_null() { 73 | Ok(from_glib_full(ret)) 74 | } else { 75 | Err(from_glib_full(error)) 76 | } 77 | } 78 | } 79 | 80 | pub fn new_from_stream_async< 81 | P: IsA, 82 | Q: IsA, 83 | R: FnOnce(Result) + Send + 'static, 84 | >( 85 | stream: &P, 86 | cancellable: Option<&Q>, 87 | callback: R, 88 | ) { 89 | let user_data: Box_ = Box_::new(callback); 90 | unsafe extern "C" fn new_from_stream_async_trampoline< 91 | R: FnOnce(Result) + Send + 'static, 92 | >( 93 | _source_object: *mut gobject_sys::GObject, 94 | res: *mut gio_sys::GAsyncResult, 95 | user_data: glib_sys::gpointer, 96 | ) { 97 | let mut error = ptr::null_mut(); 98 | let ret = gdk_pixbuf_sys::gdk_pixbuf_animation_new_from_stream_finish(res, &mut error); 99 | let result = if error.is_null() { 100 | Ok(from_glib_full(ret)) 101 | } else { 102 | Err(from_glib_full(error)) 103 | }; 104 | let callback: Box_ = Box_::from_raw(user_data as *mut _); 105 | callback(result); 106 | } 107 | let callback = new_from_stream_async_trampoline::; 108 | unsafe { 109 | gdk_pixbuf_sys::gdk_pixbuf_animation_new_from_stream_async( 110 | stream.as_ref().to_glib_none().0, 111 | cancellable.map(|p| p.as_ref()).to_glib_none().0, 112 | Some(callback), 113 | Box_::into_raw(user_data) as *mut _, 114 | ); 115 | } 116 | } 117 | 118 | pub fn new_from_stream_async_future + Clone + 'static>( 119 | stream: &P, 120 | ) -> Pin> + 'static>> 121 | { 122 | let stream = stream.clone(); 123 | Box_::pin(gio::GioFuture::new(&(), move |_obj, send| { 124 | let cancellable = gio::Cancellable::new(); 125 | Self::new_from_stream_async(&stream, Some(&cancellable), move |res| { 126 | send.resolve(res); 127 | }); 128 | 129 | cancellable 130 | })) 131 | } 132 | } 133 | 134 | pub const NONE_PIXBUF_ANIMATION: Option<&PixbufAnimation> = None; 135 | 136 | pub trait PixbufAnimationExt: 'static { 137 | fn get_height(&self) -> i32; 138 | 139 | fn get_static_image(&self) -> Option; 140 | 141 | fn get_width(&self) -> i32; 142 | 143 | fn is_static_image(&self) -> bool; 144 | } 145 | 146 | impl> PixbufAnimationExt for O { 147 | fn get_height(&self) -> i32 { 148 | unsafe { gdk_pixbuf_sys::gdk_pixbuf_animation_get_height(self.as_ref().to_glib_none().0) } 149 | } 150 | 151 | fn get_static_image(&self) -> Option { 152 | unsafe { 153 | from_glib_none(gdk_pixbuf_sys::gdk_pixbuf_animation_get_static_image( 154 | self.as_ref().to_glib_none().0, 155 | )) 156 | } 157 | } 158 | 159 | fn get_width(&self) -> i32 { 160 | unsafe { gdk_pixbuf_sys::gdk_pixbuf_animation_get_width(self.as_ref().to_glib_none().0) } 161 | } 162 | 163 | fn is_static_image(&self) -> bool { 164 | unsafe { 165 | from_glib(gdk_pixbuf_sys::gdk_pixbuf_animation_is_static_image( 166 | self.as_ref().to_glib_none().0, 167 | )) 168 | } 169 | } 170 | } 171 | 172 | impl fmt::Display for PixbufAnimation { 173 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 174 | write!(f, "PixbufAnimation") 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /src/auto/pixbuf_format.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gdk_pixbuf_sys; 6 | use glib::translate::*; 7 | use glib::GString; 8 | 9 | glib_wrapper! { 10 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 11 | pub struct PixbufFormat(Boxed); 12 | 13 | match fn { 14 | copy => |ptr| gdk_pixbuf_sys::gdk_pixbuf_format_copy(mut_override(ptr)), 15 | free => |ptr| gdk_pixbuf_sys::gdk_pixbuf_format_free(ptr), 16 | get_type => || gdk_pixbuf_sys::gdk_pixbuf_format_get_type(), 17 | } 18 | } 19 | 20 | impl PixbufFormat { 21 | pub fn get_description(&self) -> Option { 22 | unsafe { 23 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_format_get_description( 24 | mut_override(self.to_glib_none().0), 25 | )) 26 | } 27 | } 28 | 29 | pub fn get_extensions(&self) -> Vec { 30 | unsafe { 31 | FromGlibPtrContainer::from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_format_get_extensions( 32 | mut_override(self.to_glib_none().0), 33 | )) 34 | } 35 | } 36 | 37 | pub fn get_license(&self) -> Option { 38 | unsafe { 39 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_format_get_license(mut_override( 40 | self.to_glib_none().0, 41 | ))) 42 | } 43 | } 44 | 45 | pub fn get_mime_types(&self) -> Vec { 46 | unsafe { 47 | FromGlibPtrContainer::from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_format_get_mime_types( 48 | mut_override(self.to_glib_none().0), 49 | )) 50 | } 51 | } 52 | 53 | pub fn get_name(&self) -> Option { 54 | unsafe { 55 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_format_get_name(mut_override( 56 | self.to_glib_none().0, 57 | ))) 58 | } 59 | } 60 | 61 | pub fn is_disabled(&self) -> bool { 62 | unsafe { 63 | from_glib(gdk_pixbuf_sys::gdk_pixbuf_format_is_disabled(mut_override( 64 | self.to_glib_none().0, 65 | ))) 66 | } 67 | } 68 | 69 | #[cfg(any(feature = "v2_36", feature = "dox"))] 70 | pub fn is_save_option_supported(&self, option_key: &str) -> bool { 71 | unsafe { 72 | from_glib(gdk_pixbuf_sys::gdk_pixbuf_format_is_save_option_supported( 73 | mut_override(self.to_glib_none().0), 74 | option_key.to_glib_none().0, 75 | )) 76 | } 77 | } 78 | 79 | pub fn is_scalable(&self) -> bool { 80 | unsafe { 81 | from_glib(gdk_pixbuf_sys::gdk_pixbuf_format_is_scalable(mut_override( 82 | self.to_glib_none().0, 83 | ))) 84 | } 85 | } 86 | 87 | pub fn is_writable(&self) -> bool { 88 | unsafe { 89 | from_glib(gdk_pixbuf_sys::gdk_pixbuf_format_is_writable(mut_override( 90 | self.to_glib_none().0, 91 | ))) 92 | } 93 | } 94 | 95 | pub fn set_disabled(&mut self, disabled: bool) { 96 | unsafe { 97 | gdk_pixbuf_sys::gdk_pixbuf_format_set_disabled( 98 | self.to_glib_none_mut().0, 99 | disabled.to_glib(), 100 | ); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/auto/pixbuf_loader.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gdk_pixbuf_sys; 6 | use glib; 7 | use glib::object::Cast; 8 | use glib::object::IsA; 9 | use glib::signal::connect_raw; 10 | use glib::signal::SignalHandlerId; 11 | use glib::translate::*; 12 | use glib_sys; 13 | use libc; 14 | use std::boxed::Box as Box_; 15 | use std::fmt; 16 | use std::mem::transmute; 17 | use std::ptr; 18 | use Pixbuf; 19 | use PixbufAnimation; 20 | use PixbufFormat; 21 | 22 | glib_wrapper! { 23 | pub struct PixbufLoader(Object); 24 | 25 | match fn { 26 | get_type => || gdk_pixbuf_sys::gdk_pixbuf_loader_get_type(), 27 | } 28 | } 29 | 30 | impl PixbufLoader { 31 | pub fn new() -> PixbufLoader { 32 | unsafe { from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_loader_new()) } 33 | } 34 | 35 | pub fn with_mime_type(mime_type: &str) -> Result { 36 | unsafe { 37 | let mut error = ptr::null_mut(); 38 | let ret = gdk_pixbuf_sys::gdk_pixbuf_loader_new_with_mime_type( 39 | mime_type.to_glib_none().0, 40 | &mut error, 41 | ); 42 | if error.is_null() { 43 | Ok(from_glib_full(ret)) 44 | } else { 45 | Err(from_glib_full(error)) 46 | } 47 | } 48 | } 49 | 50 | pub fn with_type(image_type: &str) -> Result { 51 | unsafe { 52 | let mut error = ptr::null_mut(); 53 | let ret = gdk_pixbuf_sys::gdk_pixbuf_loader_new_with_type( 54 | image_type.to_glib_none().0, 55 | &mut error, 56 | ); 57 | if error.is_null() { 58 | Ok(from_glib_full(ret)) 59 | } else { 60 | Err(from_glib_full(error)) 61 | } 62 | } 63 | } 64 | } 65 | 66 | impl Default for PixbufLoader { 67 | fn default() -> Self { 68 | Self::new() 69 | } 70 | } 71 | 72 | pub const NONE_PIXBUF_LOADER: Option<&PixbufLoader> = None; 73 | 74 | pub trait PixbufLoaderExt: 'static { 75 | fn close(&self) -> Result<(), glib::Error>; 76 | 77 | fn get_animation(&self) -> Option; 78 | 79 | fn get_format(&self) -> Option; 80 | 81 | fn get_pixbuf(&self) -> Option; 82 | 83 | fn set_size(&self, width: i32, height: i32); 84 | 85 | fn write(&self, buf: &[u8]) -> Result<(), glib::Error>; 86 | 87 | fn write_bytes(&self, buffer: &glib::Bytes) -> Result<(), glib::Error>; 88 | 89 | fn connect_area_prepared(&self, f: F) -> SignalHandlerId; 90 | 91 | fn connect_area_updated( 92 | &self, 93 | f: F, 94 | ) -> SignalHandlerId; 95 | 96 | fn connect_closed(&self, f: F) -> SignalHandlerId; 97 | 98 | fn connect_size_prepared(&self, f: F) -> SignalHandlerId; 99 | } 100 | 101 | impl> PixbufLoaderExt for O { 102 | fn close(&self) -> Result<(), glib::Error> { 103 | unsafe { 104 | let mut error = ptr::null_mut(); 105 | let _ = 106 | gdk_pixbuf_sys::gdk_pixbuf_loader_close(self.as_ref().to_glib_none().0, &mut error); 107 | if error.is_null() { 108 | Ok(()) 109 | } else { 110 | Err(from_glib_full(error)) 111 | } 112 | } 113 | } 114 | 115 | fn get_animation(&self) -> Option { 116 | unsafe { 117 | from_glib_none(gdk_pixbuf_sys::gdk_pixbuf_loader_get_animation( 118 | self.as_ref().to_glib_none().0, 119 | )) 120 | } 121 | } 122 | 123 | fn get_format(&self) -> Option { 124 | unsafe { 125 | from_glib_none(gdk_pixbuf_sys::gdk_pixbuf_loader_get_format( 126 | self.as_ref().to_glib_none().0, 127 | )) 128 | } 129 | } 130 | 131 | fn get_pixbuf(&self) -> Option { 132 | unsafe { 133 | from_glib_none(gdk_pixbuf_sys::gdk_pixbuf_loader_get_pixbuf( 134 | self.as_ref().to_glib_none().0, 135 | )) 136 | } 137 | } 138 | 139 | fn set_size(&self, width: i32, height: i32) { 140 | unsafe { 141 | gdk_pixbuf_sys::gdk_pixbuf_loader_set_size( 142 | self.as_ref().to_glib_none().0, 143 | width, 144 | height, 145 | ); 146 | } 147 | } 148 | 149 | fn write(&self, buf: &[u8]) -> Result<(), glib::Error> { 150 | let count = buf.len() as usize; 151 | unsafe { 152 | let mut error = ptr::null_mut(); 153 | let _ = gdk_pixbuf_sys::gdk_pixbuf_loader_write( 154 | self.as_ref().to_glib_none().0, 155 | buf.to_glib_none().0, 156 | count, 157 | &mut error, 158 | ); 159 | if error.is_null() { 160 | Ok(()) 161 | } else { 162 | Err(from_glib_full(error)) 163 | } 164 | } 165 | } 166 | 167 | fn write_bytes(&self, buffer: &glib::Bytes) -> Result<(), glib::Error> { 168 | unsafe { 169 | let mut error = ptr::null_mut(); 170 | let _ = gdk_pixbuf_sys::gdk_pixbuf_loader_write_bytes( 171 | self.as_ref().to_glib_none().0, 172 | buffer.to_glib_none().0, 173 | &mut error, 174 | ); 175 | if error.is_null() { 176 | Ok(()) 177 | } else { 178 | Err(from_glib_full(error)) 179 | } 180 | } 181 | } 182 | 183 | fn connect_area_prepared(&self, f: F) -> SignalHandlerId { 184 | unsafe extern "C" fn area_prepared_trampoline( 185 | this: *mut gdk_pixbuf_sys::GdkPixbufLoader, 186 | f: glib_sys::gpointer, 187 | ) where 188 | P: IsA, 189 | { 190 | let f: &F = &*(f as *const F); 191 | f(&PixbufLoader::from_glib_borrow(this).unsafe_cast_ref()) 192 | } 193 | unsafe { 194 | let f: Box_ = Box_::new(f); 195 | connect_raw( 196 | self.as_ptr() as *mut _, 197 | b"area-prepared\0".as_ptr() as *const _, 198 | Some(transmute::<_, unsafe extern "C" fn()>( 199 | area_prepared_trampoline:: as *const (), 200 | )), 201 | Box_::into_raw(f), 202 | ) 203 | } 204 | } 205 | 206 | fn connect_area_updated( 207 | &self, 208 | f: F, 209 | ) -> SignalHandlerId { 210 | unsafe extern "C" fn area_updated_trampoline( 211 | this: *mut gdk_pixbuf_sys::GdkPixbufLoader, 212 | x: libc::c_int, 213 | y: libc::c_int, 214 | width: libc::c_int, 215 | height: libc::c_int, 216 | f: glib_sys::gpointer, 217 | ) where 218 | P: IsA, 219 | { 220 | let f: &F = &*(f as *const F); 221 | f( 222 | &PixbufLoader::from_glib_borrow(this).unsafe_cast_ref(), 223 | x, 224 | y, 225 | width, 226 | height, 227 | ) 228 | } 229 | unsafe { 230 | let f: Box_ = Box_::new(f); 231 | connect_raw( 232 | self.as_ptr() as *mut _, 233 | b"area-updated\0".as_ptr() as *const _, 234 | Some(transmute::<_, unsafe extern "C" fn()>( 235 | area_updated_trampoline:: as *const (), 236 | )), 237 | Box_::into_raw(f), 238 | ) 239 | } 240 | } 241 | 242 | fn connect_closed(&self, f: F) -> SignalHandlerId { 243 | unsafe extern "C" fn closed_trampoline( 244 | this: *mut gdk_pixbuf_sys::GdkPixbufLoader, 245 | f: glib_sys::gpointer, 246 | ) where 247 | P: IsA, 248 | { 249 | let f: &F = &*(f as *const F); 250 | f(&PixbufLoader::from_glib_borrow(this).unsafe_cast_ref()) 251 | } 252 | unsafe { 253 | let f: Box_ = Box_::new(f); 254 | connect_raw( 255 | self.as_ptr() as *mut _, 256 | b"closed\0".as_ptr() as *const _, 257 | Some(transmute::<_, unsafe extern "C" fn()>( 258 | closed_trampoline:: as *const (), 259 | )), 260 | Box_::into_raw(f), 261 | ) 262 | } 263 | } 264 | 265 | fn connect_size_prepared(&self, f: F) -> SignalHandlerId { 266 | unsafe extern "C" fn size_prepared_trampoline( 267 | this: *mut gdk_pixbuf_sys::GdkPixbufLoader, 268 | width: libc::c_int, 269 | height: libc::c_int, 270 | f: glib_sys::gpointer, 271 | ) where 272 | P: IsA, 273 | { 274 | let f: &F = &*(f as *const F); 275 | f( 276 | &PixbufLoader::from_glib_borrow(this).unsafe_cast_ref(), 277 | width, 278 | height, 279 | ) 280 | } 281 | unsafe { 282 | let f: Box_ = Box_::new(f); 283 | connect_raw( 284 | self.as_ptr() as *mut _, 285 | b"size-prepared\0".as_ptr() as *const _, 286 | Some(transmute::<_, unsafe extern "C" fn()>( 287 | size_prepared_trampoline:: as *const (), 288 | )), 289 | Box_::into_raw(f), 290 | ) 291 | } 292 | } 293 | } 294 | 295 | impl fmt::Display for PixbufLoader { 296 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 297 | write!(f, "PixbufLoader") 298 | } 299 | } 300 | -------------------------------------------------------------------------------- /src/auto/pixbuf_simple_anim.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gdk_pixbuf_sys; 6 | use glib::object::ObjectType as ObjectType_; 7 | use glib::signal::connect_raw; 8 | use glib::signal::SignalHandlerId; 9 | use glib::translate::*; 10 | use glib_sys; 11 | use std::boxed::Box as Box_; 12 | use std::fmt; 13 | use std::mem::transmute; 14 | use Pixbuf; 15 | use PixbufAnimation; 16 | 17 | glib_wrapper! { 18 | pub struct PixbufSimpleAnim(Object) @extends PixbufAnimation; 19 | 20 | match fn { 21 | get_type => || gdk_pixbuf_sys::gdk_pixbuf_simple_anim_get_type(), 22 | } 23 | } 24 | 25 | impl PixbufSimpleAnim { 26 | pub fn new(width: i32, height: i32, rate: f32) -> PixbufSimpleAnim { 27 | unsafe { 28 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_simple_anim_new( 29 | width, height, rate, 30 | )) 31 | } 32 | } 33 | 34 | pub fn add_frame(&self, pixbuf: &Pixbuf) { 35 | unsafe { 36 | gdk_pixbuf_sys::gdk_pixbuf_simple_anim_add_frame( 37 | self.to_glib_none().0, 38 | pixbuf.to_glib_none().0, 39 | ); 40 | } 41 | } 42 | 43 | pub fn get_loop(&self) -> bool { 44 | unsafe { 45 | from_glib(gdk_pixbuf_sys::gdk_pixbuf_simple_anim_get_loop( 46 | self.to_glib_none().0, 47 | )) 48 | } 49 | } 50 | 51 | pub fn set_loop(&self, loop_: bool) { 52 | unsafe { 53 | gdk_pixbuf_sys::gdk_pixbuf_simple_anim_set_loop(self.to_glib_none().0, loop_.to_glib()); 54 | } 55 | } 56 | 57 | pub fn connect_property_loop_notify( 58 | &self, 59 | f: F, 60 | ) -> SignalHandlerId { 61 | unsafe extern "C" fn notify_loop_trampoline( 62 | this: *mut gdk_pixbuf_sys::GdkPixbufSimpleAnim, 63 | _param_spec: glib_sys::gpointer, 64 | f: glib_sys::gpointer, 65 | ) { 66 | let f: &F = &*(f as *const F); 67 | f(&from_glib_borrow(this)) 68 | } 69 | unsafe { 70 | let f: Box_ = Box_::new(f); 71 | connect_raw( 72 | self.as_ptr() as *mut _, 73 | b"notify::loop\0".as_ptr() as *const _, 74 | Some(transmute::<_, unsafe extern "C" fn()>( 75 | notify_loop_trampoline:: as *const (), 76 | )), 77 | Box_::into_raw(f), 78 | ) 79 | } 80 | } 81 | } 82 | 83 | impl fmt::Display for PixbufSimpleAnim { 84 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 85 | write!(f, "PixbufSimpleAnim") 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/auto/versions.txt: -------------------------------------------------------------------------------- 1 | Generated by gir (https://github.com/gtk-rs/gir @ ad40c01) 2 | from gir-files (https://github.com/gtk-rs/gir-files @ cb01ad7) 3 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2016, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | #![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] 6 | #![cfg_attr(feature = "cargo-clippy", allow(type_complexity))] 7 | 8 | extern crate gdk_pixbuf_sys; 9 | extern crate gio_sys; 10 | extern crate glib_sys; 11 | extern crate gobject_sys; 12 | #[macro_use] 13 | extern crate glib; 14 | extern crate gio; 15 | extern crate libc; 16 | 17 | mod auto; 18 | 19 | mod pixbuf; 20 | mod pixbuf_animation; 21 | mod pixbuf_animation_iter; 22 | pub mod prelude; 23 | 24 | pub use auto::*; 25 | 26 | pub use self::pixbuf_animation_iter::PixbufAnimationIter; 27 | -------------------------------------------------------------------------------- /src/pixbuf.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2016, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use gdk_pixbuf_sys; 6 | use gio; 7 | use gio_sys; 8 | use glib::object::IsA; 9 | use glib::translate::*; 10 | use glib::Error; 11 | use glib_sys; 12 | use gobject_sys; 13 | use libc::{c_uchar, c_void}; 14 | use std::io::Read; 15 | use std::mem; 16 | use std::path::Path; 17 | use std::pin::Pin; 18 | use std::ptr; 19 | use std::slice; 20 | 21 | use std::future::Future; 22 | 23 | use {Colorspace, Pixbuf, PixbufFormat}; 24 | 25 | impl Pixbuf { 26 | pub fn from_mut_slice>( 27 | data: T, 28 | colorspace: Colorspace, 29 | has_alpha: bool, 30 | bits_per_sample: i32, 31 | width: i32, 32 | height: i32, 33 | row_stride: i32, 34 | ) -> Pixbuf { 35 | unsafe extern "C" fn destroy>(_: *mut c_uchar, data: *mut c_void) { 36 | let _data: Box = Box::from_raw(data as *mut T); // the data will be destroyed now 37 | } 38 | assert!(width > 0, "width must be greater than 0"); 39 | assert!(height > 0, "height must be greater than 0"); 40 | assert!(row_stride > 0, "row_stride must be greater than 0"); 41 | assert!( 42 | bits_per_sample == 8, 43 | "bits_per_sample == 8 is the only supported value" 44 | ); 45 | 46 | let width = width as usize; 47 | let height = height as usize; 48 | let row_stride = row_stride as usize; 49 | let bits_per_sample = bits_per_sample as usize; 50 | 51 | let n_channels = if has_alpha { 4 } else { 3 }; 52 | let last_row_len = width * ((n_channels * bits_per_sample + 7) / 8); 53 | 54 | let mut data: Box = Box::new(data); 55 | 56 | let ptr = { 57 | let data: &mut [u8] = (*data).as_mut(); 58 | assert!( 59 | data.len() >= ((height - 1) * row_stride + last_row_len) as usize, 60 | "data.len() must fit the width, height, and row_stride" 61 | ); 62 | data.as_mut_ptr() 63 | }; 64 | 65 | unsafe { 66 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_new_from_data( 67 | ptr, 68 | colorspace.to_glib(), 69 | has_alpha.to_glib(), 70 | bits_per_sample as i32, 71 | width as i32, 72 | height as i32, 73 | row_stride as i32, 74 | Some(destroy::), 75 | Box::into_raw(data) as *mut _, 76 | )) 77 | } 78 | } 79 | 80 | // rustdoc-stripper-ignore-next 81 | /// Creates a `Pixbuf` from a type implementing `Read` (like `File`). 82 | /// 83 | /// ```no_run 84 | /// use std::fs::File; 85 | /// use gdk_pixbuf::Pixbuf; 86 | /// 87 | /// let f = File::open("some_file.png").expect("failed to open image"); 88 | /// let pixbuf = Pixbuf::from_read(f).expect("failed to load image"); 89 | /// ``` 90 | pub fn from_read(r: R) -> Result { 91 | Pixbuf::from_stream(&gio::ReadInputStream::new(r), None::<&gio::Cancellable>) 92 | } 93 | 94 | pub fn from_file>(filename: T) -> Result { 95 | #[cfg(not(windows))] 96 | use gdk_pixbuf_sys::gdk_pixbuf_new_from_file; 97 | #[cfg(windows)] 98 | use gdk_pixbuf_sys::gdk_pixbuf_new_from_file_utf8 as gdk_pixbuf_new_from_file; 99 | 100 | unsafe { 101 | let mut error = ptr::null_mut(); 102 | let ptr = gdk_pixbuf_new_from_file(filename.as_ref().to_glib_none().0, &mut error); 103 | if error.is_null() { 104 | Ok(from_glib_full(ptr)) 105 | } else { 106 | Err(from_glib_full(error)) 107 | } 108 | } 109 | } 110 | 111 | pub fn from_file_at_size>( 112 | filename: T, 113 | width: i32, 114 | height: i32, 115 | ) -> Result { 116 | #[cfg(not(windows))] 117 | use gdk_pixbuf_sys::gdk_pixbuf_new_from_file_at_size; 118 | #[cfg(windows)] 119 | use gdk_pixbuf_sys::gdk_pixbuf_new_from_file_at_size_utf8 as gdk_pixbuf_new_from_file_at_size; 120 | 121 | unsafe { 122 | let mut error = ptr::null_mut(); 123 | let ptr = gdk_pixbuf_new_from_file_at_size( 124 | filename.as_ref().to_glib_none().0, 125 | width, 126 | height, 127 | &mut error, 128 | ); 129 | if error.is_null() { 130 | Ok(from_glib_full(ptr)) 131 | } else { 132 | Err(from_glib_full(error)) 133 | } 134 | } 135 | } 136 | 137 | pub fn from_file_at_scale>( 138 | filename: T, 139 | width: i32, 140 | height: i32, 141 | preserve_aspect_ratio: bool, 142 | ) -> Result { 143 | #[cfg(not(windows))] 144 | use gdk_pixbuf_sys::gdk_pixbuf_new_from_file_at_scale; 145 | #[cfg(windows)] 146 | use gdk_pixbuf_sys::gdk_pixbuf_new_from_file_at_scale_utf8 as gdk_pixbuf_new_from_file_at_scale; 147 | 148 | unsafe { 149 | let mut error = ptr::null_mut(); 150 | let ptr = gdk_pixbuf_new_from_file_at_scale( 151 | filename.as_ref().to_glib_none().0, 152 | width, 153 | height, 154 | preserve_aspect_ratio.to_glib(), 155 | &mut error, 156 | ); 157 | if error.is_null() { 158 | Ok(from_glib_full(ptr)) 159 | } else { 160 | Err(from_glib_full(error)) 161 | } 162 | } 163 | } 164 | 165 | pub fn from_stream_async< 166 | 'a, 167 | P: IsA, 168 | Q: IsA, 169 | R: FnOnce(Result) + Send + 'static, 170 | >( 171 | stream: &P, 172 | cancellable: Option<&Q>, 173 | callback: R, 174 | ) { 175 | let cancellable = cancellable.map(|p| p.as_ref()); 176 | let user_data: Box = Box::new(callback); 177 | unsafe extern "C" fn from_stream_async_trampoline< 178 | R: FnOnce(Result) + Send + 'static, 179 | >( 180 | _source_object: *mut gobject_sys::GObject, 181 | res: *mut gio_sys::GAsyncResult, 182 | user_data: glib_sys::gpointer, 183 | ) { 184 | let mut error = ptr::null_mut(); 185 | let ptr = gdk_pixbuf_sys::gdk_pixbuf_new_from_stream_finish(res, &mut error); 186 | let result = if error.is_null() { 187 | Ok(from_glib_full(ptr)) 188 | } else { 189 | Err(from_glib_full(error)) 190 | }; 191 | let callback: Box = Box::from_raw(user_data as *mut _); 192 | callback(result); 193 | } 194 | let callback = from_stream_async_trampoline::; 195 | unsafe { 196 | gdk_pixbuf_sys::gdk_pixbuf_new_from_stream_async( 197 | stream.as_ref().to_glib_none().0, 198 | cancellable.to_glib_none().0, 199 | Some(callback), 200 | Box::into_raw(user_data) as *mut _, 201 | ); 202 | } 203 | } 204 | 205 | pub fn from_stream_async_future + Clone + 'static>( 206 | stream: &P, 207 | ) -> Pin> + 'static>> { 208 | let stream = stream.clone(); 209 | Box::pin(gio::GioFuture::new(&(), move |_obj, send| { 210 | let cancellable = gio::Cancellable::new(); 211 | Self::from_stream_async(&stream, Some(&cancellable), move |res| { 212 | send.resolve(res); 213 | }); 214 | 215 | cancellable 216 | })) 217 | } 218 | 219 | pub fn from_stream_at_scale_async< 220 | 'a, 221 | P: IsA, 222 | Q: IsA, 223 | R: FnOnce(Result) + Send + 'static, 224 | >( 225 | stream: &P, 226 | width: i32, 227 | height: i32, 228 | preserve_aspect_ratio: bool, 229 | cancellable: Option<&Q>, 230 | callback: R, 231 | ) { 232 | let cancellable = cancellable.map(|p| p.as_ref()); 233 | let user_data: Box = Box::new(callback); 234 | unsafe extern "C" fn from_stream_at_scale_async_trampoline< 235 | R: FnOnce(Result) + Send + 'static, 236 | >( 237 | _source_object: *mut gobject_sys::GObject, 238 | res: *mut gio_sys::GAsyncResult, 239 | user_data: glib_sys::gpointer, 240 | ) { 241 | let mut error = ptr::null_mut(); 242 | let ptr = gdk_pixbuf_sys::gdk_pixbuf_new_from_stream_finish(res, &mut error); 243 | let result = if error.is_null() { 244 | Ok(from_glib_full(ptr)) 245 | } else { 246 | Err(from_glib_full(error)) 247 | }; 248 | let callback: Box = Box::from_raw(user_data as *mut _); 249 | callback(result); 250 | } 251 | let callback = from_stream_at_scale_async_trampoline::; 252 | unsafe { 253 | gdk_pixbuf_sys::gdk_pixbuf_new_from_stream_at_scale_async( 254 | stream.as_ref().to_glib_none().0, 255 | width, 256 | height, 257 | preserve_aspect_ratio.to_glib(), 258 | cancellable.to_glib_none().0, 259 | Some(callback), 260 | Box::into_raw(user_data) as *mut _, 261 | ); 262 | } 263 | } 264 | 265 | pub fn from_stream_at_scale_async_future + Clone + 'static>( 266 | stream: &P, 267 | width: i32, 268 | height: i32, 269 | preserve_aspect_ratio: bool, 270 | ) -> Pin> + 'static>> { 271 | let stream = stream.clone(); 272 | Box::pin(gio::GioFuture::new(&(), move |_obj, send| { 273 | let cancellable = gio::Cancellable::new(); 274 | Self::from_stream_at_scale_async( 275 | &stream, 276 | width, 277 | height, 278 | preserve_aspect_ratio, 279 | Some(&cancellable), 280 | move |res| { 281 | send.resolve(res); 282 | }, 283 | ); 284 | 285 | cancellable 286 | })) 287 | } 288 | 289 | #[cfg_attr(feature = "cargo-clippy", allow(mut_from_ref))] 290 | pub unsafe fn get_pixels(&self) -> &mut [u8] { 291 | let mut len = 0; 292 | let ptr = 293 | gdk_pixbuf_sys::gdk_pixbuf_get_pixels_with_length(self.to_glib_none().0, &mut len); 294 | slice::from_raw_parts_mut(ptr, len as usize) 295 | } 296 | 297 | pub fn put_pixel(&self, x: u32, y: u32, red: u8, green: u8, blue: u8, alpha: u8) { 298 | assert!( 299 | x < self.get_width() as u32, 300 | "x must be less than the pixbuf's width" 301 | ); 302 | assert!( 303 | y < self.get_height() as u32, 304 | "y must be less than the pixbuf's height" 305 | ); 306 | 307 | unsafe { 308 | let x = x as usize; 309 | let y = y as usize; 310 | let n_channels = self.get_n_channels() as usize; 311 | assert!(n_channels == 3 || n_channels == 4); 312 | let rowstride = self.get_rowstride() as usize; 313 | let pixels = self.get_pixels(); 314 | let pos = y * rowstride + x * n_channels; 315 | 316 | pixels[pos] = red; 317 | pixels[pos + 1] = green; 318 | pixels[pos + 2] = blue; 319 | if n_channels == 4 { 320 | pixels[pos + 3] = alpha; 321 | } 322 | } 323 | } 324 | 325 | pub fn get_file_info>(filename: T) -> Option<(PixbufFormat, i32, i32)> { 326 | unsafe { 327 | let mut width = mem::MaybeUninit::uninit(); 328 | let mut height = mem::MaybeUninit::uninit(); 329 | let ret = gdk_pixbuf_sys::gdk_pixbuf_get_file_info( 330 | filename.as_ref().to_glib_none().0, 331 | width.as_mut_ptr(), 332 | height.as_mut_ptr(), 333 | ); 334 | if !ret.is_null() { 335 | Some(( 336 | from_glib_none(ret), 337 | width.assume_init(), 338 | height.assume_init(), 339 | )) 340 | } else { 341 | None 342 | } 343 | } 344 | } 345 | 346 | #[cfg(any(feature = "v2_32", feature = "dox"))] 347 | pub fn get_file_info_async< 348 | P: IsA, 349 | Q: FnOnce(Result, Error>) + Send + 'static, 350 | T: AsRef, 351 | >( 352 | filename: T, 353 | cancellable: Option<&P>, 354 | callback: Q, 355 | ) { 356 | let cancellable = cancellable.map(|p| p.as_ref()); 357 | let user_data: Box = Box::new(callback); 358 | unsafe extern "C" fn get_file_info_async_trampoline< 359 | Q: FnOnce(Result, Error>) + Send + 'static, 360 | >( 361 | _source_object: *mut gobject_sys::GObject, 362 | res: *mut gio_sys::GAsyncResult, 363 | user_data: glib_sys::gpointer, 364 | ) { 365 | let mut error = ptr::null_mut(); 366 | let mut width = mem::MaybeUninit::uninit(); 367 | let mut height = mem::MaybeUninit::uninit(); 368 | let ret = gdk_pixbuf_sys::gdk_pixbuf_get_file_info_finish( 369 | res, 370 | width.as_mut_ptr(), 371 | height.as_mut_ptr(), 372 | &mut error, 373 | ); 374 | let result = if !error.is_null() { 375 | Err(from_glib_full(error)) 376 | } else if ret.is_null() { 377 | Ok(None) 378 | } else { 379 | Ok(Some(( 380 | from_glib_none(ret), 381 | width.assume_init(), 382 | height.assume_init(), 383 | ))) 384 | }; 385 | let callback: Box = Box::from_raw(user_data as *mut _); 386 | callback(result); 387 | } 388 | let callback = get_file_info_async_trampoline::; 389 | unsafe { 390 | gdk_pixbuf_sys::gdk_pixbuf_get_file_info_async( 391 | filename.as_ref().to_glib_none().0, 392 | cancellable.to_glib_none().0, 393 | Some(callback), 394 | Box::into_raw(user_data) as *mut _, 395 | ); 396 | } 397 | } 398 | 399 | #[cfg(any(feature = "v2_32", feature = "dox"))] 400 | pub fn get_file_info_async_future + Clone + 'static>( 401 | filename: T, 402 | ) -> Pin, Error>> + 'static>> 403 | { 404 | Box::pin(gio::GioFuture::new(&(), move |_obj, send| { 405 | let cancellable = gio::Cancellable::new(); 406 | Self::get_file_info_async(filename, Some(&cancellable), move |res| { 407 | send.resolve(res); 408 | }); 409 | 410 | cancellable 411 | })) 412 | } 413 | 414 | pub fn save_to_bufferv(&self, type_: &str, options: &[(&str, &str)]) -> Result, Error> { 415 | unsafe { 416 | let mut buffer = ptr::null_mut(); 417 | let mut buffer_size = mem::MaybeUninit::uninit(); 418 | let mut error = ptr::null_mut(); 419 | let option_keys: Vec<&str> = options.iter().map(|o| o.0).collect(); 420 | let option_values: Vec<&str> = options.iter().map(|o| o.1).collect(); 421 | let _ = gdk_pixbuf_sys::gdk_pixbuf_save_to_bufferv( 422 | self.to_glib_none().0, 423 | &mut buffer, 424 | buffer_size.as_mut_ptr(), 425 | type_.to_glib_none().0, 426 | option_keys.to_glib_none().0, 427 | option_values.to_glib_none().0, 428 | &mut error, 429 | ); 430 | if error.is_null() { 431 | Ok(FromGlibContainer::from_glib_full_num( 432 | buffer, 433 | buffer_size.assume_init() as usize, 434 | )) 435 | } else { 436 | Err(from_glib_full(error)) 437 | } 438 | } 439 | } 440 | 441 | #[cfg(any(feature = "v2_36", feature = "dox"))] 442 | pub fn save_to_streamv<'a, P: IsA, Q: IsA>( 443 | &self, 444 | stream: &P, 445 | type_: &str, 446 | options: &[(&str, &str)], 447 | cancellable: Option<&Q>, 448 | ) -> Result<(), Error> { 449 | let cancellable = cancellable.map(|p| p.as_ref()); 450 | unsafe { 451 | let mut error = ptr::null_mut(); 452 | let option_keys: Vec<&str> = options.iter().map(|o| o.0).collect(); 453 | let option_values: Vec<&str> = options.iter().map(|o| o.1).collect(); 454 | let _ = gdk_pixbuf_sys::gdk_pixbuf_save_to_streamv( 455 | self.to_glib_none().0, 456 | stream.as_ref().to_glib_none().0, 457 | type_.to_glib_none().0, 458 | option_keys.to_glib_none().0, 459 | option_values.to_glib_none().0, 460 | cancellable.to_glib_none().0, 461 | &mut error, 462 | ); 463 | if error.is_null() { 464 | Ok(()) 465 | } else { 466 | Err(from_glib_full(error)) 467 | } 468 | } 469 | } 470 | 471 | #[cfg(any(feature = "v2_36", feature = "dox"))] 472 | pub fn save_to_streamv_async< 473 | 'a, 474 | P: IsA, 475 | Q: IsA, 476 | R: FnOnce(Result<(), Error>) + Send + 'static, 477 | >( 478 | &self, 479 | stream: &P, 480 | type_: &str, 481 | options: &[(&str, &str)], 482 | cancellable: Option<&Q>, 483 | callback: R, 484 | ) { 485 | let cancellable = cancellable.map(|p| p.as_ref()); 486 | let user_data: Box = Box::new(callback); 487 | unsafe extern "C" fn save_to_streamv_async_trampoline< 488 | R: FnOnce(Result<(), Error>) + Send + 'static, 489 | >( 490 | _source_object: *mut gobject_sys::GObject, 491 | res: *mut gio_sys::GAsyncResult, 492 | user_data: glib_sys::gpointer, 493 | ) { 494 | let mut error = ptr::null_mut(); 495 | let _ = gdk_pixbuf_sys::gdk_pixbuf_save_to_stream_finish(res, &mut error); 496 | let result = if error.is_null() { 497 | Ok(()) 498 | } else { 499 | Err(from_glib_full(error)) 500 | }; 501 | let callback: Box = Box::from_raw(user_data as *mut _); 502 | callback(result); 503 | } 504 | let callback = save_to_streamv_async_trampoline::; 505 | unsafe { 506 | let option_keys: Vec<&str> = options.iter().map(|o| o.0).collect(); 507 | let option_values: Vec<&str> = options.iter().map(|o| o.1).collect(); 508 | gdk_pixbuf_sys::gdk_pixbuf_save_to_streamv_async( 509 | self.to_glib_none().0, 510 | stream.as_ref().to_glib_none().0, 511 | type_.to_glib_none().0, 512 | option_keys.to_glib_none().0, 513 | option_values.to_glib_none().0, 514 | cancellable.to_glib_none().0, 515 | Some(callback), 516 | Box::into_raw(user_data) as *mut _, 517 | ); 518 | } 519 | } 520 | 521 | #[cfg(any(feature = "v2_36", feature = "dox"))] 522 | pub fn save_to_streamv_async_future + Clone + 'static>( 523 | &self, 524 | stream: &P, 525 | type_: &str, 526 | options: &[(&str, &str)], 527 | ) -> Pin> + 'static>> { 528 | let stream = stream.clone(); 529 | let type_ = String::from(type_); 530 | let options = options 531 | .iter() 532 | .map(|&(k, v)| (String::from(k), String::from(v))) 533 | .collect::>(); 534 | Box::pin(gio::GioFuture::new(self, move |obj, send| { 535 | let cancellable = gio::Cancellable::new(); 536 | let options = options 537 | .iter() 538 | .map(|&(ref k, ref v)| (k.as_str(), v.as_str())) 539 | .collect::>(); 540 | 541 | obj.save_to_streamv_async( 542 | &stream, 543 | &type_, 544 | options.as_slice(), 545 | Some(&cancellable), 546 | move |res| { 547 | send.resolve(res); 548 | }, 549 | ); 550 | 551 | cancellable 552 | })) 553 | } 554 | 555 | pub fn savev>( 556 | &self, 557 | filename: T, 558 | type_: &str, 559 | options: &[(&str, &str)], 560 | ) -> Result<(), Error> { 561 | unsafe { 562 | let mut error = ptr::null_mut(); 563 | let option_keys: Vec<&str> = options.iter().map(|o| o.0).collect(); 564 | let option_values: Vec<&str> = options.iter().map(|o| o.1).collect(); 565 | let _ = gdk_pixbuf_sys::gdk_pixbuf_savev( 566 | self.to_glib_none().0, 567 | filename.as_ref().to_glib_none().0, 568 | type_.to_glib_none().0, 569 | option_keys.to_glib_none().0, 570 | option_values.to_glib_none().0, 571 | &mut error, 572 | ); 573 | if error.is_null() { 574 | Ok(()) 575 | } else { 576 | Err(from_glib_full(error)) 577 | } 578 | } 579 | } 580 | } 581 | -------------------------------------------------------------------------------- /src/pixbuf_animation.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2020, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use glib::object::IsA; 6 | use glib::translate::*; 7 | use PixbufAnimation; 8 | use PixbufAnimationIter; 9 | 10 | use std::ptr; 11 | use std::time::SystemTime; 12 | 13 | pub trait PixbufAnimationExtManual { 14 | fn get_iter(&self, start_time: Option) -> PixbufAnimationIter; 15 | } 16 | 17 | impl> PixbufAnimationExtManual for T { 18 | fn get_iter(&self, start_time: Option) -> PixbufAnimationIter { 19 | let start_time = start_time.map(|s| { 20 | let diff = s 21 | .duration_since(SystemTime::UNIX_EPOCH) 22 | .expect("failed to convert time"); 23 | glib_sys::GTimeVal { 24 | tv_sec: diff.as_secs() as _, 25 | tv_usec: diff.subsec_micros() as _, 26 | } 27 | }); 28 | 29 | unsafe { 30 | from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_animation_get_iter( 31 | self.as_ref().to_glib_none().0, 32 | start_time 33 | .as_ref() 34 | .map(|t| t as *const glib_sys::GTimeVal) 35 | .unwrap_or(ptr::null()), 36 | )) 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/pixbuf_animation_iter.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2020, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use super::Pixbuf; 6 | use gdk_pixbuf_sys; 7 | use glib::translate::*; 8 | 9 | use std::time::SystemTime; 10 | 11 | glib_wrapper! { 12 | pub struct PixbufAnimationIter(Object); 13 | 14 | match fn { 15 | get_type => || gdk_pixbuf_sys::gdk_pixbuf_animation_iter_get_type(), 16 | } 17 | } 18 | 19 | impl PixbufAnimationIter { 20 | pub fn advance(&self, start_time: SystemTime) -> bool { 21 | let diff = start_time 22 | .duration_since(SystemTime::UNIX_EPOCH) 23 | .expect("failed to convert time"); 24 | 25 | unsafe { 26 | from_glib(gdk_pixbuf_sys::gdk_pixbuf_animation_iter_advance( 27 | self.to_glib_none().0, 28 | &glib_sys::GTimeVal { 29 | tv_sec: diff.as_secs() as _, 30 | tv_usec: diff.subsec_micros() as _, 31 | }, 32 | )) 33 | } 34 | } 35 | 36 | pub fn get_pixbuf(&self) -> Pixbuf { 37 | unsafe { 38 | from_glib_none(gdk_pixbuf_sys::gdk_pixbuf_animation_iter_get_pixbuf( 39 | self.to_glib_none().0, 40 | )) 41 | } 42 | } 43 | 44 | pub fn get_delay_time(&self) -> i32 { 45 | unsafe { gdk_pixbuf_sys::gdk_pixbuf_animation_iter_get_delay_time(self.to_glib_none().0) } 46 | } 47 | 48 | pub fn on_currently_loading_frame(&self) -> bool { 49 | unsafe { 50 | from_glib( 51 | gdk_pixbuf_sys::gdk_pixbuf_animation_iter_on_currently_loading_frame( 52 | self.to_glib_none().0, 53 | ), 54 | ) 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/prelude.rs: -------------------------------------------------------------------------------- 1 | //! Traits inteded for blanket imports. 2 | 3 | pub use auto::traits::*; 4 | #[doc(hidden)] 5 | pub use glib::prelude::*; 6 | pub use pixbuf_animation::PixbufAnimationExtManual; 7 | -------------------------------------------------------------------------------- /tests/check_gir.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2018, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | extern crate gir_format_check; 6 | 7 | #[test] 8 | fn check_gir_file() { 9 | let res = gir_format_check::check_gir_file("Gir.toml"); 10 | println!("{}", res.to_string()); 11 | assert_eq!(res.nb_errors, 0); 12 | } 13 | -------------------------------------------------------------------------------- /tests/overflow.rs: -------------------------------------------------------------------------------- 1 | extern crate gdk_pixbuf; 2 | use gdk_pixbuf::*; 3 | 4 | #[test] 5 | #[cfg(target_pointer_width = "64")] 6 | fn put_pixel_doesnt_overflow() { 7 | // Only test this on 64-bit boxes; otherwise we can't even 8 | // allocate a pixbuf this big. 9 | 10 | let pixbuf = Pixbuf::new(Colorspace::Rgb, true, 8, 21000, 29700).unwrap(); 11 | 12 | // debug build: thread 'put_pixel_doesnt_overflow' panicked at 13 | // 'attempt to multiply with overflow', src/pixbuf.rs:274:24 14 | // 15 | // release build: thread 'put_pixel_doesnt_overflow' panicked at 16 | // 'index out of bounds: the len is 2494800000 but the index is 17 | // 18446744071598664320', src/pixbuf.rs:276:13 18 | 19 | pixbuf.put_pixel(20000, 26000, 255, 255, 255, 255); 20 | } 21 | 22 | #[test] 23 | #[cfg(target_pointer_width = "64")] 24 | fn new_from_mut_slice_doesnt_overflow() { 25 | // Only test this on 64-bit boxes; otherwise we can't even 26 | // allocate a pixbuf this big. 27 | 28 | // Plus 5 to test that new_from_mut_slice() can ignore trailing data past the last row 29 | let data = vec![0u8; 21000 * 4 * 29700 + 5]; 30 | 31 | // debug build: thread 'new_from_mut_slice_doesnt_overflow' 32 | // panicked at 'attempt to multiply with overflow', 33 | // /home/federico/src/gtk-rs/gdk-pixbuf/src/pixbuf.rs:50:36 34 | // 35 | // release build: thread 'new_from_mut_slice_doesnt_overflow' 36 | // panicked at 'assertion failed: data.len() == ((height - 1) * 37 | // row_stride + last_row_len) as usize', src/pixbuf.rs:50:13 38 | 39 | let _pixbuf = Pixbuf::from_mut_slice(data, Colorspace::Rgb, true, 8, 21000, 29700, 21000 * 4); 40 | } 41 | 42 | #[test] 43 | #[should_panic] 44 | fn put_pixel_out_of_bounds_x_should_panic() { 45 | let pixbuf = Pixbuf::new(Colorspace::Rgb, true, 8, 100, 200).unwrap(); 46 | 47 | pixbuf.put_pixel(100, 0, 0, 0, 0, 0); 48 | } 49 | 50 | #[test] 51 | #[should_panic] 52 | fn put_pixel_out_of_bounds_y_should_panic() { 53 | let pixbuf = Pixbuf::new(Colorspace::Rgb, true, 8, 100, 200).unwrap(); 54 | 55 | pixbuf.put_pixel(0, 200, 0, 0, 0, 0); 56 | } 57 | 58 | #[test] 59 | #[should_panic] 60 | fn too_small_slice_should_panic() { 61 | let data = vec![0u8; 100 * 99 * 4]; 62 | 63 | Pixbuf::from_mut_slice(data, Colorspace::Rgb, true, 8, 100, 100, 100 * 4); 64 | } 65 | 66 | #[test] 67 | fn last_row_with_incomplete_rowstride_works() { 68 | // 1-pixel wide, RGB, 3 32-bit rows, no extra padding byte on the fourth row 69 | let data = vec![0u8; 1 * 4 * 3 + 3]; 70 | 71 | Pixbuf::from_mut_slice(data, Colorspace::Rgb, false, 8, 1, 4, 4); 72 | } 73 | 74 | #[test] 75 | fn last_row_with_full_rowstride_works() { 76 | // 1-pixel wide, RGB, 4 32-bit rows 77 | let data = vec![0u8; 1 * 4 * 4]; 78 | 79 | Pixbuf::from_mut_slice(data, Colorspace::Rgb, false, 8, 1, 4, 4); 80 | } 81 | 82 | #[test] 83 | fn extra_data_after_last_row_works() { 84 | // 1-pixel wide, RGB, 4 32-bit rows, plus some extra space 85 | let data = vec![0u8; 1 * 4 * 4 + 42]; 86 | 87 | Pixbuf::from_mut_slice(data, Colorspace::Rgb, false, 8, 1, 4, 4); 88 | } 89 | --------------------------------------------------------------------------------