aboutsummaryrefslogtreecommitdiff
path: root/fastiv-io.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-11-10 21:33:30 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-11-10 21:34:15 +0100
commit192698b7bdfe04e9b6ef4ad4e022422f34a00a53 (patch)
tree44bedabda67d73493e110c69aaec212684e69b06 /fastiv-io.c
parent405f9758997e6399bb573f4fc1119e493fe9c195 (diff)
downloadfiv-192698b7bdfe04e9b6ef4ad4e022422f34a00a53.tar.gz
fiv-192698b7bdfe04e9b6ef4ad4e022422f34a00a53.tar.xz
fiv-192698b7bdfe04e9b6ef4ad4e022422f34a00a53.zip
Add support for defaulting to gdk-pixbuf
Diffstat (limited to 'fastiv-io.c')
-rw-r--r--fastiv-io.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/fastiv-io.c b/fastiv-io.c
index 66b7010..a1811a7 100644
--- a/fastiv-io.c
+++ b/fastiv-io.c
@@ -26,6 +26,10 @@
#ifdef HAVE_LIBRSVG
#include <librsvg/rsvg.h>
#endif // HAVE_LIBRSVG
+#ifdef HAVE_GDKPIXBUF
+#include <gdk/gdk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#endif // HAVE_GDKPIXBUF
#define WUFFS_IMPLEMENTATION
#define WUFFS_CONFIG__MODULES
@@ -479,6 +483,24 @@ open_librsvg(const gchar *data, gsize len, const gchar *path, GError **error)
}
#endif // HAVE_LIBRSVG --------------------------------------------------------
+#ifdef HAVE_GDKPIXBUF // ------------------------------------------------------
+
+static cairo_surface_t *
+open_gdkpixbuf(const gchar *data, gsize len, GError **error)
+{
+ GInputStream *is = g_memory_input_stream_new_from_data(data, len, NULL);
+ GdkPixbuf *pixbuf = gdk_pixbuf_new_from_stream(is, NULL, error);
+ g_object_unref(is);
+ if (!pixbuf)
+ return NULL;
+
+ cairo_surface_t *surface =
+ gdk_cairo_surface_create_from_pixbuf(pixbuf, 1, NULL);
+ g_object_unref(pixbuf);
+ return surface;
+}
+
+#endif // HAVE_GDKPIXBUF ------------------------------------------------------
cairo_surface_t *
fastiv_io_open(const gchar *path, GError **error)
@@ -550,6 +572,17 @@ fastiv_io_open_from_data(const char *data, size_t len, const gchar *path,
g_clear_error(error);
}
#endif // HAVE_LIBRSVG --------------------------------------------------------
+#ifdef HAVE_GDKPIXBUF // ------------------------------------------------------
+ // This is only used as a last resort, the rest above is special-cased.
+ if ((surface = open_gdkpixbuf(data, len, error)) ||
+ (error && (*error)->code != GDK_PIXBUF_ERROR_UNKNOWN_TYPE))
+ break;
+
+ if (error) {
+ g_debug("%s", (*error)->message);
+ g_clear_error(error);
+ }
+#endif // HAVE_GDKPIXBUF ------------------------------------------------------
// TODO(p): Integrate gdk-pixbuf as a fallback (optional dependency).
set_error(error, "unsupported file type");