From 87a9ba5f2f5b9c3cde675c238ce718147417df03 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 15 Mar 2015 16:52:55 -0400 Subject: SHERLOCK: Initial commit --- engines/sherlock/decompress.cpp | 82 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 engines/sherlock/decompress.cpp (limited to 'engines/sherlock/decompress.cpp') diff --git a/engines/sherlock/decompress.cpp b/engines/sherlock/decompress.cpp new file mode 100644 index 0000000000..61110be840 --- /dev/null +++ b/engines/sherlock/decompress.cpp @@ -0,0 +1,82 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "sherlock/decompress.h" + +namespace Sherlock { + +/** + * Decompresses an LZW compressed resource. If no outSize is specified, it will + * decompress the entire resource. If, however, an explicit size is specified, + * it will decompress only up to that many bytes from the stream starting at + * whatever position it was previously. + */ +Common::SeekableReadStream *decompressLZ(Common::SeekableReadStream &source, int32 outSize) { + if (outSize == -1) { + source.seek(5); + outSize = source.readSint32LE(); + } + + byte lzWindow[4096]; + uint16 lzWindowPos; + uint16 cmd; + + byte *outBuffer = new byte[outSize]; + byte *outBufferEnd = outBuffer + outSize; + Common::MemoryReadStream *outS = new Common::MemoryReadStream(outBuffer, outSize, DisposeAfterUse::YES); + + memset(lzWindow, 0xFF, 0xFEE); + lzWindowPos = 0xFEE; + cmd = 0; + + while (1) { + cmd >>= 1; + if (!(cmd & 0x100)) { + cmd = source.readByte() | 0xFF00; + } + if (cmd & 1) { + byte literal = source.readByte(); + *outBuffer++ = literal; + lzWindow[lzWindowPos] = literal; + lzWindowPos = (lzWindowPos + 1) & 0x0FFF; + } else { + int copyPos, copyLen; + copyPos = source.readByte(); + copyLen = source.readByte(); + copyPos = copyPos | ((copyLen & 0xF0) << 4); + copyLen = (copyLen & 0x0F) + 3; + while (copyLen--) { + byte literal = lzWindow[copyPos]; + copyPos = (copyPos + 1) & 0x0FFF; + *outBuffer++ = literal; + lzWindow[lzWindowPos] = literal; + lzWindowPos = (lzWindowPos + 1) & 0x0FFF; + } + } + if (outBuffer >= outBufferEnd) + break; + } + + return outS; +} + +} // namespace Sherlock -- cgit v1.2.3 From d9e93f8e015ce27a95090e854494c4b3f7d1c0d4 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 7 May 2015 19:33:44 +0200 Subject: SHERLOCK: some code formatting --- engines/sherlock/decompress.cpp | 78 ++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'engines/sherlock/decompress.cpp') diff --git a/engines/sherlock/decompress.cpp b/engines/sherlock/decompress.cpp index 61110be840..b319bc90c8 100644 --- a/engines/sherlock/decompress.cpp +++ b/engines/sherlock/decompress.cpp @@ -36,47 +36,47 @@ Common::SeekableReadStream *decompressLZ(Common::SeekableReadStream &source, int outSize = source.readSint32LE(); } - byte lzWindow[4096]; - uint16 lzWindowPos; - uint16 cmd; - - byte *outBuffer = new byte[outSize]; - byte *outBufferEnd = outBuffer + outSize; - Common::MemoryReadStream *outS = new Common::MemoryReadStream(outBuffer, outSize, DisposeAfterUse::YES); - - memset(lzWindow, 0xFF, 0xFEE); - lzWindowPos = 0xFEE; - cmd = 0; + byte lzWindow[4096]; + uint16 lzWindowPos; + uint16 cmd; - while (1) { - cmd >>= 1; - if (!(cmd & 0x100)) { - cmd = source.readByte() | 0xFF00; - } - if (cmd & 1) { - byte literal = source.readByte(); - *outBuffer++ = literal; - lzWindow[lzWindowPos] = literal; - lzWindowPos = (lzWindowPos + 1) & 0x0FFF; - } else { - int copyPos, copyLen; - copyPos = source.readByte(); - copyLen = source.readByte(); - copyPos = copyPos | ((copyLen & 0xF0) << 4); - copyLen = (copyLen & 0x0F) + 3; - while (copyLen--) { - byte literal = lzWindow[copyPos]; - copyPos = (copyPos + 1) & 0x0FFF; - *outBuffer++ = literal; - lzWindow[lzWindowPos] = literal; - lzWindowPos = (lzWindowPos + 1) & 0x0FFF; - } - } - if (outBuffer >= outBufferEnd) - break; - } + byte *outBuffer = new byte[outSize]; + byte *outBufferEnd = outBuffer + outSize; + Common::MemoryReadStream *outS = new Common::MemoryReadStream(outBuffer, outSize, DisposeAfterUse::YES); - return outS; + memset(lzWindow, 0xFF, 0xFEE); + lzWindowPos = 0xFEE; + cmd = 0; + + while (1) { + cmd >>= 1; + if (!(cmd & 0x100)) + cmd = source.readByte() | 0xFF00; + + if (cmd & 1) { + byte literal = source.readByte(); + *outBuffer++ = literal; + lzWindow[lzWindowPos] = literal; + lzWindowPos = (lzWindowPos + 1) & 0x0FFF; + } else { + int copyPos, copyLen; + copyPos = source.readByte(); + copyLen = source.readByte(); + copyPos = copyPos | ((copyLen & 0xF0) << 4); + copyLen = (copyLen & 0x0F) + 3; + while (copyLen--) { + byte literal = lzWindow[copyPos]; + copyPos = (copyPos + 1) & 0x0FFF; + *outBuffer++ = literal; + lzWindow[lzWindowPos] = literal; + lzWindowPos = (lzWindowPos + 1) & 0x0FFF; + } + } + if (outBuffer >= outBufferEnd) + break; + } + + return outS; } } // namespace Sherlock -- cgit v1.2.3 From 47bcb5358acddc3ef75f5a4af59ba43f06027490 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 9 May 2015 09:09:10 -0400 Subject: SHERLOCK: Cleanup fix for decompress --- engines/sherlock/decompress.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'engines/sherlock/decompress.cpp') diff --git a/engines/sherlock/decompress.cpp b/engines/sherlock/decompress.cpp index b319bc90c8..7c98b50543 100644 --- a/engines/sherlock/decompress.cpp +++ b/engines/sherlock/decompress.cpp @@ -48,7 +48,7 @@ Common::SeekableReadStream *decompressLZ(Common::SeekableReadStream &source, int lzWindowPos = 0xFEE; cmd = 0; - while (1) { + do { cmd >>= 1; if (!(cmd & 0x100)) cmd = source.readByte() | 0xFF00; @@ -72,9 +72,7 @@ Common::SeekableReadStream *decompressLZ(Common::SeekableReadStream &source, int lzWindowPos = (lzWindowPos + 1) & 0x0FFF; } } - if (outBuffer >= outBufferEnd) - break; - } + } while (outBuffer < outBufferEnd); return outS; } -- cgit v1.2.3 From 902b79116552b0605668f130e0695e4798ef87d5 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sat, 9 May 2015 18:04:13 +0200 Subject: SHERLOCK: Make copyright headers consistent --- engines/sherlock/decompress.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/sherlock/decompress.cpp') diff --git a/engines/sherlock/decompress.cpp b/engines/sherlock/decompress.cpp index 7c98b50543..fff9616c60 100644 --- a/engines/sherlock/decompress.cpp +++ b/engines/sherlock/decompress.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -- cgit v1.2.3 From 281d44706bfa2cb58b3de469d320f06f75a93c86 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 9 May 2015 15:53:18 -0400 Subject: SHERLOCK: Refine comment for decompressLZ --- engines/sherlock/decompress.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/sherlock/decompress.cpp') diff --git a/engines/sherlock/decompress.cpp b/engines/sherlock/decompress.cpp index fff9616c60..dfa573209f 100644 --- a/engines/sherlock/decompress.cpp +++ b/engines/sherlock/decompress.cpp @@ -27,8 +27,8 @@ namespace Sherlock { /** * Decompresses an LZW compressed resource. If no outSize is specified, it will * decompress the entire resource. If, however, an explicit size is specified, - * it will decompress only up to that many bytes from the stream starting at - * whatever position it was previously. + * then it means we're already within a resource, and only want to decompress + * part of it. */ Common::SeekableReadStream *decompressLZ(Common::SeekableReadStream &source, int32 outSize) { if (outSize == -1) { -- cgit v1.2.3 From 7a46c84c0d02ec3fb5aa9d607519af8fbcd2715e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 12 May 2015 22:02:59 -0400 Subject: SHERLOCK: Beginnings of Rose Tattoo engine --- engines/sherlock/decompress.cpp | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'engines/sherlock/decompress.cpp') diff --git a/engines/sherlock/decompress.cpp b/engines/sherlock/decompress.cpp index dfa573209f..8e02da3212 100644 --- a/engines/sherlock/decompress.cpp +++ b/engines/sherlock/decompress.cpp @@ -77,4 +77,52 @@ Common::SeekableReadStream *decompressLZ(Common::SeekableReadStream &source, int return outS; } + +/** + * Decompresses a Rose Tattoo resource + * +Common::SeekableReadStream *decompress32(Common::SeekableReadStream &source, int32 outSize) { + if (outSize == -1) { + outSize = source.readSint32LE(); + } + + byte lzWindow[8192]; + byte *outBuffer = new byte[outSize]; + byte *outBufferEnd = outBuffer + outSize; + Common::MemoryReadStream *outS = new Common::MemoryReadStream(outBuffer, outSize, DisposeAfterUse::YES); + + memset(lzWindow, 0xFF, 8192); + int lzWindowPos = 0xFEE; + int cmd = 0; + + do { + cmd >>= 1; + if (!(cmd & 0x100)) + cmd = source.readByte() | 0xFF00; + + if (cmd & 1) { + byte literal = source.readByte(); + *outBuffer++ = literal; + lzWindow[lzWindowPos] = literal; + lzWindowPos = (lzWindowPos + 1) & 0x0FFF; + } else { + int copyPos, copyLen; + copyPos = source.readByte(); + copyLen = source.readByte(); + copyPos = copyPos | ((copyLen & 0xF0) << 4); + copyLen = (copyLen & 0x0F) + 3; + while (copyLen--) { + byte literal = lzWindow[copyPos]; + copyPos = (copyPos + 1) & 0x0FFF; + *outBuffer++ = literal; + lzWindow[lzWindowPos] = literal; + lzWindowPos = (lzWindowPos + 1) & 0x0FFF; + } + } + } while (outBuffer < outBufferEnd); + + return outS; +} +*/ + } // namespace Sherlock -- cgit v1.2.3