diff options
author | cc <cc@localhost> | 2025-08-20 17:39:28 -0700 |
---|---|---|
committer | cc <cc@localhost> | 2025-08-20 17:39:46 -0700 |
commit | 972a413ebf54edbdd777379f1db7ebb6731f5ecc (patch) | |
tree | c013d8bf0322d02c7e8786252353eddc331c6757 /src/tiff.rs | |
parent | b248c22d0d69643f33f779c65882f1158ed8f959 (diff) |
Read TIFF Data
Diffstat (limited to 'src/tiff.rs')
-rw-r--r-- | src/tiff.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/tiff.rs b/src/tiff.rs index 04eaf02..08f4d54 100644 --- a/src/tiff.rs +++ b/src/tiff.rs @@ -1,4 +1,4 @@ -use std::os::raw::{c_char, c_void}; +use std::os::raw::{c_char, c_uint, c_void, c_longlong, c_long}; use std::ffi::CString; /// # TIFF Internal Structure @@ -21,9 +21,10 @@ 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; - fn TIFFStripSize(tiff_ptr: *mut TIFF) -> i64; - fn TIFFNumberOfStrips(tiff_ptr: *mut TIFF) -> i64; + fn TIFFGetField(tiff_ptr: *mut TIFF, tag: c_uint, ...) -> c_long; + fn TIFFStripSize(tiff_ptr: *mut TIFF) -> c_longlong; + fn TIFFNumberOfStrips(tiff_ptr: *mut TIFF) -> c_longlong; + fn TIFFReadRawStrip(tiff_ptr: *mut TIFF, strip: c_uint, buf: *mut c_void, size: c_longlong) -> c_longlong; } /// From tiff.h @@ -86,3 +87,13 @@ pub fn get_strip_count(tiff_ptr: *mut TIFF) -> i64 { TIFFNumberOfStrips(tiff_ptr) } } + +pub fn read_strip(tiff_ptr: *mut TIFF, strip: u32) -> Vec<u8> { + let strip_size = get_strip_size(tiff_ptr); + assert!(strip_size>0); + let mut buf: Vec<u8> = vec![0u8; strip_size as usize]; + unsafe { + TIFFReadRawStrip(tiff_ptr, strip, buf.as_mut_ptr() as *mut c_void, strip_size); + } + buf +} |