FreeRDP
Loading...
Searching...
No Matches
libfreerdp/gdi/gdi.h
1
20#ifndef FREERDP_LIB_GDI_CORE_H
21#define FREERDP_LIB_GDI_CORE_H
22
23#include <winpr/cast.h>
24
25#include "graphics.h"
26#include "brush.h"
27
28#include <freerdp/api.h>
29
30WINPR_ATTR_NODISCARD
31FREERDP_LOCAL BOOL gdi_bitmap_update(rdpContext* context, const BITMAP_UPDATE* bitmapUpdate);
32
33FREERDP_LOCAL void gdi_bitmap_free_ex(gdiBitmap* bitmap);
34
35WINPR_ATTR_MALLOC(gdi_bitmap_free_ex, 1)
36WINPR_ATTR_NODISCARD
37FREERDP_LOCAL gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE* data);
38
39WINPR_ATTR_NODISCARD
40static inline BYTE* gdi_get_bitmap_pointer(HGDI_DC hdcBmp, INT32 x, INT32 y)
41{
42 HGDI_BITMAP hBmp = (HGDI_BITMAP)hdcBmp->selectedObject;
43
44 if ((x >= 0) && (y >= 0) && (x < hBmp->width) && (y < hBmp->height))
45 {
46 BYTE* p = hBmp->data + (WINPR_ASSERTING_INT_CAST(size_t, y) * hBmp->scanline) +
47 (WINPR_ASSERTING_INT_CAST(size_t, x) * FreeRDPGetBytesPerPixel(hdcBmp->format));
48 return p;
49 }
50 else
51 {
52 WLog_ERR(FREERDP_TAG("gdi"),
53 "gdi_get_bitmap_pointer: requesting invalid pointer: (%" PRId32 ",%" PRId32
54 ") in %" PRId32 "x%" PRId32 "",
55 x, y, hBmp->width, hBmp->height);
56 return nullptr;
57 }
58}
59
67WINPR_ATTR_NODISCARD
68static inline BYTE* gdi_get_brush_pointer(HGDI_DC hdcBrush, UINT32 x, UINT32 y)
69{
70 BYTE* p = nullptr;
71 UINT32 brushStyle = gdi_GetBrushStyle(hdcBrush);
72
73 switch (brushStyle)
74 {
75 case GDI_BS_PATTERN:
76 case GDI_BS_HATCHED:
77 {
78 HGDI_BITMAP hBmpBrush = hdcBrush->brush->pattern;
79 /* According to msdn{dd183396}, the system always positions a brush bitmap
80 * at the brush origin and copy across the client area.
81 * Calculate the offset of the mapped pixel in the brush bitmap according to
82 * brush origin and dest coordinates */
83 const UINT32 w = WINPR_ASSERTING_INT_CAST(UINT32, hBmpBrush->width);
84 const UINT32 h = WINPR_ASSERTING_INT_CAST(UINT32, hBmpBrush->height);
85
86 WINPR_ASSERT(w > 0);
87 WINPR_ASSERT(h > 0);
88 x = (x + w - (WINPR_ASSERTING_INT_CAST(UINT32, hdcBrush->brush->nXOrg) % w)) % w;
89 y = (y + h - (WINPR_ASSERTING_INT_CAST(UINT32, hdcBrush->brush->nYOrg) % h)) % h;
90 p = hBmpBrush->data + (1ULL * y * hBmpBrush->scanline) +
91 (1ULL * x * FreeRDPGetBytesPerPixel(hBmpBrush->format));
92 return p;
93 }
94
95 default:
96 break;
97 }
98
99 p = (BYTE*)&(hdcBrush->textColor);
100 return p;
101}
102
103#endif /* FREERDP_LIB_GDI_CORE_H */