Browse Source

jpeg encoder tests for disco buffers

af/octree-no-pixelmap
Anton Firszov 6 years ago
parent
commit
c2cecdfff8
  1. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs
  2. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs
  3. 85
      tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs

4
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs

@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[Theory] [Theory]
[WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32, false)] [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32, false)]
[WithFile(TestImages.Jpeg.Baseline.Calliphora, PixelTypes.Rgba32, true)] [WithFile(TestImages.Jpeg.Baseline.Calliphora, PixelTypes.Rgba32, true)]
public void DecodeBaselineJpeg<TPixel>(TestImageProvider<TPixel> provider, bool enforceNonContiguousBuffers) public void DecodeBaselineJpeg<TPixel>(TestImageProvider<TPixel> provider, bool enforceDiscontiguousBuffers)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
static void RunTest(string providerDump, string nonContiguousBuffersStr) static void RunTest(string providerDump, string nonContiguousBuffersStr)
@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
RemoteExecutor.Invoke( RemoteExecutor.Invoke(
RunTest, RunTest,
providerDump, providerDump,
enforceNonContiguousBuffers ? "NonContiguous" : string.Empty) enforceDiscontiguousBuffers ? "Disco" : string.Empty)
.Dispose(); .Dispose();
} }

4
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs

@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[Theory] [Theory]
[WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32, false)] [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32, false)]
[WithFile(TestImages.Jpeg.Progressive.Progress, PixelTypes.Rgba32, true)] [WithFile(TestImages.Jpeg.Progressive.Progress, PixelTypes.Rgba32, true)]
public void DecodeProgressiveJpeg<TPixel>(TestImageProvider<TPixel> provider, bool enforceNonContiguousBuffers) public void DecodeProgressiveJpeg<TPixel>(TestImageProvider<TPixel> provider, bool enforceDiscontiguousBuffers)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
static void RunTest(string providerDump, string nonContiguousBuffersStr) static void RunTest(string providerDump, string nonContiguousBuffersStr)
@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
RemoteExecutor.Invoke( RemoteExecutor.Invoke(
RunTest, RunTest,
providerDump, providerDump,
enforceNonContiguousBuffers ? "NonContiguous" : string.Empty); enforceDiscontiguousBuffers ? "Disco" : string.Empty);
} }
} }
} }

85
tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs

