Browse Source

Merge pull request #2957 from stefannikolei/sn/ref/collection_expressions

Convert CodeBase to collection Expressions
pull/2972/head
James Jackson-South 10 months ago
committed by GitHub
parent
commit
08432174cf
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      .editorconfig
  2. 2
      shared-infrastructure
  3. 6
      src/ImageSharp/Color/Color.WebSafePalette.cs
  4. 6
      src/ImageSharp/Color/Color.WernerPalette.cs
  5. 8
      src/ImageSharp/Common/Helpers/HexConverter.cs
  6. 2
      src/ImageSharp/Common/InlineArray.cs
  7. 2
      src/ImageSharp/Common/InlineArray.tt
  8. 6
      src/ImageSharp/Compression/Zlib/Adler32.cs
  9. 10
      src/ImageSharp/Compression/Zlib/DeflaterConstants.cs
  10. 36
      src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs
  11. 8
      src/ImageSharp/Formats/Bmp/BmpConstants.cs
  12. 22
      src/ImageSharp/Formats/Gif/GifConstants.cs
  13. 4
      src/ImageSharp/Formats/Gif/LzwEncoder.cs
  14. 2
      src/ImageSharp/Formats/Gif/Sections/GifXmpApplicationExtension.cs
  15. 54
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs
  16. 40
      src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs
  17. 8
      src/ImageSharp/Formats/Jpeg/Components/FloatingPointDCT.cs
  18. 16
      src/ImageSharp/Formats/Jpeg/Components/Quantization.cs
  19. 12
      src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs
  20. 4
      src/ImageSharp/Formats/Jpeg/JpegConstants.cs
  21. 4
      src/ImageSharp/Formats/Pbm/PbmConstants.cs
  22. 8
      src/ImageSharp/Formats/Png/Adam7.cs
  23. 26
      src/ImageSharp/Formats/Png/PngConstants.cs
  24. 4
      src/ImageSharp/Formats/Qoi/QoiConstants.cs
  25. 4
      src/ImageSharp/Formats/Tga/TgaConstants.cs
  26. 4
      src/ImageSharp/Formats/Tiff/Compression/Compressors/T6BitCompressor.cs
  27. 4
      src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffCcittCompressor.cs
  28. 2
      src/ImageSharp/Formats/Tiff/Ifd/DirectoryReader.cs
  29. 8
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/YCbCrConverter.cs
  30. 2
      src/ImageSharp/Formats/Tiff/TiffEncoderEntriesCollector.cs
  31. 2
      src/ImageSharp/Formats/Tiff/Writers/TiffStreamWriter.cs
  32. 4
      src/ImageSharp/Formats/Webp/BitReader/Vp8LBitReader.cs
  33. 4
      src/ImageSharp/Formats/Webp/Lossless/HuffmanUtils.cs
  34. 12
      src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs
  35. 9
      src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs
  36. 4
      src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs
  37. 4
      src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs
  38. 2
      src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs
  39. 7
      src/ImageSharp/Formats/Webp/Lossy/Vp8Encoding.cs
  40. 14
      src/ImageSharp/Formats/Webp/Lossy/Vp8Matrix.cs
  41. 52
      src/ImageSharp/Formats/Webp/WebpConstants.cs
  42. 558
      src/ImageSharp/Formats/Webp/WebpLookupTables.cs
  43. 12
      src/ImageSharp/Formats/_Generated/_Formats.ttinclude
  44. 2
      src/ImageSharp/IO/ChunkedMemoryStream.cs
  45. 2
      src/ImageSharp/ImageExtensions.cs
  46. 2
      src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs
  47. 4
      src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs
  48. 14
      src/ImageSharp/Metadata/Profiles/Exif/ExifConstants.cs
  49. 2
      src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs
  50. 2
      src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs
  51. 2
      src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs
  52. 2
      src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs
  53. 48
      src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs
  54. 10
      src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs
  55. 6
      src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs
  56. 4
      src/ImageSharp/Metadata/Profiles/IPTC/IptcValue.cs
  57. 20
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude
  58. 7
      src/ImageSharp/Processing/Processors/Convolution/Kernels/EdgeDetectorCompassKernel.cs
  59. 36
      src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs
  60. 8
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs
  61. 3
      tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs
  62. 2
      tests/ImageSharp.Benchmarks/Codecs/Bmp/EncodeBmpMultiple.cs
  63. 2
      tests/ImageSharp.Benchmarks/Codecs/Gif/EncodeGifMultiple.cs
  64. 2
      tests/ImageSharp.Benchmarks/General/BasicMath/ClampFloat.cs
  65. 2
      tests/ImageSharp.Benchmarks/General/BasicMath/ClampVector4.cs
  66. 4
      tests/ImageSharp.Benchmarks/LoadResizeSave/LoadResizeSaveStressBenchmarks.cs
  67. 6
      tests/ImageSharp.Benchmarks/LoadResizeSave/LoadResizeSaveStressRunner.cs
  68. 2
      tests/ImageSharp.Tests.ProfilingSandbox/Program.cs
  69. 8
      tests/ImageSharp.Tests/Color/ReferencePalette.cs
  70. 17
      tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs
  71. 4
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  72. 2
      tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs
  73. 6
      tests/ImageSharp.Tests/Formats/Jpg/AdobeMarkerTests.cs
  74. 8
      tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs
  75. 20
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs
  76. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Internal.cs
  77. 6
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  78. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs
  79. 14
      tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs
  80. 4
      tests/ImageSharp.Tests/Formats/Jpg/SpectralToPixelConversionTests.cs
  81. 2
      tests/ImageSharp.Tests/Formats/Png/Adler32Tests.cs
  82. 44
      tests/ImageSharp.Tests/Formats/Png/PngDecoderFilterTests.cs
  83. 20
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs
  84. 24
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  85. 18
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.Chunks.cs
  86. 12
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  87. 134
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs
  88. 58
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PaletteTiffColorTests.cs
  89. 152
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbPlanarTiffColorTests.cs
  90. 110
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbTiffColorTests.cs
  91. 134
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/WhiteIsZeroTiffColorTests.cs
  92. 4
      tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs
  93. 16
      tests/ImageSharp.Tests/Formats/WebP/ColorSpaceTransformUtilsTests.cs
  94. 61
      tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs
  95. 43
      tests/ImageSharp.Tests/Formats/WebP/LossyUtilsTests.cs
  96. 8
      tests/ImageSharp.Tests/Formats/WebP/PredictorEncoderTests.cs
  97. 13
      tests/ImageSharp.Tests/Formats/WebP/QuantEncTests.cs
  98. 42
      tests/ImageSharp.Tests/Formats/WebP/Vp8EncodingTests.cs
  99. 8
      tests/ImageSharp.Tests/Formats/WebP/Vp8LHistogramTests.cs
  100. 2
      tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs

5
.editorconfig

@ -177,6 +177,11 @@ csharp_using_directive_placement = outside_namespace:warning
csharp_prefer_static_local_function = true:warning
# Primary constructor preferences
csharp_style_prefer_primary_constructors = false:none
# Collection preferences
dotnet_style_prefer_collection_expression = true:error
resharper_use_collection_expression_highlighting =true:error
##########################################
# Unnecessary Code Rules

2
shared-infrastructure

@ -1 +1 @@
Subproject commit 132a8232bd61471e9e9df727fb7a112800030327
Subproject commit d0f141bad2baf7e256aa38ef18129c31cfb857a5

6
src/ImageSharp/Color/Color.WebSafePalette.cs

@ -15,8 +15,8 @@ public partial struct Color
/// </summary>
public static ReadOnlyMemory<Color> WebSafePalette => WebSafePaletteLazy.Value;
private static Color[] CreateWebSafePalette() => new[]
{
private static Color[] CreateWebSafePalette() =>
[
AliceBlue,
AntiqueWhite,
Aqua,
@ -159,5 +159,5 @@ public partial struct Color
WhiteSmoke,
Yellow,
YellowGreen
};
];
}

6
src/ImageSharp/Color/Color.WernerPalette.cs

@ -16,8 +16,8 @@ public partial struct Color
/// </summary>
public static ReadOnlyMemory<Color> WernerPalette => WernerPaletteLazy.Value;
private static Color[] CreateWernerPalette() => new[]
{
private static Color[] CreateWernerPalette() =>
[
ParseHex("#f1e9cd"),
ParseHex("#f2e7cf"),
ParseHex("#ece6d0"),
@ -128,5 +128,5 @@ public partial struct Color
ParseHex("#9b856b"),
ParseHex("#766051"),
ParseHex("#453b32")
};
];
}

8
src/ImageSharp/Common/Helpers/HexConverter.cs

@ -35,8 +35,8 @@ internal static class HexConverter
{
// Map from an ASCII char to its hex value, e.g. arr['b'] == 11. 0xFF means it's not a hex digit.
// This doesn't actually allocate.
ReadOnlySpan<byte> charToHexLookup = new byte[]
{
ReadOnlySpan<byte> charToHexLookup =
[
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 15
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 31
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 47
@ -52,8 +52,8 @@ internal static class HexConverter
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 207
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 223
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 239
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 255
};
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF // 255
];
return (uint)c >= (uint)charToHexLookup.Length ? 0xFF : charToHexLookup[c];
}

2
src/ImageSharp/Common/InlineArray.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
// <auto-generated />

2
src/ImageSharp/Common/InlineArray.tt

@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp;
<#GenerateInlineArrays();#>
<#+
private static int[] Lengths = new int[] {4, 8, 16 };
private static int[] Lengths = [4, 8, 16 ];
void GenerateInlineArrays()
{

6
src/ImageSharp/Compression/Zlib/Adler32.cs

@ -32,11 +32,11 @@ internal static class Adler32
private const int BlockSize = 1 << 5;
// The C# compiler emits this as a compile-time constant embedded in the PE file.
private static ReadOnlySpan<byte> Tap1Tap2 => new byte[]
{
private static ReadOnlySpan<byte> Tap1Tap2 =>
[
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, // tap1
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 // tap2
};
];
/// <summary>
/// Calculates the Adler32 checksum with the bytes taken from the span.

10
src/ImageSharp/Compression/Zlib/DeflaterConstants.cs

@ -124,25 +124,25 @@ internal static class DeflaterConstants
/// <summary>
/// Internal compression engine constant
/// </summary>
public static int[] GOOD_LENGTH = { 0, 4, 4, 4, 4, 8, 8, 8, 32, 32 };
public static int[] GOOD_LENGTH = [0, 4, 4, 4, 4, 8, 8, 8, 32, 32];
/// <summary>
/// Internal compression engine constant
/// </summary>
public static int[] MAX_LAZY = { 0, 4, 5, 6, 4, 16, 16, 32, 128, 258 };
public static int[] MAX_LAZY = [0, 4, 5, 6, 4, 16, 16, 32, 128, 258];
/// <summary>
/// Internal compression engine constant
/// </summary>
public static int[] NICE_LENGTH = { 0, 8, 16, 32, 16, 32, 128, 128, 258, 258 };
public static int[] NICE_LENGTH = [0, 8, 16, 32, 16, 32, 128, 128, 258, 258];
/// <summary>
/// Internal compression engine constant
/// </summary>
public static int[] MAX_CHAIN = { 0, 4, 8, 32, 16, 32, 128, 256, 1024, 4096 };
public static int[] MAX_CHAIN = [0, 4, 8, 32, 16, 32, 128, 256, 1024, 4096];
/// <summary>
/// Internal compression engine constant
/// </summary>
public static int[] COMPR_FUNC = { 0, 1, 1, 1, 1, 2, 2, 2, 2, 2 };
public static int[] COMPR_FUNC = [0, 1, 1, 1, 1, 2, 2, 2, 2, 2];
}

36
src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs

@ -77,8 +77,8 @@ internal sealed unsafe class DeflaterHuffman : IDisposable
// See RFC 1951 3.2.6
// Literal codes
private static readonly short[] StaticLCodes = new short[]
{
private static readonly short[] StaticLCodes =
[
12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
@ -97,10 +97,10 @@ internal sealed unsafe class DeflaterHuffman : IDisposable
31, 287, 159, 415, 95, 351, 223, 479, 63, 319, 191, 447, 127, 383, 255, 511,
0, 64, 32, 96, 16, 80, 48, 112, 8, 72, 40, 104, 24, 88, 56, 120, 4, 68, 36,
100, 20, 84, 52, 116, 3, 131, 67, 195, 35, 163
};
];
private static ReadOnlySpan<byte> StaticLLength => new byte[]
{
private static ReadOnlySpan<byte> StaticLLength =>
[
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
@ -119,34 +119,34 @@ internal sealed unsafe class DeflaterHuffman : IDisposable
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8
};
];
// Distance codes and lengths.
private static readonly short[] StaticDCodes = new short[]
{
private static readonly short[] StaticDCodes =
[
0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14,
30, 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23
};
];
private static ReadOnlySpan<byte> StaticDLength => new byte[]
{
private static ReadOnlySpan<byte> StaticDLength =>
[
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
};
];
#pragma warning restore SA1201 // Elements should appear in the correct order
/// <summary>
/// Gets the lengths of the bit length codes are sent in order of decreasing probability, to avoid transmitting the lengths for unused bit length codes.
/// </summary>
private static ReadOnlySpan<byte> BitLengthOrder => new byte[]
{
private static ReadOnlySpan<byte> BitLengthOrder =>
[
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
};
];
private static ReadOnlySpan<byte> Bit4Reverse => new byte[]
{
private static ReadOnlySpan<byte> Bit4Reverse =>
[
0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
};
];
/// <summary>
/// Gets the pending buffer to use.

8
src/ImageSharp/Formats/Bmp/BmpConstants.cs

@ -11,17 +11,17 @@ internal static class BmpConstants
/// <summary>
/// The list of mimetypes that equate to a bmp.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[]
{
public static readonly IEnumerable<string> MimeTypes =
[
"image/bmp",
"image/x-windows-bmp",
"image/x-win-bitmap"
};
];
/// <summary>
/// The list of file extensions that equate to a bmp.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "bm", "bmp", "dip" };
public static readonly IEnumerable<string> FileExtensions = ["bm", "bmp", "dip"];
/// <summary>
/// Valid magic bytes markers identifying a Bitmap file.

22
src/ImageSharp/Formats/Gif/GifConstants.cs

@ -93,41 +93,41 @@ internal static class GifConstants
/// <summary>
/// The collection of mimetypes that equate to a Gif.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[] { "image/gif" };
public static readonly IEnumerable<string> MimeTypes = ["image/gif"];
/// <summary>
/// The collection of file extensions that equate to a Gif.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "gif" };
public static readonly IEnumerable<string> FileExtensions = ["gif"];
/// <summary>
/// Gets the ASCII encoded bytes used to identify the GIF file (combining <see cref="FileType"/> and <see cref="FileVersion"/>).
/// </summary>
internal static ReadOnlySpan<byte> MagicNumber => new[]
{
internal static ReadOnlySpan<byte> MagicNumber =>
[
(byte)'G', (byte)'I', (byte)'F',
(byte)'8', (byte)'9', (byte)'a'
};
];
/// <summary>
/// Gets the ASCII encoded application identification bytes (representing <see cref="NetscapeApplicationIdentification"/>).
/// </summary>
internal static ReadOnlySpan<byte> NetscapeApplicationIdentificationBytes => new[]
{
internal static ReadOnlySpan<byte> NetscapeApplicationIdentificationBytes =>
[
(byte)'N', (byte)'E', (byte)'T',
(byte)'S', (byte)'C', (byte)'A',
(byte)'P', (byte)'E',
(byte)'2', (byte)'.', (byte)'0'
};
];
/// <summary>
/// Gets the ASCII encoded application identification bytes.
/// </summary>
internal static ReadOnlySpan<byte> XmpApplicationIdentificationBytes => new[]
{
internal static ReadOnlySpan<byte> XmpApplicationIdentificationBytes =>
[
(byte)'X', (byte)'M', (byte)'P',
(byte)' ', (byte)'D', (byte)'a',
(byte)'t', (byte)'a',
(byte)'X', (byte)'M', (byte)'P'
};
];
}

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

@ -47,7 +47,7 @@ internal sealed class LzwEncoder : IDisposable
/// Mask used when shifting pixel values
/// </summary>
private static readonly int[] Masks =
{
[
0b0,
0b1,
0b11,
@ -65,7 +65,7 @@ internal sealed class LzwEncoder : IDisposable
0b11111111111111,
0b111111111111111,
0b1111111111111111
};
];
/// <summary>
/// The maximum number of bits/code.

2
src/ImageSharp/Formats/Gif/Sections/GifXmpApplicationExtension.cs

@ -34,7 +34,7 @@ internal readonly struct GifXmpApplicationExtension : IGifExtension
// Exclude the "magic trailer", see XMP Specification Part 3, 1.1.2 GIF
int xmpLength = xmpBytes.Length - 256; // 257 - unread 0x0
byte[] buffer = Array.Empty<byte>();
byte[] buffer = [];
if (xmpLength > 0)
{
buffer = new byte[xmpLength];

54
src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs

@ -11,80 +11,80 @@ internal static class ProfileResolver
/// <summary>
/// Gets the JFIF specific markers.
/// </summary>
public static ReadOnlySpan<byte> JFifMarker => new[]
{
public static ReadOnlySpan<byte> JFifMarker =>
[
(byte)'J', (byte)'F', (byte)'I', (byte)'F', (byte)'\0'
};
];
/// <summary>
/// Gets the JFXX specific markers.
/// </summary>
public static ReadOnlySpan<byte> JFxxMarker => new[]
{
public static ReadOnlySpan<byte> JFxxMarker =>
[
(byte)'J', (byte)'F', (byte)'X', (byte)'X', (byte)'\0'
};
];
/// <summary>
/// Gets the ICC specific markers.
/// </summary>
public static ReadOnlySpan<byte> IccMarker => new[]
{
public static ReadOnlySpan<byte> IccMarker =>
[
(byte)'I', (byte)'C', (byte)'C', (byte)'_',
(byte)'P', (byte)'R', (byte)'O', (byte)'F',
(byte)'I', (byte)'L', (byte)'E', (byte)'\0'
};
];
/// <summary>
/// Gets the adobe photoshop APP13 marker which can contain IPTC meta data.
/// </summary>
public static ReadOnlySpan<byte> AdobePhotoshopApp13Marker => new[]
{
public static ReadOnlySpan<byte> AdobePhotoshopApp13Marker =>
[
(byte)'P', (byte)'h', (byte)'o', (byte)'t', (byte)'o', (byte)'s', (byte)'h', (byte)'o', (byte)'p', (byte)' ', (byte)'3', (byte)'.', (byte)'0', (byte)'\0'
};
];
/// <summary>
/// Gets the 8BIM marker, which signals the start of a adobe specific image resource block.
/// </summary>
public static ReadOnlySpan<byte> AdobeImageResourceBlockMarker => new[]
{
public static ReadOnlySpan<byte> AdobeImageResourceBlockMarker =>
[
(byte)'8', (byte)'B', (byte)'I', (byte)'M'
};
];
/// <summary>
/// Gets a IPTC Image resource ID.
/// </summary>
public static ReadOnlySpan<byte> AdobeIptcMarker => new[]
{
public static ReadOnlySpan<byte> AdobeIptcMarker =>
[
(byte)4, (byte)4
};
];
/// <summary>
/// Gets the EXIF specific markers.
/// </summary>
public static ReadOnlySpan<byte> ExifMarker => new[]
{
public static ReadOnlySpan<byte> ExifMarker =>
[
(byte)'E', (byte)'x', (byte)'i', (byte)'f', (byte)'\0', (byte)'\0'
};
];
/// <summary>
/// Gets the XMP specific markers.
/// </summary>
public static ReadOnlySpan<byte> XmpMarker => new[]
{
public static ReadOnlySpan<byte> XmpMarker =>
[
(byte)'h', (byte)'t', (byte)'t', (byte)'p', (byte)':', (byte)'/', (byte)'/',
(byte)'n', (byte)'s', (byte)'.', (byte)'a', (byte)'d', (byte)'o', (byte)'b',
(byte)'e', (byte)'.', (byte)'c', (byte)'o', (byte)'m', (byte)'/', (byte)'x',
(byte)'a', (byte)'p', (byte)'/', (byte)'1', (byte)'.', (byte)'0', (byte)'/',
(byte)0
};
];
/// <summary>
/// Gets the Adobe specific markers <see href="http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html#Adobe"/>.
/// </summary>
public static ReadOnlySpan<byte> AdobeMarker => new[]
{
public static ReadOnlySpan<byte> AdobeMarker =>
[
(byte)'A', (byte)'d', (byte)'o', (byte)'b', (byte)'e'
};
];
/// <summary>
/// Returns a value indicating whether the passed bytes are a match to the profile identifier.

40
src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs

@ -15,15 +15,13 @@ internal readonly struct HuffmanSpec
/// This is an example specification taken from the jpeg specification paper.
/// </remarks>
public static readonly HuffmanSpec LuminanceDC = new(
new byte[]
{
[
0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
0, 0, 0
},
new byte[]
{
],
[
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
});
]);
/// <summary>
/// Huffman talbe specification for luminance AC.
@ -32,13 +30,11 @@ internal readonly struct HuffmanSpec
/// This is an example specification taken from the jpeg specification paper.
/// </remarks>
public static readonly HuffmanSpec LuminanceAC = new(
new byte[]
{
[
0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0,
0, 1, 125
},
new byte[]
{
],
[
0x01, 0x02, 0x03, 0x00, 0x04, 0x11,
0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13,
0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32,
@ -63,7 +59,7 @@ internal readonly struct HuffmanSpec
0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1,
0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
0xf9, 0xfa
});
]);
/// <summary>
/// Huffman talbe specification for chrominance DC.
@ -72,15 +68,13 @@ internal readonly struct HuffmanSpec
/// This is an example specification taken from the jpeg specification paper.
/// </remarks>
public static readonly HuffmanSpec ChrominanceDC = new(
new byte[]
{
[
0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
0, 0, 0
},
new byte[]
{
],
[
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
});
]);
/// <summary>
/// Huffman talbe specification for chrominance DC.
@ -89,13 +83,11 @@ internal readonly struct HuffmanSpec
/// This is an example specification taken from the jpeg specification paper.
/// </remarks>
public static readonly HuffmanSpec ChrominanceAC = new(
new byte[]
{
[
0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0,
1, 2, 119
},
new byte[]
{
],
[
0x00, 0x01, 0x02, 0x03, 0x11, 0x04,
0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51,
0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81,
@ -120,7 +112,7 @@ internal readonly struct HuffmanSpec
0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
0xf9, 0xfa
});
]);
/// <summary>
/// Initializes a new instance of the <see cref="HuffmanSpec"/> struct.

8
src/ImageSharp/Formats/Jpeg/Components/FloatingPointDCT.cs

@ -49,8 +49,8 @@ internal static partial class FloatingPointDCT
/// </code>
/// </para>
/// </remarks>
private static readonly float[] AdjustmentCoefficients = new float[]
{
private static readonly float[] AdjustmentCoefficients =
[
1f, 1.3870399f, 1.306563f, 1.1758755f, 1f, 0.78569496f, 0.5411961f, 0.27589938f,
1.3870399f, 1.9238797f, 1.812255f, 1.6309863f, 1.3870399f, 1.0897902f, 0.7506606f, 0.38268346f,
1.306563f, 1.812255f, 1.707107f, 1.5363555f, 1.306563f, 1.02656f, 0.7071068f, 0.36047992f,
@ -58,8 +58,8 @@ internal static partial class FloatingPointDCT
1f, 1.3870399f, 1.306563f, 1.1758755f, 1f, 0.78569496f, 0.5411961f, 0.27589938f,
0.78569496f, 1.0897902f, 1.02656f, 0.9238795f, 0.78569496f, 0.61731654f, 0.42521507f, 0.21677275f,
0.5411961f, 0.7506606f, 0.7071068f, 0.63637924f, 0.5411961f, 0.42521507f, 0.29289323f, 0.14931567f,
0.27589938f, 0.38268346f, 0.36047992f, 0.32442334f, 0.27589938f, 0.21677275f, 0.14931567f, 0.076120466f,
};
0.27589938f, 0.38268346f, 0.36047992f, 0.32442334f, 0.27589938f, 0.21677275f, 0.14931567f, 0.076120466f
];
/// <summary>
/// Adjusts given quantization table for usage with <see cref="TransformIDCT"/>.

16
src/ImageSharp/Formats/Jpeg/Components/Quantization.cs

@ -46,8 +46,8 @@ internal static class Quantization
// The C# compiler emits this as a compile-time constant embedded in the PE file.
// This is effectively compiled down to: return new ReadOnlySpan<byte>(&data, length)
// More details can be found: https://github.com/dotnet/roslyn/pull/24621
public static ReadOnlySpan<byte> LuminanceTable => new byte[]
{
public static ReadOnlySpan<byte> LuminanceTable =>
[
16, 11, 10, 16, 24, 40, 51, 61,
12, 12, 14, 19, 26, 58, 60, 55,
14, 13, 16, 24, 40, 57, 69, 56,
@ -55,8 +55,8 @@ internal static class Quantization
18, 22, 37, 56, 68, 109, 103, 77,
24, 35, 55, 64, 81, 104, 113, 92,
49, 64, 78, 87, 103, 121, 120, 101,
72, 92, 95, 98, 112, 100, 103, 99,
};
72, 92, 95, 98, 112, 100, 103, 99
];
/// <summary>
/// Gets unscaled chrominance quantization table.
@ -67,8 +67,8 @@ internal static class Quantization
// The C# compiler emits this as a compile-time constant embedded in the PE file.
// This is effectively compiled down to: return new ReadOnlySpan<byte>(&data, length)
// More details can be found: https://github.com/dotnet/roslyn/pull/24621
public static ReadOnlySpan<byte> ChrominanceTable => new byte[]
{
public static ReadOnlySpan<byte> ChrominanceTable =>
[
17, 18, 24, 47, 99, 99, 99, 99,
18, 21, 26, 66, 99, 99, 99, 99,
24, 26, 56, 99, 99, 99, 99, 99,
@ -76,8 +76,8 @@ internal static class Quantization
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
};
99, 99, 99, 99, 99, 99, 99, 99
];
/// Ported from JPEGsnoop:
/// https://github.com/ImpulseAdventure/JPEGsnoop/blob/9732ee0961f100eb69bbff4a0c47438d5997abee/source/JfifDecode.cpp#L4570-L4694

12
src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs

@ -18,8 +18,8 @@ internal static partial class ZigZag
/// The worst case would be a run-length of 15, which means we need 16
/// fake entries.
/// </remarks>
public static ReadOnlySpan<byte> ZigZagOrder => new byte[]
{
public static ReadOnlySpan<byte> ZigZagOrder =>
[
0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34,
@ -32,7 +32,7 @@ internal static partial class ZigZag
// Extra entries for safety in decoder
63, 63, 63, 63, 63, 63, 63, 63,
63, 63, 63, 63, 63, 63, 63, 63
};
];
/// <summary>
/// Gets span of zig-zag with fused transpose step ordering indices.
@ -47,8 +47,8 @@ internal static partial class ZigZag
/// The worst case would be a run-length of 15, which means we need 16
/// fake entries.
/// </remarks>
public static ReadOnlySpan<byte> TransposingOrder => new byte[]
{
public static ReadOnlySpan<byte> TransposingOrder =>
[
0, 8, 1, 2, 9, 16, 24, 17,
10, 3, 4, 11, 18, 25, 32, 40,
33, 26, 19, 12, 5, 6, 13, 20,
@ -61,5 +61,5 @@ internal static partial class ZigZag
// Extra entries for safety in decoder
63, 63, 63, 63, 63, 63, 63, 63,
63, 63, 63, 63, 63, 63, 63, 63
};
];
}

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

@ -18,12 +18,12 @@ internal static class JpegConstants
/// <summary>
/// The list of mimetypes that equate to a jpeg.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[] { "image/jpeg", "image/pjpeg" };
public static readonly IEnumerable<string> MimeTypes = ["image/jpeg", "image/pjpeg"];
/// <summary>
/// The list of file extensions that equate to a jpeg.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "jpg", "jpeg", "jfif" };
public static readonly IEnumerable<string> FileExtensions = ["jpg", "jpeg", "jfif"];
/// <summary>
/// Contains marker specific constants.

4
src/ImageSharp/Formats/Pbm/PbmConstants.cs

@ -16,10 +16,10 @@ internal static class PbmConstants
/// <summary>
/// The list of mimetypes that equate to a ppm.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[] { "image/x-portable-pixmap", "image/x-portable-anymap" };
public static readonly IEnumerable<string> MimeTypes = ["image/x-portable-pixmap", "image/x-portable-anymap"];
/// <summary>
/// The list of file extensions that equate to a ppm.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "ppm", "pbm", "pgm" };
public static readonly IEnumerable<string> FileExtensions = ["ppm", "pbm", "pgm"];
}

8
src/ImageSharp/Formats/Png/Adam7.cs

