diff --git a/README.md b/README.md index 7a8ba53..c674c2c 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ This table lists photometric interpretations and sample formats which are suppor | `RGB` | RGB(8|16|32|64), RGBA(8|16|32|64) | | | `RGBPalette` | | | | `Mask` | | | -| `CMYK` | CMYK(8) | | +| `CMYK` | CMYK(8|16|32|64) | | | `YCbCr` | | | | `CIELab` | | | diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index e7fdfb2..30ee3f1 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -216,7 +216,8 @@ fn rev_hpredict(image: DecodingBuffer, size: (u32, u32), color_type: ColorType) let samples = match color_type { ColorType::Gray(8) | ColorType::Gray(16) | ColorType::Gray(32) | ColorType::Gray(64) => 1, ColorType::RGB(8) | ColorType::RGB(16) | ColorType::RGB(32) | ColorType::RGB(64) => 3, - ColorType::RGBA(8) | ColorType::RGBA(16) | ColorType::RGBA(32) | ColorType::RGBA(64) | ColorType::CMYK(8) => 4, + ColorType::RGBA(8) | ColorType::RGBA(16) | ColorType::RGBA(32) | ColorType::RGBA(64) + | ColorType::CMYK(8) | ColorType::CMYK(16) | ColorType::CMYK(32) | ColorType::CMYK(64) => 4, _ => { return Err(TiffError::UnsupportedError( TiffUnsupportedError::HorizontalPredictor(color_type), @@ -283,9 +284,17 @@ impl Decoder { )), } }, - PhotometricInterpretation::CMYK if self.bits_per_sample == [8, 8, 8, 8] => { - Ok(ColorType::CMYK(8)) - } + PhotometricInterpretation::CMYK => { + match self.bits_per_sample[..] { + [c, m, y, k] if [c, c, c] == [m, y, k] => Ok(ColorType::CMYK(c)), + _ => Err(TiffError::UnsupportedError( + TiffUnsupportedError::InterpretationWithBits( + self.photometric_interpretation, + self.bits_per_sample.clone(), + ), + )), + } + }, PhotometricInterpretation::BlackIsZero | PhotometricInterpretation::WhiteIsZero if self.bits_per_sample.len() == 1 => { @@ -612,17 +621,20 @@ impl Decoder { bytes } (ColorType::RGBA(16), DecodingBuffer::U16(ref mut buffer)) - | (ColorType::RGB(16), DecodingBuffer::U16(ref mut buffer)) => { + | (ColorType::RGB(16), DecodingBuffer::U16(ref mut buffer)) + | (ColorType::CMYK(16), DecodingBuffer::U16(ref mut buffer)) => { 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)) => { + | (ColorType::RGB(32), DecodingBuffer::U32(ref mut buffer)) + | (ColorType::CMYK(32), DecodingBuffer::U32(ref mut buffer)) => { reader.read_u32_into(&mut buffer[..bytes / 4])?; bytes / 4 } (ColorType::RGBA(64), DecodingBuffer::U64(ref mut buffer)) - | (ColorType::RGB(64), DecodingBuffer::U64(ref mut buffer)) => { + | (ColorType::RGB(64), DecodingBuffer::U64(ref mut buffer)) + | (ColorType::CMYK(64), DecodingBuffer::U64(ref mut buffer)) => { reader.read_u64_into(&mut buffer[..bytes / 8])?; bytes / 8 } diff --git a/tests/decode_images.rs b/tests/decode_images.rs index bd09607..9fc8676 100644 --- a/tests/decode_images.rs +++ b/tests/decode_images.rs @@ -52,6 +52,11 @@ fn test_cmyk_u8() { test_image_sum_u8("cmyk-3c-8b.tiff", ColorType::CMYK(8), 8522658); } +#[test] +fn test_cmyk_u16() { + test_image_sum_u16("cmyk-3c-16b.tiff", ColorType::CMYK(16), 2181426827); +} + #[test] fn test_gray_u8() { test_image_sum_u8("minisblack-1c-8b.tiff", ColorType::Gray(8), 2840893); diff --git a/tests/images/cmyk-3c-16b.tiff b/tests/images/cmyk-3c-16b.tiff new file mode 100644 index 0000000..3b79eae Binary files /dev/null and b/tests/images/cmyk-3c-16b.tiff differ