diff --git a/src/pixie.nim b/src/pixie.nim index fc8ec40..0f6de99 100644 --- a/src/pixie.nim +++ b/src/pixie.nim @@ -65,7 +65,7 @@ proc encodeImage*(image: Image, fileFormat: FileFormat): string {.raises: [Pixie of PngFormat: image.encodePng() of JpgFormat: - image.encodeJpg() + raise newException(PixieError, "Unsupported file format") of BmpFormat: image.encodeBmp() of QoiFormat: diff --git a/src/pixie/fileformats/jpeg.nim b/src/pixie/fileformats/jpeg.nim index baa22dd..4a52895 100644 --- a/src/pixie/fileformats/jpeg.nim +++ b/src/pixie/fileformats/jpeg.nim @@ -63,7 +63,7 @@ type channel: Mask DecoderState = object - buffer: seq[uint8] + buffer: string pos, bitCount: int bits: uint32 hitEnd: bool @@ -97,7 +97,7 @@ proc readUint8(state: var DecoderState): uint8 = ## Reads a byte from the input stream. if state.pos >= state.buffer.len: failInvalid() - result = state.buffer[state.pos] + result = cast[uint8](state.buffer[state.pos]) inc state.pos proc readUint16be(state: var DecoderState): uint16 = @@ -773,8 +773,8 @@ template checkReset(state: var DecoderState) = if state.bitCount < 24: state.fillBits() - if state.buffer[state.pos] == 0xFF: - if state.buffer[state.pos+1] in {0xD0 .. 0xD7}: + if state.buffer[state.pos] == 0xFF.char: + if state.buffer[state.pos+1] in {0xD0.char .. 0xD7.char}: state.pos += 2 else: failInvalid("did not get expected reset marker") @@ -929,7 +929,7 @@ proc buildImage(state: var DecoderState): Image = else: failInvalid() -proc decodeJpeg*(data: seq[uint8]): Image {.raises: [PixieError].} = +proc decodeJpeg*(data: string): Image {.inline, raises: [PixieError].} = ## Decodes the JPEG into an Image. var state = DecoderState() @@ -994,11 +994,5 @@ proc decodeJpeg*(data: seq[uint8]): Image {.raises: [PixieError].} = state.buildImage() -proc decodeJpeg*(data: string): Image {.inline, raises: [PixieError].} = - decodeJpeg(cast[seq[uint8]](data)) - -proc encodeJpeg*(image: Image): string = - raise newException(PixieError, "Encoding JPG not supported yet") - when defined(release): {.pop.} diff --git a/src/pixie/fileformats/jpg.nim b/src/pixie/fileformats/jpg.nim index 4bdcd5c..d11d738 100644 --- a/src/pixie/fileformats/jpg.nim +++ b/src/pixie/fileformats/jpg.nim @@ -20,7 +20,3 @@ proc decodeJpg*(data: string): Image {.inline, raises: [PixieError].} = result = newImage(width, height) copyMem(result.data[0].addr, pixels[0].unsafeAddr, pixels.len) - -proc encodeJpg*(image: Image): string {.raises: [PixieError].} = - ## Encodes Image into a JPEG data string. - raise newException(PixieError, "Encoding JPG not supported yet")