Skip to content

Commit 1d92df4

Browse files
committed
Port to emscripten
Patch from daft-freak
1 parent 0ed01df commit 1d92df4

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

IMG.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
#include "SDL_image.h"
2525

26+
#ifdef __EMSCRIPTEN__
27+
#include <emscripten/emscripten.h>
28+
#endif
29+
2630
#define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
2731

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

183+
#ifdef __EMSCRIPTEN__
184+
/*load through preloadedImages*/
185+
186+
if ( src->type == SDL_RWOPS_STDFILE ) {
187+
int w, h, success;
188+
char *data;
189+
SDL_Surface *surf;
190+
191+
data = emscripten_get_preloaded_image_data_from_FILE(src->hidden.stdio.fp, &w, &h);
192+
193+
if(data)
194+
{
195+
surf = SDL_CreateRGBSurfaceFrom(data, w, h, 32, w * 4, 0xFF, 0xFF00, 0xFF0000, 0xFF000000);
196+
free(data);
197+
198+
if(freesrc)
199+
SDL_RWclose(src);
200+
201+
return surf;
202+
}
203+
}
204+
#endif
205+
179206
/* Detect the type of image being loaded */
180207
image = NULL;
181208
for ( i=0; i < ARRAYSIZE(supported); ++i ) {

0 commit comments

Comments
 (0)