@ -13,22 +13,22 @@ internal static class Adam7
/// <summary>
/// The amount to increment when processing each column per scanline for each interlaced pass.
/// </summary>
public static readonly int[] ColumnIncrement = { 8, 8, 4, 4, 2, 2, 1 };
public static readonly int[] ColumnIncrement = [8, 8, 4, 4, 2, 2, 1];
/// <summary>
/// The index to start at when processing each column per scanline for each interlaced pass.
/// </summary>
public static readonly int[] FirstColumn = { 0, 4, 0, 2, 0, 1, 0 };
public static readonly int[] FirstColumn = [0, 4, 0, 2, 0, 1, 0];
/// <summary>
/// The index to start at when processing each row per scanline for each interlaced pass.
/// </summary>
public static readonly int[] FirstRow = { 0, 0, 4, 0, 2, 0, 1 };
public static readonly int[] FirstRow = [0, 0, 4, 0, 2, 0, 1];
/// <summary>
/// The amount to increment when processing each row per scanline for each interlaced pass.
/// </summary>
public static readonly int[] RowIncrement = { 8, 8, 8, 4, 4, 2, 2 };
public static readonly int[] RowIncrement = [8, 8, 8, 4, 4, 2, 2];
/// <summary>
/// Gets the width of the block.

26
src/ImageSharp/Formats/Png/PngConstants.cs

@ -28,12 +28,12 @@ internal static class PngConstants
/// <summary>
/// The list of mimetypes that equate to a Png.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[] { "image/png", "image/apng" };
public static readonly IEnumerable<string> MimeTypes = ["image/png", "image/apng"];
/// <summary>
/// The list of file extensions that equate to a Png.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "png", "apng" };
public static readonly IEnumerable<string> FileExtensions = ["png", "apng"];
/// <summary>
/// The header bytes as a big-endian coded ulong.
@ -45,11 +45,11 @@ internal static class PngConstants
/// </summary>
public static readonly Dictionary<PngColorType, byte[]> ColorTypes = new()
{
[PngColorType.Grayscale] = new byte[] { 1, 2, 4, 8, 16 },
[PngColorType.Rgb] = new byte[] { 8, 16 },
[PngColorType.Palette] = new byte[] { 1, 2, 4, 8 },
[PngColorType.GrayscaleWithAlpha] = new byte[] { 8, 16 },
[PngColorType.RgbWithAlpha] = new byte[] { 8, 16 }
[PngColorType.Grayscale] = [1, 2, 4, 8, 16],
[PngColorType.Rgb] = [8, 16],
[PngColorType.Palette] = [1, 2, 4, 8],
[PngColorType.GrayscaleWithAlpha] = [8, 16],
[PngColorType.RgbWithAlpha] = [8, 16]
};
/// <summary>
@ -65,8 +65,8 @@ internal static class PngConstants
/// <summary>
/// Gets the header bytes identifying a Png.
/// </summary>
public static ReadOnlySpan<byte> HeaderBytes => new byte[]
{
public static ReadOnlySpan<byte> HeaderBytes =>
[
0x89, // Set the high bit.
0x50, // P
0x4E, // N
@ -75,13 +75,13 @@ internal static class PngConstants
0x0A, // Line ending CRLF
0x1A, // EOF
0x0A // LF
};
];
/// <summary>
/// Gets the keyword of the XMP metadata, encoded in an iTXT chunk.
/// </summary>
public static ReadOnlySpan<byte> XmpKeyword => new[]
{
public static ReadOnlySpan<byte> XmpKeyword =>
[
(byte)'X',
(byte)'M',
(byte)'L',
@ -99,5 +99,5 @@ internal static class PngConstants
(byte)'x',
(byte)'m',
(byte)'p'
};
];
}

4
src/ImageSharp/Formats/Qoi/QoiConstants.cs

@ -18,10 +18,10 @@ internal static class QoiConstants
/// Gets the list of mimetypes that equate to a QOI.
/// See https://github.com/phoboslab/qoi/issues/167
/// </summary>
public static string[] MimeTypes { get; } = { "image/qoi", "image/x-qoi", "image/vnd.qoi" };
public static string[] MimeTypes { get; } = ["image/qoi", "image/x-qoi", "image/vnd.qoi"];
/// <summary>
/// Gets the list of file extensions that equate to a QOI.
/// </summary>
public static string[] FileExtensions { get; } = { "qoi" };
public static string[] FileExtensions { get; } = ["qoi"];
}

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

@ -8,12 +8,12 @@ internal static class TgaConstants
/// <summary>
/// The list of mimetypes that equate to a targa file.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[] { "image/x-tga", "image/x-targa" };
public static readonly IEnumerable<string> MimeTypes = ["image/x-tga", "image/x-targa"];
/// <summary>
/// The list of file extensions that equate to a targa file.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "tga", "vda", "icb", "vst" };
public static readonly IEnumerable<string> FileExtensions = ["tga", "vda", "icb", "vst"];
/// <summary>
/// The file header length of a tga image in bytes.

4
src/ImageSharp/Formats/Tiff/Compression/Compressors/T6BitCompressor.cs

@ -17,7 +17,7 @@ internal sealed class T6BitCompressor : TiffCcittCompressor
/// Vertical codes from -3 to +3.
/// </summary>
private static readonly (uint Length, uint Code)[] VerticalCodes =
{
[
(7u, 3u),
(6u, 3u),
(3u, 3u),
@ -25,7 +25,7 @@ internal sealed class T6BitCompressor : TiffCcittCompressor
(3u, 2u),
(6u, 2u),
(7u, 2u)
};
];
private IMemoryOwner<byte> referenceLineBuffer;

4
src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffCcittCompressor.cs

