From 41731c72cc33dafbb903b78da584998f721b7bb3 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sat, 21 Jan 2017 21:55:07 +0100 Subject: [PATCH] jpeg test cleanup --- .../ImageSharp.Sandbox46.csproj | 17 +- .../Formats/Jpg/BadEofJpegTests.cs | 2 +- .../Formats/Jpg/Block8x8FTests.cs | 2 +- .../Formats/Jpg/JpegDecoderTests.cs | 38 +++ .../Formats/Jpg/JpegEncoderTests.cs | 75 +++++ .../Formats/Jpg/JpegProfilingBenchmarks.cs | 78 +++++ .../ImageSharp.Tests/Formats/Jpg/JpegTests.cs | 279 ------------------ ...gTestBase.cs => JpegUtilityTestFixture.cs} | 6 +- .../Formats/Jpg/JpegUtilsTests.cs | 108 +++++++ .../Jpg/ReferenceImplementationsTests.cs | 2 +- tests/ImageSharp.Tests/TestImages.cs | 1 - 11 files changed, 318 insertions(+), 290 deletions(-) create mode 100644 tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs create mode 100644 tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs create mode 100644 tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs rename tests/ImageSharp.Tests/Formats/Jpg/{JpegTestBase.cs => JpegUtilityTestFixture.cs} (94%) create mode 100644 tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs diff --git a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj index 8e7f41967..5a27190db 100644 --- a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj +++ b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj @@ -97,11 +97,20 @@ Tests\Formats\Jpg\Block8x8FTests.cs - - Tests\Formats\Jpg\JpegTestBase.cs + + Tests\Formats\Jpg\JpegDecoderTests.cs - - Tests\Formats\Jpg\JpegTests.cs + + Tests\Formats\Jpg\JpegEncoderTests.cs + + + Tests\Formats\Jpg\JpegProfilingBenchmarks.cs + + + Tests\Formats\Jpg\JpegUtilityTestFixture.cs + + + Tests\Formats\Jpg\JpegUtilsTests.cs Tests\Formats\Jpg\ReferenceImplementations.cs diff --git a/tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs index 213b50a99..2a04cc2c7 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs index 690a8b620..cd863ebf9 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs @@ -19,7 +19,7 @@ namespace ImageSharp.Tests using Xunit; using Xunit.Abstractions; - public class Block8x8FTests : JpegTestBase + public class Block8x8FTests : JpegUtilityTestFixture { #if BENCHMARKING public const int Times = 1000000; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs new file mode 100644 index 000000000..f5207204d --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -0,0 +1,38 @@ +namespace ImageSharp.Tests +{ + using System; + + using Xunit; + + public class JpegDecoderTests : TestBase + { + public static string[] BaselineTestJpegs = + { + TestImages.Jpeg.Baseline.Calliphora, TestImages.Jpeg.Baseline.Cmyk, + TestImages.Jpeg.Baseline.Jpeg400, TestImages.Jpeg.Baseline.Jpeg444 + }; + + public static string[] ProgressiveTestJpegs = TestImages.Jpeg.Progressive.All; + + [Theory] + [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)] + public void OpenBaselineJpeg_SaveBmp(TestImageProvider provider) + where TColor : struct, IPackedPixel, IEquatable + { + Image image = provider.GetImage(); + + provider.Utility.SaveTestOutputFile(image, "bmp"); + } + + [Theory] + [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)] + public void OpenProgressiveJpeg_SaveBmp(TestImageProvider provider) + where TColor : struct, IPackedPixel, IEquatable + { + Image image = provider.GetImage(); + + provider.Utility.SaveTestOutputFile(image, "bmp"); + } + + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs new file mode 100644 index 000000000..7317141ba --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs @@ -0,0 +1,75 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using ImageSharp.Formats; +using Xunit; +using Xunit.Abstractions; +// ReSharper disable InconsistentNaming + +namespace ImageSharp.Tests +{ + using ImageSharp.Formats.Jpg; + using ImageSharp.Processing; + + public class JpegEncoderTests : MeasureFixture + { + public static IEnumerable AllBmpFiles => TestImages.Bmp.All; + + public JpegEncoderTests(ITestOutputHelper output) + : base(output) + { + } + + [Theory] + [WithFile(TestImages.Jpeg.Baseline.Snake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio420)] + [WithFile(TestImages.Jpeg.Baseline.Lake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio420)] + [WithFile(TestImages.Jpeg.Baseline.Snake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio444)] + [WithFile(TestImages.Jpeg.Baseline.Lake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio444)] + public void LoadResizeSave(TestImageProvider provider, int quality, JpegSubsample subsample) + where TColor : struct, IPackedPixel, IEquatable + { + Image image = provider.GetImage() + .Resize(new ResizeOptions + { + Size = new Size(150, 100), + Mode = ResizeMode.Max + }); + image.Quality = quality; + image.ExifProfile = null; // Reduce the size of the file + JpegEncoder encoder = new JpegEncoder { Subsample = subsample, Quality = quality }; + + provider.Utility.TestName += $"{subsample}_Q{quality}"; + provider.Utility.SaveTestOutputFile(image, "png"); + provider.Utility.SaveTestOutputFile(image, "jpg", encoder); + } + + [Theory] + [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb, JpegSubsample.Ratio420, 75)] + [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb, JpegSubsample.Ratio444, 75)] + public void OpenBmp_SaveJpeg(TestImageProvider provider, JpegSubsample subSample, int quality) + where TColor : struct, IPackedPixel, IEquatable + { + Image image = provider.GetImage(); + + ImagingTestCaseUtility utility = provider.Utility; + utility.TestName += "_" + subSample + "_Q" + quality; + + using (var outputStream = File.OpenWrite(utility.GetTestOutputFileName("jpg"))) + { + var encoder = new JpegEncoder() + { + Subsample = subSample, + Quality = quality + }; + + image.Save(outputStream, encoder); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs new file mode 100644 index 000000000..d01ea428e --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs @@ -0,0 +1,78 @@ +namespace ImageSharp.Tests +{ + using System; + using System.IO; + using System.Linq; + + using ImageSharp.Formats; + + using Xunit; + using Xunit.Abstractions; + + public class JpegProfilingBenchmarks : MeasureFixture + { + public JpegProfilingBenchmarks(ITestOutputHelper output) + : base(output) + { + } + + // [Theory] // Benchmark, enable manually + [InlineData(30, TestImages.Jpeg.Baseline.Cmyk)] + [InlineData(30, TestImages.Jpeg.Baseline.Ycck)] + [InlineData(30, TestImages.Jpeg.Baseline.Calliphora)] + [InlineData(30, TestImages.Jpeg.Baseline.Jpeg400)] + [InlineData(30, TestImages.Jpeg.Baseline.Jpeg420)] + [InlineData(30, TestImages.Jpeg.Baseline.Jpeg444)] + public void DecodeJpeg(int executionCount, string fileName) + { + string path = TestFile.GetPath(fileName); + byte[] bytes = File.ReadAllBytes(path); + + this.Measure( + 100, + () => + { + Image img = new Image(bytes); + }, + // ReSharper disable once ExplicitCallerInfoArgument + $"Decode {fileName}"); + + } + + // Benchmark, enable manually! + // [Theory] + [InlineData(1, 75, JpegSubsample.Ratio420)] + [InlineData(30, 75, JpegSubsample.Ratio420)] + [InlineData(30, 75, JpegSubsample.Ratio444)] + [InlineData(30, 100, JpegSubsample.Ratio444)] + public void EncodeJpeg(int executionCount, int quality, JpegSubsample subsample) + { + string[] testFiles = TestImages.Bmp.All + .Concat(new[] { TestImages.Jpeg.Baseline.Calliphora, TestImages.Jpeg.Baseline.Cmyk }) + .ToArray(); + + Image[] testImages = + testFiles.Select( + tf => TestImageProvider.File(tf, pixelTypeOverride: PixelTypes.StandardImageClass).GetImage()) + .ToArray(); + + using (MemoryStream ms = new MemoryStream()) + { + this.Measure(executionCount, + () => + { + foreach (Image img in testImages) + { + JpegEncoder encoder = new JpegEncoder() { Quality = quality, Subsample = subsample }; + img.Save(ms, encoder); + ms.Seek(0, SeekOrigin.Begin); + } + }, + // ReSharper disable once ExplicitCallerInfoArgument + $@"Encode {testFiles.Length} images" + ); + } + } + + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs deleted file mode 100644 index 73ed9f1c2..000000000 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs +++ /dev/null @@ -1,279 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using ImageSharp.Formats; -using Xunit; -using Xunit.Abstractions; -// ReSharper disable InconsistentNaming - -namespace ImageSharp.Tests -{ - using System.Numerics; - - using ImageSharp.Formats.Jpg; - using ImageSharp.Processing; - - public class JpegTests : MeasureFixture - { - public JpegTests(ITestOutputHelper output) - : base(output) - { - } - - [Theory] - [WithFile(TestImages.Jpeg.Baseline.Snake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio420)] - [WithFile(TestImages.Jpeg.Baseline.Lake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio420)] - [WithFile(TestImages.Jpeg.Baseline.Snake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio444)] - [WithFile(TestImages.Jpeg.Baseline.Lake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio444)] - public void LoadResizeSave(TestImageProvider provider, int quality, JpegSubsample subsample) - where TColor : struct, IPackedPixel, IEquatable - { - Image image = provider.GetImage() - .Resize(new ResizeOptions - { - Size = new Size(150, 100), - Mode = ResizeMode.Max - }); - image.Quality = quality; - image.ExifProfile = null; // Reduce the size of the file - JpegEncoder encoder = new JpegEncoder { Subsample = subsample, Quality = quality }; - - provider.Utility.TestName += $"{subsample}_Q{quality}"; - provider.Utility.SaveTestOutputFile(image, "png"); - provider.Utility.SaveTestOutputFile(image, "jpg", encoder); - } - - // Benchmark, enable manually! - // [Theory] - [InlineData(1, 75, JpegSubsample.Ratio420)] - [InlineData(30, 75, JpegSubsample.Ratio420)] - [InlineData(30, 75, JpegSubsample.Ratio444)] - [InlineData(30, 100, JpegSubsample.Ratio444)] - public void Encoder_Benchmark(int executionCount, int quality, JpegSubsample subsample) - { - string[] testFiles = TestImages.Bmp.All - .Concat(new[] { TestImages.Jpeg.Baseline.Calliphora, TestImages.Jpeg.Baseline.Cmyk }) - .ToArray(); - - Image[] testImages = - testFiles.Select( - tf => TestImageProvider.File(tf, pixelTypeOverride: PixelTypes.StandardImageClass).GetImage()) - .ToArray(); - - using (MemoryStream ms = new MemoryStream()) - { - this.Measure(executionCount, - () => - { - foreach (Image img in testImages) - { - JpegEncoder encoder = new JpegEncoder() { Quality = quality, Subsample = subsample }; - img.Save(ms, encoder); - ms.Seek(0, SeekOrigin.Begin); - } - }, - // ReSharper disable once ExplicitCallerInfoArgument - $@"Encode {testFiles.Length} images" - ); - } - } - - public static IEnumerable AllJpegFiles => TestImages.Jpeg.Baseline.All; - - [Theory] - [WithFileCollection(nameof(AllJpegFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)] - public void OpenJpeg_SaveBmp(TestImageProvider provider) - where TColor : struct, IPackedPixel, IEquatable - { - Image image = provider.GetImage(); - - provider.Utility.SaveTestOutputFile(image, "bmp"); - } - - - public static IEnumerable AllBmpFiles => TestImages.Bmp.All; - - [Theory] - [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb, JpegSubsample.Ratio420, 75)] - [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb, JpegSubsample.Ratio444, 75)] - public void OpenBmp_SaveJpeg(TestImageProvider provider, JpegSubsample subSample, int quality) - where TColor : struct, IPackedPixel, IEquatable - { - Image image = provider.GetImage(); - - ImagingTestCaseUtility utility = provider.Utility; - utility.TestName += "_" + subSample + "_Q" + quality; - - using (var outputStream = File.OpenWrite(utility.GetTestOutputFileName("jpg"))) - { - var encoder = new JpegEncoder() - { - Subsample = subSample, - Quality = quality - }; - - image.Save(outputStream, encoder); - } - } - - private const int BenchmarkExecTimes = 30; - - public static readonly string[] EncoderBenchmarkFiles = - { - TestImages.Bmp.Car, TestImages.Bmp.NegHeight, - TestImages.Bmp.F, TestImages.Png.Splash, - TestImages.Jpeg.Baseline.Jpeg420, TestImages.Jpeg.Baseline.Calliphora, - TestImages.Jpeg.Baseline.Cmyk - }; - - private const PixelTypes BenchmarkPixels = PixelTypes.StandardImageClass; //PixelTypes.Color | PixelTypes.Argb; - - //[Theory] // Benchmark, enable manually - [InlineData(TestImages.Jpeg.Baseline.Cmyk)] - [InlineData(TestImages.Jpeg.Baseline.Ycck)] - [InlineData(TestImages.Jpeg.Baseline.Calliphora)] - [InlineData(TestImages.Jpeg.Baseline.Jpeg400)] - [InlineData(TestImages.Jpeg.Baseline.Jpeg420)] - [InlineData(TestImages.Jpeg.Baseline.Jpeg444)] - public void Benchmark_JpegDecoder(string fileName) - { - string path = TestFile.GetPath(fileName); - byte[] bytes = File.ReadAllBytes(path); - - this.Measure( - 100, - () => - { - Image img = new Image(bytes); - }, - // ReSharper disable once ExplicitCallerInfoArgument - $"Decode {fileName}"); - - } - - //[Theory] // Benchmark, enable manually - [WithFileCollection(nameof(EncoderBenchmarkFiles), BenchmarkPixels, JpegSubsample.Ratio420, 75)] - [WithFileCollection(nameof(EncoderBenchmarkFiles), BenchmarkPixels, JpegSubsample.Ratio444, 75)] - public void Benchmark_JpegEncoder(TestImageProvider provider, JpegSubsample subSample, int quality) - where TColor : struct, IPackedPixel, IEquatable - { - Image image = provider.GetImage(); - - using (var outputStream = new MemoryStream()) - { - JpegEncoder encoder = new JpegEncoder() - { - Subsample = subSample, - Quality = quality - }; - - for (int i = 0; i < BenchmarkExecTimes; i++) - { - image.Save(outputStream, encoder); - outputStream.Seek(0, SeekOrigin.Begin); - } - } - } - - public static Image CreateTestImage(GenericFactory factory) - where TColor : struct, IPackedPixel, IEquatable - { - Image image = factory.CreateImage(10, 10); - - using (PixelAccessor pixels = image.Lock()) - { - for (int i = 0; i < 10; i++) - { - for (int j = 0; j < 10; j++) - { - Vector4 v = new Vector4(i/10f, j/10f, 0, 1); - - TColor color = default(TColor); - color.PackFromVector4(v); - - pixels[i, j] = color; - } - } - } - return image; - } - - [Theory] - [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)] - public void CopyStretchedRGBTo_FromOrigo(TestImageProvider provider) - where TColor : struct, IPackedPixel, IEquatable - { - Image src = provider.GetImage(); - - PixelArea area = new PixelArea(8, 8, ComponentOrder.Xyz); - Image dest = provider.Factory.CreateImage(8, 8); - - using (var s = src.Lock()) - { - using (var d = dest.Lock()) - { - s.CopyRGBBytesStretchedTo(area, 0, 0); - d.CopyFrom(area, 0, 0); - - Assert.Equal(s[0, 0], d[0, 0]); - Assert.Equal(s[7, 0], d[7, 0]); - Assert.Equal(s[0, 7], d[0, 7]); - Assert.Equal(s[7, 7], d[7, 7]); - } - } - } - - [Theory] - [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)] - public void CopyStretchedRGBTo_WithOffset(TestImageProvider provider) - where TColor : struct, IPackedPixel, IEquatable - { - Image src = provider.GetImage(); - - PixelArea area = new PixelArea(8, 8, ComponentOrder.Xyz); - Image dest = provider.Factory.CreateImage(8, 8); - - using (PixelAccessor s = src.Lock()) - { - using (var d = dest.Lock()) - { - s.CopyRGBBytesStretchedTo(area, 7, 6); - d.CopyFrom(area, 0, 0); - - Assert.Equal(s[6, 7], d[0, 0]); - Assert.Equal(s[6, 8], d[0, 1]); - Assert.Equal(s[7, 8], d[1, 1]); - - Assert.Equal(s[6, 9], d[0, 2]); - Assert.Equal(s[6, 9], d[0, 3]); - Assert.Equal(s[6, 9], d[0, 7]); - - Assert.Equal(s[7, 9], d[1, 2]); - Assert.Equal(s[7, 9], d[1, 3]); - Assert.Equal(s[7, 9], d[1, 7]); - - Assert.Equal(s[9, 9], d[3, 2]); - Assert.Equal(s[9, 9], d[3, 3]); - Assert.Equal(s[9, 9], d[3, 7]); - - Assert.Equal(s[9, 7], d[3, 0]); - Assert.Equal(s[9, 7], d[4, 0]); - Assert.Equal(s[9, 7], d[7, 0]); - - Assert.Equal(s[9, 9], d[3, 2]); - Assert.Equal(s[9, 9], d[4, 2]); - Assert.Equal(s[9, 9], d[7, 2]); - - Assert.Equal(s[9, 9], d[4, 3]); - Assert.Equal(s[9, 9], d[7, 7]); - } - } - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegTestBase.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilityTestFixture.cs similarity index 94% rename from tests/ImageSharp.Tests/Formats/Jpg/JpegTestBase.cs rename to tests/ImageSharp.Tests/Formats/Jpg/JpegUtilityTestFixture.cs index 2e568ba34..736225680 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegTestBase.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilityTestFixture.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -16,9 +16,9 @@ namespace ImageSharp.Tests using ImageSharp.Formats.Jpg; - public class JpegTestBase : MeasureFixture + public class JpegUtilityTestFixture : MeasureFixture { - public JpegTestBase(ITestOutputHelper output) : base(output) + public JpegUtilityTestFixture(ITestOutputHelper output) : base(output) { } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs new file mode 100644 index 000000000..f7c922ddb --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs @@ -0,0 +1,108 @@ +// ReSharper disable InconsistentNaming +namespace ImageSharp.Tests +{ + using System; + using System.Numerics; + + using ImageSharp.Formats.Jpg; + + using Xunit; + + public class JpegUtilsTests : TestBase + { + public static Image CreateTestImage(GenericFactory factory) + where TColor : struct, IPackedPixel, IEquatable + { + Image image = factory.CreateImage(10, 10); + + using (PixelAccessor pixels = image.Lock()) + { + for (int i = 0; i < 10; i++) + { + for (int j = 0; j < 10; j++) + { + Vector4 v = new Vector4(i / 10f, j / 10f, 0, 1); + + TColor color = default(TColor); + color.PackFromVector4(v); + + pixels[i, j] = color; + } + } + } + return image; + } + + [Theory] + [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)] + public void CopyStretchedRGBTo_FromOrigo(TestImageProvider provider) + where TColor : struct, IPackedPixel, IEquatable + { + Image src = provider.GetImage(); + + PixelArea area = new PixelArea(8, 8, ComponentOrder.Xyz); + Image dest = provider.Factory.CreateImage(8, 8); + + using (var s = src.Lock()) + { + using (var d = dest.Lock()) + { + s.CopyRGBBytesStretchedTo(area, 0, 0); + d.CopyFrom(area, 0, 0); + + Assert.Equal(s[0, 0], d[0, 0]); + Assert.Equal(s[7, 0], d[7, 0]); + Assert.Equal(s[0, 7], d[0, 7]); + Assert.Equal(s[7, 7], d[7, 7]); + } + } + } + + [Theory] + [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)] + public void CopyStretchedRGBTo_WithOffset(TestImageProvider provider) + where TColor : struct, IPackedPixel, IEquatable + { + Image src = provider.GetImage(); + + PixelArea area = new PixelArea(8, 8, ComponentOrder.Xyz); + Image dest = provider.Factory.CreateImage(8, 8); + + using (PixelAccessor s = src.Lock()) + { + using (var d = dest.Lock()) + { + s.CopyRGBBytesStretchedTo(area, 7, 6); + d.CopyFrom(area, 0, 0); + + Assert.Equal(s[6, 7], d[0, 0]); + Assert.Equal(s[6, 8], d[0, 1]); + Assert.Equal(s[7, 8], d[1, 1]); + + Assert.Equal(s[6, 9], d[0, 2]); + Assert.Equal(s[6, 9], d[0, 3]); + Assert.Equal(s[6, 9], d[0, 7]); + + Assert.Equal(s[7, 9], d[1, 2]); + Assert.Equal(s[7, 9], d[1, 3]); + Assert.Equal(s[7, 9], d[1, 7]); + + Assert.Equal(s[9, 9], d[3, 2]); + Assert.Equal(s[9, 9], d[3, 3]); + Assert.Equal(s[9, 9], d[3, 7]); + + Assert.Equal(s[9, 7], d[3, 0]); + Assert.Equal(s[9, 7], d[4, 0]); + Assert.Equal(s[9, 7], d[7, 0]); + + Assert.Equal(s[9, 9], d[3, 2]); + Assert.Equal(s[9, 9], d[4, 2]); + Assert.Equal(s[9, 9], d[7, 2]); + + Assert.Equal(s[9, 9], d[4, 3]); + Assert.Equal(s[9, 9], d[7, 7]); + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.cs index 5dd6b87aa..10106ae6f 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.cs @@ -13,7 +13,7 @@ namespace ImageSharp.Tests.Formats.Jpg using Xunit; using Xunit.Abstractions; - public class ReferenceImplementationsTests : JpegTestBase + public class ReferenceImplementationsTests : JpegUtilityTestFixture { public ReferenceImplementationsTests(ITestOutputHelper output) : base(output) diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index adc600395..2e41eb0f1 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -66,7 +66,6 @@ namespace ImageSharp.Tests public const string Lake = "Jpg/baseline/Lake.jpg"; public const string Jpeg400 = "Jpg/baseline/jpeg400jfif.jpg"; public const string Jpeg420 = "Jpg/baseline/jpeg420exif.jpg"; - public const string Jpeg422 = "Jpg/baseline/jpeg422jfif.jpg"; public const string Jpeg444 = "Jpg/baseline/jpeg444.jpg"; public static readonly string[] All =