Skip to content

Commit de2b121

Browse files
committed
migrate from nimPNG to stb_image
slightly faster screenshotting + smaller binaries
1 parent 1a914ce commit de2b121

11 files changed

Lines changed: 9763 additions & 7 deletions

File tree

quark.nimble

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ license = "GPL-3.0"
77
srcDir = "src"
88

99
requires "nim >= 2.0.0"
10-
requires "nimPNG >= 0.3.1"
1110

1211
const Root = getCurrentDir()
1312
const BinDir = Root / "dist" / "System" / "bin"

src/common/fb.nim

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import std/posix
2-
import nimPNG
2+
import ffi/stb/stb_image
33

44
const
55
FbWidth* = 240
@@ -66,4 +66,11 @@ proc fbscreenshot*(fbMap: pointer, output: string) =
6666
rotatedPixels[dstIdx + 2] = FiveToEight[b]
6767
rotatedPixels[dstIdx + 3] = 255
6868

69-
discard savePNG32(output, rotatedPixels, FbHeight, FbWidth)
69+
discard stbi_write_png(
70+
cstring(output),
71+
cint(FbHeight),
72+
cint(FbWidth),
73+
cint(4),
74+
addr rotatedPixels[0],
75+
cint(FbHeight * 4)
76+
)

src/common/ffi/stb/stb_image.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define STB_IMAGE_IMPLEMENTATION
2+
#include "stb_image.h"

src/common/ffi/stb/stb_image.h

Lines changed: 7988 additions & 0 deletions
Large diffs are not rendered by default.

src/common/ffi/stb/stb_image.nim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import std/os
2+
3+
{.compile("stb_image.c", "-O3").}
4+
{.compile("stb_image_write.c", "-O3").}
5+
{.passC: "-I" & currentSourcePath().splitPath().head.}
6+
7+
proc stbi_load*(
8+
filename: cstring,
9+
x: ptr cint,
10+
y: ptr cint,
11+
channels_in_file: ptr cint,
12+
desired_channels: cint
13+
): ptr uint8 {.importc, header: "stb_image.h".}
14+
15+
proc stbi_write_png*(
16+
filename: cstring,
17+
w: cint,
18+
h: cint,
19+
comp: cint,
20+
data: pointer,
21+
stride_in_bytes: cint
22+
): cint {.importc, header: "stb_image_write.h".}
23+
24+
proc stbi_image_free*(data: pointer) {.importc, header: "stb_image.h".}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define STB_IMAGE_WRITE_IMPLEMENTATION
2+
#include "stb_image_write.h"

0 commit comments

Comments
 (0)