@ -17,9 +17,9 @@ internal abstract class TiffCcittCompressor : TiffBaseCompressor
protected const uint BlackZeroRunTermCode = 0x37;
private static readonly uint[] MakeupRunLength =
{
[
64, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 1088, 1152, 1216, 1280, 1344, 1408, 1472, 1536, 1600, 1664, 1728, 1792, 1856, 1920, 1984, 2048, 2112, 2176, 2240, 2304, 2368, 2432, 2496, 2560
};
];
private static readonly Dictionary<uint, uint> WhiteLen4TermCodes = new()
{

2
src/ImageSharp/Formats/Tiff/Ifd/DirectoryReader.cs

@ -73,7 +73,7 @@ internal class DirectoryReader
private List<ExifProfile> ReadIfds(bool isBigTiff)
{
List<EntryReader> readers = new();
List<EntryReader> readers = [];
while (this.nextIfdOffset != 0 && this.nextIfdOffset < (ulong)this.stream.Length)
{
EntryReader reader = new(this.stream, this.ByteOrder, this.allocator);

8
src/ImageSharp/Formats/Tiff/PhotometricInterpretation/YCbCrConverter.cs

@ -17,18 +17,18 @@ internal class YCbCrConverter
private readonly YCbCrToRgbConverter converter;
private static readonly Rational[] DefaultLuma =
{
[
new(299, 1000),
new(587, 1000),
new(114, 1000)
};
];
private static readonly Rational[] DefaultReferenceBlackWhite =
{
[
new(0, 1), new(255, 1),
new(128, 1), new(255, 1),
new(128, 1), new(255, 1)
};
];
public YCbCrConverter(Rational[] referenceBlackAndWhite, Rational[] coefficients)
{

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

@ -16,7 +16,7 @@ internal class TiffEncoderEntriesCollector
{
private const string SoftwareValue = "ImageSharp";
public List<IExifValue> Entries { get; } = new();
public List<IExifValue> Entries { get; } = [];
public void ProcessMetadata(Image image, bool skipMetadata)
=> new MetadataProcessor(this).Process(image, skipMetadata);

2
src/ImageSharp/Formats/Tiff/Writers/TiffStreamWriter.cs

@ -110,7 +110,7 @@ internal sealed class TiffStreamWriter : IDisposable
if (value.Length % 4 != 0)
{
// No allocation occurs, refers directly to assembly's data segment.
ReadOnlySpan<byte> paddingBytes = new byte[4] { 0x00, 0x00, 0x00, 0x00 };
ReadOnlySpan<byte> paddingBytes = [0x00, 0x00, 0x00, 0x00];
paddingBytes = paddingBytes[..(4 - (value.Length % 4))];
this.BaseStream.Write(paddingBytes);
}

4
src/ImageSharp/Formats/Webp/BitReader/Vp8LBitReader.cs

@ -28,7 +28,7 @@ internal class Vp8LBitReader : BitReaderBase
private const int Wbits = 32;
private static readonly uint[] BitMask =
{
[
0,
0x000001, 0x000003, 0x000007, 0x00000f,
0x00001f, 0x00003f, 0x00007f, 0x0000ff,
@ -36,7 +36,7 @@ internal class Vp8LBitReader : BitReaderBase
0x001fff, 0x003fff, 0x007fff, 0x00ffff,
0x01ffff, 0x03ffff, 0x07ffff, 0x0fffff,
0x1fffff, 0x3fffff, 0x7fffff, 0xffffff
};
];
/// <summary>
/// Pre-fetched bits.

4
src/ImageSharp/Formats/Webp/Lossless/HuffmanUtils.cs

@ -20,10 +20,10 @@ internal static class HuffmanUtils
// Pre-reversed 4-bit values.
private static readonly byte[] ReversedBits =
{
[
0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf
};
];
public static void CreateHuffmanTree(Span<uint> histogram, int treeDepthLimit, bool[] bufRle, Span<HuffmanTree> huffTree, HuffmanTreeCode huffCode)
{

12
src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs

@ -12,9 +12,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless;
internal static unsafe class PredictorEncoder
{
private static readonly sbyte[][] Offset =
{
new sbyte[] { 0, -1 }, new sbyte[] { 0, 1 }, new sbyte[] { -1, 0 }, new sbyte[] { 1, 0 }, new sbyte[] { -1, -1 }, new sbyte[] { -1, 1 }, new sbyte[] { 1, -1 }, new sbyte[] { 1, 1 }
};
[
[0, -1], [0, 1], [-1, 0], [1, 0], [-1, -1], [-1, 1], [1, -1], [1, 1]
];
private const int GreenRedToBlueNumAxis = 8;
@ -29,7 +29,7 @@ internal static unsafe class PredictorEncoder
private const int PredLowEffort = 11;
// This uses C#'s compiler optimization to refer to assembly's static data directly.
private static ReadOnlySpan<sbyte> DeltaLut => new sbyte[] { 16, 16, 8, 4, 2, 2, 2 };
private static ReadOnlySpan<sbyte> DeltaLut => [16, 16, 8, 4, 2, 2, 2];
/// <summary>
/// Finds the best predictor for each tile, and converts the image to residuals
@ -58,12 +58,12 @@ internal static unsafe class PredictorEncoder
// TODO: Can we optimize this?
int[][] histo =
{
[
new int[256],
new int[256],
new int[256],
new int[256]
};
];
if (lowEffort)
{

9
src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs

@ -49,7 +49,7 @@ internal sealed class WebpLosslessDecoder
private const int FixedTableSize = (630 * 3) + 410;
private static readonly int[] TableSize =
{
[
FixedTableSize + 654,
FixedTableSize + 656,
FixedTableSize + 658,
@ -62,7 +62,7 @@ internal sealed class WebpLosslessDecoder
FixedTableSize + 1168,
FixedTableSize + 1680,
FixedTableSize + 2704
};
];
private static readonly int NumCodeLengthCodes = CodeLengthCodeOrder.Length;
@ -80,10 +80,11 @@ internal sealed class WebpLosslessDecoder
}
// This uses C#'s compiler optimization to refer to assembly's static data directly.
private static ReadOnlySpan<byte> CodeLengthCodeOrder => new byte[] { 17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
private static ReadOnlySpan<byte> CodeLengthCodeOrder => [17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
];
// This uses C#'s compiler optimization to refer to assembly's static data directly.
private static ReadOnlySpan<byte> LiteralMap => new byte[] { 0, 1, 1, 1, 0 };
private static ReadOnlySpan<byte> LiteralMap => [0, 1, 1, 1, 0];
/// <summary>
/// Decodes the lossless webp image from the stream.

4
src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs

@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy;
/// </summary>
internal static unsafe class QuantEnc
{
private static readonly ushort[] WeightY = { 38, 32, 20, 9, 32, 28, 17, 7, 20, 17, 10, 4, 9, 7, 4, 2 };
private static readonly ushort[] WeightY = [38, 32, 20, 9, 32, 28, 17, 7, 20, 17, 10, 4, 9, 7, 4, 2];
private const int MaxLevel = 2047;
@ -26,7 +26,7 @@ internal static unsafe class QuantEnc
private const int DSCALE = 1; // storage descaling, needed to make the error fit byte
// This uses C#'s optimization to refer to the static data segment of the assembly, no allocation occurs.
private static ReadOnlySpan<byte> Zigzag => new byte[] { 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 };
private static ReadOnlySpan<byte> Zigzag => [0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15];
public static void PickBestIntra16(Vp8EncIterator it, ref Vp8ModeScore rd, Vp8SegmentInfo[] segmentInfos, Vp8EncProba proba)
{

4
src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs

@ -36,12 +36,12 @@ internal class Vp8EncIterator
/// Array to record the position of the top sample to pass to the prediction functions.
/// </summary>
private readonly byte[] vp8TopLeftI4 =
{
[
17, 21, 25, 29,
13, 17, 21, 25,
9, 13, 17, 21,
5, 9, 13, 17
};
];
private int currentMbIdx;

2
src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs

@ -196,7 +196,7 @@ internal class Vp8Encoder : IDisposable
}
// This uses C#'s optimization to refer to the static data segment of the assembly, no allocation occurs.
private static ReadOnlySpan<byte> AverageBytesPerMb => new byte[] { 50, 24, 16, 9, 7, 5, 3, 2 };
private static ReadOnlySpan<byte> AverageBytesPerMb => [50, 24, 16, 9, 7, 5, 3, 2];
public int BaseQuant { get; set; }

7
src/ImageSharp/Formats/Webp/Lossy/Vp8Encoding.cs

@ -37,9 +37,9 @@ internal static unsafe class Vp8Encoding
private const int C8HE8 = C8VE8 + (1 * 16);
public static readonly int[] Vp8I16ModeOffsets = { I16DC16, I16TM16, I16VE16, I16HE16 };
public static readonly int[] Vp8I16ModeOffsets = [I16DC16, I16TM16, I16VE16, I16HE16];
public static readonly int[] Vp8UvModeOffsets = { C8DC8, C8TM8, C8VE8, C8HE8 };
public static readonly int[] Vp8UvModeOffsets = [C8DC8, C8TM8, C8VE8, C8HE8];
private const int I4DC4 = (3 * 16 * WebpConstants.Bps) + 0;
@ -61,7 +61,8 @@ internal static unsafe class Vp8Encoding
private const int I4HU4 = I4HD4 + 4;
public static readonly int[] Vp8I4ModeOffsets = { I4DC4, I4TM4, I4VE4, I4HE4, I4RD4, I4VR4, I4LD4, I4VL4, I4HD4, I4HU4 };
public static readonly int[] Vp8I4ModeOffsets = [I4DC4, I4TM4, I4VE4, I4HE4, I4RD4, I4VR4, I4LD4, I4VL4, I4HD4, I4HU4
];
private static byte[] GetClip1()
{

14
src/ImageSharp/Formats/Webp/Lossy/Vp8Matrix.cs

@ -5,13 +5,13 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy;
internal unsafe struct Vp8Matrix
{
// [luma-ac,luma-dc,chroma][dc,ac]
private static readonly int[][] BiasMatrices =
{
// [luma-ac,luma-dc,chroma][dc,ac]
new[] { 96, 110 },
new[] { 96, 108 },
new[] { 110, 115 }
};
[
[96, 110],
[96, 108],
[110, 115]
];
/// <summary>
/// Number of descaling bits for sharpening bias.
@ -46,7 +46,7 @@ internal unsafe struct Vp8Matrix
// Sharpening by (slightly) raising the hi-frequency coeffs.
// Hack-ish but helpful for mid-bitrate range. Use with care.
// This uses C#'s optimization to refer to the static data segment of the assembly, no allocation occurs.
private static ReadOnlySpan<byte> FreqSharpening => new byte[] { 0, 30, 60, 90, 30, 60, 90, 90, 60, 90, 90, 90, 90, 90, 90, 90 };
private static ReadOnlySpan<byte> FreqSharpening => [0, 30, 60, 90, 30, 60, 90, 90, 60, 90, 90, 90, 90, 90, 90, 90];
/// <summary>
/// Returns the average quantizer.

52
src/ImageSharp/Formats/Webp/WebpConstants.cs

@ -11,22 +11,22 @@ internal static class WebpConstants
/// <summary>
/// The list of file extensions that equate to Webp.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "webp" };
public static readonly IEnumerable<string> FileExtensions = ["webp"];
/// <summary>
/// The list of mimetypes that equate to a jpeg.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[] { "image/webp", };
public static readonly IEnumerable<string> MimeTypes = ["image/webp"];
/// <summary>
/// Signature which identifies a VP8 header.
/// </summary>
public static readonly byte[] Vp8HeaderMagicBytes =
{
[
0x9D,
0x01,
0x2A
};
];
/// <summary>
/// Signature byte which identifies a VP8L header.
@ -37,23 +37,23 @@ internal static class WebpConstants
/// The header bytes identifying RIFF file.
/// </summary>
public static readonly byte[] RiffFourCc =
{
[
0x52, // R
0x49, // I
0x46, // F
0x46 // F
};
];
/// <summary>
/// The header bytes identifying a Webp.
/// </summary>
public static readonly byte[] WebpHeader =
{
[
0x57, // W
0x45, // E
0x42, // B
0x50 // P
};
];
/// <summary>
/// The header bytes identifying a Webp.
@ -164,16 +164,16 @@ internal static class WebpConstants
public const int CodeLengthRepeatCode = 16;
public static readonly int[] CodeLengthExtraBits = { 2, 3, 7 };
public static readonly int[] CodeLengthExtraBits = [2, 3, 7];
public static readonly int[] CodeLengthRepeatOffsets = { 3, 3, 11 };
public static readonly int[] CodeLengthRepeatOffsets = [3, 3, 11];
public static readonly int[] AlphabetSize =
{
[
NumLiteralCodes + NumLengthCodes,
NumLiteralCodes, NumLiteralCodes, NumLiteralCodes,
NumDistanceCodes
};
];
public const int NumMbSegments = 4;
@ -270,9 +270,9 @@ internal static class WebpConstants
/// </summary>
public const int Vp8MaxPartition0Size = 1 << 19;
public static readonly short[] Vp8FixedCostsUv = { 302, 984, 439, 642 };
public static readonly short[] Vp8FixedCostsUv = [302, 984, 439, 642];
public static readonly short[] Vp8FixedCostsI16 = { 663, 919, 872, 919 };
public static readonly short[] Vp8FixedCostsI16 = [663, 919, 872, 919];
/// <summary>
/// Distortion multiplier (equivalent of lambda).
@ -284,31 +284,31 @@ internal static class WebpConstants
/// Simple filter(1): up to 2 luma samples are read and 1 is written.
/// Complex filter(2): up to 4 luma samples are read and 3 are written. Same for U/V, so it's 8 samples total (because of the 2x upsampling).
/// </summary>
public static readonly byte[] FilterExtraRows = { 0, 2, 8 };
public static readonly byte[] FilterExtraRows = [0, 2, 8];
// Paragraph 9.9
public static readonly int[] Vp8EncBands =
{
[
0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 0
};
];
public static readonly short[] Scan =
{
[
0 + (0 * Bps), 4 + (0 * Bps), 8 + (0 * Bps), 12 + (0 * Bps),
0 + (4 * Bps), 4 + (4 * Bps), 8 + (4 * Bps), 12 + (4 * Bps),
0 + (8 * Bps), 4 + (8 * Bps), 8 + (8 * Bps), 12 + (8 * Bps),
0 + (12 * Bps), 4 + (12 * Bps), 8 + (12 * Bps), 12 + (12 * Bps)
};
];
// Residual decoding (Paragraph 13.2 / 13.3)
public static readonly byte[] Cat3 = { 173, 148, 140 };
public static readonly byte[] Cat4 = { 176, 155, 140, 135 };
public static readonly byte[] Cat5 = { 180, 157, 141, 134, 130 };
public static readonly byte[] Cat6 = { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129 };
public static readonly byte[] Zigzag = { 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 };
public static readonly byte[] Cat3 = [173, 148, 140];
public static readonly byte[] Cat4 = [176, 155, 140, 135];
public static readonly byte[] Cat5 = [180, 157, 141, 134, 130];
public static readonly byte[] Cat6 = [254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129];
public static readonly byte[] Zigzag = [0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15];
public static readonly sbyte[] YModesIntra4 =
{
[
-0, 1,
-1, 2,
-2, 3,
@ -318,5 +318,5 @@ internal static class WebpConstants
-6, 7,
-7, 8,
-8, -9
};
];
}

558
src/ImageSharp/Formats/Webp/WebpLookupTables.cs

@ -19,7 +19,8 @@ internal static class WebpLookupTables
// Compute susceptibility based on DCT-coeff histograms:
// the higher, the "easier" the macroblock is to compress.
public static readonly int[] Vp8DspScan =
{
[
// Luma
0 + (0 * WebpConstants.Bps), 4 + (0 * WebpConstants.Bps), 8 + (0 * WebpConstants.Bps), 12 + (0 * WebpConstants.Bps),
0 + (4 * WebpConstants.Bps), 4 + (4 * WebpConstants.Bps), 8 + (4 * WebpConstants.Bps), 12 + (4 * WebpConstants.Bps),
@ -28,22 +29,23 @@ internal static class WebpLookupTables
0 + (0 * WebpConstants.Bps), 4 + (0 * WebpConstants.Bps), 0 + (4 * WebpConstants.Bps), 4 + (4 * WebpConstants.Bps), // U
8 + (0 * WebpConstants.Bps), 12 + (0 * WebpConstants.Bps), 8 + (4 * WebpConstants.Bps), 12 + (4 * WebpConstants.Bps) // V
};
];
public static readonly short[] Vp8Scan =
{
[
// Luma
0 + (0 * WebpConstants.Bps), 4 + (0 * WebpConstants.Bps), 8 + (0 * WebpConstants.Bps), 12 + (0 * WebpConstants.Bps),
0 + (4 * WebpConstants.Bps), 4 + (4 * WebpConstants.Bps), 8 + (4 * WebpConstants.Bps), 12 + (4 * WebpConstants.Bps),
0 + (8 * WebpConstants.Bps), 4 + (8 * WebpConstants.Bps), 8 + (8 * WebpConstants.Bps), 12 + (8 * WebpConstants.Bps),
0 + (12 * WebpConstants.Bps), 4 + (12 * WebpConstants.Bps), 8 + (12 * WebpConstants.Bps), 12 + (12 * WebpConstants.Bps),
};
0 + (12 * WebpConstants.Bps), 4 + (12 * WebpConstants.Bps), 8 + (12 * WebpConstants.Bps), 12 + (12 * WebpConstants.Bps)
];
public static readonly short[] Vp8ScanUv =
{
[
0 + (0 * WebpConstants.Bps), 4 + (0 * WebpConstants.Bps), 0 + (4 * WebpConstants.Bps), 4 + (4 * WebpConstants.Bps), // U
8 + (0 * WebpConstants.Bps), 12 + (0 * WebpConstants.Bps), 8 + (4 * WebpConstants.Bps), 12 + (4 * WebpConstants.Bps) // V
};
];
[MethodImpl(InliningOptions.ShortMethod)]
public static byte Abs0(int x) => Abs0Table[x + 255];
@ -60,7 +62,7 @@ internal static class WebpLookupTables
// fixed costs for coding levels, deduce from the coding tree.
// This is only the part that doesn't depend on the probability state.
public static readonly short[] Vp8LevelFixedCosts =
{
[
0, 256, 256, 256, 256, 432, 618, 630, 731, 640, 640, 828, 901, 948, 1021, 1101, 1174, 1221, 1294, 1042,
1085, 1115, 1158, 1202, 1245, 1275, 1318, 1337, 1380, 1410, 1453, 1497, 1540, 1570, 1613, 1280, 1295,
1317, 1332, 1358, 1373, 1395, 1410, 1454, 1469, 1491, 1506, 1532, 1547, 1569, 1584, 1601, 1616, 1638,
@ -182,7 +184,7 @@ internal static class WebpLookupTables
7403, 7409, 7429, 7435, 7444, 7450, 7461, 7467, 7476, 7482, 7505, 7511, 7520, 7526, 7537, 7543, 7552,
7558, 7578, 7584, 7593, 7599, 7610, 7616, 7625, 7631, 7656, 7662, 7671, 7677, 7688, 7694, 7703, 7709,
7729, 7735, 7744, 7750, 7761
};
];
// This table gives, for a given sharpness, the filtering strength to be
// used (at least) in order to filter a given edge step delta.
@ -239,8 +241,9 @@ internal static class WebpLookupTables
};
// This uses C#'s compiler optimization to refer to assembly's static data directly.
public static ReadOnlySpan<byte> Norm => new byte[]
{
public static ReadOnlySpan<byte> Norm =>
[
// renorm_sizes[i] = 8 - log2(i)
7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
@ -251,11 +254,12 @@ internal static class WebpLookupTables
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0
};
];
// This uses C#'s compiler optimization to refer to assembly's static data directly.
public static ReadOnlySpan<byte> NewRange => new byte[]
{
public static ReadOnlySpan<byte> NewRange =>
[
// range = ((range + 1) << kVP8Log2Range[range]) - 1
127, 127, 191, 127, 159, 191, 223, 127, 143, 159, 175, 191, 207, 223, 239,
127, 135, 143, 151, 159, 167, 175, 183, 191, 199, 207, 215, 223, 231, 239,
@ -266,10 +270,10 @@ internal static class WebpLookupTables
181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209,
211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, 235, 237, 239,
241, 243, 245, 247, 249, 251, 253, 127
};
];
public static readonly ushort[] Vp8EntropyCost =
{
[
1792, 1792, 1792, 1536, 1536, 1408, 1366, 1280, 1280, 1216,
1178, 1152, 1110, 1076, 1061, 1024, 1024, 992, 968, 951,
939, 911, 896, 878, 871, 854, 838, 820, 811, 794,
@ -296,35 +300,35 @@ internal static class WebpLookupTables
41, 40, 38, 36, 35, 33, 32, 30, 29, 27,
25, 24, 22, 21, 19, 18, 16, 15, 13, 12,
10, 9, 7, 6, 4, 3
};
];
public static readonly ushort[][] Vp8LevelCodes =
{
new ushort[] { 0x001, 0x000 }, new ushort[] { 0x007, 0x001 }, new ushort[] { 0x00f, 0x005 },
new ushort[] { 0x00f, 0x00d }, new ushort[] { 0x033, 0x003 }, new ushort[] { 0x033, 0x003 }, new ushort[] { 0x033, 0x023 },
new ushort[] { 0x033, 0x023 }, new ushort[] { 0x033, 0x023 }, new ushort[] { 0x033, 0x023 }, new ushort[] { 0x0d3, 0x013 },
new ushort[] { 0x0d3, 0x013 }, new ushort[] { 0x0d3, 0x013 }, new ushort[] { 0x0d3, 0x013 }, new ushort[] { 0x0d3, 0x013 },
new ushort[] { 0x0d3, 0x013 }, new ushort[] { 0x0d3, 0x013 }, new ushort[] { 0x0d3, 0x013 }, new ushort[] { 0x0d3, 0x093 },
new ushort[] { 0x0d3, 0x093 }, new ushort[] { 0x0d3, 0x093 }, new ushort[] { 0x0d3, 0x093 }, new ushort[] { 0x0d3, 0x093 },
new ushort[] { 0x0d3, 0x093 }, new ushort[] { 0x0d3, 0x093 }, new ushort[] { 0x0d3, 0x093 }, new ushort[] { 0x0d3, 0x093 },
new ushort[] { 0x0d3, 0x093 }, new ushort[] { 0x0d3, 0x093 }, new ushort[] { 0x0d3, 0x093 }, new ushort[] { 0x0d3, 0x093 },
new ushort[] { 0x0d3, 0x093 }, new ushort[] { 0x0d3, 0x093 }, new ushort[] { 0x0d3, 0x093 }, new ushort[] { 0x153, 0x053 },
new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 },
new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 },
new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 },
new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 },
new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 },
new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 },
new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 },
new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x053 }, new ushort[] { 0x153, 0x153 },
};
[
[0x001, 0x000], [0x007, 0x001], [0x00f, 0x005],
[0x00f, 0x00d], [0x033, 0x003], [0x033, 0x003], [0x033, 0x023],
[0x033, 0x023], [0x033, 0x023], [0x033, 0x023], [0x0d3, 0x013],
[0x0d3, 0x013], [0x0d3, 0x013], [0x0d3, 0x013], [0x0d3, 0x013],
[0x0d3, 0x013], [0x0d3, 0x013], [0x0d3, 0x013], [0x0d3, 0x093],
[0x0d3, 0x093], [0x0d3, 0x093], [0x0d3, 0x093], [0x0d3, 0x093],
[0x0d3, 0x093], [0x0d3, 0x093], [0x0d3, 0x093], [0x0d3, 0x093],
[0x0d3, 0x093], [0x0d3, 0x093], [0x0d3, 0x093], [0x0d3, 0x093],
[0x0d3, 0x093], [0x0d3, 0x093], [0x0d3, 0x093], [0x153, 0x053],
[0x153, 0x053], [0x153, 0x053], [0x153, 0x053], [0x153, 0x053],
[0x153, 0x053], [0x153, 0x053], [0x153, 0x053], [0x153, 0x053],
[0x153, 0x053], [0x153, 0x053], [0x153, 0x053], [0x153, 0x053],
[0x153, 0x053], [0x153, 0x053], [0x153, 0x053], [0x153, 0x053],
[0x153, 0x053], [0x153, 0x053], [0x153, 0x053], [0x153, 0x053],
[0x153, 0x053], [0x153, 0x053], [0x153, 0x053], [0x153, 0x053],
[0x153, 0x053], [0x153, 0x053], [0x153, 0x053], [0x153, 0x053],
[0x153, 0x053], [0x153, 0x053], [0x153, 0x053], [0x153, 0x153]
];
/// <summary>
/// Lookup table for small values of log2(int).
/// </summary>
public static readonly float[] Log2Table =
{
0.0000000000000000f, 0.0000000000000000f,
[
0.0000000000000000f, 0.0000000000000000f,
1.0000000000000000f, 1.5849625007211560f,
2.0000000000000000f, 2.3219280948873621f,
2.5849625007211560f, 2.8073549220576041f,
@ -452,11 +456,11 @@ internal static class WebpLookupTables
7.9657842846620869f, 7.9715435539507719f,
7.9772799234999167f, 7.9829935746943103f,
7.9886846867721654f, 7.9943534368588577f
};
];
public static readonly float[] SLog2Table =
{
0.00000000f, 0.00000000f, 2.00000000f, 4.75488750f,
[
0.00000000f, 0.00000000f, 2.00000000f, 4.75488750f,
8.00000000f, 11.60964047f, 15.50977500f, 19.65148445f,
24.00000000f, 28.52932501f, 33.21928095f, 38.05374781f,
43.01955001f, 48.10571634f, 53.30296891f, 58.60335893f,
@ -520,10 +524,10 @@ internal static class WebpLookupTables
1935.09991037f, 1944.47629506f, 1953.85856831f, 1963.24670620f,
1972.64068498f, 1982.04048108f, 1991.44607117f, 2000.85743204f,
2010.27454072f, 2019.69737440f, 2029.12591044f, 2038.56012640f
};
];
public static readonly int[] CodeToPlane =
{
[
0x18, 0x07, 0x17, 0x19, 0x28, 0x06, 0x27, 0x29, 0x16, 0x1a,
0x26, 0x2a, 0x38, 0x05, 0x37, 0x39, 0x15, 0x1b, 0x36, 0x3a,
0x25, 0x2b, 0x48, 0x04, 0x47, 0x49, 0x14, 0x1c, 0x35, 0x3b,
@ -536,10 +540,10 @@ internal static class WebpLookupTables
0x31, 0x3f, 0x63, 0x6d, 0x52, 0x5e, 0x00, 0x74, 0x7c, 0x41,
0x4f, 0x10, 0x20, 0x62, 0x6e, 0x30, 0x73, 0x7d, 0x51, 0x5f,
0x40, 0x72, 0x7e, 0x61, 0x6f, 0x50, 0x71, 0x7f, 0x60, 0x70
};
];
public static readonly uint[] PlaneToCodeLut =
{
[
96, 73, 55, 39, 23, 13, 5, 1, 255, 255, 255, 255, 255, 255, 255, 255,
101, 78, 58, 42, 26, 16, 8, 2, 0, 3, 9, 17, 27, 43, 59, 79,
102, 86, 62, 46, 32, 20, 10, 6, 4, 7, 11, 21, 33, 47, 63, 87,
@ -548,11 +552,11 @@ internal static class WebpLookupTables
115, 108, 94, 76, 64, 50, 44, 40, 34, 41, 45, 51, 65, 77, 95, 109,
118, 113, 103, 92, 80, 68, 60, 56, 54, 57, 61, 69, 81, 93, 104, 114,
119, 116, 111, 106, 97, 88, 84, 74, 72, 75, 85, 89, 98, 107, 112, 117
};
];
// 31 ^ clz(i)
public static ReadOnlySpan<byte> LogTable8Bit => new byte[]
{
public static ReadOnlySpan<byte> LogTable8Bit =>
[
0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
@ -569,12 +573,12 @@ internal static class WebpLookupTables
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
};
];
// Paragraph 14.1
// This uses C#'s compiler optimization to refer to assembly's static data directly.
public static ReadOnlySpan<byte> DcTable => new byte[]
{
public static ReadOnlySpan<byte> DcTable =>
[
4, 5, 6, 7, 8, 9, 10, 10,
11, 12, 13, 14, 15, 16, 17, 17,
18, 19, 20, 20, 21, 21, 22, 22,
@ -591,11 +595,11 @@ internal static class WebpLookupTables
104, 106, 108, 110, 112, 114, 116, 118,
122, 124, 126, 128, 130, 132, 134, 136,
138, 140, 143, 145, 148, 151, 154, 157
};
];
// Paragraph 14.1
public static readonly ushort[] AcTable =
{
[
4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27,
@ -612,10 +616,10 @@ internal static class WebpLookupTables
181, 185, 189, 193, 197, 201, 205, 209,
213, 217, 221, 225, 229, 234, 239, 245,
249, 254, 259, 264, 269, 274, 279, 284
};
];
public static readonly ushort[] AcTable2 =
{
[
8, 8, 9, 10, 12, 13, 15, 17,
18, 20, 21, 23, 24, 26, 27, 29,
31, 32, 34, 35, 37, 38, 40, 41,
@ -632,7 +636,7 @@ internal static class WebpLookupTables
280, 286, 292, 299, 305, 311, 317, 323,
330, 336, 342, 348, 354, 362, 370, 379,
385, 393, 401, 409, 416, 424, 432, 440
};
];
// Paragraph 13
public static readonly byte[,,,] CoeffsUpdateProba =
@ -981,7 +985,7 @@ internal static class WebpLookupTables
};
public static readonly (int Code, int ExtraBits)[] PrefixEncodeCode =
{
[
(0, 0), (0, 0), (1, 0), (2, 0), (3, 0), (4, 1), (4, 1), (5, 1),
(5, 1), (6, 2), (6, 2), (6, 2), (6, 2), (7, 2), (7, 2), (7, 2),
(7, 2), (8, 3), (8, 3), (8, 3), (8, 3), (8, 3), (8, 3), (8, 3),
@ -1045,13 +1049,13 @@ internal static class WebpLookupTables
(17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7),
(17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7),
(17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7),
(17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7),
};
(17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7), (17, 7)
];
// This uses C#'s compiler optimization to refer to assembly's static data directly.
public static ReadOnlySpan<byte> PrefixEncodeExtraBitsValue => new byte[]
{
0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 2, 3, 0, 1, 2, 3,
public static ReadOnlySpan<byte> PrefixEncodeExtraBitsValue =>
[
0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 2, 3, 0, 1, 2, 3,
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
@ -1084,7 +1088,7 @@ internal static class WebpLookupTables
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126
};
];
// Following table is (1 << AlphaFix) / a. The (v * InvAlpha[a]) >> AlphaFix
// formula is then equal to v / a in most (99.6%) cases. Note that this table
@ -1094,7 +1098,7 @@ internal static class WebpLookupTables
// with ai in [0..255] and pi in [0..1<<GammaFix). The constraint to avoid
// overflow is: GammaFix + AlphaFix <= 31.
public static readonly uint[] InvAlpha =
{
[
0, /* alpha = 0 */
524288, 262144, 174762, 131072, 104857, 87381, 74898, 65536,
58254, 52428, 47662, 43690, 40329, 37449, 34952, 32768,
@ -1224,7 +1228,7 @@ internal static class WebpLookupTables
523, 523, 522, 522, 521, 521, 520, 520,
519, 519, 518, 518, 517, 517, 516, 516,
515, 515, 514, 514
};
];
static WebpLookupTables()
{
@ -1245,8 +1249,8 @@ internal static class WebpLookupTables
}
// This uses C#'s compiler optimization to refer to assembly's static data directly.
private static ReadOnlySpan<byte> Abs0Table => new byte[]
{
private static ReadOnlySpan<byte> Abs0Table =>
[
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0, 0xef,
0xee, 0xed, 0xec, 0xeb, 0xea, 0xe9, 0xe8, 0xe7, 0xe6, 0xe5, 0xe4, 0xe3, 0xe2, 0xe1, 0xe0, 0xdf, 0xde,
0xdd, 0xdc, 0xdb, 0xda, 0xd9, 0xd8, 0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0, 0xcf, 0xce, 0xcd,
@ -1278,11 +1282,11 @@ internal static class WebpLookupTables
0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed,
0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe,
0xff
};
];
// This uses C#'s compiler optimization to refer to assembly's static data directly.
private static ReadOnlySpan<byte> Clip1Table => new byte[]
{
private static ReadOnlySpan<byte> Clip1Table =>
[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -1329,11 +1333,11 @@ internal static class WebpLookupTables
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff
};
];
// This uses C#'s compiler optimization to refer to assembly's static data directly.
private static ReadOnlySpan<sbyte> Sclip1Table => new sbyte[]
{
private static ReadOnlySpan<sbyte> Sclip1Table =>
[
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
@ -1441,11 +1445,11 @@ internal static class WebpLookupTables
127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 127, 127
};
];
// This uses C#'s compiler optimization to refer to assembly's static data directly.
private static ReadOnlySpan<sbyte> Sclip2Table => new sbyte[]
{
private static ReadOnlySpan<sbyte> Sclip2Table =>
[
-16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
-16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
-16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
@ -1456,214 +1460,214 @@ internal static class WebpLookupTables
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15
};
];
private static void InitializeModesProbabilities()
{
// Paragraph 11.5
ModesProba[0, 0] = new byte[] { 231, 120, 48, 89, 115, 113, 120, 152, 112 };
ModesProba[0, 1] = new byte[] { 152, 179, 64, 126, 170, 118, 46, 70, 95 };
ModesProba[0, 2] = new byte[] { 175, 69, 143, 80, 85, 82, 72, 155, 103 };
ModesProba[0, 3] = new byte[] { 56, 58, 10, 171, 218, 189, 17, 13, 152 };
ModesProba[0, 4] = new byte[] { 114, 26, 17, 163, 44, 195, 21, 10, 173 };
ModesProba[0, 5] = new byte[] { 121, 24, 80, 195, 26, 62, 44, 64, 85 };
ModesProba[0, 6] = new byte[] { 144, 71, 10, 38, 171, 213, 144, 34, 26 };
ModesProba[0, 7] = new byte[] { 170, 46, 55, 19, 136, 160, 33, 206, 71 };
ModesProba[0, 8] = new byte[] { 63, 20, 8, 114, 114, 208, 12, 9, 226 };
ModesProba[0, 9] = new byte[] { 81, 40, 11, 96, 182, 84, 29, 16, 36 };
ModesProba[1, 0] = new byte[] { 134, 183, 89, 137, 98, 101, 106, 165, 148 };
ModesProba[1, 1] = new byte[] { 72, 187, 100, 130, 157, 111, 32, 75, 80 };
ModesProba[1, 2] = new byte[] { 66, 102, 167, 99, 74, 62, 40, 234, 128 };
ModesProba[1, 3] = new byte[] { 41, 53, 9, 178, 241, 141, 26, 8, 107 };
ModesProba[1, 4] = new byte[] { 74, 43, 26, 146, 73, 166, 49, 23, 157 };
ModesProba[1, 5] = new byte[] { 65, 38, 105, 160, 51, 52, 31, 115, 128 };
ModesProba[1, 6] = new byte[] { 104, 79, 12, 27, 217, 255, 87, 17, 7 };
ModesProba[1, 7] = new byte[] { 87, 68, 71, 44, 114, 51, 15, 186, 23 };
ModesProba[1, 8] = new byte[] { 47, 41, 14, 110, 182, 183, 21, 17, 194 };
ModesProba[1, 9] = new byte[] { 66, 45, 25, 102, 197, 189, 23, 18, 22 };
ModesProba[2, 0] = new byte[] { 88, 88, 147, 150, 42, 46, 45, 196, 205 };
ModesProba[2, 1] = new byte[] { 43, 97, 183, 117, 85, 38, 35, 179, 61 };
ModesProba[2, 2] = new byte[] { 39, 53, 200, 87, 26, 21, 43, 232, 171 };
ModesProba[2, 3] = new byte[] { 56, 34, 51, 104, 114, 102, 29, 93, 77 };
ModesProba[2, 4] = new byte[] { 39, 28, 85, 171, 58, 165, 90, 98, 64 };
ModesProba[2, 5] = new byte[] { 34, 22, 116, 206, 23, 34, 43, 166, 73 };
ModesProba[2, 6] = new byte[] { 107, 54, 32, 26, 51, 1, 81, 43, 31 };
ModesProba[2, 7] = new byte[] { 68, 25, 106, 22, 64, 171, 36, 225, 114 };
ModesProba[2, 8] = new byte[] { 34, 19, 21, 102, 132, 188, 16, 76, 124 };
ModesProba[2, 9] = new byte[] { 62, 18, 78, 95, 85, 57, 50, 48, 51 };
ModesProba[3, 0] = new byte[] { 193, 101, 35, 159, 215, 111, 89, 46, 111 };
ModesProba[3, 1] = new byte[] { 60, 148, 31, 172, 219, 228, 21, 18, 111 };
ModesProba[3, 2] = new byte[] { 112, 113, 77, 85, 179, 255, 38, 120, 114 };
ModesProba[3, 3] = new byte[] { 40, 42, 1, 196, 245, 209, 10, 25, 109 };
ModesProba[3, 4] = new byte[] { 88, 43, 29, 140, 166, 213, 37, 43, 154 };
ModesProba[3, 5] = new byte[] { 61, 63, 30, 155, 67, 45, 68, 1, 209 };
ModesProba[3, 6] = new byte[] { 100, 80, 8, 43, 154, 1, 51, 26, 71 };
ModesProba[3, 7] = new byte[] { 142, 78, 78, 16, 255, 128, 34, 197, 171 };
ModesProba[3, 8] = new byte[] { 41, 40, 5, 102, 211, 183, 4, 1, 221 };
ModesProba[3, 9] = new byte[] { 51, 50, 17, 168, 209, 192, 23, 25, 82 };
ModesProba[4, 0] = new byte[] { 138, 31, 36, 171, 27, 166, 38, 44, 229 };
ModesProba[4, 1] = new byte[] { 67, 87, 58, 169, 82, 115, 26, 59, 179 };
ModesProba[4, 2] = new byte[] { 63, 59, 90, 180, 59, 166, 93, 73, 154 };
ModesProba[4, 3] = new byte[] { 40, 40, 21, 116, 143, 209, 34, 39, 175 };
ModesProba[4, 4] = new byte[] { 47, 15, 16, 183, 34, 223, 49, 45, 183 };
ModesProba[4, 5] = new byte[] { 46, 17, 33, 183, 6, 98, 15, 32, 183 };
ModesProba[4, 6] = new byte[] { 57, 46, 22, 24, 128, 1, 54, 17, 37 };
ModesProba[4, 7] = new byte[] { 65, 32, 73, 115, 28, 128, 23, 128, 205 };
ModesProba[4, 8] = new byte[] { 40, 3, 9, 115, 51, 192, 18, 6, 223 };
ModesProba[4, 9] = new byte[] { 87, 37, 9, 115, 59, 77, 64, 21, 47 };
ModesProba[5, 0] = new byte[] { 104, 55, 44, 218, 9, 54, 53, 130, 226 };
ModesProba[5, 1] = new byte[] { 64, 90, 70, 205, 40, 41, 23, 26, 57 };
ModesProba[5, 2] = new byte[] { 54, 57, 112, 184, 5, 41, 38, 166, 213 };
ModesProba[5, 3] = new byte[] { 30, 34, 26, 133, 152, 116, 10, 32, 134 };
ModesProba[5, 4] = new byte[] { 39, 19, 53, 221, 26, 114, 32, 73, 255 };
ModesProba[5, 5] = new byte[] { 31, 9, 65, 234, 2, 15, 1, 118, 73 };
ModesProba[5, 6] = new byte[] { 75, 32, 12, 51, 192, 255, 160, 43, 51 };
ModesProba[5, 7] = new byte[] { 88, 31, 35, 67, 102, 85, 55, 186, 85 };
ModesProba[5, 8] = new byte[] { 56, 21, 23, 111, 59, 205, 45, 37, 192 };
ModesProba[5, 9] = new byte[] { 55, 38, 70, 124, 73, 102, 1, 34, 98 };
ModesProba[6, 0] = new byte[] { 125, 98, 42, 88, 104, 85, 117, 175, 82 };
ModesProba[6, 1] = new byte[] { 95, 84, 53, 89, 128, 100, 113, 101, 45 };
ModesProba[6, 2] = new byte[] { 75, 79, 123, 47, 51, 128, 81, 171, 1 };
ModesProba[6, 3] = new byte[] { 57, 17, 5, 71, 102, 57, 53, 41, 49 };
ModesProba[6, 4] = new byte[] { 38, 33, 13, 121, 57, 73, 26, 1, 85 };
ModesProba[6, 5] = new byte[] { 41, 10, 67, 138, 77, 110, 90, 47, 114 };
ModesProba[6, 6] = new byte[] { 115, 21, 2, 10, 102, 255, 166, 23, 6 };
ModesProba[6, 7] = new byte[] { 101, 29, 16, 10, 85, 128, 101, 196, 26 };
ModesProba[6, 8] = new byte[] { 57, 18, 10, 102, 102, 213, 34, 20, 43 };
ModesProba[6, 9] = new byte[] { 117, 20, 15, 36, 163, 128, 68, 1, 26 };
ModesProba[7, 0] = new byte[] { 102, 61, 71, 37, 34, 53, 31, 243, 192 };
ModesProba[7, 1] = new byte[] { 69, 60, 71, 38, 73, 119, 28, 222, 37 };
ModesProba[7, 2] = new byte[] { 68, 45, 128, 34, 1, 47, 11, 245, 171 };
ModesProba[7, 3] = new byte[] { 62, 17, 19, 70, 146, 85, 55, 62, 70 };
ModesProba[7, 4] = new byte[] { 37, 43, 37, 154, 100, 163, 85, 160, 1 };
ModesProba[7, 5] = new byte[] { 63, 9, 92, 136, 28, 64, 32, 201, 85 };
ModesProba[7, 6] = new byte[] { 75, 15, 9, 9, 64, 255, 184, 119, 16 };
ModesProba[7, 7] = new byte[] { 86, 6, 28, 5, 64, 255, 25, 248, 1 };
ModesProba[7, 8] = new byte[] { 56, 8, 17, 132, 137, 255, 55, 116, 128 };
ModesProba[7, 9] = new byte[] { 58, 15, 20, 82, 135, 57, 26, 121, 40 };
ModesProba[8, 0] = new byte[] { 164, 50, 31, 137, 154, 133, 25, 35, 218 };
ModesProba[8, 1] = new byte[] { 51, 103, 44, 131, 131, 123, 31, 6, 158 };
ModesProba[8, 2] = new byte[] { 86, 40, 64, 135, 148, 224, 45, 183, 128 };
ModesProba[8, 3] = new byte[] { 22, 26, 17, 131, 240, 154, 14, 1, 209 };
ModesProba[8, 4] = new byte[] { 45, 16, 21, 91, 64, 222, 7, 1, 197 };
ModesProba[8, 5] = new byte[] { 56, 21, 39, 155, 60, 138, 23, 102, 213 };
ModesProba[8, 6] = new byte[] { 83, 12, 13, 54, 192, 255, 68, 47, 28 };
ModesProba[8, 7] = new byte[] { 85, 26, 85, 85, 128, 128, 32, 146, 171 };
ModesProba[8, 8] = new byte[] { 18, 11, 7, 63, 144, 171, 4, 4, 246 };
ModesProba[8, 9] = new byte[] { 35, 27, 10, 146, 174, 171, 12, 26, 128 };
ModesProba[9, 0] = new byte[] { 190, 80, 35, 99, 180, 80, 126, 54, 45 };
ModesProba[9, 1] = new byte[] { 85, 126, 47, 87, 176, 51, 41, 20, 32 };
ModesProba[9, 2] = new byte[] { 101, 75, 128, 139, 118, 146, 116, 128, 85 };
ModesProba[9, 3] = new byte[] { 56, 41, 15, 176, 236, 85, 37, 9, 62 };
ModesProba[9, 4] = new byte[] { 71, 30, 17, 119, 118, 255, 17, 18, 138 };
ModesProba[9, 5] = new byte[] { 101, 38, 60, 138, 55, 70, 43, 26, 142 };
ModesProba[9, 6] = new byte[] { 146, 36, 19, 30, 171, 255, 97, 27, 20 };
ModesProba[9, 7] = new byte[] { 138, 45, 61, 62, 219, 1, 81, 188, 64 };
ModesProba[9, 8] = new byte[] { 32, 41, 20, 117, 151, 142, 20, 21, 163 };
ModesProba[9, 9] = new byte[] { 112, 19, 12, 61, 195, 128, 48, 4, 24 };
ModesProba[0, 0] = [231, 120, 48, 89, 115, 113, 120, 152, 112];
ModesProba[0, 1] = [152, 179, 64, 126, 170, 118, 46, 70, 95];
ModesProba[0, 2] = [175, 69, 143, 80, 85, 82, 72, 155, 103];
ModesProba[0, 3] = [56, 58, 10, 171, 218, 189, 17, 13, 152];
ModesProba[0, 4] = [114, 26, 17, 163, 44, 195, 21, 10, 173];
ModesProba[0, 5] = [121, 24, 80, 195, 26, 62, 44, 64, 85];
ModesProba[0, 6] = [144, 71, 10, 38, 171, 213, 144, 34, 26];
ModesProba[0, 7] = [170, 46, 55, 19, 136, 160, 33, 206, 71];
ModesProba[0, 8] = [63, 20, 8, 114, 114, 208, 12, 9, 226];
ModesProba[0, 9] = [81, 40, 11, 96, 182, 84, 29, 16, 36];
ModesProba[1, 0] = [134, 183, 89, 137, 98, 101, 106, 165, 148];
ModesProba[1, 1] = [72, 187, 100, 130, 157, 111, 32, 75, 80];
ModesProba[1, 2] = [66, 102, 167, 99, 74, 62, 40, 234, 128];
ModesProba[1, 3] = [41, 53, 9, 178, 241, 141, 26, 8, 107];
ModesProba[1, 4] = [74, 43, 26, 146, 73, 166, 49, 23, 157];
ModesProba[1, 5] = [65, 38, 105, 160, 51, 52, 31, 115, 128];
ModesProba[1, 6] = [104, 79, 12, 27, 217, 255, 87, 17, 7];
ModesProba[1, 7] = [87, 68, 71, 44, 114, 51, 15, 186, 23];
ModesProba[1, 8] = [47, 41, 14, 110, 182, 183, 21, 17, 194];
ModesProba[1, 9] = [66, 45, 25, 102, 197, 189, 23, 18, 22];
ModesProba[2, 0] = [88, 88, 147, 150, 42, 46, 45, 196, 205];
ModesProba[2, 1] = [43, 97, 183, 117, 85, 38, 35, 179, 61];
ModesProba[2, 2] = [39, 53, 200, 87, 26, 21, 43, 232, 171];
ModesProba[2, 3] = [56, 34, 51, 104, 114, 102, 29, 93, 77];
ModesProba[2, 4] = [39, 28, 85, 171, 58, 165, 90, 98, 64];
ModesProba[2, 5] = [34, 22, 116, 206, 23, 34, 43, 166, 73];
ModesProba[2, 6] = [107, 54, 32, 26, 51, 1, 81, 43, 31];
ModesProba[2, 7] = [68, 25, 106, 22, 64, 171, 36, 225, 114];
ModesProba[2, 8] = [34, 19, 21, 102, 132, 188, 16, 76, 124];
ModesProba[2, 9] = [62, 18, 78, 95, 85, 57, 50, 48, 51];
ModesProba[3, 0] = [193, 101, 35, 159, 215, 111, 89, 46, 111];
ModesProba[3, 1] = [60, 148, 31, 172, 219, 228, 21, 18, 111];
ModesProba[3, 2] = [112, 113, 77, 85, 179, 255, 38, 120, 114];
ModesProba[3, 3] = [40, 42, 1, 196, 245, 209, 10, 25, 109];
ModesProba[3, 4] = [88, 43, 29, 140, 166, 213, 37, 43, 154];
ModesProba[3, 5] = [61, 63, 30, 155, 67, 45, 68, 1, 209];
ModesProba[3, 6] = [100, 80, 8, 43, 154, 1, 51, 26, 71];
ModesProba[3, 7] = [142, 78, 78, 16, 255, 128, 34, 197, 171];
ModesProba[3, 8] = [41, 40, 5, 102, 211, 183, 4, 1, 221];
ModesProba[3, 9] = [51, 50, 17, 168, 209, 192, 23, 25, 82];
ModesProba[4, 0] = [138, 31, 36, 171, 27, 166, 38, 44, 229];
ModesProba[4, 1] = [67, 87, 58, 169, 82, 115, 26, 59, 179];
ModesProba[4, 2] = [63, 59, 90, 180, 59, 166, 93, 73, 154];
ModesProba[4, 3] = [40, 40, 21, 116, 143, 209, 34, 39, 175];
ModesProba[4, 4] = [47, 15, 16, 183, 34, 223, 49, 45, 183];
ModesProba[4, 5] = [46, 17, 33, 183, 6, 98, 15, 32, 183];
ModesProba[4, 6] = [57, 46, 22, 24, 128, 1, 54, 17, 37];
ModesProba[4, 7] = [65, 32, 73, 115, 28, 128, 23, 128, 205];
ModesProba[4, 8] = [40, 3, 9, 115, 51, 192, 18, 6, 223];
ModesProba[4, 9] = [87, 37, 9, 115, 59, 77, 64, 21, 47];
ModesProba[5, 0] = [104, 55, 44, 218, 9, 54, 53, 130, 226];
ModesProba[5, 1] = [64, 90, 70, 205, 40, 41, 23, 26, 57];
ModesProba[5, 2] = [54, 57, 112, 184, 5, 41, 38, 166, 213];
ModesProba[5, 3] = [30, 34, 26, 133, 152, 116, 10, 32, 134];
ModesProba[5, 4] = [39, 19, 53, 221, 26, 114, 32, 73, 255];
ModesProba[5, 5] = [31, 9, 65, 234, 2, 15, 1, 118, 73];
ModesProba[5, 6] = [75, 32, 12, 51, 192, 255, 160, 43, 51];
ModesProba[5, 7] = [88, 31, 35, 67, 102, 85, 55, 186, 85];
ModesProba[5, 8] = [56, 21, 23, 111, 59, 205, 45, 37, 192];
ModesProba[5, 9] = [55, 38, 70, 124, 73, 102, 1, 34, 98];
ModesProba[6, 0] = [125, 98, 42, 88, 104, 85, 117, 175, 82];
ModesProba[6, 1] = [95, 84, 53, 89, 128, 100, 113, 101, 45];
ModesProba[6, 2] = [75, 79, 123, 47, 51, 128, 81, 171, 1];
ModesProba[6, 3] = [57, 17, 5, 71, 102, 57, 53, 41, 49];
ModesProba[6, 4] = [38, 33, 13, 121, 57, 73, 26, 1, 85];
ModesProba[6, 5] = [41, 10, 67, 138, 77, 110, 90, 47, 114];
ModesProba[6, 6] = [115, 21, 2, 10, 102, 255, 166, 23, 6];
ModesProba[6, 7] = [101, 29, 16, 10, 85, 128, 101, 196, 26];
ModesProba[6, 8] = [57, 18, 10, 102, 102, 213, 34, 20, 43];
ModesProba[6, 9] = [117, 20, 15, 36, 163, 128, 68, 1, 26];
ModesProba[7, 0] = [102, 61, 71, 37, 34, 53, 31, 243, 192];
ModesProba[7, 1] = [69, 60, 71, 38, 73, 119, 28, 222, 37];
ModesProba[7, 2] = [68, 45, 128, 34, 1, 47, 11, 245, 171];
ModesProba[7, 3] = [62, 17, 19, 70, 146, 85, 55, 62, 70];
ModesProba[7, 4] = [37, 43, 37, 154, 100, 163, 85, 160, 1];
ModesProba[7, 5] = [63, 9, 92, 136, 28, 64, 32, 201, 85];
ModesProba[7, 6] = [75, 15, 9, 9, 64, 255, 184, 119, 16];
ModesProba[7, 7] = [86, 6, 28, 5, 64, 255, 25, 248, 1];
ModesProba[7, 8] = [56, 8, 17, 132, 137, 255, 55, 116, 128];
ModesProba[7, 9] = [58, 15, 20, 82, 135, 57, 26, 121, 40];
ModesProba[8, 0] = [164, 50, 31, 137, 154, 133, 25, 35, 218];
ModesProba[8, 1] = [51, 103, 44, 131, 131, 123, 31, 6, 158];
ModesProba[8, 2] = [86, 40, 64, 135, 148, 224, 45, 183, 128];
ModesProba[8, 3] = [22, 26, 17, 131, 240, 154, 14, 1, 209];
ModesProba[8, 4] = [45, 16, 21, 91, 64, 222, 7, 1, 197];
ModesProba[8, 5] = [56, 21, 39, 155, 60, 138, 23, 102, 213];
ModesProba[8, 6] = [83, 12, 13, 54, 192, 255, 68, 47, 28];
ModesProba[8, 7] = [85, 26, 85, 85, 128, 128, 32, 146, 171];
ModesProba[8, 8] = [18, 11, 7, 63, 144, 171, 4, 4, 246];
ModesProba[8, 9] = [35, 27, 10, 146, 174, 171, 12, 26, 128];
ModesProba[9, 0] = [190, 80, 35, 99, 180, 80, 126, 54, 45];
ModesProba[9, 1] = [85, 126, 47, 87, 176, 51, 41, 20, 32];
ModesProba[9, 2] = [101, 75, 128, 139, 118, 146, 116, 128, 85];
ModesProba[9, 3] = [56, 41, 15, 176, 236, 85, 37, 9, 62];
ModesProba[9, 4] = [71, 30, 17, 119, 118, 255, 17, 18, 138];
ModesProba[9, 5] = [101, 38, 60, 138, 55, 70, 43, 26, 142];
ModesProba[9, 6] = [146, 36, 19, 30, 171, 255, 97, 27, 20];
ModesProba[9, 7] = [138, 45, 61, 62, 219, 1, 81, 188, 64];
ModesProba[9, 8] = [32, 41, 20, 117, 151, 142, 20, 21, 163];
ModesProba[9, 9] = [112, 19, 12, 61, 195, 128, 48, 4, 24];
}
private static void InitializeFixedCostsI4()
{
Vp8FixedCostsI4[0, 0] = new short[] { 40, 1151, 1723, 1874, 2103, 2019, 1628, 1777, 2226, 2137 };
Vp8FixedCostsI4[0, 1] = new short[] { 192, 469, 1296, 1308, 1849, 1794, 1781, 1703, 1713, 1522 };
Vp8FixedCostsI4[0, 2] = new short[] { 142, 910, 762, 1684, 1849, 1576, 1460, 1305, 1801, 1657 };
Vp8FixedCostsI4[0, 3] = new short[] { 559, 641, 1370, 421, 1182, 1569, 1612, 1725, 863, 1007 };
Vp8FixedCostsI4[0, 4] = new short[] { 299, 1059, 1256, 1108, 636, 1068, 1581, 1883, 869, 1142 };
Vp8FixedCostsI4[0, 5] = new short[] { 277, 1111, 707, 1362, 1089, 672, 1603, 1541, 1545, 1291 };
Vp8FixedCostsI4[0, 6] = new short[] { 214, 781, 1609, 1303, 1632, 2229, 726, 1560, 1713, 918 };
Vp8FixedCostsI4[0, 7] = new short[] { 152, 1037, 1046, 1759, 1983, 2174, 1358, 742, 1740, 1390 };
Vp8FixedCostsI4[0, 8] = new short[] { 512, 1046, 1420, 753, 752, 1297, 1486, 1613, 460, 1207 };
Vp8FixedCostsI4[0, 9] = new short[] { 424, 827, 1362, 719, 1462, 1202, 1199, 1476, 1199, 538 };
Vp8FixedCostsI4[1, 0] = new short[] { 240, 402, 1134, 1491, 1659, 1505, 1517, 1555, 1979, 2099 };
Vp8FixedCostsI4[1, 1] = new short[] { 467, 242, 960, 1232, 1714, 1620, 1834, 1570, 1676, 1391 };
Vp8FixedCostsI4[1, 2] = new short[] { 500, 455, 463, 1507, 1699, 1282, 1564, 982, 2114, 2114 };
Vp8FixedCostsI4[1, 3] = new short[] { 672, 643, 1372, 331, 1589, 1667, 1453, 1938, 996, 876 };
Vp8FixedCostsI4[1, 4] = new short[] { 458, 783, 1037, 911, 738, 968, 1165, 1518, 859, 1033 };
Vp8FixedCostsI4[1, 5] = new short[] { 504, 815, 504, 1139, 1219, 719, 1506, 1085, 1268, 1268 };
Vp8FixedCostsI4[1, 6] = new short[] { 333, 630, 1445, 1239, 1883, 3672, 799, 1548, 1865, 598 };
Vp8FixedCostsI4[1, 7] = new short[] { 399, 644, 746, 1342, 1856, 1350, 1493, 613, 1855, 1015 };
Vp8FixedCostsI4[1, 8] = new short[] { 622, 749, 1205, 608, 1066, 1408, 1290, 1406, 546, 971 };
Vp8FixedCostsI4[1, 9] = new short[] { 500, 753, 1041, 668, 1230, 1617, 1297, 1425, 1383, 523 };
Vp8FixedCostsI4[2, 0] = new short[] { 394, 553, 523, 1502, 1536, 981, 1608, 1142, 1666, 2181 };
Vp8FixedCostsI4[2, 1] = new short[] { 655, 430, 375, 1411, 1861, 1220, 1677, 1135, 1978, 1553 };
Vp8FixedCostsI4[2, 2] = new short[] { 690, 640, 245, 1954, 2070, 1194, 1528, 982, 1972, 2232 };
Vp8FixedCostsI4[2, 3] = new short[] { 559, 834, 741, 867, 1131, 980, 1225, 852, 1092, 784 };
Vp8FixedCostsI4[2, 4] = new short[] { 690, 875, 516, 959, 673, 894, 1056, 1190, 1528, 1126 };
Vp8FixedCostsI4[2, 5] = new short[] { 740, 951, 384, 1277, 1177, 492, 1579, 1155, 1846, 1513 };
Vp8FixedCostsI4[2, 6] = new short[] { 323, 775, 1062, 1776, 3062, 1274, 813, 1188, 1372, 655 };
Vp8FixedCostsI4[2, 7] = new short[] { 488, 971, 484, 1767, 1515, 1775, 1115, 503, 1539, 1461 };
Vp8FixedCostsI4[2, 8] = new short[] { 740, 1006, 998, 709, 851, 1230, 1337, 788, 741, 721 };
Vp8FixedCostsI4[2, 9] = new short[] { 522, 1073, 573, 1045, 1346, 887, 1046, 1146, 1203, 697 };
Vp8FixedCostsI4[3, 0] = new short[] { 105, 864, 1442, 1009, 1934, 1840, 1519, 1920, 1673, 1579 };
Vp8FixedCostsI4[3, 1] = new short[] { 534, 305, 1193, 683, 1388, 2164, 1802, 1894, 1264, 1170 };
Vp8FixedCostsI4[3, 2] = new short[] { 305, 518, 877, 1108, 1426, 3215, 1425, 1064, 1320, 1242 };
Vp8FixedCostsI4[3, 3] = new short[] { 683, 732, 1927, 257, 1493, 2048, 1858, 1552, 1055, 947 };
Vp8FixedCostsI4[3, 4] = new short[] { 394, 814, 1024, 660, 959, 1556, 1282, 1289, 893, 1047 };
Vp8FixedCostsI4[3, 5] = new short[] { 528, 615, 996, 940, 1201, 635, 1094, 2515, 803, 1358 };
Vp8FixedCostsI4[3, 6] = new short[] { 347, 614, 1609, 1187, 3133, 1345, 1007, 1339, 1017, 667 };
Vp8FixedCostsI4[3, 7] = new short[] { 218, 740, 878, 1605, 3650, 3650, 1345, 758, 1357, 1617 };
Vp8FixedCostsI4[3, 8] = new short[] { 672, 750, 1541, 558, 1257, 1599, 1870, 2135, 402, 1087 };
Vp8FixedCostsI4[3, 9] = new short[] { 592, 684, 1161, 430, 1092, 1497, 1475, 1489, 1095, 822 };
Vp8FixedCostsI4[4, 0] = new short[] { 228, 1056, 1059, 1368, 752, 982, 1512, 1518, 987, 1782 };
Vp8FixedCostsI4[4, 1] = new short[] { 494, 514, 818, 942, 965, 892, 1610, 1356, 1048, 1363 };
Vp8FixedCostsI4[4, 2] = new short[] { 512, 648, 591, 1042, 761, 991, 1196, 1454, 1309, 1463 };
Vp8FixedCostsI4[4, 3] = new short[] { 683, 749, 1043, 676, 841, 1396, 1133, 1138, 654, 939 };
Vp8FixedCostsI4[4, 4] = new short[] { 622, 1101, 1126, 994, 361, 1077, 1203, 1318, 877, 1219 };
Vp8FixedCostsI4[4, 5] = new short[] { 631, 1068, 857, 1650, 651, 477, 1650, 1419, 828, 1170 };
Vp8FixedCostsI4[4, 6] = new short[] { 555, 727, 1068, 1335, 3127, 1339, 820, 1331, 1077, 429 };
Vp8FixedCostsI4[4, 7] = new short[] { 504, 879, 624, 1398, 889, 889, 1392, 808, 891, 1406 };
Vp8FixedCostsI4[4, 8] = new short[] { 683, 1602, 1289, 977, 578, 983, 1280, 1708, 406, 1122 };
Vp8FixedCostsI4[4, 9] = new short[] { 399, 865, 1433, 1070, 1072, 764, 968, 1477, 1223, 678 };
Vp8FixedCostsI4[5, 0] = new short[] { 333, 760, 935, 1638, 1010, 529, 1646, 1410, 1472, 2219 };
Vp8FixedCostsI4[5, 1] = new short[] { 512, 494, 750, 1160, 1215, 610, 1870, 1868, 1628, 1169 };
Vp8FixedCostsI4[5, 2] = new short[] { 572, 646, 492, 1934, 1208, 603, 1580, 1099, 1398, 1995 };
Vp8FixedCostsI4[5, 3] = new short[] { 786, 789, 942, 581, 1018, 951, 1599, 1207, 731, 768 };
Vp8FixedCostsI4[5, 4] = new short[] { 690, 1015, 672, 1078, 582, 504, 1693, 1438, 1108, 2897 };
Vp8FixedCostsI4[5, 5] = new short[] { 768, 1267, 571, 2005, 1243, 244, 2881, 1380, 1786, 1453 };
Vp8FixedCostsI4[5, 6] = new short[] { 452, 899, 1293, 903, 1311, 3100, 465, 1311, 1319, 813 };
Vp8FixedCostsI4[5, 7] = new short[] { 394, 927, 942, 1103, 1358, 1104, 946, 593, 1363, 1109 };
Vp8FixedCostsI4[5, 8] = new short[] { 559, 1005, 1007, 1016, 658, 1173, 1021, 1164, 623, 1028 };
Vp8FixedCostsI4[5, 9] = new short[] { 564, 796, 632, 1005, 1014, 863, 2316, 1268, 938, 764 };
Vp8FixedCostsI4[6, 0] = new short[] { 266, 606, 1098, 1228, 1497, 1243, 948, 1030, 1734, 1461 };
Vp8FixedCostsI4[6, 1] = new short[] { 366, 585, 901, 1060, 1407, 1247, 876, 1134, 1620, 1054 };
Vp8FixedCostsI4[6, 2] = new short[] { 452, 565, 542, 1729, 1479, 1479, 1016, 886, 2938, 1150 };
Vp8FixedCostsI4[6, 3] = new short[] { 555, 1088, 1533, 950, 1354, 895, 834, 1019, 1021, 496 };
Vp8FixedCostsI4[6, 4] = new short[] { 704, 815, 1193, 971, 973, 640, 1217, 2214, 832, 578 };
Vp8FixedCostsI4[6, 5] = new short[] { 672, 1245, 579, 871, 875, 774, 872, 1273, 1027, 949 };
Vp8FixedCostsI4[6, 6] = new short[] { 296, 1134, 2050, 1784, 1636, 3425, 442, 1550, 2076, 722 };
Vp8FixedCostsI4[6, 7] = new short[] { 342, 982, 1259, 1846, 1848, 1848, 622, 568, 1847, 1052 };
Vp8FixedCostsI4[6, 8] = new short[] { 555, 1064, 1304, 828, 746, 1343, 1075, 1329, 1078, 494 };
Vp8FixedCostsI4[6, 9] = new short[] { 288, 1167, 1285, 1174, 1639, 1639, 833, 2254, 1304, 509 };
Vp8FixedCostsI4[7, 0] = new short[] { 342, 719, 767, 1866, 1757, 1270, 1246, 550, 1746, 2151 };
Vp8FixedCostsI4[7, 1] = new short[] { 483, 653, 694, 1509, 1459, 1410, 1218, 507, 1914, 1266 };
Vp8FixedCostsI4[7, 2] = new short[] { 488, 757, 447, 2979, 1813, 1268, 1654, 539, 1849, 2109 };
Vp8FixedCostsI4[7, 3] = new short[] { 522, 1097, 1085, 851, 1365, 1111, 851, 901, 961, 605 };
Vp8FixedCostsI4[7, 4] = new short[] { 709, 716, 841, 728, 736, 945, 941, 862, 2845, 1057 };
Vp8FixedCostsI4[7, 5] = new short[] { 512, 1323, 500, 1336, 1083, 681, 1342, 717, 1604, 1350 };
Vp8FixedCostsI4[7, 6] = new short[] { 452, 1155, 1372, 1900, 1501, 3290, 311, 944, 1919, 922 };
Vp8FixedCostsI4[7, 7] = new short[] { 403, 1520, 977, 2132, 1733, 3522, 1076, 276, 3335, 1547 };
Vp8FixedCostsI4[7, 8] = new short[] { 559, 1374, 1101, 615, 673, 2462, 974, 795, 984, 984 };
Vp8FixedCostsI4[7, 9] = new short[] { 547, 1122, 1062, 812, 1410, 951, 1140, 622, 1268, 651 };
Vp8FixedCostsI4[8, 0] = new short[] { 165, 982, 1235, 938, 1334, 1366, 1659, 1578, 964, 1612 };
Vp8FixedCostsI4[8, 1] = new short[] { 592, 422, 925, 847, 1139, 1112, 1387, 2036, 861, 1041 };
Vp8FixedCostsI4[8, 2] = new short[] { 403, 837, 732, 770, 941, 1658, 1250, 809, 1407, 1407 };
Vp8FixedCostsI4[8, 3] = new short[] { 896, 874, 1071, 381, 1568, 1722, 1437, 2192, 480, 1035 };
Vp8FixedCostsI4[8, 4] = new short[] { 640, 1098, 1012, 1032, 684, 1382, 1581, 2106, 416, 865 };
Vp8FixedCostsI4[8, 5] = new short[] { 559, 1005, 819, 914, 710, 770, 1418, 920, 838, 1435 };
Vp8FixedCostsI4[8, 6] = new short[] { 415, 1258, 1245, 870, 1278, 3067, 770, 1021, 1287, 522 };
Vp8FixedCostsI4[8, 7] = new short[] { 406, 990, 601, 1009, 1265, 1265, 1267, 759, 1017, 1277 };
Vp8FixedCostsI4[8, 8] = new short[] { 968, 1182, 1329, 788, 1032, 1292, 1705, 1714, 203, 1403 };
Vp8FixedCostsI4[8, 9] = new short[] { 732, 877, 1279, 471, 901, 1161, 1545, 1294, 755, 755 };
Vp8FixedCostsI4[9, 0] = new short[] { 111, 931, 1378, 1185, 1933, 1648, 1148, 1714, 1873, 1307 };
Vp8FixedCostsI4[9, 1] = new short[] { 406, 414, 1030, 1023, 1910, 1404, 1313, 1647, 1509, 793 };
Vp8FixedCostsI4[9, 2] = new short[] { 342, 640, 575, 1088, 1241, 1349, 1161, 1350, 1756, 1502 };
Vp8FixedCostsI4[9, 3] = new short[] { 559, 766, 1185, 357, 1682, 1428, 1329, 1897, 1219, 802 };
Vp8FixedCostsI4[9, 4] = new short[] { 473, 909, 1164, 771, 719, 2508, 1427, 1432, 722, 782 };
Vp8FixedCostsI4[9, 5] = new short[] { 342, 892, 785, 1145, 1150, 794, 1296, 1550, 973, 1057 };
Vp8FixedCostsI4[9, 6] = new short[] { 208, 1036, 1326, 1343, 1606, 3395, 815, 1455, 1618, 712 };
Vp8FixedCostsI4[9, 7] = new short[] { 228, 928, 890, 1046, 3499, 1711, 994, 829, 1720, 1318 };
Vp8FixedCostsI4[9, 8] = new short[] { 768, 724, 1058, 636, 991, 1075, 1319, 1324, 616, 825 };
Vp8FixedCostsI4[9, 9] = new short[] { 305, 1167, 1358, 899, 1587, 1587, 987, 1988, 1332, 501 };
Vp8FixedCostsI4[0, 0] = [40, 1151, 1723, 1874, 2103, 2019, 1628, 1777, 2226, 2137];
Vp8FixedCostsI4[0, 1] = [192, 469, 1296, 1308, 1849, 1794, 1781, 1703, 1713, 1522];
Vp8FixedCostsI4[0, 2] = [142, 910, 762, 1684, 1849, 1576, 1460, 1305, 1801, 1657];
Vp8FixedCostsI4[0, 3] = [559, 641, 1370, 421, 1182, 1569, 1612, 1725, 863, 1007];
Vp8FixedCostsI4[0, 4] = [299, 1059, 1256, 1108, 636, 1068, 1581, 1883, 869, 1142];
Vp8FixedCostsI4[0, 5] = [277, 1111, 707, 1362, 1089, 672, 1603, 1541, 1545, 1291];
Vp8FixedCostsI4[0, 6] = [214, 781, 1609, 1303, 1632, 2229, 726, 1560, 1713, 918];
Vp8FixedCostsI4[0, 7] = [152, 1037, 1046, 1759, 1983, 2174, 1358, 742, 1740, 1390];
Vp8FixedCostsI4[0, 8] = [512, 1046, 1420, 753, 752, 1297, 1486, 1613, 460, 1207];
Vp8FixedCostsI4[0, 9] = [424, 827, 1362, 719, 1462, 1202, 1199, 1476, 1199, 538];
Vp8FixedCostsI4[1, 0] = [240, 402, 1134, 1491, 1659, 1505, 1517, 1555, 1979, 2099];
Vp8FixedCostsI4[1, 1] = [467, 242, 960, 1232, 1714, 1620, 1834, 1570, 1676, 1391];
Vp8FixedCostsI4[1, 2] = [500, 455, 463, 1507, 1699, 1282, 1564, 982, 2114, 2114];
Vp8FixedCostsI4[1, 3] = [672, 643, 1372, 331, 1589, 1667, 1453, 1938, 996, 876];
Vp8FixedCostsI4[1, 4] = [458, 783, 1037, 911, 738, 968, 1165, 1518, 859, 1033];
Vp8FixedCostsI4[1, 5] = [504, 815, 504, 1139, 1219, 719, 1506, 1085, 1268, 1268];
Vp8FixedCostsI4[1, 6] = [333, 630, 1445, 1239, 1883, 3672, 799, 1548, 1865, 598];
Vp8FixedCostsI4[1, 7] = [399, 644, 746, 1342, 1856, 1350, 1493, 613, 1855, 1015];
Vp8FixedCostsI4[1, 8] = [622, 749, 1205, 608, 1066, 1408, 1290, 1406, 546, 971];
Vp8FixedCostsI4[1, 9] = [500, 753, 1041, 668, 1230, 1617, 1297, 1425, 1383, 523];
Vp8FixedCostsI4[2, 0] = [394, 553, 523, 1502, 1536, 981, 1608, 1142, 1666, 2181];
Vp8FixedCostsI4[2, 1] = [655, 430, 375, 1411, 1861, 1220, 1677, 1135, 1978, 1553];
Vp8FixedCostsI4[2, 2] = [690, 640, 245, 1954, 2070, 1194, 1528, 982, 1972, 2232];
Vp8FixedCostsI4[2, 3] = [559, 834, 741, 867, 1131, 980, 1225, 852, 1092, 784];
Vp8FixedCostsI4[2, 4] = [690, 875, 516, 959, 673, 894, 1056, 1190, 1528, 1126];
Vp8FixedCostsI4[2, 5] = [740, 951, 384, 1277, 1177, 492, 1579, 1155, 1846, 1513];
Vp8FixedCostsI4[2, 6] = [323, 775, 1062, 1776, 3062, 1274, 813, 1188, 1372, 655];
Vp8FixedCostsI4[2, 7] = [488, 971, 484, 1767, 1515, 1775, 1115, 503, 1539, 1461];
Vp8FixedCostsI4[2, 8] = [740, 1006, 998, 709, 851, 1230, 1337, 788, 741, 721];
Vp8FixedCostsI4[2, 9] = [522, 1073, 573, 1045, 1346, 887, 1046, 1146, 1203, 697];
Vp8FixedCostsI4[3, 0] = [105, 864, 1442, 1009, 1934, 1840, 1519, 1920, 1673, 1579];
Vp8FixedCostsI4[3, 1] = [534, 305, 1193, 683, 1388, 2164, 1802, 1894, 1264, 1170];
Vp8FixedCostsI4[3, 2] = [305, 518, 877, 1108, 1426, 3215, 1425, 1064, 1320, 1242];
Vp8FixedCostsI4[3, 3] = [683, 732, 1927, 257, 1493, 2048, 1858, 1552, 1055, 947];
Vp8FixedCostsI4[3, 4] = [394, 814, 1024, 660, 959, 1556, 1282, 1289, 893, 1047];
Vp8FixedCostsI4[3, 5] = [528, 615, 996, 940, 1201, 635, 1094, 2515, 803, 1358];
Vp8FixedCostsI4[3, 6] = [347, 614, 1609, 1187, 3133, 1345, 1007, 1339, 1017, 667];
Vp8FixedCostsI4[3, 7] = [218, 740, 878, 1605, 3650, 3650, 1345, 758, 1357, 1617];
Vp8FixedCostsI4[3, 8] = [672, 750, 1541, 558, 1257, 1599, 1870, 2135, 402, 1087];
Vp8FixedCostsI4[3, 9] = [592, 684, 1161, 430, 1092, 1497, 1475, 1489, 1095, 822];
Vp8FixedCostsI4[4, 0] = [228, 1056, 1059, 1368, 752, 982, 1512, 1518, 987, 1782];
Vp8FixedCostsI4[4, 1] = [494, 514, 818, 942, 965, 892, 1610, 1356, 1048, 1363];
Vp8FixedCostsI4[4, 2] = [512, 648, 591, 1042, 761, 991, 1196, 1454, 1309, 1463];
Vp8FixedCostsI4[4, 3] = [683, 749, 1043, 676, 841, 1396, 1133, 1138, 654, 939];
Vp8FixedCostsI4[4, 4] = [622, 1101, 1126, 994, 361, 1077, 1203, 1318, 877, 1219];
Vp8FixedCostsI4[4, 5] = [631, 1068, 857, 1650, 651, 477, 1650, 1419, 828, 1170];
Vp8FixedCostsI4[4, 6] = [555, 727, 1068, 1335, 3127, 1339, 820, 1331, 1077, 429];
Vp8FixedCostsI4[4, 7] = [504, 879, 624, 1398, 889, 889, 1392, 808, 891, 1406];
Vp8FixedCostsI4[4, 8] = [683, 1602, 1289, 977, 578, 983, 1280, 1708, 406, 1122];
Vp8FixedCostsI4[4, 9] = [399, 865, 1433, 1070, 1072, 764, 968, 1477, 1223, 678];
Vp8FixedCostsI4[5, 0] = [333, 760, 935, 1638, 1010, 529, 1646, 1410, 1472, 2219];
Vp8FixedCostsI4[5, 1] = [512, 494, 750, 1160, 1215, 610, 1870, 1868, 1628, 1169];
Vp8FixedCostsI4[5, 2] = [572, 646, 492, 1934, 1208, 603, 1580, 1099, 1398, 1995];
Vp8FixedCostsI4[5, 3] = [786, 789, 942, 581, 1018, 951, 1599, 1207, 731, 768];
Vp8FixedCostsI4[5, 4] = [690, 1015, 672, 1078, 582, 504, 1693, 1438, 1108, 2897];
Vp8FixedCostsI4[5, 5] = [768, 1267, 571, 2005, 1243, 244, 2881, 1380, 1786, 1453];
Vp8FixedCostsI4[5, 6] = [452, 899, 1293, 903, 1311, 3100, 465, 1311, 1319, 813];
Vp8FixedCostsI4[5, 7] = [394, 927, 942, 1103, 1358, 1104, 946, 593, 1363, 1109];
Vp8FixedCostsI4[5, 8] = [559, 1005, 1007, 1016, 658, 1173, 1021, 1164, 623, 1028];
Vp8FixedCostsI4[5, 9] = [564, 796, 632, 1005, 1014, 863, 2316, 1268, 938, 764];
Vp8FixedCostsI4[6, 0] = [266, 606, 1098, 1228, 1497, 1243, 948, 1030, 1734, 1461];
Vp8FixedCostsI4[6, 1] = [366, 585, 901, 1060, 1407, 1247, 876, 1134, 1620, 1054];
Vp8FixedCostsI4[6, 2] = [452, 565, 542, 1729, 1479, 1479, 1016, 886, 2938, 1150];
Vp8FixedCostsI4[6, 3] = [555, 1088, 1533, 950, 1354, 895, 834, 1019, 1021, 496];
Vp8FixedCostsI4[6, 4] = [704, 815, 1193, 971, 973, 640, 1217, 2214, 832, 578];
Vp8FixedCostsI4[6, 5] = [672, 1245, 579, 871, 875, 774, 872, 1273, 1027, 949];
Vp8FixedCostsI4[6, 6] = [296, 1134, 2050, 1784, 1636, 3425, 442, 1550, 2076, 722];
Vp8FixedCostsI4[6, 7] = [342, 982, 1259, 1846, 1848, 1848, 622, 568, 1847, 1052];
Vp8FixedCostsI4[6, 8] = [555, 1064, 1304, 828, 746, 1343, 1075, 1329, 1078, 494];
Vp8FixedCostsI4[6, 9] = [288, 1167, 1285, 1174, 1639, 1639, 833, 2254, 1304, 509];
Vp8FixedCostsI4[7, 0] = [342, 719, 767, 1866, 1757, 1270, 1246, 550, 1746, 2151];
Vp8FixedCostsI4[7, 1] = [483, 653, 694, 1509, 1459, 1410, 1218, 507, 1914, 1266];
Vp8FixedCostsI4[7, 2] = [488, 757, 447, 2979, 1813, 1268, 1654, 539, 1849, 2109];
Vp8FixedCostsI4[7, 3] = [522, 1097, 1085, 851, 1365, 1111, 851, 901, 961, 605];
Vp8FixedCostsI4[7, 4] = [709, 716, 841, 728, 736, 945, 941, 862, 2845, 1057];
Vp8FixedCostsI4[7, 5] = [512, 1323, 500, 1336, 1083, 681, 1342, 717, 1604, 1350];
Vp8FixedCostsI4[7, 6] = [452, 1155, 1372, 1900, 1501, 3290, 311, 944, 1919, 922];
Vp8FixedCostsI4[7, 7] = [403, 1520, 977, 2132, 1733, 3522, 1076, 276, 3335, 1547];
Vp8FixedCostsI4[7, 8] = [559, 1374, 1101, 615, 673, 2462, 974, 795, 984, 984];
Vp8FixedCostsI4[7, 9] = [547, 1122, 1062, 812, 1410, 951, 1140, 622, 1268, 651];
Vp8FixedCostsI4[8, 0] = [165, 982, 1235, 938, 1334, 1366, 1659, 1578, 964, 1612];
Vp8FixedCostsI4[8, 1] = [592, 422, 925, 847, 1139, 1112, 1387, 2036, 861, 1041];
Vp8FixedCostsI4[8, 2] = [403, 837, 732, 770, 941, 1658, 1250, 809, 1407, 1407];
Vp8FixedCostsI4[8, 3] = [896, 874, 1071, 381, 1568, 1722, 1437, 2192, 480, 1035];
Vp8FixedCostsI4[8, 4] = [640, 1098, 1012, 1032, 684, 1382, 1581, 2106, 416, 865];
Vp8FixedCostsI4[8, 5] = [559, 1005, 819, 914, 710, 770, 1418, 920, 838, 1435];
Vp8FixedCostsI4[8, 6] = [415, 1258, 1245, 870, 1278, 3067, 770, 1021, 1287, 522];
Vp8FixedCostsI4[8, 7] = [406, 990, 601, 1009, 1265, 1265, 1267, 759, 1017, 1277];
Vp8FixedCostsI4[8, 8] = [968, 1182, 1329, 788, 1032, 1292, 1705, 1714, 203, 1403];
Vp8FixedCostsI4[8, 9] = [732, 877, 1279, 471, 901, 1161, 1545, 1294, 755, 755];
Vp8FixedCostsI4[9, 0] = [111, 931, 1378, 1185, 1933, 1648, 1148, 1714, 1873, 1307];
Vp8FixedCostsI4[9, 1] = [406, 414, 1030, 1023, 1910, 1404, 1313, 1647, 1509, 793];
Vp8FixedCostsI4[9, 2] = [342, 640, 575, 1088, 1241, 1349, 1161, 1350, 1756, 1502];
Vp8FixedCostsI4[9, 3] = [559, 766, 1185, 357, 1682, 1428, 1329, 1897, 1219, 802];
Vp8FixedCostsI4[9, 4] = [473, 909, 1164, 771, 719, 2508, 1427, 1432, 722, 782];
Vp8FixedCostsI4[9, 5] = [342, 892, 785, 1145, 1150, 794, 1296, 1550, 973, 1057];
Vp8FixedCostsI4[9, 6] = [208, 1036, 1326, 1343, 1606, 3395, 815, 1455, 1618, 712];
Vp8FixedCostsI4[9, 7] = [228, 928, 890, 1046, 3499, 1711, 994, 829, 1720, 1318];
Vp8FixedCostsI4[9, 8] = [768, 724, 1058, 636, 991, 1075, 1319, 1324, 616, 825];
Vp8FixedCostsI4[9, 9] = [305, 1167, 1358, 899, 1587, 1587, 987, 1988, 1332, 501];
}
}

