Mercurial > molko
comparison src/color.h @ 11:d1cdb90d9558
core: implement color manipulation, closes #2446
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 07 Jan 2020 20:41:11 +0100 |
parents | |
children | 8f6a1ffb1ebe |
comparison
equal
deleted
inserted
replaced
10:c91c3272101b | 11:d1cdb90d9558 |
---|---|
1 /* | |
2 * color.h -- basic color routines | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #ifndef MOLKO_COLOR_H | |
20 #define MOLKO_COLOR_H | |
21 | |
22 /** | |
23 * \file color.h | |
24 * \brief Basic color routines. | |
25 */ | |
26 | |
27 /** | |
28 * Get red component of hexadecimal color. | |
29 * | |
30 * \param c the hexadecimal color | |
31 * \return the red component | |
32 */ | |
33 #define COLOR_R(c) (c >> 24 & 0xff) | |
34 | |
35 /** | |
36 * Get green component of hexadecimal color. | |
37 * | |
38 * \param c the hexadecimal color | |
39 * \return the green component | |
40 */ | |
41 #define COLOR_G(c) (c >> 16 & 0xff) | |
42 | |
43 /** | |
44 * Get blue component of hexadecimal color. | |
45 * | |
46 * \param c the hexadecimal color | |
47 * \return the blue component | |
48 */ | |
49 #define COLOR_B(c) (c >> 8 & 0xff) | |
50 | |
51 /** | |
52 * Get alpha component of hexadecimal color. | |
53 * | |
54 * \param c the hexadecimal color | |
55 * \return the alpha component | |
56 */ | |
57 #define COLOR_A(c) (c & 0xff) | |
58 | |
59 /** | |
60 * Convert individual RGBA components into a hexadecimal color. | |
61 * | |
62 * \param r the red component | |
63 * \param g the green component | |
64 * \param b the blue component | |
65 * \param a the alpha component | |
66 * \return the hexadecimal color | |
67 */ | |
68 #define COLOR_HEX(r, g, b, a) \ | |
69 (r << 24 & 0xff000000 | \ | |
70 g << 16 & 0x00ff0000 | \ | |
71 b << 8 & 0x0000ff00 | \ | |
72 a & 0x000000ff) | |
73 | |
74 #endif /* !MOLKO_COLOR_H */ |