From 6f0496b10a84554c23b16af65f204fecadeffa57 Mon Sep 17 00:00:00 2001 From: 335g Date: Sun, 1 Jul 2018 19:49:41 +0900 Subject: [PATCH] Support CMYK --- src/decoder/mod.rs | 6 ++++-- src/lib.rs | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index 3f512d5..6cb4da1 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -124,7 +124,7 @@ fn rev_hpredict(image: DecodingResult, size: (u32, u32), color_type: ColorType) let samples = match color_type { ColorType::Gray(8) | ColorType::Gray(16) => 1, ColorType::RGB(8) | ColorType::RGB(16) => 3, - ColorType::RGBA(8) | ColorType::RGBA(16) => 4, + ColorType::RGBA(8) | ColorType::RGBA(16) | ColorType::CMYK(8) => 4, _ => return Err(TiffError::UnsupportedError(format!( "Horizontal predictor for {:?} is unsupported.", color_type ))) @@ -167,6 +167,7 @@ impl Decoder { PhotometricInterpretation::RGB if self.bits_per_sample == [8, 8, 8] => Ok(ColorType::RGB(8)), PhotometricInterpretation::RGB if self.bits_per_sample == [16, 16, 16, 16] => Ok(ColorType::RGBA(16)), PhotometricInterpretation::RGB if self.bits_per_sample == [16, 16, 16] => Ok(ColorType::RGB(16)), + PhotometricInterpretation::CMYK if self.bits_per_sample == [8, 8, 8, 8] => Ok(ColorType::CMYK(8)), PhotometricInterpretation::BlackIsZero | PhotometricInterpretation::WhiteIsZero if self.bits_per_sample.len() == 1 => Ok(ColorType::Gray(self.bits_per_sample[0])), @@ -419,7 +420,8 @@ impl Decoder { }; Ok(match (color_type, buffer) { (ColorType:: RGB(8), DecodingBuffer::U8(ref mut buffer)) | - (ColorType::RGBA(8), DecodingBuffer::U8(ref mut buffer)) => { + (ColorType::RGBA(8), DecodingBuffer::U8(ref mut buffer)) | + (ColorType::CMYK(8), DecodingBuffer::U8(ref mut buffer)) => { try!(reader.read(&mut buffer[..bytes])) } (ColorType::RGBA(16), DecodingBuffer::U16(ref mut buffer)) | diff --git a/src/lib.rs b/src/lib.rs index 2f74a6a..f95658c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,4 +33,7 @@ pub enum ColorType { /// Pixel is RGB with an alpha channel RGBA(u8), + + /// Pixel is CMYK + CMYK(u8), }