diff options
28 files changed, 1417 insertions, 574 deletions
diff --git a/gdk-pixbuf/Makefile.am b/gdk-pixbuf/Makefile.am index 40aa4635d..c506d3331 100644 --- a/gdk-pixbuf/Makefile.am +++ b/gdk-pixbuf/Makefile.am @@ -243,6 +243,7 @@ INCLUDES = @STRIP_BEGIN@ \ -I$(top_srcdir) -I$(top_builddir) \ -I$(top_srcdir)/gdk-pixbuf \ -I$(top_builddir)/gdk-pixbuf \ + -DGTK_SYSCONFDIR=\"$(sysconfdir)\" \ -DGTK_VERSION=\"@GTK_VERSION@\" \ -DGTK_BINARY_VERSION=\"@GTK_BINARY_VERSION@\" \ -DG_DISABLE_DEPRECATED \ @@ -250,6 +251,7 @@ INCLUDES = @STRIP_BEGIN@ \ @INCLUDED_LOADER_DEFINE@ \ @GTK_DEBUG_FLAGS@ \ @GDK_PIXBUF_DEP_CFLAGS@ \ + -DGDK_PIXBUF_ENABLE_BACKEND \ @STRIP_END@ AM_CPPFLAGS = "-DPIXBUF_LIBDIR=\"$(loaderdir)\"" "-DBUILT_MODULES_DIR=\"$(srcdir)/.libs\"" @@ -258,10 +260,16 @@ LDADDS = libgdk_pixbuf-$(GTK_API_VERSION).la noinst_PROGRAMS = test-gdk-pixbuf test_gdk_pixbuf_LDADD = $(LDADDS) -bin_PROGRAMS = gdk-pixbuf-csource +bin_PROGRAMS = gdk-pixbuf-csource gdk-pixbuf-query-loaders gdk_pixbuf_csource_SOURCES = gdk-pixbuf-csource.c gdk_pixbuf_csource_LDADD = $(LDADDS) +gdk_pixbuf_query_loaders_DEPENDENCIES = $(DEPS) +gdk_pixbuf_query_loaders_LDADD = $(LDADDS) + +gdk_pixbuf_query_loaders_SOURCES = queryloaders.c + + # # manual pages to install # @@ -296,6 +304,8 @@ libgdk_pixbuf_2_0_la_DEPENDENCIES = pixops/libpixops.la $(builtin_objs) $(gdk_pi gdk_pixbuf_headers = \ gdk-pixbuf.h \ + gdk-pixbuf-io.h \ + gdk-pixbuf-animation.h \ gdk-pixbuf-loader.h libgdk_pixbufinclude_HEADERS = \ @@ -305,7 +315,6 @@ libgdk_pixbufinclude_HEADERS = \ gdk-pixdata.h noinst_HEADERS = \ - gdk-pixbuf-io.h \ gdk-pixbuf-private.h gdk_pixbuf_built_headers = gdk-pixbuf-enum-types.h gdk-pixbuf-marshal.h @@ -405,6 +414,37 @@ EXTRA_DIST = \ pixbufloader_xbm.def \ pixbufloader_tga.def +if CROSS_COMPILING +RUN_QUERY_LOADER_TEST=false +else +RUN_QUERY_LOADER_TEST=test -z "$(DESTDIR)" +endif + +# Running this if cross compiling or if DESTDIR is set is going to +# not work at all, so skip it install-data-local: install-ms-lib install-libtool-import-lib + @if $(RUN_QUERY_LOADER_TEST) ; then \ + $(mkinstalldirs) $(DESTDIR)$(sysconfdir)/gtk-2.0 ; \ + $(top_builddir)/gdk-pixbuf/gdk-pixbuf-query-loaders > $(DESTDIR)$(sysconfdir)/gtk-2.0/gdk-pixbuf.loaders ; \ + else \ + echo "***" ; \ + echo "*** Warning: gdk-pixbuf.loaders not built" ; \ + echo "***" ; \ + echo "*** Generate this file manually on on host" ; \ + echo "*** system using gdk-pixbuf-query-loaders" ; \ + echo "***" ; \ + fi + +all-local: gdk-pixbuf.loaders + +gdk-pixbuf.loaders: + if find . -name 'libpixbufloader-*.so' | grep 'so' > /dev/null ; then \ + echo "Writing a gdk-pixbuf.loader file to use when running examples before installing gdk-pixbuf."; \ + GDK_PIXBUF_MODULEDIR=.libs $(top_builddir)/gdk-pixbuf/gdk-pixbuf-query-loaders > ./gdk-pixbuf.loaders ;\ + else \ + echo "No dynamic modules found; will use only static modules for uninstalled example programs."; \ + touch gdk-pixbuf.loaders; \ + fi uninstall-local: uninstall-ms-lib uninstall-libtool-import-lib + diff --git a/gdk-pixbuf/gdk-pixbuf-animation.c b/gdk-pixbuf/gdk-pixbuf-animation.c index 492e8a538..913751a69 100644 --- a/gdk-pixbuf/gdk-pixbuf-animation.c +++ b/gdk-pixbuf/gdk-pixbuf-animation.c @@ -24,8 +24,10 @@ #include <config.h> #include <errno.h> -#include "gdk-pixbuf-io.h" #include "gdk-pixbuf-private.h" +#include "gdk-pixbuf-io.h" +#include "gdk-pixbuf-i18n.h" +#include "gdk-pixbuf-animation.h" typedef struct _GdkPixbufNonAnim GdkPixbufNonAnim; typedef struct _GdkPixbufNonAnimClass GdkPixbufNonAnimClass; diff --git a/gdk-pixbuf/gdk-pixbuf-animation.h b/gdk-pixbuf/gdk-pixbuf-animation.h new file mode 100644 index 000000000..d8091e2c8 --- /dev/null +++ b/gdk-pixbuf/gdk-pixbuf-animation.h @@ -0,0 +1,99 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ +/* GdkPixbuf library - Private declarations + * + * Copyright (C) 1999 The Free Software Foundation + * + * Authors: Mark Crichton <crichton@gimp.org> + * Miguel de Icaza <miguel@gnu.org> + * Federico Mena-Quintero <federico@gimp.org> + * Havoc Pennington <hp@redhat.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef GDK_PIXBUF_ANIMATION_H +#define GDK_PIXBUF_ANIMATION_H + +#include "gdk-pixbuf/gdk-pixbuf.h" + +G_BEGIN_DECLS + +#ifdef GDK_PIXBUF_ENABLE_BACKEND + + + +typedef struct _GdkPixbufAnimationClass GdkPixbufAnimationClass; + +#define GDK_PIXBUF_ANIMATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_ANIMATION, GdkPixbufAnimationClass)) +#define GDK_IS_PIXBUF_ANIMATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_ANIMATION)) +#define GDK_PIXBUF_ANIMATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_ANIMATION, GdkPixbufAnimationClass)) + +/* Private part of the GdkPixbufAnimation structure */ +struct _GdkPixbufAnimation { + GObject parent_instance; + +}; + +struct _GdkPixbufAnimationClass { + GObjectClass parent_class; + + gboolean (*is_static_image) (GdkPixbufAnimation *anim); + + GdkPixbuf* (*get_static_image) (GdkPixbufAnimation *anim); + + void (*get_size) (GdkPixbufAnimation *anim, + int *width, + int *height); + + GdkPixbufAnimationIter* (*get_iter) (GdkPixbufAnimation *anim, + const GTimeVal *start_time); + +}; + + + +typedef struct _GdkPixbufAnimationIterClass GdkPixbufAnimationIterClass; + +#define GDK_PIXBUF_ANIMATION_ITER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_ANIMATION_ITER, GdkPixbufAnimationIterClass)) +#define GDK_IS_PIXBUF_ANIMATION_ITER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_ANIMATION_ITER)) +#define GDK_PIXBUF_ANIMATION_ITER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_ANIMATION_ITER, GdkPixbufAnimationIterClass)) + +struct _GdkPixbufAnimationIter { + GObject parent_instance; + +}; + +struct _GdkPixbufAnimationIterClass { + GObjectClass parent_class; + + int (*get_delay_time) (GdkPixbufAnimationIter *iter); + + GdkPixbuf* (*get_pixbuf) (GdkPixbufAnimationIter *iter); + + gboolean (*on_currently_loading_frame) (GdkPixbufAnimationIter *iter); + + gboolean (*advance) (GdkPixbufAnimationIter *iter, + const GTimeVal *current_time); +}; + + +GdkPixbufAnimation* gdk_pixbuf_non_anim_new (GdkPixbuf *pixbuf); + +#endif /* GDK_PIXBUF_ENABLE_BACKEND */ + +G_END_DECLS + +#endif /* GDK_PIXBUF_ANIMATION_H */ diff --git a/gdk-pixbuf/gdk-pixbuf-data.c b/gdk-pixbuf/gdk-pixbuf-data.c index 3780c0412..5156c4ee8 100644 --- a/gdk-pixbuf/gdk-pixbuf-data.c +++ b/gdk-pixbuf/gdk-pixbuf-data.c @@ -23,7 +23,6 @@ #include <config.h> #include "gdk-pixbuf.h" #include "gdk-pixbuf-private.h" -#include "gdk-pixbuf-i18n.h" #include <stdlib.h> #include <string.h> diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c index dc760ac0a..ad126337f 100644 --- a/gdk-pixbuf/gdk-pixbuf-io.c +++ b/gdk-pixbuf/gdk-pixbuf-io.c @@ -23,6 +23,8 @@ */ #include <config.h> +#include <stdlib.h> +#include <stdio.h> #include <string.h> #include <glib.h> #include <errno.h> @@ -35,250 +37,298 @@ #undef STRICT #endif - - -static gboolean -pixbuf_check_png (guchar *buffer, int size) -{ - if (size < 28) - return FALSE; - - if (buffer [0] != 0x89 || - buffer [1] != 'P' || - buffer [2] != 'N' || - buffer [3] != 'G' || - buffer [4] != 0x0d || - buffer [5] != 0x0a || - buffer [6] != 0x1a || - buffer [7] != 0x0a) - return FALSE; - - return TRUE; -} - -static gboolean -pixbuf_check_jpeg (guchar *buffer, int size) +static gint +format_check (GdkPixbufModule *module, guchar *buffer, int size) { - if (size < 10) - return FALSE; - - if (buffer [0] != 0xff || buffer [1] != 0xd8) - return FALSE; - - return TRUE; + int j; + gchar m; + GdkPixbufModulePattern *pattern; + + for (pattern = module->info->signature; pattern->prefix; pattern++) { + for (j = 0; j < size && pattern->prefix[j] != 0; j++) { + m = pattern->mask ? pattern->mask[j] : ' '; + if (m == ' ') { + if (buffer[j] != pattern->prefix[j]) + break; + } + else if (m == '!') { + if (buffer[j] == pattern->prefix[j]) + break; + } + else if (m == 'z') { + if (buffer[j] != 0) + break; + } + else if (m == 'n') { + if (buffer[j] == 0) + break; + } + } + if (pattern->prefix[j] == 0) + return pattern->relevance; + } + return 0; } -static gboolean -pixbuf_check_tiff (guchar *buffer, int size) -{ - if (size < 10) - return FALSE; - - if (buffer [0] == 'M' && - buffer [1] == 'M' && - buffer [2] == 0 && - buffer [3] == 0x2a) - return TRUE; - - if (buffer [0] == 'I' && - buffer [1] == 'I' && - buffer [2] == 0x2a && - buffer [3] == 0) - return TRUE; +static GSList *file_formats = NULL; - return FALSE; -} +static void gdk_pixbuf_io_init (); -static gboolean -pixbuf_check_gif (guchar *buffer, int size) +static GSList * +get_file_formats () { - if (size < 20) - return FALSE; - - if (strncmp (buffer, "GIF8", 4) == 0) - return TRUE; - - return FALSE; + if (file_formats == NULL) + gdk_pixbuf_io_init (); + + return file_formats; } -static gboolean -pixbuf_check_xpm (guchar *buffer, int size) -{ - if (size < 20) - return FALSE; - - if (strncmp (buffer, "/* XPM */", 9) == 0) - return TRUE; - return FALSE; -} +#ifdef USE_GMODULE static gboolean -pixbuf_check_pnm (guchar *buffer, int size) +scan_string (const char **pos, GString *out) { - if (size < 20) + const char *p = *pos, *q = *pos; + char *tmp, *tmp2; + gboolean quoted; + + while (g_ascii_isspace (*p)) + p++; + + if (!*p) return FALSE; - - if (buffer [0] == 'P') { - if (buffer [1] == '1' || - buffer [1] == '2' || - buffer [1] == '3' || - buffer [1] == '4' || - buffer [1] == '5' || - buffer [1] == '6') - return TRUE; + else if (*p == '"') { + p++; + quoted = FALSE; + for (q = p; (*q != '"') || quoted; q++) { + if (!*q) + return FALSE; + quoted = (*q == '\\') && !quoted; + } + + tmp = g_strndup (p, q - p); + tmp2 = g_strcompress (tmp); + g_string_truncate (out, 0); + g_string_append (out, tmp2); + g_free (tmp); + g_free (tmp2); } - return FALSE; -} -static gboolean -pixbuf_check_sunras (guchar *buffer, int size) -{ - if (size < 32) - return FALSE; - - if (buffer [0] != 0x59 || - buffer [1] != 0xA6 || - buffer [2] != 0x6A || - buffer [3] != 0x95) - return FALSE; - + + q++; + *pos = q; + return TRUE; } static gboolean -pixbuf_check_ico (guchar *buffer, int size) +scan_int (const char **pos, int *out) { - /* Note that this may cause false positives, but .ico's don't - have a magic number.*/ - if (size < 6) - return FALSE; - if (buffer [0] != 0x0 || - buffer [1] != 0x0 || - ((buffer [2] != 0x1)&&(buffer[2]!=0x2)) || - buffer [3] != 0x0 || - buffer [4] == 0x0 || - buffer [5] != 0x0 ) + int i = 0; + char buf[32]; + const char *p = *pos; + + while (g_ascii_isspace (*p)) + p++; + + if (*p < '0' || *p > '9') return FALSE; + + while ((*p >= '0') && (*p <= '9') && i < sizeof (buf)) { + buf[i] = *p; + i++; + p++; + } + + if (i == sizeof (buf)) + return FALSE; + else + buf[i] = '\0'; + + *out = atoi (buf); + + *pos = p; return TRUE; } static gboolean -pixbuf_check_ani (guchar *buffer, int size) -{ - if (size < 12) - return FALSE; - - if (buffer [0] != 'R' || - buffer [1] != 'I' || - buffer [2] != 'F' || - buffer [3] != 'F' || - buffer [8] != 'A' || - buffer [9] != 'C' || - buffer[10] != 'O' || - buffer[11] != 'N') - return FALSE; - - return TRUE; -} - - -static gboolean -pixbuf_check_bmp (guchar *buffer, int size) +skip_space (const char **pos) { - if (size < 20) - return FALSE; - - if (buffer [0] != 'B' || buffer [1] != 'M') - return FALSE; - - return TRUE; + const char *p = *pos; + + while (g_ascii_isspace (*p)) + p++; + + *pos = p; + + return !(*p == '\0'); } - -static gboolean -pixbuf_check_wbmp (guchar *buffer, int size) + +static gchar * +gdk_pixbuf_get_module_file (void) { - if(size < 10) /* at least */ - return FALSE; + gchar *result = g_strdup (g_getenv ("GDK_PIXBUF_MODULE_FILE")); - if(buffer[0] == '\0' /* We only handle type 0 wbmp's for now */) - return TRUE; + if (!result) + result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gdk-pixbuf.loaders", NULL); - return FALSE; + return result; } - -static gboolean -pixbuf_check_xbm (guchar *buffer, int size) +static void +gdk_pixbuf_io_init () { - if (size < 20) - return FALSE; - - if (buffer [0] == '#' - && buffer [1] == 'd' - && buffer [2] == 'e' - && buffer [3] == 'f' - && buffer [4] == 'i' - && buffer [5] == 'n' - && buffer [6] == 'e' - && buffer [7] == ' ') - return TRUE; - - /* Note that this requires xpm to be checked before xbm. */ - if (buffer [0] == '/' - && buffer [1] != '*') - return TRUE; - - return FALSE; -} + GIOChannel *channel; + gchar *line_buf; + gsize term; + GString *tmp_buf = g_string_new (NULL); + gboolean have_error = FALSE; + GdkPixbufModule *module = NULL; + gchar *filename = gdk_pixbuf_get_module_file (); + int flags; + int n_patterns = 0; + GdkPixbufModulePattern *pattern; + GError *error = NULL; + + channel = g_io_channel_new_file (filename, "r", &error); + if (!channel) { + g_warning ("Can not open pixbuf loader module file '%s': %s", + filename, error->message); + return; + } + + while (!have_error && g_io_channel_read_line (channel, &line_buf, NULL, &term, NULL) == G_IO_STATUS_NORMAL) { + const char *p; + + p = line_buf; -static gboolean -pixbuf_check_tga (guchar *buffer, int size) -{ - if (size < 18) - return FALSE; - /* buffer[1] is a boolean telling if in the file a colormap is - present, while buffer[2] is the byte which specifies the image - type. (GrayScale/PseudoColor/TrueColor/RLE) */ - if ((buffer[2] == 1) || (buffer[2] == 9)) { - if (buffer[1] != 1) - return FALSE; - } else { - if (buffer[1] != 0) - return FALSE; - } - return TRUE; -} + line_buf[term] = 0; -static GdkPixbufModule file_formats [] = { - { "png", pixbuf_check_png, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }, - { "jpeg", pixbuf_check_jpeg, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { "tiff", pixbuf_check_tiff, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { "gif", pixbuf_check_gif, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, -#define XPM_FILE_FORMAT_INDEX 4 - { "xpm", pixbuf_check_xpm, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { "pnm", pixbuf_check_pnm, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { "ras", pixbuf_check_sunras, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { "bmp", pixbuf_check_bmp, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { "xbm", pixbuf_check_xbm, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { "ico", pixbuf_check_ico, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { "ani", pixbuf_check_ani, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { "tga", pixbuf_check_tga, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { "wbmp", pixbuf_check_wbmp, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } -}; + if (!skip_space (&p)) { + /* Blank line marking the end of a module + */ + if (module && *p != '#') { + file_formats = g_slist_prepend (file_formats, module); + module = NULL; + } + + goto next_line; + } -#ifdef USE_GMODULE -static gboolean -pixbuf_module_symbol (GModule *module, const char *module_name, const char *symbol_name, gpointer *symbol) -{ - char *full_symbol_name = g_strconcat ("gdk_pixbuf__", module_name, "_", symbol_name, NULL); - gboolean return_value; + if (*p == '#') + goto next_line; + + if (!module) { + /* Read a module location + */ + module = g_new0 (GdkPixbufModule, 1); + n_patterns = 0; + + if (!scan_string (&p, tmp_buf)) { + g_warning ("Error parsing loader info in '%s'\n %s", + filename, line_buf); + have_error = TRUE; + } + module->module_path = g_strdup (tmp_buf->str); + } + else if (!module->module_name) { + module->info = g_new0 (GdkPixbufFormat, 1); + if (!scan_string (&p, tmp_buf)) { + g_warning ("Error parsing loader info in '%s'\n %s", + filename, line_buf); + have_error = TRUE; + } + module->info->name = g_strdup (tmp_buf->str); + module->module_name = module->info->name; - return_value = g_module_symbol (module, full_symbol_name, symbol); - g_free (full_symbol_name); - - return return_value; + if (!scan_int (&p, &flags)) { + g_warning ("Error parsing loader info in '%s'\n %s", + filename, line_buf); + have_error = TRUE; + } + module->info->flags = flags; + + if (!scan_string (&p, tmp_buf)) { + g_warning ("Error parsing loader info in '%s'\n %s", + filename, line_buf); + have_error = TRUE; + } + if (tmp_buf->str[0] != 0) + module->info->domain = g_strdup (tmp_buf->str); + + if (!scan_string (&p, tmp_buf)) { + g_warning ("Error parsing loader info in '%s'\n %s", + filename, line_buf); + have_error = TRUE; + } + module->info->description = g_strdup (tmp_buf->str); + } + else if (!module->info->mime_types) { + int n = 1; + module->info->mime_types = g_new0 (gchar*, 1); + while (scan_string (&p, tmp_buf)) { + if (tmp_buf->str[0] != 0) { + module->info->mime_types = + g_realloc (module->info->mime_types, (n + 1) * sizeof (gchar*)); + module->info->mime_types[n - 1] = g_strdup (tmp_buf->str); + module->info->mime_types[n] = 0; + n++; + } + } + } + else if (!module->info->extensions) { + int n = 1; + module->info->extensions = g_new0 (gchar*, 1); + while (scan_string (&p, tmp_buf)) { + if (tmp_buf->str[0] != 0) { + module->info->extensions = + g_realloc (module->info->extensions, (n + 1) * sizeof (gchar*)); + module->info->extensions[n - 1] = g_strdup (tmp_buf->str); + module->info->extensions[n] = 0; + n++; + } + } + } + else { + n_patterns++; + module->info->signature = (GdkPixbufModulePattern *) + g_realloc (module->info->signature, (n_patterns + 1) * sizeof (GdkPixbufModulePattern)); + pattern = module->info->signature + n_patterns; + pattern->prefix = NULL; + pattern->mask = NULL; + pattern->relevance = 0; + pattern--; + if (!scan_string (&p, tmp_buf)) + goto context_error; + pattern->prefix = g_strdup (tmp_buf->str); + + if (!scan_string (&p, tmp_buf)) + goto context_error; + if (*tmp_buf->str) + pattern->mask = g_strdup (tmp_buf->str); + else + pattern->mask = NULL; + + if (!scan_int (&p, &pattern->relevance)) + goto context_error; + + goto next_line; + + context_error: + g_free (pattern->prefix); + g_free (pattern->mask); + g_free (pattern); + g_warning ("Error parsing loader info in '%s'\n %s", + filename, line_buf); + have_error = TRUE; + } + next_line: + g_free (line_buf); + } + g_string_free (tmp_buf, TRUE); + g_io_channel_unref (channel); + g_free (filename); } #ifdef G_OS_WIN32 @@ -304,31 +354,6 @@ get_libdir (void) #endif -/* Like g_module_path, but use .la as the suffix - */ -static gchar* -module_build_la_path (const gchar *directory, - const gchar *module_name) -{ - gchar *filename; - gchar *result; - - if (strncmp (module_name, "lib", 3) == 0) - filename = (gchar *)module_name; - else - filename = g_strconcat ("lib", module_name, ".la", NULL); - - if (directory && *directory) - result = g_build_filename (directory, filename, NULL); - else - result = g_strdup (filename); - - if (filename != module_name) - g_free (filename); - - return result; -} - /* 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 */ @@ -336,98 +361,66 @@ gboolean _gdk_pixbuf_load_module (GdkPixbufModule *image_module, GError **error) { - char *module_name; char *path; GModule *module; gpointer sym; - char *name; - gboolean retval; - const char *dir; g_return_val_if_fail (image_module->module == NULL, FALSE); - name = image_module->module_name; - - module_name = g_strconcat ("pixbufloader-", name, NULL); - - /* This would be an exploit in an suid binary using gdk-pixbuf, - * but see http://www.gtk.org/setuid.html or the BugTraq - * archives for why you should report this as a bug against - * setuid apps using this library rather than the library - * itself. - */ - dir = g_getenv ("GDK_PIXBUF_MODULEDIR"); - if (dir == NULL || *dir == '\0') - dir = PIXBUF_LIBDIR; - - path = g_module_build_path (dir, module_name); + path = image_module->module_path; module = g_module_open (path, G_MODULE_BIND_LAZY); - if (!module) { - g_free (path); - path = module_build_la_path (dir, module_name); - module = g_module_open (path, G_MODULE_BIND_LAZY); - } - if (!module) { - g_free (path); - path = g_module_build_path (dir, module_name); - g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_FAILED, _("Unable to load image-loading module: %s: %s"), path, g_module_error ()); - g_free (module_name); - g_free (path); return FALSE; } - g_free (module_name); - image_module->module = module; - if (pixbuf_module_symbol (module, name, "fill_vtable", &sym)) { - ModuleFillVtableFunc func = (ModuleFillVtableFunc) sym; + if (g_module_symbol (module, "fill_vtable", &sym)) { + GdkPixbufModuleFillVtableFunc func = (GdkPixbufModuleFillVtableFunc) sym; (* func) (image_module); - retval = TRUE; + return TRUE; } else { g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_FAILED, _("Image-loading module %s does not export the proper interface; perhaps it's from a different GTK version?"), path); - retval = FALSE; + return FALSE; } - - g_free (path); - - return retval; } #else -#define mname(type,fn) gdk_pixbuf__ ## type ## _ ##fn -#define m_fill_vtable(type) extern void mname(type,fill_vtable) (GdkPixbufModule *module) - -m_fill_vtable (png); -m_fill_vtable (bmp); -m_fill_vtable (wbmp); -m_fill_vtable (gif); -m_fill_vtable (ico); -m_fill_vtable (ani); -m_fill_vtable (jpeg); -m_fill_vtable (pnm); -m_fill_vtable (ras); -m_fill_vtable (tiff); -m_fill_vtable (xpm); -m_fill_vtable (xbm); -m_fill_vtable (tga); +#define module(type) \ + extern void MODULE_ENTRY (type, fill_info) (GdkPixbufFormat *info); \ + extern void MODULE_ENTRY (type, fill_vtable) (GdkPixbufModule *module) + +module (png); +module (bmp); +module (wbmp); +module (gif); +module (ico); +module (ani); +module (jpeg); +module (pnm); +module (ras); +module (tiff); +module (xpm); +module (xbm); +module (tga); gboolean _gdk_pixbuf_load_module (GdkPixbufModule *image_module, GError **error) { - ModuleFillVtableFunc fill_vtable = NULL; + GdkPixbufModuleFillInfoFunc fill_info = NULL; + GdkPixbufModuleFillVtableFunc fill_vtable = NULL; + image_module->module = (void *) 1; if (FALSE) { @@ -435,85 +428,101 @@ _gdk_pixbuf_load_module (GdkPixbufModule *image_module, } #ifdef INCLUDE_png - else if (strcmp (image_module->module_name, "png") == 0){ - fill_vtable = mname (png, fill_vtable); + else if (strcmp (image_module->module_name, "png") == 0) { + fill_info = MODULE_ENTRY (png, fill_info); + fill_vtable = MODULE_ENTRY (png, fill_vtable); } #endif #ifdef INCLUDE_bmp - else if (strcmp (image_module->module_name, "bmp") == 0){ - fill_vtable = mname (bmp, fill_vtable); + else if (strcmp (image_module->module_name, "bmp") == 0) { + fill_info = MODULE_ENTRY (bmp, fill_info); + fill_vtable = MODULE_ENTRY (bmp, fill_vtable); } #endif #ifdef INCLUDE_wbmp - else if (strcmp (image_module->module_name, "wbmp") == 0){ - fill_vtable = mname (wbmp, fill_vtable); + else if (strcmp (image_module->module_name, "wbmp") == 0) { + fill_info = MODULE_ENTRY (wbmp, fill_info); + fill_vtable = MODULE_ENTRY (wbmp, fill_vtable); } #endif #ifdef INCLUDE_gif - else if (strcmp (image_module->module_name, "gif") == 0){ - fill_vtable = mname (gif, fill_vtable); + else if (strcmp (image_module->module_name, "gif") == 0) { + fill_info = MODULE_ENTRY (gif, fill_info); + fill_vtable = MODULE_ENTRY (gif, fill_vtable); } #endif #ifdef INCLUDE_ico - else if (strcmp (image_module->module_name, "ico") == 0){ - fill_vtable = mname (ico, fill_vtable); + else if (strcmp (image_module->module_name, "ico") == 0) { + fill_info = MODULE_ENTRY (ico, fill_info); + fill_vtable = MODULE_ENTRY (ico, fill_vtable); } #endif #ifdef INCLUDE_ani - else if (strcmp (image_module->module_name, "ani") == 0){ - fill_vtable = mname (ani, fill_vtable); + else if (strcmp (image_module->module_name, "ani") == 0) { + fill_info = MODULE_ENTRY (ani, fill_info); + fill_vtable = MODULE_ENTRY (ani, fill_vtable); } #endif #ifdef INCLUDE_jpeg - else if (strcmp (image_module->module_name, "jpeg") == 0){ - fill_vtable = mname (jpeg, fill_vtable); + else if (strcmp (image_module->module_name, "jpeg") == 0) { + fill_info = MODULE_ENTRY (jpeg, fill_info); + fill_vtable = MODULE_ENTRY (jpeg, fill_vtable); } #endif #ifdef INCLUDE_pnm - else if (strcmp (image_module->module_name, "pnm") == 0){ - fill_vtable = mname (pnm, fill_vtable); + else if (strcmp (image_module->module_name, "pnm") == 0) { + fill_info = MODULE_ENTRY (pnm, fill_info); + fill_vtable = MODULE_ENTRY (pnm, fill_vtable); } #endif #ifdef INCLUDE_ras - else if (strcmp (image_module->module_name, "ras") == 0){ - fill_vtable = mname (ras, fill_vtable); + else if (strcmp (image_module->module_name, "ras") == 0) { + fill_info = MODULE_ENTRY (ras, fill_info); + fill_vtable = MODULE_ENTRY (ras, fill_vtable); } #endif #ifdef INCLUDE_tiff - else if (strcmp (image_module->module_name, "tiff") == 0){ - fill_vtable = mname (tiff, fill_vtable); + else if (strcmp (image_module->module_name, "tiff") == 0) { + fill_info = MODULE_ENTRY (tiff, fill_info); + fill_vtable = MODULE_ENTRY (tiff, fill_vtable); } #endif #ifdef INCLUDE_xpm - else if (strcmp (image_module->module_name, "xpm") == 0){ - fill_vtable = mname (xpm, fill_vtable); + else if (strcmp (image_module->module_name, "xpm") == 0) { + fill_info = MODULE_ENTRY (xpm, fill_info); + fill_vtable = MODULE_ENTRY (xpm, fill_vtable); } #endif #ifdef INCLUDE_xbm - else if (strcmp (image_module->module_name, "xbm") == 0){ - fill_vtable = mname (xbm, fill_vtable); + else if (strcmp (image_module->module_name, "xbm") == 0) { + fill_info = MODULE_ENTRY (xbm, fill_info); + fill_vtable = MODULE_ENTRY (xbm, fill_vtable); } #endif #ifdef INCLUDE_tga - else if (strcmp (image_module->module_name, "tga") == 0){ - fill_vtable = mname (tga, fill_vtable); + else if (strcmp (image_module->module_name, "tga") == 0) { + fill_info = MODULE_ENTRY (tga, fill_info); + fill_vtable = MODULE_ENTRY (tga, fill_vtable); } #endif if (fill_vtable) { (* fill_vtable) (image_module); + image_module->info = g_new0 (GdkPixbufFormat, 1); + (* fill_info) (image_module->info); + return TRUE; } else { g_set_error (error, @@ -526,6 +535,27 @@ _gdk_pixbuf_load_module (GdkPixbufModule *image_module, } } +static void +gdk_pixbuf_io_init () +{ + gchar *included_formats[] = { + "ani", "png", "bmp", "wbmp", "gif", + "ico", "jpeg", "pnm", "ras", "tiff", + "xpm", "xbm", "tga", + NULL + }; + gchar **name; + GdkPixbufModule *module = NULL; + + 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); + } +} #endif @@ -535,11 +565,12 @@ GdkPixbufModule * _gdk_pixbuf_get_named_module (const char *name, GError **error) { - int i; + GSList *modules; - for (i = 0; file_formats [i].module_name; i++) { - if (!strcmp(name, file_formats[i].module_name)) - return &(file_formats[i]); + for (modules = get_file_formats (); modules; modules = g_slist_next (modules)) { + GdkPixbufModule *module = (GdkPixbufModule *)modules->data; + if (!strcmp (name, module->module_name)) + return module; } g_set_error (error, @@ -556,12 +587,22 @@ _gdk_pixbuf_get_module (guchar *buffer, guint size, const gchar *filename, GError **error) { - int i; - - for (i = 0; file_formats [i].module_name; i++) { - if ((* file_formats [i].format_check) (buffer, size)) - return &(file_formats[i]); + GSList *modules; + + gint score, best = 0; + GdkPixbufModule *selected = NULL; + for (modules = get_file_formats (); modules; modules = g_slist_next (modules)) { + GdkPixbufModule *module = (GdkPixbufModule *)modules->data; + score = format_check (module, buffer, size); + if (score > best) { + best = score; + selected = module; + } + if (score >= 100) + break; } + if (selected != NULL) + return selected; if (filename) g_set_error (error, @@ -738,23 +779,24 @@ gdk_pixbuf_new_from_xpm_data (const char **data) GdkPixbuf *(* load_xpm_data) (const char **data); GdkPixbuf *pixbuf; GError *error = NULL; + GdkPixbufModule *xpm_module = _gdk_pixbuf_get_named_module ("xpm", NULL); - if (file_formats[XPM_FILE_FORMAT_INDEX].module == NULL) { - if (!_gdk_pixbuf_load_module (&file_formats[XPM_FILE_FORMAT_INDEX], &error)) { + if (xpm_module->module == NULL) { + if (!_gdk_pixbuf_load_module (xpm_module, &error)) { g_warning ("Error loading XPM image loader: %s", error->message); g_error_free (error); return FALSE; } } - if (file_formats[XPM_FILE_FORMAT_INDEX].module == NULL) { + if (xpm_module->module == NULL) { g_warning ("Can't find gdk-pixbuf module for parsing inline XPM data"); return NULL; - } else if (file_formats[XPM_FILE_FORMAT_INDEX].load_xpm_data == NULL) { + } else if (xpm_module->load_xpm_data == NULL) { g_warning ("gdk-pixbuf XPM module lacks XPM data capability"); return NULL; } else - load_xpm_data = file_formats[XPM_FILE_FORMAT_INDEX].load_xpm_data; + load_xpm_data = xpm_module->load_xpm_data; pixbuf = (* load_xpm_data) (data); return pixbuf; @@ -952,3 +994,130 @@ gdk_pixbuf_savev (GdkPixbuf *pixbuf, return TRUE; } + +/** + * gdk_pixbuf_format_get_name: + * @format: a #GdkPixbufFormat + * + * Returns the name of the format. + * + * Return value: the name of the format. + */ +gchar * +gdk_pixbuf_format_get_name (GdkPixbufFormat *format) +{ + g_return_val_if_fail (format != NULL, NULL); + + return g_strdup (format->name); +} + +/** + * gdk_pixbuf_format_get_description: + * @format: a #GdkPixbufFormat + * + * Returns a description of the format. + * + * Return value: a description of the format. + */ +gchar * +gdk_pixbuf_format_get_description (GdkPixbufFormat *format) +{ + gchar *domain; + gchar *description; + g_return_val_if_fail (format != NULL, NULL); + + if (format->domain != NULL) + domain = format->domain; + else + domain = GETTEXT_PACKAGE; + description = dgettext (domain, format->description); + + return g_strdup (description); +} + +/** + * gdk_pixbuf_format_get_mime_types: + * @format: a #GdkPixbufFormat + * + * Returns the mime types supported by the format. + * + * Return value: a %NULL-terminated array of mime types. + */ +gchar ** +gdk_pixbuf_format_get_mime_types (GdkPixbufFormat *format) +{ + g_return_val_if_fail (format != NULL, NULL); + + return g_strdupv (format->mime_types); +} + +/** + * gdk_pixbuf_format_get_extensions: + * @format: a #GdkPixbufFormat + * + * Returns the filename extensions typically used for files in the given format. + * + * Return value: a %NULL-terminated array of filename extensions. + */ +gchar ** +gdk_pixbuf_format_get_extensions (GdkPixbufFormat *format) +{ + g_return_val_if_fail (format != NULL, NULL); + + return g_strdupv (format->extensions); +} + +/** + * gdk_pixbuf_format_is_writable: + * @format: a #GdkPixbufFormat + * + * Returns whether pixbufs can be saved in the given format. + * + * Return value: whether pixbufs can be saved in the given format. + */ +gboolean +gdk_pixbuf_format_is_writable (GdkPixbufFormat *format) +{ + g_return_val_if_fail (format != NULL, FALSE); + + return (format->flags & GDK_PIXBUF_FORMAT_WRITABLE) != 0; +} + +GdkPixbufFormat * +_gdk_pixbuf_get_format (GdkPixbufModule *module) +{ + g_return_val_if_fail (module != NULL, NULL); + + return module->info; +} + +/** + * gdk_pixbuf_get_formats: + * + * Obtains the available information about the image formats supported + * by GdkPixbuf. + * + * Returns: A list of #GdkPixbufFormat<!-- -->s describing the supported + * image formats. The list should be freed when it is no longer needed, + * but the structures themselves are owned by #GdkPixbuf and should not be + * freed. + */ +GSList * +gdk_pixbuf_get_formats (void) +{ + GSList *result = NULL; + GSList *modules; + + for (modules = get_file_formats (); modules; modules = g_slist_next (modules)) { + GdkPixbufModule *module = (GdkPixbufModule *)modules->data; + GdkPixbufFormat *info = _gdk_pixbuf_get_format (module); + result = g_slist_prepend (result, info); + } + + return result; +} + + + + + diff --git a/gdk-pixbuf/gdk-pixbuf-io.h b/gdk-pixbuf/gdk-pixbuf-io.h index b0db1a248..aeb8e9953 100644 --- a/gdk-pixbuf/gdk-pixbuf-io.h +++ b/gdk-pixbuf/gdk-pixbuf-io.h @@ -1,5 +1,6 @@ -/* GdkPixbuf library - Io handling. This is an internal header for gdk-pixbuf. - * You should never use it unless you are doing developement for gdkpixbuf itself. +/* GdkPixbuf library - Io handling. This is an internal header for + * GdkPixbuf. You should never use it unless you are doing development for + * GdkPixbuf itself. * * Copyright (C) 1999 The Free Software Foundation * @@ -28,43 +29,53 @@ #ifndef GDK_PIXBUF_IO_H #define GDK_PIXBUF_IO_H +#include "gdk-pixbuf/gdk-pixbuf.h" #include <gmodule.h> #include <stdio.h> -#include "gdk-pixbuf.h" -#include "gdk-pixbuf-i18n.h" G_BEGIN_DECLS - +#ifdef GDK_PIXBUF_ENABLE_BACKEND -typedef void (* ModuleSizeFunc) (gint *width, - gint *height, - gpointer user_data); + -typedef void (* ModulePreparedNotifyFunc) (GdkPixbuf *pixbuf, - GdkPixbufAnimation *anim, - gpointer user_data); -typedef void (* ModuleUpdatedNotifyFunc) (GdkPixbuf *pixbuf, - int x, - int y, - int width, - int height, - gpointer user_data); +typedef void (* GdkPixbufModuleSizeFunc) (gint *width, + gint *height, + gpointer user_data); + +typedef void (* GdkPixbufModulePreparedFunc) (GdkPixbuf *pixbuf, + GdkPixbufAnimation *anim, + gpointer user_data); +typedef void (* GdkPixbufModuleUpdatedFunc) (GdkPixbuf *pixbuf, + int x, + int y, + int width, + int height, + gpointer user_data); + +typedef struct _GdkPixbufModulePattern GdkPixbufModulePattern; +struct _GdkPixbufModulePattern { + unsigned char *prefix; + unsigned char *mask; + int relevance; +}; typedef struct _GdkPixbufModule GdkPixbufModule; struct _GdkPixbufModule { char *module_name; - gboolean (* format_check) (guchar *buffer, int size); + char *module_path; GModule *module; + GdkPixbufFormat *info; + GdkPixbuf *(* load) (FILE *f, GError **error); GdkPixbuf *(* load_xpm_data) (const char **data); /* Incremental loading */ - gpointer (* begin_load) (ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepare_func, - ModuleUpdatedNotifyFunc update_func, + gpointer (* begin_load) (GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepare_func, + GdkPixbufModuleUpdatedFunc update_func, gpointer user_data, GError **error); gboolean (* stop_load) (gpointer context, @@ -83,24 +94,44 @@ struct _GdkPixbufModule { gchar **param_keys, gchar **param_values, GError **error); -}; + + void (*_reserved1) (void); + void (*_reserved2) (void); + void (*_reserved3) (void); + void (*_reserved4) (void); + void (*_reserved5) (void); + void (*_reserved6) (void); -typedef void (* ModuleFillVtableFunc) (GdkPixbufModule *module); +}; -GdkPixbufModule *_gdk_pixbuf_get_module (guchar *buffer, guint size, - const gchar *filename, - GError **error); -GdkPixbufModule *_gdk_pixbuf_get_named_module (const char *name, - GError **error); -gboolean _gdk_pixbuf_load_module (GdkPixbufModule *image_module, - GError **error); +typedef void (* GdkPixbufModuleFillVtableFunc) (GdkPixbufModule *module); +typedef void (* GdkPixbufModuleFillInfoFunc) (GdkPixbufFormat *info); +typedef const GdkPixbufModulePattern *(* GdkPixbufModuleGetSignatureFunc) (void); + +/* key/value pairs that can be attached by the pixbuf loader */ + +gboolean gdk_pixbuf_set_option (GdkPixbuf *pixbuf, + const gchar *key, + const gchar *value); + +typedef enum /*< skip >*/ +{ + GDK_PIXBUF_FORMAT_WRITABLE = 1 << 0 +} GdkPixbufFormatFlags; + +struct _GdkPixbufFormat { + gchar *name; + GdkPixbufModulePattern *signature; + gchar *domain; + gchar *description; + gchar **mime_types; + gchar **extensions; + guint32 flags; +}; -GdkPixbuf *_gdk_pixbuf_generic_image_load (GdkPixbufModule *image_module, - FILE *f, - GError **error); - +#endif /* GDK_PIXBUF_ENABLE_BACKEND */ G_END_DECLS -#endif +#endif /* GDK_PIXBUF_IO_H */ diff --git a/gdk-pixbuf/gdk-pixbuf-loader.c b/gdk-pixbuf/gdk-pixbuf-loader.c index bcb7382e3..3f39b8c92 100644 --- a/gdk-pixbuf/gdk-pixbuf-loader.c +++ b/gdk-pixbuf/gdk-pixbuf-loader.c @@ -26,8 +26,9 @@ #include <string.h> #include "gdk-pixbuf-private.h" -#include "gdk-pixbuf-loader.h" +#include "gdk-pixbuf-animation.h" #include "gdk-pixbuf-io.h" +#include "gdk-pixbuf-loader.h" #include "gdk-pixbuf-marshal.h" enum { @@ -645,7 +646,32 @@ gdk_pixbuf_loader_close (GdkPixbufLoader *loader, return retval; } +/** + * gdk_pixbuf_loader_get_format: + * @loader: A pixbuf loader. + * + * Obtains the available information about the format of the + * currently loading image file. + * + * Returns: A #GdkPixbufFormat or %NULL. The return value is owned + * by GdkPixbuf and should not be freed. + */ +GdkPixbufFormat * +gdk_pixbuf_loader_get_format (GdkPixbufLoader *loader) +{ + GdkPixbufLoaderPrivate *priv; + gboolean retval = TRUE; + + g_return_val_if_fail (loader != NULL, NULL); + g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL); + + priv = loader->priv; + if (priv->image_module) + return _gdk_pixbuf_get_format (priv->image_module); + else + return NULL; +} diff --git a/gdk-pixbuf/gdk-pixbuf-loader.h b/gdk-pixbuf/gdk-pixbuf-loader.h index 030d446fa..3b870fc90 100644 --- a/gdk-pixbuf/gdk-pixbuf-loader.h +++ b/gdk-pixbuf/gdk-pixbuf-loader.h @@ -81,7 +81,7 @@ GdkPixbuf * gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader); GdkPixbufAnimation * gdk_pixbuf_loader_get_animation (GdkPixbufLoader *loader); gboolean gdk_pixbuf_loader_close (GdkPixbufLoader *loader, GError **error); - +GdkPixbufFormat *gdk_pixbuf_loader_get_format (GdkPixbufLoader *loader); G_END_DECLS diff --git a/gdk-pixbuf/gdk-pixbuf-private.h b/gdk-pixbuf/gdk-pixbuf-private.h index db13af805..e81478f99 100644 --- a/gdk-pixbuf/gdk-pixbuf-private.h +++ b/gdk-pixbuf/gdk-pixbuf-private.h @@ -28,6 +28,9 @@ #define GDK_PIXBUF_PRIVATE_H #include "gdk-pixbuf.h" +#include "gdk-pixbuf-io.h" +#include "gdk-pixbuf-i18n.h" +#include <stdio.h> @@ -74,70 +77,30 @@ struct _GdkPixbufClass { }; -typedef struct _GdkPixbufAnimationClass GdkPixbufAnimationClass; +#ifdef GDK_PIXBUF_ENABLE_BACKEND -#define GDK_PIXBUF_ANIMATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_ANIMATION, GdkPixbufAnimationClass)) -#define GDK_IS_PIXBUF_ANIMATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_ANIMATION)) -#define GDK_PIXBUF_ANIMATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_ANIMATION, GdkPixbufAnimationClass)) +GdkPixbufModule *_gdk_pixbuf_get_module (guchar *buffer, guint size, + const gchar *filename, + GError **error); +GdkPixbufModule *_gdk_pixbuf_get_named_module (const char *name, + GError **error); +gboolean _gdk_pixbuf_load_module (GdkPixbufModule *image_module, + GError **error); -/* Private part of the GdkPixbufAnimation structure */ -struct _GdkPixbufAnimation { - GObject parent_instance; - -}; - -struct _GdkPixbufAnimationClass { - GObjectClass parent_class; - - gboolean (*is_static_image) (GdkPixbufAnimation *anim); - - GdkPixbuf* (*get_static_image) (GdkPixbufAnimation *anim); - - void (*get_size) (GdkPixbufAnimation *anim, - int *width, - int *height); - - GdkPixbufAnimationIter* (*get_iter) (GdkPixbufAnimation *anim, - const GTimeVal *start_time); +GdkPixbuf *_gdk_pixbuf_generic_image_load (GdkPixbufModule *image_module, + FILE *f, + GError **error); -}; - - - -typedef struct _GdkPixbufAnimationIterClass GdkPixbufAnimationIterClass; - -#define GDK_PIXBUF_ANIMATION_ITER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_ANIMATION_ITER, GdkPixbufAnimationIterClass)) -#define GDK_IS_PIXBUF_ANIMATION_ITER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_ANIMATION_ITER)) -#define GDK_PIXBUF_ANIMATION_ITER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_ANIMATION_ITER, GdkPixbufAnimationIterClass)) - -struct _GdkPixbufAnimationIter { - GObject parent_instance; +GdkPixbufFormat *_gdk_pixbuf_get_format (GdkPixbufModule *image_module); -}; - -struct _GdkPixbufAnimationIterClass { - GObjectClass parent_class; - - int (*get_delay_time) (GdkPixbufAnimationIter *iter); - - GdkPixbuf* (*get_pixbuf) (GdkPixbufAnimationIter *iter); - - gboolean (*on_currently_loading_frame) (GdkPixbufAnimationIter *iter); - - gboolean (*advance) (GdkPixbufAnimationIter *iter, - const GTimeVal *current_time); -}; - - -GdkPixbufAnimation* gdk_pixbuf_non_anim_new (GdkPixbuf *pixbuf); - - +#ifdef USE_GMODULE +#define MODULE_ENTRY(type,function) function +#else +#define MODULE_ENTRY(type,function) _gdk_pixbuf__ ## type ## _ ## function +#endif -/* key/value pairs that can be attached by the pixbuf loader */ +#endif /* GDK_PIXBUF_ENABLE_BACKEND */ -gboolean gdk_pixbuf_set_option (GdkPixbuf *pixbuf, - const gchar *key, - const gchar *value); +#endif /* GDK_PIXBUF_PRIVATE_H */ -#endif diff --git a/gdk-pixbuf/gdk-pixbuf.h b/gdk-pixbuf/gdk-pixbuf.h index 153eea8a8..ebace7274 100644 --- a/gdk-pixbuf/gdk-pixbuf.h +++ b/gdk-pixbuf/gdk-pixbuf.h @@ -287,7 +287,16 @@ G_CONST_RETURN gchar * gdk_pixbuf_get_option (GdkPixbuf *pixbuf, const gchar *key); + +typedef struct _GdkPixbufFormat GdkPixbufFormat; +GSList *gdk_pixbuf_get_formats (void); +gchar *gdk_pixbuf_format_get_name (GdkPixbufFormat *format); +gchar *gdk_pixbuf_format_get_description (GdkPixbufFormat *format); +gchar **gdk_pixbuf_format_get_mime_types (GdkPixbufFormat *format); +gchar **gdk_pixbuf_format_get_extensions (GdkPixbufFormat *format); +gboolean gdk_pixbuf_format_is_writable (GdkPixbufFormat *format); + G_END_DECLS #include <gdk-pixbuf/gdk-pixbuf-loader.h> diff --git a/gdk-pixbuf/gdk-pixdata.c b/gdk-pixbuf/gdk-pixdata.c index 4a5735f76..c65596c19 100644 --- a/gdk-pixbuf/gdk-pixdata.c +++ b/gdk-pixbuf/gdk-pixdata.c @@ -19,7 +19,6 @@ #include "gdk-pixdata.h" #include "gdk-pixbuf-private.h" -#include "gdk-pixbuf-i18n.h" #include <string.h> #define APPEND g_string_append_printf diff --git a/gdk-pixbuf/io-ani-animation.h b/gdk-pixbuf/io-ani-animation.h index 4fc86b3f2..88629abf1 100644 --- a/gdk-pixbuf/io-ani-animation.h +++ b/gdk-pixbuf/io-ani-animation.h @@ -25,6 +25,7 @@ #define GDK_PIXBUF_ANI_ANIMATION_H #include "gdk-pixbuf-private.h" +#include "gdk-pixbuf-animation.h" typedef struct _GdkPixbufAniAnim GdkPixbufAniAnim; typedef struct _GdkPixbufAniAnimClass GdkPixbufAniAnimClass; diff --git a/gdk-pixbuf/io-ani.c b/gdk-pixbuf/io-ani.c index cc4790137..f7565b533 100644 --- a/gdk-pixbuf/io-ani.c +++ b/gdk-pixbuf/io-ani.c @@ -60,8 +60,8 @@ typedef struct _AniLoaderContext guint n_bytes; guint buffer_size; - ModulePreparedNotifyFunc prepared_func; - ModuleUpdatedNotifyFunc updated_func; + GdkPixbufModulePreparedFunc prepared_func; + GdkPixbufModuleUpdatedFunc updated_func; gpointer user_data; guint32 data_size; @@ -556,9 +556,9 @@ gdk_pixbuf__ani_image_load_increment (gpointer data, } static gpointer -gdk_pixbuf__ani_image_begin_load (ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepared_func, - ModuleUpdatedNotifyFunc updated_func, +gdk_pixbuf__ani_image_begin_load (GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error) { @@ -647,10 +647,38 @@ gdk_pixbuf__ani_image_load_animation (FILE *f, GError **error) } void -gdk_pixbuf__ani_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (ani, fill_vtable) (GdkPixbufModule *module) { module->load_animation = gdk_pixbuf__ani_image_load_animation; module->begin_load = gdk_pixbuf__ani_image_begin_load; module->stop_load = gdk_pixbuf__ani_image_stop_load; module->load_increment = gdk_pixbuf__ani_image_load_increment; } + +void +MODULE_ENTRY (ani, fill_info) (GdkPixbufFormat *info) +{ + static GdkPixbufModulePattern signature[] = { + { "RIFF ACON", " xxxx ", 100 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "application/x-navi-animation", + NULL + }; + static gchar * extensions[] = { + "ani", + NULL + }; + + info->name = "ani"; + info->signature = signature; + info->description = N_("The ANI image format"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = 0; +} + + + + diff --git a/gdk-pixbuf/io-bmp.c b/gdk-pixbuf/io-bmp.c index eece1dbd8..f7f50df15 100644 --- a/gdk-pixbuf/io-bmp.c +++ b/gdk-pixbuf/io-bmp.c @@ -1,3 +1,4 @@ +/* -*- mode: C; c-file-style: "linux" -*- */ /* GdkPixbuf library - Windows Bitmap image loader * * Copyright (C) 1999 The Free Software Foundation @@ -143,8 +144,8 @@ struct bmp_compression_state { /* Progressive loading */ struct bmp_progressive_state { - ModulePreparedNotifyFunc prepared_func; - ModuleUpdatedNotifyFunc updated_func; + GdkPixbufModulePreparedFunc prepared_func; + GdkPixbufModuleUpdatedFunc updated_func; gpointer user_data; ReadState read_state; @@ -181,9 +182,9 @@ struct bmp_progressive_state { }; static gpointer -gdk_pixbuf__bmp_image_begin_load(ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepared_func, - ModuleUpdatedNotifyFunc updated_func, +gdk_pixbuf__bmp_image_begin_load(GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error); @@ -475,9 +476,9 @@ decode_bitmasks (guchar *buf, */ static gpointer -gdk_pixbuf__bmp_image_begin_load(ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepared_func, - ModuleUpdatedNotifyFunc updated_func, +gdk_pixbuf__bmp_image_begin_load(GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error) { @@ -1045,9 +1046,36 @@ gdk_pixbuf__bmp_image_load_increment(gpointer data, } void -gdk_pixbuf__bmp_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (bmp, fill_vtable) (GdkPixbufModule *module) { - module->begin_load = gdk_pixbuf__bmp_image_begin_load; - module->stop_load = gdk_pixbuf__bmp_image_stop_load; - module->load_increment = gdk_pixbuf__bmp_image_load_increment; + module->begin_load = gdk_pixbuf__bmp_image_begin_load; + module->stop_load = gdk_pixbuf__bmp_image_stop_load; + module->load_increment = gdk_pixbuf__bmp_image_load_increment; } + +void +MODULE_ENTRY (bmp, fill_info) (GdkPixbufFormat *info) +{ + static GdkPixbufModulePattern signature[] = { + { "BM", NULL, 100 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "image/bmp", + "image/x-bmp", + "image/x-MS-bmp", + NULL + }; + static gchar * extensions[] = { + "bmp", + NULL + }; + + info->name = "bmp"; + info->signature = signature; + info->description = N_("The BMP image format"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = 0; +} + diff --git a/gdk-pixbuf/io-gif-animation.c b/gdk-pixbuf/io-gif-animation.c index 0a3ce6b70..b797f0481 100644 --- a/gdk-pixbuf/io-gif-animation.c +++ b/gdk-pixbuf/io-gif-animation.c @@ -24,7 +24,6 @@ #include <config.h> #include <errno.h> -#include "gdk-pixbuf-io.h" #include "gdk-pixbuf-private.h" #include "io-gif-animation.h" diff --git a/gdk-pixbuf/io-gif-animation.h b/gdk-pixbuf/io-gif-animation.h index f53ae05e1..0d6111438 100644 --- a/gdk-pixbuf/io-gif-animation.h +++ b/gdk-pixbuf/io-gif-animation.h @@ -27,7 +27,7 @@ #ifndef GDK_PIXBUF_GIF_H #define GDK_PIXBUF_GIF_H -#include "gdk-pixbuf-private.h" +#include "gdk-pixbuf-animation.h" typedef enum { /* Keep this frame and composite next frame over it */ diff --git a/gdk-pixbuf/io-gif.c b/gdk-pixbuf/io-gif.c index b85e2ea95..b91e78af2 100644 --- a/gdk-pixbuf/io-gif.c +++ b/gdk-pixbuf/io-gif.c @@ -138,8 +138,8 @@ struct _GifContext FILE *file; /* progressive read, only. */ - ModulePreparedNotifyFunc prepare_func; - ModuleUpdatedNotifyFunc update_func; + GdkPixbufModulePreparedFunc prepare_func; + GdkPixbufModuleUpdatedFunc update_func; gpointer user_data; guchar *buf; guint ptr; @@ -1396,9 +1396,9 @@ gdk_pixbuf__gif_image_load (FILE *file, GError **error) } static gpointer -gdk_pixbuf__gif_image_begin_load (ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepare_func, - ModuleUpdatedNotifyFunc update_func, +gdk_pixbuf__gif_image_begin_load (GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepare_func, + GdkPixbufModuleUpdatedFunc update_func, gpointer user_data, GError **error) { @@ -1560,11 +1560,35 @@ gdk_pixbuf__gif_image_load_animation (FILE *file, } void -gdk_pixbuf__gif_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (gif, fill_vtable) (GdkPixbufModule *module) { - module->load = gdk_pixbuf__gif_image_load; - module->begin_load = gdk_pixbuf__gif_image_begin_load; - module->stop_load = gdk_pixbuf__gif_image_stop_load; - module->load_increment = gdk_pixbuf__gif_image_load_increment; - module->load_animation = gdk_pixbuf__gif_image_load_animation; + module->load = gdk_pixbuf__gif_image_load; + module->begin_load = gdk_pixbuf__gif_image_begin_load; + module->stop_load = gdk_pixbuf__gif_image_stop_load; + module->load_increment = gdk_pixbuf__gif_image_load_increment; + module->load_animation = gdk_pixbuf__gif_image_load_animation; +} + +void +MODULE_ENTRY (gif, fill_info) (GdkPixbufFormat *info) +{ + static GdkPixbufModulePattern signature[] = { + { "GIF8", NULL, 100 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "image/gif", + NULL + }; + static gchar * extensions[] = { + "gif", + NULL + }; + + info->name = "gif"; + info->signature = signature; + info->description = N_("The GIF image format"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = 0; } diff --git a/gdk-pixbuf/io-ico.c b/gdk-pixbuf/io-ico.c index d54e4103e..ff2abe4df 100644 --- a/gdk-pixbuf/io-ico.c +++ b/gdk-pixbuf/io-ico.c @@ -1,3 +1,4 @@ +/* -*- mode: C; c-file-style: "linux" -*- */ /* GdkPixbuf library - Windows Icon/Cursor image loader * * Copyright (C) 1999 The Free Software Foundation @@ -23,7 +24,7 @@ * Boston, MA 02111-1307, USA. */ -#undef DUMPBIH +#define DUMPBIH /* Icons are just like BMP's, except for the header. @@ -124,8 +125,8 @@ struct headerpair { }; struct ico_progressive_state { - ModulePreparedNotifyFunc prepared_func; - ModuleUpdatedNotifyFunc updated_func; + GdkPixbufModulePreparedFunc prepared_func; + GdkPixbufModuleUpdatedFunc updated_func; gpointer user_data; gint HeaderSize; /* The size of the header-part (incl colormap) */ @@ -160,9 +161,9 @@ struct ico_progressive_state { }; static gpointer -gdk_pixbuf__ico_image_begin_load(ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepared_func, - ModuleUpdatedNotifyFunc updated_func, +gdk_pixbuf__ico_image_begin_load(GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error); static gboolean gdk_pixbuf__ico_image_stop_load(gpointer data, GError **error); @@ -442,9 +443,9 @@ static void DecodeHeader(guchar *Data, gint Bytes, */ static gpointer -gdk_pixbuf__ico_image_begin_load(ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepared_func, - ModuleUpdatedNotifyFunc updated_func, +gdk_pixbuf__ico_image_begin_load(GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error) { @@ -840,9 +841,39 @@ gdk_pixbuf__ico_image_load_increment(gpointer data, } void -gdk_pixbuf__ico_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (ico, fill_vtable) (GdkPixbufModule *module) { - module->begin_load = gdk_pixbuf__ico_image_begin_load; - module->stop_load = gdk_pixbuf__ico_image_stop_load; - module->load_increment = gdk_pixbuf__ico_image_load_increment; + module->begin_load = gdk_pixbuf__ico_image_begin_load; + module->stop_load = gdk_pixbuf__ico_image_stop_load; + module->load_increment = gdk_pixbuf__ico_image_load_increment; } + +void +MODULE_ENTRY (ico, fill_info) (GdkPixbufFormat *info) +{ + static GdkPixbufModulePattern signature[] = { + { " \x1 ", "zz znz", 100 }, + { " \x2 ", "zz znz", 100 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "image/x-icon", + NULL + }; + static gchar * extensions[] = { + "ico", + "cur", + NULL + }; + + info->name = "ico"; + info->signature = signature; + info->description = N_("The ICO image format"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = 0; +} + + + + diff --git a/gdk-pixbuf/io-jpeg.c b/gdk-pixbuf/io-jpeg.c index 365194764..bf0fb0556 100644 --- a/gdk-pixbuf/io-jpeg.c +++ b/gdk-pixbuf/io-jpeg.c @@ -65,10 +65,10 @@ struct error_handler_data { /* progressive loader context */ typedef struct { - ModuleSizeFunc size_func; - ModuleUpdatedNotifyFunc updated_func; - ModulePreparedNotifyFunc prepared_func; - gpointer user_data; + GdkPixbufModuleSizeFunc size_func; + GdkPixbufModuleUpdatedFunc updated_func; + GdkPixbufModulePreparedFunc prepared_func; + gpointer user_data; GdkPixbuf *pixbuf; guchar *dptr; /* current position in pixbuf */ @@ -82,9 +82,9 @@ typedef struct { } JpegProgContext; static GdkPixbuf *gdk_pixbuf__jpeg_image_load (FILE *f, GError **error); -static gpointer gdk_pixbuf__jpeg_image_begin_load (ModuleSizeFunc func0, - ModulePreparedNotifyFunc func1, - ModuleUpdatedNotifyFunc func2, +static gpointer gdk_pixbuf__jpeg_image_begin_load (GdkPixbufModuleSizeFunc func0, + GdkPixbufModulePreparedFunc func1, + GdkPixbufModuleUpdatedFunc func2, gpointer user_data, GError **error); static gboolean gdk_pixbuf__jpeg_image_stop_load (gpointer context, GError **error); @@ -450,9 +450,9 @@ skip_input_data (j_decompress_ptr cinfo, long num_bytes) */ gpointer -gdk_pixbuf__jpeg_image_begin_load (ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepared_func, - ModuleUpdatedNotifyFunc updated_func, +gdk_pixbuf__jpeg_image_begin_load (GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error) { @@ -908,11 +908,37 @@ gdk_pixbuf__jpeg_image_save (FILE *f, } void -gdk_pixbuf__jpeg_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (jpeg, fill_vtable) (GdkPixbufModule *module) { - module->load = gdk_pixbuf__jpeg_image_load; - module->begin_load = gdk_pixbuf__jpeg_image_begin_load; - module->stop_load = gdk_pixbuf__jpeg_image_stop_load; - module->load_increment = gdk_pixbuf__jpeg_image_load_increment; - module->save = gdk_pixbuf__jpeg_image_save; + module->load = gdk_pixbuf__jpeg_image_load; + module->begin_load = gdk_pixbuf__jpeg_image_begin_load; + module->stop_load = gdk_pixbuf__jpeg_image_stop_load; + module->load_increment = gdk_pixbuf__jpeg_image_load_increment; + module->save = gdk_pixbuf__jpeg_image_save; +} + +void +MODULE_ENTRY (jpeg, fill_info) (GdkPixbufFormat *info) +{ + static GdkPixbufModulePattern signature[] = { + { "\xff\xd8", NULL, 100 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "image/jpeg", + NULL + }; + static gchar * extensions[] = { + "jpeg", + "jpe", + "jpg", + NULL + }; + + info->name = "jpeg"; + info->signature = signature; + info->description = N_("The JPEG image format"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = GDK_PIXBUF_FORMAT_WRITABLE; } diff --git a/gdk-pixbuf/io-png.c b/gdk-pixbuf/io-png.c index 3b2317efd..5ddca7510 100644 --- a/gdk-pixbuf/io-png.c +++ b/gdk-pixbuf/io-png.c @@ -358,8 +358,8 @@ struct _LoadContext { png_structp png_read_ptr; png_infop png_info_ptr; - ModulePreparedNotifyFunc prepare_func; - ModuleUpdatedNotifyFunc update_func; + GdkPixbufModulePreparedFunc prepare_func; + GdkPixbufModuleUpdatedFunc update_func; gpointer notify_user_data; GdkPixbuf* pixbuf; @@ -386,9 +386,9 @@ struct _LoadContext { }; static gpointer -gdk_pixbuf__png_image_begin_load (ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepare_func, - ModuleUpdatedNotifyFunc update_func, +gdk_pixbuf__png_image_begin_load (GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepare_func, + GdkPixbufModuleUpdatedFunc update_func, gpointer user_data, GError **error) { @@ -888,14 +888,36 @@ cleanup: return success; } - +void +MODULE_ENTRY (png, fill_vtable) (GdkPixbufModule *module) +{ + module->load = gdk_pixbuf__png_image_load; + module->begin_load = gdk_pixbuf__png_image_begin_load; + module->stop_load = gdk_pixbuf__png_image_stop_load; + module->load_increment = gdk_pixbuf__png_image_load_increment; + module->save = gdk_pixbuf__png_image_save; +} void -gdk_pixbuf__png_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (png, fill_info) (GdkPixbufFormat *info) { - module->load = gdk_pixbuf__png_image_load; - module->begin_load = gdk_pixbuf__png_image_begin_load; - module->stop_load = gdk_pixbuf__png_image_stop_load; - module->load_increment = gdk_pixbuf__png_image_load_increment; - module->save = gdk_pixbuf__png_image_save; + static GdkPixbufModulePattern signature[] = { + { "\x89PNG\r\n\x1a\x0a", NULL, 100 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "image/png", + NULL + }; + static gchar * extensions[] = { + "png", + NULL + }; + + info->name = "png"; + info->signature = signature; + info->description = N_("The PNG image format"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = GDK_PIXBUF_FORMAT_WRITABLE; } diff --git a/gdk-pixbuf/io-pnm.c b/gdk-pixbuf/io-pnm.c index c13719146..1fc1fe7c0 100644 --- a/gdk-pixbuf/io-pnm.c +++ b/gdk-pixbuf/io-pnm.c @@ -53,8 +53,8 @@ typedef struct { } PnmIOBuffer; typedef struct { - ModuleUpdatedNotifyFunc updated_func; - ModulePreparedNotifyFunc prepared_func; + GdkPixbufModuleUpdatedFunc updated_func; + GdkPixbufModulePreparedFunc prepared_func; gpointer user_data; GdkPixbuf *pixbuf; @@ -81,9 +81,9 @@ typedef struct { } PnmLoaderContext; static GdkPixbuf *gdk_pixbuf__pnm_image_load (FILE *f, GError **error); -static gpointer gdk_pixbuf__pnm_image_begin_load (ModuleSizeFunc size_func, - ModulePreparedNotifyFunc func, - ModuleUpdatedNotifyFunc func2, +static gpointer gdk_pixbuf__pnm_image_begin_load (GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc func, + GdkPixbufModuleUpdatedFunc func2, gpointer user_data, GError **error); static gboolean gdk_pixbuf__pnm_image_stop_load (gpointer context, GError **error); @@ -804,9 +804,9 @@ gdk_pixbuf__pnm_image_load (FILE *f, GError **error) */ static gpointer -gdk_pixbuf__pnm_image_begin_load (ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepared_func, - ModuleUpdatedNotifyFunc updated_func, +gdk_pixbuf__pnm_image_begin_load (GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error) { @@ -1030,10 +1030,45 @@ gdk_pixbuf__pnm_image_load_increment (gpointer data, } void -gdk_pixbuf__pnm_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (pnm, fill_vtable) (GdkPixbufModule *module) { - module->load = gdk_pixbuf__pnm_image_load; - module->begin_load = gdk_pixbuf__pnm_image_begin_load; - module->stop_load = gdk_pixbuf__pnm_image_stop_load; - module->load_increment = gdk_pixbuf__pnm_image_load_increment; + module->load = gdk_pixbuf__pnm_image_load; + module->begin_load = gdk_pixbuf__pnm_image_begin_load; + module->stop_load = gdk_pixbuf__pnm_image_stop_load; + module->load_increment = gdk_pixbuf__pnm_image_load_increment; +} + +void +MODULE_ENTRY (pnm, fill_info) (GdkPixbufFormat *info) +{ + static GdkPixbufModulePattern signature[] = { + { "P1", NULL, 100 }, + { "P2", NULL, 100 }, + { "P3", NULL, 100 }, + { "P4", NULL, 100 }, + { "P5", NULL, 100 }, + { "P6", NULL, 100 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "image/x-portable-anymap", + "image/x-portable-bitmap", + "image/x-portable-graymap", + "image/x-portable-pixmap", + NULL + }; + static gchar * extensions[] = { + "pnm", + "pbm", + "pgm", + "ppm", + NULL + }; + + info->name = "pnm"; + info->signature = signature; + info->description = N_("The PNM/PBM/PGM/PPM image format family"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = 0; } diff --git a/gdk-pixbuf/io-ras.c b/gdk-pixbuf/io-ras.c index 13e05f217..fba4b9900 100644 --- a/gdk-pixbuf/io-ras.c +++ b/gdk-pixbuf/io-ras.c @@ -1,3 +1,4 @@ +/* -*- mode: C; c-file-style: "linux" -*- */ /* GdkPixbuf library - SUNRAS image loader * * Copyright (C) 1999 The Free Software Foundation @@ -67,8 +68,8 @@ struct rasterfile { /* Progressive loading */ struct ras_progressive_state { - ModulePreparedNotifyFunc prepared_func; - ModuleUpdatedNotifyFunc updated_func; + GdkPixbufModulePreparedFunc prepared_func; + GdkPixbufModuleUpdatedFunc updated_func; gpointer user_data; gint HeaderSize; /* The size of the header-part (incl colormap) */ @@ -94,9 +95,9 @@ struct ras_progressive_state { }; static gpointer -gdk_pixbuf__ras_image_begin_load(ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepared_func, - ModuleUpdatedNotifyFunc updated_func, +gdk_pixbuf__ras_image_begin_load(GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error); static gboolean gdk_pixbuf__ras_image_stop_load(gpointer data, GError **error); @@ -217,9 +218,9 @@ static gboolean RAS2State(struct rasterfile *RAS, */ static gpointer -gdk_pixbuf__ras_image_begin_load(ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepared_func, - ModuleUpdatedNotifyFunc updated_func, +gdk_pixbuf__ras_image_begin_load(GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error) { @@ -502,10 +503,35 @@ gdk_pixbuf__ras_image_load_increment(gpointer data, } void -gdk_pixbuf__ras_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (ras, fill_vtable) (GdkPixbufModule *module) { - module->begin_load = gdk_pixbuf__ras_image_begin_load; - module->stop_load = gdk_pixbuf__ras_image_stop_load; - module->load_increment = gdk_pixbuf__ras_image_load_increment; + module->begin_load = gdk_pixbuf__ras_image_begin_load; + module->stop_load = gdk_pixbuf__ras_image_stop_load; + module->load_increment = gdk_pixbuf__ras_image_load_increment; +} + +void +MODULE_ENTRY (ras, fill_info) (GdkPixbufFormat *info) +{ + static GdkPixbufModulePattern signature[] = { + { "\x59\xa6\x6a\x95", NULL, 100 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "image/x-cmu-raster", + "image/x-sun-raster", + NULL + }; + static gchar * extensions[] = { + "ras", + NULL + }; + + info->name = "ras"; + info->signature = signature; + info->description = N_("The Sun raster image format"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = 0; } diff --git a/gdk-pixbuf/io-tga.c b/gdk-pixbuf/io-tga.c index ff453e528..7035faf9c 100644 --- a/gdk-pixbuf/io-tga.c +++ b/gdk-pixbuf/io-tga.c @@ -1,3 +1,4 @@ +/* -*- mode: C; c-file-style: "linux" -*- */ /* * GdkPixbuf library - TGA image loader * Copyright (C) 1999 Nicola Girardi <nikke@swlibero.org> @@ -38,9 +39,8 @@ #include <stdio.h> #include <string.h> -#include "gdk-pixbuf.h" -#include "gdk-pixbuf-io.h" #include "gdk-pixbuf-private.h" +#include "gdk-pixbuf-io.h" #undef DEBUG_TGA @@ -139,8 +139,8 @@ struct _TGAContext { gboolean prepared; gboolean done; - ModulePreparedNotifyFunc pfunc; - ModuleUpdatedNotifyFunc ufunc; + GdkPixbufModulePreparedFunc pfunc; + GdkPixbufModuleUpdatedFunc ufunc; gpointer udata; }; @@ -802,9 +802,9 @@ static gboolean try_preload(TGAContext *ctx, GError **err) return TRUE; } -static gpointer gdk_pixbuf__tga_begin_load(ModuleSizeFunc f0, - ModulePreparedNotifyFunc f1, - ModuleUpdatedNotifyFunc f2, +static gpointer gdk_pixbuf__tga_begin_load(GdkPixbufModuleSizeFunc f0, + GdkPixbufModulePreparedFunc f1, + GdkPixbufModuleUpdatedFunc f2, gpointer udata, GError **err) { TGAContext *ctx; @@ -1335,10 +1335,40 @@ static GdkPixbuf *gdk_pixbuf__tga_load(FILE *f, GError **err) } void -gdk_pixbuf__tga_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (tga, fill_vtable) (GdkPixbufModule *module) { module->load = gdk_pixbuf__tga_load; module->begin_load = gdk_pixbuf__tga_begin_load; module->stop_load = gdk_pixbuf__tga_stop_load; module->load_increment = gdk_pixbuf__tga_load_increment; } + +void +MODULE_ENTRY (tga, fill_info) (GdkPixbufFormat *info) +{ + static GdkPixbufModulePattern signature[] = { + { " \x1\x1", "x ", 100 }, + { " \x1\x9", "x ", 100 }, + { " \x2", "xz ", 99 }, /* only 99 since .CUR also matches this */ + { " \x3", "xz ", 100 }, + { " \xa", "xz ", 100 }, + { " \xb", "xz ", 100 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "image/x-tga", + NULL + }; + static gchar * extensions[] = { + "tga", + "targa", + NULL + }; + + info->name = "tga"; + info->signature = signature; + info->description = N_("The Targa image format"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = 0; +} diff --git a/gdk-pixbuf/io-tiff.c b/gdk-pixbuf/io-tiff.c index d37614764..a91255b0a 100644 --- a/gdk-pixbuf/io-tiff.c +++ b/gdk-pixbuf/io-tiff.c @@ -47,8 +47,8 @@ typedef struct _TiffContext TiffContext; struct _TiffContext { - ModulePreparedNotifyFunc prepare_func; - ModuleUpdatedNotifyFunc update_func; + GdkPixbufModulePreparedFunc prepare_func; + GdkPixbufModuleUpdatedFunc update_func; gpointer user_data; guchar *buffer; @@ -361,9 +361,9 @@ gdk_pixbuf__tiff_image_load (FILE *f, GError **error) /* Progressive loader */ static gpointer -gdk_pixbuf__tiff_image_begin_load (ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepare_func, - ModuleUpdatedNotifyFunc update_func, +gdk_pixbuf__tiff_image_begin_load (GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepare_func, + GdkPixbufModuleUpdatedFunc update_func, gpointer user_data, GError **error) { @@ -560,10 +560,36 @@ gdk_pixbuf__tiff_image_load_increment (gpointer data, const guchar *buf, } void -gdk_pixbuf__tiff_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (tiff, fill_vtable) (GdkPixbufModule *module) { module->load = gdk_pixbuf__tiff_image_load; module->begin_load = gdk_pixbuf__tiff_image_begin_load; module->stop_load = gdk_pixbuf__tiff_image_stop_load; module->load_increment = gdk_pixbuf__tiff_image_load_increment; } + +void +MODULE_ENTRY (tiff, fill_info) (GdkPixbufFormat *info) +{ + static GdkPixbufModulePattern signature[] = { + { "MM \x2a", " z ", 100 }, + { "II\x2a ", " z", 100 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "image/tiff", + NULL + }; + static gchar * extensions[] = { + "tiff", + "tif", + NULL + }; + + info->name = "tiff"; + info->signature = signature; + info->description = N_("The TIFF image format"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = 0; +} diff --git a/gdk-pixbuf/io-wbmp.c b/gdk-pixbuf/io-wbmp.c index 78cc24be7..fb1e6d04a 100644 --- a/gdk-pixbuf/io-wbmp.c +++ b/gdk-pixbuf/io-wbmp.c @@ -1,3 +1,4 @@ +/* -*- mode: C; c-file-style: "linux" -*- */ /* GdkPixbuf library - Wireless Bitmap image loader * * Copyright (C) 2000 Red Hat, Inc. @@ -42,8 +43,8 @@ Known bugs: /* Progressive loading */ struct wbmp_progressive_state { - ModulePreparedNotifyFunc prepared_func; - ModuleUpdatedNotifyFunc updated_func; + GdkPixbufModulePreparedFunc prepared_func; + GdkPixbufModuleUpdatedFunc updated_func; gpointer user_data; gboolean need_type : 1; @@ -63,9 +64,9 @@ struct wbmp_progressive_state { }; static gpointer -gdk_pixbuf__wbmp_image_begin_load(ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepared_func, - ModuleUpdatedNotifyFunc updated_func, +gdk_pixbuf__wbmp_image_begin_load(GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error); @@ -82,9 +83,9 @@ static gboolean gdk_pixbuf__wbmp_image_load_increment(gpointer data, */ static gpointer -gdk_pixbuf__wbmp_image_begin_load(ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepared_func, - ModuleUpdatedNotifyFunc updated_func, +gdk_pixbuf__wbmp_image_begin_load(GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error) { @@ -339,9 +340,33 @@ static gboolean gdk_pixbuf__wbmp_image_load_increment(gpointer data, } void -gdk_pixbuf__wbmp_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (wbmp, fill_vtable) (GdkPixbufModule *module) { - module->begin_load = gdk_pixbuf__wbmp_image_begin_load; - module->stop_load = gdk_pixbuf__wbmp_image_stop_load; - module->load_increment = gdk_pixbuf__wbmp_image_load_increment; + module->begin_load = gdk_pixbuf__wbmp_image_begin_load; + module->stop_load = gdk_pixbuf__wbmp_image_stop_load; + module->load_increment = gdk_pixbuf__wbmp_image_load_increment; +} + +void +MODULE_ENTRY (wbmp, fill_info) (GdkPixbufFormat *info) +{ + static GdkPixbufModulePattern signature[] = { + { " ", "z", 1 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "image/vnd.wap.wbmp", + NULL + }; + static gchar * extensions[] = { + "wbmp", + NULL + }; + + info->name = "wbmp"; + info->signature = signature; + info->description = N_("The WBMP image format"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = 0; } diff --git a/gdk-pixbuf/io-xbm.c b/gdk-pixbuf/io-xbm.c index 0ec63755b..1a510183a 100644 --- a/gdk-pixbuf/io-xbm.c +++ b/gdk-pixbuf/io-xbm.c @@ -1,3 +1,4 @@ +/* -*- mode: C; c-file-style: "linux" -*- */ /* GdkPixbuf library - XBM image loader * * Copyright (C) 1999 Mark Crichton @@ -42,8 +43,8 @@ typedef struct _XBMData XBMData; struct _XBMData { - ModulePreparedNotifyFunc prepare_func; - ModuleUpdatedNotifyFunc update_func; + GdkPixbufModulePreparedFunc prepare_func; + GdkPixbufModuleUpdatedFunc update_func; gpointer user_data; gchar *tempname; @@ -361,9 +362,9 @@ gdk_pixbuf__xbm_image_load (FILE *f, GError **error) */ static gpointer -gdk_pixbuf__xbm_image_begin_load (ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepare_func, - ModuleUpdatedNotifyFunc update_func, +gdk_pixbuf__xbm_image_begin_load (GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepare_func, + GdkPixbufModuleUpdatedFunc update_func, gpointer user_data, GError **error) { @@ -443,10 +444,35 @@ gdk_pixbuf__xbm_image_load_increment (gpointer data, } void -gdk_pixbuf__xbm_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (xbm, fill_vtable) (GdkPixbufModule *module) { - module->load = gdk_pixbuf__xbm_image_load; - module->begin_load = gdk_pixbuf__xbm_image_begin_load; - module->stop_load = gdk_pixbuf__xbm_image_stop_load; - module->load_increment = gdk_pixbuf__xbm_image_load_increment; + module->load = gdk_pixbuf__xbm_image_load; + module->begin_load = gdk_pixbuf__xbm_image_begin_load; + module->stop_load = gdk_pixbuf__xbm_image_stop_load; + module->load_increment = gdk_pixbuf__xbm_image_load_increment; +} + +void +MODULE_ENTRY (xbm, fill_info) (GdkPixbufFormat *info) +{ + static GdkPixbufModulePattern signature[] = { + { "#define ", NULL, 100 }, + { "/*", NULL, 50 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "image/x-xbitmap", + NULL + }; + static gchar * extensions[] = { + "xbm", + NULL + }; + + info->name = "xbm"; + info->signature = signature; + info->description = N_("The XBM image format"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = 0; } diff --git a/gdk-pixbuf/io-xpm.c b/gdk-pixbuf/io-xpm.c index fff93f91c..ca0b81ebc 100644 --- a/gdk-pixbuf/io-xpm.c +++ b/gdk-pixbuf/io-xpm.c @@ -1409,8 +1409,8 @@ gdk_pixbuf__xpm_image_load_xpm_data (const gchar **data) typedef struct _XPMContext XPMContext; struct _XPMContext { - ModulePreparedNotifyFunc prepare_func; - ModuleUpdatedNotifyFunc update_func; + GdkPixbufModulePreparedFunc prepare_func; + GdkPixbufModuleUpdatedFunc update_func; gpointer user_data; gchar *tempname; @@ -1425,9 +1425,9 @@ struct _XPMContext * in the future. */ static gpointer -gdk_pixbuf__xpm_image_begin_load (ModuleSizeFunc size_func, - ModulePreparedNotifyFunc prepare_func, - ModuleUpdatedNotifyFunc update_func, +gdk_pixbuf__xpm_image_begin_load (GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepare_func, + GdkPixbufModuleUpdatedFunc update_func, gpointer user_data, GError **error) { @@ -1513,11 +1513,35 @@ gdk_pixbuf__xpm_image_load_increment (gpointer data, } void -gdk_pixbuf__xpm_fill_vtable (GdkPixbufModule *module) +MODULE_ENTRY (xpm, fill_vtable) (GdkPixbufModule *module) { - module->load = gdk_pixbuf__xpm_image_load; - module->load_xpm_data = gdk_pixbuf__xpm_image_load_xpm_data; - module->begin_load = gdk_pixbuf__xpm_image_begin_load; - module->stop_load = gdk_pixbuf__xpm_image_stop_load; - module->load_increment = gdk_pixbuf__xpm_image_load_increment; + module->load = gdk_pixbuf__xpm_image_load; + module->load_xpm_data = gdk_pixbuf__xpm_image_load_xpm_data; + module->begin_load = gdk_pixbuf__xpm_image_begin_load; + module->stop_load = gdk_pixbuf__xpm_image_stop_load; + module->load_increment = gdk_pixbuf__xpm_image_load_increment; +} + +void +MODULE_ENTRY (xpm, fill_info) (GdkPixbufFormat *info) +{ + static GdkPixbufModulePattern signature[] = { + { "/* XPM */", NULL, 100 }, + { NULL, NULL, 0 } + }; + static gchar * mime_types[] = { + "image/x-xpixmap", + NULL + }; + static gchar * extensions[] = { + "xpm", + NULL + }; + + info->name = "xpm"; + info->signature = signature; + info->description = N_("The XPM image format"); + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = 0; } diff --git a/gdk-pixbuf/queryloaders.c b/gdk-pixbuf/queryloaders.c new file mode 100644 index 000000000..6d6c0f9e8 --- /dev/null +++ b/gdk-pixbuf/queryloaders.c @@ -0,0 +1,155 @@ +/* -*- mode: C; c-file-style: "linux" -*- */ +/* GdkPixbuf library + * queryloaders.c: + * + * Copyright (C) 2002 The Free Software Foundation + * + * Author: Matthias Clasen <maclas@gmx.de> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <glib.h> +#include <gmodule.h> + +#include <errno.h> +#include <string.h> +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif +#include <stdio.h> + +#include "gdk-pixbuf/gdk-pixbuf.h" +#include "gdk-pixbuf/gdk-pixbuf-private.h" +#include "gdk-pixbuf/gdk-pixbuf-io.h" + +#if USE_LA_MODULES +#define SOEXT ".la" +#else +#define SOEXT ("." G_MODULE_SUFFIX) +#endif +#define SOEXT_LEN (strlen (SOEXT)) + +static void +print_escaped (const char *str) +{ + gchar *tmp = g_strescape (str, ""); + printf ("\"%s\" ", tmp); + g_free (tmp); +} + +static void +query_module (const char *dir, const char *file) +{ + char *path; + GModule *module; + void (*fill_info) (GdkPixbufFormat *info); + void (*fill_vtable) (GdkPixbufModule *module); + char **mime; + char **ext; + const GdkPixbufModulePattern *pattern; + + if (g_path_is_absolute (dir)) + path = g_build_filename (dir, file, NULL); + else { + char *cwd = g_get_current_dir (); + path = g_build_filename (cwd, dir, file, NULL); + g_free (cwd); + } + + + module = g_module_open (path, 0); + if (module && + g_module_symbol (module, "fill_info", (gpointer *) &fill_info) && + g_module_symbol (module, "fill_vtable", (gpointer *) &fill_vtable)) { + printf("\"%s\"\n", path); + GdkPixbufFormat *info = g_new0 (GdkPixbufFormat, 1); + (*fill_info) (info); + printf("\"%s\" %d \"%s\" \"%s\"\n", + info->name, info->flags, + info->domain ? info->domain : GETTEXT_PACKAGE, info->description); + for (mime = info->mime_types; *mime; mime++) { + printf("\"%s\" ", *mime); + } + printf("\"\"\n"); + for (ext = info->extensions; *ext; ext++) { + printf("\"%s\" ", *ext); + } + printf("\"\"\n"); + for (pattern = info->signature; pattern->prefix; pattern++) { + print_escaped (pattern->prefix); + print_escaped (pattern->mask ? (const char *)pattern->mask : ""); + printf ("%d\n", pattern->relevance); + } + printf ("\n"); + g_free (info); + } + else { + fprintf (stderr, "Cannot load loader %s\n", path); + } + if (module) + g_module_close (module); + g_free (path); +} + +int main (int argc, char **argv) +{ + gint i; + + printf ("# GdkPixbuf Image Loader Modules file\n" + "# Automatically generated file, do not edit\n" + "#\n"); + + if (argc == 1) { +#ifdef USE_GMODULE + const char *path; + + path = g_getenv ("GDK_PIXBUF_MODULEDIR"); + if (path == NULL || *path == '\0') + path = PIXBUF_LIBDIR; + + printf ("# LoaderDir = %s\n#\n", path); + + GDir *dir = g_dir_open (path, 0, NULL); + if (dir) { + const char *dent; + + while ((dent = g_dir_read_name (dir))) { + gint len = strlen (dent); + if (len > SOEXT_LEN && + strcmp (dent + len - SOEXT_LEN, SOEXT) == 0) { + query_module (path, dent); + } + } + g_dir_close (dir); + } +#else + printf ("# dynamic loading of modules not supported\n"); +#endif + } + else { + char *cwd = g_get_current_dir (); + + for (i = 1; i < argc; i++) + query_module (cwd, argv[i]); + + g_free (cwd); + } + + return 0; +} |