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
33const pattern B_SOLID_HIGH = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
34const pattern B_MIXED_COLORS = {{0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55}};
35const pattern B_SOLID_LOW = {{0, 0, 0, 0, 0, 0, 0, 0}};
36
37// colors
38const rgb_color B_TRANSPARENT_COLOR = {0x77, 0x74, 0x77, 0x00};
39const rgb_color B_TRANSPARENT_32_BIT = {0x77, 0x74, 0x77, 0x00};
40const uint8 B_TRANSPARENT_8_BIT = 0xff;
41
42const uint8 B_TRANSPARENT_MAGIC_CMAP8 = 0xff;
43const uint16 B_TRANSPARENT_MAGIC_RGBA15 = 0x39ce;
44const uint16 B_TRANSPARENT_MAGIC_RGBA15_BIG = 0xce39;
45const uint32 B_TRANSPARENT_MAGIC_RGBA32 = 0x00777477;
46const uint32 B_TRANSPARENT_MAGIC_RGBA32_BIG = 0x77747700;
47
48// misc.
49const struct screen_id B_MAIN_SCREEN_ID = {0};
50
51
52status_t
53get_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_RGB32: case B_RGBA32:
61		case B_RGB32_BIG: case B_RGBA32_BIG:
62		case B_UVL32: case B_UVLA32:
63		case B_LAB32: case B_LABA32:
64		case B_HSI32: case B_HSIA32:
65		case B_HSV32: case B_HSVA32:
66		case B_HLS32: case B_HLSA32:
67		case B_CMY32: case B_CMYA32: case B_CMYK32:
68			bytesPerPixel = 4;
69			pixPerChunk = 1;
70			break;
71		case B_RGB24: case B_RGB24_BIG:
72		case B_UVL24: case B_LAB24: case B_HSI24:
73		case B_HSV24: case B_HLS24: case B_CMY24:
74			bytesPerPixel = 3;
75			pixPerChunk = 1;
76			break;
77		case B_RGB16:		case B_RGB15:		case B_RGBA15:
78		case B_RGB16_BIG:	case B_RGB15_BIG:	case B_RGBA15_BIG:
79			bytesPerPixel = 2;
80			pixPerChunk = 1;
81			break;
82		case B_CMAP8: case B_GRAY8:
83			bytesPerPixel = 1;
84			pixPerChunk = 1;
85			break;
86		case B_GRAY1:
87			bytesPerPixel = 1;
88			pixPerChunk = 8;
89			break;
90		case B_YCbCr422: case B_YUV422:
91			bytesPerPixel = 4;
92			pixPerChunk = 2;
93			break;
94		case B_YCbCr411: case B_YUV411:
95			bytesPerPixel = 12;
96			pixPerChunk = 8;
97			break;
98		case B_YCbCr444: case B_YUV444:
99			bytesPerPixel = 3;
100			pixPerChunk = 1;
101			break;
102		// TODO: I don't know if it's correct,
103		// but beos reports B_YUV420 to be
104		// 6 bytes per pixel and 4 pixel per chunk
105		case B_YCbCr420: case B_YUV420:
106			bytesPerPixel = 3;
107			pixPerChunk = 2;
108			break;
109		case B_YUV9:
110			bytesPerPixel = 5;
111			pixPerChunk = 4;
112			break;
113		case B_YUV12:
114			bytesPerPixel = 6;
115			pixPerChunk = 4;
116			break;
117		// unsupported
118		case B_NO_COLOR_SPACE:
119		default:
120			status = B_BAD_VALUE;
121			break;
122	}
123
124	if (pixelChunk != NULL)
125		*pixelChunk = bytesPerPixel;
126
127	size_t alignment = 0;
128	if (bytesPerPixel != 0) {
129		alignment = (sizeof(int) % bytesPerPixel) * sizeof(int);
130		if (alignment < sizeof(int))
131			alignment = sizeof(int);
132	}
133
134	if (rowAlignment!= NULL)
135		*rowAlignment = alignment;
136
137	if (pixelsPerChunk!= NULL)
138		*pixelsPerChunk = pixPerChunk;
139
140	return status;
141}
142
143
144bool
145bitmaps_support_space(color_space space, uint32 *supportFlags)
146{
147	// TODO: fill supportFlags with the supported flags:
148	// - B_VIEWS_SUPPORT_DRAW_BITMAP
149	// - B_BITMAPS_SUPPORT_ATTACHED_VIEWS
150	bool result = false;
151	switch (space) {
152		// supported
153		case B_RGB32:		case B_RGBA32:		case B_RGB24:
154		case B_RGB32_BIG:	case B_RGBA32_BIG:	case B_RGB24_BIG:
155		case B_RGB16:		case B_RGB15:		case B_RGBA15:
156		case B_RGB16_BIG:	case B_RGB15_BIG:	case B_RGBA15_BIG:
157		case B_CMAP8:		case B_GRAY8:		case B_GRAY1:
158		case B_YCbCr422: case B_YCbCr411: case B_YCbCr444: case B_YCbCr420:
159		case B_YUV422: case B_YUV411: case B_YUV444: case B_YUV420:
160		case B_UVL24: case B_UVL32: case B_UVLA32:
161		case B_LAB24: case B_LAB32: case B_LABA32:
162		case B_HSI24: case B_HSI32: case B_HSIA32:
163		case B_HSV24: case B_HSV32: case B_HSVA32:
164		case B_HLS24: case B_HLS32: case B_HLSA32:
165		case B_CMY24: case B_CMY32: case B_CMYA32: case B_CMYK32:
166			result = true;
167			break;
168		// unsupported
169		case B_NO_COLOR_SPACE:
170		case B_YUV9: case B_YUV12:
171			break;
172	}
173	return result;
174}
175