diff options
author | Max Horn | 2009-01-23 23:50:54 +0000 |
---|---|---|
committer | Max Horn | 2009-01-23 23:50:54 +0000 |
commit | 5556fc7f72856fde1746c89792d97bd826da33a2 (patch) | |
tree | e47901665a0e52b5e3d3d5613968fd3a6033039b | |
parent | 4d5702606f7eb4c62ee07587724c1f21873bc096 (diff) | |
download | scummvm-rg350-5556fc7f72856fde1746c89792d97bd826da33a2.tar.gz scummvm-rg350-5556fc7f72856fde1746c89792d97bd826da33a2.tar.bz2 scummvm-rg350-5556fc7f72856fde1746c89792d97bd826da33a2.zip |
Changed Graphics::ImageDecoder to allow custom PixelFormats
svn-id: r36026
-rw-r--r-- | backends/vkeybd/virtual-keyboard-parser.cpp | 5 | ||||
-rw-r--r-- | graphics/imagedec.cpp | 16 | ||||
-rw-r--r-- | graphics/imagedec.h | 9 | ||||
-rw-r--r-- | gui/ThemeEngine.cpp | 4 |
4 files changed, 18 insertions, 16 deletions
diff --git a/backends/vkeybd/virtual-keyboard-parser.cpp b/backends/vkeybd/virtual-keyboard-parser.cpp index 7034d90a30..73575d0d9a 100644 --- a/backends/vkeybd/virtual-keyboard-parser.cpp +++ b/backends/vkeybd/virtual-keyboard-parser.cpp @@ -256,13 +256,14 @@ bool VirtualKeyboardParser::parserCallback_layout(ParserNode *node) { if (!file) return parserError("Bitmap '%s' not found", _mode->bitmapName.c_str()); - _mode->image = Graphics::ImageDecoder::loadFile(*file); + const Graphics::PixelFormat format = g_system->getOverlayFormat(); + + _mode->image = Graphics::ImageDecoder::loadFile(*file, format); delete file; if (!_mode->image) return parserError("Error loading bitmap '%s'", _mode->bitmapName.c_str()); - const Graphics::PixelFormat format = g_system->getOverlayFormat(); int r, g, b; if (node->values.contains("transparent_color")) { if (!parseIntegerKey(node->values["transparent_color"].c_str(), 3, &r, &g, &b)) diff --git a/graphics/imagedec.cpp b/graphics/imagedec.cpp index 267a331deb..b02ab7ac47 100644 --- a/graphics/imagedec.cpp +++ b/graphics/imagedec.cpp @@ -24,7 +24,6 @@ #include "graphics/imagedec.h" -#include "common/system.h" #include "common/file.h" namespace Graphics { @@ -37,7 +36,7 @@ public: virtual ~BMPDecoder() {} bool decodeable(Common::SeekableReadStream &stream); - Surface *decodeImage(Common::SeekableReadStream &stream); + Surface *decodeImage(Common::SeekableReadStream &stream, const PixelFormat &format); struct BitmapHeader { uint16 type; @@ -75,7 +74,7 @@ bool BMPDecoder::decodeable(Common::SeekableReadStream &stream) { return true; } -Surface *BMPDecoder::decodeImage(Common::SeekableReadStream &stream) { +Surface *BMPDecoder::decodeImage(Common::SeekableReadStream &stream, const PixelFormat &format) { if (!decodeable(stream)) { return 0; } @@ -120,14 +119,13 @@ Surface *BMPDecoder::decodeImage(Common::SeekableReadStream &stream) { newSurf->create(info.width, info.height, sizeof(OverlayColor)); assert(newSurf->pixels); OverlayColor *curPixel = (OverlayColor*)newSurf->pixels + (newSurf->h-1) * newSurf->w; - PixelFormat overlayFormat = g_system->getOverlayFormat(); int pitchAdd = info.width % 4; for (int i = 0; i < newSurf->h; ++i) { for (int i2 = 0; i2 < newSurf->w; ++i2) { b = stream.readByte(); g = stream.readByte(); r = stream.readByte(); - *curPixel = overlayFormat.RGBToColor(r, g, b); + *curPixel = format.RGBToColor(r, g, b); ++curPixel; } stream.seek(pitchAdd, SEEK_CUR); @@ -140,18 +138,18 @@ Surface *BMPDecoder::decodeImage(Common::SeekableReadStream &stream) { #pragma mark - -Surface *ImageDecoder::loadFile(const Common::String &name) { +Surface *ImageDecoder::loadFile(const Common::String &name, const PixelFormat &format) { Surface *newSurf = 0; Common::File imageFile; if (imageFile.open(name)) { - newSurf = loadFile(imageFile); + newSurf = loadFile(imageFile, format); } return newSurf; } -Surface *ImageDecoder::loadFile(Common::SeekableReadStream &stream) { +Surface *ImageDecoder::loadFile(Common::SeekableReadStream &stream, const PixelFormat &format) { // TODO: implement support for bzipped memory // FIXME: this is not a very nice solution but it should work @@ -174,6 +172,6 @@ Surface *ImageDecoder::loadFile(Common::SeekableReadStream &stream) { if (!decoder) return 0; - return decoder->decodeImage(stream); + return decoder->decodeImage(stream, format); } } // end of namespace Graphics diff --git a/graphics/imagedec.h b/graphics/imagedec.h index 6fac4c40c6..c2ef39ebab 100644 --- a/graphics/imagedec.h +++ b/graphics/imagedec.h @@ -30,15 +30,17 @@ #include "common/stream.h" #include "graphics/surface.h" +#include "graphics/pixelformat.h" namespace Graphics { + class ImageDecoder { public: ImageDecoder() {} virtual ~ImageDecoder() {} - static Surface *loadFile(const Common::String &name); - static Surface *loadFile(Common::SeekableReadStream &stream); + static Surface *loadFile(const Common::String &name, const PixelFormat &format); + static Surface *loadFile(Common::SeekableReadStream &stream, const PixelFormat &format); /** * checks if the data can be decoded by this decoder @@ -54,9 +56,10 @@ public: * with delete; * * @param stream the memory stream which should be decoded + * @param format the pixel format used to generate the surface * @return returns a new surface if the image could be decoded, otherwise 0 */ - virtual Surface *decodeImage(Common::SeekableReadStream &stream) = 0; + virtual Surface *decodeImage(Common::SeekableReadStream &stream, const PixelFormat &format) = 0; }; } // end of namespace Graphics diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index 89b666ce58..78b4545270 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -578,11 +578,11 @@ bool ThemeEngine::addBitmap(const Common::String &filename) { return true; // If not, try to load the bitmap via the ImageDecoder class. - surf = Graphics::ImageDecoder::loadFile(filename); + surf = Graphics::ImageDecoder::loadFile(filename, _overlayFormat); if (!surf && _themeArchive) { Common::SeekableReadStream *stream = _themeArchive->createReadStreamForMember(filename); if (stream) { - surf = Graphics::ImageDecoder::loadFile(*stream); + surf = Graphics::ImageDecoder::loadFile(*stream, _overlayFormat); delete stream; } } |