The bounds `Read + Seek` are not representational so we may remove them from the struct itself. This also allows us to use more precise bounds for direct access to the inner stream, especially were that does not seek. Groups operations according to their use case.
81 lines
2.4 KiB
Rust
81 lines
2.4 KiB
Rust
extern crate tiff;
|
|
|
|
use tiff::decoder::{Decoder, DecodingSampleBuffer};
|
|
use tiff::tags::Tag;
|
|
use tiff::ColorType;
|
|
|
|
use std::fs::File;
|
|
use std::path::PathBuf;
|
|
|
|
const TEST_IMAGE_DIR: &str = "./tests/geotiff";
|
|
|
|
#[test]
|
|
fn test_geo_tiff() {
|
|
let filenames = ["geo-5b.tif"];
|
|
for filename in filenames.iter() {
|
|
let path = PathBuf::from(TEST_IMAGE_DIR).join(filename);
|
|
let img_file = File::open(path).expect("Cannot find test image!");
|
|
let mut decoder = Decoder::open(img_file).expect("Cannot create decoder");
|
|
decoder = decoder.with_limits(tiff::decoder::Limits::unlimited());
|
|
decoder.next_image().expect("Cannot read image");
|
|
|
|
assert_eq!(
|
|
decoder.dimensions().expect("Cannot get dimensions"),
|
|
(10, 10)
|
|
);
|
|
assert_eq!(
|
|
decoder.colortype().expect("Cannot get colortype"),
|
|
ColorType::Multiband {
|
|
bit_depth: 16,
|
|
num_samples: 5
|
|
}
|
|
);
|
|
|
|
let mut ifd = decoder.current_ifd();
|
|
assert_eq!(
|
|
ifd.get_tag_u64(Tag::StripOffsets)
|
|
.expect("Cannot get StripOffsets"),
|
|
418
|
|
);
|
|
assert_eq!(
|
|
ifd.get_tag_u64(Tag::RowsPerStrip)
|
|
.expect("Cannot get RowsPerStrip"),
|
|
10
|
|
);
|
|
assert_eq!(
|
|
ifd.get_tag_u64(Tag::StripByteCounts)
|
|
.expect("Cannot get StripByteCounts"),
|
|
1000
|
|
);
|
|
assert_eq!(
|
|
ifd.get_tag(Tag::ModelPixelScaleTag)
|
|
.expect("Cannot get pixel scale")
|
|
.into_f64_vec()
|
|
.expect("Cannot get pixel scale"),
|
|
vec![60.0, 60.0, 0.0]
|
|
);
|
|
let DecodingSampleBuffer::I16(data) = decoder.read_image().unwrap() else {
|
|
panic!("Cannot read band data")
|
|
};
|
|
assert_eq!(data.len(), 500);
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "webp")]
|
|
#[test]
|
|
fn test_webp_tiff() {
|
|
let filenames = ["usda_naip_256_webp_z3.tif"];
|
|
let mut buffer = DecodingSampleBuffer::U8(vec![]);
|
|
|
|
for filename in filenames.iter() {
|
|
let path = PathBuf::from(TEST_IMAGE_DIR).join(filename);
|
|
let img_file = File::open(path).expect("Cannot find test image!");
|
|
let mut decoder = Decoder::open(img_file).expect("Cannot create decoder");
|
|
|
|
while decoder.more_images() {
|
|
decoder.next_image().unwrap();
|
|
decoder.read_image_to_buffer(&mut buffer).unwrap();
|
|
}
|
|
}
|
|
}
|