diff --git a/Cargo.toml b/Cargo.toml index baf432f..be4f4dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ exclude = ["tests/images/*", "tests/fuzz_images/*"] weezl = "0.1.0" jpeg = { package = "jpeg-decoder", version = "0.3.0", default-features = false } flate2 = "1.0.20" +zstd = "0.13" [dev-dependencies] criterion = "0.3.1" diff --git a/src/decoder/image.rs b/src/decoder/image.rs index 1a61640..07ef34e 100644 --- a/src/decoder/image.rs +++ b/src/decoder/image.rs @@ -378,7 +378,10 @@ impl Image { CompressionMethod::None => Box::new(reader), CompressionMethod::LZW => { Box::new(LZWReader::new(reader, usize::try_from(compressed_length)?)) - } + }, + CompressionMethod::ZSTD => { + Box::new(zstd::Decoder::new(reader)?) + }, CompressionMethod::PackBits => Box::new(PackBitsReader::new(reader, compressed_length)), CompressionMethod::Deflate | CompressionMethod::OldDeflate => { Box::new(DeflateReader::new(reader)) diff --git a/src/tags.rs b/src/tags.rs index 6c18fa5..81169ca 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -184,6 +184,9 @@ pub enum CompressionMethod(u16) unknown("A custom compression method") { Deflate = 8, OldDeflate = 0x80B2, PackBits = 0x8005, + + // Self-assigned by libtiff + ZSTD = 0xC350, } } diff --git a/tests/decode_images.rs b/tests/decode_images.rs index 1c769d0..f037ca3 100644 --- a/tests/decode_images.rs +++ b/tests/decode_images.rs @@ -515,3 +515,9 @@ fn test_predictor_3_rgb_f32() { fn test_predictor_3_gray_f32() { test_image_sum_f32("predictor-3-gray-f32.tif", ColorType::Gray(32), 20008.275); } + +#[test] +fn test_zstd_compression() { + // gdal_translate -co COMPRESS=ZSTD -co ZSTD_LEVEL=20 int16.tif int16_zstd.tif + test_image_sum_i16("int16_zstd.tif", ColorType::Gray(16), 354396); +} diff --git a/tests/images/int16_zstd.tif b/tests/images/int16_zstd.tif new file mode 100644 index 0000000..c1093e4 Binary files /dev/null and b/tests/images/int16_zstd.tif differ