diff options
author | Matthias Clasen <matthiasc@src.gnome.org> | 2002-07-07 20:29:48 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2002-07-07 20:29:48 +0000 |
commit | 94218b8cfe573a7996a747b6ece9c5f46f204954 (patch) | |
tree | 5526a1dcedf5c3c881af707ea9913a4e0384ae5c /gdk-pixbuf | |
parent | 9aa5ba7fa30e877915088e16126f08fd066ff265 (diff) | |
download | gtk+-94218b8cfe573a7996a747b6ece9c5f46f204954.tar.gz |
New function for loading an image from a file either via module->load or
* gdk-pixbuf-io.c (generic_image_load): New function for loading
an image from a file either via module->load or incrementally.
(prepared_notify): ModulePreparedNotifyFunc for generic_image_load.
(gdk_pixbuf_new_from_file): Use generic_image_load.
* io-bmp.c, io-ico.c, io-ras.c, io-wbmp.c: Remove trivial
implementations of module->load. (#71266)
Diffstat (limited to 'gdk-pixbuf')
-rw-r--r-- | gdk-pixbuf/ChangeLog | 7 | ||||
-rw-r--r-- | gdk-pixbuf/gdk-pixbuf-io.c | 63 | ||||
-rw-r--r-- | gdk-pixbuf/io-bmp.c | 40 | ||||
-rw-r--r-- | gdk-pixbuf/io-ico.c | 51 | ||||
-rw-r--r-- | gdk-pixbuf/io-ras.c | 36 | ||||
-rw-r--r-- | gdk-pixbuf/io-wbmp.c | 36 |
6 files changed, 58 insertions, 175 deletions
diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog index e180fd5e15..25243386f6 100644 --- a/gdk-pixbuf/ChangeLog +++ b/gdk-pixbuf/ChangeLog @@ -1,5 +1,12 @@ 2002-07-07 Matthias Clasen <maclas@gmx.de> + * gdk-pixbuf-io.c (generic_image_load): New function for loading + an image from a file either via module->load or incrementally. + (prepared_notify): ModulePreparedNotifyFunc for generic_image_load. + (gdk_pixbuf_new_from_file): Use generic_image_load. + * io-bmp.c, io-ico.c, io-ras.c, io-wbmp.c: Remove trivial + implementations of module->load. (#71266) + * io-ico.c (DecodeHeader): Correct computation of image height. (OneLine): Correct update notification. diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c index b32da24dbe..5f4cce9f31 100644 --- a/gdk-pixbuf/gdk-pixbuf-io.c +++ b/gdk-pixbuf/gdk-pixbuf-io.c @@ -1,3 +1,4 @@ +/* -*- mode: C; c-file-style: "linux" -*- */ /* GdkPixbuf library - Main loading interface. * * Copyright (C) 1999 The Free Software Foundation @@ -552,6 +553,55 @@ _gdk_pixbuf_get_module (guchar *buffer, guint size, return NULL; } + +static void +prepared_notify (GdkPixbuf *pixbuf, + GdkPixbufAnimation *anim, + gpointer user_data) +{ + if (pixbuf != NULL) + g_object_ref (pixbuf); + *((GdkPixbuf **)user_data) = pixbuf; +} + +static GdkPixbuf * +generic_image_load (GdkPixbufModule *module, + FILE *f, + GError **error) +{ + guchar buffer[4096]; + size_t length; + GdkPixbuf *pixbuf = NULL; + gpointer context; + + if (module->load != NULL) + return (* module->load) (f, error); + + context = module->begin_load (NULL, prepared_notify, NULL, &pixbuf, error); + + if (!context) + return NULL; + + while (!feof (f)) { + length = fread (buffer, 1, sizeof (buffer), f); + if (length > 0) + if (!module->load_increment (context, buffer, length, error)) { + module->stop_load (context, NULL); + if (pixbuf != NULL) + g_object_unref (pixbuf); + return NULL; + } + } + + if (!module->stop_load (context, error)) { + if (pixbuf != NULL) + g_object_unref (pixbuf); + return NULL; + } + + return pixbuf; +} + /** * gdk_pixbuf_new_from_file: * @filename: Name of file to load. @@ -612,19 +662,8 @@ gdk_pixbuf_new_from_file (const char *filename, return NULL; } - if (image_module->load == NULL) { - g_set_error (error, - GDK_PIXBUF_ERROR, - GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION, - _("Don't know how to load the image in file '%s'"), - filename); - - fclose (f); - return NULL; - } - fseek (f, 0, SEEK_SET); - pixbuf = (* image_module->load) (f, error); + pixbuf = generic_image_load (image_module, f, error); fclose (f); if (pixbuf == NULL && error != NULL && *error == NULL) { diff --git a/gdk-pixbuf/io-bmp.c b/gdk-pixbuf/io-bmp.c index 83df835f3d..8c82f7552c 100644 --- a/gdk-pixbuf/io-bmp.c +++ b/gdk-pixbuf/io-bmp.c @@ -194,45 +194,6 @@ static gboolean gdk_pixbuf__bmp_image_load_increment(gpointer data, GError **error); - -/* Shared library entry point --> This should be removed when - generic_image_load enters gdk-pixbuf-io. */ -static GdkPixbuf *gdk_pixbuf__bmp_image_load(FILE * f, GError **error) -{ - guchar membuf[4096]; - size_t length; - struct bmp_progressive_state *State; - - GdkPixbuf *pb; - - State = - gdk_pixbuf__bmp_image_begin_load(NULL, NULL, NULL, NULL, - error); - - if (State == NULL) - return NULL; - - while (feof(f) == 0) { - length = fread(membuf, 1, sizeof (membuf), f); - if (length > 0) - if (!gdk_pixbuf__bmp_image_load_increment(State, - membuf, - length, - error)) { - gdk_pixbuf__bmp_image_stop_load (State, NULL); - return NULL; - } - - } - if (State->pixbuf != NULL) - g_object_ref(State->pixbuf); - - pb = State->pixbuf; - - gdk_pixbuf__bmp_image_stop_load(State, NULL); - return pb; -} - /* Picks up a 32-bit little-endian integer starting at the specified location. * Does it by hand instead of dereferencing a simple (gint *) cast due to * alignment constraints many platforms. @@ -1083,7 +1044,6 @@ gdk_pixbuf__bmp_image_load_increment(gpointer data, void gdk_pixbuf__bmp_fill_vtable (GdkPixbufModule *module) { - module->load = gdk_pixbuf__bmp_image_load; 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; diff --git a/gdk-pixbuf/io-ico.c b/gdk-pixbuf/io-ico.c index d39f4c92ed..3f593740cf 100644 --- a/gdk-pixbuf/io-ico.c +++ b/gdk-pixbuf/io-ico.c @@ -182,56 +182,6 @@ context_free (struct ico_progressive_state *context) g_free (context); } - -/* Shared library entry point --> Can go when generic_image_load - enters gdk-pixbuf-io */ -static GdkPixbuf * -gdk_pixbuf__ico_image_load(FILE * f, GError **error) -{ - guchar membuf [4096]; - size_t length; - struct ico_progressive_state *State; - - GdkPixbuf *pb; - - State = gdk_pixbuf__ico_image_begin_load(NULL, NULL, NULL, NULL, error); - - if (State == NULL) - return NULL; - - while (!feof(f)) { - length = fread(membuf, 1, 4096, f); - if (ferror (f)) { - g_set_error (error, - G_FILE_ERROR, - g_file_error_from_errno (errno), - _("Failure reading ICO: %s"), g_strerror (errno)); - context_free (State); - return NULL; - } - if (length > 0) - if (!gdk_pixbuf__ico_image_load_increment(State, membuf, length, - error)) { - context_free (State); - return NULL; - } - } - if (State->pixbuf != NULL) - g_object_ref (State->pixbuf); - else { - g_set_error (error, - GDK_PIXBUF_ERROR, - GDK_PIXBUF_ERROR_CORRUPT_IMAGE, - _("ICO file was missing some data (perhaps it was truncated somehow?)")); - context_free (State); - return NULL; - } - - pb = State->pixbuf; - - gdk_pixbuf__ico_image_stop_load(State, NULL); - return pb; -} static void DecodeHeader(guchar *Data, gint Bytes, struct ico_progressive_state *State, @@ -878,7 +828,6 @@ gdk_pixbuf__ico_image_load_increment(gpointer data, void gdk_pixbuf__ico_fill_vtable (GdkPixbufModule *module) { - module->load = gdk_pixbuf__ico_image_load; 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; diff --git a/gdk-pixbuf/io-ras.c b/gdk-pixbuf/io-ras.c index 32bc35abf9..99938c7b5c 100644 --- a/gdk-pixbuf/io-ras.c +++ b/gdk-pixbuf/io-ras.c @@ -104,41 +104,6 @@ static gboolean gdk_pixbuf__ras_image_load_increment(gpointer data, const guchar * buf, guint size, GError **error); - - -/* Shared library entry point */ -static GdkPixbuf *gdk_pixbuf__ras_image_load(FILE * f, GError **error) -{ - guchar *membuf; - size_t length; - struct ras_progressive_state *State; - - GdkPixbuf *pb; - - State = gdk_pixbuf__ras_image_begin_load(NULL, NULL, NULL, NULL, error); - - membuf = g_malloc(4096); - - g_assert(membuf != NULL); - - while (feof(f) == 0) { - length = fread(membuf, 1, 4096, f); - if (!gdk_pixbuf__ras_image_load_increment(State, membuf, length, - error)) { - gdk_pixbuf__ras_image_stop_load (State, NULL); - return NULL; - } - } - g_free(membuf); - if (State->pixbuf != NULL) - g_object_ref(State->pixbuf); - - pb = State->pixbuf; - - gdk_pixbuf__ras_image_stop_load(State, NULL); - return pb; -} - static gboolean RAS2State(struct rasterfile *RAS, struct ras_progressive_state *State, GError **error) @@ -541,7 +506,6 @@ gdk_pixbuf__ras_image_load_increment(gpointer data, void gdk_pixbuf__ras_fill_vtable (GdkPixbufModule *module) { - module->load = gdk_pixbuf__ras_image_load; 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; diff --git a/gdk-pixbuf/io-wbmp.c b/gdk-pixbuf/io-wbmp.c index 14bb115365..78cc24be70 100644 --- a/gdk-pixbuf/io-wbmp.c +++ b/gdk-pixbuf/io-wbmp.c @@ -75,41 +75,6 @@ static gboolean gdk_pixbuf__wbmp_image_load_increment(gpointer data, guint size, GError **error); - -/* Shared library entry point --> This should be removed when - generic_image_load enters gdk-pixbuf-io. */ -static GdkPixbuf *gdk_pixbuf__wbmp_image_load(FILE * f, GError **error) -{ - size_t length; - char membuf[4096]; - struct wbmp_progressive_state *State; - - GdkPixbuf *pb; - - State = gdk_pixbuf__wbmp_image_begin_load(NULL, NULL, NULL, NULL, - error); - - if (State == NULL) - return NULL; - - while (feof(f) == 0) { - length = fread(membuf, 1, 4096, f); - if (!gdk_pixbuf__wbmp_image_load_increment(State, membuf, length, - error)) { - gdk_pixbuf__wbmp_image_stop_load (State, NULL); - return NULL; - } - - } - if (State->pixbuf != NULL) - g_object_ref(State->pixbuf); - - pb = State->pixbuf; - - gdk_pixbuf__wbmp_image_stop_load(State, NULL); - return pb; -} - /* * func - called when we have pixmap created (but no image data) * user_data - passed as arg 1 to func @@ -376,7 +341,6 @@ static gboolean gdk_pixbuf__wbmp_image_load_increment(gpointer data, void gdk_pixbuf__wbmp_fill_vtable (GdkPixbufModule *module) { - module->load = gdk_pixbuf__wbmp_image_load; 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; |