Skip to content

Commit 8407822

Browse files
committed
IMG_Load should attempt to read from preloaded data (#7)
1 parent 418665a commit 8407822

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

IMG.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@ void IMG_Quit()
128128
/* Load an image from a file */
129129
SDL_Surface *IMG_Load(const char *file)
130130
{
131+
#if __EMSCRIPTEN__
132+
int w, h;
133+
char *data;
134+
SDL_Surface *surf;
135+
136+
data = emscripten_get_preloaded_image_data(file, &w, &h);
137+
if (data != NULL) {
138+
surf = SDL_CreateRGBSurface(0, w, h, 32, 0xFF, 0xFF00, 0xFF0000, 0xFF000000);
139+
if (surf != NULL) {
140+
memcpy(surf->pixels, data, w * h * 4);
141+
}
142+
free(data);
143+
return surf;
144+
}
145+
#endif
146+
131147
SDL_RWops *src = SDL_RWFromFile(file, "rb");
132148
const char *ext = SDL_strrchr(file, '.');
133149
if(ext) {

0 commit comments

Comments
 (0)