diff options
author | marha <marha@users.sourceforge.net> | 2009-07-25 15:41:56 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2009-07-25 15:41:56 +0000 |
commit | 4b195776d5fb64e83a4e56627367d8e9ea10cbf7 (patch) | |
tree | aa09d8e4f20fe439598711149b209a6ef45f5b0c /pixman/test/composite-test.c | |
parent | 2fb179f86b0f9ecb7876759b87f9c64634a3f114 (diff) | |
download | vcxsrv-4b195776d5fb64e83a4e56627367d8e9ea10cbf7.tar.gz vcxsrv-4b195776d5fb64e83a4e56627367d8e9ea10cbf7.tar.bz2 vcxsrv-4b195776d5fb64e83a4e56627367d8e9ea10cbf7.zip |
Added pixman-0.15.18.tar.gz
Diffstat (limited to 'pixman/test/composite-test.c')
-rw-r--r-- | pixman/test/composite-test.c | 212 |
1 files changed, 123 insertions, 89 deletions
diff --git a/pixman/test/composite-test.c b/pixman/test/composite-test.c index d6596f496..49e0220a4 100644 --- a/pixman/test/composite-test.c +++ b/pixman/test/composite-test.c @@ -1,70 +1,49 @@ +#include <gtk/gtk.h> #include <stdlib.h> #include <stdio.h> #include "pixman.h" - -#include <gtk/gtk.h> - -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 (); -} - -#define WIDTH 100 -#define HEIGHT 100 +#include "utils.h" + +#define WIDTH 60 +#define HEIGHT 60 + +typedef struct { + const char *name; + pixman_op_t op; +} operator_t; + +static const operator_t operators[] = { + { "CLEAR", PIXMAN_OP_CLEAR }, + { "SRC", PIXMAN_OP_SRC }, + { "DST", PIXMAN_OP_DST }, + { "OVER", PIXMAN_OP_OVER }, + { "OVER_REVERSE", PIXMAN_OP_OVER_REVERSE }, + { "IN", PIXMAN_OP_IN }, + { "IN_REVERSE", PIXMAN_OP_IN_REVERSE }, + { "OUT", PIXMAN_OP_OUT }, + { "OUT_REVERSE", PIXMAN_OP_OUT_REVERSE }, + { "ATOP", PIXMAN_OP_ATOP }, + { "ATOP_REVERSE", PIXMAN_OP_ATOP_REVERSE }, + { "XOR", PIXMAN_OP_XOR }, + { "ADD", PIXMAN_OP_ADD }, + { "SATURATE", PIXMAN_OP_SATURATE }, + + { "MULTIPLY", PIXMAN_OP_MULTIPLY }, + { "SCREEN", PIXMAN_OP_SCREEN }, + { "OVERLAY", PIXMAN_OP_OVERLAY }, + { "DARKEN", PIXMAN_OP_DARKEN }, + { "LIGHTEN", PIXMAN_OP_LIGHTEN }, + { "COLOR_DODGE", PIXMAN_OP_COLOR_DODGE }, + { "COLOR_BURN", PIXMAN_OP_COLOR_BURN }, + { "HARD_LIGHT", PIXMAN_OP_HARD_LIGHT }, + { "SOFT_LIGHT", PIXMAN_OP_SOFT_LIGHT }, + { "DIFFERENCE", PIXMAN_OP_DIFFERENCE }, + { "EXCLUSION", PIXMAN_OP_EXCLUSION }, + { "HSL_HUE", PIXMAN_OP_HSL_HUE }, + { "HSL_SATURATION", PIXMAN_OP_HSL_SATURATION }, + { "HSL_COLOR", PIXMAN_OP_HSL_COLOR }, + { "HSL_LUMINOSITY", PIXMAN_OP_HSL_LUMINOSITY }, +}; static uint32_t reader (const void *src, int size) @@ -104,52 +83,107 @@ writer (void *src, uint32_t value, int size) int main (int argc, char **argv) { - uint32_t *src = malloc (WIDTH * HEIGHT * 4); +#define d2f pixman_double_to_fixed + + GtkWidget *window, *swindow; + GtkWidget *table; uint32_t *dest = malloc (WIDTH * HEIGHT * 4); + uint32_t *src = malloc (WIDTH * HEIGHT * 4); pixman_image_t *src_img; pixman_image_t *dest_img; - int i, j; + pixman_point_fixed_t p1 = { -10 << 0, 0 }; + pixman_point_fixed_t p2 = { WIDTH << 16, (HEIGHT - 10) << 16 }; + uint16_t full = 0xcfff; + uint16_t low = 0x5000; + uint16_t alpha = 0xffff; + pixman_gradient_stop_t stops[6] = + { + { d2f (0.0), { full, low, low, alpha } }, + { d2f (0.25), { full, full, low, alpha } }, + { d2f (0.4), { low, full, low, alpha } }, + { d2f (0.5), { low, full, full, alpha } }, + { d2f (0.8), { low, low, full, alpha } }, + { d2f (1.0), { full, low, full, alpha } }, + }; + + + int i; + gtk_init (&argc, &argv); - for (i = 0; i < WIDTH * HEIGHT; ++i) - src[i] = 0x7f7f0000; /* red */ + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - for (i = 0; i < WIDTH * HEIGHT; ++i) - dest[i] = 0x7f0000ff; /* blue */ + gtk_window_set_default_size (window, 800, 600); - src_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, - WIDTH, HEIGHT, - src, - WIDTH * 4); + g_signal_connect (window, "delete-event", + G_CALLBACK (gtk_main_quit), + NULL); + table = gtk_table_new (G_N_ELEMENTS (operators) / 6, 6, TRUE); + src_img = pixman_image_create_linear_gradient (&p1, &p2, stops, + sizeof (stops) / sizeof (stops[0])); + + pixman_image_set_repeat (src_img, PIXMAN_REPEAT_PAD); + dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, dest, WIDTH * 4); - - pixman_image_set_accessors (src_img, reader, writer); pixman_image_set_accessors (dest_img, reader, writer); - - 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 (i = 0; i < G_N_ELEMENTS (operators); ++i) { + GtkWidget *image; + GdkPixbuf *pixbuf; + GtkWidget *vbox; + GtkWidget *label; + int j, k; + + vbox = gtk_vbox_new (FALSE, 0); + + label = gtk_label_new (operators[i].name); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 6); + gtk_widget_show (label); + for (j = 0; j < HEIGHT; ++j) - g_print ("%x, ", dest[i * WIDTH + j]); - g_print ("\n"); + { + for (k = 0; k < WIDTH; ++k) + dest[j * WIDTH + k] = 0x7f6f6f00; + } + pixman_image_composite (operators[i].op, src_img, NULL, dest_img, + 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); + pixbuf = pixbuf_from_argb32 (pixman_image_get_data (dest_img), TRUE, + WIDTH, HEIGHT, WIDTH * 4); + image = gtk_image_new_from_pixbuf (pixbuf); + gtk_box_pack_start (GTK_BOX (vbox), image, FALSE, FALSE, 0); + gtk_widget_show (image); + + gtk_table_attach_defaults (GTK_TABLE (table), vbox, + i % 6, (i % 6) + 1, i / 6, (i / 6) + 1); + gtk_widget_show (vbox); + + g_object_unref (pixbuf); } -#endif - - show_window (dest, WIDTH, HEIGHT, WIDTH); - + pixman_image_unref (src_img); - pixman_image_unref (dest_img); free (src); + pixman_image_unref (dest_img); free (dest); - + swindow = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (swindow), table); + gtk_widget_show (table); + + gtk_container_add (GTK_CONTAINER (window), swindow); + gtk_widget_show (swindow); + + gtk_widget_show (window); + + gtk_main (); + return 0; } |