Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Byte as u8, SignedByte as i8 #236

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/decoder/ifd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl Value {

pub fn into_u16(self) -> TiffResult<u16> {
match self {
Byte(val) => Ok(val.into()),
Short(val) => Ok(val),
Unsigned(val) => Ok(u16::try_from(val)?),
UnsignedBig(val) => Ok(u16::try_from(val)?),
Expand All @@ -79,6 +80,7 @@ impl Value {

pub fn into_u32(self) -> TiffResult<u32> {
match self {
Byte(val) => Ok(val.into()),
Short(val) => Ok(val.into()),
Unsigned(val) => Ok(val),
UnsignedBig(val) => Ok(u32::try_from(val)?),
Expand All @@ -104,6 +106,7 @@ impl Value {

pub fn into_u64(self) -> TiffResult<u64> {
match self {
Byte(val) => Ok(val.into()),
Short(val) => Ok(val.into()),
Unsigned(val) => Ok(val.into()),
UnsignedBig(val) => Ok(val),
Expand Down Expand Up @@ -163,6 +166,7 @@ impl Value {
}
Ok(new_vec)
}
Byte(val) => Ok(vec![val.into()]),
Unsigned(val) => Ok(vec![val]),
UnsignedBig(val) => Ok(vec![u32::try_from(val)?]),
Rational(numerator, denominator) => Ok(vec![numerator, denominator]),
Expand Down Expand Up @@ -204,6 +208,7 @@ impl Value {
}
Ok(new_vec)
}
Byte(val) => Ok(vec![val.into()]),
Short(val) => Ok(vec![val]),
val => Err(TiffError::FormatError(
TiffFormatError::UnsignedIntegerExpected(val),
Expand Down Expand Up @@ -285,6 +290,7 @@ impl Value {
}
Ok(new_vec)
}
Byte(val) => Ok(vec![val.into()]),
Unsigned(val) => Ok(vec![val.into()]),
UnsignedBig(val) => Ok(vec![val]),
Rational(numerator, denominator) => Ok(vec![numerator.into(), denominator.into()]),
Expand Down Expand Up @@ -430,8 +436,8 @@ impl Entry {

// 2b: the value is at most 4 bytes or doesn't fit in the offset field.
return Ok(match self.type_ {
Type::BYTE => Unsigned(u32::from(self.offset[0])),
Type::SBYTE => Signed(i32::from(self.offset[0] as i8)),
Type::BYTE => Byte(self.offset[0]),
Type::SBYTE => SignedByte(i8::from(self.offset[0] as i8)),
Type::UNDEFINED => Byte(self.offset[0]),
Type::SHORT => Unsigned(u32::from(self.r(bo).read_u16()?)),
Type::SSHORT => Signed(i32::from(self.r(bo).read_i16()?)),
Expand Down
Loading