From 773036a3bac081935a66f74150a78d3823823801 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Thu, 21 Jan 2021 19:07:07 -0600 Subject: [PATCH] add -d:useStb --- src/pixie/fileformats/jpg.nim | 20 +++++++++++++------- tests/test_jpg.nim | 9 +++++---- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/pixie/fileformats/jpg.nim b/src/pixie/fileformats/jpg.nim index 3b3de9b..287ab89 100644 --- a/src/pixie/fileformats/jpg.nim +++ b/src/pixie/fileformats/jpg.nim @@ -1,17 +1,23 @@ -import pixie/images, pixie/common, pixie/fileformats/stb_image/stb_image +import pixie/images, pixie/common + +when defined(useStb): + import pixie/fileformats/stb_image/stb_image const jpgStartOfImage* = [0xFF.uint8, 0xD8] proc decodeJpg*(data: seq[uint8]): Image = ## Decodes the JPEG into an Image. - var - width: int - height: int - let pixels = loadFromMemory(data, width, height) + when not defined(useStb): + raise newException(PixieError, "Decoding JPG requires -d:useStb") + else: + var + width: int + height: int + let pixels = loadFromMemory(data, width, height) - result = newImage(width, height) - copyMem(result.data[0].addr, pixels[0].unsafeAddr, pixels.len) + result = newImage(width, height) + copyMem(result.data[0].addr, pixels[0].unsafeAddr, pixels.len) proc decodeJpg*(data: string): Image {.inline.} = decodeJpg(cast[seq[uint8]](data)) diff --git a/tests/test_jpg.nim b/tests/test_jpg.nim index 35f56b0..b495c9a 100644 --- a/tests/test_jpg.nim +++ b/tests/test_jpg.nim @@ -1,5 +1,6 @@ -import pixie/fileformats/jpg +when defined(useStb): + import pixie/fileformats/jpg -let - original = readFile("tests/images/jpg/jpeg420exif.jpg") - stbDecoded = decodeJpg(original) + let + original = readFile("tests/images/jpg/jpeg420exif.jpg") + stbDecoded = decodeJpg(original)