1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef MADS_COMPRESSION_H
24 #define MADS_COMPRESSION_H
25 
26 #include "common/memstream.h"
27 #include "common/stream.h"
28 
29 #include "mads/mads.h"
30 
31 namespace MADS {
32 
33 enum CompressionType { COMPRESS_NONE = 0, COMPRESS_FAB = 1 };
34 
35 struct MadsPackEntry {
36 public:
37 	CompressionType _type;
38 	byte _priority;
39 	uint32 _size;
40 	uint32 _compressedSize;
41 	byte *_data;
42 };
43 
44 class MadsPack {
45 private:
46 	MadsPackEntry *_items;
47 	int _count;
48 	int _dataOffset;
49 
50 	void initialize(Common::SeekableReadStream *stream);
51 public:
52 	static bool isCompressed(Common::SeekableReadStream *stream);
53 	MadsPack(Common::SeekableReadStream *stream);
54 	MadsPack(const Common::String &resourceName, MADSEngine *_vm);
55 	~MadsPack();
56 
getCount()57 	int getCount() const { return _count; }
getItem(int index)58 	MadsPackEntry &getItem(int index) const {
59 		assert(index < _count);
60 		return _items[index]; }
61 	MadsPackEntry &operator[](int index) const {
62 		assert(index < _count);
63 		return _items[index];
64 	}
getItemStream(int index)65 	Common::MemoryReadStream *getItemStream(int index) {
66 		assert(index < _count);
67 		return new Common::MemoryReadStream(_items[index]._data, _items[index]._size,
68 			DisposeAfterUse::NO);
69 	}
getDataOffset()70 	int getDataOffset() const { return _dataOffset; }
71 };
72 
73 class FabDecompressor {
74 private:
75 	int _bitsLeft;
76 	uint32 _bitBuffer;
77 	const byte *_srcData, *_srcP;
78 	int _srcSize;
79 
80 	int getBit();
81 public:
82 	void decompress(const byte *srcData, int srcSize, byte *destData, int destSize);
83 };
84 
85 } // End of namespace MADS
86 
87 #endif
88