-
/* testpixbuf -- test program for gdk-pixbuf code
* Copyright (C) 1999 Mark Crichton, Larry Ewing
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
+#include <config.h>
+#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-
#include <gtk/gtk.h>
-#include "gdk-pixbuf.h"
-#include "gdk-pixbuf-io.h"
-#include "gdk-pixbuf-loader.h"
+#include <gtk/gdk-pixbuf-loader.h>
+
+#include "test-inline-pixbufs.h"
+
+typedef struct {
+ FILE *imagefile;
+ GdkPixbufLoader *loader;
+ GtkWidget **rgbwin;
+ guchar *buf;
+ guint timeout;
+ guint readlen;
+} ProgressFileStatus;
+
#define DEFAULT_WIDTH 24
#define DEFAULT_HEIGHT 24
pixbuf = (GdkPixbuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
- if (!pixbuf->art_pixbuf) {
- g_warning ("art_pixbuf is NULL in expose_func!!\n");
- return;
- }
-
- if (pixbuf->art_pixbuf->has_alpha) {
+ 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,
- pixbuf->art_pixbuf->pixels
- + (event->area.y * pixbuf->art_pixbuf->rowstride)
- + (event->area.x * pixbuf->art_pixbuf->n_channels),
- pixbuf->art_pixbuf->rowstride);
+ 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.width,
event->area.height,
GDK_RGB_DITHER_NORMAL,
- pixbuf->art_pixbuf->pixels
- + (event->area.y * pixbuf->art_pixbuf->rowstride)
- + (event->area.x * pixbuf->art_pixbuf->n_channels),
- pixbuf->art_pixbuf->rowstride);
+ 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));
}
}
g_print("X:%d Y:%d\n", event->width, event->height);
#if 0
- if (((event->width) != (pixbuf->art_pixbuf->width)) ||
- ((event->height) != (pixbuf->art_pixbuf->height)))
+ if (((event->width) != gdk_pixbuf_get_width (pixbuf)) ||
+ ((event->height) != gdk_pixbuf_get_height (pixbuf)))
gdk_pixbuf_scale(pixbuf, event->width, event->height);
#endif
}
GtkWidget *button;
GtkWidget *drawing_area;
gint w, h;
-
- w = pixbuf->art_pixbuf->width;
- h = pixbuf->art_pixbuf->height;
+
+ g_return_val_if_fail (pixbuf != NULL, NULL);
+ 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::title", title ? title : "testrgb",
"GtkWindow::allow_shrink", TRUE,
NULL);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
return window;
}
+
static gint
update_timeout(gpointer data)
{
- GtkWidget** window_loc = data;
+ ProgressFileStatus *status = data;
+ gboolean done, error;
+
+ done = FALSE;
+ error = FALSE;
+ if (!feof(status->imagefile)) {
+ gint nbytes;
+
+ nbytes = fread(status->buf, 1, status->readlen,
+ status->imagefile);
+
+
+ error = !gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (status->loader), status->buf, nbytes);
+ if (error) {
+ G_BREAKPOINT();
+ }
+
+ } else { /* Really done */
+
+ GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf (status->loader);
+ new_testrgb_window (pixbuf, "After progressive load");
+ done = TRUE;
- if (*window_loc != NULL) {
- gtk_widget_queue_draw(*window_loc);
}
- return TRUE;
+ if (error) {
+ g_warning ("Serious error writing to loader");
+ done = TRUE;
+ }
+
+ if (done) {
+ gtk_widget_queue_draw(*status->rgbwin);
+ 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)
{
return;
}
-static int readlen = 1;
+
+static void
+progressive_updated_callback(GdkPixbufLoader* loader, guint x, guint y, guint width, guint height, gpointer data)
+{
+ 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;
+}
+
+static int readlen = 4096;
+
+extern void pixbuf_init();
int
main (int argc, char **argv)
GdkPixbuf *pixbuf;
GdkPixbufLoader *pixbuf_loader;
- FILE *file;
- gint val;
- guchar buf;
+
+ pixbuf_init ();
gtk_init (&argc, &argv);
gdk_rgb_init ();
gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
- gtk_widget_set_default_visual (gdk_rgb_get_visual ());
{
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) {
const gchar*** xpmp;
- pixbuf = gdk_pixbuf_new_from_data ((guchar *) default_image, ART_PIX_RGB, FALSE,
+ pixbuf = gdk_pixbuf_new_from_data (default_image, GDK_COLORSPACE_RGB, FALSE, 8,
DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH * 3,
NULL, NULL);
new_testrgb_window (pixbuf, NULL);
new_testrgb_window (pixbuf, NULL);
++xpmp;
}
+
+ /* Test loading from inline data. */
+ pixbuf = gdk_pixbuf_new_from_inline (apple_red, FALSE, -1);
+ new_testrgb_window (pixbuf, "Red apple from inline data");
+
+ pixbuf = gdk_pixbuf_new_from_inline (gnome_foot, TRUE, sizeof (gnome_foot));
+ new_testrgb_window (pixbuf, "Foot from inline data");
found_valid = TRUE;
} else {
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.rgbwin = &rgb_window;
+ status.buf = g_malloc (readlen);
gtk_signal_connect(GTK_OBJECT(pixbuf_loader),
"area_prepared",
GTK_SIGNAL_FUNC(progressive_prepared_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);
+ gtk_signal_connect(GTK_OBJECT(pixbuf_loader),
+ "area_updated",
+ GTK_SIGNAL_FUNC(progressive_updated_callback),
+ &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)