xref: /haiku/headers/os/interface/GraphicsDefs.h (revision d2e1e872611179c9cfaa43ce11bd58b1e3554e4b)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, OpenBeOS
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		GraphicsDefs.h
23 //	Author:			Frans van Nispen
24 //	Description:	BMessageFilter class creates objects that filter
25 //					in-coming BMessages.
26 //------------------------------------------------------------------------------
27 
28 #ifndef _GRAPHICS_DEFS_H
29 #define _GRAPHICS_DEFS_H
30 
31 // Standard Includes -----------------------------------------------------------
32 
33 // System Includes -------------------------------------------------------------
34 #include <BeBuild.h>
35 #include <SupportDefs.h>
36 
37 // Project Includes ------------------------------------------------------------
38 
39 // Local Includes --------------------------------------------------------------
40 
41 // Local Defines ---------------------------------------------------------------
42 
43 // Globals ---------------------------------------------------------------------
44 
45 
46 //------------------------------------------------------------------------------
47 
48 typedef struct pattern {
49 		uint8		data[8];
50 } pattern;
51 
52 #ifdef __cplusplus
53 
54 inline bool
55 operator==(const pattern& a, const pattern& b)
56 {
57 	return (*(uint64*)a.data == *(uint64*)b.data);
58 }
59 
60 inline bool
61 operator!=(const pattern& a, const pattern& b)
62 {
63 	return !(a == b);
64 }
65 
66 #endif // __cplusplus
67 
68 extern const pattern B_SOLID_HIGH;
69 extern const pattern B_MIXED_COLORS;
70 extern const pattern B_SOLID_LOW;
71 
72 //------------------------------------------------------------------------------
73 
74 typedef struct rgb_color {
75 	uint8		red;
76 	uint8		green;
77 	uint8		blue;
78 	uint8		alpha;
79 
80 #if defined(__cplusplus)
81 	// some convenient additions
82 
83 	inline rgb_color&
84 	set_to(uint8 r, uint8 g, uint8 b, uint8 a = 255)
85 	{
86 		red = r;
87 		green = g;
88 		blue = b;
89 		alpha = a;
90 		return *this;
91 	}
92 
93 	inline bool
94 	operator==(const rgb_color& other) const
95 	{
96 		return *(const uint32 *)this == *(const uint32 *)&other;
97 	}
98 
99 	inline bool
100 	operator!=(const rgb_color& other) const
101 	{
102 		return *(const uint32 *)this != *(const uint32 *)&other;
103 	}
104 
105 	inline rgb_color&
106 	operator=(const rgb_color& other)
107 	{
108 		return set_to(other.red, other.green, other.blue, other.alpha);
109 	}
110 #endif
111 } rgb_color;
112 
113 #if defined(__cplusplus)
114 inline rgb_color
115 make_color(uint8 red, uint8 green, uint8 blue, uint8 alpha = 255)
116 {
117 	rgb_color color = {red, green, blue, alpha};
118 	return color;
119 }
120 #endif
121 
122 //------------------------------------------------------------------------------
123 
124 extern const rgb_color 	B_TRANSPARENT_COLOR;
125 extern const uint8		B_TRANSPARENT_MAGIC_CMAP8;
126 extern const uint16		B_TRANSPARENT_MAGIC_RGBA15;
127 extern const uint16		B_TRANSPARENT_MAGIC_RGBA15_BIG;
128 extern const uint32		B_TRANSPARENT_MAGIC_RGBA32;
129 extern const uint32		B_TRANSPARENT_MAGIC_RGBA32_BIG;
130 
131 extern const uint8 		B_TRANSPARENT_8_BIT;
132 extern const rgb_color	B_TRANSPARENT_32_BIT;
133 
134 //------------------------------------------------------------------------------
135 
136 typedef struct color_map {
137 	int32				id;
138 	rgb_color			color_list[256];
139 	uint8				inversion_map[256];
140 	uint8				index_map[32768];
141 } color_map;
142 
143 typedef struct overlay_rect_limits {
144 	uint16				horizontal_alignment;
145 	uint16				vertical_alignment;
146 	uint16				width_alignment;
147 	uint16				height_alignment;
148 	uint16				min_width;
149 	uint16				max_width;
150 	uint16				min_height;
151 	uint16				max_height;
152 	uint32				reserved[8];
153 } overlay_rect_limits;
154 
155 typedef struct overlay_restrictions {
156 	overlay_rect_limits	source;
157 	overlay_rect_limits	destination;
158 	float				min_width_scale;
159 	float				max_width_scale;
160 	float				min_height_scale;
161 	float				max_height_scale;
162 	uint32				reserved[8];
163 } overlay_restrictions;
164 
165 //------------------------------------------------------------------------------
166 
167 struct screen_id { int32 id; };
168 
169 extern const struct screen_id B_MAIN_SCREEN_ID;
170 
171 //------------------------------------------------------------------------------
172 
173 typedef enum
174 {
175 	B_NO_COLOR_SPACE =	0x0000,	//* byte in memory order, high bit first
176 
177 	// linear color space (little endian is the default)
178 	B_RGB32 = 			0x0008,	//* B[7:0]  G[7:0]  R[7:0]  -[7:0]
179 	B_RGBA32 = 			0x2008,	// B[7:0]  G[7:0]  R[7:0]  A[7:0]
180 	B_RGB24 = 			0x0003,	// B[7:0]  G[7:0]  R[7:0]
181 	B_RGB16 = 			0x0005,	// G[2:0],B[4:0]  R[4:0],G[5:3]
182 	B_RGB15 = 			0x0010,	// G[2:0],B[4:0]  	   -[0],R[4:0],G[4:3]
183 	B_RGBA15 = 			0x2010,	// G[2:0],B[4:0]  	   A[0],R[4:0],G[4:3]
184 	B_CMAP8 = 			0x0004,	// D[7:0]
185 	B_GRAY8 = 			0x0002,	// Y[7:0]
186 	B_GRAY1 = 			0x0001,	// Y0[0],Y1[0],Y2[0],Y3[0],Y4[0],Y5[0],Y6[0],Y7[0]
187 
188 	// big endian version, when the encoding is not endianess independant
189 	B_RGB32_BIG =		0x1008,	// -[7:0]  R[7:0]  G[7:0]  B[7:0]
190 	B_RGBA32_BIG = 		0x3008,	// A[7:0]  R[7:0]  G[7:0]  B[7:0]
191 	B_RGB24_BIG = 		0x1003,	// R[7:0]  G[7:0]  B[7:0]
192 	B_RGB16_BIG = 		0x1005,	// R[4:0],G[5:3]  G[2:0],B[4:0]
193 	B_RGB15_BIG = 		0x1010,	// -[0],R[4:0],G[4:3]  G[2:0],B[4:0]
194 	B_RGBA15_BIG = 		0x3010,	// A[0],R[4:0],G[4:3]  G[2:0],B[4:0]
195 
196 	// little-endian declarations, for completness
197 	B_RGB32_LITTLE = 	B_RGB32,
198 	B_RGBA32_LITTLE =	B_RGBA32,
199 	B_RGB24_LITTLE =	B_RGB24,
200 	B_RGB16_LITTLE =	B_RGB16,
201 	B_RGB15_LITTLE =	B_RGB15,
202 	B_RGBA15_LITTLE =	B_RGBA15,
203 
204 	// non linear color space -- note that these are here for exchange purposes;
205 	// a BBitmap or BView may not necessarily support all these color spaces.
206 
207 	// Loss/Saturation points are Y 16-235 (absoulte); Cb/Cr 16-240 (center 128)
208 
209 	B_YCbCr422 = 		0x4000,	// Y0[7:0]  Cb0[7:0]  Y1[7:0]  Cr0[7:0]  Y2[7:0]...
210 								// Cb2[7:0]  Y3[7:0]  Cr2[7:0]
211 	B_YCbCr411 = 		0x4001,	// Cb0[7:0]  Y0[7:0]  Cr0[7:0]  Y1[7:0]  Cb4[7:0]...
212 								// Y2[7:0]  Cr4[7:0]  Y3[7:0]  Y4[7:0]  Y5[7:0]...
213 								// Y6[7:0]  Y7[7:0]
214 	B_YCbCr444 = 		0x4003,	// Y0[7:0]  Cb0[7:0]  Cr0[7:0]
215 	B_YCbCr420 = 		0x4004,	// Non-interlaced only, Cb0  Y0  Y1  Cb2 Y2  Y3
216 								// on even scan lines,  Cr0  Y0  Y1  Cr2 Y2  Y3
217 								// on odd scan lines
218 
219 	// Extrema points are
220 	//		Y 0 - 207 (absolute)
221 	//		U -91 - 91 (offset 128)
222 	//		V -127 - 127 (offset 128)
223 	// note that YUV byte order is different from YCbCr
224 	// USE YCbCr, not YUV, when that's what you mean!
225 	B_YUV422 =			0x4020, // U0[7:0]  Y0[7:0]   V0[7:0]  Y1[7:0] ...
226 								// U2[7:0]  Y2[7:0]   V2[7:0]  Y3[7:0]
227 	B_YUV411 =			0x4021, // U0[7:0]  Y0[7:0]  Y1[7:0]  V0[7:0]  Y2[7:0]  Y3[7:0]
228 								// U4[7:0]  Y4[7:0]  Y5[7:0]  V4[7:0]  Y6[7:0]  Y7[7:0]
229 	B_YUV444 =			0x4023,	// U0[7:0]  Y0[7:0]  V0[7:0]  U1[7:0]  Y1[7:0]  V1[7:0]
230 	B_YUV420 = 			0x4024,	// Non-interlaced only, U0  Y0  Y1  U2 Y2  Y3
231 								// on even scan lines,  V0  Y0  Y1  V2 Y2  Y3
232 								// on odd scan lines
233 	B_YUV9 = 			0x402C,	// planar?	410?
234 	B_YUV12 = 			0x402D,	// planar?	420?
235 
236 	B_UVL24 =			0x4030,	// U0[7:0] V0[7:0] L0[7:0] ...
237 	B_UVL32 =			0x4031,	// U0[7:0] V0[7:0] L0[7:0] X0[7:0]...
238 	B_UVLA32 =			0x6031,	// U0[7:0] V0[7:0] L0[7:0] A0[7:0]...
239 
240 	B_LAB24 =			0x4032,	// L0[7:0] a0[7:0] b0[7:0] ...  (a is not alpha!)
241 	B_LAB32 =			0x4033,	// L0[7:0] a0[7:0] b0[7:0] X0[7:0] ... (b is not alpha!)
242 	B_LABA32 =			0x6033,	// L0[7:0] a0[7:0] b0[7:0] A0[7:0] ... (A is alpha)
243 
244 	// red is at hue = 0
245 
246 	B_HSI24 =			0x4040,	// H[7:0]  S[7:0]  I[7:0]
247 	B_HSI32 =			0x4041,	// H[7:0]  S[7:0]  I[7:0]  X[7:0]
248 	B_HSIA32 =			0x6041,	// H[7:0]  S[7:0]  I[7:0]  A[7:0]
249 
250 	B_HSV24 =			0x4042,	// H[7:0]  S[7:0]  V[7:0]
251 	B_HSV32 =			0x4043,	// H[7:0]  S[7:0]  V[7:0]  X[7:0]
252 	B_HSVA32 =			0x6043,	// H[7:0]  S[7:0]  V[7:0]  A[7:0]
253 
254 	B_HLS24 =			0x4044,	// H[7:0]  L[7:0]  S[7:0]
255 	B_HLS32 =			0x4045,	// H[7:0]  L[7:0]  S[7:0]  X[7:0]
256 	B_HLSA32 =			0x6045,	// H[7:0]  L[7:0]  S[7:0]  A[7:0]
257 
258 	B_CMY24 =			0xC001,	// C[7:0]  M[7:0]  Y[7:0]  			No gray removal done
259 	B_CMY32 =			0xC002,	// C[7:0]  M[7:0]  Y[7:0]  X[7:0]	No gray removal done
260 	B_CMYA32 =			0xE002,	// C[7:0]  M[7:0]  Y[7:0]  A[7:0]	No gray removal done
261 	B_CMYK32 =			0xC003,	// C[7:0]  M[7:0]  Y[7:0]  K[7:0]
262 
263 	// compatibility declarations
264 	B_MONOCHROME_1_BIT = 	B_GRAY1,
265 	B_GRAYSCALE_8_BIT =		B_GRAY8,
266 	B_COLOR_8_BIT =			B_CMAP8,
267 	B_RGB_32_BIT =			B_RGB32,
268 	B_RGB_16_BIT =			B_RGB15,
269 	B_BIG_RGB_32_BIT =		B_RGB32_BIG,
270 	B_BIG_RGB_16_BIT =		B_RGB15_BIG
271 } color_space;
272 
273 
274 // Find out whether a specific color space is supported by BBitmaps.
275 // Support_flags will be set to what kinds of support are available.
276 // If support_flags is set to 0, false will be returned.
277 enum {
278 	B_VIEWS_SUPPORT_DRAW_BITMAP = 0x1,
279 	B_BITMAPS_SUPPORT_ATTACHED_VIEWS = 0x2
280 };
281 bool bitmaps_support_space(color_space space, uint32 * support_flags);
282 
283 //------------------------------------------------------------------------------
284 // "pixel_chunk" is the native increment from one pixel starting on an integral byte
285 // to the next. "row_alignment" is the native alignment for pixel scanline starts.
286 // "pixels_per_chunk" is the number of pixels in a pixel_chunk. For instance, B_GRAY1
287 // sets pixel_chunk to 1, row_alignment to 4 and pixels_per_chunk to 8, whereas
288 // B_RGB24 sets pixel_chunk to 3, row_alignment to 4 and pixels_per_chunk to 1.
289 //------------------------------------------------------------------------------
290 status_t get_pixel_size_for(color_space space, size_t * pixel_chunk,
291 	size_t * row_alignment, size_t * pixels_per_chunk);
292 
293 
294 enum buffer_orientation {
295 	B_BUFFER_TOP_TO_BOTTOM,
296 	B_BUFFER_BOTTOM_TO_TOP
297 };
298 
299 enum buffer_layout {
300 	B_BUFFER_NONINTERLEAVED = 1
301 };
302 
303 //------------------------------------------------------------------------------
304 
305 enum drawing_mode {
306 	B_OP_COPY,
307 	B_OP_OVER,
308 	B_OP_ERASE,
309 	B_OP_INVERT,
310 	B_OP_ADD,
311 	B_OP_SUBTRACT,
312 	B_OP_BLEND,
313 	B_OP_MIN,
314 	B_OP_MAX,
315 	B_OP_SELECT,
316 	B_OP_ALPHA
317 };
318 
319 enum source_alpha {
320 	B_PIXEL_ALPHA=0,
321 	B_CONSTANT_ALPHA
322 };
323 
324 enum alpha_function {
325 	B_ALPHA_OVERLAY=0,
326 	B_ALPHA_COMPOSITE
327 };
328 
329 enum {
330 	B_8_BIT_640x480    = 0x00000001,
331 	B_8_BIT_800x600    = 0x00000002,
332 	B_8_BIT_1024x768   = 0x00000004,
333 	B_8_BIT_1280x1024  = 0x00000008,
334 	B_8_BIT_1600x1200  = 0x00000010,
335 	B_16_BIT_640x480   = 0x00000020,
336 	B_16_BIT_800x600   = 0x00000040,
337 	B_16_BIT_1024x768  = 0x00000080,
338 	B_16_BIT_1280x1024 = 0x00000100,
339 	B_16_BIT_1600x1200 = 0x00000200,
340 	B_32_BIT_640x480   = 0x00000400,
341 	B_32_BIT_800x600   = 0x00000800,
342 	B_32_BIT_1024x768  = 0x00001000,
343 	B_32_BIT_1280x1024 = 0x00002000,
344 	B_32_BIT_1600x1200 = 0x00004000,
345     B_8_BIT_1152x900   = 0x00008000,
346     B_16_BIT_1152x900  = 0x00010000,
347     B_32_BIT_1152x900  = 0x00020000,
348 	B_15_BIT_640x480   = 0x00040000,
349 	B_15_BIT_800x600   = 0x00080000,
350 	B_15_BIT_1024x768  = 0x00100000,
351 	B_15_BIT_1280x1024 = 0x00200000,
352 	B_15_BIT_1600x1200 = 0x00400000,
353     B_15_BIT_1152x900  = 0x00800000,
354 
355 	// do not use B_FAKE_DEVICE--it will go away!
356 	B_FAKE_DEVICE	   = 0x40000000,
357 	B_8_BIT_640x400	   = (int)0x80000000
358 };
359 
360 #endif	// _GRAPHICSDEFS_H
361 
362 /*
363  * $Log $
364  *
365  * $Id  $
366  *
367  */
368 
369