fetch-test.c 3.7 KB

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