FreeRDP
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 
30 FREERDP_LOCAL BOOL gdi_bitmap_update(rdpContext* context, const BITMAP_UPDATE* bitmapUpdate);
31 
32 FREERDP_LOCAL gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE* data);
33 FREERDP_LOCAL void gdi_bitmap_free_ex(gdiBitmap* gdi_bmp);
34 
35 static INLINE BYTE* gdi_get_bitmap_pointer(HGDI_DC hdcBmp, INT32 x, INT32 y)
36 {
37  HGDI_BITMAP hBmp = (HGDI_BITMAP)hdcBmp->selectedObject;
38 
39  if ((x >= 0) && (y >= 0) && (x < hBmp->width) && (y < hBmp->height))
40  {
41  BYTE* p = hBmp->data + (WINPR_ASSERTING_INT_CAST(size_t, y) * hBmp->scanline) +
42  (WINPR_ASSERTING_INT_CAST(size_t, x) * FreeRDPGetBytesPerPixel(hdcBmp->format));
43  return p;
44  }
45  else
46  {
47  WLog_ERR(FREERDP_TAG("gdi"),
48  "gdi_get_bitmap_pointer: requesting invalid pointer: (%" PRIu32 ",%" PRIu32
49  ") in %" PRIu32 "x%" PRIu32 "",
50  x, y, hBmp->width, hBmp->height);
51  return 0;
52  }
53 }
54 
62 static INLINE BYTE* gdi_get_brush_pointer(HGDI_DC hdcBrush, UINT32 x, UINT32 y)
63 {
64  BYTE* p = NULL;
65  UINT32 brushStyle = gdi_GetBrushStyle(hdcBrush);
66 
67  switch (brushStyle)
68  {
69  case GDI_BS_PATTERN:
70  case GDI_BS_HATCHED:
71  {
72  HGDI_BITMAP hBmpBrush = hdcBrush->brush->pattern;
73  /* According to msdn{dd183396}, the system always positions a brush bitmap
74  * at the brush origin and copy across the client area.
75  * Calculate the offset of the mapped pixel in the brush bitmap according to
76  * brush origin and dest coordinates */
77  const UINT32 w = WINPR_ASSERTING_INT_CAST(UINT32, hBmpBrush->width);
78  const UINT32 h = WINPR_ASSERTING_INT_CAST(UINT32, hBmpBrush->height);
79 
80  WINPR_ASSERT(w > 0);
81  WINPR_ASSERT(h > 0);
82  x = (x + w - (WINPR_ASSERTING_INT_CAST(UINT32, hdcBrush->brush->nXOrg) % w)) % w;
83  y = (y + h - (WINPR_ASSERTING_INT_CAST(UINT32, hdcBrush->brush->nYOrg) % h)) % h;
84  p = hBmpBrush->data + (y * hBmpBrush->scanline) +
85  (x * FreeRDPGetBytesPerPixel(hBmpBrush->format));
86  return p;
87  }
88 
89  default:
90  break;
91  }
92 
93  p = (BYTE*)&(hdcBrush->textColor);
94  return p;
95 }
96 
97 #endif /* FREERDP_LIB_GDI_CORE_H */