summaryrefslogtreecommitdiff
path: root/libs/pixman-0.40.0/test/combiner-test.c
blob: 01f63a56ec5d2e3f0c1e5232ccbd2304a6f65da6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <stdio.h>
#include <stdlib.h>
#include "utils.h"
#include <sys/types.h>
#include "pixman-private.h"

static const pixman_op_t op_list[] =
{
    PIXMAN_OP_SRC,
    PIXMAN_OP_OVER,
    PIXMAN_OP_ADD,
    PIXMAN_OP_CLEAR,
    PIXMAN_OP_SRC,
    PIXMAN_OP_DST,
    PIXMAN_OP_OVER,
    PIXMAN_OP_OVER_REVERSE,
    PIXMAN_OP_IN,
    PIXMAN_OP_IN_REVERSE,
    PIXMAN_OP_OUT,
    PIXMAN_OP_OUT_REVERSE,
    PIXMAN_OP_ATOP,
    PIXMAN_OP_ATOP_REVERSE,
    PIXMAN_OP_XOR,
    PIXMAN_OP_ADD,
    PIXMAN_OP_SATURATE,
    PIXMAN_OP_DISJOINT_CLEAR,
    PIXMAN_OP_DISJOINT_SRC,
    PIXMAN_OP_DISJOINT_DST,
    PIXMAN_OP_DISJOINT_OVER,
    PIXMAN_OP_DISJOINT_OVER_REVERSE,
    PIXMAN_OP_DISJOINT_IN,
    PIXMAN_OP_DISJOINT_IN_REVERSE,
    PIXMAN_OP_DISJOINT_OUT,
    PIXMAN_OP_DISJOINT_OUT_REVERSE,
    PIXMAN_OP_DISJOINT_ATOP,
    PIXMAN_OP_DISJOINT_ATOP_REVERSE,
    PIXMAN_OP_DISJOINT_XOR,
    PIXMAN_OP_CONJOINT_CLEAR,
    PIXMAN_OP_CONJOINT_SRC,
    PIXMAN_OP_CONJOINT_DST,
    PIXMAN_OP_CONJOINT_OVER,
    PIXMAN_OP_CONJOINT_OVER_REVERSE,
    PIXMAN_OP_CONJOINT_IN,
    PIXMAN_OP_CONJOINT_IN_REVERSE,
    PIXMAN_OP_CONJOINT_OUT,
    PIXMAN_OP_CONJOINT_OUT_REVERSE,
    PIXMAN_OP_CONJOINT_ATOP,
    PIXMAN_OP_CONJOINT_ATOP_REVERSE,
    PIXMAN_OP_CONJOINT_XOR,
    PIXMAN_OP_MULTIPLY,
    PIXMAN_OP_SCREEN,
    PIXMAN_OP_OVERLAY,
    PIXMAN_OP_DARKEN,
    PIXMAN_OP_LIGHTEN,
    PIXMAN_OP_COLOR_DODGE,
    PIXMAN_OP_COLOR_BURN,
    PIXMAN_OP_HARD_LIGHT,
    PIXMAN_OP_DIFFERENCE,
    PIXMAN_OP_EXCLUSION,
    PIXMAN_OP_SOFT_LIGHT,
    PIXMAN_OP_HSL_HUE,
    PIXMAN_OP_HSL_SATURATION,
    PIXMAN_OP_HSL_COLOR,
    PIXMAN_OP_HSL_LUMINOSITY,
};

static float
rand_float (void)
{
    uint32_t u = prng_rand();

    return *(float *)&u;
}

static void
random_floats (argb_t *argb, int width)
{
    int i;

    for (i = 0; i < width; ++i)
    {
	argb_t *p = argb + i;

	p->a = rand_float();
	p->r = rand_float();
	p->g = rand_float();
	p->b = rand_float();
    }
}

#define WIDTH	512

static pixman_combine_float_func_t
lookup_combiner (pixman_implementation_t *imp, pixman_op_t op,
		 pixman_bool_t component_alpha)
{
    pixman_combine_float_func_t f;

    do
    {
	if (component_alpha)
	    f = imp->combine_float_ca[op];
	else
	    f = imp->combine_float[op];
	
	imp = imp->fallback;
    }
    while (!f);

    return f;
}

int
main ()
{
    pixman_implementation_t *impl;
    argb_t *src_bytes = malloc (WIDTH * sizeof (argb_t));
    argb_t *mask_bytes = malloc (WIDTH * sizeof (argb_t));
    argb_t *dest_bytes = malloc (WIDTH * sizeof (argb_t));
    int i;

    enable_divbyzero_exceptions();
    
    impl = _pixman_internal_only_get_implementation();
    
    prng_srand (0);

    for (i = 0; i < ARRAY_LENGTH (op_list); ++i)
    {
	pixman_op_t op = op_list[i];
	pixman_combine_float_func_t combiner;
	int ca;

	for (ca = 0; ca < 2; ++ca)
	{
	    combiner = lookup_combiner (impl, op, ca);

	    random_floats (src_bytes, WIDTH);
	    random_floats (mask_bytes, WIDTH);
	    random_floats (dest_bytes, WIDTH);

	    combiner (impl, op,
		      (float *)dest_bytes,
		      (float *)mask_bytes,
		      (float *)src_bytes,
		      WIDTH);
	}
    }	

    return 0;
}