summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcc <cc@localhost>2025-08-20 17:04:35 -0700
committercc <cc@localhost>2025-08-20 17:04:35 -0700
commitd0deb0161c48e10505c668a57e0ed8a56c36c25a (patch)
treee6c09156ed8a33c303d00520dc0ae7fe498116b1
parent173d7f73646d6e20b2c0b4e7a051d7e0f9c445c0 (diff)
Add TIFF Open/ Close
-rw-r--r--src/lib.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 565f519..e3395e9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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);
+ }
}