aboutsummaryrefslogtreecommitdiff
path: root/pixman/demos/gtk-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'pixman/demos/gtk-utils.c')
-rw-r--r--pixman/demos/gtk-utils.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/pixman/demos/gtk-utils.c b/pixman/demos/gtk-utils.c
index 1ff89ebd3..8291a1ed2 100644
--- a/pixman/demos/gtk-utils.c
+++ b/pixman/demos/gtk-utils.c
@@ -5,7 +5,6 @@
GdkPixbuf *
pixbuf_from_argb32 (uint32_t *bits,
- gboolean has_alpha,
int width,
int height,
int stride)
@@ -47,12 +46,12 @@ show_image (pixman_image_t *image)
{
GtkWidget *window;
GdkPixbuf *pixbuf;
- int width, height, stride;
+ int width, height;
int argc;
char **argv;
char *arg0 = g_strdup ("pixman-test-program");
- gboolean has_alpha;
pixman_format_code_t format;
+ pixman_image_t *copy;
argc = 1;
argv = (char **)&arg0;
@@ -62,21 +61,43 @@ show_image (pixman_image_t *image)
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
width = pixman_image_get_width (image);
height = pixman_image_get_height (image);
- stride = pixman_image_get_stride (image);
gtk_window_set_default_size (GTK_WINDOW (window), width, height);
-
+
format = pixman_image_get_format (image);
-
- if (format == PIXMAN_a8r8g8b8)
- has_alpha = TRUE;
- else if (format == PIXMAN_x8r8g8b8)
- has_alpha = FALSE;
- else
- g_error ("Can't deal with this format: %x\n", format);
-
- pixbuf = pixbuf_from_argb32 (pixman_image_get_data (image), has_alpha,
- width, height, stride);
+
+ /* Three cases:
+ *
+ * - image is a8r8g8b8_sRGB: we will display without modification
+ * under the assumption that the monitor is sRGB
+ *
+ * - image is a8r8g8b8: we will display without modification
+ * under the assumption that whoever created the image
+ * probably did it wrong by using sRGB inputs
+ *
+ * - other: we will convert to a8r8g8b8 under the assumption that
+ * whoever created the image probably did it wrong.
+ */
+ switch (format)
+ {
+ case PIXMAN_a8r8g8b8_sRGB:
+ case PIXMAN_a8r8g8b8:
+ copy = pixman_image_ref (image);
+ break;
+
+ default:
+ copy = pixman_image_create_bits (PIXMAN_a8r8g8b8,
+ width, height, NULL, -1);
+ pixman_image_composite32 (PIXMAN_OP_SRC,
+ image, NULL, copy,
+ 0, 0, 0, 0, 0, 0,
+ width, height);
+ break;
+ }
+
+ pixbuf = pixbuf_from_argb32 (pixman_image_get_data (copy),
+ width, height,
+ pixman_image_get_stride (copy));
g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), pixbuf);
g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);