From 7afea49893078cfc624ee7f943c1155a4c31e58a Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Mon, 16 May 2022 19:05:13 -0500 Subject: [PATCH] single branch --- src/pixie/fileformats/jpeg.nim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pixie/fileformats/jpeg.nim b/src/pixie/fileformats/jpeg.nim index 543c8ea..3bb484d 100644 --- a/src/pixie/fileformats/jpeg.nim +++ b/src/pixie/fileformats/jpeg.nim @@ -91,7 +91,11 @@ template failInvalid(reason = "unable to load") = template clampByte(x: int32): uint8 = ## Clamp integer into byte range. - clamp(x, 0, 0xFF).uint8 + # clamp(x, 0, 0xFF).uint8 + let + signBit = (cast[uint32](x) shr 31) + value = cast[uint32](x) and (signBit - 1) + min(value, 255).uint8 proc readUint8(state: var DecoderState): uint8 = ## Reads a byte from the input stream.