Line data Source code
1 : #include "ColorReference.h"
2 :
3 0 : libmspub::Color libmspub::ColorReference::getRealColor(unsigned c, const std::vector<Color> &palette) const
4 : {
5 0 : unsigned char type = (c >> 24) & 0xFF;
6 0 : if (type == 0x08)
7 : {
8 0 : if ((c & 0xFFFFFF) >= palette.size())
9 : {
10 0 : return Color();
11 : }
12 0 : return palette[c & 0xFFFFFF];
13 : }
14 0 : return Color(c & 0xFF, (c >> 8) & 0xFF, (c >> 16) & 0xFF);
15 : }
16 0 : libmspub::Color libmspub::ColorReference::getFinalColor(const std::vector<Color> &palette) const
17 : {
18 0 : unsigned char modifiedType = (m_modifiedColor >> 24) & 0xFF;
19 0 : if (modifiedType == CHANGE_INTENSITY)
20 : {
21 0 : Color c = getRealColor(m_baseColor, palette);
22 0 : unsigned char changeIntensityBase = (m_modifiedColor >> 8) & 0xFF;
23 0 : double intensity = (double)((m_modifiedColor >> 16) & 0xFF) / 0xFF;
24 0 : if (changeIntensityBase == BLACK_BASE)
25 : {
26 0 : return Color(c.r * intensity, c.g * intensity, c.b * intensity);
27 : }
28 0 : if (changeIntensityBase == WHITE_BASE)
29 : {
30 0 : return Color(c.r + (255 - c.r) * (1 - intensity), c.g + (255 - c.g) * (1 - intensity), c.b + (255 - c.b) * (1 - intensity));
31 : }
32 0 : return Color();
33 : }
34 : else
35 : {
36 0 : return getRealColor(m_modifiedColor, palette);
37 : }
38 : }
39 :
40 : namespace libmspub
41 : {
42 0 : bool operator==(const libmspub::ColorReference &l, const libmspub::ColorReference &r)
43 : {
44 0 : return l.m_baseColor == r.m_baseColor && l.m_modifiedColor == r.m_modifiedColor;
45 : }
46 :
47 : // const unsigned char ColorReference::COLOR_PALETTE = 0x8;
48 :
49 : const unsigned char ColorReference::CHANGE_INTENSITY = 0x10;
50 :
51 : const unsigned char ColorReference::BLACK_BASE = 0x1;
52 :
53 : const unsigned char ColorReference::WHITE_BASE = 0x2;
54 :
55 : }
56 :
57 : /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
|