| 1 |
#include <stdlib.h> |
| 2 |
#include "utils.h" |
| 3 |
|
| 4 |
#define WIDTH 32 |
| 5 |
#define HEIGHT 32 |
| 6 |
|
| 7 |
static const pixman_format_code_t formats[] = |
| 8 |
{ |
| 9 |
PIXMAN_a8r8g8b8, |
| 10 |
PIXMAN_a8b8g8r8, |
| 11 |
PIXMAN_x8r8g8b8, |
| 12 |
PIXMAN_x8b8g8r8, |
| 13 |
PIXMAN_r5g6b5, |
| 14 |
PIXMAN_b5g6r5, |
| 15 |
PIXMAN_a8, |
| 16 |
PIXMAN_a1, |
| 17 |
}; |
| 18 |
|
| 19 |
static const pixman_op_t ops[] = |
| 20 |
{ |
| 21 |
PIXMAN_OP_OVER, |
| 22 |
PIXMAN_OP_SRC, |
| 23 |
PIXMAN_OP_ADD, |
| 24 |
}; |
| 25 |
|
| 26 |
#define TRANSFORM(v00, v01, v10, v11) \ |
| 27 |
{ { { v00, v01, WIDTH * pixman_fixed_1 / 2 }, \ |
| 28 |
{ v10, v11, HEIGHT * pixman_fixed_1 / 2 }, \ |
| 29 |
{ 0, 0, pixman_fixed_1 } } } |
| 30 |
|
| 31 |
#define F1 pixman_fixed_1 |
| 32 |
|
| 33 |
static const pixman_transform_t transforms[] = |
| 34 |
{ |
| 35 |
TRANSFORM (0, -1, 1, 0), /* wrong 90 degree rotation */ |
| 36 |
TRANSFORM (0, 1, -1, 0), /* wrong 270 degree rotation */ |
| 37 |
TRANSFORM (1, 0, 0, 1), /* wrong identity */ |
| 38 |
TRANSFORM (-1, 0, 0, -1), /* wrong 180 degree rotation */ |
| 39 |
TRANSFORM (0, -F1, F1, 0), /* correct 90 degree rotation */ |
| 40 |
TRANSFORM (0, F1, -F1, 0), /* correct 270 degree rotation */ |
| 41 |
TRANSFORM (F1, 0, 0, F1), /* correct identity */ |
| 42 |
TRANSFORM (-F1, 0, 0, -F1), /* correct 180 degree rotation */ |
| 43 |
}; |
| 44 |
|
| 45 |
#define RANDOM_FORMAT() \ |
| 46 |
(formats[prng_rand_n (ARRAY_LENGTH (formats))]) |
| 47 |
|
| 48 |
#define RANDOM_OP() \ |
| 49 |
(ops[prng_rand_n (ARRAY_LENGTH (ops))]) |
| 50 |
|
| 51 |
#define RANDOM_TRANSFORM() \ |
| 52 |
(&(transforms[prng_rand_n (ARRAY_LENGTH (transforms))])) |
| 53 |
|
| 54 |
static void |
| 55 |
on_destroy (pixman_image_t *image, void *data) |
| 56 |
{ |
| 57 |
free (data); |
| 58 |
} |
| 59 |
|
| 60 |
static pixman_image_t * |
| 61 |
make_image (void) |
| 62 |
{ |
| 63 |
pixman_format_code_t format = RANDOM_FORMAT(); |
| 64 |
uint32_t *bytes, *orig; |
| 65 |
pixman_image_t *image; |
| 66 |
int stride; |
| 67 |
|
| 68 |
orig = bytes = malloc (WIDTH * HEIGHT * 4); |
| 69 |
prng_randmemset (bytes, WIDTH * HEIGHT * 4, 0); |
| 70 |
|
| 71 |
stride = WIDTH * 4; |
| 72 |
if (prng_rand_n (2) == 0) |
| 73 |
{ |
| 74 |
bytes += (stride / 4) * (HEIGHT - 1); |
| 75 |
stride = - stride; |
| 76 |
} |
| 77 |
|
| 78 |
image = pixman_image_create_bits ( |
| 79 |
format, WIDTH, HEIGHT, bytes, stride); |
| 80 |
|
| 81 |
pixman_image_set_transform (image, RANDOM_TRANSFORM()); |
| 82 |
pixman_image_set_destroy_function (image, on_destroy, orig); |
| 83 |
pixman_image_set_repeat (image, PIXMAN_REPEAT_NORMAL); |
| 84 |
|
| 85 |
image_endian_swap (image); |
| 86 |
|
| 87 |
return image; |
| 88 |
} |
| 89 |
|
| 90 |
static uint32_t |
| 91 |
test_transform (int testnum, int verbose) |
| 92 |
{ |
| 93 |
pixman_image_t *src, *dest; |
| 94 |
uint32_t crc; |
| 95 |
|
| 96 |
prng_srand (testnum); |
| 97 |
|
| 98 |
src = make_image (); |
| 99 |
dest = make_image (); |
| 100 |
|
| 101 |
pixman_image_composite (RANDOM_OP(), |
| 102 |
src, NULL, dest, |
| 103 |
0, 0, 0, 0, WIDTH / 2, HEIGHT / 2, |
| 104 |
WIDTH, HEIGHT); |
| 105 |
|
| 106 |
crc = compute_crc32_for_image (0, dest); |
| 107 |
|
| 108 |
pixman_image_unref (src); |
| 109 |
pixman_image_unref (dest); |
| 110 |
|
| 111 |
return crc; |
| 112 |
} |
| 113 |
|
| 114 |
int |
| 115 |
main (int argc, const char *argv[]) |
| 116 |
{ |
| 117 |
return fuzzer_test_main ("rotate", 15000, |
| 118 |
0x81E9EC2F, |
| 119 |
test_transform, argc, argv); |
| 120 |
} |