Add VFS support to imageviewer (should get Unicode filenames working on Windows too, even without VFS)
This commit is contained in:
parent
29b9ec0b5e
commit
c88e5e08a0
|
@ -1,5 +1,6 @@
|
||||||
image_core.so:
|
image_core.so: image_core.c
|
||||||
gcc \
|
gcc \
|
||||||
|
-g \
|
||||||
image_core.c \
|
image_core.c \
|
||||||
../../libretro-common/file/file_path.c \
|
../../libretro-common/file/file_path.c \
|
||||||
../../libretro-common/lists/dir_list.c \
|
../../libretro-common/lists/dir_list.c \
|
||||||
|
@ -7,10 +8,13 @@ image_core.so:
|
||||||
../../libretro-common/compat/compat_strcasestr.c \
|
../../libretro-common/compat/compat_strcasestr.c \
|
||||||
../../libretro-common/lists/string_list.c \
|
../../libretro-common/lists/string_list.c \
|
||||||
../../libretro-common/file/retro_dirent.c \
|
../../libretro-common/file/retro_dirent.c \
|
||||||
|
../../libretro-common/streams/file_stream.c \
|
||||||
|
../../libretro-common/vfs/vfs_implementation.c \
|
||||||
-o image_core.so \
|
-o image_core.so \
|
||||||
-DHAVE_STB_IMAGE \
|
-DHAVE_STB_IMAGE \
|
||||||
-I ../../libretro-common/include/ \
|
-I ../../libretro-common/include/ \
|
||||||
-I../../deps/stb \
|
-I../../deps/stb \
|
||||||
|
-Wl,--no-undefined \
|
||||||
-shared \
|
-shared \
|
||||||
-fPIC \
|
-fPIC \
|
||||||
-lm
|
-lm
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <compat/strl.h>
|
#include <compat/strl.h>
|
||||||
#include <retro_environment.h>
|
#include <retro_environment.h>
|
||||||
|
|
||||||
|
#include <streams/file_stream.h>
|
||||||
|
|
||||||
#if defined(HAVE_RPNG) || defined(HAVE_RJPEG) || defined(HAVE_RTGA) || defined(HAVE_RBMP)
|
#if defined(HAVE_RPNG) || defined(HAVE_RJPEG) || defined(HAVE_RTGA) || defined(HAVE_RBMP)
|
||||||
#define PREFER_NON_STB_IMAGE
|
#define PREFER_NON_STB_IMAGE
|
||||||
#endif
|
#endif
|
||||||
|
@ -157,10 +159,19 @@ void IMAGE_CORE_PREFIX(retro_set_environment)(retro_environment_t cb)
|
||||||
static const struct retro_variable vars[] = {
|
static const struct retro_variable vars[] = {
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct retro_vfs_interface_info vfs_iface_info = { 1, NULL };
|
||||||
|
|
||||||
IMAGE_CORE_PREFIX(environ_cb) = cb;
|
IMAGE_CORE_PREFIX(environ_cb) = cb;
|
||||||
|
|
||||||
cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
|
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)
|
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
|
#ifdef STB_IMAGE_IMPLEMENTATION
|
||||||
int comp;
|
int comp;
|
||||||
|
RFILE* f;
|
||||||
|
size_t len;
|
||||||
|
void* buf;
|
||||||
#endif
|
#endif
|
||||||
#ifdef RARCH_INTERNAL
|
#ifdef RARCH_INTERNAL
|
||||||
extern bool video_driver_supports_rgba(void);
|
extern bool video_driver_supports_rgba(void);
|
||||||
|
@ -235,12 +249,17 @@ static bool imageviewer_load(const char *path, int image_index)
|
||||||
imageviewer_free_image();
|
imageviewer_free_image();
|
||||||
|
|
||||||
#ifdef STB_IMAGE_IMPLEMENTATION
|
#ifdef STB_IMAGE_IMPLEMENTATION
|
||||||
image_buffer = (uint32_t*)stbi_load(
|
f = filestream_open(path, RETRO_VFS_FILE_ACCESS_READ, 0);
|
||||||
path,
|
len = filestream_get_size(f);
|
||||||
&image_width,
|
buf = malloc(len);
|
||||||
&image_height,
|
filestream_read(f, buf, len);
|
||||||
&comp,
|
filestream_close(f);
|
||||||
4);
|
|
||||||
|
image_buffer = (uint32_t*)stbi_load_from_memory(
|
||||||
|
buf, len,
|
||||||
|
&image_width, &image_height,
|
||||||
|
&comp, 4);
|
||||||
|
free(buf);
|
||||||
#else
|
#else
|
||||||
#ifdef RARCH_INTERNAL
|
#ifdef RARCH_INTERNAL
|
||||||
image_texture.supports_rgba = video_driver_supports_rgba();
|
image_texture.supports_rgba = video_driver_supports_rgba();
|
||||||
|
|
|
@ -182,6 +182,11 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, uns
|
||||||
const char *mode_str = NULL;
|
const char *mode_str = NULL;
|
||||||
libretro_vfs_implementation_file *stream = (libretro_vfs_implementation_file*)calloc(1, sizeof(*stream));
|
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)
|
if (!stream)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue