Browse Source

Golang is skipping EXIF reading when it shouldn't.

pull/549/head
James Jackson-South 8 years ago
parent
commit
f6b374d60a
  1. 9
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
  2. 2
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs
  3. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  4. 16
      tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs

9
src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

@ -22,7 +22,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
{ {
/// <summary> /// <summary>
/// Performs the jpeg decoding operation. /// Performs the jpeg decoding operation.
/// Ported from <see href="https://github.com/mozilla/pdf.js/blob/master/src/core/jpg.js"/> with additional fixes to handle common encoding errors /// Originally ported from <see href="https://github.com/mozilla/pdf.js/blob/master/src/core/jpg.js"/>
/// with additional fixes for both performance and common encoding errors.
/// </summary> /// </summary>
internal sealed class PdfJsJpegDecoderCore : IRawJpegData internal sealed class PdfJsJpegDecoderCore : IRawJpegData
{ {
@ -31,7 +32,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
/// </summary> /// </summary>
public const int SupportedPrecision = 8; public const int SupportedPrecision = 8;
#pragma warning disable SA1401 // Fields should be private
/// <summary> /// <summary>
/// The global configuration /// The global configuration
/// </summary> /// </summary>
@ -242,7 +242,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
case PdfJsJpegConstants.Markers.SOF0: case PdfJsJpegConstants.Markers.SOF0:
case PdfJsJpegConstants.Markers.SOF1: case PdfJsJpegConstants.Markers.SOF1:
case PdfJsJpegConstants.Markers.SOF2: case PdfJsJpegConstants.Markers.SOF2:
this.ProcessStartOfFrameMarker(remaining, fileMarker, metadataOnly); this.ProcessStartOfFrameMarker(remaining, fileMarker, metadataOnly);
break; break;
@ -291,17 +290,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
break; break;
case PdfJsJpegConstants.Markers.APP0: case PdfJsJpegConstants.Markers.APP0:
this.ProcessApplicationHeaderMarker(remaining); this.ProcessApplicationHeaderMarker(remaining);
break; break;
case PdfJsJpegConstants.Markers.APP1: case PdfJsJpegConstants.Markers.APP1:
this.ProcessApp1Marker(remaining); this.ProcessApp1Marker(remaining);
break; break;
case PdfJsJpegConstants.Markers.APP2: case PdfJsJpegConstants.Markers.APP2:
this.ProcessApp2Marker(remaining); this.ProcessApp2Marker(remaining);
break; break;
@ -320,7 +316,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
break; break;
case PdfJsJpegConstants.Markers.APP14: case PdfJsJpegConstants.Markers.APP14:
this.ProcessApp14Marker(remaining); this.ProcessApp14Marker(remaining);
break; break;

2
tests/ImageSharp.Benchmarks/Codecs/Jpeg/Identify.cs → tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs

@ -10,7 +10,7 @@ using SixLabors.ImageSharp.Tests;
namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg
{ {
[Config(typeof(Config.ShortClr))] [Config(typeof(Config.ShortClr))]
public class Identify public class IdentifyJpeg
{ {
private byte[] jpegBytes; private byte[] jpegBytes;

2
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -478,6 +478,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[InlineData(TestImages.Jpeg.Baseline.Ycck, 32)] [InlineData(TestImages.Jpeg.Baseline.Ycck, 32)]
[InlineData(TestImages.Jpeg.Baseline.Jpeg400, 8)] [InlineData(TestImages.Jpeg.Baseline.Jpeg400, 8)]
[InlineData(TestImages.Jpeg.Baseline.Snake, 24)] [InlineData(TestImages.Jpeg.Baseline.Snake, 24)]
[InlineData(TestImages.Jpeg.Baseline.Jpeg420Exif, 24)]
public void DetectPixelSizeGolang(string imagePath, int expectedPixelSize) public void DetectPixelSizeGolang(string imagePath, int expectedPixelSize)
{ {
var testFile = TestFile.Create(imagePath); var testFile = TestFile.Create(imagePath);
@ -494,6 +495,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[InlineData(TestImages.Jpeg.Baseline.Ycck, 32)] [InlineData(TestImages.Jpeg.Baseline.Ycck, 32)]
[InlineData(TestImages.Jpeg.Baseline.Jpeg400, 8)] [InlineData(TestImages.Jpeg.Baseline.Jpeg400, 8)]
[InlineData(TestImages.Jpeg.Baseline.Snake, 24)] [InlineData(TestImages.Jpeg.Baseline.Snake, 24)]
[InlineData(TestImages.Jpeg.Baseline.Jpeg420Exif, 24)]
public void DetectPixelSizePdfJs(string imagePath, int expectedPixelSize) public void DetectPixelSizePdfJs(string imagePath, int expectedPixelSize)
{ {
var testFile = TestFile.Create(imagePath); var testFile = TestFile.Create(imagePath);

16
tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs

@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{ {
var expecteColorSpace = (JpegColorSpace)expectedColorSpaceValue; var expecteColorSpace = (JpegColorSpace)expectedColorSpaceValue;
using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, true)) using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, false))
{ {
Assert.Equal(expecteColorSpace, decoder.ColorSpace); Assert.Equal(expecteColorSpace, decoder.ColorSpace);
} }
@ -42,11 +42,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[Fact] [Fact]
public void ComponentScalingIsCorrect_1ChannelJpeg() public void ComponentScalingIsCorrect_1ChannelJpeg()
{ {
using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(TestImages.Jpeg.Baseline.Jpeg400, true)) using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(TestImages.Jpeg.Baseline.Jpeg400, false))
{ {
Assert.Equal(1, decoder.ComponentCount); Assert.Equal(1, decoder.ComponentCount);
Assert.Equal(1, decoder.Components.Length); Assert.Equal(1, decoder.Components.Length);
Size expectedSizeInBlocks = decoder.ImageSizeInPixels.DivideRoundUp(8); Size expectedSizeInBlocks = decoder.ImageSizeInPixels.DivideRoundUp(8);
Assert.Equal(expectedSizeInBlocks, decoder.ImageSizeInMCU); Assert.Equal(expectedSizeInBlocks, decoder.ImageSizeInMCU);
@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, true)) using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, false))
{ {
sb.AppendLine(imageFile); sb.AppendLine(imageFile);
sb.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}"); sb.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}");
@ -103,23 +103,23 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Size fLuma = (Size)expectedLumaFactors; Size fLuma = (Size)expectedLumaFactors;
Size fChroma = (Size)expectedChromaFactors; Size fChroma = (Size)expectedChromaFactors;
using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, true)) using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, false))
{ {
Assert.Equal(componentCount, decoder.ComponentCount); Assert.Equal(componentCount, decoder.ComponentCount);
Assert.Equal(componentCount, decoder.Components.Length); Assert.Equal(componentCount, decoder.Components.Length);
OrigComponent c0 = decoder.Components[0]; OrigComponent c0 = decoder.Components[0];
OrigComponent c1 = decoder.Components[1]; OrigComponent c1 = decoder.Components[1];
OrigComponent c2 = decoder.Components[2]; OrigComponent c2 = decoder.Components[2];
var uniform1 = new Size(1, 1); var uniform1 = new Size(1, 1);
Size expectedLumaSizeInBlocks = decoder.ImageSizeInMCU.MultiplyBy(fLuma) ; Size expectedLumaSizeInBlocks = decoder.ImageSizeInMCU.MultiplyBy(fLuma);
Size divisor = fLuma.DivideBy(fChroma); Size divisor = fLuma.DivideBy(fChroma);
Size expectedChromaSizeInBlocks = expectedLumaSizeInBlocks.DivideRoundUp(divisor); Size expectedChromaSizeInBlocks = expectedLumaSizeInBlocks.DivideRoundUp(divisor);
VerifyJpeg.VerifyComponent(c0, expectedLumaSizeInBlocks, fLuma, uniform1); VerifyJpeg.VerifyComponent(c0, expectedLumaSizeInBlocks, fLuma, uniform1);
VerifyJpeg.VerifyComponent(c1, expectedChromaSizeInBlocks, fChroma, divisor); VerifyJpeg.VerifyComponent(c1, expectedChromaSizeInBlocks, fChroma, divisor);
VerifyJpeg.VerifyComponent(c2, expectedChromaSizeInBlocks, fChroma, divisor); VerifyJpeg.VerifyComponent(c2, expectedChromaSizeInBlocks, fChroma, divisor);

Loading…
Cancel
Save