Browse Source

Merge branch 'master' into master

af/merge-core
Vicente Penades 8 years ago
committed by GitHub
parent
commit
26e91bc1cb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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) else if (this.isExif)
{ {
double horizontalValue = this.MetaData.ExifProfile.TryGetValue(ExifTag.XResolution, out ExifValue horizontalTag) double horizontalValue = this.GetExifResolutionValue(ExifTag.XResolution);
? ((Rational)horizontalTag.Value).ToDouble() double verticalValue = this.GetExifResolutionValue(ExifTag.YResolution);
: 0;
double verticalValue = this.MetaData.ExifProfile.TryGetValue(ExifTag.YResolution, out ExifValue verticalTag)
? ((Rational)verticalTag.Value).ToDouble()
: 0;
if (horizontalValue > 0 && verticalValue > 0) 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> /// <summary>
/// Extends the profile with additional data. /// Extends the profile with additional data.
/// </summary> /// </summary>

Loading…
Cancel
Save