@ -15,30 +15,30 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public class JpegEncoderTests public class JpegEncoderTests
{ {
public static readonly TheoryData<string, int> QualityFiles = public static readonly TheoryData<string, int> QualityFiles =
new TheoryData<string, int> new TheoryData<string, int>
{ {
{ TestImages.Jpeg.Baseline.Calliphora, 80 }, { TestImages.Jpeg.Baseline.Calliphora, 80 },
{ TestImages.Jpeg.Progressive.Fb, 75 } { TestImages.Jpeg.Progressive.Fb, 75 }
}; };
public static readonly TheoryData<JpegSubsample, int> BitsPerPixel_Quality = public static readonly TheoryData<JpegSubsample, int> BitsPerPixel_Quality =
new TheoryData<JpegSubsample, int> new TheoryData<JpegSubsample, int>
{ {
{ JpegSubsample.Ratio420, 40 }, { JpegSubsample.Ratio420, 40 },
{ JpegSubsample.Ratio420, 60 }, { JpegSubsample.Ratio420, 60 },
{ JpegSubsample.Ratio420, 100 }, { JpegSubsample.Ratio420, 100 },
{ JpegSubsample.Ratio444, 40 }, { JpegSubsample.Ratio444, 40 },
{ JpegSubsample.Ratio444, 60 }, { JpegSubsample.Ratio444, 60 },
{ JpegSubsample.Ratio444, 100 }, { JpegSubsample.Ratio444, 100 },
}; };
public static readonly TheoryData<string, int, int, PixelResolutionUnit> RatioFiles = public static readonly TheoryData<string, int, int, PixelResolutionUnit> RatioFiles =
new TheoryData<string, int, int, PixelResolutionUnit> new TheoryData<string, int, int, PixelResolutionUnit>
{ {
{ TestImages.Jpeg.Baseline.Ratio1x1, 1, 1, PixelResolutionUnit.AspectRatio }, { TestImages.Jpeg.Baseline.Ratio1x1, 1, 1, PixelResolutionUnit.AspectRatio },
{ TestImages.Jpeg.Baseline.Snake, 300, 300, PixelResolutionUnit.PixelsPerInch }, { TestImages.Jpeg.Baseline.Snake, 300, 300, PixelResolutionUnit.PixelsPerInch },
{ TestImages.Jpeg.Baseline.GammaDalaiLamaGray, 72, 72, PixelResolutionUnit.PixelsPerInch } { TestImages.Jpeg.Baseline.GammaDalaiLamaGray, 72, 72, PixelResolutionUnit.PixelsPerInch }
}; };
[Theory] [Theory]
[MemberData(nameof(QualityFiles))] [MemberData(nameof(QualityFiles))]
@ -71,6 +71,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[WithTestPatternImages(nameof(BitsPerPixel_Quality), 51, 7, PixelTypes.Rgba32)] [WithTestPatternImages(nameof(BitsPerPixel_Quality), 51, 7, PixelTypes.Rgba32)]
[WithSolidFilledImages(nameof(BitsPerPixel_Quality), 1, 1, 255, 100, 50, 255, PixelTypes.Rgba32)] [WithSolidFilledImages(nameof(BitsPerPixel_Quality), 1, 1, 255, 100, 50, 255, PixelTypes.Rgba32)]
[WithTestPatternImages(nameof(BitsPerPixel_Quality), 7, 5, PixelTypes.Rgba32)] [WithTestPatternImages(nameof(BitsPerPixel_Quality), 7, 5, PixelTypes.Rgba32)]
[WithTestPatternImages(nameof(BitsPerPixel_Quality), 600, 400, PixelTypes.Rgba32)]
public void EncodeBaseline_WorksWithDifferentSizes<TPixel>(TestImageProvider<TPixel> provider, JpegSubsample subsample, int quality) public void EncodeBaseline_WorksWithDifferentSizes<TPixel>(TestImageProvider<TPixel> provider, JpegSubsample subsample, int quality)
where TPixel : struct, IPixel<TPixel> => TestJpegEncoderCore(provider, subsample, quality); where TPixel : struct, IPixel<TPixel> => TestJpegEncoderCore(provider, subsample, quality);
@ -79,6 +80,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void EncodeBaseline_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider, JpegSubsample subsample, int quality) public void EncodeBaseline_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider, JpegSubsample subsample, int quality)
where TPixel : struct, IPixel<TPixel> => TestJpegEncoderCore(provider, subsample, quality); where TPixel : struct, IPixel<TPixel> => TestJpegEncoderCore(provider, subsample, quality);
[Theory]
[WithTestPatternImages(nameof(BitsPerPixel_Quality), 600, 400, PixelTypes.Rgba32)]
public void EncodeBaseline_WorksWithDiscontiguousBuffers<TPixel>(TestImageProvider<TPixel> provider, JpegSubsample subsample, int quality)
where TPixel : struct, IPixel<TPixel> => TestJpegEncoderCore(provider, subsample, quality, true, ImageComparer.TolerantPercentage(0.1f));
/// <summary> /// <summary>
/// Anton's SUPER-SCIENTIFIC tolerance threshold calculation /// Anton's SUPER-SCIENTIFIC tolerance threshold calculation
/// </summary> /// </summary>
@ -105,25 +111,36 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
private static void TestJpegEncoderCore<TPixel>( private static void TestJpegEncoderCore<TPixel>(
TestImageProvider<TPixel> provider, TestImageProvider<TPixel> provider,
JpegSubsample subsample, JpegSubsample subsample,
int quality = 100) int quality = 100,
bool enforceDiscontiguousBuffers = false,
ImageComparer comparer = null)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage()) if (enforceDiscontiguousBuffers)
{ {
// There is no alpha in Jpeg! provider.LimitAllocatorBufferCapacity();
image.Mutate(c => c.MakeOpaque()); }
var encoder = new JpegEncoder using Image<TPixel> image = provider.GetImage();
{
Subsample = subsample, // There is no alpha in Jpeg!
Quality = quality image.Mutate(c => c.MakeOpaque());
};
string info = $"{subsample}-Q{quality}"; var encoder = new JpegEncoder
ImageComparer comparer = GetComparer(quality, subsample); {
Subsample = subsample,
// Does DebugSave & load reference CompareToReferenceInput(): Quality = quality
image.VerifyEncoder(provider, "jpeg", info, encoder, comparer, referenceImageExtension: "png"); };
string info = $"{subsample}-Q{quality}";
if (enforceDiscontiguousBuffers)
{
info += "-Disco";
} }
comparer ??= GetComparer(quality, subsample);
// Does DebugSave & load reference CompareToReferenceInput():
image.VerifyEncoder(provider, "jpeg", info, encoder, comparer, referenceImageExtension: "png");
} }
[Fact] [Fact]

Loading…
Cancel
Save