From 923b80eb73a0388c87e63cc0de2a4fef6cc41a4b Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 22 Sep 2017 00:42:03 +1000 Subject: [PATCH] Use JFifMarker --- .../Jpeg/GolangPort/OrigJpegDecoderCore.cs | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs index dc40577fb..2d300a38f 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs @@ -48,14 +48,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort private readonly Configuration configuration; /// - /// The horizontal resolution. Calculated if the image has a JFIF header. + /// Whether the image has a JFIF header /// - private short horizontalResolution; + private bool isJFif; /// - /// Whether the image has a JFIF header + /// Contains information about the JFIF marker /// - private bool isJfif; + private JFifMarker jFif; /// /// Whether the image has a EXIF header @@ -72,11 +72,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort /// private AdobeMarker adobe; - /// - /// The vertical resolution. Calculated if the image has a JFIF header. - /// - private short verticalResolution; - /// /// Initializes a new instance of the class. /// @@ -305,7 +300,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort case OrigJpegConstants.Markers.SOF2: this.IsProgressive = marker == OrigJpegConstants.Markers.SOF2; this.ProcessStartOfFrameMarker(remaining); - if (metadataOnly && this.isJfif) + if (metadataOnly && this.isJFif) { return; } @@ -400,12 +395,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort /// private void InitDerivedMetaDataProperties() { - if (this.isJfif && this.horizontalResolution > 0 && this.verticalResolution > 0) - { - this.MetaData.HorizontalResolution = this.horizontalResolution; - this.MetaData.VerticalResolution = this.verticalResolution; - } - else if (this.isExif) + if (this.isExif) { ExifValue horizontal = this.MetaData.ExifProfile.GetValue(ExifTag.XResolution); ExifValue vertical = this.MetaData.ExifProfile.GetValue(ExifTag.YResolution); @@ -418,6 +408,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort this.MetaData.VerticalResolution = verticalValue; } } + else if (this.jFif.XDensity > 0 && this.jFif.YDensity > 0) + { + this.MetaData.HorizontalResolution = this.jFif.XDensity; + this.MetaData.VerticalResolution = this.jFif.YDensity; + } } /// @@ -435,16 +430,22 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort this.InputProcessor.ReadFull(this.Temp, 0, 13); remaining -= 13; - this.isJfif = this.Temp[0] == OrigJpegConstants.JFif.J && + this.isJFif = this.Temp[0] == OrigJpegConstants.JFif.J && this.Temp[1] == OrigJpegConstants.JFif.F && this.Temp[2] == OrigJpegConstants.JFif.I && this.Temp[3] == OrigJpegConstants.JFif.F && this.Temp[4] == OrigJpegConstants.JFif.Null; - if (this.isJfif) + if (this.isJFif) { - this.horizontalResolution = (short)((this.Temp[8] << 8) | this.Temp[9]); - this.verticalResolution = (short)((this.Temp[10] << 8) | this.Temp[11]); + this.jFif = new JFifMarker + { + MajorVersion = this.Temp[5], + MinorVersion = this.Temp[6], + DensityUnits = this.Temp[7], + XDensity = (short)((this.Temp[8] << 8) | this.Temp[9]), + YDensity = (short)((this.Temp[10] << 8) | this.Temp[11]) + }; } if (remaining > 0)