From 6d072a321b05693fefdbe0f9db1db0b8b76324f1 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Sat, 27 Dec 2008 22:47:34 +0000 Subject: 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 --- graphics/dither.cpp | 15 +++++++++++---- graphics/dither.h | 7 ++++++- 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. -- cgit v1.2.3