12
src/ImageSharp/Formats/_Generated/_Formats.ttinclude

@ -3,7 +3,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
<#+
private static readonly string[] formats = new []{
private static readonly string[] formats = [
"Bmp",
"Cur",
"Gif",
@ -14,15 +14,15 @@
"Qoi",
"Tga",
"Tiff",
"Webp",
};
"Webp"
];
private static readonly string[] frameFormats = new []{
private static readonly string[] frameFormats = [
"Cur",
"Ico",
"Gif",
"Png",
"Tiff",
"Webp",
};
"Webp"
];
#>

2
src/ImageSharp/IO/ChunkedMemoryStream.cs

@ -387,7 +387,7 @@ internal sealed class ChunkedMemoryStream : Stream
private sealed class MemoryChunkBuffer : IDisposable
{
private readonly List<MemoryChunk> memoryChunks = new();
private readonly List<MemoryChunk> memoryChunks = [];
private readonly MemoryAllocator allocator;
private readonly int allocatorCapacity;
private bool isDisposed;

2
src/ImageSharp/ImageExtensions.cs

@ -179,6 +179,6 @@ public static partial class ImageExtensions
// Always available.
stream.TryGetBuffer(out ArraySegment<byte> buffer);
return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(buffer.Array ?? Array.Empty<byte>(), 0, (int)stream.Length)}";
return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(buffer.Array ?? [], 0, (int)stream.Length)}";
}
}

