aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-02-21 19:27:06 +0000
committerMax Horn2009-02-21 19:27:06 +0000
commit1bbde7be4ebcd2d61ee1f10a7bd49c6546837c8a (patch)
tree68984d01c594e0200961ede91250fdbdf3f13316
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
-rw-r--r--engines/sci/gfx/gfx_line.cpp2
-rw-r--r--engines/sci/include/sciresource.h2
-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
-rw-r--r--engines/sci/tools.h23
7 files changed, 40 insertions, 104 deletions
diff --git a/engines/sci/gfx/gfx_line.cpp b/engines/sci/gfx/gfx_line.cpp
index 84c4e78d04..579d622080 100644
--- a/engines/sci/gfx/gfx_line.cpp
+++ b/engines/sci/gfx/gfx_line.cpp
@@ -53,7 +53,7 @@ static inline void DRAWLINE_FUNC(byte *buffer, int linewidth, Common::Point star
finalx = end.x;
finaly = end.y;
#ifdef SCUMM_BIG_ENDIAN
- color = GUINT32_SWAP_LE_BE_CONSTANT(color);
+ color = SWAP_BYTES_32(color);
#endif
dx = abs(dx);
dy = abs(dy);
diff --git a/engines/sci/include/sciresource.h b/engines/sci/include/sciresource.h
index 74b6d33a2b..8d885d9d9b 100644
--- a/engines/sci/include/sciresource.h
+++ b/engines/sci/include/sciresource.h
@@ -37,8 +37,8 @@
namespace Sci {
+/** The maximum allowed size for a compressed or decompressed resource */
#define SCI_MAX_RESOURCE_SIZE 0x0400000
-/* The maximum allowed size for a compressed or decompressed resource */
/*** RESOURCE STATUS TYPES ***/
#define SCI_STATUS_NOMALLOC 0
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?)
diff --git a/engines/sci/tools.h b/engines/sci/tools.h
index 7f007b5ea3..00ad0da3eb 100644
--- a/engines/sci/tools.h
+++ b/engines/sci/tools.h
@@ -76,35 +76,12 @@
#endif
-#define GUINT16_SWAP_LE_BE_CONSTANT(val) ((((val) & 0x00ff) << 8) | (((val) & 0xff00) >> 8))
-
-#define GUINT32_SWAP_LE_BE_CONSTANT(val) ( \
- (((val) & 0xff000000) >> 24) \
- | (((val) & 0x00ff0000) >> 8) \
- | (((val) & 0x0000ff00) << 8) \
- | (((val) & 0x000000ff) << 24))
-
-#define SCI_MAX_RESOURCE_SIZE 0x0400000
-/* The maximum allowed size for a compressed or decompressed resource */
-
-
-
#ifdef WIN32
# define FO_BINARY "b"
#else
# define FO_BINARY ""
#endif
-#ifdef WIN32
-# define FO_TEXT "t"
-#else
-# define FO_TEXT ""
-#endif
-
-#ifndef O_BINARY
-# define O_BINARY 0
-#endif
-
namespace Sci {