diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index cfdbbe0..d754b94 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -273,8 +273,8 @@ where fn rev_hpredict(image: DecodingBuffer, size: (u32, u32), color_type: ColorType) -> TiffResult<()> { let samples = match color_type { ColorType::Gray(8) | ColorType::Gray(16) | ColorType::Gray(32) => 1, - ColorType::RGB(8) | ColorType::RGB(16) => 3, - ColorType::RGBA(8) | ColorType::RGBA(16) | ColorType::CMYK(8) => 4, + ColorType::RGB(8) | ColorType::RGB(16) | ColorType::RGB(32) => 3, + ColorType::RGBA(8) | ColorType::RGBA(16) | ColorType::RGBA(32) | ColorType::CMYK(8) => 4, _ => { return Err(TiffError::UnsupportedError( TiffUnsupportedError::HorizontalPredictor(color_type), @@ -339,6 +339,12 @@ impl Decoder { PhotometricInterpretation::RGB if self.bits_per_sample == [16, 16, 16] => { Ok(ColorType::RGB(16)) } + PhotometricInterpretation::RGB if self.bits_per_sample == [32, 32, 32, 32] => { + Ok(ColorType::RGBA(32)) + } + PhotometricInterpretation::RGB if self.bits_per_sample == [32, 32, 32] => { + Ok(ColorType::RGB(32)) + } PhotometricInterpretation::CMYK if self.bits_per_sample == [8, 8, 8, 8] => { Ok(ColorType::CMYK(8)) } @@ -684,6 +690,11 @@ impl Decoder { reader.read_u16_into(&mut buffer[..bytes / 2])?; bytes / 2 } + (ColorType::RGBA(32), DecodingBuffer::U32(ref mut buffer)) + | (ColorType::RGB(32), DecodingBuffer::U32(ref mut buffer)) => { + reader.read_u32_into(&mut buffer[..bytes / 4])?; + bytes / 4 + } (ColorType::Gray(32), DecodingBuffer::U32(ref mut buffer)) => { reader.read_u32_into(&mut buffer[..bytes / 4])?; if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero { diff --git a/tests/decode_images.rs b/tests/decode_images.rs index 9a6076a..900606f 100644 --- a/tests/decode_images.rs +++ b/tests/decode_images.rs @@ -103,6 +103,25 @@ fn test_rgb_u16() { } } +#[test] +fn test_rgb_u32() { + let img_file = File::open("./tests/images/gradient-3c-32b.tiff").expect("Cannot find test image!"); + let mut decoder = Decoder::new(img_file).expect("Cannot create decoder"); + assert_eq!(decoder.colortype().unwrap(), ColorType::RGB(32)); + let img_res = decoder.read_image().unwrap(); + if let DecodingResult::U32(res) = img_res { + let mut res_sum: u64 = 0; + for x in res { + res_sum += x as u64; + } + + assert_eq!(res_sum, 2030834111716); + } + else { + panic!("Wrong bit depth") + } +} + #[test] fn test_string_tags() { // these files have null-terminated strings for their Software tag. One has extra bytes after diff --git a/tests/images/gradient-3c-32b.tiff b/tests/images/gradient-3c-32b.tiff new file mode 100644 index 0000000..d76596e Binary files /dev/null and b/tests/images/gradient-3c-32b.tiff differ