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