15#include <freerdp/config.h>
17#include <winpr/sysinfo.h>
18#include <freerdp/utils/profiler.h>
23static 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)
47 if (winpr_RAND(r, 1ULL * rgbStride * roi.height) < 0)
49 if (winpr_RAND(g, 1ULL * rgbStride * roi.height) < 0)
51 if (winpr_RAND(b, 1ULL * rgbStride * roi.height) < 0)
56 PROFILER_ENTER(genericProf)
58 if (generic->RGBToRGB_16s8u_P3AC4R(ptrs, rgbStride, out1, dstStride, DstFormat, &roi) !=
62 PROFILER_EXIT(genericProf)
63 PROFILER_ENTER(optProf)
65 if (optimized->RGBToRGB_16s8u_P3AC4R(ptrs, rgbStride, out2, dstStride, DstFormat, &roi) !=
69 PROFILER_EXIT(optProf)
71 if (memcmp(out1, out2, 1ULL * dstStride * roi.height) != 0)
73 for (UINT64 i = 0; i < 1ull * roi.width * roi.height; ++i)
75 const UINT32 o1 = FreeRDPReadColor(out1 + 4 * i, DstFormat);
76 const UINT32 o2 = FreeRDPReadColor(out2 + 4 * i, DstFormat);
80 printf(
"RGBToRGB_16s8u_P3AC4R FAIL: out1[%" PRIu64
"]=0x%08" PRIx8
" out2[%" PRIu64
82 i, out1[i], i, out2[i]);
88 printf(
"Results for %" PRIu32
"x%" PRIu32
" [%s]\n", roi.width, roi.height,
89 FreeRDPGetColorFormatName(DstFormat));
91 PROFILER_PRINT(genericProf)
92 PROFILER_PRINT(optProf)
95 PROFILER_FREE(genericProf)
96 PROFILER_FREE(optProf)
97 winpr_aligned_free(r);
98 winpr_aligned_free(g);
99 winpr_aligned_free(b);
100 winpr_aligned_free(out1);
101 winpr_aligned_free(out2);
106static BOOL test_RGBToRGB_16s8u_P3AC4R_speed(
void)
114 INT16 r[4096 + 1] = WINPR_C_ARRAY_INIT;
115 INT16 g[4096 + 1] = WINPR_C_ARRAY_INIT;
116 INT16 b[4096 + 1] = WINPR_C_ARRAY_INIT;
117 UINT32 dst[4096 + 1] = WINPR_C_ARRAY_INIT;
118 INT16* ptrs[3] = WINPR_C_ARRAY_INIT;
119 if (winpr_RAND(r,
sizeof(r)) < 0)
121 if (winpr_RAND(g,
sizeof(g)) < 0)
123 if (winpr_RAND(b,
sizeof(b)) < 0)
127 for (
int i = 0; i < 4096; ++i)
139 if (!speed_test(
"RGBToRGB_16s8u_P3AC4R",
"aligned", g_Iterations,
140 (speed_test_fkt)generic->RGBToRGB_16s8u_P3AC4R,
141 (speed_test_fkt)optimized->RGBToRGB_16s8u_P3AC4R, cnv.cpv, 64 * 2, (BYTE*)dst,
145 if (!speed_test(
"RGBToRGB_16s8u_P3AC4R",
"unaligned", g_Iterations,
146 (speed_test_fkt)generic->RGBToRGB_16s8u_P3AC4R,
147 (speed_test_fkt)optimized->RGBToRGB_16s8u_P3AC4R, cnv.cpv, 64 * 2,
148 ((BYTE*)dst) + 1, 64 * 4, &roi64x64))
155static BOOL test_yCbCrToRGB_16s16s_P3P3_func(
void)
157 pstatus_t status = 0;
158 INT16 y[4096] = WINPR_C_ARRAY_INIT;
159 INT16 cb[4096] = WINPR_C_ARRAY_INIT;
160 INT16 cr[4096] = WINPR_C_ARRAY_INIT;
161 INT16 r1[4096] = WINPR_C_ARRAY_INIT;
162 INT16 g1[4096] = WINPR_C_ARRAY_INIT;
163 INT16 b1[4096] = WINPR_C_ARRAY_INIT;
164 INT16 r2[4096] = WINPR_C_ARRAY_INIT;
165 INT16 g2[4096] = WINPR_C_ARRAY_INIT;
166 INT16 b2[4096] = WINPR_C_ARRAY_INIT;
171 if (winpr_RAND(y,
sizeof(y)) < 0)
173 if (winpr_RAND(cb,
sizeof(cb)) < 0)
175 if (winpr_RAND(cr,
sizeof(cr)) < 0)
179 for (
int i = 0; i < 4096; ++i)
195 status =
generic->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out1, 64 * 2, &roi);
197 if (status != PRIMITIVES_SUCCESS)
200 status = optimized->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out2, 64 * 2, &roi);
202 if (status != PRIMITIVES_SUCCESS)
205 for (
int i = 0; i < 4096; ++i)
207 if ((ABS(r1[i] - r2[i]) > 1) || (ABS(g1[i] - g2[i]) > 1) || (ABS(b1[i] - b2[i]) > 1))
209 printf(
"YCbCrToRGB-SSE FAIL[%d]: %" PRId16
",%" PRId16
",%" PRId16
" vs %" PRId16
210 ",%" PRId16
",%" PRId16
"\n",
211 i, r1[i], g1[i], b1[i], r2[i], g2[i], b2[i]);
220static int test_yCbCrToRGB_16s16s_P3P3_speed(
void)
223 INT16 y[4096] = WINPR_C_ARRAY_INIT;
224 INT16 cb[4096] = WINPR_C_ARRAY_INIT;
225 INT16 cr[4096] = WINPR_C_ARRAY_INIT;
226 INT16 r[4096] = WINPR_C_ARRAY_INIT;
227 INT16 g[4096] = WINPR_C_ARRAY_INIT;
228 INT16 b[4096] = WINPR_C_ARRAY_INIT;
229 const INT16* input[3] = WINPR_C_ARRAY_INIT;
230 INT16* output[3] = WINPR_C_ARRAY_INIT;
231 if (winpr_RAND(y,
sizeof(y)) < 0)
233 if (winpr_RAND(cb,
sizeof(cb)) < 0)
235 if (winpr_RAND(cr,
sizeof(cr)) < 0)
239 for (
int i = 0; i < 4096; ++i)
253 return (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,
259int TestPrimitivesColors(
int argc,
char* argv[])
261 const DWORD formats[] = { PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_ABGR32,
262 PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32,
263 PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 };
267 prim_test_setup(FALSE);
269 for (UINT32 x = 0; x <
sizeof(formats) /
sizeof(formats[0]); x++)
271 if (!test_RGBToRGB_16s8u_P3AC4R_func(roi, formats[x]))
274 if (g_TestPrimitivesPerformance)
276 if (!test_RGBToRGB_16s8u_P3AC4R_speed())
280 if (!test_yCbCrToRGB_16s16s_P3P3_func())
283 if (g_TestPrimitivesPerformance)
285 if (!test_yCbCrToRGB_16s16s_P3P3_speed())