Browse Source

Use shared instances for all built-in decoders.

pull/2276/head
James Jackson-South 3 years ago
parent
commit
4007a48b89
  1. 2
      src/ImageSharp/Formats/Bmp/BmpConfigurationModule.cs
  2. 9
      src/ImageSharp/Formats/Bmp/BmpDecoder.cs
  3. 6
      src/ImageSharp/Formats/Bmp/BmpFormat.cs
  4. 4
      src/ImageSharp/Formats/Gif/GifConfigurationModule.cs
  5. 9
      src/ImageSharp/Formats/Gif/GifDecoder.cs
  6. 2
      src/ImageSharp/Formats/Gif/GifFormat.cs
  7. 4
      src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs
  8. 9
      src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
  9. 6
      src/ImageSharp/Formats/Jpeg/JpegFormat.cs
  10. 2
      src/ImageSharp/Formats/Pbm/PbmConfigurationModule.cs
  11. 9
      src/ImageSharp/Formats/Pbm/PbmDecoder.cs
  12. 2
      src/ImageSharp/Formats/Pbm/PbmFormat.cs
  13. 4
      src/ImageSharp/Formats/Png/PngConfigurationModule.cs
  14. 9
      src/ImageSharp/Formats/Png/PngDecoder.cs
  15. 6
      src/ImageSharp/Formats/Png/PngFormat.cs
  16. 2
      src/ImageSharp/Formats/Tga/TgaConfigurationModule.cs
  17. 9
      src/ImageSharp/Formats/Tga/TgaDecoder.cs
  18. 4
      src/ImageSharp/Formats/Tga/TgaFormat.cs
  19. 2
      src/ImageSharp/Formats/Tiff/TiffConfigurationModule.cs
  20. 9
      src/ImageSharp/Formats/Tiff/TiffDecoder.cs
  21. 2
      src/ImageSharp/Formats/Tiff/TiffFormat.cs
  22. 2
      src/ImageSharp/Formats/Webp/WebpConfigurationModule.cs
  23. 9
      src/ImageSharp/Formats/Webp/WebpDecoder.cs
  24. 2
      src/ImageSharp/Formats/Webp/WebpFormat.cs
  25. 2
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg.cs
  26. 3
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs
  27. 3
      tests/ImageSharp.Benchmarks/LoadResizeSave/LoadResizeSaveStressRunner.cs
  28. 79
      tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
  29. 8
      tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs
  30. 2
      tests/ImageSharp.Tests/Formats/Bmp/BmpMetadataTests.cs
  31. 18
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  32. 26
      tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs
  33. 5
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs
  34. 32
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs
  35. 7
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs
  36. 28
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  37. 11
      tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.Metadata.cs
  38. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs
  39. 2
      tests/ImageSharp.Tests/Formats/Pbm/PbmDecoderTests.cs
  40. 4
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs
  41. 66
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  42. 8
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  43. 32
      tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs
  44. 4
      tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs
  45. 124
      tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs
  46. 4
      tests/ImageSharp.Tests/Formats/Tiff/BigTiffDecoderTests.cs
  47. 4
      tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderBaseTester.cs
  48. 26
      tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs
  49. 2
      tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs
  50. 14
      tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs
  51. 60
      tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs
  52. 16
      tests/ImageSharp.Tests/Formats/WebP/WebpMetaDataTests.cs
  53. 4
      tests/ImageSharp.Tests/Formats/WebP/YuvConversionTests.cs
  54. 12
      tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs
  55. 32
      tests/ImageSharp.Tests/Metadata/Profiles/XMP/XmpProfileTests.cs

2
src/ImageSharp/Formats/Bmp/BmpConfigurationModule.cs

@ -12,7 +12,7 @@ public sealed class BmpConfigurationModule : IImageFormatConfigurationModule
public void Configure(Configuration configuration)
{
configuration.ImageFormatsManager.SetEncoder(BmpFormat.Instance, new BmpEncoder());
configuration.ImageFormatsManager.SetDecoder(BmpFormat.Instance, new BmpDecoder());
configuration.ImageFormatsManager.SetDecoder(BmpFormat.Instance, BmpDecoder.Instance);
configuration.ImageFormatsManager.AddImageFormatDetector(new BmpImageFormatDetector());
}
}

9
src/ImageSharp/Formats/Bmp/BmpDecoder.cs

@ -10,6 +10,15 @@ namespace SixLabors.ImageSharp.Formats.Bmp;
/// </summary>
public sealed class BmpDecoder : SpecializedImageDecoder<BmpDecoderOptions>
{
private BmpDecoder()
{
}
/// <summary>
/// Gets the shared instance.
/// </summary>
public static BmpDecoder Instance { get; } = new();
/// <inheritdoc/>
protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
{

6
src/ImageSharp/Formats/Bmp/BmpFormat.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Bmp;
@ -13,7 +13,7 @@ public sealed class BmpFormat : IImageFormat<BmpMetadata>
}
/// <summary>
/// Gets the current instance.
/// Gets the shared instance.
/// </summary>
public static BmpFormat Instance { get; } = new BmpFormat();
@ -30,5 +30,5 @@ public sealed class BmpFormat : IImageFormat<BmpMetadata>
public IEnumerable<string> FileExtensions => BmpConstants.FileExtensions;
/// <inheritdoc/>
public BmpMetadata CreateDefaultFormatMetadata() => new BmpMetadata();
public BmpMetadata CreateDefaultFormatMetadata() => new();
}

4
src/ImageSharp/Formats/Gif/GifConfigurationModule.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Gif;
@ -12,7 +12,7 @@ public sealed class GifConfigurationModule : IImageFormatConfigurationModule
public void Configure(Configuration configuration)
{
configuration.ImageFormatsManager.SetEncoder(GifFormat.Instance, new GifEncoder());
configuration.ImageFormatsManager.SetDecoder(GifFormat.Instance, new GifDecoder());
configuration.ImageFormatsManager.SetDecoder(GifFormat.Instance, GifDecoder.Instance);
configuration.ImageFormatsManager.AddImageFormatDetector(new GifImageFormatDetector());
}
}

9
src/ImageSharp/Formats/Gif/GifDecoder.cs

@ -10,6 +10,15 @@ namespace SixLabors.ImageSharp.Formats.Gif;
/// </summary>
public sealed class GifDecoder : ImageDecoder
{
private GifDecoder()
{
}
/// <summary>
/// Gets the shared instance.
/// </summary>
public static GifDecoder Instance { get; } = new();
/// <inheritdoc/>
protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
{

2
src/ImageSharp/Formats/Gif/GifFormat.cs

@ -13,7 +13,7 @@ public sealed class GifFormat : IImageFormat<GifMetadata, GifFrameMetadata>
}
/// <summary>
/// Gets the current instance.
/// Gets the shared instance.
/// </summary>
public static GifFormat Instance { get; } = new();

4
src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg;
@ -12,7 +12,7 @@ public sealed class JpegConfigurationModule : IImageFormatConfigurationModule
public void Configure(Configuration configuration)
{
configuration.ImageFormatsManager.SetEncoder(JpegFormat.Instance, new JpegEncoder());
configuration.ImageFormatsManager.SetDecoder(JpegFormat.Instance, new JpegDecoder());
configuration.ImageFormatsManager.SetDecoder(JpegFormat.Instance, JpegDecoder.Instance);
configuration.ImageFormatsManager.AddImageFormatDetector(new JpegImageFormatDetector());
}
}

9
src/ImageSharp/Formats/Jpeg/JpegDecoder.cs

@ -10,6 +10,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg;
/// </summary>
public sealed class JpegDecoder : SpecializedImageDecoder<JpegDecoderOptions>
{
private JpegDecoder()
{
}
/// <summary>
/// Gets the shared instance.
/// </summary>
public static JpegDecoder Instance { get; } = new();
/// <inheritdoc/>
protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
{

6
src/ImageSharp/Formats/Jpeg/JpegFormat.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg;
@ -13,7 +13,7 @@ public sealed class JpegFormat : IImageFormat<JpegMetadata>
}
/// <summary>
/// Gets the current instance.
/// Gets the shared instance.
/// </summary>
public static JpegFormat Instance { get; } = new JpegFormat();
@ -30,5 +30,5 @@ public sealed class JpegFormat : IImageFormat<JpegMetadata>
public IEnumerable<string> FileExtensions => JpegConstants.FileExtensions;
/// <inheritdoc/>
public JpegMetadata CreateDefaultFormatMetadata() => new JpegMetadata();
public JpegMetadata CreateDefaultFormatMetadata() => new();
}

2
src/ImageSharp/Formats/Pbm/PbmConfigurationModule.cs

@ -12,7 +12,7 @@ public sealed class PbmConfigurationModule : IImageFormatConfigurationModule
public void Configure(Configuration configuration)
{
configuration.ImageFormatsManager.SetEncoder(PbmFormat.Instance, new PbmEncoder());
configuration.ImageFormatsManager.SetDecoder(PbmFormat.Instance, new PbmDecoder());
configuration.ImageFormatsManager.SetDecoder(PbmFormat.Instance, PbmDecoder.Instance);
configuration.ImageFormatsManager.AddImageFormatDetector(new PbmImageFormatDetector());
}
}

9
src/ImageSharp/Formats/Pbm/PbmDecoder.cs

@ -26,6 +26,15 @@ namespace SixLabors.ImageSharp.Formats.Pbm;
/// </summary>
public sealed class PbmDecoder : ImageDecoder
{
private PbmDecoder()
{
}
/// <summary>
/// Gets the shared instance.
/// </summary>
public static PbmDecoder Instance { get; } = new();
/// <inheritdoc/>
protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
{

2
src/ImageSharp/Formats/Pbm/PbmFormat.cs

@ -13,7 +13,7 @@ public sealed class PbmFormat : IImageFormat<PbmMetadata>
}
/// <summary>
/// Gets the current instance.
/// Gets the shared instance.
/// </summary>
public static PbmFormat Instance { get; } = new();

4
src/ImageSharp/Formats/Png/PngConfigurationModule.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Png;
@ -12,7 +12,7 @@ public sealed class PngConfigurationModule : IImageFormatConfigurationModule
public void Configure(Configuration configuration)
{
configuration.ImageFormatsManager.SetEncoder(PngFormat.Instance, new PngEncoder());
configuration.ImageFormatsManager.SetDecoder(PngFormat.Instance, new PngDecoder());
configuration.ImageFormatsManager.SetDecoder(PngFormat.Instance, PngDecoder.Instance);
configuration.ImageFormatsManager.AddImageFormatDetector(new PngImageFormatDetector());
}
}

