|
|
|
@ -17,17 +17,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components |
|
|
|
internal unsafe struct ZigZag |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Copy of <see cref="Unzig"/> in a value type
|
|
|
|
/// </summary>
|
|
|
|
public fixed byte Data[64 + 16]; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <para>
|
|
|
|
/// Unzig maps from the zigzag ordering to the natural ordering. For example,
|
|
|
|
/// unzig[3] is the column and row of the fourth element in zigzag order. The
|
|
|
|
/// value is 16, which means first column (16%8 == 0) and third row (16/8 == 2).
|
|
|
|
/// </para>
|
|
|
|
/// <para>
|
|
|
|
/// When reading corrupted data, the Huffman decoders could attempt
|
|
|
|
/// to reference an entry beyond the end of this array (if the decoded
|
|
|
|
/// zero run length reaches past the end of the block). To prevent
|
|
|
|
@ -36,9 +25,21 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components |
|
|
|
/// to be stored in location 63 of the block, not somewhere random.
|
|
|
|
/// The worst case would be a run-length of 15, which means we need 16
|
|
|
|
/// fake entries.
|
|
|
|
/// </para>
|
|
|
|
/// </summary>
|
|
|
|
private const int Size = 64 + 16; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Copy of <see cref="Unzig"/> in a value type
|
|
|
|
/// </summary>
|
|
|
|
public fixed byte Data[Size]; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Unzig maps from the zigzag ordering to the natural ordering. For example,
|
|
|
|
/// unzig[3] is the column and row of the fourth element in zigzag order. The
|
|
|
|
/// value is 16, which means first column (16%8 == 0) and third row (16/8 == 2).
|
|
|
|
/// </summary>
|
|
|
|
private static readonly byte[] Unzig = |
|
|
|
new byte[Size] |
|
|
|
{ |
|
|
|
0, 1, 8, 16, 9, 2, 3, 10, |
|
|
|
17, 24, 32, 25, 18, 11, 4, 5, |
|
|
|
@ -75,7 +76,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components |
|
|
|
{ |
|
|
|
ZigZag result = default; |
|
|
|
byte* unzigPtr = result.Data; |
|
|
|
Marshal.Copy(Unzig, 0, (IntPtr)unzigPtr, 64 + 16); |
|
|
|
Marshal.Copy(Unzig, 0, (IntPtr)unzigPtr, Size); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@ -86,7 +87,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components |
|
|
|
{ |
|
|
|
Block8x8F result = default; |
|
|
|
|
|
|
|
for (int i = 0; i < 64; i++) |
|
|
|
for (int i = 0; i < Block8x8F.Size; i++) |
|
|
|
{ |
|
|
|
result[Unzig[i]] = qt[i]; |
|
|
|
} |
|
|
|
|