pixman: Branch 'master' - 3 commits

Søren Sandmann Pedersen sandmann at kemper.freedesktop.org
Thu Aug 9 08:41:54 PDT 2012


 demos/Makefile.am       |    2 
 demos/composite-test.c  |    2 
 demos/gtk-utils.c       |   51 ++++++++++++++------
 demos/gtk-utils.h       |    1 
 demos/srgb-test.c       |    9 ---
 demos/srgb-trap-test.c  |  119 ++++++++++++++++++++++++++++++++++++++++++++++++
 pixman/pixman-private.h |    5 ++
 7 files changed, 163 insertions(+), 26 deletions(-)

New commits:
commit 09cb1ae10b1976970233c934d27c36e0a4203e1c
Author: Søren Sandmann Pedersen <ssp at redhat.com>
Date:   Sat Jun 9 09:15:53 2012 -0400

    demos: Add srgb_trap_test.c
    
    This demo program composites a bunch of trapezoids side by side with
    and without gamma aware compositing.

diff --git a/demos/Makefile.am b/demos/Makefile.am
index d8fb0da..f324f5f 100644
--- a/demos/Makefile.am
+++ b/demos/Makefile.am
@@ -21,6 +21,7 @@ DEMOS =				\
 	tri-test		\
 	quad2quad		\
 	checkerboard		\
+	srgb-trap-test		\
 	srgb-test
 
 EXTRA_DIST = parrot.c parrot.jpg
@@ -37,6 +38,7 @@ radial_test_SOURCES = radial-test.c $(GTK_UTILS)
 tri_test_SOURCES = tri-test.c $(GTK_UTILS)
 checkerboard_SOURCES = checkerboard.c $(GTK_UTILS)
 srgb_test_SOURCES = srgb-test.c $(GTK_UTILS)
+srgb_trap_test_SOURCES = srgb-trap-test.c $(GTK_UTILS)
 
 noinst_PROGRAMS = $(DEMOS)
 
