int main () { static const pixman_point_fixed_t inner = { 0x0000, 0x0000 }; static const pixman_point_fixed_t outer = { 0x0000, 0x0000 }; static const pixman_fixed_t r_inner = 0; static const pixman_fixed_t r_outer = 64 << 16; static const pixman_gradient_stop_t stops[] = { { 0x00000, { 0x6666, 0x6666, 0x6666, 0xffff } }, { 0x10000, { 0x0000, 0x0000, 0x0000, 0xffff } } }; static const pixman_transform_t transform = { { { 0x0, 0x26ee, 0x0}, { 0xffffeeef, 0x0, 0x0}, { 0x0, 0x0, 0x10000} } }; static const pixman_color_t z = { 0x0000, 0x0000, 0x0000, 0x0000 }; pixman_image_t *dest, *radial, *zero; int i; double before, after; dest = pixman_image_create_bits ( PIXMAN_x8r8g8b8, 640, 429, NULL, -1); zero = pixman_image_create_solid_fill (&z); radial = pixman_image_create_radial_gradient ( &inner, &outer, r_inner, r_outer, stops, ARRAY_LENGTH (stops)); pixman_image_set_transform (radial, &transform); pixman_image_set_repeat (radial, PIXMAN_REPEAT_PAD); #define N_COMPOSITE 500 before = gettime(); for (i = 0; i < N_COMPOSITE; ++i) { before -= gettime(); pixman_image_composite ( PIXMAN_OP_SRC, zero, NULL, dest, 0, 0, 0, 0, 0, 0, 640, 429); before += gettime(); pixman_image_composite32 ( PIXMAN_OP_OVER, radial, NULL, dest, - 150, -158, 0, 0, 0, 0, 640, 361); } after = gettime(); write_png (dest, "radial.png"); printf ("Average time to composite: %f\n", (after - before) / N_COMPOSITE); return 0; }
static pixman_image_t * create_radial_gradient_image (PictGradient *gradient) { PictRadialGradient *radial = (PictRadialGradient *)gradient; pixman_point_fixed_t c1; pixman_point_fixed_t c2; c1.x = radial->c1.x; c1.y = radial->c1.y; c2.x = radial->c2.x; c2.y = radial->c2.y; return pixman_image_create_radial_gradient ( &c1, &c2, radial->c1.radius, radial->c2.radius, (pixman_gradient_stop_t *)gradient->stops, gradient->nstops); }
static pixman_image_t * create_radial (int index) { pixman_point_fixed_t p0, p1; pixman_fixed_t r0, r1; double x0, x1, radius0, radius1, left, right, center; x0 = 0; x1 = 1; radius0 = radiuses[index]; radius1 = radiuses[NUM_GRADIENTS - index - 1]; /* center the gradient */ left = MIN (x0 - radius0, x1 - radius1); right = MAX (x0 + radius0, x1 + radius1); center = (left + right) * 0.5; x0 -= center; x1 -= center; /* scale to make it fit within a 1x1 rect centered in (0,0) */ x0 *= 0.25; x1 *= 0.25; radius0 *= 0.25; radius1 *= 0.25; p0.x = pixman_double_to_fixed (x0); p0.y = pixman_double_to_fixed (0); p1.x = pixman_double_to_fixed (x1); p1.y = pixman_double_to_fixed (0); r0 = pixman_double_to_fixed (radius0); r1 = pixman_double_to_fixed (radius1); return pixman_image_create_radial_gradient (&p0, &p1, r0, r1, stops, NUM_STOPS); }
int main (int argc, char **argv) { #define WIDTH 400 #define HEIGHT 200 uint32_t *dest = malloc (WIDTH * HEIGHT * 4); pixman_image_t *src_img; pixman_image_t *dest_img; int i, j, k, p; typedef struct { pixman_point_fixed_t p0; pixman_point_fixed_t p1; } point_pair_t; pixman_gradient_stop_t onestop[1] = { { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, }; pixman_gradient_stop_t subsetstops[2] = { { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, }; pixman_gradient_stop_t stops01[2] = { { pixman_int_to_fixed (0), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, { pixman_int_to_fixed (1), { 0xffff, 0x1111, 0x1111, 0x1111 } } }; point_pair_t point_pairs [] = { { { pixman_double_to_fixed (0), 0 }, { pixman_double_to_fixed (WIDTH / 8.), pixman_int_to_fixed (0) } }, { { pixman_double_to_fixed (WIDTH / 2.0), pixman_double_to_fixed (HEIGHT / 2.0) }, { pixman_double_to_fixed (WIDTH / 2.0), pixman_double_to_fixed (HEIGHT / 2.0) } } }; pixman_transform_t transformations[] = { { { { pixman_double_to_fixed (2), pixman_double_to_fixed (0.5), pixman_double_to_fixed (-100), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (3), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) } } }, { { { pixman_double_to_fixed (1), pixman_double_to_fixed (0), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) } } }, { { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (2), pixman_double_to_fixed (1.000), pixman_double_to_fixed (1.0) } } }, { { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (0), pixman_double_to_fixed (0) } } }, { { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (2), pixman_double_to_fixed (-1), pixman_double_to_fixed (0) } } }, { { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (3), }, { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (2), pixman_double_to_fixed (-1), pixman_double_to_fixed (0) } } }, }; pixman_fixed_t r_inner; pixman_fixed_t r_outer; enable_divbyzero_exceptions(); for (i = 0; i < WIDTH * HEIGHT; ++i) dest[i] = 0x4f00004f; /* pale blue */ dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, dest, WIDTH * 4); r_inner = 0; r_outer = pixman_double_to_fixed (50.0); for (i = 0; i < 3; ++i) { pixman_gradient_stop_t *stops; int num_stops; if (i == 0) { stops = onestop; num_stops = ARRAY_LENGTH (onestop); } else if (i == 1) { stops = subsetstops; num_stops = ARRAY_LENGTH (subsetstops); } else { stops = stops01; num_stops = ARRAY_LENGTH (stops01); } for (j = 0; j < 3; ++j) { for (p = 0; p < ARRAY_LENGTH (point_pairs); ++p) { point_pair_t *pair = &(point_pairs[p]); if (j == 0) src_img = pixman_image_create_conical_gradient (&(pair->p0), r_inner, stops, num_stops); else if (j == 1) src_img = pixman_image_create_radial_gradient (&(pair->p0), &(pair->p1), r_inner, r_outer, stops, num_stops); else src_img = pixman_image_create_linear_gradient (&(pair->p0), &(pair->p1), stops, num_stops); for (k = 0; k < ARRAY_LENGTH (transformations); ++k) { pixman_image_set_transform (src_img, &transformations[k]); pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NONE); pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img, 0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT); } pixman_image_unref (src_img); } } } pixman_image_unref (dest_img); free (dest); return 0; }
int main (int argc, char **argv) { pixman_image_t *gradient_img; pixman_image_t *src_img, *dst_img; pixman_gradient_stop_t stops[2] = { { pixman_int_to_fixed (0), { 0xffff, 0x0000, 0x0000, 0xffff } }, { pixman_int_to_fixed (1), { 0xffff, 0xffff, 0x0000, 0xffff } } }; pixman_point_fixed_t p1 = { 0, 0 }; pixman_point_fixed_t p2 = { pixman_int_to_fixed (WIDTH), pixman_int_to_fixed (HEIGHT) }; pixman_point_fixed_t c_inner; pixman_point_fixed_t c_outer; pixman_fixed_t r_inner; pixman_fixed_t r_outer; pixman_region32_t clip_region; pixman_transform_t trans = { { { pixman_double_to_fixed (1.3), pixman_double_to_fixed (0), pixman_double_to_fixed (-0.5), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (1), pixman_double_to_fixed (-0.5), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (0), pixman_double_to_fixed (1.0) } } }; src_img = create_solid_bits (0xff0000ff); c_inner.x = pixman_double_to_fixed (100.0); c_inner.y = pixman_double_to_fixed (100.0); c_outer.x = pixman_double_to_fixed (100.0); c_outer.y = pixman_double_to_fixed (100.0); r_inner = 0; r_outer = pixman_double_to_fixed (100.0); gradient_img = pixman_image_create_radial_gradient (&c_inner, &c_outer, r_inner, r_outer, stops, 2); #if 0 gradient_img = pixman_image_create_linear_gradient (&p1, &p2, stops, 2); #endif pixman_image_composite (PIXMAN_OP_OVER, gradient_img, NULL, src_img, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); pixman_region32_init_rect (&clip_region, 50, 0, 100, 200); pixman_image_set_clip_region32 (src_img, &clip_region); pixman_image_set_source_clipping (src_img, TRUE); pixman_image_set_has_client_clip (src_img, TRUE); pixman_image_set_transform (src_img, &trans); pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL); dst_img = create_solid_bits (0xffff0000); pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dst_img, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); #if 0 printf ("0, 0: %x\n", src[0]); printf ("10, 10: %x\n", src[10 * 10 + 10]); printf ("w, h: %x\n", src[(HEIGHT - 1) * 100 + (WIDTH - 1)]); #endif show_image (dst_img); pixman_image_unref (gradient_img); pixman_image_unref (src_img); return 0; }