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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef MADS_PALETTE_H
#define MADS_PALETTE_H
#include "common/scummsys.h"
#include "common/stream.h"
namespace MADS {
class MADSEngine;
struct RGB4 {
byte r;
byte g;
byte b;
byte u;
};
/**
* Used to store a list of RGB values
*/
class RGBList {
private:
int _size;
byte *_data;
byte *_palIndexes;
bool _freeData;
public:
/**
* Constructor
*/
RGBList(int numEntries = 256, byte *srcData = NULL, bool freeData = true);
/**
* Destructor
*/
~RGBList();
/**
* Returns the raw data containing the RGB values as 3 bytes per entry
*/
byte *data() { return _data; }
/**
* Returns the list of palette indexes each RGB tuple maps to in the current palette
*/
byte *palIndexes() { return _palIndexes; }
/**
* Returns the size of the palette
*/
int size() const { return _size; }
};
#define PALETTE_COUNT 256
#define PALETTE_SIZE (256 * 3)
class Palette {
private:
/**
* Initialises a stanadrd range of colours for the given palette
*/
void initRange(byte *palette);
protected:
MADSEngine *_vm;
bool _colorsChanged;
bool _fading_in_progress;
byte _originalPalette[PALETTE_COUNT * 4];
byte _fadedPalette[PALETTE_COUNT * 4];
int _usageCount[PALETTE_COUNT];
void reset();
public:
byte _mainPalette[PALETTE_SIZE];
RGB4 _gamePalette[PALETTE_COUNT];
public:
/**
* Constructor
*/
Palette(MADSEngine *vm);
/**
* Destructor
*/
virtual ~Palette() {}
/**
* Sets a new palette
*/
void setPalette(const byte *colors, uint start, uint num);
/**
* Returns a subset of the currently loaded palette
*/
void grabPalette(byte *colors, uint start, uint num);
/**
* Returns the palette index in the palette that most closely matches the
* specified RGB pair
*/
uint8 palIndexFromRgb(byte r, byte g, byte b, byte *paletteData = nullptr);
// Methods used for reference counting color usage
/**
* Resets the usage counts for the palette
*/
void resetColorCounts();
/**
* Blocks out a range of the palette from being used
*/
void blockRange(int startIndex, int size);
/**
* Adds the data of an RGBList into the current palette and increment usage counts.
*/
void addRange(RGBList *list);
/**
* Delets a range from the current palette, dercementing the accompanying usage counts.
*/
void deleteRange(RGBList *list);
/**
* Deletes all loaded RGB lists are their usage references.
*/
void deleteAllRanges();
// Virtual method table
/**
* Decode a palette and return it, without affecting the Palette itself
*/
byte *decodePalette(Common::SeekableReadStream *palStream, int *numColors);
/**
* Loads a palette from a stream
*/
int loadPalette(Common::SeekableReadStream *palStream, int indexStart = 0);
/**
* Sets a small set of system/core colors needed by the game
*/
void setSystemPalette();
/**
* Update a range of an arbitrary palette
*/
static void setGradient(byte *palette, int start, int count, int rgbValue1, int rgbValue2);
/**
* Resets the game palette
*/
void resetGamePalette(int v1, int v2);
/**
* Initialises game palette
*/
void initGamePalette();
/**
* Set the first four palette entries with preset values
*/
void setLowRange();
/**
* Set up the palette as the game ends
*/
void close() {
warning("TODO: Palette::close");
}
// Color indexes
uint8 BLACK;
uint8 BLUE;
uint8 GREEN;
uint8 CYAN;
uint8 RED;
uint8 VIOLET;
uint8 BROWN;
uint8 LIGHT_GRAY;
uint8 DARK_GRAY;
uint8 LIGHT_BLUE;
uint8 LIGHT_GREEN;
uint8 LIGHT_CYAN;
uint8 LIGHT_RED;
uint8 PINK;
uint8 YELLOW;
uint8 WHITE;
};
} // End of namespace MADS
#endif /* MADS_PALETTE_H */
|