annotate src/color.h @ 32:91bc2329ab0c

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