Browse Source

Add benchmarks for tga images

af/merge-core
Brian Popow 7 years ago
parent
commit
2acaea2ee4
  1. 2
      src/ImageSharp/Formats/Tga/TgaEncoder.cs
  2. 18
      src/ImageSharp/Formats/Tga/TgaImageTypeExtensions.cs
  3. 42
      tests/ImageSharp.Benchmarks/Codecs/DecodeTga.cs
  4. 54
      tests/ImageSharp.Benchmarks/Codecs/EncodeTga.cs
  5. 1
      tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj

2
src/ImageSharp/Formats/Tga/TgaEncoder.cs

@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// <summary> /// <summary>
/// Gets or sets a value indicating whether no compression or run length compression should be used. /// Gets or sets a value indicating whether no compression or run length compression should be used.
/// </summary> /// </summary>
public TgaCompression Compression { get; set; } public TgaCompression Compression { get; set; } = TgaCompression.RunLength;
/// <inheritdoc/> /// <inheritdoc/>
public void Encode<TPixel>(Image<TPixel> image, Stream stream) public void Encode<TPixel>(Image<TPixel> image, Stream stream)

18
src/ImageSharp/Formats/Tga/TgaImageTypeExtensions.cs

@ -30,17 +30,15 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// <returns>true, if its a valid tga image type.</returns> /// <returns>true, if its a valid tga image type.</returns>
public static bool IsValid(this TgaImageType imageType) public static bool IsValid(this TgaImageType imageType)
{ {
byte imageTypeVal = (byte)imageType; switch (imageType)
switch (imageTypeVal)
{ {
case 0: case TgaImageType.NoImageData:
case 1: case TgaImageType.ColorMapped:
case 2: case TgaImageType.TrueColor:
case 3: case TgaImageType.BlackAndWhite:
case 9: case TgaImageType.RleColorMapped:
case 10: case TgaImageType.RleTrueColor:
case 11: case TgaImageType.RleBlackAndWhite:
return true; return true;
default: default:

42
tests/ImageSharp.Benchmarks/Codecs/DecodeTga.cs

@ -0,0 +1,42 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using BenchmarkDotNet.Attributes;
using ImageMagick;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
[Config(typeof(Config.ShortClr))]
public class DecodeTga : BenchmarkBase
{
private string TestImageFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage);
[Params(TestImages.Tga.Bit24)]
public string TestImage { get; set; }
[Benchmark(Baseline = true, Description = "ImageMagick Tga")]
public Size TgaImageMagick()
{
using (var magickImage = new MagickImage(this.TestImageFullPath))
{
return new Size(magickImage.Width, magickImage.Height);
}
}
[Benchmark(Description = "ImageSharp Tga")]
public Size TgaCore()
{
using (var image = Image.Load<Rgba32>(this.TestImageFullPath))
{
return new Size(image.Width, image.Height);
}
}
}
}

54
tests/ImageSharp.Benchmarks/Codecs/EncodeTga.cs

@ -0,0 +1,54 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using BenchmarkDotNet.Attributes;
using ImageMagick;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;
namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
[Config(typeof(Config.ShortClr))]
public class EncodeTga : BenchmarkBase
{
private MagickImage tgaMagick;
private Image<Rgba32> tgaCore;
private string TestImageFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage);
[Params(TestImages.Tga.Bit24)]
public string TestImage { get; set; }
[GlobalSetup]
public void ReadImages()
{
if (this.tgaCore == null)
{
this.tgaCore = Image.Load<Rgba32>(TestImageFullPath);
this.tgaMagick = new MagickImage(this.TestImageFullPath);
}
}
[Benchmark(Baseline = true, Description = "Magick Tga")]
public void BmpSystemDrawing()
{
using (var memoryStream = new MemoryStream())
{
this.tgaMagick.Write(memoryStream, MagickFormat.Tga);
}
}
[Benchmark(Description = "ImageSharp Tga")]
public void BmpCore()
{
using (var memoryStream = new MemoryStream())
{
this.tgaCore.SaveAsBmp(memoryStream);
}
}
}
}

1
tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj

@ -16,6 +16,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Magick.NET-Q16-AnyCPU" />
<PackageReference Include="BenchmarkDotNet" /> <PackageReference Include="BenchmarkDotNet" />
<PackageReference Include="Colourful" /> <PackageReference Include="Colourful" />
<PackageReference Include="SixLabors.Shapes.Text" /> <PackageReference Include="SixLabors.Shapes.Text" />

Loading…
Cancel
Save