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