diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index e555fde..5c6cb3f 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -923,6 +923,12 @@ impl Decoder { reader.read_u64_into(&mut buffer[..bytes / 8])?; bytes / 8 } + (ColorType::RGBA(8), DecodingBuffer::I8(ref mut buffer)) + | (ColorType::RGB(8), DecodingBuffer::I8(ref mut buffer)) + | (ColorType::CMYK(8), DecodingBuffer::I8(ref mut buffer)) => { + reader.read_i8_into(&mut buffer[..bytes])?; + bytes + } (ColorType::RGBA(16), DecodingBuffer::I16(ref mut buffer)) | (ColorType::RGB(16), DecodingBuffer::I16(ref mut buffer)) | (ColorType::CMYK(16), DecodingBuffer::I16(ref mut buffer)) => { @@ -957,6 +963,15 @@ impl Decoder { } bytes / 2 } + (ColorType::Gray(8), DecodingBuffer::I8(ref mut buffer)) => { + reader.read_i8_into(&mut buffer[..bytes])?; + if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero { + for datum in buffer[..bytes].iter_mut() { + *datum = !*datum; + } + } + bytes + } // The following conversions interpret the image as in libtiff. // In particular, MIN is white and MAX is black and not Zero as the name would imply. (ColorType::Gray(16), DecodingBuffer::I16(ref mut buffer)) => { diff --git a/tests/decode_images.rs b/tests/decode_images.rs index 3049700..1af340f 100644 --- a/tests/decode_images.rs +++ b/tests/decode_images.rs @@ -29,6 +29,7 @@ macro_rules! test_image_sum { } test_image_sum!(test_image_sum_u8, U8, u64); +test_image_sum!(test_image_sum_i8, I8, i64); test_image_sum!(test_image_sum_u16, U16, u64); test_image_sum!(test_image_sum_i16, I16, i64); test_image_sum!(test_image_sum_u32, U32, u64); @@ -136,6 +137,16 @@ fn test_rgb_f32() { test_image_sum_f32("gradient-3c-32b-float.tiff", ColorType::RGB(32), 472.8405); } +#[test] +fn test_int8() { + test_image_sum_i8("int8.tif", ColorType::Gray(8), 3111) +} + +#[test] +fn test_int8_rgb() { + test_image_sum_i8("int8_rgb.tif", ColorType::RGB(8), -10344) +} + #[test] fn test_int16() { test_image_sum_i16("int16.tif", ColorType::Gray(16), 354396); diff --git a/tests/images/int8.tif b/tests/images/int8.tif new file mode 100644 index 0000000..807e0fd Binary files /dev/null and b/tests/images/int8.tif differ diff --git a/tests/images/int8_rgb.tif b/tests/images/int8_rgb.tif new file mode 100644 index 0000000..a0f6db0 Binary files /dev/null and b/tests/images/int8_rgb.tif differ