2
src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Memory.Internals;
internal partial class UniformUnmanagedMemoryPool : System.Runtime.ConstrainedExecution.CriticalFinalizerObject
{
private static int minTrimPeriodMilliseconds = int.MaxValue;
private static readonly List<WeakReference<UniformUnmanagedMemoryPool>> AllPools = new();
private static readonly List<WeakReference<UniformUnmanagedMemoryPool>> AllPools = [];
private static Timer? trimTimer;
private static readonly Stopwatch Stopwatch = Stopwatch.StartNew();

4
src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs

@ -97,7 +97,7 @@ internal abstract partial class MemoryGroup<T> : IMemoryGroup<T>, IDisposable
if (totalLengthInElements == 0)
{
IMemoryOwner<T>[] buffers0 = new IMemoryOwner<T>[1] { allocator.Allocate<T>(0, options) };
IMemoryOwner<T>[] buffers0 = [allocator.Allocate<T>(0, options)];
return new Owned(buffers0, 0, 0, true);
}
@ -142,7 +142,7 @@ internal abstract partial class MemoryGroup<T> : IMemoryGroup<T>, IDisposable
}
int length = buffer.Memory.Length;
IMemoryOwner<T>[] buffers = new IMemoryOwner<T>[1] { buffer };
IMemoryOwner<T>[] buffers = [buffer];
return new Owned(buffers, length, length, true);
}

14
src/ImageSharp/Metadata/Profiles/Exif/ExifConstants.cs

