]> Pileus Git - ~andy/gtk/blobdiff - gdk-pixbuf/io-wbmp.c
chain finalize to parent class to get removed from the toplevel_list.
[~andy/gtk] / gdk-pixbuf / io-wbmp.c
index d49658930b9cbde799eb6979a3ca436a7a8550bc..c495b21cbf668f0951c8edd72dad11dc007718c4 100644 (file)
@@ -30,7 +30,9 @@ Known bugs:
 
 #include <config.h>
 #include <stdio.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <string.h>
 #include "gdk-pixbuf-private.h"
 #include "gdk-pixbuf-io.h"
@@ -60,21 +62,22 @@ struct wbmp_progressive_state {
   GdkPixbuf *pixbuf;   /* Our "target" */
 };
 
-gpointer
+static gpointer
 gdk_pixbuf__wbmp_image_begin_load(ModulePreparedNotifyFunc prepared_func,
                                  ModuleUpdatedNotifyFunc updated_func,
-                                 ModuleFrameDoneNotifyFunc frame_done_func,
-                                 ModuleAnimationDoneNotifyFunc
-                                 anim_done_func, gpointer user_data);
+                                  gpointer user_data,
+                                  GError **error);
 
-void gdk_pixbuf__wbmp_image_stop_load(gpointer data);
-gboolean gdk_pixbuf__wbmp_image_load_increment(gpointer data, guchar * buf,
-                                              guint size);
+static gboolean gdk_pixbuf__wbmp_image_stop_load(gpointer data, GError **error);
+static gboolean gdk_pixbuf__wbmp_image_load_increment(gpointer data,
+                                                      const guchar * buf,
+                                                      guint size,
+                                                      GError **error);
 
 
 /* Shared library entry point --> This should be removed when
    generic_image_load enters gdk-pixbuf-io. */
-GdkPixbuf *gdk_pixbuf__wbmp_image_load(FILE * f)
+static GdkPixbuf *gdk_pixbuf__wbmp_image_load(FILE * f, GError **error)
 {
        size_t length;
        char membuf[4096];
@@ -82,14 +85,19 @@ GdkPixbuf *gdk_pixbuf__wbmp_image_load(FILE * f)
 
        GdkPixbuf *pb;
 
-       State = gdk_pixbuf__wbmp_image_begin_load(NULL, NULL, NULL, NULL, NULL);
+       State = gdk_pixbuf__wbmp_image_begin_load(NULL, NULL, NULL,
+                                                  error);
 
+        if (State == NULL)
+          return NULL;
+        
        while (feof(f) == 0) {
                length = fread(membuf, 1, 4096, f);
                if (length > 0)
                  gdk_pixbuf__wbmp_image_load_increment(State,
                                                        membuf,
-                                                       length);
+                                                       length,
+                                                        error);
 
        }
        if (State->pixbuf != NULL)
@@ -97,7 +105,7 @@ GdkPixbuf *gdk_pixbuf__wbmp_image_load(FILE * f)
 
        pb = State->pixbuf;
 
-       gdk_pixbuf__wbmp_image_stop_load(State);
+       gdk_pixbuf__wbmp_image_stop_load(State, NULL);
        return pb;
 }
 
@@ -107,12 +115,11 @@ GdkPixbuf *gdk_pixbuf__wbmp_image_load(FILE * f)
  * return context (opaque to user)
  */
 
-gpointer
+static gpointer
 gdk_pixbuf__wbmp_image_begin_load(ModulePreparedNotifyFunc prepared_func,
-                                ModuleUpdatedNotifyFunc updated_func,
-                                ModuleFrameDoneNotifyFunc frame_done_func,
-                                ModuleAnimationDoneNotifyFunc
-                                anim_done_func, gpointer user_data)
+                                  ModuleUpdatedNotifyFunc updated_func,
+                                  gpointer user_data,
+                                  GError **error)
 {
        struct wbmp_progressive_state *context;
 
@@ -133,20 +140,27 @@ gdk_pixbuf__wbmp_image_begin_load(ModulePreparedNotifyFunc prepared_func,
  *
  * free context, unref gdk_pixbuf
  */
-void gdk_pixbuf__wbmp_image_stop_load(gpointer data)
+static gboolean gdk_pixbuf__wbmp_image_stop_load(gpointer data,
+                                                 GError **error)
 {
        struct wbmp_progressive_state *context =
            (struct wbmp_progressive_state *) data;
 
-       g_return_if_fail(context != NULL);
+        /* FIXME this thing needs to report errors if
+         * we have unused image data
+         */
+        
+       g_return_val_if_fail(context != NULL, TRUE);
        if (context->pixbuf)
          gdk_pixbuf_unref(context->pixbuf);
 
        g_free(context);
+
+        return TRUE;
 }
 
 static gboolean
-getin(struct wbmp_progressive_state *context, guchar **buf, guint *buf_size, guchar *ptr, int datum_size)
+getin(struct wbmp_progressive_state *context, const guchar **buf, guint *buf_size, guchar *ptr, int datum_size)
 {
   int last_num, buf_num;
 
@@ -181,7 +195,7 @@ save_rest(struct wbmp_progressive_state *context, const guchar *buf, guint buf_s
 }
 
 static gboolean
-get_mbi(struct wbmp_progressive_state *context, guchar **buf, guint *buf_size, int *val)
+get_mbi(struct wbmp_progressive_state *context, const guchar **buf, guint *buf_size, int *val)
 {
   guchar intbuf[16];
   int i, n;
@@ -218,12 +232,13 @@ get_mbi(struct wbmp_progressive_state *context, guchar **buf, guint *buf_size, i
  *
  * append image data onto inrecrementally built output image
  */
-gboolean gdk_pixbuf__wbmp_image_load_increment(gpointer data, guchar * buf,
-                                             guint size)
+static gboolean gdk_pixbuf__wbmp_image_load_increment(gpointer data,
+                                                      const guchar * buf,
+                                                      guint size, GError **error)
 {
        struct wbmp_progressive_state *context =
            (struct wbmp_progressive_state *) data;
-       gboolean bv;
+       gboolean bv = FALSE;
 
        do
          {
@@ -266,7 +281,7 @@ gboolean gdk_pixbuf__wbmp_image_load_increment(gpointer data, guchar * buf,
                    g_assert(context->pixbuf);
 
                    if(context->prepared_func)
-                     context->prepared_func(context->pixbuf, context->user_data);
+                     context->prepared_func(context->pixbuf, NULL, context->user_data);
                  }
              }
            else if(context->needmore)
@@ -314,3 +329,12 @@ gboolean gdk_pixbuf__wbmp_image_load_increment(gpointer data, guchar * buf,
        else
          return context->needmore;
 }
+
+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;
+}