From 460faaa41105c2939d041506f6ff08e2b12e7596 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=B8ren=20Sandmann=20Pedersen?= Date: Thu, 14 Feb 2013 20:32:31 -0500 Subject: [PATCH] demos: Add linear-gradient demo program This program displays a linear gradient from blue to yellow. Due to limited precision in pixman-gradient-walker.c, it currently has some ugly artefacts that gives it a 'brushed metal' appearance. V2: Update .gitignore --- .gitignore | 1 + demos/Makefile.am | 2 ++ demos/linear-gradient.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 demos/linear-gradient.c diff --git a/.gitignore b/.gitignore index 648699b..584253b 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ demos/composite-test demos/conical-test demos/convolution-test demos/gradient-test +demos/linear-gradient demos/quad2quad demos/radial-test demos/scale diff --git a/demos/Makefile.am b/demos/Makefile.am index 5f53407..9be9ab6 100644 --- a/demos/Makefile.am +++ b/demos/Makefile.am @@ -15,6 +15,7 @@ DEMOS = \ composite-test \ gradient-test \ radial-test \ + linear-gradient \ conical-test \ alpha-test \ screen-test \ @@ -38,6 +39,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) +linear_gradient_SOURCES = linear-gradient.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) diff --git a/demos/linear-gradient.c b/demos/linear-gradient.c new file mode 100644 index 0000000..46433a6 --- /dev/null +++ b/demos/linear-gradient.c @@ -0,0 +1,50 @@ +#include "../test/utils.h" +#include "gtk-utils.h" + +#define WIDTH 1024 +#define HEIGHT 640 + +int +main (int argc, char **argv) +{ + pixman_image_t *src_img, *dest_img; + pixman_gradient_stop_t stops[] = { + { 0x00000, { 0x0000, 0x0000, 0x4444, 0xdddd } }, + { 0x10000, { 0xeeee, 0xeeee, 0x8888, 0xdddd } }, +#if 0 + /* These colors make it very obvious that dithering + * is useful even for 8-bit gradients + */ + { 0x00000, { 0x6666, 0x3333, 0x3333, 0xffff } }, + { 0x10000, { 0x3333, 0x6666, 0x6666, 0xffff } }, +#endif + }; + pixman_point_fixed_t p1, p2; + + enable_divbyzero_exceptions (); + + dest_img = pixman_image_create_bits (PIXMAN_x8r8g8b8, + WIDTH, HEIGHT, + NULL, 0); + + p1.x = p1.y = 0x0000; + p2.x = WIDTH << 16; + p2.y = HEIGHT << 16; + + src_img = pixman_image_create_linear_gradient (&p1, &p2, stops, ARRAY_LENGTH (stops)); + + pixman_image_composite32 (PIXMAN_OP_OVER, + src_img, + NULL, + dest_img, + 0, 0, + 0, 0, + 0, 0, + WIDTH, HEIGHT); + + show_image (dest_img); + + pixman_image_unref (dest_img); + + return 0; +} -- 2.7.4