Support 64-bit rgb and rgba decoding

This commit is contained in:
Andrew Champion committed 2019-12-10 20:18:53 +00:00
1 parent f4e985e0bd
commit 0c53e1066a
3 files changed
+32 -2

No files matched your search

+13 -2
View File
@@ -295,8 +295,8 @@ where
fn rev_hpredict(image: DecodingBuffer, size: (u32, u32), color_type: ColorType) -> TiffResult<()> {
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) => 3,
ColorType::RGBA(8) | ColorType::RGBA(16) | ColorType::RGBA(32) | ColorType::CMYK(8) => 4,
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,
_ => {
return Err(TiffError::UnsupportedError(
TiffUnsupportedError::HorizontalPredictor(color_type),
@@ -370,6 +370,12 @@ impl<R: Read + Seek> Decoder<R> {
PhotometricInterpretation::RGB if self.bits_per_sample == [32, 32, 32] => {
Ok(ColorType::RGB(32))
}
PhotometricInterpretation::RGB if self.bits_per_sample == [64, 64, 64, 64] => {
Ok(ColorType::RGBA(64))
}
PhotometricInterpretation::RGB if self.bits_per_sample == [64, 64, 64] => {
Ok(ColorType::RGB(64))
}
PhotometricInterpretation::CMYK if self.bits_per_sample == [8, 8, 8, 8] => {
Ok(ColorType::CMYK(8))
}
@@ -720,6 +726,11 @@ impl<R: Read + Seek> Decoder<R> {
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)) => {
reader.read_u64_into(&mut buffer[..bytes / 8])?;
bytes / 8
}
(ColorType::Gray(64), DecodingBuffer::U64(ref mut buffer)) => {
reader.read_u64_into(&mut buffer[..bytes / 8])?;
if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero {
+19
View File
@@ -142,6 +142,25 @@ fn test_rgb_u32() {
}
}
#[test]
fn test_rgb_u64() {
let img_file = File::open("./tests/images/gradient-3c-64b.tiff").expect("Cannot find test image!");
let mut decoder = Decoder::new(img_file).expect("Cannot create decoder");
assert_eq!(decoder.colortype().unwrap(), ColorType::RGB(64));
let img_res = decoder.read_image().unwrap();
if let DecodingResult::U64(res) = img_res {
let mut res_sum: u64 = 0;
for x in res {
res_sum += x as u64;
}
assert_eq!(res_sum, 2030834111716);
}
else {
panic!("Wrong bit depth")
}
}
#[test]
fn test_string_tags() {
// these files have null-terminated strings for their Software tag. One has extra bytes after
Binary file not shown.