ScummVM API documentation
redreader.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 MADE_REDREADER_H
23#define MADE_REDREADER_H
24
25#include "common/scummsys.h"
26
27namespace Common {
28class SeekableReadStream;
29class File;
30}
31
32namespace Made {
33
34class RedReader {
35public:
36 Common::SeekableReadStream *load(const char *redFilename, const char *filename);
37 static Common::SeekableReadStream *loadFromRed(const char *redFilename, const char *filename);
38private:
39 struct FileEntry {
40 uint32 compSize, origSize;
41 };
42 bool seekFile(Common::File &fd, FileEntry &fileEntry, const char *filename);
43};
44
45const uint BITBUFSIZ = 16;
46const uint DICBIT = 13;
47const uint DICSIZ = 1 << DICBIT;
48const uint MATCHBIT = 8;
49const uint MAXMATCH = 256;
50const uint THRESHOLD = 3;
51const uint NC = 255 + MAXMATCH + 2 - THRESHOLD;
52const uint CBIT = 9;
53const uint CODE_BIT = 16;
54const uint NP = DICBIT + 1;
55const int NT = CODE_BIT + 3;
56const uint PBIT = 4;
57const uint TBIT = 5;
58const uint NPT = NT;
59
61public:
64 int decompress(Common::SeekableReadStream &source, byte *dest, uint32 compSize, uint32 origSize);
65private:
67 uint32 _compSize, _blockPos;
68
69 uint16 _bitbuf;
70 uint _subbitbuf;
71 int _bitcount;
72 uint16 _left[2 * NC - 1], _right[2 * NC - 1];
73 byte _c_len[NC], _pt_len[NPT];
74 uint _blocksize;
75 uint16 _c_table[4096], _pt_table[256];
76 int tree_n, heapsize;
77 short heap[NC + 1];
78 uint16 *freq, *sortptr, len_cnt[17];
79 byte *len_table;
80
81 int decode_i, decode_j;
82 int count_len_depth;
83
84 byte readByte();
85
86 void fillbuf(int count);
87 uint getbits(int count);
88 void init_getbits();
89 void decode_start();
90 void decode(uint count, byte text[]);
91 void huf_decode_start();
92 unsigned int decode_c();
93 unsigned int decode_p();
94 void read_pt_len(int nn, int nbit, int i_special);
95 void read_c_len();
96 void count_len(int i);
97 void make_len(int root);
98 void downheap(int i);
99 void make_code(int n, byte len[], uint16 code[]);
100 void make_table(uint nchar, byte bitlen[], uint tablebits, uint16 table[]);
101 int make_tree(int nparm, uint16 freqparm[], byte lenparm[], uint16 codeparm[]);
102
103};
104
105} // End of namespace Made
106
107#endif /* MADE_H */
Definition: file.h:47
Definition: stream.h:745
Definition: redreader.h:60
Definition: redreader.h:34
Definition: algorithm.h:29
Definition: console.h:27