Skip to main content

Crate async_tiff

Crate async_tiff 

Source
Expand description

§async-tiff

An async, low-level TIFF reader for Rust and Python.

§Features

  • Async, read-only support for tiled TIFF images.
  • Read directly from object storage providers, via the object_store crate.
  • Separation of concerns between data reading and decoding so that IO-bound and CPU-bound tasks can be scheduled appropriately.
  • Support for user-defined decompression algorithms.
  • Tile request merging and concurrency.
  • Integration with the ndarray crate for easy manipulation of decoded image data.
  • Support for GeoTIFF tag metadata.
  • Supported compressions:
    • Deflate, LERC, LERC+Deflate, LERC+ZSTD, LZMA, LZW, JPEG, JPEG2000, WebP, ZSTD
    • Support for user-defined decompression algorithms.

§Example

use object_store::local::LocalFileSystem;
use async_tiff::metadata::TiffMetadataReader;
use async_tiff::metadata::cache::ReadaheadMetadataCache;
use async_tiff::reader::ObjectReader;
use async_tiff::TIFF;

let store = Arc::new(LocalFileSystem::new_with_prefix(current_dir().unwrap()).unwrap());
let reader = ObjectReader::new(store, "fixtures/image-tiff/tiled-jpeg-rgb-u8.tif".into());
let cache = ReadaheadMetadataCache::new(reader.clone());

let mut meta = TiffMetadataReader::try_open(&cache).await.unwrap();
let ifds = meta.read_all_ifds(&cache).await.unwrap();
let tiff = TIFF::new(ifds, meta.endianness());

// Fetch and decode a tile
let tile = tiff.ifds()[0].fetch_tile(0, 0, &reader).await.unwrap();
let array = tile.decode(&Default::default()).unwrap();
println!("shape: {:?}, dtype: {:?}", array.shape(), array.data_type());

§Background

The existing tiff crate is great, but only supports synchronous reading of TIFF files. Furthermore, due to low maintenance bandwidth it is not designed for extensibility (see #250).

This crate was initially forked from the tiff crate, and still maintains some of its TIFF tag parsing code.

Modules§

decoder
Decoders for different TIFF compression methods.
error
Error handling.
geo
Support for GeoTIFF files.
metadata
API for reading metadata out of a TIFF file.
reader
Abstractions for network reading.
tags
TIFF tag definitions and enum types.

Structs§

Array
A 3D array that represents decoded TIFF image data.
ImageFileDirectory
An ImageFileDirectory representing Image content
TIFF
A TIFF file.
Tile
A TIFF Tile response.

Enums§

CompressedBytes
Compressed tile data, either as a single chunk (chunky) or multiple chunks (planar).
DataType
Supported numeric data types for array elements.
TagValue
A dynamically-typed value parsed from a TIFF IFD entry.
TileByteRange
A description of the byte ranges for a tile, which may differ based on whether the TIFF is in chunky or planar format.
TilesByteRanges
A description of the byte ranges for multiple tiles
TypedArray
An enum representing a typed view of the array data.