ScummVM API documentation
decompressor.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SCI_RESOURCE_DECOMPRESSOR_H
23 #define SCI_RESOURCE_DECOMPRESSOR_H
24 
25 #include "common/scummsys.h"
26 
27 namespace Common {
28 class ReadStream;
29 }
30 
31 namespace Sci {
32 
33 enum ResourceCompression {
34  kCompUnknown = -1,
35  kCompNone = 0,
36  kCompLZW, // LZW compression used in SCI0
37  kCompHuffman, // Huffman compression used for vector pics
38  kCompLZW1, // LZW compression used in SCI01 and SCI1
39  kCompLZW1View, // LZW + view post-processing
40  kCompLZW1Pic, // LZW + pic post-processing
41  kCompDCL // SCI11
42 #ifdef ENABLE_SCI32
43 , kCompSTACpack // SCI32
44 #endif
45 };
46 
51 class Decompressor {
52 public:
53  Decompressor() :
54  _dwBits(0),
55  _nBits(0),
56  _szPacked(0),
57  _szUnpacked(0),
58  _dwRead(0),
59  _dwWrote(0),
60  _src(nullptr),
61  _dest(nullptr)
62  {}
63 
64  virtual ~Decompressor() {}
65 
71  virtual int unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked);
72 
73 protected:
81  virtual void init(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked);
82 
89  uint32 getBitsMSB(int n);
90 
97  uint32 getBitsLSB(int n);
98 
103  byte getByteMSB();
104  byte getByteLSB();
105 
106  void fetchBitsMSB();
107  void fetchBitsLSB();
108 
113  virtual void putByte(byte b);
114 
119  bool isFinished() {
120  return (_dwWrote == _szUnpacked) && (_dwRead >= _szPacked);
121  }
122 
123  uint32 _dwBits;
124  byte _nBits;
125  uint32 _szPacked;
126  uint32 _szUnpacked;
127  uint32 _dwRead;
128  uint32 _dwWrote;
129  Common::ReadStream *_src;
130  byte *_dest;
131 };
132 
137 public:
138  int unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) override;
139 
140 protected:
141  int16 getc2();
142 
143  byte *_nodes;
144 };
145 
150 public:
151  DecompressorLZW(ResourceCompression compression) : _compression(compression) {}
152  int unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) override;
153 
154 protected:
155  int unpackLZW(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked);
156 
157  // post-processing functions for view and pic resources
158  static void unpackView(byte *src, byte *dest);
159  static void unpackPic(byte *src, byte *dest, int unpackedSize);
160  static void decodeRLE(byte **rleData, byte **pixelData, byte *dest, int decodedSize);
161  static void skipRLE(byte **rleData, int decodedSize);
162 
163  ResourceCompression _compression;
164 };
165 
170 public:
171  int unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) override;
172 };
173 
174 #ifdef ENABLE_SCI32
175 
179 class DecompressorLZS : public Decompressor {
180 public:
181  int unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) override;
182 
183 protected:
184  int unpackLZS();
185  uint32 getCompLen();
186  void copyComp(int offs, uint32 clen);
187 };
188 
189 #endif
190 
191 } // End of namespace Sci
192 
193 #endif // SCI_RESOURCE_DECOMPRESSOR_H
uint32 _dwRead
number of bytes read from _src
Definition: decompressor.h:127
byte _nBits
number of unread bits in _dwBits
Definition: decompressor.h:124
uint32 _dwBits
bits buffer
Definition: decompressor.h:123
uint32 _dwWrote
number of bytes written to _dest
Definition: decompressor.h:128
Definition: decompressor.h:149
Definition: algorithm.h:29
Definition: console.h:28
bool isFinished()
Definition: decompressor.h:119
Definition: decompressor.h:51
uint32 _szPacked
size of the compressed data
Definition: decompressor.h:125
uint32 _szUnpacked
size of the decompressed data
Definition: decompressor.h:126
Definition: stream.h:385
Definition: decompressor.h:169
Definition: decompressor.h:136