From 0915c799d3d54798c50d7928c93004b77709c6f6 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 15 Dec 2020 12:11:58 +0100 Subject: [PATCH] A little cleanup: - Fix some warnings - Remove not necessary usings - Fix some naming violations --- .../Compression/DeflateTiffCompression.cs | 2 - .../Tiff/Compression/LzwTiffCompression.cs | 1 - .../ModifiedHuffmanTiffCompression.cs | 1 - .../Tiff/Compression/NoneTiffCompression.cs | 2 - .../Compression/PackBitsTiffCompression.cs | 6 +- .../Formats/Tiff/Compression/T4BitWriter.cs | 2 +- .../Tiff/Compression/T4TiffCompression.cs | 1 - .../Tiff/Compression/TiffBaseCompression.cs | 15 +- .../Formats/Tiff/Ifd/EntryReader.cs | 6 +- .../RgbPlanarTiffColor.cs | 12 +- .../PhotometricInterpretation/RgbTiffColor.cs | 12 +- .../TiffColorDecoderFactory.cs | 1 - .../Tiff/Streams/TiffBigEndianStream.cs | 2 - .../Tiff/Streams/TiffLittleEndianStream.cs | 2 - .../Formats/Tiff/Streams/TiffStream.cs | 1 - .../Formats/Tiff/TiffBitsPerPixel.cs | 2 +- .../Formats/Tiff/TiffDecoderCore.cs | 2 +- .../Formats/Tiff/TiffEncoderCore.cs | 4 +- .../Tiff/TiffEncoderEntriesCollector.cs | 1 - .../Tiff/TiffFrameMetadataExtensions.cs | 2 +- .../BlackIsZeroTiffColorTests.cs | 137 ++++++------ .../PaletteTiffColorTests.cs | 65 +++--- .../PhotometricInterpretationTestBase.cs | 6 +- .../RgbPlanarTiffColorTests.cs | 209 +++++++++--------- .../RgbTiffColorTests.cs | 189 ++++++++-------- .../WhiteIsZeroTiffColorTests.cs | 149 ++++++------- .../Formats/Tiff/TiffMetadataTests.cs | 15 +- .../TestUtilities/TestEnvironment.Formats.cs | 2 +- 28 files changed, 414 insertions(+), 435 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/Compression/DeflateTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/DeflateTiffCompression.cs index 074b04c6b5..73669d3cb4 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/DeflateTiffCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/DeflateTiffCompression.cs @@ -2,12 +2,10 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.IO; using System.IO.Compression; using SixLabors.ImageSharp.Compression.Zlib; using SixLabors.ImageSharp.Formats.Experimental.Tiff.Constants; -using SixLabors.ImageSharp.Formats.Experimental.Tiff.Utils; using SixLabors.ImageSharp.Formats.Tiff.Compression; using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Memory; diff --git a/src/ImageSharp/Formats/Tiff/Compression/LzwTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/LzwTiffCompression.cs index 92468a00c2..5e5cdd3791 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/LzwTiffCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/LzwTiffCompression.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.IO; using SixLabors.ImageSharp.Formats.Experimental.Tiff.Constants; using SixLabors.ImageSharp.Formats.Experimental.Tiff.Utils; diff --git a/src/ImageSharp/Formats/Tiff/Compression/ModifiedHuffmanTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/ModifiedHuffmanTiffCompression.cs index 1d7c2eef57..e46b0621dd 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/ModifiedHuffmanTiffCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/ModifiedHuffmanTiffCompression.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.IO; using SixLabors.ImageSharp.Formats.Experimental.Tiff.Constants; using SixLabors.ImageSharp.IO; diff --git a/src/ImageSharp/Formats/Tiff/Compression/NoneTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/NoneTiffCompression.cs index 9140a52e04..d1b0c79b31 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/NoneTiffCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/NoneTiffCompression.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.IO; -using SixLabors.ImageSharp.Formats.Experimental.Tiff.Utils; using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Memory; diff --git a/src/ImageSharp/Formats/Tiff/Compression/PackBitsTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/PackBitsTiffCompression.cs index a7c8b93481..181c8e558d 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/PackBitsTiffCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/PackBitsTiffCompression.cs @@ -3,9 +3,7 @@ using System; using System.Buffers; -using System.IO; -using SixLabors.ImageSharp.Formats.Experimental.Tiff.Utils; using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Memory; @@ -40,7 +38,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Compression { byte headerByte = compressedData[compressedOffset]; - if (headerByte <= (byte)127) + if (headerByte <= 127) { int literalOffset = compressedOffset + 1; int literalLength = compressedData[compressedOffset] + 1; @@ -50,7 +48,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Compression compressedOffset += literalLength + 1; decompressedOffset += literalLength; } - else if (headerByte == (byte)0x80) + else if (headerByte == 0x80) { compressedOffset += 1; } diff --git a/src/ImageSharp/Formats/Tiff/Compression/T4BitWriter.cs b/src/ImageSharp/Formats/Tiff/Compression/T4BitWriter.cs index 2e168de59b..4041a57c32 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/T4BitWriter.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/T4BitWriter.cs @@ -187,7 +187,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Compression /// /// The modified huffman is basically the same as CCITT T4, but without EOL markers and padding at the end of the rows. /// - private bool useModifiedHuffman; + private readonly bool useModifiedHuffman; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Formats/Tiff/Compression/T4TiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/T4TiffCompression.cs index f0c3a29bdd..8ffb2e6926 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/T4TiffCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/T4TiffCompression.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.IO; using SixLabors.ImageSharp.Formats.Experimental.Tiff.Constants; using SixLabors.ImageSharp.IO; diff --git a/src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs index 1937d20eca..323e777831 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs @@ -5,7 +5,6 @@ using System; using System.IO; using SixLabors.ImageSharp.Formats.Experimental.Tiff.Constants; -using SixLabors.ImageSharp.Formats.Tiff.Compression; using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Memory; @@ -18,24 +17,24 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Compression { private readonly MemoryAllocator allocator; - private TiffPhotometricInterpretation photometricInterpretation; + private readonly TiffPhotometricInterpretation photometricInterpretation; - private int width; + private readonly int width; - private int bitsPerPixel; + private readonly int bitsPerPixel; - private TiffPredictor predictor; + private readonly TiffPredictor predictor; - public TiffBaseCompression(MemoryAllocator allocator) => this.allocator = allocator; + protected TiffBaseCompression(MemoryAllocator allocator) => this.allocator = allocator; - public TiffBaseCompression(MemoryAllocator allocator, TiffPhotometricInterpretation photometricInterpretation, int width) + protected TiffBaseCompression(MemoryAllocator allocator, TiffPhotometricInterpretation photometricInterpretation, int width) : this(allocator) { this.photometricInterpretation = photometricInterpretation; this.width = width; } - public TiffBaseCompression(MemoryAllocator allocator, int width, int bitsPerPixel, TiffPredictor predictor) + protected TiffBaseCompression(MemoryAllocator allocator, int width, int bitsPerPixel, TiffPredictor predictor) : this(allocator) { this.width = width; diff --git a/src/ImageSharp/Formats/Tiff/Ifd/EntryReader.cs b/src/ImageSharp/Formats/Tiff/Ifd/EntryReader.cs index da2f96211e..b51997a7ed 100644 --- a/src/ImageSharp/Formats/Tiff/Ifd/EntryReader.cs +++ b/src/ImageSharp/Formats/Tiff/Ifd/EntryReader.cs @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff public IExifValue ReadNext() { var tagId = (ExifTagValue)this.stream.ReadUInt16(); - var dataType = (ExifDataType)EnumUtils.Parse(this.stream.ReadUInt16(), ExifDataType.Unknown); + ExifDataType dataType = EnumUtils.Parse(this.stream.ReadUInt16(), ExifDataType.Unknown); uint count = this.stream.ReadUInt32(); ExifDataType rawDataType = dataType; @@ -116,9 +116,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff private bool ReadValueOrOffset(ExifValue entry, ExifDataType rawDataType, uint count) { - if (entry.Tag == ExifTag.SubIFDOffset - || entry.Tag == ExifTag.GPSIFDOffset - /*|| entry.Tag == ExifTagValue.SubIFDs*/) + if (entry.Tag == ExifTag.SubIFDOffset || entry.Tag == ExifTag.GPSIFDOffset /*|| entry.Tag == ExifTagValue.SubIFDs*/) { // todo: ignore subIfds (exif, gps) this.stream.Skip(4); diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/RgbPlanarTiffColor.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/RgbPlanarTiffColor.cs index 20ce17d991..3ff8e34a06 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/RgbPlanarTiffColor.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/RgbPlanarTiffColor.cs @@ -33,9 +33,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff this.bitsPerSampleG = bitsPerSample[1]; this.bitsPerSampleB = bitsPerSample[2]; - this.rFactor = (float)(1 << this.bitsPerSampleR) - 1.0f; - this.gFactor = (float)(1 << this.bitsPerSampleG) - 1.0f; - this.bFactor = (float)(1 << this.bitsPerSampleB) - 1.0f; + this.rFactor = (1 << this.bitsPerSampleR) - 1.0f; + this.gFactor = (1 << this.bitsPerSampleG) - 1.0f; + this.bFactor = (1 << this.bitsPerSampleB) - 1.0f; } /// @@ -59,9 +59,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff { for (int x = left; x < left + width; x++) { - float r = ((float)rBitReader.ReadBits(this.bitsPerSampleR)) / this.rFactor; - float g = ((float)gBitReader.ReadBits(this.bitsPerSampleG)) / this.gFactor; - float b = ((float)bBitReader.ReadBits(this.bitsPerSampleB)) / this.bFactor; + float r = rBitReader.ReadBits(this.bitsPerSampleR) / this.rFactor; + float g = gBitReader.ReadBits(this.bitsPerSampleG) / this.gFactor; + float b = bBitReader.ReadBits(this.bitsPerSampleB) / this.bFactor; color.FromVector4(new Vector4(r, g, b, 1.0f)); pixels[x, y] = color; diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/RgbTiffColor.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/RgbTiffColor.cs index 6b812ed074..712bf6f2a9 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/RgbTiffColor.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/RgbTiffColor.cs @@ -33,9 +33,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff this.bitsPerSampleG = bitsPerSample[1]; this.bitsPerSampleB = bitsPerSample[2]; - this.rFactor = (float)(1 << this.bitsPerSampleR) - 1.0f; - this.gFactor = (float)(1 << this.bitsPerSampleG) - 1.0f; - this.bFactor = (float)(1 << this.bitsPerSampleB) - 1.0f; + this.rFactor = (1 << this.bitsPerSampleR) - 1.0f; + this.gFactor = (1 << this.bitsPerSampleG) - 1.0f; + this.bFactor = (1 << this.bitsPerSampleB) - 1.0f; } /// @@ -49,9 +49,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff { for (int x = left; x < left + width; x++) { - float r = ((float)bitReader.ReadBits(this.bitsPerSampleR)) / this.rFactor; - float g = ((float)bitReader.ReadBits(this.bitsPerSampleG)) / this.gFactor; - float b = ((float)bitReader.ReadBits(this.bitsPerSampleB)) / this.bFactor; + float r = bitReader.ReadBits(this.bitsPerSampleR) / this.rFactor; + float g = bitReader.ReadBits(this.bitsPerSampleG) / this.gFactor; + float b = bitReader.ReadBits(this.bitsPerSampleB) / this.bFactor; color.FromVector4(new Vector4(r, g, b, 1.0f)); pixels[x, y] = color; diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory.cs index abc502deac..633edd2cbd 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Experimental.Tiff diff --git a/src/ImageSharp/Formats/Tiff/Streams/TiffBigEndianStream.cs b/src/ImageSharp/Formats/Tiff/Streams/TiffBigEndianStream.cs index 845353acbd..021fb9d51f 100644 --- a/src/ImageSharp/Formats/Tiff/Streams/TiffBigEndianStream.cs +++ b/src/ImageSharp/Formats/Tiff/Streams/TiffBigEndianStream.cs @@ -4,8 +4,6 @@ using System; using System.IO; -using SixLabors.ImageSharp.Formats.Experimental.Tiff.Constants; - namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Streams { internal class TiffBigEndianStream : TiffStream diff --git a/src/ImageSharp/Formats/Tiff/Streams/TiffLittleEndianStream.cs b/src/ImageSharp/Formats/Tiff/Streams/TiffLittleEndianStream.cs index c31c2320a5..43c27b98fe 100644 --- a/src/ImageSharp/Formats/Tiff/Streams/TiffLittleEndianStream.cs +++ b/src/ImageSharp/Formats/Tiff/Streams/TiffLittleEndianStream.cs @@ -4,8 +4,6 @@ using System; using System.IO; -using SixLabors.ImageSharp.Formats.Experimental.Tiff.Constants; - namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Streams { internal class TiffLittleEndianStream : TiffStream diff --git a/src/ImageSharp/Formats/Tiff/Streams/TiffStream.cs b/src/ImageSharp/Formats/Tiff/Streams/TiffStream.cs index 930be0d05d..e178dd1795 100644 --- a/src/ImageSharp/Formats/Tiff/Streams/TiffStream.cs +++ b/src/ImageSharp/Formats/Tiff/Streams/TiffStream.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System.IO; -using SixLabors.ImageSharp.Formats.Experimental.Tiff.Constants; namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Streams { diff --git a/src/ImageSharp/Formats/Tiff/TiffBitsPerPixel.cs b/src/ImageSharp/Formats/Tiff/TiffBitsPerPixel.cs index ea53fa0617..2f816463cf 100644 --- a/src/ImageSharp/Formats/Tiff/TiffBitsPerPixel.cs +++ b/src/ImageSharp/Formats/Tiff/TiffBitsPerPixel.cs @@ -4,7 +4,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff { /// - /// Enumerates the available bits per pixel the tiff encoder supports. + /// Enumerates the available bits per pixel for the tiff format. /// public enum TiffBitsPerPixel { diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs index db8b59858b..e6d5f873dd 100644 --- a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs +++ b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs @@ -238,7 +238,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff /// The size (in bytes) of the required pixel buffer. private int CalculateStripBufferSize(int width, int height, int plane = -1) { - int bitsPerPixel = 0; + int bitsPerPixel; if (this.PlanarConfiguration == TiffPlanarConfiguration.Chunky) { diff --git a/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs index c7301049de..9a692a1609 100644 --- a/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs +++ b/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff public long WriteHeader(TiffWriter writer) { writer.Write(ByteOrderMarker); - writer.Write((ushort)TiffConstants.HeaderMagicNumber); + writer.Write(TiffConstants.HeaderMagicNumber); long firstIfdMarker = writer.PlaceMarker(); return firstIfdMarker; @@ -239,7 +239,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff if (dataBlock.Length % 2 == 1) { - writer.Write((byte)0); + writer.Write(0); } } diff --git a/src/ImageSharp/Formats/Tiff/TiffEncoderEntriesCollector.cs b/src/ImageSharp/Formats/Tiff/TiffEncoderEntriesCollector.cs index 41d833299a..5b26a8551e 100644 --- a/src/ImageSharp/Formats/Tiff/TiffEncoderEntriesCollector.cs +++ b/src/ImageSharp/Formats/Tiff/TiffEncoderEntriesCollector.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; -using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.Formats.Experimental.Tiff.Constants; using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata.Profiles.Exif; diff --git a/src/ImageSharp/Formats/Tiff/TiffFrameMetadataExtensions.cs b/src/ImageSharp/Formats/Tiff/TiffFrameMetadataExtensions.cs index 78e2174845..aea12dbe58 100644 --- a/src/ImageSharp/Formats/Tiff/TiffFrameMetadataExtensions.cs +++ b/src/ImageSharp/Formats/Tiff/TiffFrameMetadataExtensions.cs @@ -152,7 +152,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff IExifValue obj = FindOrCreate(meta, tag); DebugGuard.IsTrue(!obj.IsArray, "Expected non array entry"); - object val = (T)(object)value; + object val = value; return obj.TrySetValue(val); } diff --git a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs index 79dd659684..d7a4bc7ed2 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs @@ -10,18 +10,19 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation { + [Trait("Format", "Tiff")] public class BlackIsZeroTiffColorTests : PhotometricInterpretationTestBase { - private static Rgba32 gray000 = new Rgba32(0, 0, 0, 255); - private static Rgba32 gray128 = new Rgba32(128, 128, 128, 255); - private static Rgba32 gray255 = new Rgba32(255, 255, 255, 255); - private static Rgba32 gray0 = new Rgba32(0, 0, 0, 255); - private static Rgba32 gray8 = new Rgba32(136, 136, 136, 255); - private static Rgba32 grayF = new Rgba32(255, 255, 255, 255); - private static Rgba32 bit0 = new Rgba32(0, 0, 0, 255); - private static Rgba32 bit1 = new Rgba32(255, 255, 255, 255); + private static readonly Rgba32 Gray000 = new Rgba32(0, 0, 0, 255); + private static readonly Rgba32 Gray128 = new Rgba32(128, 128, 128, 255); + private static readonly Rgba32 Gray255 = new Rgba32(255, 255, 255, 255); + private static readonly Rgba32 Gray0 = new Rgba32(0, 0, 0, 255); + private static readonly Rgba32 Gray8 = new Rgba32(136, 136, 136, 255); + private static readonly Rgba32 GrayF = new Rgba32(255, 255, 255, 255); + private static readonly Rgba32 Bit0 = new Rgba32(0, 0, 0, 255); + private static readonly Rgba32 Bit1 = new Rgba32(255, 255, 255, 255); - private static readonly byte[] Bilevel_Bytes4x4 = + private static readonly byte[] BilevelBytes4X4 = { 0b01010000, 0b11110000, @@ -29,15 +30,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0b10010000 }; - private static readonly Rgba32[][] Bilevel_Result4x4 = new[] + private static readonly Rgba32[][] BilevelResult4X4 = new[] { - new[] { bit0, bit1, bit0, bit1 }, - new[] { bit1, bit1, bit1, bit1 }, - new[] { bit0, bit1, bit1, bit1 }, - new[] { bit1, bit0, bit0, bit1 } + new[] { Bit0, Bit1, Bit0, Bit1 }, + new[] { Bit1, Bit1, Bit1, Bit1 }, + new[] { Bit0, Bit1, Bit1, Bit1 }, + new[] { Bit1, Bit0, Bit0, Bit1 } }; - private static readonly byte[] Bilevel_Bytes12x4 = + private static readonly byte[] BilevelBytes12X4 = { 0b01010101, 0b01010000, 0b11111111, 0b11111111, @@ -45,15 +46,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0b10010000, 0b01100000 }; - private static readonly Rgba32[][] Bilevel_Result12x4 = + private static readonly Rgba32[][] BilevelResult12X4 = { - new[] { bit0, bit1, bit0, bit1, bit0, bit1, bit0, bit1, bit0, bit1, bit0, bit1 }, - new[] { bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1 }, - new[] { bit0, bit1, bit1, bit0, bit1, bit0, bit0, bit1, bit1, bit0, bit1, bit0 }, - new[] { bit1, bit0, bit0, bit1, bit0, bit0, bit0, bit0, bit0, bit1, bit1, bit0 } + new[] { Bit0, Bit1, Bit0, Bit1, Bit0, Bit1, Bit0, Bit1, Bit0, Bit1, Bit0, Bit1 }, + new[] { Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1 }, + new[] { Bit0, Bit1, Bit1, Bit0, Bit1, Bit0, Bit0, Bit1, Bit1, Bit0, Bit1, Bit0 }, + new[] { Bit1, Bit0, Bit0, Bit1, Bit0, Bit0, Bit0, Bit0, Bit0, Bit1, Bit1, Bit0 } }; - private static readonly byte[] Grayscale4_Bytes4x4 = + private static readonly byte[] Grayscale4Bytes4X4 = { 0x8F, 0x0F, 0xFF, 0xFF, @@ -61,15 +62,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0xF0, 0xF8 }; - private static readonly Rgba32[][] Grayscale4_Result4x4 = + private static readonly Rgba32[][] Grayscale4Result4X4 = { - new[] { gray8, grayF, gray0, grayF }, - new[] { grayF, grayF, grayF, grayF }, - new[] { gray0, gray8, gray8, grayF }, - new[] { grayF, gray0, grayF, gray8 } + new[] { Gray8, GrayF, Gray0, GrayF }, + new[] { GrayF, GrayF, GrayF, GrayF }, + new[] { Gray0, Gray8, Gray8, GrayF }, + new[] { GrayF, Gray0, GrayF, Gray8 } }; - private static readonly byte[] Grayscale4_Bytes3x4 = + private static readonly byte[] Grayscale4Bytes3X4 = { 0x8F, 0x00, 0xFF, 0xF0, @@ -77,15 +78,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0xF0, 0xF0 }; - private static readonly Rgba32[][] Grayscale4_Result3x4 = + private static readonly Rgba32[][] Grayscale4Result3X4 = { - new[] { gray8, grayF, gray0 }, - new[] { grayF, grayF, grayF }, - new[] { gray0, gray8, gray8 }, - new[] { grayF, gray0, grayF } + new[] { Gray8, GrayF, Gray0 }, + new[] { GrayF, GrayF, GrayF }, + new[] { Gray0, Gray8, Gray8 }, + new[] { GrayF, Gray0, GrayF } }; - private static readonly byte[] Grayscale8_Bytes4x4 = + private static readonly byte[] Grayscale8Bytes4X4 = { 128, 255, 000, 255, 255, 255, 255, 255, @@ -93,29 +94,29 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 255, 000, 255, 128 }; - private static readonly Rgba32[][] Grayscale8_Result4x4 = + private static readonly Rgba32[][] Grayscale8Result4X4 = { - new[] { gray128, gray255, gray000, gray255 }, - new[] { gray255, gray255, gray255, gray255 }, - new[] { gray000, gray128, gray128, gray255 }, - new[] { gray255, gray000, gray255, gray128 } + new[] { Gray128, Gray255, Gray000, Gray255 }, + new[] { Gray255, Gray255, Gray255, Gray255 }, + new[] { Gray000, Gray128, Gray128, Gray255 }, + new[] { Gray255, Gray000, Gray255, Gray128 } }; - public static IEnumerable Bilevel_Data + public static IEnumerable BilevelData { get { - yield return new object[] { Bilevel_Bytes4x4, 1, 0, 0, 4, 4, Bilevel_Result4x4 }; - yield return new object[] { Bilevel_Bytes4x4, 1, 0, 0, 4, 4, Offset(Bilevel_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { Bilevel_Bytes4x4, 1, 1, 0, 4, 4, Offset(Bilevel_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { Bilevel_Bytes4x4, 1, 0, 1, 4, 4, Offset(Bilevel_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { Bilevel_Bytes4x4, 1, 1, 1, 4, 4, Offset(Bilevel_Result4x4, 1, 1, 6, 6) }; - - yield return new object[] { Bilevel_Bytes12x4, 1, 0, 0, 12, 4, Bilevel_Result12x4 }; - yield return new object[] { Bilevel_Bytes12x4, 1, 0, 0, 12, 4, Offset(Bilevel_Result12x4, 0, 0, 18, 6) }; - yield return new object[] { Bilevel_Bytes12x4, 1, 1, 0, 12, 4, Offset(Bilevel_Result12x4, 1, 0, 18, 6) }; - yield return new object[] { Bilevel_Bytes12x4, 1, 0, 1, 12, 4, Offset(Bilevel_Result12x4, 0, 1, 18, 6) }; - yield return new object[] { Bilevel_Bytes12x4, 1, 1, 1, 12, 4, Offset(Bilevel_Result12x4, 1, 1, 18, 6) }; + yield return new object[] { BilevelBytes4X4, 1, 0, 0, 4, 4, BilevelResult4X4 }; + yield return new object[] { BilevelBytes4X4, 1, 0, 0, 4, 4, Offset(BilevelResult4X4, 0, 0, 6, 6) }; + yield return new object[] { BilevelBytes4X4, 1, 1, 0, 4, 4, Offset(BilevelResult4X4, 1, 0, 6, 6) }; + yield return new object[] { BilevelBytes4X4, 1, 0, 1, 4, 4, Offset(BilevelResult4X4, 0, 1, 6, 6) }; + yield return new object[] { BilevelBytes4X4, 1, 1, 1, 4, 4, Offset(BilevelResult4X4, 1, 1, 6, 6) }; + + yield return new object[] { BilevelBytes12X4, 1, 0, 0, 12, 4, BilevelResult12X4 }; + yield return new object[] { BilevelBytes12X4, 1, 0, 0, 12, 4, Offset(BilevelResult12X4, 0, 0, 18, 6) }; + yield return new object[] { BilevelBytes12X4, 1, 1, 0, 12, 4, Offset(BilevelResult12X4, 1, 0, 18, 6) }; + yield return new object[] { BilevelBytes12X4, 1, 0, 1, 12, 4, Offset(BilevelResult12X4, 0, 1, 18, 6) }; + yield return new object[] { BilevelBytes12X4, 1, 1, 1, 12, 4, Offset(BilevelResult12X4, 1, 1, 18, 6) }; } } @@ -123,17 +124,17 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation { get { - yield return new object[] { Grayscale4_Bytes4x4, 4, 0, 0, 4, 4, Grayscale4_Result4x4 }; - yield return new object[] { Grayscale4_Bytes4x4, 4, 0, 0, 4, 4, Offset(Grayscale4_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { Grayscale4_Bytes4x4, 4, 1, 0, 4, 4, Offset(Grayscale4_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { Grayscale4_Bytes4x4, 4, 0, 1, 4, 4, Offset(Grayscale4_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { Grayscale4_Bytes4x4, 4, 1, 1, 4, 4, Offset(Grayscale4_Result4x4, 1, 1, 6, 6) }; - - yield return new object[] { Grayscale4_Bytes3x4, 4, 0, 0, 3, 4, Grayscale4_Result3x4 }; - yield return new object[] { Grayscale4_Bytes3x4, 4, 0, 0, 3, 4, Offset(Grayscale4_Result3x4, 0, 0, 6, 6) }; - yield return new object[] { Grayscale4_Bytes3x4, 4, 1, 0, 3, 4, Offset(Grayscale4_Result3x4, 1, 0, 6, 6) }; - yield return new object[] { Grayscale4_Bytes3x4, 4, 0, 1, 3, 4, Offset(Grayscale4_Result3x4, 0, 1, 6, 6) }; - yield return new object[] { Grayscale4_Bytes3x4, 4, 1, 1, 3, 4, Offset(Grayscale4_Result3x4, 1, 1, 6, 6) }; + yield return new object[] { Grayscale4Bytes4X4, 4, 0, 0, 4, 4, Grayscale4Result4X4 }; + yield return new object[] { Grayscale4Bytes4X4, 4, 0, 0, 4, 4, Offset(Grayscale4Result4X4, 0, 0, 6, 6) }; + yield return new object[] { Grayscale4Bytes4X4, 4, 1, 0, 4, 4, Offset(Grayscale4Result4X4, 1, 0, 6, 6) }; + yield return new object[] { Grayscale4Bytes4X4, 4, 0, 1, 4, 4, Offset(Grayscale4Result4X4, 0, 1, 6, 6) }; + yield return new object[] { Grayscale4Bytes4X4, 4, 1, 1, 4, 4, Offset(Grayscale4Result4X4, 1, 1, 6, 6) }; + + yield return new object[] { Grayscale4Bytes3X4, 4, 0, 0, 3, 4, Grayscale4Result3X4 }; + yield return new object[] { Grayscale4Bytes3X4, 4, 0, 0, 3, 4, Offset(Grayscale4Result3X4, 0, 0, 6, 6) }; + yield return new object[] { Grayscale4Bytes3X4, 4, 1, 0, 3, 4, Offset(Grayscale4Result3X4, 1, 0, 6, 6) }; + yield return new object[] { Grayscale4Bytes3X4, 4, 0, 1, 3, 4, Offset(Grayscale4Result3X4, 0, 1, 6, 6) }; + yield return new object[] { Grayscale4Bytes3X4, 4, 1, 1, 3, 4, Offset(Grayscale4Result3X4, 1, 1, 6, 6) }; } } @@ -141,16 +142,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation { get { - yield return new object[] { Grayscale8_Bytes4x4, 8, 0, 0, 4, 4, Grayscale8_Result4x4 }; - yield return new object[] { Grayscale8_Bytes4x4, 8, 0, 0, 4, 4, Offset(Grayscale8_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { Grayscale8_Bytes4x4, 8, 1, 0, 4, 4, Offset(Grayscale8_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { Grayscale8_Bytes4x4, 8, 0, 1, 4, 4, Offset(Grayscale8_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { Grayscale8_Bytes4x4, 8, 1, 1, 4, 4, Offset(Grayscale8_Result4x4, 1, 1, 6, 6) }; + yield return new object[] { Grayscale8Bytes4X4, 8, 0, 0, 4, 4, Grayscale8Result4X4 }; + yield return new object[] { Grayscale8Bytes4X4, 8, 0, 0, 4, 4, Offset(Grayscale8Result4X4, 0, 0, 6, 6) }; + yield return new object[] { Grayscale8Bytes4X4, 8, 1, 0, 4, 4, Offset(Grayscale8Result4X4, 1, 0, 6, 6) }; + yield return new object[] { Grayscale8Bytes4X4, 8, 0, 1, 4, 4, Offset(Grayscale8Result4X4, 0, 1, 6, 6) }; + yield return new object[] { Grayscale8Bytes4X4, 8, 1, 1, 4, 4, Offset(Grayscale8Result4X4, 1, 1, 6, 6) }; } } [Theory] - [MemberData(nameof(Bilevel_Data))] + [MemberData(nameof(BilevelData))] [MemberData(nameof(Grayscale4_Data))] [MemberData(nameof(Grayscale8_Data))] public void Decode_WritesPixelData(byte[] inputData, int bitsPerSample, int left, int top, int width, int height, Rgba32[][] expectedResult) @@ -162,7 +163,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation } [Theory] - [MemberData(nameof(Bilevel_Data))] + [MemberData(nameof(BilevelData))] public void Decode_WritesPixelData_Bilevel(byte[] inputData, int bitsPerSample, int left, int top, int width, int height, Rgba32[][] expectedResult) { AssertDecode(expectedResult, pixels => diff --git a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PaletteTiffColorTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PaletteTiffColorTests.cs index 79a9900f63..8425e97a6b 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PaletteTiffColorTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PaletteTiffColorTests.cs @@ -10,22 +10,23 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation { + [Trait("Format", "Tiff")] public class PaletteTiffColorTests : PhotometricInterpretationTestBase { - public static uint[][] Palette4_ColorPalette { get => GeneratePalette(16); } + public static uint[][] Palette4ColorPalette { get => GeneratePalette(16); } - public static ushort[] Palette4_ColorMap { get => GenerateColorMap(Palette4_ColorPalette); } + public static ushort[] Palette4ColorMap { get => GenerateColorMap(Palette4ColorPalette); } - private static readonly byte[] Palette4_Bytes4x4 = + private static readonly byte[] Palette4Bytes4X4 = { 0x01, 0x23, 0x4A, 0xD2, 0x12, 0x34, 0xAB, 0xEF }; - private static readonly Rgba32[][] Palette4_Result4x4 = GenerateResult( - Palette4_ColorPalette, + private static readonly Rgba32[][] Palette4Result4X4 = GenerateResult( + Palette4ColorPalette, new[] { new[] { 0x00, 0x01, 0x02, 0x03 }, new[] { 0x04, 0x0A, 0x0D, 0x02 }, new[] { 0x01, 0x02, 0x03, 0x04 }, new[] { 0x0A, 0x0B, 0x0E, 0x0F } }); - private static readonly byte[] Palette4_Bytes3x4 = + private static readonly byte[] Palette4Bytes3X4 = { 0x01, 0x20, 0x4A, 0xD0, @@ -33,31 +34,31 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0xAB, 0xE0 }; - private static readonly Rgba32[][] Palette4_Result3x4 = GenerateResult(Palette4_ColorPalette, new[] { new[] { 0x00, 0x01, 0x02 }, new[] { 0x04, 0x0A, 0x0D }, new[] { 0x01, 0x02, 0x03 }, new[] { 0x0A, 0x0B, 0x0E } }); + private static readonly Rgba32[][] Palette4Result3X4 = GenerateResult(Palette4ColorPalette, new[] { new[] { 0x00, 0x01, 0x02 }, new[] { 0x04, 0x0A, 0x0D }, new[] { 0x01, 0x02, 0x03 }, new[] { 0x0A, 0x0B, 0x0E } }); - public static IEnumerable Palette4_Data + public static IEnumerable Palette4Data { get { - yield return new object[] { Palette4_Bytes4x4, 4, Palette4_ColorMap, 0, 0, 4, 4, Palette4_Result4x4 }; - yield return new object[] { Palette4_Bytes4x4, 4, Palette4_ColorMap, 0, 0, 4, 4, Offset(Palette4_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { Palette4_Bytes4x4, 4, Palette4_ColorMap, 1, 0, 4, 4, Offset(Palette4_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { Palette4_Bytes4x4, 4, Palette4_ColorMap, 0, 1, 4, 4, Offset(Palette4_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { Palette4_Bytes4x4, 4, Palette4_ColorMap, 1, 1, 4, 4, Offset(Palette4_Result4x4, 1, 1, 6, 6) }; - - yield return new object[] { Palette4_Bytes3x4, 4, Palette4_ColorMap, 0, 0, 3, 4, Palette4_Result3x4 }; - yield return new object[] { Palette4_Bytes3x4, 4, Palette4_ColorMap, 0, 0, 3, 4, Offset(Palette4_Result3x4, 0, 0, 6, 6) }; - yield return new object[] { Palette4_Bytes3x4, 4, Palette4_ColorMap, 1, 0, 3, 4, Offset(Palette4_Result3x4, 1, 0, 6, 6) }; - yield return new object[] { Palette4_Bytes3x4, 4, Palette4_ColorMap, 0, 1, 3, 4, Offset(Palette4_Result3x4, 0, 1, 6, 6) }; - yield return new object[] { Palette4_Bytes3x4, 4, Palette4_ColorMap, 1, 1, 3, 4, Offset(Palette4_Result3x4, 1, 1, 6, 6) }; + yield return new object[] { Palette4Bytes4X4, 4, Palette4ColorMap, 0, 0, 4, 4, Palette4Result4X4 }; + yield return new object[] { Palette4Bytes4X4, 4, Palette4ColorMap, 0, 0, 4, 4, Offset(Palette4Result4X4, 0, 0, 6, 6) }; + yield return new object[] { Palette4Bytes4X4, 4, Palette4ColorMap, 1, 0, 4, 4, Offset(Palette4Result4X4, 1, 0, 6, 6) }; + yield return new object[] { Palette4Bytes4X4, 4, Palette4ColorMap, 0, 1, 4, 4, Offset(Palette4Result4X4, 0, 1, 6, 6) }; + yield return new object[] { Palette4Bytes4X4, 4, Palette4ColorMap, 1, 1, 4, 4, Offset(Palette4Result4X4, 1, 1, 6, 6) }; + + yield return new object[] { Palette4Bytes3X4, 4, Palette4ColorMap, 0, 0, 3, 4, Palette4Result3X4 }; + yield return new object[] { Palette4Bytes3X4, 4, Palette4ColorMap, 0, 0, 3, 4, Offset(Palette4Result3X4, 0, 0, 6, 6) }; + yield return new object[] { Palette4Bytes3X4, 4, Palette4ColorMap, 1, 0, 3, 4, Offset(Palette4Result3X4, 1, 0, 6, 6) }; + yield return new object[] { Palette4Bytes3X4, 4, Palette4ColorMap, 0, 1, 3, 4, Offset(Palette4Result3X4, 0, 1, 6, 6) }; + yield return new object[] { Palette4Bytes3X4, 4, Palette4ColorMap, 1, 1, 3, 4, Offset(Palette4Result3X4, 1, 1, 6, 6) }; } } - public static uint[][] Palette8_ColorPalette { get => GeneratePalette(256); } + public static uint[][] Palette8ColorPalette { get => GeneratePalette(256); } - public static ushort[] Palette8_ColorMap { get => GenerateColorMap(Palette8_ColorPalette); } + public static ushort[] Palette8ColorMap { get => GenerateColorMap(Palette8ColorPalette); } - private static readonly byte[] Palette8_Bytes4x4 = + private static readonly byte[] Palette8Bytes4X4 = { 000, 001, 002, 003, 100, 110, 120, 130, @@ -65,28 +66,28 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 050, 100, 150, 200 }; - private static readonly Rgba32[][] Palette8_Result4x4 = GenerateResult(Palette8_ColorPalette, new[] { new[] { 000, 001, 002, 003 }, new[] { 100, 110, 120, 130 }, new[] { 000, 255, 128, 255 }, new[] { 050, 100, 150, 200 } }); + private static readonly Rgba32[][] Palette8Result4X4 = GenerateResult(Palette8ColorPalette, new[] { new[] { 000, 001, 002, 003 }, new[] { 100, 110, 120, 130 }, new[] { 000, 255, 128, 255 }, new[] { 050, 100, 150, 200 } }); - public static IEnumerable Palette8_Data + public static IEnumerable Palette8Data { get { - yield return new object[] { Palette8_Bytes4x4, 8, Palette8_ColorMap, 0, 0, 4, 4, Palette8_Result4x4 }; - yield return new object[] { Palette8_Bytes4x4, 8, Palette8_ColorMap, 0, 0, 4, 4, Offset(Palette8_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { Palette8_Bytes4x4, 8, Palette8_ColorMap, 1, 0, 4, 4, Offset(Palette8_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { Palette8_Bytes4x4, 8, Palette8_ColorMap, 0, 1, 4, 4, Offset(Palette8_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { Palette8_Bytes4x4, 8, Palette8_ColorMap, 1, 1, 4, 4, Offset(Palette8_Result4x4, 1, 1, 6, 6) }; + yield return new object[] { Palette8Bytes4X4, 8, Palette8ColorMap, 0, 0, 4, 4, Palette8Result4X4 }; + yield return new object[] { Palette8Bytes4X4, 8, Palette8ColorMap, 0, 0, 4, 4, Offset(Palette8Result4X4, 0, 0, 6, 6) }; + yield return new object[] { Palette8Bytes4X4, 8, Palette8ColorMap, 1, 0, 4, 4, Offset(Palette8Result4X4, 1, 0, 6, 6) }; + yield return new object[] { Palette8Bytes4X4, 8, Palette8ColorMap, 0, 1, 4, 4, Offset(Palette8Result4X4, 0, 1, 6, 6) }; + yield return new object[] { Palette8Bytes4X4, 8, Palette8ColorMap, 1, 1, 4, 4, Offset(Palette8Result4X4, 1, 1, 6, 6) }; } } [Theory] - [MemberData(nameof(Palette4_Data))] - [MemberData(nameof(Palette8_Data))] + [MemberData(nameof(Palette4Data))] + [MemberData(nameof(Palette8Data))] public void Decode_WritesPixelData(byte[] inputData, ushort bitsPerSample, ushort[] colorMap, int left, int top, int width, int height, Rgba32[][] expectedResult) { AssertDecode(expectedResult, pixels => { - new PaletteTiffColor(new[] { (ushort)bitsPerSample }, colorMap).Decode(inputData, pixels, left, top, width, height); + new PaletteTiffColor(new[] { bitsPerSample }, colorMap).Decode(inputData, pixels, left, top, width, height); }); } diff --git a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PhotometricInterpretationTestBase.cs b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PhotometricInterpretationTestBase.cs index 8ff099655b..0bb61ce1c4 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PhotometricInterpretationTestBase.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PhotometricInterpretationTestBase.cs @@ -7,7 +7,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using Xunit; -namespace SixLabors.ImageSharp.Tests.Formats.Tiff +namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation { [Trait("Format", "Tiff")] public abstract class PhotometricInterpretationTestBase @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff int inputHeight = input.Length; int inputWidth = input[0].Length; - Rgba32[][] output = new Rgba32[height][]; + var output = new Rgba32[height][]; for (int y = 0; y < output.Length; y++) { @@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff int resultWidth = expectedResult[0].Length; int resultHeight = expectedResult.Length; - using (Image image = new Image(resultWidth, resultHeight)) + using (var image = new Image(resultWidth, resultHeight)) { image.Mutate(x => x.BackgroundColor(DefaultColor)); Buffer2D pixels = image.GetRootFramePixelBuffer(); diff --git a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbPlanarTiffColorTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbPlanarTiffColorTests.cs index f1372e712d..ca4b19f83c 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbPlanarTiffColorTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbPlanarTiffColorTests.cs @@ -12,23 +12,24 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation { + [Trait("Format", "Tiff")] public class RgbPlanarTiffColorTests : PhotometricInterpretationTestBase { - private static Rgba32 rgb4_000 = new Rgba32(0, 0, 0, 255); - private static Rgba32 rgb4_444 = new Rgba32(68, 68, 68, 255); - private static Rgba32 rgb4_888 = new Rgba32(136, 136, 136, 255); - private static Rgba32 rgb4_CCC = new Rgba32(204, 204, 204, 255); - private static Rgba32 rgb4_FFF = new Rgba32(255, 255, 255, 255); - private static Rgba32 rgb4_F00 = new Rgba32(255, 0, 0, 255); - private static Rgba32 rgb4_0F0 = new Rgba32(0, 255, 0, 255); - private static Rgba32 rgb4_00F = new Rgba32(0, 0, 255, 255); - private static Rgba32 rgb4_F0F = new Rgba32(255, 0, 255, 255); - private static Rgba32 rgb4_400 = new Rgba32(68, 0, 0, 255); - private static Rgba32 rgb4_800 = new Rgba32(136, 0, 0, 255); - private static Rgba32 rgb4_C00 = new Rgba32(204, 0, 0, 255); - private static Rgba32 rgb4_48C = new Rgba32(68, 136, 204, 255); - - private static byte[] rgb4_Bytes4x4_R = + private static readonly Rgba32 Rgb4_000 = new Rgba32(0, 0, 0, 255); + private static readonly Rgba32 Rgb4_444 = new Rgba32(68, 68, 68, 255); + private static readonly Rgba32 Rgb4_888 = new Rgba32(136, 136, 136, 255); + private static readonly Rgba32 Rgb4_CCC = new Rgba32(204, 204, 204, 255); + private static readonly Rgba32 Rgb4_FFF = new Rgba32(255, 255, 255, 255); + private static readonly Rgba32 Rgb4_F00 = new Rgba32(255, 0, 0, 255); + private static readonly Rgba32 Rgb4_0F0 = new Rgba32(0, 255, 0, 255); + private static readonly Rgba32 Rgb4_00F = new Rgba32(0, 0, 255, 255); + private static readonly Rgba32 Rgb4_F0F = new Rgba32(255, 0, 255, 255); + private static readonly Rgba32 Rgb4_400 = new Rgba32(68, 0, 0, 255); + private static readonly Rgba32 Rgb4_800 = new Rgba32(136, 0, 0, 255); + private static readonly Rgba32 Rgb4_C00 = new Rgba32(204, 0, 0, 255); + private static readonly Rgba32 Rgb4_48C = new Rgba32(68, 136, 204, 255); + + private static readonly byte[] Rgb4Bytes4X4R = { 0x0F, 0x0F, 0xF0, 0x0F, @@ -36,7 +37,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0x04, 0x8C }; - private static byte[] rgb4_Bytes4x4_G = + private static readonly byte[] Rgb4Bytes4X4G = { 0x0F, 0x0F, 0x0F, 0x00, @@ -44,7 +45,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0x04, 0x8C }; - private static byte[] rgb4_Bytes4x4_B = + private static readonly byte[] Rgb4Bytes4X4B = { 0x0F, 0x0F, 0x00, 0xFF, @@ -52,17 +53,17 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0x04, 0x8C }; - private static byte[][] rgb4_Bytes4x4 = { rgb4_Bytes4x4_R, rgb4_Bytes4x4_G, rgb4_Bytes4x4_B }; + private static readonly byte[][] Rgb4Bytes4X4 = { Rgb4Bytes4X4R, Rgb4Bytes4X4G, Rgb4Bytes4X4B }; - private static Rgba32[][] rgb4_Result4x4 = + private static readonly Rgba32[][] Rgb4Result4X4 = { - new[] { rgb4_000, rgb4_FFF, rgb4_000, rgb4_FFF }, - new[] { rgb4_F00, rgb4_0F0, rgb4_00F, rgb4_F0F }, - new[] { rgb4_400, rgb4_800, rgb4_C00, rgb4_48C }, - new[] { rgb4_000, rgb4_444, rgb4_888, rgb4_CCC } + new[] { Rgb4_000, Rgb4_FFF, Rgb4_000, Rgb4_FFF }, + new[] { Rgb4_F00, Rgb4_0F0, Rgb4_00F, Rgb4_F0F }, + new[] { Rgb4_400, Rgb4_800, Rgb4_C00, Rgb4_48C }, + new[] { Rgb4_000, Rgb4_444, Rgb4_888, Rgb4_CCC } }; - private static byte[] rgb4_Bytes3x4_R = + private static readonly byte[] Rgb4Bytes3X4R = { 0x0F, 0x00, 0xF0, 0x00, @@ -70,7 +71,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0x04, 0x80 }; - private static byte[] rgb4_Bytes3x4_G = + private static readonly byte[] Rgb4Bytes3X4G = { 0x0F, 0x00, 0x0F, 0x00, @@ -78,7 +79,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0x04, 0x80 }; - private static byte[] rgb4_Bytes3x4_B = + private static readonly byte[] Rgb4Bytes3X4B = { 0x0F, 0x00, 0x00, 0xF0, @@ -86,49 +87,49 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0x04, 0x80 }; - private static byte[][] rgb4_Bytes3x4 = { rgb4_Bytes3x4_R, rgb4_Bytes3x4_G, rgb4_Bytes3x4_B }; + private static readonly byte[][] Rgb4Bytes3X4 = { Rgb4Bytes3X4R, Rgb4Bytes3X4G, Rgb4Bytes3X4B }; - private static Rgba32[][] rgb4_Result3x4 = + private static readonly Rgba32[][] Rgb4Result3X4 = { - new[] { rgb4_000, rgb4_FFF, rgb4_000 }, - new[] { rgb4_F00, rgb4_0F0, rgb4_00F }, - new[] { rgb4_400, rgb4_800, rgb4_C00 }, - new[] { rgb4_000, rgb4_444, rgb4_888 } + new[] { Rgb4_000, Rgb4_FFF, Rgb4_000 }, + new[] { Rgb4_F00, Rgb4_0F0, Rgb4_00F }, + new[] { Rgb4_400, Rgb4_800, Rgb4_C00 }, + new[] { Rgb4_000, Rgb4_444, Rgb4_888 } }; - public static IEnumerable Rgb4_Data + public static IEnumerable Rgb4Data { get { - yield return new object[] { rgb4_Bytes4x4, new ushort[] { 4, 4, 4 }, 0, 0, 4, 4, rgb4_Result4x4 }; - yield return new object[] { rgb4_Bytes4x4, new ushort[] { 4, 4, 4 }, 0, 0, 4, 4, Offset(rgb4_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { rgb4_Bytes4x4, new ushort[] { 4, 4, 4 }, 1, 0, 4, 4, Offset(rgb4_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { rgb4_Bytes4x4, new ushort[] { 4, 4, 4 }, 0, 1, 4, 4, Offset(rgb4_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { rgb4_Bytes4x4, new ushort[] { 4, 4, 4 }, 1, 1, 4, 4, Offset(rgb4_Result4x4, 1, 1, 6, 6) }; - - yield return new object[] { rgb4_Bytes3x4, new ushort[] { 4, 4, 4 }, 0, 0, 3, 4, rgb4_Result3x4 }; - yield return new object[] { rgb4_Bytes3x4, new ushort[] { 4, 4, 4 }, 0, 0, 3, 4, Offset(rgb4_Result3x4, 0, 0, 6, 6) }; - yield return new object[] { rgb4_Bytes3x4, new ushort[] { 4, 4, 4 }, 1, 0, 3, 4, Offset(rgb4_Result3x4, 1, 0, 6, 6) }; - yield return new object[] { rgb4_Bytes3x4, new ushort[] { 4, 4, 4 }, 0, 1, 3, 4, Offset(rgb4_Result3x4, 0, 1, 6, 6) }; - yield return new object[] { rgb4_Bytes3x4, new ushort[] { 4, 4, 4 }, 1, 1, 3, 4, Offset(rgb4_Result3x4, 1, 1, 6, 6) }; + yield return new object[] { Rgb4Bytes4X4, new ushort[] { 4, 4, 4 }, 0, 0, 4, 4, Rgb4Result4X4 }; + yield return new object[] { Rgb4Bytes4X4, new ushort[] { 4, 4, 4 }, 0, 0, 4, 4, Offset(Rgb4Result4X4, 0, 0, 6, 6) }; + yield return new object[] { Rgb4Bytes4X4, new ushort[] { 4, 4, 4 }, 1, 0, 4, 4, Offset(Rgb4Result4X4, 1, 0, 6, 6) }; + yield return new object[] { Rgb4Bytes4X4, new ushort[] { 4, 4, 4 }, 0, 1, 4, 4, Offset(Rgb4Result4X4, 0, 1, 6, 6) }; + yield return new object[] { Rgb4Bytes4X4, new ushort[] { 4, 4, 4 }, 1, 1, 4, 4, Offset(Rgb4Result4X4, 1, 1, 6, 6) }; + + yield return new object[] { Rgb4Bytes3X4, new ushort[] { 4, 4, 4 }, 0, 0, 3, 4, Rgb4Result3X4 }; + yield return new object[] { Rgb4Bytes3X4, new ushort[] { 4, 4, 4 }, 0, 0, 3, 4, Offset(Rgb4Result3X4, 0, 0, 6, 6) }; + yield return new object[] { Rgb4Bytes3X4, new ushort[] { 4, 4, 4 }, 1, 0, 3, 4, Offset(Rgb4Result3X4, 1, 0, 6, 6) }; + yield return new object[] { Rgb4Bytes3X4, new ushort[] { 4, 4, 4 }, 0, 1, 3, 4, Offset(Rgb4Result3X4, 0, 1, 6, 6) }; + yield return new object[] { Rgb4Bytes3X4, new ushort[] { 4, 4, 4 }, 1, 1, 3, 4, Offset(Rgb4Result3X4, 1, 1, 6, 6) }; } } - private static Rgba32 rgb8_000 = new Rgba32(0, 0, 0, 255); - private static Rgba32 rgb8_444 = new Rgba32(64, 64, 64, 255); - private static Rgba32 rgb8_888 = new Rgba32(128, 128, 128, 255); - private static Rgba32 rgb8_CCC = new Rgba32(192, 192, 192, 255); - private static Rgba32 rgb8_FFF = new Rgba32(255, 255, 255, 255); - private static Rgba32 rgb8_F00 = new Rgba32(255, 0, 0, 255); - private static Rgba32 rgb8_0F0 = new Rgba32(0, 255, 0, 255); - private static Rgba32 rgb8_00F = new Rgba32(0, 0, 255, 255); - private static Rgba32 rgb8_F0F = new Rgba32(255, 0, 255, 255); - private static Rgba32 rgb8_400 = new Rgba32(64, 0, 0, 255); - private static Rgba32 rgb8_800 = new Rgba32(128, 0, 0, 255); - private static Rgba32 rgb8_C00 = new Rgba32(192, 0, 0, 255); - private static Rgba32 rgb8_48C = new Rgba32(64, 128, 192, 255); - - private static byte[] rgb8_Bytes4x4_R = + private static readonly Rgba32 Rgb8_000 = new Rgba32(0, 0, 0, 255); + private static readonly Rgba32 Rgb8_444 = new Rgba32(64, 64, 64, 255); + private static readonly Rgba32 Rgb8_888 = new Rgba32(128, 128, 128, 255); + private static readonly Rgba32 Rgb8_CCC = new Rgba32(192, 192, 192, 255); + private static readonly Rgba32 Rgb8_FFF = new Rgba32(255, 255, 255, 255); + private static readonly Rgba32 Rgb8_F00 = new Rgba32(255, 0, 0, 255); + private static readonly Rgba32 Rgb8_0F0 = new Rgba32(0, 255, 0, 255); + private static readonly Rgba32 Rgb8_00F = new Rgba32(0, 0, 255, 255); + private static readonly Rgba32 Rgb8_F0F = new Rgba32(255, 0, 255, 255); + private static readonly Rgba32 Rgb8_400 = new Rgba32(64, 0, 0, 255); + private static readonly Rgba32 Rgb8_800 = new Rgba32(128, 0, 0, 255); + private static readonly Rgba32 Rgb8_C00 = new Rgba32(192, 0, 0, 255); + private static readonly Rgba32 Rgb8_48C = new Rgba32(64, 128, 192, 255); + + private static readonly byte[] Rgb8Bytes4X4R = { 000, 255, 000, 255, 255, 000, 000, 255, @@ -136,7 +137,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 000, 064, 128, 192 }; - private static byte[] rgb8_Bytes4x4_G = + private static readonly byte[] Rgb8Bytes4X4G = { 000, 255, 000, 255, 000, 255, 000, 000, @@ -144,7 +145,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 000, 064, 128, 192 }; - private static byte[] rgb8_Bytes4x4_B = + private static readonly byte[] Rgb8Bytes4X4B = { 000, 255, 000, 255, 000, 000, 255, 255, @@ -152,46 +153,46 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 000, 064, 128, 192 }; - private static byte[][] rgb8_Bytes4x4 = + private static readonly byte[][] Rgb8Bytes4X4 = { - rgb8_Bytes4x4_R, rgb8_Bytes4x4_G, rgb8_Bytes4x4_B + Rgb8Bytes4X4R, Rgb8Bytes4X4G, Rgb8Bytes4X4B }; - private static Rgba32[][] rgb8_Result4x4 = + private static readonly Rgba32[][] Rgb8Result4X4 = { - new[] { rgb8_000, rgb8_FFF, rgb8_000, rgb8_FFF }, - new[] { rgb8_F00, rgb8_0F0, rgb8_00F, rgb8_F0F }, - new[] { rgb8_400, rgb8_800, rgb8_C00, rgb8_48C }, - new[] { rgb8_000, rgb8_444, rgb8_888, rgb8_CCC } + new[] { Rgb8_000, Rgb8_FFF, Rgb8_000, Rgb8_FFF }, + new[] { Rgb8_F00, Rgb8_0F0, Rgb8_00F, Rgb8_F0F }, + new[] { Rgb8_400, Rgb8_800, Rgb8_C00, Rgb8_48C }, + new[] { Rgb8_000, Rgb8_444, Rgb8_888, Rgb8_CCC } }; - public static IEnumerable Rgb8_Data + public static IEnumerable Rgb8Data { get { - yield return new object[] { rgb8_Bytes4x4, new ushort[] { 8, 8, 8 }, 0, 0, 4, 4, rgb8_Result4x4 }; - yield return new object[] { rgb8_Bytes4x4, new ushort[] { 8, 8, 8 }, 0, 0, 4, 4, Offset(rgb8_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { rgb8_Bytes4x4, new ushort[] { 8, 8, 8 }, 1, 0, 4, 4, Offset(rgb8_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { rgb8_Bytes4x4, new ushort[] { 8, 8, 8 }, 0, 1, 4, 4, Offset(rgb8_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { rgb8_Bytes4x4, new ushort[] { 8, 8, 8 }, 1, 1, 4, 4, Offset(rgb8_Result4x4, 1, 1, 6, 6) }; + yield return new object[] { Rgb8Bytes4X4, new ushort[] { 8, 8, 8 }, 0, 0, 4, 4, Rgb8Result4X4 }; + yield return new object[] { Rgb8Bytes4X4, new ushort[] { 8, 8, 8 }, 0, 0, 4, 4, Offset(Rgb8Result4X4, 0, 0, 6, 6) }; + yield return new object[] { Rgb8Bytes4X4, new ushort[] { 8, 8, 8 }, 1, 0, 4, 4, Offset(Rgb8Result4X4, 1, 0, 6, 6) }; + yield return new object[] { Rgb8Bytes4X4, new ushort[] { 8, 8, 8 }, 0, 1, 4, 4, Offset(Rgb8Result4X4, 0, 1, 6, 6) }; + yield return new object[] { Rgb8Bytes4X4, new ushort[] { 8, 8, 8 }, 1, 1, 4, 4, Offset(Rgb8Result4X4, 1, 1, 6, 6) }; } } - private static Rgba32 rgb484_000 = new Rgba32(0, 0, 0, 255); - private static Rgba32 rgb484_444 = new Rgba32(68, 64, 68, 255); - private static Rgba32 rgb484_888 = new Rgba32(136, 128, 136, 255); - private static Rgba32 rgb484_CCC = new Rgba32(204, 192, 204, 255); - private static Rgba32 rgb484_FFF = new Rgba32(255, 255, 255, 255); - private static Rgba32 rgb484_F00 = new Rgba32(255, 0, 0, 255); - private static Rgba32 rgb484_0F0 = new Rgba32(0, 255, 0, 255); - private static Rgba32 rgb484_00F = new Rgba32(0, 0, 255, 255); - private static Rgba32 rgb484_F0F = new Rgba32(255, 0, 255, 255); - private static Rgba32 rgb484_400 = new Rgba32(68, 0, 0, 255); - private static Rgba32 rgb484_800 = new Rgba32(136, 0, 0, 255); - private static Rgba32 rgb484_C00 = new Rgba32(204, 0, 0, 255); - private static Rgba32 rgb484_48C = new Rgba32(68, 128, 204, 255); - - private static byte[] rgb484_Bytes4x4_R = + private static readonly Rgba32 Rgb484_000 = new Rgba32(0, 0, 0, 255); + private static readonly Rgba32 Rgb484_444 = new Rgba32(68, 64, 68, 255); + private static readonly Rgba32 Rgb484_888 = new Rgba32(136, 128, 136, 255); + private static readonly Rgba32 Rgb484_CCC = new Rgba32(204, 192, 204, 255); + private static readonly Rgba32 Rgb484_FFF = new Rgba32(255, 255, 255, 255); + private static readonly Rgba32 Rgb484_F00 = new Rgba32(255, 0, 0, 255); + private static readonly Rgba32 Rgb484_0F0 = new Rgba32(0, 255, 0, 255); + private static readonly Rgba32 Rgb484_00F = new Rgba32(0, 0, 255, 255); + private static readonly Rgba32 Rgb484_F0F = new Rgba32(255, 0, 255, 255); + private static readonly Rgba32 Rgb484_400 = new Rgba32(68, 0, 0, 255); + private static readonly Rgba32 Rgb484_800 = new Rgba32(136, 0, 0, 255); + private static readonly Rgba32 Rgb484_C00 = new Rgba32(204, 0, 0, 255); + private static readonly Rgba32 Rgb484_48C = new Rgba32(68, 128, 204, 255); + + private static readonly byte[] Rgb484Bytes4X4R = { 0x0F, 0x0F, 0xF0, 0x0F, @@ -199,7 +200,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0x04, 0x8C }; - private static byte[] rgb484_Bytes4x4_G = + private static readonly byte[] Rgb484Bytes4X4G = { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, @@ -207,7 +208,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0x00, 0x40, 0x80, 0xC0 }; - private static byte[] rgb484_Bytes4x4_B = + private static readonly byte[] Rgb484Bytes4X4B = { 0x0F, 0x0F, 0x00, 0xFF, @@ -215,31 +216,31 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0x04, 0x8C }; - private static Rgba32[][] rgb484_Result4x4 = + private static readonly Rgba32[][] Rgb484Result4X4 = { - new[] { rgb484_000, rgb484_FFF, rgb484_000, rgb484_FFF }, - new[] { rgb484_F00, rgb484_0F0, rgb484_00F, rgb484_F0F }, - new[] { rgb484_400, rgb484_800, rgb484_C00, rgb484_48C }, - new[] { rgb484_000, rgb484_444, rgb484_888, rgb484_CCC } + new[] { Rgb484_000, Rgb484_FFF, Rgb484_000, Rgb484_FFF }, + new[] { Rgb484_F00, Rgb484_0F0, Rgb484_00F, Rgb484_F0F }, + new[] { Rgb484_400, Rgb484_800, Rgb484_C00, Rgb484_48C }, + new[] { Rgb484_000, Rgb484_444, Rgb484_888, Rgb484_CCC } }; - private static byte[][] rgb484_Bytes4x4 = { rgb484_Bytes4x4_R, rgb484_Bytes4x4_G, rgb484_Bytes4x4_B }; + private static readonly byte[][] Rgb484Bytes4X4 = { Rgb484Bytes4X4R, Rgb484Bytes4X4G, Rgb484Bytes4X4B }; public static IEnumerable Rgb484_Data { get { - yield return new object[] { rgb484_Bytes4x4, new ushort[] { 4, 8, 4 }, 0, 0, 4, 4, rgb484_Result4x4 }; - yield return new object[] { rgb484_Bytes4x4, new ushort[] { 4, 8, 4 }, 0, 0, 4, 4, Offset(rgb484_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { rgb484_Bytes4x4, new ushort[] { 4, 8, 4 }, 1, 0, 4, 4, Offset(rgb484_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { rgb484_Bytes4x4, new ushort[] { 4, 8, 4 }, 0, 1, 4, 4, Offset(rgb484_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { rgb484_Bytes4x4, new ushort[] { 4, 8, 4 }, 1, 1, 4, 4, Offset(rgb484_Result4x4, 1, 1, 6, 6) }; + yield return new object[] { Rgb484Bytes4X4, new ushort[] { 4, 8, 4 }, 0, 0, 4, 4, Rgb484Result4X4 }; + yield return new object[] { Rgb484Bytes4X4, new ushort[] { 4, 8, 4 }, 0, 0, 4, 4, Offset(Rgb484Result4X4, 0, 0, 6, 6) }; + yield return new object[] { Rgb484Bytes4X4, new ushort[] { 4, 8, 4 }, 1, 0, 4, 4, Offset(Rgb484Result4X4, 1, 0, 6, 6) }; + yield return new object[] { Rgb484Bytes4X4, new ushort[] { 4, 8, 4 }, 0, 1, 4, 4, Offset(Rgb484Result4X4, 0, 1, 6, 6) }; + yield return new object[] { Rgb484Bytes4X4, new ushort[] { 4, 8, 4 }, 1, 1, 4, 4, Offset(Rgb484Result4X4, 1, 1, 6, 6) }; } } [Theory] - [MemberData(nameof(Rgb4_Data))] - [MemberData(nameof(Rgb8_Data))] + [MemberData(nameof(Rgb4Data))] + [MemberData(nameof(Rgb8Data))] [MemberData(nameof(Rgb484_Data))] public void Decode_WritesPixelData(byte[][] inputData, ushort[] bitsPerSample, int left, int top, int width, int height, Rgba32[][] expectedResult) { diff --git a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbTiffColorTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbTiffColorTests.cs index aa3da7d411..d79068b221 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbTiffColorTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbTiffColorTests.cs @@ -10,23 +10,24 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation { + [Trait("Format", "Tiff")] public class RgbTiffColorTests : PhotometricInterpretationTestBase { - private static Rgba32 rgb4_000 = new Rgba32(0, 0, 0, 255); - private static Rgba32 rgb4_444 = new Rgba32(68, 68, 68, 255); - private static Rgba32 rgb4_888 = new Rgba32(136, 136, 136, 255); - private static Rgba32 rgb4_CCC = new Rgba32(204, 204, 204, 255); - private static Rgba32 rgb4_FFF = new Rgba32(255, 255, 255, 255); - private static Rgba32 rgb4_F00 = new Rgba32(255, 0, 0, 255); - private static Rgba32 rgb4_0F0 = new Rgba32(0, 255, 0, 255); - private static Rgba32 rgb4_00F = new Rgba32(0, 0, 255, 255); - private static Rgba32 rgb4_F0F = new Rgba32(255, 0, 255, 255); - private static Rgba32 rgb4_400 = new Rgba32(68, 0, 0, 255); - private static Rgba32 rgb4_800 = new Rgba32(136, 0, 0, 255); - private static Rgba32 rgb4_C00 = new Rgba32(204, 0, 0, 255); - private static Rgba32 rgb4_48C = new Rgba32(68, 136, 204, 255); - - private static byte[] rgb4_Bytes4x4 = + private static readonly Rgba32 Rgb4_000 = new Rgba32(0, 0, 0, 255); + private static readonly Rgba32 Rgb4_444 = new Rgba32(68, 68, 68, 255); + private static readonly Rgba32 Rgb4_888 = new Rgba32(136, 136, 136, 255); + private static readonly Rgba32 Rgb4_CCC = new Rgba32(204, 204, 204, 255); + private static readonly Rgba32 Rgb4_FFF = new Rgba32(255, 255, 255, 255); + private static readonly Rgba32 Rgb4_F00 = new Rgba32(255, 0, 0, 255); + private static readonly Rgba32 Rgb4_0F0 = new Rgba32(0, 255, 0, 255); + private static readonly Rgba32 Rgb4_00F = new Rgba32(0, 0, 255, 255); + private static readonly Rgba32 Rgb4_F0F = new Rgba32(255, 0, 255, 255); + private static readonly Rgba32 Rgb4_400 = new Rgba32(68, 0, 0, 255); + private static readonly Rgba32 Rgb4_800 = new Rgba32(136, 0, 0, 255); + private static readonly Rgba32 Rgb4_C00 = new Rgba32(204, 0, 0, 255); + private static readonly Rgba32 Rgb4_48C = new Rgba32(68, 136, 204, 255); + + private static readonly byte[] Rgb4Bytes4X4 = { 0x00, 0x0F, 0xFF, 0x00, 0x0F, 0xFF, 0xF0, 0x00, 0xF0, 0x00, 0xFF, 0x0F, @@ -34,15 +35,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0x00, 0x04, 0x44, 0x88, 0x8C, 0xCC }; - private static Rgba32[][] rgb4_Result4x4 = + private static readonly Rgba32[][] Rgb4Result4X4 = { - new[] { rgb4_000, rgb4_FFF, rgb4_000, rgb4_FFF }, - new[] { rgb4_F00, rgb4_0F0, rgb4_00F, rgb4_F0F }, - new[] { rgb4_400, rgb4_800, rgb4_C00, rgb4_48C }, - new[] { rgb4_000, rgb4_444, rgb4_888, rgb4_CCC } + new[] { Rgb4_000, Rgb4_FFF, Rgb4_000, Rgb4_FFF }, + new[] { Rgb4_F00, Rgb4_0F0, Rgb4_00F, Rgb4_F0F }, + new[] { Rgb4_400, Rgb4_800, Rgb4_C00, Rgb4_48C }, + new[] { Rgb4_000, Rgb4_444, Rgb4_888, Rgb4_CCC } }; - private static byte[] rgb4_Bytes3x4 = + private static readonly byte[] Rgb4Bytes3X4 = { 0x00, 0x0F, 0xFF, 0x00, 0x00, 0xF0, 0x00, 0xF0, 0x00, 0xF0, @@ -50,47 +51,47 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0x00, 0x04, 0x44, 0x88, 0x80 }; - private static Rgba32[][] rgb4_Result3x4 = + private static readonly Rgba32[][] Rgb4Result3X4 = { - new[] { rgb4_000, rgb4_FFF, rgb4_000 }, - new[] { rgb4_F00, rgb4_0F0, rgb4_00F }, - new[] { rgb4_400, rgb4_800, rgb4_C00 }, - new[] { rgb4_000, rgb4_444, rgb4_888 } + new[] { Rgb4_000, Rgb4_FFF, Rgb4_000 }, + new[] { Rgb4_F00, Rgb4_0F0, Rgb4_00F }, + new[] { Rgb4_400, Rgb4_800, Rgb4_C00 }, + new[] { Rgb4_000, Rgb4_444, Rgb4_888 } }; - public static IEnumerable Rgb4_Data + public static IEnumerable Rgb4Data { get { - yield return new object[] { rgb4_Bytes4x4, new ushort[] { 4, 4, 4 }, 0, 0, 4, 4, rgb4_Result4x4 }; - yield return new object[] { rgb4_Bytes4x4, new ushort[] { 4, 4, 4 }, 0, 0, 4, 4, Offset(rgb4_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { rgb4_Bytes4x4, new ushort[] { 4, 4, 4 }, 1, 0, 4, 4, Offset(rgb4_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { rgb4_Bytes4x4, new ushort[] { 4, 4, 4 }, 0, 1, 4, 4, Offset(rgb4_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { rgb4_Bytes4x4, new ushort[] { 4, 4, 4 }, 1, 1, 4, 4, Offset(rgb4_Result4x4, 1, 1, 6, 6) }; - - yield return new object[] { rgb4_Bytes3x4, new ushort[] { 4, 4, 4 }, 0, 0, 3, 4, rgb4_Result3x4 }; - yield return new object[] { rgb4_Bytes3x4, new ushort[] { 4, 4, 4 }, 0, 0, 3, 4, Offset(rgb4_Result3x4, 0, 0, 6, 6) }; - yield return new object[] { rgb4_Bytes3x4, new ushort[] { 4, 4, 4 }, 1, 0, 3, 4, Offset(rgb4_Result3x4, 1, 0, 6, 6) }; - yield return new object[] { rgb4_Bytes3x4, new ushort[] { 4, 4, 4 }, 0, 1, 3, 4, Offset(rgb4_Result3x4, 0, 1, 6, 6) }; - yield return new object[] { rgb4_Bytes3x4, new ushort[] { 4, 4, 4 }, 1, 1, 3, 4, Offset(rgb4_Result3x4, 1, 1, 6, 6) }; + yield return new object[] { Rgb4Bytes4X4, new ushort[] { 4, 4, 4 }, 0, 0, 4, 4, Rgb4Result4X4 }; + yield return new object[] { Rgb4Bytes4X4, new ushort[] { 4, 4, 4 }, 0, 0, 4, 4, Offset(Rgb4Result4X4, 0, 0, 6, 6) }; + yield return new object[] { Rgb4Bytes4X4, new ushort[] { 4, 4, 4 }, 1, 0, 4, 4, Offset(Rgb4Result4X4, 1, 0, 6, 6) }; + yield return new object[] { Rgb4Bytes4X4, new ushort[] { 4, 4, 4 }, 0, 1, 4, 4, Offset(Rgb4Result4X4, 0, 1, 6, 6) }; + yield return new object[] { Rgb4Bytes4X4, new ushort[] { 4, 4, 4 }, 1, 1, 4, 4, Offset(Rgb4Result4X4, 1, 1, 6, 6) }; + + yield return new object[] { Rgb4Bytes3X4, new ushort[] { 4, 4, 4 }, 0, 0, 3, 4, Rgb4Result3X4 }; + yield return new object[] { Rgb4Bytes3X4, new ushort[] { 4, 4, 4 }, 0, 0, 3, 4, Offset(Rgb4Result3X4, 0, 0, 6, 6) }; + yield return new object[] { Rgb4Bytes3X4, new ushort[] { 4, 4, 4 }, 1, 0, 3, 4, Offset(Rgb4Result3X4, 1, 0, 6, 6) }; + yield return new object[] { Rgb4Bytes3X4, new ushort[] { 4, 4, 4 }, 0, 1, 3, 4, Offset(Rgb4Result3X4, 0, 1, 6, 6) }; + yield return new object[] { Rgb4Bytes3X4, new ushort[] { 4, 4, 4 }, 1, 1, 3, 4, Offset(Rgb4Result3X4, 1, 1, 6, 6) }; } } - private static Rgba32 rgb8_000 = new Rgba32(0, 0, 0, 255); - private static Rgba32 rgb8_444 = new Rgba32(64, 64, 64, 255); - private static Rgba32 rgb8_888 = new Rgba32(128, 128, 128, 255); - private static Rgba32 rgb8_CCC = new Rgba32(192, 192, 192, 255); - private static Rgba32 rgb8_FFF = new Rgba32(255, 255, 255, 255); - private static Rgba32 rgb8_F00 = new Rgba32(255, 0, 0, 255); - private static Rgba32 rgb8_0F0 = new Rgba32(0, 255, 0, 255); - private static Rgba32 rgb8_00F = new Rgba32(0, 0, 255, 255); - private static Rgba32 rgb8_F0F = new Rgba32(255, 0, 255, 255); - private static Rgba32 rgb8_400 = new Rgba32(64, 0, 0, 255); - private static Rgba32 rgb8_800 = new Rgba32(128, 0, 0, 255); - private static Rgba32 rgb8_C00 = new Rgba32(192, 0, 0, 255); - private static Rgba32 rgb8_48C = new Rgba32(64, 128, 192, 255); - - private static byte[] rgb8_Bytes4x4 = + private static readonly Rgba32 Rgb8_000 = new Rgba32(0, 0, 0, 255); + private static readonly Rgba32 Rgb8_444 = new Rgba32(64, 64, 64, 255); + private static readonly Rgba32 Rgb8_888 = new Rgba32(128, 128, 128, 255); + private static readonly Rgba32 Rgb8_CCC = new Rgba32(192, 192, 192, 255); + private static readonly Rgba32 Rgb8_FFF = new Rgba32(255, 255, 255, 255); + private static readonly Rgba32 Rgb8_F00 = new Rgba32(255, 0, 0, 255); + private static readonly Rgba32 Rgb8_0F0 = new Rgba32(0, 255, 0, 255); + private static readonly Rgba32 Rgb8_00F = new Rgba32(0, 0, 255, 255); + private static readonly Rgba32 Rgb8_F0F = new Rgba32(255, 0, 255, 255); + private static readonly Rgba32 Rgb8_400 = new Rgba32(64, 0, 0, 255); + private static readonly Rgba32 Rgb8_800 = new Rgba32(128, 0, 0, 255); + private static readonly Rgba32 Rgb8_C00 = new Rgba32(192, 0, 0, 255); + private static readonly Rgba32 Rgb8_48C = new Rgba32(64, 128, 192, 255); + + private static readonly byte[] Rgb8Bytes4X4 = { 000, 000, 000, 255, 255, 255, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 255, 000, 000, 000, 255, 255, 000, 255, @@ -98,41 +99,41 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 000, 000, 000, 064, 064, 064, 128, 128, 128, 192, 192, 192 }; - private static Rgba32[][] rgb8_Result4x4 = + private static readonly Rgba32[][] Rgb8Result4X4 = { - new[] { rgb8_000, rgb8_FFF, rgb8_000, rgb8_FFF }, - new[] { rgb8_F00, rgb8_0F0, rgb8_00F, rgb8_F0F }, - new[] { rgb8_400, rgb8_800, rgb8_C00, rgb8_48C }, - new[] { rgb8_000, rgb8_444, rgb8_888, rgb8_CCC } + new[] { Rgb8_000, Rgb8_FFF, Rgb8_000, Rgb8_FFF }, + new[] { Rgb8_F00, Rgb8_0F0, Rgb8_00F, Rgb8_F0F }, + new[] { Rgb8_400, Rgb8_800, Rgb8_C00, Rgb8_48C }, + new[] { Rgb8_000, Rgb8_444, Rgb8_888, Rgb8_CCC } }; - public static IEnumerable Rgb8_Data + public static IEnumerable Rgb8Data { get { - yield return new object[] { rgb8_Bytes4x4, new ushort[] { 8, 8, 8 }, 0, 0, 4, 4, rgb8_Result4x4 }; - yield return new object[] { rgb8_Bytes4x4, new ushort[] { 8, 8, 8 }, 0, 0, 4, 4, Offset(rgb8_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { rgb8_Bytes4x4, new ushort[] { 8, 8, 8 }, 1, 0, 4, 4, Offset(rgb8_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { rgb8_Bytes4x4, new ushort[] { 8, 8, 8 }, 0, 1, 4, 4, Offset(rgb8_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { rgb8_Bytes4x4, new ushort[] { 8, 8, 8 }, 1, 1, 4, 4, Offset(rgb8_Result4x4, 1, 1, 6, 6) }; + yield return new object[] { Rgb8Bytes4X4, new ushort[] { 8, 8, 8 }, 0, 0, 4, 4, Rgb8Result4X4 }; + yield return new object[] { Rgb8Bytes4X4, new ushort[] { 8, 8, 8 }, 0, 0, 4, 4, Offset(Rgb8Result4X4, 0, 0, 6, 6) }; + yield return new object[] { Rgb8Bytes4X4, new ushort[] { 8, 8, 8 }, 1, 0, 4, 4, Offset(Rgb8Result4X4, 1, 0, 6, 6) }; + yield return new object[] { Rgb8Bytes4X4, new ushort[] { 8, 8, 8 }, 0, 1, 4, 4, Offset(Rgb8Result4X4, 0, 1, 6, 6) }; + yield return new object[] { Rgb8Bytes4X4, new ushort[] { 8, 8, 8 }, 1, 1, 4, 4, Offset(Rgb8Result4X4, 1, 1, 6, 6) }; } } - private static Rgba32 rgb484_000 = new Rgba32(0, 0, 0, 255); - private static Rgba32 rgb484_444 = new Rgba32(68, 64, 68, 255); - private static Rgba32 rgb484_888 = new Rgba32(136, 128, 136, 255); - private static Rgba32 rgb484_CCC = new Rgba32(204, 192, 204, 255); - private static Rgba32 rgb484_FFF = new Rgba32(255, 255, 255, 255); - private static Rgba32 rgb484_F00 = new Rgba32(255, 0, 0, 255); - private static Rgba32 rgb484_0F0 = new Rgba32(0, 255, 0, 255); - private static Rgba32 rgb484_00F = new Rgba32(0, 0, 255, 255); - private static Rgba32 rgb484_F0F = new Rgba32(255, 0, 255, 255); - private static Rgba32 rgb484_400 = new Rgba32(68, 0, 0, 255); - private static Rgba32 rgb484_800 = new Rgba32(136, 0, 0, 255); - private static Rgba32 rgb484_C00 = new Rgba32(204, 0, 0, 255); - private static Rgba32 rgb484_48C = new Rgba32(68, 128, 204, 255); - - private static byte[] rgb484_Bytes4x4 = + private static readonly Rgba32 Rgb484_000 = new Rgba32(0, 0, 0, 255); + private static readonly Rgba32 Rgb484_444 = new Rgba32(68, 64, 68, 255); + private static readonly Rgba32 Rgb484_888 = new Rgba32(136, 128, 136, 255); + private static readonly Rgba32 Rgb484_CCC = new Rgba32(204, 192, 204, 255); + private static readonly Rgba32 Rgb484_FFF = new Rgba32(255, 255, 255, 255); + private static readonly Rgba32 Rgb484_F00 = new Rgba32(255, 0, 0, 255); + private static readonly Rgba32 Rgb484_0F0 = new Rgba32(0, 255, 0, 255); + private static readonly Rgba32 Rgb484_00F = new Rgba32(0, 0, 255, 255); + private static readonly Rgba32 Rgb484_F0F = new Rgba32(255, 0, 255, 255); + private static readonly Rgba32 Rgb484_400 = new Rgba32(68, 0, 0, 255); + private static readonly Rgba32 Rgb484_800 = new Rgba32(136, 0, 0, 255); + private static readonly Rgba32 Rgb484_C00 = new Rgba32(204, 0, 0, 255); + private static readonly Rgba32 Rgb484_48C = new Rgba32(68, 128, 204, 255); + + private static readonly byte[] Rgb484Bytes4X4 = { 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xF0, 0x00, 0x0F, 0xF0, 0x00, 0x0F, 0xF0, 0x0F, @@ -140,30 +141,30 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0x00, 0x00, 0x44, 0x04, 0x88, 0x08, 0xCC, 0x0C }; - private static Rgba32[][] rgb484_Result4x4 = + private static readonly Rgba32[][] Rgb484Result4X4 = { - new[] { rgb484_000, rgb484_FFF, rgb484_000, rgb484_FFF }, - new[] { rgb484_F00, rgb484_0F0, rgb484_00F, rgb484_F0F }, - new[] { rgb484_400, rgb484_800, rgb484_C00, rgb484_48C }, - new[] { rgb484_000, rgb484_444, rgb484_888, rgb484_CCC } + new[] { Rgb484_000, Rgb484_FFF, Rgb484_000, Rgb484_FFF }, + new[] { Rgb484_F00, Rgb484_0F0, Rgb484_00F, Rgb484_F0F }, + new[] { Rgb484_400, Rgb484_800, Rgb484_C00, Rgb484_48C }, + new[] { Rgb484_000, Rgb484_444, Rgb484_888, Rgb484_CCC } }; - public static IEnumerable Rgb484_Data + public static IEnumerable Rgb484Data { get { - yield return new object[] { rgb484_Bytes4x4, new ushort[] { 4, 8, 4 }, 0, 0, 4, 4, rgb484_Result4x4 }; - yield return new object[] { rgb484_Bytes4x4, new ushort[] { 4, 8, 4 }, 0, 0, 4, 4, Offset(rgb484_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { rgb484_Bytes4x4, new ushort[] { 4, 8, 4 }, 1, 0, 4, 4, Offset(rgb484_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { rgb484_Bytes4x4, new ushort[] { 4, 8, 4 }, 0, 1, 4, 4, Offset(rgb484_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { rgb484_Bytes4x4, new ushort[] { 4, 8, 4 }, 1, 1, 4, 4, Offset(rgb484_Result4x4, 1, 1, 6, 6) }; + yield return new object[] { Rgb484Bytes4X4, new ushort[] { 4, 8, 4 }, 0, 0, 4, 4, Rgb484Result4X4 }; + yield return new object[] { Rgb484Bytes4X4, new ushort[] { 4, 8, 4 }, 0, 0, 4, 4, Offset(Rgb484Result4X4, 0, 0, 6, 6) }; + yield return new object[] { Rgb484Bytes4X4, new ushort[] { 4, 8, 4 }, 1, 0, 4, 4, Offset(Rgb484Result4X4, 1, 0, 6, 6) }; + yield return new object[] { Rgb484Bytes4X4, new ushort[] { 4, 8, 4 }, 0, 1, 4, 4, Offset(Rgb484Result4X4, 0, 1, 6, 6) }; + yield return new object[] { Rgb484Bytes4X4, new ushort[] { 4, 8, 4 }, 1, 1, 4, 4, Offset(Rgb484Result4X4, 1, 1, 6, 6) }; } } [Theory] - [MemberData(nameof(Rgb4_Data))] - [MemberData(nameof(Rgb8_Data))] - [MemberData(nameof(Rgb484_Data))] + [MemberData(nameof(Rgb4Data))] + [MemberData(nameof(Rgb8Data))] + [MemberData(nameof(Rgb484Data))] public void Decode_WritesPixelData(byte[] inputData, ushort[] bitsPerSample, int left, int top, int width, int height, Rgba32[][] expectedResult) { AssertDecode(expectedResult, pixels => @@ -173,7 +174,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation } [Theory] - [MemberData(nameof(Rgb8_Data))] + [MemberData(nameof(Rgb8Data))] public void Decode_WritesPixelData_8Bit(byte[] inputData, ushort[] bitsPerSample, int left, int top, int width, int height, Rgba32[][] expectedResult) { AssertDecode(expectedResult, pixels => diff --git a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/WhiteIsZeroTiffColorTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/WhiteIsZeroTiffColorTests.cs index e714996aea..d29b668a8d 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/WhiteIsZeroTiffColorTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/WhiteIsZeroTiffColorTests.cs @@ -10,18 +10,19 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation { + [Trait("Format", "Tiff")] public class WhiteIsZeroTiffColorTests : PhotometricInterpretationTestBase { - private static Rgba32 gray000 = new Rgba32(255, 255, 255, 255); - private static Rgba32 gray128 = new Rgba32(127, 127, 127, 255); - private static Rgba32 gray255 = new Rgba32(0, 0, 0, 255); - private static Rgba32 gray0 = new Rgba32(255, 255, 255, 255); - private static Rgba32 gray8 = new Rgba32(119, 119, 119, 255); - private static Rgba32 grayF = new Rgba32(0, 0, 0, 255); - private static Rgba32 bit0 = new Rgba32(255, 255, 255, 255); - private static Rgba32 bit1 = new Rgba32(0, 0, 0, 255); + private static readonly Rgba32 Gray000 = new Rgba32(255, 255, 255, 255); + private static readonly Rgba32 Gray128 = new Rgba32(127, 127, 127, 255); + private static readonly Rgba32 Gray255 = new Rgba32(0, 0, 0, 255); + private static readonly Rgba32 Gray0 = new Rgba32(255, 255, 255, 255); + private static readonly Rgba32 Gray8 = new Rgba32(119, 119, 119, 255); + private static readonly Rgba32 GrayF = new Rgba32(0, 0, 0, 255); + private static readonly Rgba32 Bit0 = new Rgba32(255, 255, 255, 255); + private static readonly Rgba32 Bit1 = new Rgba32(0, 0, 0, 255); - private static readonly byte[] Bilevel_Bytes4x4 = + private static readonly byte[] BilevelBytes4X4 = { 0b01010000, 0b11110000, @@ -29,15 +30,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0b10010000 }; - private static readonly Rgba32[][] Bilevel_Result4x4 = + private static readonly Rgba32[][] BilevelResult4X4 = { - new[] { bit0, bit1, bit0, bit1 }, - new[] { bit1, bit1, bit1, bit1 }, - new[] { bit0, bit1, bit1, bit1 }, - new[] { bit1, bit0, bit0, bit1 } + new[] { Bit0, Bit1, Bit0, Bit1 }, + new[] { Bit1, Bit1, Bit1, Bit1 }, + new[] { Bit0, Bit1, Bit1, Bit1 }, + new[] { Bit1, Bit0, Bit0, Bit1 } }; - private static readonly byte[] Bilevel_Bytes12x4 = + private static readonly byte[] BilevelBytes12X4 = { 0b01010101, 0b01010000, 0b11111111, 0b11111111, @@ -45,15 +46,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0b10010000, 0b01100000 }; - private static readonly Rgba32[][] Bilevel_Result12x4 = + private static readonly Rgba32[][] BilevelResult12X4 = { - new[] { bit0, bit1, bit0, bit1, bit0, bit1, bit0, bit1, bit0, bit1, bit0, bit1 }, - new[] { bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1 }, - new[] { bit0, bit1, bit1, bit0, bit1, bit0, bit0, bit1, bit1, bit0, bit1, bit0 }, - new[] { bit1, bit0, bit0, bit1, bit0, bit0, bit0, bit0, bit0, bit1, bit1, bit0 } + new[] { Bit0, Bit1, Bit0, Bit1, Bit0, Bit1, Bit0, Bit1, Bit0, Bit1, Bit0, Bit1 }, + new[] { Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1 }, + new[] { Bit0, Bit1, Bit1, Bit0, Bit1, Bit0, Bit0, Bit1, Bit1, Bit0, Bit1, Bit0 }, + new[] { Bit1, Bit0, Bit0, Bit1, Bit0, Bit0, Bit0, Bit0, Bit0, Bit1, Bit1, Bit0 } }; - private static readonly byte[] Grayscale4_Bytes4x4 = + private static readonly byte[] Grayscale4Bytes4X4 = { 0x8F, 0x0F, 0xFF, 0xFF, @@ -61,15 +62,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0xF0, 0xF8 }; - private static readonly Rgba32[][] Grayscale4_Result4x4 = + private static readonly Rgba32[][] Grayscale4Result4X4 = { - new[] { gray8, grayF, gray0, grayF }, - new[] { grayF, grayF, grayF, grayF }, - new[] { gray0, gray8, gray8, grayF }, - new[] { grayF, gray0, grayF, gray8 } + new[] { Gray8, GrayF, Gray0, GrayF }, + new[] { GrayF, GrayF, GrayF, GrayF }, + new[] { Gray0, Gray8, Gray8, GrayF }, + new[] { GrayF, Gray0, GrayF, Gray8 } }; - private static readonly byte[] Grayscale4_Bytes3x4 = + private static readonly byte[] Grayscale4Bytes3X4 = { 0x8F, 0x00, 0xFF, 0xF0, @@ -77,15 +78,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 0xF0, 0xF0 }; - private static readonly Rgba32[][] Grayscale4_Result3x4 = + private static readonly Rgba32[][] Grayscale4Result3X4 = { - new[] { gray8, grayF, gray0 }, - new[] { grayF, grayF, grayF }, - new[] { gray0, gray8, gray8 }, - new[] { grayF, gray0, grayF } + new[] { Gray8, GrayF, Gray0 }, + new[] { GrayF, GrayF, GrayF }, + new[] { Gray0, Gray8, Gray8 }, + new[] { GrayF, Gray0, GrayF } }; - private static readonly byte[] Grayscale8_Bytes4x4 = + private static readonly byte[] Grayscale8Bytes4X4 = { 128, 255, 000, 255, 255, 255, 255, 255, @@ -93,66 +94,66 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation 255, 000, 255, 128 }; - private static readonly Rgba32[][] Grayscale8_Result4x4 = + private static readonly Rgba32[][] Grayscale8Result4X4 = { - new[] { gray128, gray255, gray000, gray255 }, - new[] { gray255, gray255, gray255, gray255 }, - new[] { gray000, gray128, gray128, gray255 }, - new[] { gray255, gray000, gray255, gray128 } + new[] { Gray128, Gray255, Gray000, Gray255 }, + new[] { Gray255, Gray255, Gray255, Gray255 }, + new[] { Gray000, Gray128, Gray128, Gray255 }, + new[] { Gray255, Gray000, Gray255, Gray128 } }; - public static IEnumerable Bilevel_Data + public static IEnumerable BilevelData { get { - yield return new object[] { Bilevel_Bytes4x4, 1, 0, 0, 4, 4, Bilevel_Result4x4 }; - yield return new object[] { Bilevel_Bytes4x4, 1, 0, 0, 4, 4, Offset(Bilevel_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { Bilevel_Bytes4x4, 1, 1, 0, 4, 4, Offset(Bilevel_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { Bilevel_Bytes4x4, 1, 0, 1, 4, 4, Offset(Bilevel_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { Bilevel_Bytes4x4, 1, 1, 1, 4, 4, Offset(Bilevel_Result4x4, 1, 1, 6, 6) }; - - yield return new object[] { Bilevel_Bytes12x4, 1, 0, 0, 12, 4, Bilevel_Result12x4 }; - yield return new object[] { Bilevel_Bytes12x4, 1, 0, 0, 12, 4, Offset(Bilevel_Result12x4, 0, 0, 18, 6) }; - yield return new object[] { Bilevel_Bytes12x4, 1, 1, 0, 12, 4, Offset(Bilevel_Result12x4, 1, 0, 18, 6) }; - yield return new object[] { Bilevel_Bytes12x4, 1, 0, 1, 12, 4, Offset(Bilevel_Result12x4, 0, 1, 18, 6) }; - yield return new object[] { Bilevel_Bytes12x4, 1, 1, 1, 12, 4, Offset(Bilevel_Result12x4, 1, 1, 18, 6) }; + yield return new object[] { BilevelBytes4X4, 1, 0, 0, 4, 4, BilevelResult4X4 }; + yield return new object[] { BilevelBytes4X4, 1, 0, 0, 4, 4, Offset(BilevelResult4X4, 0, 0, 6, 6) }; + yield return new object[] { BilevelBytes4X4, 1, 1, 0, 4, 4, Offset(BilevelResult4X4, 1, 0, 6, 6) }; + yield return new object[] { BilevelBytes4X4, 1, 0, 1, 4, 4, Offset(BilevelResult4X4, 0, 1, 6, 6) }; + yield return new object[] { BilevelBytes4X4, 1, 1, 1, 4, 4, Offset(BilevelResult4X4, 1, 1, 6, 6) }; + + yield return new object[] { BilevelBytes12X4, 1, 0, 0, 12, 4, BilevelResult12X4 }; + yield return new object[] { BilevelBytes12X4, 1, 0, 0, 12, 4, Offset(BilevelResult12X4, 0, 0, 18, 6) }; + yield return new object[] { BilevelBytes12X4, 1, 1, 0, 12, 4, Offset(BilevelResult12X4, 1, 0, 18, 6) }; + yield return new object[] { BilevelBytes12X4, 1, 0, 1, 12, 4, Offset(BilevelResult12X4, 0, 1, 18, 6) }; + yield return new object[] { BilevelBytes12X4, 1, 1, 1, 12, 4, Offset(BilevelResult12X4, 1, 1, 18, 6) }; } } - public static IEnumerable Grayscale4_Data + public static IEnumerable Grayscale4Data { get { - yield return new object[] { Grayscale4_Bytes4x4, 4, 0, 0, 4, 4, Grayscale4_Result4x4 }; - yield return new object[] { Grayscale4_Bytes4x4, 4, 0, 0, 4, 4, Offset(Grayscale4_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { Grayscale4_Bytes4x4, 4, 1, 0, 4, 4, Offset(Grayscale4_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { Grayscale4_Bytes4x4, 4, 0, 1, 4, 4, Offset(Grayscale4_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { Grayscale4_Bytes4x4, 4, 1, 1, 4, 4, Offset(Grayscale4_Result4x4, 1, 1, 6, 6) }; - - yield return new object[] { Grayscale4_Bytes3x4, 4, 0, 0, 3, 4, Grayscale4_Result3x4 }; - yield return new object[] { Grayscale4_Bytes3x4, 4, 0, 0, 3, 4, Offset(Grayscale4_Result3x4, 0, 0, 6, 6) }; - yield return new object[] { Grayscale4_Bytes3x4, 4, 1, 0, 3, 4, Offset(Grayscale4_Result3x4, 1, 0, 6, 6) }; - yield return new object[] { Grayscale4_Bytes3x4, 4, 0, 1, 3, 4, Offset(Grayscale4_Result3x4, 0, 1, 6, 6) }; - yield return new object[] { Grayscale4_Bytes3x4, 4, 1, 1, 3, 4, Offset(Grayscale4_Result3x4, 1, 1, 6, 6) }; + yield return new object[] { Grayscale4Bytes4X4, 4, 0, 0, 4, 4, Grayscale4Result4X4 }; + yield return new object[] { Grayscale4Bytes4X4, 4, 0, 0, 4, 4, Offset(Grayscale4Result4X4, 0, 0, 6, 6) }; + yield return new object[] { Grayscale4Bytes4X4, 4, 1, 0, 4, 4, Offset(Grayscale4Result4X4, 1, 0, 6, 6) }; + yield return new object[] { Grayscale4Bytes4X4, 4, 0, 1, 4, 4, Offset(Grayscale4Result4X4, 0, 1, 6, 6) }; + yield return new object[] { Grayscale4Bytes4X4, 4, 1, 1, 4, 4, Offset(Grayscale4Result4X4, 1, 1, 6, 6) }; + + yield return new object[] { Grayscale4Bytes3X4, 4, 0, 0, 3, 4, Grayscale4Result3X4 }; + yield return new object[] { Grayscale4Bytes3X4, 4, 0, 0, 3, 4, Offset(Grayscale4Result3X4, 0, 0, 6, 6) }; + yield return new object[] { Grayscale4Bytes3X4, 4, 1, 0, 3, 4, Offset(Grayscale4Result3X4, 1, 0, 6, 6) }; + yield return new object[] { Grayscale4Bytes3X4, 4, 0, 1, 3, 4, Offset(Grayscale4Result3X4, 0, 1, 6, 6) }; + yield return new object[] { Grayscale4Bytes3X4, 4, 1, 1, 3, 4, Offset(Grayscale4Result3X4, 1, 1, 6, 6) }; } } - public static IEnumerable Grayscale8_Data + public static IEnumerable Grayscale8Data { get { - yield return new object[] { Grayscale8_Bytes4x4, 8, 0, 0, 4, 4, Grayscale8_Result4x4 }; - yield return new object[] { Grayscale8_Bytes4x4, 8, 0, 0, 4, 4, Offset(Grayscale8_Result4x4, 0, 0, 6, 6) }; - yield return new object[] { Grayscale8_Bytes4x4, 8, 1, 0, 4, 4, Offset(Grayscale8_Result4x4, 1, 0, 6, 6) }; - yield return new object[] { Grayscale8_Bytes4x4, 8, 0, 1, 4, 4, Offset(Grayscale8_Result4x4, 0, 1, 6, 6) }; - yield return new object[] { Grayscale8_Bytes4x4, 8, 1, 1, 4, 4, Offset(Grayscale8_Result4x4, 1, 1, 6, 6) }; + yield return new object[] { Grayscale8Bytes4X4, 8, 0, 0, 4, 4, Grayscale8Result4X4 }; + yield return new object[] { Grayscale8Bytes4X4, 8, 0, 0, 4, 4, Offset(Grayscale8Result4X4, 0, 0, 6, 6) }; + yield return new object[] { Grayscale8Bytes4X4, 8, 1, 0, 4, 4, Offset(Grayscale8Result4X4, 1, 0, 6, 6) }; + yield return new object[] { Grayscale8Bytes4X4, 8, 0, 1, 4, 4, Offset(Grayscale8Result4X4, 0, 1, 6, 6) }; + yield return new object[] { Grayscale8Bytes4X4, 8, 1, 1, 4, 4, Offset(Grayscale8Result4X4, 1, 1, 6, 6) }; } } [Theory] - [MemberData(nameof(Bilevel_Data))] - [MemberData(nameof(Grayscale4_Data))] - [MemberData(nameof(Grayscale8_Data))] + [MemberData(nameof(BilevelData))] + [MemberData(nameof(Grayscale4Data))] + [MemberData(nameof(Grayscale8Data))] public void Decode_WritesPixelData(byte[] inputData, int bitsPerSample, int left, int top, int width, int height, Rgba32[][] expectedResult) { AssertDecode(expectedResult, pixels => @@ -162,7 +163,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation } [Theory] - [MemberData(nameof(Bilevel_Data))] + [MemberData(nameof(BilevelData))] public void Decode_WritesPixelData_Bilevel(byte[] inputData, int bitsPerSample, int left, int top, int width, int height, Rgba32[][] expectedResult) { AssertDecode(expectedResult, pixels => @@ -172,7 +173,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation } [Theory] - [MemberData(nameof(Grayscale4_Data))] + [MemberData(nameof(Grayscale4Data))] public void Decode_WritesPixelData_4Bit(byte[] inputData, int bitsPerSample, int left, int top, int width, int height, Rgba32[][] expectedResult) { AssertDecode(expectedResult, pixels => @@ -182,7 +183,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation } [Theory] - [MemberData(nameof(Grayscale8_Data))] + [MemberData(nameof(Grayscale8Data))] public void Decode_WritesPixelData_8Bit(byte[] inputData, int bitsPerSample, int left, int top, int width, int height, Rgba32[][] expectedResult) { AssertDecode(expectedResult, pixels => diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs index 20826df8c3..be9f189072 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs @@ -229,7 +229,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff // Assert ms.Position = 0; - using var output = Image.Load(ms); + using var output = Image.Load(this.configuration, ms); ImageMetadata coreMetaOut = output.Metadata; TiffMetadata tiffMetaOut = output.Metadata.GetTiffMetadata(); @@ -300,19 +300,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff coreMeta.IptcProfile = new IptcProfile(); coreMeta.IptcProfile.SetValue(IptcTag.Caption, "iptc caption"); - coreMeta.IccProfile = new IccProfile( - new IccProfileHeader() { CreationDate = DateTime.Now }, - new IccTagDataEntry[] - { - new IccTextTagDataEntry("test string"), - new IccDataTagDataEntry(new byte[] { 11, 22, 33, 44 }) - }); + coreMeta.IccProfile = new IccProfile(new IccProfileHeader() { CreationDate = DateTime.Now }, new IccTagDataEntry[] { new IccTextTagDataEntry("test string"), new IccDataTagDataEntry(new byte[] { 11, 22, 33, 44 }) }); coreMeta.ResolutionUnits = PixelResolutionUnit.PixelsPerMeter; coreMeta.HorizontalResolution = 4500; coreMeta.VerticalResolution = 5400; - var datetime = System.DateTime.Now.ToString(); + var datetime = DateTime.Now.ToString(); frameMeta.ImageDescription = "test ImageDescription"; frameMeta.DateTime = datetime; @@ -328,7 +322,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff // Assert ms.Position = 0; - using var output = Image.Load(ms); + using var output = Image.Load(this.configuration, ms); TiffMetadata meta = output.Metadata.GetTiffMetadata(); ImageMetadata coreMetaOut = output.Metadata; @@ -357,7 +351,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff Assert.NotNull(coreMeta.IccProfile); Assert.Equal(tiffMeta.XmpProfile, tiffMetaOut.XmpProfile); - //// todo: failure Assert.Equal(coreMeta.IptcProfile, coreMetaOut.IptcProfile); Assert.Equal(coreMeta.IptcProfile.Data, coreMetaOut.IptcProfile.Data); Assert.Equal(coreMeta.IccProfile.ToByteArray(), coreMetaOut.IccProfile.ToByteArray()); diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs index 70ae84190d..4788144eff 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs @@ -5,11 +5,11 @@ using System; using System.IO; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Bmp; +using SixLabors.ImageSharp.Formats.Experimental.Tiff; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Formats.Tga; -using SixLabors.ImageSharp.Formats.Experimental.Tiff; using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; namespace SixLabors.ImageSharp.Tests