From 840782235ce2b75447f8cbddfd50519dc429938e Mon Sep 17 00:00:00 2001 From: Amadeus Date: Mon, 10 Jun 2019 16:46:53 -0700 Subject: [PATCH] IMG_Load should attempt to read from preloaded data (#7) --- IMG.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/IMG.c b/IMG.c index a213f9e6..8bc65221 100644 --- a/IMG.c +++ b/IMG.c @@ -128,6 +128,22 @@ void IMG_Quit() /* Load an image from a file */ SDL_Surface *IMG_Load(const char *file) { +#if __EMSCRIPTEN__ + int w, h; + char *data; + SDL_Surface *surf; + + data = emscripten_get_preloaded_image_data(file, &w, &h); + if (data != NULL) { + surf = SDL_CreateRGBSurface(0, w, h, 32, 0xFF, 0xFF00, 0xFF0000, 0xFF000000); + if (surf != NULL) { + memcpy(surf->pixels, data, w * h * 4); + } + free(data); + return surf; + } +#endif + SDL_RWops *src = SDL_RWFromFile(file, "rb"); const char *ext = SDL_strrchr(file, '.'); if(ext) {