diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 26 | ||||
-rw-r--r-- | src/tiff.rs | 22 |
2 files changed, 48 insertions, 0 deletions
@@ -24,4 +24,30 @@ mod tests { assert!(false); } } + + #[test] + fn tiff_height_test() { + tiff::ignore_warnings(); + if let Some(t_handle) = tiff::open("../test.tif") { + let height = tiff::get_height(t_handle); + assert!(height > 0); + println!("{:?}", height); + tiff::close(t_handle); + } else { + assert!(false); + } + } + + #[test] + fn tiff_width_test() { + tiff::ignore_warnings(); + if let Some(t_handle) = tiff::open("../test.tif") { + let width = tiff::get_width(t_handle); + assert!(width > 0); + println!("{:?}", width); + tiff::close(t_handle); + } else { + assert!(false); + } + } } diff --git a/src/tiff.rs b/src/tiff.rs index c2f1a17..7143664 100644 --- a/src/tiff.rs +++ b/src/tiff.rs @@ -21,8 +21,14 @@ unsafe extern "C" { fn TIFFSetWarningHandler(handler: TIFFWarningHandler) -> TIFFWarningHandler; fn TIFFOpen(filename: *const c_char, mode: *const c_char) -> *mut TIFF; fn TIFFClose(tiff_ptr: *mut TIFF); + fn TIFFGetField(tiff_ptr: *mut TIFF, tag: u32, ...) -> i32; } +/// From tiff.h +const TIFFTAG_IMAGEWIDTH: u32 = 256; +/// From tiff.h +const TIFFTAG_IMAGEHEIGHT: u32 = 257; + /// # Ignore TIFF Warnings pub fn ignore_warnings() { unsafe { @@ -50,3 +56,19 @@ pub fn close(tiff_ptr: *mut TIFF) { TIFFClose(tiff_ptr); } } + +pub fn get_width(tiff_ptr: *mut TIFF) -> u32 { + let mut width: u32 = 0; + unsafe { + let status = TIFFGetField(tiff_ptr, TIFFTAG_IMAGEWIDTH, &mut width as *mut u32); + } + return width; +} + +pub fn get_height(tiff_ptr: *mut TIFF) -> u32 { + let mut height: u32 = 0; + unsafe { + let status = TIFFGetField(tiff_ptr, TIFFTAG_IMAGEHEIGHT, &mut height as *mut u32); + } + return height; +} |