pixman: Branch 'master' - 2 commits

Søren Sandmann Pedersen sandmann at kemper.freedesktop.org
Sat Apr 4 03:06:09 PDT 2009


 test/Makefile.am      |   36 +++++++++-----
 test/clip-test.c      |   29 ++++++++---
 test/composite-test.c |   33 +++++++++----
 test/gradient-test.c  |   29 ++++++++---
 test/trap-test.c      |  126 ++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 217 insertions(+), 36 deletions(-)

New commits:
commit 47dabe1d025c420a07ac940ab46e5d00c752d2d8
Author: Søren Sandmann Pedersen <ssp at dhcp-100-2-40.bos.redhat.com>
Date:   Sat Apr 4 06:04:42 2009 -0400

    Fix pixbuf_from_argb32() to take premultiplied alpha into account

diff --git a/test/clip-test.c b/test/clip-test.c
index 457e97a..4995083 100644
--- a/test/clip-test.c
+++ b/test/clip-test.c
@@ -20,14 +20,27 @@ pixbuf_from_argb32 (uint32_t *bits,
 	for (w = 0; w < width; ++w)
 	{
 	    uint32_t argb = bits[h * stride + w];
-	    guint32 abgr;
-	    
-	    abgr = (argb & 0xff000000) |
-		(argb & 0xff) << 16 |
-		(argb & 0x00ff00) |
-		(argb & 0xff0000) >> 16;
-	    
-	    p_bits[h * (p_stride / 4) + w] = abgr;
+	    guint r, g, b, a;
+	    char *pb = p_bits;
+
+	    pb += h * p_stride + w * 4;
+
+	    r = (argb & 0x00ff0000) >> 16;
+	    g = (argb & 0x0000ff00) >> 8;
+	    b = (argb & 0x000000ff) >> 0;
+	    a = (argb & 0xff000000) >> 24;
+
+	    if (a)
+	    {
+		r = (r * 255) / a;
+		g = (g * 255) / a;
+		b = (b * 255) / a;
+	    }
+
+	    pb[0] = r;
+	    pb[1] = g;
+	    pb[2] = b;
+	    pb[3] = a;
 	}
     }
     
diff --git a/test/composite-test.c b/test/composite-test.c
index d6596f4..388c8e6 100644
--- a/test/composite-test.c
+++ b/test/composite-test.c
@@ -1,10 +1,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include "pixman.h"
-
 #include <gtk/gtk.h>
 
