aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/cine/pal.cpp38
-rw-r--r--engines/cine/pal.h5
2 files changed, 39 insertions, 4 deletions
diff --git a/engines/cine/pal.cpp b/engines/cine/pal.cpp
index b2cb9b3451..72c04086da 100644
--- a/engines/cine/pal.cpp
+++ b/engines/cine/pal.cpp
@@ -29,6 +29,9 @@
namespace Cine {
+static const Graphics::PixelFormat kLowPalFormat = {2, 5, 5, 5, 8, 8, 4, 0, 0};
+static const Graphics::PixelFormat kHighPalFormat = {3, 0, 0, 0, 8, 0, 8, 16, 0};
+
Common::Array<PalEntry> palArray;
static byte paletteBuffer1[16];
static byte paletteBuffer2[16];
@@ -196,13 +199,11 @@ void Palette::saturatedAddColor(byte index, signed r, signed g, signed b) {
}
Palette &Palette::loadCineLowPal(const byte *colors, const uint numColors) {
- static const Graphics::PixelFormat format = {2, 5, 5, 5, 8, 8, 4, 0, 0};
- return load(colors, format, numColors);
+ return load(colors, kLowPalFormat, numColors);
}
Palette &Palette::loadCineHighPal(const byte *colors, const uint numColors) {
- static const Graphics::PixelFormat format = {3, 0, 0, 0, 8, 0, 8, 16, 0};
- return load(colors, format, numColors);
+ return load(colors, kHighPalFormat, numColors);
}
Palette &Palette::load(const byte *colors, const Graphics::PixelFormat format, const uint numColors) {
@@ -232,4 +233,33 @@ Palette &Palette::load(const byte *colors, const Graphics::PixelFormat format, c
return *this;
}
+byte *Palette::save(byte *colors, const uint numBytes, const Graphics::PixelFormat format) const
+{
+ assert(numBytes <= format.bytesPerPixel * colorCount()); // Make sure there's enough output space
+
+ // Clear the part of the output palette we're going to be writing to with all black
+ memset(colors, 0, format.bytesPerPixel * colorCount());
+
+ // Save the palette to the output in the specified format
+ for (uint i = 0; i < colorCount(); i++) {
+ // _rMax, _gMax, _bMax are also used as masks here
+ colors[i * format.bytesPerPixel + (format.rShift / 8)] |= ((_colors[i].r & _rMax) << (format.rShift % 8));
+ colors[i * format.bytesPerPixel + (format.gShift / 8)] |= ((_colors[i].g & _gMax) << (format.gShift % 8));
+ colors[i * format.bytesPerPixel + (format.bShift / 8)] |= ((_colors[i].b & _bMax) << (format.bShift % 8));
+ }
+
+ // Return the pointer to the output palette
+ return colors;
+}
+
+byte *Palette::saveCineLowPal(byte *colors, const uint numBytes) const
+{
+ return save(colors, numBytes, kLowPalFormat);
+}
+
+byte *Palette::saveCineHighPal(byte *colors, const uint numBytes) const
+{
+ return save(colors, numBytes, kHighPalFormat);
+}
+
} // End of namespace Cine
diff --git a/engines/cine/pal.h b/engines/cine/pal.h
index 3bebcaabba..5e6b3ea9a2 100644
--- a/engines/cine/pal.h
+++ b/engines/cine/pal.h
@@ -60,6 +60,11 @@ public:
Palette &loadCineLowPal(const byte *colors, const uint numColors = 16);
Palette &loadCineHighPal(const byte *colors, const uint numColors = 256);
Palette &load(const byte *colors, const Graphics::PixelFormat format, const uint numColors);
+
+ byte *saveCineLowPal(byte *colors, const uint numBytes) const;
+ byte *saveCineHighPal(byte *colors, const uint numBytes) const;
+ byte *save(byte *colors, const uint numBytes, const Graphics::PixelFormat format) const;
+
Palette &rotateRight(byte firstIndex, byte lastIndex);
Palette &saturatedAddColor(byte firstIndex, byte lastIndex, signed r, signed g, signed b);
uint colorCount() const;