@ -7,21 +7,21 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif;
internal static class ExifConstants
{
public static ReadOnlySpan<byte> LittleEndianByteOrderMarker => new byte[]
{
public static ReadOnlySpan<byte> LittleEndianByteOrderMarker =>
[
(byte)'I',
(byte)'I',
0x2A,
0x00,
};
0x00
];
public static ReadOnlySpan<byte> BigEndianByteOrderMarker => new byte[]
{
public static ReadOnlySpan<byte> BigEndianByteOrderMarker =>
[
(byte)'M',
(byte)'M',
0x00,
0x2A
};
];
// UTF-8 is better than ASCII, UTF-8 encodes the ASCII codes the same way
public static Encoding DefaultEncoding => Encoding.UTF8;

2
src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs

@ -103,7 +103,7 @@ internal sealed partial class IccDataReader
public IccNamedColor ReadNamedColor(uint deviceCoordCount)
{
string name = this.ReadAsciiString(32);
ushort[] pcsCoord = { this.ReadUInt16(), this.ReadUInt16(), this.ReadUInt16() };
ushort[] pcsCoord = [this.ReadUInt16(), this.ReadUInt16(), this.ReadUInt16()];
ushort[] deviceCoord = new ushort[deviceCoordCount];
for (int i = 0; i < deviceCoordCount; i++)

2
src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs

@ -154,7 +154,7 @@ internal sealed partial class IccDataReader
double[][] values = new double[channelCount][];
for (int i = 0; i < channelCount; i++)
{
values[i] = new double[] { this.ReadUFix16(), this.ReadUFix16() };
values[i] = [this.ReadUFix16(), this.ReadUFix16()];
}
return new IccChromaticityTagDataEntry(values);

2
src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs

@ -115,7 +115,7 @@ internal sealed class IccReader
// A normal profile usually has 5-15 entries
if (tagCount > 100)
{
return Array.Empty<IccTagTableEntry>();
return [];
}
List<IccTagTableEntry> table = new((int)tagCount);

2
src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs

@ -71,7 +71,7 @@ internal sealed class IccWriter
// (Header size) + (entry count) + (nr of entries) * (size of table entry)
writer.SetIndex(128 + 4 + (entries.Length * 12));
List<IccTagTableEntry> table = new();
List<IccTagTableEntry> table = [];
foreach (IGrouping<IccTagDataEntry, IccTagDataEntry> group in grouped)
{
writer.WriteTagDataEntry(group.Key, out IccTagTableEntry tableEntry);

48
src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs

@ -112,33 +112,33 @@ internal sealed class IccChromaticityTagDataEntry : IccTagDataEntry, IEquatable<
switch (colorantType)
{
case IccColorantEncoding.EbuTech3213E:
return new[]
{
new[] { 0.640, 0.330 },
new[] { 0.290, 0.600 },
new[] { 0.150, 0.060 },
};
return
[
[0.640, 0.330],
[0.290, 0.600],
[0.150, 0.060]
];
case IccColorantEncoding.ItuRBt709_2:
return new[]
{
new[] { 0.640, 0.330 },
new[] { 0.300, 0.600 },
new[] { 0.150, 0.060 },
};
return
[
[0.640, 0.330],
[0.300, 0.600],
[0.150, 0.060]
];
case IccColorantEncoding.P22:
return new[]
{
new[] { 0.625, 0.340 },
new[] { 0.280, 0.605 },
new[] { 0.155, 0.070 },
};
return
[
[0.625, 0.340],
[0.280, 0.605],
[0.155, 0.070]
];
case IccColorantEncoding.SmpteRp145:
return new[]
{
new[] { 0.630, 0.340 },
new[] { 0.310, 0.595 },
new[] { 0.155, 0.070 },
};
return
[
[0.630, 0.340],
[0.310, 0.595],
[0.155, 0.070]
];
default:
throw new ArgumentException("Unrecognized colorant encoding");
}

10
src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs

@ -12,7 +12,7 @@ internal sealed class IccCurveTagDataEntry : IccTagDataEntry, IEquatable<IccCurv
/// Initializes a new instance of the <see cref="IccCurveTagDataEntry"/> class.
/// </summary>
public IccCurveTagDataEntry()
: this(Array.Empty<float>(), IccProfileTag.Unknown)
: this([], IccProfileTag.Unknown)
{
}
@ -21,7 +21,7 @@ internal sealed class IccCurveTagDataEntry : IccTagDataEntry, IEquatable<IccCurv
/// </summary>
/// <param name="gamma">Gamma value</param>
public IccCurveTagDataEntry(float gamma)
: this(new[] { gamma }, IccProfileTag.Unknown)
: this([gamma], IccProfileTag.Unknown)
{
}
@ -39,7 +39,7 @@ internal sealed class IccCurveTagDataEntry : IccTagDataEntry, IEquatable<IccCurv
/// </summary>
/// <param name="tagSignature">Tag Signature</param>
public IccCurveTagDataEntry(IccProfileTag tagSignature)
: this(Array.Empty<float>(), tagSignature)
: this([], tagSignature)
{
}
@ -49,7 +49,7 @@ internal sealed class IccCurveTagDataEntry : IccTagDataEntry, IEquatable<IccCurv
/// <param name="gamma">Gamma value</param>
/// <param name="tagSignature">Tag Signature</param>
public IccCurveTagDataEntry(float gamma, IccProfileTag tagSignature)
: this(new[] { gamma }, tagSignature)
: this([gamma], tagSignature)
{
}
@ -61,7 +61,7 @@ internal sealed class IccCurveTagDataEntry : IccTagDataEntry, IEquatable<IccCurv
public IccCurveTagDataEntry(float[] curveData, IccProfileTag tagSignature)
: base(IccTypeSignature.Curve, tagSignature)
{
this.CurveData = curveData ?? Array.Empty<float>();
this.CurveData = curveData ?? [];
}
/// <summary>

6
src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs

@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc;
/// </summary>
public sealed class IptcProfile : IDeepCloneable<IptcProfile>
{
private readonly Collection<IptcValue> values = new();
private readonly Collection<IptcValue> values = [];
private const byte IptcTagMarkerByte = 0x1c;
@ -67,7 +67,7 @@ public sealed class IptcProfile : IDeepCloneable<IptcProfile>
/// <summary>
/// Gets a byte array marking that UTF-8 encoding is used in application records.
/// </summary>
private static ReadOnlySpan<byte> CodedCharacterSetUtf8Value => new byte[] { 0x1B, 0x25, 0x47 }; // Uses C#'s optimization to refer to the data segment in the assembly directly, no allocation occurs.
private static ReadOnlySpan<byte> CodedCharacterSetUtf8Value => [0x1B, 0x25, 0x47]; // Uses C#'s optimization to refer to the data segment in the assembly directly, no allocation occurs.
/// <summary>
/// Gets the byte data of the IPTC profile.
@ -89,7 +89,7 @@ public sealed class IptcProfile : IDeepCloneable<IptcProfile>
/// <returns>The values found with the specified tag.</returns>
public List<IptcValue> GetValues(IptcTag tag)
{
List<IptcValue> iptcValues = new();
List<IptcValue> iptcValues = [];
foreach (IptcValue iptcValue in this.Values)
{
if (iptcValue.Tag == tag)

4
src/ImageSharp/Metadata/Profiles/IPTC/IptcValue.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc;
[DebuggerDisplay("{Tag} = {ToString(),nq} ({GetType().Name,nq})")]
public sealed class IptcValue : IDeepCloneable<IptcValue>
{
private byte[] data = Array.Empty<byte>();
private byte[] data = [];
private Encoding encoding;
internal IptcValue(IptcValue other)
@ -91,7 +91,7 @@ public sealed class IptcValue : IDeepCloneable<IptcValue>
{
if (string.IsNullOrEmpty(value))
{
this.data = Array.Empty<byte>();
this.data = [];
}
else
{

20
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude

@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
<#+
private static readonly string[] CommonPixelTypes =
{
"Argb32",
[
"Argb32",
"Abgr32",
"Bgr24",
"Bgra32",
@ -28,27 +28,27 @@ using SixLabors.ImageSharp.PixelFormats.Utils;
"Rgb48",
"Rgba64",
"Bgra5551"
};
];
private static readonly string[] OptimizedPixelTypes =
{
"Rgba32",
[
"Rgba32",
"Argb32",
"Abgr32",
"Bgra32",
"Rgb24",
"Bgr24"
};
];
// Types with Rgba32-combatable to/from Vector4 conversion
private static readonly string[] Rgba32CompatibleTypes =
{
"Argb32",
[
"Argb32",
"Abgr32",
"Bgra32",
"Rgb24",
"Bgr24"
};
];
void GenerateGenericConverterMethods(string pixelType)
{
@ -187,7 +187,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils;
var matching32BitTypes = OptimizedPixelTypes.Contains(pixelType) ?
OptimizedPixelTypes.Where(p => p != pixelType) :
Enumerable.Empty<string>();
[];
foreach (string destPixelType in matching32BitTypes)
{

7
src/ImageSharp/Processing/Processors/Convolution/Kernels/EdgeDetectorCompassKernel.cs

@ -152,9 +152,8 @@ public readonly struct EdgeDetectorCompassKernel : IEquatable<EdgeDetectorCompas
this.NorthEast);
internal DenseMatrix<float>[] Flatten() =>
new[]
{
this.North, this.NorthWest, this.West, this.SouthWest,
[
this.North, this.NorthWest, this.West, this.SouthWest,
this.South, this.SouthEast, this.East, this.NorthEast
};
];
}

36
src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs

@ -21,61 +21,57 @@ internal static class BokehBlurKernelDataProvider
/// <summary>
/// Gets the kernel scales to adjust the component values in each kernel
/// </summary>
private static float[] KernelScales { get; } = new[] { 1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f };
private static float[] KernelScales { get; } = [1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f];
/// <summary>
/// Gets the available bokeh blur kernel parameters
/// </summary>
private static Vector4[][] KernelComponents { get; } = new[]
{
private static Vector4[][] KernelComponents { get; } =
[
// 1 component
new[] { new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f) },
[new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f)],
// 2 components
new[]
{
[
new Vector4(0.886528f, 5.268909f, 0.411259f, -0.548794f),
new Vector4(1.960518f, 1.558213f, 0.513282f, 4.56111f)
},
],
// 3 components
new[]
{
[
new Vector4(2.17649f, 5.043495f, 1.621035f, -2.105439f),
new Vector4(1.019306f, 9.027613f, -0.28086f, -0.162882f),
new Vector4(2.81511f, 1.597273f, -0.366471f, 10.300301f)
},
],
// 4 components
new[]
{
[
new Vector4(4.338459f, 1.553635f, -5.767909f, 46.164397f),
new Vector4(3.839993f, 4.693183f, 9.795391f, -15.227561f),
new Vector4(2.791880f, 8.178137f, -3.048324f, 0.302959f),
new Vector4(1.342190f, 12.328289f, 0.010001f, 0.244650f)
},
],
// 5 components
new[]
{
[
new Vector4(4.892608f, 1.685979f, -22.356787f, 85.91246f),
new Vector4(4.71187f, 4.998496f, 35.918936f, -28.875618f),
new Vector4(4.052795f, 8.244168f, -13.212253f, -1.578428f),
new Vector4(2.929212f, 11.900859f, 0.507991f, 1.816328f),
new Vector4(1.512961f, 16.116382f, 0.138051f, -0.01f)
},
],
// 6 components
new[]
{
[
new Vector4(5.143778f, 2.079813f, -82.326596f, 111.231024f),
new Vector4(5.612426f, 6.153387f, 113.878661f, 58.004879f),
new Vector4(5.982921f, 9.802895f, 39.479083f, -162.028887f),
new Vector4(6.505167f, 11.059237f, -71.286026f, 95.027069f),
new Vector4(3.869579f, 14.81052f, 1.405746f, -3.704914f),
new Vector4(2.201904f, 19.032909f, -0.152784f, -0.107988f)
}
};
]
];
/// <summary>
/// Gets the bokeh blur kernel data for the specified parameters.

8
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs

@ -74,13 +74,13 @@ internal readonly unsafe struct ResizeKernel
float* bufferEnd = bufferStart + (this.Length & ~3);
Vector256<float> result256_0 = Vector256<float>.Zero;
Vector256<float> result256_1 = Vector256<float>.Zero;
ReadOnlySpan<byte> maskBytes = new byte[]
{
ReadOnlySpan<byte> maskBytes =
[
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 1, 0, 0, 0,
1, 0, 0, 0, 1, 0, 0, 0,
};
1, 0, 0, 0, 1, 0, 0, 0
];
Vector256<int> mask = Unsafe.ReadUnaligned<Vector256<int>>(ref MemoryMarshal.GetReference(maskBytes));
while (bufferStart < bufferEnd)

3
tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

@ -73,7 +73,8 @@ public class FromVector4Rgba32 : FromVector4<Rgba32>
SimdUtils.HwIntrinsics.NormalizedFloatToByteSaturate(sBytes, dFloats);
}
private static ReadOnlySpan<byte> PermuteMaskDeinterleave8x32 => new byte[] { 0, 0, 0, 0, 4, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 3, 0, 0, 0, 7, 0, 0, 0 };
private static ReadOnlySpan<byte> PermuteMaskDeinterleave8x32 => [0, 0, 0, 0, 4, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 3, 0, 0, 0, 7, 0, 0, 0
];
[Benchmark]
public void UseAvx2_Grouped()

2
tests/ImageSharp.Benchmarks/Codecs/Bmp/EncodeBmpMultiple.cs

@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs;
[Config(typeof(Config.Short))]
public class EncodeBmpMultiple : MultiImageBenchmarkBase.WithImagesPreloaded
{
protected override IEnumerable<string> InputImageSubfoldersOrFiles => new[] { "Bmp/", "Jpg/baseline" };
protected override IEnumerable<string> InputImageSubfoldersOrFiles => ["Bmp/", "Jpg/baseline"];
[Benchmark(Description = "EncodeBmpMultiple - ImageSharp")]
public void EncodeBmpImageSharp()

2
tests/ImageSharp.Benchmarks/Codecs/Gif/EncodeGifMultiple.cs

@ -15,7 +15,7 @@ public class EncodeGifMultiple : MultiImageBenchmarkBase.WithImagesPreloaded
[Params(InputImageCategory.AllImages)]
public override InputImageCategory InputCategory { get; set; }
protected override IEnumerable<string> InputImageSubfoldersOrFiles => new[] { "Gif/" };
protected override IEnumerable<string> InputImageSubfoldersOrFiles => ["Gif/"];
[Benchmark(Description = "EncodeGifMultiple - ImageSharp")]
public void EncodeGifImageSharp()

2
tests/ImageSharp.Benchmarks/General/BasicMath/ClampFloat.cs

@ -10,7 +10,7 @@ public class ClampFloat
{
private readonly float min = -1.5f;
private readonly float max = 2.5f;
private static readonly float[] Values = { -10, -5, -3, -1.5f, -0.5f, 0f, 1f, 1.5f, 2.5f, 3, 10 };
private static readonly float[] Values = [-10, -5, -3, -1.5f, -0.5f, 0f, 1f, 1.5f, 2.5f, 3, 10];
[Benchmark(Baseline = true)]
public float UsingMathF()

2
tests/ImageSharp.Benchmarks/General/BasicMath/ClampVector4.cs

@ -11,7 +11,7 @@ public class ClampVector4
{
private readonly float min = -1.5f;
private readonly float max = 2.5f;
private static readonly float[] Values = { -10, -5, -3, -1.5f, -0.5f, 0f, 1f, 1.5f, 2.5f, 3, 10 };
private static readonly float[] Values = [-10, -5, -3, -1.5f, -0.5f, 0f, 1f, 1.5f, 2.5f, 3, 10];
[Benchmark(Baseline = true)]
public Vector4 UsingVectorClamp()

4
tests/ImageSharp.Benchmarks/LoadResizeSave/LoadResizeSaveStressBenchmarks.cs

@ -34,12 +34,12 @@ public class LoadResizeSaveStressBenchmarks
}
public int[] ParallelismValues { get; } =
{
[
// Environment.ProcessorCount,
// Environment.ProcessorCount / 2,
// Environment.ProcessorCount / 4,
1
};
];
[Benchmark]
[ArgumentsSource(nameof(ParallelismValues))]

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

@ -53,7 +53,7 @@ public class LoadResizeSaveStressRunner
public int ThumbnailSize { get; set; } = 150;
private static readonly string[] ProgressiveFiles =
{
[
"ancyloscelis-apiformis-m-paraguay-face_2014-08-08-095255-zs-pmax_15046500892_o.jpg",
"acanthopus-excellens-f-face-brasil_2014-08-06-132105-zs-pmax_14792513890_o.jpg",
"bee-ceratina-monster-f-ukraine-face_2014-08-09-123342-zs-pmax_15068816101_o.jpg",
@ -84,8 +84,8 @@ public class LoadResizeSaveStressRunner
"triepeolus-simplex-m-face-md-kent-county_2014-07-22-100937-zs-pmax_14805405233_o.jpg",
"washed-megachile-f-face-chile_2014-08-06-103414-zs-pmax_14977843152_o.jpg",
"xylocopa-balck-violetwing-f-kyrgystan-angle_2014-08-09-182433-zs-pmax_15123416061_o.jpg",
"xylocopa-india-yellow-m-india-face_2014-08-10-111701-zs-pmax_15166559172_o.jpg",
};
"xylocopa-india-yellow-m-india-face_2014-08-10-111701-zs-pmax_15166559172_o.jpg"
];
public void Init()
{

2
tests/ImageSharp.Tests.ProfilingSandbox/Program.cs

@ -52,7 +52,7 @@ public class Program
{
Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
Console.WriteLine(assembly.Location);
string[] assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
string[] assemblyPath = assembly.Location.Split(['/', '\\'], StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
{

8
tests/ImageSharp.Tests/Color/ReferencePalette.cs

@ -9,7 +9,7 @@ internal static class ReferencePalette
/// Gets a collection of named, web safe, colors as defined in the CSS Color Module Level 4.
/// </summary>
public static readonly Color[] WebSafeColors =
{
[
Color.AliceBlue,
Color.AntiqueWhite,
Color.Aqua,
@ -152,14 +152,14 @@ internal static class ReferencePalette
Color.WhiteSmoke,
Color.Yellow,
Color.YellowGreen
};
];
/// <summary>
/// Gets a collection of colors as defined in the original second edition of Werner’s Nomenclature of Colours 1821.
/// The hex codes were collected and defined by Nicholas Rougeux <see href="https://www.c82.net/werner"/>
/// </summary>
public static readonly Color[] WernerColors =
{
[
Color.ParseHex("#f1e9cd"),
Color.ParseHex("#f2e7cf"),
Color.ParseHex("#ece6d0"),
@ -270,7 +270,7 @@ internal static class ReferencePalette
Color.ParseHex("#9b856b"),
Color.ParseHex("#766051"),
Color.ParseHex("#453b32")
};
];
public static readonly Dictionary<string, Color> ColorNames =
new(StringComparer.OrdinalIgnoreCase)

17
tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs

@ -16,24 +16,23 @@ public class GeneralFormatTests
/// A collection made up of one file for each image format.
/// </summary>
public static readonly IEnumerable<string> DefaultFiles =
new[]
{
TestImages.Bmp.Car,
[
TestImages.Bmp.Car,
TestImages.Jpeg.Baseline.Calliphora,
TestImages.Png.Splash,
TestImages.Gif.Trans
};
];
/// <summary>
/// The collection of image files to test against.
/// </summary>
protected static readonly List<TestFile> Files = new()
{
protected static readonly List<TestFile> Files =
[
TestFile.Create(TestImages.Jpeg.Baseline.Calliphora),
TestFile.Create(TestImages.Bmp.Car),
TestFile.Create(TestImages.Png.Splash),
TestFile.Create(TestImages.Gif.Rings),
};
TestFile.Create(TestImages.Gif.Rings)
];
[Theory]
[WithFileCollection(nameof(DefaultFiles), PixelTypes.Rgba32)]
@ -151,7 +150,7 @@ public class GeneralFormatTests
private static IQuantizer GetQuantizer(string name)
{
PropertyInfo property = typeof(KnownQuantizers).GetTypeInfo().GetProperty(name);
return (IQuantizer)property.GetMethod.Invoke(null, Array.Empty<object>());
return (IQuantizer)property.GetMethod.Invoke(null, []);
}
[Fact]

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

@ -20,9 +20,9 @@ public class GifDecoderTests
private const PixelTypes TestPixelTypes = PixelTypes.Rgba32 | PixelTypes.RgbaVector | PixelTypes.Argb32;
public static readonly string[] MultiFrameTestFiles =
{
[
TestImages.Gif.Giphy, TestImages.Gif.Kumin
};
];
[Theory]
[WithFileCollection(nameof(MultiFrameTestFiles), PixelTypes.Rgba32)]

2
tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs

@ -123,7 +123,7 @@ public class ImageFormatManagerTests
IImageFormat format = Image.DetectFormat(jpegImage);
Assert.IsType<JpegFormat>(format);
byte[] invalidImage = { 1, 2, 3 };
byte[] invalidImage = [1, 2, 3];
Assert.Throws<UnknownImageFormatException>(() => Image.DetectFormat(invalidImage));
}
}

6
tests/ImageSharp.Tests/Formats/Jpg/AdobeMarkerTests.cs

@ -10,10 +10,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg;
public class AdobeMarkerTests
{
// Taken from actual test image
private readonly byte[] bytes = { 0x41, 0x64, 0x6F, 0x62, 0x65, 0x0, 0x64, 0x0, 0x0, 0x0, 0x0, 0x2 };
private readonly byte[] bytes = [0x41, 0x64, 0x6F, 0x62, 0x65, 0x0, 0x64, 0x0, 0x0, 0x0, 0x0, 0x2];
// Altered components
private readonly byte[] bytes2 = { 0x41, 0x64, 0x6F, 0x62, 0x65, 0x0, 0x64, 0x0, 0x0, 0x1, 0x1, 0x1 };
private readonly byte[] bytes2 = [0x41, 0x64, 0x6F, 0x62, 0x65, 0x0, 0x64, 0x0, 0x0, 0x1, 0x1, 0x1];
[Fact]
public void MarkerLengthIsCorrect()
@ -36,7 +36,7 @@ public class AdobeMarkerTests
[Fact]
public void MarkerIgnoresIncorrectValue()
{
bool isAdobe = AdobeMarker.TryParse(new byte[] { 0, 0, 0, 0 }, out AdobeMarker marker);
bool isAdobe = AdobeMarker.TryParse([0, 0, 0, 0], out AdobeMarker marker);
Assert.False(isAdobe);
Assert.Equal(default, marker);

8
tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs

@ -10,13 +10,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg;
public class JFifMarkerTests
{
// Taken from actual test image
private readonly byte[] bytes = { 0x4A, 0x46, 0x49, 0x46, 0x0, 0x1, 0x1, 0x1, 0x0, 0x60, 0x0, 0x60, 0x0 };
private readonly byte[] bytes = [0x4A, 0x46, 0x49, 0x46, 0x0, 0x1, 0x1, 0x1, 0x0, 0x60, 0x0, 0x60, 0x0];
// Altered components
private readonly byte[] bytes2 = { 0x4A, 0x46, 0x49, 0x46, 0x0, 0x1, 0x1, 0x1, 0x0, 0x48, 0x0, 0x48, 0x0 };
private readonly byte[] bytes2 = [0x4A, 0x46, 0x49, 0x46, 0x0, 0x1, 0x1, 0x1, 0x0, 0x48, 0x0, 0x48, 0x0];
// Incorrect density values. Zero is invalid.
private readonly byte[] bytes3 = { 0x4A, 0x46, 0x49, 0x46, 0x0, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0 };
private readonly byte[] bytes3 = [0x4A, 0x46, 0x49, 0x46, 0x0, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0];
[Fact]
public void MarkerLengthIsCorrect()
@ -40,7 +40,7 @@ public class JFifMarkerTests
[Fact]
public void MarkerIgnoresIncorrectValue()
{
bool isJFif = JFifMarker.TryParse(new byte[] { 0, 0, 0, 0 }, out JFifMarker marker);
bool isJFif = JFifMarker.TryParse([0, 0, 0, 0], out JFifMarker marker);
Assert.False(isJFif);
Assert.Equal(default, marker);

20
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs

@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg;
public partial class JpegDecoderTests
{
public static string[] BaselineTestJpegs =
{
[
TestImages.Jpeg.Baseline.Calliphora,
TestImages.Jpeg.Baseline.Cmyk,
TestImages.Jpeg.Baseline.Ycck,
@ -41,11 +41,11 @@ public partial class JpegDecoderTests
TestImages.Jpeg.Baseline.Testorig12bit,
// Grayscale jpeg with 2x2 sampling factors (not a usual thing to encounter in the wild)
TestImages.Jpeg.Baseline.GrayscaleSampling2x2,
};
TestImages.Jpeg.Baseline.GrayscaleSampling2x2
];
public static string[] ProgressiveTestJpegs =
{
[
TestImages.Jpeg.Progressive.Fb,
TestImages.Jpeg.Progressive.Progress,
TestImages.Jpeg.Progressive.Festzug,
@ -61,20 +61,20 @@ public partial class JpegDecoderTests
TestImages.Jpeg.Issues.OrderedInterleavedProgressive723A,
TestImages.Jpeg.Issues.OrderedInterleavedProgressive723B,
TestImages.Jpeg.Issues.OrderedInterleavedProgressive723C
};
];
public static string[] UnsupportedTestJpegs =
{
[
// Invalid componentCount value (2 or > 4)
TestImages.Jpeg.Issues.Fuzz.NullReferenceException823,
TestImages.Jpeg.Issues.MalformedUnsupportedComponentCount,
// Lossless jpeg
TestImages.Jpeg.Baseline.Lossless
};
];
public static string[] UnrecoverableTestJpegs =
{
[
TestImages.Jpeg.Issues.CriticalEOF214,
TestImages.Jpeg.Issues.Fuzz.NullReferenceException797,
TestImages.Jpeg.Issues.Fuzz.AccessViolationException798,
@ -98,8 +98,8 @@ public partial class JpegDecoderTests
TestImages.Jpeg.Issues.Fuzz.IndexOutOfRangeException1693A,
TestImages.Jpeg.Issues.Fuzz.IndexOutOfRangeException1693B,
TestImages.Jpeg.Issues.Fuzz.IndexOutOfRangeException824C,
TestImages.Jpeg.Issues.Fuzz.NullReferenceException2085,
};
TestImages.Jpeg.Issues.Fuzz.NullReferenceException2085
];
private static readonly Dictionary<string, float> CustomToleranceValues = new()
{

2
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Internal.cs

@ -19,7 +19,7 @@ public partial class JpegDecoderTests
[InlineData(4, JpegConstants.Adobe.ColorTransformYcck, JpegColorSpace.Ycck)]
internal void DeduceJpegColorSpaceAdobeMarker_ShouldReturnValidColorSpace(byte componentCount, byte adobeFlag, JpegColorSpace expectedColorSpace)
{
byte[] adobeMarkerPayload = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, adobeFlag };
byte[] adobeMarkerPayload = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, adobeFlag];
ProfileResolver.AdobeMarker.CopyTo(adobeMarkerPayload);
_ = AdobeMarker.TryParse(adobeMarkerPayload, out AdobeMarker adobeMarker);

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

@ -44,8 +44,8 @@ public partial class JpegDecoderTests
private static bool SkipTest(ITestImageProvider provider)
{
string[] largeImagesToSkipOn32Bit =
{
TestImages.Jpeg.Baseline.Jpeg420Exif,
[
TestImages.Jpeg.Baseline.Jpeg420Exif,
TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159,
TestImages.Jpeg.Issues.BadZigZagProgressive385,
TestImages.Jpeg.Issues.NoEoiProgressive517,
@ -53,7 +53,7 @@ public partial class JpegDecoderTests
TestImages.Jpeg.Issues.InvalidEOI695,
TestImages.Jpeg.Issues.ExifResizeOutOfRange696,
TestImages.Jpeg.Issues.ExifGetString750Transform
};
];
return !TestEnvironment.Is64BitProcess && largeImagesToSkipOn32Bit.Contains(provider.SourceFileOrDescription);
}

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

@ -258,8 +258,8 @@ where TPixel : unmanaged, IPixel<TPixel>
using Image<TPixel> image = provider.GetImage();
image.Mutate(x => x.Crop(132, 1606));
int[] quality = new int[] { 100, 50 };
JpegColorType[] colors = new[] { JpegColorType.YCbCrRatio444, JpegColorType.YCbCrRatio420 };
int[] quality = [100, 50];
JpegColorType[] colors = [JpegColorType.YCbCrRatio444, JpegColorType.YCbCrRatio420];
for (int i = 0; i < quality.Length; i++)
{
int q = quality[i];

14
tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs

@ -22,19 +22,19 @@ public class SpectralJpegTests
private ITestOutputHelper Output { get; }
public static readonly string[] BaselineTestJpegs =
{
TestImages.Jpeg.Baseline.Calliphora, TestImages.Jpeg.Baseline.Cmyk, TestImages.Jpeg.Baseline.Jpeg400,
[
TestImages.Jpeg.Baseline.Calliphora, TestImages.Jpeg.Baseline.Cmyk, TestImages.Jpeg.Baseline.Jpeg400,
TestImages.Jpeg.Baseline.Jpeg444, TestImages.Jpeg.Baseline.Testorig420,
TestImages.Jpeg.Baseline.Jpeg420Small, TestImages.Jpeg.Baseline.Bad.BadEOF,
TestImages.Jpeg.Baseline.MultiScanBaselineCMYK
};
];
public static readonly string[] ProgressiveTestJpegs =
{
TestImages.Jpeg.Progressive.Fb, TestImages.Jpeg.Progressive.Progress,
[
TestImages.Jpeg.Progressive.Fb, TestImages.Jpeg.Progressive.Progress,
TestImages.Jpeg.Progressive.Festzug, TestImages.Jpeg.Progressive.Bad.BadEOF,
TestImages.Jpeg.Progressive.Bad.ExifUndefType,
};
TestImages.Jpeg.Progressive.Bad.ExifUndefType
];
public static readonly string[] AllTestJpegs = BaselineTestJpegs.Concat(ProgressiveTestJpegs).ToArray();

4
tests/ImageSharp.Tests/Formats/Jpg/SpectralToPixelConversionTests.cs

@ -15,12 +15,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg;
public class SpectralToPixelConversionTests
{
public static readonly string[] BaselineTestJpegs =
{
[
TestImages.Jpeg.Baseline.Calliphora, TestImages.Jpeg.Baseline.Cmyk, TestImages.Jpeg.Baseline.Jpeg400,
TestImages.Jpeg.Baseline.Jpeg444, TestImages.Jpeg.Baseline.Testorig420,
TestImages.Jpeg.Baseline.Jpeg420Small, TestImages.Jpeg.Baseline.Bad.BadEOF,
TestImages.Jpeg.Baseline.MultiScanBaselineCMYK
};
];
public SpectralToPixelConversionTests(ITestOutputHelper output) => this.Output = output;

2
tests/ImageSharp.Tests/Formats/Png/Adler32Tests.cs

@ -60,7 +60,7 @@ public class Adler32Tests
private static void RunCalculateAdlerTest()
{
int[] testData = { 0, 8, 215, 1024, 1024 + 15, 2034, 4096 };
int[] testData = [0, 8, 215, 1024, 1024 + 15, 2034, 4096];
for (int i = 0; i < testData.Length; i++)
{
CalculateAdlerAndCompareToReference(testData[i]);

44
tests/ImageSharp.Tests/Formats/Png/PngDecoderFilterTests.cs

@ -13,33 +13,33 @@ public class PngDecoderFilterTests
{
// arrange
byte[] scanline =
{
[
3, 39, 39, 39, 0, 4, 4, 4, 0, 1, 1, 1, 0, 1, 1, 1, 0, 2, 2, 2, 0, 2, 2, 2, 0, 2, 2, 2, 0, 4, 4, 4,
0, 2, 2, 2, 0, 3, 3, 3, 0, 1, 1, 1, 0, 3, 3, 3, 0, 3, 3, 3, 0, 1, 1, 1, 0, 3, 3, 3, 0, 2, 2, 2, 0,
1, 1, 1, 0, 3, 3, 3, 0, 1, 1, 1, 0, 3, 3, 3, 0, 1, 1, 1, 0, 3, 3, 3, 0, 3, 3, 3, 0, 254, 254, 254,
0, 6, 6, 6, 14, 71, 71, 71, 157, 254, 254, 254, 28, 251, 251, 251, 0, 4, 4, 4, 0, 2, 2, 2, 0, 11,
11, 11, 0, 226, 226, 226, 0, 255, 128, 234
};
];
byte[] previousScanline =
{
[
3, 74, 74, 74, 0, 73, 73, 73, 0, 73, 73, 73, 0, 74, 74, 74, 0, 74, 74, 74, 0, 73, 73, 73, 0, 72, 72,
72, 0, 72, 72, 72, 0, 73, 73, 73, 0, 74, 74, 74, 0, 73, 73, 73, 0, 72, 72, 72, 0, 72, 72, 72, 0, 74,
74, 74, 0, 72, 72, 72, 0, 73, 73, 73, 0, 75, 75, 75, 0, 73, 73, 73, 0, 74, 74, 74, 0, 72, 72, 72, 0,
73, 73, 73, 0, 73, 73, 73, 0, 72, 72, 72, 0, 74, 74, 74, 0, 61, 61, 61, 0, 101, 101, 101, 78, 197,
197, 197, 251, 152, 152, 152, 255, 155, 155, 155, 255, 162, 162, 162, 255, 175, 175, 175, 255, 160,
160, 160, 255, 139, 128, 134
};
];
byte[] expected =
{
[
3, 76, 76, 76, 0, 78, 78, 78, 0, 76, 76, 76, 0, 76, 76, 76, 0, 77, 77, 77, 0, 77, 77, 77, 0, 76, 76,
76, 0, 78, 78, 78, 0, 77, 77, 77, 0, 78, 78, 78, 0, 76, 76, 76, 0, 77, 77, 77, 0, 77, 77, 77, 0, 76,
76, 76, 0, 77, 77, 77, 0, 77, 77, 77, 0, 77, 77, 77, 0, 78, 78, 78, 0, 77, 77, 77, 0, 77, 77, 77, 0,
76, 76, 76, 0, 77, 77, 77, 0, 77, 77, 77, 0, 73, 73, 73, 0, 73, 73, 73, 14, 158, 158, 158, 203, 175,
175, 175, 255, 158, 158, 158, 255, 160, 160, 160, 255, 163, 163, 163, 255, 180, 180, 180, 255, 140,
140, 140, 255, 138, 6, 115
};
];
// act
AverageFilter.Decode(scanline, previousScanline, 4);
@ -52,25 +52,25 @@ public class PngDecoderFilterTests
{
// arrange
byte[] scanline =
{
[
62, 23, 186, 150, 174, 4, 205, 59, 153, 134, 158, 86, 240, 173, 191, 58, 111, 183, 77, 37, 85, 23,
93, 204, 110, 139, 9, 20, 87, 154, 176, 54, 207, 214, 40, 11, 179, 199, 7, 219, 174, 242, 112, 220,
149, 5, 9, 110, 103, 107, 231, 241, 13, 70, 216, 39, 186, 237, 39, 34, 251, 185, 228, 254
};
];
byte[] previousScanline =
{
[
214, 103, 135, 26, 133, 179, 134, 168, 175, 114, 118, 99, 167, 129, 55, 105, 129, 154, 173, 235,
179, 191, 41, 137, 253, 0, 81, 198, 159, 228, 224, 245, 14, 113, 5, 45, 126, 239, 233, 179, 229, 62,
66, 155, 207, 117, 128, 56, 181, 190, 160, 96, 11, 248, 74, 23, 62, 253, 29, 132, 98, 192, 9, 202
};
];
byte[] expected =
{
[
62, 126, 65, 176, 51, 183, 83, 227, 72, 248, 20, 185, 151, 46, 246, 163, 240, 81, 250, 16, 8, 214,
134, 85, 107, 139, 90, 218, 246, 126, 144, 43, 221, 71, 45, 56, 49, 182, 240, 142, 147, 48, 178,
119, 100, 122, 137, 166, 28, 41, 135, 81, 24, 62, 34, 62, 248, 234, 68, 166, 93, 121, 237, 200
};
];
// act
UpFilter.Decode(scanline, previousScanline);
@ -83,18 +83,18 @@ public class PngDecoderFilterTests
{
// arrange
byte[] scanline =
{
[
62, 23, 186, 150, 174, 4, 205, 59, 153, 134, 158, 86, 240, 173, 191, 58, 111, 183, 77, 37, 85, 23,
93, 204, 110, 139, 9, 20, 87, 154, 176, 54, 207, 214, 40, 11, 179, 199, 7, 219, 174, 242, 112, 220,
149, 5, 9, 110, 103, 107, 231, 241, 13, 70, 216, 39, 186, 237, 39, 34, 251, 185, 228, 254
};
];
byte[] expected =
{
[
62, 23, 186, 150, 174, 27, 135, 209, 71, 161, 37, 39, 55, 78, 228, 97, 166, 5, 49, 134, 251, 28,
142, 82, 105, 167, 151, 102, 192, 65, 71, 156, 143, 23, 111, 167, 66, 222, 118, 130, 240, 208, 230,
94, 133, 213, 239, 204, 236, 64, 214, 189, 249, 134, 174, 228, 179, 115, 213, 6, 174, 44, 185, 4
};
];
// act
SubFilter.Decode(scanline, 4);
@ -107,25 +107,25 @@ public class PngDecoderFilterTests
{
// arrange
byte[] scanline =
{
[
62, 23, 186, 150, 174, 4, 205, 59, 153, 134, 158, 86, 240, 173, 191, 58, 111, 183, 77, 37, 85, 23,
93, 204, 110, 139, 9, 20, 87, 154, 176, 54, 207, 214, 40, 11, 179, 199, 7, 219, 174, 242, 112, 220,
149, 5, 9, 110, 103, 107, 231, 241, 13, 70, 216, 39, 186, 237, 39, 34, 251, 185, 228, 254
};
];
byte[] previousScanline =
{
[
214, 103, 135, 26, 133, 179, 134, 168, 175, 114, 118, 99, 167, 129, 55, 105, 129, 154, 173, 235,
179, 191, 41, 137, 253, 0, 81, 198, 159, 228, 224, 245, 14, 113, 5, 45, 126, 239, 233, 179, 229, 62,
66, 155, 207, 117, 128, 56, 181, 190, 160, 96, 11, 248, 74, 23, 62, 253, 29, 132, 98, 192, 9, 202
};
];
byte[] expected =
{
[
62, 126, 65, 176, 51, 183, 14, 235, 30, 248, 172, 254, 14, 165, 53, 56, 125, 92, 250, 16, 8, 177,
10, 220, 118, 139, 50, 240, 205, 126, 144, 43, 221, 71, 45, 54, 144, 182, 240, 142, 147, 48, 178,
106, 40, 122, 187, 166, 143, 41, 162, 151, 24, 111, 34, 135, 248, 92, 68, 169, 243, 21, 1, 200
};
];
// act
PaethFilter.Decode(scanline, previousScanline, 4);

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

@ -14,12 +14,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png;
public partial class PngDecoderTests
{
// Represents ASCII string of "123456789"
private readonly byte[] check = { 49, 50, 51, 52, 53, 54, 55, 56, 57 };
private readonly byte[] check = [49, 50, 51, 52, 53, 54, 55, 56, 57];
// Contains the png marker, IHDR and pHYs chunks of a 1x1 pixel 32bit png 1 a single black pixel.
private static readonly byte[] Raw1X1PngIhdrAndpHYs =
{
// PNG Identifier
[
// PNG Identifier
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A,
// IHDR
@ -36,12 +36,12 @@ public partial class PngDecoderTests
// pHYS CRC
0xC7, 0x6F, 0xA8, 0x64
};
];
// Contains the png marker, IDAT and IEND chunks of a 1x1 pixel 32bit png 1 a single black pixel.
private static readonly byte[] Raw1X1PngIdatAndIend =
{
// IDAT
[
// IDAT
0x00, 0x00, 0x00, 0x0C, 0x49, 0x44, 0x41, 0x54, 0x18,
0x57, 0x63, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x04,
0x00, 0x01,
@ -54,7 +54,7 @@ public partial class PngDecoderTests
// IEND CRC
0xAE, 0x42, 0x60, 0x82
};
];
[Theory]
[InlineData((uint)PngChunkType.Header)] // IHDR
@ -94,10 +94,10 @@ public partial class PngDecoderTests
private static void WriteChunk(MemoryStream memStream, string chunkName)
{
// Needs a minimum length of 9 for pHYs chunk.
memStream.Write(new byte[] { 0, 0, 0, 9 }, 0, 4);
memStream.Write([0, 0, 0, 9], 0, 4);
memStream.Write(Encoding.ASCII.GetBytes(chunkName), 0, 4); // 4 bytes chunk header
memStream.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 9); // 9 bytes of chunk data
memStream.Write(new byte[] { 0, 0, 0, 0 }, 0, 4); // Junk Crc
memStream.Write([0, 0, 0, 0, 0, 0, 0, 0, 0], 0, 9); // 9 bytes of chunk data
memStream.Write([0, 0, 0, 0], 0, 4); // Junk Crc
}
private static void WriteDataChunk(MemoryStream memStream)

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

@ -21,7 +21,7 @@ public partial class PngDecoderTests
private const PixelTypes TestPixelTypes = PixelTypes.Rgba32 | PixelTypes.RgbaVector | PixelTypes.Argb32;
public static readonly string[] CommonTestImages =
{
[
TestImages.Png.Splash,
TestImages.Png.FilterVar,
@ -35,29 +35,29 @@ public partial class PngDecoderTests
TestImages.Png.Rgb24BppTrans,
TestImages.Png.Bad.ChunkLength1,
TestImages.Png.Bad.ChunkLength2,
};
TestImages.Png.Bad.ChunkLength2
];
public static readonly string[] TestImagesIssue1014 =
{
[
TestImages.Png.Issue1014_1, TestImages.Png.Issue1014_2,
TestImages.Png.Issue1014_3, TestImages.Png.Issue1014_4,
TestImages.Png.Issue1014_5, TestImages.Png.Issue1014_6
};
];
public static readonly string[] TestImagesIssue1177 =
{
[
TestImages.Png.Issue1177_1,
TestImages.Png.Issue1177_2
};
];
public static readonly string[] CorruptedTestImages =
{
[
TestImages.Png.Bad.CorruptedChunk,
TestImages.Png.Bad.ZlibOverflow,
TestImages.Png.Bad.ZlibOverflow2,
TestImages.Png.Bad.ZlibZtxtBadHeader,
};
TestImages.Png.Bad.ZlibZtxtBadHeader
];
public static readonly TheoryData<string, Type> PixelFormatRange = new()
{
@ -79,7 +79,7 @@ public partial class PngDecoderTests
};
public static readonly string[] MultiFrameTestFiles =
{
[
TestImages.Png.APng,
TestImages.Png.SplitIDatZeroLength,
TestImages.Png.DisposeNone,
@ -90,7 +90,7 @@ public partial class PngDecoderTests
TestImages.Png.BlendOverMultiple,
TestImages.Png.FrameOffset,
TestImages.Png.DefaultNotAnimated
};
];
[Theory]
[MemberData(nameof(PixelFormatRange))]

18
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.Chunks.cs

@ -188,15 +188,15 @@ public partial class PngEncoderTests
{ PngChunkType.Data, false },
{ PngChunkType.End, false }
};
List<PngChunkType> excludedChunkTypes = new()
{
List<PngChunkType> excludedChunkTypes =
[
PngChunkType.Gamma,
PngChunkType.Exif,
PngChunkType.Physical,
PngChunkType.Text,
PngChunkType.InternationalText,
PngChunkType.CompressedText,
};
PngChunkType.CompressedText
];
// act
input.Save(memStream, encoder);
@ -252,7 +252,7 @@ public partial class PngEncoderTests
{ PngChunkType.Data, false },
{ PngChunkType.End, false }
};
List<PngChunkType> excludedChunkTypes = new();
List<PngChunkType> excludedChunkTypes = [];
switch (chunkFilter)
{
case PngChunkFilter.ExcludeGammaChunk:
@ -326,8 +326,8 @@ public partial class PngEncoderTests
using Image<Rgba32> input = testFile.CreateRgba32Image();
using MemoryStream memStream = new();
PngEncoder encoder = new() { ChunkFilter = PngChunkFilter.None, TextCompressionThreshold = 8 };
List<PngChunkType> expectedChunkTypes = new()
{
List<PngChunkType> expectedChunkTypes =
[
PngChunkType.Header,
PngChunkType.Gamma,
PngChunkType.EmbeddedColorProfile,
@ -338,8 +338,8 @@ public partial class PngEncoderTests
PngChunkType.Exif,
PngChunkType.Physical,
PngChunkType.Data,
PngChunkType.End,
};
PngChunkType.End
];
// act
input.Save(memStream, encoder);

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

@ -88,11 +88,11 @@ public partial class PngEncoderTests
80, 100, 120, 230
};
public static readonly PngInterlaceMode[] InterlaceMode = new[]
{
public static readonly PngInterlaceMode[] InterlaceMode =
[
PngInterlaceMode.None,
PngInterlaceMode.Adam7
};
];
public static readonly TheoryData<string, int, int, PixelResolutionUnit> RatioFiles =
new()
@ -289,8 +289,8 @@ public partial class PngEncoderTests
byte[] data = ms.ToArray().Take(8).ToArray();
byte[] expected =
{
0x89, // Set the high bit.
[
0x89, // Set the high bit.
0x50, // P
0x4E, // N
0x47, // G
@ -298,7 +298,7 @@ public partial class PngEncoderTests
0x0A, // Line ending CRLF
0x1A, // EOF
0x0A // LF
};
];
Assert.Equal(expected, data);
}

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

@ -20,100 +20,100 @@ public class BlackIsZeroTiffColorTests : PhotometricInterpretationTestBase
private static readonly Rgba32 Bit1 = new(255, 255, 255, 255);
private static readonly byte[] BilevelBytes4X4 =
{
[
0b01010000,
0b11110000,
0b01110000,
0b10010000
};
];
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 }
};
[
[Bit0, Bit1, Bit0, Bit1],
[Bit1, Bit1, Bit1, Bit1],
[Bit0, Bit1, Bit1, Bit1],
[Bit1, Bit0, Bit0, Bit1]
];
private static readonly byte[] BilevelBytes12X4 =
{
[
0b01010101, 0b01010000,
0b11111111, 0b11111111,
0b01101001, 0b10100000,
0b10010000, 0b01100000
};
];
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 }
};
[
[Bit0, Bit1, Bit0, Bit1, Bit0, Bit1, Bit0, Bit1, Bit0, Bit1, Bit0, Bit1],
[Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1],
[Bit0, Bit1, Bit1, Bit0, Bit1, Bit0, Bit0, Bit1, Bit1, Bit0, Bit1, Bit0],
[Bit1, Bit0, Bit0, Bit1, Bit0, Bit0, Bit0, Bit0, Bit0, Bit1, Bit1, Bit0]
];
private static readonly byte[] Grayscale4Bytes4X4 =
{
[
0x8F, 0x0F,
0xFF, 0xFF,
0x08, 0x8F,
0xF0, 0xF8
};
];
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 }
};
[
[Gray8, GrayF, Gray0, GrayF],
[GrayF, GrayF, GrayF, GrayF],
[Gray0, Gray8, Gray8, GrayF],
[GrayF, Gray0, GrayF, Gray8]
];
private static readonly byte[] Grayscale4Bytes3X4 =
{
[
0x8F, 0x00,
0xFF, 0xF0,
0x08, 0x80,
0xF0, 0xF0
};
];
private static readonly Rgba32[][] Grayscale4Result3X4 =
{
new[] { Gray8, GrayF, Gray0 },
new[] { GrayF, GrayF, GrayF },
new[] { Gray0, Gray8, Gray8 },
new[] { GrayF, Gray0, GrayF }
};
[
[Gray8, GrayF, Gray0],
[GrayF, GrayF, GrayF],
[Gray0, Gray8, Gray8],
[GrayF, Gray0, GrayF]
];
private static readonly byte[] Grayscale8Bytes4X4 =
{
[
128, 255, 000, 255,
255, 255, 255, 255,
000, 128, 128, 255,
255, 000, 255, 128
};
];
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 }
};
[
[Gray128, Gray255, Gray000, Gray255],
[Gray255, Gray255, Gray255, Gray255],
[Gray000, Gray128, Gray128, Gray255],
[Gray255, Gray000, Gray255, Gray128]
];
public static IEnumerable<object[]> BilevelData
{
get
{
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) };
yield return [BilevelBytes4X4, 1, 0, 0, 4, 4, BilevelResult4X4];
yield return [BilevelBytes4X4, 1, 0, 0, 4, 4, Offset(BilevelResult4X4, 0, 0, 6, 6)];
yield return [BilevelBytes4X4, 1, 1, 0, 4, 4, Offset(BilevelResult4X4, 1, 0, 6, 6)];
yield return [BilevelBytes4X4, 1, 0, 1, 4, 4, Offset(BilevelResult4X4, 0, 1, 6, 6)];
yield return [BilevelBytes4X4, 1, 1, 1, 4, 4, Offset(BilevelResult4X4, 1, 1, 6, 6)];
yield return [BilevelBytes12X4, 1, 0, 0, 12, 4, BilevelResult12X4];
yield return [BilevelBytes12X4, 1, 0, 0, 12, 4, Offset(BilevelResult12X4, 0, 0, 18, 6)];
yield return [BilevelBytes12X4, 1, 1, 0, 12, 4, Offset(BilevelResult12X4, 1, 0, 18, 6)];
yield return [BilevelBytes12X4, 1, 0, 1, 12, 4, Offset(BilevelResult12X4, 0, 1, 18, 6)];
yield return [BilevelBytes12X4, 1, 1, 1, 12, 4, Offset(BilevelResult12X4, 1, 1, 18, 6)];
}
}
@ -121,17 +121,17 @@ public class BlackIsZeroTiffColorTests : PhotometricInterpretationTestBase
{
get
{
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) };
yield return [Grayscale4Bytes4X4, 4, 0, 0, 4, 4, Grayscale4Result4X4];
yield return [Grayscale4Bytes4X4, 4, 0, 0, 4, 4, Offset(Grayscale4Result4X4, 0, 0, 6, 6)];
yield return [Grayscale4Bytes4X4, 4, 1, 0, 4, 4, Offset(Grayscale4Result4X4, 1, 0, 6, 6)];
yield return [Grayscale4Bytes4X4, 4, 0, 1, 4, 4, Offset(Grayscale4Result4X4, 0, 1, 6, 6)];
yield return [Grayscale4Bytes4X4, 4, 1, 1, 4, 4, Offset(Grayscale4Result4X4, 1, 1, 6, 6)];
yield return [Grayscale4Bytes3X4, 4, 0, 0, 3, 4, Grayscale4Result3X4];
yield return [Grayscale4Bytes3X4, 4, 0, 0, 3, 4, Offset(Grayscale4Result3X4, 0, 0, 6, 6)];
yield return [Grayscale4Bytes3X4, 4, 1, 0, 3, 4, Offset(Grayscale4Result3X4, 1, 0, 6, 6)];
yield return [Grayscale4Bytes3X4, 4, 0, 1, 3, 4, Offset(Grayscale4Result3X4, 0, 1, 6, 6)];
yield return [Grayscale4Bytes3X4, 4, 1, 1, 3, 4, Offset(Grayscale4Result3X4, 1, 1, 6, 6)];
}
}
@ -139,11 +139,11 @@ public class BlackIsZeroTiffColorTests : PhotometricInterpretationTestBase
{
get
{
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) };
yield return [Grayscale8Bytes4X4, 8, 0, 0, 4, 4, Grayscale8Result4X4];
yield return [Grayscale8Bytes4X4, 8, 0, 0, 4, 4, Offset(Grayscale8Result4X4, 0, 0, 6, 6)];
yield return [Grayscale8Bytes4X4, 8, 1, 0, 4, 4, Offset(Grayscale8Result4X4, 1, 0, 6, 6)];
yield return [Grayscale8Bytes4X4, 8, 0, 1, 4, 4, Offset(Grayscale8Result4X4, 0, 1, 6, 6)];
yield return [Grayscale8Bytes4X4, 8, 1, 1, 4, 4, Offset(Grayscale8Result4X4, 1, 1, 6, 6)];
}
}

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

@ -15,39 +15,43 @@ public class PaletteTiffColorTests : PhotometricInterpretationTestBase
public static ushort[] Palette4ColorMap => GenerateColorMap(Palette4ColorPalette);
private static readonly byte[] Palette4Bytes4X4 =
{
[
0x01, 0x23, 0x4A, 0xD2, 0x12, 0x34, 0xAB, 0xEF
};
];
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 } });
[
[0x00, 0x01, 0x02, 0x03], [0x04, 0x0A, 0x0D, 0x02], [0x01, 0x02, 0x03, 0x04], [0x0A, 0x0B, 0x0E, 0x0F]
]);
private static readonly byte[] Palette4Bytes3X4 =
{
[
0x01, 0x20,
0x4A, 0xD0,
0x12, 0x30,
0xAB, 0xE0
};
];
private static readonly Rgba32[][] Palette4Result3X4 = GenerateResult(Palette4ColorPalette, new[] { new[] { 0x00, 0x01, 0x02 }, new[] { 0x04, 0x0A, 0x0D }, new[] { 0x01, 0x02, 0x03 }, new[] { 0x0A, 0x0B, 0x0E } });
private static readonly Rgba32[][] Palette4Result3X4 = GenerateResult(Palette4ColorPalette, [
[0x00, 0x01, 0x02], [0x04, 0x0A, 0x0D], [0x01, 0x02, 0x03], [0x0A, 0x0B, 0x0E]
]);
public static IEnumerable<object[]> Palette4Data
{
get
{
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) };
yield return [Palette4Bytes4X4, 4, Palette4ColorMap, 0, 0, 4, 4, Palette4Result4X4];
yield return [Palette4Bytes4X4, 4, Palette4ColorMap, 0, 0, 4, 4, Offset(Palette4Result4X4, 0, 0, 6, 6)];
yield return [Palette4Bytes4X4, 4, Palette4ColorMap, 1, 0, 4, 4, Offset(Palette4Result4X4, 1, 0, 6, 6)];
yield return [Palette4Bytes4X4, 4, Palette4ColorMap, 0, 1, 4, 4, Offset(Palette4Result4X4, 0, 1, 6, 6)];
yield return [Palette4Bytes4X4, 4, Palette4ColorMap, 1, 1, 4, 4, Offset(Palette4Result4X4, 1, 1, 6, 6)];
yield return [Palette4Bytes3X4, 4, Palette4ColorMap, 0, 0, 3, 4, Palette4Result3X4];
yield return [Palette4Bytes3X4, 4, Palette4ColorMap, 0, 0, 3, 4, Offset(Palette4Result3X4, 0, 0, 6, 6)];
yield return [Palette4Bytes3X4, 4, Palette4ColorMap, 1, 0, 3, 4, Offset(Palette4Result3X4, 1, 0, 6, 6)];
yield return [Palette4Bytes3X4, 4, Palette4ColorMap, 0, 1, 3, 4, Offset(Palette4Result3X4, 0, 1, 6, 6)];
yield return [Palette4Bytes3X4, 4, Palette4ColorMap, 1, 1, 3, 4, Offset(Palette4Result3X4, 1, 1, 6, 6)];
}
}
@ -56,24 +60,26 @@ public class PaletteTiffColorTests : PhotometricInterpretationTestBase
public static ushort[] Palette8ColorMap => GenerateColorMap(Palette8ColorPalette);
private static readonly byte[] Palette8Bytes4X4 =
{
[
000, 001, 002, 003,
100, 110, 120, 130,
000, 255, 128, 255,
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 } });
private static readonly Rgba32[][] Palette8Result4X4 = GenerateResult(Palette8ColorPalette, [
[000, 001, 002, 003], [100, 110, 120, 130], [000, 255, 128, 255], [050, 100, 150, 200]
]);
public static IEnumerable<object[]> Palette8Data
{
get
{
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) };
yield return [Palette8Bytes4X4, 8, Palette8ColorMap, 0, 0, 4, 4, Palette8Result4X4];
yield return [Palette8Bytes4X4, 8, Palette8ColorMap, 0, 0, 4, 4, Offset(Palette8Result4X4, 0, 0, 6, 6)];
yield return [Palette8Bytes4X4, 8, Palette8ColorMap, 1, 0, 4, 4, Offset(Palette8Result4X4, 1, 0, 6, 6)];
yield return [Palette8Bytes4X4, 8, Palette8ColorMap, 0, 1, 4, 4, Offset(Palette8Result4X4, 0, 1, 6, 6)];
yield return [Palette8Bytes4X4, 8, Palette8ColorMap, 1, 1, 4, 4, Offset(Palette8Result4X4, 1, 1, 6, 6)];
}
}
@ -92,7 +98,7 @@ public class PaletteTiffColorTests : PhotometricInterpretationTestBase
for (uint i = 0; i < count; i++)
{
palette[i] = new[] { (i * 2u) % 65536u, (i * 2625u) % 65536u, (i * 29401u) % 65536u };
palette[i] = [(i * 2u) % 65536u, (i * 2625u) % 65536u, (i * 29401u) % 65536u];
}
return palette;

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