-static GdkPixbuf *
+GdkPixbuf *
 pixbuf_from_argb32 (uint32_t *bits,
 		    int width,
 		    int height,
@@ -15,20 +14,36 @@ pixbuf_from_argb32 (uint32_t *bits,
     int p_stride = gdk_pixbuf_get_rowstride (pixbuf);
     guint32 *p_bits = (guint32 *)gdk_pixbuf_get_pixels (pixbuf);
     int w, h;
-
+    
     for (h = 0; h < height; ++h)
     {
 	for (w = 0; w < width; ++w)
 	{
 	    uint32_t argb = bits[h * stride + w];
-	    guint32 rgba;
-
-	    rgba = (argb << 8) | (argb >> 24);
-
-	    p_bits[h * (p_stride / 4) + w] = rgba;
+	    guint r, g, b, a;
+	    char *pb = p_bits;
+
+	    pb += h * p_stride + w * 4;
+
+	    r = (argb & 0x00ff0000) >> 16;
+	    g = (argb & 0x0000ff00) >> 8;
+	    b = (argb & 0x000000ff) >> 0;
+	    a = (argb & 0xff000000) >> 24;
+
+	    if (a)
+	    {
+		r = (r * 255) / a;
+		g = (g * 255) / a;
+		b = (b * 255) / a;
+	    }
+
+	    pb[0] = r;
+	    pb[1] = g;
+	    pb[2] = b;
+	    pb[3] = a;
 	}
     }
-
+    
     return pixbuf;
 }
 
diff --git a/test/gradient-test.c b/test/gradient-test.c
index 8a99ff0..806256b 100644
--- a/test/gradient-test.c
+++ b/test/gradient-test.c
@@ -20,14 +20,27 @@ pixbuf_from_argb32 (uint32_t *bits,
 	for (w = 0; w < width; ++w)
 	{
 	    uint32_t argb = bits[h * stride + w];
-	    guint32 abgr;
-	    
-	    abgr = (argb & 0xff000000) |
-		(argb & 0xff) << 16 |
-		(argb & 0x00ff00) |
-		(argb & 0xff0000) >> 16;
-	    
-	    p_bits[h * (p_stride / 4) + w] = abgr;
+	    guint r, g, b, a;
+	    char *pb = p_bits;
+
+	    pb += h * p_stride + w * 4;
+
+	    r = (argb & 0x00ff0000) >> 16;
+	    g = (argb & 0x0000ff00) >> 8;
+	    b = (argb & 0x000000ff) >> 0;
+	    a = (argb & 0xff000000) >> 24;
+
+	    if (a)
+	    {
+		r = (r * 255) / a;
+		g = (g * 255) / a;
+		b = (b * 255) / a;
+	    }
+
+	    pb[0] = r;
+	    pb[1] = g;
+	    pb[2] = b;
+	    pb[3] = a;
 	}
     }
     
commit fb8e9b16d5760aa82c1ca4c180faed964a4e7ff5
Author: Søren Sandmann Pedersen <ssp at dhcp-100-2-40.bos.redhat.com>
Date:   Sat Apr 4 05:57:20 2009 -0400

    Add a new trap-test test program.
    
    Also some tweaks to the build system in the test directory to make it
    build non-gtk+-using application when use of gtk+ is disabled.

diff --git a/test/Makefile.am b/test/Makefile.am
index 31307d4..cccb6f8 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,21 +1,35 @@
-if HAVE_GTK
+TEST_LDADD = $(top_builddir)/pixman/libpixman-1.la
+INCLUDES = -I$(top_srcdir)/pixman -I$(top_builddir)/pixman 
+
 TESTPROGRAMS =			\
-	clip-test		\
-	composite-test		\
-	gradient-test		\
 	region-test		\
 	scaling-test		\
 	fetch-test
 
+fetch_test_LDADD = $(TEST_LDADD)
+region_test_LDADD = $(TEST_LDADD)
+scaling_test_LDADD = $(TEST_LDADD)
+
+# GTK using test programs
+
+if HAVE_GTK
+
+GTK_LDADD = $(TEST_LDADD) $(GTK_LIBS)
+
+TESTPROGRAMS +=			\
+	clip-test		\
+	composite-test		\
+	gradient-test		\
+	trap-test
+
 noinst_PROGRAMS = $(TESTPROGRAMS)
 
-INCLUDES = -I$(top_srcdir)/pixman -I$(top_builddir)/pixman $(GTK_CFLAGS)
+INCLUDES += $(GTK_CFLAGS)
 
-composite_test_LDADD =	$(top_builddir)/pixman/libpixman-1.la $(GTK_LIBS)
-gradient_test_LDADD = $(top_builddir)/pixman/libpixman-1.la $(GTK_LIBS)
-fetch_test_LDADD = $(top_builddir)/pixman/libpixman-1.la
-region_test_LDADD = $(top_builddir)/pixman/libpixman-1.la
-scaling_test_LDADD = $(top_builddir)/pixman/libpixman-1.la
-clip_test_LDADD = $(top_builddir)/pixman/libpixman-1.la $(GTK_LIBS)
+composite_test_LDADD = $(GTK_LDADD)
+gradient_test_LDADD = $(GTK_LDADD)
+clip_test_LDADD = $(GTK_LDADD)
+trap_test_LDADD = $(GTK_LDADD)
 
 endif
+
diff --git a/test/trap-test.c b/test/trap-test.c
new file mode 100644
index 0000000..7750e5a
--- /dev/null
+++ b/test/trap-test.c
@@ -0,0 +1,126 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <gtk/gtk.h>
+#include "pixman.h"
+
+GdkPixbuf *
+pixbuf_from_argb32 (uint32_t *bits,
+		    int width,
+		    int height,
+		    int stride)
+{
+    GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,
+					8, width, height);
+    int p_stride = gdk_pixbuf_get_rowstride (pixbuf);
+    guint32 *p_bits = (guint32 *)gdk_pixbuf_get_pixels (pixbuf);
+    int w, h;
+    
+    for (h = 0; h < height; ++h)
+    {
+	for (w = 0; w < width; ++w)
+	{
+	    uint32_t argb = bits[h * stride + w];
+	    guint r, g, b, a;
+	    char *pb = p_bits;
+
+	    pb += h * p_stride + w * 4;
+
+	    r = (argb & 0x00ff0000) >> 16;
+	    g = (argb & 0x0000ff00) >> 8;
+	    b = (argb & 0x000000ff) >> 0;
+	    a = (argb & 0xff000000) >> 24;
+
+	    if (a)
+	    {
+		r = (r * 255) / a;
+		g = (g * 255) / a;
+		b = (b * 255) / a;
+	    }
+
+	    pb[0] = r;
+	    pb[1] = g;
+	    pb[2] = b;
+	    pb[3] = a;
+	}
+    }
+    
+    return pixbuf;
+}
+
+static gboolean
+on_expose (GtkWidget *widget, GdkEventExpose *expose, gpointer data)
+{
+    GdkPixbuf *pixbuf = data;
+    
+    gdk_draw_pixbuf (widget->window, NULL,
+		     pixbuf, 0, 0, 0, 0,
+		     gdk_pixbuf_get_width (pixbuf),
+		     gdk_pixbuf_get_height (pixbuf),
+		     GDK_RGB_DITHER_NONE,
+		     0, 0);
+    
+    return TRUE;
+}
+
+static void
+show_window (uint32_t *bits, int w, int h, int stride)
+{
+    GdkPixbuf *pixbuf;
+    
+    GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+    
+    pixbuf = pixbuf_from_argb32 (bits, w, h, stride);
+    
+    g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), pixbuf);
+    g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
+    
+    gtk_widget_show (window);
+    
+    gtk_main ();
+}
+
+int
+main (int argc, char **argv)
+{
+#define WIDTH 200
+#define HEIGHT 200
+
+    pixman_image_t *src_img;
+    pixman_image_t *mask_img;
+    pixman_image_t *dest_img;
+    pixman_trap_t trap;
+    pixman_color_t white = { 0x0000, 0xffff, 0x0000, 0xffff };
+    uint32_t *bits = malloc (WIDTH * HEIGHT * 4);
+    uint32_t *mbits = malloc (WIDTH * HEIGHT);
+
+    memset (mbits, 0, WIDTH * HEIGHT);
+    memset (bits, 0xff, WIDTH * HEIGHT * 4);
+    
+    trap.top.l = pixman_int_to_fixed (50) + 0x8000;
+    trap.top.r = pixman_int_to_fixed (150) + 0x8000;
+    trap.top.y = pixman_int_to_fixed (30);
+
+    trap.bot.l = pixman_int_to_fixed (50) + 0x8000;
+    trap.bot.r = pixman_int_to_fixed (150) + 0x8000;
+    trap.bot.y = pixman_int_to_fixed (150);
+
+    mask_img = pixman_image_create_bits (PIXMAN_a8, WIDTH, HEIGHT, mbits, WIDTH);
+    src_img = pixman_image_create_solid_fill (&white);
+    dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, bits, WIDTH * 4);
+    
+    pixman_add_traps (mask_img, 0, 0, 1, &trap);
+
+    pixman_image_composite (PIXMAN_OP_OVER,
+			    src_img, mask_img, dest_img,
+			    0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
+    
+    gtk_init (&argc, &argv);
+    
+    show_window (bits, WIDTH, HEIGHT, WIDTH);
+    
+    pixman_image_unref (src_img);
+    pixman_image_unref (dest_img);
+    free (bits);
+    
+    return 0;
+}


More information about the xorg-commit mailing list