From: Søren Sandmann Pedersen Date: Sat, 9 Jun 2012 13:42:56 +0000 (-0400) Subject: Make show_image() cope with more formats X-Git-Tag: pixman-0.27.4~58 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04e878c231ad3624c57e51a5fcdc55a177d4dc0f;p=platform%2Fupstream%2Fpixman.git Make show_image() cope with more formats This makes show_image() deal with more formats than just a8r8g8b8, in particular, a8r8g8b8_sRGB can now be handled. Images that are passed to show_image with a format of a8r8g8b8_sRGB are displayed without modification under the assumption that the monitor is approximately sRGB. Images with a format of a8r8g8b8 are also displayed without modification since many other users of show_image() have been generating essentially sRGB data with this format. Other formats are also assumed to be gamma compressed; these are converted to a8r8g8b8 before being displayed. With these changes, srgb-test.c doesn't need to do its own conversion anymore. --- diff --git a/demos/composite-test.c b/demos/composite-test.c index dc24f8e..8213e2f 100644 --- a/demos/composite-test.c +++ b/demos/composite-test.c @@ -149,7 +149,7 @@ main (int argc, char **argv) 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); pixman_image_composite (operators[i].op, parrot, NULL, dest_img, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); - pixbuf = pixbuf_from_argb32 (pixman_image_get_data (dest_img), TRUE, + pixbuf = pixbuf_from_argb32 (pixman_image_get_data (dest_img), WIDTH, HEIGHT, WIDTH * 4); image = gtk_image_new_from_pixbuf (pixbuf); gtk_box_pack_start (GTK_BOX (vbox), image, FALSE, FALSE, 0); diff --git a/demos/gtk-utils.c b/demos/gtk-utils.c index 1ff89eb..8291a1e 100644 --- a/demos/gtk-utils.c +++ b/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); diff --git a/demos/gtk-utils.h b/demos/gtk-utils.h index 2cb13bc..55cb701 100644 --- a/demos/gtk-utils.h +++ b/demos/gtk-utils.h @@ -7,7 +7,6 @@ void show_image (pixman_image_t *image); GdkPixbuf *pixbuf_from_argb32 (uint32_t *bits, - gboolean has_alpha, int width, int height, int stride); diff --git a/demos/srgb-test.c b/demos/srgb-test.c index bc07349..681d521 100644 --- a/demos/srgb-test.c +++ b/demos/srgb-test.c @@ -79,15 +79,6 @@ main (int argc, char **argv) pixman_image_unref (src1_img); free (src1); - pixman_image_unref (dest_img); - - /* Now that the picture has been correctly constructed, - * we hand it over to our support library as argb which it - * knows how to handle (it doesn't understand _sRGB format). */ - dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, - WIDTH, HEIGHT, - dest, - WIDTH * 4); show_image (dest_img); pixman_image_unref (dest_img); free (dest);