Browse Source

Use constants for data type sizes

pull/1570/head
Andrew Wilkinson 9 years ago
parent
commit
f56367f6be
  1. 15
      src/ImageSharp.Formats.Tiff/TiffConstants.cs
  2. 16
      src/ImageSharp.Formats.Tiff/TiffDecoderCore.cs

15
src/ImageSharp.Formats.Tiff/TiffConstants.cs

@ -36,5 +36,20 @@ namespace ImageSharp.Formats
/// Size (in bytes) of each individual TIFF IFD entry
/// </summary>
public const int SizeOfIfdEntry = 12;
/// <summary>
/// Size (in bytes) of the Short and SShort data types
/// </summary>
public const int SizeOfShort = 2;
/// <summary>
/// Size (in bytes) of the Long and SLong data types
/// </summary>
public const int SizeOfLong = 4;
/// <summary>
/// Size (in bytes) of the Rational and SRational data types
/// </summary>
public const int SizeOfRational = 8;
}
}

16
src/ImageSharp.Formats.Tiff/TiffDecoderCore.cs

@ -203,13 +203,13 @@ namespace ImageSharp.Formats
case TiffType.Short:
{
for (int i = 0 ; i < result.Length ; i++)
result[i] = (uint)ToUInt16(bytes, i * 2);
result[i] = (uint)ToUInt16(bytes, i * TiffConstants.SizeOfShort);
break;
}
case TiffType.Long:
{
for (int i = 0 ; i < result.Length ; i++)
result[i] = ToUInt32(bytes, i * 4);
result[i] = ToUInt32(bytes, i * TiffConstants.SizeOfLong);
break;
}
default:
@ -235,13 +235,13 @@ namespace ImageSharp.Formats
case TiffType.SShort:
{
for (int i = 0 ; i < result.Length ; i++)
result[i] = (int)ToInt16(bytes, i * 2);
result[i] = (int)ToInt16(bytes, i * TiffConstants.SizeOfShort);
break;
}
case TiffType.SLong:
{
for (int i = 0 ; i < result.Length ; i++)
result[i] = ToInt32(bytes, i * 4);
result[i] = ToInt32(bytes, i * TiffConstants.SizeOfLong);
break;
}
default:
@ -290,8 +290,8 @@ namespace ImageSharp.Formats
for (int i = 0 ; i < result.Length ; i++)
{
uint numerator = ToUInt32(bytes, i * 8);
uint denominator = ToUInt32(bytes, i * 8 + 4);
uint numerator = ToUInt32(bytes, i * TiffConstants.SizeOfRational);
uint denominator = ToUInt32(bytes, i * TiffConstants.SizeOfRational + TiffConstants.SizeOfLong);
result[i] = new Rational(numerator, denominator);
}
@ -308,8 +308,8 @@ namespace ImageSharp.Formats
for (int i = 0 ; i < result.Length ; i++)
{
int numerator = ToInt32(bytes, i * 8);
int denominator = ToInt32(bytes, i * 8 + 4);
int numerator = ToInt32(bytes, i * TiffConstants.SizeOfRational);
int denominator = ToInt32(bytes, i * TiffConstants.SizeOfRational + TiffConstants.SizeOfLong);
result[i] = new SignedRational(numerator, denominator);
}

Loading…
Cancel
Save