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 = WINPR_PACKED_ALIGN_CAST(HGDI_BITMAP, hdcBmp->selectedObject);
43
44 if ((x >= 0) && (y >= 0) && (x < hBmp->width) && (y < hBmp->height))
45 {
46 const size_t offset =
47 (WINPR_ASSERTING_INT_CAST(size_t, y) * hBmp->scanline) +
48 (WINPR_ASSERTING_INT_CAST(size_t, x) * FreeRDPGetBytesPerPixel(hdcBmp->format));
49 return &hBmp->data[offset];
50 }
51 else
52 {
53 WLog_ERR(FREERDP_TAG("gdi"),
54 "gdi_get_bitmap_pointer: requesting invalid pointer: (%" PRId32 ",%" PRId32
55 ") in %" PRId32 "x%" PRId32 "",
56 x, y, hBmp->width, hBmp->height);
57 return nullptr;
58 }
59}
60
68WINPR_ATTR_NODISCARD
69static inline BYTE* gdi_get_brush_pointer(HGDI_DC hdcBrush, UINT32 x, UINT32 y)
70{
71 BYTE* p = nullptr;
72 UINT32 brushStyle = gdi_GetBrushStyle(hdcBrush);
73
74 switch (brushStyle)
75 {
76 case GDI_BS_PATTERN:
77 case GDI_BS_HATCHED:
78 {
79 HGDI_BITMAP hBmpBrush = hdcBrush->brush->pattern;
80 /* According to msdn{dd183396}, the system always positions a brush bitmap
81 * at the brush origin and copy across the client area.
82 * Calculate the offset of the mapped pixel in the brush bitmap according to
83 * brush origin and dest coordinates */
84 const UINT32 w = WINPR_ASSERTING_INT_CAST(UINT32, hBmpBrush->width);
85 const UINT32 h = WINPR_ASSERTING_INT_CAST(UINT32, hBmpBrush->height);
86
87 WINPR_ASSERT(w > 0);
88 WINPR_ASSERT(h > 0);
89 x = (x + w - (WINPR_ASSERTING_INT_CAST(UINT32, hdcBrush->brush->nXOrg) % w)) % w;
90 y = (y + h - (WINPR_ASSERTING_INT_CAST(UINT32, hdcBrush->brush->nYOrg) % h)) % h;
91 p = hBmpBrush->data + (1ULL * y * hBmpBrush->scanline) +
92 (1ULL * x * FreeRDPGetBytesPerPixel(hBmpBrush->format));
93 return p;
94 }
95
96 default:
97 break;
98 }
99
100 p = (BYTE*)&(hdcBrush->textColor);
101 return p;
102}
103
104#endif /* FREERDP_LIB_GDI_CORE_H */