22HGDI_BITMAP test_convert_to_bitmap(
const BYTE* src, UINT32 SrcFormat, UINT32 SrcStride, UINT32 xSrc,
 
   23                                   UINT32 ySrc, UINT32 DstFormat, UINT32 DstStride, UINT32 xDst,
 
   24                                   UINT32 yDst, UINT32 nWidth, UINT32 nHeight,
 
   25                                   const gdiPalette* hPalette)
 
   31    DstStride = nWidth * FreeRDPGetBytesPerPixel(DstFormat);
 
   33  data = winpr_aligned_malloc(1ULL * DstStride * nHeight, 16);
 
   38  if (!freerdp_image_copy(data, DstFormat, DstStride, xDst, yDst, nWidth, nHeight, src, SrcFormat,
 
   39                          SrcStride, xSrc, ySrc, hPalette, FREERDP_FLIP_NONE))
 
   41    winpr_aligned_free(data);
 
   45  bmp = gdi_CreateBitmap(nWidth, nHeight, DstFormat, data);
 
   49    winpr_aligned_free(data);
 
   56static void test_dump_data(
unsigned char* p, 
size_t len, 
size_t width, 
const char* name)
 
   58  unsigned char* line = p;
 
   59  const size_t stride = (width > 0) ? len / width : 1;
 
   61  printf(
"\n%s[%" PRIuz 
"][%" PRIuz 
"]:\n", name, stride, width);
 
   66    printf(
"%04" PRIxz 
" ", offset);
 
   67    size_t thisline = len - offset;
 
   72    for (; i < thisline; i++)
 
   73      printf(
"%02x ", line[i]);
 
   75    for (; i < width; i++)
 
   87void test_dump_bitmap(
HGDI_BITMAP hBmp, 
const char* name)
 
   90      WINPR_ASSERTING_INT_CAST(
size_t, hBmp->width) * FreeRDPGetBytesPerPixel(hBmp->format);
 
   91  test_dump_data(hBmp->data, stride * WINPR_ASSERTING_INT_CAST(uint32_t, hBmp->height), stride,
 
   97  const BYTE* p1 = hBmp1->data;
 
   98  const BYTE* p2 = hBmp2->data;
 
   99  const UINT32 minw = WINPR_ASSERTING_INT_CAST(
 
  100      uint32_t, (hBmp1->width < hBmp2->width) ? hBmp1->width : hBmp2->width);
 
  101  const UINT32 minh = WINPR_ASSERTING_INT_CAST(
 
  102      uint32_t, (hBmp1->height < hBmp2->height) ? hBmp1->height : hBmp2->height);
 
  104  for (UINT32 y = 0; y < minh; y++)
 
  106    for (UINT32 x = 0; x < minw; x++)
 
  108      UINT32 colorA = FreeRDPReadColor(p1, hBmp1->format);
 
  109      UINT32 colorB = FreeRDPReadColor(p2, hBmp2->format);
 
  110      p1 += FreeRDPGetBytesPerPixel(hBmp1->format);
 
  111      p2 += FreeRDPGetBytesPerPixel(hBmp2->format);
 
  113      if (hBmp1->format != hBmp2->format)
 
  114        colorB = FreeRDPConvertColor(colorB, hBmp2->format, hBmp1->format, palette);
 
  116      if (colorA != colorB)
 
  125                               const gdiPalette* palette)
 
  127  BOOL bitmapsEqual = CompareBitmaps(hBmpActual, hBmpExpected, palette);
 
  131    printf(
"Testing ROP %s [%s|%s]\n", name, FreeRDPGetColorFormatName(hBmpActual->format),
 
  132           FreeRDPGetColorFormatName(hBmpExpected->format));
 
  133    test_dump_bitmap(hBmpActual, 
"Actual");
 
  134    test_dump_bitmap(hBmpExpected, 
"Expected");
 
  135    (void)fflush(stdout);
 
  136    (void)fflush(stderr);