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