diff options
author | richiesams | 2013-07-08 14:03:37 -0500 |
---|---|---|
committer | richiesams | 2013-08-04 13:32:07 -0500 |
commit | 4c7db7f5de574833b360653e423d8240d7af8fa9 (patch) | |
tree | dc98e2463c02459951d2880711d0de69f4725e4a /engines | |
parent | 811ea394862a35faacd2e87c68ef57a501f67f3c (diff) | |
download | scummvm-rg350-4c7db7f5de574833b360653e423d8240d7af8fa9.tar.gz scummvm-rg350-4c7db7f5de574833b360653e423d8240d7af8fa9.tar.bz2 scummvm-rg350-4c7db7f5de574833b360653e423d8240d7af8fa9.zip |
ZVISION: renderImageToScreen: Check for TGZ first instead of TGA
TGA's aren't required to have a magic number in the header, but TGZ are.
Therefore it's easier to identify TGZ files.
Diffstat (limited to 'engines')
-rw-r--r-- | engines/zvision/image.cpp | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/engines/zvision/image.cpp b/engines/zvision/image.cpp index 1463401e0f..35ec9b3e2f 100644 --- a/engines/zvision/image.cpp +++ b/engines/zvision/image.cpp @@ -35,49 +35,49 @@ namespace ZVision { void ZVision::renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y) { Common::File file; - if (file.open(fileName)) { - // Read the magic number - // Some files are true TGA, while others are TGZ - char fileType[4]; - file.read(fileType, 4); - - // Check for true TGA files - if (fileType[0] == 'T' && fileType[1] == 'G' && fileType[2] == 'A' && fileType[3] == '\0') { - // Reset the cursor - file.seek(0); - - // Decode - Graphics::TGADecoder tga; - if (!tga.loadStream(file)) - error("Error while reading TGA image"); - file.close(); - - const Graphics::Surface *tgaSurface = tga.getSurface(); - - _system->copyRectToScreen(tgaSurface->pixels, tgaSurface->pitch, x, y, tgaSurface->w, tgaSurface->h); - - tga.destroy(); - } else { - // TGZ files have a header and then Bitmap data that is compressed with LZSS - uint32 decompressedSize = file.readSint32LE(); - uint32 width = file.readSint32LE(); - uint32 height = file.readSint32LE(); - - LzssReadStream stream(&file, false, decompressedSize); - byte *buffer = new byte[stream.currentSize()]; - stream.read(buffer, stream.currentSize()); - - //Graphics::PixelFormat format(16, 5, 6, 5, 0, 11, 5, 0, 0); - // Graphics::PixelFormat format(16, 5, 5, 5, 1, 11, 6, 1, 0); - - _system->copyRectToScreen(buffer, width * 2, x, y, width, height); - } - - - _needsScreenUpdate = true; - } else { + if (!file.open(fileName)) { error("Could not open file %s", fileName.c_str()); + return; } + + // Read the magic number + // Some files are true TGA, while others are TGZ + char fileType[4]; + file.read(fileType, 4); + + // Check for TGZ files + if (fileType[0] == 'T' && fileType[1] == 'G' && fileType[2] == 'Z' && fileType[3] == '\0') { + // TGZ files have a header and then Bitmap data that is compressed with LZSS + uint32 decompressedSize = file.readSint32LE(); + uint32 width = file.readSint32LE(); + uint32 height = file.readSint32LE(); + + LzssReadStream stream(&file, false, decompressedSize); + byte *buffer = new byte[stream.currentSize()]; + stream.read(buffer, stream.currentSize()); + + //Graphics::PixelFormat format(16, 5, 6, 5, 0, 11, 5, 0, 0); + // Graphics::PixelFormat format(16, 5, 5, 5, 1, 11, 6, 1, 0); + + _system->copyRectToScreen(buffer, width * 2, x, y, width, height); + } else { + // Reset the cursor + file.seek(0); + + // Decode + Graphics::TGADecoder tga; + if (!tga.loadStream(file)) + error("Error while reading TGA image"); + file.close(); + + const Graphics::Surface *tgaSurface = tga.getSurface(); + + _system->copyRectToScreen(tgaSurface->pixels, tgaSurface->pitch, x, y, tgaSurface->w, tgaSurface->h); + + tga.destroy(); + } + + _needsScreenUpdate = true; } } // End of namespace ZVision |