/
colorpalette.h
108 lines (96 loc) · 3.21 KB
/
colorpalette.h
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/** @file colorpalette.h Color palette resource.
*
* @authors Copyright © 2009-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef DENG_RESOURCE_COLORPALETTE_H
#define DENG_RESOURCE_COLORPALETTE_H
#include "dd_types.h"
#include <de/Vector>
/**
* Color Palette.
*
* @ingroup resource
*/
class ColorPalette
{
public:
/// Maximum number of bits per color component.
static int const max_component_bits = 16;
public:
/**
* Construct a new empty color palette.
*/
ColorPalette();
/**
* Constructs a new color palette using the specified color table.
*
* @param compOrder Component order. Examples:
* <pre> [0,1,2] == RGB
* [2,1,0] == BGR
* </pre>
*
* @param compBits Number of bits per component [R,G,B].
* @param colorData Color triplets (at least @a numColors * 3).
* @param colorCount Number of color triplets.
*/
ColorPalette(int const compOrder[3], uint8_t const compBits[3],
uint8_t const *colorData, int colorCount);
/**
* Returns the total number of colors in the palette.
*/
int size() const;
/**
* Replace the entire color table.
*
* @param compOrder Component order. Examples:
* <pre> [0,1,2] == RGB
* [2,1,0] == BGR
* </pre>
*
* @param compBits Number of bits per component [R,G,B].
* @param colorData Color triplets (at least @a numColors * 3).
* @param colorCount Number of color triplets.
*/
void replaceColorTable(int const compOrder[3], uint8_t const compBits[3],
uint8_t const *colorData, int colorCount);
/**
* Lookup a color in the palette by @a colorIndex. If the specified index is
* out of valid [0..colorCount) range it will be clamped.
*
* @param colorIndex Index of the color in the palette.
*
* @return Associated R8G8B8 color triplet.
*
* @see colorf()
*/
de::Vector3ub color(int colorIndex) const;
/**
* Same as @ref color() except the color is returned in [0..1] floating-point.
*/
de::Vector3f colorf(int colorIndex) const;
/**
* Given an R8G8B8 color triplet return the closet matching color index.
*
* @param rgb R8G8B8 color to be matched.
*
* @return Closet matching color index or @c -1 if no colors in the palette.
*/
int nearestIndex(de::Vector3ub const &rgb) const;
private:
DENG2_PRIVATE(d)
};
#endif // DENG_RESOURCE_COLORPALETTE_H