@ -27,88 +27,88 @@ public class RgbPlanarTiffColorTests : PhotometricInterpretationTestBase
private static readonly Rgba32 Rgb4_48C = new(68, 136, 204, 255);
private static readonly byte[] Rgb4Bytes4X4R =
{
[
0x0F, 0x0F,
0xF0, 0x0F,
0x48, 0xC4,
0x04, 0x8C
};
];
private static readonly byte[] Rgb4Bytes4X4G =
{
[
0x0F, 0x0F,
0x0F, 0x00,
0x00, 0x08,
0x04, 0x8C
};
];
private static readonly byte[] Rgb4Bytes4X4B =
{
[
0x0F, 0x0F,
0x00, 0xFF,
0x00, 0x0C,
0x04, 0x8C
};
];
private static readonly byte[][] Rgb4Bytes4X4 = { Rgb4Bytes4X4R, Rgb4Bytes4X4G, Rgb4Bytes4X4B };
private static readonly byte[][] Rgb4Bytes4X4 = [Rgb4Bytes4X4R, Rgb4Bytes4X4G, Rgb4Bytes4X4B];
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 }
};
[
[Rgb4_000, Rgb4_FFF, Rgb4_000, Rgb4_FFF],
[Rgb4_F00, Rgb4_0F0, Rgb4_00F, Rgb4_F0F],
[Rgb4_400, Rgb4_800, Rgb4_C00, Rgb4_48C],
[Rgb4_000, Rgb4_444, Rgb4_888, Rgb4_CCC]
];
private static readonly byte[] Rgb4Bytes3X4R =
{
[
0x0F, 0x00,
0xF0, 0x00,
0x48, 0xC0,
0x04, 0x80
};
];
private static readonly byte[] Rgb4Bytes3X4G =
{
[
0x0F, 0x00,
0x0F, 0x00,
0x00, 0x00,
0x04, 0x80
};
];
private static readonly byte[] Rgb4Bytes3X4B =
{
[
0x0F, 0x00,
0x00, 0xF0,
0x00, 0x00,
0x04, 0x80
};
];
private static readonly byte[][] Rgb4Bytes3X4 = { Rgb4Bytes3X4R, Rgb4Bytes3X4G, Rgb4Bytes3X4B };
private static readonly byte[][] Rgb4Bytes3X4 = [Rgb4Bytes3X4R, Rgb4Bytes3X4G, Rgb4Bytes3X4B];
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 }
};
[
[Rgb4_000, Rgb4_FFF, Rgb4_000],
[Rgb4_F00, Rgb4_0F0, Rgb4_00F],
[Rgb4_400, Rgb4_800, Rgb4_C00],
[Rgb4_000, Rgb4_444, Rgb4_888]
];
public static IEnumerable<object[]> Rgb4Data
{
get
{
yield return new object[] { Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 4, 4, Rgb4Result4X4 };
yield return new object[] { Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 4, 4, Offset(Rgb4Result4X4, 0, 0, 6, 6) };
yield return new object[] { Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 1, 0, 4, 4, Offset(Rgb4Result4X4, 1, 0, 6, 6) };
yield return new object[] { Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 0, 1, 4, 4, Offset(Rgb4Result4X4, 0, 1, 6, 6) };
yield return new object[] { Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 1, 1, 4, 4, Offset(Rgb4Result4X4, 1, 1, 6, 6) };
yield return new object[] { Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 3, 4, Rgb4Result3X4 };
yield return new object[] { Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 3, 4, Offset(Rgb4Result3X4, 0, 0, 6, 6) };
yield return new object[] { Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 1, 0, 3, 4, Offset(Rgb4Result3X4, 1, 0, 6, 6) };
yield return new object[] { Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 0, 1, 3, 4, Offset(Rgb4Result3X4, 0, 1, 6, 6) };
yield return new object[] { Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 1, 1, 3, 4, Offset(Rgb4Result3X4, 1, 1, 6, 6) };
yield return [Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 4, 4, Rgb4Result4X4];
yield return [Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 4, 4, Offset(Rgb4Result4X4, 0, 0, 6, 6)];
yield return [Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 1, 0, 4, 4, Offset(Rgb4Result4X4, 1, 0, 6, 6)];
yield return [Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 0, 1, 4, 4, Offset(Rgb4Result4X4, 0, 1, 6, 6)];
yield return [Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 1, 1, 4, 4, Offset(Rgb4Result4X4, 1, 1, 6, 6)];
yield return [Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 3, 4, Rgb4Result3X4];
yield return [Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 3, 4, Offset(Rgb4Result3X4, 0, 0, 6, 6)];
yield return [Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 1, 0, 3, 4, Offset(Rgb4Result3X4, 1, 0, 6, 6)];
yield return [Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 0, 1, 3, 4, Offset(Rgb4Result3X4, 0, 1, 6, 6)];
yield return [Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 1, 1, 3, 4, Offset(Rgb4Result3X4, 1, 1, 6, 6)];
}
}
@ -127,51 +127,51 @@ public class RgbPlanarTiffColorTests : PhotometricInterpretationTestBase
private static readonly Rgba32 Rgb8_48C = new(64, 128, 192, 255);
private static readonly byte[] Rgb8Bytes4X4R =
{
[
000, 255, 000, 255,
255, 000, 000, 255,
064, 128, 192, 064,
000, 064, 128, 192
};
];
private static readonly byte[] Rgb8Bytes4X4G =
{
[
000, 255, 000, 255,
000, 255, 000, 000,
000, 000, 000, 128,
000, 064, 128, 192
};
];
private static readonly byte[] Rgb8Bytes4X4B =
{
[
000, 255, 000, 255,
000, 000, 255, 255,
000, 000, 000, 192,
000, 064, 128, 192
};
];
private static readonly byte[][] Rgb8Bytes4X4 =
{
[
Rgb8Bytes4X4R, Rgb8Bytes4X4G, Rgb8Bytes4X4B
};
];
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 }
};
[
[Rgb8_000, Rgb8_FFF, Rgb8_000, Rgb8_FFF],
[Rgb8_F00, Rgb8_0F0, Rgb8_00F, Rgb8_F0F],
[Rgb8_400, Rgb8_800, Rgb8_C00, Rgb8_48C],
[Rgb8_000, Rgb8_444, Rgb8_888, Rgb8_CCC]
];
public static IEnumerable<object[]> Rgb8Data
{
get
{
yield return new object[] { Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 0, 0, 4, 4, Rgb8Result4X4 };
yield return new object[] { Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 0, 0, 4, 4, Offset(Rgb8Result4X4, 0, 0, 6, 6) };
yield return new object[] { Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 1, 0, 4, 4, Offset(Rgb8Result4X4, 1, 0, 6, 6) };
yield return new object[] { Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 0, 1, 4, 4, Offset(Rgb8Result4X4, 0, 1, 6, 6) };
yield return new object[] { Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 1, 1, 4, 4, Offset(Rgb8Result4X4, 1, 1, 6, 6) };
yield return [Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 0, 0, 4, 4, Rgb8Result4X4];
yield return [Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 0, 0, 4, 4, Offset(Rgb8Result4X4, 0, 0, 6, 6)];
yield return [Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 1, 0, 4, 4, Offset(Rgb8Result4X4, 1, 0, 6, 6)];
yield return [Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 0, 1, 4, 4, Offset(Rgb8Result4X4, 0, 1, 6, 6)];
yield return [Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 1, 1, 4, 4, Offset(Rgb8Result4X4, 1, 1, 6, 6)];
}
}
@ -190,48 +190,52 @@ public class RgbPlanarTiffColorTests : PhotometricInterpretationTestBase
private static readonly Rgba32 Rgb484_48C = new(68, 128, 204, 255);
private static readonly byte[] Rgb484Bytes4X4R =
{
[
0x0F, 0x0F,
0xF0, 0x0F,
0x48, 0xC4,
0x04, 0x8C
};
];
private static readonly byte[] Rgb484Bytes4X4G =
{
[
0x00, 0xFF, 0x00, 0xFF,
0x00, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80,
0x00, 0x40, 0x80, 0xC0
};
];
private static readonly byte[] Rgb484Bytes4X4B =
{
[
0x0F, 0x0F,
0x00, 0xFF,
0x00, 0x0C,
0x04, 0x8C
};
];
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 }
};
[
[Rgb484_000, Rgb484_FFF, Rgb484_000, Rgb484_FFF],
[Rgb484_F00, Rgb484_0F0, Rgb484_00F, Rgb484_F0F],
[Rgb484_400, Rgb484_800, Rgb484_C00, Rgb484_48C],
[Rgb484_000, Rgb484_444, Rgb484_888, Rgb484_CCC]
];
private static readonly byte[][] Rgb484Bytes4X4 = { Rgb484Bytes4X4R, Rgb484Bytes4X4G, Rgb484Bytes4X4B };
private static readonly byte[][] Rgb484Bytes4X4 = [Rgb484Bytes4X4R, Rgb484Bytes4X4G, Rgb484Bytes4X4B];
public static IEnumerable<object[]> Rgb484_Data
{
get
{
yield return new object[] { Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 0, 0, 4, 4, Rgb484Result4X4 };
yield return new object[] { Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 0, 0, 4, 4, Offset(Rgb484Result4X4, 0, 0, 6, 6) };
yield return new object[] { Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 1, 0, 4, 4, Offset(Rgb484Result4X4, 1, 0, 6, 6) };
yield return new object[] { Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 0, 1, 4, 4, Offset(Rgb484Result4X4, 0, 1, 6, 6) };
yield return new object[] { Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 1, 1, 4, 4, Offset(Rgb484Result4X4, 1, 1, 6, 6) };
yield return [Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 0, 0, 4, 4, Rgb484Result4X4];
yield return [Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 0, 0, 4, 4, Offset(Rgb484Result4X4, 0, 0, 6, 6)
];
yield return [Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 1, 0, 4, 4, Offset(Rgb484Result4X4, 1, 0, 6, 6)
];
yield return [Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 0, 1, 4, 4, Offset(Rgb484Result4X4, 0, 1, 6, 6)
];
yield return [Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 1, 1, 4, 4, Offset(Rgb484Result4X4, 1, 1, 6, 6)
];
}
}

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

@ -25,52 +25,52 @@ public class RgbTiffColorTests : PhotometricInterpretationTestBase
private static readonly Rgba32 Rgb4_48C = new(68, 136, 204, 255);
private static readonly byte[] Rgb4Bytes4X4 =
{
[
0x00, 0x0F, 0xFF, 0x00, 0x0F, 0xFF,
0xF0, 0x00, 0xF0, 0x00, 0xFF, 0x0F,
0x40, 0x08, 0x00, 0xC0, 0x04, 0x8C,
0x00, 0x04, 0x44, 0x88, 0x8C, 0xCC
};
];
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 }
};
[
[Rgb4_000, Rgb4_FFF, Rgb4_000, Rgb4_FFF],
[Rgb4_F00, Rgb4_0F0, Rgb4_00F, Rgb4_F0F],
[Rgb4_400, Rgb4_800, Rgb4_C00, Rgb4_48C],
[Rgb4_000, Rgb4_444, Rgb4_888, Rgb4_CCC]
];
private static readonly byte[] Rgb4Bytes3X4 =
{
[
0x00, 0x0F, 0xFF, 0x00, 0x00,
0xF0, 0x00, 0xF0, 0x00, 0xF0,
0x40, 0x08, 0x00, 0xC0, 0x00,
0x00, 0x04, 0x44, 0x88, 0x80
};
];
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 }
};
[
[Rgb4_000, Rgb4_FFF, Rgb4_000],
[Rgb4_F00, Rgb4_0F0, Rgb4_00F],
[Rgb4_400, Rgb4_800, Rgb4_C00],
[Rgb4_000, Rgb4_444, Rgb4_888]
];
public static IEnumerable<object[]> Rgb4Data
{
get
{
yield return new object[] { Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 4, 4, Rgb4Result4X4 };
yield return new object[] { Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 4, 4, Offset(Rgb4Result4X4, 0, 0, 6, 6) };
yield return new object[] { Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 1, 0, 4, 4, Offset(Rgb4Result4X4, 1, 0, 6, 6) };
yield return new object[] { Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 0, 1, 4, 4, Offset(Rgb4Result4X4, 0, 1, 6, 6) };
yield return new object[] { Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 1, 1, 4, 4, Offset(Rgb4Result4X4, 1, 1, 6, 6) };
yield return new object[] { Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 3, 4, Rgb4Result3X4 };
yield return new object[] { Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 3, 4, Offset(Rgb4Result3X4, 0, 0, 6, 6) };
yield return new object[] { Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 1, 0, 3, 4, Offset(Rgb4Result3X4, 1, 0, 6, 6) };
yield return new object[] { Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 0, 1, 3, 4, Offset(Rgb4Result3X4, 0, 1, 6, 6) };
yield return new object[] { Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 1, 1, 3, 4, Offset(Rgb4Result3X4, 1, 1, 6, 6) };
yield return [Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 4, 4, Rgb4Result4X4];
yield return [Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 4, 4, Offset(Rgb4Result4X4, 0, 0, 6, 6)];
yield return [Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 1, 0, 4, 4, Offset(Rgb4Result4X4, 1, 0, 6, 6)];
yield return [Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 0, 1, 4, 4, Offset(Rgb4Result4X4, 0, 1, 6, 6)];
yield return [Rgb4Bytes4X4, new TiffBitsPerSample(4, 4, 4), 1, 1, 4, 4, Offset(Rgb4Result4X4, 1, 1, 6, 6)];
yield return [Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 3, 4, Rgb4Result3X4];
yield return [Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 0, 0, 3, 4, Offset(Rgb4Result3X4, 0, 0, 6, 6)];
yield return [Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 1, 0, 3, 4, Offset(Rgb4Result3X4, 1, 0, 6, 6)];
yield return [Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 0, 1, 3, 4, Offset(Rgb4Result3X4, 0, 1, 6, 6)];
yield return [Rgb4Bytes3X4, new TiffBitsPerSample(4, 4, 4), 1, 1, 3, 4, Offset(Rgb4Result3X4, 1, 1, 6, 6)];
}
}
@ -89,30 +89,30 @@ public class RgbTiffColorTests : PhotometricInterpretationTestBase
private static readonly Rgba32 Rgb8_48C = new(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,
064, 000, 000, 128, 000, 000, 192, 000, 000, 064, 128, 192,
000, 000, 000, 064, 064, 064, 128, 128, 128, 192, 192, 192
};
];
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 }
};
[
[Rgb8_000, Rgb8_FFF, Rgb8_000, Rgb8_FFF],
[Rgb8_F00, Rgb8_0F0, Rgb8_00F, Rgb8_F0F],
[Rgb8_400, Rgb8_800, Rgb8_C00, Rgb8_48C],
[Rgb8_000, Rgb8_444, Rgb8_888, Rgb8_CCC]
];
public static IEnumerable<object[]> Rgb8Data
{
get
{
yield return new object[] { Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 0, 0, 4, 4, Rgb8Result4X4 };
yield return new object[] { Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 0, 0, 4, 4, Offset(Rgb8Result4X4, 0, 0, 6, 6) };
yield return new object[] { Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 1, 0, 4, 4, Offset(Rgb8Result4X4, 1, 0, 6, 6) };
yield return new object[] { Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 0, 1, 4, 4, Offset(Rgb8Result4X4, 0, 1, 6, 6) };
yield return new object[] { Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 1, 1, 4, 4, Offset(Rgb8Result4X4, 1, 1, 6, 6) };
yield return [Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 0, 0, 4, 4, Rgb8Result4X4];
yield return [Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 0, 0, 4, 4, Offset(Rgb8Result4X4, 0, 0, 6, 6)];
yield return [Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 1, 0, 4, 4, Offset(Rgb8Result4X4, 1, 0, 6, 6)];
yield return [Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 0, 1, 4, 4, Offset(Rgb8Result4X4, 0, 1, 6, 6)];
yield return [Rgb8Bytes4X4, new TiffBitsPerSample(8, 8, 8), 1, 1, 4, 4, Offset(Rgb8Result4X4, 1, 1, 6, 6)];
}
}
@ -131,30 +131,34 @@ public class RgbTiffColorTests : PhotometricInterpretationTestBase
private static readonly Rgba32 Rgb484_48C = new(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,
0x40, 0x00, 0x80, 0x00, 0xC0, 0x00, 0x48, 0x0C,
0x00, 0x00, 0x44, 0x04, 0x88, 0x08, 0xCC, 0x0C
};
];
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 }
};
[
[Rgb484_000, Rgb484_FFF, Rgb484_000, Rgb484_FFF],
[Rgb484_F00, Rgb484_0F0, Rgb484_00F, Rgb484_F0F],
[Rgb484_400, Rgb484_800, Rgb484_C00, Rgb484_48C],
[Rgb484_000, Rgb484_444, Rgb484_888, Rgb484_CCC]
];
public static IEnumerable<object[]> Rgb484Data
{
get
{
yield return new object[] { Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 0, 0, 4, 4, Rgb484Result4X4 };
yield return new object[] { Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 0, 0, 4, 4, Offset(Rgb484Result4X4, 0, 0, 6, 6) };
yield return new object[] { Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 1, 0, 4, 4, Offset(Rgb484Result4X4, 1, 0, 6, 6) };
yield return new object[] { Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 0, 1, 4, 4, Offset(Rgb484Result4X4, 0, 1, 6, 6) };
yield return new object[] { Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 1, 1, 4, 4, Offset(Rgb484Result4X4, 1, 1, 6, 6) };
yield return [Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 0, 0, 4, 4, Rgb484Result4X4];
yield return [Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 0, 0, 4, 4, Offset(Rgb484Result4X4, 0, 0, 6, 6)
];
yield return [Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 1, 0, 4, 4, Offset(Rgb484Result4X4, 1, 0, 6, 6)
];
yield return [Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 0, 1, 4, 4, Offset(Rgb484Result4X4, 0, 1, 6, 6)
];
yield return [Rgb484Bytes4X4, new TiffBitsPerSample(4, 8, 4), 1, 1, 4, 4, Offset(Rgb484Result4X4, 1, 1, 6, 6)
];
}
}

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

@ -20,100 +20,100 @@ public class WhiteIsZeroTiffColorTests : PhotometricInterpretationTestBase
private static readonly Rgba32 Bit1 = new(0, 0, 0, 255);
private static readonly byte[] BilevelBytes4X4 =
{
[
0b01010000,
0b11110000,
0b01110000,
0b10010000
};
];
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 }
};
[
[Bit0, Bit1, Bit0, Bit1],
[Bit1, Bit1, Bit1, Bit1],
[Bit0, Bit1, Bit1, Bit1],
[Bit1, Bit0, Bit0, Bit1]
];
private static readonly byte[] BilevelBytes12X4 =
{
[
0b01010101, 0b01010000,
0b11111111, 0b11111111,
0b01101001, 0b10100000,
0b10010000, 0b01100000
};
];
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 }
};
[
[Bit0, Bit1, Bit0, Bit1, Bit0, Bit1, Bit0, Bit1, Bit0, Bit1, Bit0, Bit1],
[Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1, Bit1],
[Bit0, Bit1, Bit1, Bit0, Bit1, Bit0, Bit0, Bit1, Bit1, Bit0, Bit1, Bit0],
[Bit1, Bit0, Bit0, Bit1, Bit0, Bit0, Bit0, Bit0, Bit0, Bit1, Bit1, Bit0]
];
private static readonly byte[] Grayscale4Bytes4X4 =
{
[
0x8F, 0x0F,
0xFF, 0xFF,
0x08, 0x8F,
0xF0, 0xF8
};
];
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 }
};
[
[Gray8, GrayF, Gray0, GrayF],
[GrayF, GrayF, GrayF, GrayF],
[Gray0, Gray8, Gray8, GrayF],
[GrayF, Gray0, GrayF, Gray8]
];
private static readonly byte[] Grayscale4Bytes3X4 =
{
[
0x8F, 0x00,
0xFF, 0xF0,
0x08, 0x80,
0xF0, 0xF0
};
];
private static readonly Rgba32[][] Grayscale4Result3X4 =
{
new[] { Gray8, GrayF, Gray0 },
new[] { GrayF, GrayF, GrayF },
new[] { Gray0, Gray8, Gray8 },
new[] { GrayF, Gray0, GrayF }
};
[
[Gray8, GrayF, Gray0],
[GrayF, GrayF, GrayF],
[Gray0, Gray8, Gray8],
[GrayF, Gray0, GrayF]
];
private static readonly byte[] Grayscale8Bytes4X4 =
{
[
128, 255, 000, 255,
255, 255, 255, 255,
000, 128, 128, 255,
255, 000, 255, 128
};
];
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 }
};
[
[Gray128, Gray255, Gray000, Gray255],
[Gray255, Gray255, Gray255, Gray255],
[Gray000, Gray128, Gray128, Gray255],
[Gray255, Gray000, Gray255, Gray128]
];
public static IEnumerable<object[]> BilevelData
{
get
{
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) };
yield return [BilevelBytes4X4, 1, 0, 0, 4, 4, BilevelResult4X4];
yield return [BilevelBytes4X4, 1, 0, 0, 4, 4, Offset(BilevelResult4X4, 0, 0, 6, 6)];
yield return [BilevelBytes4X4, 1, 1, 0, 4, 4, Offset(BilevelResult4X4, 1, 0, 6, 6)];
yield return [BilevelBytes4X4, 1, 0, 1, 4, 4, Offset(BilevelResult4X4, 0, 1, 6, 6)];
yield return [BilevelBytes4X4, 1, 1, 1, 4, 4, Offset(BilevelResult4X4, 1, 1, 6, 6)];
yield return [BilevelBytes12X4, 1, 0, 0, 12, 4, BilevelResult12X4];
yield return [BilevelBytes12X4, 1, 0, 0, 12, 4, Offset(BilevelResult12X4, 0, 0, 18, 6)];
yield return [BilevelBytes12X4, 1, 1, 0, 12, 4, Offset(BilevelResult12X4, 1, 0, 18, 6)];
yield return [BilevelBytes12X4, 1, 0, 1, 12, 4, Offset(BilevelResult12X4, 0, 1, 18, 6)];
yield return [BilevelBytes12X4, 1, 1, 1, 12, 4, Offset(BilevelResult12X4, 1, 1, 18, 6)];
}
}
@ -121,17 +121,17 @@ public class WhiteIsZeroTiffColorTests : PhotometricInterpretationTestBase
{
get
{
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) };
yield return [Grayscale4Bytes4X4, 4, 0, 0, 4, 4, Grayscale4Result4X4];
yield return [Grayscale4Bytes4X4, 4, 0, 0, 4, 4, Offset(Grayscale4Result4X4, 0, 0, 6, 6)];
yield return [Grayscale4Bytes4X4, 4, 1, 0, 4, 4, Offset(Grayscale4Result4X4, 1, 0, 6, 6)];
yield return [Grayscale4Bytes4X4, 4, 0, 1, 4, 4, Offset(Grayscale4Result4X4, 0, 1, 6, 6)];
yield return [Grayscale4Bytes4X4, 4, 1, 1, 4, 4, Offset(Grayscale4Result4X4, 1, 1, 6, 6)];
yield return [Grayscale4Bytes3X4, 4, 0, 0, 3, 4, Grayscale4Result3X4];
yield return [Grayscale4Bytes3X4, 4, 0, 0, 3, 4, Offset(Grayscale4Result3X4, 0, 0, 6, 6)];
yield return [Grayscale4Bytes3X4, 4, 1, 0, 3, 4, Offset(Grayscale4Result3X4, 1, 0, 6, 6)];
yield return [Grayscale4Bytes3X4, 4, 0, 1, 3, 4, Offset(Grayscale4Result3X4, 0, 1, 6, 6)];
yield return [Grayscale4Bytes3X4, 4, 1, 1, 3, 4, Offset(Grayscale4Result3X4, 1, 1, 6, 6)];
}
}
@ -139,11 +139,11 @@ public class WhiteIsZeroTiffColorTests : PhotometricInterpretationTestBase
{
get
{
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) };
yield return [Grayscale8Bytes4X4, 8, 0, 0, 4, 4, Grayscale8Result4X4];
yield return [Grayscale8Bytes4X4, 8, 0, 0, 4, 4, Offset(Grayscale8Result4X4, 0, 0, 6, 6)];
yield return [Grayscale8Bytes4X4, 8, 1, 0, 4, 4, Offset(Grayscale8Result4X4, 1, 0, 6, 6)];
yield return [Grayscale8Bytes4X4, 8, 0, 1, 4, 4, Offset(Grayscale8Result4X4, 0, 1, 6, 6)];
yield return [Grayscale8Bytes4X4, 8, 1, 1, 4, 4, Offset(Grayscale8Result4X4, 1, 1, 6, 6)];
}
}

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

@ -208,8 +208,8 @@ public class TiffMetadataTests
Rational expectedResolution = new(10, 1, simplify: false);
Assert.Equal(expectedResolution, exifProfile.GetValue(ExifTag.XResolution).Value);
Assert.Equal(expectedResolution, exifProfile.GetValue(ExifTag.YResolution).Value);
Assert.Equal(new Number[] { 8u }, exifProfile.GetValue(ExifTag.StripOffsets)?.Value, new NumberComparer());
Assert.Equal(new Number[] { 285u }, exifProfile.GetValue(ExifTag.StripByteCounts)?.Value, new NumberComparer());
Assert.Equal([8u], exifProfile.GetValue(ExifTag.StripOffsets)?.Value, new NumberComparer());
Assert.Equal([285u], exifProfile.GetValue(ExifTag.StripByteCounts)?.Value, new NumberComparer());
Assert.Null(exifProfile.GetValue(ExifTag.ExtraSamples, false)?.Value);
Assert.Equal(32u, exifProfile.GetValue(ExifTag.RowsPerStrip).Value);
Assert.Null(exifProfile.GetValue(ExifTag.SampleFormat, false));

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

