diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -1,4 +1,12 @@ use std::os::raw::{c_char, c_void}; +use std::ffi::CString; + +/// # TIFF Internal Structure +/// An opaque type +#[repr(C)] +pub struct TIFF { + _unused: [u8; 0], +} /// # TIFF Warning Handler Definition pub type TIFFWarningHandler = Option<unsafe extern "C" fn(module: *const c_char, fmt: *const c_char, ap: *mut c_void)>; @@ -11,6 +19,8 @@ unsafe extern "C" fn tiff_ignore_warning_handle(_module: *const c_char, _fmt: *c #[link(name = "tiff")] unsafe extern "C" { pub fn TIFFSetWarningHandler(handler: TIFFWarningHandler) -> TIFFWarningHandler; + pub fn TIFFOpen(filename: *const c_char, mode: *const c_char) -> *mut TIFF; + pub fn TIFFClose(tiff_ptr: *mut TIFF); } /// # Ignore TIFF Warnings @@ -20,6 +30,22 @@ pub fn tiff_ignore_warnings() { } } +/// # Open TIFF File +pub fn tiff_open(filename: &str) -> *mut TIFF { + let c_filename = CString::new(filename).expect("Cast error"); + let c_mode = CString::new("r").expect("Cast error"); + unsafe { + TIFFOpen(c_filename.as_ptr(), c_mode.as_ptr()) + } +} + +/// # Close TIFF File +pub fn tiff_close(tiff_ptr: *mut TIFF) { + unsafe { + TIFFClose(tiff_ptr); + } +} + #[cfg(test)] mod tests { use super::*; @@ -34,4 +60,13 @@ mod tests { tiff_ignore_warnings(); assert_eq!(1, 1); } + + #[test] + fn tiff_open_test() { + tiff_ignore_warnings(); + let result = tiff_open("../test.tif"); + assert!(!result.is_null()); + tiff_close(result); + assert_eq!(1, 1); + } } |