// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System.Runtime.Intrinsics.X86; using Microsoft.DotNet.RemoteExecutor; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Tga; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.TestUtilities; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using static SixLabors.ImageSharp.Tests.TestImages.Tga; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests.Formats.Tga; [Trait("Format", "Tga")] [ValidateDisposedMemoryAllocations] public class TgaDecoderTests { [Theory] [WithFile(Gray8BitTopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_Gray_WithTopLeftOrigin_8Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Gray8BitBottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_Gray_WithBottomLeftOrigin_8Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Gray8BitTopRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_Gray_WithTopRightOrigin_8Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Gray8BitBottomRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_Gray_WithBottomRightOrigin_8Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Gray8BitRleTopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithTopLeftOrigin_8Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Gray8BitRleTopRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithTopRightOrigin_8Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Gray8BitRleBottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithBottomLeftOrigin_8Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Gray8BitRleBottomRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithBottomRightOrigin_8Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Gray16BitTopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_Gray_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); // Using here the reference output instead of the the reference decoder, // because the reference decoder output seems not to be correct for 16bit gray images. image.CompareToReferenceOutput(ImageComparer.Exact, provider); } } [Theory] [WithFile(Gray16BitBottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_Gray_WithBottomLeftOrigin_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); // Using here the reference output instead of the the reference decoder, // because the reference decoder output seems not to be correct for 16bit gray images. image.CompareToReferenceOutput(ImageComparer.Exact, provider); } } [Theory] [WithFile(Gray16BitBottomRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_Gray_WithBottomRightOrigin_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); // Using here the reference output instead of the the reference decoder, // because the reference decoder output seems not to be correct for 16bit gray images. image.CompareToReferenceOutput(ImageComparer.Exact, provider); } } [Theory] [WithFile(Gray16BitTopRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_Gray_WithTopRightOrigin_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); // Using here the reference output instead of the the reference decoder, // because the reference decoder output seems not to be correct for 16bit gray images. image.CompareToReferenceOutput(ImageComparer.Exact, provider); } } [Theory] [WithFile(Gray16BitRleTopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); // Using here the reference output instead of the the reference decoder, // because the reference decoder output seems not to be correct for 16bit gray images. image.CompareToReferenceOutput(ImageComparer.Exact, provider); } } [Theory] [WithFile(Gray16BitRleBottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithBottomLeftOrigin_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); // Using here the reference output instead of the the reference decoder, // because the reference decoder output seems not to be correct for 16bit gray images. image.CompareToReferenceOutput(ImageComparer.Exact, provider); } } [Theory] [WithFile(Gray16BitRleBottomRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithBottomRightOrigin_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); // Using here the reference output instead of the the reference decoder, // because the reference decoder output seems not to be correct for 16bit gray images. image.CompareToReferenceOutput(ImageComparer.Exact, provider); } } [Theory] [WithFile(Gray16BitRleTopRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_Gray_WithTopRightOrigin_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); // Using here the reference output instead of the the reference decoder, // because the reference decoder output seems not to be correct for 16bit gray images. image.CompareToReferenceOutput(ImageComparer.Exact, provider); } } [Theory] [WithFile(Bit15, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_15Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit15Rle, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_15Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit16BottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithBottomLeftOrigin_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit16PalRle, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_WithPalette_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24TopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithTopLeftOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24BottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithBottomLeftOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24TopRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithTopRightOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24BottomRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithBottomRightOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24RleTopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_WithTopLeftOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24RleTopRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_WithTopRightOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24RleBottomRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_WithBottomRightOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24TopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_Palette_WithTopLeftOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32TopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithTopLeftOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32TopRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithTopRightOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32BottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithBottomLeftOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32BottomRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithBottomRightOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit16RleBottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_WithBottomLeftOrigin_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24RleBottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_WithBottomLeftOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32RleTopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_WithTopLeftOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32RleBottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_WithBottomLeftOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32RleTopRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_WithTopRightOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32RleBottomRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RunLengthEncoded_WithBottomRightOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32PalRleTopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RLE_Paletted_WithTopLeftOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32PalRleBottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RLE_Paletted_WithBottomLeftOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32PalRleTopRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RLE_WithTopRightOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32PalRleBottomRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RLE_Paletted_WithBottomRightOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit16PalBottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithPaletteBottomLeftOrigin_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24PalTopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithPaletteTopLeftOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24PalTopRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithPaletteTopRightOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24PalBottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithPaletteBottomLeftOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24PalBottomRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithPaletteBottomRightOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24PalRleTopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RLE_WithPaletteTopLeftOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24PalRleTopRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RLE_WithPaletteTopRightOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24PalRleBottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RLE_WithPaletteBottomLeftOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit24PalRleBottomRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_RLE_WithPaletteBottomRightOrigin_24Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32PalTopLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithPalette_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32PalBottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithPalette_WithBottomLeftOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32PalBottomRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithPalette_WithBottomRightOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32PalTopRight, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithPalette_WithTopRightOrigin_32Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(NoAlphaBits16Bit, PixelTypes.Rgba32)] [WithFile(NoAlphaBits16BitRle, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WhenAlphaBitsNotSet_16Bit(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(NoAlphaBits32Bit, PixelTypes.Rgba32)] [WithFile(NoAlphaBits32BitRle, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WhenAlphaBitsNotSet(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } // Test case for legacy format, when RLE crosses multiple lines: // https://github.com/SixLabors/ImageSharp/pull/2172 [Theory] [WithFile(Github_RLE_legacy, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_LegacyFormat(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit32RleTopLeft, PixelTypes.Rgba32)] public void TgaDecoder_Decode_Resize(TestImageProvider provider) where TPixel : unmanaged, IPixel { DecoderOptions options = new() { TargetSize = new Size { Width = 150, Height = 150 } }; using Image image = provider.GetImage(TgaDecoder.Instance, options); FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}"; image.DebugSave(provider, testOutputDetails: details, appendPixelTypeToFileName: false); // Floating point differences in FMA used in the ResizeKernel result in minor pixel differences. // Output have been manually verified. // For more details see discussion: https://github.com/SixLabors/ImageSharp/pull/1513#issuecomment-763643594 image.CompareToReferenceOutput( ImageComparer.TolerantPercentage(Fma.IsSupported ? 0.0001F : 0.0016F), provider, testOutputDetails: details, appendPixelTypeToFileName: false); } // https://github.com/SixLabors/ImageSharp/issues/2629 [Theory] [WithFile(Issue2629, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_Issue2629(TestImageProvider provider) where TPixel : unmanaged, IPixel { using (Image image = provider.GetImage(TgaDecoder.Instance)) { image.DebugSave(provider); ImageComparingUtils.CompareWithReferenceDecoder(provider, image); } } [Theory] [WithFile(Bit16BottomLeft, PixelTypes.Rgba32)] [WithFile(Bit24BottomLeft, PixelTypes.Rgba32)] [WithFile(Bit32BottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_DegenerateMemoryRequest_ShouldTranslateTo_ImageFormatException(TestImageProvider provider) where TPixel : unmanaged, IPixel { provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10); InvalidImageContentException ex = Assert.Throws(() => provider.GetImage(TgaDecoder.Instance)); Assert.IsType(ex.InnerException); } [Theory] [WithFile(Bit24BottomLeft, PixelTypes.Rgba32)] [WithFile(Bit32BottomLeft, PixelTypes.Rgba32)] public void TgaDecoder_CanDecode_WithLimitedAllocatorBufferCapacity(TestImageProvider provider) { static void RunTest(string providerDump, string nonContiguousBuffersStr) { TestImageProvider provider = BasicSerializer.Deserialize>(providerDump); provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100); using Image image = provider.GetImage(TgaDecoder.Instance); image.DebugSave(provider, testOutputDetails: nonContiguousBuffersStr); if (TestEnvironment.IsWindows) { image.CompareToOriginal(provider); } } string providerDump = BasicSerializer.Serialize(provider); RemoteExecutor.Invoke( RunTest, providerDump, "Disco") .Dispose(); } }