Skip to content

Commit b1ee9ac

Browse files
authored
Test opening single-channel OME-TIFF file (#102)
* Add utility function to read TIFF files from remote object stores Also enable http feature for object_store * Add test for opening single-channel OME-TIFF file
1 parent 6b7df90 commit b1ee9ac

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tokio = { version = "1.43.0", optional = true, default-features = false, feature
2525
weezl = "0.1.0"
2626

2727
[dev-dependencies]
28-
object_store = "0.12"
28+
object_store = { version = "0.12", features = ["http"] }
2929
tiff = "0.9.1"
3030
tokio = { version = "1.9", features = [
3131
"macros",

tests/ome_tiff.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// Integration tests on OME-TIFF files.
2+
use async_tiff::tiff::tags::PhotometricInterpretation;
3+
4+
mod util;
5+
6+
#[tokio::test]
7+
async fn test_ome_tiff_single_channel() {
8+
let tiff =
9+
util::open_remote_tiff("https://downloads.openmicroscopy.org/images/OME-TIFF/2016-06/bioformats-artificial/single-channel.ome.tif").await;
10+
11+
assert_eq!(tiff.ifds().len(), 1);
12+
let ifd = &tiff.ifds()[0];
13+
14+
assert_eq!(
15+
ifd.photometric_interpretation(),
16+
PhotometricInterpretation::BlackIsZero
17+
);
18+
assert_eq!(ifd.image_description(), Some("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!-- Warning: this comment is an OME-XML metadata block, which contains crucial dimensional parameters and other important metadata. Please edit cautiously (if at all), and back up the original data before doing so. For more information, see the OME-TIFF web site: http://www.openmicroscopy.org/site/support/ome-model/ome-tiff/. --><OME xmlns=\"http://www.openmicroscopy.org/Schemas/OME/2016-06\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" Creator=\"OME Bio-Formats 5.2.2\" UUID=\"urn:uuid:2bc2aa39-30d2-44ee-8399-c513492dd5de\" xsi:schemaLocation=\"http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd\"><Image ID=\"Image:0\" Name=\"single-channel.ome.tif\"><Pixels BigEndian=\"true\" DimensionOrder=\"XYZCT\" ID=\"Pixels:0\" SizeC=\"1\" SizeT=\"1\" SizeX=\"439\" SizeY=\"167\" SizeZ=\"1\" Type=\"int8\"><Channel ID=\"Channel:0:0\" SamplesPerPixel=\"1\"><LightPath/></Channel><TiffData FirstC=\"0\" FirstT=\"0\" FirstZ=\"0\" IFD=\"0\" PlaneCount=\"1\"><UUID FileName=\"single-channel.ome.tif\">urn:uuid:2bc2aa39-30d2-44ee-8399-c513492dd5de</UUID></TiffData></Pixels></Image></OME>"));
19+
20+
assert!(ifd.bits_per_sample().iter().all(|x| *x == 8));
21+
}

tests/util/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::sync::Arc;
2+
3+
use async_tiff::metadata::{PrefetchBuffer, TiffMetadataReader};
4+
use async_tiff::reader::{AsyncFileReader, ObjectReader};
5+
use async_tiff::TIFF;
6+
use reqwest::Url;
7+
8+
pub(crate) async fn open_remote_tiff(url: &str) -> TIFF {
9+
let parsed_url = Url::parse(url).expect("failed parsing url");
10+
let (store, path) = object_store::parse_url(&parsed_url).unwrap();
11+
12+
let reader = Arc::new(ObjectReader::new(Arc::new(store), path)) as Arc<dyn AsyncFileReader>;
13+
let prefetch_reader = PrefetchBuffer::new(reader.clone(), 32 * 1024)
14+
.await
15+
.unwrap();
16+
let mut metadata_reader = TiffMetadataReader::try_open(&prefetch_reader)
17+
.await
18+
.unwrap();
19+
let ifds = metadata_reader
20+
.read_all_ifds(&prefetch_reader)
21+
.await
22+
.unwrap();
23+
TIFF::new(ifds)
24+
}

0 commit comments

Comments
 (0)