Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/decoder/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,6 @@ impl Image {
let row = &mut row[..data_row_bytes];
reader.read_exact(row)?;

println!("chunk={chunk_index}, index={i}");

// Skip horizontal padding
if chunk_row_bytes > data_row_bytes {
let len = u64::try_from(chunk_row_bytes - data_row_bytes)?;
Expand Down
17 changes: 12 additions & 5 deletions src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,13 +969,20 @@ impl<R: Read + Seek> Decoder<R> {
}

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)
.and_then(|x| x.checked_mul(self.image().samples_per_pixel()))
{
Some(s) => s,
None => return Err(TiffError::LimitsExceeded),
};
.ok_or(TiffError::LimitsExceeded)?;

let max_sample_bits = self.image().bits_per_sample;
match self.image().sample_format {
Expand Down
5 changes: 5 additions & 0 deletions tests/decode_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ fn issue_69() {
//assert!(img_res.is_ok());
//}

#[test]
fn test_tiled_gray_i1() {
test_image_sum_u8("tiled-gray-i1.tif", ColorType::Gray(1), 30531);
}

#[test]
fn test_tiled_rgb_u8() {
test_image_sum_u8("tiled-rgb-u8.tif", ColorType::RGB(8), 39528948);
Expand Down
Binary file added tests/images/tiled-gray-i1.tif
Binary file not shown.
Loading