Fix 1bpp image decoding and add a test image (#252)

This commit is contained in:
Jonathan Behrens authored and GitHub committed 2024-10-31 20:21:02 -07:00
1 parent e28ad564d9
commit 96d3a02efe
4 files changed
+17 -7

No files matched your search

-2
View File
@@ -687,8 +687,6 @@ impl Image {
let row = &mut row[..data_row_bytes]; let row = &mut row[..data_row_bytes];
reader.read_exact(row)?; reader.read_exact(row)?;
println!("chunk={chunk_index}, index={i}");
// Skip horizontal padding // Skip horizontal padding
if chunk_row_bytes > data_row_bytes { if chunk_row_bytes > data_row_bytes {
let len = u64::try_from(chunk_row_bytes - data_row_bytes)?; let len = u64::try_from(chunk_row_bytes - data_row_bytes)?;
+12 -5
View File
@@ -969,13 +969,20 @@ impl<R: Read + Seek> Decoder<R> {
} }
fn result_buffer(&self, width: usize, height: usize) -> TiffResult<DecodingResult> { fn result_buffer(&self, width: usize, height: usize) -> TiffResult<DecodingResult> {
let buffer_size = match width let bits_per_sample = self.image().bits_per_sample;
let row_samples = if bits_per_sample >= 8 {
width
} else {
((((width as u64) * bits_per_sample as u64) + 7) / 8)
.try_into()
.map_err(|_| TiffError::LimitsExceeded)?
};
let buffer_size = row_samples
.checked_mul(height) .checked_mul(height)
.and_then(|x| x.checked_mul(self.image().samples_per_pixel())) .and_then(|x| x.checked_mul(self.image().samples_per_pixel()))
{ .ok_or(TiffError::LimitsExceeded)?;
Some(s) => s,
None => return Err(TiffError::LimitsExceeded),
};
let max_sample_bits = self.image().bits_per_sample; let max_sample_bits = self.image().bits_per_sample;
match self.image().sample_format { match self.image().sample_format {
+5
View File
@@ -216,6 +216,11 @@ fn issue_69() {
//assert!(img_res.is_ok()); //assert!(img_res.is_ok());
//} //}
#[test]
fn test_tiled_gray_i1() {
test_image_sum_u8("tiled-gray-i1.tif", ColorType::Gray(1), 30531);
}
#[test] #[test]
fn test_tiled_rgb_u8() { fn test_tiled_rgb_u8() {
test_image_sum_u8("tiled-rgb-u8.tif", ColorType::RGB(8), 39528948); test_image_sum_u8("tiled-rgb-u8.tif", ColorType::RGB(8), 39528948);
Binary file not shown.