remove stb, commit to new jpeg
This commit is contained in:
parent
3e204e829f
commit
4194c4a677
6 changed files with 8 additions and 7973 deletions
|
@ -1,5 +1,5 @@
|
|||
import bumpy, chroma, flatty/binny, os, pixie/common, pixie/contexts,
|
||||
pixie/fileformats/bmp, pixie/fileformats/gif, pixie/fileformats/jpg,
|
||||
pixie/fileformats/bmp, pixie/fileformats/gif, pixie/fileformats/jpeg,
|
||||
pixie/fileformats/png, pixie/fileformats/ppm, pixie/fileformats/qoi,
|
||||
pixie/fileformats/svg, pixie/fonts, pixie/images, pixie/masks, pixie/paints,
|
||||
pixie/paths, strutils, vmath
|
||||
|
@ -8,7 +8,7 @@ export bumpy, chroma, common, contexts, fonts, images, masks, paints, paths, vma
|
|||
|
||||
type
|
||||
FileFormat* = enum
|
||||
PngFormat, BmpFormat, JpgFormat, GifFormat, QoiFormat, PpmFormat
|
||||
PngFormat, BmpFormat, JpegFormat, GifFormat, QoiFormat, PpmFormat
|
||||
|
||||
converter autoStraightAlpha*(c: ColorRGBX): ColorRGBA {.inline, raises: [].} =
|
||||
## Convert a premultiplied alpha RGBA to a straight alpha RGBA.
|
||||
|
@ -22,8 +22,8 @@ proc decodeImage*(data: string): Image {.raises: [PixieError].} =
|
|||
## Loads an image from memory.
|
||||
if data.len > 8 and data.readUint64(0) == cast[uint64](pngSignature):
|
||||
decodePng(data)
|
||||
elif data.len > 2 and data.readUint16(0) == cast[uint16](jpgStartOfImage):
|
||||
decodeJpg(data)
|
||||
elif data.len > 2 and data.readUint16(0) == cast[uint16](jpegStartOfImage):
|
||||
decodeJpeg(data)
|
||||
elif data.len > 2 and data.readStr(0, 2) == bmpSignature:
|
||||
decodeBmp(data)
|
||||
elif data.len > 5 and
|
||||
|
@ -64,7 +64,7 @@ proc encodeImage*(image: Image, fileFormat: FileFormat): string {.raises: [Pixie
|
|||
case fileFormat:
|
||||
of PngFormat:
|
||||
image.encodePng()
|
||||
of JpgFormat:
|
||||
of JpegFormat:
|
||||
raise newException(PixieError, "Unsupported file format")
|
||||
of BmpFormat:
|
||||
image.encodeBmp()
|
||||
|
@ -88,7 +88,7 @@ proc writeFile*(image: Image, filePath: string) {.raises: [PixieError].} =
|
|||
let fileFormat = case splitFile(filePath).ext.toLowerAscii():
|
||||
of ".png": PngFormat
|
||||
of ".bmp": BmpFormat
|
||||
of ".jpg", ".jpeg": JpgFormat
|
||||
of ".jpg", ".jpeg": JpegFormat
|
||||
of ".qoi": QoiFormat
|
||||
of ".ppm": PpmFormat
|
||||
else:
|
||||
|
@ -104,7 +104,7 @@ proc writeFile*(mask: Mask, filePath: string) {.raises: [PixieError].} =
|
|||
let fileFormat = case splitFile(filePath).ext.toLowerAscii():
|
||||
of ".png": PngFormat
|
||||
of ".bmp": BmpFormat
|
||||
of ".jpg", ".jpeg": JpgFormat
|
||||
of ".jpg", ".jpeg": JpegFormat
|
||||
of ".qoi": QoiFormat
|
||||
of ".ppm": PpmFormat
|
||||
else:
|
||||
|
|
|
@ -21,7 +21,7 @@ import pixie/common, pixie/images, pixie/masks, sequtils, strutils, chroma, std/
|
|||
|
||||
const
|
||||
fastBits = 9
|
||||
jpgStartOfImage* = [0xFF.uint8, 0xD8]
|
||||
jpegStartOfImage* = [0xFF.uint8, 0xD8]
|
||||
deZigZag = [
|
||||
uint8 00, 01, 08, 16, 09, 02, 03, 10,
|
||||
uint8 17, 24, 32, 25, 18, 11, 04, 05,
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
import pixie/common, pixie/images
|
||||
|
||||
const
|
||||
jpgStartOfImage* = [0xFF.uint8, 0xD8]
|
||||
|
||||
when defined(pixieUseStb):
|
||||
import pixie/fileformats/stb_image/stb_image
|
||||
else:
|
||||
import pixie/fileformats/jpeg
|
||||
|
||||
proc decodeJpg*(data: string): Image {.inline, raises: [PixieError].} =
|
||||
## Decodes the JPEG into an Image.
|
||||
when not defined(pixieUseStb):
|
||||
decodeJpeg(data)
|
||||
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)
|
|
@ -1,6 +0,0 @@
|
|||
#define STBI_NO_STDIO
|
||||
#define STBI_NO_LINEAR
|
||||
#define STBI_NO_HDR
|
||||
#define STBI_ONLY_JPEG
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
File diff suppressed because it is too large
Load diff
|
@ -1,40 +0,0 @@
|
|||
import pixie/common
|
||||
|
||||
when defined(windows) and defined(vcc):
|
||||
{.pragma: stbcall, stdcall.}
|
||||
else:
|
||||
{.pragma: stbcall, cdecl.}
|
||||
|
||||
{.compile: "stb_image.c".}
|
||||
|
||||
proc stbi_image_free(retval_from_stbi_load: pointer)
|
||||
{.importc: "stbi_image_free", stbcall.}
|
||||
|
||||
proc stbi_load_from_memory(
|
||||
buffer: pointer,
|
||||
len: cint,
|
||||
x, y, channels_in_file: var cint,
|
||||
desired_channels: cint
|
||||
): pointer
|
||||
{.importc: "stbi_load_from_memory", stbcall.}
|
||||
|
||||
proc loadFromMemory*(buffer: string, width, height: var int): string =
|
||||
var outWidth, outHeight, outComponents: cint
|
||||
let data = stbi_load_from_memory(
|
||||
buffer[0].unsafeAddr,
|
||||
buffer.len.cint,
|
||||
outWidth,
|
||||
outHeight,
|
||||
outComponents,
|
||||
4
|
||||
)
|
||||
if data == nil:
|
||||
raise newException(PixieError, "Decoding JPG failed")
|
||||
|
||||
width = outWidth.int
|
||||
height = outHeight.int
|
||||
|
||||
result.setLen(width * height * 4)
|
||||
copyMem(result[0].addr, data, result.len)
|
||||
|
||||
stbi_image_free(data)
|
Loading…
Reference in a new issue