Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
#include 
2
#include 
3
#include 
4
#include "pixman-private.h"
5
#include "pixman.h"
6
 
7
#define FALSE 0
8
#define TRUE 1
9
 
10
/* Randomly decide between 32 and 16 bit
11
 *
12
 * Allocate bits with random width, stride and height
13
 *
14
 * Then make up some random offset (dx, dy)
15
 *
16
 * Then make an image with those values.
17
 *
18
 * Do this for both source and destination
19
 *
20
 * Composite them together using OVER.
21
 *
22
 * The bits in the source and the destination should have
23
 * recognizable colors so that the result can be verified.
24
 *
25
 * Ie., walk the bits and verify that they have been composited.
26
 */
27
 
28
static int
29
get_rand (int bound)
30
{
31
    return rand () % bound;
32
}
33
 
34
static pixman_image_t *
35
make_image (int width, int height, pixman_bool_t src, int *rx, int *ry)
36
{
37
    pixman_format_code_t format;
38
    pixman_image_t *image;
39
    pixman_region32_t region;
40
    uint8_t *bits;
41
    int stride;
42
    int bpp;
43
    int dx, dy;
44
    int i, j;
45
 
46
    if (src)
47
	format = PIXMAN_a8r8g8b8;
48
    else
49
	format = PIXMAN_r5g6b5;
50
 
51
    bpp = PIXMAN_FORMAT_BPP (format) / 8;
52
 
53
    stride = width + get_rand (width);
54
    stride += (stride & 1);		/* Make it an even number */
55
 
56
    bits = malloc (height * stride * bpp);
57
 
58
    for (j = 0; j < height; ++j)
59
    {
60
	for (i = 0; i < width; ++i)
61
	{
62
	    uint8_t *pixel = bits + (stride * j + i) * bpp;
63
 
64
	    if (src)
65
		*(uint32_t *)pixel = 0x7f00007f;
66
	    else
67
		*(uint16_t *)pixel = 0xf100;
68
	}
69
    }
70
 
71
    dx = dy = 0;
72
 
73
    dx = get_rand (500);
74
    dy = get_rand (500);
75
 
76
    if (!src)
77
    {
78
	/* Now simulate the bogus X server translations */
79
	bits -= (dy * stride + dx) * bpp;
80
    }
81
 
82
    image = pixman_image_create_bits (
83
	format, width, height, (uint32_t *)bits, stride * bpp);
84
 
85
    if (!src)
86
    {
87
	/* And add the bogus clip region */
88
	pixman_region32_init_rect (®ion, dx, dy, dx + width, dy + height);
89
 
90
	pixman_image_set_clip_region32 (image, ®ion);
91
    }
92
 
93
    pixman_image_set_source_clipping (image, TRUE);
94
 
95
    if (src)
96
    {
97
	pixman_transform_t trans;
98
 
99
	pixman_transform_init_identity (&trans);
100
 
101
	pixman_transform_translate (&trans,
102
				    NULL,
103
				    - pixman_int_to_fixed (width / 2),
104
				    - pixman_int_to_fixed (height / 2));
105
 
106
	pixman_transform_scale (&trans,
107
				NULL,
108
				pixman_double_to_fixed (0.5),
109
				pixman_double_to_fixed (0.5));
110
 
111
	pixman_transform_translate (&trans,
112
				    NULL,
113
				    pixman_int_to_fixed (width / 2),
114
				    pixman_int_to_fixed (height / 2));
115
 
116
	pixman_image_set_transform (image, &trans);
117
	pixman_image_set_filter (image, PIXMAN_FILTER_BILINEAR, NULL, 0);
118
	pixman_image_set_repeat (image, PIXMAN_REPEAT_PAD);
119
    }
120
 
121
    if (!src)
122
    {
123
	*rx = dx;
124
	*ry = dy;
125
    }
126
    else
127
    {
128
	*rx = *ry = 0;
129
    }
130
 
131
    return image;
132
}
133
 
134
int
135
main ()
136
{
137
    pixman_image_t *src, *dest;
138
    int src_x, src_y, dest_x, dest_y;
139
    int i, j;
140
    int width = get_rand (499) + 1;
141
    int height = get_rand (499) + 1;
142
 
143
    src = make_image (width, height, TRUE, &src_x, &src_y);
144
    dest = make_image (width, height, FALSE, &dest_x, &dest_y);
145
 
146
    pixman_image_composite (
147
	PIXMAN_OP_OVER, src, NULL, dest,
148
	src_x, src_y,
149
	-1, -1,
150
	dest_x, dest_y,
151
	width, height);
152
 
153
    for (i = 0; i < height; ++i)
154
    {
155
	for (j = 0; j < width; ++j)
156
	{
157
	    uint8_t *bits = (uint8_t *)dest->bits.bits;
158
	    int bpp = PIXMAN_FORMAT_BPP (dest->bits.format) / 8;
159
	    int stride = dest->bits.rowstride * 4;
160
 
161
	    uint8_t *pixel =
162
		bits + (i + dest_y) * stride + (j + dest_x) * bpp;
163
 
164
	    if (*(uint16_t *)pixel != 0x788f)
165
	    {
166
		printf ("bad pixel %x\n", *(uint16_t *)pixel);
167
		assert (*(uint16_t *)pixel == 0x788f);
168
	    }
169
	}
170
    }
171
 
172
    return 0;
173
}