Debian Codegraph @

.cargo/vendor/tiff/tests/subsubifds.rs

raw
1 use tiff::decoder::Decoder;
2
3 // This file has the following IFD structure:
4 //
5 // ```
6 // IFD -> IFD -> IFD
7 // |-> IFD
8 // |-> IFD -> IFD
9 // | \-> IFD -> IFD
10 // \-> IFD
11 // ```
12 //
13 // where the main chain of IFD has 3 images, the second of which has several sub-IFDs and some have
14 // more nested IFDs.
15 const TEST_IMAGE_SUBIFD: &str = "./tests/subsubifds.tif";
16 use std::fs::File;
17
18 #[test]
19 fn decode_seek_chain() {
20 let file = File::open(TEST_IMAGE_SUBIFD).expect("Cannot open test image");
21 let mut decoder = Decoder::new(file).expect("Invalid format to create decoder");
22
23 // Remember the offsets in the first iteration.
24 let offset0 = decoder.ifd_pointer().expect("First IFD pointer not found");
25 decoder.next_image().unwrap();
26 let offset1 = decoder.ifd_pointer().expect("Second IFD pointer not found");
27 decoder.next_image().unwrap();
28 let offset2 = decoder.ifd_pointer().expect("Third IFD pointer not found");
29 assert!(!decoder.more_images());
30
31 // Ensure we can seek, to do this again.
32 decoder
33 .seek_to_image(0)
34 .expect("Failed to seek to first image");
35 assert_eq!(Some(offset0), decoder.ifd_pointer());
36 decoder.next_image().unwrap();
37 assert_eq!(Some(offset1), decoder.ifd_pointer());
38 decoder.next_image().unwrap();
39 assert_eq!(Some(offset2), decoder.ifd_pointer());
40 assert!(!decoder.more_images());
41 }