Merge pull request #56 from guzba/master

add -d:pixieUseStb
This commit is contained in:
treeform 2021-01-21 22:27:26 -08:00 committed by GitHub
commit 379abcb638
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 11 deletions

View file

@ -1,17 +1,23 @@
import pixie/images, pixie/common, pixie/fileformats/stb_image/stb_image import pixie/images, pixie/common
when defined(pixieUseStb):
import pixie/fileformats/stb_image/stb_image
const const
jpgStartOfImage* = [0xFF.uint8, 0xD8] jpgStartOfImage* = [0xFF.uint8, 0xD8]
proc decodeJpg*(data: seq[uint8]): Image = proc decodeJpg*(data: seq[uint8]): Image =
## Decodes the JPEG into an Image. ## Decodes the JPEG into an Image.
var when not defined(pixieUseStb):
width: int raise newException(PixieError, "Decoding JPG requires -d:pixieUseStb")
height: int else:
let pixels = loadFromMemory(data, width, height) var
width: int
height: int
let pixels = loadFromMemory(data, width, height)
result = newImage(width, height) result = newImage(width, height)
copyMem(result.data[0].addr, pixels[0].unsafeAddr, pixels.len) copyMem(result.data[0].addr, pixels[0].unsafeAddr, pixels.len)
proc decodeJpg*(data: string): Image {.inline.} = proc decodeJpg*(data: string): Image {.inline.} =
decodeJpg(cast[seq[uint8]](data)) decodeJpg(cast[seq[uint8]](data))

View file

@ -1,5 +1,6 @@
import pixie/fileformats/jpg when defined(pixieUseStb):
import pixie/fileformats/jpg
let let
original = readFile("tests/images/jpg/jpeg420exif.jpg") original = readFile("tests/images/jpg/jpeg420exif.jpg")
stbDecoded = decodeJpg(original) stbDecoded = decodeJpg(original)