19#include <freerdp/config.h> 
   21#include <winpr/sysinfo.h> 
   23#include <freerdp/utils/profiler.h> 
   26static BOOL test_YCoCgRToRGB_8u_AC4R_func(UINT32 width, UINT32 height)
 
   28  pstatus_t status = -1;
 
   32  const UINT32 srcStride = width * 4;
 
   33  const UINT32 size = srcStride * height;
 
   34  const UINT32 formats[] = { PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_RGBA32,
 
   35                           PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 };
 
   36  PROFILER_DEFINE(genericProf)
 
   37  PROFILER_DEFINE(optProf)
 
   38  in = winpr_aligned_calloc(1, size, 16);
 
   39  out_c = winpr_aligned_calloc(1, size, 16);
 
   40  out_sse = winpr_aligned_calloc(1, size, 16);
 
   42  if (!in || !out_c || !out_sse)
 
   47  for (
size_t x = 0; x < 
sizeof(formats) / 
sizeof(formats[0]); x++)
 
   49    const UINT32 format = formats[x];
 
   50    const UINT32 dstStride = width * FreeRDPGetBytesPerPixel(format);
 
   51    const char* formatName = FreeRDPGetColorFormatName(format);
 
   52    PROFILER_CREATE(genericProf, 
"YCoCgRToRGB_8u_AC4R-GENERIC")
 
   53    PROFILER_CREATE(optProf, "YCoCgRToRGB_8u_AC4R-OPT")
 
   54    PROFILER_ENTER(genericProf)
 
   55    status = generic->YCoCgToRGB_8u_AC4R(in, WINPR_ASSERTING_INT_CAST(
int, srcStride), out_c,
 
   56                                         format, WINPR_ASSERTING_INT_CAST(
int, dstStride),
 
   57                                         width, height, 2, TRUE);
 
   58    PROFILER_EXIT(genericProf)
 
   60    if (status != PRIMITIVES_SUCCESS)
 
   63    PROFILER_ENTER(optProf)
 
   64    status = optimized->YCoCgToRGB_8u_AC4R(
 
   65        in, WINPR_ASSERTING_INT_CAST(
int, srcStride), out_sse, format,
 
   66        WINPR_ASSERTING_INT_CAST(
int, dstStride), width, height, 2, TRUE);
 
   67    PROFILER_EXIT(optProf)
 
   69    if (status != PRIMITIVES_SUCCESS)
 
   72    if (memcmp(out_c, out_sse, 1ULL * dstStride * height) != 0)
 
   74      for (
size_t i = 0; i < 1ull * width * height; ++i)
 
   76        const UINT32 c = FreeRDPReadColor(out_c + 4 * i, format);
 
   77        const UINT32 sse = FreeRDPReadColor(out_sse + 4 * i, format);
 
   81          printf(
"optimized->YCoCgRToRGB FAIL[%s] [%" PRIuz 
"]: 0x%08" PRIx32
 
   82                 " -> C 0x%08" PRIx32 
" vs optimized 0x%08" PRIx32 
"\n",
 
   83                 formatName, i, in[i + 1], c, sse);
 
   89    printf(
"--------------------------- [%s] [%" PRIu32 
"x%" PRIu32
 
   90           "] ---------------------------\n",
 
   91           formatName, width, height);
 
   93    PROFILER_PRINT(genericProf)
 
   94    PROFILER_PRINT(optProf)
 
   97    PROFILER_FREE(genericProf)
 
   98    PROFILER_FREE(optProf)
 
  100    if (status != PRIMITIVES_SUCCESS)
 
  105  winpr_aligned_free(in);
 
  106  winpr_aligned_free(out_c);
 
  107  winpr_aligned_free(out_sse);
 
  108  return status == PRIMITIVES_SUCCESS;
 
  111int TestPrimitivesYCoCg(
int argc, 
char* argv[])
 
  115  prim_test_setup(FALSE);
 
  120    for (UINT32 x = 0; x < 10; x++)
 
  127        winpr_RAND(&w, 
sizeof(w));
 
  133        winpr_RAND(&h, 
sizeof(h));
 
  137      if (!test_YCoCgRToRGB_8u_AC4R_func(w, h))
 
  143  if (!test_YCoCgRToRGB_8u_AC4R_func(1920 / 4, 1080 / 4))