summaryrefslogtreecommitdiff
path: root/addons/image/stb.c
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 13:28:30 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:24:59 -0300
commit0f81de017ca7b52e951bb70f6f5f3e8c88b425e6 (patch)
treefde88db0ed0dd68fbeb7bf7aaa49d3cd1f08b1c1 /addons/image/stb.c
parentb7fdfb18ffd199d49a254c1c799bc3415ad45ec2 (diff)
downloadpardes-0f81de017ca7b52e951bb70f6f5f3e8c88b425e6.tar.gz
pardes-0f81de017ca7b52e951bb70f6f5f3e8c88b425e6.zip
kinds #25, addons in Zig: src/kinds/addon.zig, over the translated header and nothing of the core, makes a kind's pa_ops from a struct of the functions it has (its head from name, version, extensions and words; a public function of no kind's name a compile error), the pane's arena and a job's pa_out as std Allocators, typed keys, a Window to put text in, a Paint for the prefix and placements, tick's flags and a Deadline, dump and load as an extern struct's bytes in one line each, and body and ctl over a Writer; snake.zig and image.zig (stb_image in stb.c, static, beside any zstbi) replace snake.c and image.c with the same goldens, harness and perf cell, and addon-test runs their own zig tests
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'addons/image/stb.c')
-rw-r--r--addons/image/stb.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/addons/image/stb.c b/addons/image/stb.c
new file mode 100644
index 00000000..5fba51bc
--- /dev/null
+++ b/addons/image/stb.c
@@ -0,0 +1,27 @@
+/* stb_image and its resize for image.zig, static here (a static pardes
+ * links a zstbi beside them), their memory image.zig's: the job's on a
+ * worker, else the pane's arena; both are freed whole. */
+#include <stddef.h>
+#include <string.h>
+void *pa_image_mem(size_t n);
+void *pa_image_remem(void *p, size_t old, size_t n);
+#define STBI_MALLOC(n) pa_image_mem(n)
+#define STBI_REALLOC_SIZED(p, old, n) pa_image_remem(p, old, n)
+#define STBI_FREE(p) ((void)(p))
+#define STBIR_MALLOC(n, c) ((void)(c), pa_image_mem(n))
+#define STBIR_FREE(p, c) ((void)(p), (void)(c))
+#define STBI_NO_STDIO
+#define STBI_NO_HDR
+#define STB_IMAGE_IMPLEMENTATION
+#define STB_IMAGE_RESIZE_IMPLEMENTATION
+#define STB_IMAGE_STATIC
+#define STB_IMAGE_RESIZE_STATIC
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+#include "stb_image.h"
+#include "stb_image_resize.h"
+#pragma GCC diagnostic pop
+
+int pa_image_info(const unsigned char *b, int n, int *w, int *h) { int c; return stbi_info_from_memory(b, n, w, h, &c); }
+unsigned char *pa_image_load(const unsigned char *b, int n, int *w, int *h) { int c; return stbi_load_from_memory(b, n, w, h, &c, 4); }
+int pa_image_resize(const unsigned char *in, int w, int h, unsigned char *out, int nw, int nh) { return stbir_resize_uint8(in, w, h, 0, out, nw, nh, 0, 4); }