From 2991c16c9d3b0efb840d07f4b9f023cdb54c7506 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Thu, 12 May 2022 22:55:35 -0500 Subject: [PATCH] f --- src/pixie/fileformats/jpeg.nim | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pixie/fileformats/jpeg.nim b/src/pixie/fileformats/jpeg.nim index ec601ec..92b72a7 100644 --- a/src/pixie/fileformats/jpeg.nim +++ b/src/pixie/fileformats/jpeg.nim @@ -383,25 +383,23 @@ proc decodeSOS(state: var DecoderState) = proc fillBitBuffer(state: var DecoderState) = ## When we are low on bits, we need to call this to populate some more. - while true: - let b = if state.hitEnd: + while state.bitsBuffered < 24: + let b = + if state.hitEnd: 0.uint32 else: state.readUint8().uint32 if b == 0xFF: var c = state.readUint8() - while c == 0xFF: c = state.readUint8() + while c == 0xFF: + c = state.readUint8() if c != 0: - dec state.pos - dec state.pos + state.pos -= 2 state.hitEnd = true return state.bitBuffer = state.bitBuffer or (b shl (24 - state.bitsBuffered)) state.bitsBuffered += 8 - if not(state.bitsBuffered <= 24): - break - proc huffmanDecode(state: var DecoderState, tableCurrent, table: int): uint8 = ## Decode a uint8 from the huffman table. if state.bitsBuffered < 16: