]> Pileus Git - ~andy/gtk/blobdiff - demos/testpixbuf.c
contrib subdir
[~andy/gtk] / demos / testpixbuf.c
index 5d36b7a0b852a7079ebcfa6fb13b9b29fe3059e1..f118205e2153c802f4c402839ace0532ce33004a 100644 (file)
@@ -1,31 +1,31 @@
-
 /* 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/gdk-pixbuf.h"
-#include "gdk-pixbuf/gdk-pixbuf-io.h"
-#include "gdk-pixbuf/gdk-pixbuf-loader.h"
+#include <gtk/gdk-pixbuf-loader.h>
+
+#include "test-inline-pixbufs.h"
 
 typedef struct {
        FILE             *imagefile;
@@ -34,7 +34,6 @@ typedef struct {
        guchar           *buf;
        guint            timeout;
        guint            readlen;
-
 } ProgressFileStatus;
 
 
@@ -321,22 +320,17 @@ expose_func (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data)
 
        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,
@@ -344,10 +338,10 @@ expose_func (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data)
                                    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));
        }
 }
 
@@ -361,8 +355,8 @@ config_func (GtkWidget *drawing_area, GdkEventConfigure *event, gpointer data)
        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
 }
@@ -376,14 +370,15 @@ new_testrgb_window (GdkPixbuf *pixbuf, gchar *title)
        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",
@@ -433,18 +428,34 @@ static gint
 update_timeout(gpointer data)
 {
         ProgressFileStatus *status = data;
-       gboolean done;
-
-       done = TRUE;
+       gboolean done, error;
+        
+       done = FALSE;
+        error = FALSE;
        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);
-                       
-       }
+
+                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 (error) { 
+                g_warning ("Serious error writing to loader"); 
+                done = TRUE; 
+        } 
 
        if (done) {
                 gtk_widget_queue_draw(*status->rgbwin);
@@ -491,6 +502,8 @@ progressive_updated_callback(GdkPixbufLoader* loader, guint x, guint y, guint wi
 
 static int readlen = 4096;
 
+extern void pixbuf_init();
+
 int
 main (int argc, char **argv)
 {
@@ -500,6 +513,8 @@ main (int argc, char **argv)
        GdkPixbuf *pixbuf;
        GdkPixbufLoader *pixbuf_loader;
 
+       pixbuf_init ();
+
        gtk_init (&argc, &argv);
 
        gdk_rgb_set_verbose (TRUE);
@@ -507,7 +522,6 @@ main (int argc, char **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");
@@ -529,7 +543,7 @@ main (int argc, char **argv)
        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);
@@ -540,6 +554,13 @@ main (int argc, char **argv)
                         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 {