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 #define WIDTH 200
      7 #define HEIGHT 200
      8 
      9 static pixman_image_t *
     10 create_solid_bits (uint32_t pixel)
     11 {
     12     uint32_t *pixels = malloc (WIDTH * HEIGHT * 4);
     13     int i;
     14 
     15     for (i = 0; i < WIDTH * HEIGHT; ++i)
     16 	pixels[i] = pixel;
     17 
     18     return pixman_image_create_bits (PIXMAN_a8r8g8b8,
     19 				     WIDTH, HEIGHT,
     20 				     pixels,
     21 				     WIDTH * 4);
     22 }
     23 
     24 int
     25 main (int argc, char **argv)
     26 {
     27     pixman_image_t *gradient_img;
     28     pixman_image_t *src_img, *dst_img;
     29     pixman_gradient_stop_t stops[2] =
     30 	{
     31 	    { pixman_int_to_fixed (0), { 0xffff, 0x0000, 0x0000, 0xffff } },
     32 	    { pixman_int_to_fixed (1), { 0xffff, 0xffff, 0x0000, 0xffff } }
     33 	};
     34 #if 0
     35     pixman_point_fixed_t p1 = { 0, 0 };
     36     pixman_point_fixed_t p2 = { pixman_int_to_fixed (WIDTH),
     37 				pixman_int_to_fixed (HEIGHT) };
     38 #endif
     39     pixman_point_fixed_t c_inner;
     40     pixman_point_fixed_t c_outer;
     41     pixman_fixed_t r_inner;
     42     pixman_fixed_t r_outer;
     43     pixman_region32_t clip_region;
     44     pixman_transform_t trans = {
     45 	{ { pixman_double_to_fixed (1.3), pixman_double_to_fixed (0), pixman_double_to_fixed (-0.5), },
     46 	  { pixman_double_to_fixed (0), pixman_double_to_fixed (1), pixman_double_to_fixed (-0.5), },
     47 	  { pixman_double_to_fixed (0), pixman_double_to_fixed (0), pixman_double_to_fixed (1.0) }
     48 	}
     49     };
     50 
     51     src_img = create_solid_bits (0xff0000ff);
     52 
     53     c_inner.x = pixman_double_to_fixed (100.0);
     54     c_inner.y = pixman_double_to_fixed (100.0);
     55     c_outer.x = pixman_double_to_fixed (100.0);
     56     c_outer.y = pixman_double_to_fixed (100.0);
     57     r_inner = 0;
     58     r_outer = pixman_double_to_fixed (100.0);
     59 
     60     gradient_img = pixman_image_create_radial_gradient (&c_inner, &c_outer,
     61 							r_inner, r_outer,
     62 							stops, 2);
     63 
     64 #if 0
     65     gradient_img = pixman_image_create_linear_gradient  (&p1, &p2,
     66 							 stops, 2);
     67 
     68 #endif
     69 
     70     pixman_image_composite (PIXMAN_OP_OVER, gradient_img, NULL, src_img,
     71 			    0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
     72 
     73     pixman_region32_init_rect (&clip_region, 50, 0, 100, 200);
     74     pixman_image_set_clip_region32 (src_img, &clip_region);
     75     pixman_image_set_source_clipping (src_img, TRUE);
     76     pixman_image_set_has_client_clip (src_img, TRUE);
     77     pixman_image_set_transform (src_img, &trans);
     78     pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL);
     79 
     80     dst_img = create_solid_bits (0xffff0000);
     81     pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dst_img,
     82 			    0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
     83 
     84 
     85 #if 0
     86     printf ("0, 0: %x\n", src[0]);
     87     printf ("10, 10: %x\n", src[10 * 10 + 10]);
     88     printf ("w, h: %x\n", src[(HEIGHT - 1) * 100 + (WIDTH - 1)]);
     89 #endif
     90 
     91     show_image (dst_img);
     92 
     93     pixman_image_unref (gradient_img);
     94     pixman_image_unref (src_img);
     95 
     96     return 0;
     97 }
     98