Skip to content

Commit

Permalink
Add SignedByte and SignedShort to into_ conversion methods
Browse files Browse the repository at this point in the history
Ensure that Value::SignedByte and Value::SignedShort to the into_i32, into_i64, into_i32_vec, into_i64_vec methods.
  • Loading branch information
weiji14 committed May 17, 2024
1 parent 9d96765 commit 04ebad7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/decoder/ifd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{TiffError, TiffFormatError, TiffResult};

use self::Value::{
Ascii, Byte, Double, Float, Ifd, IfdBig, List, Rational, RationalBig, SRational, SRationalBig,
Short, Signed, SignedBig, Unsigned, UnsignedBig,
Short, Signed, SignedBig, SignedByte, SignedShort, Unsigned, UnsignedBig,
};

#[allow(unused_qualifications)]
Expand Down Expand Up @@ -72,6 +72,8 @@ impl Value {

pub fn into_i32(self) -> TiffResult<i32> {
match self {
SignedByte(val) => Ok(val.into()),
SignedShort(val) => Ok(val.into()),
Signed(val) => Ok(val),
SignedBig(val) => Ok(i32::try_from(val)?),
val => Err(TiffError::FormatError(
Expand All @@ -95,6 +97,8 @@ impl Value {

pub fn into_i64(self) -> TiffResult<i64> {
match self {
SignedByte(val) => Ok(val.into()),
SignedShort(val) => Ok(val.into()),
Signed(val) => Ok(val.into()),
SignedBig(val) => Ok(val),
val => Err(TiffError::FormatError(
Expand Down Expand Up @@ -206,6 +210,8 @@ impl Value {
}
Ok(new_vec)
}
SignedByte(val) => Ok(vec![val.into()]),
SignedShort(val) => Ok(vec![val.into()]),
Signed(val) => Ok(vec![val]),
SignedBig(val) => Ok(vec![i32::try_from(val)?]),
SRational(numerator, denominator) => Ok(vec![numerator, denominator]),
Expand Down Expand Up @@ -291,6 +297,8 @@ impl Value {
}
Ok(new_vec)
}
SignedByte(val) => Ok(vec![val.into()]),
SignedShort(val) => Ok(vec![val.into()]),
Signed(val) => Ok(vec![val.into()]),
SignedBig(val) => Ok(vec![val]),
SRational(numerator, denominator) => Ok(vec![numerator.into(), denominator.into()]),
Expand Down

0 comments on commit 04ebad7

Please sign in to comment.