FreeRDP
core/graphics.c
1 
20 #include <freerdp/config.h>
21 
22 #include <winpr/crt.h>
23 
24 #include <freerdp/graphics.h>
25 
26 #include "graphics.h"
27 
28 /* Bitmap Class */
29 
30 rdpBitmap* Bitmap_Alloc(rdpContext* context)
31 {
32  rdpBitmap* bitmap = NULL;
33  rdpGraphics* graphics = NULL;
34  graphics = context->graphics;
35  bitmap = (rdpBitmap*)calloc(1, graphics->Bitmap_Prototype->size);
36 
37  if (bitmap)
38  {
39  *bitmap = *graphics->Bitmap_Prototype;
40  bitmap->data = NULL;
41  }
42 
43  return bitmap;
44 }
45 
46 void Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
47 {
48  if (bitmap)
49  bitmap->Free(context, bitmap);
50 }
51 
52 BOOL Bitmap_SetRectangle(rdpBitmap* bitmap, UINT16 left, UINT16 top, UINT16 right, UINT16 bottom)
53 {
54  if (!bitmap)
55  return FALSE;
56 
57  bitmap->left = left;
58  bitmap->top = top;
59  bitmap->right = right;
60  bitmap->bottom = bottom;
61  return TRUE;
62 }
63 
64 BOOL Bitmap_SetDimensions(rdpBitmap* bitmap, UINT16 width, UINT16 height)
65 {
66  if (!bitmap)
67  return FALSE;
68 
69  bitmap->right = bitmap->left + width - 1;
70  bitmap->bottom = bitmap->top + height - 1;
71  bitmap->width = width;
72  bitmap->height = height;
73  return TRUE;
74 }
75 
76 void graphics_register_bitmap(rdpGraphics* graphics, const rdpBitmap* bitmap)
77 {
78  WINPR_ASSERT(graphics);
79  WINPR_ASSERT(graphics->Bitmap_Prototype);
80  WINPR_ASSERT(bitmap);
81 
82  *graphics->Bitmap_Prototype = *bitmap;
83 }
84 
85 /* Pointer Class */
86 rdpPointer* Pointer_Alloc(rdpContext* context)
87 {
88  rdpPointer* pointer = NULL;
89  rdpGraphics* graphics = NULL;
90  graphics = context->graphics;
91  pointer = (rdpPointer*)calloc(1, graphics->Pointer_Prototype->size);
92 
93  if (pointer)
94  {
95  *pointer = *graphics->Pointer_Prototype;
96  }
97 
98  return pointer;
99 }
100 
101 /* static method */
102 void graphics_register_pointer(rdpGraphics* graphics, const rdpPointer* pointer)
103 {
104  WINPR_ASSERT(graphics);
105  WINPR_ASSERT(graphics->Pointer_Prototype);
106  WINPR_ASSERT(pointer);
107 
108  *graphics->Pointer_Prototype = *pointer;
109 }
110 
111 /* Glyph Class */
112 
113 rdpGlyph* Glyph_Alloc(rdpContext* context, INT32 x, INT32 y, UINT32 cx, UINT32 cy, UINT32 cb,
114  const BYTE* aj)
115 {
116  rdpGlyph* glyph = NULL;
117  rdpGraphics* graphics = NULL;
118 
119  if (!context || !context->graphics)
120  return NULL;
121 
122  graphics = context->graphics;
123 
124  if (!graphics->Glyph_Prototype)
125  return NULL;
126 
127  glyph = (rdpGlyph*)calloc(1, graphics->Glyph_Prototype->size);
128 
129  if (!glyph)
130  return NULL;
131 
132  *glyph = *graphics->Glyph_Prototype;
133  glyph->cb = cb;
134  glyph->cx = cx;
135  glyph->cy = cy;
136  glyph->x = x;
137  glyph->y = y;
138  glyph->aj = malloc(glyph->cb);
139 
140  if (!glyph->aj)
141  {
142  free(glyph);
143  return NULL;
144  }
145 
146  CopyMemory(glyph->aj, aj, cb);
147 
148  if (!glyph->New(context, glyph))
149  {
150  free(glyph->aj);
151  free(glyph);
152  return NULL;
153  }
154 
155  return glyph;
156 }
157 
158 void graphics_register_glyph(rdpGraphics* graphics, const rdpGlyph* glyph)
159 {
160  WINPR_ASSERT(graphics);
161  WINPR_ASSERT(graphics->Glyph_Prototype);
162  WINPR_ASSERT(glyph);
163 
164  *graphics->Glyph_Prototype = *glyph;
165 }
166 
167 /* Graphics Module */
168 
169 rdpGraphics* graphics_new(rdpContext* context)
170 {
171  rdpGraphics* graphics = NULL;
172  graphics = (rdpGraphics*)calloc(1, sizeof(rdpGraphics));
173 
174  if (graphics)
175  {
176  graphics->context = context;
177  graphics->Bitmap_Prototype = (rdpBitmap*)calloc(1, sizeof(rdpBitmap));
178 
179  if (!graphics->Bitmap_Prototype)
180  {
181  free(graphics);
182  return NULL;
183  }
184 
185  graphics->Bitmap_Prototype->size = sizeof(rdpBitmap);
186  graphics->Pointer_Prototype = (rdpPointer*)calloc(1, sizeof(rdpPointer));
187 
188  if (!graphics->Pointer_Prototype)
189  {
190  free(graphics->Bitmap_Prototype);
191  free(graphics);
192  return NULL;
193  }
194 
195  graphics->Pointer_Prototype->size = sizeof(rdpPointer);
196  graphics->Glyph_Prototype = (rdpGlyph*)calloc(1, sizeof(rdpGlyph));
197 
198  if (!graphics->Glyph_Prototype)
199  {
200  free(graphics->Pointer_Prototype);
201  free(graphics->Bitmap_Prototype);
202  free(graphics);
203  return NULL;
204  }
205 
206  graphics->Glyph_Prototype->size = sizeof(rdpGlyph);
207  }
208 
209  return graphics;
210 }
211 
212 void graphics_free(rdpGraphics* graphics)
213 {
214  if (graphics)
215  {
216  free(graphics->Bitmap_Prototype);
217  free(graphics->Pointer_Prototype);
218  free(graphics->Glyph_Prototype);
219  free(graphics);
220  }
221 }