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