fetch-test.c revision a450e446
1#include <assert.h>
2#include <stdlib.h>
3#include <stdio.h>
4#include "pixman.h"
5#include <config.h>
6
7#define SIZE 1024
8
9pixman_indexed_t mono_pallete = {
10    .rgba = { 0x00000000, 0x00ffffff },
11};
12
13
14typedef struct {
15    pixman_format_code_t format;
16    int width, height;
17    int stride;
18    uint32_t src[SIZE];
19    uint32_t dst[SIZE];
20    pixman_indexed_t *indexed;
21} testcase_t;
22
23testcase_t testcases[] = {
24    {
25	.format = PIXMAN_a8r8g8b8,
26	.width = 2, .height = 2,
27	.stride = 8,
28	.src = { 0x00112233, 0x44556677,
29	         0x8899aabb, 0xccddeeff },
30	.dst = { 0x00112233, 0x44556677,
31	         0x8899aabb, 0xccddeeff },
32	.indexed = NULL,
33    },
34    {
35	.format = PIXMAN_g1,
36	.width = 8, .height = 2,
37	.stride = 4,
38#ifdef WORDS_BIGENDIAN
39	.src = { 0xaa000000,
40		 0x55000000 },
41#else
42	.src = { 0x00000055,
43	         0x000000aa },
44#endif
45	.dst = { 0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000,
46	         0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff },
47	.indexed = &mono_pallete,
48    },
49#if 0
50    {
51	.format = PIXMAN_g8,
52	.width = 4, .height = 2,
53	.stride = 4,
54	.src = { 0x01234567,
55	         0x89abcdef },
56	.dst = { 0x00010101, 0x00232323, 0x00454545, 0x00676767,
57	         0x00898989, 0x00ababab, 0x00cdcdcd, 0x00efefef, },
58    },
59#endif
60    /* FIXME: make this work on big endian */
61    {
62	.format = PIXMAN_yv12,
63	.width = 8, .height = 2,
64	.stride = 8,
65#ifdef WORDS_BIGENDIAN
66	.src = { 0x00ff00ff, 0x00ff00ff,
67	         0xff00ff00, 0xff00ff00,
68	         0x80ff8000,
69		 0x800080ff
70	},
71#else
72	.src = { 0xff00ff00, 0xff00ff00,
73	         0x00ff00ff, 0x00ff00ff,
74	         0x0080ff80,
75		 0xff800080
76	 },
77#endif
78	.dst = {
79		0xff000000, 0xffffffff, 0xffb80000, 0xffffe113,
80		0xff000000, 0xffffffff, 0xff0023ee, 0xff4affff,
81		0xffffffff, 0xff000000, 0xffffe113, 0xffb80000,
82		0xffffffff, 0xff000000, 0xff4affff, 0xff0023ee,
83	},
84    },
85};
86
87const int ntestcases = sizeof(testcases)/sizeof(testcases[0]);
88
89
90static uint32_t
91reader (const void *src, int size)
92{
93    switch (size)
94    {
95    case 1:
96	return *(uint8_t *)src;
97    case 2:
98	return *(uint16_t *)src;
99    case 4:
100	return *(uint32_t *)src;
101    default:
102	assert(0);
103    }
104}
105
106
107static void
108writer (void *src, uint32_t value, int size)
109{
110    switch (size)
111    {
112    case 1:
113	*(uint8_t *)src = value;
114	break;
115    case 2:
116	*(uint16_t *)src = value;
117	break;
118    case 4:
119	*(uint32_t *)src = value;
120	break;
121    default:
122	assert(0);
123    }
124}
125
126
127int
128main (int argc, char **argv)
129{
130    uint32_t dst[SIZE];
131    pixman_image_t *src_img;
132    pixman_image_t *dst_img;
133    int i, j, x, y;
134    int ret = 0;
135
136    for (i = 0; i < ntestcases; ++i) {
137	for (j = 0; j < 2; ++j) {
138	    src_img = pixman_image_create_bits (testcases[i].format,
139						testcases[i].width,
140						testcases[i].height,
141						testcases[i].src,
142						testcases[i].stride);
143	    pixman_image_set_indexed(src_img, testcases[i].indexed);
144
145	    dst_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
146						testcases[i].width,
147						testcases[i].height,
148						dst,
149						testcases[i].width*4);
150
151	    if (j) {
152		pixman_image_set_accessors (src_img, reader, writer);
153		pixman_image_set_accessors (dst_img, reader, writer);
154	    }
155
156	    pixman_image_composite (PIXMAN_OP_SRC, src_img, NULL, dst_img,
157				    0, 0, 0, 0, 0, 0, testcases[i].width, testcases[i].height);
158
159	    pixman_image_unref (src_img);
160	    pixman_image_unref (dst_img);
161
162	    for (y = 0; y < testcases[i].height; ++y)
163		for (x = 0; x < testcases[i].width; ++x) {
164		    int offset = y*testcases[i].width + x;
165		    if (dst[offset] != testcases[i].dst[offset]) {
166			printf ("test %i%c: pixel mismatch at (x=%d,y=%d): %08x expected, %08x obtained\n",
167			        i + 1, 'a' + j,
168			        x, y,
169			        testcases[i].dst[offset], dst[offset]);
170			ret = 1;
171		    }
172		}
173	}
174    }
175
176    return ret;
177}
178