1 | // LAF Gfx Library |
---|---|
2 | // Copyright (C) 2021 Igara Studio S.A. |
3 | // Copyright (C) 2001-2016 David Capello |
4 | // |
5 | // This file is released under the terms of the MIT license. |
6 | // Read LICENSE.txt for more information. |
7 | |
8 | #ifndef GFX_COLOR_H_INCLUDED |
9 | #define GFX_COLOR_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "base/ints.h" |
13 | |
14 | namespace gfx { |
15 | |
16 | typedef uint32_t Color; |
17 | typedef uint8_t ColorComponent; |
18 | |
19 | static const uint32_t ColorRShift = 0; |
20 | static const uint32_t ColorGShift = 8; |
21 | static const uint32_t ColorBShift = 16; |
22 | static const uint32_t ColorAShift = 24; |
23 | |
24 | static const uint32_t ColorRMask = 0x000000ff; |
25 | static const uint32_t ColorGMask = 0x0000ff00; |
26 | static const uint32_t ColorBMask = 0x00ff0000; |
27 | static const uint32_t ColorAMask = 0xff000000; |
28 | static const uint32_t ColorRGBMask = 0x00ffffff; |
29 | |
30 | static const Color ColorNone = Color(0); |
31 | |
32 | inline Color rgba(ColorComponent r, ColorComponent g, ColorComponent b, ColorComponent a = 255) { |
33 | return Color((r << ColorRShift) | |
34 | (g << ColorGShift) | |
35 | (b << ColorBShift) | |
36 | (a << ColorAShift)); |
37 | } |
38 | |
39 | inline ColorComponent getr(Color c) { return (c >> ColorRShift) & 0xff; } |
40 | inline ColorComponent getg(Color c) { return (c >> ColorGShift) & 0xff; } |
41 | inline ColorComponent getb(Color c) { return (c >> ColorBShift) & 0xff; } |
42 | inline ColorComponent geta(Color c) { return (c >> ColorAShift) & 0xff; } |
43 | |
44 | inline Color seta(Color c, ColorComponent a) { |
45 | return (c & ColorRGBMask) | (a << ColorAShift); |
46 | } |
47 | |
48 | inline bool is_transparent(Color c) { return geta(c) == 0; } |
49 | |
50 | } // namespace gfx |
51 | |
52 | #endif // GFX_COLOR_H_INCLUDED |
53 |