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  winpr_RAND(r, 1ULL * rgbStride * roi.height);
 
   48  winpr_RAND(g, 1ULL * rgbStride * roi.height);
 
   49  winpr_RAND(b, 1ULL * rgbStride * roi.height);
 
   53  PROFILER_ENTER(genericProf)
 
   55  if (generic->RGBToRGB_16s8u_P3AC4R(ptrs, rgbStride, out1, dstStride, DstFormat, &roi) !=
 
   59  PROFILER_EXIT(genericProf)
 
   60  PROFILER_ENTER(optProf)
 
   62  if (optimized->RGBToRGB_16s8u_P3AC4R(ptrs, rgbStride, out2, dstStride, DstFormat, &roi) !=
 
   66  PROFILER_EXIT(optProf)
 
   68  if (memcmp(out1, out2, 1ULL * dstStride * roi.height) != 0)
 
   70    for (UINT64 i = 0; i < 1ull * roi.width * roi.height; ++i)
 
   72      const UINT32 o1 = FreeRDPReadColor(out1 + 4 * i, DstFormat);
 
   73      const UINT32 o2 = FreeRDPReadColor(out2 + 4 * i, DstFormat);
 
   77        printf(
"RGBToRGB_16s8u_P3AC4R FAIL: out1[%" PRIu64 
"]=0x%08" PRIx8 
" out2[%" PRIu64
 
   79               i, out1[i], i, out2[i]);
 
   85  printf(
"Results for %" PRIu32 
"x%" PRIu32 
" [%s]\n", roi.width, roi.height,
 
   86         FreeRDPGetColorFormatName(DstFormat));
 
   88  PROFILER_PRINT(genericProf)
 
   89  PROFILER_PRINT(optProf)
 
   92  PROFILER_FREE(genericProf)
 
   93  PROFILER_FREE(optProf)
 
   94  winpr_aligned_free(r);
 
   95  winpr_aligned_free(g);
 
   96  winpr_aligned_free(b);
 
   97  winpr_aligned_free(out1);
 
   98  winpr_aligned_free(out2);
 
  103static BOOL test_RGBToRGB_16s8u_P3AC4R_speed(
void)
 
  111  INT16 ALIGN(r[4096 + 1]);
 
  112  INT16 ALIGN(g[4096 + 1]);
 
  113  INT16 ALIGN(b[4096 + 1]);
 
  114  UINT32 ALIGN(dst[4096 + 1]);
 
  116  winpr_RAND(r, 
sizeof(r));
 
  117  winpr_RAND(g, 
sizeof(g));
 
  118  winpr_RAND(b, 
sizeof(b));
 
  121  for (
int i = 0; i < 4096; ++i)
 
  133  if (!speed_test(
"RGBToRGB_16s8u_P3AC4R", 
"aligned", g_Iterations,
 
  134                  (speed_test_fkt)generic->RGBToRGB_16s8u_P3AC4R,
 
  135                  (speed_test_fkt)optimized->RGBToRGB_16s8u_P3AC4R, cnv.cpv, 64 * 2, (BYTE*)dst,
 
  139  if (!speed_test(
"RGBToRGB_16s8u_P3AC4R", 
"unaligned", g_Iterations,
 
  140                  (speed_test_fkt)generic->RGBToRGB_16s8u_P3AC4R,
 
  141                  (speed_test_fkt)optimized->RGBToRGB_16s8u_P3AC4R, cnv.cpv, 64 * 2,
 
  142                  ((BYTE*)dst) + 1, 64 * 4, &roi64x64))
 
  149static BOOL test_yCbCrToRGB_16s16s_P3P3_func(
void)
 
  151  pstatus_t status = 0;
 
  152  INT16 ALIGN(y[4096]) = { 0 };
 
  153  INT16 ALIGN(cb[4096]) = { 0 };
 
  154  INT16 ALIGN(cr[4096]) = { 0 };
 
  155  INT16 ALIGN(r1[4096]) = { 0 };
 
  156  INT16 ALIGN(g1[4096]) = { 0 };
 
  157  INT16 ALIGN(b1[4096]) = { 0 };
 
  158  INT16 ALIGN(r2[4096]) = { 0 };
 
  159  INT16 ALIGN(g2[4096]) = { 0 };
 
  160  INT16 ALIGN(b2[4096]) = { 0 };
 
  165  winpr_RAND(y, 
sizeof(y));
 
  166  winpr_RAND(cb, 
sizeof(cb));
 
  167  winpr_RAND(cr, 
sizeof(cr));
 
  170  for (
int i = 0; i < 4096; ++i)
 
  186  status = 
generic->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out1, 64 * 2, &roi);
 
  188  if (status != PRIMITIVES_SUCCESS)
 
  191  status = optimized->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out2, 64 * 2, &roi);
 
  193  if (status != PRIMITIVES_SUCCESS)
 
  196  for (
int i = 0; i < 4096; ++i)
 
  198    if ((ABS(r1[i] - r2[i]) > 1) || (ABS(g1[i] - g2[i]) > 1) || (ABS(b1[i] - b2[i]) > 1))
 
  200      printf(
"YCbCrToRGB-SSE FAIL[%d]: %" PRId16 
",%" PRId16 
",%" PRId16 
" vs %" PRId16
 
  201             ",%" PRId16 
",%" PRId16 
"\n",
 
  202             i, r1[i], g1[i], b1[i], r2[i], g2[i], b2[i]);
 
  211static int test_yCbCrToRGB_16s16s_P3P3_speed(
void)
 
  214  INT16 ALIGN(y[4096]);
 
  215  INT16 ALIGN(cb[4096]);
 
  216  INT16 ALIGN(cr[4096]);
 
  217  INT16 ALIGN(r[4096]);
 
  218  INT16 ALIGN(g[4096]);
 
  219  INT16 ALIGN(b[4096]);
 
  220  const INT16* input[3];
 
  222  winpr_RAND(y, 
sizeof(y));
 
  223  winpr_RAND(cb, 
sizeof(cb));
 
  224  winpr_RAND(cr, 
sizeof(cr));
 
  227  for (
int i = 0; i < 4096; ++i)
 
  241  if (!speed_test(
"yCbCrToRGB_16s16s_P3P3", 
"aligned", g_Iterations,
 
  242                  (speed_test_fkt)generic->yCbCrToRGB_16s16s_P3P3,
 
  243                  (speed_test_fkt)optimized->yCbCrToRGB_16s16s_P3P3, input, 64 * 2, output,
 
  250int TestPrimitivesColors(
int argc, 
char* argv[])
 
  252  const DWORD formats[] = { PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_ABGR32,
 
  253                          PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32,
 
  254                          PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 };
 
  258  prim_test_setup(FALSE);
 
  260  for (UINT32 x = 0; x < 
sizeof(formats) / 
sizeof(formats[0]); x++)
 
  262    if (!test_RGBToRGB_16s8u_P3AC4R_func(roi, formats[x]))
 
  265    if (g_TestPrimitivesPerformance)
 
  267      if (!test_RGBToRGB_16s8u_P3AC4R_speed())
 
  271    if (!test_yCbCrToRGB_16s16s_P3P3_func())
 
  274    if (g_TestPrimitivesPerformance)
 
  276      if (!test_yCbCrToRGB_16s16s_P3P3_speed())