Coverage Report

Created: 2025-07-01 06:46

/src/FreeRDP/libfreerdp/gdi/gdi.h
Line
Count
Source (jump to first uncovered line)
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
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
0
{
37
0
  HGDI_BITMAP hBmp = (HGDI_BITMAP)hdcBmp->selectedObject;
38
39
0
  if ((x >= 0) && (y >= 0) && (x < hBmp->width) && (y < hBmp->height))
40
0
  {
41
0
    BYTE* p = hBmp->data + (WINPR_ASSERTING_INT_CAST(size_t, y) * hBmp->scanline) +
42
0
              (WINPR_ASSERTING_INT_CAST(size_t, x) * FreeRDPGetBytesPerPixel(hdcBmp->format));
43
0
    return p;
44
0
  }
45
0
  else
46
0
  {
47
0
    WLog_ERR(FREERDP_TAG("gdi"),
48
0
             "gdi_get_bitmap_pointer: requesting invalid pointer: (%" PRIu32 ",%" PRIu32
49
0
             ") in %" PRIu32 "x%" PRIu32 "",
50
0
             x, y, hBmp->width, hBmp->height);
51
0
    return 0;
52
0
  }
53
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
54
55
/**
56
 * Get current color in brush bitmap according to dest coordinates. msdn{dd183396}
57
 *
58
 * @param x dest x-coordinate
59
 * @param y dest y-coordinate
60
 * @return color pointer
61
 */
62
static INLINE BYTE* gdi_get_brush_pointer(HGDI_DC hdcBrush, UINT32 x, UINT32 y)
63
0
{
64
0
  BYTE* p = NULL;
65
0
  UINT32 brushStyle = gdi_GetBrushStyle(hdcBrush);
66
67
0
  switch (brushStyle)
68
0
  {
69
0
    case GDI_BS_PATTERN:
70
0
    case GDI_BS_HATCHED:
71
0
    {
72
0
      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
0
      const UINT32 w = WINPR_ASSERTING_INT_CAST(UINT32, hBmpBrush->width);
78
0
      const UINT32 h = WINPR_ASSERTING_INT_CAST(UINT32, hBmpBrush->height);
79
80
0
      WINPR_ASSERT(w > 0);
81
0
      WINPR_ASSERT(h > 0);
82
0
      x = (x + w - (WINPR_ASSERTING_INT_CAST(UINT32, hdcBrush->brush->nXOrg) % w)) % w;
83
0
      y = (y + h - (WINPR_ASSERTING_INT_CAST(UINT32, hdcBrush->brush->nYOrg) % h)) % h;
84
0
      p = hBmpBrush->data + (1ULL * y * hBmpBrush->scanline) +
85
0
          (1ULL * x * FreeRDPGetBytesPerPixel(hBmpBrush->format));
86
0
      return p;
87
0
    }
88
89
0
    default:
90
0
      break;
91
0
  }
92
93
0
  p = (BYTE*)&(hdcBrush->textColor);
94
0
  return p;
95
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
96
97
#endif /* FREERDP_LIB_GDI_CORE_H */