6 pixbuf_from_argb32 (uint32_t *bits,
12 GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,
14 int p_stride = gdk_pixbuf_get_rowstride (pixbuf);
15 guint32 *p_bits = (guint32 *)gdk_pixbuf_get_pixels (pixbuf);
18 for (h = 0; h < height; ++h)
20 for (w = 0; w < width; ++w)
22 uint32_t argb = bits[h * (stride / 4) + w];
24 char *pb = (char *)p_bits;
26 pb += h * p_stride + w * 4;
28 r = (argb & 0x00ff0000) >> 16;
29 g = (argb & 0x0000ff00) >> 8;
30 b = (argb & 0x000000ff) >> 0;
31 a = has_alpha? (argb & 0xff000000) >> 24 : 0xff;
56 on_expose (GtkWidget *widget, GdkEventExpose *expose, gpointer data)
58 GdkPixbuf *pixbuf = data;
60 gdk_draw_pixbuf (widget->window, NULL,
62 gdk_pixbuf_get_width (pixbuf),
63 gdk_pixbuf_get_height (pixbuf),
71 show_image (pixman_image_t *image)
75 int width, height, stride;
78 char *arg0 = g_strdup ("pixman-test-program");
80 pixman_format_code_t format;
83 argv = (char **)&arg0;
85 gtk_init (&argc, &argv);
87 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
88 width = pixman_image_get_width (image);
89 height = pixman_image_get_height (image);
90 stride = pixman_image_get_stride (image);
92 gtk_window_set_default_size (GTK_WINDOW (window), width, height);
94 format = pixman_image_get_format (image);
96 if (format == PIXMAN_a8r8g8b8)
98 else if (format == PIXMAN_x8r8g8b8)
101 g_error ("Can't deal with this format: %x\n", format);
103 pixbuf = pixbuf_from_argb32 (pixman_image_get_data (image), has_alpha,
104 width, height, stride);
106 g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), pixbuf);
107 g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
109 gtk_widget_show (window);