aboutsummaryrefslogtreecommitdiff
path: root/engines/mads/palette.h
diff options
context:
space:
mode:
authorPaul Gilbert2014-02-19 21:28:54 -0500
committerPaul Gilbert2014-02-19 21:28:54 -0500
commitc687d3f64cc5ac6ec09539129c5f8b0d3a7148ad (patch)
tree736c1405cc98590d733e7e2eb3c26ba45c1c36de /engines/mads/palette.h
parent5c565797e5516de97686650be8cc810007111641 (diff)
downloadscummvm-rg350-c687d3f64cc5ac6ec09539129c5f8b0d3a7148ad.tar.gz
scummvm-rg350-c687d3f64cc5ac6ec09539129c5f8b0d3a7148ad.tar.bz2
scummvm-rg350-c687d3f64cc5ac6ec09539129c5f8b0d3a7148ad.zip
MADS: Cleanup of palette code, updated old-style 4 byte RGB usage to 3 bytes
Diffstat (limited to 'engines/mads/palette.h')
-rw-r--r--engines/mads/palette.h142
1 files changed, 120 insertions, 22 deletions
diff --git a/engines/mads/palette.h b/engines/mads/palette.h
index ab03d8d20b..a5d9c6ad1e 100644
--- a/engines/mads/palette.h
+++ b/engines/mads/palette.h
@@ -29,63 +29,137 @@ namespace MADS {
class MADSEngine;
-struct RGB8 {
- uint8 r, g, b, u;
-};
-
+/**
+ * Used to store a list of RGB values
+ */
class RGBList {
private:
int _size;
- RGB8 *_data;
+ byte *_data;
byte *_palIndexes;
bool _freeData;
public:
- RGBList(int numEntries = 256, RGB8 *srcData = NULL, bool freeData = true);
+ /**
+ * Constructor
+ */
+ RGBList(int numEntries = 256, byte *srcData = NULL, bool freeData = true);
+
+ /**
+ * Destructor
+ */
~RGBList();
- RGB8 *data() { return _data; }
+ /**
+ * 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; }
- int size() { return _size; }
+
+ /**
+ * Returns the size of the palette
+ */
+ int size() const { return _size; }
};
#define PALETTE_COUNT 256
+#define PALETTE_SIZE (256 * 3)
class Palette {
private:
+ /**
+ * Support method used by the fading code
+ */
+ void fadeRange(byte *srcPal, byte *destPal, int startIndex, int endIndex,
+ int numSteps, uint delayAmount);
+protected:
MADSEngine *_vm;
bool _colorsChanged;
+
bool _fading_in_progress;
byte _originalPalette[PALETTE_COUNT * 4];
byte _fadedPalette[PALETTE_COUNT * 4];
int _usageCount[PALETTE_COUNT];
+ Palette(MADSEngine *vm);
void reset();
public:
- Palette(MADSEngine *vm);
-
+ /**
+ * Creates a new palette instance
+ */
+ static Palette *init(MADSEngine *vm);
+
+ /**
+ * Sets a new palette
+ */
void setPalette(const byte *colors, uint start, uint num);
- void setPalette(const RGB8 *colors, uint start, uint num);
- void grabPalette(byte *colors, uint start, uint num);
- void grabPalette(RGB8 *colors, uint start, uint num) {
- grabPalette((byte *)colors, start, num);
- }
- uint8 palIndexFromRgb(byte r, byte g, byte b, RGB8 *paletteData = NULL);
- void fadeIn(int numSteps, uint delayAmount, RGB8 *destPalette, int numColors);
+ /**
+ * 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);
+
+ /**
+ * Performs a fade in
+ */
+ void fadeIn(int numSteps, uint delayAmount, byte *destPalette, int numColors);
+
+ /**
+ * Performs a fade in
+ */
void fadeIn(int numSteps, uint delayAmount, RGBList *destPalette);
- static RGB8 *decodeMadsPalette(Common::SeekableReadStream *palStream, int *numColors);
- int setMadsPalette(Common::SeekableReadStream *palStream, int indexStart = 0);
- void setMadsSystemPalette();
- void fadeRange(RGB8 *srcPal, RGB8 *destPal, int startIndex, int endIndex,
- int numSteps, uint delayAmount);
// 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
+ */
+ virtual byte *decodePalette(Common::SeekableReadStream *palStream, int *numColors) = 0;
+
+ /**
+ * Loads a palette from a stream
+ */
+ virtual int loadPalette(Common::SeekableReadStream *palStream, int indexStart = 0) = 0;
+
+ /**
+ * Sets a small set of system/core colors needed by the game
+ */
+ virtual void setSystemPalette() = 0;
+
// Color indexes
uint8 BLACK;
uint8 BLUE;
@@ -105,6 +179,30 @@ public:
uint8 WHITE;
};
+class PaletteMADS: protected Palette {
+ friend class Palette;
+protected:
+ PaletteMADS(MADSEngine *vm): Palette(vm) {}
+public:
+ virtual byte *decodePalette(Common::SeekableReadStream *palStream, int *numColors);
+ virtual int loadPalette(Common::SeekableReadStream *palStream, int indexStart = 0);
+ virtual void setSystemPalette();
+};
+
+class PaletteM4: protected Palette {
+ friend class Palette;
+protected:
+ PaletteM4(MADSEngine *vm): Palette(vm) {}
+public:
+ virtual byte *decodePalette(Common::SeekableReadStream *palStream, int *numColors) {
+ return nullptr;
+ }
+ virtual int loadPalette(Common::SeekableReadStream *palStream, int indexStart = 0) {
+ return 0;
+ }
+ virtual void setSystemPalette() {}
+};
+
} // End of namespace MADS
#endif /* MADS_PALETTE_H */