aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-11-10 00:45:36 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-11-10 00:46:19 +0100
commit7ef4a06defdd57956655c6e5145bb46faddf8a96 (patch)
treeb64063dba837851510a8dbc79a8614775d5bed39
parent1c5cc5093937b9ea68bba8200f2d71eb613e2979 (diff)
downloadfiv-7ef4a06defdd57956655c6e5145bb46faddf8a96.tar.gz
fiv-7ef4a06defdd57956655c6e5145bb46faddf8a96.tar.xz
fiv-7ef4a06defdd57956655c6e5145bb46faddf8a96.zip
Improve librsvg integration
Let it load external <image>s and not rescale images.
-rw-r--r--fastiv-io.c17
-rw-r--r--fastiv-io.h2
2 files changed, 12 insertions, 7 deletions
diff --git a/fastiv-io.c b/fastiv-io.c
index 14f4e3b..172bddb 100644
--- a/fastiv-io.c
+++ b/fastiv-io.c
@@ -400,10 +400,14 @@ open_libraw(const gchar *data, gsize len, GError **error)
// FIXME: librsvg rasterizes filters, so this method isn't fully appropriate.
static cairo_surface_t *
-open_librsvg(const gchar *data, gsize len, GError **error)
+open_librsvg(const gchar *data, gsize len, const gchar *path, GError **error)
{
- RsvgHandle *handle =
- rsvg_handle_new_from_data((const guint8 *) data, len, error);
+ GFile *base_file = g_file_new_for_path(path);
+ GInputStream *is = g_memory_input_stream_new_from_data(data, len, NULL);
+ RsvgHandle *handle = rsvg_handle_new_from_stream_sync(is, base_file,
+ RSVG_HANDLE_FLAG_KEEP_IMAGE_DATA, NULL, error);
+ g_object_unref(base_file);
+ g_object_unref(is);
if (!handle)
return NULL;
@@ -481,13 +485,14 @@ fastiv_io_open(const gchar *path, GError **error)
if (!g_file_get_contents(path, &data, &len, error))
return NULL;
- cairo_surface_t *surface = fastiv_io_open_from_data(data, len, error);
+ cairo_surface_t *surface = fastiv_io_open_from_data(data, len, path, error);
free(data);
return surface;
}
cairo_surface_t *
-fastiv_io_open_from_data(const char *data, size_t len, GError **error)
+fastiv_io_open_from_data(const char *data, size_t len, const gchar *path,
+ GError **error)
{
wuffs_base__slice_u8 prefix =
wuffs_base__make_slice_u8((uint8_t *) data, len);
@@ -524,7 +529,7 @@ fastiv_io_open_from_data(const char *data, size_t len, GError **error)
g_clear_error(error);
#endif // HAVE_LIBRAW ---------------------------------------------------------
#ifdef HAVE_LIBRSVG // --------------------------------------------------------
- if ((surface = open_librsvg(data, len, error)))
+ if ((surface = open_librsvg(data, len, path, error)))
break;
// XXX: It doesn't look like librsvg can return sensible errors.
diff --git a/fastiv-io.h b/fastiv-io.h
index 616bfc8..6275bc2 100644
--- a/fastiv-io.h
+++ b/fastiv-io.h
@@ -24,5 +24,5 @@ extern const char *fastiv_io_supported_media_types[];
cairo_surface_t *fastiv_io_open(const gchar *path, GError **error);
cairo_surface_t *fastiv_io_open_from_data(
- const char *data, size_t len, GError **error);
+ const char *data, size_t len, const gchar *path, GError **error);
cairo_surface_t *fastiv_io_lookup_thumbnail(const gchar *target);