9
src/ImageSharp/Formats/Png/PngDecoder.cs

@ -10,6 +10,15 @@ namespace SixLabors.ImageSharp.Formats.Png;
/// </summary>
public sealed class PngDecoder : ImageDecoder
{
private PngDecoder()
{
}
/// <summary>
/// Gets the shared instance.
/// </summary>
public static PngDecoder Instance { get; } = new();
/// <inheritdoc/>
protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
{

6
src/ImageSharp/Formats/Png/PngFormat.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Png;
@ -13,7 +13,7 @@ public sealed class PngFormat : IImageFormat<PngMetadata>
}
/// <summary>
/// Gets the current instance.
/// Gets the shared instance.
/// </summary>
public static PngFormat Instance { get; } = new PngFormat();
@ -30,5 +30,5 @@ public sealed class PngFormat : IImageFormat<PngMetadata>
public IEnumerable<string> FileExtensions => PngConstants.FileExtensions;
/// <inheritdoc/>
public PngMetadata CreateDefaultFormatMetadata() => new PngMetadata();
public PngMetadata CreateDefaultFormatMetadata() => new();
}

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

@ -12,7 +12,7 @@ public sealed class TgaConfigurationModule : IImageFormatConfigurationModule
public void Configure(Configuration configuration)
{
configuration.ImageFormatsManager.SetEncoder(TgaFormat.Instance, new TgaEncoder());
configuration.ImageFormatsManager.SetDecoder(TgaFormat.Instance, new TgaDecoder());
configuration.ImageFormatsManager.SetDecoder(TgaFormat.Instance, TgaDecoder.Instance);
configuration.ImageFormatsManager.AddImageFormatDetector(new TgaImageFormatDetector());
}
}

9
src/ImageSharp/Formats/Tga/TgaDecoder.cs

@ -10,6 +10,15 @@ namespace SixLabors.ImageSharp.Formats.Tga;
/// </summary>
public sealed class TgaDecoder : ImageDecoder
{
private TgaDecoder()
{
}
/// <summary>
/// Gets the shared instance.
/// </summary>
public static TgaDecoder Instance { get; } = new();
/// <inheritdoc/>
protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
{

4
src/ImageSharp/Formats/Tga/TgaFormat.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.Tga;
public sealed class TgaFormat : IImageFormat<TgaMetadata>
{
/// <summary>
/// Gets the current instance.
/// Gets the shared instance.
/// </summary>
public static TgaFormat Instance { get; } = new TgaFormat();
@ -26,5 +26,5 @@ public sealed class TgaFormat : IImageFormat<TgaMetadata>
public IEnumerable<string> FileExtensions => TgaConstants.FileExtensions;
/// <inheritdoc/>
public TgaMetadata CreateDefaultFormatMetadata() => new TgaMetadata();
public TgaMetadata CreateDefaultFormatMetadata() => new();
}

2
src/ImageSharp/Formats/Tiff/TiffConfigurationModule.cs

@ -12,7 +12,7 @@ public sealed class TiffConfigurationModule : IImageFormatConfigurationModule
public void Configure(Configuration configuration)
{
configuration.ImageFormatsManager.SetEncoder(TiffFormat.Instance, new TiffEncoder());
configuration.ImageFormatsManager.SetDecoder(TiffFormat.Instance, new TiffDecoder());
configuration.ImageFormatsManager.SetDecoder(TiffFormat.Instance, TiffDecoder.Instance);
configuration.ImageFormatsManager.AddImageFormatDetector(new TiffImageFormatDetector());
}
}

9
src/ImageSharp/Formats/Tiff/TiffDecoder.cs

@ -10,6 +10,15 @@ namespace SixLabors.ImageSharp.Formats.Tiff;
/// </summary>
public class TiffDecoder : ImageDecoder
{
private TiffDecoder()
{
}
/// <summary>
/// Gets the shared instance.
/// </summary>
public static TiffDecoder Instance { get; } = new();
/// <inheritdoc/>
protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
{

2
src/ImageSharp/Formats/Tiff/TiffFormat.cs

@ -15,7 +15,7 @@ public sealed class TiffFormat : IImageFormat<TiffMetadata, TiffFrameMetadata>
}
/// <summary>
/// Gets the current instance.
/// Gets the shared instance.
/// </summary>
public static TiffFormat Instance { get; } = new TiffFormat();

2
src/ImageSharp/Formats/Webp/WebpConfigurationModule.cs

@ -11,7 +11,7 @@ public sealed class WebpConfigurationModule : IImageFormatConfigurationModule
/// <inheritdoc/>
public void Configure(Configuration configuration)
{
configuration.ImageFormatsManager.SetDecoder(WebpFormat.Instance, new WebpDecoder());
configuration.ImageFormatsManager.SetDecoder(WebpFormat.Instance, WebpDecoder.Instance);
configuration.ImageFormatsManager.SetEncoder(WebpFormat.Instance, new WebpEncoder());
configuration.ImageFormatsManager.AddImageFormatDetector(new WebpImageFormatDetector());
}

9
src/ImageSharp/Formats/Webp/WebpDecoder.cs

@ -10,6 +10,15 @@ namespace SixLabors.ImageSharp.Formats.Webp;
/// </summary>
public sealed class WebpDecoder : ImageDecoder
{
private WebpDecoder()
{
}
/// <summary>
/// Gets the shared instance.
/// </summary>
public static WebpDecoder Instance { get; } = new();
/// <inheritdoc/>
protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
{

2
src/ImageSharp/Formats/Webp/WebpFormat.cs

@ -13,7 +13,7 @@ public sealed class WebpFormat : IImageFormat<WebpMetadata, WebpFrameMetadata>
}
/// <summary>
/// Gets the current instance.
/// Gets the shared instance.
/// </summary>
public static WebpFormat Instance { get; } = new();

2
tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg.cs

@ -16,7 +16,7 @@ public class DecodeJpeg
private void GenericSetup(string imageSubpath)
{
this.decoder = new JpegDecoder();
this.decoder = JpegDecoder.Instance;
byte[] bytes = File.ReadAllBytes(Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, imageSubpath));
this.preloadedImageStream = new MemoryStream(bytes);
}

3
tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs

@ -25,7 +25,6 @@ public class IdentifyJpeg
public IImageInfo Identify()
{
using MemoryStream memoryStream = new(this.jpegBytes);
JpegDecoder decoder = new();
return decoder.Identify(DecoderOptions.Default, memoryStream);
return JpegDecoder.Instance.Identify(DecoderOptions.Default, memoryStream);
}
}

3
tests/ImageSharp.Benchmarks/LoadResizeSave/LoadResizeSaveStressRunner.cs

@ -208,8 +208,7 @@ public class LoadResizeSaveStressRunner
TargetSize = new ImageSharpSize(this.ThumbnailSize, this.ThumbnailSize)
};
var decoder = new JpegDecoder();
using ImageSharpImage image = decoder.Decode(options, inputStream);
using ImageSharpImage image = JpegDecoder.Instance.Decode(options, inputStream);
this.LogImageProcessed(image.Width, image.Height);
// Reduce the size of the file

79
tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs

