19ad247e8Sjmcneill#include <stdio.h>
29ad247e8Sjmcneill#include <stdlib.h>
39ad247e8Sjmcneill#include "pixman.h"
49ad247e8Sjmcneill#include "gtk-utils.h"
59ad247e8Sjmcneill
69ad247e8Sjmcneillint
79ad247e8Sjmcneillmain (int argc, char **argv)
89ad247e8Sjmcneill{
99ad247e8Sjmcneill#define WIDTH 400
109ad247e8Sjmcneill#define HEIGHT 400
119ad247e8Sjmcneill#define TILE_SIZE 25
129ad247e8Sjmcneill
139ad247e8Sjmcneill    pixman_image_t *checkerboard;
149ad247e8Sjmcneill    pixman_image_t *destination;
159ad247e8Sjmcneill#define D2F(d) (pixman_double_to_fixed(d))
169ad247e8Sjmcneill    pixman_transform_t trans = { {
179ad247e8Sjmcneill	    { D2F (-1.96830), D2F (-1.82250), D2F (512.12250)},
189ad247e8Sjmcneill	    { D2F (0.00000), D2F (-7.29000), D2F (1458.00000)},
199ad247e8Sjmcneill	    { D2F (0.00000), D2F (-0.00911), D2F (0.59231)},
209ad247e8Sjmcneill	}};
219ad247e8Sjmcneill    int i, j;
229ad247e8Sjmcneill
239ad247e8Sjmcneill    checkerboard = pixman_image_create_bits (PIXMAN_a8r8g8b8,
249ad247e8Sjmcneill					     WIDTH, HEIGHT,
259ad247e8Sjmcneill					     NULL, 0);
269ad247e8Sjmcneill
279ad247e8Sjmcneill    destination = pixman_image_create_bits (PIXMAN_a8r8g8b8,
289ad247e8Sjmcneill					    WIDTH, HEIGHT,
299ad247e8Sjmcneill					    NULL, 0);
309ad247e8Sjmcneill
319ad247e8Sjmcneill    for (i = 0; i < HEIGHT / TILE_SIZE; ++i)
329ad247e8Sjmcneill    {
339ad247e8Sjmcneill	for (j = 0; j < WIDTH / TILE_SIZE; ++j)
349ad247e8Sjmcneill	{
359ad247e8Sjmcneill	    double u = (double)(j + 1) / (WIDTH / TILE_SIZE);
369ad247e8Sjmcneill	    double v = (double)(i + 1) / (HEIGHT / TILE_SIZE);
379ad247e8Sjmcneill	    pixman_color_t black = { 0, 0, 0, 0xffff };
389ad247e8Sjmcneill	    pixman_color_t white = {
399ad247e8Sjmcneill		v * 0xffff,
409ad247e8Sjmcneill		u * 0xffff,
419ad247e8Sjmcneill		(1 - (double)u) * 0xffff,
429ad247e8Sjmcneill		0xffff };
439ad247e8Sjmcneill	    pixman_color_t *c;
449ad247e8Sjmcneill	    pixman_image_t *fill;
459ad247e8Sjmcneill
469ad247e8Sjmcneill	    if ((j & 1) != (i & 1))
479ad247e8Sjmcneill		c = &black;
489ad247e8Sjmcneill	    else
499ad247e8Sjmcneill		c = &white;
509ad247e8Sjmcneill
519ad247e8Sjmcneill	    fill = pixman_image_create_solid_fill (c);
529ad247e8Sjmcneill
539ad247e8Sjmcneill	    pixman_image_composite (PIXMAN_OP_SRC, fill, NULL, checkerboard,
549ad247e8Sjmcneill				    0, 0, 0, 0, j * TILE_SIZE, i * TILE_SIZE,
559ad247e8Sjmcneill				    TILE_SIZE, TILE_SIZE);
569ad247e8Sjmcneill	}
579ad247e8Sjmcneill    }
589ad247e8Sjmcneill
599ad247e8Sjmcneill    pixman_image_set_transform (checkerboard, &trans);
609ad247e8Sjmcneill    pixman_image_set_filter (checkerboard, PIXMAN_FILTER_BEST, NULL, 0);
619ad247e8Sjmcneill    pixman_image_set_repeat (checkerboard, PIXMAN_REPEAT_NONE);
629ad247e8Sjmcneill
639ad247e8Sjmcneill    pixman_image_composite (PIXMAN_OP_SRC,
649ad247e8Sjmcneill			    checkerboard, NULL, destination,
659ad247e8Sjmcneill			    0, 0, 0, 0, 0, 0,
669ad247e8Sjmcneill			    WIDTH, HEIGHT);
679ad247e8Sjmcneill
689ad247e8Sjmcneill    show_image (destination);
699ad247e8Sjmcneill
709ad247e8Sjmcneill    return 0;
719ad247e8Sjmcneill}
72