Skip to content

Commit f94b7d3

Browse files
authored
Merge pull request #36 from cobaltgit/stb_image
Migrate fbscreenshot/display from nimPNG to stb_image
2 parents 1a914ce + 6c83742 commit f94b7d3

9 files changed

Lines changed: 78 additions & 5098 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[submodule "modules/third-party/stb"]
2+
path = modules/third-party/stb
3+
url = https://github.com/nothings/stb
14
[submodule "third-party/dropbear"]
25
path = modules/third-party/dropbear
36
url = https://github.com/mkj/dropbear

modules/third-party/stb

Submodule stb added at 31c1ad3

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.nim

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

3-
{.compile: "stb_truetype.c".}
4-
{.passC: "-I" & currentSourcePath().splitPath().head.}
3+
const StbDir = currentSourcePath().splitPath().head /
4+
".." / ".." / ".." / ".." /
5+
"modules" / "third-party" / "stb"
6+
7+
{.passC: "-O3 -I" & StbDir.}
8+
9+
{.emit: """
10+
#define STB_TRUETYPE_IMPLEMENTATION
11+
#include "stb_truetype.h"
12+
""".}
513

614
type
7-
stbtt_fontinfo* {.importc, header: "stb_truetype.h".} = object
15+
stbtt_fontinfo* {.importc, header: StbDir / "stb_truetype.h".} = object
816

917
proc stbtt_InitFont*(info: ptr stbtt_fontinfo, data: ptr UncheckedArray[byte], offset: cint): cint
10-
{.importc, header: "stb_truetype.h".}
18+
{.importc, header: StbDir / "stb_truetype.h".}
1119

1220
proc stbtt_ScaleForPixelHeight*(info: ptr stbtt_fontinfo, pixels: cfloat): cfloat
13-
{.importc, header: "stb_truetype.h".}
21+
{.importc, header: StbDir / "stb_truetype.h".}
1422

1523
proc stbtt_GetFontVMetrics*(info: ptr stbtt_fontinfo, ascent, descent, lineGap: ptr cint)
16-
{.importc, header: "stb_truetype.h".}
24+
{.importc, header: StbDir / "stb_truetype.h".}
1725

1826
proc stbtt_GetCodepointBitmapBox*(info: ptr stbtt_fontinfo, codepoint: cint,
1927
scale_x, scale_y: cfloat, ix0, iy0, ix1, iy1: ptr cint)
20-
{.importc, header: "stb_truetype.h".}
28+
{.importc, header: StbDir / "stb_truetype.h".}
2129

2230
proc stbtt_MakeCodepointBitmap*(info: ptr stbtt_fontinfo, output: ptr UncheckedArray[byte],
2331
out_w, out_h, out_stride: cint, scale_x, scale_y: cfloat, codepoint: cint)
24-
{.importc, header: "stb_truetype.h".}
32+
{.importc, header: StbDir / "stb_truetype.h".}
2533

2634
proc stbtt_GetCodepointHMetrics*(info: ptr stbtt_fontinfo, codepoint: cint,
2735
advanceWidth, leftSideBearing: ptr cint)
28-
{.importc, header: "stb_truetype.h".}
36+
{.importc, header: StbDir / "stb_truetype.h".}
2937

3038
proc stbtt_GetCodepointKernAdvance*(info: ptr stbtt_fontinfo, ch1, ch2: cint): cint
31-
{.importc, header: "stb_truetype.h".}
39+
{.importc, header: StbDir / "stb_truetype.h".}

src/common/ffi/stb_truetype.c

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)