getBits
This commit is contained in:
parent
7b1cd09cd3
commit
b1d111d1bf
1 changed files with 5 additions and 6 deletions
|
@ -547,17 +547,16 @@ proc getBitsAsSignedInt(state: var DecoderState, n: int): int =
|
||||||
state.bitsBuffered -= n
|
state.bitsBuffered -= n
|
||||||
result = k.int + (biases[n] and (not sign))
|
result = k.int + (biases[n] and (not sign))
|
||||||
|
|
||||||
proc getBitsAsUnsignedInt(state: var DecoderState, n: int): int =
|
proc getBits(state: var DecoderState, n: int): int =
|
||||||
## Get n number of bits as a unsigned integer.
|
## Get n number of bits as a unsigned integer.
|
||||||
if n notin 0 .. 16:
|
if n notin 0 .. 16:
|
||||||
failInvalid()
|
failInvalid()
|
||||||
if state.bitsBuffered < n:
|
if state.bitsBuffered < n:
|
||||||
state.fillBitBuffer()
|
state.fillBitBuffer()
|
||||||
var k = lrot(state.bitBuffer, n)
|
let k = lrot(state.bitBuffer, n)
|
||||||
state.bitBuffer = k and (not bitMasks[n])
|
state.bitBuffer = k and (not bitMasks[n])
|
||||||
k = k and bitMasks[n]
|
result = (k and bitMasks[n]).int
|
||||||
state.bitsBuffered -= n
|
state.bitsBuffered -= n
|
||||||
return k.int
|
|
||||||
|
|
||||||
proc decodeRegularBlock(
|
proc decodeRegularBlock(
|
||||||
state: var DecoderState, component: int, data: var array[64, int16]
|
state: var DecoderState, component: int, data: var array[64, int16]
|
||||||
|
@ -642,7 +641,7 @@ proc decodeProgressiveContinuationBlock(
|
||||||
if r < 15:
|
if r < 15:
|
||||||
state.eobRun = 1 shl r
|
state.eobRun = 1 shl r
|
||||||
if r != 0:
|
if r != 0:
|
||||||
state.eobRun += state.getBitsAsUnsignedInt(r)
|
state.eobRun += state.getBits(r)
|
||||||
dec state.eobRun
|
dec state.eobRun
|
||||||
break
|
break
|
||||||
k += 16
|
k += 16
|
||||||
|
@ -681,7 +680,7 @@ proc decodeProgressiveContinuationBlock(
|
||||||
if r < 15:
|
if r < 15:
|
||||||
state.eobRun = (1 shl r) - 1
|
state.eobRun = (1 shl r) - 1
|
||||||
if r != 0:
|
if r != 0:
|
||||||
state.eobRun += state.getBitsAsUnsignedInt(r)
|
state.eobRun += state.getBits(r)
|
||||||
r = 64 # force end of block
|
r = 64 # force end of block
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
Loading…
Reference in a new issue