Skip to content

Commit 5d0d344

Browse files
committed
Bigtiff stub
1 parent 4b3f2b2 commit 5d0d344

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/ifd.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ async fn read_tag_value(
798798
cursor: &mut AsyncCursor,
799799
tag_type: Type,
800800
count: usize,
801+
bigtiff: bool,
801802
// length: usize,
802803
) -> Result<Value> {
803804
// Case 1: there are no values so we can return immediately.
@@ -824,6 +825,41 @@ async fn read_tag_value(
824825
if count == 1 {
825826
// 2a: the value is 5-8 bytes and we're in BigTiff mode.
826827
// We don't support bigtiff yet
828+
if bigtiff && value_byte_length > 4 && value_byte_length <= 8 {
829+
let data = cursor.read(value_byte_length).await?;
830+
831+
return Ok(match tag_type {
832+
Type::LONG8 => Value::UnsignedBig(data.reader().read_u64::<LittleEndian>()?),
833+
Type::SLONG8 => Value::SignedBig(data.reader().read_i64::<LittleEndian>()?),
834+
Type::DOUBLE => Value::Double(data.reader().read_f64::<LittleEndian>()?),
835+
Type::RATIONAL => {
836+
let mut reader = data.reader();
837+
Value::Rational(
838+
reader.read_u32::<LittleEndian>()?,
839+
reader.read_u32::<LittleEndian>()?,
840+
)
841+
}
842+
Type::SRATIONAL => {
843+
let mut reader = data.reader();
844+
Value::SRational(
845+
reader.read_i32::<LittleEndian>()?,
846+
reader.read_i32::<LittleEndian>()?,
847+
)
848+
}
849+
Type::IFD8 => Value::IfdBig(data.reader().read_u64::<LittleEndian>()?),
850+
Type::BYTE
851+
| Type::SBYTE
852+
| Type::ASCII
853+
| Type::UNDEFINED
854+
| Type::SHORT
855+
| Type::SSHORT
856+
| Type::LONG
857+
| Type::SLONG
858+
| Type::FLOAT
859+
| Type::IFD => unreachable!(),
860+
_ => panic!("Unknown tag type"),
861+
});
862+
}
827863

828864
// NOTE: we should only be reading value_byte_length when it's 4 bytes or fewer. Right now
829865
// we're reading even if it's 8 bytes, but then only using the first 4 bytes of this
@@ -887,7 +923,7 @@ async fn read_tag_value(
887923
}
888924

889925
// Case 3: There is more than one value, but it fits in the offset field.
890-
if value_byte_length <= 4 {
926+
if value_byte_length <= 4 || bigtiff && value_byte_length <= 8 {
891927
let data = cursor.read(value_byte_length).await?;
892928
cursor.advance(4 - value_byte_length);
893929

0 commit comments

Comments
 (0)