Skip to content

Commit

Permalink
Add VFS support to imageviewer (should get Unicode filenames working …
Browse files Browse the repository at this point in the history
…on Windows too, even without VFS)
  • Loading branch information
Alcaro committed Dec 15, 2017
1 parent 29b9ec0 commit c88e5e0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
6 changes: 5 additions & 1 deletion cores/libretro-imageviewer/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
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 \
../../libretro-common/compat/compat_strl.c \
../../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
31 changes: 25 additions & 6 deletions cores/libretro-imageviewer/image_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <compat/strl.h>
#include <retro_environment.h>

#include <streams/file_stream.h>

#if defined(HAVE_RPNG) || defined(HAVE_RJPEG) || defined(HAVE_RTGA) || defined(HAVE_RBMP)
#define PREFER_NON_STB_IMAGE
#endif
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions libretro-common/vfs/vfs_implementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c88e5e0

Please sign in to comment.