xref: /haiku/headers/os/interface/GraphicsDefs.h (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 /*
2  * Copyright 2008-2015 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _GRAPHICS_DEFS_H
6 #define _GRAPHICS_DEFS_H
7 
8 
9 #include <SupportDefs.h>
10 
11 
12 // Pattern
13 typedef struct pattern {
14 	uint8 data[8];
15 } pattern;
16 
17 
18 #ifdef __cplusplus
19 inline bool
20 operator==(const pattern& a, const pattern& b)
21 {
22 	uint64* pa = (uint64*)a.data;
23 	uint64* pb = (uint64*)b.data;
24 	return (*pa == *pb);
25 }
26 
27 
28 inline bool
29 operator!=(const pattern& a, const pattern& b)
30 {
31 	return !(a == b);
32 }
33 #endif // __cplusplus
34 
35 
36 extern const pattern B_SOLID_HIGH;
37 extern const pattern B_MIXED_COLORS;
38 extern const pattern B_SOLID_LOW;
39 
40 
41 // rgb_color
42 typedef struct rgb_color {
43 	uint8		red;
44 	uint8		green;
45 	uint8		blue;
46 	uint8		alpha;
47 
48 #if defined(__cplusplus)
49 	// some convenient additions
50 	inline rgb_color&
51 	set_to(uint8 r, uint8 g, uint8 b, uint8 a = 255)
52 	{
53 		red = r;
54 		green = g;
55 		blue = b;
56 		alpha = a;
57 		return *this;
58 	}
59 
60 	int32 Brightness() const;
61 
62 	inline bool
63 	operator==(const rgb_color& other) const
64 	{
65 		return *(const uint32 *)this == *(const uint32 *)&other;
66 	}
67 
68 	inline bool
69 	operator!=(const rgb_color& other) const
70 	{
71 		return *(const uint32 *)this != *(const uint32 *)&other;
72 	}
73 
74 	inline rgb_color&
75 	operator=(const rgb_color& other)
76 	{
77 		return set_to(other.red, other.green, other.blue, other.alpha);
78 	}
79 #endif
80 } rgb_color;
81 
82 
83 #if defined(__cplusplus)
84 inline rgb_color
85 make_color(uint8 red, uint8 green, uint8 blue, uint8 alpha = 255)
86 {
87 	rgb_color color = {red, green, blue, alpha};
88 	return color;
89 }
90 #endif
91 
92 
93 rgb_color mix_color(rgb_color color1, rgb_color color2, uint8 amount);
94 rgb_color blend_color(rgb_color color1, rgb_color color2, uint8 amount);
95 rgb_color disable_color(rgb_color color, rgb_color background);
96 
97 
98 extern const rgb_color 	B_TRANSPARENT_COLOR;
99 extern const uint8		B_TRANSPARENT_MAGIC_CMAP8;
100 extern const uint16		B_TRANSPARENT_MAGIC_RGBA15;
101 extern const uint16		B_TRANSPARENT_MAGIC_RGBA15_BIG;
102 extern const uint32		B_TRANSPARENT_MAGIC_RGBA32;
103 extern const uint32		B_TRANSPARENT_MAGIC_RGBA32_BIG;
104 extern const uint8 		B_TRANSPARENT_8_BIT;
105 extern const rgb_color	B_TRANSPARENT_32_BIT;
106 
107 
108 // color map
109 typedef struct color_map {
110 	int32				id;
111 	rgb_color			color_list[256];
112 	uint8				inversion_map[256];
113 	uint8				index_map[32768];
114 } color_map;
115 
116 
117 // overlay
118 typedef struct overlay_rect_limits {
119 	uint16				horizontal_alignment;
120 	uint16				vertical_alignment;
121 	uint16				width_alignment;
122 	uint16				height_alignment;
123 	uint16				min_width;
124 	uint16				max_width;
125 	uint16				min_height;
126 	uint16				max_height;
127 	uint32				reserved[8];
128 } overlay_rect_limits;
129 
130 
131 typedef struct overlay_restrictions {
132 	overlay_rect_limits	source;
133 	overlay_rect_limits	destination;
134 	float				min_width_scale;
135 	float				max_width_scale;
136 	float				min_height_scale;
137 	float				max_height_scale;
138 	uint32				reserved[8];
139 } overlay_restrictions;
140 
141 
142 // Screen ID
143 struct screen_id { int32 id; };
144 extern const struct screen_id B_MAIN_SCREEN_ID;
145 
146 
147 // Color spaces
148 typedef enum {
149 	B_NO_COLOR_SPACE	= 0x0000,
150 
151 	// linear color space (little endian)
152 	B_RGBA64			= 0x2012,	// RGBA		RGBA 16:16:16:16
153 	B_RGB48				= 0x0011,	// RGB		 RGB 16:16:16
154 	B_RGB32				= 0x0008,	// BGR-		-RGB 8:8:8:8
155 	B_RGBA32			= 0x2008,	// BGRA		ARGB 8:8:8:8
156 	B_RGB24				= 0x0003,	// BGR		 RGB 8:8:8
157 	B_RGB16				= 0x0005,	// BGR		 RGB 5:6:5
158 	B_RGB15				= 0x0010,	// BGR-		-RGB 1:5:5:5
159 	B_RGBA15			= 0x2010,	// BGRA		ARGB 1:5:5:5
160 	B_CMAP8				= 0x0004,	// 256 color index table
161 	B_GRAY8				= 0x0002,	// 256 greyscale table
162 	B_GRAY1				= 0x0001,	// Each bit represents a single pixel
163 
164 	// linear color space (big endian)
165 	B_RGBA64_BIG		= 0x3012,	// RGBA		RGBA 16:16:16:16
166 	B_RGB48_BIG			= 0x1011,	//  RGB		RGB  16:16:16
167 	B_RGB32_BIG			= 0x1008,	// -RGB		BGR- 8:8:8:8
168 	B_RGBA32_BIG		= 0x3008,	// ARGB		BGRA 8:8:8:8
169 	B_RGB24_BIG			= 0x1003,	//  RGB		BGR  8:8:8
170 	B_RGB16_BIG			= 0x1005,	//  RGB		BGR  5:6:5
171 	B_RGB15_BIG			= 0x1010,	// -RGB		BGR- 5:5:5:1
172 	B_RGBA15_BIG		= 0x3010,	// ARGB		BGRA 5:5:5:1
173 
174 	// linear color space (little endian, for completeness)
175 	B_RGBA64_LITTLE		= B_RGBA64,
176 	B_RGB48_LITTLE		= B_RGB48,
177 	B_RGB32_LITTLE		= B_RGB32,
178 	B_RGBA32_LITTLE		= B_RGBA32,
179 	B_RGB24_LITTLE		= B_RGB24,
180 	B_RGB16_LITTLE		= B_RGB16,
181 	B_RGB15_LITTLE		= B_RGB15,
182 	B_RGBA15_LITTLE		= B_RGBA15,
183 
184 	// non linear color space -- incidently, all with 8 bits per value
185 	// Note, BBitmap and BView do not support all of these!
186 
187 	// Loss / saturation points:
188 	//  Y		16 - 235 (absolute)
189 	//  Cb/Cr	16 - 240 (center 128)
190 
191 	B_YCbCr422			= 0x4000,	// Y0  Cb0 Y1  Cr0
192 									// Y2  Cb2 Y3  Cr4
193 	B_YCbCr411			= 0x4001,	// Cb0 Y0  Cr0 Y1
194 									// Cb4 Y2  Cr4 Y3
195 									// Y4  Y5  Y6  Y7
196 	B_YCbCr444			= 0x4003,	// Y   Cb  Cr
197 	B_YCbCr420			= 0x4004,	// Non-interlaced only
198 		// on even scan lines: Cb0  Y0  Y1  Cb2 Y2  Y3
199 		// on odd scan lines:  Cr0  Y0  Y1  Cr2 Y2  Y3
200 
201 	// Extrema points are:
202 	//  Y 0 - 207 (absolute)
203 	//  U -91 - 91 (offset 128)
204 	//  V -127 - 127 (offset 128)
205 
206 	// Note that YUV byte order is different from YCbCr; use YCbCr, not YUV,
207 	// when that's what you mean!
208 	B_YUV422			= 0x4020,	// U0  Y0  V0  Y1
209 									// U2  Y2  V2  Y3
210 	B_YUV411			= 0x4021,	// U0  Y0  Y1  V0  Y2  Y3
211 									// U4  Y4  Y5  V4  Y6  Y7
212 	B_YUV444			= 0x4023,	// U0  Y0  V0  U1  Y1  V1
213 	B_YUV420			= 0x4024,	// Non-interlaced only
214 		// on even scan lines: U0  Y0  Y1  U2 Y2  Y3
215 		// on odd scan lines:  V0  Y0  Y1  V2 Y2  Y3
216 	B_YUV9				= 0x402C,
217 	B_YUV12				= 0x402D,
218 
219 	B_UVL24				= 0x4030,	// UVL
220 	B_UVL32				= 0x4031,	// UVL-
221 	B_UVLA32			= 0x6031,	// UVLA
222 
223 	// L lightness, a/b color-opponent dimensions
224 	B_LAB24				= 0x4032,	// Lab
225 	B_LAB32				= 0x4033,	// Lab-
226 	B_LABA32			= 0x6033,	// LabA
227 
228 	// Red is at hue 0
229 	B_HSI24				= 0x4040,	// HSI
230 	B_HSI32				= 0x4041,	// HSI-
231 	B_HSIA32			= 0x6041,	// HSIA
232 
233 	B_HSV24				= 0x4042,	// HSV
234 	B_HSV32				= 0x4043,	// HSV-
235 	B_HSVA32			= 0x6043,	// HSVA
236 
237 	B_HLS24				= 0x4044,	// HLS
238 	B_HLS32				= 0x4045,	// HLS-
239 	B_HLSA32			= 0x6045,	// HLSA
240 
241 	B_CMY24				= 0xC001,	// CMY
242 	B_CMY32				= 0xC002,	// CMY-
243 	B_CMYA32			= 0xE002,	// CMYA
244 	B_CMYK32			= 0xC003,	// CMYK
245 
246 	// Compatibility declarations
247 	B_MONOCHROME_1_BIT	= B_GRAY1,
248 	B_GRAYSCALE_8_BIT	= B_GRAY8,
249 	B_COLOR_8_BIT		= B_CMAP8,
250 	B_RGB_32_BIT		= B_RGB32,
251 	B_RGB_16_BIT		= B_RGB15,
252 	B_BIG_RGB_32_BIT	= B_RGB32_BIG,
253 	B_BIG_RGB_16_BIT	= B_RGB15_BIG
254 } color_space;
255 
256 
257 // Bitmap Support Flags
258 enum {
259 	B_VIEWS_SUPPORT_DRAW_BITMAP			= 0x1,
260 	B_BITMAPS_SUPPORT_ATTACHED_VIEWS	= 0x2,
261 	B_BITMAPS_SUPPORT_OVERLAY			= 0x4
262 };
263 
264 
265 bool bitmaps_support_space(color_space space, uint32* _supportFlags);
266 
267 
268 status_t get_pixel_size_for(color_space space, size_t* _pixelChunk,
269 	size_t* _rowAlignment, size_t* _pixelsPerChunk);
270 
271 
272 enum buffer_orientation {
273 	B_BUFFER_TOP_TO_BOTTOM,
274 	B_BUFFER_BOTTOM_TO_TOP
275 };
276 
277 
278 enum buffer_layout {
279 	B_BUFFER_NONINTERLEAVED = 1
280 };
281 
282 
283 // Drawing Modes
284 enum drawing_mode {
285 	B_OP_COPY,
286 	B_OP_OVER,
287 	B_OP_ERASE,
288 	B_OP_INVERT,
289 	B_OP_ADD,
290 	B_OP_SUBTRACT,
291 	B_OP_BLEND,
292 	B_OP_MIN,
293 	B_OP_MAX,
294 	B_OP_SELECT,
295 	B_OP_ALPHA
296 };
297 
298 
299 enum source_alpha {
300 	B_PIXEL_ALPHA = 0,
301 	B_CONSTANT_ALPHA
302 };
303 
304 
305 enum alpha_function {
306 	B_ALPHA_OVERLAY = 0,
307 	B_ALPHA_COMPOSITE,
308 	B_ALPHA_COMPOSITE_SOURCE_OVER = B_ALPHA_COMPOSITE,
309 	B_ALPHA_COMPOSITE_SOURCE_IN,
310 	B_ALPHA_COMPOSITE_SOURCE_OUT,
311 	B_ALPHA_COMPOSITE_SOURCE_ATOP,
312 	B_ALPHA_COMPOSITE_DESTINATION_OVER,
313 	B_ALPHA_COMPOSITE_DESTINATION_IN,
314 	B_ALPHA_COMPOSITE_DESTINATION_OUT,
315 	B_ALPHA_COMPOSITE_DESTINATION_ATOP,
316 	B_ALPHA_COMPOSITE_XOR,
317 	B_ALPHA_COMPOSITE_CLEAR,
318 	B_ALPHA_COMPOSITE_DIFFERENCE,
319 	B_ALPHA_COMPOSITE_LIGHTEN,
320 	B_ALPHA_COMPOSITE_DARKEN
321 };
322 
323 
324 // Fixed Screen Modes
325 enum {
326 	B_8_BIT_640x480		= 0x00000001,
327 	B_8_BIT_800x600		= 0x00000002,
328 	B_8_BIT_1024x768	= 0x00000004,
329 	B_8_BIT_1280x1024	= 0x00000008,
330 	B_8_BIT_1600x1200	= 0x00000010,
331 	B_16_BIT_640x480	= 0x00000020,
332 	B_16_BIT_800x600	= 0x00000040,
333 	B_16_BIT_1024x768	= 0x00000080,
334 	B_16_BIT_1280x1024	= 0x00000100,
335 	B_16_BIT_1600x1200	= 0x00000200,
336 	B_32_BIT_640x480	= 0x00000400,
337 	B_32_BIT_800x600	= 0x00000800,
338 	B_32_BIT_1024x768	= 0x00001000,
339 	B_32_BIT_1280x1024	= 0x00002000,
340 	B_32_BIT_1600x1200	= 0x00004000,
341 	B_8_BIT_1152x900	= 0x00008000,
342 	B_16_BIT_1152x900	= 0x00010000,
343 	B_32_BIT_1152x900	= 0x00020000,
344 	B_15_BIT_640x480	= 0x00040000,
345 	B_15_BIT_800x600	= 0x00080000,
346 	B_15_BIT_1024x768	= 0x00100000,
347 	B_15_BIT_1280x1024	= 0x00200000,
348 	B_15_BIT_1600x1200	= 0x00400000,
349 	B_15_BIT_1152x900	= 0x00800000,
350 	B_8_BIT_640x400		= 0x80000000
351 };
352 
353 
354 #endif	// _GRAPHICS_DEFS_H
355