Fixed up testpixbuf.c to simulate downloading at certain speed, set

env var TBF_KBPS=n to get n kBytes/sec.

Dr Mike
This commit is contained in:
Michael Fulbright 1999-11-09 23:51:35 +00:00
parent 39bb0d649c
commit 78141c328f
3 changed files with 75 additions and 36 deletions

View File

@ -27,6 +27,16 @@
#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;
if (*window_loc != NULL) {
gtk_widget_queue_draw(*window_loc);
}
done = TRUE;
if (!feof(status->imagefile)) {
gint nbytes;
return TRUE;
nbytes = fread(status->buf, 1, status->readlen,
status->imagefile);
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);
status.imagefile = fopen (argv[1], "r");
g_assert (status.imagefile != NULL);
while (!feof(file)) {
int nbytes;
nbytes = fread(buf, 1, readlen, file);
status.readlen = readlen;
//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.timeout = gtk_timeout_add(100, update_timeout, &status);
}
#endif
}
if (found_valid)

View 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

View 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 =