Support 64-bit encoding

Note that this adds the LONG8 data type from BigTIFF because of bounds
requiring TiffValue. However, this datatype should not actually be
written to tags.
This commit is contained in:
Andrew Champion committed 2019-12-10 20:18:53 +00:00
1 parent 0c53e1066a
commit 8c4cea5d97
4 files changed
+115

No files matched your search

+21
View File
@@ -31,6 +31,13 @@ impl ColorType for Gray32 {
const BITS_PER_SAMPLE: &'static [u16] = &[32];
}
pub struct Gray64;
impl ColorType for Gray64 {
type Inner = u64;
const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::BlackIsZero;
const BITS_PER_SAMPLE: &'static [u16] = &[64];
}
pub struct RGB8;
impl ColorType for RGB8 {
type Inner = u8;
@@ -52,6 +59,13 @@ impl ColorType for RGB32 {
const BITS_PER_SAMPLE: &'static [u16] = &[32, 32, 32];
}
pub struct RGB64;
impl ColorType for RGB64 {
type Inner = u64;
const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
const BITS_PER_SAMPLE: &'static [u16] = &[64, 64, 64];
}
pub struct RGBA8;
impl ColorType for RGBA8 {
type Inner = u8;
@@ -73,6 +87,13 @@ impl ColorType for RGBA32 {
const BITS_PER_SAMPLE: &'static [u16] = &[32, 32, 32, 32];
}
pub struct RGBA64;
impl ColorType for RGBA64 {
type Inner = u16;
const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
const BITS_PER_SAMPLE: &'static [u16] = &[64, 64, 64, 64];
}
pub struct CMYK8;
impl ColorType for CMYK8 {
type Inner = u8;
+31
View File
@@ -142,6 +142,23 @@ impl TiffValue for [i32] {
}
}
impl TiffValue for [u64] {
const BYTE_LEN: u32 = 8;
const FIELD_TYPE: ifd::Type = ifd::Type::LONG8;
fn count(&self) -> u32 {
self.len() as u32
}
fn write<W: Write>(&self, writer: &mut TiffWriter<W>) -> TiffResult<()> {
// We write using nativeedian so this sould be safe
let slice =
unsafe { ::std::slice::from_raw_parts(self.as_ptr() as *const u8, self.len() * 8) };
writer.write_bytes(slice)?;
Ok(())
}
}
impl TiffValue for [Rational] {
const BYTE_LEN: u32 = 8;
const FIELD_TYPE: ifd::Type = ifd::Type::RATIONAL;
@@ -258,6 +275,20 @@ impl TiffValue for i32 {
}
}
impl TiffValue for u64 {
const BYTE_LEN: u32 = 8;
const FIELD_TYPE: ifd::Type = ifd::Type::LONG8;
fn count(&self) -> u32 {
1
}
fn write<W: Write>(&self, writer: &mut TiffWriter<W>) -> TiffResult<()> {
writer.write_u64(*self)?;
Ok(())
}
}
impl TiffValue for Rational {
const BYTE_LEN: u32 = 8;
const FIELD_TYPE: ifd::Type = ifd::Type::RATIONAL;