[Scummvm-cvs-logs] SF.net SVN: scummvm:[39336] scummvm/trunk/engines/cine

buddha_ at users.sourceforge.net buddha_ at users.sourceforge.net
Wed Mar 11 21:44:16 CET 2009


Revision: 39336
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39336&view=rev
Author:   buddha_
Date:     2009-03-11 20:44:16 +0000 (Wed, 11 Mar 2009)

Log Message:
-----------
Add saving functions to Cine::Palette (Now one can output the palette in other formats too).

Modified Paths:
--------------
    scummvm/trunk/engines/cine/pal.cpp
    scummvm/trunk/engines/cine/pal.h

Modified: scummvm/trunk/engines/cine/pal.cpp
===================================================================
--- scummvm/trunk/engines/cine/pal.cpp	2009-03-11 20:39:31 UTC (rev 39335)
+++ scummvm/trunk/engines/cine/pal.cpp	2009-03-11 20:44:16 UTC (rev 39336)
@@ -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 @@
 }
 
 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 @@
 	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

Modified: scummvm/trunk/engines/cine/pal.h
===================================================================
--- scummvm/trunk/engines/cine/pal.h	2009-03-11 20:39:31 UTC (rev 39335)
+++ scummvm/trunk/engines/cine/pal.h	2009-03-11 20:44:16 UTC (rev 39336)
@@ -60,6 +60,11 @@
 	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;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list