Skip to content

Commit

Permalink
sleep time.
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusfriedman committed Oct 27, 2024
1 parent 9d21bcc commit 2461ec5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 2 additions & 5 deletions Codecs/Image/Jpeg/Classes/HuffmanTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ internal void BuildCodeTable()
throw new ArgumentException($"Value {value} not found in Huffman table.");
}

public bool TryGetCode(int code, int length, out (ushort code, byte length) value)
public bool TryGetCode(int code, out (ushort code, byte length) value)
{
// Convert the code and length to a byte key
byte key = (byte)((code << 4) | length);

if (_codeTable.TryGetValue(key, out value))
if (_codeTable.TryGetValue((byte)code, out value))
{
return true;
}
Expand Down
10 changes: 7 additions & 3 deletions Codecs/Image/Jpeg/JpegCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ private static int DecodeHuffman(BitReader stream, HuffmanTable table)
length++;

// Try to get the Huffman code from the table
if (table.TryGetCode(code, length, out var value))
if (table.TryGetCode(code, out var value))
{
return value.code;
return value.length;
}

// Check for an invalid length (e.g., exceeding the maximum code length)
Expand All @@ -270,8 +270,8 @@ private static int DecodeHuffman(BitReader stream, HuffmanTable table)

private static short[] ReadBlock(BitReader stream, HuffmanTable dcTable, HuffmanTable acTable, ref int previousDC)
{
//Todo, should not build every time called.
dcTable.BuildCodeTable();

acTable.BuildCodeTable();

var block = new short[BlockSize * BlockSize]; // Assuming 8x8 block
Expand Down Expand Up @@ -337,6 +337,10 @@ internal static void Decompress(JpegImage jpegImage)

var quantTable = jpegImage.JpegState.GetQuantizationTable(component.Tqi);

//Should have logging support
if (dcTable == null || acTable == null || quantTable == null)
continue;

int previousDC = 0;
for (int i = 0; i < BlockSize; i++)
{
Expand Down

0 comments on commit 2461ec5

Please sign in to comment.