summaryrefslogtreecommitdiff
path: root/demos
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2001-05-07 15:58:47 +0000
committerHavoc Pennington <hp@src.gnome.org>2001-05-07 15:58:47 +0000
commitb4e4a0ed9d66132efad0539bc5901b35ea262d88 (patch)
tree7eea37afc0c2f32334112872547373758ac7d6b6 /demos
parent607ac1e1b31dc21598830a22930bcc39a77cb5c3 (diff)
downloadgtk+-b4e4a0ed9d66132efad0539bc5901b35ea262d88.tar.gz
fix some shell typos
2001-05-04 Havoc Pennington <hp@redhat.com> * configure.in: fix some shell typos * gtk/gtkcolorsel.c (gtk_color_selection_destroy): warning fix * gtk/gtkimage.c: handle animations * gtk/gtkcheckbutton.c (gtk_check_button_size_request): request border_width * 2, not just border_width * gtk/gtkscale.c: add "format_value" signal to allow people to override the way values are drawn. (gtk_scale_get_value_size): fix width/height mistake, and compute size from actual displayed text, not from made-up text. * gtk/gtktexttag.c (gtk_text_tag_class_init): fix return type in signal registration * tests/testtext.c: Add "Remove all tags" menu item for testing * gtk/gtktextbuffer.c (gtk_text_buffer_remove_all_tags): implement * demos/gtk-demo/main.c (main): add hack so we can find modules without installing gtk * demos/gtk-demo/textview.c (insert_text): demo font scaling * gtk/gtkcellrenderertext.c: Add "scale" property (font scaling factor) (gtk_cell_renderer_text_set_property): remove some bogus g_object_notify * gtk/gtktexttag.c: add "scale" property which is a font scaling factor * gtk/gtktextlayout.c (add_text_attrs): add font scale attribute to layout * gtk/gtktextiter.c (gtk_text_iter_is_start): rename from gtk_text_iter_is_first 2001-05-04 Havoc Pennington <hp@redhat.com> * pixops/pixops.c (pixops_process): merge fix from stable: Patch from hoshem@mel.comcen.com.au to fix nonzero X offsets. Fixes bug #50371. * gdk-pixbuf/pixops/pixops.c (pixops_composite_nearest): merge from stable: Patch from OKADA Mitsuru <m-okada@fjb.co.jp> to fix confusion of using "src" instead of "p". (pixops_composite_color_nearest): Use a more accurate (and correct, to begin with) compositing method. This cures checks showing through on images with no alpha. * gdk-pixbuf.c (gdk_pixbuf_fill): fix bug that left some trailing bytes unfilled. * gdk-pixbuf-io.h: fix UpdatedNotifyFunc to use signed ints * gdk-pixbuf-loader.h (struct _GdkPixbufLoaderClass): Change area_updated signal to use signed ints. Removed animation-related signals. * io-gif.c, io-gif-animation.h, io-gif-animation.c: Massive rewrite action * gdk-pixbuf-animation.c: Add GdkPixbufAnimationIter to abstract all the pesky details. Remove old frame-based API. Make GdkPixbufAnimation an abstract base class, derived by the loaders.
Diffstat (limited to 'demos')
-rw-r--r--demos/gtk-demo/Makefile.am4
-rw-r--r--demos/gtk-demo/alphatest.pngbin0 -> 26529 bytes
-rw-r--r--demos/gtk-demo/floppybuddy.gifbin0 -> 5216 bytes
-rw-r--r--demos/gtk-demo/images.c49
-rw-r--r--demos/gtk-demo/main.c12
-rw-r--r--demos/gtk-demo/textview.c19
-rw-r--r--demos/testanimation.c814
7 files changed, 460 insertions, 438 deletions
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index 3cb530503b..7d199e09c5 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -59,8 +59,10 @@ gtk_demo_SOURCES = \
gtk_demo_DEPENDENCIES = $(DEPS)
gtk_demo_LDADD = $(LDADDS)
-IMAGEFILES= apple-red.png \
+IMAGEFILES= alphatest.png \
+ apple-red.png \
background.jpg \
+ floppybuddy.gif \
gnome-applets.png \
gnome-calendar.png \
gnome-foot.png \
diff --git a/demos/gtk-demo/alphatest.png b/demos/gtk-demo/alphatest.png
new file mode 100644
index 0000000000..eb5885f89c
--- /dev/null
+++ b/demos/gtk-demo/alphatest.png
Binary files differ
diff --git a/demos/gtk-demo/floppybuddy.gif b/demos/gtk-demo/floppybuddy.gif
new file mode 100644
index 0000000000..ac986c8ed3
--- /dev/null
+++ b/demos/gtk-demo/floppybuddy.gif
Binary files differ
diff --git a/demos/gtk-demo/images.c b/demos/gtk-demo/images.c
index 353cb4c8c2..7faeb53cca 100644
--- a/demos/gtk-demo/images.c
+++ b/demos/gtk-demo/images.c
@@ -8,6 +8,8 @@
*
* If you want to put image data in your program as a C variable,
* use the make-inline-pixbuf program that comes with GTK+.
+ * This way you won't need to depend on loading external files, your
+ * application binary can be self-contained.
*/
#include <gtk/gtk.h>
@@ -39,14 +41,14 @@ progressive_prepared_callback (GdkPixbufLoader* loader, gpointer data)
static void
progressive_updated_callback (GdkPixbufLoader* loader,
- guint x, guint y, guint width, guint height,
+ gint x, gint y, gint width, gint height,
gpointer data)
{
GtkWidget* image;
image = GTK_WIDGET (data);
- /* We know the pixbuf inside the image has changed, but the image
+ /* We know the pixbuf inside the GtkImage has changed, but the image
* itself doesn't know this; so queue a redraw. If we wanted to be
* really efficient, we could use a drawing area or something
* instead of a GtkImage, so we could control the exact position of
@@ -85,7 +87,7 @@ progressive_timeout (gpointer data)
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
- "Failure reading image file 'gtk-logo-rgb.gif': %s",
+ "Failure reading image file 'alphatest.png': %s",
g_strerror (errno));
gtk_signal_connect (GTK_OBJECT (dialog),
@@ -180,10 +182,10 @@ progressive_timeout (gpointer data)
{
const gchar *filename;
- if (g_file_test ("./gtk-logo-rgb.gif", G_FILE_TEST_EXISTS))
- filename = "./gtk-logo-rgb.gif";
+ if (g_file_test ("./alphatest.png", G_FILE_TEST_EXISTS))
+ filename = "./alphatest.png";
else
- filename = DEMOCODEDIR"/gtk-logo-rgb.gif";
+ filename = DEMOCODEDIR"/alphatest.png";
image_stream = fopen (filename, "r");
@@ -195,7 +197,7 @@ progressive_timeout (gpointer data)
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
- "Unable to open image file 'gtk-logo-rgb.gif': %s",
+ "Unable to open image file 'alphatest.png': %s",
g_strerror (errno));
gtk_signal_connect (GTK_OBJECT (dialog),
@@ -246,7 +248,7 @@ start_progressive_loading (GtkWidget *image)
* The timeout simply simulates a slow data source by inserting
* pauses in the reading process.
*/
- load_timeout = g_timeout_add (300,
+ load_timeout = g_timeout_add (150,
progressive_timeout,
image);
}
@@ -359,6 +361,37 @@ do_images (void)
gtk_container_add (GTK_CONTAINER (frame), image);
+
+ /* Animation */
+
+ label = gtk_label_new (NULL);
+ gtk_label_set_markup (GTK_LABEL (label),
+ "<u>Animation loaded from a file</u>");
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ frame = gtk_frame_new (NULL);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+ /* The alignment keeps the frame from growing when users resize
+ * the window
+ */
+ align = gtk_alignment_new (0.5, 0.5, 0, 0);
+ gtk_container_add (GTK_CONTAINER (align), frame);
+ gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 0);
+
+ /* We look for the image in the current directory first,
+ * so you can run gtk-demo without installing GTK
+ */
+ if (g_file_test ("./floppybuddy.gif", G_FILE_TEST_EXISTS))
+ image = gtk_image_new_from_file ("./floppybuddy.gif");
+ else
+ image = gtk_image_new_from_file (DEMOCODEDIR"/floppybuddy.gif");
+
+ gtk_container_add (GTK_CONTAINER (frame), image);
+
+
+ /* Progressive */
+
+
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
"<u>Progressive image loading</u>");
diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c
index fabf898d44..83a27b362f 100644
--- a/demos/gtk-demo/main.c
+++ b/demos/gtk-demo/main.c
@@ -465,6 +465,18 @@ main (int argc, char **argv)
GtkWidget *tree;
GtkTextTag *tag;
+ /* Most code in gtk-demo is intended to be exemplary, but not
+ * these few lines, which are just a hack so gtk-demo will work
+ * in the GTK tree without installing it.
+ */
+ if (g_file_test ("../../gdk-pixbuf/.libs/libpixbufloader-pnm.so",
+ G_FILE_TEST_EXISTS))
+ {
+ putenv ("GDK_PIXBUF_MODULEDIR=../../gdk-pixbuf/.libs");
+ putenv ("GTK_IM_MODULE_FILE=../../modules/input/gtk.immodules");
+ }
+ /* -- End of hack -- */
+
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
diff --git a/demos/gtk-demo/textview.c b/demos/gtk-demo/textview.c
index 928df9073b..2fc970bfd4 100644
--- a/demos/gtk-demo/textview.c
+++ b/demos/gtk-demo/textview.c
@@ -84,6 +84,12 @@ create_tags (GtkTextBuffer *buffer)
/* points times the PANGO_SCALE factor */
"size", 30 * PANGO_SCALE, NULL);
+ gtk_text_buffer_create_tag (buffer, "xx-small",
+ "scale", PANGO_SCALE_XX_SMALL, NULL);
+
+ gtk_text_buffer_create_tag (buffer, "x-large",
+ "scale", PANGO_SCALE_X_LARGE, NULL);
+
gtk_text_buffer_create_tag (buffer, "monospace",
"family", "monospace", NULL);
@@ -199,8 +205,17 @@ insert_text (GtkTextBuffer *buffer)
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"big", -1,
"big", NULL);
- gtk_text_buffer_insert (buffer, &iter, " text.\n\n", -1);
-
+ gtk_text_buffer_insert (buffer, &iter, " text. ", -1);
+ gtk_text_buffer_insert (buffer, &iter, "It's best not to hardcode specific text sizes; you can use relative sizes as with CSS, such as ", -1);
+ gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
+ "xx-small", -1,
+ "xx-small", NULL);
+ gtk_text_buffer_insert (buffer, &iter, " or ", -1);
+ gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
+ "x-large", -1,
+ "x-large", NULL);
+ gtk_text_buffer_insert (buffer, &iter, " to ensure that your program properly adapts if the user changes the default font size.\n\n", -1);
+
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Colors. ", -1,
"heading", NULL);
diff --git a/demos/testanimation.c b/demos/testanimation.c
index a823249b42..82b932c2d0 100644
--- a/demos/testanimation.c
+++ b/demos/testanimation.c
@@ -23,466 +23,426 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
+#include <errno.h>
#include <gtk/gtk.h>
-#include <gdk-pixbuf/gdk-pixbuf-loader.h>
-
-typedef struct {
- FILE *imagefile;
- GdkPixbufLoader *loader;
- GtkWidget **rgbwin;
- guchar *buf;
- guint timeout;
- guint readlen;
-
-} ProgressFileStatus;
-
-
-#define DEFAULT_WIDTH 24
-#define DEFAULT_HEIGHT 24
-
-static const unsigned char default_image[] = {
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xae, 0xb3, 0xb3, 0xc6, 0xc9, 0xcd, 0xd7, 0xd4, 0xdf,
- 0xec, 0xde, 0xf3, 0xe7, 0xcb, 0xe9, 0xd9, 0xb5, 0xd3, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xb1, 0xb7, 0xa5,
- 0xb0, 0xb8, 0xad, 0xb3, 0xb9, 0xb6, 0xc1, 0xc6, 0xc8, 0xd5, 0xd3, 0xdc,
- 0xec, 0xde, 0xf3, 0xe5, 0xca, 0xe6, 0xe0, 0xbb, 0xd7, 0xe1, 0xad, 0xc2,
- 0xe3, 0xac, 0xa3, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xca, 0xc1, 0xa4, 0xc5, 0xc7, 0xac,
- 0xb7, 0xbe, 0xaf, 0xad, 0xb4, 0xaf, 0xbd, 0xc2, 0xc3, 0xd1, 0xd0, 0xd8,
- 0xec, 0xde, 0xf3, 0xe5, 0xc7, 0xe4, 0xe0, 0xb6, 0xd1, 0xe7, 0xa9, 0xb4,
- 0xed, 0xcd, 0xb6, 0xd6, 0xcf, 0xae, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0x00, 0x00, 0x00, 0xdf, 0xa7, 0x9f, 0xdd, 0xbf, 0xaa, 0xcf, 0xc5, 0xa9,
- 0xc1, 0xc4, 0xac, 0xb2, 0xba, 0xaf, 0xb6, 0xbb, 0xbb, 0xcd, 0xce,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ff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
- 0xe8, 0xc6, 0xe7, 0xe5, 0xc2, 0xe3, 0xe3, 0xbd, 0xdd, 0xe1, 0xb6, 0xd5,
- 0xe2, 0xb0, 0xcb, 0x6a, 0x6a, 0x6a, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x6a, 0x6a, 0x6a, 0x9d, 0xa8, 0x9f,
- 0x8f, 0x97, 0x96, 0x8b, 0x90, 0x92, 0x97, 0x9e, 0xa2, 0xa0, 0xa7, 0xae,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
- 0xe7, 0xd3, 0xed, 0xe8, 0xd1, 0xed, 0xe8, 0xce, 0xec, 0xe9, 0xcc, 0xeb,
- 0xe8, 0xc6, 0xe7, 0x0d, 0x0d, 0x0d, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x0d, 0x0d, 0x0d, 0x97, 0x9e, 0xa2,
- 0xa7, 0xae, 0xb7, 0xb2, 0xb6, 0xc5, 0xba, 0xbc, 0xce, 0xbf, 0xbe, 0xd3,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
- 0xe9, 0xdf, 0xf0, 0xe9, 0xdf, 0xf0, 0xe9, 0xdf, 0xf0, 0xe9, 0xdf, 0xf0,
- 0xe9, 0xdf, 0xf0, 0x0d, 0x0d, 0x0d, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff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, 0xc1, 0xb0, 0xdb, 0xa8, 0xa3, 0xd2, 0x8a, 0xa9,
- 0xb7, 0x7e, 0xa2, 0xbd, 0x89, 0xa9, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xc9, 0xaf, 0xaf,
- 0xc5, 0xb5, 0xb8, 0xb8, 0xb1, 0xb1, 0xb6, 0xbb, 0xad, 0xd0, 0xd6, 0xb5,
- 0xe3, 0xd7, 0xb5, 0xe2, 0xbf, 0xaf, 0xdd, 0xb4, 0xa9, 0xdb, 0x92, 0x9a,
- 0xc6, 0x84, 0xa7, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xac, 0xaa, 0xa6, 0xbd, 0xc3, 0xb0, 0xd2, 0xd7, 0xb5,
- 0xe3, 0xd7, 0xb5, 0xe2, 0xbf, 0xae, 0xdb, 0xb6, 0xa8, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff
+
+typedef struct _LoadContext LoadContext;
+
+struct _LoadContext
+{
+ gchar *filename;
+ GtkWidget *window;
+ GdkPixbufLoader *pixbuf_loader;
+ guint load_timeout;
+ FILE* image_stream;
};
static void
-quit_func (GtkWidget *widget, gpointer dummy)
+destroy_context (gpointer data)
{
- gtk_main_quit ();
+ LoadContext *lc = data;
+
+ g_free (lc->filename);
+
+ if (lc->load_timeout)
+ g_source_remove (lc->load_timeout);
+
+ if (lc->image_stream)
+ fclose (lc->image_stream);
+
+ if (lc->pixbuf_loader)
+ {
+ gdk_pixbuf_loader_close (lc->pixbuf_loader, NULL);
+ g_object_unref (G_OBJECT (lc->pixbuf_loader));
+ }
+
+ g_free (lc);
}
-static void
-expose_func (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data)
+static LoadContext*
+get_load_context (GtkWidget *image)
{
- GdkPixbuf *pixbuf;
-
- pixbuf = (GdkPixbuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
-
- if (gdk_pixbuf_get_has_alpha (pixbuf)) {
- gdk_draw_rgb_32_image (drawing_area->window,
- drawing_area->style->black_gc,
- event->area.x, event->area.y,
- event->area.width,
- event->area.height,
- GDK_RGB_DITHER_MAX,
- gdk_pixbuf_get_pixels (pixbuf)
- + (event->area.y * gdk_pixbuf_get_rowstride (pixbuf))
- + (event->area.x * gdk_pixbuf_get_n_channels (pixbuf)),
- gdk_pixbuf_get_rowstride (pixbuf));
- } else {
- gdk_draw_rgb_image (drawing_area->window,
- drawing_area->style->white_gc,
- event->area.x, event->area.y,
- event->area.width,
- event->area.height,
- GDK_RGB_DITHER_NORMAL,
- gdk_pixbuf_get_pixels (pixbuf)
- + (event->area.y * gdk_pixbuf_get_rowstride (pixbuf))
- + (event->area.x * gdk_pixbuf_get_n_channels (pixbuf)),
- gdk_pixbuf_get_rowstride (pixbuf));
- }
+ LoadContext *lc;
+
+ lc = g_object_get_data (G_OBJECT (image), "lc");
+
+ if (lc == NULL)
+ {
+ lc = g_new0 (LoadContext, 1);
+
+ g_object_set_data_full (G_OBJECT (image),
+ "lc",
+ lc,
+ destroy_context);
+ }
+
+ return lc;
}
static void
-config_func (GtkWidget *drawing_area, GdkEventConfigure *event, gpointer data)
+progressive_prepared_callback (GdkPixbufLoader* loader,
+ gpointer data)
{
- GdkPixbuf *pixbuf;
-
- pixbuf = (GdkPixbuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
+ GdkPixbuf* pixbuf;
+ GtkWidget* image;
-#if 0
- if (((event->width) != gdk_pixbuf_get_width (pixbuf)) ||
- ((event->height) != gdk_pixbuf_get_height (pixbuf)))
- gdk_pixbuf_scale(pixbuf, event->width, event->height);
-#endif
+ image = GTK_WIDGET (data);
+
+ pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+
+ /* Avoid displaying random memory contents, since the pixbuf
+ * isn't filled in yet.
+ */
+ gdk_pixbuf_fill (pixbuf, 0xaaaaaaff);
+
+ /* Could set the pixbuf instead, if we only wanted to display
+ * static images.
+ */
+ gtk_image_set_from_animation (GTK_IMAGE (image),
+ gdk_pixbuf_loader_get_animation (loader));
}
-static GtkWidget*
-new_testrgb_window (GdkPixbuf *pixbuf, gchar *title)
+static void
+progressive_updated_callback (GdkPixbufLoader* loader,
+ gint x, gint y, gint width, gint height,
+ gpointer data)
{
- GtkWidget *window;
- GtkWidget *vbox;
- GtkWidget *temp_box;
- GtkWidget *button;
- GtkWidget *drawing_area;
- gint w, h;
-
- w = gdk_pixbuf_get_width (pixbuf);
- h = gdk_pixbuf_get_height (pixbuf);
-
- window = gtk_widget_new (gtk_window_get_type (),
- "GtkObject::user_data", NULL,
- "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
- "GtkWindow::title", "testrgb",
- "GtkWindow::allow_shrink", TRUE,
- NULL);
- gtk_signal_connect (GTK_OBJECT (window), "destroy",
- (GtkSignalFunc) quit_func, NULL);
-
- vbox = gtk_vbox_new (FALSE, 0);
-
- if (title)
- gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (title),
- TRUE, TRUE, 0);
-
- drawing_area = gtk_drawing_area_new ();
-
- temp_box = gtk_hbox_new (FALSE, 0);
- gtk_widget_set_usize (GTK_WIDGET (drawing_area), w, h);
- gtk_box_pack_start (GTK_BOX (temp_box), drawing_area, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), temp_box, FALSE, FALSE, 0);
-
-
- gtk_signal_connect (GTK_OBJECT(drawing_area), "expose_event",
- GTK_SIGNAL_FUNC(expose_func), NULL);
- gtk_signal_connect (GTK_OBJECT(drawing_area), "configure_event",
- GTK_SIGNAL_FUNC (config_func), NULL);
-
- gtk_object_set_data (GTK_OBJECT(drawing_area), "pixbuf", pixbuf);
-
- gtk_widget_show (drawing_area);
-
- button = gtk_button_new_with_label ("Quit");
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
- gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
- (GtkSignalFunc) gtk_widget_destroy,
- GTK_OBJECT (window));
-
- gtk_widget_show (button);
-
- gtk_container_add (GTK_CONTAINER (window), vbox);
- gtk_widget_show_all (vbox);
-
- gtk_widget_show (window);
-
- return window;
+ GtkWidget* image;
+
+ image = GTK_WIDGET (data);
+
+ /* We know the pixbuf inside the GtkImage has changed, but the image
+ * itself doesn't know this; so queue a redraw. If we wanted to be
+ * really efficient, we could use a drawing area or something
+ * instead of a GtkImage, so we could control the exact position of
+ * the pixbuf on the display, then we could queue a draw for only
+ * the updated area of the image.
+ */
+
+ /* We only really need to redraw if the image's animation iterator
+ * is gdk_pixbuf_animation_iter_on_currently_loading_frame(), but
+ * who cares.
+ */
+
+ gtk_widget_queue_draw (image);
}
-#if 0
-
static gint
-update_timeout(gpointer data)
+progressive_timeout (gpointer data)
{
- ProgressFileStatus *status = data;
- gboolean done;
-
- done = TRUE;
- if (!feof(status->imagefile)) {
- gint nbytes;
-
- nbytes = fread(status->buf, 1, status->readlen,
- status->imagefile);
-
- done = !gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (status->loader), status->buf, nbytes);
-
- }
-
- if (done) {
- gtk_widget_queue_draw(*status->rgbwin);
- gdk_pixbuf_loader_close (GDK_PIXBUF_LOADER (status->loader));
- g_object_destroy (G_OBJECT(status->loader));
- fclose (status->imagefile);
- g_free (status->buf);
- }
+ GtkWidget *image;
+ LoadContext *lc;
+
+ image = GTK_WIDGET (data);
+ lc = get_load_context (image);
+
+ /* This shows off fully-paranoid error handling, so looks scary.
+ * You could factor out the error handling code into a nice separate
+ * function to make things nicer.
+ */
+
+ if (lc->image_stream)
+ {
+ size_t bytes_read;
+ guchar buf[256];
+ GError *error = NULL;
+
+ bytes_read = fread (buf, 1, 256, lc->image_stream);
+
+ if (ferror (lc->image_stream))
+ {
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (lc->window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "Failure reading image file 'alphatest.png': %s",
+ g_strerror (errno));
+
+ gtk_signal_connect (GTK_OBJECT (dialog),
+ "response",
+ GTK_SIGNAL_FUNC (gtk_widget_destroy),
+ NULL);
+
+ fclose (lc->image_stream);
+ lc->image_stream = NULL;
+
+ gtk_widget_show (dialog);
+
+ lc->load_timeout = 0;
+
+ return FALSE; /* uninstall the timeout */
+ }
+
+ if (!gdk_pixbuf_loader_write (lc->pixbuf_loader,
+ buf, bytes_read,
+ &error))
+ {
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (lc->window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "Failed to load image: %s",
+ error->message);
- return !done;
+ g_error_free (error);
+
+ gtk_signal_connect (GTK_OBJECT (dialog),
+ "response",
+ GTK_SIGNAL_FUNC (gtk_widget_destroy),
+ NULL);
+
+ fclose (lc->image_stream);
+ lc->image_stream = NULL;
+
+ gtk_widget_show (dialog);
+
+ lc->load_timeout = 0;
+
+ return FALSE; /* uninstall the timeout */
+ }
+
+ if (feof (lc->image_stream))
+ {
+ fclose (lc->image_stream);
+ lc->image_stream = NULL;
+
+ /* Errors can happen on close, e.g. if the image
+ * file was truncated we'll know on close that
+ * it was incomplete.
+ */
+ error = NULL;
+ if (!gdk_pixbuf_loader_close (lc->pixbuf_loader,
+ &error))
+ {
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (lc->window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "Failed to load image: %s",
+ error->message);
+
+ g_error_free (error);
+
+ gtk_signal_connect (GTK_OBJECT (dialog),
+ "response",
+ GTK_SIGNAL_FUNC (gtk_widget_destroy),
+ NULL);
+
+ gtk_widget_show (dialog);
+
+ g_object_unref (G_OBJECT (lc->pixbuf_loader));
+ lc->pixbuf_loader = NULL;
+
+ lc->load_timeout = 0;
+
+ return FALSE; /* uninstall the timeout */
+ }
+
+ g_object_unref (G_OBJECT (lc->pixbuf_loader));
+ lc->pixbuf_loader = NULL;
+ }
+ }
+ else
+ {
+ lc->image_stream = fopen (lc->filename, "r");
+
+ if (lc->image_stream == NULL)
+ {
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (lc->window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "Unable to open image file '%s': %s",
+ lc->filename,
+ g_strerror (errno));
+
+ gtk_signal_connect (GTK_OBJECT (dialog),
+ "response",
+ GTK_SIGNAL_FUNC (gtk_widget_destroy),
+ NULL);
+
+ gtk_widget_show (dialog);
+
+ lc->load_timeout = 0;
+
+ return FALSE; /* uninstall the timeout */
+ }
+
+ if (lc->pixbuf_loader)
+ {
+ gdk_pixbuf_loader_close (lc->pixbuf_loader, NULL);
+ g_object_unref (G_OBJECT (lc->pixbuf_loader));
+ lc->pixbuf_loader = NULL;
+ }
+
+ lc->pixbuf_loader = gdk_pixbuf_loader_new ();
+
+ g_signal_connect_data (G_OBJECT (lc->pixbuf_loader),
+ "area_prepared",
+ G_CALLBACK (progressive_prepared_callback),
+ image,
+ NULL, FALSE, FALSE);
+
+ g_signal_connect_data (G_OBJECT (lc->pixbuf_loader),
+ "area_updated",
+ G_CALLBACK (progressive_updated_callback),
+ image,
+ NULL, FALSE, FALSE);
+ }
+
+ /* leave timeout installed */
+ return TRUE;
}
static void
-progressive_prepared_callback(GdkPixbufLoader* loader, gpointer data)
+start_progressive_loading (GtkWidget *image)
{
- GtkWidget** retloc = data;
- GdkPixbuf* pixbuf;
-
- pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
- g_assert(pixbuf != NULL);
-
- gdk_pixbuf_ref(pixbuf); /* for the RGB window */
-
- *retloc = new_testrgb_window(pixbuf, "Progressive");
-
- return;
+ LoadContext *lc;
+
+ lc = get_load_context (image);
+
+ /* This is obviously totally contrived (we slow down loading
+ * on purpose to show how incremental loading works).
+ * The real purpose of incremental loading is the case where
+ * you are reading data from a slow source such as the network.
+ * The timeout simply simulates a slow data source by inserting
+ * pauses in the reading process.
+ */
+ lc->load_timeout = g_timeout_add (100,
+ progressive_timeout,
+ image);
}
+static GtkWidget *
+do_image (const char *filename)
+{
+ GtkWidget *frame;
+ GtkWidget *vbox;
+ GtkWidget *image;
+ GtkWidget *label;
+ GtkWidget *align;
+ GtkWidget *window;
+ gchar *str, *escaped;
+ LoadContext *lc;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (window), "Image Loading");
+
+ gtk_container_set_border_width (GTK_CONTAINER (window), 8);
+
+ vbox = gtk_vbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ label = gtk_label_new (NULL);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ escaped = g_markup_escape_text (filename, -1);
+ str = g_strdup_printf ("Progressively loading: <b>%s</b>", escaped);
+ gtk_label_set_markup (GTK_LABEL (label),
+ str);
+ g_free (escaped);
+ g_free (str);
+
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ frame = gtk_frame_new (NULL);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+ /* The alignment keeps the frame from growing when users resize
+ * the window
+ */
+ align = gtk_alignment_new (0.5, 0.5, 0, 0);
+ gtk_container_add (GTK_CONTAINER (align), frame);
+ gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 0);
+
+ image = gtk_image_new_from_pixbuf (NULL);
+ gtk_container_add (GTK_CONTAINER (frame), image);
+
+ lc = get_load_context (image);
+
+ lc->window = window;
+ lc->filename = g_strdup (filename);
+
+ start_progressive_loading (image);
+
+ gtk_widget_show_all (window);
+
+ return window;
+}
static void
-progressive_updated_callback(GdkPixbufLoader* loader, guint x, guint y, guint width, guint height, gpointer data)
+do_nonprogressive (const gchar *filename)
{
- 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;
+ GtkWidget *frame;
+ GtkWidget *vbox;
+ GtkWidget *image;
+ GtkWidget *label;
+ GtkWidget *align;
+ GtkWidget *window;
+ gchar *str, *escaped;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (window), "Animation");
+
+ gtk_container_set_border_width (GTK_CONTAINER (window), 8);
+
+ vbox = gtk_vbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ label = gtk_label_new (NULL);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ escaped = g_markup_escape_text (filename, -1);
+ str = g_strdup_printf ("Loaded from file: <b>%s</b>", escaped);
+ gtk_label_set_markup (GTK_LABEL (label),
+ str);
+ g_free (escaped);
+ g_free (str);
+
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ frame = gtk_frame_new (NULL);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+ /* The alignment keeps the frame from growing when users resize
+ * the window
+ */
+ align = gtk_alignment_new (0.5, 0.5, 0, 0);
+ gtk_container_add (GTK_CONTAINER (align), frame);
+ gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 0);
+
+ image = gtk_image_new_from_file (filename);
+ gtk_container_add (GTK_CONTAINER (frame), image);
+
+ gtk_widget_show_all (window);
}
-#endif
-
-static int readlen = 4096;
-
-extern void pixbuf_init();
-
int
-main (int argc, char **argv)
+main (int argc,
+ char **argv)
{
- int i;
- int found_valid = FALSE;
-
- GdkPixbufAnimation *animation;
-
- pixbuf_init ();
-
- gtk_init (&argc, &argv);
-
- gdk_rgb_set_verbose (TRUE);
-
- gdk_rgb_init ();
-
- gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
-
- {
- char *tbf_readlen = getenv("TBF_READLEN");
- if(tbf_readlen) readlen = atoi(tbf_readlen);
- }
-
- {
- char *tbf_bps = getenv("TBF_KBPS");
- guint bps;
-
- if (tbf_bps) {
- bps = atoi(tbf_bps);
- g_print ("Simulating %d kBytes/sec\n", bps);
- readlen = (bps*1024)/10;
- }
- }
-
- i = 1;
- if (argc == 1) {
- g_print ("USAGE: testanimation FILE1 ...\n");
- return 0;
- } else {
- for (i = 1; i < argc; i++) {
- GError *error;
+ gint i;
+
+ gtk_init (&argc, &argv);
+
+ i = 1;
+ while (i < argc)
+ {
+ do_image (argv[i]);
+ do_nonprogressive (argv[i]);
+
+ ++i;
+ }
+
+ gtk_main ();
+
+ return 0;
+}
- error = NULL;
- animation = gdk_pixbuf_animation_new_from_file (argv[i],
- &error);
- if (animation == NULL) {
- g_warning ("Failed to load animation: %s",
- error->message);
- g_error_free (error);
- }
-
- if (animation) {
- gint i = 0;
- GList *listptr;
- for (listptr = gdk_pixbuf_animation_get_frames (animation);
- listptr;
- listptr = listptr->next) {
- GdkPixbufFrame *frame;
- GdkPixbuf *pixbuf;
- gchar *title;
-
- frame = listptr->data;
- pixbuf = gdk_pixbuf_frame_get_pixbuf (frame);
-
- title = g_strdup_printf ("Frame %d", i);
- g_print ("Frame %d x:%d y:%d width:%d height:%d\n",
- i,
- gdk_pixbuf_frame_get_x_offset (frame),
- gdk_pixbuf_frame_get_y_offset (frame),
- gdk_pixbuf_get_width (pixbuf),
- gdk_pixbuf_get_height (pixbuf));
- new_testrgb_window (pixbuf, title);
- g_free (title);
- i++;
- }
- found_valid = TRUE;
- }
- }
-#if 0
- {
- GtkWidget* rgb_window = NULL;
- ProgressFileStatus status;
- GdkPixbufLoader *pixbuf_loader;
-
- pixbuf_loader = gdk_pixbuf_loader_new ();
- status.loader = pixbuf_loader;
-
- status.rgbwin = &rgb_window;
-
- status.buf = g_malloc (readlen);
- g_signal_connect_data(G_OBJECT(pixbuf_loader),
- "area_prepared",
- GTK_SIGNAL_FUNC(progressive_prepared_callback),
- &rgb_window,
- NULL, FALSE, FALSE);
-
- g_signal_connect_data(G_OBJECT(pixbuf_loader),
- "area_updated",
- GTK_SIGNAL_FUNC(progressive_updated_callback),
- &rgb_window,
- NULL, FALSE, FALSE);
-
-
- 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)
- gtk_main ();
-
- return 0;
-}