aboutsummaryrefslogtreecommitdiff
path: root/graphics/decoders
diff options
context:
space:
mode:
authorMatthew Hoops2012-05-14 00:49:10 -0400
committerMatthew Hoops2012-05-14 09:56:56 -0400
commitd789df894552bf73709628f09a0282b462df797e (patch)
tree221de03284a568a9db5f54a88754bdb0aa3b8241 /graphics/decoders
parentc3f0a426fcbe2c8991b29c0e4bda1e7f0c9263b9 (diff)
downloadscummvm-rg350-d789df894552bf73709628f09a0282b462df797e.tar.gz
scummvm-rg350-d789df894552bf73709628f09a0282b462df797e.tar.bz2
scummvm-rg350-d789df894552bf73709628f09a0282b462df797e.zip
GRAPHICS: Add palette start index and color count functions to ImageDecoder
Diffstat (limited to 'graphics/decoders')
-rw-r--r--graphics/decoders/bmp.cpp12
-rw-r--r--graphics/decoders/bmp.h2
-rw-r--r--graphics/decoders/image_decoder.h5
-rw-r--r--graphics/decoders/pict.cpp7
-rw-r--r--graphics/decoders/pict.h2
-rw-r--r--graphics/decoders/png.cpp4
-rw-r--r--graphics/decoders/png.h1
7 files changed, 25 insertions, 8 deletions
diff --git a/graphics/decoders/bmp.cpp b/graphics/decoders/bmp.cpp
index 0d44881d7c..5f764e1bd3 100644
--- a/graphics/decoders/bmp.cpp
+++ b/graphics/decoders/bmp.cpp
@@ -31,6 +31,7 @@ namespace Graphics {
BitmapDecoder::BitmapDecoder() {
_surface = 0;
_palette = 0;
+ _paletteColorCount = 0;
}
BitmapDecoder::~BitmapDecoder() {
@@ -44,6 +45,7 @@ void BitmapDecoder::destroy() {
}
delete[] _palette; _palette = 0;
+ _paletteColorCount = 0;
}
bool BitmapDecoder::loadStream(Common::SeekableReadStream &stream) {
@@ -95,16 +97,16 @@ bool BitmapDecoder::loadStream(Common::SeekableReadStream &stream) {
/* uint32 imageSize = */ stream.readUint32LE();
/* uint32 pixelsPerMeterX = */ stream.readUint32LE();
/* uint32 pixelsPerMeterY = */ stream.readUint32LE();
- uint32 colorsUsed = stream.readUint32LE();
+ _paletteColorCount = stream.readUint32LE();
/* uint32 colorsImportant = */ stream.readUint32LE();
- if (colorsUsed == 0)
- colorsUsed = 256;
+ if (_paletteColorCount == 0)
+ _paletteColorCount = 256;
if (bitsPerPixel == 8) {
// Read the palette
- _palette = new byte[colorsUsed * 3];
- for (uint16 i = 0; i < colorsUsed; i++) {
+ _palette = new byte[_paletteColorCount * 3];
+ for (uint16 i = 0; i < _paletteColorCount; i++) {
_palette[i * 3 + 2] = stream.readByte();
_palette[i * 3 + 1] = stream.readByte();
_palette[i * 3 + 0] = stream.readByte();
diff --git a/graphics/decoders/bmp.h b/graphics/decoders/bmp.h
index 8a37538ee1..59da682e4d 100644
--- a/graphics/decoders/bmp.h
+++ b/graphics/decoders/bmp.h
@@ -52,10 +52,12 @@ public:
virtual bool loadStream(Common::SeekableReadStream &stream);
virtual const Surface *getSurface() const { return _surface; }
const byte *getPalette() const { return _palette; }
+ uint16 getPaletteColorCount() const { return _paletteColorCount; }
private:
Surface *_surface;
byte *_palette;
+ uint16 _paletteColorCount;
};
} // End of namespace Graphics
diff --git a/graphics/decoders/image_decoder.h b/graphics/decoders/image_decoder.h
index e768f7f9a2..7fa00749ff 100644
--- a/graphics/decoders/image_decoder.h
+++ b/graphics/decoders/image_decoder.h
@@ -78,6 +78,11 @@ public:
* @return the decoded palette, or 0 if no palette is present
*/
virtual const byte *getPalette() const { return 0; }
+
+ /** Return the starting index of the palette. */
+ virtual byte getPaletteStartIndex() const { return 0; }
+ /** Return the number of colors in the palette. */
+ virtual uint16 getPaletteColorCount() const { return 0; }
};
} // End of namespace Graphics
diff --git a/graphics/decoders/pict.cpp b/graphics/decoders/pict.cpp
index bdb733a87d..7eddd3b893 100644
--- a/graphics/decoders/pict.cpp
+++ b/graphics/decoders/pict.cpp
@@ -38,6 +38,7 @@ namespace Graphics {
PICTDecoder::PICTDecoder() {
_outputSurface = 0;
+ _paletteColorCount = 0;
}
PICTDecoder::~PICTDecoder() {
@@ -50,6 +51,8 @@ void PICTDecoder::destroy() {
delete _outputSurface;
_outputSurface = 0;
}
+
+ _paletteColorCount = 0;
}
#define OPCODE(a, b, c) _opcodes.push_back(PICTOpcode(a, &PICTDecoder::b, c))
@@ -298,9 +301,9 @@ void PICTDecoder::unpackBitsRect(Common::SeekableReadStream &stream, bool hasPal
// See http://developer.apple.com/legacy/mac/library/documentation/mac/QuickDraw/QuickDraw-267.html
stream.readUint32BE(); // seed
stream.readUint16BE(); // flags
- uint16 colorCount = stream.readUint16BE() + 1;
+ _paletteColorCount = stream.readUint16BE() + 1;
- for (uint32 i = 0; i < colorCount; i++) {
+ for (uint32 i = 0; i < _paletteColorCount; i++) {
stream.readUint16BE();
_palette[i * 3] = stream.readUint16BE() >> 8;
_palette[i * 3 + 1] = stream.readUint16BE() >> 8;
diff --git a/graphics/decoders/pict.h b/graphics/decoders/pict.h
index 1d07df1ab9..417a7c5134 100644
--- a/graphics/decoders/pict.h
+++ b/graphics/decoders/pict.h
@@ -57,6 +57,7 @@ public:
void destroy();
const Surface *getSurface() const { return _outputSurface; }
const byte *getPalette() const { return _palette; }
+ uint16 getPaletteColorCount() const { return _paletteColorCount; }
struct PixMap {
uint32 baseAddr;
@@ -81,6 +82,7 @@ public:
private:
Common::Rect _imageRect;
byte _palette[256 * 3];
+ uint16 _paletteColorCount;
Graphics::Surface *_outputSurface;
bool _continueParsing;
diff --git a/graphics/decoders/png.cpp b/graphics/decoders/png.cpp
index b87b6fdc7a..492c69779f 100644
--- a/graphics/decoders/png.cpp
+++ b/graphics/decoders/png.cpp
@@ -99,7 +99,7 @@ enum PNGFilters {
};
PNGDecoder::PNGDecoder() : _compressedBuffer(0), _compressedBufferSize(0),
- _transparentColorSpecified(false), _outputSurface(0) {
+ _transparentColorSpecified(false), _outputSurface(0), _paletteEntries(0) {
}
PNGDecoder::~PNGDecoder() {
@@ -112,6 +112,8 @@ void PNGDecoder::destroy() {
delete _outputSurface;
_outputSurface = 0;
}
+
+ _paletteEntries = 0;
}
bool PNGDecoder::loadStream(Common::SeekableReadStream &stream) {
diff --git a/graphics/decoders/png.h b/graphics/decoders/png.h
index 1da0bea1ab..ca204f6dd3 100644
--- a/graphics/decoders/png.h
+++ b/graphics/decoders/png.h
@@ -73,6 +73,7 @@ public:
void destroy();
const Graphics::Surface *getSurface() const { return _outputSurface; }
const byte *getPalette() const { return _palette; }
+ uint16 getPaletteColorCount() const { return _paletteEntries; }
private:
enum PNGColorType {