mirror of
https://github.com/libretro/scummvm.git
synced 2025-05-13 09:36:21 +00:00
SCI: Changed decompressors to take advantage of Common::ReadStream::readUint16LE; cleanup
svn-id: r38733
This commit is contained in:
parent
d451c7794d
commit
1bbde7be4e
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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?)
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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?)
|
||||
|
@ -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 {
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user