tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / interface / GraphicsDefs.cpp
blobdb59bd596f7cd15df7c93ae3efa08538bdcb5c3a
1 /*
2 * Copyright 2001-2008, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * DarkWyrm <bpmagic@columbus.rr.com>
7 * Caz <turok2@currantbun.com>
8 * Axel Dörfler, axeld@pinc-software.de
9 */
11 //! Graphics functions and variables for the Interface Kit
13 #include <GraphicsDefs.h>
15 #include <AppServerLink.h>
16 #include <ServerProtocol.h>
19 // patterns
20 const pattern B_SOLID_HIGH = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
21 const pattern B_MIXED_COLORS = {{0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55}};
22 const pattern B_SOLID_LOW = {{0, 0, 0, 0, 0, 0, 0, 0}};
24 // colors
25 const rgb_color B_TRANSPARENT_COLOR = {0x77, 0x74, 0x77, 0x00};
26 const rgb_color B_TRANSPARENT_32_BIT = {0x77, 0x74, 0x77, 0x00};
27 const uint8 B_TRANSPARENT_8_BIT = 0xff;
29 const uint8 B_TRANSPARENT_MAGIC_CMAP8 = 0xff;
30 const uint16 B_TRANSPARENT_MAGIC_RGBA15 = 0x39ce;
31 const uint16 B_TRANSPARENT_MAGIC_RGBA15_BIG = 0xce39;
32 const uint32 B_TRANSPARENT_MAGIC_RGBA32 = 0x00777477;
33 const uint32 B_TRANSPARENT_MAGIC_RGBA32_BIG = 0x77747700;
35 // misc.
36 const struct screen_id B_MAIN_SCREEN_ID = {0};
39 status_t
40 get_pixel_size_for(color_space space, size_t *pixelChunk, size_t *rowAlignment,
41 size_t *pixelsPerChunk)
43 status_t status = B_OK;
44 int32 bytesPerPixel = 0;
45 int32 pixPerChunk = 0;
46 switch (space) {
47 // supported
48 case B_RGB32: case B_RGBA32:
49 case B_RGB32_BIG: case B_RGBA32_BIG:
50 case B_UVL32: case B_UVLA32:
51 case B_LAB32: case B_LABA32:
52 case B_HSI32: case B_HSIA32:
53 case B_HSV32: case B_HSVA32:
54 case B_HLS32: case B_HLSA32:
55 case B_CMY32: case B_CMYA32: case B_CMYK32:
56 bytesPerPixel = 4;
57 pixPerChunk = 1;
58 break;
59 case B_RGB24: case B_RGB24_BIG:
60 case B_UVL24: case B_LAB24: case B_HSI24:
61 case B_HSV24: case B_HLS24: case B_CMY24:
62 bytesPerPixel = 3;
63 pixPerChunk = 1;
64 break;
65 case B_RGB16: case B_RGB15: case B_RGBA15:
66 case B_RGB16_BIG: case B_RGB15_BIG: case B_RGBA15_BIG:
67 bytesPerPixel = 2;
68 pixPerChunk = 1;
69 break;
70 case B_CMAP8: case B_GRAY8:
71 bytesPerPixel = 1;
72 pixPerChunk = 1;
73 break;
74 case B_GRAY1:
75 bytesPerPixel = 1;
76 pixPerChunk = 8;
77 break;
78 case B_YCbCr422: case B_YUV422:
79 bytesPerPixel = 4;
80 pixPerChunk = 2;
81 break;
82 case B_YCbCr411: case B_YUV411:
83 bytesPerPixel = 12;
84 pixPerChunk = 8;
85 break;
86 case B_YCbCr444: case B_YUV444:
87 bytesPerPixel = 3;
88 pixPerChunk = 1;
89 break;
90 // TODO: I don't know if it's correct,
91 // but beos reports B_YUV420 to be
92 // 6 bytes per pixel and 4 pixel per chunk
93 case B_YCbCr420: case B_YUV420:
94 bytesPerPixel = 3;
95 pixPerChunk = 2;
96 break;
97 case B_YUV9:
98 bytesPerPixel = 5;
99 pixPerChunk = 4;
100 break;
101 case B_YUV12:
102 bytesPerPixel = 6;
103 pixPerChunk = 4;
104 break;
105 // unsupported
106 case B_NO_COLOR_SPACE:
107 default:
108 status = B_BAD_VALUE;
109 break;
112 if (pixelChunk != NULL)
113 *pixelChunk = bytesPerPixel;
115 size_t alignment = 0;
116 if (bytesPerPixel != 0) {
117 alignment = (sizeof(int) % bytesPerPixel) * sizeof(int);
118 if (alignment < sizeof(int))
119 alignment = sizeof(int);
122 if (rowAlignment!= NULL)
123 *rowAlignment = alignment;
125 if (pixelsPerChunk!= NULL)
126 *pixelsPerChunk = pixPerChunk;
128 return status;
132 static uint32
133 get_overlay_flags(color_space space)
135 BPrivate::AppServerLink link;
136 link.StartMessage(AS_GET_BITMAP_SUPPORT_FLAGS);
137 link.Attach<uint32>((uint32)space);
139 uint32 flags = 0;
140 int32 code;
141 if (link.FlushWithReply(code) == B_OK && code == B_OK) {
142 if (link.Read<uint32>(&flags) < B_OK)
143 flags = 0;
145 return flags;
149 bool
150 bitmaps_support_space(color_space space, uint32 *supportFlags)
152 bool result = true;
153 switch (space) {
154 // supported, also for drawing and for attaching BViews
155 case B_RGB32: case B_RGBA32: case B_RGB24:
156 case B_RGB32_BIG: case B_RGBA32_BIG: case B_RGB24_BIG:
157 case B_RGB16: case B_RGB15: case B_RGBA15:
158 case B_RGB16_BIG: case B_RGB15_BIG: case B_RGBA15_BIG:
159 case B_CMAP8: case B_GRAY8: case B_GRAY1:
160 if (supportFlags != NULL) {
161 *supportFlags = B_VIEWS_SUPPORT_DRAW_BITMAP
162 | B_BITMAPS_SUPPORT_ATTACHED_VIEWS
163 | get_overlay_flags(space);
165 break;
167 // supported, but cannot draw
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 if (supportFlags != NULL)
177 *supportFlags = get_overlay_flags(space);
178 break;
179 // unsupported
180 case B_NO_COLOR_SPACE:
181 case B_YUV9: case B_YUV12:
182 result = false;
183 break;
185 return result;