Cleanup
This commit is contained in:
parent
a6ea5fe6c2
commit
1825ab6cd7
1 changed files with 6 additions and 23 deletions
|
@ -50,16 +50,6 @@ type
|
||||||
maxCodes: array[18, int]
|
maxCodes: array[18, int]
|
||||||
fast: array[1 shl fastBits, uint8]
|
fast: array[1 shl fastBits, uint8]
|
||||||
|
|
||||||
ResampleProc = proc(dst, line0, line1: ptr UncheckedArray[uint8],
|
|
||||||
widthPreExpansion, horizontalExpansionFactor: int
|
|
||||||
): ptr UncheckedArray[uint8] {.raises: [].}
|
|
||||||
|
|
||||||
Resample = object
|
|
||||||
horizontalExpansionFactor, verticalExpansionFactor: int
|
|
||||||
yStep, yPos, widthPreExpansion: int
|
|
||||||
line0, line1: ptr UncheckedArray[uint8]
|
|
||||||
resample: ResampleProc
|
|
||||||
|
|
||||||
Component = object
|
Component = object
|
||||||
id, quantizationTableId: uint8
|
id, quantizationTableId: uint8
|
||||||
yScale, xScale: int
|
yScale, xScale: int
|
||||||
|
@ -151,6 +141,7 @@ proc decodeDQT(state: var DecoderState) =
|
||||||
failInvalid("DQT table length did not match")
|
failInvalid("DQT table length did not match")
|
||||||
|
|
||||||
proc buildHuffman(huffman: var Huffman, counts: array[16, uint8]) =
|
proc buildHuffman(huffman: var Huffman, counts: array[16, uint8]) =
|
||||||
|
## Builds the huffman data structure.
|
||||||
block:
|
block:
|
||||||
var k: int
|
var k: int
|
||||||
for i in 0.uint8 ..< 16:
|
for i in 0.uint8 ..< 16:
|
||||||
|
@ -187,7 +178,6 @@ proc buildHuffman(huffman: var Huffman, counts: array[16, uint8]) =
|
||||||
|
|
||||||
proc decodeDHT(state: var DecoderState) =
|
proc decodeDHT(state: var DecoderState) =
|
||||||
## Decode Define Huffman Table
|
## Decode Define Huffman Table
|
||||||
|
|
||||||
var len = state.readUint16be() - 2
|
var len = state.readUint16be() - 2
|
||||||
while len > 0:
|
while len > 0:
|
||||||
let
|
let
|
||||||
|
@ -259,14 +249,8 @@ proc decodeSOF0(state: var DecoderState) =
|
||||||
state.components.add(component)
|
state.components.add(component)
|
||||||
|
|
||||||
for component in state.components.mitems:
|
for component in state.components.mitems:
|
||||||
state.maxXScale = max(
|
state.maxXScale = max(state.maxXScale, component.xScale)
|
||||||
state.maxXScale,
|
state.maxYScale = max(state.maxYScale, component.yScale)
|
||||||
component.xScale
|
|
||||||
)
|
|
||||||
state.maxYScale = max(
|
|
||||||
state.maxYScale,
|
|
||||||
component.yScale
|
|
||||||
)
|
|
||||||
|
|
||||||
state.mcuWidth = state.maxYScale * 8
|
state.mcuWidth = state.maxYScale * 8
|
||||||
state.mcuHeight = state.maxXScale * 8
|
state.mcuHeight = state.maxXScale * 8
|
||||||
|
@ -295,10 +279,8 @@ proc decodeSOF0(state: var DecoderState) =
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
component.widthStride =
|
component.widthStride = state.numMcuWide * component.yScale * 8
|
||||||
state.numMcuWide * component.yScale * 8
|
component.heightStride = state.numMcuHigh * component.xScale * 8
|
||||||
component.heightStride =
|
|
||||||
state.numMcuHigh * component.xScale * 8
|
|
||||||
|
|
||||||
component.channel = newMask(
|
component.channel = newMask(
|
||||||
component.widthStride, component.heightStride
|
component.widthStride, component.heightStride
|
||||||
|
@ -321,6 +303,7 @@ proc decodeSOF2(state: var DecoderState) =
|
||||||
state.progressive = true
|
state.progressive = true
|
||||||
|
|
||||||
proc reset(state: var DecoderState) =
|
proc reset(state: var DecoderState) =
|
||||||
|
## Rests the decoder state need for reset markers.
|
||||||
state.bits = 0
|
state.bits = 0
|
||||||
state.bitCount = 0
|
state.bitCount = 0
|
||||||
for component in 0 ..< state.components.len:
|
for component in 0 ..< state.components.len:
|
||||||
|
|
Loading…
Reference in a new issue