diff options
author | cc <cc@localhost> | 2025-08-20 17:11:53 -0700 |
---|---|---|
committer | cc <cc@localhost> | 2025-08-20 17:11:53 -0700 |
commit | 950a720a5c0b43199877b3727f0d06412f8a12fb (patch) | |
tree | 3223020184feb9c69a4b9d8534f3914be0519e8b /src/tiff.rs | |
parent | d0deb0161c48e10505c668a57e0ed8a56c36c25a (diff) |
Modularization
Diffstat (limited to 'src/tiff.rs')
-rw-r--r-- | src/tiff.rs | 52 |
1 files changed, 52 insertions, 0 deletions
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<unsafe extern "C" fn(module: *const c_char, fmt: *const c_char, ap: *mut c_void)>; + +/// # 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); + } +} |