Repository navigation
feat: Expose API to find byte range of an internal COG tile - #261
Conversation
|
|
||
| impl CompressedBytes { | ||
| fn into_tile(self, x: usize, y: usize, ifd: &ImageFileDirectory) -> Tile { | ||
| let data_type = DataType::from_tags(&ifd.sample_format, &ifd.bits_per_sample); |
There was a problem hiding this comment.
A downside here is that after this refactor we call DataType::from_tags and PredictorInfo::from_ifd once per tile instead of just once. These are simple functions so it shouldn't be much of a difference, and it's worth it for this cleaner code. In the future we could clean it up further
There was a problem hiding this comment.
At least it will handle the super rare case where each ifd has a separate dtype 😆
There was a problem hiding this comment.
Well previously it was once per request (amortized across multiple tiles in fetch_tiles), now it's per-tile.
|
|
||
| impl CompressedBytes { | ||
| fn into_tile(self, x: usize, y: usize, ifd: &ImageFileDirectory) -> Tile { | ||
| let data_type = DataType::from_tags(&ifd.sample_format, &ifd.bits_per_sample); |
There was a problem hiding this comment.
At least it will handle the super rare case where each ifd has a separate dtype 😆
| fn tiles_byte_ranges(&self, xy: Vec<(usize, usize)>) -> PyAsyncTiffResult<PyTilesByteRanges> { | ||
| let byte_ranges = self | ||
| .ifd | ||
| .tiles_byte_ranges(&xy) | ||
| .ok_or(PyValueError::new_err("Not a tiled tiff"))?; | ||
| Ok(PyTilesByteRanges(byte_ranges)) | ||
| } |
There was a problem hiding this comment.
I guess a question for @maxrjones, does virtual-tiff need the merged/coalesced byte ranges from multiple tiles? Or just the (start, end) / (offset, length) for each tile? Also not a fan of the list[list[(start, end)]] nesting 🙂
There was a problem hiding this comment.
I would like to be able to batch chunk (in zarr land) requests to get the byte ranges associated with multiple tiles (in tiff land). I wasn't expecting those to be merged/coalesced.
There was a problem hiding this comment.
Oh sorry, I don't think there's merging/coalescing here. Just a list of the byte ranges (or a list of list of byte ranges in the case of planar config).
There was a problem hiding this comment.
I would use the list of byte ranges, but could also work around its absence. I find the dynamic return type more confusing than the alternative of two functions (e.g., #257 (comment)).
There was a problem hiding this comment.
I find the dynamic return type more confusing than the alternative of two functions
Well, here in the Python API we're emulating a Rust enum. I like the single-function approach because it doesn't require the caller to know/check in advance what interleaving the image is using. We could make the return type have two different classes, or dicts.
There was a problem hiding this comment.
This PR also changes the Rust side to only have a single helper function, which is much cleaner on the Rust side than having these two parallel functions. So following from that decision we just need to figure out the best Python API
| fn tiles_byte_ranges(&self, xy: Vec<(usize, usize)>) -> PyAsyncTiffResult<PyTilesByteRanges> { | ||
| let byte_ranges = self | ||
| .ifd | ||
| .tiles_byte_ranges(&xy) | ||
| .ok_or(PyValueError::new_err("Not a tiled tiff"))?; | ||
| Ok(PyTilesByteRanges(byte_ranges)) | ||
| } |
There was a problem hiding this comment.
Oh sorry, I don't think there's merging/coalescing here. Just a list of the byte ranges (or a list of list of byte ranges in the case of planar config).
Change list
TileByteRangeandTilesByteRangesenums (overchunkyandplanarvariants) that hold various byte rangesinto_fetchprivate methods for each of those that manage calling the underlying reader'sget_byte_range/get_byte_rangescallsfetch_tileandfetch_tilesvery small.Tileby addingCompressedBytes::into_tileThe last commit also exposed them to Python where:
ifd.tile_byte_range(x, y) returns either(start, end) orlist[(start, end)]We could switch to some sort of discriminated union, or, perhaps it's best to only expose to Python the single-tile byte range, not the multi-tile byte range.
We also still need to update the type hints in the pyi