Skip to content

Commit

Permalink
IMG_Load should attempt to read from preloaded data (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
gliheng committed Jun 10, 2019
1 parent 418665a commit 8407822
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions IMG.c
Expand Up @@ -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) {
Expand Down

0 comments on commit 8407822

Please sign in to comment.