Fix changelog email address
[freerdp-ubuntu-pcb-backport.git] / include / freerdp / codec / color.h
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * Color Conversion Routines
4  *
5  * Copyright 2010 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 __COLOR_H
21 #define __COLOR_H
22
23 #include <freerdp/api.h>
24 #include <freerdp/freerdp.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /* Color Space Conversions: http://msdn.microsoft.com/en-us/library/ff566496/ */
31
32 /* Color Space Conversion */
33
34 #define RGB_555_565(_r, _g, _b) \
35         _r = _r; \
36         _g = (_g << 1 & ~0x1) | (_g >> 4); \
37         _b = _b;
38
39 #define RGB_565_555(_r, _g, _b) \
40         _r = _r; \
41         _g = (_g >> 1); \
42         _b = _b;
43
44 #define RGB_555_888(_r, _g, _b) \
45         _r = (_r << 3 & ~0x7) | (_r >> 2); \
46         _g = (_g << 3 & ~0x7) | (_g >> 2); \
47         _b = (_b << 3 & ~0x7) | (_b >> 2);
48
49 #define RGB_565_888(_r, _g, _b) \
50         _r = (_r << 3 & ~0x7) | (_r >> 2); \
51         _g = (_g << 2 & ~0x3) | (_g >> 4); \
52         _b = (_b << 3 & ~0x7) | (_b >> 2);
53
54 #define RGB_888_565(_r, _g, _b) \
55         _r = (_r >> 3); \
56         _g = (_g >> 2); \
57         _b = (_b >> 3);
58
59 #define RGB_888_555(_r, _g, _b) \
60         _r = (_r >> 3); \
61         _g = (_g >> 3); \
62         _b = (_b >> 3);
63
64 /* RGB 15 (RGB_555) */
65
66 #define RGB555(_r, _g, _b)  \
67         ((_r & 0x1F) << 10) | ((_g & 0x1F) << 5) | (_b & 0x1F)
68
69 #define RGB15(_r, _g, _b)  \
70         (((_r >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | ((_b >> 3) & 0x1F)
71
72 #define GetRGB_555(_r, _g, _b, _p) \
73         _r = (_p & 0x7C00) >> 10; \
74         _g = (_p & 0x3E0) >> 5; \
75         _b = (_p & 0x1F);
76
77 #define GetRGB15(_r, _g, _b, _p) \
78         GetRGB_555(_r, _g, _b, _p); \
79         RGB_555_888(_r, _g, _b);
80
81 /* BGR 15 (BGR_555) */
82
83 #define BGR555(_r, _g, _b)  \
84         ((_b & 0x1F) << 10) | ((_g & 0x1F) << 5) | (_r & 0x1F)
85
86 #define BGR15(_r, _g, _b)  \
87         (((_b >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | ((_r >> 3) & 0x1F)
88
89 #define GetBGR_555(_r, _g, _b, _p) \
90         _b = (_p & 0x7C00) >> 10; \
91         _g = (_p & 0x3E0) >> 5; \
92         _r = (_p & 0x1F);
93
94 #define GetBGR15(_r, _g, _b, _p) \
95         GetBGR_555(_r, _g, _b, _p); \
96         RGB_555_888(_r, _g, _b);
97
98 /* RGB 16 (RGB_565) */
99
100 #define RGB565(_r, _g, _b)  \
101         ((_r & 0x1F) << 11) | ((_g & 0x3F) << 5) | (_b & 0x1F)
102
103 #define RGB16(_r, _g, _b)  \
104         (((_r >> 3) & 0x1F) << 11) | (((_g >> 2) & 0x3F) << 5) | ((_b >> 3) & 0x1F)
105
106 #define GetRGB_565(_r, _g, _b, _p) \
107         _r = (_p & 0xF800) >> 11; \
108         _g = (_p & 0x7E0) >> 5; \
109         _b = (_p & 0x1F);
110
111 #define GetRGB16(_r, _g, _b, _p) \
112         GetRGB_565(_r, _g, _b, _p); \
113         RGB_565_888(_r, _g, _b);
114
115 /* BGR 16 (BGR_565) */
116
117 #define BGR565(_r, _g, _b)  \
118         ((_b & 0x1F) << 11) | ((_g & 0x3F) << 5) | (_r & 0x1F)
119
120 #define BGR16(_r, _g, _b)  \
121         (((_b >> 3) & 0x1F) << 11) | (((_g >> 2) & 0x3F) << 5) | ((_r >> 3) & 0x1F)
122
123 #define GetBGR_565(_r, _g, _b, _p) \
124         _b = (_p & 0xF800) >> 11; \
125         _g = (_p & 0x7E0) >> 5; \
126         _r = (_p & 0x1F);
127
128 #define GetBGR16(_r, _g, _b, _p) \
129         GetBGR_565(_r, _g, _b, _p); \
130         RGB_565_888(_r, _g, _b);
131
132 /* RGB 24 (RGB_888) */
133
134 #define RGB24(_r, _g, _b)  \
135         (_r << 16) | (_g << 8) | _b
136
137 #define GetRGB24(_r, _g, _b, _p) \
138         _r = (_p & 0xFF0000) >> 16; \
139         _g = (_p & 0xFF00) >> 8; \
140         _b = (_p & 0xFF);
141
142 /* BGR 24 (BGR_888) */
143
144 #define BGR24(_r, _g, _b)  \
145         (_b << 16) | (_g << 8) | _r
146
147 #define GetBGR24(_r, _g, _b, _p) \
148         _b = (_p & 0xFF0000) >> 16; \
149         _g = (_p & 0xFF00) >> 8; \
150         _r = (_p & 0xFF);
151
152 /* RGB 32 (ARGB_8888), alpha ignored */
153
154 #define RGB32(_r, _g, _b)  \
155         (_r << 16) | (_g << 8) | _b
156
157 #define GetRGB32(_r, _g, _b, _p) \
158         _r = (_p & 0xFF0000) >> 16; \
159         _g = (_p & 0xFF00) >> 8; \
160         _b = (_p & 0xFF);
161
162 /* ARGB 32 (ARGB_8888) */
163
164 #define ARGB32(_a,_r, _g, _b)  \
165         (_a << 24) | (_r << 16) | (_g << 8) | _b
166
167 #define GetARGB32(_a, _r, _g, _b, _p) \
168         _a = (_p & 0xFF000000) >> 24; \
169         _r = (_p & 0xFF0000) >> 16; \
170         _g = (_p & 0xFF00) >> 8; \
171         _b = (_p & 0xFF);
172
173 /* BGR 32 (ABGR_8888), alpha ignored */
174
175 #define BGR32(_r, _g, _b)  \
176         (_b << 16) | (_g << 8) | _r
177
178 #define GetBGR32(_r, _g, _b, _p) \
179         _b = (_p & 0xFF0000) >> 16; \
180         _g = (_p & 0xFF00) >> 8; \
181         _r = (_p & 0xFF);
182
183 /* BGR 32 (ABGR_8888) */
184
185 #define ABGR32(_a, _r, _g, _b)  \
186         (_a << 24) | (_b << 16) | (_g << 8) | _r
187
188 #define GetABGR32(_a, _r, _g, _b, _p) \
189         _a = (_p & 0xFF000000) >> 24; \
190         _b = (_p & 0xFF0000) >> 16; \
191         _g = (_p & 0xFF00) >> 8; \
192         _r = (_p & 0xFF);
193
194 /* Color Conversion */
195
196 #define BGR16_RGB32(_r, _g, _b, _p) \
197         GetBGR16(_r, _g, _b, _p); \
198         RGB_565_888(_r, _g, _b); \
199         _p = RGB32(_r, _g, _b);
200
201 #define RGB32_RGB16(_r, _g, _b, _p) \
202         GetRGB32(_r, _g, _b, _p); \
203         RGB_888_565(_r, _g, _b); \
204         _p = RGB565(_r, _g, _b);
205
206 #define RGB15_RGB16(_r, _g, _b, _p) \
207         GetRGB_555(_r, _g, _b, _p); \
208         _g = (_g << 1 & ~0x1) | (_g >> 4); \
209         _p = RGB565(_r, _g, _b);
210
211 #define RGB16_RGB15(_r, _g, _b, _p) \
212         GetRGB_565(_r, _g, _b, _p); \
213         _g = (_g >> 1); \
214         _p = RGB555(_r, _g, _b);
215
216 #define CLRCONV_ALPHA           1
217 #define CLRCONV_INVERT          2
218 /* if defined RGB555 format is used when rendering with a 16-bit frame buffer */
219 #define CLRCONV_RGB555          4
220
221 /* Supported Internal Buffer Formats */
222 #define CLRBUF_16BPP            8
223 #define CLRBUF_24BPP            16
224 #define CLRBUF_32BPP            32
225
226 struct _CLRCONV
227 {
228         int alpha;
229         int invert;
230         int rgb555;
231         rdpPalette* palette;
232 };
233 typedef struct _CLRCONV CLRCONV;
234 typedef CLRCONV* HCLRCONV;
235
236 #define IBPP(_bpp) (((_bpp + 1)/ 8) % 5)
237
238 typedef uint8* (*p_freerdp_image_convert)(uint8* srcData, uint8* dstData, int width, int height, int srcBpp, int dstBpp, HCLRCONV clrconv);
239
240 FREERDP_API uint8* freerdp_image_convert(uint8* srcData, uint8 *dstData, int width, int height, int srcBpp, int dstBpp, HCLRCONV clrconv);
241 FREERDP_API uint8* freerdp_glyph_convert(int width, int height, uint8* data);
242 FREERDP_API void   freerdp_bitmap_flip(uint8 * src, uint8 * dst, int scanLineSz, int height);
243 FREERDP_API uint8* freerdp_image_flip(uint8* srcData, uint8* dstData, int width, int height, int bpp);
244 FREERDP_API uint8* freerdp_icon_convert(uint8* srcData, uint8* dstData, uint8* mask, int width, int height, int bpp, HCLRCONV clrconv);
245 FREERDP_API uint8* freerdp_mono_image_convert(uint8* srcData, int width, int height, int srcBpp, int dstBpp, uint32 bgcolor, uint32 fgcolor, HCLRCONV clrconv);
246 FREERDP_API void freerdp_alpha_cursor_convert(uint8* alphaData, uint8* xorMask, uint8* andMask, int width, int height, int bpp, HCLRCONV clrconv);
247 FREERDP_API void freerdp_image_swap_color_order(uint8* data, int width, int height);
248
249 FREERDP_API uint32 freerdp_color_convert_var(uint32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv);
250 FREERDP_API uint32 freerdp_color_convert_rgb(uint32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv);
251 FREERDP_API uint32 freerdp_color_convert_bgr(uint32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv);
252 FREERDP_API uint32 freerdp_color_convert_rgb_bgr(uint32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv);
253 FREERDP_API uint32 freerdp_color_convert_bgr_rgb(uint32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv);
254 FREERDP_API uint32 freerdp_color_convert_var_rgb(uint32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv);
255 FREERDP_API uint32 freerdp_color_convert_var_bgr(uint32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv);
256
257 FREERDP_API HCLRCONV freerdp_clrconv_new(uint32 flags);
258 FREERDP_API void freerdp_clrconv_free(HCLRCONV clrconv);
259
260 #ifdef __cplusplus
261 }
262 #endif
263
264 #endif /* __COLOR_H */