summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/gdk-pixbuf-io.c
diff options
context:
space:
mode:
authorTor Lillqvist <tml@novell.com>2006-10-11 12:41:14 +0000
committerTor Lillqvist <tml@src.gnome.org>2006-10-11 12:41:14 +0000
commitf6783c746673495080d737d2eed67f55188a34a5 (patch)
treee716d2ed5a3a2fe5540fce85540a5e05b93d524c /gdk-pixbuf/gdk-pixbuf-io.c
parentf58c280d21e87adfa34761f01497e188e222d3ad (diff)
downloadgtk+-f6783c746673495080d737d2eed67f55188a34a5.tar.gz
Enable having some gdk-pixbuf loaders built-in even if loading the others
2006-10-11 Tor Lillqvist <tml@novell.com> * configure.in: Enable having some gdk-pixbuf loaders built-in even if loading the others dynamically. Define Automake conditional INCLUDE_FOO for each loader as TRUE if that loader is built-in. See also gdk-pixbuf/ChangeLog. 2006-10-11 Tor Lillqvist <tml@novell.com> Enable having some loaders built-in even if loading the others dynamically. Have loaders in the same order as in configure.in in all places where they are handled/listed. * Makefile.am: Define the STATIC_FOO_LIB and FOO_LIB macros conditionally depending on whether said loader is built-in or not. Use the names libstatic-pixbufloader-foo.la instead of libpixbufloader-static-foo.la for the built-in ones so that the "echo libpixbufloader-*.la" won't match them. * gdk-pixbuf-io.c: Reorganize code as to plumb the built-in loaders also if USE_GMODULE. Don't warn about a missing gdk-pixbuf.loaders file if we have at least one included loader. * gdk-pixbuf-private.h * io-*.c: Don't define a generic MODULE_ENTRY, as we can't use it in the loaders anyway. Each loader needs to check if INCLUDE_foo is defined.
Diffstat (limited to 'gdk-pixbuf/gdk-pixbuf-io.c')
-rw-r--r--gdk-pixbuf/gdk-pixbuf-io.c265
1 files changed, 127 insertions, 138 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c
index 9b83f4b48a..1dbbd26cf9 100644
--- a/gdk-pixbuf/gdk-pixbuf-io.c
+++ b/gdk-pixbuf/gdk-pixbuf-io.c
@@ -282,9 +282,12 @@ gdk_pixbuf_get_module_file (void)
return result;
}
+#endif /* USE_GMODULE */
+
static void
gdk_pixbuf_io_init (void)
{
+#ifdef USE_GMODULE
GIOChannel *channel;
gchar *line_buf;
gsize term;
@@ -296,11 +299,69 @@ gdk_pixbuf_io_init (void)
int n_patterns = 0;
GdkPixbufModulePattern *pattern;
GError *error = NULL;
+#endif
+ GdkPixbufModule *builtin_module = NULL;
+
+#define load_one_builtin_module(format) \
+ builtin_module = g_new0 (GdkPixbufModule, 1); \
+ builtin_module->module_name = #format; \
+ if (_gdk_pixbuf_load_module (builtin_module, NULL)) \
+ file_formats = g_slist_prepend (file_formats, builtin_module);\
+ else \
+ g_free (builtin_module)
+#ifdef INCLUDE_ani
+ load_one_builtin_module (ani);
+#endif
+#ifdef INCLUDE_png
+ load_one_builtin_module (png);
+#endif
+#ifdef INCLUDE_bmp
+ load_one_builtin_module (bmp);
+#endif
+#ifdef INCLUDE_wbmp
+ load_one_builtin_module (wbmp);
+#endif
+#ifdef INCLUDE_gif
+ load_one_builtin_module (gif);
+#endif
+#ifdef INCLUDE_ico
+ load_one_builtin_module (ico);
+#endif
+#ifdef INCLUDE_jpeg
+ load_one_builtin_module (jpeg);
+#endif
+#ifdef INCLUDE_pnm
+ load_one_builtin_module (pnm);
+#endif
+#ifdef INCLUDE_ras
+ load_one_builtin_module (ras);
+#endif
+#ifdef INCLUDE_tiff
+ load_one_builtin_module (tiff);
+#endif
+#ifdef INCLUDE_xpm
+ load_one_builtin_module (xpm);
+#endif
+#ifdef INCLUDE_xbm
+ load_one_builtin_module (xbm);
+#endif
+#ifdef INCLUDE_tga
+ load_one_builtin_module (tga);
+#endif
+#ifdef INCLUDE_pcx
+ load_one_builtin_module (pcx);
+#endif
+
+#undef load_one_builtin_module
+
+#ifdef USE_GMODULE
channel = g_io_channel_new_file (filename, "r", &error);
if (!channel) {
- g_warning ("Cannot open pixbuf loader module file '%s': %s",
- filename, error->message);
+ /* Don't bother warning if we have some built-in loaders */
+ if (file_formats == NULL)
+ g_warning ("Cannot open pixbuf loader module file '%s': %s",
+ filename, error->message);
return;
}
@@ -438,8 +499,11 @@ gdk_pixbuf_io_init (void)
g_string_free (tmp_buf, TRUE);
g_io_channel_unref (channel);
g_free (filename);
+#endif
}
+#ifdef USE_GMODULE
+
/* actually load the image handler - gdk_pixbuf_get_module only get a */
/* reference to the module to load, it doesn't actually load it */
/* perhaps these actions should be combined in one function */
@@ -481,199 +545,124 @@ _gdk_pixbuf_load_module_unlocked (GdkPixbufModule *image_module,
}
}
-gboolean
-_gdk_pixbuf_load_module (GdkPixbufModule *image_module,
- GError **error)
-{
- gboolean ret;
- gboolean locked = FALSE;
-
- /* be extra careful, maybe the module initializes
- * the thread system
- */
- if (g_threads_got_initialized)
- {
- G_LOCK (init_lock);
- locked = TRUE;
- }
- ret = _gdk_pixbuf_load_module_unlocked (image_module, error);
- if (locked)
- G_UNLOCK (init_lock);
- return ret;
-}
-
-#else /* !USE_GMODULE */
+#endif /* !USE_GMODULE */
#define module(type) \
- extern void MODULE_ENTRY (type, fill_info) (GdkPixbufFormat *info); \
- extern void MODULE_ENTRY (type, fill_vtable) (GdkPixbufModule *module)
+ extern void _gdk_pixbuf__##type##_fill_info (GdkPixbufFormat *info); \
+ extern void _gdk_pixbuf__##type##_fill_vtable (GdkPixbufModule *module)
module (png);
-module (bmp);
-module (wbmp);
+module (jpeg);
module (gif);
module (ico);
module (ani);
-module (jpeg);
-module (pnm);
module (ras);
-module (tiff);
module (xpm);
+module (tiff);
+module (pnm);
+module (bmp);
+module (wbmp);
module (xbm);
module (tga);
module (pcx);
+#undef module
+
gboolean
_gdk_pixbuf_load_module (GdkPixbufModule *image_module,
- GError **error)
+ GError **error)
{
+ gboolean ret;
+ gboolean locked = FALSE;
GdkPixbufModuleFillInfoFunc fill_info = NULL;
GdkPixbufModuleFillVtableFunc fill_vtable = NULL;
- image_module->module = (void *) 1;
-
- if (FALSE) {
- /* Ugly hack so we can use else if unconditionally below ;-) */
- }
-
-#ifdef INCLUDE_png
- else if (strcmp (image_module->module_name, "png") == 0) {
- fill_info = MODULE_ENTRY (png, fill_info);
- fill_vtable = MODULE_ENTRY (png, fill_vtable);
+#define try_module(format) \
+ if (fill_info == NULL && \
+ strcmp (image_module->module_name, #format) == 0) { \
+ fill_info = _gdk_pixbuf__##format##_fill_info; \
+ fill_vtable = _gdk_pixbuf__##format##_fill_vtable; \
}
+#ifdef INCLUDE_png
+ try_module (png);
#endif
-
-#ifdef INCLUDE_bmp
- else if (strcmp (image_module->module_name, "bmp") == 0) {
- fill_info = MODULE_ENTRY (bmp, fill_info);
- fill_vtable = MODULE_ENTRY (bmp, fill_vtable);
- }
+#ifdef INCLUDE_bmp
+ try_module (bmp);
#endif
-
#ifdef INCLUDE_wbmp
- else if (strcmp (image_module->module_name, "wbmp") == 0) {
- fill_info = MODULE_ENTRY (wbmp, fill_info);
- fill_vtable = MODULE_ENTRY (wbmp, fill_vtable);
- }
+ try_module (wbmp);
#endif
-
#ifdef INCLUDE_gif
- else if (strcmp (image_module->module_name, "gif") == 0) {
- fill_info = MODULE_ENTRY (gif, fill_info);
- fill_vtable = MODULE_ENTRY (gif, fill_vtable);
- }
+ try_module (gif);
#endif
-
#ifdef INCLUDE_ico
- else if (strcmp (image_module->module_name, "ico") == 0) {
- fill_info = MODULE_ENTRY (ico, fill_info);
- fill_vtable = MODULE_ENTRY (ico, fill_vtable);
- }
+ try_module (ico);
#endif
-
#ifdef INCLUDE_ani
- else if (strcmp (image_module->module_name, "ani") == 0) {
- fill_info = MODULE_ENTRY (ani, fill_info);
- fill_vtable = MODULE_ENTRY (ani, fill_vtable);
- }
+ try_module (ani);
#endif
-
#ifdef INCLUDE_jpeg
- else if (strcmp (image_module->module_name, "jpeg") == 0) {
- fill_info = MODULE_ENTRY (jpeg, fill_info);
- fill_vtable = MODULE_ENTRY (jpeg, fill_vtable);
- }
+ try_module (jpeg);
#endif
-
#ifdef INCLUDE_pnm
- else if (strcmp (image_module->module_name, "pnm") == 0) {
- fill_info = MODULE_ENTRY (pnm, fill_info);
- fill_vtable = MODULE_ENTRY (pnm, fill_vtable);
- }
+ try_module (pnm);
#endif
-
#ifdef INCLUDE_ras
- else if (strcmp (image_module->module_name, "ras") == 0) {
- fill_info = MODULE_ENTRY (ras, fill_info);
- fill_vtable = MODULE_ENTRY (ras, fill_vtable);
- }
+ try_module (ras);
#endif
-
#ifdef INCLUDE_tiff
- else if (strcmp (image_module->module_name, "tiff") == 0) {
- fill_info = MODULE_ENTRY (tiff, fill_info);
- fill_vtable = MODULE_ENTRY (tiff, fill_vtable);
- }
+ try_module (tiff);
#endif
-
#ifdef INCLUDE_xpm
- else if (strcmp (image_module->module_name, "xpm") == 0) {
- fill_info = MODULE_ENTRY (xpm, fill_info);
- fill_vtable = MODULE_ENTRY (xpm, fill_vtable);
- }
+ try_module (xpm);
#endif
-
#ifdef INCLUDE_xbm
- else if (strcmp (image_module->module_name, "xbm") == 0) {
- fill_info = MODULE_ENTRY (xbm, fill_info);
- fill_vtable = MODULE_ENTRY (xbm, fill_vtable);
- }
+ try_module (xbm);
#endif
-
#ifdef INCLUDE_tga
- else if (strcmp (image_module->module_name, "tga") == 0) {
- fill_info = MODULE_ENTRY (tga, fill_info);
- fill_vtable = MODULE_ENTRY (tga, fill_vtable);
- }
+ try_module (tga);
#endif
-
#ifdef INCLUDE_pcx
- else if (strcmp (image_module->module_name, "pcx") == 0) {
- fill_info = MODULE_ENTRY (pcx, fill_info);
- fill_vtable = MODULE_ENTRY (pcx, fill_vtable);
- }
+ try_module (pcx);
#endif
+
+#undef try_module
if (fill_vtable) {
+ image_module->module = (void *) 1;
(* fill_vtable) (image_module);
image_module->info = g_new0 (GdkPixbufFormat, 1);
(* fill_info) (image_module->info);
return TRUE;
- } else {
- g_set_error (error,
- GDK_PIXBUF_ERROR,
- GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
- _("Image type '%s' is not supported"),
- image_module->module_name);
-
- return FALSE;
- }
-}
+ }
-static void
-gdk_pixbuf_io_init ()
-{
- gchar *included_formats[] = {
- "ani", "png", "bmp", "wbmp", "gif",
- "ico", "jpeg", "pnm", "ras", "tiff",
- "xpm", "xbm", "tga", "pcx",
- NULL
- };
- gchar **name;
- GdkPixbufModule *module = NULL;
+#ifdef USE_GMODULE
- for (name = included_formats; *name; name++) {
- module = g_new0 (GdkPixbufModule, 1);
- module->module_name = *name;
- if (_gdk_pixbuf_load_module (module, NULL))
- file_formats = g_slist_prepend (file_formats, module);
- else
- g_free (module);
+ /* be extra careful, maybe the module initializes
+ * the thread system
+ */
+ if (g_threads_got_initialized)
+ {
+ G_LOCK (init_lock);
+ locked = TRUE;
}
-}
+ ret = _gdk_pixbuf_load_module_unlocked (image_module, error);
+ if (locked)
+ G_UNLOCK (init_lock);
+ return ret;
-#endif /* !USE_GMODULE */
+#else
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
+ _("Image type '%s' is not supported"),
+ image_module->module_name);
+
+ return FALSE;
+
+#endif
+}