diff --git a/demos/srgb-trap-test.c b/demos/srgb-trap-test.c
new file mode 100644
index 0000000..d5ae16a
--- /dev/null
+++ b/demos/srgb-trap-test.c
@@ -0,0 +1,119 @@
+#include <math.h>
+#include "pixman.h"
+#include "gtk-utils.h"
+
+#define F(x)								\
+    pixman_double_to_fixed (x)
+
+#define WIDTH 600
+#define HEIGHT 300
+
+static uint16_t
+convert_to_srgb (uint16_t in)
+{
+    double d = in * (1/65535.0);
+    double a = 0.055;
+
+    if (d < 0.0031308)
+	d = 12.92 * d;
+    else
+	d = (1 + a) * pow (d, 1 / 2.4) - a;
+
+    return (d * 65535.0) + 0.5;
+}
+
+static void
+convert_color (pixman_color_t *dest_srgb, pixman_color_t *linear)
+{
+    dest_srgb->alpha = convert_to_srgb (linear->alpha);
+    dest_srgb->red = convert_to_srgb (linear->red);
+    dest_srgb->green = convert_to_srgb (linear->green);
+    dest_srgb->blue = convert_to_srgb (linear->blue);
+}
+
+int
+main (int argc, char **argv)
+{
+    static const pixman_trapezoid_t traps[] =
+    {
+	{ F(10.10), F(280.0),
+	  { { F(20.0), F(10.10) },
+	    { F(5.3), F(280.0) } },
+	  { { F(20.3), F(10.10) },
+	    { F(5.6), F(280.0) } }
+	},
+	{ F(10.10), F(280.0),
+	  { { F(40.0), F(10.10) },
+	    { F(15.3), F(280.0) } },
+	  { { F(41.0), F(10.10) },
+	    { F(16.3), F(280.0) } }
+	},
+	{ F(10.10), F(280.0),
+	  { { F(120.0), F(10.10) },
+	    { F(5.3), F(280.0) } },
+	  { { F(128.3), F(10.10) },
+	    { F(6.6), F(280.0) } }
+	},
+	{ F(10.10), F(280.0),
+	  { { F(60.0), F(10.10) },
+	    { F(25.3), F(280.0) } },
+	  { { F(61.0), F(10.10) },
+	    { F(26.3), F(280.0) } }
+	},
+	{ F(10.10), F(280.0),
+	  { { F(90.0), F(10.10) },
+	    { F(55.3), F(280.0) } },
+	  { { F(93.0), F(10.10) },
+	    { F(58.3), F(280.0) } }
+	},
+	{ F(130.10), F(150.0),
+	  { { F(100.0), F(130.10) },
+	    { F(250.3), F(150.0) } },
+	  { { F(110.0), F(130.10) },
+	    { F(260.3), F(150.0) } }
+	},
+	{ F(170.10), F(240.0),
+	  { { F(100.0), F(170.10) },
+	    { F(120.3), F(240.0) } },
+	  { { F(250.0), F(170.10) },
+	    { F(250.3), F(240.0) } }
+	},
+    };
+
+    pixman_image_t *src, *dest_srgb, *dest_linear;
+    pixman_color_t bg = { 0x0000, 0x0000, 0x0000, 0xffff };
+    pixman_color_t fg = { 0xffff, 0xffff, 0xffff, 0xffff };
+    pixman_color_t fg_srgb;
+    uint32_t *d;
+
+    d = malloc (WIDTH * HEIGHT * 4);
+    
+    dest_srgb = pixman_image_create_bits (
+	PIXMAN_a8r8g8b8_sRGB, WIDTH, HEIGHT, d, WIDTH * 4);
+    dest_linear = pixman_image_create_bits (
+	PIXMAN_a8r8g8b8, WIDTH, HEIGHT, d, WIDTH * 4);
+    
+    src = pixman_image_create_solid_fill (&bg);
+    pixman_image_composite32 (PIXMAN_OP_SRC,
+			      src, NULL, dest_srgb,
+			      0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
+    
+    src = pixman_image_create_solid_fill (&fg);
+    
+    pixman_composite_trapezoids (PIXMAN_OP_OVER,
+				 src, dest_srgb, PIXMAN_a8,
+				 0, 0, 10, 10, G_N_ELEMENTS (traps), traps);
+
+    convert_color (&fg_srgb, &fg);
+    src = pixman_image_create_solid_fill (&fg_srgb);
+    
+    pixman_composite_trapezoids (PIXMAN_OP_OVER,
+				 src, dest_linear, PIXMAN_a8,
+				 0, 0, 310, 10, G_N_ELEMENTS (traps), traps);
+
+    show_image (dest_linear);
+    pixman_image_unref(dest_linear);
+    free(d);
+    
+    return 0;
+}
commit 04e878c231ad3624c57e51a5fcdc55a177d4dc0f
Author: Søren Sandmann Pedersen <ssp at redhat.com>
Date:   Sat Jun 9 09:42:56 2012 -0400

    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);
commit 8db9ec9814a3dcd8211ec60cd4fd3c9ae9d77924
Author: Søren Sandmann Pedersen <ssp at redhat.com>
Date:   Tue Jul 31 15:01:16 2012 -0400

    Define TIMER_BEGIN and TIMER_END even when timers are not enabled
    
    This allows code that uses these macros to build when timers are
    disabled.

diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index d5e6a72..dbfa829 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -1082,6 +1082,11 @@ void pixman_timer_register (pixman_timer_t *timer);
     timer ## tname.total += OIL_STAMP () - begin ## tname;		\
     }
 
+#else
+
+#define TIMER_BEGIN(tname)
+#define TIMER_END(tname)
+
 #endif /* PIXMAN_TIMERS */
 
 /* sRGB<->linear conversion tables. Linear color space is the same


More information about the xorg-commit mailing list