diff --git a/ImageSharp.sln b/ImageSharp.sln index b25388422..362127afe 100644 --- a/ImageSharp.sln +++ b/ImageSharp.sln @@ -23,7 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{815C06 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{56801022-D71A-4FBE-BC5B-CBA08E2284EC}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "JpegBenchmark", "tests\JpegBenchmark\JpegBenchmark.xproj", "{7C69F09A-3286-45A1-BED2-B9C628150FA9}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ImageSharp.Benchmarks", "tests\ImageSharp.Benchmarks\ImageSharp.Benchmarks.xproj", "{299D8E18-102C-42DE-ADBF-79098EE706A8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,10 +39,10 @@ Global {F836E8E6-B4D9-4208-8346-140C74678B91}.Debug|Any CPU.Build.0 = Debug|Any CPU {F836E8E6-B4D9-4208-8346-140C74678B91}.Release|Any CPU.ActiveCfg = Release|Any CPU {F836E8E6-B4D9-4208-8346-140C74678B91}.Release|Any CPU.Build.0 = Release|Any CPU - {7C69F09A-3286-45A1-BED2-B9C628150FA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7C69F09A-3286-45A1-BED2-B9C628150FA9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7C69F09A-3286-45A1-BED2-B9C628150FA9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7C69F09A-3286-45A1-BED2-B9C628150FA9}.Release|Any CPU.Build.0 = Release|Any CPU + {299D8E18-102C-42DE-ADBF-79098EE706A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {299D8E18-102C-42DE-ADBF-79098EE706A8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {299D8E18-102C-42DE-ADBF-79098EE706A8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {299D8E18-102C-42DE-ADBF-79098EE706A8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -50,6 +50,6 @@ Global GlobalSection(NestedProjects) = preSolution {2AA31A1F-142C-43F4-8687-09ABCA4B3A26} = {815C0625-CD3D-440F-9F80-2D83856AB7AE} {F836E8E6-B4D9-4208-8346-140C74678B91} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} - {7C69F09A-3286-45A1-BED2-B9C628150FA9} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} + {299D8E18-102C-42DE-ADBF-79098EE706A8} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} EndGlobalSection EndGlobal diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs b/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs new file mode 100644 index 000000000..497b20734 --- /dev/null +++ b/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs @@ -0,0 +1,111 @@ +namespace ImageSharp.Benchmarks.Image +{ + using System; + using System.Collections.Generic; + using System.Drawing; + using System.IO; + using System.Linq; + + using BenchmarkDotNet.Attributes; + + using Image = ImageSharp.Image; + using ImageSharpSize = ImageSharp.Size; + + public class DecodeJpegMultiple + { + private Dictionary fileNamesToBytes; + + public enum JpegTestingMode + { + All, + SmallImagesOnly, + LargeImagesOnly, + CalliphoraOnly, + } + + [Params(JpegTestingMode.All, JpegTestingMode.SmallImagesOnly, JpegTestingMode.LargeImagesOnly, JpegTestingMode.CalliphoraOnly)] + public JpegTestingMode Mode { get; set; } + + private IEnumerable> RequestedImages + { + get + { + int thresholdInBytes = 100000; + + switch (this.Mode) + { + case JpegTestingMode.All: + return this.fileNamesToBytes; + case JpegTestingMode.SmallImagesOnly: + return this.fileNamesToBytes.Where(kv => kv.Value.Length < thresholdInBytes); + case JpegTestingMode.LargeImagesOnly: + return this.fileNamesToBytes.Where(kv => kv.Value.Length >= thresholdInBytes); + case JpegTestingMode.CalliphoraOnly: + return new[] { + this.fileNamesToBytes.First(kv => kv.Key.ToLower().Contains("calliphora")) + }; + default: + throw new ArgumentOutOfRangeException(); + } + } + } + + +#if BENCHMARK46 + private const string Folder = "../../../ImageSharp.Tests/TestImages/Formats/Jpg/"; +#else + private const string Folder = "../ImageSharp.Tests/TestImages/Formats/Jpg/"; +#endif + + [Setup] + public void ReadImages() + { + if (this.fileNamesToBytes != null) return; + + // Decoder does not work for these images (yet?): + string[] filterWords = { "testimgari", "corrupted", "gray", "longvertical" }; + + var allFiles = Directory.EnumerateFiles(Folder, "*.jpg", SearchOption.AllDirectories) + .Where(fn => !filterWords.Any(w => fn.ToLower().Contains(w))) + .ToArray(); + + this.fileNamesToBytes = allFiles.ToDictionary(fn => fn, File.ReadAllBytes); + } + + + [Benchmark(Description = "DecodeJpegMultiple - ImageSharp")] + public ImageSharpSize JpegImageSharp() + { + ImageSharpSize lastSize = new ImageSharpSize(); + foreach (var kv in this.RequestedImages) + { + using (MemoryStream memoryStream = new MemoryStream(kv.Value)) + { + Image image = new ImageSharp.Image(memoryStream); + lastSize = new ImageSharpSize(image.Width, image.Height); + } + } + + return lastSize; + } + + [Benchmark(Baseline = true, Description = "DecodeJpegMultiple - System.Drawing")] + public Size JpegSystemDrawing() + { + Size lastSize = new System.Drawing.Size(); + foreach (var kv in this.RequestedImages) + { + using (MemoryStream memoryStream = new MemoryStream(kv.Value)) + { + using (System.Drawing.Image image = System.Drawing.Image.FromStream(memoryStream)) + { + lastSize = image.Size; + } + } + } + + return lastSize; + } + + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/DctTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/DctTests.cs deleted file mode 100644 index 77f9fd98c..000000000 --- a/tests/ImageSharp.Tests/Formats/Jpg/DctTests.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Numerics; -using ImageSharp.Formats; -using Xunit; -using Xunit.Abstractions; - -namespace ImageSharp.Tests.Formats.Jpg -{ - public class DctTests : UtilityTestClassBase - { - public DctTests(ITestOutputHelper output) - : base(output) - { - } - - [Fact] - public void Mennyi() - { - Output.WriteLine(Vector.IsHardwareAccelerated.ToString()); - Output.WriteLine(Vector.Count.ToString()); - } - - [Fact] - public void CheckTestData() - { - var data = Create8x8FloatData(); - - Print8x8Data(data); - } - - [Fact] - public void Transpose8x8() - { - var data = Create8x8FloatData(); - - MutableSpan result = new MutableSpan(64); - - ReferenceImplementations.Transpose8x8(data, result); - - Print8x8Data(result.Data); - } - - [Fact] - public void Transpose8x8_Inplace() - { - var data = Create8x8FloatData(); - - ReferenceImplementations.Transpose8x8(data); - - Print8x8Data(data); - } - - - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 05d18d80a..9c0a9d66c 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -39,16 +39,26 @@ namespace ImageSharp.Tests private static readonly string folder = "TestImages/Formats/Jpg/"; public static string Cmyk => folder + "cmyk.jpg"; public static string Exif => folder + "exif.jpg"; - public static string Floorplan => folder + "Floorplan.jpeg"; + public static string Floorplan => folder + "Floorplan.jpg"; public static string Calliphora => folder + "Calliphora.jpg"; public static string Turtle => folder + "turtle.jpg"; public static string Fb => folder + "fb.jpg"; public static string Progress => folder + "progress.jpg"; public static string GammaDalaiLamaGray => folder + "gamma_dalai_lama_gray.jpg"; + public static string Festzug => folder + "Festzug.jpg"; + public static string Hiyamugi => folder + "Hiyamugi.jpg"; + + public static string Jpeg400 => folder + "baseline/jpeg400jfif.jpg"; + public static string Jpeg420 => folder + "baseline/jpeg420exif.jpg"; + public static string Jpeg422 => folder + "baseline/jpeg422jfif.jpg"; + public static string Jpeg444 => folder + "baseline/jpeg444.jpg"; + public static readonly string[] All = { - Cmyk, Exif, Floorplan, Calliphora, Turtle, Fb, Progress, GammaDalaiLamaGray + Cmyk, Exif, Floorplan, Calliphora, Turtle, Fb, Progress, GammaDalaiLamaGray, + Festzug, Hiyamugi, + Jpeg400, Jpeg420, Jpeg444, }; } diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/Festzug.jpg b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/Festzug.jpg new file mode 100644 index 000000000..ff542a385 Binary files /dev/null and b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/Festzug.jpg differ diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/Hiyamugi.jpg b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/Hiyamugi.jpg new file mode 100644 index 000000000..de758e0dc Binary files /dev/null and b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/Hiyamugi.jpg differ diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg400jfif.jpg b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg400jfif.jpg new file mode 100644 index 000000000..d71fb5cb5 Binary files /dev/null and b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg400jfif.jpg differ diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg new file mode 100644 index 000000000..2289a3f63 Binary files /dev/null and b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg differ diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg444.jpg b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg444.jpg new file mode 100644 index 000000000..f77d69dee Binary files /dev/null and b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg444.jpg differ diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/testimgint.jpg b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/testimgint.jpg new file mode 100644 index 000000000..2501c6159 Binary files /dev/null and b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/testimgint.jpg differ diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/testorig.jpg b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/testorig.jpg new file mode 100644 index 000000000..9816a0c62 Binary files /dev/null and b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/testorig.jpg differ