Browse Source

Merge pull request #34 from antonfirsov/master

DecodeJpegMultiple + Test Images
af/merge-core
James Jackson-South 9 years ago
committed by GitHub
parent
commit
5a77f0107e
  1. 106
      tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs
  2. 14
      tests/ImageSharp.Tests/TestImages.cs
  3. 3
      tests/ImageSharp.Tests/TestImages/Formats/Jpg/Festzug.jpg
  4. 0
      tests/ImageSharp.Tests/TestImages/Formats/Jpg/Floorplan.jpg
  5. 3
      tests/ImageSharp.Tests/TestImages/Formats/Jpg/Hiyamugi.jpg
  6. 3
      tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg400jfif.jpg
  7. 3
      tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg
  8. 3
      tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg444.jpg
  9. 3
      tests/ImageSharp.Tests/TestImages/Formats/Jpg/testimgint.jpg
  10. 3
      tests/ImageSharp.Tests/TestImages/Formats/Jpg/testorig.jpg

106
tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs

@ -0,0 +1,106 @@
// <copyright file="DecodeJpegMultiple.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
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<string, byte[]> fileNamesToBytes;
public enum JpegTestingMode
{
All,
SmallImagesOnly,
LargeImagesOnly,
CalliphoraOnly,
}
[Params(JpegTestingMode.All, JpegTestingMode.SmallImagesOnly, JpegTestingMode.LargeImagesOnly,
JpegTestingMode.CalliphoraOnly)]
public JpegTestingMode Mode { get; set; }
private IEnumerable<KeyValuePair<string, byte[]>> 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);
}
}
}

14
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,
};
}

3
tests/ImageSharp.Tests/TestImages/Formats/Jpg/Festzug.jpg

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:06239c321880733aad329338a647b565bf7321d74523ea3fc3b6ced45d7b2058
size 49977

0
tests/ImageSharp.Tests/TestImages/Formats/Jpg/Floorplan.jpeg → tests/ImageSharp.Tests/TestImages/Formats/Jpg/Floorplan.jpg

3
tests/ImageSharp.Tests/TestImages/Formats/Jpg/Hiyamugi.jpg

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ff20d5d0ad75e648b1ea388f65fb41d02bd2a049cd22ef86a4648b357bde94ce
size 540458

3
tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg400jfif.jpg

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f4fc842ed15a8c451d25f2595d68b533777b19f10748d961ab2b0afcc51bcc07
size 45066

3
tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:223f9ca11722e7eccae9eadb158fa2c7bf806ed0aa6ee4390a96df7770035ba4
size 768608

3
tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg444.jpg

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:89c632bbc42bc917f81e7c47595c95cb914a619604ac07b8cebf6fd4d1d744ca
size 5667

3
tests/ImageSharp.Tests/TestImages/Formats/Jpg/testimgint.jpg

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:491679b8057739b3c8e5bacd1e918efb1691d271cbbd69820ff8d480dcb90963
size 5756

3
tests/ImageSharp.Tests/TestImages/Formats/Jpg/testorig.jpg

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:acc6ec555d41d15b368320edaa3b20958ee6fa97cb6e4a18d1213d5ae8bec73b
size 5770
Loading…
Cancel
Save