1 | // Aseprite Document Library |
2 | // Copyright (c) 2020 Igara Studio S.A. |
3 | // |
4 | // This file is released under the terms of the MIT license. |
5 | // Read LICENSE.txt for more information. |
6 | |
7 | #ifdef HAVE_CONFIG_H |
8 | #include "config.h" |
9 | #endif |
10 | |
11 | #include "doc/color.h" |
12 | |
13 | #include <algorithm> |
14 | |
15 | namespace doc { |
16 | |
17 | color_t rgba_to_graya_using_hsv(const color_t c) |
18 | { |
19 | const uint8_t M = std::max(rgba_getr(c), |
20 | std::max(rgba_getg(c), |
21 | rgba_getb(c))); |
22 | return graya(M, |
23 | rgba_geta(c)); |
24 | } |
25 | |
26 | color_t rgba_to_graya_using_hsl(const color_t c) |
27 | { |
28 | const int m = std::min(rgba_getr(c), |
29 | std::min(rgba_getg(c), |
30 | rgba_getb(c))); |
31 | const int M = std::max(rgba_getr(c), |
32 | std::max(rgba_getg(c), |
33 | rgba_getb(c))); |
34 | return graya((M + m) / 2, |
35 | rgba_geta(c)); |
36 | } |
37 | |
38 | color_t rgba_to_graya_using_luma(const color_t c) |
39 | { |
40 | return graya(rgb_luma(rgba_getr(c), |
41 | rgba_getg(c), |
42 | rgba_getb(c)), |
43 | rgba_geta(c)); |
44 | } |
45 | |
46 | } // namespace doc |
47 | |