diff options
author | Paweł Kołodziejski | 2009-02-21 12:16:35 +0000 |
---|---|---|
committer | Paweł Kołodziejski | 2009-02-21 12:16:35 +0000 |
commit | f069c04c60abf8616b258c9550f31b6b58ece787 (patch) | |
tree | e66002ab89ab1f9619d986f5ebf2c55f6920c5f9 /engines/sci/scicore | |
parent | 2784e08a90c1279e431374051ee5515010eabefd (diff) | |
download | scummvm-rg350-f069c04c60abf8616b258c9550f31b6b58ece787.tar.gz scummvm-rg350-f069c04c60abf8616b258c9550f31b6b58ece787.tar.bz2 scummvm-rg350-f069c04c60abf8616b258c9550f31b6b58ece787.zip |
formating
svn-id: r38688
Diffstat (limited to 'engines/sci/scicore')
-rw-r--r-- | engines/sci/scicore/aatree.cpp | 39 | ||||
-rw-r--r-- | engines/sci/scicore/console.cpp | 36 | ||||
-rw-r--r-- | engines/sci/scicore/decompress0.cpp | 123 | ||||
-rw-r--r-- | engines/sci/scicore/decompress01.cpp | 155 | ||||
-rw-r--r-- | engines/sci/scicore/decompress1.cpp | 96 | ||||
-rw-r--r-- | engines/sci/scicore/decompress11.cpp | 47 |
6 files changed, 208 insertions, 288 deletions
diff --git a/engines/sci/scicore/aatree.cpp b/engines/sci/scicore/aatree.cpp index 2ec239259c..80552f6580 100644 --- a/engines/sci/scicore/aatree.cpp +++ b/engines/sci/scicore/aatree.cpp @@ -35,13 +35,12 @@ struct aatree { void *key; }; -/* Sentinel node */ +// Sentinel node static aatree_t bottom = {&bottom, &bottom, 0, NULL}; -static void -skew(aatree_t **t) { +static void skew(aatree_t **t) { if ((*t)->left->level == (*t)->level) { - /* Rotate right */ + // Rotate right aatree_t *temp = *t; *t = (*t)->left; temp->left = (*t)->right; @@ -49,10 +48,9 @@ skew(aatree_t **t) { } } -static void -split(aatree_t **t) { +static void split(aatree_t **t) { if ((*t)->right->right->level == (*t)->level) { - /* Rotate left */ + // Rotate left aatree_t *temp = *t; *t = (*t)->right; temp->right = (*t)->left; @@ -61,12 +59,11 @@ split(aatree_t **t) { } } -static int -delete_node(void *x, aatree_t **t, aatree_t *deleted, int (*compar)(const void *, const void *)) { +static int delete_node(void *x, aatree_t **t, aatree_t *deleted, int (*compar)(const void *, const void *)) { int retval = -1; if (*t != &bottom) { - /* Search down the tree */ + // Search down the tree aatree_t **n; if (compar(x, (*t)->key) < 0) @@ -78,7 +75,7 @@ delete_node(void *x, aatree_t **t, aatree_t *deleted, int (*compar)(const void * retval = delete_node(x, n, deleted, compar); - /* At the bottom of the tree we remove the element (if it is present) */ + // At the bottom of the tree we remove the element (if it is present) if ((*n == &bottom) && (deleted != &bottom) && (compar(x, deleted->key) == 0)) { aatree_t *temp; deleted->key = (*t)->key; @@ -101,18 +98,16 @@ delete_node(void *x, aatree_t **t, aatree_t *deleted, int (*compar)(const void * return retval; } -aatree_t * -aatree_new() { +aatree_t *aatree_new() { return ⊥ } -int -aatree_insert(void *x, aatree_t **t, int (*compar)(const void *, const void *)) { +int aatree_insert(void *x, aatree_t **t, int (*compar)(const void *, const void *)) { int retval = -1; int c; if (*t == &bottom) { - *t = (aatree_t*)sci_malloc(sizeof(aatree_t)); + *t = (aatree_t *)sci_malloc(sizeof(aatree_t)); if (*t == NULL) return 1; @@ -136,13 +131,11 @@ aatree_insert(void *x, aatree_t **t, int (*compar)(const void *, const void *)) return retval; } -int -aatree_delete(void *x, aatree_t **t, int (*compar)(const void *, const void *)) { +int aatree_delete(void *x, aatree_t **t, int (*compar)(const void *, const void *)) { return delete_node(x, t, &bottom, compar); } -aatree_t * -aatree_walk(aatree_t *t, int direction) { +aatree_t *aatree_walk(aatree_t *t, int direction) { if ((direction == AATREE_WALK_LEFT) && (t->left != &bottom)) return t->left; @@ -152,13 +145,11 @@ aatree_walk(aatree_t *t, int direction) { return NULL; } -void * -aatree_get_data(aatree_t *t) { +void *aatree_get_data(aatree_t *t) { return t->key; } -void -aatree_free(aatree_t *t) { +void aatree_free(aatree_t *t) { if (t == &bottom) return; diff --git a/engines/sci/scicore/console.cpp b/engines/sci/scicore/console.cpp index 6cb2bf5b55..a276875bc2 100644 --- a/engines/sci/scicore/console.cpp +++ b/engines/sci/scicore/console.cpp @@ -39,17 +39,11 @@ FILE *con_file = NULL; static void(*_con_string_callback)(char*) = NULL; static void (*_con_pixmap_callback)(gfx_pixmap_t *) = NULL; - -/****************************************/ -/* sciprintf */ -/****************************************/ - - int sciprintf(const char *fmt, ...) { va_list argp; int bufsize = 256; int i; - char *buf = (char *)sci_malloc(bufsize); + char *buf = (char *)sci_malloc(bufsize); if (NULL == fmt) { error("console.c: sciprintf(): NULL passed for parameter fmt\n"); @@ -62,11 +56,10 @@ int sciprintf(const char *fmt, ...) { } va_start(argp, fmt); - while ((i = vsnprintf(buf, bufsize - 1, fmt, argp)) == -1 - || (i >= bufsize - 2)) { - /* while we're out of space... */ + while ((i = vsnprintf(buf, bufsize - 1, fmt, argp)) == -1 || (i >= bufsize - 2)) { + // while we're out of space... va_end(argp); - va_start(argp, fmt); /* reset argp */ + va_start(argp, fmt); // reset argp free(buf); buf = (char *)sci_malloc(bufsize <<= 1); @@ -78,7 +71,6 @@ int sciprintf(const char *fmt, ...) { if (con_file) fprintf(con_file, "%s", buf); - if (_con_string_callback) _con_string_callback(buf); else @@ -91,18 +83,15 @@ void con_set_string_callback(void(*callback)(char *)) { _con_string_callback = callback; } -void -con_set_pixmap_callback(void(*callback)(gfx_pixmap_t *)) { +void con_set_pixmap_callback(void(*callback)(gfx_pixmap_t *)) { _con_pixmap_callback = callback; } -int -con_can_handle_pixmaps(void) { +int con_can_handle_pixmaps() { return _con_pixmap_callback != NULL; } -int -con_insert_pixmap(gfx_pixmap_t *pixmap) { +int con_insert_pixmap(gfx_pixmap_t *pixmap) { if (_con_pixmap_callback) _con_pixmap_callback(pixmap); else @@ -110,9 +99,7 @@ con_insert_pixmap(gfx_pixmap_t *pixmap) { return 0; } - -void -open_console_file(char *filename) { +void open_console_file(char *filename) { if (con_file != NULL) fclose(con_file); @@ -127,18 +114,15 @@ open_console_file(char *filename) { if (NULL == con_file) error("console.c: open_console_file(): Could not open output file %s\n", filename); - } -void -close_console_file(void) { +void close_console_file() { if (con_file != NULL) { fclose(con_file); con_file = NULL; } } - -#endif /* SCI_CONSOLE */ +#endif // SCI_CONSOLE } // End of namespace Sci diff --git a/engines/sci/scicore/decompress0.cpp b/engines/sci/scicore/decompress0.cpp index c132edebd1..4768e033de 100644 --- a/engines/sci/scicore/decompress0.cpp +++ b/engines/sci/scicore/decompress0.cpp @@ -33,13 +33,11 @@ namespace Sci { -/* #define _SCI_DECOMPRESS_DEBUG */ +//#define _SCI_DECOMPRESS_DEBUG -/* 9-12 bit LZW encoding */ -int -decrypt1(guint8 *dest, guint8 *src, int length, int complength) -/* Doesn't do length checking yet */ -{ +// 9-12 bit LZW encoding +int decrypt1(guint8 *dest, guint8 *src, int length, int complength) { + // Doesn't do length checking yet /* Theory: Considering the input as a bit stream, we get a series of ** 9 bit elements in the beginning. Every one of them is a 'token' ** and either represents a literal (if < 0x100), or a link to a previous @@ -56,16 +54,16 @@ decrypt1(guint8 *dest, guint8 *src, int length, int complength) ** be faster than the recursive approach. */ - guint16 bitlen = 9; /* no. of bits to read (max. 12) */ + guint16 bitlen = 9; // no. of bits to read (max. 12) guint16 bitmask = 0x01ff; - guint16 bitctr = 0; /* current bit position */ - guint16 bytectr = 0; /* current byte position */ - guint16 token; /* The last received value */ - guint16 maxtoken = 0x200; /* The biggest token */ + guint16 bitctr = 0; // current bit position + guint16 bytectr = 0; // current byte position + guint16 token; // The last received value + guint16 maxtoken = 0x200; // The biggest token - guint16 tokenlist[4096]; /* pointers to dest[] */ - guint16 tokenlengthlist[4096]; /* char length of each token */ - guint16 tokenctr = 0x102; /* no. of registered tokens (starts here)*/ + guint16 tokenlist[4096]; // pointers to dest[] + guint16 tokenlengthlist[4096]; // char length of each token + guint16 tokenctr = 0x102; // no. of registered tokens (starts here) guint16 tokenlastlength = 0; @@ -88,14 +86,14 @@ decrypt1(guint8 *dest, guint8 *src, int length, int complength) bytectr++; } - if (token == 0x101) return 0; /* terminator */ - if (token == 0x100) { /* reset command */ + if (token == 0x101) + return 0; // terminator + if (token == 0x100) { // reset command maxtoken = 0x200; bitlen = 9; bitmask = 0x01ff; tokenctr = 0x0102; } else { - { int i; @@ -104,18 +102,16 @@ decrypt1(guint8 *dest, guint8 *src, int length, int complength) #ifdef _SCI_DECOMPRESS_DEBUG error("decrypt1: Bad token %x", token); #endif - /* Well this is really bad */ - /* May be it should throw something like SCI_ERROR_DECOMPRESSION_INSANE */ + // Well this is really bad + // May be it should throw something like SCI_ERROR_DECOMPRESSION_INSANE } else { tokenlastlength = tokenlengthlist[token] + 1; if (destctr + tokenlastlength > length) { #ifdef _SCI_DECOMPRESS_DEBUG - - /* For me this seems a normal situation, It's necessary to handle it*/ + // For me this seems a normal situation, It's necessary to handle it printf("decrypt1: Trying to write beyond the end of array(len=%d, destctr=%d, tok_len=%d)", length, destctr, tokenlastlength); #endif - i = 0; for (; destctr < length; destctr++) { dest[destctr++] = dest [tokenlist[token] + i]; @@ -144,30 +140,26 @@ decrypt1(guint8 *dest, guint8 *src, int length, int complength) bitmask <<= 1; bitmask |= 1; maxtoken <<= 1; - } else continue; /* no further tokens allowed */ + } else + continue; // no further tokens allowed } tokenlist[tokenctr] = destctr - tokenlastlength; tokenlengthlist[tokenctr++] = tokenlastlength; - } - } return 0; - } - -/* Huffman-style token encoding */ +// Huffman-style token encoding /***************************************************************************/ /* This code was taken from Carl Muckenhoupt's sde.c, with some minor */ /* modifications. */ /***************************************************************************/ -/* decrypt2 helper function */ -gint16 getc2(guint8 *node, guint8 *src, - guint16 *bytectr, guint16 *bitctr, int complength) { +// decrypt2 helper function +gint16 getc2(guint8 *node, guint8 *src, guint16 *bytectr, guint16 *bitctr, int complength) { guint16 next; while (node[1] != 0) { @@ -179,7 +171,7 @@ gint16 getc2(guint8 *node, guint8 *src, } if (value & 0x80) { - next = node[1] & 0x0f; /* low 4 bits */ + next = node[1] & 0x0f; // low 4 bits if (next == 0) { guint16 result = (src[*bytectr] << (*bitctr)); @@ -192,17 +184,17 @@ gint16 getc2(guint8 *node, guint8 *src, return (result | 0x100); } } else { - next = node[1] >> 4; /* high 4 bits */ + next = node[1] >> 4; // high 4 bits } node += next << 1; } + return getInt16(node); } -/* Huffman token decryptor */ -int decrypt2(guint8* dest, guint8* src, int length, int complength) -/* no complength checking atm */ -{ +// Huffman token decryptor +int decrypt2(guint8* dest, guint8* src, int length, int complength) { + // no complength checking atm */ guint8 numnodes, terminator; guint8 *nodes; gint16 c; @@ -213,9 +205,9 @@ int decrypt2(guint8* dest, guint8* src, int length, int complength) bytectr = 2 + (numnodes << 1); nodes = src + 2; - while (((c = getc2(nodes, src, &bytectr, &bitctr, complength)) - != (0x0100 | terminator)) && (c >= 0)) { - if (length-- == 0) return SCI_ERROR_DECOMPRESSION_OVERFLOW; + while (((c = getc2(nodes, src, &bytectr, &bitctr, complength)) != (0x0100 | terminator)) && (c >= 0)) { + if (length-- == 0) + return SCI_ERROR_DECOMPRESSION_OVERFLOW; *dest = (guint8)c; dest++; @@ -224,22 +216,19 @@ int decrypt2(guint8* dest, guint8* src, int length, int complength) return (c == -1) ? SCI_ERROR_DECOMPRESSION_OVERFLOW : 0; } -/***************************************************************************/ -/* Carl Muckenhoupt's decompression code ends here */ -/***************************************************************************/ + +// Carl Muckenhoupt's decompression code ends here int sci0_get_compression_method(Common::ReadStream &stream) { guint16 compressedLength; guint16 compressionMethod; guint16 result_size; - /* Dummy variable */ + // Dummy variable if (stream.read(&result_size, 2) != 2) return SCI_ERROR_IO_ERROR; - if ((stream.read(&compressedLength, 2) != 2) || - (stream.read(&result_size, 2) != 2) || - (stream.read(&compressionMethod, 2) != 2)) + if ((stream.read(&compressedLength, 2) != 2) || (stream.read(&result_size, 2) != 2) || (stream.read(&compressionMethod, 2) != 2)) return SCI_ERROR_IO_ERROR; #ifdef WORDS_BIGENDIAN @@ -249,7 +238,6 @@ int sci0_get_compression_method(Common::ReadStream &stream) { return compressionMethod; } - int decompress0(resource_t *result, Common::ReadStream &stream, int sci_version) { uint16 compressedLength; uint16 compressionMethod; @@ -268,9 +256,7 @@ int decompress0(resource_t *result, Common::ReadStream &stream, int sci_version) 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)) + if ((stream.read(&compressedLength, 2) != 2) || (stream.read(&result_size, 2) != 2) || (stream.read(&compressionMethod, 2) != 2)) return SCI_ERROR_IO_ERROR; #ifdef WORDS_BIGENDIAN @@ -282,18 +268,18 @@ int decompress0(resource_t *result, Common::ReadStream &stream, int sci_version) if (result->size > SCI_MAX_RESOURCE_SIZE) return SCI_ERROR_RESOURCE_TOO_BIG; - /* With SCI0, this simply cannot happen. */ + // With SCI0, this simply cannot happen. if (compressedLength > 4) compressedLength -= 4; - else { /* Object has size zero (e.g. view.000 in sq3) (does this really exist?) */ + else { // Object has size zero (e.g. view.000 in sq3) (does this really exist?) result->data = 0; result->status = SCI_STATUS_NOMALLOC; return SCI_ERROR_EMPTY_OBJECT; } buffer = (guint8*)sci_malloc(compressedLength); - result->data = (unsigned char*)sci_malloc(result->size); + result->data = (unsigned char *)sci_malloc(result->size); if (stream.read(buffer, compressedLength) != compressedLength) { free(result->data); @@ -303,18 +289,13 @@ int decompress0(resource_t *result, Common::ReadStream &stream, int sci_version) #ifdef _SCI_DECOMPRESS_DEBUG - error("Resource %s.%03hi encrypted with method %hi at %.2f%%" - " ratio\n", - sci_resource_types[result->type], result->number, compressionMethod, - (result->size == 0) ? -1.0 : - (100.0 * compressedLength / result->size)); - error(" compressedLength = 0x%hx, actualLength=0x%hx\n", - compressedLength, result->size); + error("Resource %s.%03hi encrypted with method %hi at %.2f%% ratio\n", sci_resource_types[result->type], + result->number, compressionMethod, (result->size == 0) ? -1.0 : (100.0 * compressedLength / result->size)); + error(" compressedLength = 0x%hx, actualLength=0x%hx\n", compressedLength, result->size); #endif switch (compressionMethod) { - - case 0: /* no compression */ + case 0: // no compression if (result->size != compressedLength) { free(result->data); result->data = NULL; @@ -326,10 +307,10 @@ int decompress0(resource_t *result, Common::ReadStream &stream, int sci_version) result->status = SCI_STATUS_ALLOCATED; break; - case 1: /* LZW compression */ + case 1: // LZW compression if (decrypt1(result->data, buffer, result->size, compressedLength)) { free(result->data); - result->data = 0; /* 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_DECOMPRESSION_OVERFLOW; @@ -337,10 +318,10 @@ int decompress0(resource_t *result, Common::ReadStream &stream, int sci_version) result->status = SCI_STATUS_ALLOCATED; break; - case 2: /* Some sort of Huffman encoding */ + case 2: // Some sort of Huffman encoding if (decrypt2(result->data, buffer, result->size, compressedLength)) { free(result->data); - result->data = 0; /* 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_DECOMPRESSION_OVERFLOW; @@ -349,17 +330,17 @@ int decompress0(resource_t *result, Common::ReadStream &stream, int sci_version) break; default: - error("Resource %s.%03hi: Compression method %hi not " - "supported", sci_resource_types[result->type], result->number, - compressionMethod); + error("Resource %s.%03hi: Compression method %hi not supported", sci_resource_types[result->type], + result->number, compressionMethod); free(result->data); - result->data = 0; /* 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; } free(buffer); + return 0; } diff --git a/engines/sci/scicore/decompress01.cpp b/engines/sci/scicore/decompress01.cpp index e6c4dcd9fa..6c22437d46 100644 --- a/engines/sci/scicore/decompress01.cpp +++ b/engines/sci/scicore/decompress01.cpp @@ -23,7 +23,7 @@ * */ -/* Reads data from a resource file and stores the result in memory */ +// Reads data from a resource file and stores the result in memory #include "common/util.h" #include "sci/include/sci_memory.h" @@ -31,12 +31,10 @@ namespace Sci { -/*************************************************************************** -* The following code was originally created by Carl Muckenhoupt for his -* SCI decoder. It has been ported to the FreeSCI environment by Sergey Lapin. -***************************************************************************/ +// The following code was originally created by Carl Muckenhoupt for his +// SCI decoder. It has been ported to the FreeSCI environment by Sergey Lapin. -/* TODO: Clean up, re-organize, improve speed-wise */ +// TODO: Clean up, re-organize, improve speed-wise */ struct tokenlist { guint8 data; @@ -49,17 +47,18 @@ static gint16 stakptr = 0; static guint16 s_numbits, s_bitstring, lastbits, decryptstart; static gint16 curtoken, endtoken; - uint32 gbits(int numbits, guint8 * data, int dlen); -void decryptinit3(void) { +void decryptinit3() { int i; + lastchar = lastbits = s_bitstring = stakptr = 0; s_numbits = 9; curtoken = 0x102; endtoken = 0x1ff; decryptstart = 0; gbits(0, 0, 0); + for (i = 0;i < 0x1004;i++) { tokens[i].next = 0; tokens[i].data = 0; @@ -69,23 +68,23 @@ void decryptinit3(void) { int decrypt3(guint8 *dest, guint8 *src, int length, int complength) { static gint16 token; while (length != 0) { - switch (decryptstart) { case 0: case 1: s_bitstring = gbits(s_numbits, src, complength); - if (s_bitstring == 0x101) { /* found end-of-data signal */ + if (s_bitstring == 0x101) { // found end-of-data signal decryptstart = 4; return 0; } - if (decryptstart == 0) { /* first char */ + if (decryptstart == 0) { // first char decryptstart = 1; lastbits = s_bitstring; *(dest++) = lastchar = (s_bitstring & 0xff); - if (--length != 0) continue; + if (--length != 0) + continue; return 0; } - if (s_bitstring == 0x100) { /* start-over signal */ + if (s_bitstring == 0x100) { // start-over signal s_numbits = 9; endtoken = 0x1ff; curtoken = 0x102; @@ -93,17 +92,17 @@ int decrypt3(guint8 *dest, guint8 *src, int length, int complength) { continue; } token = s_bitstring; - if (token >= curtoken) { /* index past current point */ + if (token >= curtoken) { // index past current point token = lastbits; stak[stakptr++] = lastchar; } - while ((token > 0xff) && (token < 0x1004)) { /* follow links back in data */ + while ((token > 0xff) && (token < 0x1004)) { // follow links back in data stak[stakptr++] = tokens[token].data; token = tokens[token].next; } lastchar = stak[stakptr++] = token & 0xff; case 2: - while (stakptr > 0) { /* put stack in buffer */ + while (stakptr > 0) { // put stack in buffer *(dest++) = stak[--stakptr]; length--; if (length == 0) { @@ -112,7 +111,7 @@ int decrypt3(guint8 *dest, guint8 *src, int length, int complength) { } } decryptstart = 1; - if (curtoken <= endtoken) { /* put token into record */ + if (curtoken <= endtoken) { // put token into record tokens[curtoken].data = lastchar; tokens[curtoken].next = lastbits; curtoken++; @@ -123,21 +122,25 @@ int decrypt3(guint8 *dest, guint8 *src, int length, int complength) { } } lastbits = s_bitstring; - continue; /* When are "break" and "continue" synonymous? */ + continue; // When are "break" and "continue" synonymous? case 4: return 0; } } - return 0; /* [DJ] shut up compiler warning */ + + return 0; } guint32 gbits(int numbits, guint8 * data, int dlen) { - int place; /* indicates location within byte */ + int place; // indicates location within byte guint32 bitstring; static guint32 whichbit = 0; int i; - if (numbits == 0) {whichbit = 0; return 0;} + if (numbits == 0) { + whichbit = 0; + return 0; + } place = whichbit >> 3; bitstring = 0; @@ -145,19 +148,17 @@ guint32 gbits(int numbits, guint8 * data, int dlen) { if (i + place < dlen) bitstring |= data[place+i] << (8 * (2 - i)); } - /* bitstring = data[place+2] | (long)(data[place+1])<<8 - | (long)(data[place])<<16;*/ + //bitstring = data[place + 2] | (long)(data[place + 1]) << 8 | (long)(data[place]) << 16; bitstring >>= 24 - (whichbit & 7) - numbits; bitstring &= (0xffffffff >> (32 - numbits)); - /* Okay, so this could be made faster with a table lookup. - It doesn't matter. It's fast enough as it is. */ + // Okay, so this could be made faster with a table lookup. + // It doesn't matter. It's fast enough as it is. whichbit += numbits; + return bitstring; } -/*************************************************************************** -* Carl Muckenhoupt's code ends here -***************************************************************************/ +// Carl Muckenhoupt's code ends here enum { PIC_OP_SET_COLOR = 0xf0, @@ -190,8 +191,7 @@ enum { #define CEL_HEADER_SIZE 7 #define EXTRA_MAGIC_SIZE 15 -static -void decode_rle(byte **rledata, byte **pixeldata, byte *outbuffer, int size) { +static void decode_rle(byte **rledata, byte **pixeldata, byte *outbuffer, int size) { int pos = 0; char nextbyte; byte *rd = *rledata; @@ -230,8 +230,7 @@ void decode_rle(byte **rledata, byte **pixeldata, byte *outbuffer, int size) { * * Yes, this is inefficient. */ -static -int rle_size(byte *rledata, int dsize) { +static int rle_size(byte *rledata, int dsize) { int pos = 0; char nextbyte; int size = 0; @@ -273,10 +272,10 @@ byte *pic_reorder(byte *inbuffer, int dsize) { *(writer++) = PIC_OP_OPX; *(writer++) = PIC_OPX_SET_PALETTE; - for (i = 0;i < 256;i++) /* Palette translation map */ + for (i = 0;i < 256;i++) // Palette translation map *(writer++) = i; - putInt16(writer, 0); /* Palette stamp */ + putInt16(writer, 0); // Palette stamp writer += 2; putInt16(writer, 0); writer += 2; @@ -291,11 +290,11 @@ byte *pic_reorder(byte *inbuffer, int dsize) { memcpy(viewdata, seeker, sizeof(viewdata)); seeker += sizeof(viewdata); - memcpy(writer, seeker, 4*256); /* Palette */ + memcpy(writer, seeker, 4 * 256); // Palette seeker += 4 * 256; writer += 4 * 256; - if (view_start != PAL_SIZE + 2) { /* +2 for the opcode */ + if (view_start != PAL_SIZE + 2) { // +2 for the opcode memcpy(writer, seeker, view_start - PAL_SIZE - 2); seeker += view_start - PAL_SIZE - 2; writer += view_start - PAL_SIZE - 2; @@ -307,7 +306,7 @@ byte *pic_reorder(byte *inbuffer, int dsize) { seeker += dsize - view_size - view_start - EXTRA_MAGIC_SIZE; } - cdata_start = cdata = (byte *) malloc(cdata_size); + cdata_start = cdata = (byte *)malloc(cdata_size); memcpy(cdata, seeker, cdata_size); seeker += cdata_size; @@ -329,13 +328,13 @@ byte *pic_reorder(byte *inbuffer, int dsize) { free(cdata_start); free(inbuffer); + return reorderBuffer; } #define VIEW_HEADER_COLORS_8BIT 0x80 -static -void build_cel_headers(byte **seeker, byte **writer, int celindex, int *cc_lengths, int max) { +static void build_cel_headers(byte **seeker, byte **writer, int celindex, int *cc_lengths, int max) { int c, w; for (c = 0;c < max;c++) { @@ -352,7 +351,7 @@ void build_cel_headers(byte **seeker, byte **writer, int celindex, int *cc_lengt *seeker += 2; *writer += 2; w = *((*seeker)++); - putInt16(*writer, w); /* Zero extension */ + putInt16(*writer, w); // Zero extension *writer += 2; *writer += cc_lengths[celindex]; @@ -360,8 +359,6 @@ void build_cel_headers(byte **seeker, byte **writer, int celindex, int *cc_lengt } } - - byte *view_reorder(byte *inbuffer, int dsize) { byte *cellengths; int loopheaders; @@ -372,7 +369,7 @@ byte *view_reorder(byte *inbuffer, int dsize) { int unknown; byte *seeker = inbuffer; char celcounts[100]; - byte *outbuffer = (byte *) malloc(dsize); + byte *outbuffer = (byte *)malloc(dsize); byte *writer = outbuffer; byte *lh_ptr; byte *rle_ptr, *pix_ptr; @@ -382,7 +379,7 @@ byte *view_reorder(byte *inbuffer, int dsize) { int *cc_lengths; byte **cc_pos; - /* Parse the main header */ + // Parse the main header cellengths = inbuffer + getUInt16(seeker) + 2; seeker += 2; loopheaders = *(seeker++); @@ -396,8 +393,8 @@ byte *view_reorder(byte *inbuffer, int dsize) { cel_total = getUInt16(seeker); seeker += 2; - cc_pos = (byte **) malloc(sizeof(byte *) * cel_total); - cc_lengths = (int *) malloc(sizeof(int) * cel_total); + cc_pos = (byte **)malloc(sizeof(byte *) * cel_total); + cc_lengths = (int *)malloc(sizeof(int) * cel_total); for (c = 0;c < cel_total;c++) cc_lengths[c] = getUInt16(cellengths + 2 * c); @@ -412,7 +409,7 @@ byte *view_reorder(byte *inbuffer, int dsize) { writer += 2; lh_ptr = writer; - writer += 2 * loopheaders; /* Make room for the loop offset table */ + writer += 2 * loopheaders; // Make room for the loop offset table pix_ptr = writer; @@ -426,7 +423,7 @@ byte *view_reorder(byte *inbuffer, int dsize) { w = 0; for (l = 0;l < loopheaders;l++) { - if (lh_mask & lb) { /* The loop is _not_ present */ + if (lh_mask & lb) { // The loop is _not_ present if (lh_last == -1) { error("Error: While reordering view: Loop not present, but can't re-use last loop"); lh_last = 0; @@ -442,13 +439,13 @@ byte *view_reorder(byte *inbuffer, int dsize) { putInt16(writer, 0); writer += 2; - /* Now, build the cel offset table */ + // Now, build the cel offset table chptr = (writer - outbuffer) + (2 * celcounts[w]); - for (c = 0;c < celcounts[w];c++) { + for (c = 0; c < celcounts[w]; c++) { putInt16(writer, chptr); writer += 2; - cc_pos[celindex+c] = outbuffer + chptr; + cc_pos[celindex + c] = outbuffer + chptr; chptr += 8 + getUInt16(cellengths + 2 * (celindex + c)); } @@ -466,7 +463,7 @@ byte *view_reorder(byte *inbuffer, int dsize) { return NULL; } - /* Figure out where the pixel data begins. */ + // Figure out where the pixel data begins. for (c = 0;c < cel_total;c++) pix_ptr += rle_size(pix_ptr, cc_lengths[c]); @@ -481,17 +478,16 @@ byte *view_reorder(byte *inbuffer, int dsize) { for (c = 0;c < 256;c++) *(writer++) = c; - seeker -= 4; /* The missing four. Don't ask why. */ - memcpy(writer, seeker, 4*256 + 4); + seeker -= 4; // The missing four. Don't ask why. + memcpy(writer, seeker, 4 * 256 + 4); free(cc_pos); free(cc_lengths); free(inbuffer); + return outbuffer; } - - int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version) { uint16 compressedLength, result_size; uint16 compressionMethod; @@ -510,9 +506,7 @@ int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version 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)) + if ((stream.read(&compressedLength, 2) != 2) || (stream.read(&result_size, 2) != 2) || (stream.read(&compressionMethod, 2) != 2)) return SCI_ERROR_IO_ERROR; #ifdef WORDS_BIGENDIAN @@ -522,23 +516,23 @@ int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version #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?) */ + //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?) if (result->size > SCI_MAX_RESOURCE_SIZE) return SCI_ERROR_RESOURCE_TOO_BIG; if (compressedLength > 4) compressedLength -= 4; - else { /* Object has size zero (e.g. view.000 in sq3) (does this really exist?) */ + else { // Object has size zero (e.g. view.000 in sq3) (does this really exist?) result->data = 0; result->status = SCI_STATUS_NOMALLOC; return SCI_ERROR_EMPTY_OBJECT; } - buffer = (guint8*)sci_malloc(compressedLength); - result->data = (unsigned char*)sci_malloc(result->size); + buffer = (guint8 *)sci_malloc(compressedLength); + result->data = (unsigned char *)sci_malloc(result->size); if (stream.read(buffer, compressedLength) != compressedLength) { free(result->data); @@ -548,18 +542,14 @@ int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version #ifdef _SCI_DECOMPRESS_DEBUG - error("Resource %s.%03hi encrypted with method SCI01/%hi at %.2f%%" - " ratio\n", - sci_resource_types[result->type], result->number, compressionMethod, - (result->size == 0) ? -1.0 : - (100.0 * compressedLength / result->size)); - error(" compressedLength = 0x%hx, actualLength=0x%hx\n", - compressedLength, result->size); + error("Resource %s.%03hi encrypted with method SCI01/%hi at %.2f%% ratio\n", sci_resource_types[result->type], + result->number, compressionMethod, (result->size == 0) ? -1.0 : (100.0 * compressedLength / result->size)); + error(" compressedLength = 0x%hx, actualLength=0x%hx\n", compressedLength, result->size); #endif switch (compressionMethod) { - case 0: /* no compression */ + case 0: // no compression if (result->size != compressedLength) { free(result->data); result->data = NULL; @@ -571,10 +561,10 @@ int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version result->status = SCI_STATUS_ALLOCATED; break; - case 1: /* Some huffman encoding */ + case 1: // Some huffman encoding if (decrypt2(result->data, buffer, result->size, compressedLength)) { free(result->data); - result->data = 0; /* 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_DECOMPRESSION_OVERFLOW; @@ -582,11 +572,11 @@ int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version result->status = SCI_STATUS_ALLOCATED; break; - case 2: /* ??? */ + case 2: // ??? decryptinit3(); if (decrypt3(result->data, buffer, result->size, compressedLength)) { free(result->data); - result->data = 0; /* 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_DECOMPRESSION_OVERFLOW; @@ -598,7 +588,7 @@ int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version decryptinit3(); if (decrypt3(result->data, buffer, result->size, compressedLength)) { free(result->data); - result->data = 0; /* 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_DECOMPRESSION_OVERFLOW; @@ -611,7 +601,7 @@ int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version decryptinit3(); if (decrypt3(result->data, buffer, result->size, compressedLength)) { free(result->data); - result->data = 0; /* 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_DECOMPRESSION_OVERFLOW; @@ -621,11 +611,10 @@ int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version break; default: - error("Resource %s.%03hi: Compression method SCI1/%hi not " - "supported", sci_resource_types[result->type], result->number, - compressionMethod); + error("Resource %s.%03hi: Compression method SCI1/%hi not supported", sci_resource_types[result->type], + result->number, compressionMethod); free(result->data); - result->data = 0; /* 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; diff --git a/engines/sci/scicore/decompress1.cpp b/engines/sci/scicore/decompress1.cpp index 306540c889..7d56545070 100644 --- a/engines/sci/scicore/decompress1.cpp +++ b/engines/sci/scicore/decompress1.cpp @@ -23,7 +23,7 @@ * */ -/* Reads data from a resource file and stores the result in memory */ +// Reads data from a resource file and stores the result in memory #include "common/util.h" #include "sci/include/sci_memory.h" @@ -31,9 +31,8 @@ namespace Sci { -/* DEFLATE-DCL -** Refer to the FreeSCI docs for a full description. -*/ +// DEFLATE-DCL +// Refer to the FreeSCI docs for a full description. #define HUFFMAN_LEAF 0x40000000 @@ -51,30 +50,28 @@ struct bit_read_struct { static int length_tree[] = { #include "treedef.1" - 0 /* We need something witout a comma at the end */ + 0 // We need something witout a comma at the end }; static int distance_tree[] = { #include "treedef.2" - 0 /* We need something witout a comma at the end */ + 0 // We need something witout a comma at the end }; static int ascii_tree[] = { #include "treedef.3" - 0 /* We need something witout a comma at the end */ + 0 // We need something witout a comma at the end }; #define CALLC(x) { if ((x) == -SCI_ERROR_DECOMPRESSION_OVERFLOW) return -SCI_ERROR_DECOMPRESSION_OVERFLOW; } -static inline int -getbits_msb_first(struct bit_read_struct *inp, int bits) { +static inline int getbits_msb_first(struct bit_read_struct *inp, int bits) { int morebytes = (bits + inp->bitpos - 1) >> 3; int result = 0; int i; if (inp->bytepos + morebytes >= inp->length) { - error("read out-of-bounds with bytepos %d + morebytes %d >= length %d\n", - inp->bytepos, morebytes, inp->length); + error("read out-of-bounds with bytepos %d + morebytes %d >= length %d\n", inp->bytepos, morebytes, inp->length); return -SCI_ERROR_DECOMPRESSION_OVERFLOW; } @@ -90,17 +87,15 @@ getbits_msb_first(struct bit_read_struct *inp, int bits) { return result; } -static int DEBUG_DCL_INFLATE = 0; /* FIXME: Make this a define eventually */ +static int DEBUG_DCL_INFLATE = 0; // FIXME: Make this a define eventually -static inline int -getbits(struct bit_read_struct *inp, int bits) { +static inline int getbits(struct bit_read_struct *inp, int bits) { int morebytes = (bits + inp->bitpos - 1) >> 3; int result = 0; int i; if (inp->bytepos + morebytes >= inp->length) { - error("read out-of-bounds with bytepos %d + morebytes %d >= length %d\n", - inp->bytepos, morebytes, inp->length); + error("read out-of-bounds with bytepos %d + morebytes %d >= length %d\n", inp->bytepos, morebytes, inp->length); return -SCI_ERROR_DECOMPRESSION_OVERFLOW; } @@ -119,8 +114,7 @@ getbits(struct bit_read_struct *inp, int bits) { return result; } -static int -huffman_lookup(struct bit_read_struct *inp, int *tree) { +static int huffman_lookup(struct bit_read_struct *inp, int *tree) { int pos = 0; int bit; @@ -142,8 +136,7 @@ huffman_lookup(struct bit_read_struct *inp, int *tree) { #define DCL_ASCII_MODE 1 -static int -decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) { +static int decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) { int mode, length_param, value, val_length, val_distance; int write_pos = 0; @@ -152,7 +145,7 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) { if (mode == DCL_ASCII_MODE) { warning("DCL-INFLATE: Warning: Decompressing ASCII mode (untested)"); - /* DEBUG_DCL_INFLATE = 1; */ + //DEBUG_DCL_INFLATE = 1; } else if (mode) { error("DCL-INFLATE: Error: Encountered mode %02x, expected 00 or 01\n", mode); return 1; @@ -160,6 +153,7 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) { if (DEBUG_DCL_INFLATE) { int i; + for (i = 0; i < reader->length; i++) { error("%02x ", reader->data[i]); if (!((i + 1) & 0x1f)) @@ -177,7 +171,7 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) { while (write_pos < length) { CALLC(value = getbits(reader, 1)); - if (value) { /* (length,distance) pair */ + if (value) { // (length,distance) pair CALLC(value = huffman_lookup(reader, length_tree)); if (value < 8) @@ -238,7 +232,7 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) { write_pos += copy_length; } - } else { /* Copy byte verbatim */ + } else { // Copy byte verbatim if (mode == DCL_ASCII_MODE) { CALLC(value = huffman_lookup(reader, ascii_tree)); } else { @@ -255,8 +249,7 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) { return 0; } -int -decrypt4(guint8* dest, guint8* src, int length, int complength) { +int decrypt4(guint8* dest, guint8* src, int length, int complength) { struct bit_read_struct reader; reader.length = complength; @@ -267,10 +260,7 @@ decrypt4(guint8* dest, guint8* src, int length, int complength) { return -decrypt4_hdyn(dest, length, &reader); } - - - -void decryptinit3(void); +void decryptinit3(); int decrypt3(guint8* dest, guint8* src, int length, int complength); int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version) { @@ -304,14 +294,12 @@ int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version) #ifdef WORDS_BIGENDIAN result->number = GUINT16_SWAP_LE_BE_CONSTANT(result->number); -#endif /* WORDS_BIGENDIAN */ +#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)) + if ((stream.read(&compressedLength, 2) != 2) || (stream.read(&result_size, 2) != 2) || (stream.read(&compressionMethod, 2) != 2)) return SCI_ERROR_IO_ERROR; #ifdef WORDS_BIGENDIAN @@ -326,14 +314,14 @@ int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version) if (compressedLength > 4) compressedLength -= 4; - else { /* Object has size zero (e.g. view.000 in sq3) (does this really exist?) */ + else { // Object has size zero (e.g. view.000 in sq3) (does this really exist?) result->data = 0; result->status = SCI_STATUS_NOMALLOC; return SCI_ERROR_EMPTY_OBJECT; } - buffer = (guint8*)sci_malloc(compressedLength); - result->data = (unsigned char*)sci_malloc(result->size); + buffer = (guint8 *)sci_malloc(compressedLength); + result->data = (unsigned char *)sci_malloc(result->size); if (stream.read(buffer, compressedLength) != compressedLength) { free(result->data); @@ -343,20 +331,14 @@ int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version) #ifdef _SCI_DECOMPRESS_DEBUG - error("Resource %i.%s encrypted with method SCI1%c/%hi at %.2f%%" - " ratio\n", - result->number, sci_resource_type_suffixes[result->type], - early ? 'e' : 'l', - compressionMethod, - (result->size == 0) ? -1.0 : - (100.0 * compressedLength / result->size)); - error(" compressedLength = 0x%hx, actualLength=0x%hx\n", - compressedLength, result->size); + error("Resource %i.%s encrypted with method SCI1%c/%hi at %.2f%% ratio\n", result->number, + sci_resource_type_suffixes[result->type], early ? 'e' : 'l', compressionMethod, + (result->size == 0) ? -1.0 : (100.0 * compressedLength / result->size)); + error(" compressedLength = 0x%hx, actualLength=0x%hx\n", compressedLength, result->size); #endif switch (compressionMethod) { - - case 0: /* no compression */ + case 0: // no compression if (result->size != compressedLength) { free(result->data); result->data = NULL; @@ -368,10 +350,10 @@ int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version) result->status = SCI_STATUS_ALLOCATED; break; - case 1: /* LZW */ + case 1: // LZW if (decrypt2(result->data, buffer, result->size, compressedLength)) { free(result->data); - result->data = 0; /* 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_DECOMPRESSION_OVERFLOW; @@ -379,11 +361,11 @@ int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version) result->status = SCI_STATUS_ALLOCATED; break; - case 2: /* ??? */ + case 2: // ??? decryptinit3(); if (decrypt3(result->data, buffer, result->size, compressedLength)) { free(result->data); - result->data = 0; /* 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_DECOMPRESSION_OVERFLOW; @@ -395,7 +377,7 @@ int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version) decryptinit3(); if (decrypt3(result->data, buffer, result->size, compressedLength)) { free(result->data); - result->data = 0; /* 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_DECOMPRESSION_OVERFLOW; @@ -408,7 +390,7 @@ int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version) decryptinit3(); if (decrypt3(result->data, buffer, result->size, compressedLength)) { free(result->data); - result->data = 0; /* 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_DECOMPRESSION_OVERFLOW; @@ -418,17 +400,17 @@ int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version) break; default: - error("Resource %s.%03hi: Compression method SCI1/%hi not " - "supported", sci_resource_types[result->type], result->number, - compressionMethod); + error("Resource %s.%03hi: Compression method SCI1/%hi not supported", sci_resource_types[result->type], + result->number, compressionMethod); free(result->data); - result->data = 0; /* 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; } free(buffer); + return 0; } diff --git a/engines/sci/scicore/decompress11.cpp b/engines/sci/scicore/decompress11.cpp index 701f4ea089..49a355d8bd 100644 --- a/engines/sci/scicore/decompress11.cpp +++ b/engines/sci/scicore/decompress11.cpp @@ -23,7 +23,7 @@ * */ -/* Reads data from a resource file and stores the result in memory */ +// Reads data from a resource file and stores the result in memory #include "common/util.h" #include "sci/include/sci_memory.h" @@ -33,7 +33,7 @@ namespace Sci { #define DDEBUG if (0) printf -void decryptinit3(void); +void decryptinit3(); int decrypt3(guint8* dest, guint8* src, int length, int complength); int decrypt4(guint8* dest, guint8* src, int length, int complength); @@ -56,13 +56,11 @@ int decompress11(resource_t *result, Common::ReadStream &stream, int sci_version #ifdef WORDS_BIGENDIAN result->number = GUINT16_SWAP_LE_BE_CONSTANT(result->number); -#endif /* WORDS_BIGENDIAN */ +#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)) + if ((stream.read(&compressedLength, 2) != 2) || (stream.read(&result_size, 2) != 2) || (stream.read(&compressionMethod, 2) != 2)) return SCI_ERROR_IO_ERROR; #ifdef WORDS_BIGENDIAN @@ -72,16 +70,16 @@ int decompress11(resource_t *result, Common::ReadStream &stream, int sci_version #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?) */ + //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?) if (result->size > SCI_MAX_RESOURCE_SIZE) return SCI_ERROR_RESOURCE_TOO_BIG; if (compressedLength > 0) compressedLength -= 0; - else { /* Object has size zero (e.g. view.000 in sq3) (does this really exist?) */ + else { // Object has size zero (e.g. view.000 in sq3) (does this really exist?) result->data = 0; result->status = SCI_STATUS_NOMALLOC; return SCI_ERROR_EMPTY_OBJECT; @@ -96,26 +94,21 @@ int decompress11(resource_t *result, Common::ReadStream &stream, int sci_version return SCI_ERROR_IO_ERROR; }; - if (!(compressedLength & 1)) { /* Align */ + if (!(compressedLength & 1)) { // Align stream.readByte(); } #ifdef _SCI_DECOMPRESS_DEBUG - error("Resource %i.%s encrypted with method SCI1.1/%hi at %.2f%%" - " ratio\n", - result->number, sci_resource_type_suffixes[result->type], - compressionMethod, - (result->size == 0) ? -1.0 : - (100.0 * compressedLength / result->size)); - error(" compressedLength = 0x%hx, actualLength=0x%hx\n", - compressedLength, result->size); + error("Resource %i.%s encrypted with method SCI1.1/%hi at %.2f%% ratio\n", result->number, + sci_resource_type_suffixes[result->type], compressionMethod, (result->size == 0) ? -1.0 : + (100.0 * compressedLength / result->size)); + error(" compressedLength = 0x%hx, actualLength=0x%hx\n", compressedLength, result->size); #endif DDEBUG("/%d[%d]", compressionMethod, result->size); switch (compressionMethod) { - - case 0: /* no compression */ + case 0: // no compression if (result->size != compressedLength) { free(result->data); result->data = NULL; @@ -132,7 +125,7 @@ int decompress11(resource_t *result, Common::ReadStream &stream, int sci_version case 20: if (decrypt4(result->data, buffer, result->size, compressedLength)) { free(result->data); - result->data = 0; /* 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_DECOMPRESSION_OVERFLOW; @@ -141,7 +134,7 @@ int decompress11(resource_t *result, Common::ReadStream &stream, int sci_version break; case 3: - case 4: /* NYI */ + case 4: // NYI error("Resource %d.%s: Warning: compression type #%d not yet implemented\n", result->number, sci_resource_type_suffixes[result->type], compressionMethod); free(result->data); @@ -150,17 +143,17 @@ int decompress11(resource_t *result, Common::ReadStream &stream, int sci_version break; default: - error("Resource %d.%s: Compression method SCI1/%hi not " - "supported", result->number, sci_resource_type_suffixes[result->type], - compressionMethod); + error("Resource %d.%s: Compression method SCI1/%hi not supported", result->number, + sci_resource_type_suffixes[result->type], compressionMethod); free(result->data); - result->data = NULL; /* So that we know that it didn't work */ + result->data = NULL; // So that we know that it didn't work result->status = SCI_STATUS_NOMALLOC; free(buffer); return SCI_ERROR_UNKNOWN_COMPRESSION; } free(buffer); + return 0; } |