mirror of https://github.com/SixLabors/ImageSharp
4 changed files with 242 additions and 232 deletions
@ -0,0 +1,89 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using Xunit; |
|||
// ReSharper disable InconsistentNaming
|
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|||
{ |
|||
public partial class JpegDecoderTests |
|||
{ |
|||
[Theory] |
|||
[WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] |
|||
public void DecodeBaselineJpeg_Orig<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
if (SkipTest(provider)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
// For 32 bit test enviroments:
|
|||
provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); |
|||
|
|||
using (Image<TPixel> image = provider.GetImage(GolangJpegDecoder)) |
|||
{ |
|||
image.DebugSave(provider); |
|||
provider.Utility.TestName = DecodeBaselineJpegOutputName; |
|||
image.CompareToReferenceOutput( |
|||
this.GetImageComparer(provider), |
|||
provider, |
|||
appendPixelTypeToFileName: false); |
|||
} |
|||
|
|||
provider.Configuration.MemoryManager.ReleaseRetainedResources(); |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] |
|||
public void DecodeBaselineJpeg_PdfJs<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess) |
|||
{ |
|||
// skipping to avoid OutOfMemoryException on CI
|
|||
return; |
|||
} |
|||
|
|||
using (Image<TPixel> image = provider.GetImage(PdfJsJpegDecoder)) |
|||
{ |
|||
image.DebugSave(provider); |
|||
|
|||
provider.Utility.TestName = DecodeBaselineJpegOutputName; |
|||
image.CompareToReferenceOutput( |
|||
this.GetImageComparer(provider), |
|||
provider, |
|||
appendPixelTypeToFileName: false); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFile(TestImages.Jpeg.Issues.CriticalEOF214, PixelTypes.Rgba32)] |
|||
public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_Golang<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
// TODO: We need a public ImageDecoderException class in ImageSharp!
|
|||
Assert.ThrowsAny<Exception>(() => provider.GetImage(GolangJpegDecoder)); |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFile(TestImages.Jpeg.Issues.CriticalEOF214, PixelTypes.Rgba32)] |
|||
public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_PdfJs<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
// TODO: We need a public ImageDecoderException class in ImageSharp!
|
|||
Assert.ThrowsAny<Exception>(() => provider.GetImage(PdfJsJpegDecoder)); |
|||
} |
|||
|
|||
[Theory(Skip = "Debug only, enable manually!")] |
|||
[WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] |
|||
public void CompareJpegDecoders_Baseline<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
this.CompareJpegDecodersImpl(provider, DecodeBaselineJpegOutputName); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,72 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.Collections.Generic; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|||
{ |
|||
public partial class JpegDecoderTests |
|||
{ |
|||
public static string[] BaselineTestJpegs = |
|||
{ |
|||
TestImages.Jpeg.Baseline.Calliphora, |
|||
TestImages.Jpeg.Baseline.Cmyk, TestImages.Jpeg.Baseline.Ycck, |
|||
TestImages.Jpeg.Baseline.Jpeg400, |
|||
TestImages.Jpeg.Baseline.Testorig420, |
|||
|
|||
// BUG: The following image has a high difference compared to the expected output:
|
|||
// TestImages.Jpeg.Baseline.Jpeg420Small,
|
|||
|
|||
TestImages.Jpeg.Baseline.Jpeg444, |
|||
TestImages.Jpeg.Baseline.Bad.BadEOF, |
|||
TestImages.Jpeg.Issues.MultiHuffmanBaseline394, |
|||
TestImages.Jpeg.Baseline.MultiScanBaselineCMYK, |
|||
TestImages.Jpeg.Baseline.Bad.BadRST |
|||
}; |
|||
|
|||
public static string[] ProgressiveTestJpegs = |
|||
{ |
|||
TestImages.Jpeg.Progressive.Fb, |
|||
TestImages.Jpeg.Progressive.Progress, |
|||
TestImages.Jpeg.Progressive.Festzug, |
|||
TestImages.Jpeg.Progressive.Bad.BadEOF, |
|||
TestImages.Jpeg.Issues.BadCoeffsProgressive178, |
|||
TestImages.Jpeg.Issues.MissingFF00ProgressiveGirl159, |
|||
TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159, |
|||
TestImages.Jpeg.Issues.BadZigZagProgressive385, |
|||
TestImages.Jpeg.Progressive.Bad.ExifUndefType, |
|||
TestImages.Jpeg.Issues.NoEoiProgressive517, |
|||
TestImages.Jpeg.Issues.BadRstProgressive518, |
|||
TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159, |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Golang decoder is unable to decode these
|
|||
/// </summary>
|
|||
public static string[] PdfJsOnly = |
|||
{ |
|||
TestImages.Jpeg.Issues.NoEoiProgressive517, TestImages.Jpeg.Issues.BadRstProgressive518, |
|||
TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159 |
|||
}; |
|||
|
|||
private static readonly Dictionary<string, float> CustomToleranceValues = |
|||
new Dictionary<string, float> |
|||
{ |
|||
// Baseline:
|
|||
[TestImages.Jpeg.Baseline.Calliphora] = 0.00002f / 100, |
|||
[TestImages.Jpeg.Baseline.Bad.BadEOF] = 0.38f / 100, |
|||
[TestImages.Jpeg.Baseline.Testorig420] = 0.38f / 100, |
|||
[TestImages.Jpeg.Baseline.Bad.BadRST] = 0.0589f / 100, |
|||
|
|||
// Progressive:
|
|||
[TestImages.Jpeg.Issues.MissingFF00ProgressiveGirl159] = 0.34f / 100, |
|||
[TestImages.Jpeg.Issues.BadCoeffsProgressive178] = 0.38f / 100, |
|||
[TestImages.Jpeg.Progressive.Bad.BadEOF] = 0.3f / 100, |
|||
[TestImages.Jpeg.Progressive.Festzug] = 0.02f / 100, |
|||
[TestImages.Jpeg.Progressive.Fb] = 0.16f / 100, |
|||
[TestImages.Jpeg.Progressive.Progress] = 0.31f / 100, |
|||
[TestImages.Jpeg.Issues.BadZigZagProgressive385] = 0.23f / 100, |
|||
[TestImages.Jpeg.Progressive.Bad.ExifUndefType] = 0.011f / 100, |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.Linq; |
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using Xunit; |
|||
// ReSharper disable InconsistentNaming
|
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|||
{ |
|||
public partial class JpegDecoderTests |
|||
{ |
|||
public const string DecodeProgressiveJpegOutputName = "DecodeProgressiveJpeg"; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] |
|||
public void DecodeProgressiveJpeg_Orig<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess) |
|||
{ |
|||
// skipping to avoid OutOfMemoryException on CI
|
|||
return; |
|||
} |
|||
|
|||
// Golang decoder is unable to decode these:
|
|||
if (PdfJsOnly.Any(fn => fn.Contains(provider.SourceFileOrDescription))) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
// For 32 bit test enviroments:
|
|||
provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); |
|||
|
|||
using (Image<TPixel> image = provider.GetImage(GolangJpegDecoder)) |
|||
{ |
|||
image.DebugSave(provider); |
|||
|
|||
provider.Utility.TestName = DecodeProgressiveJpegOutputName; |
|||
image.CompareToReferenceOutput( |
|||
this.GetImageComparer(provider), |
|||
provider, |
|||
appendPixelTypeToFileName: false); |
|||
} |
|||
|
|||
provider.Configuration.MemoryManager.ReleaseRetainedResources(); |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] |
|||
public void DecodeProgressiveJpeg_PdfJs<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
if (SkipTest(provider)) |
|||
{ |
|||
// skipping to avoid OutOfMemoryException on CI
|
|||
return; |
|||
} |
|||
|
|||
using (Image<TPixel> image = provider.GetImage(PdfJsJpegDecoder)) |
|||
{ |
|||
image.DebugSave(provider); |
|||
|
|||
provider.Utility.TestName = DecodeProgressiveJpegOutputName; |
|||
image.CompareToReferenceOutput( |
|||
this.GetImageComparer(provider), |
|||
provider, |
|||
appendPixelTypeToFileName: false); |
|||
} |
|||
} |
|||
|
|||
[Theory(Skip = "Debug only, enable manually!")] |
|||
[WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] |
|||
public void CompareJpegDecoders_Progressive<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
this.CompareJpegDecodersImpl(provider, DecodeProgressiveJpegOutputName); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue