diff --git a/sdl2-sys/build.rs b/sdl2-sys/build.rs index 8af05a29..83567a3f 100644 --- a/sdl2-sys/build.rs +++ b/sdl2-sys/build.rs @@ -281,6 +281,9 @@ fn copy_pregenerated_bindings() { let crate_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); fs::copy(crate_path.join("pregenerated_bindings.rs"), out_path.join("bindings.rs")) .expect("Couldn't find pregenerated bindings!"); + + fs::copy(crate_path.join("sdl_image_bindings.rs"), out_path.join("image_bindings.rs")) + .expect("Couldn't find pregenerated SDL_image bindings!"); } #[cfg(feature = "bindgen")] @@ -289,11 +292,15 @@ fn copy_pregenerated_bindings() { fn generate_bindings + ::std::fmt::Debug>(target: &str, host: &str, headers_paths: &[S]) { let target_os = get_os_from_triple(target).unwrap(); let mut bindings = bindgen::Builder::default(); + let mut image_bindings = bindgen::Builder::default(); // Set correct target triple for bindgen when cross-compiling if target != host { bindings = bindings.clang_arg("-target"); bindings = bindings.clang_arg(target.clone()); + + image_bindings = image_bindings.clang_arg("-target"); + image_bindings = image_bindings.clang_arg(target.clone()); } if headers_paths.len() == 0 { @@ -302,10 +309,12 @@ fn generate_bindings + ::std::fmt::Debug>(target: &str, host: &str include_path.push(format!("SDL2-{}", SDL2_HEADERS_BUNDLED_VERSION)); include_path.push("include"); bindings = bindings.clang_arg(format!("-I{}", include_path.display())); + image_bindings = image_bindings.clang_arg(format!("-I{}", include_path.display())); } else { // if paths are included, use them for bindgen. Bindgen should use the first one. for headers_path in headers_paths { - bindings = bindings.clang_arg(format!("-I{}", headers_path.as_ref())) + bindings = bindings.clang_arg(format!("-I{}", headers_path.as_ref())); + image_bindings = image_bindings.clang_arg(format!("-I{}", headers_path.as_ref())); } } @@ -315,12 +324,20 @@ fn generate_bindings + ::std::fmt::Debug>(target: &str, host: &str bindings = bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt")); bindings = bindings.clang_arg(format!("-IC:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include")); bindings = bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/8.1/Include/um")); + + image_bindings = image_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/8.1/Include/shared")); + image_bindings = image_bindings.clang_arg(format!("-IC:/Program Files/LLVM/lib/clang/5.0.0/include")); + image_bindings = image_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt")); + image_bindings = image_bindings.clang_arg(format!("-IC:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include")); + image_bindings = image_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/8.1/Include/um")); }; // SDL2 hasn't a default configuration for Linux if target_os == "linux-gnu" { bindings = bindings.clang_arg("-DSDL_VIDEO_DRIVER_X11"); bindings = bindings.clang_arg("-DSDL_VIDEO_DRIVER_WAYLAND"); + image_bindings = image_bindings.clang_arg("-DSDL_VIDEO_DRIVER_X11"); + image_bindings = image_bindings.clang_arg("-DSDL_VIDEO_DRIVER_WAYLAND"); } let bindings = bindings @@ -335,6 +352,24 @@ fn generate_bindings + ::std::fmt::Debug>(target: &str, host: &str bindings .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); + + let image_bindings = image_bindings + .header("wrapper_image.h") + .blacklist_type("max_align_t") // Until https://github.com/rust-lang-nursery/rust-bindgen/issues/550 gets fixed + .whitelist_type("IMG.*") + .whitelist_function("IMG.*") + .whitelist_var("IMG.*") + .blacklist_type("SDL_.*") + .blacklist_type("_IO.*|FILE") + .generate() + .expect("Unable to generate image_bindings!"); + + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + + image_bindings + .write_to_file(out_path.join("image_bindings.rs")) + .expect("Couldn't write image_bindings!"); + } fn get_os_from_triple(triple: &str) -> Option<&str> diff --git a/sdl2-sys/sdl_image_bindings.rs b/sdl2-sys/sdl_image_bindings.rs new file mode 100644 index 00000000..0b482607 --- /dev/null +++ b/sdl2-sys/sdl_image_bindings.rs @@ -0,0 +1,182 @@ +/* automatically generated by rust-bindgen */ + +pub type __uint8_t = ::std::os::raw::c_uchar; +pub type __uint32_t = ::std::os::raw::c_uint; +pub type __int64_t = ::std::os::raw::c_long; +pub type __off_t = ::std::os::raw::c_long; +pub type __off64_t = ::std::os::raw::c_long; +pub type Uint8 = u8; +pub type Uint32 = u32; +pub type Sint64 = i64; +extern "C" { + pub fn IMG_Linked_Version() -> *const SDL_version; +} +pub const IMG_InitFlags_IMG_INIT_JPG: IMG_InitFlags = 1; +pub const IMG_InitFlags_IMG_INIT_PNG: IMG_InitFlags = 2; +pub const IMG_InitFlags_IMG_INIT_TIF: IMG_InitFlags = 4; +pub const IMG_InitFlags_IMG_INIT_WEBP: IMG_InitFlags = 8; +pub type IMG_InitFlags = u32; +extern "C" { + pub fn IMG_Init(flags: ::std::os::raw::c_int) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_Quit(); +} +extern "C" { + pub fn IMG_LoadTyped_RW( + src: *mut SDL_RWops, + freesrc: ::std::os::raw::c_int, + type_: *const ::std::os::raw::c_char, + ) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_Load(file: *const ::std::os::raw::c_char) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_Load_RW(src: *mut SDL_RWops, freesrc: ::std::os::raw::c_int) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadTexture( + renderer: *mut SDL_Renderer, + file: *const ::std::os::raw::c_char, + ) -> *mut SDL_Texture; +} +extern "C" { + pub fn IMG_LoadTexture_RW( + renderer: *mut SDL_Renderer, + src: *mut SDL_RWops, + freesrc: ::std::os::raw::c_int, + ) -> *mut SDL_Texture; +} +extern "C" { + pub fn IMG_LoadTextureTyped_RW( + renderer: *mut SDL_Renderer, + src: *mut SDL_RWops, + freesrc: ::std::os::raw::c_int, + type_: *const ::std::os::raw::c_char, + ) -> *mut SDL_Texture; +} +extern "C" { + pub fn IMG_isICO(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isCUR(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isBMP(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isGIF(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isJPG(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isLBM(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isPCX(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isPNG(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isPNM(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isSVG(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isTIF(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isXCF(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isXPM(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isXV(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_isWEBP(src: *mut SDL_RWops) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_LoadICO_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadCUR_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadBMP_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadGIF_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadJPG_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadLBM_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadPCX_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadPNG_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadPNM_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadSVG_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadTGA_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadTIF_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadXCF_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadXPM_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadXV_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_LoadWEBP_RW(src: *mut SDL_RWops) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_ReadXPMFromArray(xpm: *mut *mut ::std::os::raw::c_char) -> *mut SDL_Surface; +} +extern "C" { + pub fn IMG_SavePNG( + surface: *mut SDL_Surface, + file: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_SavePNG_RW( + surface: *mut SDL_Surface, + dst: *mut SDL_RWops, + freedst: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_SaveJPG( + surface: *mut SDL_Surface, + file: *const ::std::os::raw::c_char, + quality: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn IMG_SaveJPG_RW( + surface: *mut SDL_Surface, + dst: *mut SDL_RWops, + freedst: ::std::os::raw::c_int, + quality: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} diff --git a/sdl2-sys/src/image.rs b/sdl2-sys/src/image.rs index d8ac8740..52d9199e 100644 --- a/sdl2-sys/src/image.rs +++ b/sdl2-sys/src/image.rs @@ -1,84 +1,2 @@ -use std::os::raw::{c_int, c_char}; -use ::{SDL_RWops, SDL_Surface, SDL_Renderer, SDL_Texture}; - -pub type IMG_InitFlags = c_int; -pub const IMG_INIT_JPG: IMG_InitFlags = 0x00_00_00_01; -pub const IMG_INIT_PNG: IMG_InitFlags = 0x00_00_00_02; -pub const IMG_INIT_TIF: IMG_InitFlags = 0x00_00_00_04; -pub const IMG_INIT_WEBP: IMG_InitFlags = 0x00_00_00_08; - -extern "C" { - -// This function gets the version of the dynamically linked SDL_image library. -pub fn IMG_Linked_Version() -> *const ::SDL_version; - -// Loads dynamic libraries and prepares them for use. Flags should be -// one or more flags from IMG_InitFlags OR'd together. -// It returns the flags successfully initialized, or 0 on failure. -pub fn IMG_Init(flags: c_int) -> c_int; - -// Unloads libraries loaded with IMG_Init -pub fn IMG_Quit(); - -// Load an image from an SDL data source. -// The 'type' may be one of: "BMP", "GIF", "PNG", etc. -// If the image format supports a transparent pixel, SDL will set the -// colorkey for the surface. You can enable RLE acceleration on the -// surface afterwards by calling: -// SDL_SetColorKey(image, SDL_RLEACCEL, image->format->colorkey); -pub fn IMG_LoadTyped_RW(src: *const SDL_RWops, freesrc: c_int, - fmt: *const c_char) -> *mut SDL_Surface; - -// Convenience functions -pub fn IMG_Load(file: *const c_char) -> *mut SDL_Surface; -pub fn IMG_Load_RW(src: *const SDL_RWops, freesrc: c_int) -> *mut SDL_Surface; - -// Load an image directly into a render texture. -// Requires SDL2 -pub fn IMG_LoadTexture(renderer: *const SDL_Renderer, - file: *const c_char) -> *mut SDL_Texture; -pub fn IMG_LoadTexture_RW(renderer: *const SDL_Renderer, src: *const SDL_RWops, - freesrc: c_int) -> *const SDL_Texture; -pub fn IMG_LoadTextureTyped_RW(renderer: *const SDL_Renderer, src: *const SDL_RWops, - freesrc: c_int, fmt: *const c_char) -> *const SDL_Texture; - -// Functions to detect a file type, given a seekable source -pub fn IMG_isICO(src: *const SDL_RWops) -> c_int; -pub fn IMG_isCUR(src: *const SDL_RWops) -> c_int; -pub fn IMG_isBMP(src: *const SDL_RWops) -> c_int; -pub fn IMG_isGIF(src: *const SDL_RWops) -> c_int; -pub fn IMG_isJPG(src: *const SDL_RWops) -> c_int; -pub fn IMG_isLBM(src: *const SDL_RWops) -> c_int; -pub fn IMG_isPCX(src: *const SDL_RWops) -> c_int; -pub fn IMG_isPNG(src: *const SDL_RWops) -> c_int; -pub fn IMG_isPNM(src: *const SDL_RWops) -> c_int; -pub fn IMG_isTIF(src: *const SDL_RWops) -> c_int; -pub fn IMG_isXCF(src: *const SDL_RWops) -> c_int; -pub fn IMG_isXPM(src: *const SDL_RWops) -> c_int; -pub fn IMG_isXV(src: *const SDL_RWops) -> c_int; -pub fn IMG_isWEBP(src: *const SDL_RWops) -> c_int; - -// Individual loading functions -pub fn IMG_LoadICO_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadCUR_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadBMP_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadGIF_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadJPG_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadLBM_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadPCX_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadPNG_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadPNM_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadTGA_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadTIF_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadXCF_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadXPM_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadXV_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_LoadWEBP_RW(src: *const SDL_RWops) -> *mut SDL_Surface; -pub fn IMG_ReadXPMFromArray(xpm: *const *const c_char) -> *mut SDL_Surface; - -// Individual saving functions -pub fn IMG_SavePNG(surface: *mut SDL_Surface, file: *const c_char) -> c_int; -pub fn IMG_SavePNG_RW(surface: *mut SDL_Surface, dst: *const SDL_RWops, - freedst: c_int) -> c_int; - -} // extern "C" +use ::*; +include!(concat!(env!("OUT_DIR"), "/image_bindings.rs")); diff --git a/sdl2-sys/wrapper_image.h b/sdl2-sys/wrapper_image.h new file mode 100644 index 00000000..db2bbf60 --- /dev/null +++ b/sdl2-sys/wrapper_image.h @@ -0,0 +1 @@ +#include diff --git a/src/sdl2/image/mod.rs b/src/sdl2/image/mod.rs index b79c6963..da30e6d5 100644 --- a/src/sdl2/image/mod.rs +++ b/src/sdl2/image/mod.rs @@ -34,10 +34,10 @@ use sys; /// functionality to load. bitflags! { pub flags InitFlag : u32 { - const INIT_JPG = sys::image::IMG_INIT_JPG as u32, - const INIT_PNG = sys::image::IMG_INIT_PNG as u32, - const INIT_TIF = sys::image::IMG_INIT_TIF as u32, - const INIT_WEBP = sys::image::IMG_INIT_WEBP as u32 + const INIT_JPG = sys::image::IMG_InitFlags_IMG_INIT_JPG as u32, + const INIT_PNG = sys::image::IMG_InitFlags_IMG_INIT_PNG as u32, + const INIT_TIF = sys::image::IMG_InitFlags_IMG_INIT_TIF as u32, + const INIT_WEBP = sys::image::IMG_InitFlags_IMG_INIT_WEBP as u32 } } @@ -93,7 +93,7 @@ impl<'a> LoadSurface for Surface<'a> { fn from_xpm_array(xpm: *const *const i8) -> Result, String> { //! Loads an SDL Surface from XPM data unsafe { - let raw = sys::image::IMG_ReadXPMFromArray(xpm as *const *const c_char); + let raw = sys::image::IMG_ReadXPMFromArray(xpm as *mut *mut c_char); if (raw as *mut ()).is_null() { Err(get_error()) } else {