Browse Source

Change CodeLengthCodeOrder, LiteralMap and Norm to ReadOnlySpan

pull/1846/head
Brian Popow 5 years ago
parent
commit
c712f98e05
  1. 13
      src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs
  2. 3
      src/ImageSharp/Formats/Webp/WebpLookupTables.cs

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

@ -65,15 +65,8 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
FixedTableSize + 2704 FixedTableSize + 2704
}; };
private static readonly byte[] CodeLengthCodeOrder = { 17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
private static readonly int NumCodeLengthCodes = CodeLengthCodeOrder.Length; private static readonly int NumCodeLengthCodes = CodeLengthCodeOrder.Length;
private static readonly byte[] LiteralMap =
{
0, 1, 1, 1, 0
};
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WebpLosslessDecoder"/> class. /// Initializes a new instance of the <see cref="WebpLosslessDecoder"/> class.
/// </summary> /// </summary>
@ -87,6 +80,12 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
this.configuration = configuration; this.configuration = configuration;
} }
// 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 };
// 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 };
/// <summary> /// <summary>
/// Decodes the image from the stream using the bitreader. /// Decodes the image from the stream using the bitreader.
/// </summary> /// </summary>

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

@ -239,7 +239,8 @@ namespace SixLabors.ImageSharp.Formats.Webp
} }
}; };
public static readonly byte[] Norm = // This uses C#'s compiler optimization to refer to assembly's static data directly.
public static ReadOnlySpan<byte> Norm => new byte[]
{ {
// renorm_sizes[i] = 8 - log2(i) // renorm_sizes[i] = 8 - log2(i)
7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,

Loading…
Cancel
Save