Browse Source

Refactored byte[] array in ZigZag type

pull/1574/head
Sergio Pedri 6 years ago
parent
commit
65114123ce
  1. 16
      src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs

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

@ -34,12 +34,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
public fixed byte Data[Size]; public fixed byte Data[Size];
/// <summary> /// <summary>
/// Unzig maps from the zigzag ordering to the natural ordering. For example, /// Gets the unzigs map, which maps from the zigzag ordering to the natural ordering.
/// unzig[3] is the column and row of the fourth element in zigzag order. The /// For example, unzig[3] is the column and row of the fourth element in zigzag order.
/// value is 16, which means first column (16%8 == 0) and third row (16/8 == 2). /// The value is 16, which means first column (16%8 == 0) and third row (16/8 == 2).
/// </summary> /// </summary>
private static readonly byte[] Unzig = private static ReadOnlySpan<byte> Unzig => new byte[]
new byte[Size]
{ {
0, 1, 8, 16, 9, 2, 3, 10, 0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5, 17, 24, 32, 25, 18, 11, 4, 5,
@ -75,8 +74,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
public static ZigZag CreateUnzigTable() public static ZigZag CreateUnzigTable()
{ {
ZigZag result = default; ZigZag result = default;
byte* unzigPtr = result.Data; ref byte sourceRef = ref MemoryMarshal.GetReference(Unzig);
Marshal.Copy(Unzig, 0, (IntPtr)unzigPtr, Size); ref byte destinationRef = ref Unsafe.AsRef<byte>(result.Data);
Unsafe.CopyBlock(ref sourceRef, ref destinationRef, Size);
return result; return result;
} }

Loading…
Cancel
Save