Browse Source

Allow several invalid data types when reading the exif resolution.

af/merge-core
Dirk Lemstra 8 years ago
parent
commit
cf2e641000
  1. 29
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

29
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -463,13 +463,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
}
else if (this.isExif)
{
double horizontalValue = this.MetaData.ExifProfile.TryGetValue(ExifTag.XResolution, out ExifValue horizontalTag)
? ((Rational)horizontalTag.Value).ToDouble()
: 0;
double verticalValue = this.MetaData.ExifProfile.TryGetValue(ExifTag.YResolution, out ExifValue verticalTag)
? ((Rational)verticalTag.Value).ToDouble()
: 0;
double horizontalValue = this.GetExifResolutionValue(ExifTag.XResolution);
double verticalValue = this.GetExifResolutionValue(ExifTag.YResolution);
if (horizontalValue > 0 && verticalValue > 0)
{
@ -480,6 +475,26 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
}
}
private double GetExifResolutionValue(ExifTag tag)
{
if (!this.MetaData.ExifProfile.TryGetValue(tag, out ExifValue exifValue))
{
return 0;
}
switch (exifValue.DataType)
{
case ExifDataType.Rational:
return ((Rational)exifValue.Value).ToDouble();
case ExifDataType.Long:
return (uint)exifValue.Value;
case ExifDataType.DoubleFloat:
return (double)exifValue.Value;
default:
return 0;
}
}
/// <summary>
/// Extends the profile with additional data.
/// </summary>

Loading…
Cancel
Save