mirror of https://github.com/SixLabors/ImageSharp
2 changed files with 70 additions and 19 deletions
@ -0,0 +1,44 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
using Xunit; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|||
{ |
|||
public class ZigZagTests |
|||
{ |
|||
[Fact] |
|||
public void ZigZagCanHandleAllPossibleCoefficients() |
|||
{ |
|||
// Mimic the behaviour of the huffman scan decoder using all possible byte values
|
|||
short[] block = new short[64]; |
|||
var zigzag = ZigZag.CreateUnzigTable(); |
|||
|
|||
for (int h = 0; h < 255; h++) |
|||
{ |
|||
for (int i = 1; i < 64; i++) |
|||
{ |
|||
int s = h; |
|||
int r = s >> 4; |
|||
s &= 15; |
|||
|
|||
if (s != 0) |
|||
{ |
|||
i += r; |
|||
block[zigzag[i++]] = (short)s; |
|||
} |
|||
else |
|||
{ |
|||
if (r == 0) |
|||
{ |
|||
break; |
|||
} |
|||
|
|||
i += 16; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue