Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / include / freerdp / gdi / gdi.h
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
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 __GDI_H
21 #define __GDI_H
22
23 #include <freerdp/api.h>
24 #include <freerdp/freerdp.h>
25 #include <freerdp/cache/cache.h>
26 #include <freerdp/utils/debug.h>
27 #include <freerdp/codec/color.h>
28
29 /* For more information, see [MS-RDPEGDI] */
30
31 /* Binary Raster Operations (ROP2) */
32 #define GDI_R2_BLACK                    0x01  /* D = 0 */
33 #define GDI_R2_NOTMERGEPEN              0x02  /* D = ~(D | P) */
34 #define GDI_R2_MASKNOTPEN               0x03  /* D = D & ~P */
35 #define GDI_R2_NOTCOPYPEN               0x04  /* D = ~P */
36 #define GDI_R2_MASKPENNOT               0x05  /* D = P & ~D */
37 #define GDI_R2_NOT                      0x06  /* D = ~D */
38 #define GDI_R2_XORPEN                   0x07  /* D = D ^ P */
39 #define GDI_R2_NOTMASKPEN               0x08  /* D = ~(D & P) */
40 #define GDI_R2_MASKPEN                  0x09  /* D = D & P */
41 #define GDI_R2_NOTXORPEN                0x0A  /* D = ~(D ^ P) */
42 #define GDI_R2_NOP                      0x0B  /* D = D */
43 #define GDI_R2_MERGENOTPEN              0x0C  /* D = D | ~P */
44 #define GDI_R2_COPYPEN                  0x0D  /* D = P */
45 #define GDI_R2_MERGEPENNOT              0x0E  /* D = P | ~D */
46 #define GDI_R2_MERGEPEN                 0x0F  /* D = P | D */
47 #define GDI_R2_WHITE                    0x10  /* D = 1 */
48
49 /* Ternary Raster Operations (ROP3) */
50 #define GDI_SRCCOPY                     0x00CC0020 /* D = S */
51 #define GDI_SRCPAINT                    0x00EE0086 /* D = S | D */
52 #define GDI_SRCAND                      0x008800C6 /* D = S & D */
53 #define GDI_SRCINVERT                   0x00660046 /* D = S ^ D */
54 #define GDI_SRCERASE                    0x00440328 /* D = S & ~D */
55 #define GDI_NOTSRCCOPY                  0x00330008 /* D = ~S */
56 #define GDI_NOTSRCERASE                 0x001100A6 /* D = ~S & ~D */
57 #define GDI_MERGECOPY                   0x00C000CA /* D = S & P */
58 #define GDI_MERGEPAINT                  0x00BB0226 /* D = ~S | D */
59 #define GDI_PATCOPY                     0x00F00021 /* D = P */
60 #define GDI_PATPAINT                    0x00FB0A09 /* D = D | (P | ~S) */
61 #define GDI_PATINVERT                   0x005A0049 /* D = P ^ D */
62 #define GDI_DSTINVERT                   0x00550009 /* D = ~D */
63 #define GDI_BLACKNESS                   0x00000042 /* D = 0 */
64 #define GDI_WHITENESS                   0x00FF0062 /* D = 1 */
65 #define GDI_DSPDxax                     0x00E20746 /* D = (S & P) | (~S & D) */
66 #define GDI_SPna                        0x000C0324 /* D = S & ~P */
67 #define GDI_DSna                        0x00220326 /* D = D & ~S */
68 #define GDI_PDxn                        0x00A50065 /* D = D ^ ~P */
69
70 /* Brush Styles */
71 #define GDI_BS_SOLID                    0x00
72 #define GDI_BS_NULL                     0x01
73 #define GDI_BS_HATCHED                  0x02
74 #define GDI_BS_PATTERN                  0x03
75
76 /* Hatch Patterns */
77 #define GDI_HS_HORIZONTAL               0x00
78 #define GDI_HS_VERTICAL                 0x01
79 #define GDI_HS_FDIAGONAL                0x02
80 #define GDI_HS_BDIAGONAL                0x03
81 #define GDI_HS_CROSS                    0x04
82 #define GDI_HS_DIAGCROSS                0x05
83
84 /* Pen Styles */
85 #define GDI_PS_SOLID                    0x00
86 #define GDI_PS_DASH                     0x01
87 #define GDI_PS_NULL                     0x05
88
89 /* Background Modes */
90 #define GDI_OPAQUE                      0x00000001
91 #define GDI_TRANSPARENT                 0x00000002
92
93 /* GDI Object Types */
94 #define GDIOBJECT_BITMAP                0x00
95 #define GDIOBJECT_PEN                   0x01
96 #define GDIOBJECT_PALETTE               0x02
97 #define GDIOBJECT_BRUSH                 0x03
98 #define GDIOBJECT_RECT                  0x04
99 #define GDIOBJECT_REGION                0x04
100
101 struct _GDIOBJECT
102 {
103         uint8 objectType;
104 };
105 typedef struct _GDIOBJECT GDIOBJECT;
106 typedef GDIOBJECT* HGDIOBJECT;
107
108 /* RGB encoded as 0x00BBGGRR */
109 typedef unsigned int GDI_COLOR;
110 typedef GDI_COLOR* LPGDI_COLOR;
111
112 struct _GDI_RECT
113 {
114         uint8 objectType;
115         int left;
116         int top;
117         int right;
118         int bottom;
119 };
120 typedef struct _GDI_RECT GDI_RECT;
121 typedef GDI_RECT* HGDI_RECT;
122
123 struct _GDI_RGN
124 {
125         uint8 objectType;
126         int x; /* left */
127         int y; /* top */
128         int w; /* width */
129         int h; /* height */
130         int null; /* null region */
131 };
132 typedef struct _GDI_RGN GDI_RGN;
133 typedef GDI_RGN* HGDI_RGN;
134
135 struct _GDI_BITMAP
136 {
137         uint8 objectType;
138         int bytesPerPixel;
139         int bitsPerPixel;
140         int width;
141         int height;
142         int scanline;
143         uint8* data;
144 };
145 typedef struct _GDI_BITMAP GDI_BITMAP;
146 typedef GDI_BITMAP* HGDI_BITMAP;
147
148 struct _GDI_PEN
149 {
150         uint8 objectType;
151         int style;
152         int width;
153         int posX;
154         int posY;
155         GDI_COLOR color;
156 };
157 typedef struct _GDI_PEN GDI_PEN;
158 typedef GDI_PEN* HGDI_PEN;
159
160 struct _GDI_PALETTEENTRY
161 {
162         uint8 red;
163         uint8 green;
164         uint8 blue;
165 };
166 typedef struct _GDI_PALETTEENTRY GDI_PALETTEENTRY;
167
168 struct _GDI_PALETTE
169 {
170         uint16 count;
171         GDI_PALETTEENTRY *entries;
172 };
173 typedef struct _GDI_PALETTE GDI_PALETTE;
174 typedef GDI_PALETTE* HGDI_PALETTE;
175
176 struct _GDI_POINT
177 {
178         int x;
179         int y;
180 };
181 typedef struct _GDI_POINT GDI_POINT;
182 typedef GDI_POINT* HGDI_POINT;
183
184 struct _GDI_BRUSH
185 {
186         uint8 objectType;
187         int style;
188         HGDI_BITMAP pattern;
189         GDI_COLOR color;
190 };
191 typedef struct _GDI_BRUSH GDI_BRUSH;
192 typedef GDI_BRUSH* HGDI_BRUSH;
193
194 struct _GDI_WND
195 {
196         int count;
197         int ninvalid;
198         HGDI_RGN invalid;
199         HGDI_RGN cinvalid;
200 };
201 typedef struct _GDI_WND GDI_WND;
202 typedef GDI_WND* HGDI_WND;
203
204 struct _GDI_DC
205 {
206         HGDIOBJECT selectedObject;
207         int bytesPerPixel;
208         int bitsPerPixel;
209         GDI_COLOR bkColor;
210         GDI_COLOR textColor;
211         HGDI_BRUSH brush;
212         HGDI_RGN clip;
213         HGDI_PEN pen;
214         HGDI_WND hwnd;
215         int drawMode;
216         int bkMode;
217         int alpha;
218         int invert;
219         int rgb555;
220 };
221 typedef struct _GDI_DC GDI_DC;
222 typedef GDI_DC* HGDI_DC;
223
224 struct gdi_bitmap
225 {
226         rdpBitmap _p;
227
228         HGDI_DC hdc;
229         HGDI_BITMAP bitmap;
230         HGDI_BITMAP org_bitmap;
231 };
232 typedef struct gdi_bitmap gdiBitmap;
233
234 struct gdi_glyph
235 {
236         rdpBitmap _p;
237
238         HGDI_DC hdc;
239         HGDI_BITMAP bitmap;
240         HGDI_BITMAP org_bitmap;
241 };
242 typedef struct gdi_glyph gdiGlyph;
243
244 struct rdp_gdi
245 {
246         rdpContext* context;
247
248         int width;
249         int height;
250         int dstBpp;
251         int srcBpp;
252         int cursor_x;
253         int cursor_y;
254         int bytesPerPixel;
255
256         HGDI_DC hdc;
257         HCLRCONV clrconv;
258         gdiBitmap* primary;
259         gdiBitmap* drawing;
260         uint8* primary_buffer;
261         GDI_COLOR textColor;
262         void* rfx_context;
263         void* nsc_context;
264         gdiBitmap* tile;
265         gdiBitmap* image;
266 };
267
268 FREERDP_API uint32 gdi_rop3_code(uint8 code);
269 FREERDP_API uint8* gdi_get_bitmap_pointer(HGDI_DC hdcBmp, int x, int y);
270 FREERDP_API uint8* gdi_get_brush_pointer(HGDI_DC hdcBrush, int x, int y);
271 FREERDP_API int gdi_is_mono_pixel_set(uint8* data, int x, int y, int width);
272 FREERDP_API void gdi_resize(rdpGdi* gdi, int width, int height);
273
274 FREERDP_API int gdi_init(freerdp* instance, uint32 flags, uint8* buffer);
275 FREERDP_API void gdi_free(freerdp* instance);
276
277 #ifdef WITH_DEBUG_GDI
278 #define DEBUG_GDI(fmt, ...) DEBUG_CLASS(GDI, fmt, ## __VA_ARGS__)
279 #else
280 #define DEBUG_GDI(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
281 #endif
282
283 #endif /* __GDI_H */