diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs b/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs
new file mode 100644
index 0000000000..a3c2eba733
--- /dev/null
+++ b/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs
@@ -0,0 +1,106 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+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 const string Folder = "../ImageSharp.Tests/TestImages/Formats/Jpg/";
+
+ 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();
+ }
+ }
+ }
+
+ [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 Image(memoryStream);
+ lastSize = new ImageSharpSize(image.Width, image.Height);
+ }
+ }
+
+ return lastSize;
+ }
+
+ [Benchmark(Baseline = true, Description = "DecodeJpegMultiple - System.Drawing")]
+ public Size JpegSystemDrawing()
+ {
+ Size lastSize = new 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;
+ }
+
+ [Setup]
+ public void ReadImages()
+ {
+ if (this.fileNamesToBytes != null) return;
+
+ var allFiles = Directory.EnumerateFiles(Folder, "*.jpg", SearchOption.AllDirectories).ToArray();
+
+ this.fileNamesToBytes = allFiles.ToDictionary(fn => fn, File.ReadAllBytes);
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs
index 05d18d80a5..9c0a9d66c9 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 0000000000..ff542a3856
Binary files /dev/null and b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/Festzug.jpg differ
diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/Floorplan.jpeg b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/Floorplan.jpg
similarity index 100%
rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/Floorplan.jpeg
rename to tests/ImageSharp.Tests/TestImages/Formats/Jpg/Floorplan.jpg
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 0000000000..de758e0dc6
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 0000000000..d71fb5cb5f
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 0000000000..2289a3f633
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 0000000000..f77d69deef
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 0000000000..2501c61598
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 0000000000..9816a0c623
Binary files /dev/null and b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/testorig.jpg differ