mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-15 06:08:35 +00:00
Gave decompression methods more descriptive names. Some cleanup
svn-id: r39082
This commit is contained in:
parent
59e847dc2d
commit
f31990f897
@ -38,7 +38,7 @@ namespace Sci {
|
||||
//#define _SCI_DECOMPRESS_DEBUG
|
||||
|
||||
// 9-12 bit LZW encoding
|
||||
int decrypt1(uint8 *dest, uint8 *src, int length, int complength) {
|
||||
int unpackLZW(uint8 *dest, uint8 *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'
|
||||
@ -102,7 +102,7 @@ int decrypt1(uint8 *dest, uint8 *src, int length, int complength) {
|
||||
if (token > 0xff) {
|
||||
if (token >= tokenctr) {
|
||||
#ifdef _SCI_DECOMPRESS_DEBUG
|
||||
warning("decrypt1: Bad token %x", token);
|
||||
warning("unpackLZW: Bad token %x", token);
|
||||
#endif
|
||||
// Well this is really bad
|
||||
// May be it should throw something like SCI_ERROR_DECOMPRESSION_INSANE
|
||||
@ -111,7 +111,7 @@ int decrypt1(uint8 *dest, uint8 *src, int length, int complength) {
|
||||
if (destctr + tokenlastlength > length) {
|
||||
#ifdef _SCI_DECOMPRESS_DEBUG
|
||||
// For me this seems a normal situation, It's necessary to handle it
|
||||
warning("decrypt1: Trying to write beyond the end of array(len=%d, destctr=%d, tok_len=%d)",
|
||||
warning("unpackLZW: Trying to write beyond the end of array(len=%d, destctr=%d, tok_len=%d)",
|
||||
length, destctr, tokenlastlength);
|
||||
#endif
|
||||
i = 0;
|
||||
@ -128,7 +128,7 @@ int decrypt1(uint8 *dest, uint8 *src, int length, int complength) {
|
||||
tokenlastlength = 1;
|
||||
if (destctr >= length) {
|
||||
#ifdef _SCI_DECOMPRESS_DEBUG
|
||||
warning("decrypt1: Try to write single byte beyond end of array");
|
||||
warning("unpackLZW: Try to write single byte beyond end of array");
|
||||
#endif
|
||||
} else
|
||||
dest[destctr++] = (byte)token;
|
||||
@ -160,7 +160,7 @@ int decrypt1(uint8 *dest, uint8 *src, int length, int complength) {
|
||||
/* modifications. */
|
||||
/***************************************************************************/
|
||||
|
||||
// decrypt2 helper function
|
||||
// unpackHuffman helper function
|
||||
int16 getc2(uint8 *node, uint8 *src, uint16 *bytectr, uint16 *bitctr, int complength) {
|
||||
uint16 next;
|
||||
|
||||
@ -195,7 +195,7 @@ int16 getc2(uint8 *node, uint8 *src, uint16 *bytectr, uint16 *bitctr, int comple
|
||||
}
|
||||
|
||||
// Huffman token decryptor
|
||||
int decrypt2(uint8* dest, uint8* src, int length, int complength) {
|
||||
int unpackHuffman(uint8* dest, uint8* src, int length, int complength) {
|
||||
// no complength checking atm */
|
||||
uint8 numnodes, terminator;
|
||||
uint8 *nodes;
|
||||
@ -299,12 +299,12 @@ int decompress0(Resource *result, Common::ReadStream &stream, int sci_version) {
|
||||
break;
|
||||
|
||||
case 1: // LZW compression
|
||||
if (decrypt1(result->data, buffer, result->size, compressedLength))
|
||||
if (unpackLZW(result->data, buffer, result->size, compressedLength))
|
||||
overflow = true;
|
||||
break;
|
||||
|
||||
case 2: // Some sort of Huffman encoding
|
||||
if (decrypt2(result->data, buffer, result->size, compressedLength))
|
||||
if (unpackHuffman(result->data, buffer, result->size, compressedLength))
|
||||
overflow = true;
|
||||
break;
|
||||
|
||||
|
@ -559,7 +559,7 @@ int decompress01(Resource *result, Common::ReadStream &stream, int sci_version)
|
||||
break;
|
||||
|
||||
case 1: // Some huffman encoding
|
||||
if (decrypt2(result->data, buffer, result->size, compressedLength))
|
||||
if (unpackHuffman(result->data, buffer, result->size, compressedLength))
|
||||
overflow = true;
|
||||
break;
|
||||
|
||||
|
@ -137,7 +137,7 @@ static int 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 unpackDCL_hdyn(byte *dest, int length, struct bit_read_struct *reader) {
|
||||
int mode, length_param, value, val_length, val_distance;
|
||||
int write_pos = 0;
|
||||
|
||||
@ -243,7 +243,7 @@ static int decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int decrypt4(uint8* dest, uint8* src, int length, int complength) {
|
||||
int unpackDCL(uint8* dest, uint8* src, int length, int complength) {
|
||||
struct bit_read_struct reader;
|
||||
|
||||
reader.length = complength;
|
||||
@ -251,7 +251,7 @@ int decrypt4(uint8* dest, uint8* src, int length, int complength) {
|
||||
reader.bytepos = 0;
|
||||
reader.data = src;
|
||||
|
||||
return -decrypt4_hdyn(dest, length, &reader);
|
||||
return -unpackDCL_hdyn(dest, length, &reader);
|
||||
}
|
||||
|
||||
void decryptinit3();
|
||||
@ -340,7 +340,7 @@ int decompress1(Resource *result, Common::ReadStream &stream, int sci_version) {
|
||||
break;
|
||||
|
||||
case 1: // LZW
|
||||
if (decrypt2(result->data, buffer, result->size, compressedLength)) {
|
||||
if (unpackHuffman(result->data, buffer, result->size, compressedLength)) {
|
||||
free(result->data);
|
||||
result->data = 0; // So that we know that it didn't work
|
||||
result->status = SCI_STATUS_NOMALLOC;
|
||||
@ -351,30 +351,7 @@ int decompress1(Resource *result, Common::ReadStream &stream, int sci_version) {
|
||||
break;
|
||||
|
||||
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->status = SCI_STATUS_NOMALLOC;
|
||||
free(buffer);
|
||||
return SCI_ERROR_DECOMPRESSION_OVERFLOW;
|
||||
}
|
||||
result->status = SCI_STATUS_ALLOCATED;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
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->status = SCI_STATUS_NOMALLOC;
|
||||
free(buffer);
|
||||
return SCI_ERROR_DECOMPRESSION_OVERFLOW;
|
||||
}
|
||||
result->data = view_reorder(result->data, result->size);
|
||||
result->status = SCI_STATUS_ALLOCATED;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
decryptinit3();
|
||||
if (decrypt3(result->data, buffer, result->size, compressedLength)) {
|
||||
@ -384,7 +361,11 @@ int decompress1(Resource *result, Common::ReadStream &stream, int sci_version) {
|
||||
free(buffer);
|
||||
return SCI_ERROR_DECOMPRESSION_OVERFLOW;
|
||||
}
|
||||
result->data = pic_reorder(result->data, result->size);
|
||||
|
||||
if (compressionMethod == 3)
|
||||
result->data = view_reorder(result->data, result->size);
|
||||
if (compressionMethod == 4)
|
||||
result->data = pic_reorder(result->data, result->size);
|
||||
result->status = SCI_STATUS_ALLOCATED;
|
||||
break;
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
namespace Sci {
|
||||
|
||||
int decrypt4(uint8* dest, uint8* src, int length, int complength);
|
||||
int unpackDCL(uint8* dest, uint8* src, int length, int complength);
|
||||
|
||||
int decompress11(Resource *result, Common::ReadStream &stream, int sci_version) {
|
||||
uint16 compressedLength;
|
||||
@ -110,7 +110,7 @@ int decompress11(Resource *result, Common::ReadStream &stream, int sci_version)
|
||||
case 18:
|
||||
case 19:
|
||||
case 20:
|
||||
if (decrypt4(result->data, buffer, result->size, compressedLength)) {
|
||||
if (unpackDCL(result->data, buffer, result->size, compressedLength)) {
|
||||
free(result->data);
|
||||
result->data = 0; // So that we know that it didn't work
|
||||
result->status = SCI_STATUS_NOMALLOC;
|
||||
|
@ -412,11 +412,11 @@ protected:
|
||||
** encountered.
|
||||
*/
|
||||
|
||||
int decrypt2(uint8* dest, uint8* src, int length, int complength);
|
||||
int unpackHuffman(uint8* dest, uint8* src, int length, int complength);
|
||||
/* Huffman token decryptor - defined in decompress0.c and used in decompress01.c
|
||||
*/
|
||||
|
||||
int decrypt4(uint8* dest, uint8* src, int length, int complength);
|
||||
int unpackDCL(uint8* dest, uint8* src, int length, int complength);
|
||||
/* DCL inflate- implemented in decompress1.c
|
||||
*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user