diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index c8e7a71..4139229 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -261,23 +261,32 @@ pub enum ChunkType { #[derive(Debug)] #[non_exhaustive] +/// ChunkInfo describes the properties of a chunk (either tile or strip). pub struct ChunkInfo { - /// Width of the chunk as specified (includes potential padding) + /// Width of the chunk as specified (includes potential padding). This has the same + /// value for all chunks in the image. pub chunk_width: usize, + /// Height/Length of the chunk as specified (includes potential padding). This has + /// the same value for all chunks in the image. pub chunk_height: usize, - /// Width of the data (excluding potential padding) + /// Width of the data (excluding potential padding). This can take different values + /// on the right column of the image due to padding. pub data_width: usize, + /// Height/Length of the data (excluding potential padding). This can take different values + /// on the bottom row of the image due to padding. pub data_height: usize, } impl ChunkInfo { #[inline] + /// Returns the amount of padding (pixles) on the right-side of the chunk. pub fn padding_right(&self) -> usize { self.chunk_width - self.data_width } #[inline] + /// Returns the amount of padding (pixles) on the bottom-side of the chunk. pub fn padding_down(&self) -> usize { self.chunk_height - self.data_height } @@ -1095,9 +1104,9 @@ impl Decoder { } /// Decompresses the strip into the supplied buffer. - fn expand_strip<'a>( + fn expand_strip( &mut self, - mut buffer: DecodingBuffer<'a>, + mut buffer: DecodingBuffer, offset: u64, length: u64, ) -> TiffResult<()> { @@ -1478,8 +1487,10 @@ impl Decoder { } /// Read a single strip from the image and return it as a Vector - pub fn read_strip(&mut self) -> TiffResult<(DecodingResult, ChunkInfo)> { - self.read_strip_at(self.current_chunk) + pub fn read_strip(&mut self) -> TiffResult { + let result = self.read_strip_at(self.current_chunk)?; + + Ok(result.0) } pub fn read_strip_at(&mut self, strip_index: usize) -> TiffResult<(DecodingResult, ChunkInfo)> { @@ -1496,12 +1507,12 @@ impl Decoder { } /// Read a single tile from the image and return it as a Vector - pub fn read_tile(&mut self) -> TiffResult<(DecodingResult, ChunkInfo)> { - let result = self.read_tile_at(self.current_chunk); + pub fn read_tile(&mut self) -> TiffResult { + let result = self.read_tile_at(self.current_chunk)?; self.current_chunk += 1; - result + Ok(result.0) } pub fn read_tile_at(&mut self, tile_index: usize) -> TiffResult<(DecodingResult, ChunkInfo)> { diff --git a/tests/decode_images.rs b/tests/decode_images.rs index 3e6b3ef..d2a4419 100644 --- a/tests/decode_images.rs +++ b/tests/decode_images.rs @@ -276,7 +276,7 @@ fn test_tiled_incremental() { for tile in 0..tiles { match decoder.read_tile().unwrap() { - (DecodingResult::U8(res), _chunk_info) => { + DecodingResult::U8(res) => { let sum: u64 = res.into_iter().map(::from).sum(); assert_eq!(sum, sums[tile as usize]); } diff --git a/tests/encode_images.rs b/tests/encode_images.rs index 6d34ee6..a8e1ca3 100644 --- a/tests/encode_images.rs +++ b/tests/encode_images.rs @@ -513,7 +513,7 @@ fn test_rows_per_strip() { for i in 0..50 { let img2 = [i; 2 * 100]; match decoder.read_strip().unwrap() { - (DecodingResult::U8(data), _chunk_info) => assert_eq!(&img2[..], &data[..]), + DecodingResult::U8(data) => assert_eq!(&img2[..], &data[..]), other => panic!("Incorrect strip type {:?}", other), } }