[gtk+/rendering-cleanup: 11/81] demos: Convert testpixbuf-save to Cairo



commit 656cc9211ed2dd3861a8be5fcfb852a774db3a78
Author: Benjamin Otte <otte redhat com>
Date:   Tue Jul 13 17:49:33 2010 +0200

    demos: Convert testpixbuf-save to Cairo

 demos/testpixbuf-save.c |   34 +++++++++-------------------------
 1 files changed, 9 insertions(+), 25 deletions(-)
---
diff --git a/demos/testpixbuf-save.c b/demos/testpixbuf-save.c
index 3929c7e..c8a6679 100644
--- a/demos/testpixbuf-save.c
+++ b/demos/testpixbuf-save.c
@@ -311,32 +311,18 @@ static int
 expose_cb (GtkWidget *drawing_area, GdkEventExpose *evt, gpointer data)
 {
         GdkPixbuf *pixbuf;
+        cairo_t *cr;
          
         pixbuf = (GdkPixbuf *) g_object_get_data (G_OBJECT (drawing_area),
 						  "pixbuf");
-        if (gdk_pixbuf_get_has_alpha (pixbuf)) {
-                gdk_draw_rgb_32_image (drawing_area->window,
-                                       drawing_area->style->black_gc,
-                                       evt->area.x, evt->area.y,
-                                       evt->area.width,
-                                       evt->area.height,
-                                       GDK_RGB_DITHER_MAX,
-                                       gdk_pixbuf_get_pixels (pixbuf) +
-                                       (evt->area.y * gdk_pixbuf_get_rowstride (pixbuf)) +
-                                       (evt->area.x * gdk_pixbuf_get_n_channels (pixbuf)),
-                                       gdk_pixbuf_get_rowstride (pixbuf));
-        } else {
-                gdk_draw_rgb_image (drawing_area->window, 
-                                    drawing_area->style->black_gc, 
-                                    evt->area.x, evt->area.y,
-                                    evt->area.width,
-                                    evt->area.height,  
-                                    GDK_RGB_DITHER_NORMAL,
-                                    gdk_pixbuf_get_pixels (pixbuf) +
-                                    (evt->area.y * gdk_pixbuf_get_rowstride (pixbuf)) +
-                                    (evt->area.x * gdk_pixbuf_get_n_channels (pixbuf)),
-                                    gdk_pixbuf_get_rowstride (pixbuf));
-        }
+
+        cr = gdk_cairo_create (evt->window);
+        gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+        gdk_cairo_rectangle (cr, &evt->area);
+        cairo_fill (cr);
+
+        cairo_destroy (cr);
+
         return FALSE;
 }
 
@@ -374,8 +360,6 @@ main (int argc, char **argv)
    
         gtk_init (&argc, &argv);   
 
-        gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
-
         root = gdk_get_default_root_window ();
         pixbuf = gdk_pixbuf_get_from_drawable (NULL, root, NULL,
                                                0, 0, 0, 0, 150, 160);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]