| 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/geotiff"; |
| 11 |
|
| 12 |
#[test] |
| •13 |
#[ignore = "skipping, missing test data"] |
| 14 |
fn test_geo_tiff() { |
| 15 |
let filenames = ["geo-5b.tif"]; |
| 16 |
for filename in filenames.iter() { |
| 17 |
let path = PathBuf::from(TEST_IMAGE_DIR).join(filename); |
| 18 |
let img_file = File::open(path).expect("Cannot find test image!"); |
| 19 |
let mut decoder = Decoder::new(img_file).expect("Cannot create decoder"); |
| 20 |
decoder = decoder.with_limits(tiff::decoder::Limits::unlimited()); |
| 21 |
|
| 22 |
assert_eq!( |
| 23 |
decoder.dimensions().expect("Cannot get dimensions"), |
| 24 |
(10, 10) |
| 25 |
); |
| 26 |
assert_eq!( |
| 27 |
decoder.colortype().expect("Cannot get colortype"), |
| 28 |
ColorType::Multiband { |
| 29 |
bit_depth: 16, |
| 30 |
num_samples: 5 |
| 31 |
} |
| 32 |
); |
| 33 |
assert_eq!( |
| 34 |
decoder |
| 35 |
.get_tag_u64(Tag::StripOffsets) |
| 36 |
.expect("Cannot get StripOffsets"), |
| 37 |
418 |
| 38 |
); |
| 39 |
assert_eq!( |
| 40 |
decoder |
| 41 |
.get_tag_u64(Tag::RowsPerStrip) |
| 42 |
.expect("Cannot get RowsPerStrip"), |
| 43 |
10 |
| 44 |
); |
| 45 |
assert_eq!( |
| 46 |
decoder |
| 47 |
.get_tag_u64(Tag::StripByteCounts) |
| 48 |
.expect("Cannot get StripByteCounts"), |
| 49 |
1000 |
| 50 |
); |
| 51 |
assert_eq!( |
| 52 |
decoder |
| 53 |
.get_tag(Tag::ModelPixelScaleTag) |
| 54 |
.expect("Cannot get pixel scale") |
| 55 |
.into_f64_vec() |
| 56 |
.expect("Cannot get pixel scale"), |
| 57 |
vec![60.0, 60.0, 0.0] |
| 58 |
); |
| 59 |
let DecodingResult::I16(data) = decoder.read_image().unwrap() else { |
| 60 |
panic!("Cannot read band data") |
| 61 |
}; |
| 62 |
assert_eq!(data.len(), 500); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
#[cfg(feature = "webp")] |
| 67 |
#[test] |
| •68 |
#[ignore = "skipping, missing test data"] |
| 69 |
fn test_webp_tiff() { |
| 70 |
let filenames = ["usda_naip_256_webp_z3.tif"]; |
| 71 |
let mut buffer = DecodingResult::U8(vec![]); |
| 72 |
|
| 73 |
for filename in filenames.iter() { |
| 74 |
let path = PathBuf::from(TEST_IMAGE_DIR).join(filename); |
| 75 |
let img_file = File::open(path).expect("Cannot find test image!"); |
| 76 |
let mut decoder = Decoder::new(img_file).expect("Cannot create decoder"); |
| 77 |
|
| 78 |
loop { |
| 79 |
decoder.read_image_to_buffer(&mut buffer).unwrap(); |
| 80 |
|
| 81 |
if !decoder.more_images() { |
| 82 |
break; |
| 83 |
} |
| 84 |
|
| 85 |
decoder.next_image().unwrap(); |
| 86 |
} |
| 87 |
} |
| 88 |
} |