Browse Source

ExifResolutionValues struct

pull/1686/head
Ildar Khayrutdinov 5 years ago
parent
commit
941df950e1
  1. 9
      src/ImageSharp/Common/Helpers/UnitConverter.cs
  2. 10
      src/ImageSharp/Formats/Tiff/TiffEncoderEntriesCollector.cs

9
src/ImageSharp/Common/Helpers/UnitConverter.cs

@ -98,13 +98,14 @@ namespace SixLabors.ImageSharp.Common.Helpers
}
/// <summary>
/// Sets the exif profile resolution values.
/// Gets the exif profile resolution values.
/// </summary>
/// <param name="unit">The resolution unit.</param>
/// <param name="horizontal">The horizontal resolution value.</param>
/// <param name="vertical">The vertical resolution value.</param>
/// <returns><see cref="ExifResolutionValues"/></returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static (ushort, double?, double?) AdjustToExif(PixelResolutionUnit unit, double horizontal, double vertical)
public static ExifResolutionValues GetExifResolutionValues(PixelResolutionUnit unit, double horizontal, double vertical)
{
switch (unit)
{
@ -128,10 +129,10 @@ namespace SixLabors.ImageSharp.Common.Helpers
ushort exifUnit = (ushort)(unit + 1);
if (unit == PixelResolutionUnit.AspectRatio)
{
return (exifUnit, null, null);
return new ExifResolutionValues(exifUnit, null, null);
}
return (exifUnit, horizontal, vertical);
return new ExifResolutionValues(exifUnit, horizontal, vertical);
}
}
}

10
src/ImageSharp/Formats/Tiff/TiffEncoderEntriesCollector.cs

@ -239,26 +239,26 @@ namespace SixLabors.ImageSharp.Formats.Tiff
private void ProcessResolution(ImageMetadata imageMetadata)
{
(ushort, double?, double?) exifValues = UnitConverter.AdjustToExif(
ExifResolutionValues resolution = UnitConverter.GetExifResolutionValues(
imageMetadata.ResolutionUnits,
imageMetadata.HorizontalResolution,
imageMetadata.VerticalResolution);
this.Collector.AddOrReplace(new ExifShort(ExifTagValue.ResolutionUnit)
{
Value = exifValues.Item1
Value = resolution.ResolutionUnit
});
if (exifValues.Item2 != null && exifValues.Item3 != null)
if (resolution.VerticalResolution.HasValue && resolution.HorizontalResolution.HasValue)
{
this.Collector.AddOrReplace(new ExifRational(ExifTagValue.XResolution)
{
Value = new Rational(exifValues.Item2.Value)
Value = new Rational(resolution.HorizontalResolution.Value)
});
this.Collector.AddOrReplace(new ExifRational(ExifTagValue.YResolution)
{
Value = new Rational(exifValues.Item3.Value)
Value = new Rational(resolution.VerticalResolution.Value)
});
}
}

Loading…
Cancel
Save