xref: /haiku/src/build/libbe/interface/GraphicsDefs.cpp (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2004, Haiku
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.cpp
23 //	Author:			DarkWyrm <bpmagic@columbus.rr.com>
24 //					Caz <turok2@currantbun.com>
25 //					Axel Dörfler <axeld@pinc-software.de>
26 //	Description:	Graphics functions and variables for the Interface Kit
27 //
28 //------------------------------------------------------------------------------
29 
30 #include <GraphicsDefs.h>
31 
32 // patterns
33 const pattern B_SOLID_HIGH = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
34 const pattern B_MIXED_COLORS = {{0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55}};
35 const pattern B_SOLID_LOW = {{0, 0, 0, 0, 0, 0, 0, 0}};
36 
37 // colors
38 const rgb_color B_TRANSPARENT_COLOR = {0x77, 0x74, 0x77, 0x00};
39 const rgb_color B_TRANSPARENT_32_BIT = {0x77, 0x74, 0x77, 0x00};
40 const uint8 B_TRANSPARENT_8_BIT = 0xff;
41 
42 const uint8 B_TRANSPARENT_MAGIC_CMAP8 = 0xff;
43 const uint16 B_TRANSPARENT_MAGIC_RGBA15 = 0x39ce;
44 const uint16 B_TRANSPARENT_MAGIC_RGBA15_BIG = 0xce39;
45 const uint32 B_TRANSPARENT_MAGIC_RGBA32 = 0x00777477;
46 const uint32 B_TRANSPARENT_MAGIC_RGBA32_BIG = 0x77747700;
47 
48 // misc.
49 const struct screen_id B_MAIN_SCREEN_ID = {0};
50 
51 
52 status_t
53 get_pixel_size_for(color_space space, size_t *pixelChunk, size_t *rowAlignment, size_t *pixelsPerChunk)
54 {
55 	status_t status = B_OK;
56 	int32 bytesPerPixel = 0;
57 	int32 pixPerChunk = 0;
58 	switch (space) {
59 		// supported
60 		case B_RGBA64: case B_RGBA64_BIG:
61 			bytesPerPixel = 8;
62 			pixPerChunk = 2;
63 			break;
64 		case B_RGB48: case B_RGB48_BIG:
65 			bytesPerPixel = 6;
66 			pixPerChunk = 2;
67 			break;
68 		case B_RGB32: case B_RGBA32:
69 		case B_RGB32_BIG: case B_RGBA32_BIG:
70 		case B_UVL32: case B_UVLA32:
71 		case B_LAB32: case B_LABA32:
72 		case B_HSI32: case B_HSIA32:
73 		case B_HSV32: case B_HSVA32:
74 		case B_HLS32: case B_HLSA32:
75 		case B_CMY32: case B_CMYA32: case B_CMYK32:
76 			bytesPerPixel = 4;
77 			pixPerChunk = 1;
78 			break;
79 		case B_RGB24: case B_RGB24_BIG:
80 		case B_UVL24: case B_LAB24: case B_HSI24:
81 		case B_HSV24: case B_HLS24: case B_CMY24:
82 			bytesPerPixel = 3;
83 			pixPerChunk = 1;
84 			break;
85 		case B_RGB16:		case B_RGB15:		case B_RGBA15:
86 		case B_RGB16_BIG:	case B_RGB15_BIG:	case B_RGBA15_BIG:
87 			bytesPerPixel = 2;
88 			pixPerChunk = 1;
89 			break;
90 		case B_CMAP8: case B_GRAY8:
91 			bytesPerPixel = 1;
92 			pixPerChunk = 1;
93 			break;
94 		case B_GRAY1:
95 			bytesPerPixel = 1;
96 			pixPerChunk = 8;
97 			break;
98 		case B_YCbCr422: case B_YUV422:
99 			bytesPerPixel = 4;
100 			pixPerChunk = 2;
101 			break;
102 		case B_YCbCr411: case B_YUV411:
103 			bytesPerPixel = 12;
104 			pixPerChunk = 8;
105 			break;
106 		case B_YCbCr444: case B_YUV444:
107 			bytesPerPixel = 3;
108 			pixPerChunk = 1;
109 			break;
110 		// TODO: I don't know if it's correct,
111 		// but beos reports B_YUV420 to be
112 		// 6 bytes per pixel and 4 pixel per chunk
113 		case B_YCbCr420: case B_YUV420:
114 			bytesPerPixel = 3;
115 			pixPerChunk = 2;
116 			break;
117 		case B_YUV9:
118 			bytesPerPixel = 5;
119 			pixPerChunk = 4;
120 			break;
121 		case B_YUV12:
122 			bytesPerPixel = 6;
123 			pixPerChunk = 4;
124 			break;
125 		// unsupported
126 		case B_NO_COLOR_SPACE:
127 		default:
128 			status = B_BAD_VALUE;
129 			break;
130 	}
131 
132 	if (pixelChunk != NULL)
133 		*pixelChunk = bytesPerPixel;
134 
135 	size_t alignment = 0;
136 	if (bytesPerPixel != 0) {
137 		alignment = (sizeof(int) % bytesPerPixel) * sizeof(int);
138 		if (alignment < sizeof(int))
139 			alignment = sizeof(int);
140 	}
141 
142 	if (rowAlignment!= NULL)
143 		*rowAlignment = alignment;
144 
145 	if (pixelsPerChunk!= NULL)
146 		*pixelsPerChunk = pixPerChunk;
147 
148 	return status;
149 }
150 
151 
152 bool
153 bitmaps_support_space(color_space space, uint32 *supportFlags)
154 {
155 	// TODO: fill supportFlags with the supported flags:
156 	// - B_VIEWS_SUPPORT_DRAW_BITMAP
157 	// - B_BITMAPS_SUPPORT_ATTACHED_VIEWS
158 	bool result = false;
159 	switch (space) {
160 		// supported
161 		case B_RGBA64:		case B_RGBA64_BIG:
162 		case B_RGB48:		case B_RGB48_BIG:
163 		case B_RGB32:		case B_RGBA32:		case B_RGB24:
164 		case B_RGB32_BIG:	case B_RGBA32_BIG:	case B_RGB24_BIG:
165 		case B_RGB16:		case B_RGB15:		case B_RGBA15:
166 		case B_RGB16_BIG:	case B_RGB15_BIG:	case B_RGBA15_BIG:
167 		case B_CMAP8:		case B_GRAY8:		case B_GRAY1:
168 		case B_YCbCr422: case B_YCbCr411: case B_YCbCr444: case B_YCbCr420:
169 		case B_YUV422: case B_YUV411: case B_YUV444: case B_YUV420:
170 		case B_UVL24: case B_UVL32: case B_UVLA32:
171 		case B_LAB24: case B_LAB32: case B_LABA32:
172 		case B_HSI24: case B_HSI32: case B_HSIA32:
173 		case B_HSV24: case B_HSV32: case B_HSVA32:
174 		case B_HLS24: case B_HLS32: case B_HLSA32:
175 		case B_CMY24: case B_CMY32: case B_CMYA32: case B_CMYK32:
176 			result = true;
177 			break;
178 		// unsupported
179 		case B_NO_COLOR_SPACE:
180 		case B_YUV9: case B_YUV12:
181 			break;
182 	}
183 	return result;
184 }
185