]> Pileus Git - ~andy/gtk/commitdiff
Fixed up testpixbuf.c to simulate downloading at certain speed, set
authorMichael Fulbright <drmike@src.gnome.org>
Tue, 9 Nov 1999 23:51:35 +0000 (23:51 +0000)
committerMichael Fulbright <drmike@src.gnome.org>
Tue, 9 Nov 1999 23:51:35 +0000 (23:51 +0000)
env var TBF_KBPS=n to get n kBytes/sec.

Dr Mike

demos/testpixbuf.c
gdk-pixbuf/ChangeLog
gdk-pixbuf/Makefile.am

index 3035e2c9797310d7253a8412a3353bf1a50be3c4..c844f3f83265aa0014152b4c17d87b3577197b87 100644 (file)
 #include "gdk-pixbuf-io.h"
 #include "gdk-pixbuf-loader.h"
 
+typedef struct {
+       FILE             *imagefile;
+       GdkPixbufLoader  *loader;
+       guchar           *buf;
+       guint            timeout;
+       guint            readlen;
+
+} ProgressFileStatus;
+
+
 #define DEFAULT_WIDTH  24
 #define DEFAULT_HEIGHT 24
 
@@ -417,18 +427,35 @@ new_testrgb_window (GdkPixbuf *pixbuf, gchar *title)
         return window;
 }
 
+
 static gint
 update_timeout(gpointer data)
 {
-        GtkWidget** window_loc = data;
+        ProgressFileStatus *status = data;
+       gboolean done;
+
+       done = TRUE;
+       if (!feof(status->imagefile)) {
+               gint nbytes;
 
-        if (*window_loc != NULL) {
-                gtk_widget_queue_draw(*window_loc);
-        }
+               nbytes = fread(status->buf, 1, status->readlen, 
+                              status->imagefile);
 
-       return TRUE;
+               done = !gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (status->loader), status->buf, nbytes);
+                       
+       }
+
+       if (done) {
+               gdk_pixbuf_loader_close (GDK_PIXBUF_LOADER (status->loader));
+               gtk_object_destroy (GTK_OBJECT(status->loader));
+               fclose (status->imagefile);
+               g_free (status->buf);
+       }
+
+       return !done;
 }
 
+
 static void
 progressive_prepared_callback(GdkPixbufLoader* loader, gpointer data)
 {
@@ -449,7 +476,14 @@ progressive_prepared_callback(GdkPixbufLoader* loader, gpointer data)
 static void
 progressive_updated_callback(GdkPixbufLoader* loader, guint x, guint y, guint width, guint height, gpointer data)
 {
-       g_print ("progressive_updated_callback:\n\t%d\t%d\t%d\t%d\n", x, y, width, height);
+        GtkWidget** window_loc = data;
+
+/*     g_print ("progressive_updated_callback:\n\t%d\t%d\t%d\t%d\n", x, y, width, height); */
+
+        if (*window_loc != NULL)
+                gtk_widget_queue_draw_area(*window_loc,
+                                          x, y, width, height);
+
         return;
 }
 
@@ -479,6 +513,16 @@ main (int argc, char **argv)
                if(tbf_readlen) readlen = atoi(tbf_readlen);
        }
 
+       {
+               char *tbf_bps = getenv("TBF_KBPS");
+               guint bps;
+
+               if (tbf_bps) {
+                       bps = atoi(tbf_bps);
+                       readlen = (bps*1024)/10;
+               }
+       }
+
        i = 1;
        if (argc == 1) {
                 const gchar*** xpmp;
@@ -509,14 +553,15 @@ main (int argc, char **argv)
                                found_valid = TRUE;
                        }
                }
-
+#if 1
                 {
                         GtkWidget* rgb_window = NULL;
-                        guint timeout;
-                       char *buf;
+                       ProgressFileStatus   status;
 
                         pixbuf_loader = gdk_pixbuf_loader_new ();
+                       status.loader = pixbuf_loader;
 
+                       status.buf = g_malloc (readlen);
                         gtk_signal_connect(GTK_OBJECT(pixbuf_loader),
                                            "area_prepared",
                                            GTK_SIGNAL_FUNC(progressive_prepared_callback),
@@ -527,35 +572,15 @@ main (int argc, char **argv)
                                            GTK_SIGNAL_FUNC(progressive_updated_callback),
                                            &rgb_window);
 
-                        timeout = gtk_timeout_add(1000, update_timeout, &rgb_window);
-                        
-                        file = fopen (argv[1], "r");
-                        g_assert (file != NULL);
-                       buf = g_malloc(readlen);
-
-                        while (!feof(file)) {
-                               int nbytes;
-                               nbytes = fread(buf, 1, readlen, file);
-
-                                //printf(".");
-                                fflush(stdout);
-                                
-                                if (gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (pixbuf_loader), buf, nbytes) == FALSE)
-                                        break;
-
-                               while (gtk_events_pending())
-                                       gtk_main_iteration();
-                        }
-                       printf("\n");
-                       gtk_timeout_remove (timeout);
-                        gdk_pixbuf_loader_close (GDK_PIXBUF_LOADER (pixbuf_loader));
-                       gtk_object_destroy (GTK_OBJECT(pixbuf_loader));
-                        fclose (file);
-
-                        if (rgb_window != NULL)
-                                gtk_widget_queue_draw(rgb_window);
+                       
+                        status.imagefile = fopen (argv[1], "r");
+                        g_assert (status.imagefile != NULL);
+
+                       status.readlen = readlen;
+
+                        status.timeout = gtk_timeout_add(100, update_timeout, &status);
                 }
-               
+#endif
        }
 
        if (found_valid)
index 05e3329068be80436d4d9841d484399bd46c9a86..f96ea76c59210a774de76d3e06be7f80b9c7a37f 100644 (file)
@@ -1,5 +1,9 @@
 1999-11-09  Michael Fulbright  <drmike@redhat.com>
 
+        * src/testpixbuf.c: Fixed it to use timeout to read from file
+       for progressive loading. Set TBF_KBPS=n, where n is the number of
+       kilobytes/second to simulate in downloading. n has to be an integer.
+       
        * src/io-jpeg.c: Slight cosmetic cleanup.
 
        * src/io-pnm.c: Fixed raw PNM loading bug. Also discovered that ASCII
index 10d90f7518c64447258063570059db3caa7c123b..387690bf29ddde1cf8e15222f415159824583fe3 100644 (file)
@@ -21,13 +21,16 @@ endif
 
 XPM_LIB =      libpixbuf-xpm.la
 
+PNM_LIB =      libpixbuf-pnm.la
+
 libexec_LTLIBRARIES =          \
        $(PNG_LIB)      \
        $(JPEG_LIB)     \
        $(GIF_LIB)      \
        $(RAS_LIB)      \
        $(XPM_LIB)      \
-       $(TIFF_LIB)
+       $(TIFF_LIB)     \
+       $(PNM_LIB)
 
 noinst_PROGRAMS = testpixbuf
 
@@ -105,3 +108,10 @@ libpixbuf_ras_la_LIBADD =
 libpixbuf_tiff_la_SOURCES = io-tiff.c
 libpixbuf_tiff_la_LDFLAGS = -avoid-version -module
 libpixbuf_tiff_la_LIBADD = $(LIBTIFF)
+
+#
+# The PNM loader
+#
+libpixbuf_pnm_la_SOURCES = io-pnm.c
+libpixbuf_pnm_la_LDFLAGS = -avoid-version -module
+libpixbuf_pnm_la_LIBADD =