예제 #1
0
int
main (int argc, char **argv)
{
    uint8_t *alpha = make_random_bytes (WIDTH * HEIGHT);
    uint32_t *src = (uint32_t *)make_random_bytes (WIDTH * HEIGHT * 4);
    uint32_t *dest = (uint32_t *)make_random_bytes (WIDTH * HEIGHT * 4);

    pixman_image_t *a = pixman_image_create_bits (PIXMAN_a8, WIDTH, HEIGHT, (uint32_t *)alpha, WIDTH);
    pixman_image_t *d = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, dest, WIDTH * 4);
    pixman_image_t *s = pixman_image_create_bits (PIXMAN_a2r10g10b10, WIDTH, HEIGHT, src, WIDTH * 4);

    fail_after (5, "Infinite loop detected: 5 seconds without progress\n");

    pixman_image_set_alpha_map (s, a, 0, 0);
    pixman_image_set_alpha_map (a, s, 0, 0);

    pixman_image_composite (PIXMAN_OP_SRC, s, NULL, d, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);

    pixman_image_unref (s);

    return 0;
}
예제 #2
0
파일: alphamap.c 프로젝트: aosm/X11libs
static pixman_image_t *
create_image (pixman_format_code_t format, pixman_format_code_t alpha_format,
	      int alpha_origin_x, int alpha_origin_y)
{
    pixman_image_t *image = make_image (format);

    if (alpha_format != PIXMAN_null)
    {
	pixman_image_t *alpha = make_image (alpha_format);

	pixman_image_set_alpha_map (image, alpha,
				    alpha_origin_x, alpha_origin_y);
	pixman_image_unref (alpha);
    }

    return image;
}
예제 #3
0
int
main (int argc, char **argv)
{
#define WIDTH 400
#define HEIGHT 200
    
    uint32_t *alpha = malloc (WIDTH * HEIGHT * 4);
    uint32_t *dest = malloc (WIDTH * HEIGHT * 4);
    uint32_t *src = malloc (WIDTH * HEIGHT * 4);
    pixman_image_t *grad_img;
    pixman_image_t *alpha_img;
    pixman_image_t *dest_img;
    pixman_image_t *src_img;
    int i;
    pixman_gradient_stop_t stops[2] =
	{
	    { pixman_int_to_fixed (0), { 0x0000, 0x0000, 0x0000, 0x0000 } },
	    { pixman_int_to_fixed (1), { 0xffff, 0x0000, 0x1111, 0xffff } }
	};
    pixman_point_fixed_t p1 = { pixman_double_to_fixed (0), 0 };
    pixman_point_fixed_t p2 = { pixman_double_to_fixed (WIDTH),
				pixman_int_to_fixed (0) };
#if 0
    pixman_transform_t trans = {
	{ { 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) } 
	}
    };
#else
    pixman_transform_t trans = {
	{ { pixman_fixed_1, 0, 0 },
	  { 0, pixman_fixed_1, 0 },
	  { 0, 0, pixman_fixed_1 } }
    };
#endif

    pixman_point_fixed_t c_inner;
    pixman_point_fixed_t c_outer;
    pixman_fixed_t r_inner;
    pixman_fixed_t r_outer;
    
    for (i = 0; i < WIDTH * HEIGHT; ++i)
	alpha[i] = 0x4f00004f; /* pale blue */
    
    alpha_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
					 WIDTH, HEIGHT, 
					  alpha,
					 WIDTH * 4);

    for (i = 0; i < WIDTH * HEIGHT; ++i)
	dest[i] = 0xffffff00;		/* yellow */
    
    dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
					 WIDTH, HEIGHT, 
					 dest,
					 WIDTH * 4);

    for (i = 0; i < WIDTH * HEIGHT; ++i)
	src[i] = 0xffff0000;

    src_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
					WIDTH, HEIGHT,
					src,
					WIDTH * 4);
    
    c_inner.x = pixman_double_to_fixed (50.0);
    c_inner.y = pixman_double_to_fixed (50.0);
    c_outer.x = pixman_double_to_fixed (50.0);
    c_outer.y = pixman_double_to_fixed (50.0);
    r_inner = 0;
    r_outer = pixman_double_to_fixed (50.0);
    
