Skip to content

Commit

Permalink
Port to emscripten
Browse files Browse the repository at this point in the history
Patch from daft-freak
  • Loading branch information
gsathya committed Jun 10, 2019
1 parent 0ed01df commit 1d92df4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions IMG.c
Expand Up @@ -23,6 +23,10 @@

#include "SDL_image.h"

#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif

#define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))

/* Table of image detection and loading functions */
Expand Down Expand Up @@ -176,6 +180,29 @@ SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, const char *type)
return(NULL);
}

#ifdef __EMSCRIPTEN__
/*load through preloadedImages*/

if ( src->type == SDL_RWOPS_STDFILE ) {
int w, h, success;
char *data;
SDL_Surface *surf;

data = emscripten_get_preloaded_image_data_from_FILE(src->hidden.stdio.fp, &w, &h);

if(data)
{
surf = SDL_CreateRGBSurfaceFrom(data, w, h, 32, w * 4, 0xFF, 0xFF00, 0xFF0000, 0xFF000000);
free(data);

if(freesrc)
SDL_RWclose(src);

return surf;
}
}
#endif

/* Detect the type of image being loaded */
image = NULL;
for ( i=0; i < ARRAYSIZE(supported); ++i ) {
Expand Down

0 comments on commit 1d92df4

Please sign in to comment.