15 #include <freerdp/config.h>
17 #include <winpr/sysinfo.h>
19 #include "prim_test.h"
21 #define MAX_BLOCK_SIZE 256
22 #define SIZE_SQUARED (MAX_BLOCK_SIZE * MAX_BLOCK_SIZE)
25 #define ALF(_c_) (((_c_)&0xFF000000U) >> 24)
26 #define RED(_c_) (((_c_)&0x00FF0000U) >> 16)
27 #define GRN(_c_) (((_c_)&0x0000FF00U) >> 8)
28 #define BLU(_c_) ((_c_)&0x000000FFU)
30 static inline const UINT32* PIXEL(
const BYTE* _addr_, UINT32 _bytes_, UINT32 _x_, UINT32 _y_)
32 const BYTE* addr = _addr_ + 1ULL * _x_ *
sizeof(UINT32) + 1ULL * _y_ * _bytes_;
33 return (
const UINT32*)addr;
46 static UINT32 alpha_add(UINT32 c1, UINT32 c2)
56 UINT32 a3 = ((a1 * a1 + (255 - a1) * a2) / 255) & 0xff;
57 UINT32 r3 = ((a1 * r1 + (255 - a1) * r2) / 255) & 0xff;
58 UINT32 g3 = ((a1 * g1 + (255 - a1) * g2) / 255) & 0xff;
59 UINT32 b3 = ((a1 * b1 + (255 - a1) * b2) / 255) & 0xff;
60 return (a3 << 24) | (r3 << 16) | (g3 << 8) | b3;
64 static UINT32 colordist(UINT32 c1, UINT32 c2)
68 d = ABS((INT32)(ALF(c1) - ALF(c2)));
73 d = ABS((INT32)(RED(c1) - RED(c2)));
78 d = ABS((INT32)(GRN(c1) - GRN(c2)));
83 d = ABS((INT32)(BLU(c1) - BLU(c2)));
92 static BOOL check(
const BYTE* pSrc1, UINT32 src1Step,
const BYTE* pSrc2, UINT32 src2Step,
93 BYTE* pDst, UINT32 dstStep, UINT32 width, UINT32 height)
95 for (UINT32 y = 0; y < height; ++y)
97 for (UINT32 x = 0; x < width; ++x)
99 UINT32 s1 = *PIXEL(pSrc1, src1Step, x, y);
100 UINT32 s2 = *PIXEL(pSrc2, src2Step, x, y);
101 UINT32 c0 = alpha_add(s1, s2);
102 UINT32 c1 = *PIXEL(pDst, dstStep, x, y);
104 if (colordist(c0, c1) > TOLERANCE)
106 printf(
"alphaComp-general: [%" PRIu32
",%" PRIu32
"] 0x%08" PRIx32
"+0x%08" PRIx32
107 "=0x%08" PRIx32
", got 0x%08" PRIx32
"\n",
108 x, y, s1, s2, c0, c1);
117 static BOOL test_alphaComp_func(
void)
119 pstatus_t status = 0;
120 BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT * 4]) = { 0 };
121 BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT * 4]) = { 0 };
122 BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT * 4]) = { 0 };
124 winpr_RAND(src1,
sizeof(src1));
126 src1[0] &= 0x00FFFFFFU;
127 src1[1] |= 0xFF000000U;
128 winpr_RAND(src2,
sizeof(src2));
132 for (UINT32 i = 0; i <
sizeof(src2) / 4; ++i)
133 *ptr++ |= 0xFF000000U;
135 status =
generic->alphaComp_argb(src1, 4 * SRC1_WIDTH, src2, 4 * SRC2_WIDTH, dst1,
136 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT);
138 if (status != PRIMITIVES_SUCCESS)
141 if (!check(src1, 4 * SRC1_WIDTH, src2, 4 * SRC2_WIDTH, dst1, 4 * DST_WIDTH, TEST_WIDTH,
145 status = optimized->alphaComp_argb((
const BYTE*)src1, 4 * SRC1_WIDTH, (
const BYTE*)src2,
146 4 * SRC2_WIDTH, (BYTE*)dst1, 4 * DST_WIDTH, TEST_WIDTH,
149 if (status != PRIMITIVES_SUCCESS)
152 if (!check(src1, 4 * SRC1_WIDTH, src2, 4 * SRC2_WIDTH, dst1, 4 * DST_WIDTH, TEST_WIDTH,
159 static int test_alphaComp_speed(
void)
161 BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT]) = { 0 };
162 BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT]) = { 0 };
163 BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT]) = { 0 };
166 winpr_RAND(src1,
sizeof(src1));
168 src1[0] &= 0x00FFFFFFU;
169 src1[1] |= 0xFF000000U;
170 winpr_RAND(src2,
sizeof(src2));
174 for (UINT32 i = 0; i <
sizeof(src2) / 4; ++i)
175 *ptr++ |= 0xFF000000U;
177 if (!speed_test(
"add16s",
"aligned", g_Iterations, (speed_test_fkt)
generic->alphaComp_argb,
178 (speed_test_fkt)optimized->alphaComp_argb, src1, 4 * SRC1_WIDTH, src2,
179 4 * SRC2_WIDTH, dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT))
185 int TestPrimitivesAlphaComp(
int argc,
char* argv[])
190 prim_test_setup(FALSE);
192 if (!test_alphaComp_func())
195 if (g_TestPrimitivesPerformance)
197 if (!test_alphaComp_speed())