@ -12,13 +12,13 @@ public class ColorSpaceTransformUtilsTests
private static void RunCollectColorBlueTransformsTest()
{
uint[] pixelData =
{
[
3074, 256, 256, 256, 0, 65280, 65280, 65280, 256, 256, 0, 256, 0, 65280, 0, 65280, 16711680, 256,
256, 0, 65024, 0, 256, 256, 0, 65280, 0, 65280, 0, 256, 0, 256
};
];
int[] expectedOutput =
{
[
31, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -27,7 +27,7 @@ public class ColorSpaceTransformUtilsTests
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
];
int[] histo = new int[256];
ColorSpaceTransformUtils.CollectColorBlueTransforms(pixelData, 0, 32, 1, 0, 0, histo);
@ -38,13 +38,13 @@ public class ColorSpaceTransformUtilsTests
private static void RunCollectColorRedTransformsTest()
{
uint[] pixelData =
{
[
3074, 256, 256, 256, 0, 65280, 65280, 65280, 256, 256, 0, 256, 0, 65280, 0, 65280, 16711680, 256,
256, 0, 65024, 0, 256, 256, 0, 65280, 0, 65280, 0, 256, 0, 256
};
];
int[] expectedOutput =
{
[
31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -53,7 +53,7 @@ public class ColorSpaceTransformUtilsTests
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
};
];
int[] histo = new int[256];
ColorSpaceTransformUtils.CollectColorRedTransforms(pixelData, 0, 32, 1, 0, histo);

61
tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs

@ -11,8 +11,10 @@ public class LosslessUtilsTests
{
private static void RunCombinedShannonEntropyTest()
{
int[] x = { 3, 5, 2, 5, 3, 1, 2, 2, 3, 3, 1, 2, 1, 2, 1, 1, 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 1, 1, 0, 0, 2, 1, 1, 0, 3, 1, 2, 3, 2, 3 };
int[] y = { 11, 12, 8, 3, 4, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 2, 1, 1, 2, 4, 6, 4 };
int[] x = [3, 5, 2, 5, 3, 1, 2, 2, 3, 3, 1, 2, 1, 2, 1, 1, 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 1, 1, 0, 0, 2, 1, 1, 0, 3, 1, 2, 3, 2, 3
];
int[] y = [11, 12, 8, 3, 4, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 2, 1, 1, 2, 4, 6, 4
];
const float expected = 884.7585f;
float actual = LosslessUtils.CombinedShannonEntropy(x, y);
@ -23,7 +25,7 @@ public class LosslessUtilsTests
private static void RunSubtractGreenTest()
{
uint[] pixelData =
{
[
4293035898, 4293101432, 4292903793, 4292838511, 4292837995, 4292771950, 4292903791, 4293299316,
4293563769, 4293629303, 4293363312, 4291913575, 4289282905, 4288692313, 4289349210, 4289809240,
4289743703, 4289874775, 4289940567, 4289743701, 4290137943, 4290860378, 4291058267, 4291386715,
@ -31,10 +33,10 @@ public class LosslessUtilsTests
4291913571, 4292044130, 4291978850, 4291847521, 4291847524, 4291847779, 4291913571, 4291848293,
4291651689, 4291585895, 4291519584, 4291715936, 4291520355, 4291650658, 4291847263, 4291913313,
4291847777, 4291781731, 4291783015
};
];
uint[] expectedOutput =
{
[
4284188659, 4284254193, 4284318702, 4284187883, 4284318441, 4284383470, 4284318700, 4284124392,
4283799012, 4283864546, 4284581610, 4285163264, 4284891926, 4284497945, 4284761620, 4284893965,
4284828428, 4284959500, 4284959755, 4284828426, 4284960520, 4285289733, 4285159937, 4285292030,
@ -42,7 +44,7 @@ public class LosslessUtilsTests
4285163516, 4285425149, 4285294332, 4285228540, 4285228543, 4285163261, 4285163516, 4285032701,
4284835841, 4284835584, 4284966140, 4285228029, 4284770300, 4285097214, 4285293819, 4285228795,
4285163259, 4285228287, 4284901886
};
];
LosslessUtils.SubtractGreenFromBlueAndRed(pixelData);
@ -52,7 +54,7 @@ public class LosslessUtilsTests
private static void RunAddGreenToBlueAndRedTest()
{
uint[] pixelData =
{
[
4284188659, 4284254193, 4284318702, 4284187883, 4284318441, 4284383470, 4284318700, 4284124392,
4283799012, 4283864546, 4284581610, 4285163264, 4284891926, 4284497945, 4284761620, 4284893965,
4284828428, 4284959500, 4284959755, 4284828426, 4284960520, 4285289733, 4285159937, 4285292030,
@ -60,10 +62,10 @@ public class LosslessUtilsTests
4285163516, 4285425149, 4285294332, 4285228540, 4285228543, 4285163261, 4285163516, 4285032701,
4284835841, 4284835584, 4284966140, 4285228029, 4284770300, 4285097214, 4285293819, 4285228795,
4285163259, 4285228287, 4284901886
};
];
uint[] expectedOutput =
{
[
4293035898, 4293101432, 4292903793, 4292838511, 4292837995, 4292771950, 4292903791, 4293299316,
4293563769, 4293629303, 4293363312, 4291913575, 4289282905, 4288692313, 4289349210, 4289809240,
4289743703, 4289874775, 4289940567, 4289743701, 4290137943, 4290860378, 4291058267, 4291386715,
@ -71,7 +73,7 @@ public class LosslessUtilsTests
4291913571, 4292044130, 4291978850, 4291847521, 4291847524, 4291847779, 4291913571, 4291848293,
4291651689, 4291585895, 4291519584, 4291715936, 4291520355, 4291650658, 4291847263, 4291913313,
4291847777, 4291781731, 4291783015
};
];
LosslessUtils.AddGreenToBlueAndRed(pixelData);
@ -81,13 +83,13 @@ public class LosslessUtilsTests
private static void RunTransformColorTest()
{
uint[] pixelData =
{
[
5998579, 65790, 130301, 16646653, 196350, 130565, 16712702, 16583164, 16452092, 65790, 782600,
647446, 16571414, 16448771, 263931, 132601, 16711935, 131072, 511, 16711679, 132350, 329469,
16647676, 132093, 66303, 16647169, 16515584, 196607, 196096, 16646655, 514, 131326, 16712192,
327169, 16646655, 16776960, 3, 16712190, 511, 16646401, 16580612, 65535, 196092, 327425, 16319743,
392450, 196861, 16712192, 16711680, 130564, 16451071
};
];
Vp8LMultipliers m = new()
{
@ -97,13 +99,13 @@ public class LosslessUtilsTests
};
uint[] expectedOutput =
{
[
100279, 65790, 16710907, 16712190, 130813, 65028, 131840, 264449, 133377, 65790, 61697, 15917319,
14801924, 16317698, 591614, 394748, 16711935, 131072, 65792, 16711679, 328704, 656896, 132607,
328703, 197120, 66563, 16646657, 196607, 130815, 16711936, 131587, 131326, 66049, 261632, 16711936,
16776960, 3, 511, 65792, 16711938, 16580612, 65535, 65019, 327425, 16516097, 261377, 196861, 66049,
16711680, 65027, 16712962
};
];
LosslessUtils.TransformColor(m, pixelData, pixelData.Length);
@ -113,13 +115,13 @@ public class LosslessUtilsTests
private static void RunTransformColorInverseTest()
{
uint[] pixelData =
{
[
100279, 65790, 16710907, 16712190, 130813, 65028, 131840, 264449, 133377, 65790, 61697, 15917319,
14801924, 16317698, 591614, 394748, 16711935, 131072, 65792, 16711679, 328704, 656896, 132607,
328703, 197120, 66563, 16646657, 196607, 130815, 16711936, 131587, 131326, 66049, 261632, 16711936,
16776960, 3, 511, 65792, 16711938, 16580612, 65535, 65019, 327425, 16516097, 261377, 196861, 66049,
16711680, 65027, 16712962
};
];
Vp8LMultipliers m = new()
{
@ -129,13 +131,13 @@ public class LosslessUtilsTests
};
uint[] expectedOutput =
{
[
5998579, 65790, 130301, 16646653, 196350, 130565, 16712702, 16583164, 16452092, 65790, 782600,
647446, 16571414, 16448771, 263931, 132601, 16711935, 131072, 511, 16711679, 132350, 329469,
16647676, 132093, 66303, 16647169, 16515584, 196607, 196096, 16646655, 514, 131326, 16712192,
327169, 16646655, 16776960, 3, 16712190, 511, 16646401, 16580612, 65535, 196092, 327425, 16319743,
392450, 196861, 16712192, 16711680, 130564, 16451071
};
];
LosslessUtils.TransformColorInverse(m, pixelData);
@ -145,7 +147,7 @@ public class LosslessUtilsTests
private static void RunPredictor11Test()
{
// arrange
uint[] topData = { 4278258949, 4278258949 };
uint[] topData = [4278258949, 4278258949];
const uint left = 4294839812;
short[] scratch = new short[8];
const uint expectedResult = 4294839812;
@ -166,7 +168,7 @@ public class LosslessUtilsTests
private static void RunPredictor12Test()
{
// arrange
uint[] topData = { 4294844413, 4294779388 };
uint[] topData = [4294844413, 4294779388];
const uint left = 4294844413;
const uint expectedResult = 4294779388;
@ -186,10 +188,10 @@ public class LosslessUtilsTests
private static void RunPredictor13Test()
{
// arrange
uint[] topData0 = { 4278193922, 4278193666 };
uint[] topData0 = [4278193922, 4278193666];
const uint left0 = 4278193410;
const uint expectedResult0 = 4278193154;
uint[] topData1 = { 4294933015, 4278219803 };
uint[] topData1 = [4294933015, 4278219803];
const uint left1 = 4278236686;
const uint expectedResult1 = 4278231571;
uint actual0 = 0;
@ -218,17 +220,18 @@ public class LosslessUtilsTests
public void BundleColorMap_WithXbitsZero_Works()
{
// arrange
byte[] row = { 238, 238, 238, 238, 238, 238, 240, 237, 240, 235, 223, 223, 218, 220, 226, 219, 220, 204, 218, 211, 218, 221, 254, 255 };
byte[] row = [238, 238, 238, 238, 238, 238, 240, 237, 240, 235, 223, 223, 218, 220, 226, 219, 220, 204, 218, 211, 218, 221, 254, 255
];
int xBits = 0;
uint[] actual = new uint[row.Length];
uint[] expected =
{
[
4278251008, 4278251008, 4278251008, 4278251008, 4278251008,
4278251008, 4278251520, 4278250752, 4278251520, 4278250240,
4278247168, 4278247168, 4278245888, 4278246400, 4278247936,
4278246144, 4278246400, 4278242304, 4278245888, 4278244096,
4278245888, 4278246656, 4278255104, 4278255360
};
];
// act
LosslessUtils.BundleColorMap(row, actual.Length, xBits, actual);
@ -242,7 +245,7 @@ public class LosslessUtilsTests
{
// arrange
byte[] row =
{
[
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
@ -251,17 +254,17 @@ public class LosslessUtilsTests
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
};
];
int xBits = 2;
uint[] actual = new uint[row.Length];
uint[] expected =
{
[
4278233600, 4278233600, 4278233600, 4278233600, 4278255360, 4278255360, 4278255360, 4278255360, 4278233600, 4278233600, 4278233600, 4278233600,
4278255360, 4278255360, 4278255360, 4278255360, 4278211840, 4278211840, 4278211840, 4278211840, 4278255360, 4278255360, 4278255360, 4278255360,
4278255360, 4278255360, 4278255360, 4278255360, 4278255360, 4278255360, 4278255360, 4278206208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
];
// act
LosslessUtils.BundleColorMap(row, actual.Length, xBits, actual);

43
tests/ImageSharp.Tests/Formats/WebP/LossyUtilsTests.cs

@ -13,9 +13,10 @@ public class LossyUtilsTests
private static void RunTransformTwoTest()
{
// arrange
short[] src = { 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 23, 0, 0, -23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
short[] src = [19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 23, 0, 0, -23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
];
byte[] dst =
{
[
103, 103, 103, 103, 103, 103, 103, 103, 0, 0, 0, 0, 169, 169, 169, 169, 171, 171, 171, 171,
171, 171, 171, 171, 0, 0, 0, 0, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
0, 0, 0, 0, 169, 169, 169, 169, 171, 171, 171, 171, 171, 171, 171, 171, 0, 0, 0, 0,
@ -23,16 +24,16 @@ public class LossyUtilsTests
171, 171, 171, 171, 171, 171, 171, 171, 0, 0, 0, 0, 103, 103, 103, 103, 103, 103, 103, 103,
103, 103, 103, 103, 0, 0, 0, 0, 169, 169, 169, 169, 171, 171, 171, 171, 171, 171, 171, 171,
0, 0, 0, 0, 0, 0, 0, 0
};
];
byte[] expected =
{
[
105, 105, 105, 105, 105, 103, 100, 98, 0, 0, 0, 0, 169, 169, 169, 169, 171, 171, 171, 171, 171, 171,
171, 171, 0, 0, 0, 0, 103, 103, 103, 103, 105, 105, 105, 105, 108, 105, 102, 100, 0, 0, 0, 0, 169,
169, 169, 169, 171, 171, 171, 171, 171, 171, 171, 171, 0, 0, 0, 0, 103, 103, 103, 103, 105, 105,
105, 105, 111, 109, 106, 103, 0, 0, 0, 0, 169, 169, 169, 169, 171, 171, 171, 171, 171, 171, 171,
171, 0, 0, 0, 0, 103, 103, 103, 103, 105, 105, 105, 105, 113, 111, 108, 106, 0, 0, 0, 0, 169, 169,
169, 169, 171, 171, 171, 171, 171, 171, 171, 171, 0, 0, 0, 0, 0, 0, 0, 0
};
];
int[] scratch = new int[16];
// act
@ -45,9 +46,9 @@ public class LossyUtilsTests
private static void RunTransformOneTest()
{
// arrange
short[] src = { -176, 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
short[] src = [-176, 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
byte[] dst =
{
[
128, 128, 128, 128, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 129, 128, 128, 128, 128,
128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 129, 128, 128, 128, 128, 128, 128, 128, 128,
0, 0, 0, 0, 0, 0, 0, 129, 128, 128, 128, 128, 128, 128, 128, 128, 0, 0, 0, 0,
@ -55,9 +56,9 @@ public class LossyUtilsTests
128, 128, 128, 128, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 129, 128, 128, 128, 128,
128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 129, 128, 128, 128, 128, 128, 128, 128, 128,
0, 0, 0, 0, 0, 0, 0, 129
};
];
byte[] expected =
{
[
111, 111, 111, 111, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 129, 128, 128, 128, 128,
128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 129, 108, 108, 108, 108, 128, 128, 128, 128,
0, 0, 0, 0, 0, 0, 0, 129, 128, 128, 128, 128, 128, 128, 128, 128, 0, 0, 0, 0,
@ -65,7 +66,7 @@ public class LossyUtilsTests
128, 128, 128, 128, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 129, 101, 101, 101, 101,
128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 129, 128, 128, 128, 128, 128, 128, 128, 128,
0, 0, 0, 0, 0, 0, 0, 129
};
];
int[] scratch = new int[16];
// act
@ -86,7 +87,7 @@ public class LossyUtilsTests
a[i] = (byte)rand.Next(byte.MaxValue);
b[i] = (byte)rand.Next(byte.MaxValue);
}
int[] expected = { 2533110, 2818581, 2984663, 2891188, 2855134, 2634604, 2466504, 3061747, 2626010, 2640965 };
int[] expected = [2533110, 2818581, 2984663, 2891188, 2855134, 2634604, 2466504, 3061747, 2626010, 2640965];
// act + assert
int offset = 0;
@ -110,7 +111,7 @@ public class LossyUtilsTests
a[i] = (byte)rand.Next(byte.MaxValue);
b[i] = (byte)rand.Next(byte.MaxValue);
}
int[] expected = { 1298274, 1234836, 1325264, 1493317, 1551995, 1432668, 1407891, 1483297, 1537930, 1317204 };
int[] expected = [1298274, 1234836, 1325264, 1493317, 1551995, 1432668, 1407891, 1483297, 1537930, 1317204];
// act + assert
int offset = 0;
@ -134,7 +135,7 @@ public class LossyUtilsTests
a[i] = (byte)rand.Next(byte.MaxValue);
b[i] = (byte)rand.Next(byte.MaxValue);
}
int[] expected = { 194133, 125861, 165966, 195688, 106491, 173015, 266960, 200272, 311224, 122545 };
int[] expected = [194133, 125861, 165966, 195688, 106491, 173015, 266960, 200272, 311224, 122545];
// act + assert
int offset = 0;
@ -151,7 +152,7 @@ public class LossyUtilsTests
{
// arrange
byte[] input =
{
[
154, 145, 102, 115, 127, 129, 126, 125, 126, 120, 133, 152, 157, 153, 119, 94, 104, 116, 111, 113,
113, 109, 105, 124, 173, 175, 177, 170, 175, 172, 166, 164, 151, 141, 99, 114, 125, 126, 135, 150,
133, 115, 127, 149, 141, 168, 100, 54, 110, 117, 115, 116, 119, 115, 117, 130, 174, 174, 174, 157,
@ -159,9 +160,9 @@ public class LossyUtilsTests
109, 115, 113, 120, 120, 117, 128, 115, 174, 173, 173, 161, 152, 148, 153, 162, 105, 140, 96, 114,
115, 122, 141, 173, 190, 190, 142, 106, 151, 78, 66, 141, 110, 117, 123, 136, 118, 124, 127, 114,
173, 175, 166, 155, 155, 159, 159, 158
};
];
uint[] dc = new uint[4];
uint[] expectedDc = { 1940, 2139, 2252, 1813 };
uint[] expectedDc = [1940, 2139, 2252, 1813];
// act
LossyUtils.Mean16x4(input, dc);
@ -174,24 +175,24 @@ public class LossyUtilsTests
{
// arrange
byte[] a =
{
[
27, 27, 28, 29, 29, 28, 27, 27, 27, 28, 28, 29, 29, 28, 28, 27, 129, 129, 129, 129, 129, 129, 129,
129, 128, 128, 128, 128, 128, 128, 128, 128, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 29, 29, 28,
28, 27, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128, 27, 27, 26,
26, 26, 26, 27, 27, 27, 28, 28, 29, 29, 28, 28, 27, 129, 129, 129, 129, 129, 129, 129, 129, 128,
128, 128, 128, 128, 128, 128, 128, 28, 27, 27, 26, 26, 27, 27, 28, 27, 28, 28, 29, 29, 28, 28, 27
};
];
byte[] b =
{
[
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 204, 204, 204, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204, 204, 204, 204, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
28, 28, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 28, 28, 28,
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 204, 204, 204, 204, 204, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204, 204, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28
};
];
ushort[] w = { 38, 32, 20, 9, 32, 28, 17, 7, 20, 17, 10, 4, 9, 7, 4, 2 };
ushort[] w = [38, 32, 20, 9, 32, 28, 17, 7, 20, 17, 10, 4, 9, 7, 4, 2];
int expected = 2;
// act

8
tests/ImageSharp.Tests/Formats/WebP/PredictorEncoderTests.cs

@ -43,7 +43,7 @@ public class PredictorEncoderTests
{
// arrange
uint[] expectedData =
{
[
4278191104, 4278191104, 4278191104, 4278191104, 4278191104, 4278191104, 4278191104, 4294577152,
4294707200, 4294707200, 4294707200, 4294707200, 4294837248, 4294837248, 4293926912, 4294316544,
4278191104, 4278191104, 4294837248, 4294837248, 4280287232, 4280350720, 4294447104, 4294707200,
@ -76,7 +76,7 @@ public class PredictorEncoderTests
4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4279503872, 4279503872, 4280288256,
4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4280287232,
4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4280287232
};
];
// Convert image pixels to bgra array.
byte[] imgBytes = File.ReadAllBytes(TestImageFullPath(TestImages.Webp.Peak));
@ -100,13 +100,13 @@ public class PredictorEncoderTests
{
// arrange
uint[] expectedData =
{
[
4278714368, 4278192876, 4278198304, 4278198304, 4278190304, 4278190080, 4278190080, 4278198272,
4278197760, 4278198816, 4278197794, 4278197774, 4278190080, 4278190080, 4278198816, 4278197281,
4278197280, 4278197792, 4278200353, 4278191343, 4278190304, 4294713873, 4278198784, 4294844416,
4278201578, 4278200044, 4278191343, 4278190288, 4294705200, 4294717139, 4278203628, 4278201064,
4278201586, 4278197792, 4279240909
};
];
// Convert image pixels to bgra array.
byte[] imgBytes = File.ReadAllBytes(TestImageFullPath(TestImages.Webp.Lossy.BikeSmall));

13
tests/ImageSharp.Tests/Formats/WebP/QuantEncTests.cs

@ -12,13 +12,14 @@ public class QuantEncTests
private static unsafe void RunQuantizeBlockTest()
{
// arrange
short[] input = { 378, 777, -851, 888, 259, 148, 0, -111, -185, -185, -74, -37, 148, 74, 111, 74 };
short[] input = [378, 777, -851, 888, 259, 148, 0, -111, -185, -185, -74, -37, 148, 74, 111, 74];
short[] output = new short[16];
ushort[] q = { 42, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37 };
ushort[] iq = { 3120, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542 };
uint[] bias = { 49152, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296 };
uint[] zthresh = { 26, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21 };
short[] expectedOutput = { 9, 21, 7, -5, 4, -23, 24, 0, -5, 4, 2, -2, -3, -1, 3, 2 };
ushort[] q = [42, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37];
ushort[] iq = [3120, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542, 3542];
uint[] bias = [49152, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296, 55296
];
uint[] zthresh = [26, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21];
short[] expectedOutput = [9, 21, 7, -5, 4, -23, 24, 0, -5, 4, 2, -2, -3, -1, 3, 2];
int expectedResult = 1;
Vp8Matrix vp8Matrix = default;
for (int i = 0; i < 16; i++)

42
tests/ImageSharp.Tests/Formats/WebP/Vp8EncodingTests.cs

@ -12,12 +12,14 @@ public class Vp8EncodingTests
private static void RunFTransform2Test()
{
// arrange
byte[] src = { 154, 154, 151, 151, 149, 148, 151, 157, 163, 163, 154, 132, 102, 98, 104, 108, 107, 104, 104, 103, 101, 106, 123, 119, 170, 171, 172, 171, 168, 175, 171, 173, 151, 151, 149, 150, 147, 147, 146, 159, 164, 165, 154, 129, 92, 90, 101, 105, 104, 103, 104, 101, 100, 105, 123, 117, 172, 172, 172, 168, 170, 177, 170, 175, 151, 149, 150, 150, 147, 147, 156, 161, 161, 161, 151, 126, 93, 90, 102, 107, 104, 103, 104, 101, 104, 104, 122, 117, 172, 172, 170, 168, 170, 177, 172, 175, 150, 149, 152, 151, 148, 151, 160, 159, 157, 157, 148, 133, 96, 90, 103, 107, 104, 104, 101, 100, 102, 102, 121, 117, 170, 170, 169, 171, 171, 179, 173, 175 };
byte[] reference = { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129 };
byte[] src = [154, 154, 151, 151, 149, 148, 151, 157, 163, 163, 154, 132, 102, 98, 104, 108, 107, 104, 104, 103, 101, 106, 123, 119, 170, 171, 172, 171, 168, 175, 171, 173, 151, 151, 149, 150, 147, 147, 146, 159, 164, 165, 154, 129, 92, 90, 101, 105, 104, 103, 104, 101, 100, 105, 123, 117, 172, 172, 172, 168, 170, 177, 170, 175, 151, 149, 150, 150, 147, 147, 156, 161, 161, 161, 151, 126, 93, 90, 102, 107, 104, 103, 104, 101, 104, 104, 122, 117, 172, 172, 170, 168, 170, 177, 172, 175, 150, 149, 152, 151, 148, 151, 160, 159, 157, 157, 148, 133, 96, 90, 103, 107, 104, 104, 101, 100, 102, 102, 121, 117, 170, 170, 169, 171, 171, 179, 173, 175
];
byte[] reference = [128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129
];
short[] actualOutput1 = new short[16];
short[] actualOutput2 = new short[16];
short[] expectedOutput1 = { 182, 4, 1, 1, 6, 7, -1, -4, 5, 0, -2, 1, 2, 1, 1, 1 };
short[] expectedOutput2 = { 192, -34, 10, 1, -11, 8, 10, -7, 6, 3, -8, 4, 5, -3, -2, 6 };
short[] expectedOutput1 = [182, 4, 1, 1, 6, 7, -1, -4, 5, 0, -2, 1, 2, 1, 1, 1];
short[] expectedOutput2 = [192, -34, 10, 1, -11, 8, 10, -7, 6, 3, -8, 4, 5, -3, -2, 6];
// act
Vp8Encoding.FTransform2(src, reference, actualOutput1, actualOutput2, new int[16]);
@ -31,7 +33,7 @@ public class Vp8EncodingTests
{
// arrange
byte[] src =
{
[
154, 154, 151, 151, 149, 148, 151, 157, 163, 163, 154, 132, 102, 98, 104, 108, 107, 104, 104, 103,
101, 106, 123, 119, 170, 171, 172, 171, 168, 175, 171, 173, 151, 151, 149, 150, 147, 147, 146, 159,
164, 165, 154, 129, 92, 90, 101, 105, 104, 103, 104, 101, 100, 105, 123, 117, 172, 172, 172, 168,
@ -39,9 +41,9 @@ public class Vp8EncodingTests
104, 103, 104, 101, 104, 104, 122, 117, 172, 172, 170, 168, 170, 177, 172, 175, 150, 149, 152, 151,
148, 151, 160, 159, 157, 157, 148, 133, 96, 90, 103, 107, 104, 104, 101, 100, 102, 102, 121, 117,
170, 170, 169, 171, 171, 179, 173, 175
};
];
byte[] reference =
{
[
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129,
@ -49,9 +51,9 @@ public class Vp8EncodingTests
129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129,
129, 129, 129, 129, 129, 129, 129, 129
};
];
short[] actualOutput = new short[16];
short[] expectedOutput = { 182, 4, 1, 1, 6, 7, -1, -4, 5, 0, -2, 1, 2, 1, 1, 1 };
short[] expectedOutput = [182, 4, 1, 1, 6, 7, -1, -4, 5, 0, -2, 1, 2, 1, 1, 1];
// act
Vp8Encoding.FTransform(src, reference, actualOutput, new int[16]);
@ -64,7 +66,7 @@ public class Vp8EncodingTests
{
// arrange
byte[] reference =
{
[
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129,
@ -72,17 +74,18 @@ public class Vp8EncodingTests
129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129,
129, 129, 129, 129, 129, 129, 129, 129
};
short[] input = { 1, 216, -48, 0, 96, -24, -48, 24, 0, -24, 24, 0, 0, 0, 0, 0, 38, -240, -72, -24, 0, -24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
];
short[] input = [1, 216, -48, 0, 96, -24, -48, 24, 0, -24, 24, 0, 0, 0, 0, 0, 38, -240, -72, -24, 0, -24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
];
byte[] dst = new byte[128];
byte[] expected =
{
[
161, 160, 149, 105, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 160, 160, 133, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 156, 147, 109, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 152, 128, 87, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};
];
int[] scratch = new int[16];
// act
@ -96,7 +99,7 @@ public class Vp8EncodingTests
{
// arrange
byte[] reference =
{
[
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129,
@ -104,17 +107,18 @@ public class Vp8EncodingTests
129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129,
129, 129, 129, 129, 129, 129, 129, 129
};
short[] input = { 1, 216, -48, 0, 96, -24, -48, 24, 0, -24, 24, 0, 0, 0, 0, 0, 38, -240, -72, -24, 0, -24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
];
short[] input = [1, 216, -48, 0, 96, -24, -48, 24, 0, -24, 24, 0, 0, 0, 0, 0, 38, -240, -72, -24, 0, -24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
];
byte[] dst = new byte[128];
byte[] expected =
{
[
161, 160, 149, 105, 78, 127, 156, 170, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 160, 160, 133, 85, 81, 129, 155, 167, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 156, 147, 109, 76, 85, 130, 153, 163, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 152, 128, 87, 83, 88, 132, 152, 159, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
];
int[] scratch = new int[16];
// act

8
tests/ImageSharp.Tests/Formats/WebP/Vp8LHistogramTests.cs

@ -14,7 +14,7 @@ public class Vp8LHistogramTests
{
// arrange
uint[] pixelData =
{
[
4278191104, 4278191104, 4278191104, 4278191104, 4278191104, 4278191104, 4278191104, 4294577152,
4294707200, 4294707200, 4294707200, 4294707200, 4294837248, 4294837248, 4293926912, 4294316544,
4278191104, 4278191104, 4294837248, 4294837248, 4280287232, 4280350720, 4294447104, 4294707200,
@ -47,10 +47,10 @@ public class Vp8LHistogramTests
4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4279503872, 4279503872, 4280288256,
4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4280287232,
4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4280287232, 4280287232
};
];
uint[] literals =
{
[
198, 0, 14, 0, 46, 0, 22, 0, 36, 0, 24, 0, 12, 0, 10, 0, 10, 0, 2, 0, 2, 0, 0, 0, 0, 0, 6, 0, 0, 0,
10, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 4, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -59,7 +59,7 @@ public class Vp8LHistogramTests
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 6, 0, 2, 0, 0, 0, 0, 0, 6, 0, 0, 0, 2, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 6, 0, 2, 0, 2, 0, 2, 0, 0, 0, 8, 0, 2, 0, 38, 0, 4
};
];
uint[] expectedLiterals = new uint[1305];

2
tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs

@ -239,7 +239,7 @@ public class Vp8ResidualTests
{
// arrange
Vp8Residual residual = new();
short[] coeffs = { 110, 0, -2, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0 };
short[] coeffs = [110, 0, -2, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0];
// act
residual.SetCoeffs(coeffs);

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save