diff --git a/src/encoder/colortype.rs b/src/encoder/colortype.rs index a348ee7..6dcceae 100644 --- a/src/encoder/colortype.rs +++ b/src/encoder/colortype.rs @@ -24,6 +24,13 @@ impl ColorType for Gray16 { const BITS_PER_SAMPLE: &'static [u16] = &[16]; } +pub struct Gray32; +impl ColorType for Gray32 { + type Inner = u32; + const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::BlackIsZero; + const BITS_PER_SAMPLE: &'static [u16] = &[32]; +} + pub struct RGB8; impl ColorType for RGB8 { type Inner = u8; @@ -38,6 +45,13 @@ impl ColorType for RGB16 { const BITS_PER_SAMPLE: &'static [u16] = &[16, 16, 16]; } +pub struct RGB32; +impl ColorType for RGB32 { + type Inner = u32; + const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB; + const BITS_PER_SAMPLE: &'static [u16] = &[32, 32, 32]; +} + pub struct RGBA8; impl ColorType for RGBA8 { type Inner = u8; @@ -52,6 +66,13 @@ impl ColorType for RGBA16 { const BITS_PER_SAMPLE: &'static [u16] = &[16, 16, 16, 16]; } +pub struct RGBA32; +impl ColorType for RGBA32 { + type Inner = u16; + const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB; + const BITS_PER_SAMPLE: &'static [u16] = &[32, 32, 32, 32]; +} + pub struct CMYK8; impl ColorType for CMYK8 { type Inner = u8; diff --git a/tests/encode_images.rs b/tests/encode_images.rs index af31025..080a8b1 100644 --- a/tests/encode_images.rs +++ b/tests/encode_images.rs @@ -177,6 +177,67 @@ fn test_rgb_u16_roundtrip() { } } +#[test] +fn test_gray_u32_roundtrip() { + let img_file = + File::open("./tests/images/gradient-1c-32b.tiff").expect("Cannot find test image!"); + let mut decoder = Decoder::new(img_file).expect("Cannot create decoder"); + assert_eq!(decoder.colortype().unwrap(), ColorType::Gray(32)); + + let image_data = match decoder.read_image().unwrap() { + DecodingResult::U32(res) => res, + _ => panic!("Wrong data type"), + }; + + let mut file = tempfile::tempfile().unwrap(); + { + let mut tiff = TiffEncoder::new(&mut file).unwrap(); + + let (width, height) = decoder.dimensions().unwrap(); + tiff.write_image::(width, height, &image_data) + .unwrap(); + } + file.seek(SeekFrom::Start(0)).unwrap(); + { + let mut decoder = Decoder::new(&mut file).unwrap(); + if let DecodingResult::U32(img_res) = decoder.read_image().unwrap() { + assert_eq!(image_data, img_res); + } else { + panic!("Wrong data type"); + } + } +} + +#[test] +fn test_rgb_u32_roundtrip() { + 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 image_data = match decoder.read_image().unwrap() { + DecodingResult::U32(res) => res, + _ => panic!("Wrong data type"), + }; + + let mut file = tempfile::tempfile().unwrap(); + { + let mut tiff = TiffEncoder::new(&mut file).unwrap(); + + let (width, height) = decoder.dimensions().unwrap(); + tiff.write_image::(width, height, &image_data) + .unwrap(); + } + file.seek(SeekFrom::Start(0)).unwrap(); + { + let mut decoder = Decoder::new(&mut file).unwrap(); + if let DecodingResult::U32(img_res) = decoder.read_image().unwrap() { + assert_eq!(image_data, img_res); + } else { + panic!("Wrong data type"); + } + } +} + #[test] fn test_multiple_byte() { let mut data = Cursor::new(Vec::new());