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