diff --git a/cores/libretro-imageviewer/Makefile b/cores/libretro-imageviewer/Makefile index 5fc4be5e60..2699b3c5a5 100644 --- a/cores/libretro-imageviewer/Makefile +++ b/cores/libretro-imageviewer/Makefile @@ -1,5 +1,6 @@ -image_core.so: +image_core.so: image_core.c gcc \ + -g \ image_core.c \ ../../libretro-common/file/file_path.c \ ../../libretro-common/lists/dir_list.c \ @@ -7,10 +8,13 @@ image_core.so: ../../libretro-common/compat/compat_strcasestr.c \ ../../libretro-common/lists/string_list.c \ ../../libretro-common/file/retro_dirent.c \ + ../../libretro-common/streams/file_stream.c \ + ../../libretro-common/vfs/vfs_implementation.c \ -o image_core.so \ -DHAVE_STB_IMAGE \ -I ../../libretro-common/include/ \ -I../../deps/stb \ + -Wl,--no-undefined \ -shared \ -fPIC \ -lm diff --git a/cores/libretro-imageviewer/image_core.c b/cores/libretro-imageviewer/image_core.c index 2c562b3e5f..5f2364e85d 100644 --- a/cores/libretro-imageviewer/image_core.c +++ b/cores/libretro-imageviewer/image_core.c @@ -10,6 +10,8 @@ #include #include +#include + #if defined(HAVE_RPNG) || defined(HAVE_RJPEG) || defined(HAVE_RTGA) || defined(HAVE_RBMP) #define PREFER_NON_STB_IMAGE #endif @@ -157,10 +159,19 @@ void IMAGE_CORE_PREFIX(retro_set_environment)(retro_environment_t cb) static const struct retro_variable vars[] = { { NULL, NULL }, }; + + + struct retro_vfs_interface_info vfs_iface_info = { 1, NULL }; IMAGE_CORE_PREFIX(environ_cb) = cb; cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars); + +#ifndef RARCH_INTERNAL + /* I don't trust filestream_vfs_init to work inside rarch */ + if (environ_cb(RETRO_ENVIRONMENT_GET_VFS_INTERFACE, &vfs_iface_info)) + filestream_vfs_init(&vfs_iface_info); +#endif } void IMAGE_CORE_PREFIX(retro_set_video_refresh)(retro_video_refresh_t cb) @@ -227,6 +238,9 @@ static bool imageviewer_load(const char *path, int image_index) { #ifdef STB_IMAGE_IMPLEMENTATION int comp; + RFILE* f; + size_t len; + void* buf; #endif #ifdef RARCH_INTERNAL extern bool video_driver_supports_rgba(void); @@ -235,12 +249,17 @@ static bool imageviewer_load(const char *path, int image_index) imageviewer_free_image(); #ifdef STB_IMAGE_IMPLEMENTATION - image_buffer = (uint32_t*)stbi_load( - path, - &image_width, - &image_height, - &comp, - 4); + f = filestream_open(path, RETRO_VFS_FILE_ACCESS_READ, 0); + len = filestream_get_size(f); + buf = malloc(len); + filestream_read(f, buf, len); + filestream_close(f); + + image_buffer = (uint32_t*)stbi_load_from_memory( + buf, len, + &image_width, &image_height, + &comp, 4); + free(buf); #else #ifdef RARCH_INTERNAL image_texture.supports_rgba = video_driver_supports_rgba(); diff --git a/libretro-common/vfs/vfs_implementation.c b/libretro-common/vfs/vfs_implementation.c index 396aad61da..eae78ee8bf 100644 --- a/libretro-common/vfs/vfs_implementation.c +++ b/libretro-common/vfs/vfs_implementation.c @@ -182,6 +182,11 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, uns const char *mode_str = NULL; libretro_vfs_implementation_file *stream = (libretro_vfs_implementation_file*)calloc(1, sizeof(*stream)); +#ifdef VFS_FRONTEND + const char * dumb_prefix = "vfsonly://"; + if (!memcmp(path, dumb_prefix, strlen(dumb_prefix))) path += strlen(dumb_prefix); +#endif + if (!stream) return NULL;