1
2 #include <freerdp/gdi/gdi.h>
3
4 #include <freerdp/gdi/dc.h>
5 #include <freerdp/gdi/pen.h>
6 #include <freerdp/gdi/shape.h>
7 #include <freerdp/gdi/region.h>
8 #include <freerdp/gdi/bitmap.h>
9
10 #include <winpr/crt.h>
11 #include <winpr/print.h>
12
13 #include "line.h"
14 #include "brush.h"
15 #include "clipping.h"
16
test_gdi_PtInRect(void)17 static int test_gdi_PtInRect(void)
18 {
19 int rc = -1;
20 HGDI_RECT hRect;
21 UINT32 left = 20;
22 UINT32 top = 40;
23 UINT32 right = 60;
24 UINT32 bottom = 80;
25
26 if (!(hRect = gdi_CreateRect(left, top, right, bottom)))
27 {
28 printf("gdi_CreateRect failed\n");
29 return rc;
30 }
31
32 if (gdi_PtInRect(hRect, 0, 0))
33 goto fail;
34
35 if (gdi_PtInRect(hRect, 500, 500))
36 goto fail;
37
38 if (gdi_PtInRect(hRect, 40, 100))
39 goto fail;
40
41 if (gdi_PtInRect(hRect, 10, 40))
42 goto fail;
43
44 if (!gdi_PtInRect(hRect, 30, 50))
45 goto fail;
46
47 if (!gdi_PtInRect(hRect, left, top))
48 goto fail;
49
50 if (!gdi_PtInRect(hRect, right, bottom))
51 goto fail;
52
53 if (!gdi_PtInRect(hRect, right, 60))
54 goto fail;
55
56 if (!gdi_PtInRect(hRect, 40, bottom))
57 goto fail;
58
59 rc = 0;
60 fail:
61 gdi_DeleteObject((HGDIOBJECT)hRect);
62 return rc;
63 }
64
test_gdi_FillRect(void)65 int test_gdi_FillRect(void)
66 {
67 int rc = -1;
68 HGDI_DC hdc = NULL;
69 HGDI_RECT hRect = NULL;
70 HGDI_BRUSH hBrush = NULL;
71 HGDI_BITMAP hBitmap = NULL;
72 UINT32 color;
73 UINT32 pixel;
74 UINT32 rawPixel;
75 UINT32 x, y;
76 UINT32 badPixels;
77 UINT32 goodPixels;
78 UINT32 width = 200;
79 UINT32 height = 300;
80 UINT32 left = 20;
81 UINT32 top = 40;
82 UINT32 right = 60;
83 UINT32 bottom = 80;
84
85 if (!(hdc = gdi_GetDC()))
86 {
87 printf("failed to get gdi device context\n");
88 goto fail;
89 }
90
91 hdc->format = PIXEL_FORMAT_XRGB32;
92
93 if (!(hRect = gdi_CreateRect(left, top, right, bottom)))
94 {
95 printf("gdi_CreateRect failed\n");
96 goto fail;
97 }
98
99 hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
100 ZeroMemory(hBitmap->data, width * height * GetBytesPerPixel(hdc->format));
101 gdi_SelectObject(hdc, (HGDIOBJECT)hBitmap);
102 color = FreeRDPGetColor(PIXEL_FORMAT_ARGB32, 0xAA, 0xBB, 0xCC, 0xFF);
103 hBrush = gdi_CreateSolidBrush(color);
104 gdi_FillRect(hdc, hRect, hBrush);
105 badPixels = 0;
106 goodPixels = 0;
107
108 for (x = 0; x < width; x++)
109 {
110 for (y = 0; y < height; y++)
111 {
112 rawPixel = gdi_GetPixel(hdc, x, y);
113 pixel = FreeRDPConvertColor(rawPixel, hdc->format, PIXEL_FORMAT_ARGB32, NULL);
114
115 if (gdi_PtInRect(hRect, x, y))
116 {
117 if (pixel == color)
118 {
119 goodPixels++;
120 }
121 else
122 {
123 printf("actual:%08" PRIX32 " expected:%08" PRIX32 "\n", gdi_GetPixel(hdc, x, y),
124 color);
125 badPixels++;
126 }
127 }
128 else
129 {
130 if (pixel == color)
131 {
132 badPixels++;
133 }
134 else
135 {
136 goodPixels++;
137 }
138 }
139 }
140 }
141
142 if (goodPixels != width * height)
143 goto fail;
144
145 if (badPixels != 0)
146 goto fail;
147
148 rc = 0;
149 fail:
150 gdi_DeleteObject((HGDIOBJECT)hBrush);
151 gdi_DeleteObject((HGDIOBJECT)hBitmap);
152 gdi_DeleteObject((HGDIOBJECT)hRect);
153 gdi_DeleteDC(hdc);
154 return rc;
155 }
156
TestGdiRect(int argc,char * argv[])157 int TestGdiRect(int argc, char* argv[])
158 {
159 WINPR_UNUSED(argc);
160 WINPR_UNUSED(argv);
161
162 if (test_gdi_PtInRect() < 0)
163 return -1;
164
165 if (test_gdi_FillRect() < 0)
166 return -1;
167
168 return 0;
169 }
170