├── .gitignore ├── .travis.yml ├── Cargo.toml ├── LICENSE ├── README.md ├── examples └── demo.rs └── src └── sdl2_image ├── ffi.rs └── lib.rs /.gitignore: -------------------------------------------------------------------------------- 1 | .rust/ 2 | build/ 3 | bin/ 4 | lib/ 5 | src/generated 6 | /rustpkg_db.json 7 | *.so 8 | target/ 9 | Cargo.lock 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | os: 3 | - linux 4 | env: 5 | global: 6 | - LD_LIBRARY_PATH: /usr/local/lib 7 | install: 8 | - cd .. 9 | - time wget -q http://www.libsdl.org/release/SDL2-2.0.3.tar.gz 10 | - time wget -q http://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.0.tar.gz 11 | - time tar xf SDL2-*.tar.gz 12 | - time tar xf SDL2_image-*.tar.gz 13 | - cd SDL2-* 14 | - ./configure && make && sudo make install 15 | - cd - 16 | - cd SDL2_image-* 17 | - ./configure && make && sudo make install 18 | - cd - 19 | script: 20 | - cd rust-sdl2_image 21 | - cargo build -v 22 | - cargo test -v 23 | - cargo doc -v 24 | after_script: 25 | - curl http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN | sh 26 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sdl2_image" 3 | version = "0.25.0" 4 | authors = ["xsleonard"] 5 | description = "SDL2_image bindings and wrappers" 6 | license = "MIT" 7 | repository = "https://github.com/xsleonard/rust-sdl2_image" 8 | keywords = ["SDL2"] 9 | 10 | [lib] 11 | name = "sdl2_image" 12 | path = "src/sdl2_image/lib.rs" 13 | 14 | [dependencies] 15 | bitflags = "0.7" 16 | sdl2 = "0.25.0" 17 | sdl2-sys = "0.25.0" 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Mozilla Foundation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [As of rust-sdl2v0.27 this crate is deprecated and its functionality has been moved as a feature in rust-sdl2](https://github.com/AngryLawyer/rust-sdl2) 2 | 3 | Rust-SDL2_image 4 | =============== 5 | 6 | Rust bindings for SDL2_image 7 | 8 | > **NOTE**: The 1.0.0 and 1.1.0 version of this crate are yanked because of [#65](https://github.com/xsleonard/rust-sdl2_image/issues/65)! We are now using same ``x.y._`` version number as [sdl2](https://crates.io/crates/sdl2). See [sdl2_image/0.25.0](https://crates.io/crates/sdl2_image/0.25.0). 9 | 10 | # Overview 11 | 12 | Rust-SDL2_image is a library for talking to the new SDL2_image library from Rust. 13 | 14 | Rust-SDL2_image uses the MIT license. 15 | 16 | # Requirements 17 | 18 | * [Rust-SDL2](https://github.com/AngryLawyer/rust-sdl2) 19 | * [SDL_image 2.0 development libraries](https://www.libsdl.org/projects/SDL_image/) 20 | * Rust master -- usage of Nightly is recommended 21 | 22 | # [Documentation](https://docs.rs/sdl2_image/0.25.0/sdl2_image/) 23 | 24 | # Installation 25 | 26 | If you're using Cargo to manage your project, enter the following into your 27 | Cargo.toml file: 28 | 29 | ```toml 30 | [dependencies] 31 | sdl2 = "0.25.0" 32 | sdl2_image = "0.25.0" 33 | ``` 34 | 35 | Or, to reference this repository directly: 36 | 37 | ```toml 38 | [dependencies.sdl2_image] 39 | git = "https://github.com/xsleonard/rust-sdl2_image" 40 | ``` 41 | 42 | Otherwise, clone this repo and run: 43 | 44 | ```bash 45 | cargo build 46 | ``` 47 | 48 | If you're not using Cargo, you can compile manually: 49 | 50 | ```bash 51 | git clone https://github.com/xsleonard/rust-sdl2_image 52 | cd rust-sdl2_image 53 | rustc src/sdl2_image/lib.rs 54 | # OR if you are using the mac framework version 55 | rustc --cfg mac_framework src/sdl2_image/lib.rs 56 | ``` 57 | 58 | # Demo 59 | 60 | You'll find included with the library a simple demo that loads and displays 61 | a given image : 62 | 63 | ```bash 64 | cargo run /path/to/some/image.(jpg|png) 65 | ``` 66 | 67 | Or: 68 | 69 | ```bash 70 | rustc -L. src/demo/main.rs -o demo 71 | ./demo image.(png|jpg) 72 | ``` 73 | -------------------------------------------------------------------------------- /examples/demo.rs: -------------------------------------------------------------------------------- 1 | #![crate_type = "bin"] 2 | 3 | extern crate sdl2; 4 | extern crate sdl2_image; 5 | 6 | use std::env; 7 | use std::path::Path; 8 | use sdl2_image::{self, LoadTexture, INIT_PNG, INIT_JPG}; 9 | use sdl2::event::Event; 10 | use sdl2::keyboard::Keycode; 11 | 12 | pub fn run(png: &Path) { 13 | 14 | let sdl_context = sdl2::init().unwrap(); 15 | let video_subsystem = sdl_context.video().unwrap(); 16 | let _image_context = sdl2_image::init(INIT_PNG | INIT_JPG).unwrap(); 17 | let window = video_subsystem.window("rust-sdl2 demo: Video", 800, 600) 18 | .position_centered() 19 | .build() 20 | .unwrap(); 21 | 22 | let mut renderer = window.renderer().software().build().unwrap(); 23 | let texture = renderer.load_texture(png).unwrap(); 24 | 25 | renderer.copy(&texture, None, None); 26 | renderer.present(); 27 | 28 | 'mainloop: loop { 29 | for event in sdl_context.event_pump().unwrap().poll_iter() { 30 | match event { 31 | Event::Quit{..} | 32 | Event::KeyDown {keycode: Option::Some(Keycode::Escape), ..} => 33 | break 'mainloop, 34 | _ => {} 35 | } 36 | } 37 | } 38 | } 39 | 40 | 41 | fn main() { 42 | 43 | let args: Vec<_> = env::args().collect(); 44 | 45 | if args.len() < 2 { 46 | println!("Usage: cargo run /path/to/image.(png|jpg)") 47 | } else { 48 | run(Path::new(&args[1])); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/sdl2_image/ffi.rs: -------------------------------------------------------------------------------- 1 | extern crate sdl2; 2 | extern crate sdl2_sys as sys; 3 | 4 | use std::os::raw::{c_int, c_char}; 5 | use sys::surface::SDL_Surface; 6 | use sys::rwops::SDL_RWops; 7 | use sys::render::SDL_Texture; 8 | use sys::render::SDL_Renderer; 9 | use sys::version::SDL_version; 10 | 11 | pub type IMG_InitFlags = c_int; 12 | pub const IMG_INIT_JPG: IMG_InitFlags = 0x00000001; 13 | pub const IMG_INIT_PNG: IMG_InitFlags = 0x00000002; 14 | pub const IMG_INIT_TIF: IMG_InitFlags = 0x00000004; 15 | pub const IMG_INIT_WEBP: IMG_InitFlags = 0x00000008; 16 | 17 | extern "C" { 18 | 19 | // This function gets the version of the dynamically linked SDL_image library. 20 | pub fn IMG_Linked_Version() -> *const SDL_version; 21 | 22 | // Loads dynamic libraries and prepares them for use. Flags should be 23 | // one or more flags from IMG_InitFlags OR'd together. 24 | // It returns the flags successfully initialized, or 0 on failure. 25 | pub fn IMG_Init(flags: c_int) -> c_int; 26 | 27 | // Unloads libraries loaded with IMG_Init 28 | pub fn IMG_Quit(); 29 | 30 | // Load an image from an SDL data source. 31 | // The 'type' may be one of: "BMP", "GIF", "PNG", etc. 32 | // If the image format supports a transparent pixel, SDL will set the 33 | // colorkey for the surface. You can enable RLE acceleration on the 34 | // surface afterwards by calling: 35 | // SDL_SetColorKey(image, SDL_RLEACCEL, image->format->colorkey); 36 | pub fn IMG_LoadTyped_RW(src: *const SDL_RWops, freesrc: c_int, 37 | fmt: *const c_char) -> *mut SDL_Surface; 38 | 39 | // Convenience functions 40 | pub fn IMG_Load(file: *const c_char) -> *mut SDL_Surface; 41 | pub fn IMG_Load_RW(src: *const SDL_RWops, freesrc: c_int) -> *mut SDL_Surface; 42 | 43 | // Load an image directly into a render texture. 44 | // Requires SDL2 45 | pub fn IMG_LoadTexture(renderer: *const SDL_Renderer, 46 | file: *const c_char) -> *mut SDL_Texture; 47 | pub fn IMG_LoadTexture_RW(renderer: *const SDL_Renderer, src: *const SDL_RWops, 48 | freesrc: c_int) -> *const SDL_Texture; 49 | pub fn IMG_LoadTextureTyped_RW(renderer: *const SDL_Renderer, src: *const SDL_RWops, 50 | freesrc: c_int, fmt: *const c_char) -> *const SDL_Texture; 51 | 52 | // Functions to detect a file type, given a seekable source 53 | pub fn IMG_isICO(src: *const SDL_RWops) -> c_int; 54 | pub fn IMG_isCUR(src: *const SDL_RWops) -> c_int; 55 | pub fn IMG_isBMP(src: *const SDL_RWops) -> c_int; 56 | pub fn IMG_isGIF(src: *const SDL_RWops) -> c_int; 57 | pub fn IMG_isJPG(src: *const SDL_RWops) -> c_int; 58 | pub fn IMG_isLBM(src: *const SDL_RWops) -> c_int; 59 | pub fn IMG_isPCX(src: *const SDL_RWops) -> c_int; 60 | pub fn IMG_isPNG(src: *const SDL_RWops) -> c_int; 61 | pub fn IMG_isPNM(src: *const SDL_RWops) -> c_int; 62 | pub fn IMG_isTIF(src: *const SDL_RWops) -> c_int; 63 | pub fn IMG_isXCF(src: *const SDL_RWops) -> c_int; 64 | pub fn IMG_isXPM(src: *const SDL_RWops) -> c_int; 65 | pub fn IMG_isXV(src: *const SDL_RWops) -> c_int; 66 | pub fn IMG_isWEBP(src: *const SDL_RWops) -> c_int; 67 | 68 | // Individual loading functions 69 | pub fn IMG_LoadICO_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 70 | pub fn IMG_LoadCUR_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 71 | pub fn IMG_LoadBMP_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 72 | pub fn IMG_LoadGIF_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 73 | pub fn IMG_LoadJPG_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 74 | pub fn IMG_LoadLBM_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 75 | pub fn IMG_LoadPCX_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 76 | pub fn IMG_LoadPNG_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 77 | pub fn IMG_LoadPNM_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 78 | pub fn IMG_LoadTGA_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 79 | pub fn IMG_LoadTIF_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 80 | pub fn IMG_LoadXCF_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 81 | pub fn IMG_LoadXPM_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 82 | pub fn IMG_LoadXV_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 83 | pub fn IMG_LoadWEBP_RW(src: *const SDL_RWops) -> *mut SDL_Surface; 84 | pub fn IMG_ReadXPMFromArray(xpm: *const *const c_char) -> *mut SDL_Surface; 85 | 86 | // Individual saving functions 87 | pub fn IMG_SavePNG(surface: *mut SDL_Surface, file: *const c_char) -> c_int; 88 | pub fn IMG_SavePNG_RW(surface: *mut SDL_Surface, dst: *const SDL_RWops, 89 | freedst: c_int) -> c_int; 90 | 91 | } // extern "C" 92 | -------------------------------------------------------------------------------- /src/sdl2_image/lib.rs: -------------------------------------------------------------------------------- 1 | #![crate_name="sdl2_image"] 2 | #![crate_type = "lib"] 3 | 4 | extern crate sdl2; 5 | extern crate sdl2_sys as sys; 6 | 7 | #[macro_use] 8 | extern crate bitflags; 9 | 10 | use std::os::raw::{c_int, c_char}; 11 | use std::ffi::CString; 12 | use std::path::Path; 13 | use sdl2::surface::Surface; 14 | use sdl2::render::Texture; 15 | use sdl2::render::Renderer; 16 | use sdl2::rwops::RWops; 17 | use sdl2::version::Version; 18 | use sdl2::get_error; 19 | 20 | // Setup linking for all targets. 21 | #[cfg(target_os="macos")] 22 | mod mac { 23 | #[cfg(mac_framework)] 24 | #[link(kind="framework", name="SDL2_image")] 25 | extern {} 26 | 27 | #[cfg(not(mac_framework))] 28 | #[link(name="SDL2_image")] 29 | extern {} 30 | } 31 | 32 | #[cfg(any(target_os="windows", target_os="linux", target_os="freebsd"))] 33 | mod others { 34 | #[link(name="SDL2_image")] 35 | extern {} 36 | } 37 | 38 | #[allow(non_camel_case_types, dead_code)] 39 | mod ffi; 40 | 41 | /// InitFlags are passed to init() to control which subsystem 42 | /// functionality to load. 43 | bitflags! { 44 | pub flags InitFlag : u32 { 45 | const INIT_JPG = ::ffi::IMG_INIT_JPG as u32, 46 | const INIT_PNG = ::ffi::IMG_INIT_PNG as u32, 47 | const INIT_TIF = ::ffi::IMG_INIT_TIF as u32, 48 | const INIT_WEBP = ::ffi::IMG_INIT_WEBP as u32 49 | } 50 | } 51 | 52 | // This is used for error message for init 53 | impl ToString for InitFlag { 54 | fn to_string(&self) -> String { 55 | let mut string = "".to_string(); 56 | if self.contains(INIT_JPG) { 57 | string = string + &"INIT_JPG ".to_string(); 58 | } 59 | if self.contains(INIT_PNG) { 60 | string = string + &"INIT_PNG ".to_string(); 61 | } 62 | if self.contains(INIT_TIF) { 63 | string = string + &"INIT_TIF ".to_string(); 64 | } 65 | if self.contains(INIT_WEBP) { 66 | string = string + &"INIT_WEBP ".to_string(); 67 | } 68 | string 69 | } 70 | } 71 | 72 | 73 | /// Static method extensions for creating Surfaces 74 | pub trait LoadSurface: Sized { 75 | // Self is only returned here to type hint to the compiler. 76 | // The syntax for type hinting in this case is not yet defined. 77 | // The intended return value is Result<~Surface, String>. 78 | fn from_file(filename: &Path) -> Result; 79 | fn from_xpm_array(xpm: *const *const i8) -> Result; 80 | } 81 | 82 | /// Method extensions to Surface for saving to disk 83 | pub trait SaveSurface { 84 | fn save(&self, filename: &Path) -> Result<(), String>; 85 | fn save_rw(&self, dst: &mut RWops) -> Result<(), String>; 86 | } 87 | 88 | impl<'a> LoadSurface for Surface<'a> { 89 | fn from_file(filename: &Path) -> Result, String> { 90 | //! Loads an SDL Surface from a file 91 | unsafe { 92 | let c_filename = CString::new(filename.to_str().unwrap()).unwrap(); 93 | let raw = ffi::IMG_Load(c_filename.as_ptr() as *const _); 94 | if (raw as *mut ()).is_null() { 95 | Err(get_error()) 96 | } else { 97 | Ok(Surface::from_ll(raw)) 98 | } 99 | } 100 | } 101 | 102 | fn from_xpm_array(xpm: *const *const i8) -> Result, String> { 103 | //! Loads an SDL Surface from XPM data 104 | unsafe { 105 | let raw = ffi::IMG_ReadXPMFromArray(xpm as *const *const c_char); 106 | if (raw as *mut ()).is_null() { 107 | Err(get_error()) 108 | } else { 109 | Ok(Surface::from_ll(raw)) 110 | } 111 | } 112 | } 113 | } 114 | 115 | impl<'a> SaveSurface for Surface<'a> { 116 | fn save(&self, filename: &Path) -> Result<(), String> { 117 | //! Saves an SDL Surface to a file 118 | unsafe { 119 | let c_filename = CString::new(filename.to_str().unwrap()).unwrap(); 120 | let status = ffi::IMG_SavePNG(self.raw(), c_filename.as_ptr() as *const _); 121 | if status != 0 { 122 | Err(get_error()) 123 | } else { 124 | Ok(()) 125 | } 126 | } 127 | } 128 | 129 | fn save_rw(&self, dst: &mut RWops) -> Result<(), String> { 130 | //! Saves an SDL Surface to an RWops 131 | unsafe { 132 | let status = ffi::IMG_SavePNG_RW(self.raw(), dst.raw(), 0); 133 | 134 | if status != 0 { 135 | Err(get_error()) 136 | } else { 137 | Ok(()) 138 | } 139 | } 140 | } 141 | } 142 | 143 | /// Method extensions for creating Textures from a Renderer 144 | pub trait LoadTexture { 145 | fn load_texture(&self, filename: &Path) -> Result; 146 | } 147 | 148 | impl<'a> LoadTexture for Renderer<'a> { 149 | fn load_texture(&self, filename: &Path) -> Result { 150 | //! Loads an SDL Texture from a file 151 | unsafe { 152 | let c_filename = CString::new(filename.to_str().unwrap()).unwrap(); 153 | let raw = ffi::IMG_LoadTexture(self.raw(), c_filename.as_ptr() as *const _); 154 | if (raw as *mut ()).is_null() { 155 | Err(get_error()) 156 | } else { 157 | Ok(Texture::from_ll(self, raw)) 158 | } 159 | } 160 | } 161 | } 162 | 163 | /// Context manager for `sdl2_image` to manage quiting. Can't do much with it but 164 | /// keep it alive while you are using it. 165 | pub struct Sdl2ImageContext; 166 | 167 | impl Drop for Sdl2ImageContext { 168 | fn drop(&mut self) { 169 | unsafe { ffi::IMG_Quit(); } 170 | } 171 | } 172 | 173 | /// Initializes `SDL2_image` with `InitFlags`. 174 | /// If not every flag is set it returns an error 175 | pub fn init(flags: InitFlag) -> Result { 176 | let return_flags = unsafe { 177 | let used = ffi::IMG_Init(flags.bits() as c_int); 178 | InitFlag::from_bits_truncate(used as u32) 179 | }; 180 | if !flags.intersects(return_flags) { 181 | // According to docs, error message text is not always set 182 | if get_error() == "" { 183 | let un_init_flags = return_flags ^ flags; 184 | let error_str = &("Could not init: ".to_string() + &un_init_flags.to_string()); 185 | let _ = sdl2::set_error(error_str); 186 | } 187 | Err(get_error()) 188 | } else { 189 | Ok(Sdl2ImageContext) 190 | } 191 | } 192 | 193 | /// Returns the version of the dynamically linked `SDL_image` library 194 | pub fn get_linked_version() -> Version { 195 | unsafe { 196 | Version::from_ll(*ffi::IMG_Linked_Version()) 197 | } 198 | } 199 | 200 | #[inline] 201 | fn to_surface_result<'a>(raw: *mut sys::surface::SDL_Surface) -> Result, String> { 202 | if (raw as *mut ()).is_null() { 203 | Err(get_error()) 204 | } else { 205 | unsafe { Ok(Surface::from_ll(raw)) } 206 | } 207 | } 208 | 209 | pub trait ImageRWops { 210 | /// load as a surface. except TGA 211 | fn load(&self) -> Result; 212 | /// load as a surface. This can load all supported image formats. 213 | fn load_typed(&self, _type: &str) -> Result; 214 | 215 | fn load_cur(&self) -> Result; 216 | fn load_ico(&self) -> Result; 217 | fn load_bmp(&self) -> Result; 218 | fn load_pnm(&self) -> Result; 219 | fn load_xpm(&self) -> Result; 220 | fn load_xcf(&self) -> Result; 221 | fn load_pcx(&self) -> Result; 222 | fn load_gif(&self) -> Result; 223 | fn load_jpg(&self) -> Result; 224 | fn load_tif(&self) -> Result; 225 | fn load_png(&self) -> Result; 226 | fn load_tga(&self) -> Result; 227 | fn load_lbm(&self) -> Result; 228 | fn load_xv(&self) -> Result; 229 | fn load_webp(&self) -> Result; 230 | 231 | fn is_cur(&self) -> bool; 232 | fn is_ico(&self) -> bool; 233 | fn is_bmp(&self) -> bool; 234 | fn is_pnm(&self) -> bool; 235 | fn is_xpm(&self) -> bool; 236 | fn is_xcf(&self) -> bool; 237 | fn is_pcx(&self) -> bool; 238 | fn is_gif(&self) -> bool; 239 | fn is_jpg(&self) -> bool; 240 | fn is_tif(&self) -> bool; 241 | fn is_png(&self) -> bool; 242 | fn is_lbm(&self) -> bool; 243 | fn is_xv(&self) -> bool; 244 | fn is_webp(&self) -> bool; 245 | } 246 | 247 | impl<'a> ImageRWops for RWops<'a> { 248 | fn load(&self) -> Result { 249 | let raw = unsafe { 250 | ffi::IMG_Load_RW(self.raw(), 0) 251 | }; 252 | to_surface_result(raw) 253 | } 254 | fn load_typed(&self, _type: &str) -> Result { 255 | let raw = unsafe { 256 | let c_type = CString::new(_type.as_bytes()).unwrap(); 257 | ffi::IMG_LoadTyped_RW(self.raw(), 0, c_type.as_ptr() as *const _) 258 | }; 259 | to_surface_result(raw) 260 | } 261 | 262 | fn load_cur(&self) -> Result { 263 | let raw = unsafe { ffi::IMG_LoadCUR_RW(self.raw()) }; 264 | to_surface_result(raw) 265 | } 266 | fn load_ico(&self) -> Result { 267 | let raw = unsafe { ffi::IMG_LoadICO_RW(self.raw()) }; 268 | to_surface_result(raw) 269 | } 270 | fn load_bmp(&self) -> Result { 271 | let raw = unsafe { ffi::IMG_LoadBMP_RW(self.raw()) }; 272 | to_surface_result(raw) 273 | } 274 | fn load_pnm(&self) -> Result { 275 | let raw = unsafe { ffi::IMG_LoadPNM_RW(self.raw()) }; 276 | to_surface_result(raw) 277 | } 278 | fn load_xpm(&self) -> Result { 279 | let raw = unsafe { ffi::IMG_LoadXPM_RW(self.raw()) }; 280 | to_surface_result(raw) 281 | } 282 | fn load_xcf(&self) -> Result { 283 | let raw = unsafe { ffi::IMG_LoadXCF_RW(self.raw()) }; 284 | to_surface_result(raw) 285 | } 286 | fn load_pcx(&self) -> Result { 287 | let raw = unsafe { ffi::IMG_LoadPCX_RW(self.raw()) }; 288 | to_surface_result(raw) 289 | } 290 | fn load_gif(&self) -> Result { 291 | let raw = unsafe { ffi::IMG_LoadGIF_RW(self.raw()) }; 292 | to_surface_result(raw) 293 | } 294 | fn load_jpg(&self) -> Result { 295 | let raw = unsafe { ffi::IMG_LoadJPG_RW(self.raw()) }; 296 | to_surface_result(raw) 297 | } 298 | fn load_tif(&self) -> Result { 299 | let raw = unsafe { ffi::IMG_LoadTIF_RW(self.raw()) }; 300 | to_surface_result(raw) 301 | } 302 | fn load_png(&self) -> Result { 303 | let raw = unsafe { ffi::IMG_LoadPNG_RW(self.raw()) }; 304 | to_surface_result(raw) 305 | } 306 | fn load_tga(&self) -> Result { 307 | let raw = unsafe { ffi::IMG_LoadTGA_RW(self.raw()) }; 308 | to_surface_result(raw) 309 | } 310 | fn load_lbm(&self) -> Result { 311 | let raw = unsafe { ffi::IMG_LoadLBM_RW(self.raw()) }; 312 | to_surface_result(raw) 313 | } 314 | fn load_xv(&self) -> Result { 315 | let raw = unsafe { ffi::IMG_LoadXV_RW(self.raw()) }; 316 | to_surface_result(raw) 317 | } 318 | fn load_webp(&self) -> Result { 319 | let raw = unsafe { ffi::IMG_LoadWEBP_RW(self.raw()) }; 320 | to_surface_result(raw) 321 | } 322 | 323 | fn is_cur(&self) -> bool { 324 | unsafe { ffi::IMG_isCUR(self.raw()) == 1 } 325 | } 326 | fn is_ico(&self) -> bool { 327 | unsafe { ffi::IMG_isICO(self.raw()) == 1 } 328 | } 329 | fn is_bmp(&self) -> bool { 330 | unsafe { ffi::IMG_isBMP(self.raw()) == 1 } 331 | } 332 | fn is_pnm(&self) -> bool { 333 | unsafe { ffi::IMG_isPNM(self.raw()) == 1 } 334 | } 335 | fn is_xpm(&self) -> bool { 336 | unsafe { ffi::IMG_isXPM(self.raw()) == 1 } 337 | } 338 | fn is_xcf(&self) -> bool { 339 | unsafe { ffi::IMG_isXCF(self.raw()) == 1 } 340 | } 341 | fn is_pcx(&self) -> bool { 342 | unsafe { ffi::IMG_isPCX(self.raw()) == 1 } 343 | } 344 | fn is_gif(&self) -> bool { 345 | unsafe { ffi::IMG_isGIF(self.raw()) == 1 } 346 | } 347 | fn is_jpg(&self) -> bool { 348 | unsafe { ffi::IMG_isJPG(self.raw()) == 1 } 349 | } 350 | fn is_tif(&self) -> bool { 351 | unsafe { ffi::IMG_isTIF(self.raw()) == 1 } 352 | } 353 | fn is_png(&self) -> bool { 354 | unsafe { ffi::IMG_isPNG(self.raw()) == 1 } 355 | } 356 | fn is_lbm(&self) -> bool { 357 | unsafe { ffi::IMG_isLBM(self.raw()) == 1 } 358 | } 359 | fn is_xv(&self) -> bool { 360 | unsafe { ffi::IMG_isXV(self.raw()) == 1 } 361 | } 362 | fn is_webp(&self) -> bool { 363 | unsafe { ffi::IMG_isWEBP(self.raw()) == 1 } 364 | } 365 | } 366 | --------------------------------------------------------------------------------