aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/scicore
diff options
context:
space:
mode:
authorMax Horn2009-02-21 19:27:06 +0000
committerMax Horn2009-02-21 19:27:06 +0000
commit1bbde7be4ebcd2d61ee1f10a7bd49c6546837c8a (patch)
tree68984d01c594e0200961ede91250fdbdf3f13316 /engines/sci/scicore
parentd451c7794d0980524ed470bc8b0dbcd14d7e8e2b (diff)
downloadscummvm-rg350-1bbde7be4ebcd2d61ee1f10a7bd49c6546837c8a.tar.gz
scummvm-rg350-1bbde7be4ebcd2d61ee1f10a7bd49c6546837c8a.tar.bz2
scummvm-rg350-1bbde7be4ebcd2d61ee1f10a7bd49c6546837c8a.zip
SCI: Changed decompressors to take advantage of Common::ReadStream::readUint16LE; cleanup
svn-id: r38733
Diffstat (limited to 'engines/sci/scicore')
-rw-r--r--engines/sci/scicore/decompress0.cpp35
-rw-r--r--engines/sci/scicore/decompress01.cpp21
-rw-r--r--engines/sci/scicore/decompress1.cpp34
-rw-r--r--engines/sci/scicore/decompress11.cpp27
4 files changed, 38 insertions, 79 deletions
diff --git a/engines/sci/scicore/decompress0.cpp b/engines/sci/scicore/decompress0.cpp
index 4cf476713a..aa6dd0c286 100644
--- a/engines/sci/scicore/decompress0.cpp
+++ b/engines/sci/scicore/decompress0.cpp
@@ -219,52 +219,39 @@ int decrypt2(guint8* dest, guint8* src, int length, int complength) {
// Carl Muckenhoupt's decompression code ends here
int sci0_get_compression_method(Common::ReadStream &stream) {
- guint16 compressedLength;
guint16 compressionMethod;
- guint16 result_size;
- // Dummy variable
- if (stream.read(&result_size, 2) != 2)
+ stream.readUint16LE();
+ stream.readUint16LE();
+ stream.readUint16LE();
+ compressionMethod = stream.readUint16LE();
+ if (stream.err())
return SCI_ERROR_IO_ERROR;
- if ((stream.read(&compressedLength, 2) != 2) || (stream.read(&result_size, 2) != 2) || (stream.read(&compressionMethod, 2) != 2))
- return SCI_ERROR_IO_ERROR;
-
-#ifdef SCUMM_BIG_ENDIAN
- compressionMethod = GUINT16_SWAP_LE_BE_CONSTANT(compressionMethod);
-#endif
-
return compressionMethod;
}
int decompress0(resource_t *result, Common::ReadStream &stream, int sci_version) {
uint16 compressedLength;
uint16 compressionMethod;
- uint16 result_size;
uint8 *buffer;
- if (stream.read(&(result->id), 2) != 2)
+ result->id = stream.readUint16LE();
+ if (stream.err())
return SCI_ERROR_IO_ERROR;
-#ifdef SCUMM_BIG_ENDIAN
- result->id = GUINT16_SWAP_LE_BE_CONSTANT(result->id);
-#endif
result->number = result->id & 0x07ff;
result->type = result->id >> 11;
if ((result->number > sci_max_resource_nr[sci_version]) || (result->type > sci_invalid_resource))
return SCI_ERROR_DECOMPRESSION_INSANE;
- if ((stream.read(&compressedLength, 2) != 2) || (stream.read(&result_size, 2) != 2) || (stream.read(&compressionMethod, 2) != 2))
+ compressedLength = stream.readUint16LE();
+ result->size = stream.readUint16LE();
+ compressionMethod = stream.readUint16LE();
+ if (stream.err())
return SCI_ERROR_IO_ERROR;
-#ifdef SCUMM_BIG_ENDIAN
- compressedLength = GUINT16_SWAP_LE_BE_CONSTANT(compressedLength);
- result_size = GUINT16_SWAP_LE_BE_CONSTANT(result_size);
- compressionMethod = GUINT16_SWAP_LE_BE_CONSTANT(compressionMethod);
-#endif
- result->size = result_size;
-
if (result->size > SCI_MAX_RESOURCE_SIZE)
return SCI_ERROR_RESOURCE_TOO_BIG;
// With SCI0, this simply cannot happen.
diff --git a/engines/sci/scicore/decompress01.cpp b/engines/sci/scicore/decompress01.cpp
index 7b3a1d004c..b3fbf965d3 100644
--- a/engines/sci/scicore/decompress01.cpp
+++ b/engines/sci/scicore/decompress01.cpp
@@ -488,33 +488,26 @@ byte *view_reorder(byte *inbuffer, int dsize) {
}
int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version) {
- uint16 compressedLength, result_size;
+ uint16 compressedLength;
uint16 compressionMethod;
uint8 *buffer;
- if (stream.read(&(result->id), 2) != 2)
+ result->id = stream.readUint16LE();
+ if (stream.err())
return SCI_ERROR_IO_ERROR;
-#ifdef SCUMM_BIG_ENDIAN
- result->id = GUINT16_SWAP_LE_BE_CONSTANT(result->id);
-#endif
-
result->number = result->id & 0x07ff;
result->type = result->id >> 11;
if ((result->number > sci_max_resource_nr[sci_version] || (result->type > sci_invalid_resource)))
return SCI_ERROR_DECOMPRESSION_INSANE;
- if ((stream.read(&compressedLength, 2) != 2) || (stream.read(&result_size, 2) != 2) || (stream.read(&compressionMethod, 2) != 2))
+ compressedLength = stream.readUint16LE();
+ result->size = stream.readUint16LE();
+ compressionMethod = stream.readUint16LE();
+ if (stream.err())
return SCI_ERROR_IO_ERROR;
-#ifdef SCUMM_BIG_ENDIAN
- compressedLength = GUINT16_SWAP_LE_BE_CONSTANT(compressedLength);
- result_size = GUINT16_SWAP_LE_BE_CONSTANT(result_size);
- compressionMethod = GUINT16_SWAP_LE_BE_CONSTANT(compressionMethod);
-#endif
- result->size = result_size;
-
//if ((result->size < 0) || (compressedLength < 0))
// return SCI_ERROR_DECOMPRESSION_INSANE;
// This return will never happen in SCI0 or SCI1 (does it have any use?)
diff --git a/engines/sci/scicore/decompress1.cpp b/engines/sci/scicore/decompress1.cpp
index 7ee7715870..ab26033083 100644
--- a/engines/sci/scicore/decompress1.cpp
+++ b/engines/sci/scicore/decompress1.cpp
@@ -267,50 +267,40 @@ int decrypt3(guint8* dest, guint8* src, int length, int complength);
int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version) {
uint16 compressedLength;
- uint16 compressionMethod, result_size;
+ uint16 compressionMethod;
uint8 *buffer;
- uint8 tempid;
if (sci_version == SCI_VERSION_1_EARLY) {
- if (stream.read(&(result->id), 2) != 2)
+ result->id = stream.readUint16LE();
+ if (stream.err())
return SCI_ERROR_IO_ERROR;
-#ifdef SCUMM_BIG_ENDIAN
- result->id = GUINT16_SWAP_LE_BE_CONSTANT(result->id);
-#endif
-
result->number = result->id & 0x07ff;
result->type = result->id >> 11;
+ // FIXME: Shouldn't it be SCI_VERSION_1_EARLY instead of SCI_VERSION_1_LATE?
if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_LATE]) || (result->type > sci_invalid_resource))
return SCI_ERROR_DECOMPRESSION_INSANE;
} else {
- if (stream.read(&tempid, 1) != 1)
+ result->id = stream.readByte();
+ if (stream.err())
return SCI_ERROR_IO_ERROR;
- result->id = tempid;
-
result->type = result->id & 0x7f;
- if (stream.read(&(result->number), 2) != 2)
+ result->number = stream.readUint16LE();
+ if (stream.err())
return SCI_ERROR_IO_ERROR;
-#ifdef SCUMM_BIG_ENDIAN
- result->number = GUINT16_SWAP_LE_BE_CONSTANT(result->number);
-#endif
if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_LATE]) || (result->type > sci_invalid_resource))
return SCI_ERROR_DECOMPRESSION_INSANE;
}
- if ((stream.read(&compressedLength, 2) != 2) || (stream.read(&result_size, 2) != 2) || (stream.read(&compressionMethod, 2) != 2))
+ compressedLength = stream.readUint16LE();
+ result->size = stream.readUint16LE();
+ compressionMethod = stream.readUint16LE();
+ if (stream.err())
return SCI_ERROR_IO_ERROR;
-#ifdef SCUMM_BIG_ENDIAN
- compressedLength = GUINT16_SWAP_LE_BE_CONSTANT(compressedLength);
- result_size = GUINT16_SWAP_LE_BE_CONSTANT(result_size);
- compressionMethod = GUINT16_SWAP_LE_BE_CONSTANT(compressionMethod);
-#endif
- result->size = result_size;
-
if (result->size > SCI_MAX_RESOURCE_SIZE)
return SCI_ERROR_RESOURCE_TOO_BIG;
diff --git a/engines/sci/scicore/decompress11.cpp b/engines/sci/scicore/decompress11.cpp
index d2600b46e8..8f54fb6278 100644
--- a/engines/sci/scicore/decompress11.cpp
+++ b/engines/sci/scicore/decompress11.cpp
@@ -38,37 +38,26 @@ int decrypt4(guint8* dest, guint8* src, int length, int complength);
int decompress11(resource_t *result, Common::ReadStream &stream, int sci_version) {
guint16 compressedLength;
- guint16 compressionMethod, result_size;
+ guint16 compressionMethod;
guint8 *buffer;
- guint8 tempid;
DDEBUG("d1");
- if (stream.read(&tempid, 1) != 1)
+ result->id = stream.readByte();
+ if (stream.err())
return SCI_ERROR_IO_ERROR;
- result->id = tempid;
-
result->type = result->id & 0x7f;
- if (stream.read(&(result->number), 2) != 2)
- return SCI_ERROR_IO_ERROR;
-
-#ifdef SCUMM_BIG_ENDIAN
- result->number = GUINT16_SWAP_LE_BE_CONSTANT(result->number);
-#endif
if ((result->type > sci_invalid_resource))
return SCI_ERROR_DECOMPRESSION_INSANE;
- if ((stream.read(&compressedLength, 2) != 2) || (stream.read(&result_size, 2) != 2) || (stream.read(&compressionMethod, 2) != 2))
+ result->number = stream.readUint16LE();
+ compressedLength = stream.readUint16LE();
+ result->size = stream.readUint16LE();
+ compressionMethod = stream.readUint16LE();
+ if (stream.err())
return SCI_ERROR_IO_ERROR;
-#ifdef SCUMM_BIG_ENDIAN
- compressedLength = GUINT16_SWAP_LE_BE_CONSTANT(compressedLength);
- result_size = GUINT16_SWAP_LE_BE_CONSTANT(result_size);
- compressionMethod = GUINT16_SWAP_LE_BE_CONSTANT(compressionMethod);
-#endif
- result->size = result_size;
-
//if ((result->size < 0) || (compressedLength < 0))
// return SCI_ERROR_DECOMPRESSION_INSANE;
// This return will never happen in SCI0 or SCI1 (does it have any use?)