aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Hesse2008-12-27 22:47:34 +0000
committerSven Hesse2008-12-27 22:47:34 +0000
commit6d072a321b05693fefdbe0f9db1db0b8b76324f1 (patch)
treee071632e787818fa19e1b5db3339f2e9f34ca300
parent88ac9b5a9be0a4ee000b302a357d6bc7ee2c2305 (diff)
downloadscummvm-rg350-6d072a321b05693fefdbe0f9db1db0b8b76324f1.tar.gz
scummvm-rg350-6d072a321b05693fefdbe0f9db1db0b8b76324f1.tar.bz2
scummvm-rg350-6d072a321b05693fefdbe0f9db1db0b8b76324f1.zip
Adding support for specifying an index that will be ignored when building the PaletteLUT (for transparent values that should never be found)
svn-id: r35584
-rw-r--r--graphics/dither.cpp15
-rw-r--r--graphics/dither.h7
2 files changed, 17 insertions, 5 deletions
diff --git a/graphics/dither.cpp b/graphics/dither.cpp
index ff58961a17..7a92441571 100644
--- a/graphics/dither.cpp
+++ b/graphics/dither.cpp
@@ -54,9 +54,13 @@ PaletteLUT::PaletteLUT(byte depth, PaletteFormat format) {
memset(_gots, 1, _dim1);
}
-void PaletteLUT::setPalette(const byte *palette, PaletteFormat format, byte depth) {
+void PaletteLUT::setPalette(const byte *palette, PaletteFormat format,
+ byte depth, int transp) {
+
assert((depth > 1) && (depth < 9));
+ _transp = transp;
+
int shift = 8 - depth;
// Checking for the table's and the palette's pixel format
@@ -113,6 +117,10 @@ void PaletteLUT::build(int d1) {
// Going over every palette entry, searching for the closest
for (int c = 0; c < 256; c++, p += 3) {
+ // Ignore the transparent color
+ if (c == _transp)
+ continue;
+
uint32 di = SQR(d1 - p[0]) + SQR(j - p[1]) + SQR(k - p[2]);
if (di < d) {
d = di;
@@ -165,7 +173,7 @@ bool PaletteLUT::save(Common::WriteStream &stream) {
buildNext();
stream.writeUint32BE(MKID_BE('PLUT')); // Magic
- stream.writeUint32BE(0); // Version
+ stream.writeUint32BE(kVersion);
stream.writeByte(_depth1);
if (stream.write(_realPal, 768) != 768)
return false;
@@ -193,8 +201,7 @@ bool PaletteLUT::load(Common::SeekableReadStream &stream) {
if (stream.readUint32BE() != MKID_BE('PLUT'))
return false;
- // Version
- if (stream.readUint32BE() != 0)
+ if (stream.readUint32BE() != kVersion)
return false;
byte depth1 = stream.readByte();
diff --git a/graphics/dither.h b/graphics/dither.h
index 270cc8c5c2..e6d606cdd4 100644
--- a/graphics/dither.h
+++ b/graphics/dither.h
@@ -71,8 +71,9 @@ public:
* @param palette The palette, plain 256 * 3 color components.
* @param format The format the palette is in.
* @param depth The number of significant bits in each color component.
+ * @param transp An index that's seen as transparent and therefore ignored.
*/
- void setPalette(const byte *palette, PaletteFormat format, byte depth);
+ void setPalette(const byte *palette, PaletteFormat format, byte depth, int transp = -1);
/** Build the next slice.
*
@@ -111,6 +112,8 @@ public:
bool load(Common::SeekableReadStream &stream);
private:
+ static const uint32 kVersion = 1;
+
byte _depth1; //!< The table's depth for one dimension.
byte _depth2; //!< The table's depth for two dimensions.
byte _shift; //!< Amount to shift to adjust for the table's depth.
@@ -119,6 +122,8 @@ private:
uint32 _dim2; //!< The table's entry offset for two dimensions.
uint32 _dim3; //!< The table's entry offset for three dimensions.
+ int _transp; //!< The transparent palette index.
+
PaletteFormat _format; //!< The table's palette format.
byte _lutPal[768]; //!< The palette used for looking up a color.
byte _realPal[768]; //!< The original palette.