Home | History | Annotate | Download | only in demos
      1 #include "../test/utils.h"
      2 #include "gtk-utils.h"
      3 
      4 #define SIZE 128
      5 #define GRADIENTS_PER_ROW 7
      6 #define NUM_ROWS ((NUM_GRADIENTS + GRADIENTS_PER_ROW - 1) / GRADIENTS_PER_ROW)
      7 #define WIDTH (SIZE * GRADIENTS_PER_ROW)
      8 #define HEIGHT (SIZE * NUM_ROWS)
      9 #define NUM_GRADIENTS 35
     10 
     11 #define double_to_color(x)					\
     12     (((uint32_t) ((x)*65536)) - (((uint32_t) ((x)*65536)) >> 16))
     13 
     14 #define PIXMAN_STOP(offset,r,g,b,a)		\
     15     { pixman_double_to_fixed (offset),		\
     16 	{					\
     17 	    double_to_color (r),		\
     18 		double_to_color (g),		\
     19 		double_to_color (b),		\
     20 		double_to_color (a)		\
     21 	}					\
     22     }
     23 
     24 
     25 static const pixman_gradient_stop_t stops[] = {
     26     PIXMAN_STOP (0.25,       1, 0, 0, 0.7),
     27     PIXMAN_STOP (0.5,        1, 1, 0, 0.7),
     28     PIXMAN_STOP (0.75,       0, 1, 0, 0.7),
     29     PIXMAN_STOP (1.0,        0, 0, 1, 0.7)
     30 };
     31 
     32 #define NUM_STOPS (sizeof (stops) / sizeof (stops[0]))
     33 
     34 static pixman_image_t *
     35 create_conical (int index)
     36 {
     37     pixman_point_fixed_t c;
     38     double angle;
     39 
     40     c.x = pixman_double_to_fixed (0);
     41     c.y = pixman_double_to_fixed (0);
     42 
     43     angle = (0.5 / NUM_GRADIENTS + index / (double)NUM_GRADIENTS) * 720 - 180;
     44 
     45     return pixman_image_create_conical_gradient (
     46 	&c, pixman_double_to_fixed (angle), stops, NUM_STOPS);
     47 }
     48 
     49 int
     50 main (int argc, char **argv)
     51 {
     52     pixman_transform_t transform;
     53     pixman_image_t *src_img, *dest_img;
     54     int i;
     55 
     56     enable_divbyzero_exceptions ();
     57 
     58     dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
     59 					 WIDTH, HEIGHT,
     60 					 NULL, 0);
     61 
     62     draw_checkerboard (dest_img, 25, 0xffaaaaaa, 0xff888888);
     63 
     64     pixman_transform_init_identity (&transform);
     65 
     66     pixman_transform_translate (NULL, &transform,
     67 				pixman_double_to_fixed (0.5),
     68 				pixman_double_to_fixed (0.5));
     69 
     70     pixman_transform_scale (NULL, &transform,
     71 			    pixman_double_to_fixed (SIZE),
     72 			    pixman_double_to_fixed (SIZE));
     73     pixman_transform_translate (NULL, &transform,
     74 				pixman_double_to_fixed (0.5),
     75 				pixman_double_to_fixed (0.5));
     76 
     77     for (i = 0; i < NUM_GRADIENTS; i++)
     78     {
     79 	int column = i % GRADIENTS_PER_ROW;
     80 	int row = i / GRADIENTS_PER_ROW;
     81 
     82 	src_img = create_conical (i);
     83 	pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL);
     84 
     85 	pixman_image_set_transform (src_img, &transform);
     86 
     87 	pixman_image_composite32 (
     88 	    PIXMAN_OP_OVER, src_img, NULL,dest_img,
     89 	    0, 0, 0, 0, column * SIZE, row * SIZE,
     90 	    SIZE, SIZE);
     91 
     92 	pixman_image_unref (src_img);
     93     }
     94 
     95     show_image (dest_img);
     96 
     97     pixman_image_unref (dest_img);
     98 
     99     return 0;
    100 }
    101