2
* Copyright © 2015 RISC OS Open Ltd
4
* Permission to use, copy, modify, distribute, and sell this software and its
5
* documentation for any purpose is hereby granted without fee, provided that
6
* the above copyright notice appear in all copies and that both that
7
* copyright notice and this permission notice appear in supporting
8
* documentation, and that the name of the copyright holders not be used in
9
* advertising or publicity pertaining to distribution of the software without
10
* specific, written prior permission. The copyright holders make no
11
* representations about the suitability of this software for any purpose. It
12
* is provided "as is" without express or implied warranty.
14
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
19
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
20
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23
* Author: Ben Avison (bavison@riscosopen.org)
34
static const pixman_op_t op_list[] = {
42
PIXMAN_OP_OVER_REVERSE,
46
PIXMAN_OP_OUT_REVERSE,
48
PIXMAN_OP_ATOP_REVERSE,
59
#if 0 /* these use floating point math and are not always bitexact on different platforms */
61
PIXMAN_OP_DISJOINT_CLEAR,
62
PIXMAN_OP_DISJOINT_SRC,
63
PIXMAN_OP_DISJOINT_DST,
64
PIXMAN_OP_DISJOINT_OVER,
65
PIXMAN_OP_DISJOINT_OVER_REVERSE,
66
PIXMAN_OP_DISJOINT_IN,
67
PIXMAN_OP_DISJOINT_IN_REVERSE,
68
PIXMAN_OP_DISJOINT_OUT,
69
PIXMAN_OP_DISJOINT_OUT_REVERSE,
70
PIXMAN_OP_DISJOINT_ATOP,
71
PIXMAN_OP_DISJOINT_ATOP_REVERSE,
72
PIXMAN_OP_DISJOINT_XOR,
73
PIXMAN_OP_CONJOINT_CLEAR,
74
PIXMAN_OP_CONJOINT_SRC,
75
PIXMAN_OP_CONJOINT_DST,
76
PIXMAN_OP_CONJOINT_OVER,
77
PIXMAN_OP_CONJOINT_OVER_REVERSE,
78
PIXMAN_OP_CONJOINT_IN,
79
PIXMAN_OP_CONJOINT_IN_REVERSE,
80
PIXMAN_OP_CONJOINT_OUT,
81
PIXMAN_OP_CONJOINT_OUT_REVERSE,
82
PIXMAN_OP_CONJOINT_ATOP,
83
PIXMAN_OP_CONJOINT_ATOP_REVERSE,
84
PIXMAN_OP_CONJOINT_XOR,
85
PIXMAN_OP_COLOR_DODGE,
89
PIXMAN_OP_HSL_SATURATION,
91
PIXMAN_OP_HSL_LUMINOSITY,
95
/* The first eight format in the list are by far the most widely
96
* used formats, so we test those more than the others
98
#define N_MOST_LIKELY_FORMATS 8
100
static const pixman_format_code_t img_fmt_list[] = {
117
#if 0 /* These are going to use floating point in the near future */
151
static const pixman_format_code_t mask_fmt_list[] = {
159
static pixman_indexed_t rgb_palette[9];
160
static pixman_indexed_t y_palette[9];
162
static pixman_format_code_t
163
random_format (const pixman_format_code_t *allowed_formats)
167
while (allowed_formats[n] != PIXMAN_null)
170
if (n > N_MOST_LIKELY_FORMATS && prng_rand_n (4) != 0)
171
n = N_MOST_LIKELY_FORMATS;
173
return allowed_formats[prng_rand_n (n)];
176
static pixman_image_t *
177
create_multi_pixel_image (const pixman_format_code_t *allowed_formats,
179
pixman_format_code_t *used_fmt)
181
pixman_format_code_t fmt;
185
fmt = random_format (allowed_formats);
186
stride = (WIDTH * PIXMAN_FORMAT_BPP (fmt) + 31) / 32 * 4;
187
img = pixman_image_create_bits (fmt, WIDTH, HEIGHT, buffer, stride);
189
if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_COLOR)
190
pixman_image_set_indexed (img, &(rgb_palette[PIXMAN_FORMAT_BPP (fmt)]));
191
else if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_GRAY)
192
pixman_image_set_indexed (img, &(y_palette[PIXMAN_FORMAT_BPP (fmt)]));
194
prng_randmemset (buffer, WIDTH * HEIGHT * 4, 0);
195
image_endian_swap (img);
203
static pixman_image_t *
204
create_solid_image (const pixman_format_code_t *allowed_formats,
206
pixman_format_code_t *used_fmt)
210
/* Use a repeating 1x1 bitmap image for solid */
211
pixman_format_code_t fmt;
212
pixman_image_t *img, *dummy_img;
213
uint32_t bpp, dummy_buf;
215
fmt = random_format (allowed_formats);
216
bpp = PIXMAN_FORMAT_BPP (fmt);
217
img = pixman_image_create_bits (fmt, 1, 1, buffer, 4);
218
pixman_image_set_repeat (img, PIXMAN_REPEAT_NORMAL);
220
if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_COLOR)
221
pixman_image_set_indexed (img, &(rgb_palette[bpp]));
222
else if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_GRAY)
223
pixman_image_set_indexed (img, &(y_palette[bpp]));
225
/* Force the flags to be calculated for image with initial
226
* bitmap contents of 0 or 2^bpp-1 by plotting from it into a
227
* separate throwaway image. It is simplest to write all 0s
228
* or all 1s to the first word irrespective of the colour
229
* depth even though we actually only care about the first
230
* pixel since the stride has to be a whole number of words.
232
*buffer = prng_rand_n (2) ? 0xFFFFFFFFu : 0;
233
dummy_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, 1, 1,
235
pixman_image_composite (PIXMAN_OP_SRC, img, NULL, dummy_img,
236
0, 0, 0, 0, 0, 0, 1, 1);
237
pixman_image_unref (dummy_img);
239
/* Now set the bitmap contents to a random value */
240
prng_randmemset (buffer, 4, 0);
241
image_endian_swap (img);
250
/* Use a native solid image */
251
pixman_color_t color;
254
color.alpha = prng_rand_n (UINT16_MAX + 1);
255
color.red = prng_rand_n (UINT16_MAX + 1);
256
color.green = prng_rand_n (UINT16_MAX + 1);
257
color.blue = prng_rand_n (UINT16_MAX + 1);
258
img = pixman_image_create_solid_fill (&color);
261
*used_fmt = PIXMAN_solid;
268
test_solid (int testnum, int verbose)
271
uint32_t src_buf[WIDTH * HEIGHT];
272
uint32_t dst_buf[WIDTH * HEIGHT];
273
uint32_t mask_buf[WIDTH * HEIGHT];
274
pixman_image_t *src_img;
275
pixman_image_t *dst_img;
276
pixman_image_t *mask_img = NULL;
277
pixman_format_code_t src_fmt, dst_fmt, mask_fmt = PIXMAN_null;
278
pixman_bool_t ca = 0;
281
prng_srand (testnum);
283
op = op_list[prng_rand_n (ARRAY_LENGTH (op_list))];
285
dst_img = create_multi_pixel_image (img_fmt_list, dst_buf, &dst_fmt);
286
switch (prng_rand_n (3))
288
case 0: /* Solid source, no mask */
289
src_img = create_solid_image (img_fmt_list, src_buf, &src_fmt);
291
case 1: /* Solid source, bitmap mask */
292
src_img = create_solid_image (img_fmt_list, src_buf, &src_fmt);
293
mask_img = create_multi_pixel_image (mask_fmt_list, mask_buf, &mask_fmt);
295
case 2: /* Bitmap image, solid mask */
296
src_img = create_multi_pixel_image (img_fmt_list, src_buf, &src_fmt);
297
mask_img = create_solid_image (mask_fmt_list, mask_buf, &mask_fmt);
305
ca = prng_rand_n (2);
306
pixman_image_set_component_alpha (mask_img, ca);
311
printf ("op=%s\n", operator_name (op));
312
printf ("src_fmt=%s, dst_fmt=%s, mask_fmt=%s\n",
313
format_name (src_fmt), format_name (dst_fmt),
314
format_name (mask_fmt));
315
printf ("src_size=%u, mask_size=%u, component_alpha=%u\n",
316
src_fmt == PIXMAN_solid ? 1 : src_img->bits.width,
317
!mask_img || mask_fmt == PIXMAN_solid ? 1 : mask_img->bits.width,
321
pixman_image_composite (op, src_img, mask_img, dst_img,
322
0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
325
print_image (dst_img);
327
crc32 = compute_crc32_for_image (0, dst_img);
329
pixman_image_unref (src_img);
330
pixman_image_unref (dst_img);
332
pixman_image_unref (mask_img);
338
main (int argc, const char *argv[])
344
for (i = 1; i <= 8; i++)
346
initialize_palette (&(rgb_palette[i]), i, TRUE);
347
initialize_palette (&(y_palette[i]), i, FALSE);
350
return fuzzer_test_main ("solid", 500000,
352
test_solid, argc, argv);