#if 0
    grad_img = pixman_image_create_conical_gradient (&c_inner, r_inner,
						    stops, 2);
#endif
#if 0
    grad_img = pixman_image_create_conical_gradient (&c_inner, r_inner,
						    stops, 2);
    grad_img = pixman_image_create_linear_gradient (&c_inner, &c_outer,
						   r_inner, r_outer,
						   stops, 2);
#endif
    
    grad_img = pixman_image_create_linear_gradient  (&p1, &p2,
						    stops, 2);

    pixman_image_set_transform (grad_img, &trans);
    pixman_image_set_repeat (grad_img, PIXMAN_REPEAT_PAD);
    
    pixman_image_composite (PIXMAN_OP_OVER, grad_img, NULL, alpha_img,
			    0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT);

    pixman_image_set_alpha_map (src_img, alpha_img, 10, 10);
    
    pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img,
			    0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT);
    
    printf ("0, 0: %x\n", dest[0]);
    printf ("10, 10: %x\n", dest[10 * 10 + 10]);
    printf ("w, h: %x\n", dest[(HEIGHT - 1) * 100 + (WIDTH - 1)]);
    
    show_image (dest_img);

    pixman_image_unref (src_img);
    pixman_image_unref (grad_img);
    pixman_image_unref (alpha_img);
    free (dest);
    
    return 0;
}
예제 #4
0
static void
set_image_properties(pixman_image_t * image, PicturePtr pict, Bool has_clip,
                     int *xoff, int *yoff, Bool is_alpha_map)
{
    pixman_repeat_t repeat;
    pixman_filter_t filter;

    if (pict->transform) {
        /* For source images, adjust the transform to account
         * for the drawable offset within the pixman image,
         * then set the offset to 0 as it will be used
         * to compute positions within the transformed image.
         */
        if (!has_clip) {
            struct pixman_transform adjusted;

            adjusted = *pict->transform;
            pixman_transform_translate(&adjusted,
                                       NULL,
                                       pixman_int_to_fixed(*xoff),
                                       pixman_int_to_fixed(*yoff));
            pixman_image_set_transform(image, &adjusted);
            *xoff = 0;
            *yoff = 0;
        }
        else
            pixman_image_set_transform(image, pict->transform);
    }

    switch (pict->repeatType) {
    default:
    case RepeatNone:
        repeat = PIXMAN_REPEAT_NONE;
        break;

    case RepeatPad:
        repeat = PIXMAN_REPEAT_PAD;
        break;

    case RepeatNormal:
        repeat = PIXMAN_REPEAT_NORMAL;
        break;

    case RepeatReflect:
        repeat = PIXMAN_REPEAT_REFLECT;
        break;
    }

    pixman_image_set_repeat(image, repeat);

    /* Fetch alpha map unless 'pict' is being used
     * as the alpha map for this operation
     */
    if (pict->alphaMap && !is_alpha_map) {
        int alpha_xoff, alpha_yoff;
        pixman_image_t *alpha_map =
            image_from_pict_internal(pict->alphaMap, FALSE, &alpha_xoff,
                                     &alpha_yoff, TRUE);

        pixman_image_set_alpha_map(image, alpha_map, pict->alphaOrigin.x,
                                   pict->alphaOrigin.y);

        free_pixman_pict(pict->alphaMap, alpha_map);
    }

    pixman_image_set_component_alpha(image, pict->componentAlpha);

    switch (pict->filter) {
    default:
    case PictFilterNearest:
    case PictFilterFast:
        filter = PIXMAN_FILTER_NEAREST;
        break;

    case PictFilterBilinear:
    case PictFilterGood:
        filter = PIXMAN_FILTER_BILINEAR;
        break;

    case PictFilterConvolution:
        filter = PIXMAN_FILTER_CONVOLUTION;
        break;
    }

    if (pict->pDrawable)
        pixman_image_set_destroy_function(image, &image_destroy,
                                          pict->pDrawable);

    pixman_image_set_filter(image, filter,
                            (pixman_fixed_t *) pict->filter_params,
                            pict->filter_nparams);
    pixman_image_set_source_clipping(image, TRUE);
}
예제 #5
0
static pixman_image_t *
create_image (int max_size, const pixman_format_code_t *formats, uint32_t flags)
{
    int width, height;
    pixman_image_t *image;
    pixman_format_code_t format;
    uint32_t *data;
    int bpp;
    int stride;
    int i;
    pixman_image_destroy_func_t destroy;

    if ((flags & ALLOW_SOLID) && lcg_rand_n (4) == 0)
    {
	pixman_color_t color;

	color.alpha = lcg_rand_u32();
	color.red = lcg_rand_u32();
	color.green = lcg_rand_u32();
	color.blue = lcg_rand_u32();

	return pixman_image_create_solid_fill (&color);
    }

    width = lcg_rand_n (max_size) + 1;
    height = lcg_rand_n (max_size) + 1;
    format = random_format (formats);

    bpp = PIXMAN_FORMAT_BPP (format);
    stride = (width * bpp + 7) / 8 + lcg_rand_n (17);
    stride = (stride + 3) & ~3;

    if (lcg_rand_n (64) == 0)
    {
	if (!(data = (uint32_t *)make_random_bytes (stride * height)))
	{
	    fprintf (stderr, "Out of memory\n");
	    abort ();
	}
	destroy = destroy_fenced;
    }
    else
    {
	uint8_t *d8;

	data = malloc (stride * height);

	d8 = (uint8_t *)data;
	for (i = 0; i < height * stride; ++i)
	    d8[i] = lcg_rand_n (256);

	destroy = destroy_malloced;
    }

    image = pixman_image_create_bits (format, width, height, data, stride);
    pixman_image_set_destroy_function (image, destroy, data);

    if ((flags & ALLOW_CLIPPED) && lcg_rand_n (8) == 0)
    {
	pixman_box16_t clip_boxes[8];
	pixman_region16_t clip;
	int n = lcg_rand_n (8) + 1;

	for (i = 0; i < n; i++)
	{
	    clip_boxes[i].x1 = lcg_rand_n (width);
	    clip_boxes[i].y1 = lcg_rand_n (height);
	    clip_boxes[i].x2 =
		clip_boxes[i].x1 + lcg_rand_n (width - clip_boxes[i].x1);
	    clip_boxes[i].y2 =
		clip_boxes[i].y1 + lcg_rand_n (height - clip_boxes[i].y1);
	}

	pixman_region_init_rects (&clip, clip_boxes, n);
	pixman_image_set_clip_region (image, &clip);
	pixman_region_fini (&clip);
    }

    if ((flags & ALLOW_SOURCE_CLIPPING) && lcg_rand_n (4) == 0)
    {
	pixman_image_set_source_clipping (image, TRUE);
	pixman_image_set_has_client_clip (image, TRUE);
    }

    if ((flags & ALLOW_ALPHA_MAP) && lcg_rand_n (16) == 0)
    {
	pixman_image_t *alpha_map;
	int alpha_x, alpha_y;

	alpha_x = lcg_rand_n (width);
	alpha_y = lcg_rand_n (height);
	alpha_map =
	    create_image (max_size, formats, (flags & ~(ALLOW_ALPHA_MAP | ALLOW_SOLID)));
	pixman_image_set_alpha_map (image, alpha_map, alpha_x, alpha_y);
	pixman_image_unref (alpha_map);
    }

    if ((flags & ALLOW_REPEAT) && lcg_rand_n (2) == 0)
	pixman_image_set_repeat (image, lcg_rand_n (4));

    image_endian_swap (image);

    return image;
}