Browse Source

Fix warnings

pull/1570/head
Brian Popow 6 years ago
parent
commit
6851e4bd74
  1. 150
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs
  2. 67
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PaletteTiffColorTests.cs
  3. 351
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbPlanarTiffColorTests.cs
  4. 228
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbTiffColorTests.cs
  5. 150
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/WhiteIsZeroTiffColorTests.cs
  6. 10
      tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs
  7. 10
      tests/ImageSharp.Tests/Formats/Tiff/Utils/TiffWriterTests.cs
  8. 8
      tests/ImageSharp.Tests/TestUtilities/ByteArrayUtility.cs
  9. 16
      tests/ImageSharp.Tests/TestUtilities/ByteBuffer.cs
  10. 3
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs

150
tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs

@ -2,72 +2,104 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Collections.Generic; using System.Collections.Generic;
using SixLabors.ImageSharp.Formats.Tiff; using SixLabors.ImageSharp.Formats.Tiff;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation
{ {
public class BlackIsZeroTiffColorTests : PhotometricInterpretationTestBase public class BlackIsZeroTiffColorTests : PhotometricInterpretationTestBase
{ {
private static Rgba32 Gray000 = new Rgba32(0, 0, 0, 255); private static Rgba32 gray000 = new Rgba32(0, 0, 0, 255);
private static Rgba32 Gray128 = new Rgba32(128, 128, 128, 255); private static Rgba32 gray128 = new Rgba32(128, 128, 128, 255);
private static Rgba32 Gray255 = new Rgba32(255, 255, 255, 255); private static Rgba32 gray255 = new Rgba32(255, 255, 255, 255);
private static Rgba32 Gray0 = new Rgba32(0, 0, 0, 255); private static Rgba32 gray0 = new Rgba32(0, 0, 0, 255);
private static Rgba32 Gray8 = new Rgba32(136, 136, 136, 255); private static Rgba32 gray8 = new Rgba32(136, 136, 136, 255);
private static Rgba32 GrayF = new Rgba32(255, 255, 255, 255); private static Rgba32 grayF = new Rgba32(255, 255, 255, 255);
private static Rgba32 Bit0 = new Rgba32(0, 0, 0, 255); private static Rgba32 bit0 = new Rgba32(0, 0, 0, 255);
private static Rgba32 Bit1 = new Rgba32(255, 255, 255, 255); private static Rgba32 bit1 = new Rgba32(255, 255, 255, 255);
private static readonly byte[] Bilevel_Bytes4x4 = new byte[] { 0b01010000, private static readonly byte[] Bilevel_Bytes4x4 =
0b11110000, {
0b01110000, 0b01010000,
0b10010000 }; 0b11110000,
0b01110000,
private static readonly Rgba32[][] Bilevel_Result4x4 = new[] { new[] { Bit0, Bit1, Bit0, Bit1 }, 0b10010000
new[] { Bit1, Bit1, Bit1, Bit1 }, };
new[] { Bit0, Bit1, Bit1, Bit1 },
new[] { Bit1, Bit0, Bit0, Bit1 }}; private static readonly Rgba32[][] Bilevel_Result4x4 = new[]
{
private static readonly byte[] Bilevel_Bytes12x4 = new byte[] { 0b01010101, 0b01010000, new[] { bit0, bit1, bit0, bit1 },
0b11111111, 0b11111111, new[] { bit1, bit1, bit1, bit1 },
0b01101001, 0b10100000, new[] { bit0, bit1, bit1, bit1 },
0b10010000, 0b01100000}; new[] { bit1, bit0, bit0, bit1 }
};
private static readonly Rgba32[][] Bilevel_Result12x4 = new[] { 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 }, private static readonly byte[] Bilevel_Bytes12x4 =
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 }}; 0b01010101, 0b01010000,
0b11111111, 0b11111111,
private static readonly byte[] Grayscale4_Bytes4x4 = new byte[] { 0x8F, 0x0F, 0b01101001, 0b10100000,
0xFF, 0xFF, 0b10010000, 0b01100000
0x08, 0x8F, };
0xF0, 0xF8 };
private static readonly Rgba32[][] Bilevel_Result12x4 =
private static readonly Rgba32[][] Grayscale4_Result4x4 = new[] { new[] { Gray8, GrayF, Gray0, GrayF }, {
new[] { GrayF, GrayF, GrayF, GrayF }, new[] { bit0, bit1, bit0, bit1, bit0, bit1, bit0, bit1, bit0, bit1, bit0, bit1 },
new[] { Gray0, Gray8, Gray8, GrayF }, new[] { bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1 },
new[] { GrayF, Gray0, GrayF, Gray8 }}; 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_Bytes3x4 = new byte[] { 0x8F, 0x00, };
0xFF, 0xF0,
0x08, 0x80, private static readonly byte[] Grayscale4_Bytes4x4 =
0xF0, 0xF0 }; {
0x8F, 0x0F,
private static readonly Rgba32[][] Grayscale4_Result3x4 = new[] { new[] { Gray8, GrayF, Gray0 }, 0xFF, 0xFF,
new[] { GrayF, GrayF, GrayF }, 0x08, 0x8F,
new[] { Gray0, Gray8, Gray8 }, 0xF0, 0xF8
new[] { GrayF, Gray0, GrayF }}; };
private static readonly byte[] Grayscale8_Bytes4x4 = new byte[] { 128, 255, 000, 255, private static readonly Rgba32[][] Grayscale4_Result4x4 =
255, 255, 255, 255, {
000, 128, 128, 255, new[] { gray8, grayF, gray0, grayF },
255, 000, 255, 128 }; new[] { grayF, grayF, grayF, grayF },
new[] { gray0, gray8, gray8, grayF },
private static readonly Rgba32[][] Grayscale8_Result4x4 = new[] { new[] { Gray128, Gray255, Gray000, Gray255 }, new[] { grayF, gray0, grayF, gray8 }
new[] { Gray255, Gray255, Gray255, Gray255 }, };
new[] { Gray000, Gray128, Gray128, Gray255 },
new[] { Gray255, Gray000, Gray255, Gray128 }}; private static readonly byte[] Grayscale4_Bytes3x4 =
{
0x8F, 0x00,
0xFF, 0xF0,
0x08, 0x80,
0xF0, 0xF0
};
private static readonly Rgba32[][] Grayscale4_Result3x4 =
{
new[] { gray8, grayF, gray0 },
new[] { grayF, grayF, grayF },
new[] { gray0, gray8, gray8 },
new[] { grayF, gray0, grayF }
};
private static readonly byte[] Grayscale8_Bytes4x4 =
{
128, 255, 000, 255,
255, 255, 255, 255,
000, 128, 128, 255,
255, 000, 255, 128
};
private static readonly Rgba32[][] Grayscale8_Result4x4 =
{
new[] { gray128, gray255, gray000, gray255 },
new[] { gray255, gray255, gray255, gray255 },
new[] { gray000, gray128, gray128, gray255 },
new[] { gray255, gray000, gray255, gray128 }
};
public static IEnumerable<object[]> Bilevel_Data public static IEnumerable<object[]> Bilevel_Data
{ {

67
tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PaletteTiffColorTests.cs

@ -2,11 +2,13 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Collections.Generic; using System.Collections.Generic;
using SixLabors.ImageSharp.Formats.Tiff; using SixLabors.ImageSharp.Formats.Tiff;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation
{ {
public class PaletteTiffColorTests : PhotometricInterpretationTestBase public class PaletteTiffColorTests : PhotometricInterpretationTestBase
{ {
@ -14,27 +16,24 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
public static ushort[] Palette4_ColorMap { get => GenerateColorMap(Palette4_ColorPalette); } public static ushort[] Palette4_ColorMap { get => GenerateColorMap(Palette4_ColorPalette); }
private static readonly byte[] Palette4_Bytes4x4 = new byte[] { 0x01, 0x23, private static readonly byte[] Palette4_Bytes4x4 =
0x4A, 0xD2, {
0x12, 0x34, 0x01, 0x23, 0x4A, 0xD2, 0x12, 0x34, 0xAB, 0xEF
0xAB, 0xEF }; };
private static readonly Rgba32[][] Palette4_Result4x4 = GenerateResult(Palette4_ColorPalette, private static readonly Rgba32[][] Palette4_Result4x4 = GenerateResult(
new[] { new[] { 0x00, 0x01, 0x02, 0x03 }, Palette4_ColorPalette,
new[] { 0x04, 0x0A, 0x0D, 0x02 }, new[] { new[] { 0x00, 0x01, 0x02, 0x03 }, new[] { 0x04, 0x0A, 0x0D, 0x02 }, new[] { 0x01, 0x02, 0x03, 0x04 }, new[] { 0x0A, 0x0B, 0x0E, 0x0F } });
new[] { 0x01, 0x02, 0x03, 0x04 },
new[] { 0x0A, 0x0B, 0x0E, 0x0F }});
private static readonly byte[] Palette4_Bytes3x4 = new byte[] { 0x01, 0x20, private static readonly byte[] Palette4_Bytes3x4 =
0x4A, 0xD0, {
0x12, 0x30, 0x01, 0x20,
0xAB, 0xE0 }; 0x4A, 0xD0,
0x12, 0x30,
0xAB, 0xE0
};
private static readonly Rgba32[][] Palette4_Result3x4 = GenerateResult(Palette4_ColorPalette, 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 } });
new[] { new[] { 0x00, 0x01, 0x02 },
new[] { 0x04, 0x0A, 0x0D },
new[] { 0x01, 0x02, 0x03 },
new[] { 0x0A, 0x0B, 0x0E }});
public static IEnumerable<object[]> Palette4_Data public static IEnumerable<object[]> Palette4_Data
{ {
@ -51,7 +50,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
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, 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, 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[] { Palette4_Bytes3x4, 4, Palette4_ColorMap, 1, 1, 3, 4, Offset(Palette4_Result3x4, 1, 1, 6, 6) };
} }
} }
@ -59,16 +57,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
public static ushort[] Palette8_ColorMap { get => GenerateColorMap(Palette8_ColorPalette); } public static ushort[] Palette8_ColorMap { get => GenerateColorMap(Palette8_ColorPalette); }
private static readonly byte[] Palette8_Bytes4x4 = new byte[] { 000, 001, 002, 003, private static readonly byte[] Palette8_Bytes4x4 =
100, 110, 120, 130, {
000, 255, 128, 255, 000, 001, 002, 003,
050, 100, 150, 200 }; 100, 110, 120, 130,
000, 255, 128, 255,
050, 100, 150, 200
};
private static readonly Rgba32[][] Palette8_Result4x4 = GenerateResult(Palette8_ColorPalette, 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 } });
new[] { new[] { 000, 001, 002, 003 },
new[] { 100, 110, 120, 130 },
new[] { 000, 255, 128, 255 },
new[] { 050, 100, 150, 200 }});
public static IEnumerable<object[]> Palette8_Data public static IEnumerable<object[]> Palette8_Data
{ {
@ -95,11 +92,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
private static uint[][] GeneratePalette(int count) private static uint[][] GeneratePalette(int count)
{ {
uint[][] palette = new uint[count][]; var palette = new uint[count][];
for (uint i = 0; i < count; i++) for (uint i = 0; i < count; i++)
{ {
palette[i] = new uint[] { (i * 2u) % 65536u, (i * 2625u) % 65536u, (i * 29401u) % 65536u }; palette[i] = new[] { (i * 2u) % 65536u, (i * 2625u) % 65536u, (i * 29401u) % 65536u };
} }
return palette; return palette;
@ -108,13 +105,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
private static ushort[] GenerateColorMap(uint[][] colorPalette) private static ushort[] GenerateColorMap(uint[][] colorPalette)
{ {
int colorCount = colorPalette.Length; int colorCount = colorPalette.Length;
ushort[] colorMap = new ushort[colorCount * 3]; var colorMap = new ushort[colorCount * 3];
for (int i = 0; i < colorCount; i++) for (int i = 0; i < colorCount; i++)
{ {
colorMap[colorCount * 0 + i] = (ushort)colorPalette[i][0]; colorMap[(colorCount * 0) + i] = (ushort)colorPalette[i][0];
colorMap[colorCount * 1 + i] = (ushort)colorPalette[i][1]; colorMap[(colorCount * 1) + i] = (ushort)colorPalette[i][1];
colorMap[colorCount * 2 + i] = (ushort)colorPalette[i][2]; colorMap[(colorCount * 2) + i] = (ushort)colorPalette[i][2];
} }
return colorMap; return colorMap;

351
tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbPlanarTiffColorTests.cs

@ -3,184 +3,237 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using SixLabors.ImageSharp.Formats.Tiff; using SixLabors.ImageSharp.Formats.Tiff;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation
{ {
public class RgbPlanarTiffColorTests : PhotometricInterpretationTestBase public class RgbPlanarTiffColorTests : PhotometricInterpretationTestBase
{ {
private static Rgba32 Rgb4_000 = new Rgba32(0, 0, 0, 255); 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_444 = new Rgba32(68, 68, 68, 255);
private static Rgba32 Rgb4_888 = new Rgba32(136, 136, 136, 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_CCC = new Rgba32(204, 204, 204, 255);
private static Rgba32 Rgb4_FFF = new Rgba32(255, 255, 255, 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_F00 = new Rgba32(255, 0, 0, 255);
private static Rgba32 Rgb4_0F0 = new Rgba32(0, 255, 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_00F = new Rgba32(0, 0, 255, 255);
private static Rgba32 Rgb4_F0F = new Rgba32(255, 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_400 = new Rgba32(68, 0, 0, 255);
private static Rgba32 Rgb4_800 = new Rgba32(136, 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_C00 = new Rgba32(204, 0, 0, 255);
private static Rgba32 Rgb4_48C = new Rgba32(68, 136, 204, 255); private static Rgba32 rgb4_48C = new Rgba32(68, 136, 204, 255);
private static byte[] Rgb4_Bytes4x4_R = new byte[] { 0x0F, 0x0F, private static byte[] rgb4_Bytes4x4_R =
0xF0, 0x0F, {
0x48, 0xC4, 0x0F, 0x0F,
0x04, 0x8C }; 0xF0, 0x0F,
0x48, 0xC4,
private static byte[] Rgb4_Bytes4x4_G = new byte[] { 0x0F, 0x0F, 0x04, 0x8C
0x0F, 0x00, };
0x00, 0x08,
0x04, 0x8C }; private static byte[] rgb4_Bytes4x4_G =
{
private static byte[] Rgb4_Bytes4x4_B = new byte[] { 0x0F, 0x0F, 0x0F, 0x0F,
0x00, 0xFF, 0x0F, 0x00,
0x00, 0x0C, 0x00, 0x08,
0x04, 0x8C }; 0x04, 0x8C
};
private static byte[][] Rgb4_Bytes4x4 = new[] { Rgb4_Bytes4x4_R, Rgb4_Bytes4x4_G, Rgb4_Bytes4x4_B };
private static byte[] rgb4_Bytes4x4_B =
private static Rgba32[][] Rgb4_Result4x4 = new[] { new[] { Rgb4_000, Rgb4_FFF, Rgb4_000, Rgb4_FFF }, {
new[] { Rgb4_F00, Rgb4_0F0, Rgb4_00F, Rgb4_F0F }, 0x0F, 0x0F,
new[] { Rgb4_400, Rgb4_800, Rgb4_C00, Rgb4_48C }, 0x00, 0xFF,
new[] { Rgb4_000, Rgb4_444, Rgb4_888, Rgb4_CCC }}; 0x00, 0x0C,
0x04, 0x8C
private static byte[] Rgb4_Bytes3x4_R = new byte[] { 0x0F, 0x00, };
0xF0, 0x00,
0x48, 0xC0, private static byte[][] rgb4_Bytes4x4 = { rgb4_Bytes4x4_R, rgb4_Bytes4x4_G, rgb4_Bytes4x4_B };
0x04, 0x80 };
private static Rgba32[][] rgb4_Result4x4 =
private static byte[] Rgb4_Bytes3x4_G = new byte[] { 0x0F, 0x00, {
0x0F, 0x00, new[] { rgb4_000, rgb4_FFF, rgb4_000, rgb4_FFF },
0x00, 0x00, new[] { rgb4_F00, rgb4_0F0, rgb4_00F, rgb4_F0F },
0x04, 0x80 }; new[] { rgb4_400, rgb4_800, rgb4_C00, rgb4_48C },
new[] { rgb4_000, rgb4_444, rgb4_888, rgb4_CCC }
private static byte[] Rgb4_Bytes3x4_B = new byte[] { 0x0F, 0x00, };
0x00, 0xF0,
0x00, 0x00, private static byte[] rgb4_Bytes3x4_R =
0x04, 0x80 }; {
0x0F, 0x00,
private static byte[][] Rgb4_Bytes3x4 = new[] { Rgb4_Bytes3x4_R, Rgb4_Bytes3x4_G, Rgb4_Bytes3x4_B }; 0xF0, 0x00,
0x48, 0xC0,
private static Rgba32[][] Rgb4_Result3x4 = new[] { new[] { Rgb4_000, Rgb4_FFF, Rgb4_000 }, 0x04, 0x80
new[] { Rgb4_F00, Rgb4_0F0, Rgb4_00F }, };
new[] { Rgb4_400, Rgb4_800, Rgb4_C00 },
new[] { Rgb4_000, Rgb4_444, Rgb4_888 }}; private static byte[] rgb4_Bytes3x4_G =
{
0x0F, 0x00,
0x0F, 0x00,
0x00, 0x00,
0x04, 0x80
};
private static byte[] rgb4_Bytes3x4_B =
{
0x0F, 0x00,
0x00, 0xF0,
0x00, 0x00,
0x04, 0x80
};
private static byte[][] rgb4_Bytes3x4 = { rgb4_Bytes3x4_R, rgb4_Bytes3x4_G, rgb4_Bytes3x4_B };
private static Rgba32[][] rgb4_Result3x4 =
{
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<object[]> Rgb4_Data public static IEnumerable<object[]> Rgb4_Data
{ {
get 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, 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 }, 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 }, 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 }, 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_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, 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 }, 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 }, 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 }, 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[] { rgb4_Bytes3x4, new ushort[] { 4, 4, 4 }, 1, 1, 3, 4, Offset(rgb4_Result3x4, 1, 1, 6, 6) };
} }
} }
private static Rgba32 Rgb8_000 = new Rgba32(0, 0, 0, 255); 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_444 = new Rgba32(64, 64, 64, 255);
private static Rgba32 Rgb8_888 = new Rgba32(128, 128, 128, 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_CCC = new Rgba32(192, 192, 192, 255);
private static Rgba32 Rgb8_FFF = new Rgba32(255, 255, 255, 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_F00 = new Rgba32(255, 0, 0, 255);
private static Rgba32 Rgb8_0F0 = new Rgba32(0, 255, 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_00F = new Rgba32(0, 0, 255, 255);
private static Rgba32 Rgb8_F0F = new Rgba32(255, 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_400 = new Rgba32(64, 0, 0, 255);
private static Rgba32 Rgb8_800 = new Rgba32(128, 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_C00 = new Rgba32(192, 0, 0, 255);
private static Rgba32 Rgb8_48C = new Rgba32(64, 128, 192, 255); private static Rgba32 rgb8_48C = new Rgba32(64, 128, 192, 255);
private static byte[] Rgb8_Bytes4x4_R = new byte[] { 000, 255, 000, 255, private static byte[] rgb8_Bytes4x4_R =
255, 000, 000, 255, {
064, 128, 192, 064, 000, 255, 000, 255,
000, 064, 128, 192 }; 255, 000, 000, 255,
064, 128, 192, 064,
private static byte[] Rgb8_Bytes4x4_G = new byte[] { 000, 255, 000, 255, 000, 064, 128, 192
000, 255, 000, 000, };
000, 000, 000, 128,
000, 064, 128, 192 }; private static byte[] rgb8_Bytes4x4_G =
{
private static byte[] Rgb8_Bytes4x4_B = new byte[] { 000, 255, 000, 255, 000, 255, 000, 255,
000, 000, 255, 255, 000, 255, 000, 000,
000, 000, 000, 192, 000, 000, 000, 128,
000, 064, 128, 192 }; 000, 064, 128, 192
};
private static byte[][] Rgb8_Bytes4x4 = new[] { Rgb8_Bytes4x4_R, Rgb8_Bytes4x4_G, Rgb8_Bytes4x4_B };
private static byte[] rgb8_Bytes4x4_B =
private static Rgba32[][] Rgb8_Result4x4 = new[] { new[] { Rgb8_000, Rgb8_FFF, Rgb8_000, Rgb8_FFF }, {
new[] { Rgb8_F00, Rgb8_0F0, Rgb8_00F, Rgb8_F0F }, 000, 255, 000, 255,
new[] { Rgb8_400, Rgb8_800, Rgb8_C00, Rgb8_48C }, 000, 000, 255, 255,
new[] { Rgb8_000, Rgb8_444, Rgb8_888, Rgb8_CCC }}; 000, 000, 000, 192,
000, 064, 128, 192
};
private static byte[][] rgb8_Bytes4x4 =
{
rgb8_Bytes4x4_R, rgb8_Bytes4x4_G, rgb8_Bytes4x4_B
};
private static Rgba32[][] rgb8_Result4x4 =
{
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<object[]> Rgb8_Data public static IEnumerable<object[]> Rgb8_Data
{ {
get 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, 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 }, 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 }, 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 }, 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[] { rgb8_Bytes4x4, new ushort[] { 8, 8, 8 }, 1, 1, 4, 4, Offset(rgb8_Result4x4, 1, 1, 6, 6) };
} }
} }
private static Rgba32 Rgb484_000 = new Rgba32(0, 0, 0, 255); 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_444 = new Rgba32(68, 64, 68, 255);
private static Rgba32 Rgb484_888 = new Rgba32(136, 128, 136, 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_CCC = new Rgba32(204, 192, 204, 255);
private static Rgba32 Rgb484_FFF = new Rgba32(255, 255, 255, 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_F00 = new Rgba32(255, 0, 0, 255);
private static Rgba32 Rgb484_0F0 = new Rgba32(0, 255, 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_00F = new Rgba32(0, 0, 255, 255);
private static Rgba32 Rgb484_F0F = new Rgba32(255, 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_400 = new Rgba32(68, 0, 0, 255);
private static Rgba32 Rgb484_800 = new Rgba32(136, 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_C00 = new Rgba32(204, 0, 0, 255);
private static Rgba32 Rgb484_48C = new Rgba32(68, 128, 204, 255); private static Rgba32 rgb484_48C = new Rgba32(68, 128, 204, 255);
private static byte[] Rgb484_Bytes4x4_R = new byte[] { 0x0F, 0x0F, private static byte[] rgb484_Bytes4x4_R =
0xF0, 0x0F, {
0x48, 0xC4, 0x0F, 0x0F,
0x04, 0x8C }; 0xF0, 0x0F,
0x48, 0xC4,
private static byte[] Rgb484_Bytes4x4_G = new byte[] { 0x00, 0xFF, 0x00, 0xFF, 0x04, 0x8C
0x00, 0xFF, 0x00, 0x00, };
0x00, 0x00, 0x00, 0x80,
0x00, 0x40, 0x80, 0xC0 }; private static byte[] rgb484_Bytes4x4_G =
{
private static byte[] Rgb484_Bytes4x4_B = new byte[] { 0x0F, 0x0F, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00,
0x00, 0x0C, 0x00, 0x00, 0x00, 0x80,
0x04, 0x8C }; 0x00, 0x40, 0x80, 0xC0
};
private static Rgba32[][] Rgb484_Result4x4 = new[] { new[] { Rgb484_000, Rgb484_FFF, Rgb484_000, Rgb484_FFF },
new[] { Rgb484_F00, Rgb484_0F0, Rgb484_00F, Rgb484_F0F }, private static byte[] rgb484_Bytes4x4_B =
new[] { Rgb484_400, Rgb484_800, Rgb484_C00, Rgb484_48C }, {
new[] { Rgb484_000, Rgb484_444, Rgb484_888, Rgb484_CCC }}; 0x0F, 0x0F,
0x00, 0xFF,
private static byte[][] Rgb484_Bytes4x4 = new[] { Rgb484_Bytes4x4_R, Rgb484_Bytes4x4_G, Rgb484_Bytes4x4_B }; 0x00, 0x0C,
0x04, 0x8C
};
private static Rgba32[][] rgb484_Result4x4 =
{
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 };
public static IEnumerable<object[]> Rgb484_Data public static IEnumerable<object[]> Rgb484_Data
{ {
get 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, 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 }, 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 }, 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 }, 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[] { rgb484_Bytes4x4, new ushort[] { 4, 8, 4 }, 1, 1, 4, 4, Offset(rgb484_Result4x4, 1, 1, 6, 6) };
} }
} }

228
tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbTiffColorTests.cs

@ -2,135 +2,161 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Collections.Generic; using System.Collections.Generic;
using SixLabors.ImageSharp.Formats.Tiff; using SixLabors.ImageSharp.Formats.Tiff;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation
{ {
public class RgbTiffColorTests : PhotometricInterpretationTestBase public class RgbTiffColorTests : PhotometricInterpretationTestBase
{ {
private static Rgba32 Rgb4_000 = new Rgba32(0, 0, 0, 255); 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_444 = new Rgba32(68, 68, 68, 255);
private static Rgba32 Rgb4_888 = new Rgba32(136, 136, 136, 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_CCC = new Rgba32(204, 204, 204, 255);
private static Rgba32 Rgb4_FFF = new Rgba32(255, 255, 255, 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_F00 = new Rgba32(255, 0, 0, 255);
private static Rgba32 Rgb4_0F0 = new Rgba32(0, 255, 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_00F = new Rgba32(0, 0, 255, 255);
private static Rgba32 Rgb4_F0F = new Rgba32(255, 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_400 = new Rgba32(68, 0, 0, 255);
private static Rgba32 Rgb4_800 = new Rgba32(136, 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_C00 = new Rgba32(204, 0, 0, 255);
private static Rgba32 Rgb4_48C = new Rgba32(68, 136, 204, 255); private static Rgba32 rgb4_48C = new Rgba32(68, 136, 204, 255);
private static byte[] Rgb4_Bytes4x4 = new byte[] { 0x00, 0x0F, 0xFF, 0x00, 0x0F, 0xFF, private static byte[] rgb4_Bytes4x4 =
0xF0, 0x00, 0xF0, 0x00, 0xFF, 0x0F, {
0x40, 0x08, 0x00, 0xC0, 0x04, 0x8C, 0x00, 0x0F, 0xFF, 0x00, 0x0F, 0xFF,
0x00, 0x04, 0x44, 0x88, 0x8C, 0xCC }; 0xF0, 0x00, 0xF0, 0x00, 0xFF, 0x0F,
0x40, 0x08, 0x00, 0xC0, 0x04, 0x8C,
private static Rgba32[][] Rgb4_Result4x4 = new[] { new[] { Rgb4_000, Rgb4_FFF, Rgb4_000, Rgb4_FFF }, 0x00, 0x04, 0x44, 0x88, 0x8C, 0xCC
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 Rgba32[][] rgb4_Result4x4 =
{
private static byte[] Rgb4_Bytes3x4 = new byte[] { 0x00, 0x0F, 0xFF, 0x00, 0x00, new[] { rgb4_000, rgb4_FFF, rgb4_000, rgb4_FFF },
0xF0, 0x00, 0xF0, 0x00, 0xF0, new[] { rgb4_F00, rgb4_0F0, rgb4_00F, rgb4_F0F },
0x40, 0x08, 0x00, 0xC0, 0x00, new[] { rgb4_400, rgb4_800, rgb4_C00, rgb4_48C },
0x00, 0x04, 0x44, 0x88, 0x80 }; new[] { rgb4_000, rgb4_444, rgb4_888, rgb4_CCC }
};
private static Rgba32[][] Rgb4_Result3x4 = new[] { new[] { Rgb4_000, Rgb4_FFF, Rgb4_000 },
new[] { Rgb4_F00, Rgb4_0F0, Rgb4_00F }, private static byte[] rgb4_Bytes3x4 =
new[] { Rgb4_400, Rgb4_800, Rgb4_C00 }, {
new[] { Rgb4_000, Rgb4_444, Rgb4_888 }}; 0x00, 0x0F, 0xFF, 0x00, 0x00,
0xF0, 0x00, 0xF0, 0x00, 0xF0,
0x40, 0x08, 0x00, 0xC0, 0x00,
0x00, 0x04, 0x44, 0x88, 0x80
};
private static Rgba32[][] rgb4_Result3x4 =
{
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<object[]> Rgb4_Data public static IEnumerable<object[]> Rgb4_Data
{ {
get 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, 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 }, 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 }, 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 }, 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_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, 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 }, 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 }, 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 }, 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[] { rgb4_Bytes3x4, new ushort[] { 4, 4, 4 }, 1, 1, 3, 4, Offset(rgb4_Result3x4, 1, 1, 6, 6) };
} }
} }
private static Rgba32 Rgb8_000 = new Rgba32(0, 0, 0, 255); 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_444 = new Rgba32(64, 64, 64, 255);
private static Rgba32 Rgb8_888 = new Rgba32(128, 128, 128, 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_CCC = new Rgba32(192, 192, 192, 255);
private static Rgba32 Rgb8_FFF = new Rgba32(255, 255, 255, 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_F00 = new Rgba32(255, 0, 0, 255);
private static Rgba32 Rgb8_0F0 = new Rgba32(0, 255, 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_00F = new Rgba32(0, 0, 255, 255);
private static Rgba32 Rgb8_F0F = new Rgba32(255, 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_400 = new Rgba32(64, 0, 0, 255);
private static Rgba32 Rgb8_800 = new Rgba32(128, 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_C00 = new Rgba32(192, 0, 0, 255);
private static Rgba32 Rgb8_48C = new Rgba32(64, 128, 192, 255); private static Rgba32 rgb8_48C = new Rgba32(64, 128, 192, 255);
private static byte[] Rgb8_Bytes4x4 = new byte[] { 000, 000, 000, 255, 255, 255, 000, 000, 000, 255, 255, 255, private static byte[] rgb8_Bytes4x4 =
255, 000, 000, 000, 255, 000, 000, 000, 255, 255, 000, 255, {
064, 000, 000, 128, 000, 000, 192, 000, 000, 064, 128, 192, 000, 000, 000, 255, 255, 255, 000, 000, 000, 255, 255, 255,
000, 000, 000, 064, 064, 064, 128, 128, 128, 192, 192, 192 }; 255, 000, 000, 000, 255, 000, 000, 000, 255, 255, 000, 255,
064, 000, 000, 128, 000, 000, 192, 000, 000, 064, 128, 192,
private static Rgba32[][] Rgb8_Result4x4 = new[] { new[] { Rgb8_000, Rgb8_FFF, Rgb8_000, Rgb8_FFF }, 000, 000, 000, 064, 064, 064, 128, 128, 128, 192, 192, 192
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 }}; private static Rgba32[][] rgb8_Result4x4 =
{
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<object[]> Rgb8_Data public static IEnumerable<object[]> Rgb8_Data
{ {
get 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, 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 }, 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 }, 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 }, 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[] { rgb8_Bytes4x4, new ushort[] { 8, 8, 8 }, 1, 1, 4, 4, Offset(rgb8_Result4x4, 1, 1, 6, 6) };
} }
} }
private static Rgba32 Rgb484_000 = new Rgba32(0, 0, 0, 255); 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_444 = new Rgba32(68, 64, 68, 255);
private static Rgba32 Rgb484_888 = new Rgba32(136, 128, 136, 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_CCC = new Rgba32(204, 192, 204, 255);
private static Rgba32 Rgb484_FFF = new Rgba32(255, 255, 255, 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_F00 = new Rgba32(255, 0, 0, 255);
private static Rgba32 Rgb484_0F0 = new Rgba32(0, 255, 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_00F = new Rgba32(0, 0, 255, 255);
private static Rgba32 Rgb484_F0F = new Rgba32(255, 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_400 = new Rgba32(68, 0, 0, 255);
private static Rgba32 Rgb484_800 = new Rgba32(136, 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_C00 = new Rgba32(204, 0, 0, 255);
private static Rgba32 Rgb484_48C = new Rgba32(68, 128, 204, 255); private static Rgba32 rgb484_48C = new Rgba32(68, 128, 204, 255);
private static byte[] Rgb484_Bytes4x4 = new byte[] { 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, private static byte[] rgb484_Bytes4x4 =
0xF0, 0x00, 0x0F, 0xF0, 0x00, 0x0F, 0xF0, 0x0F, {
0x40, 0x00, 0x80, 0x00, 0xC0, 0x00, 0x48, 0x0C, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF,
0x00, 0x00, 0x44, 0x04, 0x88, 0x08, 0xCC, 0x0C }; 0xF0, 0x00, 0x0F, 0xF0, 0x00, 0x0F, 0xF0, 0x0F,
0x40, 0x00, 0x80, 0x00, 0xC0, 0x00, 0x48, 0x0C,
private static Rgba32[][] Rgb484_Result4x4 = new[] { new[] { Rgb484_000, Rgb484_FFF, Rgb484_000, Rgb484_FFF }, 0x00, 0x00, 0x44, 0x04, 0x88, 0x08, 0xCC, 0x0C
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 Rgba32[][] rgb484_Result4x4 =
{
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<object[]> Rgb484_Data public static IEnumerable<object[]> Rgb484_Data
{ {
get 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, 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 }, 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 }, 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 }, 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[] { rgb484_Bytes4x4, new ushort[] { 4, 8, 4 }, 1, 1, 4, 4, Offset(rgb484_Result4x4, 1, 1, 6, 6) };
} }
} }

150
tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/WhiteIsZeroTiffColorTests.cs

@ -2,72 +2,104 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Collections.Generic; using System.Collections.Generic;
using SixLabors.ImageSharp.Formats.Tiff; using SixLabors.ImageSharp.Formats.Tiff;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation
{ {
public class WhiteIsZeroTiffColorTests : PhotometricInterpretationTestBase public class WhiteIsZeroTiffColorTests : PhotometricInterpretationTestBase
{ {
private static Rgba32 Gray000 = new Rgba32(255, 255, 255, 255); private static Rgba32 gray000 = new Rgba32(255, 255, 255, 255);
private static Rgba32 Gray128 = new Rgba32(127, 127, 127, 255); private static Rgba32 gray128 = new Rgba32(127, 127, 127, 255);
private static Rgba32 Gray255 = new Rgba32(0, 0, 0, 255); private static Rgba32 gray255 = new Rgba32(0, 0, 0, 255);
private static Rgba32 Gray0 = new Rgba32(255, 255, 255, 255); private static Rgba32 gray0 = new Rgba32(255, 255, 255, 255);
private static Rgba32 Gray8 = new Rgba32(119, 119, 119, 255); private static Rgba32 gray8 = new Rgba32(119, 119, 119, 255);
private static Rgba32 GrayF = new Rgba32(0, 0, 0, 255); private static Rgba32 grayF = new Rgba32(0, 0, 0, 255);
private static Rgba32 Bit0 = new Rgba32(255, 255, 255, 255); private static Rgba32 bit0 = new Rgba32(255, 255, 255, 255);
private static Rgba32 Bit1 = new Rgba32(0, 0, 0, 255); private static Rgba32 bit1 = new Rgba32(0, 0, 0, 255);
private static readonly byte[] Bilevel_Bytes4x4 = new byte[] { 0b01010000, private static readonly byte[] Bilevel_Bytes4x4 =
0b11110000, {
0b01110000, 0b01010000,
0b10010000 }; 0b11110000,
0b01110000,
private static readonly Rgba32[][] Bilevel_Result4x4 = new[] { new[] { Bit0, Bit1, Bit0, Bit1 }, 0b10010000
new[] { Bit1, Bit1, Bit1, Bit1 }, };
new[] { Bit0, Bit1, Bit1, Bit1 },
new[] { Bit1, Bit0, Bit0, Bit1 }}; private static readonly Rgba32[][] Bilevel_Result4x4 =
{
private static readonly byte[] Bilevel_Bytes12x4 = new byte[] { 0b01010101, 0b01010000, new[] { bit0, bit1, bit0, bit1 },
0b11111111, 0b11111111, new[] { bit1, bit1, bit1, bit1 },
0b01101001, 0b10100000, new[] { bit0, bit1, bit1, bit1 },
0b10010000, 0b01100000}; new[] { bit1, bit0, bit0, bit1 }
};
private static readonly Rgba32[][] Bilevel_Result12x4 = new[] { 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 }, private static readonly byte[] Bilevel_Bytes12x4 =
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 }}; 0b01010101, 0b01010000,
0b11111111, 0b11111111,
private static readonly byte[] Grayscale4_Bytes4x4 = new byte[] { 0x8F, 0x0F, 0b01101001, 0b10100000,
0xFF, 0xFF, 0b10010000, 0b01100000
0x08, 0x8F, };
0xF0, 0xF8 };
private static readonly Rgba32[][] Bilevel_Result12x4 =
private static readonly Rgba32[][] Grayscale4_Result4x4 = new[] { new[] { Gray8, GrayF, Gray0, GrayF }, {
new[] { GrayF, GrayF, GrayF, GrayF }, new[] { bit0, bit1, bit0, bit1, bit0, bit1, bit0, bit1, bit0, bit1, bit0, bit1 },
new[] { Gray0, Gray8, Gray8, GrayF }, new[] { bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1, bit1 },
new[] { GrayF, Gray0, GrayF, Gray8 }}; 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_Bytes3x4 = new byte[] { 0x8F, 0x00, };
0xFF, 0xF0,
0x08, 0x80, private static readonly byte[] Grayscale4_Bytes4x4 =
0xF0, 0xF0 }; {
0x8F, 0x0F,
private static readonly Rgba32[][] Grayscale4_Result3x4 = new[] { new[] { Gray8, GrayF, Gray0 }, 0xFF, 0xFF,
new[] { GrayF, GrayF, GrayF }, 0x08, 0x8F,
new[] { Gray0, Gray8, Gray8 }, 0xF0, 0xF8
new[] { GrayF, Gray0, GrayF }}; };
private static readonly byte[] Grayscale8_Bytes4x4 = new byte[] { 128, 255, 000, 255, private static readonly Rgba32[][] Grayscale4_Result4x4 =
255, 255, 255, 255, {
000, 128, 128, 255, new[] { gray8, grayF, gray0, grayF },
255, 000, 255, 128 }; new[] { grayF, grayF, grayF, grayF },
new[] { gray0, gray8, gray8, grayF },
private static readonly Rgba32[][] Grayscale8_Result4x4 = new[] { new[] { Gray128, Gray255, Gray000, Gray255 }, new[] { grayF, gray0, grayF, gray8 }
new[] { Gray255, Gray255, Gray255, Gray255 }, };
new[] { Gray000, Gray128, Gray128, Gray255 },
new[] { Gray255, Gray000, Gray255, Gray128 }}; private static readonly byte[] Grayscale4_Bytes3x4 =
{
0x8F, 0x00,
0xFF, 0xF0,
0x08, 0x80,
0xF0, 0xF0
};
private static readonly Rgba32[][] Grayscale4_Result3x4 =
{
new[] { gray8, grayF, gray0 },
new[] { grayF, grayF, grayF },
new[] { gray0, gray8, gray8 },
new[] { grayF, gray0, grayF }
};
private static readonly byte[] Grayscale8_Bytes4x4 =
{
128, 255, 000, 255,
255, 255, 255, 255,
000, 128, 128, 255,
255, 000, 255, 128
};
private static readonly Rgba32[][] Grayscale8_Result4x4 =
{
new[] { gray128, gray255, gray000, gray255 },
new[] { gray255, gray255, gray255, gray255 },
new[] { gray000, gray128, gray128, gray255 },
new[] { gray255, gray000, gray255, gray128 }
};
public static IEnumerable<object[]> Bilevel_Data public static IEnumerable<object[]> Bilevel_Data
{ {

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

@ -70,18 +70,18 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
Assert.Equal(TiffPlanarConfiguration.Chunky, frame.PlanarConfiguration); Assert.Equal(TiffPlanarConfiguration.Chunky, frame.PlanarConfiguration);
Assert.Equal(TiffResolutionUnit.Inch, frame.ResolutionUnit); Assert.Equal(TiffResolutionUnit.Inch, frame.ResolutionUnit);
Assert.Equal("IrfanView", frame.Software); Assert.Equal("IrfanView", frame.Software);
Assert.Equal(null, frame.DateTime); Assert.Null(frame.DateTime);
Assert.Equal("This is author1;Author2", frame.Artist); Assert.Equal("This is author1;Author2", frame.Artist);
Assert.Equal(null, frame.HostComputer); Assert.Null(frame.HostComputer);
Assert.Equal(48, frame.ColorMap.Length); Assert.Equal(48, frame.ColorMap.Length);
Assert.Equal(10537, frame.ColorMap[0]); Assert.Equal(10537, frame.ColorMap[0]);
Assert.Equal(14392, frame.ColorMap[1]); Assert.Equal(14392, frame.ColorMap[1]);
Assert.Equal(58596, frame.ColorMap[46]); Assert.Equal(58596, frame.ColorMap[46]);
Assert.Equal(3855, frame.ColorMap[47]); Assert.Equal(3855, frame.ColorMap[47]);
Assert.Equal(null, frame.ExtraSamples); Assert.Null(frame.ExtraSamples);
Assert.Equal(TiffPredictor.None, frame.Predictor); Assert.Equal(TiffPredictor.None, frame.Predictor);
Assert.Equal(null, frame.SampleFormat); Assert.Null(frame.SampleFormat);
Assert.Equal("This is Авторские права", frame.Copyright); Assert.Equal("This is Авторские права", frame.Copyright);
} }
} }
@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
TiffFrameMetadata frame0 = image.Frames[0].Metadata.GetTiffMetadata(); TiffFrameMetadata frame0 = image.Frames[0].Metadata.GetTiffMetadata();
Assert.Equal(TiffNewSubfileType.FullImage, frame0.NewSubfileType); Assert.Equal(TiffNewSubfileType.FullImage, frame0.NewSubfileType);
Assert.Equal(null, frame0.SubfileType); Assert.Null(frame0.SubfileType);
Assert.Equal(255u, frame0.Width); Assert.Equal(255u, frame0.Width);
Assert.Equal(255u, frame0.Height); Assert.Equal(255u, frame0.Height);

10
tests/ImageSharp.Tests/Formats/Tiff/Utils/TiffWriterTests.cs

@ -8,7 +8,7 @@ using SixLabors.ImageSharp.Memory;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff namespace SixLabors.ImageSharp.Tests.Formats.Tiff.Utils
{ {
[Trait("Category", "Tiff")] [Trait("Category", "Tiff")]
public class TiffWriterTests public class TiffWriterTests
@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
using var writer = new TiffWriter(stream, MemoryAllocator, Configuration); using var writer = new TiffWriter(stream, MemoryAllocator, Configuration);
writer.Write((uint)12345678); writer.Write(12345678U);
Assert.Equal(new byte[] { 0x4E, 0x61, 0xBC, 0x00 }, stream.ToArray()); Assert.Equal(new byte[] { 0x4E, 0x61, 0xBC, 0x00 }, stream.ToArray());
} }
@ -99,13 +99,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
using (var writer = new TiffWriter(stream, MemoryAllocator, Configuration)) using (var writer = new TiffWriter(stream, MemoryAllocator, Configuration))
{ {
writer.Write((uint)0x11111111); writer.Write(0x11111111);
long marker = writer.PlaceMarker(); long marker = writer.PlaceMarker();
writer.Write((uint)0x33333333); writer.Write(0x33333333);
writer.WriteMarker(marker, 0x12345678); writer.WriteMarker(marker, 0x12345678);
writer.Write((uint)0x44444444); writer.Write(0x44444444);
} }
Assert.Equal( Assert.Equal(

8
tests/ImageSharp.Tests/TestUtilities/ByteArrayUtility.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests.TestUtilities
{ {
using System; using System;
@ -9,9 +9,9 @@ namespace SixLabors.ImageSharp.Tests
{ {
public static byte[] WithByteOrder(this byte[] bytes, bool isLittleEndian) public static byte[] WithByteOrder(this byte[] bytes, bool isLittleEndian)
{ {
if (BitConverter.IsLittleEndian != isLittleEndian) if (isLittleEndian != BitConverter.IsLittleEndian)
{ {
byte[] reversedBytes = new byte[bytes.Length]; var reversedBytes = new byte[bytes.Length];
Array.Copy(bytes, reversedBytes, bytes.Length); Array.Copy(bytes, reversedBytes, bytes.Length);
Array.Reverse(reversedBytes); Array.Reverse(reversedBytes);
return reversedBytes; return reversedBytes;
@ -22,4 +22,4 @@ namespace SixLabors.ImageSharp.Tests
} }
} }
} }
} }

16
tests/ImageSharp.Tests/TestUtilities/ByteBuffer.cs

@ -1,15 +1,15 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests.TestUtilities
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
public class ByteBuffer public class ByteBuffer
{ {
List<byte> bytes = new List<byte>(); private readonly List<byte> bytes = new List<byte>();
bool isLittleEndian; private readonly bool isLittleEndian;
public ByteBuffer(bool isLittleEndian) public ByteBuffer(bool isLittleEndian)
{ {
@ -18,22 +18,22 @@ namespace SixLabors.ImageSharp.Tests
public void AddByte(byte value) public void AddByte(byte value)
{ {
bytes.Add(value); this.bytes.Add(value);
} }
public void AddUInt16(ushort value) public void AddUInt16(ushort value)
{ {
bytes.AddRange(BitConverter.GetBytes(value).WithByteOrder(isLittleEndian)); this.bytes.AddRange(BitConverter.GetBytes(value).WithByteOrder(this.isLittleEndian));
} }
public void AddUInt32(uint value) public void AddUInt32(uint value)
{ {
bytes.AddRange(BitConverter.GetBytes(value).WithByteOrder(isLittleEndian)); this.bytes.AddRange(BitConverter.GetBytes(value).WithByteOrder(this.isLittleEndian));
} }
public byte[] ToArray() public byte[] ToArray()
{ {
return bytes.ToArray(); return this.bytes.ToArray();
} }
} }
} }

3
tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs

@ -57,8 +57,7 @@ namespace SixLabors.ImageSharp.Tests
new JpegConfigurationModule(), new JpegConfigurationModule(),
new GifConfigurationModule(), new GifConfigurationModule(),
new TgaConfigurationModule(), new TgaConfigurationModule(),
new TiffConfigurationModule() new TiffConfigurationModule());
);
// Magick codecs should work on all platforms // Magick codecs should work on all platforms
IImageEncoder pngEncoder = IsWindows ? (IImageEncoder)SystemDrawingReferenceEncoder.Png : new PngEncoder(); IImageEncoder pngEncoder = IsWindows ? (IImageEncoder)SystemDrawingReferenceEncoder.Png : new PngEncoder();

Loading…
Cancel
Save