@ -25,8 +25,6 @@ public class BmpDecoderTests
public static readonly string[] BitfieldsBmpFiles = BitFields;
private static BmpDecoder BmpDecoder => new();
public static readonly TheoryData<string, int, int, PixelResolutionUnit> RatioFiles =
new()
{
@ -40,7 +38,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode_MiscellaneousBitmaps<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
if (TestEnvironment.IsWindows)
@ -61,7 +59,7 @@ public class BmpDecoderTests
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100);
using Image<Rgba32> image = provider.GetImage(BmpDecoder);
using Image<Rgba32> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider, nonContiguousBuffersStr);
if (TestEnvironment.IsWindows)
@ -81,7 +79,7 @@ public class BmpDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(BmpDecoder));
InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(BmpDecoder.Instance));
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
}
@ -90,7 +88,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecodeBitfields<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -101,7 +99,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode_Inverted<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -112,7 +110,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode_1Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, new SystemDrawingReferenceDecoder());
}
@ -123,7 +121,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode_2Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
// Reference decoder cant decode 2-bit, compare to reference output instead.
@ -135,7 +133,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode_4Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -145,7 +143,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode_8Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -155,7 +153,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -165,7 +163,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -175,7 +173,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode_32BitV4Header_Fast<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -190,7 +188,7 @@ public class BmpDecoderTests
RleSkippedPixelHandling skippedPixelHandling = TestEnvironment.IsWindows ? RleSkippedPixelHandling.Black : RleSkippedPixelHandling.FirstColorOfPalette;
BmpDecoderOptions options = new() { RleSkippedPixelHandling = skippedPixelHandling };
using Image<TPixel> image = provider.GetImage(BmpDecoder, options);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance, options);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -203,7 +201,7 @@ public class BmpDecoderTests
RleSkippedPixelHandling skippedPixelHandling = TestEnvironment.IsWindows ? RleSkippedPixelHandling.Black : RleSkippedPixelHandling.FirstColorOfPalette;
BmpDecoderOptions options = new() { RleSkippedPixelHandling = skippedPixelHandling };
using Image<TPixel> image = provider.GetImage(BmpDecoder, options);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance, options);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -217,7 +215,7 @@ public class BmpDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
BmpDecoderOptions options = new() { RleSkippedPixelHandling = RleSkippedPixelHandling.Black };
using Image<TPixel> image = provider.GetImage(BmpDecoder, options);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance, options);
image.DebugSave(provider);
if (TestEnvironment.IsWindows)
{
@ -232,7 +230,7 @@ public class BmpDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
BmpDecoderOptions options = new() { RleSkippedPixelHandling = RleSkippedPixelHandling.FirstColorOfPalette };
using Image<TPixel> image = provider.GetImage(BmpDecoder, options);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance, options);
image.DebugSave(provider);
image.CompareToOriginal(provider, new MagickReferenceDecoder());
}
@ -251,7 +249,7 @@ public class BmpDecoderTests
}
BmpDecoderOptions options = new() { RleSkippedPixelHandling = RleSkippedPixelHandling.FirstColorOfPalette };
using Image<TPixel> image = provider.GetImage(BmpDecoder, options);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance, options);
image.DebugSave(provider);
image.CompareToOriginal(provider, new MagickReferenceDecoder());
}
@ -272,7 +270,7 @@ public class BmpDecoderTests
}
BmpDecoderOptions options = new() { RleSkippedPixelHandling = RleSkippedPixelHandling.Black };
using Image<TPixel> image = provider.GetImage(BmpDecoder, options);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance, options);
image.DebugSave(provider);
// Neither System.Drawing nor MagickReferenceDecoder decode this file.
@ -285,7 +283,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecodeAlphaBitfields<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
// Neither System.Drawing nor MagickReferenceDecoder decode this file.
@ -298,7 +296,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecodeBitmap_WithAlphaChannel<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, new MagickReferenceDecoder());
}
@ -308,7 +306,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecodeBitfields_WithUnusualBitmasks<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
// Choosing large tolerance of 6.1 here, because for some reason with the MagickReferenceDecoder the alpha channel
@ -325,7 +323,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecodeBmpv2<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
// Do not validate. Reference files will fail validation.
@ -337,7 +335,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecodeBmpv3<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -347,7 +345,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecodeLessThanFullPalette<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, new MagickReferenceDecoder());
}
@ -358,7 +356,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecodeOversizedPalette<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
if (TestEnvironment.IsWindows)
{
@ -372,7 +370,7 @@ public class BmpDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
=> Assert.Throws<InvalidImageContentException>(() =>
{
using (provider.GetImage(BmpDecoder))
using (provider.GetImage(BmpDecoder.Instance))
{
}
});
@ -384,7 +382,7 @@ public class BmpDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
=> Assert.Throws<NotSupportedException>(() =>
{
using (provider.GetImage(BmpDecoder))
using (provider.GetImage(BmpDecoder.Instance))
{
}
});
@ -394,7 +392,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecodeAdobeBmpv3<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, new MagickReferenceDecoder());
}
@ -404,7 +402,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecodeAdobeBmpv3_WithAlpha<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, new MagickReferenceDecoder());
}
@ -414,7 +412,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecodeBmpv4<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -425,7 +423,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecodeBmpv5<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -435,7 +433,7 @@ public class BmpDecoderTests
public void BmpDecoder_RespectsFileHeaderOffset<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -445,7 +443,7 @@ public class BmpDecoderTests
public void BmpDecoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -455,7 +453,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode4BytePerEntryPalette<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -507,8 +505,7 @@ public class BmpDecoderTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new BmpDecoder();
using Image<Rgba32> image = decoder.Decode<Rgba32>(DecoderOptions.Default, stream);
using Image<Rgba32> image = BmpDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream);
ImageMetadata meta = image.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);
@ -520,7 +517,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode_Os2v2XShortHeader<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
// Neither System.Drawing or MagickReferenceDecoder can correctly decode this file.
@ -533,7 +530,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode_Os2v2Header<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
// System.Drawing can not decode this image. MagickReferenceDecoder can decode it,
@ -554,7 +551,7 @@ public class BmpDecoderTests
public void BmpDecoder_CanDecode_Os2BitmapArray<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(BmpDecoder);
using Image<TPixel> image = provider.GetImage(BmpDecoder.Instance);
image.DebugSave(provider);
// Neither System.Drawing or MagickReferenceDecoder can correctly decode this file.

8
tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs

@ -17,8 +17,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp;
[Trait("Format", "Bmp")]
public class BmpEncoderTests
{
private static BmpDecoder BmpDecoder => new();
private static BmpEncoder BmpEncoder => new();
public static readonly TheoryData<BmpBitsPerPixel> BitsPerPixel =
@ -200,7 +198,7 @@ public class BmpEncoderTests
// arrange
var encoder = new BmpEncoder() { BitsPerPixel = bitsPerPixel };
using var memoryStream = new MemoryStream();
using Image<TPixel> input = provider.GetImage(BmpDecoder);
using Image<TPixel> input = provider.GetImage(BmpDecoder.Instance);
// act
encoder.Encode(input, memoryStream);
@ -222,7 +220,7 @@ public class BmpEncoderTests
// arrange
var encoder = new BmpEncoder() { BitsPerPixel = bitsPerPixel };
using var memoryStream = new MemoryStream();
using Image<TPixel> input = provider.GetImage(BmpDecoder);
using Image<TPixel> input = provider.GetImage(BmpDecoder.Instance);
// act
encoder.Encode(input, memoryStream);
@ -331,7 +329,7 @@ public class BmpEncoderTests
public void Encode_PreservesColorProfile<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> input = provider.GetImage(new BmpDecoder(), new());
using Image<TPixel> input = provider.GetImage(BmpDecoder.Instance, new());
ImageSharp.Metadata.Profiles.Icc.IccProfile expectedProfile = input.Metadata.IccProfile;
byte[] expectedProfileBytes = expectedProfile.ToByteArray();

2
tests/ImageSharp.Tests/Formats/Bmp/BmpMetadataTests.cs

@ -51,7 +51,7 @@ public class BmpMetadataTests
public void Decoder_CanReadColorProfile<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(new BmpDecoder()))
using (Image<TPixel> image = provider.GetImage(BmpDecoder.Instance))
{
ImageSharp.Metadata.ImageMetadata metaData = image.Metadata;
Assert.NotNull(metaData);

18
tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs

@ -18,8 +18,6 @@ public class GifDecoderTests
{
private const PixelTypes TestPixelTypes = PixelTypes.Rgba32 | PixelTypes.RgbaVector | PixelTypes.Argb32;
private static GifDecoder GifDecoder => new();
public static readonly string[] MultiFrameTestFiles =
{
TestImages.Gif.Giphy, TestImages.Gif.Kumin
@ -46,7 +44,7 @@ public class GifDecoderTests
MaxFrames = 1
};
using Image<TPixel> image = provider.GetImage(GifDecoder, options);
using Image<TPixel> image = provider.GetImage(GifDecoder.Instance, options);
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
@ -68,7 +66,7 @@ public class GifDecoderTests
fixed (byte* data = testFile.Bytes.AsSpan(0, length))
{
using var stream = new UnmanagedMemoryStream(data, length);
using Image<Rgba32> image = GifDecoder.Decode<Rgba32>(DecoderOptions.Default, stream);
using Image<Rgba32> image = GifDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream);
Assert.Equal((200, 200), (image.Width, image.Height));
}
}
@ -102,7 +100,7 @@ public class GifDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
DecoderOptions options = new() { MaxFrames = 1 };
using Image<TPixel> image = provider.GetImage(new GifDecoder(), options);
using Image<TPixel> image = provider.GetImage(GifDecoder.Instance, options);
Assert.Equal(1, image.Frames.Count);
}
@ -111,7 +109,7 @@ public class GifDecoderTests
public void CanDecodeAllFrames<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(new GifDecoder());
using Image<TPixel> image = provider.GetImage(GifDecoder.Instance);
Assert.True(image.Frames.Count > 1);
}
@ -137,7 +135,7 @@ public class GifDecoderTests
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(GifDecoder);
using Image<TPixel> image = provider.GetImage(GifDecoder.Instance);
});
Assert.NotNull(ex);
Assert.Contains("Width or height should not be 0", ex.Message);
@ -149,7 +147,7 @@ public class GifDecoderTests
public void Decode_WithMaxDimensions_Works<TPixel>(TestImageProvider<TPixel> provider, int expectedWidth, int expectedHeight)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(GifDecoder);
using Image<TPixel> image = provider.GetImage(GifDecoder.Instance);
Assert.Equal(expectedWidth, image.Width);
Assert.Equal(expectedHeight, image.Height);
}
@ -216,7 +214,7 @@ public class GifDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(GifDecoder));
InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(GifDecoder.Instance));
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
}
@ -233,7 +231,7 @@ public class GifDecoderTests
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100);
using Image<Rgba32> image = provider.GetImage(GifDecoder);
using Image<Rgba32> image = provider.GetImage(GifDecoder.Instance);
image.DebugSave(provider, nonContiguousBuffersStr);
image.CompareToOriginal(provider);
}

26
tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs

@ -56,7 +56,7 @@ public class GifMetadataTests
{
var testFile = TestFile.Create(TestImages.Gif.Rings);
using Image<Rgba32> image = testFile.CreateRgba32Image(new GifDecoder());
using Image<Rgba32> image = testFile.CreateRgba32Image(GifDecoder.Instance);
GifMetadata metadata = image.Metadata.GetGifMetadata();
Assert.Equal(1, metadata.Comments.Count);
Assert.Equal("ImageSharp", metadata.Comments[0]);
@ -72,7 +72,7 @@ public class GifMetadataTests
var testFile = TestFile.Create(TestImages.Gif.Rings);
using Image<Rgba32> image = testFile.CreateRgba32Image(new GifDecoder(), options);
using Image<Rgba32> image = testFile.CreateRgba32Image(GifDecoder.Instance, options);
GifMetadata metadata = image.Metadata.GetGifMetadata();
Assert.Equal(0, metadata.Comments.Count);
}
@ -82,7 +82,7 @@ public class GifMetadataTests
{
var testFile = TestFile.Create(TestImages.Gif.LargeComment);
using Image<Rgba32> image = testFile.CreateRgba32Image(new GifDecoder());
using Image<Rgba32> image = testFile.CreateRgba32Image(GifDecoder.Instance);
GifMetadata metadata = image.Metadata.GetGifMetadata();
Assert.Equal(2, metadata.Comments.Count);
Assert.Equal(new string('c', 349), metadata.Comments[0]);
@ -92,7 +92,7 @@ public class GifMetadataTests
[Fact]
public void Encode_PreservesTextData()
{
var decoder = new GifDecoder();
var decoder = GifDecoder.Instance;
var testFile = TestFile.Create(TestImages.Gif.LargeComment);
using Image<Rgba32> input = testFile.CreateRgba32Image(decoder);
@ -113,8 +113,7 @@ public class GifMetadataTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new GifDecoder();
IImageInfo image = decoder.Identify(DecoderOptions.Default, stream);
IImageInfo image = GifDecoder.Instance.Identify(DecoderOptions.Default, stream);
ImageMetadata meta = image.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);
@ -127,8 +126,7 @@ public class GifMetadataTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new GifDecoder();
IImageInfo image = await decoder.IdentifyAsync(DecoderOptions.Default, stream);
IImageInfo image = await GifDecoder.Instance.IdentifyAsync(DecoderOptions.Default, stream);
ImageMetadata meta = image.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);
@ -141,8 +139,7 @@ public class GifMetadataTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new GifDecoder();
using Image<Rgba32> image = decoder.Decode<Rgba32>(DecoderOptions.Default, stream);
using Image<Rgba32> image = GifDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream);
ImageMetadata meta = image.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);
@ -155,8 +152,7 @@ public class GifMetadataTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new GifDecoder();
using Image<Rgba32> image = await decoder.DecodeAsync<Rgba32>(DecoderOptions.Default, stream);
using Image<Rgba32> image = await GifDecoder.Instance.DecodeAsync<Rgba32>(DecoderOptions.Default, stream);
ImageMetadata meta = image.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);
@ -169,8 +165,7 @@ public class GifMetadataTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new GifDecoder();
IImageInfo image = decoder.Identify(DecoderOptions.Default, stream);
IImageInfo image = GifDecoder.Instance.Identify(DecoderOptions.Default, stream);
GifMetadata meta = image.Metadata.GetGifMetadata();
Assert.Equal(repeatCount, meta.RepeatCount);
}
@ -181,8 +176,7 @@ public class GifMetadataTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new GifDecoder();
using Image<Rgba32> image = decoder.Decode<Rgba32>(DecoderOptions.Default, stream);
using Image<Rgba32> image = GifDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream);
GifMetadata meta = image.Metadata.GetGifMetadata();
Assert.Equal(repeatCount, meta.RepeatCount);
}

