2 #include <freerdp/gdi/gdi.h>
4 #include <freerdp/gdi/dc.h>
5 #include <freerdp/gdi/pen.h>
6 #include <freerdp/gdi/region.h>
7 #include <freerdp/gdi/bitmap.h>
10 #include <winpr/crypto.h>
16 static const UINT32 colorFormatList[] = {
17 PIXEL_FORMAT_RGB15, PIXEL_FORMAT_BGR15, PIXEL_FORMAT_RGB16, PIXEL_FORMAT_BGR16,
18 PIXEL_FORMAT_RGB24, PIXEL_FORMAT_BGR24, PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_ABGR32,
19 PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGRX32
22 static const UINT32 colorFormatCount =
sizeof(colorFormatList) /
sizeof(colorFormatList[0]);
24 static int test_gdi_GetDC(
void)
29 if (!(hdc = gdi_GetDC()))
31 printf(
"failed to get gdi device context\n");
35 if (hdc->format != PIXEL_FORMAT_XRGB32)
38 if (hdc->drawMode != GDI_R2_BLACK)
47 static int test_gdi_CreateCompatibleDC(
void)
53 if (!(hdc = gdi_GetDC()))
55 printf(
"failed to get gdi device context\n");
59 hdc->format = PIXEL_FORMAT_RGB16;
60 hdc->drawMode = GDI_R2_XORPEN;
62 if (!(chdc = gdi_CreateCompatibleDC(hdc)))
64 printf(
"gdi_CreateCompatibleDC failed\n");
68 if (chdc->format != hdc->format)
71 if (chdc->drawMode != hdc->drawMode)
84 static int test_gdi_CreateBitmap(
void)
87 UINT32 format = PIXEL_FORMAT_ARGB32;
95 if (!(data = (BYTE*)winpr_aligned_malloc(4ULL * width * height, 16)))
97 printf(
"failed to allocate aligned bitmap data memory\n");
101 if (!(hBitmap = gdi_CreateBitmap(width, height, format, data)))
103 printf(
"gdi_CreateBitmap failed\n");
107 if (hBitmap->objectType != GDIOBJECT_BITMAP)
110 if (hBitmap->format != format)
113 if (hBitmap->width != width)
116 if (hBitmap->height != height)
119 if (hBitmap->data != data)
128 winpr_aligned_free(data);
133 static int test_gdi_CreateCompatibleBitmap(
void)
141 if (!(hdc = gdi_GetDC()))
143 printf(
"failed to get gdi device context\n");
147 hdc->format = PIXEL_FORMAT_ARGB32;
150 hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
152 if (hBitmap->objectType != GDIOBJECT_BITMAP)
155 if (hBitmap->format != hdc->format)
158 if (hBitmap->width != width)
161 if (hBitmap->height != height)
177 static int test_gdi_CreatePen(
void)
180 const UINT32 format = PIXEL_FORMAT_RGBA32;
181 HGDI_PEN hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD, format, NULL);
185 printf(
"gdi_CreatePen failed\n");
189 if (hPen->style != GDI_PS_SOLID)
192 if (hPen->width != 8)
195 if (hPen->color != 0xAABBCCDD)
204 static int test_gdi_CreateSolidBrush(
void)
207 HGDI_BRUSH hBrush = gdi_CreateSolidBrush(0xAABBCCDD);
209 if (hBrush->objectType != GDIOBJECT_BRUSH)
212 if (hBrush->style != GDI_BS_SOLID)
215 if (hBrush->color != 0xAABBCCDD)
224 static int test_gdi_CreatePatternBrush(
void)
229 hBitmap = gdi_CreateBitmap(64, 64, 32, NULL);
230 hBrush = gdi_CreatePatternBrush(hBitmap);
232 if (!hBitmap || !hBrush)
235 if (hBrush->objectType != GDIOBJECT_BRUSH)
238 if (hBrush->style != GDI_BS_PATTERN)
241 if (hBrush->pattern != hBitmap)
256 static int test_gdi_CreateRectRgn(
void)
263 HGDI_RGN hRegion = gdi_CreateRectRgn(x1, y1, x2, y2);
268 if (hRegion->objectType != GDIOBJECT_REGION)
271 if (hRegion->x != x1)
274 if (hRegion->y != y1)
277 if (hRegion->w != x2 - x1 + 1)
280 if (hRegion->h != y2 - y1 + 1)
292 static int test_gdi_CreateRect(
void)
301 if (!(hRect = gdi_CreateRect(x1, y1, x2, y2)))
303 printf(
"gdi_CreateRect failed\n");
307 if (hRect->objectType != GDIOBJECT_RECT)
310 if (hRect->left != x1)
313 if (hRect->top != y1)
316 if (hRect->right != x2)
319 if (hRect->bottom != y2)
328 static BYTE prand(
void)
331 winpr_RAND(&tmp,
sizeof(tmp));
335 static BOOL test_gdi_GetPixel(
void)
339 for (UINT32 x = 0; x < colorFormatCount; x++)
347 if (!(hdc = gdi_GetDC()))
349 printf(
"failed to get gdi device context\n");
353 hdc->format = colorFormatList[x];
354 hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
363 bpp = FreeRDPGetBytesPerPixel(hBitmap->format);
365 for (UINT32 i = 0; i < height; i++)
367 for (UINT32 j = 0; j < width; j++)
371 FreeRDPGetColor(hBitmap->format, prand(), prand(), prand(), prand());
372 FreeRDPWriteColor(&hBitmap->data[i * hBitmap->scanline + j * bpp], hBitmap->format,
374 pixel = gdi_GetPixel(hdc, j, i);
394 static BOOL test_gdi_SetPixel(
void)
398 for (UINT32 x = 0; x < colorFormatCount; x++)
406 if (!(hdc = gdi_GetDC()))
408 printf(
"failed to get gdi device context\n");
412 hdc->format = colorFormatList[x];
413 hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
415 bpp = FreeRDPGetBytesPerPixel(hBitmap->format);
417 for (UINT32 i = 0; i < height; i++)
419 for (UINT32 j = 0; j < width; j++)
423 FreeRDPGetColor(hBitmap->format, prand(), prand(), prand(), prand());
424 gdi_SetPixel(hdc, j, i, color);
425 pixel = FreeRDPReadColor(&hBitmap->data[i * hBitmap->scanline + j * bpp],
446 static int test_gdi_SetROP2(
void)
451 if (!(hdc = gdi_GetDC()))
453 printf(
"failed to get gdi device context\n");
457 gdi_SetROP2(hdc, GDI_R2_BLACK);
459 if (hdc->drawMode != GDI_R2_BLACK)
468 static int test_gdi_MoveToEx(
void)
474 const UINT32 format = PIXEL_FORMAT_RGBA32;
475 gdiPalette* palette = NULL;
477 if (!(hdc = gdi_GetDC()))
479 printf(
"failed to get gdi device context\n");
483 if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD, format, palette)))
485 printf(
"gdi_CreatePen failed\n");
490 gdi_MoveToEx(hdc, 128, 256, NULL);
492 if (hdc->pen->posX != 128)
495 if (hdc->pen->posY != 256)
499 ZeroMemory(prevPoint,
sizeof(
GDI_POINT));
500 gdi_MoveToEx(hdc, 64, 128, prevPoint);
502 if (prevPoint->x != 128)
505 if (prevPoint->y != 256)
508 if (hdc->pen->posX != 64)
511 if (hdc->pen->posY != 128)
525 int TestGdiCreate(
int argc,
char* argv[])
529 (void)fprintf(stderr,
"test_gdi_GetDC()\n");
531 if (test_gdi_GetDC() < 0)
534 (void)fprintf(stderr,
"test_gdi_CreateCompatibleDC()\n");
536 if (test_gdi_CreateCompatibleDC() < 0)
539 (void)fprintf(stderr,
"test_gdi_CreateBitmap()\n");
541 if (test_gdi_CreateBitmap() < 0)
544 (void)fprintf(stderr,
"test_gdi_CreateCompatibleBitmap()\n");
546 if (test_gdi_CreateCompatibleBitmap() < 0)
549 (void)fprintf(stderr,
"test_gdi_CreatePen()\n");
551 if (test_gdi_CreatePen() < 0)
554 (void)fprintf(stderr,
"test_gdi_CreateSolidBrush()\n");
556 if (test_gdi_CreateSolidBrush() < 0)
559 (void)fprintf(stderr,
"test_gdi_CreatePatternBrush()\n");
561 if (test_gdi_CreatePatternBrush() < 0)
564 (void)fprintf(stderr,
"test_gdi_CreateRectRgn()\n");
566 if (test_gdi_CreateRectRgn() < 0)
569 (void)fprintf(stderr,
"test_gdi_CreateRect()\n");
571 if (test_gdi_CreateRect() < 0)
574 (void)fprintf(stderr,
"test_gdi_GetPixel()\n");
576 if (!test_gdi_GetPixel())
579 (void)fprintf(stderr,
"test_gdi_SetPixel()\n");
581 if (!test_gdi_SetPixel())
584 (void)fprintf(stderr,
"test_gdi_SetROP2()\n");
586 if (test_gdi_SetROP2() < 0)
589 (void)fprintf(stderr,
"test_gdi_MoveToEx()\n");
591 if (test_gdi_MoveToEx() < 0)