Port to emscripten
authorSathyanarayanan Gunasekaran <gsathya.ceg@gmail.com>
Mon, 10 Jun 2019 16:41:40 -0700
changeset 65066ee31359d0f
parent 649 07fe7a23da89
child 651 97e271eca329
Port to emscripten
Patch from daft-freak
IMG.c
     1.1 --- a/IMG.c	Mon Jun 10 16:32:43 2019 -0700
     1.2 +++ b/IMG.c	Mon Jun 10 16:41:40 2019 -0700
     1.3 @@ -23,6 +23,10 @@
     1.4  
     1.5  #include "SDL_image.h"
     1.6  
     1.7 +#ifdef __EMSCRIPTEN__
     1.8 +#include <emscripten/emscripten.h>
     1.9 +#endif
    1.10 +
    1.11  #define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
    1.12  
    1.13  /* Table of image detection and loading functions */
    1.14 @@ -176,6 +180,29 @@
    1.15          return(NULL);
    1.16      }
    1.17  
    1.18 +#ifdef __EMSCRIPTEN__
    1.19 +    /*load through preloadedImages*/
    1.20 +
    1.21 +    if ( src->type == SDL_RWOPS_STDFILE ) {
    1.22 +        int w, h, success;
    1.23 +        char *data;
    1.24 +        SDL_Surface *surf;
    1.25 +
    1.26 +        data = emscripten_get_preloaded_image_data_from_FILE(src->hidden.stdio.fp, &w, &h);
    1.27 +
    1.28 +        if(data)
    1.29 +        {
    1.30 +            surf = SDL_CreateRGBSurfaceFrom(data, w, h, 32, w * 4, 0xFF, 0xFF00, 0xFF0000, 0xFF000000);
    1.31 +            free(data);
    1.32 +
    1.33 +            if(freesrc)
    1.34 +                SDL_RWclose(src);
    1.35 +
    1.36 +            return surf;
    1.37 +        }
    1.38 +    }
    1.39 +#endif
    1.40 +
    1.41      /* Detect the type of image being loaded */
    1.42      image = NULL;
    1.43      for ( i=0; i < ARRAYSIZE(supported); ++i ) {