5
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs

@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
@ -28,7 +29,7 @@ public partial class JpegDecoderTests
provider.LimitAllocatorBufferCapacity().InPixels(16_000);
}
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
image.DebugSave(provider, testOutputDetails: nonContiguousBuffersStr);
provider.Utility.TestName = DecodeBaselineJpegOutputName;
@ -57,7 +58,7 @@ public partial class JpegDecoderTests
public void DecodeJpeg_WithArithmeticCoding<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Tolerant(0.002f), ReferenceDecoder);
}

32
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs

@ -65,7 +65,7 @@ public partial class JpegDecoderTests
bool exifProfilePresent,
bool iccProfilePresent) => TestMetadataImpl(
useIdentify,
JpegDecoder,
JpegDecoder.Instance,
imagePath,
expectedPixelSize,
exifProfilePresent,
@ -77,8 +77,7 @@ public partial class JpegDecoderTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new JpegDecoder();
using Image image = decoder.Decode(DecoderOptions.Default, stream);
using Image image = JpegDecoder.Instance.Decode(DecoderOptions.Default, stream);
ImageMetadata meta = image.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);
@ -91,8 +90,7 @@ public partial class JpegDecoderTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new JpegDecoder();
IImageInfo image = decoder.Identify(DecoderOptions.Default, stream);
IImageInfo image = JpegDecoder.Instance.Identify(DecoderOptions.Default, stream);
ImageMetadata meta = image.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);
@ -105,8 +103,7 @@ public partial class JpegDecoderTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new JpegDecoder();
IImageInfo image = await decoder.IdentifyAsync(DecoderOptions.Default, stream);
IImageInfo image = await JpegDecoder.Instance.IdentifyAsync(DecoderOptions.Default, stream);
ImageMetadata meta = image.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);
@ -119,8 +116,7 @@ public partial class JpegDecoderTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new JpegDecoder();
IImageInfo image = decoder.Identify(DecoderOptions.Default, stream);
IImageInfo image = JpegDecoder.Instance.Identify(DecoderOptions.Default, stream);
JpegMetadata meta = image.Metadata.GetJpegMetadata();
Assert.Equal(quality, meta.Quality);
}
@ -131,7 +127,7 @@ public partial class JpegDecoderTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
using Image image = JpegDecoder.Decode(DecoderOptions.Default, stream);
using Image image = JpegDecoder.Instance.Decode(DecoderOptions.Default, stream);
JpegMetadata meta = image.Metadata.GetJpegMetadata();
Assert.Equal(quality, meta.Quality);
}
@ -142,7 +138,7 @@ public partial class JpegDecoderTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
using Image image = await JpegDecoder.DecodeAsync(DecoderOptions.Default, stream);
using Image image = await JpegDecoder.Instance.DecodeAsync(DecoderOptions.Default, stream);
JpegMetadata meta = image.Metadata.GetJpegMetadata();
Assert.Equal(quality, meta.Quality);
}
@ -159,7 +155,7 @@ public partial class JpegDecoderTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
IImageInfo image = JpegDecoder.Identify(DecoderOptions.Default, stream);
IImageInfo image = JpegDecoder.Instance.Identify(DecoderOptions.Default, stream);
JpegMetadata meta = image.Metadata.GetJpegMetadata();
Assert.Equal(expectedColorType, meta.ColorType);
}
@ -173,7 +169,7 @@ public partial class JpegDecoderTests
public void Decode_DetectsCorrectColorType<TPixel>(TestImageProvider<TPixel> provider, JpegEncodingColor expectedColorType)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
JpegMetadata meta = image.Metadata.GetJpegMetadata();
Assert.Equal(expectedColorType, meta.ColorType);
}
@ -255,7 +251,7 @@ public partial class JpegDecoderTests
// Snake.jpg has both Exif and ICC profiles defined:
TestFile testFile = TestFile.Create(TestImages.Jpeg.Baseline.Snake);
using Image<Rgba32> image = testFile.CreateRgba32Image(JpegDecoder, options);
using Image<Rgba32> image = testFile.CreateRgba32Image(JpegDecoder.Instance, options);
if (ignoreMetadata)
{
Assert.Null(image.Metadata.ExifProfile);
@ -273,7 +269,7 @@ public partial class JpegDecoderTests
[InlineData(true)]
public void Decoder_Reads_Correct_Resolution_From_Jfif(bool useIdentify) => TestImageInfo(
TestImages.Jpeg.Baseline.Floorplan,
JpegDecoder,
JpegDecoder.Instance,
useIdentify,
imageInfo =>
{
@ -286,7 +282,7 @@ public partial class JpegDecoderTests
[InlineData(true)]
public void Decoder_Reads_Correct_Resolution_From_Exif(bool useIdentify) => TestImageInfo(
TestImages.Jpeg.Baseline.Jpeg420Exif,
JpegDecoder,
JpegDecoder.Instance,
useIdentify,
imageInfo =>
{
@ -301,7 +297,7 @@ public partial class JpegDecoderTests
{
Exception ex = Record.Exception(() =>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
});
Assert.Null(ex);
}
@ -313,7 +309,7 @@ public partial class JpegDecoderTests
{
Exception ex = Record.Exception(() =>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
ExifProfile clone = image.Metadata.ExifProfile.DeepClone();
});
Assert.Null(ex);

7
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs

@ -2,6 +2,7 @@
// Licensed under the Six Labors Split License.
using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
@ -19,7 +20,7 @@ public partial class JpegDecoderTests
public void DecodeProgressiveJpeg<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
image.DebugSave(provider);
provider.Utility.TestName = DecodeProgressiveJpegOutputName;
@ -35,7 +36,7 @@ public partial class JpegDecoderTests
public void DecodeProgressiveJpeg_WithArithmeticCoding<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Tolerant(0.004f), ReferenceDecoder);
}
@ -51,7 +52,7 @@ public partial class JpegDecoderTests
provider.LimitAllocatorBufferCapacity().InBytesSqrt(200);
using Image<Rgb24> image = provider.GetImage(JpegDecoder);
using Image<Rgb24> image = provider.GetImage(JpegDecoder.Instance);
image.DebugSave(provider, nonContiguousBuffersStr);
provider.Utility.TestName = DecodeProgressiveJpegOutputName;

28
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -63,8 +63,6 @@ public partial class JpegDecoderTests
private ITestOutputHelper Output { get; }
private static JpegDecoder JpegDecoder => new();
[Fact]
public void ParseStream_BasicPropertiesAreCorrect()
{
@ -104,7 +102,7 @@ public partial class JpegDecoderTests
public void JpegDecoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
image.DebugSave(provider);
provider.Utility.TestName = DecodeBaselineJpegOutputName;
@ -120,7 +118,7 @@ public partial class JpegDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
DecoderOptions options = new() { TargetSize = new() { Width = 150, Height = 150 } };
using Image<TPixel> image = provider.GetImage(JpegDecoder, options);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance, options);
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
@ -142,7 +140,7 @@ public partial class JpegDecoderTests
TargetSize = new() { Width = 150, Height = 150 },
Sampler = KnownResamplers.Bicubic
};
using Image<TPixel> image = provider.GetImage(JpegDecoder, options);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance, options);
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
@ -166,7 +164,7 @@ public partial class JpegDecoderTests
ResizeMode = JpegDecoderResizeMode.IdctOnly
};
using Image<TPixel> image = provider.GetImage(JpegDecoder, specializedOptions);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance, specializedOptions);
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
@ -190,7 +188,7 @@ public partial class JpegDecoderTests
ResizeMode = JpegDecoderResizeMode.ScaleOnly
};
using Image<TPixel> image = provider.GetImage(JpegDecoder, specializedOptions);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance, specializedOptions);
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
@ -214,7 +212,7 @@ public partial class JpegDecoderTests
ResizeMode = JpegDecoderResizeMode.Combined
};
using Image<TPixel> image = provider.GetImage(JpegDecoder, specializedOptions);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance, specializedOptions);
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
@ -233,7 +231,7 @@ public partial class JpegDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InBytesSqrt(10);
InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(JpegDecoder));
InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(JpegDecoder.Instance));
this.Output.WriteLine(ex.Message);
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
}
@ -245,7 +243,7 @@ public partial class JpegDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InBytesSqrt(10);
InvalidImageContentException ex = await Assert.ThrowsAsync<InvalidImageContentException>(() => provider.GetImageAsync(JpegDecoder));
InvalidImageContentException ex = await Assert.ThrowsAsync<InvalidImageContentException>(() => provider.GetImageAsync(JpegDecoder.Instance));
this.Output.WriteLine(ex.Message);
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
}
@ -256,7 +254,7 @@ public partial class JpegDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
=> Assert.Throws<NotSupportedException>(() =>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
});
// https://github.com/SixLabors/ImageSharp/pull/1732
@ -265,7 +263,7 @@ public partial class JpegDecoderTests
public void Issue1732_DecodesWithRgbColorSpace<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -276,7 +274,7 @@ public partial class JpegDecoderTests
public void Issue2057_DecodeWorks<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -287,7 +285,7 @@ public partial class JpegDecoderTests
public void Issue2133_DeduceColorSpace<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
@ -298,7 +296,7 @@ public partial class JpegDecoderTests
public void Issue2136_DecodeWorks<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}

