diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-12-04 13:17:49 -0500 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-12-08 10:50:51 -0500 |
commit | 4f18ba30cea56331e30992242201b20954c8f7f2 (patch) | |
tree | 5d508af54db3e449c576538d4d70c3c356dc08d1 /demos | |
parent | 3a98787bddeb007a1cd2b86235205774c15250f2 (diff) |
Add demo program for conical gradients
This new test is derived from radial-test.c and displays conical
gradients at various angles.
It also demonstrates how PIXMAN_REPEAT_NORMAL is supposed to work when
used with a gradient specification where the first stop is not a 0.0:
In this case the gradient is supposed to have a smooth transition from
the last stop back to the first stop with no sharp transitions. It
also shows that the repeat mode is not ignored for conical gradients
as one might be tempted to think.
Diffstat (limited to 'demos')
-rw-r--r-- | demos/Makefile.am | 2 | ||||
-rw-r--r-- | demos/conical-test.c | 134 |
2 files changed, 136 insertions, 0 deletions
diff --git a/demos/Makefile.am b/demos/Makefile.am index 9e9db81..3f2a3fa 100644 --- a/demos/Makefile.am +++ b/demos/Makefile.am @@ -15,6 +15,7 @@ DEMOS = \ composite-test \ gradient-test \ radial-test \ + conical-test \ alpha-test \ screen-test \ convolution-test \ @@ -37,6 +38,7 @@ trap_test_SOURCES = trap-test.c $(GTK_UTILS) screen_test_SOURCES = screen-test.c $(GTK_UTILS) convolution_test_SOURCES = convolution-test.c $(GTK_UTILS) radial_test_SOURCES = radial-test.c $(GTK_UTILS) +conical_test_SOURCES = conical-test.c $(GTK_UTILS) tri_test_SOURCES = tri-test.c $(GTK_UTILS) checkerboard_SOURCES = checkerboard.c $(GTK_UTILS) srgb_test_SOURCES = srgb-test.c $(GTK_UTILS) diff --git a/demos/conical-test.c b/demos/conical-test.c new file mode 100644 index 0000000..1e08e42 --- /dev/null +++ b/demos/conical-test.c @@ -0,0 +1,134 @@ +#include "../test/utils.h" +#include "gtk-utils.h" + +#define SIZE 128 +#define GRADIENTS_PER_ROW 7 +#define NUM_ROWS ((NUM_GRADIENTS + GRADIENTS_PER_ROW - 1) / GRADIENTS_PER_ROW) +#define WIDTH (SIZE * GRADIENTS_PER_ROW) +#define HEIGHT (SIZE * NUM_ROWS) +#define NUM_GRADIENTS 35 + +#define double_to_color(x) \ + (((uint32_t) ((x)*65536)) - (((uint32_t) ((x)*65536)) >> 16)) + +#define PIXMAN_STOP(offset,r,g,b,a) \ + { pixman_double_to_fixed (offset), \ + { \ + double_to_color (r), \ + double_to_color (g), \ + double_to_color (b), \ + double_to_color (a) \ + } \ + } + + +static const pixman_gradient_stop_t stops[] = { + PIXMAN_STOP (0.25, 1, 0, 0, 0.7), + PIXMAN_STOP (0.5, 1, 1, 0, 0.7), + PIXMAN_STOP (0.75, 0, 1, 0, 0.7), + PIXMAN_STOP (1.0, 0, 0, 1, 0.7) +}; + +#define NUM_STOPS (sizeof (stops) / sizeof (stops[0])) + +static pixman_image_t * +create_conical (int index) +{ + pixman_point_fixed_t c; + double angle; + + c.x = pixman_double_to_fixed (0); + c.y = pixman_double_to_fixed (0); + + angle = (0.5 / NUM_GRADIENTS + index / (double)NUM_GRADIENTS) * 720 - 180; + + return pixman_image_create_conical_gradient ( + &c, pixman_double_to_fixed (angle), stops, NUM_STOPS); +} + +#define CHECK_SIZE 25 + +static void +fill_checkerboard (pixman_image_t *image, int width, int height) +{ +#define C1 0xaaaa +#define C2 0x8888 + + pixman_color_t check1 = { C1, C1, C1, 0xffff }; + pixman_color_t check2 = { C2, C2, C2, 0xffff }; + pixman_image_t *c1, *c2; + int i, j; + + c1 = pixman_image_create_solid_fill (&check1); + c2 = pixman_image_create_solid_fill (&check2); + + for (j = 0; j < height; j += CHECK_SIZE) + { + for (i = 0; i < width; i += CHECK_SIZE) + { + pixman_image_t *src; + + if ((((i / CHECK_SIZE) ^ (j / CHECK_SIZE)) & 1) == 0) + src = c1; + else + src = c2; + + pixman_image_composite32 (PIXMAN_OP_SRC, src, NULL, image, + 0, 0, 0, 0, i, j, + CHECK_SIZE, CHECK_SIZE); + } + } +} + +int +main (int argc, char **argv) +{ + pixman_transform_t transform; + pixman_image_t *src_img, *dest_img; + int i; + + enable_divbyzero_exceptions (); + + dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, + WIDTH, HEIGHT, + NULL, 0); + + fill_checkerboard (dest_img, WIDTH, HEIGHT); + + pixman_transform_init_identity (&transform); + + pixman_transform_translate (NULL, &transform, + pixman_double_to_fixed (0.5), + pixman_double_to_fixed (0.5)); + + pixman_transform_scale (NULL, &transform, + pixman_double_to_fixed (SIZE), + pixman_double_to_fixed (SIZE)); + pixman_transform_translate (NULL, &transform, + pixman_double_to_fixed (0.5), + pixman_double_to_fixed (0.5)); + + for (i = 0; i < NUM_GRADIENTS; i++) + { + int column = i % GRADIENTS_PER_ROW; + int row = i / GRADIENTS_PER_ROW; + + src_img = create_conical (i); + pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL); + + pixman_image_set_transform (src_img, &transform); + + pixman_image_composite32 ( + PIXMAN_OP_OVER, src_img, NULL,dest_img, + 0, 0, 0, 0, column * SIZE, row * SIZE, + SIZE, SIZE); + + pixman_image_unref (src_img); + } + + show_image (dest_img); + + pixman_image_unref (dest_img); + + return 0; +} |