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