diff options
author | bptato <nincsnevem662@gmail.com> | 2024-07-02 16:56:33 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-07-02 17:50:10 +0200 |
commit | 02b549ee0c7bda8ad110eba6aac14bafb10d45e3 (patch) | |
tree | 4628d8fbba059098f7e6fdc78fd3ab5070cb8820 /adapter/img/stbi.nim | |
parent | c69f9f6c1bc18b718a8c8deb11934cca19929e02 (diff) | |
download | chawan-02b549ee0c7bda8ad110eba6aac14bafb10d45e3.tar.gz |
pager: PNGify kitty images, clear images on buffer switch
Saves bandwidth; it's especially useful over SSH. Still not sure if this is the right solution, since it now needs two select cycles instead of one, and it does yet another copy of the image. (Unnecessarily, because stbi cannot stream its output, and stbiw cannot stream its input.) Also, to save memory, we now discard decoded images of buffers that are not being viewed.
Diffstat (limited to 'adapter/img/stbi.nim')
-rw-r--r-- | adapter/img/stbi.nim | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/adapter/img/stbi.nim b/adapter/img/stbi.nim index e4580d5c..f32c7f77 100644 --- a/adapter/img/stbi.nim +++ b/adapter/img/stbi.nim @@ -8,9 +8,11 @@ import utils/twtstr {.passc: "-fno-strict-aliasing".} {.passl: "-fno-strict-aliasing".} -{.compile: "stb_image.c".} +{.compile("stb_image.c", "-O3").} -type stbi_io_callbacks = object +{.push header: "stb_image.h".} + +type stbi_io_callbacks {.importc.} = object read: proc(user: pointer; data: ptr uint8; size: cint): cint {.cdecl.} skip: proc(user: pointer; n: cint) {.cdecl.} eof: proc(user: pointer): cint {.cdecl.} @@ -26,6 +28,8 @@ proc stbi_failure_reason(): cstring {.importc.} proc stbi_image_free(retval_from_stbi_load: pointer) {.importc.} +{.pop.} + proc myRead(user: pointer; data: ptr uint8; size: cint): cint {.cdecl.} = return cint(stdin.readBuffer(data, size)) @@ -41,20 +45,24 @@ proc myEof(user: pointer): cint {.cdecl.} = type stbi_write_func = proc(context, data: pointer; size: cint) {.cdecl.} +{.push header: "stb_image_write.h".} proc stbi_write_png_to_func(fun: stbi_write_func; context: pointer; w, h, comp: cint; data: pointer; stride_in_bytes: cint) {.importc.} proc stbi_write_bmp_to_func(fun: stbi_write_func; context: pointer; w, h, comp: cint; data: pointer) {.importc.} proc stbi_write_jpg_to_func(fun: stbi_write_func; context: pointer; w, h, comp: cint; data: pointer; quality: cint) {.importc.} +{.pop.} proc myWriteFunc(context, data: pointer; size: cint) {.cdecl.} = discard stdout.writeBuffer(data, size) +{.push header: "stb_image_resize.h".} proc stbir_resize_uint8(input_pixels: ptr uint8; input_w, input_h, input_stride_in_bytes: cint; output_pixels: ptr uint8; output_w, output_h, output_stride_in_bytes, num_channels: cint): cint {.importc.} +{.pop.} proc main() = enterNetworkSandbox() |