Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/pixie/fileformats/jpeg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ proc decodeSOF0(state: var DecoderState) =
if state.imageWidth == 0:
failInvalid("image invalid 0 width")

let numComponents = state.readUint8().int
if numComponents notin {1, 3}:
let numComponentsU8 = state.readUint8()
let numComponents = numComponentsU8.int
if numComponentsU8 notin {1'u8, 3}:
failInvalid("unsupported component count, must be 1 or 3")

len -= 6
Expand All @@ -315,7 +316,7 @@ proc decodeSOF0(state: var DecoderState) =
if quantizationTableId > 3:
failInvalid("invalid quantization table id")

if vertical notin {1, 2, 4} or horizontal notin {1, 2, 4}:
if vertical notin {1'u8, 2, 4} or horizontal notin {1'u8, 2, 4}:
failInvalid("invalid component scaling factor")

component.xScale = vertical.int
Expand Down Expand Up @@ -443,13 +444,13 @@ proc reset(state: var DecoderState) =
proc decodeSOS(state: var DecoderState) =
## Decode Start of Scan - header before the block data.
var len = state.readUint16be() - 2

state.scanComponents = state.readUint8().int
let scanComponentsU8 = state.readUint8()
state.scanComponents = scanComponentsU8.int

if state.scanComponents > state.components.len:
failInvalid("extra components")

if state.scanComponents notin {1, 3}:
if scanComponentsU8 notin {1'u8, 3}:
failInvalid("unsupported scan component count")

state.componentOrder.setLen(0)
Expand Down Expand Up @@ -878,7 +879,7 @@ proc checkRestart(state: var DecoderState) =
if state.pos + 1 > state.len:
failInvalid()
if state.buffer[state.pos] != 0xFF or
state.buffer[state.pos + 1] notin {0xD0 .. 0xD7}:
state.buffer[state.pos + 1] notin 0xD0'u8 .. 0xD7'u8:
failInvalid("did not get expected restart marker")
state.pos += 2
state.reset()
Expand Down
2 changes: 1 addition & 1 deletion src/pixie/fileformats/qoi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ proc decodeQoi*(data: string): Qoi {.raises: [PixieError].} =
channels = data.readUint8(12)
colorspace = data.readUint8(13)

if channels notin {3, 4} or colorspace notin {0, 1}:
if channels notin {3'u8, 4} or colorspace notin {0'u8, 1}:
raise newException(PixieError, "Invalid QOI header")

if width.int * height.int > uint32.high.int64:
Expand Down