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