22#include <freerdp/config.h>
28#include <freerdp/freerdp.h>
29#include <freerdp/gdi/gdi.h>
31#include <freerdp/gdi/bitmap.h>
32#include <freerdp/gdi/region.h>
33#include <freerdp/gdi/shape.h>
35#include <freerdp/log.h>
38#include "../gdi/gdi.h"
40#define TAG FREERDP_TAG("gdi.shape")
43static BOOL Ellipse_Bresenham(
HGDI_DC hdc,
int x1,
int y1,
int x2,
int y2)
45 INT32 a = (x1 < x2) ? x2 - x1 : x1 - x2;
46 const INT32 b = (y1 < y2) ? y2 - y1 : y1 - y2;
48 INT32 dx = 4 * (1 - a) * b * b;
49 INT32 dy = 4 * (c + 1) * a * a;
50 INT32 e = dx + dy + c * a * a;
68 gdi_SetPixel(hdc, WINPR_ASSERTING_INT_CAST(UINT32, x2),
69 WINPR_ASSERTING_INT_CAST(UINT32, y1), 0);
70 gdi_SetPixel(hdc, WINPR_ASSERTING_INT_CAST(UINT32, x1),
71 WINPR_ASSERTING_INT_CAST(UINT32, y1), 0);
72 gdi_SetPixel(hdc, WINPR_ASSERTING_INT_CAST(UINT32, x1),
73 WINPR_ASSERTING_INT_CAST(UINT32, y2), 0);
74 gdi_SetPixel(hdc, WINPR_ASSERTING_INT_CAST(UINT32, x2),
75 WINPR_ASSERTING_INT_CAST(UINT32, y2), 0);
77 const INT32 e2 = 2 * e;
99 gdi_SetPixel(hdc, WINPR_ASSERTING_INT_CAST(uint32_t, x1 - 1),
100 WINPR_ASSERTING_INT_CAST(uint32_t, y1), 0);
101 gdi_SetPixel(hdc, WINPR_ASSERTING_INT_CAST(uint32_t, x1 - 1),
102 WINPR_ASSERTING_INT_CAST(uint32_t, y2), 0);
119BOOL gdi_Ellipse(
HGDI_DC hdc,
int nLeftRect,
int nTopRect,
int nRightRect,
int nBottomRect)
121 return Ellipse_Bresenham(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect);
142 if (!gdi_RectToCRgn(rect, &nXDest, &nYDest, &nWidth, &nHeight))
148 if (!gdi_ClipCoords(hdc, &nXDest, &nYDest, &nWidth, &nHeight,
nullptr,
nullptr))
155 const UINT32 color = hbr->color;
157 for (INT32 x = 0; x < nWidth; x++)
159 BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest + x, nYDest);
162 FreeRDPWriteColor(dstp, hdc->format, color);
165 const BYTE* srcp = gdi_get_bitmap_pointer(hdc, nXDest, nYDest);
166 const UINT32 formatSize = FreeRDPGetBytesPerPixel(hdc->format);
170 for (INT32 y = 1; y < nHeight; y++)
172 BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest, nYDest + y);
175 memcpy(dstp, srcp, 1ull * WINPR_ASSERTING_INT_CAST(
size_t, nWidth) * formatSize);
183 const BOOL monochrome = (hbr->pattern->format == PIXEL_FORMAT_MONO);
184 const UINT32 formatSize = FreeRDPGetBytesPerPixel(hbr->pattern->format);
188 for (INT32 y = 0; y < nHeight; y++)
190 for (INT32 x = 0; x < nWidth; x++)
192 const size_t yOffset =
193 ((1ULL * WINPR_ASSERTING_INT_CAST(
size_t, nYDest) +
194 WINPR_ASSERTING_INT_CAST(
size_t, y)) *
195 WINPR_ASSERTING_INT_CAST(
size_t, hbr->pattern->width) %
196 WINPR_ASSERTING_INT_CAST(
size_t, hbr->pattern->height)) *
198 const size_t xOffset = ((1ULL * WINPR_ASSERTING_INT_CAST(
size_t, nXDest) +
199 WINPR_ASSERTING_INT_CAST(
size_t, x)) %
200 WINPR_ASSERTING_INT_CAST(
size_t, hbr->pattern->width)) *
202 const BYTE* patp = &hbr->pattern->data[yOffset + xOffset];
208 dstColor = hdc->bkColor;
210 dstColor = hdc->textColor;
214 const UINT32 tmp = FreeRDPReadColor(patp, hbr->pattern->format);
216 FreeRDPConvertColor(tmp, hbr->pattern->format, hdc->format,
nullptr);
219 BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest + x, nYDest + y);
221 FreeRDPWriteColor(dstp, hdc->format, dstColor);
231 return gdi_InvalidateRegion(hdc, nXDest, nYDest, nWidth, nHeight);
242BOOL gdi_Polygon(WINPR_ATTR_UNUSED
HGDI_DC hdc, WINPR_ATTR_UNUSED
GDI_POINT* lpPoints,
243 WINPR_ATTR_UNUSED
int nCount)
245 WLog_ERR(TAG,
"Not implemented!");
258BOOL gdi_PolyPolygon(WINPR_ATTR_UNUSED
HGDI_DC hdc, WINPR_ATTR_UNUSED
GDI_POINT* lpPoints,
259 WINPR_ATTR_UNUSED
int* lpPolyCounts, WINPR_ATTR_UNUSED
int nCount)
261 WLog_ERR(TAG,
"Not implemented!");
265BOOL gdi_Rectangle(
HGDI_DC hdc, INT32 nXDst, INT32 nYDst, INT32 nWidth, INT32 nHeight)
269 if (!gdi_ClipCoords(hdc, &nXDst, &nYDst, &nWidth, &nHeight,
nullptr,
nullptr))
272 color = hdc->textColor;
274 for (INT32 y = 0; y < nHeight; y++)
276 BYTE* dstLeft = gdi_get_bitmap_pointer(hdc, nXDst, nYDst + y);
277 BYTE* dstRight = gdi_get_bitmap_pointer(hdc, nXDst + nWidth - 1, nYDst + y);
280 FreeRDPWriteColor(dstLeft, hdc->format, color);
283 FreeRDPWriteColor(dstRight, hdc->format, color);
286 for (INT32 x = 0; x < nWidth; x++)
288 BYTE* dstTop = gdi_get_bitmap_pointer(hdc, nXDst + x, nYDst);
289 BYTE* dstBottom = gdi_get_bitmap_pointer(hdc, nXDst + x, nYDst + nHeight - 1);
292 FreeRDPWriteColor(dstTop, hdc->format, color);
295 FreeRDPWriteColor(dstBottom, hdc->format, color);