3 #include "../test/utils.h"
7 pixman_image_from_file (const char *filename, pixman_format_code_t format)
10 pixman_image_t *image;
18 if (!(pixbuf = gdk_pixbuf_new_from_file (filename, NULL)))
23 width = gdk_pixbuf_get_width (pixbuf);
24 height = gdk_pixbuf_get_height (pixbuf);
25 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
26 gdk_data = gdk_pixbuf_get_pixels (pixbuf);
27 stride = gdk_pixbuf_get_rowstride (pixbuf);
29 if (!(data = malloc (width * height * sizeof (uint32_t))))
33 for (j = 0; j < height; ++j)
35 uint8_t *gdk_line = gdk_data;
37 for (i = 0; i < width; ++i)
51 r = (r * a + 127) / 255;
52 g = (g * a + 127) / 255;
53 b = (b * a + 127) / 255;
55 pixel = (a << 24) | (r << 16) | (g << 8) | b;
58 gdk_line += n_channels;
64 image = pixman_image_create_bits (
65 format, width, height, data, width * 4);
68 g_object_unref (pixbuf);
73 pixbuf_from_argb32 (uint32_t *bits,
78 GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,
80 int p_stride = gdk_pixbuf_get_rowstride (pixbuf);
81 guint32 *p_bits = (guint32 *)gdk_pixbuf_get_pixels (pixbuf);
84 for (i = 0; i < height; ++i)
86 uint32_t *src_row = &bits[i * (stride / 4)];
87 uint32_t *dst_row = p_bits + i * (p_stride / 4);
89 a8r8g8b8_to_rgba_np (dst_row, src_row, width);
96 on_expose (GtkWidget *widget, GdkEventExpose *expose, gpointer data)
98 pixman_image_t *pimage = data;
99 int width = pixman_image_get_width (pimage);
100 int height = pixman_image_get_height (pimage);
101 int stride = pixman_image_get_stride (pimage);
102 cairo_surface_t *cimage;
103 cairo_format_t format;
106 if (pixman_image_get_format (pimage) == PIXMAN_x8r8g8b8)
107 format = CAIRO_FORMAT_RGB24;
109 format = CAIRO_FORMAT_ARGB32;
111 cimage = cairo_image_surface_create_for_data (
112 (uint8_t *)pixman_image_get_data (pimage),
113 format, width, height, stride);
115 cr = gdk_cairo_create (widget->window);
117 cairo_rectangle (cr, 0, 0, width, height);
118 cairo_set_source_surface (cr, cimage, 0, 0);
122 cairo_surface_destroy (cimage);
128 show_image (pixman_image_t *image)
134 char *arg0 = g_strdup ("pixman-test-program");
135 pixman_format_code_t format;
136 pixman_image_t *copy;
139 argv = (char **)&arg0;
141 gtk_init (&argc, &argv);
143 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
144 width = pixman_image_get_width (image);
145 height = pixman_image_get_height (image);
147 gtk_window_set_default_size (GTK_WINDOW (window), width, height);
149 format = pixman_image_get_format (image);
151 /* We always display the image as if it contains sRGB data. That
152 * means that no conversion should take place when the image
153 * has the a8r8g8b8_sRGB format.
157 case PIXMAN_a8r8g8b8_sRGB:
158 case PIXMAN_a8r8g8b8:
159 case PIXMAN_x8r8g8b8:
160 copy = pixman_image_ref (image);
164 copy = pixman_image_create_bits (PIXMAN_a8r8g8b8,
165 width, height, NULL, -1);
166 pixman_image_composite32 (PIXMAN_OP_SRC,
173 g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), copy);
174 g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
176 gtk_widget_show (window);