From 950a720a5c0b43199877b3727f0d06412f8a12fb Mon Sep 17 00:00:00 2001 From: cc Date: Wed, 20 Aug 2025 17:11:53 -0700 Subject: Modularization --- src/tiff.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/tiff.rs (limited to 'src/tiff.rs') diff --git a/src/tiff.rs b/src/tiff.rs new file mode 100644 index 0000000..c2f1a17 --- /dev/null +++ b/src/tiff.rs @@ -0,0 +1,52 @@ +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 +type TIFFWarningHandler = Option; + +/// # TIFF Ignore Warnings Handle +unsafe extern "C" fn tiff_ignore_warning_handle(_module: *const c_char, _fmt: *const c_char, _ap: *mut std::ffi::c_void) { + // Do nothing +} + +#[link(name = "tiff")] +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); +} + +/// # Ignore TIFF Warnings +pub fn ignore_warnings() { + unsafe { + let _ = TIFFSetWarningHandler(Some(tiff_ignore_warning_handle)); + } +} + +/// # Open TIFF File +pub fn open(filename: &str) -> Option<*mut TIFF> { + let c_filename = CString::new(filename).expect("Cast error"); + let c_mode = CString::new("r").expect("Cast error"); + unsafe { + let result = TIFFOpen(c_filename.as_ptr(), c_mode.as_ptr()); + if result.is_null() { + return None; + } else { + return Some(result); + } + } +} + +/// # Close TIFF File +pub fn close(tiff_ptr: *mut TIFF) { + unsafe { + TIFFClose(tiff_ptr); + } +} -- cgit v1.2.1