Add support for defaulting to gdk-pixbuf

This commit is contained in:
Přemysl Eric Janouch 2021-11-10 21:33:30 +01:00
parent 405f975899
commit 192698b7bd
Signed by: p
GPG Key ID: A0420B94F92B9493
5 changed files with 42 additions and 2 deletions

View File

@ -2,7 +2,7 @@ fastiv
====== ======
'fastiv' is a fast image viewer, supporting BMP, PNG, GIF, JPEG, and optionally 'fastiv' is a fast image viewer, supporting BMP, PNG, GIF, JPEG, and optionally
RAW and SVG pictures. Currently, it's not particularly usable. RAW and SVG pictures, or whatever gdk-pixbuf loads. Currently, it's very basic.
Non-goals Non-goals
--------- ---------

View File

@ -26,6 +26,10 @@
#ifdef HAVE_LIBRSVG #ifdef HAVE_LIBRSVG
#include <librsvg/rsvg.h> #include <librsvg/rsvg.h>
#endif // HAVE_LIBRSVG #endif // HAVE_LIBRSVG
#ifdef HAVE_GDKPIXBUF
#include <gdk/gdk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#endif // HAVE_GDKPIXBUF
#define WUFFS_IMPLEMENTATION #define WUFFS_IMPLEMENTATION
#define WUFFS_CONFIG__MODULES #define WUFFS_CONFIG__MODULES
@ -479,6 +483,24 @@ open_librsvg(const gchar *data, gsize len, const gchar *path, GError **error)
} }
#endif // HAVE_LIBRSVG -------------------------------------------------------- #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 * cairo_surface_t *
fastiv_io_open(const gchar *path, GError **error) 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); g_clear_error(error);
} }
#endif // HAVE_LIBRSVG -------------------------------------------------------- #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). // TODO(p): Integrate gdk-pixbuf as a fallback (optional dependency).
set_error(error, "unsupported file type"); set_error(error, "unsupported file type");

View File

@ -182,10 +182,12 @@ on_open(void)
"_Cancel", GTK_RESPONSE_CANCEL, "_Cancel", GTK_RESPONSE_CANCEL,
"_Open", GTK_RESPONSE_ACCEPT, NULL); "_Open", GTK_RESPONSE_ACCEPT, NULL);
// NOTE: gdk-pixbuf has gtk_file_filter_add_pixbuf_formats().
GtkFileFilter *filter = gtk_file_filter_new(); GtkFileFilter *filter = gtk_file_filter_new();
for (const char **p = fastiv_io_supported_media_types; *p; p++) for (const char **p = fastiv_io_supported_media_types; *p; p++)
gtk_file_filter_add_mime_type(filter, *p); gtk_file_filter_add_mime_type(filter, *p);
#ifdef HAVE_GDKPIXBUF
gtk_file_filter_add_pixbuf_formats(filter);
#endif // HAVE_GDKPIXBUF
gtk_file_filter_set_name(filter, "Supported images"); gtk_file_filter_set_name(filter, "Supported images");
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
@ -389,6 +391,7 @@ main(int argc, char *argv[])
G_CALLBACK(on_key_press), NULL); G_CALLBACK(on_key_press), NULL);
gtk_container_add(GTK_CONTAINER(g.window), g.stack); gtk_container_add(GTK_CONTAINER(g.window), g.stack);
// TODO(p): Also milk gdk-pixbuf, if linked in, needs to be done in runtime.
g.supported_globs = extract_mime_globs(fastiv_io_supported_media_types); g.supported_globs = extract_mime_globs(fastiv_io_supported_media_types);
g.files = g_ptr_array_new_full(16, g_free); g.files = g_ptr_array_new_full(16, g_free);
gchar *cwd = g_get_current_dir(); gchar *cwd = g_get_current_dir();

View File

@ -3,6 +3,7 @@ project('fastiv', 'c', default_options : ['c_std=gnu99'], version : '0.1.0')
# TODO(p): Use libraw_r later, when we start parallelizing/preloading. # TODO(p): Use libraw_r later, when we start parallelizing/preloading.
libraw = dependency('libraw', required : get_option('libraw')) libraw = dependency('libraw', required : get_option('libraw'))
librsvg = dependency('librsvg-2.0', required : get_option('librsvg')) librsvg = dependency('librsvg-2.0', required : get_option('librsvg'))
gdkpixbuf = dependency('gdk-pixbuf-2.0', required : get_option('gdk-pixbuf'))
dependencies = [ dependencies = [
dependency('gtk+-3.0'), dependency('gtk+-3.0'),
dependency('libturbojpeg'), dependency('libturbojpeg'),
@ -18,6 +19,7 @@ conf.set_quoted('PROJECT_NAME', meson.project_name())
conf.set_quoted('PROJECT_VERSION', meson.project_version()) conf.set_quoted('PROJECT_VERSION', meson.project_version())
conf.set('HAVE_LIBRAW', libraw.found()) conf.set('HAVE_LIBRAW', libraw.found())
conf.set('HAVE_LIBRSVG', librsvg.found()) conf.set('HAVE_LIBRSVG', librsvg.found())
conf.set('HAVE_GDKPIXBUF', gdkpixbuf.found())
configure_file( configure_file(
output : 'config.h', output : 'config.h',
configuration : conf, configuration : conf,

View File

@ -2,3 +2,5 @@ option('libraw', type : 'feature', value : 'auto',
description : 'Build with RAW support, requires LibRaw') description : 'Build with RAW support, requires LibRaw')
option('librsvg', type : 'feature', value : 'auto', option('librsvg', type : 'feature', value : 'auto',
description : 'Build with SVG support, requires librsvg') description : 'Build with SVG support, requires librsvg')
option('gdk-pixbuf', type : 'feature', value : 'auto',
description : 'Build with a fallback to the gdk-pixbuf library')