From 0ebb7e31db85a179afdcd731fcc6b0e311084cb1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=B8ren=20Sandmann?= Date: Wed, 9 May 2007 18:10:30 -0400 Subject: [PATCH] Remove AM_MAINTAINER_MODE ; add new gradient-test --- configure.ac | 1 - test/Makefile.am | 12 ++++-- test/composite-test.c | 80 +++++++++++++++++++++++++++++++++-- test/gradient-test.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 200 insertions(+), 7 deletions(-) create mode 100644 test/gradient-test.c diff --git a/configure.ac b/configure.ac index fa8a9a9..8b5217e 100644 --- a/configure.ac +++ b/configure.ac @@ -25,7 +25,6 @@ AC_PREREQ([2.57]) AC_INIT(pixman, 0.9.0, "sandmann@daimi.au.dk", pixman) AM_INIT_AUTOMAKE([dist-bzip2]) -AM_MAINTAINER_MODE AM_CONFIG_HEADER(config.h) diff --git a/test/Makefile.am b/test/Makefile.am index d9c7c44..fedbcdc 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,8 +1,14 @@ TESTPROGRAMS = \ - composite-test + composite-test \ + gradient-test noinst_PROGRAMS = $(TESTPROGRAMS) -INCLUDES = -I$(top_srcdir)/pixman +INCLUDES = -I$(top_srcdir)/pixman `pkg-config --cflags gtk+-2.0` + +GTKLIBS = -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpng12 -lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 + +composite_test_LDADD = $(top_builddir)/pixman/libpixman.la $(GTKLIBS) +gradient_test_LDADD = $(top_builddir)/pixman/libpixman.la $(GTKLIBS) + -composite_test_LDADD = $(top_builddir)/pixman/libpixman.la diff --git a/test/composite-test.c b/test/composite-test.c index 798b06a..bc09943 100644 --- a/test/composite-test.c +++ b/test/composite-test.c @@ -2,15 +2,76 @@ #include #include "pixman.h" +#include + +static 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]; + guint32 rgba; + + rgba = (argb << 8) | (argb >> 24); + + p_bits[h * (p_stride / 4) + w] = rgba; + } + } + + 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); + + gtk_widget_show (window); + + gtk_main (); +} + int -main () +main (int argc, char **argv) { uint32_t *src = malloc (10 * 10 * 4); uint32_t *dest = malloc (10 * 10 * 4); pixman_image_t *src_img; pixman_image_t *dest_img; - - int i; + int i, j; + gtk_init (&argc, &argv); for (i = 0; i < 10 * 10; ++i) src[i] = 0x7f7f0000; /* red */ @@ -31,8 +92,21 @@ main () pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img, 0, 0, 0, 0, 0, 0, 10, 10); + for (i = 0; i < 10; ++i) + { + for (j = 0; j < 10; ++j) + g_print ("%x, ", dest[i * 10 + j]); + g_print ("\n"); + } + + show_window (dest, 10, 10, 10); + pixman_image_unref (src_img); pixman_image_unref (dest_img); + free (src); + free (dest); + + return 0; } diff --git a/test/gradient-test.c b/test/gradient-test.c new file mode 100644 index 0000000..4501ea7 --- /dev/null +++ b/test/gradient-test.c @@ -0,0 +1,114 @@ +#include +#include +#include +#include + +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]; + guint32 abgr; + + abgr = (argb & 0xff000000) | + (argb & 0xff) << 16 | + (argb & 0x00ff00) | + (argb & 0xff0000) >> 16; + + p_bits[h * (p_stride / 4) + w] = abgr; + } + } + + 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); + + gtk_widget_show (window); + + gtk_main (); +} + +int +main (int argc, char **argv) +{ +#define WIDTH 100 +#define HEIGHT 100 + + uint32_t *dest = malloc (WIDTH * HEIGHT * 4); + pixman_image_t *src_img; + pixman_image_t *dest_img; + int i; + pixman_gradient_stop_t stops[2] = + { + { 0.0, { 0xffff, 0x0000, 0x0000, 0xffff } }, + { 1.0, { 0xffff, 0xffff, 0x0000, 0xffff } } + }; + pixman_point_fixed_t p1 = { 0, 0 }; + pixman_point_fixed_t p2 = { pixman_int_to_fixed (WIDTH), + pixman_int_to_fixed (HEIGHT) }; + + gtk_init (&argc, &argv); + + for (i = 0; i < WIDTH * HEIGHT; ++i) + dest[i] = 0x3f0000ff; /* pale blue */ + + dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, + WIDTH, HEIGHT, + dest, + WIDTH * 4); + + src_img = pixman_image_create_linear_gradient (&p1, &p2, + stops, 2); + + pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img, + 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); + + printf ("0, 0: %x\n", dest[0]); + printf ("10, 10: %x\n", dest[10 * 10 + 10]); + printf ("w, h: %x\n", dest[(HEIGHT - 1) * 100 + (WIDTH - 1)]); + + show_window (dest, WIDTH, HEIGHT, WIDTH); + + pixman_image_unref (src_img); + pixman_image_unref (dest_img); + free (dest); + + return 0; +} -- 2.7.4