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,
37  kCompHuffman,
38  kCompLZW1, // LZW-like compression used in SCI01 and SCI1
39  kCompLZW1View, // Comp3 + view Post-processing
40  kCompLZW1Pic, // Comp3 + pic Post-processing
41 #ifdef ENABLE_SCI32
42  kCompSTACpack, // ? Used in SCI32
43 #endif
44  kCompDCL
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 
66 
67  virtual int unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked);
68 
69 protected:
78  virtual void init(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked);
79 
86  uint32 getBitsMSB(int n);
87 
94  uint32 getBitsLSB(int n);
95 
100  byte getByteMSB();
101  byte getByteLSB();
102 
103  void fetchBitsMSB();
104  void fetchBitsLSB();
105 
111  virtual void putByte(byte b);
112 
117  bool isFinished() {
118  return (_dwWrote == _szUnpacked) && (_dwRead >= _szPacked);
119  }
120 
121  uint32 _dwBits;
122  byte _nBits;
123  uint32 _szPacked;
124  uint32 _szUnpacked;
125  uint32 _dwRead;
126  uint32 _dwWrote;
127  Common::ReadStream *_src;
128  byte *_dest;
129 };
130 
135 public:
136  int unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) override;
137 
138 protected:
139  int16 getc2();
140 
141  byte *_nodes;
142 };
143 
149 public:
150  DecompressorLZW(ResourceCompression compression) : _compression(compression) {}
151  int unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) override;
152 
153 protected:
154  int unpackLZW(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked);
155 
156  // functions to post-process view and pic resources
157  void reorderPic(byte *src, byte *dest, int dsize);
158  void reorderView(byte *src, byte *dest);
159  void decodeRLE(byte **rledata, byte **pixeldata, byte *outbuffer, int size);
160  int getRLEsize(byte *rledata, int dsize);
161  void buildCelHeaders(byte **seeker, byte **writer, int celindex, int *cc_lengths, int max);
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 
178 class DecompressorLZS : public Decompressor {
179 public:
180  int unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) override;
181 protected:
182  int unpackLZS();
183  uint32 getCompLen();
184  void copyComp(int offs, uint32 clen);
185 };
186 #endif
187 
188 } // End of namespace Sci
189 
190 #endif // SCI_RESOURCE_DECOMPRESSOR_H
uint32 _dwRead
number of bytes read from _src
Definition: decompressor.h:125
byte _nBits
number of unread bits in _dwBits
Definition: decompressor.h:122
uint32 _dwBits
bits buffer
Definition: decompressor.h:121
uint32 _dwWrote
number of bytes written to _dest
Definition: decompressor.h:126
Definition: decompressor.h:148
Definition: algorithm.h:29
Definition: console.h:28
bool isFinished()
Definition: decompressor.h:117
Definition: decompressor.h:51
uint32 _szPacked
size of the compressed data
Definition: decompressor.h:123
uint32 _szUnpacked
size of the decompressed data
Definition: decompressor.h:124
Definition: stream.h:385
Definition: decompressor.h:169
Definition: decompressor.h:134