summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcc <cc@localhost>2025-08-20 17:19:05 -0700
committercc <cc@localhost>2025-08-20 17:19:05 -0700
commite38b77ca4a0bef6e5ae0a28d445929e9af2ddd05 (patch)
tree47278c28099c2ffb1a3ed1345b921b7d2c9125d5 /src
parent950a720a5c0b43199877b3727f0d06412f8a12fb (diff)
Width and Height Bindings
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs26
-rw-r--r--src/tiff.rs22
2 files changed, 48 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 4e630d5..9b726c8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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;
+}