static pixman_image_t * create_image (pixman_image_t **clone) { pixman_format_code_t format = RANDOM_ELT (formats); pixman_image_t *image; int width = prng_rand_n (MAX_WIDTH); int height = prng_rand_n (MAX_HEIGHT); int stride = ((width * (PIXMAN_FORMAT_BPP (format) / 8)) + 3) & ~3; uint32_t *bytes = malloc (stride * height); prng_randmemset (bytes, stride * height, RANDMEMSET_MORE_00_AND_FF); image = pixman_image_create_bits ( format, width, height, bytes, stride); pixman_image_set_destroy_function (image, free_bits, NULL); assert (image); if (clone) { uint32_t *bytes_dup = malloc (stride * height); memcpy (bytes_dup, bytes, stride * height); *clone = pixman_image_create_bits ( format, width, height, bytes_dup, stride); pixman_image_set_destroy_function (*clone, free_bits, NULL); } return image; }
static pixman_image_t * make_image (void) { pixman_format_code_t format = RANDOM_FORMAT(); uint32_t *bytes = malloc (WIDTH * HEIGHT * 4); pixman_image_t *image; prng_randmemset (bytes, WIDTH * HEIGHT * 4, 0); image = pixman_image_create_bits ( format, WIDTH, HEIGHT, bytes, WIDTH * 4); pixman_image_set_transform (image, RANDOM_TRANSFORM()); pixman_image_set_destroy_function (image, on_destroy, bytes); pixman_image_set_repeat (image, PIXMAN_REPEAT_NORMAL); image_endian_swap (image); return image; }
/* Create random image for testing purposes */ static pixman_image_t * create_random_image (pixman_format_code_t *allowed_formats, int max_width, int max_height, int max_extra_stride, pixman_format_code_t *used_fmt) { int n = 0, width, height, stride; pixman_format_code_t fmt; uint32_t *buf; pixman_image_t *img; while (allowed_formats[n] != PIXMAN_null) n++; if (n > N_MOST_LIKELY_FORMATS && prng_rand_n (4) != 0) n = N_MOST_LIKELY_FORMATS; fmt = allowed_formats[prng_rand_n (n)]; width = prng_rand_n (max_width) + 1; height = prng_rand_n (max_height) + 1; stride = (width * PIXMAN_FORMAT_BPP (fmt) + 7) / 8 + prng_rand_n (max_extra_stride + 1); stride = (stride + 3) & ~3; /* do the allocation */ buf = aligned_malloc (64, stride * height); if (prng_rand_n (4) == 0) { /* uniform distribution */ prng_randmemset (buf, stride * height, 0); } else { /* significantly increased probability for 0x00 and 0xFF */ prng_randmemset (buf, stride * height, RANDMEMSET_MORE_00_AND_FF); } /* test negative stride */ if (prng_rand_n (4) == 0) { buf += (stride / 4) * (height - 1); stride = - stride; } img = pixman_image_create_bits (fmt, width, height, buf, stride); if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_COLOR) { pixman_image_set_indexed (img, &(rgb_palette[PIXMAN_FORMAT_BPP (fmt)])); } else if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_GRAY) { pixman_image_set_indexed (img, &(y_palette[PIXMAN_FORMAT_BPP (fmt)])); } if (prng_rand_n (16) == 0) pixman_image_set_filter (img, PIXMAN_FILTER_BILINEAR, NULL, 0); image_endian_swap (img); if (used_fmt) *used_fmt = fmt; return img; }