16ba797d6Smrg#include <stdio.h>
26ba797d6Smrg#include <stdlib.h>
36ba797d6Smrg#include "pixman.h"
46ba797d6Smrg#include "gtk-utils.h"
56ba797d6Smrg
66ba797d6Smrg#define WIDTH 200
76ba797d6Smrg#define HEIGHT 200
86ba797d6Smrg
96ba797d6Smrgstatic pixman_image_t *
106ba797d6Smrgcreate_solid_bits (uint32_t pixel)
116ba797d6Smrg{
126ba797d6Smrg    uint32_t *pixels = malloc (WIDTH * HEIGHT * 4);
136ba797d6Smrg    int i;
146ba797d6Smrg
156ba797d6Smrg    for (i = 0; i < WIDTH * HEIGHT; ++i)
166ba797d6Smrg	pixels[i] = pixel;
176ba797d6Smrg
186ba797d6Smrg    return pixman_image_create_bits (PIXMAN_a8r8g8b8,
196ba797d6Smrg				     WIDTH, HEIGHT,
206ba797d6Smrg				     pixels,
216ba797d6Smrg				     WIDTH * 4);
226ba797d6Smrg}
236ba797d6Smrg
246ba797d6Smrgint
256ba797d6Smrgmain (int argc, char **argv)
266ba797d6Smrg{
276ba797d6Smrg    pixman_image_t *gradient_img;
286ba797d6Smrg    pixman_image_t *src_img, *dst_img;
296ba797d6Smrg    pixman_gradient_stop_t stops[2] =
306ba797d6Smrg	{
316ba797d6Smrg	    { pixman_int_to_fixed (0), { 0xffff, 0x0000, 0x0000, 0xffff } },
326ba797d6Smrg	    { pixman_int_to_fixed (1), { 0xffff, 0xffff, 0x0000, 0xffff } }
336ba797d6Smrg	};
346ba797d6Smrg#if 0
356ba797d6Smrg    pixman_point_fixed_t p1 = { 0, 0 };
366ba797d6Smrg    pixman_point_fixed_t p2 = { pixman_int_to_fixed (WIDTH),
376ba797d6Smrg				pixman_int_to_fixed (HEIGHT) };
386ba797d6Smrg#endif
396ba797d6Smrg    pixman_point_fixed_t c_inner;
406ba797d6Smrg    pixman_point_fixed_t c_outer;
416ba797d6Smrg    pixman_fixed_t r_inner;
426ba797d6Smrg    pixman_fixed_t r_outer;
436ba797d6Smrg    pixman_region32_t clip_region;
446ba797d6Smrg    pixman_transform_t trans = {
456ba797d6Smrg	{ { pixman_double_to_fixed (1.3), pixman_double_to_fixed (0), pixman_double_to_fixed (-0.5), },
466ba797d6Smrg	  { pixman_double_to_fixed (0), pixman_double_to_fixed (1), pixman_double_to_fixed (-0.5), },
476ba797d6Smrg	  { pixman_double_to_fixed (0), pixman_double_to_fixed (0), pixman_double_to_fixed (1.0) }
486ba797d6Smrg	}
496ba797d6Smrg    };
506ba797d6Smrg
516ba797d6Smrg    src_img = create_solid_bits (0xff0000ff);
526ba797d6Smrg
536ba797d6Smrg    c_inner.x = pixman_double_to_fixed (100.0);
546ba797d6Smrg    c_inner.y = pixman_double_to_fixed (100.0);
556ba797d6Smrg    c_outer.x = pixman_double_to_fixed (100.0);
566ba797d6Smrg    c_outer.y = pixman_double_to_fixed (100.0);
576ba797d6Smrg    r_inner = 0;
586ba797d6Smrg    r_outer = pixman_double_to_fixed (100.0);
596ba797d6Smrg
606ba797d6Smrg    gradient_img = pixman_image_create_radial_gradient (&c_inner, &c_outer,
616ba797d6Smrg							r_inner, r_outer,
626ba797d6Smrg							stops, 2);
636ba797d6Smrg
646ba797d6Smrg#if 0
656ba797d6Smrg    gradient_img = pixman_image_create_linear_gradient  (&p1, &p2,
666ba797d6Smrg							 stops, 2);
676ba797d6Smrg
686ba797d6Smrg#endif
696ba797d6Smrg
706ba797d6Smrg    pixman_image_composite (PIXMAN_OP_OVER, gradient_img, NULL, src_img,
716ba797d6Smrg			    0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
726ba797d6Smrg
736ba797d6Smrg    pixman_region32_init_rect (&clip_region, 50, 0, 100, 200);
746ba797d6Smrg    pixman_image_set_clip_region32 (src_img, &clip_region);
756ba797d6Smrg    pixman_image_set_source_clipping (src_img, TRUE);
766ba797d6Smrg    pixman_image_set_has_client_clip (src_img, TRUE);
776ba797d6Smrg    pixman_image_set_transform (src_img, &trans);
786ba797d6Smrg    pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL);
796ba797d6Smrg
806ba797d6Smrg    dst_img = create_solid_bits (0xffff0000);
816ba797d6Smrg    pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dst_img,
826ba797d6Smrg			    0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
836ba797d6Smrg
846ba797d6Smrg
856ba797d6Smrg#if 0
866ba797d6Smrg    printf ("0, 0: %x\n", src[0]);
876ba797d6Smrg    printf ("10, 10: %x\n", src[10 * 10 + 10]);
886ba797d6Smrg    printf ("w, h: %x\n", src[(HEIGHT - 1) * 100 + (WIDTH - 1)]);
896ba797d6Smrg#endif
906ba797d6Smrg
916ba797d6Smrg    show_image (dst_img);
926ba797d6Smrg
936ba797d6Smrg    pixman_image_unref (gradient_img);
946ba797d6Smrg    pixman_image_unref (src_img);
956ba797d6Smrg
966ba797d6Smrg    return 0;
976ba797d6Smrg}
98