From a5a11df9024f9b7ee6194e0b842cd430f4fb5697 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=B8ren=20Sandmann?= Date: Thu, 10 May 2007 09:16:34 -0400 Subject: [PATCH] Add a transformation to the gradient test --- pixman/pixman.h | 1 + test/gradient-test.c | 54 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/pixman/pixman.h b/pixman/pixman.h index 4157b27..89a79b1 100644 --- a/pixman/pixman.h +++ b/pixman/pixman.h @@ -118,6 +118,7 @@ typedef pixman_fixed_16_16_t pixman_fixed_t; #define pixman_fixed_to_int(f) ((int) ((f) >> 16)) #define pixman_int_to_fixed(i) ((pixman_fixed_t) ((i) << 16)) #define pixman_fixed_to_double(f) (double) ((f) / (double) pixman_fixed_1) +#define pixman_double_to_fixed(d) ((pixman_fixed_t) ((d) * 65536.0)) #define pixman_fixed_frac(f) ((f) & pixman_fixed_1_minus_e) #define pixman_fixed_floor(f) ((f) & ~pixman_fixed_1_minus_e) #define pixman_fixed_ceil(f) pixman_fixed_floor ((f) + pixman_fixed_1_minus_e) diff --git a/test/gradient-test.c b/test/gradient-test.c index 60027dc..2beb38a 100644 --- a/test/gradient-test.c +++ b/test/gradient-test.c @@ -14,23 +14,23 @@ 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 abgr; - + abgr = (argb & 0xff000000) | (argb & 0xff) << 16 | (argb & 0x00ff00) | (argb & 0xff0000) >> 16; - + p_bits[h * (p_stride / 4) + w] = abgr; } } - + return pixbuf; } @@ -45,7 +45,7 @@ on_expose (GtkWidget *widget, GdkEventExpose *expose, gpointer data) gdk_pixbuf_get_height (pixbuf), GDK_RGB_DITHER_NONE, 0, 0); - + return TRUE; } @@ -53,62 +53,76 @@ 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 +#define WIDTH 200 +#define HEIGHT 200 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] = - { - { pixman_int_to_fixed (0), { 0xffff, 0x0000, 0x0000, 0xffff } }, - { pixman_int_to_fixed (1), { 0xffff, 0xffff, 0x0000, 0xffff } } - }; + { + { pixman_int_to_fixed (0), { 0xffff, 0x0000, 0x0000, 0xffff } }, + { pixman_int_to_fixed (1), { 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) }; + 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.005), pixman_double_to_fixed (1.0) } + } + }; + pixman_transform_t id = { + { { pixman_fixed_1, 0, 0 }, + { 0, pixman_fixed_1, 0 }, + { 0, 0, pixman_fixed_1 } } + }; + 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_set_transform (src_img, &id); + 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