IMG_Load should attempt to read from preloaded data (#7)
authorAmadeus <gliheng@gmail.com>
Mon, 10 Jun 2019 16:46:53 -0700
changeset 6542af29733c9e0
parent 653 d5baeefe5687
child 655 db1f3b1892ab
IMG_Load should attempt to read from preloaded data (#7)
IMG.c
     1.1 --- a/IMG.c	Mon Jun 10 16:45:40 2019 -0700
     1.2 +++ b/IMG.c	Mon Jun 10 16:46:53 2019 -0700
     1.3 @@ -128,6 +128,22 @@
     1.4  /* Load an image from a file */
     1.5  SDL_Surface *IMG_Load(const char *file)
     1.6  {
     1.7 +#if __EMSCRIPTEN__
     1.8 +    int w, h;
     1.9 +    char *data;
    1.10 +    SDL_Surface *surf;
    1.11 +
    1.12 +    data = emscripten_get_preloaded_image_data(file, &w, &h);
    1.13 +    if (data != NULL) {
    1.14 +        surf = SDL_CreateRGBSurface(0, w, h, 32, 0xFF, 0xFF00, 0xFF0000, 0xFF000000);
    1.15 +        if (surf != NULL) {
    1.16 +            memcpy(surf->pixels, data, w * h * 4);
    1.17 +        }
    1.18 +        free(data);
    1.19 +        return surf;
    1.20 +    }
    1.21 +#endif
    1.22 +
    1.23      SDL_RWops *src = SDL_RWFromFile(file, "rb");
    1.24      const char *ext = SDL_strrchr(file, '.');
    1.25      if(ext) {