[Scummvm-cvs-logs] SF.net SVN: scummvm:[38733] scummvm/trunk/engines/sci
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Sat Feb 21 20:27:06 CET 2009
Revision: 38733
http://scummvm.svn.sourceforge.net/scummvm/?rev=38733&view=rev
Author: fingolfin
Date: 2009-02-21 19:27:06 +0000 (Sat, 21 Feb 2009)
Log Message:
-----------
SCI: Changed decompressors to take advantage of Common::ReadStream::readUint16LE; cleanup
Modified Paths:
--------------
scummvm/trunk/engines/sci/gfx/gfx_line.cpp
scummvm/trunk/engines/sci/include/sciresource.h
scummvm/trunk/engines/sci/scicore/decompress0.cpp
scummvm/trunk/engines/sci/scicore/decompress01.cpp
scummvm/trunk/engines/sci/scicore/decompress1.cpp
scummvm/trunk/engines/sci/scicore/decompress11.cpp
scummvm/trunk/engines/sci/tools.h
Modified: scummvm/trunk/engines/sci/gfx/gfx_line.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/gfx_line.cpp 2009-02-21 19:22:38 UTC (rev 38732)
+++ scummvm/trunk/engines/sci/gfx/gfx_line.cpp 2009-02-21 19:27:06 UTC (rev 38733)
@@ -53,7 +53,7 @@
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);
Modified: scummvm/trunk/engines/sci/include/sciresource.h
===================================================================
--- scummvm/trunk/engines/sci/include/sciresource.h 2009-02-21 19:22:38 UTC (rev 38732)
+++ scummvm/trunk/engines/sci/include/sciresource.h 2009-02-21 19:27:06 UTC (rev 38733)
@@ -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
Modified: scummvm/trunk/engines/sci/scicore/decompress0.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress0.cpp 2009-02-21 19:22:38 UTC (rev 38732)
+++ scummvm/trunk/engines/sci/scicore/decompress0.cpp 2009-02-21 19:27:06 UTC (rev 38733)
@@ -219,52 +219,39 @@
// 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.
Modified: scummvm/trunk/engines/sci/scicore/decompress01.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress01.cpp 2009-02-21 19:22:38 UTC (rev 38732)
+++ scummvm/trunk/engines/sci/scicore/decompress01.cpp 2009-02-21 19:27:06 UTC (rev 38733)
@@ -488,33 +488,26 @@
}
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?)
Modified: scummvm/trunk/engines/sci/scicore/decompress1.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress1.cpp 2009-02-21 19:22:38 UTC (rev 38732)
+++ scummvm/trunk/engines/sci/scicore/decompress1.cpp 2009-02-21 19:27:06 UTC (rev 38733)
@@ -267,50 +267,40 @@
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;
Modified: scummvm/trunk/engines/sci/scicore/decompress11.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress11.cpp 2009-02-21 19:22:38 UTC (rev 38732)
+++ scummvm/trunk/engines/sci/scicore/decompress11.cpp 2009-02-21 19:27:06 UTC (rev 38733)
@@ -38,37 +38,26 @@
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?)
Modified: scummvm/trunk/engines/sci/tools.h
===================================================================
--- scummvm/trunk/engines/sci/tools.h 2009-02-21 19:22:38 UTC (rev 38732)
+++ scummvm/trunk/engines/sci/tools.h 2009-02-21 19:27:06 UTC (rev 38733)
@@ -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 {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list