11
tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.Metadata.cs

@ -100,10 +100,11 @@ public partial class JpegEncoderTests
Exception ex = Record.Exception(() =>
{
var encoder = new JpegEncoder();
var stream = new MemoryStream();
using Image<TPixel> image = provider.GetImage(JpegDecoder);
image.Save(stream, encoder);
using (var stream = new MemoryStream())
{
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
image.Save(stream, encoder);
}
});
Assert.Null(ex);
@ -162,7 +163,7 @@ public partial class JpegEncoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
// arrange
using Image<TPixel> input = provider.GetImage(JpegDecoder);
using Image<TPixel> input = provider.GetImage(JpegDecoder.Instance);
using var memoryStream = new MemoryStream();
// act

2
tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs

@ -13,8 +13,6 @@ public partial class JpegEncoderTests
{
private static JpegEncoder JpegEncoder => new();
private static JpegDecoder JpegDecoder => new();
private static readonly TheoryData<int> TestQualities = new()
{
40,

2
tests/ImageSharp.Tests/Formats/Pbm/PbmDecoderTests.cs

@ -108,7 +108,7 @@ public class PbmDecoderTests
TargetSize = new() { Width = 150, Height = 150 }
};
using Image<TPixel> image = provider.GetImage(new PbmDecoder(), options);
using Image<TPixel> image = provider.GetImage(PbmDecoder.Instance, options);
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";

4
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs

@ -70,10 +70,8 @@ public partial class PngDecoderTests
WriteChunk(memStream, chunkName);
WriteDataChunk(memStream);
var decoder = new PngDecoder();
ImageFormatException exception =
Assert.Throws<InvalidImageContentException>(() => decoder.Decode<Rgb24>(DecoderOptions.Default, memStream));
Assert.Throws<InvalidImageContentException>(() => PngDecoder.Instance.Decode<Rgb24>(DecoderOptions.Default, memStream));
Assert.Equal($"CRC Error. PNG {chunkName} chunk is corrupt!", exception.Message);
}

66
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -19,8 +19,6 @@ public partial class PngDecoderTests
{
private const PixelTypes TestPixelTypes = PixelTypes.Rgba32 | PixelTypes.RgbaVector | PixelTypes.Argb32;
private static PngDecoder PngDecoder => new();
public static readonly string[] CommonTestImages =
{
TestImages.Png.Splash,
@ -102,7 +100,7 @@ public partial class PngDecoderTests
public void Decode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -117,7 +115,7 @@ public partial class PngDecoderTests
TargetSize = new() { Width = 150, Height = 150 }
};
using Image<TPixel> image = provider.GetImage(PngDecoder, options);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance, options);
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
@ -135,7 +133,7 @@ public partial class PngDecoderTests
public void Decode_WithAverageFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -146,7 +144,7 @@ public partial class PngDecoderTests
public void Decode_WithSubFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -156,7 +154,7 @@ public partial class PngDecoderTests
public void Decode_WithUpFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -167,7 +165,7 @@ public partial class PngDecoderTests
public void Decode_WithPaethFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -178,7 +176,7 @@ public partial class PngDecoderTests
public void Decode_GrayWithAlpha<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -190,7 +188,7 @@ public partial class PngDecoderTests
public void Decode_Interlaced<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -205,7 +203,7 @@ public partial class PngDecoderTests
public void Decode_Indexed<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -216,7 +214,7 @@ public partial class PngDecoderTests
public void Decode_48Bpp<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -227,7 +225,7 @@ public partial class PngDecoderTests
public void Decode_64Bpp<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -240,7 +238,7 @@ public partial class PngDecoderTests
public void Decoder_L8bitInterlaced<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -250,7 +248,7 @@ public partial class PngDecoderTests
public void Decode_L16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -261,7 +259,7 @@ public partial class PngDecoderTests
public void Decode_GrayAlpha16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -271,7 +269,7 @@ public partial class PngDecoderTests
public void Decoder_CanDecode_Grey8bitInterlaced_WithAlpha<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -281,7 +279,7 @@ public partial class PngDecoderTests
public void Decoder_CanDecode_CorruptedImages<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -291,7 +289,7 @@ public partial class PngDecoderTests
public void Decoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
@ -319,7 +317,7 @@ public partial class PngDecoderTests
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
});
Assert.NotNull(ex);
@ -335,7 +333,7 @@ public partial class PngDecoderTests
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
});
Assert.NotNull(ex);
@ -350,7 +348,7 @@ public partial class PngDecoderTests
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
});
Assert.Null(ex);
@ -365,7 +363,7 @@ public partial class PngDecoderTests
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
});
Assert.NotNull(ex);
@ -381,7 +379,7 @@ public partial class PngDecoderTests
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
});
Assert.NotNull(ex);
@ -396,7 +394,7 @@ public partial class PngDecoderTests
InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
});
Assert.NotNull(ex);
Assert.Contains("CRC Error. PNG IDAT chunk is corrupt!", ex.Message);
@ -411,7 +409,7 @@ public partial class PngDecoderTests
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
});
@ -427,7 +425,7 @@ public partial class PngDecoderTests
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
});
@ -443,7 +441,7 @@ public partial class PngDecoderTests
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
});
@ -459,7 +457,7 @@ public partial class PngDecoderTests
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
// We don't have another x-plat reference decoder that can be compared for this image.
@ -480,7 +478,7 @@ public partial class PngDecoderTests
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
});
@ -493,7 +491,7 @@ public partial class PngDecoderTests
public void Issue2209_Decode_HasTransparencyIsTrue<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
PngMetadata metadata = image.Metadata.GetPngMetadata();
Assert.True(metadata.HasTransparency);
@ -520,7 +518,7 @@ public partial class PngDecoderTests
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider);
// We don't have another x-plat reference decoder that can be compared for this image.
@ -540,7 +538,7 @@ public partial class PngDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(PngDecoder));
InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(PngDecoder.Instance));
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
}
@ -555,7 +553,7 @@ public partial class PngDecoderTests
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100);
using Image<Rgba32> image = provider.GetImage(PngDecoder);
using Image<Rgba32> image = provider.GetImage(PngDecoder.Instance);
image.DebugSave(provider, testOutputDetails: nonContiguousBuffersStr);
image.CompareToOriginal(provider);
}

8
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -284,9 +284,7 @@ public partial class PngEncoderTests
stream.Seek(0, SeekOrigin.Begin);
var decoder = new PngDecoder();
Image image = decoder.Decode(DecoderOptions.Default, stream);
using Image image = PngDecoder.Instance.Decode(DecoderOptions.Default, stream);
PngMetadata metadata = image.Metadata.GetPngMetadata();
Assert.Equal(pngColorType, metadata.ColorType);
@ -542,7 +540,7 @@ public partial class PngEncoderTests
// https://github.com/SixLabors/ImageSharp/issues/935
using var ms = new MemoryStream();
var testFile = TestFile.Create(TestImages.Png.Issue935);
using Image<Rgba32> image = testFile.CreateRgba32Image(new PngDecoder());
using Image<Rgba32> image = testFile.CreateRgba32Image(PngDecoder.Instance);
image.Save(ms, new PngEncoder { ColorType = PngColorType.RgbWithAlpha });
}
@ -594,7 +592,7 @@ public partial class PngEncoderTests
// occurs within the encoder itself leaving the input image unaffected.
// This means we are benefiting from testing our decoder also.
using FileStream fileStream = File.OpenRead(actualOutputFile);
using Image<TPixel> imageSharpImage = new PngDecoder().Decode<TPixel>(DecoderOptions.Default, fileStream);
using Image<TPixel> imageSharpImage = PngDecoder.Instance.Decode<TPixel>(DecoderOptions.Default, fileStream);
fileStream.Position = 0;

32
tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs

