diff options
author | Max Horn | 2009-03-01 22:03:37 +0000 |
---|---|---|
committer | Max Horn | 2009-03-01 22:03:37 +0000 |
commit | 4f2f82adc2d9ce83407d2decf2fc2f8526d01b1c (patch) | |
tree | 0fa819669b272b690651125db9c0a3ad1d531795 /engines | |
parent | f509f65023d79e7f609a683c2614f9623552dcb7 (diff) | |
download | scummvm-rg350-4f2f82adc2d9ce83407d2decf2fc2f8526d01b1c.tar.gz scummvm-rg350-4f2f82adc2d9ce83407d2decf2fc2f8526d01b1c.tar.bz2 scummvm-rg350-4f2f82adc2d9ce83407d2decf2fc2f8526d01b1c.zip |
SCI: Unified some of the decompression funcs (they share so much code, would be nice to reduce the code duplication)
svn-id: r39057
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/scicore/decompress0.cpp | 2 | ||||
-rw-r--r-- | engines/sci/scicore/decompress01.cpp | 11 | ||||
-rw-r--r-- | engines/sci/scicore/decompress1.cpp | 14 | ||||
-rw-r--r-- | engines/sci/scicore/decompress11.cpp | 9 |
4 files changed, 17 insertions, 19 deletions
diff --git a/engines/sci/scicore/decompress0.cpp b/engines/sci/scicore/decompress0.cpp index 997f30ee87..2a715fd334 100644 --- a/engines/sci/scicore/decompress0.cpp +++ b/engines/sci/scicore/decompress0.cpp @@ -269,7 +269,7 @@ int decompress0(Resource *result, Common::ReadStream &stream, int sci_version) { return SCI_ERROR_EMPTY_OBJECT; } - buffer = (uint8*)sci_malloc(compressedLength); + buffer = (uint8 *)sci_malloc(compressedLength); result->data = (unsigned char *)sci_malloc(result->size); if (stream.read(buffer, compressedLength) != compressedLength) { diff --git a/engines/sci/scicore/decompress01.cpp b/engines/sci/scicore/decompress01.cpp index a78bf30686..13d8de1944 100644 --- a/engines/sci/scicore/decompress01.cpp +++ b/engines/sci/scicore/decompress01.cpp @@ -494,19 +494,20 @@ int decompress01(Resource *result, Common::ReadStream &stream, int sci_version) uint16 compressedLength; uint16 compressionMethod; uint8 *buffer; + uint8 type; result->id = stream.readUint16LE(); if (stream.err()) return SCI_ERROR_IO_ERROR; result->number = result->id & 0x07ff; - uint8 type = result->id >> 11; - - if ((result->number > sci_max_resource_nr[sci_version] || (type > kResourceTypeInvalid))) - return SCI_ERROR_DECOMPRESSION_INSANE; + type = result->id >> 11; result->type = (ResourceType)type; + if ((result->number > sci_max_resource_nr[sci_version]) || (type > kResourceTypeInvalid)) + return SCI_ERROR_DECOMPRESSION_INSANE; + compressedLength = stream.readUint16LE(); result->size = stream.readUint16LE(); compressionMethod = stream.readUint16LE(); @@ -548,7 +549,6 @@ int decompress01(Resource *result, Common::ReadStream &stream, int sci_version) #endif switch (compressionMethod) { - case 0: // no compression if (result->size != compressedLength) { free(result->data); @@ -622,6 +622,7 @@ int decompress01(Resource *result, Common::ReadStream &stream, int sci_version) } free(buffer); + return 0; } diff --git a/engines/sci/scicore/decompress1.cpp b/engines/sci/scicore/decompress1.cpp index cadd390aeb..fa0e0abdf1 100644 --- a/engines/sci/scicore/decompress1.cpp +++ b/engines/sci/scicore/decompress1.cpp @@ -261,6 +261,7 @@ int decompress1(Resource *result, Common::ReadStream &stream, int sci_version) { uint16 compressedLength; uint16 compressionMethod; uint8 *buffer; + uint16 type; if (sci_version == SCI_VERSION_1_EARLY) { result->id = stream.readUint16LE(); @@ -268,10 +269,7 @@ int decompress1(Resource *result, Common::ReadStream &stream, int sci_version) { return SCI_ERROR_IO_ERROR; result->number = result->id & 0x07ff; - uint16 type = result->id >> 11; - - if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_EARLY]) || (type > kResourceTypeInvalid)) - return SCI_ERROR_DECOMPRESSION_INSANE; + type = result->id >> 11; result->type = (ResourceType)type; } else { @@ -279,17 +277,17 @@ int decompress1(Resource *result, Common::ReadStream &stream, int sci_version) { if (stream.err()) return SCI_ERROR_IO_ERROR; - uint16 type = result->id & 0x7f; + type = result->id & 0x7f; result->number = stream.readUint16LE(); if (stream.err()) return SCI_ERROR_IO_ERROR; - if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_LATE]) || (type > kResourceTypeInvalid)) - return SCI_ERROR_DECOMPRESSION_INSANE; - result->type = (ResourceType)type; } + if ((result->number > sci_max_resource_nr[sci_version]) || (type > kResourceTypeInvalid)) + return SCI_ERROR_DECOMPRESSION_INSANE; + compressedLength = stream.readUint16LE(); result->size = stream.readUint16LE(); compressionMethod = stream.readUint16LE(); diff --git a/engines/sci/scicore/decompress11.cpp b/engines/sci/scicore/decompress11.cpp index cabbb5a50d..d1b7cd1f73 100644 --- a/engines/sci/scicore/decompress11.cpp +++ b/engines/sci/scicore/decompress11.cpp @@ -32,8 +32,6 @@ namespace Sci { -void decryptinit3(); -int decrypt3(uint8* dest, uint8* src, int length, int complength); int decrypt4(uint8* dest, uint8* src, int length, int complength); int decompress11(Resource *result, Common::ReadStream &stream, int sci_version) { @@ -48,6 +46,7 @@ int decompress11(Resource *result, Common::ReadStream &stream, int sci_version) uint16 type = result->id & 0x7f; if (type > kResourceTypeInvalid) return SCI_ERROR_DECOMPRESSION_INSANE; + result->type = (ResourceType)type; result->number = stream.readUint16LE(); @@ -72,8 +71,8 @@ int decompress11(Resource *result, Common::ReadStream &stream, int sci_version) return SCI_ERROR_EMPTY_OBJECT; } - buffer = (uint8*)sci_malloc(compressedLength); - result->data = (unsigned char*)sci_malloc(result->size); + buffer = (uint8 *)sci_malloc(compressedLength); + result->data = (unsigned char *)sci_malloc(result->size); if (stream.read(buffer, compressedLength) != compressedLength) { free(result->data); @@ -135,7 +134,7 @@ int decompress11(Resource *result, Common::ReadStream &stream, int sci_version) result->number, getResourceTypeSuffix(result->type), compressionMethod); free(result->data); - result->data = NULL; // So that we know that it didn't work + result->data = 0; // So that we know that it didn't work result->status = SCI_STATUS_NOMALLOC; free(buffer); return SCI_ERROR_UNKNOWN_COMPRESSION; |