- more transforms
This commit is contained in:
@@ -389,6 +389,7 @@ impl BioFormatsJavaReader {
|
||||
|
||||
fn deinterleave(&self, bytes: Vec<u8>, channel: usize) -> Result<Vec<u8>, Error> {
|
||||
let chunk_size = match self.pixel_type {
|
||||
PixelType::Bool => 1,
|
||||
PixelType::I8 => 1,
|
||||
PixelType::U8 => 1,
|
||||
PixelType::I16 => 2,
|
||||
@@ -413,6 +414,26 @@ impl BioFormatsJavaReader {
|
||||
|
||||
fn bytes_to_frame(&self, bytes: Vec<u8>) -> Result<Frame, Error> {
|
||||
macro_rules! get_frame {
|
||||
(bool, <$n:expr) => {
|
||||
Ok(ArrayT::from(Array2::from_shape_vec(
|
||||
(self.shape.y, self.shape.x),
|
||||
bytes
|
||||
.iter()
|
||||
.map(|x| [x & 128, x & 64, x & 32, x & 16, x & 8, x & 4, x & 2, x & 1])
|
||||
.flatten()
|
||||
.collect(),
|
||||
)?))
|
||||
};
|
||||
(bool, >$n:expr) => {
|
||||
Ok(ArrayT::from(Array2::from_shape_vec(
|
||||
(self.shape.y, self.shape.x),
|
||||
bytes
|
||||
.iter()
|
||||
.map(|x| [x & 1, x & 2, x & 4, x & 8, x & 16, x & 32, x & 64, x & 128])
|
||||
.flatten()
|
||||
.collect(),
|
||||
)?))
|
||||
};
|
||||
($t:tt, <$n:expr) => {
|
||||
Ok(ArrayT::from(Array2::from_shape_vec(
|
||||
(self.shape.y, self.shape.x),
|
||||
@@ -434,6 +455,7 @@ impl BioFormatsJavaReader {
|
||||
}
|
||||
|
||||
match (&self.pixel_type, self.little_endian) {
|
||||
(PixelType::Bool, true) => get_frame!(bool, <1),
|
||||
(PixelType::I8, true) => get_frame!(i8, <1),
|
||||
(PixelType::U8, true) => get_frame!(u8, <1),
|
||||
(PixelType::I16, true) => get_frame!(i16, <2),
|
||||
@@ -447,6 +469,7 @@ impl BioFormatsJavaReader {
|
||||
(PixelType::I128, true) => get_frame!(i128, <16),
|
||||
(PixelType::U128, true) => get_frame!(u128, <16),
|
||||
(PixelType::F128, true) => get_frame!(f64, <8),
|
||||
(PixelType::Bool, false) => get_frame!(bool, >1),
|
||||
(PixelType::I8, false) => get_frame!(i8, >1),
|
||||
(PixelType::U8, false) => get_frame!(u8, >1),
|
||||
(PixelType::I16, false) => get_frame!(i16, >2),
|
||||
@@ -501,7 +524,7 @@ impl Reader for BioFormatsJavaReader {
|
||||
Error::FileDoesNotExist(orig.join("**").join("*.tif").display().to_string())
|
||||
})?;
|
||||
}
|
||||
let mut new = BioFormatsJavaReader {
|
||||
let mut new = Self {
|
||||
reader: ThreadLocal::default(),
|
||||
path,
|
||||
series,
|
||||
|
||||
Reference in New Issue
Block a user