15 #include <freerdp/config.h>
17 #include <winpr/sysinfo.h>
18 #include <freerdp/utils/profiler.h>
20 #include "prim_test.h"
23 static BOOL test_RGBToRGB_16s8u_P3AC4R_func(
prim_size_t roi, DWORD DstFormat)
32 const UINT32 rgbStride = roi.width * 2;
33 const UINT32 dstStride = roi.width * 4;
34 PROFILER_DEFINE(genericProf)
35 PROFILER_DEFINE(optProf)
36 PROFILER_CREATE(genericProf,
"RGBToRGB_16s8u_P3AC4R-GENERIC")
37 PROFILER_CREATE(optProf, "RGBToRGB_16s8u_P3AC4R-OPTIMIZED")
38 r = winpr_aligned_calloc(1, 1ULL * rgbStride * roi.height, 16);
39 g = winpr_aligned_calloc(1, 1ULL * rgbStride * roi.height, 16);
40 b = winpr_aligned_calloc(1, 1ULL * rgbStride * roi.height, 16);
41 out1 = winpr_aligned_calloc(1, 1ULL * dstStride * roi.height, 16);
42 out2 = winpr_aligned_calloc(1, 1ULL * dstStride * roi.height, 16);
44 if (!r || !g || !b || !out1 || !out2)
49 for (UINT32 y = 0; y < roi.height; y++)
51 for (UINT32 x = 0; x < roi.width; x++)
53 r[y * roi.width + x] = 0x01;
54 g[y * roi.width + x] = 0x02;
55 b[y * roi.width + x] = 0x04;
60 winpr_RAND(r, 1ULL * rgbStride * roi.height);
61 winpr_RAND(g, 1ULL * rgbStride * roi.height);
62 winpr_RAND(b, 1ULL * rgbStride * roi.height);
67 PROFILER_ENTER(genericProf)
69 if (generic->RGBToRGB_16s8u_P3AC4R(ptrs, rgbStride, out1, dstStride, DstFormat, &roi) !=
73 PROFILER_EXIT(genericProf)
74 PROFILER_ENTER(optProf)
76 if (optimized->RGBToRGB_16s8u_P3AC4R(ptrs, rgbStride, out2, dstStride, DstFormat, &roi) !=
80 PROFILER_EXIT(optProf)
82 if (memcmp(out1, out2, 1ULL * dstStride * roi.height) != 0)
84 for (UINT64 i = 0; i < 1ull * roi.width * roi.height; ++i)
86 const UINT32 o1 = FreeRDPReadColor(out1 + 4 * i, DstFormat);
87 const UINT32 o2 = FreeRDPReadColor(out2 + 4 * i, DstFormat);
91 printf(
"RGBToRGB_16s8u_P3AC4R FAIL: out1[%" PRIu64
"]=0x%08" PRIx8
" out2[%" PRIu64
93 i, out1[i], i, out2[i]);
99 printf(
"Results for %" PRIu32
"x%" PRIu32
" [%s]", roi.width, roi.height,
100 FreeRDPGetColorFormatName(DstFormat));
101 PROFILER_PRINT_HEADER
102 PROFILER_PRINT(genericProf)
103 PROFILER_PRINT(optProf)
104 PROFILER_PRINT_FOOTER
106 PROFILER_FREE(genericProf)
107 PROFILER_FREE(optProf)
108 winpr_aligned_free(r);
109 winpr_aligned_free(g);
110 winpr_aligned_free(b);
111 winpr_aligned_free(out1);
112 winpr_aligned_free(out2);
117 static BOOL test_RGBToRGB_16s8u_P3AC4R_speed(
void)
125 INT16 ALIGN(r[4096 + 1]);
126 INT16 ALIGN(g[4096 + 1]);
127 INT16 ALIGN(b[4096 + 1]);
128 UINT32 ALIGN(dst[4096 + 1]);
130 winpr_RAND(r,
sizeof(r));
131 winpr_RAND(g,
sizeof(g));
132 winpr_RAND(b,
sizeof(b));
135 for (
int i = 0; i < 4096; ++i)
147 if (!speed_test(
"RGBToRGB_16s8u_P3AC4R",
"aligned", g_Iterations,
148 generic->RGBToRGB_16s8u_P3AC4R, optimized->RGBToRGB_16s8u_P3AC4R, cnv.cpv,
149 64 * 2, (BYTE*)dst, 64 * 4, &roi64x64))
152 if (!speed_test(
"RGBToRGB_16s8u_P3AC4R",
"unaligned", g_Iterations,
153 generic->RGBToRGB_16s8u_P3AC4R, optimized->RGBToRGB_16s8u_P3AC4R, cnv.cpv,
154 64 * 2, ((BYTE*)dst) + 1, 64 * 4, &roi64x64))
161 static BOOL test_yCbCrToRGB_16s16s_P3P3_func(
void)
163 pstatus_t status = 0;
164 INT16 ALIGN(y[4096]) = { 0 };
165 INT16 ALIGN(cb[4096]) = { 0 };
166 INT16 ALIGN(cr[4096]) = { 0 };
167 INT16 ALIGN(r1[4096]) = { 0 };
168 INT16 ALIGN(g1[4096]) = { 0 };
169 INT16 ALIGN(b1[4096]) = { 0 };
170 INT16 ALIGN(r2[4096]) = { 0 };
171 INT16 ALIGN(g2[4096]) = { 0 };
172 INT16 ALIGN(b2[4096]) = { 0 };
177 winpr_RAND(y,
sizeof(y));
178 winpr_RAND(cb,
sizeof(cb));
179 winpr_RAND(cr,
sizeof(cr));
182 for (
int i = 0; i < 4096; ++i)
198 status =
generic->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out1, 64 * 2, &roi);
200 if (status != PRIMITIVES_SUCCESS)
203 status = optimized->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out2, 64 * 2, &roi);
205 if (status != PRIMITIVES_SUCCESS)
208 for (
int i = 0; i < 4096; ++i)
210 if ((ABS(r1[i] - r2[i]) > 1) || (ABS(g1[i] - g2[i]) > 1) || (ABS(b1[i] - b2[i]) > 1))
212 printf(
"YCbCrToRGB-SSE FAIL[%d]: %" PRId16
",%" PRId16
",%" PRId16
" vs %" PRId16
213 ",%" PRId16
",%" PRId16
"\n",
214 i, r1[i], g1[i], b1[i], r2[i], g2[i], b2[i]);
223 static int test_yCbCrToRGB_16s16s_P3P3_speed(
void)
226 INT16 ALIGN(y[4096]);
227 INT16 ALIGN(cb[4096]);
228 INT16 ALIGN(cr[4096]);
229 INT16 ALIGN(r[4096]);
230 INT16 ALIGN(g[4096]);
231 INT16 ALIGN(b[4096]);
232 const INT16* input[3];
234 winpr_RAND(y,
sizeof(y));
235 winpr_RAND(cb,
sizeof(cb));
236 winpr_RAND(cr,
sizeof(cr));
239 for (
int i = 0; i < 4096; ++i)
253 if (!speed_test(
"yCbCrToRGB_16s16s_P3P3",
"aligned", g_Iterations,
254 (speed_test_fkt)generic->yCbCrToRGB_16s16s_P3P3,
255 (speed_test_fkt)optimized->yCbCrToRGB_16s16s_P3P3, input, 64 * 2, output,
262 int TestPrimitivesColors(
int argc,
char* argv[])
264 const DWORD formats[] = { PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_ABGR32,
265 PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32,
266 PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 };
270 prim_test_setup(FALSE);
272 for (UINT32 x = 0; x <
sizeof(formats) /
sizeof(formats[0]); x++)
274 if (!test_RGBToRGB_16s8u_P3AC4R_func(roi, formats[x]))
279 if (g_TestPrimitivesPerformance)
281 if (!test_RGBToRGB_16s8u_P3AC4R_speed())
285 if (!test_yCbCrToRGB_16s16s_P3P3_func())
288 if (g_TestPrimitivesPerformance)
290 if (!test_yCbCrToRGB_16s16s_P3P3_speed())