case
This commit is contained in:
parent
403a2b95a8
commit
75f630f824
1 changed files with 7 additions and 5 deletions
|
@ -955,7 +955,10 @@ proc grayScaleToRgbx(gray: uint8): ColorRGBX {.inline.} =
|
||||||
proc buildImage(state: var DecoderState): Image =
|
proc buildImage(state: var DecoderState): Image =
|
||||||
## Takes a jpeg image object and builds a pixie Image from it.
|
## Takes a jpeg image object and builds a pixie Image from it.
|
||||||
|
|
||||||
if state.components.len == 3:
|
result = newImage(state.imageWidth, state.imageHeight)
|
||||||
|
|
||||||
|
case state.components.len:
|
||||||
|
of 3:
|
||||||
for component in state.components.mitems:
|
for component in state.components.mitems:
|
||||||
while component.yScale < state.maxYScale:
|
while component.yScale < state.maxYScale:
|
||||||
component.channel = component.channel.magnifyXBy2()
|
component.channel = component.channel.magnifyXBy2()
|
||||||
|
@ -965,9 +968,6 @@ proc buildImage(state: var DecoderState): Image =
|
||||||
component.channel = component.channel.magnifyYBy2()
|
component.channel = component.channel.magnifyYBy2()
|
||||||
component.xScale *= 2
|
component.xScale *= 2
|
||||||
|
|
||||||
result = newImage(state.imageWidth, state.imageHeight)
|
|
||||||
|
|
||||||
if state.components.len == 3:
|
|
||||||
let
|
let
|
||||||
cy = state.components[0].channel
|
cy = state.components[0].channel
|
||||||
cb = state.components[1].channel
|
cb = state.components[1].channel
|
||||||
|
@ -981,13 +981,15 @@ proc buildImage(state: var DecoderState): Image =
|
||||||
cr.data[channelIndex],
|
cr.data[channelIndex],
|
||||||
)
|
)
|
||||||
inc channelIndex
|
inc channelIndex
|
||||||
elif state.components.len == 1:
|
|
||||||
|
of 1:
|
||||||
let cy = state.components[0].channel
|
let cy = state.components[0].channel
|
||||||
for y in 0 ..< state.imageHeight:
|
for y in 0 ..< state.imageHeight:
|
||||||
var channelIndex = cy.dataIndex(0, y)
|
var channelIndex = cy.dataIndex(0, y)
|
||||||
for x in 0 ..< state.imageWidth:
|
for x in 0 ..< state.imageWidth:
|
||||||
result.unsafe[x, y] = grayScaleToRgbx(cy.data[channelIndex])
|
result.unsafe[x, y] = grayScaleToRgbx(cy.data[channelIndex])
|
||||||
inc channelIndex
|
inc channelIndex
|
||||||
|
|
||||||
else:
|
else:
|
||||||
failInvalid()
|
failInvalid()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue