Richard Boegli's CnC_Generals_Zero_Hour Fork
WIP
This is documentation of Richard Boegil's Zero Hour Fork
Loading...
Searching...
No Matches
lzo1x_d.cpp
Go to the documentation of this file.
1
/*
2
** Command & Conquer Generals Zero Hour(tm)
3
** Copyright 2025 Electronic Arts Inc.
4
**
5
** This program is free software: you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation, either version 3 of the License, or
8
** (at your option) any later version.
9
**
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
/***********************************************************************************************
20
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21
***********************************************************************************************
22
* *
23
* Project Name : Command & Conquer *
24
* *
25
* $Archive:: /Commando/Library/LZO1X_D.CPP $*
26
* *
27
* $Author:: Greg_h $*
28
* *
29
* $Modtime:: 7/22/97 11:37a $*
30
* *
31
* $Revision:: 1 $*
32
* *
33
*---------------------------------------------------------------------------------------------*
34
* Functions: *
35
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
/* $Header: /Commando/Library/LZO1X_D.CPP 1 7/22/97 12:00p Greg_h $ */
38
/* lzo1x_d.c -- standalone LZO1X decompressor
39
40
This file is part of the LZO real-time data compression library.
41
42
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
43
44
The LZO library is free software; you can redistribute it and/or
45
modify it under the terms of the GNU Library General Public
46
License as published by the Free Software Foundation; either
47
version 2 of the License, or (at your option) any later version.
48
49
The LZO library is distributed in the hope that it will be useful,
50
but WITHOUT ANY WARRANTY; without even the implied warranty of
51
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
52
Library General Public License for more details.
53
54
You should have received a copy of the GNU Library General Public
55
License along with the LZO library; see the file COPYING.LIB.
56
If not, write to the Free Software Foundation, Inc.,
57
675 Mass Ave, Cambridge, MA 02139, USA.
58
59
Markus F.X.J. Oberhumer
60
markus.oberhumer@jk.uni-linz.ac.at
61
*/
62
63
#include "
always.h
"
64
#include "
lzo1x.h
"
65
#include <assert.h>
66
67
#if !defined(LZO1X) && !defined(LZO1Y)
68
# define LZO1X
69
#endif
70
71
#if 1
72
# define TEST_IP 1
73
#else
74
# define TEST_IP (ip < ip_end)
75
#endif
76
77
78
/***********************************************************************
79
// decompress a block of data.
80
************************************************************************/
81
82
int
lzo1x_decompress
(
const
lzo_byte
* in,
lzo_uint
in_len,
83
lzo_byte
* out,
lzo_uint
* out_len,
84
lzo_voidp
)
85
{
86
register
lzo_byte
*op;
87
register
const
lzo_byte
*ip;
88
register
lzo_uint
t;
89
register
const
lzo_byte
*m_pos;
90
const
lzo_byte
*
const
ip_end = in + in_len;
91
92
*out_len = 0;
93
94
op = out;
95
ip = in;
96
97
if
(*ip > 17) {
98
t = *ip++ - 17;
99
goto
first_literal_run;
100
}
101
102
for
(;;) {
103
// while (TEST_IP) {
104
t = *ip++;
105
if
(t >= 16)
106
goto
match;
107
/* a literal run */
108
if
(t == 0) {
109
t = 15;
110
while
(*ip == 0) {
111
t += 255, ip++;
112
}
113
t += *ip++;
114
}
115
/* copy literals */
116
*op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
117
first_literal_run:
118
do
*op++ = *ip++;
while
(--t > 0);
119
120
121
t = *ip++;
122
123
if
(t >= 16) {
124
goto
match;
125
}
126
#if defined(LZO1X)
127
m_pos = op - 1 - 0x800;
128
#elif defined(LZO1Y)
129
m_pos = op - 1 - 0x400;
130
#endif
131
m_pos -= t >> 2;
132
m_pos -= *ip++ << 2;
133
*op++ = *m_pos++;
134
*op++ = *m_pos++;
135
*op++ = *m_pos;
136
// *op++ = *m_pos++;
137
goto
match_done;
138
139
140
/* handle matches */
141
for
(;;) {
142
// while (TEST_IP) {
143
if
(t < 16) {
/* a M1 match */
144
m_pos = op - 1;
145
m_pos -= t >> 2;
146
m_pos -= *ip++ << 2;
147
*op++ = *m_pos++;
148
*op++ = *m_pos;
149
// *op++ = *m_pos++;
150
}
else
{
151
match:
152
if
(t >= 64) {
/* a M2 match */
153
m_pos = op - 1;
154
#if defined(LZO1X)
155
m_pos -= (t >> 2) & 7;
156
m_pos -= *ip++ << 3;
157
t = (t >> 5) - 1;
158
#elif defined(LZO1Y)
159
m_pos -= (t >> 2) & 3;
160
m_pos -= *ip++ << 2;
161
t = (t >> 4) - 3;
162
#endif
163
}
else
{
164
if
(t >= 32) {
/* a M3 match */
165
t &= 31;
166
if
(t == 0) {
167
t = 31;
168
while
(*ip == 0) {
169
t += 255, ip++;
170
}
171
t += *ip++;
172
}
173
m_pos = op - 1;
174
m_pos -= *ip++ >> 2;
175
m_pos -= *ip++ << 6;
176
}
else
{
/* a M4 match */
177
m_pos = op;
178
m_pos -= (t & 8) << 11;
179
t &= 7;
180
if
(t == 0) {
181
t = 7;
182
while
(*ip == 0) {
183
t += 255, ip++;
184
}
185
t += *ip++;
186
}
187
m_pos -= *ip++ >> 2;
188
m_pos -= *ip++ << 6;
189
if
(m_pos == op) {
190
goto
eof_found;
191
}
192
m_pos -= 0x4000;
193
}
194
}
195
*op++ = *m_pos++; *op++ = *m_pos++;
196
do
*op++ = *m_pos++;
while
(--t > 0);
197
}
198
199
match_done:
200
t = ip[-2] & 3;
201
if
(t == 0)
202
break
;
203
/* copy literals */
204
do
*op++ = *ip++;
while
(--t > 0);
205
t = *ip++;
206
}
207
}
208
209
/* ip == ip_end and no EOF code was found */
210
211
//Unreachable - ST 9/5/96 5:07PM
212
//*out_len = op - out;
213
//return (ip == ip_end ? LZO_E_EOF_NOT_FOUND : LZO_E_ERROR);
214
215
eof_found:
216
assert(t == 1);
217
*out_len = op - out;
218
return
(ip == ip_end ?
LZO_E_OK
:
LZO_E_ERROR
);
219
}
220
221
222
/*
223
vi:ts=4
224
*/
always.h
lzo1x.h
lzo1x_decompress
int lzo1x_decompress(const lzo_byte *in, lzo_uint in_len, lzo_byte *out, lzo_uint *out_len, lzo_voidp)
Definition
lzo1x_d.cpp:82
lzo_voidp
#define lzo_voidp
Definition
lzoconf.h:128
LZO_E_ERROR
#define LZO_E_ERROR
Definition
lzoconf.h:192
LZO_E_OK
#define LZO_E_OK
Definition
lzoconf.h:191
lzo_byte
#define lzo_byte
Definition
lzoconf.h:127
lzo_uint
unsigned int lzo_uint
Definition
lzoconf.h:99
Code
Libraries
Source
WWVegas
WWLib
lzo1x_d.cpp
Generated by
1.13.2