| 1 |
extern crate tiff; |
| 2 |
|
| 3 |
use tiff::decoder::{Decoder, DecodingResult}; |
| 4 |
use tiff::tags::Tag; |
| 5 |
use tiff::ColorType; |
| 6 |
|
| 7 |
use std::fs::File; |
| 8 |
use std::path::PathBuf; |
| 9 |
|
| 10 |
const TEST_IMAGE_DIR: &str = "./tests/images"; |
| 11 |
|
| 12 |
#[test] |
| 13 |
fn test_geo_tiff() { |
| 14 |
let filenames = ["geo-5b.tif"]; |
| 15 |
for filename in filenames.iter() { |
| 16 |
let path = PathBuf::from(TEST_IMAGE_DIR).join(filename); |
| 17 |
let img_file = File::open(path).expect("Cannot find test image!"); |
| 18 |
let mut decoder = Decoder::new(img_file).expect("Cannot create decoder"); |
| 19 |
decoder = decoder.with_limits(tiff::decoder::Limits::unlimited()); |
| 20 |
|
| 21 |
assert_eq!( |
| 22 |
decoder.dimensions().expect("Cannot get dimensions"), |
| 23 |
(10, 10) |
| 24 |
); |
| 25 |
assert_eq!( |
| 26 |
decoder.colortype().expect("Cannot get colortype"), |
| 27 |
ColorType::Multiband { |
| 28 |
bit_depth: 16, |
| 29 |
num_samples: 5 |
| 30 |
} |
| 31 |
); |
| 32 |
assert_eq!( |
| 33 |
decoder |
| 34 |
.get_tag_u64(Tag::StripOffsets) |
| 35 |
.expect("Cannot get StripOffsets"), |
| 36 |
418 |
| 37 |
); |
| 38 |
assert_eq!( |
| 39 |
decoder |
| 40 |
.get_tag_u64(Tag::RowsPerStrip) |
| 41 |
.expect("Cannot get RowsPerStrip"), |
| 42 |
10 |
| 43 |
); |
| 44 |
assert_eq!( |
| 45 |
decoder |
| 46 |
.get_tag_u64(Tag::StripByteCounts) |
| 47 |
.expect("Cannot get StripByteCounts"), |
| 48 |
1000 |
| 49 |
); |
| 50 |
assert_eq!( |
| 51 |
decoder |
| 52 |
.get_tag(Tag::ModelPixelScaleTag) |
| 53 |
.expect("Cannot get pixel scale") |
| 54 |
.into_f64_vec() |
| 55 |
.expect("Cannot get pixel scale"), |
| 56 |
vec![60.0, 60.0, 0.0] |
| 57 |
); |
| 58 |
let DecodingResult::I16(data) = decoder.read_image().unwrap() else { |
| 59 |
panic!("Cannot read band data") |
| 60 |
}; |
| 61 |
assert_eq!(data.len(), 500); |
| 62 |
} |
| 63 |
} |