From e047f605e2e9ef4f23e63c38259c5ceb720060dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=B8ren=20Sandmann=20Pedersen?= Date: Mon, 4 May 2009 18:34:54 -0400 Subject: [PATCH] Move all the GTK+ test code into its own file, utils.c --- pixman/pixman.h | 2 +- test/Makefile.am | 11 ++++- test/clip-test.c | 82 +----------------------------------- test/composite-test.c | 93 ++-------------------------------------- test/fetch-test.c | 2 - test/gradient-test.c | 114 ++++++++++---------------------------------------- test/trap-test.c | 82 +----------------------------------- test/utils.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ test/utils.h | 6 +++ 9 files changed, 157 insertions(+), 348 deletions(-) create mode 100644 test/utils.c create mode 100644 test/utils.h diff --git a/pixman/pixman.h b/pixman/pixman.h index d207b56..7ae425c 100644 --- a/pixman/pixman.h +++ b/pixman/pixman.h @@ -779,7 +779,7 @@ void pixman_image_set_indexed (pixman_image_t *image, uint32_t *pixman_image_get_data (pixman_image_t *image); int pixman_image_get_width (pixman_image_t *image); int pixman_image_get_height (pixman_image_t *image); -int pixman_image_get_stride (pixman_image_t *image); +int pixman_image_get_stride (pixman_image_t *image); /* in bytes */ int pixman_image_get_depth (pixman_image_t *image); pixman_bool_t pixman_image_fill_rectangles (pixman_op_t op, pixman_image_t *image, diff --git a/test/Makefile.am b/test/Makefile.am index 1beac5b..3889c56 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,5 +1,5 @@ TEST_LDADD = $(top_builddir)/pixman/libpixman-1.la -INCLUDES = -I$(top_srcdir)/pixman -I$(top_builddir)/pixman +INCLUDES = -I$(top_srcdir)/pixman -I$(top_builddir)/pixman TESTPROGRAMS = \ region-test \ @@ -28,10 +28,17 @@ noinst_PROGRAMS = $(TESTPROGRAMS) INCLUDES += $(GTK_CFLAGS) -composite_test_LDADD = $(GTK_LDADD) gradient_test_LDADD = $(GTK_LDADD) +gradient_test_SOURCES = gradient-test.c utils.c + +composite_test_LDADD = $(GTK_LDADD) +composite_test_SOURCES = composite-test.c utils.c + clip_test_LDADD = $(GTK_LDADD) +clip_test_SOURCES = clip-test.c utils.c + trap_test_LDADD = $(GTK_LDADD) +trap_test_SOURCES = trap-test.c utils.c endif diff --git a/test/clip-test.c b/test/clip-test.c index 4995083..90310f4 100644 --- a/test/clip-test.c +++ b/test/clip-test.c @@ -1,83 +1,7 @@ #include #include -#include #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 (pixman_image_t *img, int w, int h, int stride) -{ - GdkPixbuf *pixbuf; - - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - pixbuf = pixbuf_from_argb32 (pixman_image_get_data (img), 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 (); -} +#include "utils.h" #define WIDTH 200 #define HEIGHT 200 @@ -122,8 +46,6 @@ main (int argc, char **argv) } }; - gtk_init (&argc, &argv); - src_img = create_solid_bits (0xff0000ff); c_inner.x = pixman_double_to_fixed (100.0); @@ -163,7 +85,7 @@ main (int argc, char **argv) printf ("w, h: %x\n", src[(HEIGHT - 1) * 100 + (WIDTH - 1)]); #endif - show_window (dst_img, WIDTH, HEIGHT, WIDTH); + show_image (dst_img); pixman_image_unref (gradient_img); pixman_image_unref (src_img); diff --git a/test/composite-test.c b/test/composite-test.c index 388c8e6..eaa8820 100644 --- a/test/composite-test.c +++ b/test/composite-test.c @@ -1,82 +1,7 @@ #include #include #include "pixman.h" -#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]; - 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); - - gtk_widget_show (window); - - gtk_main (); -} +#include "utils.h" #define WIDTH 100 #define HEIGHT 100 @@ -123,8 +48,7 @@ main (int argc, char **argv) uint32_t *dest = malloc (WIDTH * HEIGHT * 4); pixman_image_t *src_img; pixman_image_t *dest_img; - int i, j; - gtk_init (&argc, &argv); + int i; for (i = 0; i < WIDTH * HEIGHT; ++i) src[i] = 0x7f7f0000; /* red */ @@ -148,23 +72,12 @@ main (int argc, char **argv) pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); -#if 0 - for (i = 0; i < WIDTH; ++i) - { - for (j = 0; j < HEIGHT; ++j) - g_print ("%x, ", dest[i * WIDTH + j]); - g_print ("\n"); - } -#endif - - show_window (dest, WIDTH, HEIGHT, WIDTH); + show_image (dest_img); pixman_image_unref (src_img); pixman_image_unref (dest_img); free (src); free (dest); - - return 0; } diff --git a/test/fetch-test.c b/test/fetch-test.c index 717f6d4..c41f1a6 100644 --- a/test/fetch-test.c +++ b/test/fetch-test.c @@ -3,10 +3,8 @@ #include #include "pixman.h" - #define SIZE 1024 - pixman_indexed_t mono_pallete = { .rgba = { 0x00000000, 0x00ffffff }, }; diff --git a/test/gradient-test.c b/test/gradient-test.c index 806256b..c3a0d1c 100644 --- a/test/gradient-test.c +++ b/test/gradient-test.c @@ -1,88 +1,12 @@ #include #include -#include #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 (); -} +#include "utils.h" int main (int argc, char **argv) { -#define WIDTH 200 +#define WIDTH 400 #define HEIGHT 200 uint32_t *dest = malloc (WIDTH * HEIGHT * 4); @@ -91,16 +15,16 @@ main (int argc, char **argv) int i; pixman_gradient_stop_t stops[2] = { - { pixman_int_to_fixed (0), { 0xffff, 0x0000, 0x0000, 0xffff } }, - { pixman_int_to_fixed (1), { 0xffff, 0xffff, 0x0000, 0xffff } } + { pixman_int_to_fixed (0), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, + { pixman_int_to_fixed (1), { 0xffff, 0x1111, 0x1111, 0x1111 } } }; - pixman_point_fixed_t p1 = { 0, 0 }; - pixman_point_fixed_t p2 = { pixman_int_to_fixed (WIDTH), - pixman_int_to_fixed (HEIGHT) }; + pixman_point_fixed_t p1 = { pixman_double_to_fixed (0), 0 }; + pixman_point_fixed_t p2 = { pixman_double_to_fixed (WIDTH / 8.), + pixman_int_to_fixed (0) }; pixman_transform_t trans = { { { pixman_double_to_fixed (2), pixman_double_to_fixed (0.5), pixman_double_to_fixed (-100), }, - { pixman_double_to_fixed (0), pixman_double_to_fixed (2), pixman_double_to_fixed (0), }, - { pixman_double_to_fixed (0), pixman_double_to_fixed (0.004990), pixman_double_to_fixed (1.0) } + { pixman_double_to_fixed (0), pixman_double_to_fixed (3), pixman_double_to_fixed (0), }, + { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) } } }; @@ -115,10 +39,8 @@ main (int argc, char **argv) pixman_fixed_t r_inner; pixman_fixed_t r_outer; - gtk_init (&argc, &argv); - for (i = 0; i < WIDTH * HEIGHT; ++i) - dest[i] = 0x3f0000ff; /* pale blue */ + dest[i] = 0x4f00004f; /* pale blue */ dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, @@ -135,22 +57,28 @@ main (int argc, char **argv) src_img = pixman_image_create_radial_gradient (&c_inner, &c_outer, r_inner, r_outer, stops, 2); - #if 0 + src_img = pixman_image_create_conical_gradient (&c_inner, r_inner, + stops, 2); + src_img = pixman_image_create_linear_gradient (&c_inner, &c_outer, + r_inner, r_outer, + stops, 2); +#endif + src_img = pixman_image_create_linear_gradient (&p1, &p2, stops, 2); -#endif - pixman_image_set_transform (src_img, &trans); + pixman_image_set_transform (src_img, &id); + pixman_image_set_repeat (src_img, PIXMAN_REPEAT_PAD); pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img, - 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); + 0, 0, 0, 0, 0, 0, 10 * 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); + show_image (dest_img); pixman_image_unref (src_img); pixman_image_unref (dest_img); diff --git a/test/trap-test.c b/test/trap-test.c index adf796d..1da439b 100644 --- a/test/trap-test.c +++ b/test/trap-test.c @@ -1,84 +1,8 @@ #include #include -#include #include #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 = (char *)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 (); -} +#include "utils.h" int main (int argc, char **argv) @@ -115,9 +39,7 @@ main (int argc, char **argv) src_img, mask_img, dest_img, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); - gtk_init (&argc, &argv); - - show_window (bits, WIDTH, HEIGHT, WIDTH); + show_image (dest_img); pixman_image_unref (src_img); pixman_image_unref (dest_img); diff --git a/test/utils.c b/test/utils.c new file mode 100644 index 0000000..a609315 --- /dev/null +++ b/test/utils.c @@ -0,0 +1,113 @@ +#include +#include +#include "pixman-private.h" /* For image->bits.format + * FIXME: there should probably be public API for this + */ +#include "utils.h" + +GdkPixbuf * +pixbuf_from_argb32 (uint32_t *bits, + gboolean has_alpha, + 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 / 4) + w]; + guint r, g, b, a; + char *pb = (char *)p_bits; + + pb += h * p_stride + w * 4; + + r = (argb & 0x00ff0000) >> 16; + g = (argb & 0x0000ff00) >> 8; + b = (argb & 0x000000ff) >> 0; + a = has_alpha? (argb & 0xff000000) >> 24 : 0xff; + + if (a) + { + r = (r * 255) / a; + g = (g * 255) / a; + b = (b * 255) / a; + } + + if (r > 255) r = 255; + if (g > 255) g = 255; + if (b > 255) b = 255; + + 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; +} + +void +show_image (pixman_image_t *image) +{ + GtkWidget *window; + GdkPixbuf *pixbuf; + int width, height, stride; + int argc; + char **argv; + char *arg0 = g_strdup ("pixman-test-program"); + gboolean has_alpha; + pixman_format_code_t format; + + argc = 1; + argv = (char **)&arg0; + + gtk_init (&argc, &argv); + + 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); + + format = image->bits.format; + + 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); + + 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 (); +} diff --git a/test/utils.h b/test/utils.h new file mode 100644 index 0000000..bc110d8 --- /dev/null +++ b/test/utils.h @@ -0,0 +1,6 @@ +#include +#include +#include +#include "pixman.h" + +void show_image (pixman_image_t *image); -- 2.7.4