diff --git a/Cargo.toml b/Cargo.toml index 0fc528f..8f5ccc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiffwrite" -version = "2024.10.6" +version = "2024.10.7" edition = "2021" authors = ["Wim Pomp "] license = "GPL-3.0-or-later" diff --git a/src/lib.rs b/src/lib.rs index f439708..d0d6f7a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ mod py; use anyhow::Result; use chrono::Utc; -use ndarray::{s, Array2}; +use ndarray::{s, Array2, ArrayView2}; use num::{traits::ToBytes, Complex, FromPrimitive, Rational32, Zero}; use rayon::prelude::*; use std::collections::HashSet; @@ -632,17 +632,18 @@ impl IJTiffFile { } } - pub fn save(&mut self, frame: Array2, c: usize, z: usize, t: usize) -> Result<()> + pub fn save(&mut self, frame: ArrayView2, c: usize, z: usize, t: usize) -> Result<()> where - T: Bytes + Clone + Send + Sync + Zero + 'static, + T: Bytes + Clone + Send + Zero + 'static, { self.compress_frame(frame.reversed_axes(), c, z, t)?; Ok(()) } - fn compress_frame(&mut self, frame: Array2, c: usize, z: usize, t: usize) -> Result<()> + fn compress_frame(&mut self, frame: ArrayView2, + c: usize, z: usize, t: usize) -> Result<()> where - T: Bytes + Clone + Zero + Send + 'static, + T: Bytes + Clone + Send + Zero + 'static, { fn compress(frame: Array2, compression_level: i32) -> CompressedFrame where @@ -657,7 +658,7 @@ impl IJTiffFile { ) .max(16) .min(1024); - let tiles = IJTiffFile::tile(frame.reversed_axes(), tile_size); + let tiles = IJTiffFile::tile(frame.view().reversed_axes(), tile_size); let byte_tiles: Vec> = tiles .into_iter() .map(|tile| tile.map(|x| x.bytes()).into_iter().flatten().collect()) @@ -690,6 +691,7 @@ impl IJTiffFile { sleep(Duration::from_millis(100)); } let compression_level = self.compression_level; + let frame = frame.to_owned(); self.threads.insert( (c, z, t), thread::spawn(move || compress(frame, compression_level)), @@ -729,7 +731,7 @@ impl IJTiffFile { Ok(()) } - fn tile(frame: Array2, size: usize) -> Vec> { + fn tile(frame: ArrayView2, size: usize) -> Vec> { let shape = frame.shape(); let (n, m) = (shape[0] / size, shape[1] / size); let mut tiles = Vec::new(); diff --git a/src/main.rs b/src/main.rs index 449463d..4078d62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,12 +12,12 @@ fn main() -> Result<()> { arr[[i, j]] = i as u16; } } - f.save(arr.to_owned(), 0, 0, 0)?; + f.save(arr.view(), 0, 0, 0)?; let mut arr = Array2::::zeros((100, 100)); arr.slice_mut(s![64.., ..64]).fill(1); arr.slice_mut(s![..64, 64..]).fill(2); arr.slice_mut(s![64.., 64..]).fill(3); - f.save(arr.to_owned(), 1, 0, 0)?; + f.save(arr.view(), 1, 0, 0)?; Ok(()) } diff --git a/src/py.rs b/src/py.rs index ce567f2..59e3465 100644 --- a/src/py.rs +++ b/src/py.rs @@ -332,7 +332,7 @@ macro_rules! impl_save { z: usize, ) -> PyResult<()> { if let Some(ijtifffile) = self.ijtifffile.as_mut() { - ijtifffile.save(frame.to_owned_array(), c, t, z)?; + ijtifffile.save(frame.as_array(), c, t, z)?; } Ok(()) }