@ -52,7 +52,7 @@ public class PngMetadataTests
public void Decoder_CanReadTextData<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(new PngDecoder());
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance);
VerifyTextDataIsPresent(meta);
}
@ -62,13 +62,12 @@ public class PngMetadataTests
public void Encoder_PreservesTextData<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
var decoder = new PngDecoder();
using Image<TPixel> input = provider.GetImage(decoder);
using Image<TPixel> input = provider.GetImage(PngDecoder.Instance);
using var memoryStream = new MemoryStream();
input.Save(memoryStream, new PngEncoder());
memoryStream.Position = 0;
using Image<Rgba32> image = decoder.Decode<Rgba32>(DecoderOptions.Default, memoryStream);
using Image<Rgba32> image = PngDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, memoryStream);
PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance);
VerifyTextDataIsPresent(meta);
}
@ -78,7 +77,7 @@ public class PngMetadataTests
public void Decoder_IgnoresInvalidTextData<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(new PngDecoder());
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance);
Assert.DoesNotContain(meta.TextData, m => m.Value is "leading space");
Assert.DoesNotContain(meta.TextData, m => m.Value is "trailing space");
@ -93,8 +92,7 @@ public class PngMetadataTests
public void Encode_UseCompression_WhenTextIsGreaterThenThreshold_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
var decoder = new PngDecoder();
using Image<TPixel> input = provider.GetImage(decoder);
using Image<TPixel> input = provider.GetImage(PngDecoder.Instance);
using var memoryStream = new MemoryStream();
// This will be a zTXt chunk.
@ -111,7 +109,7 @@ public class PngMetadataTests
});
memoryStream.Position = 0;
using Image<Rgba32> image = decoder.Decode<Rgba32>(DecoderOptions.Default, memoryStream);
using Image<Rgba32> image = PngDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, memoryStream);
PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance);
Assert.Contains(meta.TextData, m => m.Equals(expectedText));
Assert.Contains(meta.TextData, m => m.Equals(expectedTextNoneLatin));
@ -127,7 +125,7 @@ public class PngMetadataTests
SkipMetadata = false
};
using Image<TPixel> image = provider.GetImage(new PngDecoder(), options);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance, options);
Assert.NotNull(image.Metadata.ExifProfile);
ExifProfile exif = image.Metadata.ExifProfile;
VerifyExifDataIsPresent(exif);
@ -143,9 +141,7 @@ public class PngMetadataTests
SkipMetadata = true
};
PngDecoder decoder = new();
using Image<TPixel> image = provider.GetImage(decoder, options);
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance, options);
Assert.Null(image.Metadata.ExifProfile);
}
@ -159,7 +155,7 @@ public class PngMetadataTests
var testFile = TestFile.Create(TestImages.Png.Blur);
using Image<Rgba32> image = testFile.CreateRgba32Image(new PngDecoder(), options);
using Image<Rgba32> image = testFile.CreateRgba32Image(PngDecoder.Instance, options);
PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance);
Assert.Equal(1, meta.TextData.Count);
@ -178,7 +174,7 @@ public class PngMetadataTests
var testFile = TestFile.Create(TestImages.Png.PngWithMetadata);
using Image<Rgba32> image = testFile.CreateRgba32Image(new PngDecoder(), options);
using Image<Rgba32> image = testFile.CreateRgba32Image(PngDecoder.Instance, options);
PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance);
Assert.Equal(0, meta.TextData.Count);
}
@ -189,8 +185,7 @@ public class PngMetadataTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new PngDecoder();
using Image<Rgba32> image = decoder.Decode<Rgba32>(DecoderOptions.Default, stream);
using Image<Rgba32> image = PngDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream);
ImageMetadata meta = image.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);
@ -202,7 +197,7 @@ public class PngMetadataTests
public void Encode_PreservesColorProfile<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> input = provider.GetImage(new PngDecoder());
using Image<TPixel> input = provider.GetImage(PngDecoder.Instance);
ImageSharp.Metadata.Profiles.Icc.IccProfile expectedProfile = input.Metadata.IccProfile;
byte[] expectedProfileBytes = expectedProfile.ToByteArray();
@ -224,8 +219,7 @@ public class PngMetadataTests
{
var testFile = TestFile.Create(imagePath);
using var stream = new MemoryStream(testFile.Bytes, false);
var decoder = new PngDecoder();
IImageInfo image = decoder.Identify(DecoderOptions.Default, stream);
IImageInfo image = PngDecoder.Instance.Identify(DecoderOptions.Default, stream);
ImageMetadata meta = image.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);

4
tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs

@ -24,7 +24,7 @@ public class PngSmokeTests
// image.Save(provider.Utility.GetTestOutputFileName("bmp"));
image.Save(ms, new PngEncoder());
ms.Position = 0;
using Image<Rgba32> img2 = new PngDecoder().Decode<Rgba32>(DecoderOptions.Default, ms);
using Image<Rgba32> img2 = PngDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, ms);
ImageComparer.Tolerant().VerifySimilarity(image, img2);
// img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder());
@ -45,7 +45,7 @@ public class PngSmokeTests
// image.Save(provider.Utility.GetTestOutputFileName("png", "resize"));
image.Save(ms, new PngEncoder());
ms.Position = 0;
using Image<Rgba32> img2 = new PngDecoder().Decode<Rgba32>(DecoderOptions.Default, ms);
using Image<Rgba32> img2 = PngDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, ms);
ImageComparer.Tolerant().VerifySimilarity(image, img2);
}
}

124
tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs

@ -17,14 +17,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tga;
[ValidateDisposedMemoryAllocations]
public class TgaDecoderTests
{
private static TgaDecoder TgaDecoder => new();
[Theory]
[WithFile(Gray8BitTopLeft, PixelTypes.Rgba32)]
public void TgaDecoder_CanDecode_Gray_WithTopLeftOrigin_8Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -36,7 +34,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_Gray_WithBottomLeftOrigin_8Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -48,7 +46,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_Gray_WithTopRightOrigin_8Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -60,7 +58,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_Gray_WithBottomRightOrigin_8Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -72,7 +70,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithTopLeftOrigin_8Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -84,7 +82,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithTopRightOrigin_8Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -96,7 +94,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithBottomLeftOrigin_8Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -108,7 +106,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithBottomRightOrigin_8Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -120,7 +118,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_Gray_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
@ -135,7 +133,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_Gray_WithBottomLeftOrigin_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
@ -150,7 +148,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_Gray_WithBottomRightOrigin_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
@ -165,7 +163,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_Gray_WithTopRightOrigin_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
@ -180,7 +178,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
@ -195,7 +193,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithBottomLeftOrigin_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
@ -210,7 +208,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithBottomRightOrigin_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
@ -225,7 +223,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithTopRightOrigin_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
@ -240,7 +238,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_15Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -252,7 +250,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_15Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -264,7 +262,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithBottomLeftOrigin_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -276,7 +274,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_WithPalette_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -288,7 +286,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithTopLeftOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -300,7 +298,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithBottomLeftOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -312,7 +310,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithTopRightOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -324,7 +322,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithBottomRightOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -336,7 +334,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_WithTopLeftOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -348,7 +346,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_WithTopRightOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -360,7 +358,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_WithBottomRightOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -372,7 +370,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_Palette_WithTopLeftOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -384,7 +382,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithTopLeftOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -396,7 +394,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithTopRightOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -408,7 +406,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithBottomLeftOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -420,7 +418,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithBottomRightOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -432,7 +430,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_WithBottomLeftOrigin_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -444,7 +442,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_WithBottomLeftOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -456,7 +454,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_WithTopLeftOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -468,7 +466,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_WithBottomLeftOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -480,7 +478,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_WithTopRightOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -492,7 +490,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RunLengthEncoded_WithBottomRightOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -504,7 +502,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RLE_Paletted_WithTopLeftOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -516,7 +514,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RLE_Paletted_WithBottomLeftOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -528,7 +526,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RLE_WithTopRightOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -540,7 +538,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RLE_Paletted_WithBottomRightOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -552,7 +550,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithPaletteBottomLeftOrigin_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -564,7 +562,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithPaletteTopLeftOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -576,7 +574,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithPaletteTopRightOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -588,7 +586,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithPaletteBottomLeftOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -600,7 +598,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithPaletteBottomRightOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -612,7 +610,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RLE_WithPaletteTopLeftOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -624,7 +622,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RLE_WithPaletteTopRightOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -636,7 +634,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RLE_WithPaletteBottomLeftOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -648,7 +646,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_RLE_WithPaletteBottomRightOrigin_24Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -660,7 +658,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithPalette_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -672,7 +670,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithPalette_WithBottomLeftOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -684,7 +682,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithPalette_WithBottomRightOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -696,7 +694,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WithPalette_WithTopRightOrigin_32Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -709,7 +707,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WhenAlphaBitsNotSet_16Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -722,7 +720,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_WhenAlphaBitsNotSet<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
// Using here the reference output instead of the the reference decoder,
// because the reference decoder does not ignore the alpha data here.
@ -738,7 +736,7 @@ public class TgaDecoderTests
public void TgaDecoder_CanDecode_LegacyFormat<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TgaDecoder))
using (Image<TPixel> image = provider.GetImage(TgaDecoder.Instance))
{
image.DebugSave(provider);
ImageComparingUtils.CompareWithReferenceDecoder(provider, image);
@ -755,7 +753,7 @@ public class TgaDecoderTests
TargetSize = new() { Width = 150, Height = 150 }
};
using Image<TPixel> image = provider.GetImage(TgaDecoder, options);
using Image<TPixel> image = provider.GetImage(TgaDecoder.Instance, options);
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
@ -775,7 +773,7 @@ public class TgaDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(TgaDecoder));
InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(TgaDecoder.Instance));
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
}
@ -790,7 +788,7 @@ public class TgaDecoderTests
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100);
using Image<Rgba32> image = provider.GetImage(TgaDecoder);
using Image<Rgba32> image = provider.GetImage(TgaDecoder.Instance);
image.DebugSave(provider, testOutputDetails: nonContiguousBuffersStr);
if (TestEnvironment.IsWindows)

4
tests/ImageSharp.Tests/Formats/Tiff/BigTiffDecoderTests.cs

