Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ reqwest = { version = "0.12", default-features = false, optional = true }
thiserror = "1"
tokio = { version = "1.43.0", default-features = false, features = ["sync"] }
weezl = "0.1.0"
zstd = "0.13"

[dev-dependencies]
object_store = { version = "0.12", features = ["http"] }
Expand Down
21 changes: 20 additions & 1 deletion src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ impl AsMut<HashMap<CompressionMethod, Box<dyn Decoder>>> for DecoderRegistry {

impl Default for DecoderRegistry {
fn default() -> Self {
let mut registry = HashMap::with_capacity(5);
let mut registry = HashMap::with_capacity(6);
registry.insert(CompressionMethod::None, Box::new(UncompressedDecoder) as _);
registry.insert(CompressionMethod::Deflate, Box::new(DeflateDecoder) as _);
registry.insert(CompressionMethod::OldDeflate, Box::new(DeflateDecoder) as _);
registry.insert(CompressionMethod::LZW, Box::new(LZWDecoder) as _);
registry.insert(CompressionMethod::ModernJPEG, Box::new(JPEGDecoder) as _);
registry.insert(CompressionMethod::ZSTD, Box::new(ZstdDecoder) as _);
Self(registry)
}
}
Expand Down Expand Up @@ -125,6 +126,24 @@ impl Decoder for UncompressedDecoder {
}
}

/// A decoder for the Zstd compression method.
#[derive(Debug, Clone)]
pub struct ZstdDecoder;

impl Decoder for ZstdDecoder {
fn decode_tile(
&self,
buffer: Bytes,
_photometric_interpretation: PhotometricInterpretation,
_jpeg_tables: Option<&[u8]>,
) -> AsyncTiffResult<Bytes> {
let mut decoder = zstd::Decoder::new(Cursor::new(buffer))?;
let mut buf = Vec::new();
decoder.read_to_end(&mut buf)?;
Ok(buf.into())
}
}

// https://github.com/image-rs/image-tiff/blob/3bfb43e83e31b0da476832067ada68a82b378b7b/src/decoder/image.rs#L389-L450
fn decode_modern_jpeg(
buf: Bytes,
Expand Down
11 changes: 11 additions & 0 deletions tests/image_tiff/decode_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ async fn test_int16_rgb() {
assert!(ifd.bits_per_sample().iter().all(|x| *x == 16));
}

#[tokio::test]
async fn test_zstd_compression() {
let tiff = open_tiff("int16_zstd.tif").await;
let ifd = &tiff.ifds()[0];
assert!(matches!(
ifd.photometric_interpretation(),
PhotometricInterpretation::BlackIsZero
));
assert!(ifd.bits_per_sample().iter().all(|x| *x == 16));
}

#[tokio::test]
async fn test_string_tags() {
// these files have null-terminated strings for their Software tag. One has extra bytes after
Expand Down
Loading