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