@ -39,7 +39,7 @@ public class BigTiffDecoderTests : TiffDecoderBaseTester
{
Assert.Throws<ImageDifferenceIsOverThresholdException>(() => TestTiffDecoder(provider));
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
ExifProfile exif = image.Frames.RootFrame.Metadata.ExifProfile;
// PhotometricInterpretation is required tag: https://www.awaresystems.be/imaging/tiff/tifftags/photometricinterpretation.html
@ -104,7 +104,7 @@ public class BigTiffDecoderTests : TiffDecoderBaseTester
public void TiffDecoder_SubIfd8<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
ExifProfile meta = image.Frames.RootFrame.Metadata.ExifProfile;

4
tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderBaseTester.cs

@ -12,14 +12,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff;
public abstract class TiffDecoderBaseTester
{
protected static TiffDecoder TiffDecoder => new();
protected static MagickReferenceDecoder ReferenceDecoder => new();
protected static void TestTiffDecoder<TPixel>(TestImageProvider<TPixel> provider, IImageDecoder referenceDecoder = null, bool useExactComparer = true, float compareTolerance = 0.001f)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(
provider,

26
tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs

@ -21,7 +21,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
[WithFile(MultiframeDifferentSize, PixelTypes.Rgba32)]
[WithFile(MultiframeDifferentVariants, PixelTypes.Rgba32)]
public void ThrowsNotSupported<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => Assert.Throws<NotSupportedException>(() => provider.GetImage(TiffDecoder));
where TPixel : unmanaged, IPixel<TPixel> => Assert.Throws<NotSupportedException>(() => provider.GetImage(TiffDecoder.Instance));
[Theory]
[InlineData(RgbUncompressed, 24, 256, 256, 300, 300, PixelResolutionUnit.PixelsPerInch)]
@ -201,7 +201,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
if (TestEnvironment.IsMacOS)
{
// Only debug save on OSX: For some reason the reference image has a difference of 50%. The imagesharp output file looks ok though.
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
image.DebugSave(provider);
return;
}
@ -258,7 +258,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
if (TestEnvironment.IsMacOS)
{
// Only debug save on OSX: For some reason the reference image has a difference of 50%. The imagesharp output file looks ok though.
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
image.DebugSave(provider);
return;
}
@ -285,7 +285,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
if (TestEnvironment.IsMacOS)
{
// Only debug save on OSX: For some reason the reference image has a difference of 50%. The imagesharp output file looks ok though.
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
image.DebugSave(provider);
return;
}
@ -387,7 +387,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
if (TestEnvironment.IsMacOS)
{
// Only debug save on OSX: For some reason the reference image has a difference of 50%. The imagesharp output file looks ok though.
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
image.DebugSave(provider);
return;
}
@ -427,7 +427,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
if (TestEnvironment.IsMacOS)
{
// Only debug save on OSX: For some reason the reference image has a difference of 50%. The imagesharp output file looks ok though.
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
image.DebugSave(provider);
return;
}
@ -466,7 +466,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
if (TestEnvironment.IsMacOS)
{
// Only debug save on OSX: For some reason the reference image has a difference of 50%. The imagesharp output file looks ok though.
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
image.DebugSave(provider);
return;
}
@ -496,7 +496,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
if (TestEnvironment.IsMacOS)
{
// Only debug save on OSX: For some reason the reference image has a difference of 50%. The imagesharp output file looks ok though.
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
image.DebugSave(provider);
return;
}
@ -667,7 +667,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
where TPixel : unmanaged, IPixel<TPixel>
{
DecoderOptions options = new() { MaxFrames = 1 };
using Image<TPixel> image = provider.GetImage(new TiffDecoder(), options);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance, options);
Assert.Equal(1, image.Frames.Count);
}
@ -696,7 +696,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
{
MaxFrames = 1
};
using Image<TPixel> image = provider.GetImage(TiffDecoder, decoderOptions);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance, decoderOptions);
image.DebugSave(provider);
image.CompareToOriginal(
provider,
@ -723,7 +723,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
where TPixel : unmanaged, IPixel<TPixel> => Assert.Throws<ImageFormatException>(
() =>
{
using (provider.GetImage(TiffDecoder))
using (provider.GetImage(TiffDecoder.Instance))
{
}
});
@ -739,7 +739,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
public void DecodeMultiframe<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
Assert.True(image.Frames.Count > 1);
image.DebugSave(provider);
@ -759,7 +759,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
TargetSize = new() { Width = 150, Height = 150 }
};
using Image<TPixel> image = provider.GetImage(TiffDecoder, options);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance, options);
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";

2
tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs

@ -295,7 +295,7 @@ public class TiffEncoderTests : TiffEncoderBaseTester
[Theory]
[WithFile(FlowerRgb444Planar, PixelTypes.Rgba32)]
public void TiffEncoder_EncodePlanar_AndReload_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, TiffPhotometricInterpretation.Rgb, imageDecoder: new TiffDecoder());
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, TiffPhotometricInterpretation.Rgb, imageDecoder: TiffDecoder.Instance);
[Theory]
[WithFile(Calliphora_RgbUncompressed, PixelTypes.Rgba32)]

14
tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs

