Reverted read_strip and read_tile to previous call signature
Added comments to ChunkInfo
This commit is contained in:
1 parent
e57ca1a926
commit
6bec36ab20
3 files changed
+20
-9
No files matched your search
+18
-7
@@ -243,23 +243,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
|
||||
}
|
||||
@@ -1212,8 +1221,10 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
}
|
||||
|
||||
/// 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<DecodingResult> {
|
||||
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)> {
|
||||
@@ -1230,12 +1241,12 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
}
|
||||
|
||||
/// 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<DecodingResult> {
|
||||
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)> {
|
||||
|
||||
@@ -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(<u64>::from).sum();
|
||||
assert_eq!(sum, sums[tile as usize]);
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user