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);
168 const UINT32 formatSize = FreeRDPGetBytesPerPixel(hdc->format);
172 for (INT32 y = 1; y < nHeight; y++)
174 BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest, nYDest + y);
177 memcpy(dstp, srcp, 1ull * WINPR_ASSERTING_INT_CAST(
size_t, nWidth) * formatSize);
185 const BOOL monochrome = (hbr->pattern->format == PIXEL_FORMAT_MONO);
186 const UINT32 formatSize = FreeRDPGetBytesPerPixel(hbr->pattern->format);
189 if (hbr->pattern->width <= 0)
191 if (hbr->pattern->height <= 0)
194 for (INT32 y = 0; y < nHeight; y++)
196 for (INT32 x = 0; x < nWidth; x++)
198 const size_t yOffset =
199 ((1ULL * WINPR_ASSERTING_INT_CAST(
size_t, nYDest) +
200 WINPR_ASSERTING_INT_CAST(
size_t, y)) *
201 WINPR_ASSERTING_INT_CAST(
size_t, hbr->pattern->width) %
202 WINPR_ASSERTING_INT_CAST(
size_t, hbr->pattern->height)) *
204 const size_t xOffset = ((1ULL * WINPR_ASSERTING_INT_CAST(
size_t, nXDest) +
205 WINPR_ASSERTING_INT_CAST(
size_t, x)) %
206 WINPR_ASSERTING_INT_CAST(
size_t, hbr->pattern->width)) *
208 const BYTE* patp = &hbr->pattern->data[yOffset + xOffset];
214 dstColor = hdc->bkColor;
216 dstColor = hdc->textColor;
220 const UINT32 tmp = FreeRDPReadColor(patp, hbr->pattern->format);
222 FreeRDPConvertColor(tmp, hbr->pattern->format, hdc->format,
nullptr);
225 BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest + x, nYDest + y);
227 FreeRDPWriteColor(dstp, hdc->format, dstColor);
237 return gdi_InvalidateRegion(hdc, nXDest, nYDest, nWidth, nHeight);
248BOOL gdi_Polygon(WINPR_ATTR_UNUSED
HGDI_DC hdc, WINPR_ATTR_UNUSED
GDI_POINT* lpPoints,
249 WINPR_ATTR_UNUSED
int nCount)
251 WLog_ERR(TAG,
"Not implemented!");
264BOOL gdi_PolyPolygon(WINPR_ATTR_UNUSED
HGDI_DC hdc, WINPR_ATTR_UNUSED
GDI_POINT* lpPoints,
265 WINPR_ATTR_UNUSED
int* lpPolyCounts, WINPR_ATTR_UNUSED
int nCount)
267 WLog_ERR(TAG,
"Not implemented!");
271BOOL gdi_Rectangle(
HGDI_DC hdc, INT32 nXDst, INT32 nYDst, INT32 nWidth, INT32 nHeight)
275 if (!gdi_ClipCoords(hdc, &nXDst, &nYDst, &nWidth, &nHeight,
nullptr,
nullptr))
278 color = hdc->textColor;
280 for (INT32 y = 0; y < nHeight; y++)
282 BYTE* dstLeft = gdi_get_bitmap_pointer(hdc, nXDst, nYDst + y);
283 BYTE* dstRight = gdi_get_bitmap_pointer(hdc, nXDst + nWidth - 1, nYDst + y);
286 FreeRDPWriteColor(dstLeft, hdc->format, color);
289 FreeRDPWriteColor(dstRight, hdc->format, color);
292 for (INT32 x = 0; x < nWidth; x++)
294 BYTE* dstTop = gdi_get_bitmap_pointer(hdc, nXDst + x, nYDst);
295 BYTE* dstBottom = gdi_get_bitmap_pointer(hdc, nXDst + x, nYDst + nHeight - 1);
298 FreeRDPWriteColor(dstTop, hdc->format, color);
301 FreeRDPWriteColor(dstBottom, hdc->format, color);