Home | History | Annotate | Download | only in demos
      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include "pixman.h"
      4 #include "gtk-utils.h"
      5 
      6 int
      7 main (int argc, char **argv)
      8 {
      9 #define WIDTH 400
     10 #define HEIGHT 400
     11 #define TILE_SIZE 25
     12 
     13     pixman_image_t *checkerboard;
     14     pixman_image_t *destination;
     15 #define D2F(d) (pixman_double_to_fixed(d))
     16     pixman_transform_t trans = { {
     17 	    { D2F (-1.96830), D2F (-1.82250), D2F (512.12250)},
     18 	    { D2F (0.00000), D2F (-7.29000), D2F (1458.00000)},
     19 	    { D2F (0.00000), D2F (-0.00911), D2F (0.59231)},
     20 	}};
     21     int i, j;
     22 
     23     checkerboard = pixman_image_create_bits (PIXMAN_a8r8g8b8,
     24 					     WIDTH, HEIGHT,
     25 					     NULL, 0);
     26 
     27     destination = pixman_image_create_bits (PIXMAN_a8r8g8b8,
     28 					    WIDTH, HEIGHT,
     29 					    NULL, 0);
     30 
     31     for (i = 0; i < HEIGHT / TILE_SIZE; ++i)
     32     {
     33 	for (j = 0; j < WIDTH / TILE_SIZE; ++j)
     34 	{
     35 	    double u = (double)(j + 1) / (WIDTH / TILE_SIZE);
     36 	    double v = (double)(i + 1) / (HEIGHT / TILE_SIZE);
     37 	    pixman_color_t black = { 0, 0, 0, 0xffff };
     38 	    pixman_color_t white = {
     39 		v * 0xffff,
     40 		u * 0xffff,
     41 		(1 - (double)u) * 0xffff,
     42 		0xffff };
     43 	    pixman_color_t *c;
     44 	    pixman_image_t *fill;
     45 
     46 	    if ((j & 1) != (i & 1))
     47 		c = &black;
     48 	    else
     49 		c = &white;
     50 
     51 	    fill = pixman_image_create_solid_fill (c);
     52 
     53 	    pixman_image_composite (PIXMAN_OP_SRC, fill, NULL, checkerboard,
     54 				    0, 0, 0, 0, j * TILE_SIZE, i * TILE_SIZE,
     55 				    TILE_SIZE, TILE_SIZE);
     56 	}
     57     }
     58 
     59     pixman_image_set_transform (checkerboard, &trans);
     60     pixman_image_set_filter (checkerboard, PIXMAN_FILTER_BEST, NULL, 0);
     61     pixman_image_set_repeat (checkerboard, PIXMAN_REPEAT_NONE);
     62 
     63     pixman_image_composite (PIXMAN_OP_SRC,
     64 			    checkerboard, NULL, destination,
     65 			    0, 0, 0, 0, 0, 0,
     66 			    WIDTH, HEIGHT);
     67 
     68     show_image (destination);
     69 
     70     return 0;
     71 }
     72