summaryrefslogtreecommitdiff
path: root/addons/image/stb.c
diff options
context:
space:
mode:
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); }