Support 32-bit encoding

This commit is contained in:
Andrew Champion committed 2019-12-10 20:18:53 +00:00
1 parent f32b3b9d10
commit af010edcfd
2 files changed
+82

No files matched your search

+21
View File
@@ -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;
+61
View File
@@ -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::<colortype::Gray32>(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::<colortype::RGB32>(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());