Coverage Report

Created: 2026-02-26 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/FreeRDP/libfreerdp/gdi/gdi.h
Line
Count
Source
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * GDI Library
4
 *
5
 * Copyright 2010-2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
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
WINPR_ATTR_NODISCARD
31
FREERDP_LOCAL BOOL gdi_bitmap_update(rdpContext* context, const BITMAP_UPDATE* bitmapUpdate);
32
33
FREERDP_LOCAL void gdi_bitmap_free_ex(gdiBitmap* gdi_bmp);
34
35
WINPR_ATTR_MALLOC(gdi_bitmap_free_ex, 1)
36
WINPR_ATTR_NODISCARD
37
FREERDP_LOCAL gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE* data);
38
39
WINPR_ATTR_NODISCARD
40
static inline BYTE* gdi_get_bitmap_pointer(HGDI_DC hdcBmp, INT32 x, INT32 y)
41
0
{
42
0
  HGDI_BITMAP hBmp = (HGDI_BITMAP)hdcBmp->selectedObject;
43
44
0
  if ((x >= 0) && (y >= 0) && (x < hBmp->width) && (y < hBmp->height))
45
0
  {
46
0
    BYTE* p = hBmp->data + (WINPR_ASSERTING_INT_CAST(size_t, y) * hBmp->scanline) +
47
0
              (WINPR_ASSERTING_INT_CAST(size_t, x) * FreeRDPGetBytesPerPixel(hdcBmp->format));
48
0
    return p;
49
0
  }
50
0
  else
51
0
  {
52
0
    WLog_ERR(FREERDP_TAG("gdi"),
53
0
             "gdi_get_bitmap_pointer: requesting invalid pointer: (%" PRId32 ",%" PRId32
54
0
             ") in %" PRId32 "x%" PRId32 "",
55
0
             x, y, hBmp->width, hBmp->height);
56
0
    return 0;
57
0
  }
58
0
}
Unexecuted instantiation: bitmap.c:gdi_get_bitmap_pointer
Unexecuted instantiation: gdi.c:gdi_get_bitmap_pointer
Unexecuted instantiation: shape.c:gdi_get_bitmap_pointer
59
60
/**
61
 * Get current color in brush bitmap according to dest coordinates. msdn{dd183396}
62
 *
63
 * @param x dest x-coordinate
64
 * @param y dest y-coordinate
65
 * @return color pointer
66
 */
67
WINPR_ATTR_NODISCARD
68
static inline BYTE* gdi_get_brush_pointer(HGDI_DC hdcBrush, UINT32 x, UINT32 y)
69
0
{
70
0
  BYTE* p = NULL;
71
0
  UINT32 brushStyle = gdi_GetBrushStyle(hdcBrush);
72
73
0
  switch (brushStyle)
74
0
  {
75
0
    case GDI_BS_PATTERN:
76
0
    case GDI_BS_HATCHED:
77
0
    {
78
0
      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
0
      const UINT32 w = WINPR_ASSERTING_INT_CAST(UINT32, hBmpBrush->width);
84
0
      const UINT32 h = WINPR_ASSERTING_INT_CAST(UINT32, hBmpBrush->height);
85
86
0
      WINPR_ASSERT(w > 0);
87
0
      WINPR_ASSERT(h > 0);
88
0
      x = (x + w - (WINPR_ASSERTING_INT_CAST(UINT32, hdcBrush->brush->nXOrg) % w)) % w;
89
0
      y = (y + h - (WINPR_ASSERTING_INT_CAST(UINT32, hdcBrush->brush->nYOrg) % h)) % h;
90
0
      p = hBmpBrush->data + (1ULL * y * hBmpBrush->scanline) +
91
0
          (1ULL * x * FreeRDPGetBytesPerPixel(hBmpBrush->format));
92
0
      return p;
93
0
    }
94
95
0
    default:
96
0
      break;
97
0
  }
98
99
0
  p = (BYTE*)&(hdcBrush->textColor);
100
0
  return p;
101
0
}
Unexecuted instantiation: bitmap.c:gdi_get_brush_pointer
Unexecuted instantiation: gdi.c:gdi_get_brush_pointer
Unexecuted instantiation: shape.c:gdi_get_brush_pointer
102
103
#endif /* FREERDP_LIB_GDI_CORE_H */