diff --git a/src/pixie/fileformats/jpeg.nim b/src/pixie/fileformats/jpeg.nim index c868275..2fb59e2 100644 --- a/src/pixie/fileformats/jpeg.nim +++ b/src/pixie/fileformats/jpeg.nim @@ -399,11 +399,10 @@ proc fillBitBuffer(state: var DecoderState) = proc huffmanDecode(state: var DecoderState, tableCurrent, table: int): uint8 = ## Decode a uint8 from the huffman table. - if state.bitsBuffered < 16: - state.fillBitBuffer() - var huffman {.byaddr.} = state.huffmanTables[tableCurrent][table] + state.fillBitBuffer() + let fastId = (state.bitBuffer shr (32 - fastBits)) and ((1 shl fastBits) - 1) fast = huffman.fast[fastId] @@ -430,7 +429,7 @@ proc huffmanDecode(state: var DecoderState, tableCurrent, table: int): uint8 = let symbolId = (state.bitBuffer shr (32 - i)).int + huffman.deltas[i] state.bitBuffer = state.bitBuffer shl i state.bitsBuffered -= i - huffman.symbols[symbolId] + return huffman.symbols[symbolId] template lrot(value: uint32, shift: int): uint32 = ## Left rotate - used for huffman decoding.