diff --git a/Cargo.toml b/Cargo.toml index 3f8fc35..d1fc5a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiffwrite" -version = "2026.5.0" +version = "2026.5.1" edition = "2024" rust-version = "1.88.0" authors = ["Wim Pomp "] diff --git a/README.md b/README.md index 81ce6fd..451c351 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ makes that very hard anyway. or - install [rust](https://rustup.rs/) -- ``` pip install tiffwrite@git+https://github.com/wimpomp/tiffwrite ``` +- ``` pip install tiffwrite@git+https://git.wimpomp.nl/wim/tiffwrite ``` ## Usage ### Write an image stack diff --git a/pyproject.toml b/pyproject.toml index d6d162f..5474fc2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,10 +29,6 @@ dependencies = ["numpy", "tqdm"] [project.optional-dependencies] test = ["pytest", "tifffile", "imagecodecs"] -[project.urls] -homepage = "https://github.com/wimpomp/tiffwrite" -repository = "https://github.com/wimpomp/tiffwrite" - [project.scripts] tiffwrite_generate_stub = "tiffwrite:tiffwrite_generate_stub" diff --git a/src/lib.rs b/src/lib.rs index 079d36c..1156a26 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ use colorgrad::{Gradient, LinearGradient}; use css_color::Srgb; use flate2::write::ZlibEncoder; use lazy_static::lazy_static; -use ndarray::{ArcArray2, AsArray, Ix2, s}; +use ndarray::{Array, Array2, ArrayView, ArrayView2, Dimension, Ix2, s}; use num::{Complex, FromPrimitive, Rational32, traits::ToBytes}; use rayon::prelude::*; use std::collections::HashSet; @@ -380,7 +380,7 @@ impl Frame { fn new( hashes: Arc>>, file: Arc>>, - frame: ArcArray2, + frame: Array2, compression: Compression, ) -> Result where @@ -434,14 +434,14 @@ impl Frame { slices .into_par_iter() .map(|slice| { - Frame::compress_tile_deflate(frame.clone(), slice, tile_size, tile_size) + Frame::compress_tile_deflate(frame.view(), slice, tile_size, tile_size) }) .collect::, Error>>()? } else { slices .into_iter() .map(|slice| { - Frame::compress_tile_deflate(frame.clone(), slice, tile_size, tile_size) + Frame::compress_tile_deflate(frame.view(), slice, tile_size, tile_size) }) .collect::, Error>>()? } @@ -453,7 +453,7 @@ impl Frame { .into_par_iter() .map(|slice| { Frame::compress_tile_zstd( - frame.clone(), + frame.view(), slice, tile_size, tile_size, @@ -466,7 +466,7 @@ impl Frame { .into_iter() .map(|slice| { Frame::compress_tile_zstd( - frame.clone(), + frame.view(), slice, tile_size, tile_size, @@ -501,7 +501,7 @@ impl Frame { fn encode( mut encoder: W, - frame: ArcArray2, + frame: ArrayView2, slice: (usize, usize, usize, usize), tile_width: usize, tile_length: usize, @@ -532,7 +532,7 @@ impl Frame { } fn compress_tile_deflate( - frame: ArcArray2, + frame: ArrayView2, slice: (usize, usize, usize, usize), tile_width: usize, tile_length: usize, @@ -546,7 +546,7 @@ impl Frame { } fn compress_tile_zstd( - frame: ArcArray2, + frame: ArrayView2, slice: (usize, usize, usize, usize), tile_width: usize, tile_length: usize, @@ -621,6 +621,47 @@ pub enum Colors { Colormap(Vec>), } +/// Clone if array is a view, do not clone if array is owned already. +pub trait IntoOwnedArray { + fn into_owned(self) -> Array; +} + +impl IntoOwnedArray for Array { + fn into_owned(self) -> Array { + self + } +} + +impl IntoOwnedArray for &Array +where + T: Clone, + D: Dimension, +{ + fn into_owned(self) -> Array { + self.to_owned() + } +} + +impl IntoOwnedArray for ArrayView<'_, T, D> +where + T: Clone, + D: Dimension, +{ + fn into_owned(self) -> Array { + self.to_owned() + } +} + +impl IntoOwnedArray for &ArrayView<'_, T, D> +where + T: Clone, + D: Dimension, +{ + fn into_owned(self) -> Array { + self.to_owned() + } +} + /// save 2d arrays in a tif file compatible with Fiji/ImageJ #[derive(Debug)] pub struct IJTiffFile { @@ -842,15 +883,15 @@ impl IJTiffFile { } /// save a 2d array to the tiff file at channel c, slice z, and time t - pub fn save<'a, A, T>(&mut self, frame: A, c: usize, z: usize, t: usize) -> Result<(), Error> + pub fn save(&mut self, frame: A, c: usize, z: usize, t: usize) -> Result<(), Error> where - A: AsArray<'a, T, Ix2>, + A: IntoOwnedArray, T: Bytes + Clone + Send + Sync + 'static, { self.collect_threads(false, usize::from(available_parallelism()?))?; let hashes = self.hashes.clone(); let file = self.file.clone(); - let frame = frame.into().to_shared(); + let frame = frame.into_owned(); let compression = self.compression; self.threads.insert( (c, z, t),