11b18d63aSmrg#include <stdio.h> 21b18d63aSmrg#include <stdlib.h> 3953d7d37Smrg#include "utils.h" 41b18d63aSmrg 51b18d63aSmrgint 61b18d63aSmrgmain (int argc, char **argv) 71b18d63aSmrg{ 81b18d63aSmrg#define WIDTH 400 91b18d63aSmrg#define HEIGHT 200 101b18d63aSmrg 111b18d63aSmrg uint32_t *dest = malloc (WIDTH * HEIGHT * 4); 121b18d63aSmrg pixman_image_t *src_img; 131b18d63aSmrg pixman_image_t *dest_img; 14953d7d37Smrg int i, j, k, p; 151b18d63aSmrg 16953d7d37Smrg typedef struct 17953d7d37Smrg { 18953d7d37Smrg pixman_point_fixed_t p0; 19953d7d37Smrg pixman_point_fixed_t p1; 20953d7d37Smrg } point_pair_t; 21953d7d37Smrg 221b18d63aSmrg pixman_gradient_stop_t onestop[1] = 231b18d63aSmrg { 241b18d63aSmrg { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, 251b18d63aSmrg }; 261b18d63aSmrg 271b18d63aSmrg pixman_gradient_stop_t subsetstops[2] = 281b18d63aSmrg { 291b18d63aSmrg { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, 301b18d63aSmrg { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, 311b18d63aSmrg }; 321b18d63aSmrg 331b18d63aSmrg pixman_gradient_stop_t stops01[2] = 341b18d63aSmrg { 351b18d63aSmrg { pixman_int_to_fixed (0), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, 361b18d63aSmrg { pixman_int_to_fixed (1), { 0xffff, 0x1111, 0x1111, 0x1111 } } 371b18d63aSmrg }; 381b18d63aSmrg 39953d7d37Smrg point_pair_t point_pairs [] = 40953d7d37Smrg { { { pixman_double_to_fixed (0), 0 }, 41953d7d37Smrg { pixman_double_to_fixed (WIDTH / 8.), pixman_int_to_fixed (0) } }, 42953d7d37Smrg { { pixman_double_to_fixed (WIDTH / 2.0), pixman_double_to_fixed (HEIGHT / 2.0) }, 43953d7d37Smrg { pixman_double_to_fixed (WIDTH / 2.0), pixman_double_to_fixed (HEIGHT / 2.0) } } 44953d7d37Smrg }; 45953d7d37Smrg 46953d7d37Smrg pixman_transform_t transformations[] = { 47953d7d37Smrg { 48953d7d37Smrg { { pixman_double_to_fixed (2), pixman_double_to_fixed (0.5), pixman_double_to_fixed (-100), }, 49953d7d37Smrg { pixman_double_to_fixed (0), pixman_double_to_fixed (3), pixman_double_to_fixed (0), }, 50953d7d37Smrg { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) } 51953d7d37Smrg } 52953d7d37Smrg }, 53953d7d37Smrg { 54953d7d37Smrg { { pixman_double_to_fixed (1), pixman_double_to_fixed (0), pixman_double_to_fixed (0), }, 55953d7d37Smrg { pixman_double_to_fixed (0), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, 56953d7d37Smrg { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) } 57953d7d37Smrg } 58953d7d37Smrg }, 59953d7d37Smrg { 60953d7d37Smrg { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, 61953d7d37Smrg { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, 62953d7d37Smrg { pixman_double_to_fixed (2), pixman_double_to_fixed (1.000), pixman_double_to_fixed (1.0) } 63953d7d37Smrg } 64953d7d37Smrg }, 65953d7d37Smrg { 66953d7d37Smrg { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, 67953d7d37Smrg { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, 68953d7d37Smrg { pixman_double_to_fixed (0), pixman_double_to_fixed (0), pixman_double_to_fixed (0) } 69953d7d37Smrg } 70953d7d37Smrg }, 71953d7d37Smrg { 72953d7d37Smrg { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, 73953d7d37Smrg { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, 74953d7d37Smrg { pixman_double_to_fixed (2), pixman_double_to_fixed (-1), pixman_double_to_fixed (0) } 75953d7d37Smrg } 76953d7d37Smrg }, 77953d7d37Smrg { 78953d7d37Smrg { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (3), }, 79953d7d37Smrg { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, 80953d7d37Smrg { pixman_double_to_fixed (2), pixman_double_to_fixed (-1), pixman_double_to_fixed (0) } 81953d7d37Smrg } 82953d7d37Smrg }, 831b18d63aSmrg }; 84953d7d37Smrg 851b18d63aSmrg pixman_fixed_t r_inner; 861b18d63aSmrg pixman_fixed_t r_outer; 87953d7d37Smrg 889ad247e8Sjmcneill enable_divbyzero_exceptions(); 891b18d63aSmrg 901b18d63aSmrg for (i = 0; i < WIDTH * HEIGHT; ++i) 911b18d63aSmrg dest[i] = 0x4f00004f; /* pale blue */ 921b18d63aSmrg 931b18d63aSmrg dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, 941b18d63aSmrg WIDTH, HEIGHT, 951b18d63aSmrg dest, 961b18d63aSmrg WIDTH * 4); 971b18d63aSmrg 981b18d63aSmrg r_inner = 0; 991b18d63aSmrg r_outer = pixman_double_to_fixed (50.0); 1001b18d63aSmrg 1011b18d63aSmrg for (i = 0; i < 3; ++i) 1021b18d63aSmrg { 1031b18d63aSmrg pixman_gradient_stop_t *stops; 1041b18d63aSmrg int num_stops; 105953d7d37Smrg 1061b18d63aSmrg if (i == 0) 1071b18d63aSmrg { 1081b18d63aSmrg stops = onestop; 1099ad247e8Sjmcneill num_stops = ARRAY_LENGTH (onestop); 1101b18d63aSmrg } 1111b18d63aSmrg else if (i == 1) 1121b18d63aSmrg { 1131b18d63aSmrg stops = subsetstops; 1149ad247e8Sjmcneill num_stops = ARRAY_LENGTH (subsetstops); 1151b18d63aSmrg } 1161b18d63aSmrg else 1171b18d63aSmrg { 1181b18d63aSmrg stops = stops01; 1199ad247e8Sjmcneill num_stops = ARRAY_LENGTH (stops01); 1201b18d63aSmrg } 1211b18d63aSmrg 1221b18d63aSmrg for (j = 0; j < 3; ++j) 1231b18d63aSmrg { 124953d7d37Smrg for (p = 0; p < ARRAY_LENGTH (point_pairs); ++p) 125953d7d37Smrg { 126953d7d37Smrg point_pair_t *pair = &(point_pairs[p]); 127953d7d37Smrg 128953d7d37Smrg if (j == 0) 129953d7d37Smrg src_img = pixman_image_create_conical_gradient (&(pair->p0), r_inner, 130953d7d37Smrg stops, num_stops); 131953d7d37Smrg else if (j == 1) 132953d7d37Smrg src_img = pixman_image_create_radial_gradient (&(pair->p0), &(pair->p1), 133953d7d37Smrg r_inner, r_outer, 134953d7d37Smrg stops, num_stops); 135953d7d37Smrg else 136953d7d37Smrg src_img = pixman_image_create_linear_gradient (&(pair->p0), &(pair->p1), 137953d7d37Smrg stops, num_stops); 138953d7d37Smrg 139953d7d37Smrg for (k = 0; k < ARRAY_LENGTH (transformations); ++k) 140953d7d37Smrg { 141953d7d37Smrg pixman_image_set_transform (src_img, &transformations[k]); 142953d7d37Smrg 143953d7d37Smrg pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NONE); 144953d7d37Smrg pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img, 145953d7d37Smrg 0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT); 146953d7d37Smrg } 147953d7d37Smrg 148953d7d37Smrg pixman_image_unref (src_img); 149953d7d37Smrg } 1501b18d63aSmrg 1511b18d63aSmrg } 1521b18d63aSmrg } 1531b18d63aSmrg 1541b18d63aSmrg pixman_image_unref (dest_img); 1551b18d63aSmrg free (dest); 1561b18d63aSmrg 1571b18d63aSmrg return 0; 1581b18d63aSmrg} 159