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