From 0559ff7af78caa47e17c338e2aaa83517e705644 Mon Sep 17 00:00:00 2001 From: rxi Date: Thu, 29 Sep 2016 19:22:45 +0100 Subject: [PATCH] Changed Image to load using filesystem --- src/image.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/image.c b/src/image.c index e59127e..234ef18 100644 --- a/src/image.c +++ b/src/image.c @@ -11,6 +11,7 @@ #include "lib/dmt/dmt.h" #include "lib/stb/stb_image.h" +#include "filesystem.h" #include "image.h" #include "palette.h" #include "luaobj.h" @@ -37,16 +38,30 @@ void image_setFlip(int mode) { const char *image_init(image_t *self, const char *filename) { /* Loads an image file into the struct and inits the mask */ const char *errmsg = NULL; + void *filedata = NULL; + unsigned char *data32 = NULL; memset(self, 0, sizeof(*self)); + /* Load file data */ + int size; + filedata = filesystem_read(filename, &size); + if (!filedata) { + errmsg = "could not read file"; + goto fail; + } + /* Load 32bit image data */ int width, height, n; - unsigned char *data32 = stbi_load(filename, &width, &height, &n, 4); + data32 = stbi_load_from_memory(filedata, size, &width, &height, &n, 4); if (!data32) { errmsg = "could not load image file"; goto fail; } + /* Free file data */ + filesystem_free(filedata); + filedata = NULL; + /* Set dimensions and allocate memory */ int sz = width * height; self->width = width; @@ -82,6 +97,7 @@ const char *image_init(image_t *self, const char *filename) { return NULL; fail: + filesystem_free(filedata); free(data32); return errmsg; }