ScummVM API documentation
u6_lzw.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 NUVIE_FILES_U6_LZW_H
23 #define NUVIE_FILES_U6_LZW_H
24 
25 #include "ultima/shared/std/string.h"
26 
27 namespace Ultima {
28 namespace Nuvie {
29 
30 class NuvieIOFileRead;
31 
32 // LZW Stack
33 
34 #define STACK_SIZE 10000
35 
36 class U6LzwStack {
37 protected:
38  unsigned char stack[STACK_SIZE];
39  int contains;
40 
41 public:
42  U6LzwStack();
43 
44  void reset(void);
45  bool is_empty(void);
46  bool is_full(void);
47  void push(unsigned char element);
48  unsigned char pop(void);
49  unsigned char gettop(void);
50 };
51 
52 // LZW dictionary
53 
54 #define DICT_SIZE 10000
55 
56 typedef struct {
57  unsigned char root;
58  int codeword;
59  int contains;
60 } dict_entry;
61 
62 class U6LzwDict {
63  dict_entry dict[DICT_SIZE];
64  int contains;
65 
66 public:
67 
68  U6LzwDict();
69 
70  void reset(void);
71  void add(unsigned char root, int codeword);
72  unsigned char get_root(int codeword) const;
73  int get_codeword(int codeword) const;
74 };
75 
76 class U6Lzw {
77  U6LzwStack *stack;
78  U6LzwDict *dict;
79  const char *errstr; // error string
80 public:
81 
82  U6Lzw(void);
83  ~U6Lzw(void);
84 
85  unsigned char *decompress_buffer(unsigned char *source, uint32 source_length, uint32 &destination_length);
86  bool decompress_buffer(unsigned char *source, uint32 source_length, unsigned char *destination, uint32 destination_length);
87  unsigned char *decompress_file(const Common::Path &filename, uint32 &destination_length);
88  unsigned char *compress_buffer(unsigned char *src, uint32 src_len,
89  uint32 &dest_len);
90  const char *strerror() const {
91  return errstr; // get error string
92  }
93 protected:
94 
95  bool is_valid_lzw_file(NuvieIOFileRead *input_file);
96  bool is_valid_lzw_buffer(unsigned char *buf, uint32 length);
97 
98  long get_uncompressed_file_size(NuvieIOFileRead *input_file);
99  long get_uncompressed_buffer_size(unsigned char *buf, uint32 length);
100 
101  int get_next_codeword(long *bits_read, unsigned char *source,
102  int codeword_size);
103  void output_root(unsigned char root, unsigned char *destination,
104  long *position);
105  void get_string(int codeword);
106 };
107 
108 } // End of namespace Nuvie
109 } // End of namespace Ultima
110 
111 #endif
Definition: u6_lzw.h:62
Definition: path.h:52
Definition: u6_lzw.h:56
Definition: u6_lzw.h:36
Definition: u6_lzw.h:76
Definition: detection.h:27
Definition: nuvie_io_file.h:44