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)]
|
#[derive(Debug)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
|
/// ChunkInfo describes the properties of a chunk (either tile or strip).
|
||||||
pub struct ChunkInfo {
|
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,
|
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,
|
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,
|
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,
|
pub data_height: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChunkInfo {
|
impl ChunkInfo {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
/// Returns the amount of padding (pixles) on the right-side of the chunk.
|
||||||
pub fn padding_right(&self) -> usize {
|
pub fn padding_right(&self) -> usize {
|
||||||
self.chunk_width - self.data_width
|
self.chunk_width - self.data_width
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
/// Returns the amount of padding (pixles) on the bottom-side of the chunk.
|
||||||
pub fn padding_down(&self) -> usize {
|
pub fn padding_down(&self) -> usize {
|
||||||
self.chunk_height - self.data_height
|
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
|
/// Read a single strip from the image and return it as a Vector
|
||||||
pub fn read_strip(&mut self) -> TiffResult<(DecodingResult, ChunkInfo)> {
|
pub fn read_strip(&mut self) -> TiffResult<DecodingResult> {
|
||||||
self.read_strip_at(self.current_chunk)
|
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)> {
|
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
|
/// Read a single tile from the image and return it as a Vector
|
||||||
pub fn read_tile(&mut self) -> TiffResult<(DecodingResult, ChunkInfo)> {
|
pub fn read_tile(&mut self) -> TiffResult<DecodingResult> {
|
||||||
let result = self.read_tile_at(self.current_chunk);
|
let result = self.read_tile_at(self.current_chunk)?;
|
||||||
|
|
||||||
self.current_chunk += 1;
|
self.current_chunk += 1;
|
||||||
|
|
||||||
result
|
Ok(result.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_tile_at(&mut self, tile_index: usize) -> TiffResult<(DecodingResult, ChunkInfo)> {
|
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 {
|
for tile in 0..tiles {
|
||||||
match decoder.read_tile().unwrap() {
|
match decoder.read_tile().unwrap() {
|
||||||
(DecodingResult::U8(res), _chunk_info) => {
|
DecodingResult::U8(res) => {
|
||||||
let sum: u64 = res.into_iter().map(<u64>::from).sum();
|
let sum: u64 = res.into_iter().map(<u64>::from).sum();
|
||||||
assert_eq!(sum, sums[tile as usize]);
|
assert_eq!(sum, sums[tile as usize]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -513,7 +513,7 @@ fn test_rows_per_strip() {
|
|||||||
for i in 0..50 {
|
for i in 0..50 {
|
||||||
let img2 = [i; 2 * 100];
|
let img2 = [i; 2 * 100];
|
||||||
match decoder.read_strip().unwrap() {
|
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),
|
other => panic!("Incorrect strip type {:?}", other),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user