/rust/registry/src/index.crates.io-6f17d22bba15001f/tiff-0.10.0/src/decoder/stream.rs
Line | Count | Source (jump to first uncovered line) |
1 | | //! All IO functionality needed for TIFF decoding |
2 | | |
3 | | use std::io::{self, BufRead, BufReader, Read, Seek, Take}; |
4 | | |
5 | | /// Byte order of the TIFF file. |
6 | | #[derive(Clone, Copy, Debug)] |
7 | | pub enum ByteOrder { |
8 | | /// little endian byte order |
9 | | LittleEndian, |
10 | | /// big endian byte order |
11 | | BigEndian, |
12 | | } |
13 | | |
14 | | /// Reader that is aware of the byte order. |
15 | | #[derive(Debug)] |
16 | | pub struct EndianReader<R> { |
17 | | reader: R, |
18 | | pub(crate) byte_order: ByteOrder, |
19 | | } |
20 | | |
21 | | impl<R: Read + Seek> EndianReader<R> { |
22 | 0 | pub fn new(reader: R, byte_order: ByteOrder) -> Self { |
23 | 0 | Self { reader, byte_order } |
24 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::new Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::new |
25 | | |
26 | 0 | pub fn inner(&mut self) -> &mut R { |
27 | 0 | &mut self.reader |
28 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::inner Unexecuted instantiation: <tiff::decoder::stream::EndianReader<_>>::inner Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::inner Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::inner Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::inner Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::inner Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::inner Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::inner Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::inner Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::inner Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::inner Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::inner |
29 | | |
30 | 0 | pub fn goto_offset(&mut self, offset: u64) -> io::Result<()> { |
31 | 0 | self.reader.seek(io::SeekFrom::Start(offset))?; |
32 | 0 | Ok(()) |
33 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::goto_offset Unexecuted instantiation: <tiff::decoder::stream::EndianReader<_>>::goto_offset Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::goto_offset Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::goto_offset Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::goto_offset Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::goto_offset Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::goto_offset Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::goto_offset Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::goto_offset Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::goto_offset Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::goto_offset Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::goto_offset |
34 | | |
35 | | /// Reads an u16 |
36 | | #[inline(always)] |
37 | 0 | pub fn read_u16(&mut self) -> Result<u16, io::Error> { |
38 | 0 | let mut n = [0u8; 2]; |
39 | 0 | self.reader.read_exact(&mut n)?; |
40 | 0 | Ok(match self.byte_order { |
41 | 0 | ByteOrder::LittleEndian => u16::from_le_bytes(n), |
42 | 0 | ByteOrder::BigEndian => u16::from_be_bytes(n), |
43 | | }) |
44 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<_>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u16 |
45 | | |
46 | | /// Reads an i8 |
47 | | #[inline(always)] |
48 | 0 | pub fn read_i8(&mut self) -> Result<i8, io::Error> { |
49 | 0 | let mut n = [0u8; 1]; |
50 | 0 | self.reader.read_exact(&mut n)?; |
51 | 0 | Ok(match self.byte_order { |
52 | 0 | ByteOrder::LittleEndian => i8::from_le_bytes(n), |
53 | 0 | ByteOrder::BigEndian => i8::from_be_bytes(n), |
54 | | }) |
55 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i8 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<_>>::read_i8 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i8 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i8 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i8 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i8 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i8 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i8 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i8 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i8 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i8 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i8 |
56 | | |
57 | | /// Reads an i16 |
58 | | #[inline(always)] |
59 | 0 | pub fn read_i16(&mut self) -> Result<i16, io::Error> { |
60 | 0 | let mut n = [0u8; 2]; |
61 | 0 | self.reader.read_exact(&mut n)?; |
62 | 0 | Ok(match self.byte_order { |
63 | 0 | ByteOrder::LittleEndian => i16::from_le_bytes(n), |
64 | 0 | ByteOrder::BigEndian => i16::from_be_bytes(n), |
65 | | }) |
66 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<_>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i16 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i16 |
67 | | |
68 | | /// Reads an u32 |
69 | | #[inline(always)] |
70 | 0 | pub fn read_u32(&mut self) -> Result<u32, io::Error> { |
71 | 0 | let mut n = [0u8; 4]; |
72 | 0 | self.reader.read_exact(&mut n)?; |
73 | 0 | Ok(match self.byte_order { |
74 | 0 | ByteOrder::LittleEndian => u32::from_le_bytes(n), |
75 | 0 | ByteOrder::BigEndian => u32::from_be_bytes(n), |
76 | | }) |
77 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<_>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u32 |
78 | | |
79 | | /// Reads an i32 |
80 | | #[inline(always)] |
81 | 0 | pub fn read_i32(&mut self) -> Result<i32, io::Error> { |
82 | 0 | let mut n = [0u8; 4]; |
83 | 0 | self.reader.read_exact(&mut n)?; |
84 | 0 | Ok(match self.byte_order { |
85 | 0 | ByteOrder::LittleEndian => i32::from_le_bytes(n), |
86 | 0 | ByteOrder::BigEndian => i32::from_be_bytes(n), |
87 | | }) |
88 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<_>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i32 |
89 | | |
90 | | /// Reads an u64 |
91 | | #[inline(always)] |
92 | 0 | pub fn read_u64(&mut self) -> Result<u64, io::Error> { |
93 | 0 | let mut n = [0u8; 8]; |
94 | 0 | self.reader.read_exact(&mut n)?; |
95 | 0 | Ok(match self.byte_order { |
96 | 0 | ByteOrder::LittleEndian => u64::from_le_bytes(n), |
97 | 0 | ByteOrder::BigEndian => u64::from_be_bytes(n), |
98 | | }) |
99 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<_>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_u64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_u64 |
100 | | |
101 | | /// Reads an i64 |
102 | | #[inline(always)] |
103 | 0 | pub fn read_i64(&mut self) -> Result<i64, io::Error> { |
104 | 0 | let mut n = [0u8; 8]; |
105 | 0 | self.reader.read_exact(&mut n)?; |
106 | 0 | Ok(match self.byte_order { |
107 | 0 | ByteOrder::LittleEndian => i64::from_le_bytes(n), |
108 | 0 | ByteOrder::BigEndian => i64::from_be_bytes(n), |
109 | | }) |
110 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<_>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_i64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_i64 |
111 | | |
112 | | /// Reads an f32 |
113 | | #[inline(always)] |
114 | 0 | pub fn read_f32(&mut self) -> Result<f32, io::Error> { |
115 | 0 | let mut n = [0u8; 4]; |
116 | 0 | self.reader.read_exact(&mut n)?; |
117 | 0 | Ok(f32::from_bits(match self.byte_order { |
118 | 0 | ByteOrder::LittleEndian => u32::from_le_bytes(n), |
119 | 0 | ByteOrder::BigEndian => u32::from_be_bytes(n), |
120 | | })) |
121 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<_>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f32 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f32 |
122 | | |
123 | | /// Reads an f64 |
124 | | #[inline(always)] |
125 | 0 | pub fn read_f64(&mut self) -> Result<f64, io::Error> { |
126 | 0 | let mut n = [0u8; 8]; |
127 | 0 | self.reader.read_exact(&mut n)?; |
128 | 0 | Ok(f64::from_bits(match self.byte_order { |
129 | 0 | ByteOrder::LittleEndian => u64::from_le_bytes(n), |
130 | 0 | ByteOrder::BigEndian => u64::from_be_bytes(n), |
131 | | })) |
132 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<_>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::read_f64 Unexecuted instantiation: <tiff::decoder::stream::EndianReader<std::io::cursor::Cursor<&[u8]>>>::read_f64 |
133 | | } |
134 | | |
135 | | /// |
136 | | /// # READERS |
137 | | /// |
138 | | |
139 | | /// |
140 | | /// ## Deflate Reader |
141 | | /// |
142 | | |
143 | | #[cfg(feature = "deflate")] |
144 | | pub type DeflateReader<R> = flate2::read::ZlibDecoder<R>; |
145 | | |
146 | | /// |
147 | | /// ## LZW Reader |
148 | | /// |
149 | | |
150 | | /// Reader that decompresses LZW streams |
151 | | #[cfg(feature = "lzw")] |
152 | | pub struct LZWReader<R: Read> { |
153 | | reader: BufReader<Take<R>>, |
154 | | decoder: weezl::decode::Decoder, |
155 | | } |
156 | | |
157 | | #[cfg(feature = "lzw")] |
158 | | impl<R: Read> LZWReader<R> { |
159 | | /// Wraps a reader |
160 | 0 | pub fn new(reader: R, compressed_length: usize) -> LZWReader<R> { |
161 | 0 | Self { |
162 | 0 | reader: BufReader::with_capacity( |
163 | 0 | (32 * 1024).min(compressed_length), |
164 | 0 | reader.take(u64::try_from(compressed_length).unwrap()), |
165 | 0 | ), |
166 | 0 | decoder: weezl::decode::Decoder::with_tiff_size_switch(weezl::BitOrder::Msb, 8), |
167 | 0 | } |
168 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::LZWReader<_>>::new Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>>>::new |
169 | | } |
170 | | |
171 | | #[cfg(feature = "lzw")] |
172 | | impl<R: Read> Read for LZWReader<R> { |
173 | 0 | fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { |
174 | | loop { |
175 | 0 | let result = self.decoder.decode_bytes(self.reader.fill_buf()?, buf); |
176 | 0 | self.reader.consume(result.consumed_in); |
177 | | |
178 | 0 | match result.status { |
179 | | Ok(weezl::LzwStatus::Ok) => { |
180 | 0 | if result.consumed_out == 0 { |
181 | 0 | continue; |
182 | | } else { |
183 | 0 | return Ok(result.consumed_out); |
184 | | } |
185 | | } |
186 | | Ok(weezl::LzwStatus::NoProgress) => { |
187 | 0 | assert_eq!(result.consumed_in, 0); |
188 | 0 | assert_eq!(result.consumed_out, 0); |
189 | 0 | assert!(self.reader.buffer().is_empty()); |
190 | 0 | return Err(io::Error::new( |
191 | 0 | io::ErrorKind::UnexpectedEof, |
192 | 0 | "no lzw end code found", |
193 | 0 | )); |
194 | | } |
195 | | Ok(weezl::LzwStatus::Done) => { |
196 | 0 | return Ok(result.consumed_out); |
197 | | } |
198 | 0 | Err(err) => return Err(io::Error::new(io::ErrorKind::InvalidData, err)), |
199 | | } |
200 | | } |
201 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::LZWReader<_> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::LZWReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read |
202 | | } |
203 | | |
204 | | /// |
205 | | /// ## PackBits Reader |
206 | | /// |
207 | | |
208 | | enum PackBitsReaderState { |
209 | | Header, |
210 | | Literal, |
211 | | Repeat { value: u8 }, |
212 | | } |
213 | | |
214 | | /// Reader that unpacks Apple's `PackBits` format |
215 | | pub struct PackBitsReader<R: Read> { |
216 | | reader: Take<R>, |
217 | | state: PackBitsReaderState, |
218 | | count: usize, |
219 | | } |
220 | | |
221 | | impl<R: Read> PackBitsReader<R> { |
222 | | /// Wraps a reader |
223 | 0 | pub fn new(reader: R, length: u64) -> Self { |
224 | 0 | Self { |
225 | 0 | reader: reader.take(length), |
226 | 0 | state: PackBitsReaderState::Header, |
227 | 0 | count: 0, |
228 | 0 | } |
229 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<_>>::new Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>>>::new Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>>>::new |
230 | | } |
231 | | |
232 | | impl<R: Read> Read for PackBitsReader<R> { |
233 | 0 | fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { |
234 | 0 | while let PackBitsReaderState::Header = self.state { |
235 | 0 | if self.reader.limit() == 0 { |
236 | 0 | return Ok(0); |
237 | 0 | } |
238 | 0 | let mut header: [u8; 1] = [0]; |
239 | 0 | self.reader.read_exact(&mut header)?; |
240 | 0 | let h = header[0] as i8; |
241 | 0 | if (-127..=-1).contains(&h) { |
242 | 0 | let mut data: [u8; 1] = [0]; |
243 | 0 | self.reader.read_exact(&mut data)?; |
244 | 0 | self.state = PackBitsReaderState::Repeat { value: data[0] }; |
245 | 0 | self.count = (1 - h as isize) as usize; |
246 | 0 | } else if h >= 0 { |
247 | 0 | self.state = PackBitsReaderState::Literal; |
248 | 0 | self.count = h as usize + 1; |
249 | 0 | } else { |
250 | 0 | // h = -128 is a no-op. |
251 | 0 | } |
252 | | } |
253 | | |
254 | 0 | let length = buf.len().min(self.count); |
255 | 0 | let actual = match self.state { |
256 | 0 | PackBitsReaderState::Literal => self.reader.read(&mut buf[..length])?, |
257 | 0 | PackBitsReaderState::Repeat { value } => { |
258 | 0 | for b in &mut buf[..length] { |
259 | 0 | *b = value; |
260 | 0 | } |
261 | | |
262 | 0 | length |
263 | | } |
264 | 0 | PackBitsReaderState::Header => unreachable!(), |
265 | | }; |
266 | | |
267 | 0 | self.count -= actual; |
268 | 0 | if self.count == 0 { |
269 | 0 | self.state = PackBitsReaderState::Header; |
270 | 0 | } |
271 | 0 | Ok(actual) |
272 | 0 | } Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<_> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read Unexecuted instantiation: <tiff::decoder::stream::PackBitsReader<&mut std::io::cursor::Cursor<&[u8]>> as std::io::Read>::read |
273 | | } |
274 | | |
275 | | #[cfg(test)] |
276 | | mod test { |
277 | | use super::*; |
278 | | |
279 | | #[test] |
280 | | fn test_packbits() { |
281 | | let encoded = vec![ |
282 | | 0xFE, 0xAA, 0x02, 0x80, 0x00, 0x2A, 0xFD, 0xAA, 0x03, 0x80, 0x00, 0x2A, 0x22, 0xF7, |
283 | | 0xAA, |
284 | | ]; |
285 | | let encoded_len = encoded.len(); |
286 | | |
287 | | let buff = io::Cursor::new(encoded); |
288 | | let mut decoder = PackBitsReader::new(buff, encoded_len as u64); |
289 | | |
290 | | let mut decoded = Vec::new(); |
291 | | decoder.read_to_end(&mut decoded).unwrap(); |
292 | | |
293 | | let expected = vec![ |
294 | | 0xAA, 0xAA, 0xAA, 0x80, 0x00, 0x2A, 0xAA, 0xAA, 0xAA, 0xAA, 0x80, 0x00, 0x2A, 0x22, |
295 | | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
296 | | ]; |
297 | | assert_eq!(decoded, expected); |
298 | | } |
299 | | } |