-
Notifications
You must be signed in to change notification settings - Fork 2
Test opening single-channel OME-TIFF file #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// Integration tests on OME-TIFF files. | ||
use async_tiff::tiff::tags::PhotometricInterpretation; | ||
|
||
mod util; | ||
|
||
#[tokio::test] | ||
async fn test_ome_tiff_single_channel() { | ||
let tiff = | ||
util::open_remote_tiff("https://downloads.openmicroscopy.org/images/OME-TIFF/2016-06/bioformats-artificial/single-channel.ome.tif").await; | ||
|
||
assert_eq!(tiff.ifds().len(), 1); | ||
let ifd = &tiff.ifds()[0]; | ||
|
||
assert_eq!( | ||
ifd.photometric_interpretation(), | ||
PhotometricInterpretation::BlackIsZero | ||
); | ||
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>")); | ||
|
||
assert!(ifd.bits_per_sample().iter().all(|x| *x == 8)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use std::sync::Arc; | ||
|
||
use async_tiff::metadata::{PrefetchBuffer, TiffMetadataReader}; | ||
use async_tiff::reader::{AsyncFileReader, ObjectReader}; | ||
use async_tiff::TIFF; | ||
use reqwest::Url; | ||
|
||
pub(crate) async fn open_remote_tiff(url: &str) -> TIFF { | ||
let parsed_url = Url::parse(url).expect("failed parsing url"); | ||
let (store, path) = object_store::parse_url(&parsed_url).unwrap(); | ||
|
||
let reader = Arc::new(ObjectReader::new(Arc::new(store), path)) as Arc<dyn AsyncFileReader>; | ||
let prefetch_reader = PrefetchBuffer::new(reader.clone(), 32 * 1024) | ||
.await | ||
.unwrap(); | ||
let mut metadata_reader = TiffMetadataReader::try_open(&prefetch_reader) | ||
.await | ||
.unwrap(); | ||
let ifds = metadata_reader | ||
.read_all_ifds(&prefetch_reader) | ||
.await | ||
.unwrap(); | ||
TIFF::new(ifds) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think it would be better to either check in this file into this repo, or perhaps create an
async-tiff-fixtures
separate repo that we can check data into.Assuming this file is large, it would be great if we could extract like a one-pixel or very small subset of this file, while maintaining all header metadata the same.
Or, we could find the size of the last IFD and just clip the existing buffer to that region. So all IFD parsing would succeed but any image loading would fail as the image data is past the byte region checked in to the test fixture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is 74.3KB, not huge but having many test files like these will add up (the vendored images from #28 add up to 4.5MB already 🙂).
Probably best to bring this discussion over to #23.