mirror of https://github.com/SixLabors/ImageSharp
11 changed files with 143 additions and 9 deletions
@ -0,0 +1,107 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
|
|||
using ImageMagick; |
|||
|
|||
using SixLabors.ImageSharp.Advanced; |
|||
using SixLabors.ImageSharp.Formats.Tga; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|||
|
|||
using Xunit; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Formats.Tga |
|||
{ |
|||
using static TestImages.Tga; |
|||
|
|||
public class TgaDecoderTests |
|||
{ |
|||
[Theory] |
|||
[WithFile(Grey, PixelTypes.Rgba32)] |
|||
public void TgaDecoder_CanDecode_Uncompressed_MonoChrome<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage(new TgaDecoder())) |
|||
{ |
|||
image.DebugSave(provider); |
|||
CompareWithReferenceDecoder(provider, image); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFile(Bit16, PixelTypes.Rgba32)] |
|||
public void TgaDecoder_CanDecode_Uncompressed_16Bit<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage(new TgaDecoder())) |
|||
{ |
|||
image.DebugSave(provider); |
|||
CompareWithReferenceDecoder(provider, image); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFile(Bit24, PixelTypes.Rgba32)] |
|||
public void TgaDecoder_CanDecode_Uncompressed_24Bit<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage(new TgaDecoder())) |
|||
{ |
|||
image.DebugSave(provider); |
|||
CompareWithReferenceDecoder(provider, image); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFile(Bit32, PixelTypes.Rgba32)] |
|||
public void TgaDecoder_CanDecode_Uncompressed_32Bit<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage(new TgaDecoder())) |
|||
{ |
|||
image.DebugSave(provider); |
|||
CompareWithReferenceDecoder(provider, image); |
|||
} |
|||
} |
|||
|
|||
private void CompareWithReferenceDecoder<TPixel>(TestImageProvider<TPixel> provider, Image<TPixel> image) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
string path = TestImageProvider<TPixel>.GetFilePathOrNull(provider); |
|||
if (path == null) |
|||
{ |
|||
throw new InvalidOperationException("CompareToOriginal() works only with file providers!"); |
|||
} |
|||
|
|||
TestFile testFile = TestFile.Create(path); |
|||
Image<Rgba32> magickImage = this.DecodeWithMagick<Rgba32>(Configuration.Default, new FileInfo(testFile.FullPath)); |
|||
ImageComparer.Exact.VerifySimilarity(image, magickImage); |
|||
} |
|||
|
|||
private Image<TPixel> DecodeWithMagick<TPixel>(Configuration configuration, FileInfo fileInfo) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (var magickImage = new MagickImage(fileInfo)) |
|||
{ |
|||
var result = new Image<TPixel>(configuration, magickImage.Width, magickImage.Height); |
|||
Span<TPixel> resultPixels = result.GetPixelSpan(); |
|||
|
|||
using (IPixelCollection pixels = magickImage.GetPixelsUnsafe()) |
|||
{ |
|||
byte[] data = pixels.ToByteArray(PixelMapping.RGBA); |
|||
|
|||
PixelOperations<TPixel>.Instance.FromRgba32Bytes( |
|||
configuration, |
|||
data, |
|||
resultPixels, |
|||
resultPixels.Length); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:3b2bc922e2397ce8cd8b1e7792f20e2c7edad68ad8fac037a5b91bba5148a80b |
|||
size 97518 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:26d55794c9b012b07517d1129630ccc35ca56015cbdd481debea00826130f925 |
|||
size 146268 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:cb3774b695d2409f3e7584dc67ce7b3d8a75377c194e7f33e4cc315b3ae36a35 |
|||
size 195018 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:75f3ce893f38d90767c692eb9628026c0421330934a5cbb686813ec26a9606d2 |
|||
size 48768 |
|||
Loading…
Reference in new issue