int main (int argc, char **argv) { pixman_transform_t transform; pixman_image_t *src_img, *dest_img; int i, j; enable_fp_exceptions (); dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, NULL, 0); pixman_transform_init_identity (&transform); /* * The create_radial() function returns gradients centered in the * origin and whose interesting part fits a 1x1 square. We want to * paint these gradients on a SIZExSIZE square and to make things * easier we want the origin in the top-left corner of the square * we want to see. */ pixman_transform_translate (NULL, &transform, pixman_double_to_fixed (0.5), pixman_double_to_fixed (0.5)); pixman_transform_scale (NULL, &transform, pixman_double_to_fixed (SIZE), pixman_double_to_fixed (SIZE)); /* * Gradients are evaluated at the center of each pixel, so we need * to translate by half a pixel to trigger some interesting * cornercases. In particular, the original implementation of PDF * radial gradients tried to divide by 0 when using this transform * on the "tangent circles" cases. */ pixman_transform_translate (NULL, &transform, pixman_double_to_fixed (0.5), pixman_double_to_fixed (0.5)); for (i = 0; i < NUM_GRADIENTS; i++) { src_img = create_radial (i); pixman_image_set_transform (src_img, &transform); for (j = 0; j < NUM_REPEAT; j++) { pixman_image_set_repeat (src_img, repeat[j]); pixman_image_composite32 (PIXMAN_OP_OVER, src_img, NULL, dest_img, 0, 0, 0, 0, i * SIZE, j * SIZE, SIZE, SIZE); } pixman_image_unref (src_img); } show_image (dest_img); pixman_image_unref (dest_img); return 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; }
/* * We have a source image filled with solid color, set NORMAL or PAD repeat, * and some transform which results in nearest neighbour scaling. * * The expected result is either that the destination image filled with this solid * color or, if the transformation is such that we can't composite anything at * all, that nothing has changed in the destination. * * The surrounding memory of the source image is a different solid color so that * we are sure to get failures if we access it. */ static int run_test (int32_t dst_width, int32_t dst_height, int32_t src_width, int32_t src_height, int32_t src_x, int32_t src_y, int32_t scale_x, int32_t scale_y, pixman_filter_t filter, pixman_repeat_t repeat) { pixman_image_t * src_img; pixman_image_t * dst_img; pixman_transform_t transform; uint32_t * srcbuf; uint32_t * dstbuf; pixman_box32_t box = { 0, 0, src_width, src_height }; pixman_color_t color_cc = { 0xcccc, 0xcccc, 0xcccc, 0xcccc }; int result; int i; static const pixman_fixed_t kernel[] = { #define D(f) (pixman_double_to_fixed (f) + 0x0001) pixman_int_to_fixed (5), pixman_int_to_fixed (5), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0) }; result = 0; srcbuf = (uint32_t *)malloc ((src_width + 10) * (src_height + 10) * 4); dstbuf = (uint32_t *)malloc (dst_width * dst_height * 4); memset (srcbuf, 0x88, src_width * src_height * 4); memset (dstbuf, 0x33, dst_width * dst_height * 4); src_img = pixman_image_create_bits ( PIXMAN_a8r8g8b8, src_width, src_height, srcbuf + (src_width + 10) * 5 + 5, (src_width + 10) * 4); pixman_image_fill_boxes (PIXMAN_OP_SRC, src_img, &color_cc, 1, &box); dst_img = pixman_image_create_bits ( PIXMAN_a8r8g8b8, dst_width, dst_height, dstbuf, dst_width * 4); pixman_transform_init_scale (&transform, scale_x, scale_y); pixman_image_set_transform (src_img, &transform); pixman_image_set_repeat (src_img, repeat); if (filter == PIXMAN_FILTER_CONVOLUTION) pixman_image_set_filter (src_img, filter, kernel, 27); else pixman_image_set_filter (src_img, filter, NULL, 0); pixman_image_composite (PIXMAN_OP_SRC, src_img, NULL, dst_img, src_x, src_y, 0, 0, 0, 0, dst_width, dst_height); pixman_image_unref (src_img); pixman_image_unref (dst_img); for (i = 0; i < dst_width * dst_height; i++) { if (dstbuf[i] != 0xCCCCCCCC && dstbuf[i] != 0x33333333) { result = 1; break; } } free (srcbuf); free (dstbuf); return result; }
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; }