@ -17,8 +17,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff;
[Trait("Format", "Tiff")]
public class TiffMetadataTests
{
private static TiffDecoder TiffDecoder => new();
private class NumberComparer : IEqualityComparer<Number>
{
public bool Equals(Number x, Number y) => x.Equals(y);
@ -46,7 +44,7 @@ public class TiffMetadataTests
public void TiffFrameMetadata_CloneIsDeep<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
TiffFrameMetadata meta = image.Frames.RootFrame.Metadata.GetTiffMetadata();
var cloneSameAsSampleMetaData = (TiffFrameMetadata)meta.DeepClone();
VerifyExpectedTiffFrameMetaDataIsPresent(cloneSameAsSampleMetaData);
@ -113,7 +111,7 @@ public class TiffMetadataTests
where TPixel : unmanaged, IPixel<TPixel>
{
DecoderOptions options = new() { SkipMetadata = ignoreMetadata };
using Image<TPixel> image = provider.GetImage(new TiffDecoder(), options);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance, options);
TiffMetadata meta = image.Metadata.GetTiffMetadata();
ImageFrameMetadata rootFrameMetaData = image.Frames.RootFrame.Metadata;
@ -137,7 +135,7 @@ public class TiffMetadataTests
public void CanDecodeImage_WithIptcDataAsLong<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
IptcProfile iptcProfile = image.Frames.RootFrame.Metadata.IptcProfile;
Assert.NotNull(iptcProfile);
@ -151,7 +149,7 @@ public class TiffMetadataTests
public void BaselineTags<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
ImageFrame<TPixel> rootFrame = image.Frames.RootFrame;
Assert.Equal(32, rootFrame.Width);
Assert.Equal(32, rootFrame.Height);
@ -208,7 +206,7 @@ public class TiffMetadataTests
public void SubfileType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(TiffDecoder);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
TiffMetadata meta = image.Metadata.GetTiffMetadata();
Assert.NotNull(meta);
@ -232,7 +230,7 @@ public class TiffMetadataTests
{
// Load Tiff image
DecoderOptions options = new() { SkipMetadata = false };
using Image<TPixel> image = provider.GetImage(TiffDecoder, options);
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance, options);
ImageMetadata inputMetaData = image.Metadata;
ImageFrame<TPixel> rootFrameInput = image.Frames.RootFrame;

60
tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs

@ -16,8 +16,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp;
[ValidateDisposedMemoryAllocations]
public class WebpDecoderTests
{
private static WebpDecoder WebpDecoder => new();
private static MagickReferenceDecoder ReferenceDecoder => new();
private static string TestImageLossyHorizontalFilterPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, Lossy.AlphaCompressedHorizontalFilter);
@ -63,7 +61,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossy_WithoutFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -77,7 +75,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossy_WithSimpleFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -98,7 +96,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossy_WithComplexFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -111,7 +109,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossy_VerySmall<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -128,7 +126,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossy_WithPartitions<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -140,7 +138,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossy_WithSegmentation<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -155,7 +153,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossy_WithSharpnessLevel<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -178,7 +176,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossy_WithAlpha<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -188,7 +186,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossless_WithAlpha<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -199,7 +197,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossless_WithoutTransforms<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -216,7 +214,7 @@ public class WebpDecoderTests
TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -230,7 +228,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossless_WithColorIndexTransform<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -241,7 +239,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossless_WithPredictorTransform<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -252,7 +250,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossless_WithCrossColorTransform<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -274,7 +272,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossless_WithTwoTransforms<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -291,7 +289,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Lossless_WithThreeTransforms<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -301,7 +299,7 @@ public class WebpDecoderTests
public void Decode_AnimatedLossless_VerifyAllFrames<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
WebpMetadata webpMetaData = image.Metadata.GetWebpMetadata();
WebpFrameMetadata frameMetaData = image.Frames.RootFrame.Metadata.GetWebpMetadata();
@ -318,7 +316,7 @@ public class WebpDecoderTests
public void Decode_AnimatedLossy_VerifyAllFrames<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
WebpMetadata webpMetaData = image.Metadata.GetWebpMetadata();
WebpFrameMetadata frameMetaData = image.Frames.RootFrame.Metadata.GetWebpMetadata();
@ -336,7 +334,7 @@ public class WebpDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
DecoderOptions options = new() { MaxFrames = 1 };
using Image<TPixel> image = provider.GetImage(new WebpDecoder(), options);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance, options);
Assert.Equal(1, image.Frames.Count);
}
@ -348,7 +346,7 @@ public class WebpDecoderTests
where TPixel : unmanaged, IPixel<TPixel>
{
// Just make sure no exception is thrown. The reference decoder fails to load the image.
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
}
@ -362,7 +360,7 @@ public class WebpDecoderTests
TargetSize = new() { Width = 150, Height = 150 }
};
using Image<TPixel> image = provider.GetImage(WebpDecoder, options);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance, options);
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
@ -380,7 +378,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Issue1594<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -391,7 +389,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Issue2243<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -402,7 +400,7 @@ public class WebpDecoderTests
public void WebpDecoder_CanDecode_Issue2257<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -414,7 +412,7 @@ public class WebpDecoderTests
Assert.Throws<ImageFormatException>(
() =>
{
using (provider.GetImage(WebpDecoder))
using (provider.GetImage(WebpDecoder.Instance))
{
}
});
@ -422,7 +420,7 @@ public class WebpDecoderTests
private static void RunDecodeLossyWithHorizontalFilter()
{
var provider = TestImageProvider<Rgba32>.File(TestImageLossyHorizontalFilterPath);
using Image<Rgba32> image = provider.GetImage(WebpDecoder);
using Image<Rgba32> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -430,7 +428,7 @@ public class WebpDecoderTests
private static void RunDecodeLossyWithVerticalFilter()
{
var provider = TestImageProvider<Rgba32>.File(TestImageLossyVerticalFilterPath);
using Image<Rgba32> image = provider.GetImage(WebpDecoder);
using Image<Rgba32> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -438,7 +436,7 @@ public class WebpDecoderTests
private static void RunDecodeLossyWithSimpleFilterTest()
{
var provider = TestImageProvider<Rgba32>.File(TestImageLossySimpleFilterPath);
using Image<Rgba32> image = provider.GetImage(WebpDecoder);
using Image<Rgba32> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
@ -446,7 +444,7 @@ public class WebpDecoderTests
private static void RunDecodeLossyWithComplexFilterTest()
{
var provider = TestImageProvider<Rgba32>.File(TestImageLossyComplexFilterPath);
using Image<Rgba32> image = provider.GetImage(WebpDecoder);
using Image<Rgba32> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}

16
tests/ImageSharp.Tests/Formats/WebP/WebpMetaDataTests.cs

@ -12,8 +12,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp;
[Trait("Format", "Webp")]
public class WebpMetaDataTests
{
private static WebpDecoder WebpDecoder => new();
[Theory]
[WithFile(TestImages.Webp.Lossy.BikeWithExif, PixelTypes.Rgba32, false)]
[WithFile(TestImages.Webp.Lossy.BikeWithExif, PixelTypes.Rgba32, true)]
@ -21,7 +19,7 @@ public class WebpMetaDataTests
where TPixel : unmanaged, IPixel<TPixel>
{
DecoderOptions options = new() { SkipMetadata = ignoreMetadata };
using Image<TPixel> image = provider.GetImage(WebpDecoder, options);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance, options);
if (ignoreMetadata)
{
Assert.Null(image.Metadata.ExifProfile);
@ -42,7 +40,7 @@ public class WebpMetaDataTests
where TPixel : unmanaged, IPixel<TPixel>
{
DecoderOptions options = new() { SkipMetadata = ignoreMetadata };
using Image<TPixel> image = provider.GetImage(WebpDecoder, options);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance, options);
if (ignoreMetadata)
{
Assert.Null(image.Metadata.ExifProfile);
@ -67,7 +65,7 @@ public class WebpMetaDataTests
where TPixel : unmanaged, IPixel<TPixel>
{
DecoderOptions options = new() { SkipMetadata = ignoreMetadata };
using Image<TPixel> image = provider.GetImage(WebpDecoder, options);
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance, options);
if (ignoreMetadata)
{
Assert.Null(image.Metadata.IccProfile);
@ -86,7 +84,7 @@ public class WebpMetaDataTests
where TPixel : unmanaged, IPixel<TPixel>
{
DecoderOptions options = new() { SkipMetadata = ignoreMetadata };
using Image<TPixel> image = await provider.GetImageAsync(WebpDecoder, options);
using Image<TPixel> image = await provider.GetImageAsync(WebpDecoder.Instance, options);
if (ignoreMetadata)
{
Assert.Null(image.Metadata.XmpProfile);
@ -129,7 +127,7 @@ public class WebpMetaDataTests
where TPixel : unmanaged, IPixel<TPixel>
{
// arrange
using Image<TPixel> input = provider.GetImage(WebpDecoder);
using Image<TPixel> input = provider.GetImage(WebpDecoder.Instance);
using var memoryStream = new MemoryStream();
ExifProfile expectedExif = input.Metadata.ExifProfile;
@ -150,7 +148,7 @@ public class WebpMetaDataTests
where TPixel : unmanaged, IPixel<TPixel>
{
// arrange
using Image<TPixel> input = provider.GetImage(WebpDecoder);
using Image<TPixel> input = provider.GetImage(WebpDecoder.Instance);
using var memoryStream = new MemoryStream();
ExifProfile expectedExif = input.Metadata.ExifProfile;
@ -171,7 +169,7 @@ public class WebpMetaDataTests
public void Encode_PreservesColorProfile<TPixel>(TestImageProvider<TPixel> provider, WebpFileFormatType fileFormat)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> input = provider.GetImage(WebpDecoder);
using Image<TPixel> input = provider.GetImage(WebpDecoder.Instance);
ImageSharp.Metadata.Profiles.Icc.IccProfile expectedProfile = input.Metadata.IccProfile;
byte[] expectedProfileBytes = expectedProfile.ToByteArray();

4
tests/ImageSharp.Tests/Formats/WebP/YuvConversionTests.cs

@ -14,8 +14,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp;
[Trait("Format", "Webp")]
public class YuvConversionTests
{
private static WebpDecoder WebpDecoder => new();
private static MagickReferenceDecoder ReferenceDecoder => new();
private static string TestImageLossyFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, TestImages.Webp.Lossy.NoFilter06);
@ -23,7 +21,7 @@ public class YuvConversionTests
public static void RunUpSampleYuvToRgbTest()
{
var provider = TestImageProvider<Rgba32>.File(TestImageLossyFullPath);
using Image<Rgba32> image = provider.GetImage(WebpDecoder);
using Image<Rgba32> image = provider.GetImage(WebpDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}

12
tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs

@ -10,10 +10,6 @@ namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.IPTC;
public class IptcProfileTests
{
private static JpegDecoder JpegDecoder => new();
private static TiffDecoder TiffDecoder => new();
public static IEnumerable<object[]> AllIptcTags()
{
foreach (object tag in Enum.GetValues(typeof(IptcTag)))
@ -117,7 +113,7 @@ public class IptcProfileTests
public void ReadIptcMetadata_FromJpg_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(JpegDecoder))
using (Image<TPixel> image = provider.GetImage(JpegDecoder.Instance))
{
Assert.NotNull(image.Metadata.IptcProfile);
var iptcValues = image.Metadata.IptcProfile.Values.ToList();
@ -130,7 +126,7 @@ public class IptcProfileTests
public void ReadIptcMetadata_FromTiff_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TiffDecoder))
using (Image<TPixel> image = provider.GetImage(TiffDecoder.Instance))
{
IptcProfile iptc = image.Frames.RootFrame.Metadata.IptcProfile;
Assert.NotNull(iptc);
@ -166,7 +162,7 @@ public class IptcProfileTests
public void ReadApp13_WithEmptyIptc_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder);
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
Assert.Null(image.Metadata.IptcProfile);
}
@ -231,7 +227,7 @@ public class IptcProfileTests
public void WritingImage_PreservesIptcProfile()
{
// arrange
var image = new Image<Rgba32>(1, 1);
using Image<Rgba32> image = new(1, 1);
image.Metadata.IptcProfile = new IptcProfile();
const string expectedCaptionWriter = "unittest";
const string expectedCaption = "test";

32
tests/ImageSharp.Tests/Metadata/Profiles/XMP/XmpProfileTests.cs

@ -16,22 +16,12 @@ namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.Xmp;
public class XmpProfileTests
{
private static GifDecoder GifDecoder => new();
private static JpegDecoder JpegDecoder => new();
private static PngDecoder PngDecoder => new();
private static TiffDecoder TiffDecoder => new();
private static WebpDecoder WebpDecoder => new();
[Theory]
[WithFile(TestImages.Gif.Receipt, PixelTypes.Rgba32)]
public async Task ReadXmpMetadata_FromGif_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = await provider.GetImageAsync(GifDecoder))
using (Image<TPixel> image = await provider.GetImageAsync(GifDecoder.Instance))
{
XmpProfile actual = image.Metadata.XmpProfile ?? image.Frames.RootFrame.Metadata.XmpProfile;
XmpProfileContainsExpectedValues(actual);
@ -45,7 +35,7 @@ public class XmpProfileTests
public async Task ReadXmpMetadata_FromJpg_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = await provider.GetImageAsync(JpegDecoder))
using (Image<TPixel> image = await provider.GetImageAsync(JpegDecoder.Instance))
{
XmpProfile actual = image.Metadata.XmpProfile ?? image.Frames.RootFrame.Metadata.XmpProfile;
XmpProfileContainsExpectedValues(actual);
@ -57,7 +47,7 @@ public class XmpProfileTests
public async Task ReadXmpMetadata_FromPng_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = await provider.GetImageAsync(PngDecoder))
using (Image<TPixel> image = await provider.GetImageAsync(PngDecoder.Instance))
{
XmpProfile actual = image.Metadata.XmpProfile ?? image.Frames.RootFrame.Metadata.XmpProfile;
XmpProfileContainsExpectedValues(actual);
@ -69,7 +59,7 @@ public class XmpProfileTests
public async Task ReadXmpMetadata_FromTiff_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = await provider.GetImageAsync(TiffDecoder))
using (Image<TPixel> image = await provider.GetImageAsync(TiffDecoder.Instance))
{
XmpProfile actual = image.Metadata.XmpProfile ?? image.Frames.RootFrame.Metadata.XmpProfile;
XmpProfileContainsExpectedValues(actual);
@ -81,7 +71,7 @@ public class XmpProfileTests
public async Task ReadXmpMetadata_FromWebp_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = await provider.GetImageAsync(WebpDecoder))
using (Image<TPixel> image = await provider.GetImageAsync(WebpDecoder.Instance))
{
XmpProfile actual = image.Metadata.XmpProfile ?? image.Frames.RootFrame.Metadata.XmpProfile;
XmpProfileContainsExpectedValues(actual);
@ -121,7 +111,7 @@ public class XmpProfileTests
public void WritingGif_PreservesXmpProfile()
{
// arrange
var image = new Image<Rgba32>(1, 1);
using var image = new Image<Rgba32>(1, 1);
XmpProfile original = CreateMinimalXmlProfile();
image.Metadata.XmpProfile = original;
var encoder = new GifEncoder();
@ -139,7 +129,7 @@ public class XmpProfileTests
public void WritingJpeg_PreservesXmpProfile()
{
// arrange
var image = new Image<Rgba32>(1, 1);
using var image = new Image<Rgba32>(1, 1);
XmpProfile original = CreateMinimalXmlProfile();
image.Metadata.XmpProfile = original;
var encoder = new JpegEncoder();
@ -158,7 +148,7 @@ public class XmpProfileTests
{
// arrange
var provider = TestImageProvider<Rgba32>.File(TestImages.Jpeg.Baseline.ExtendedXmp);
using Image<Rgba32> image = await provider.GetImageAsync(JpegDecoder);
using Image<Rgba32> image = await provider.GetImageAsync(JpegDecoder.Instance);
XmpProfile original = image.Metadata.XmpProfile;
var encoder = new JpegEncoder();
@ -175,7 +165,7 @@ public class XmpProfileTests
public void WritingPng_PreservesXmpProfile()
{
// arrange
var image = new Image<Rgba32>(1, 1);
using var image = new Image<Rgba32>(1, 1);
XmpProfile original = CreateMinimalXmlProfile();
image.Metadata.XmpProfile = original;
var encoder = new PngEncoder();
@ -193,7 +183,7 @@ public class XmpProfileTests
public void WritingTiff_PreservesXmpProfile()
{
// arrange
var image = new Image<Rgba32>(1, 1);
using var image = new Image<Rgba32>(1, 1);
XmpProfile original = CreateMinimalXmlProfile();
image.Frames.RootFrame.Metadata.XmpProfile = original;
var encoder = new TiffEncoder();
@ -211,7 +201,7 @@ public class XmpProfileTests
public void WritingWebp_PreservesXmpProfile()
{
// arrange
var image = new Image<Rgba32>(1, 1);
using var image = new Image<Rgba32>(1, 1);
XmpProfile original = CreateMinimalXmlProfile();
image.Metadata.XmpProfile = original;
var encoder = new WebpEncoder();

Loading…
Cancel
Save