lzma1 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/lzma.js +2413 -2148
- package/lib/esm/lzma.js +2398 -2148
- package/package.json +9 -10
- package/lib/esm/lzma.d.ts +0 -61
- /package/lib/{cjs/lzma.d.ts → lzma.d.ts} +0 -0
package/lib/cjs/lzma.js
CHANGED
|
@@ -1,2464 +1,2729 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var lzma_exports = {};
|
|
20
|
+
__export(lzma_exports, {
|
|
21
|
+
compress: () => compress,
|
|
22
|
+
decompress: () => decompress
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(lzma_exports);
|
|
4
25
|
const MAX_UINT32 = 4294967296;
|
|
5
26
|
const MAX_INT32 = 2147483647;
|
|
6
27
|
const MIN_INT32 = -2147483648;
|
|
7
|
-
const MAX_COMPRESSION_SIZE =
|
|
28
|
+
const MAX_COMPRESSION_SIZE = 9223372036854776e3;
|
|
8
29
|
const N1_longLit = [4294967295, -MAX_UINT32];
|
|
9
|
-
const MIN_VALUE = [0, -
|
|
30
|
+
const MIN_VALUE = [0, -9223372036854776e3];
|
|
10
31
|
const P0_longLit = [0, 0];
|
|
11
32
|
const P1_longLit = [1, 0];
|
|
12
|
-
/**
|
|
13
|
-
* This is MUCH faster than "new Array(len)" in newer versions of v8
|
|
14
|
-
* (starting with Node.js 0.11.15, which uses v8 3.28.73).
|
|
15
|
-
*/
|
|
16
33
|
function initArr(len) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
34
|
+
var array = [];
|
|
35
|
+
array[len - 1] = void 0;
|
|
36
|
+
return array;
|
|
20
37
|
}
|
|
21
38
|
function add(a, b) {
|
|
22
|
-
|
|
39
|
+
return create(a[0] + b[0], a[1] + b[1]);
|
|
23
40
|
}
|
|
24
41
|
function and(a, b) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
const highBits = ~~Math.max(
|
|
43
|
+
Math.min(a[1] / MAX_UINT32, MAX_INT32),
|
|
44
|
+
MIN_INT32
|
|
45
|
+
) & ~~Math.max(
|
|
46
|
+
Math.min(b[1] / MAX_UINT32, MAX_INT32),
|
|
47
|
+
MIN_INT32
|
|
48
|
+
);
|
|
49
|
+
const lowBits = lowBits_0(a) & lowBits_0(b);
|
|
50
|
+
let high = highBits * MAX_UINT32;
|
|
51
|
+
let low = lowBits;
|
|
52
|
+
if (lowBits < 0) {
|
|
53
|
+
low += MAX_UINT32;
|
|
54
|
+
}
|
|
55
|
+
return [low, high];
|
|
35
56
|
}
|
|
36
57
|
function compare(a, b) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return 1;
|
|
47
|
-
}
|
|
48
|
-
if (sub(a, b)[1] < 0) {
|
|
49
|
-
return -1;
|
|
50
|
-
}
|
|
58
|
+
if (a[0] == b[0] && a[1] == b[1]) {
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
const nega = a[1] < 0;
|
|
62
|
+
const negb = b[1] < 0;
|
|
63
|
+
if (nega && !negb) {
|
|
64
|
+
return -1;
|
|
65
|
+
}
|
|
66
|
+
if (!nega && negb) {
|
|
51
67
|
return 1;
|
|
68
|
+
}
|
|
69
|
+
if (sub(a, b)[1] < 0) {
|
|
70
|
+
return -1;
|
|
71
|
+
}
|
|
72
|
+
return 1;
|
|
52
73
|
}
|
|
53
74
|
function create(valueLow, valueHigh) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
let diffHigh, diffLow;
|
|
76
|
+
valueHigh %= 18446744073709552e3;
|
|
77
|
+
valueLow %= 18446744073709552e3;
|
|
78
|
+
diffHigh = valueHigh % MAX_UINT32;
|
|
79
|
+
diffLow = Math.floor(valueLow / MAX_UINT32) * MAX_UINT32;
|
|
80
|
+
valueHigh = valueHigh - diffHigh + diffLow;
|
|
81
|
+
valueLow = valueLow - diffLow + diffHigh;
|
|
82
|
+
while (valueLow < 0) {
|
|
83
|
+
valueLow += MAX_UINT32;
|
|
84
|
+
valueHigh -= MAX_UINT32;
|
|
85
|
+
}
|
|
86
|
+
while (valueLow > 4294967295) {
|
|
87
|
+
valueLow -= MAX_UINT32;
|
|
88
|
+
valueHigh += MAX_UINT32;
|
|
89
|
+
}
|
|
90
|
+
valueHigh = valueHigh % 18446744073709552e3;
|
|
91
|
+
while (valueHigh > 9223372032559809e3) {
|
|
92
|
+
valueHigh -= 18446744073709552e3;
|
|
93
|
+
}
|
|
94
|
+
while (valueHigh < -9223372036854776e3) {
|
|
95
|
+
valueHigh += 18446744073709552e3;
|
|
96
|
+
}
|
|
97
|
+
return [valueLow, valueHigh];
|
|
77
98
|
}
|
|
78
99
|
function eq(a, b) {
|
|
79
|
-
|
|
100
|
+
return a[0] == b[0] && a[1] == b[1];
|
|
80
101
|
}
|
|
81
102
|
function fromInt(value) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
103
|
+
if (value >= 0) {
|
|
104
|
+
return [value, 0];
|
|
105
|
+
} else {
|
|
106
|
+
return [value + MAX_UINT32, -MAX_UINT32];
|
|
107
|
+
}
|
|
88
108
|
}
|
|
89
109
|
function lowBits_0(a) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
110
|
+
if (a[0] >= 2147483648) {
|
|
111
|
+
return ~~Math.max(
|
|
112
|
+
Math.min(a[0] - MAX_UINT32, MAX_INT32),
|
|
113
|
+
MIN_INT32
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
return ~~Math.max(
|
|
117
|
+
Math.min(a[0], MAX_INT32),
|
|
118
|
+
MIN_INT32
|
|
119
|
+
);
|
|
94
120
|
}
|
|
95
121
|
function pwrAsDouble(n) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
122
|
+
if (n <= 30) {
|
|
123
|
+
return 1 << n;
|
|
124
|
+
}
|
|
125
|
+
return pwrAsDouble(30) * pwrAsDouble(n - 30);
|
|
100
126
|
}
|
|
101
127
|
function shl(a, n) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
let diff, newHigh, newLow, twoToN;
|
|
129
|
+
n &= 63;
|
|
130
|
+
if (eq(a, MIN_VALUE)) {
|
|
131
|
+
if (!n) {
|
|
132
|
+
return a;
|
|
133
|
+
}
|
|
134
|
+
return P0_longLit;
|
|
135
|
+
}
|
|
136
|
+
if (a[1] < 0) {
|
|
137
|
+
throw new Error("Neg");
|
|
138
|
+
}
|
|
139
|
+
twoToN = pwrAsDouble(n);
|
|
140
|
+
newHigh = a[1] * twoToN % 18446744073709552e3;
|
|
141
|
+
newLow = a[0] * twoToN;
|
|
142
|
+
diff = newLow - newLow % MAX_UINT32;
|
|
143
|
+
newHigh += diff;
|
|
144
|
+
newLow -= diff;
|
|
145
|
+
if (newHigh >= MAX_COMPRESSION_SIZE) {
|
|
146
|
+
newHigh -= 18446744073709552e3;
|
|
147
|
+
}
|
|
148
|
+
return [newLow, newHigh];
|
|
123
149
|
}
|
|
124
150
|
function shr(a, n) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
151
|
+
n &= 63;
|
|
152
|
+
let shiftFact = pwrAsDouble(n);
|
|
153
|
+
return create(
|
|
154
|
+
Math.floor(a[0] / shiftFact),
|
|
155
|
+
a[1] / shiftFact
|
|
156
|
+
);
|
|
128
157
|
}
|
|
129
158
|
function shru(a, n) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
159
|
+
let sr = shr(a, n);
|
|
160
|
+
n &= 63;
|
|
161
|
+
if (a[1] < 0) {
|
|
162
|
+
sr = add(sr, shl([2, 0], 63 - n));
|
|
163
|
+
}
|
|
164
|
+
return sr;
|
|
136
165
|
}
|
|
137
166
|
function sub(a, b) {
|
|
138
|
-
|
|
167
|
+
return create(a[0] - b[0], a[1] - b[1]);
|
|
139
168
|
}
|
|
140
169
|
function $ByteArrayInputStream(obj, buf) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
170
|
+
obj.buf = buf;
|
|
171
|
+
obj.pos = 0;
|
|
172
|
+
obj.count = buf.length;
|
|
173
|
+
return obj;
|
|
145
174
|
}
|
|
146
175
|
function $read(obj) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
176
|
+
if (obj.pos >= obj.count) {
|
|
177
|
+
return -1;
|
|
178
|
+
}
|
|
179
|
+
return obj.buf[obj.pos++] & 255;
|
|
151
180
|
}
|
|
152
181
|
function $read_0(obj, buf, off, len) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
182
|
+
if (obj.pos >= obj.count) {
|
|
183
|
+
return -1;
|
|
184
|
+
}
|
|
185
|
+
len = Math.min(len, obj.count - obj.pos);
|
|
186
|
+
arraycopy(obj.buf, obj.pos, buf, off, len);
|
|
187
|
+
obj.pos += len;
|
|
188
|
+
return len;
|
|
160
189
|
}
|
|
161
190
|
function $toByteArray(obj) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
191
|
+
const data = obj.buf;
|
|
192
|
+
data.length = obj.count;
|
|
193
|
+
return data;
|
|
165
194
|
}
|
|
166
195
|
function $write(obj, b) {
|
|
167
|
-
|
|
196
|
+
obj.buf[obj.count++] = b << 24 >> 24;
|
|
168
197
|
}
|
|
169
198
|
function $write_0(obj, buf, off, len) {
|
|
170
|
-
|
|
171
|
-
|
|
199
|
+
arraycopy(buf, off, obj.buf, obj.count, len);
|
|
200
|
+
obj.count += len;
|
|
172
201
|
}
|
|
173
202
|
function $getChars(obj, srcBegin, srcEnd, dst, dstBegin) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
203
|
+
var srcIdx;
|
|
204
|
+
for (srcIdx = srcBegin; srcIdx < srcEnd; ++srcIdx) {
|
|
205
|
+
dst[dstBegin++] = obj.charCodeAt(srcIdx);
|
|
206
|
+
}
|
|
178
207
|
}
|
|
179
208
|
function arraycopy(src, srcOfs, dest, destOfs, len) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
209
|
+
for (let i = 0; i < len; ++i) {
|
|
210
|
+
try {
|
|
211
|
+
dest[destOfs + i] = src[srcOfs + i];
|
|
212
|
+
} catch (error) {
|
|
213
|
+
break;
|
|
187
214
|
}
|
|
215
|
+
}
|
|
188
216
|
}
|
|
189
217
|
function $configure(mode, encoder) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
*/
|
|
198
|
-
encoder._numLiteralContextBits = 3;
|
|
199
|
-
encoder._numLiteralPosStateBits = 0;
|
|
200
|
-
encoder._posStateBits = 2;
|
|
201
|
-
encoder._posStateMask = 3;
|
|
218
|
+
$SetDictionarySize_0(encoder, 1 << mode.s);
|
|
219
|
+
encoder._numFastBytes = mode.f;
|
|
220
|
+
$SetMatchFinder(encoder, mode.m);
|
|
221
|
+
encoder._numLiteralContextBits = 3;
|
|
222
|
+
encoder._numLiteralPosStateBits = 0;
|
|
223
|
+
encoder._posStateBits = 2;
|
|
224
|
+
encoder._posStateMask = 3;
|
|
202
225
|
}
|
|
203
226
|
function $init(obj, input, output, len, mode) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
$Create_2(encoder),
|
|
219
|
-
encoder._rangeEncoder.Stream = output,
|
|
220
|
-
$Init_4(encoder),
|
|
221
|
-
$FillDistancesPrices(encoder),
|
|
222
|
-
$FillAlignPrices(encoder),
|
|
223
|
-
encoder._lenEncoder._tableSize = encoder._numFastBytes + 1 - 2,
|
|
224
|
-
$UpdateTables(encoder._lenEncoder, 1 << encoder._posStateBits),
|
|
225
|
-
encoder._repMatchLenEncoder._tableSize = encoder._numFastBytes
|
|
226
|
-
+ 1
|
|
227
|
-
- 2,
|
|
228
|
-
$UpdateTables(encoder._repMatchLenEncoder, 1 << encoder._posStateBits),
|
|
229
|
-
encoder.nowPos64 = P0_longLit,
|
|
230
|
-
undefined),
|
|
231
|
-
$Chunker_0({}, encoder));
|
|
227
|
+
if (compare(len, N1_longLit) < 0) {
|
|
228
|
+
throw new Error("invalid length " + len);
|
|
229
|
+
}
|
|
230
|
+
obj.length_0 = len;
|
|
231
|
+
let encoder = $Encoder();
|
|
232
|
+
$configure(mode, encoder);
|
|
233
|
+
writeHeaderProperties(encoder, output);
|
|
234
|
+
for (let i = 0; i < 64; i += 8) {
|
|
235
|
+
$write(output, lowBits_0(shr(len, i)) & 255);
|
|
236
|
+
}
|
|
237
|
+
obj.chunker = (encoder._needReleaseMFStream = 0, encoder._inStream = input, encoder._finished = 0, $Create_2(encoder), encoder._rangeEncoder.Stream = output, $Init_4(encoder), $FillDistancesPrices(encoder), $FillAlignPrices(encoder), encoder._lenEncoder._tableSize = encoder._numFastBytes + 1 - 2, $UpdateTables(encoder._lenEncoder, 1 << encoder._posStateBits), encoder._repMatchLenEncoder._tableSize = encoder._numFastBytes + 1 - 2, $UpdateTables(
|
|
238
|
+
encoder._repMatchLenEncoder,
|
|
239
|
+
1 << encoder._posStateBits
|
|
240
|
+
), encoder.nowPos64 = P0_longLit, void 0, $Chunker_0({}, encoder));
|
|
232
241
|
}
|
|
233
242
|
function $LZMAByteArrayCompressor(obj, data, mode) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
243
|
+
obj.output = {
|
|
244
|
+
buf: initArr(32),
|
|
245
|
+
count: 0
|
|
246
|
+
};
|
|
247
|
+
$init(
|
|
248
|
+
obj,
|
|
249
|
+
$ByteArrayInputStream({}, data),
|
|
250
|
+
obj.output,
|
|
251
|
+
fromInt(data.length),
|
|
252
|
+
mode
|
|
253
|
+
);
|
|
254
|
+
return obj;
|
|
240
255
|
}
|
|
241
256
|
function $init_0(obj, input, output) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
obj.length_0 = N1_longLit;
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
obj.length_0 = fromInt(tmp_length);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
obj.chunker = $CodeInChunks(decoder, input, output, obj.length_0);
|
|
257
|
+
let hex_length = "", properties = [], r, tmp_length;
|
|
258
|
+
for (let i = 0; i < 5; ++i) {
|
|
259
|
+
r = $read(input);
|
|
260
|
+
if (r == -1) {
|
|
261
|
+
throw new Error("truncated input");
|
|
262
|
+
}
|
|
263
|
+
properties[i] = r << 24 >> 24;
|
|
264
|
+
}
|
|
265
|
+
let decoder = $Decoder({});
|
|
266
|
+
if (!$SetDecoderProperties(decoder, properties)) {
|
|
267
|
+
throw new Error("corrupted input");
|
|
268
|
+
}
|
|
269
|
+
for (let i = 0; i < 64; i += 8) {
|
|
270
|
+
r = $read(input);
|
|
271
|
+
if (r == -1) {
|
|
272
|
+
throw new Error("truncated input");
|
|
273
|
+
}
|
|
274
|
+
r = r.toString(16);
|
|
275
|
+
if (r.length == 1)
|
|
276
|
+
r = "0" + r;
|
|
277
|
+
hex_length = r + "" + hex_length;
|
|
278
|
+
}
|
|
279
|
+
if (/^0+$|^f+$/i.test(hex_length)) {
|
|
280
|
+
obj.length_0 = N1_longLit;
|
|
281
|
+
} else {
|
|
282
|
+
tmp_length = parseInt(hex_length, 16);
|
|
283
|
+
if (tmp_length > 4294967295) {
|
|
284
|
+
obj.length_0 = N1_longLit;
|
|
285
|
+
} else {
|
|
286
|
+
obj.length_0 = fromInt(tmp_length);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
obj.chunker = $CodeInChunks(
|
|
290
|
+
decoder,
|
|
291
|
+
input,
|
|
292
|
+
output,
|
|
293
|
+
obj.length_0
|
|
294
|
+
);
|
|
287
295
|
}
|
|
288
296
|
function $LZMAByteArrayDecompressor(obj, data) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
297
|
+
obj.output = {
|
|
298
|
+
buf: initArr(32),
|
|
299
|
+
count: 0
|
|
300
|
+
};
|
|
301
|
+
$init_0(obj, $ByteArrayInputStream({}, data), obj.output);
|
|
302
|
+
return obj;
|
|
295
303
|
}
|
|
296
304
|
function $Create_4(obj, keepSizeBefore, keepSizeAfter, keepSizeReserv) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
let blockSize;
|
|
306
|
+
obj._keepSizeBefore = keepSizeBefore;
|
|
307
|
+
obj._keepSizeAfter = keepSizeAfter;
|
|
308
|
+
blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;
|
|
309
|
+
if (obj._bufferBase == null || obj._blockSize != blockSize) {
|
|
310
|
+
obj._bufferBase = null;
|
|
311
|
+
obj._blockSize = blockSize;
|
|
312
|
+
obj._bufferBase = initArr(obj._blockSize);
|
|
313
|
+
}
|
|
314
|
+
obj._pointerToLastSafePosition = obj._blockSize - keepSizeAfter;
|
|
307
315
|
}
|
|
308
316
|
function $GetIndexByte(obj, index) {
|
|
309
|
-
|
|
310
|
-
._bufferBase[obj._bufferOffset + obj._pos + index];
|
|
317
|
+
return obj._bufferBase[obj._bufferOffset + obj._pos + index];
|
|
311
318
|
}
|
|
312
319
|
function $GetMatchLen(obj, index, distance, limit) {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
320
|
+
if (obj._streamEndWasReached) {
|
|
321
|
+
if (obj._pos + index + limit > obj._streamPos) {
|
|
322
|
+
limit = obj._streamPos - (obj._pos + index);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
;
|
|
326
|
+
++distance;
|
|
327
|
+
let i, pby = obj._bufferOffset + obj._pos + index;
|
|
328
|
+
for (i = 0; i < limit && obj._bufferBase[pby + i] == obj._bufferBase[pby + i - distance]; ++i)
|
|
318
329
|
;
|
|
319
|
-
|
|
320
|
-
let i, pby = obj._bufferOffset + obj._pos + index;
|
|
321
|
-
for (i = 0; i < limit
|
|
322
|
-
&& obj._bufferBase[pby + i] == obj._bufferBase[pby + i - distance]; ++i)
|
|
323
|
-
;
|
|
324
|
-
return i;
|
|
330
|
+
return i;
|
|
325
331
|
}
|
|
326
332
|
function $GetNumAvailableBytes(obj) {
|
|
327
|
-
|
|
333
|
+
return obj._streamPos - obj._pos;
|
|
328
334
|
}
|
|
329
335
|
function $MoveBlock(obj) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
336
|
+
let offset = obj._bufferOffset + obj._pos - obj._keepSizeBefore;
|
|
337
|
+
if (offset > 0) {
|
|
338
|
+
;
|
|
339
|
+
--offset;
|
|
340
|
+
}
|
|
341
|
+
let numBytes = obj._bufferOffset + obj._streamPos - offset;
|
|
342
|
+
for (let i = 0; i < numBytes; ++i) {
|
|
343
|
+
obj._bufferBase[i] = obj._bufferBase[offset + i];
|
|
344
|
+
}
|
|
345
|
+
obj._bufferOffset -= offset;
|
|
340
346
|
}
|
|
341
347
|
function $MovePos_1(obj) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
$ReadBlock(obj);
|
|
348
|
+
var pointerToPostion;
|
|
349
|
+
obj._pos += 1;
|
|
350
|
+
if (obj._pos > obj._posLimit) {
|
|
351
|
+
pointerToPostion = obj._bufferOffset + obj._pos;
|
|
352
|
+
if (pointerToPostion > obj._pointerToLastSafePosition) {
|
|
353
|
+
$MoveBlock(obj);
|
|
350
354
|
}
|
|
355
|
+
$ReadBlock(obj);
|
|
356
|
+
}
|
|
351
357
|
}
|
|
352
358
|
function $ReadBlock(obj) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
359
|
+
let numReadBytes, pointerToPostion, size;
|
|
360
|
+
if (obj._streamEndWasReached) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
while (1) {
|
|
364
|
+
size = -obj._bufferOffset + obj._blockSize - obj._streamPos;
|
|
365
|
+
if (!size) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
numReadBytes = $read_0(
|
|
369
|
+
obj._stream,
|
|
370
|
+
obj._bufferBase,
|
|
371
|
+
obj._bufferOffset + obj._streamPos,
|
|
372
|
+
size
|
|
373
|
+
);
|
|
374
|
+
if (numReadBytes == -1) {
|
|
375
|
+
obj._posLimit = obj._streamPos;
|
|
376
|
+
pointerToPostion = obj._bufferOffset + obj._posLimit;
|
|
377
|
+
if (pointerToPostion > obj._pointerToLastSafePosition) {
|
|
378
|
+
obj._posLimit = obj._pointerToLastSafePosition - obj._bufferOffset;
|
|
379
|
+
}
|
|
380
|
+
obj._streamEndWasReached = 1;
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
obj._streamPos += numReadBytes;
|
|
384
|
+
if (obj._streamPos >= obj._pos + obj._keepSizeAfter) {
|
|
385
|
+
obj._posLimit = obj._streamPos - obj._keepSizeAfter;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
378
388
|
}
|
|
379
389
|
function $ReduceOffsets(obj, subValue) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
const crcTable = function
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
return crcTable;
|
|
390
|
+
obj._bufferOffset += subValue;
|
|
391
|
+
obj._posLimit -= subValue;
|
|
392
|
+
obj._pos -= subValue;
|
|
393
|
+
obj._streamPos -= subValue;
|
|
394
|
+
}
|
|
395
|
+
const crcTable = function() {
|
|
396
|
+
const crcTable2 = [];
|
|
397
|
+
for (let i = 0, r; i < 256; ++i, r = i) {
|
|
398
|
+
r = i;
|
|
399
|
+
for (let j = 0; j < 8; ++j) {
|
|
400
|
+
if ((r & 1) != 0) {
|
|
401
|
+
r >>>= 1;
|
|
402
|
+
r ^= -306674912;
|
|
403
|
+
} else {
|
|
404
|
+
r >>>= 1;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
crcTable2[i] = r;
|
|
408
|
+
}
|
|
409
|
+
return crcTable2;
|
|
401
410
|
}();
|
|
402
411
|
function $Create_3(obj, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter) {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
412
|
+
if (historySize < 1073741567) {
|
|
413
|
+
obj._cutValue = 16 + (matchMaxLen >> 1);
|
|
414
|
+
let windowReservSize = ~~((historySize + keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2) + 256;
|
|
415
|
+
$Create_4(
|
|
416
|
+
obj,
|
|
417
|
+
historySize + keepAddBufferBefore,
|
|
418
|
+
matchMaxLen + keepAddBufferAfter,
|
|
419
|
+
windowReservSize
|
|
420
|
+
);
|
|
421
|
+
obj._matchMaxLen = matchMaxLen;
|
|
422
|
+
let cyclicBufferSize = historySize + 1;
|
|
423
|
+
if (obj._cyclicBufferSize != cyclicBufferSize) {
|
|
424
|
+
obj._son = initArr(
|
|
425
|
+
(obj._cyclicBufferSize = cyclicBufferSize) * 2
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
let hs = 65536;
|
|
429
|
+
if (obj.HASH_ARRAY) {
|
|
430
|
+
hs = historySize - 1;
|
|
431
|
+
hs |= hs >> 1;
|
|
432
|
+
hs |= hs >> 2;
|
|
433
|
+
hs |= hs >> 4;
|
|
434
|
+
hs |= hs >> 8;
|
|
435
|
+
hs >>= 1;
|
|
436
|
+
hs |= 65535;
|
|
437
|
+
if (hs > 16777216) {
|
|
438
|
+
hs >>= 1;
|
|
439
|
+
}
|
|
440
|
+
obj._hashMask = hs;
|
|
441
|
+
hs += 1;
|
|
442
|
+
hs += obj.kFixHashSize;
|
|
443
|
+
}
|
|
444
|
+
if (hs != obj._hashSizeSum) {
|
|
445
|
+
obj._hash = initArr(obj._hashSizeSum = hs);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
435
448
|
}
|
|
436
449
|
function $GetMatches(obj, distances) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
450
|
+
var count, cur, curMatch, curMatch2, curMatch3, cyclicPos, delta, hash2Value, hash3Value, hashValue, len, len0, len1, lenLimit, matchMinPos, maxLen, offset, pby1, ptr0, ptr1, temp;
|
|
451
|
+
if (obj._pos + obj._matchMaxLen <= obj._streamPos) {
|
|
452
|
+
lenLimit = obj._matchMaxLen;
|
|
453
|
+
} else {
|
|
454
|
+
lenLimit = obj._streamPos - obj._pos;
|
|
455
|
+
if (lenLimit < obj.kMinMatchCheck) {
|
|
456
|
+
$MovePos_0(obj);
|
|
457
|
+
return 0;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
offset = 0;
|
|
461
|
+
matchMinPos = obj._pos > obj._cyclicBufferSize ? obj._pos - obj._cyclicBufferSize : 0;
|
|
462
|
+
cur = obj._bufferOffset + obj._pos;
|
|
463
|
+
maxLen = 1;
|
|
464
|
+
hash2Value = 0;
|
|
465
|
+
hash3Value = 0;
|
|
466
|
+
if (obj.HASH_ARRAY) {
|
|
467
|
+
temp = crcTable[obj._bufferBase[cur] & 255] ^ obj._bufferBase[cur + 1] & 255;
|
|
468
|
+
hash2Value = temp & 1023;
|
|
469
|
+
temp ^= (obj._bufferBase[cur + 2] & 255) << 8;
|
|
470
|
+
hash3Value = temp & 65535;
|
|
471
|
+
hashValue = (temp ^ crcTable[obj._bufferBase[cur + 3] & 255] << 5) & obj._hashMask;
|
|
472
|
+
} else {
|
|
473
|
+
hashValue = obj._bufferBase[cur] & 255 ^ (obj._bufferBase[cur + 1] & 255) << 8;
|
|
474
|
+
}
|
|
475
|
+
curMatch = obj._hash[obj.kFixHashSize + hashValue] || 0;
|
|
476
|
+
if (obj.HASH_ARRAY) {
|
|
477
|
+
curMatch2 = obj._hash[hash2Value] || 0;
|
|
478
|
+
curMatch3 = obj._hash[1024 + hash3Value] || 0;
|
|
479
|
+
obj._hash[hash2Value] = obj._pos;
|
|
480
|
+
obj._hash[1024 + hash3Value] = obj._pos;
|
|
481
|
+
if (curMatch2 > matchMinPos) {
|
|
482
|
+
if (obj._bufferBase[obj._bufferOffset + curMatch2] == obj._bufferBase[cur]) {
|
|
483
|
+
distances[offset++] = maxLen = 2;
|
|
484
|
+
distances[offset++] = obj._pos - curMatch2 - 1;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (curMatch3 > matchMinPos) {
|
|
488
|
+
if (obj._bufferBase[obj._bufferOffset + curMatch3] == obj._bufferBase[cur]) {
|
|
489
|
+
if (curMatch3 == curMatch2) {
|
|
490
|
+
offset -= 2;
|
|
491
|
+
}
|
|
492
|
+
distances[offset++] = maxLen = 3;
|
|
493
|
+
distances[offset++] = obj._pos - curMatch3 - 1;
|
|
494
|
+
curMatch2 = curMatch3;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
if (offset != 0 && curMatch2 == curMatch) {
|
|
498
|
+
offset -= 2;
|
|
499
|
+
maxLen = 1;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
obj._hash[obj.kFixHashSize + hashValue] = obj._pos;
|
|
503
|
+
ptr0 = (obj._cyclicBufferPos << 1) + 1;
|
|
504
|
+
ptr1 = obj._cyclicBufferPos << 1;
|
|
505
|
+
len0 = len1 = obj.kNumHashDirectBytes;
|
|
506
|
+
if (obj.kNumHashDirectBytes != 0) {
|
|
507
|
+
if (curMatch > matchMinPos) {
|
|
508
|
+
if (obj._bufferBase[obj._bufferOffset + curMatch + obj.kNumHashDirectBytes] != obj._bufferBase[cur + obj.kNumHashDirectBytes]) {
|
|
509
|
+
distances[offset++] = maxLen = obj.kNumHashDirectBytes;
|
|
510
|
+
distances[offset++] = obj._pos - curMatch - 1;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
count = obj._cutValue;
|
|
515
|
+
while (1) {
|
|
516
|
+
if (curMatch <= matchMinPos || count == 0) {
|
|
517
|
+
count -= 1;
|
|
518
|
+
obj._son[ptr0] = obj._son[ptr1] = 0;
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
delta = obj._pos - curMatch;
|
|
522
|
+
cyclicPos = (delta <= obj._cyclicBufferPos ? obj._cyclicBufferPos - delta : obj._cyclicBufferPos - delta + obj._cyclicBufferSize) << 1;
|
|
523
|
+
pby1 = obj._bufferOffset + curMatch;
|
|
524
|
+
len = len0 < len1 ? len0 : len1;
|
|
525
|
+
if (obj._bufferBase[pby1 + len] == obj._bufferBase[cur + len]) {
|
|
526
|
+
while ((len += 1) != lenLimit) {
|
|
527
|
+
if (obj._bufferBase[pby1 + len] != obj._bufferBase[cur + len]) {
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
if (maxLen < len) {
|
|
532
|
+
distances[offset++] = maxLen = len;
|
|
533
|
+
distances[offset++] = delta - 1;
|
|
534
|
+
if (len == lenLimit) {
|
|
535
|
+
obj._son[ptr1] = obj._son[cyclicPos];
|
|
536
|
+
obj._son[ptr0] = obj._son[cyclicPos + 1];
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if ((obj._bufferBase[pby1 + len] & 255) < (obj._bufferBase[cur + len] & 255)) {
|
|
542
|
+
obj._son[ptr1] = curMatch;
|
|
543
|
+
ptr1 = cyclicPos + 1;
|
|
544
|
+
curMatch = obj._son[ptr1];
|
|
545
|
+
len1 = len;
|
|
546
|
+
} else {
|
|
547
|
+
obj._son[ptr0] = curMatch;
|
|
548
|
+
ptr0 = cyclicPos;
|
|
549
|
+
curMatch = obj._son[ptr0];
|
|
550
|
+
len0 = len;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
$MovePos_0(obj);
|
|
554
|
+
return offset;
|
|
555
|
+
}
|
|
556
|
+
function $Init_5(obj) {
|
|
557
|
+
obj._bufferOffset = 0;
|
|
558
|
+
obj._pos = 0;
|
|
559
|
+
obj._streamPos = 0;
|
|
560
|
+
obj._streamEndWasReached = 0;
|
|
561
|
+
$ReadBlock(obj);
|
|
562
|
+
obj._cyclicBufferPos = 0;
|
|
563
|
+
$ReduceOffsets(obj, -1);
|
|
564
|
+
}
|
|
565
|
+
function $MovePos_0(obj) {
|
|
566
|
+
var subValue;
|
|
567
|
+
if ((obj._cyclicBufferPos += 1) >= obj._cyclicBufferSize) {
|
|
568
|
+
obj._cyclicBufferPos = 0;
|
|
569
|
+
}
|
|
570
|
+
$MovePos_1(obj);
|
|
571
|
+
if (obj._pos == 1073741823) {
|
|
572
|
+
subValue = obj._pos - obj._cyclicBufferSize;
|
|
573
|
+
$NormalizeLinks(
|
|
574
|
+
obj._son,
|
|
575
|
+
obj._cyclicBufferSize * 2,
|
|
576
|
+
subValue
|
|
577
|
+
);
|
|
578
|
+
$NormalizeLinks(obj._hash, obj._hashSizeSum, subValue);
|
|
579
|
+
$ReduceOffsets(obj, subValue);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
function $NormalizeLinks(items, numItems, subValue) {
|
|
583
|
+
var i, value;
|
|
584
|
+
for (i = 0; i < numItems; ++i) {
|
|
585
|
+
value = items[i] || 0;
|
|
586
|
+
if (value <= subValue) {
|
|
587
|
+
value = 0;
|
|
588
|
+
} else {
|
|
589
|
+
value -= subValue;
|
|
440
590
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
591
|
+
items[i] = value;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
function $SetType(obj, numHashBytes) {
|
|
595
|
+
obj.HASH_ARRAY = numHashBytes > 2;
|
|
596
|
+
if (obj.HASH_ARRAY) {
|
|
597
|
+
obj.kNumHashDirectBytes = 0;
|
|
598
|
+
obj.kMinMatchCheck = 4;
|
|
599
|
+
obj.kFixHashSize = 66560;
|
|
600
|
+
} else {
|
|
601
|
+
obj.kNumHashDirectBytes = 2;
|
|
602
|
+
obj.kMinMatchCheck = 3;
|
|
603
|
+
obj.kFixHashSize = 0;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
function $Skip(obj, num) {
|
|
607
|
+
var count, cur, curMatch, cyclicPos, delta, hash2Value, hash3Value, hashValue, len, len0, len1, lenLimit, matchMinPos, pby1, ptr0, ptr1, temp;
|
|
608
|
+
do {
|
|
609
|
+
if (obj._pos + obj._matchMaxLen <= obj._streamPos) {
|
|
610
|
+
lenLimit = obj._matchMaxLen;
|
|
611
|
+
} else {
|
|
612
|
+
lenLimit = obj._streamPos - obj._pos;
|
|
613
|
+
if (lenLimit < obj.kMinMatchCheck) {
|
|
614
|
+
$MovePos_0(obj);
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
447
617
|
}
|
|
448
|
-
|
|
449
|
-
matchMinPos = obj._pos > obj._cyclicBufferSize
|
|
450
|
-
? obj._pos - obj._cyclicBufferSize
|
|
451
|
-
: 0;
|
|
618
|
+
matchMinPos = obj._pos > obj._cyclicBufferSize ? obj._pos - obj._cyclicBufferSize : 0;
|
|
452
619
|
cur = obj._bufferOffset + obj._pos;
|
|
453
|
-
maxLen = 1;
|
|
454
|
-
hash2Value = 0;
|
|
455
|
-
hash3Value = 0;
|
|
456
620
|
if (obj.HASH_ARRAY) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
curMatch = obj._hash[obj.kFixHashSize + hashValue] || 0;
|
|
470
|
-
if (obj.HASH_ARRAY) {
|
|
471
|
-
curMatch2 = obj._hash[hash2Value] || 0;
|
|
472
|
-
curMatch3 = obj._hash[1024 + hash3Value] || 0;
|
|
473
|
-
obj._hash[hash2Value] = obj._pos;
|
|
474
|
-
obj._hash[1024 + hash3Value] = obj._pos;
|
|
475
|
-
if (curMatch2 > matchMinPos) {
|
|
476
|
-
if (obj._bufferBase[obj._bufferOffset + curMatch2]
|
|
477
|
-
== obj._bufferBase[cur]) {
|
|
478
|
-
distances[offset++] = maxLen = 2;
|
|
479
|
-
distances[offset++] = obj._pos - curMatch2 - 1;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
if (curMatch3 > matchMinPos) {
|
|
483
|
-
if (obj._bufferBase[obj._bufferOffset + curMatch3]
|
|
484
|
-
== obj._bufferBase[cur]) {
|
|
485
|
-
if (curMatch3 == curMatch2) {
|
|
486
|
-
offset -= 2;
|
|
487
|
-
}
|
|
488
|
-
distances[offset++] = maxLen = 3;
|
|
489
|
-
distances[offset++] = obj._pos - curMatch3 - 1;
|
|
490
|
-
curMatch2 = curMatch3;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
if (offset != 0 && curMatch2 == curMatch) {
|
|
494
|
-
offset -= 2;
|
|
495
|
-
maxLen = 1;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
621
|
+
temp = crcTable[obj._bufferBase[cur] & 255] ^ obj._bufferBase[cur + 1] & 255;
|
|
622
|
+
hash2Value = temp & 1023;
|
|
623
|
+
obj._hash[hash2Value] = obj._pos;
|
|
624
|
+
temp ^= (obj._bufferBase[cur + 2] & 255) << 8;
|
|
625
|
+
hash3Value = temp & 65535;
|
|
626
|
+
obj._hash[1024 + hash3Value] = obj._pos;
|
|
627
|
+
hashValue = (temp ^ crcTable[obj._bufferBase[cur + 3] & 255] << 5) & obj._hashMask;
|
|
628
|
+
} else {
|
|
629
|
+
hashValue = obj._bufferBase[cur] & 255 ^ (obj._bufferBase[cur + 1] & 255) << 8;
|
|
630
|
+
}
|
|
631
|
+
curMatch = obj._hash[obj.kFixHashSize + hashValue];
|
|
498
632
|
obj._hash[obj.kFixHashSize + hashValue] = obj._pos;
|
|
499
633
|
ptr0 = (obj._cyclicBufferPos << 1) + 1;
|
|
500
634
|
ptr1 = obj._cyclicBufferPos << 1;
|
|
501
635
|
len0 = len1 = obj.kNumHashDirectBytes;
|
|
502
|
-
if (obj.kNumHashDirectBytes != 0) {
|
|
503
|
-
if (curMatch > matchMinPos) {
|
|
504
|
-
if (obj
|
|
505
|
-
._bufferBase[obj._bufferOffset + curMatch + obj.kNumHashDirectBytes] != obj
|
|
506
|
-
._bufferBase[cur + obj.kNumHashDirectBytes]) {
|
|
507
|
-
distances[offset++] = maxLen = obj.kNumHashDirectBytes;
|
|
508
|
-
distances[offset++] = obj._pos - curMatch - 1;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
636
|
count = obj._cutValue;
|
|
513
637
|
while (1) {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
638
|
+
if (curMatch <= matchMinPos || count == 0) {
|
|
639
|
+
count -= 1;
|
|
640
|
+
obj._son[ptr0] = obj._son[ptr1] = 0;
|
|
641
|
+
break;
|
|
642
|
+
}
|
|
643
|
+
delta = obj._pos - curMatch;
|
|
644
|
+
cyclicPos = (delta <= obj._cyclicBufferPos ? obj._cyclicBufferPos - delta : obj._cyclicBufferPos - delta + obj._cyclicBufferSize) << 1;
|
|
645
|
+
pby1 = obj._bufferOffset + curMatch;
|
|
646
|
+
len = len0 < len1 ? len0 : len1;
|
|
647
|
+
if (obj._bufferBase[pby1 + len] == obj._bufferBase[cur + len]) {
|
|
648
|
+
while ((len += 1) != lenLimit) {
|
|
649
|
+
if (obj._bufferBase[pby1 + len] != obj._bufferBase[cur + len]) {
|
|
517
650
|
break;
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
break;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
if ((obj._bufferBase[pby1 + len] & 255)
|
|
542
|
-
< (obj._bufferBase[cur + len] & 255)) {
|
|
543
|
-
obj._son[ptr1] = curMatch;
|
|
544
|
-
ptr1 = cyclicPos + 1;
|
|
545
|
-
curMatch = obj._son[ptr1];
|
|
546
|
-
len1 = len;
|
|
547
|
-
}
|
|
548
|
-
else {
|
|
549
|
-
obj._son[ptr0] = curMatch;
|
|
550
|
-
ptr0 = cyclicPos;
|
|
551
|
-
curMatch = obj._son[ptr0];
|
|
552
|
-
len0 = len;
|
|
553
|
-
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
if (len == lenLimit) {
|
|
654
|
+
obj._son[ptr1] = obj._son[cyclicPos];
|
|
655
|
+
obj._son[ptr0] = obj._son[cyclicPos + 1];
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
if ((obj._bufferBase[pby1 + len] & 255) < (obj._bufferBase[cur + len] & 255)) {
|
|
660
|
+
obj._son[ptr1] = curMatch;
|
|
661
|
+
ptr1 = cyclicPos + 1;
|
|
662
|
+
curMatch = obj._son[ptr1];
|
|
663
|
+
len1 = len;
|
|
664
|
+
} else {
|
|
665
|
+
obj._son[ptr0] = curMatch;
|
|
666
|
+
ptr0 = cyclicPos;
|
|
667
|
+
curMatch = obj._son[ptr0];
|
|
668
|
+
len0 = len;
|
|
669
|
+
}
|
|
554
670
|
}
|
|
555
671
|
$MovePos_0(obj);
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
function $Init_5(obj) {
|
|
559
|
-
obj._bufferOffset = 0;
|
|
560
|
-
obj._pos = 0;
|
|
561
|
-
obj._streamPos = 0;
|
|
562
|
-
obj._streamEndWasReached = 0;
|
|
563
|
-
$ReadBlock(obj);
|
|
564
|
-
obj._cyclicBufferPos = 0;
|
|
565
|
-
$ReduceOffsets(obj, -1);
|
|
566
|
-
}
|
|
567
|
-
function $MovePos_0(obj) {
|
|
568
|
-
var subValue;
|
|
569
|
-
if ((obj._cyclicBufferPos += 1) >= obj._cyclicBufferSize) {
|
|
570
|
-
obj._cyclicBufferPos = 0;
|
|
571
|
-
}
|
|
572
|
-
$MovePos_1(obj);
|
|
573
|
-
if (obj._pos == 1073741823) {
|
|
574
|
-
subValue = obj._pos - obj._cyclicBufferSize;
|
|
575
|
-
$NormalizeLinks(obj._son, obj._cyclicBufferSize * 2, subValue);
|
|
576
|
-
$NormalizeLinks(obj._hash, obj._hashSizeSum, subValue);
|
|
577
|
-
$ReduceOffsets(obj, subValue);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
/**
|
|
581
|
-
* This is only called after reading one whole gigabyte.
|
|
582
|
-
*/
|
|
583
|
-
function $NormalizeLinks(items, numItems, subValue) {
|
|
584
|
-
var i, value;
|
|
585
|
-
for (i = 0; i < numItems; ++i) {
|
|
586
|
-
value = items[i] || 0;
|
|
587
|
-
if (value <= subValue) {
|
|
588
|
-
value = 0;
|
|
589
|
-
}
|
|
590
|
-
else {
|
|
591
|
-
value -= subValue;
|
|
592
|
-
}
|
|
593
|
-
items[i] = value;
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
function $SetType(obj, numHashBytes) {
|
|
597
|
-
obj.HASH_ARRAY = numHashBytes > 2;
|
|
598
|
-
if (obj.HASH_ARRAY) {
|
|
599
|
-
obj.kNumHashDirectBytes = 0;
|
|
600
|
-
obj.kMinMatchCheck = 4;
|
|
601
|
-
obj.kFixHashSize = 66560;
|
|
602
|
-
}
|
|
603
|
-
else {
|
|
604
|
-
obj.kNumHashDirectBytes = 2;
|
|
605
|
-
obj.kMinMatchCheck = 3;
|
|
606
|
-
obj.kFixHashSize = 0;
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
function $Skip(obj, num) {
|
|
610
|
-
var count, cur, curMatch, cyclicPos, delta, hash2Value, hash3Value, hashValue, len, len0, len1, lenLimit, matchMinPos, pby1, ptr0, ptr1, temp;
|
|
611
|
-
do {
|
|
612
|
-
if (obj._pos + obj._matchMaxLen <= obj._streamPos) {
|
|
613
|
-
lenLimit = obj._matchMaxLen;
|
|
614
|
-
}
|
|
615
|
-
else {
|
|
616
|
-
lenLimit = obj._streamPos - obj._pos;
|
|
617
|
-
if (lenLimit < obj.kMinMatchCheck) {
|
|
618
|
-
$MovePos_0(obj);
|
|
619
|
-
continue;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
matchMinPos = obj._pos > obj._cyclicBufferSize
|
|
623
|
-
? obj._pos - obj._cyclicBufferSize
|
|
624
|
-
: 0;
|
|
625
|
-
cur = obj._bufferOffset + obj._pos;
|
|
626
|
-
if (obj.HASH_ARRAY) {
|
|
627
|
-
temp = crcTable[obj._bufferBase[cur] & 255]
|
|
628
|
-
^ obj._bufferBase[cur + 1] & 255;
|
|
629
|
-
hash2Value = temp & 1023;
|
|
630
|
-
obj._hash[hash2Value] = obj._pos;
|
|
631
|
-
temp ^= (obj._bufferBase[cur + 2] & 255) << 8;
|
|
632
|
-
hash3Value = temp & 65535;
|
|
633
|
-
obj._hash[1024 + hash3Value] = obj._pos;
|
|
634
|
-
hashValue = (temp ^ crcTable[obj._bufferBase[cur + 3] & 255] << 5)
|
|
635
|
-
& obj._hashMask;
|
|
636
|
-
}
|
|
637
|
-
else {
|
|
638
|
-
hashValue = obj._bufferBase[cur] & 255
|
|
639
|
-
^ (obj._bufferBase[cur + 1] & 255) << 8;
|
|
640
|
-
}
|
|
641
|
-
curMatch = obj._hash[obj.kFixHashSize + hashValue];
|
|
642
|
-
obj._hash[obj.kFixHashSize + hashValue] = obj._pos;
|
|
643
|
-
ptr0 = (obj._cyclicBufferPos << 1) + 1;
|
|
644
|
-
ptr1 = obj._cyclicBufferPos << 1;
|
|
645
|
-
len0 = len1 = obj.kNumHashDirectBytes;
|
|
646
|
-
count = obj._cutValue;
|
|
647
|
-
while (1) {
|
|
648
|
-
if (curMatch <= matchMinPos || count == 0) {
|
|
649
|
-
count -= 1;
|
|
650
|
-
obj._son[ptr0] = obj._son[ptr1] = 0;
|
|
651
|
-
break;
|
|
652
|
-
}
|
|
653
|
-
delta = obj._pos - curMatch;
|
|
654
|
-
cyclicPos = (delta <= obj._cyclicBufferPos
|
|
655
|
-
? obj._cyclicBufferPos - delta
|
|
656
|
-
: obj._cyclicBufferPos - delta + obj._cyclicBufferSize) << 1;
|
|
657
|
-
pby1 = obj._bufferOffset + curMatch;
|
|
658
|
-
len = len0 < len1 ? len0 : len1;
|
|
659
|
-
if (obj._bufferBase[pby1 + len] == obj._bufferBase[cur + len]) {
|
|
660
|
-
while ((len += 1) != lenLimit) {
|
|
661
|
-
if (obj._bufferBase[pby1 + len]
|
|
662
|
-
!= obj._bufferBase[cur + len]) {
|
|
663
|
-
break;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
if (len == lenLimit) {
|
|
667
|
-
obj._son[ptr1] = obj._son[cyclicPos];
|
|
668
|
-
obj._son[ptr0] = obj._son[cyclicPos + 1];
|
|
669
|
-
break;
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
if ((obj._bufferBase[pby1 + len] & 255)
|
|
673
|
-
< (obj._bufferBase[cur + len] & 255)) {
|
|
674
|
-
obj._son[ptr1] = curMatch;
|
|
675
|
-
ptr1 = cyclicPos + 1;
|
|
676
|
-
curMatch = obj._son[ptr1];
|
|
677
|
-
len1 = len;
|
|
678
|
-
}
|
|
679
|
-
else {
|
|
680
|
-
obj._son[ptr0] = curMatch;
|
|
681
|
-
ptr0 = cyclicPos;
|
|
682
|
-
curMatch = obj._son[ptr0];
|
|
683
|
-
len0 = len;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
$MovePos_0(obj);
|
|
687
|
-
} while ((num -= 1) != 0);
|
|
672
|
+
} while ((num -= 1) != 0);
|
|
688
673
|
}
|
|
689
674
|
function $CopyBlock(obj, distance, len) {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
}
|
|
675
|
+
var pos = obj._pos - distance - 1;
|
|
676
|
+
if (pos < 0) {
|
|
677
|
+
pos += obj._windowSize;
|
|
678
|
+
}
|
|
679
|
+
for (; len != 0; len -= 1) {
|
|
680
|
+
if (pos >= obj._windowSize) {
|
|
681
|
+
pos = 0;
|
|
682
|
+
}
|
|
683
|
+
obj._buffer[obj._pos] = obj._buffer[pos];
|
|
684
|
+
obj._pos += 1;
|
|
685
|
+
pos += 1;
|
|
686
|
+
if (obj._pos >= obj._windowSize) {
|
|
687
|
+
$Flush_0(obj);
|
|
704
688
|
}
|
|
689
|
+
}
|
|
705
690
|
}
|
|
706
691
|
function $Create_5(obj, windowSize) {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
692
|
+
if (obj._buffer == null || obj._windowSize != windowSize) {
|
|
693
|
+
obj._buffer = initArr(windowSize);
|
|
694
|
+
}
|
|
695
|
+
obj._windowSize = windowSize;
|
|
696
|
+
obj._pos = 0;
|
|
697
|
+
obj._streamPos = 0;
|
|
713
698
|
}
|
|
714
699
|
function $Flush_0(obj) {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
700
|
+
var size = obj._pos - obj._streamPos;
|
|
701
|
+
if (!size) {
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
$write_0(
|
|
705
|
+
obj._stream,
|
|
706
|
+
obj._buffer,
|
|
707
|
+
obj._streamPos,
|
|
708
|
+
size
|
|
709
|
+
);
|
|
710
|
+
if (obj._pos >= obj._windowSize) {
|
|
711
|
+
obj._pos = 0;
|
|
712
|
+
}
|
|
713
|
+
obj._streamPos = obj._pos;
|
|
724
714
|
}
|
|
725
715
|
function $GetByte(obj, distance) {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
716
|
+
var pos = obj._pos - distance - 1;
|
|
717
|
+
if (pos < 0) {
|
|
718
|
+
pos += obj._windowSize;
|
|
719
|
+
}
|
|
720
|
+
return obj._buffer[pos];
|
|
731
721
|
}
|
|
732
722
|
function $PutByte(obj, b) {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
723
|
+
obj._buffer[obj._pos] = b;
|
|
724
|
+
obj._pos += 1;
|
|
725
|
+
if (obj._pos >= obj._windowSize) {
|
|
726
|
+
$Flush_0(obj);
|
|
727
|
+
}
|
|
738
728
|
}
|
|
739
729
|
function $ReleaseStream(obj) {
|
|
740
|
-
|
|
741
|
-
|
|
730
|
+
$Flush_0(obj);
|
|
731
|
+
obj._stream = null;
|
|
742
732
|
}
|
|
743
733
|
function GetLenToPosState(len) {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
734
|
+
len -= 2;
|
|
735
|
+
if (len < 4) {
|
|
736
|
+
return len;
|
|
737
|
+
}
|
|
738
|
+
return 3;
|
|
749
739
|
}
|
|
750
740
|
function StateUpdateChar(index) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
741
|
+
if (index < 4) {
|
|
742
|
+
return 0;
|
|
743
|
+
}
|
|
744
|
+
if (index < 10) {
|
|
745
|
+
return index - 3;
|
|
746
|
+
}
|
|
747
|
+
return index - 6;
|
|
758
748
|
}
|
|
759
749
|
function $Chunker_0(obj, encoder) {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
750
|
+
obj.encoder = encoder;
|
|
751
|
+
obj.decoder = null;
|
|
752
|
+
obj.alive = 1;
|
|
753
|
+
return obj;
|
|
764
754
|
}
|
|
765
755
|
function $Chunker(obj, decoder) {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
756
|
+
obj.decoder = decoder;
|
|
757
|
+
obj.encoder = null;
|
|
758
|
+
obj.alive = 1;
|
|
759
|
+
return obj;
|
|
770
760
|
}
|
|
771
761
|
function $processChunkDecode(obj) {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
return obj.alive;
|
|
762
|
+
if (!obj.alive)
|
|
763
|
+
throw new Error("Bad state");
|
|
764
|
+
if (obj.encoder) {
|
|
765
|
+
throw new Error("No encoding");
|
|
766
|
+
} else {
|
|
767
|
+
$processDecoderChunk(obj);
|
|
768
|
+
}
|
|
769
|
+
return obj.alive;
|
|
781
770
|
}
|
|
782
771
|
function $processDecoderChunk(obj) {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
obj.alive = 0;
|
|
796
|
-
}
|
|
772
|
+
const result = $CodeOneChunk(obj.decoder);
|
|
773
|
+
if (result === -1) {
|
|
774
|
+
throw new Error("Corrupted input");
|
|
775
|
+
}
|
|
776
|
+
obj.inBytesProcessed = N1_longLit;
|
|
777
|
+
obj.outBytesProcessed = obj.decoder.nowPos64;
|
|
778
|
+
if (result || compare(obj.decoder.outSize, P0_longLit) >= 0 && compare(obj.decoder.nowPos64, obj.decoder.outSize) >= 0) {
|
|
779
|
+
$Flush_0(obj.decoder.m_OutWindow);
|
|
780
|
+
$ReleaseStream(obj.decoder.m_OutWindow);
|
|
781
|
+
obj.decoder.m_RangeDecoder.Stream = null;
|
|
782
|
+
obj.alive = 0;
|
|
783
|
+
}
|
|
797
784
|
}
|
|
798
785
|
function $processChunkEncode(obj) {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
return obj.alive;
|
|
786
|
+
if (!obj.alive) {
|
|
787
|
+
throw new Error("bad state");
|
|
788
|
+
}
|
|
789
|
+
if (obj.encoder) {
|
|
790
|
+
$processEncoderChunk(obj);
|
|
791
|
+
} else {
|
|
792
|
+
throw new Error("No decoding");
|
|
793
|
+
}
|
|
794
|
+
return obj.alive;
|
|
809
795
|
}
|
|
810
796
|
function $processEncoderChunk(obj) {
|
|
811
|
-
|
|
812
|
-
obj.
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
797
|
+
$CodeOneBlock(
|
|
798
|
+
obj.encoder,
|
|
799
|
+
obj.encoder.processedInSize,
|
|
800
|
+
obj.encoder.processedOutSize,
|
|
801
|
+
obj.encoder.finished
|
|
802
|
+
);
|
|
803
|
+
obj.inBytesProcessed = obj.encoder.processedInSize[0];
|
|
804
|
+
if (obj.encoder.finished[0]) {
|
|
805
|
+
$ReleaseStreams(obj.encoder);
|
|
806
|
+
obj.alive = 0;
|
|
807
|
+
}
|
|
817
808
|
}
|
|
818
809
|
function $CodeInChunks(obj, inStream, outStream, outSize) {
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
810
|
+
obj.m_RangeDecoder.Stream = inStream;
|
|
811
|
+
$ReleaseStream(obj.m_OutWindow);
|
|
812
|
+
obj.m_OutWindow._stream = outStream;
|
|
813
|
+
$Init_1(obj);
|
|
814
|
+
obj.state = 0;
|
|
815
|
+
obj.rep0 = 0;
|
|
816
|
+
obj.rep1 = 0;
|
|
817
|
+
obj.rep2 = 0;
|
|
818
|
+
obj.rep3 = 0;
|
|
819
|
+
obj.outSize = outSize;
|
|
820
|
+
obj.nowPos64 = P0_longLit;
|
|
821
|
+
obj.prevByte = 0;
|
|
822
|
+
return $Chunker({}, obj);
|
|
832
823
|
}
|
|
833
824
|
function $CodeOneChunk(obj) {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
825
|
+
var decoder2, distance, len, numDirectBits, posSlot, posState;
|
|
826
|
+
posState = lowBits_0(obj.nowPos64) & obj.m_PosStateMask;
|
|
827
|
+
if (!decodeBit(
|
|
828
|
+
obj.m_RangeDecoder,
|
|
829
|
+
obj.m_IsMatchDecoders,
|
|
830
|
+
(obj.state << 4) + posState
|
|
831
|
+
)) {
|
|
832
|
+
decoder2 = $GetDecoder(
|
|
833
|
+
obj.m_LiteralDecoder,
|
|
834
|
+
lowBits_0(obj.nowPos64),
|
|
835
|
+
obj.prevByte
|
|
836
|
+
);
|
|
837
|
+
if (obj.state < 7) {
|
|
838
|
+
obj.prevByte = $DecodeNormal(
|
|
839
|
+
decoder2,
|
|
840
|
+
obj.m_RangeDecoder
|
|
841
|
+
);
|
|
842
|
+
} else {
|
|
843
|
+
obj.prevByte = $DecodeWithMatchByte(
|
|
844
|
+
decoder2,
|
|
845
|
+
obj.m_RangeDecoder,
|
|
846
|
+
$GetByte(obj.m_OutWindow, obj.rep0)
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
$PutByte(obj.m_OutWindow, obj.prevByte);
|
|
850
|
+
obj.state = StateUpdateChar(obj.state);
|
|
851
|
+
obj.nowPos64 = add(obj.nowPos64, P1_longLit);
|
|
852
|
+
} else {
|
|
853
|
+
if (decodeBit(
|
|
854
|
+
obj.m_RangeDecoder,
|
|
855
|
+
obj.m_IsRepDecoders,
|
|
856
|
+
obj.state
|
|
857
|
+
)) {
|
|
858
|
+
len = 0;
|
|
859
|
+
if (!decodeBit(
|
|
860
|
+
obj.m_RangeDecoder,
|
|
861
|
+
obj.m_IsRepG0Decoders,
|
|
862
|
+
obj.state
|
|
863
|
+
)) {
|
|
864
|
+
if (!decodeBit(
|
|
865
|
+
obj.m_RangeDecoder,
|
|
866
|
+
obj.m_IsRep0LongDecoders,
|
|
867
|
+
(obj.state << 4) + posState
|
|
868
|
+
)) {
|
|
869
|
+
obj.state = obj.state < 7 ? 9 : 11;
|
|
870
|
+
len = 1;
|
|
871
|
+
}
|
|
872
|
+
} else {
|
|
873
|
+
if (!decodeBit(
|
|
874
|
+
obj.m_RangeDecoder,
|
|
875
|
+
obj.m_IsRepG1Decoders,
|
|
876
|
+
obj.state
|
|
877
|
+
)) {
|
|
878
|
+
distance = obj.rep1;
|
|
879
|
+
} else {
|
|
880
|
+
if (!decodeBit(
|
|
881
|
+
obj.m_RangeDecoder,
|
|
882
|
+
obj.m_IsRepG2Decoders,
|
|
883
|
+
obj.state
|
|
884
|
+
)) {
|
|
885
|
+
distance = obj.rep2;
|
|
886
|
+
} else {
|
|
887
|
+
distance = obj.rep3;
|
|
880
888
|
obj.rep3 = obj.rep2;
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
889
|
+
}
|
|
890
|
+
obj.rep2 = obj.rep1;
|
|
891
|
+
}
|
|
892
|
+
obj.rep1 = obj.rep0;
|
|
893
|
+
obj.rep0 = distance;
|
|
894
|
+
}
|
|
895
|
+
if (!len) {
|
|
896
|
+
len = $Decode(
|
|
897
|
+
obj.m_RepLenDecoder,
|
|
898
|
+
obj.m_RangeDecoder,
|
|
899
|
+
posState
|
|
900
|
+
) + 2;
|
|
901
|
+
obj.state = obj.state < 7 ? 8 : 11;
|
|
902
|
+
}
|
|
903
|
+
} else {
|
|
904
|
+
obj.rep3 = obj.rep2;
|
|
905
|
+
obj.rep2 = obj.rep1;
|
|
906
|
+
obj.rep1 = obj.rep0;
|
|
907
|
+
len = 2 + $Decode(
|
|
908
|
+
obj.m_LenDecoder,
|
|
909
|
+
obj.m_RangeDecoder,
|
|
910
|
+
posState
|
|
911
|
+
);
|
|
912
|
+
obj.state = obj.state < 7 ? 7 : 10;
|
|
913
|
+
posSlot = $Decode_0(
|
|
914
|
+
obj.m_PosSlotDecoder[GetLenToPosState(len)],
|
|
915
|
+
obj.m_RangeDecoder
|
|
916
|
+
);
|
|
917
|
+
if (posSlot >= 4) {
|
|
918
|
+
numDirectBits = (posSlot >> 1) - 1;
|
|
919
|
+
obj.rep0 = (2 | posSlot & 1) << numDirectBits;
|
|
920
|
+
if (posSlot < 14) {
|
|
921
|
+
obj.rep0 += reverseDecode(
|
|
922
|
+
obj.m_PosDecoders,
|
|
923
|
+
obj.rep0 - posSlot - 1,
|
|
924
|
+
obj.m_RangeDecoder,
|
|
925
|
+
numDirectBits
|
|
926
|
+
);
|
|
927
|
+
} else {
|
|
928
|
+
obj.rep0 += $DecodeDirectBits(
|
|
929
|
+
obj.m_RangeDecoder,
|
|
930
|
+
numDirectBits - 4
|
|
931
|
+
) << 4;
|
|
932
|
+
obj.rep0 += $ReverseDecode(
|
|
933
|
+
obj.m_PosAlignDecoder,
|
|
934
|
+
obj.m_RangeDecoder
|
|
935
|
+
);
|
|
936
|
+
if (obj.rep0 < 0) {
|
|
937
|
+
if (obj.rep0 == -1) {
|
|
938
|
+
return 1;
|
|
905
939
|
}
|
|
906
|
-
}
|
|
907
|
-
if (compare(fromInt(obj.rep0), obj.nowPos64) >= 0
|
|
908
|
-
|| obj.rep0 >= obj.m_DictionarySizeCheck) {
|
|
909
940
|
return -1;
|
|
941
|
+
}
|
|
910
942
|
}
|
|
911
|
-
|
|
912
|
-
obj.
|
|
913
|
-
|
|
943
|
+
} else {
|
|
944
|
+
obj.rep0 = posSlot;
|
|
945
|
+
}
|
|
914
946
|
}
|
|
915
|
-
|
|
947
|
+
if (compare(fromInt(obj.rep0), obj.nowPos64) >= 0 || obj.rep0 >= obj.m_DictionarySizeCheck) {
|
|
948
|
+
return -1;
|
|
949
|
+
}
|
|
950
|
+
$CopyBlock(obj.m_OutWindow, obj.rep0, len);
|
|
951
|
+
obj.nowPos64 = add(obj.nowPos64, fromInt(len));
|
|
952
|
+
obj.prevByte = $GetByte(obj.m_OutWindow, 0);
|
|
953
|
+
}
|
|
954
|
+
return 0;
|
|
916
955
|
}
|
|
917
956
|
function $Decoder(obj) {
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
957
|
+
obj.m_OutWindow = {};
|
|
958
|
+
obj.m_RangeDecoder = {};
|
|
959
|
+
obj.m_IsMatchDecoders = initArr(192);
|
|
960
|
+
obj.m_IsRepDecoders = initArr(12);
|
|
961
|
+
obj.m_IsRepG0Decoders = initArr(12);
|
|
962
|
+
obj.m_IsRepG1Decoders = initArr(12);
|
|
963
|
+
obj.m_IsRepG2Decoders = initArr(12);
|
|
964
|
+
obj.m_IsRep0LongDecoders = initArr(192);
|
|
965
|
+
obj.m_PosSlotDecoder = initArr(4);
|
|
966
|
+
obj.m_PosDecoders = initArr(114);
|
|
967
|
+
obj.m_PosAlignDecoder = $BitTreeDecoder({}, 4);
|
|
968
|
+
obj.m_LenDecoder = $Decoder$LenDecoder({});
|
|
969
|
+
obj.m_RepLenDecoder = $Decoder$LenDecoder({});
|
|
970
|
+
obj.m_LiteralDecoder = {};
|
|
971
|
+
for (let i = 0; i < 4; ++i) {
|
|
972
|
+
obj.m_PosSlotDecoder[i] = $BitTreeDecoder({}, 6);
|
|
973
|
+
}
|
|
974
|
+
return obj;
|
|
936
975
|
}
|
|
937
976
|
function $Init_1(obj) {
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
977
|
+
obj.m_OutWindow._streamPos = 0;
|
|
978
|
+
obj.m_OutWindow._pos = 0;
|
|
979
|
+
InitBitModels(obj.m_IsMatchDecoders);
|
|
980
|
+
InitBitModels(obj.m_IsRep0LongDecoders);
|
|
981
|
+
InitBitModels(obj.m_IsRepDecoders);
|
|
982
|
+
InitBitModels(obj.m_IsRepG0Decoders);
|
|
983
|
+
InitBitModels(obj.m_IsRepG1Decoders);
|
|
984
|
+
InitBitModels(obj.m_IsRepG2Decoders);
|
|
985
|
+
InitBitModels(obj.m_PosDecoders);
|
|
986
|
+
$Init_0(obj.m_LiteralDecoder);
|
|
987
|
+
for (let i = 0; i < 4; ++i) {
|
|
988
|
+
InitBitModels(obj.m_PosSlotDecoder[i].Models);
|
|
989
|
+
}
|
|
990
|
+
$Init(obj.m_LenDecoder);
|
|
991
|
+
$Init(obj.m_RepLenDecoder);
|
|
992
|
+
InitBitModels(obj.m_PosAlignDecoder.Models);
|
|
993
|
+
$Init_8(obj.m_RangeDecoder);
|
|
955
994
|
}
|
|
956
995
|
function $SetDecoderProperties(obj, properties) {
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
return $SetDictionarySize(obj, dictionarySize);
|
|
996
|
+
var dictionarySize, i, lc, lp, pb, remainder, val;
|
|
997
|
+
if (properties.length < 5) {
|
|
998
|
+
return 0;
|
|
999
|
+
}
|
|
1000
|
+
val = properties[0] & 255;
|
|
1001
|
+
lc = val % 9;
|
|
1002
|
+
remainder = ~~(val / 9);
|
|
1003
|
+
lp = remainder % 5;
|
|
1004
|
+
pb = ~~(remainder / 5);
|
|
1005
|
+
dictionarySize = 0;
|
|
1006
|
+
for (i = 0; i < 4; ++i) {
|
|
1007
|
+
dictionarySize += (properties[1 + i] & 255) << i * 8;
|
|
1008
|
+
}
|
|
1009
|
+
if (dictionarySize > 99999999 || !$SetLcLpPb(obj, lc, lp, pb)) {
|
|
1010
|
+
return 0;
|
|
1011
|
+
}
|
|
1012
|
+
return $SetDictionarySize(obj, dictionarySize);
|
|
975
1013
|
}
|
|
976
1014
|
function $SetDictionarySize(obj, dictionarySize) {
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1015
|
+
if (dictionarySize < 0) {
|
|
1016
|
+
return 0;
|
|
1017
|
+
}
|
|
1018
|
+
if (obj.m_DictionarySize != dictionarySize) {
|
|
1019
|
+
obj.m_DictionarySize = dictionarySize;
|
|
1020
|
+
obj.m_DictionarySizeCheck = Math.max(
|
|
1021
|
+
obj.m_DictionarySize,
|
|
1022
|
+
1
|
|
1023
|
+
);
|
|
1024
|
+
$Create_5(
|
|
1025
|
+
obj.m_OutWindow,
|
|
1026
|
+
Math.max(obj.m_DictionarySizeCheck, 4096)
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
return 1;
|
|
986
1030
|
}
|
|
987
1031
|
function $SetLcLpPb(obj, lc, lp, pb) {
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1032
|
+
if (lc > 8 || lp > 4 || pb > 4) {
|
|
1033
|
+
return 0;
|
|
1034
|
+
}
|
|
1035
|
+
$Create_0(obj.m_LiteralDecoder, lp, lc);
|
|
1036
|
+
var numPosStates = 1 << pb;
|
|
1037
|
+
$Create(obj.m_LenDecoder, numPosStates);
|
|
1038
|
+
$Create(obj.m_RepLenDecoder, numPosStates);
|
|
1039
|
+
obj.m_PosStateMask = numPosStates - 1;
|
|
1040
|
+
return 1;
|
|
997
1041
|
}
|
|
998
1042
|
function $Create(obj, numPosStates) {
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1043
|
+
for (; obj.m_NumPosStates < numPosStates; obj.m_NumPosStates += 1) {
|
|
1044
|
+
obj.m_LowCoder[obj.m_NumPosStates] = $BitTreeDecoder({}, 3);
|
|
1045
|
+
obj.m_MidCoder[obj.m_NumPosStates] = $BitTreeDecoder({}, 3);
|
|
1046
|
+
}
|
|
1003
1047
|
}
|
|
1004
1048
|
function $Decode(obj, rangeDecoder, posState) {
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
return symbol;
|
|
1049
|
+
if (!decodeBit(rangeDecoder, obj.m_Choice, 0)) {
|
|
1050
|
+
return $Decode_0(obj.m_LowCoder[posState], rangeDecoder);
|
|
1051
|
+
}
|
|
1052
|
+
let symbol = 8;
|
|
1053
|
+
if (!decodeBit(rangeDecoder, obj.m_Choice, 1)) {
|
|
1054
|
+
symbol += $Decode_0(obj.m_MidCoder[posState], rangeDecoder);
|
|
1055
|
+
} else {
|
|
1056
|
+
symbol += 8 + $Decode_0(obj.m_HighCoder, rangeDecoder);
|
|
1057
|
+
}
|
|
1058
|
+
return symbol;
|
|
1016
1059
|
}
|
|
1017
1060
|
function $Decoder$LenDecoder(obj) {
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1061
|
+
obj.m_Choice = initArr(2);
|
|
1062
|
+
obj.m_LowCoder = initArr(16);
|
|
1063
|
+
obj.m_MidCoder = initArr(16);
|
|
1064
|
+
obj.m_HighCoder = $BitTreeDecoder({}, 8);
|
|
1065
|
+
obj.m_NumPosStates = 0;
|
|
1066
|
+
return obj;
|
|
1024
1067
|
}
|
|
1025
1068
|
function $Init(obj) {
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1069
|
+
InitBitModels(obj.m_Choice);
|
|
1070
|
+
for (let posState = 0; posState < obj.m_NumPosStates; ++posState) {
|
|
1071
|
+
InitBitModels(obj.m_LowCoder[posState].Models);
|
|
1072
|
+
InitBitModels(obj.m_MidCoder[posState].Models);
|
|
1073
|
+
}
|
|
1074
|
+
InitBitModels(obj.m_HighCoder.Models);
|
|
1032
1075
|
}
|
|
1033
1076
|
function $Create_0(obj, numPosBits, numPrevBits) {
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
obj.m_Coders =
|
|
1045
|
-
|
|
1046
|
-
obj.m_Coders[i] = $Decoder$LiteralDecoder$Decoder2({});
|
|
1047
|
-
}
|
|
1077
|
+
var i, numStates;
|
|
1078
|
+
if (obj.m_Coders !== null && obj.m_NumPrevBits == numPrevBits && obj.m_NumPosBits == numPosBits) {
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
obj.m_NumPosBits = numPosBits;
|
|
1082
|
+
obj.m_PosMask = (1 << numPosBits) - 1;
|
|
1083
|
+
obj.m_NumPrevBits = numPrevBits;
|
|
1084
|
+
numStates = 1 << obj.m_NumPrevBits + obj.m_NumPosBits;
|
|
1085
|
+
obj.m_Coders = initArr(numStates);
|
|
1086
|
+
for (i = 0; i < numStates; ++i) {
|
|
1087
|
+
obj.m_Coders[i] = $Decoder$LiteralDecoder$Decoder2({});
|
|
1088
|
+
}
|
|
1048
1089
|
}
|
|
1049
1090
|
function $GetDecoder(obj, pos, prevByte) {
|
|
1050
|
-
|
|
1051
|
-
.m_Coders[((pos & obj.m_PosMask) << obj.m_NumPrevBits)
|
|
1052
|
-
+ ((prevByte & 255) >>> 8 - obj.m_NumPrevBits)];
|
|
1091
|
+
return obj.m_Coders[((pos & obj.m_PosMask) << obj.m_NumPrevBits) + ((prevByte & 255) >>> 8 - obj.m_NumPrevBits)];
|
|
1053
1092
|
}
|
|
1054
1093
|
function $Init_0(obj) {
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1094
|
+
var i, numStates;
|
|
1095
|
+
numStates = 1 << obj.m_NumPrevBits + obj.m_NumPosBits;
|
|
1096
|
+
for (i = 0; i < numStates; ++i) {
|
|
1097
|
+
InitBitModels(obj.m_Coders[i].m_Decoders);
|
|
1098
|
+
}
|
|
1060
1099
|
}
|
|
1061
1100
|
function $DecodeNormal(obj, rangeDecoder) {
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1101
|
+
var symbol = 1;
|
|
1102
|
+
do {
|
|
1103
|
+
symbol = symbol << 1 | decodeBit(rangeDecoder, obj.m_Decoders, symbol);
|
|
1104
|
+
} while (symbol < 256);
|
|
1105
|
+
return symbol << 24 >> 24;
|
|
1067
1106
|
}
|
|
1068
1107
|
function $DecodeWithMatchByte(obj, rangeDecoder, matchByte) {
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1108
|
+
var bit, matchBit, symbol = 1;
|
|
1109
|
+
do {
|
|
1110
|
+
matchBit = matchByte >> 7 & 1;
|
|
1111
|
+
matchByte <<= 1;
|
|
1112
|
+
bit = decodeBit(
|
|
1113
|
+
rangeDecoder,
|
|
1114
|
+
obj.m_Decoders,
|
|
1115
|
+
(1 + matchBit << 8) + symbol
|
|
1116
|
+
);
|
|
1117
|
+
symbol = symbol << 1 | bit;
|
|
1118
|
+
if (matchBit != bit) {
|
|
1119
|
+
while (symbol < 256) {
|
|
1120
|
+
symbol = symbol << 1 | decodeBit(rangeDecoder, obj.m_Decoders, symbol);
|
|
1121
|
+
}
|
|
1122
|
+
break;
|
|
1123
|
+
}
|
|
1124
|
+
} while (symbol < 256);
|
|
1125
|
+
return symbol << 24 >> 24;
|
|
1084
1126
|
}
|
|
1085
1127
|
function $Decoder$LiteralDecoder$Decoder2(obj) {
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
}
|
|
1089
|
-
const g_FastPos = function
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
return g_FastPos;
|
|
1128
|
+
obj.m_Decoders = initArr(768);
|
|
1129
|
+
return obj;
|
|
1130
|
+
}
|
|
1131
|
+
const g_FastPos = function() {
|
|
1132
|
+
let j, k, slotFast, c = 2, g_FastPos2 = [0, 1];
|
|
1133
|
+
for (slotFast = 2; slotFast < 22; ++slotFast) {
|
|
1134
|
+
let s = slotFast;
|
|
1135
|
+
s >>= 1;
|
|
1136
|
+
s -= 1;
|
|
1137
|
+
k = 1;
|
|
1138
|
+
k <<= s;
|
|
1139
|
+
for (j = 0; j < k; ++j, ++c) {
|
|
1140
|
+
g_FastPos2[c] = slotFast << 24 >> 24;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return g_FastPos2;
|
|
1103
1144
|
}();
|
|
1104
1145
|
function $Backward(obj, cur) {
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1146
|
+
let backCur, backMem, posMem, posPrev;
|
|
1147
|
+
obj._optimumEndIndex = cur;
|
|
1148
|
+
posMem = obj._optimum[cur].PosPrev;
|
|
1149
|
+
backMem = obj._optimum[cur].BackPrev;
|
|
1150
|
+
do {
|
|
1151
|
+
if (obj._optimum[cur].Prev1IsChar) {
|
|
1152
|
+
$MakeAsChar(obj._optimum[posMem]);
|
|
1153
|
+
obj._optimum[posMem].PosPrev = posMem - 1;
|
|
1154
|
+
if (obj._optimum[cur].Prev2) {
|
|
1155
|
+
obj._optimum[posMem - 1].Prev1IsChar = 0;
|
|
1156
|
+
obj._optimum[posMem - 1].PosPrev = obj._optimum[cur].PosPrev2;
|
|
1157
|
+
obj._optimum[posMem - 1].BackPrev = obj._optimum[cur].BackPrev2;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
posPrev = posMem;
|
|
1161
|
+
backCur = backMem;
|
|
1162
|
+
backMem = obj._optimum[posPrev].BackPrev;
|
|
1163
|
+
posMem = obj._optimum[posPrev].PosPrev;
|
|
1164
|
+
obj._optimum[posPrev].BackPrev = backCur;
|
|
1165
|
+
obj._optimum[posPrev].PosPrev = cur;
|
|
1166
|
+
cur = posPrev;
|
|
1167
|
+
} while (cur > 0);
|
|
1168
|
+
obj.backRes = obj._optimum[0].BackPrev;
|
|
1169
|
+
obj._optimumCurrentIndex = obj._optimum[0].PosPrev;
|
|
1170
|
+
return obj._optimumCurrentIndex;
|
|
1130
1171
|
}
|
|
1131
1172
|
function $BaseInit(obj) {
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1173
|
+
obj._state = 0;
|
|
1174
|
+
obj._previousByte = 0;
|
|
1175
|
+
for (let i = 0; i < 4; ++i) {
|
|
1176
|
+
obj._repDistances[i] = 0;
|
|
1177
|
+
}
|
|
1137
1178
|
}
|
|
1138
1179
|
function $CodeOneBlock(obj, inSize, outSize, finished) {
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
if (!$GetNumAvailableBytes(obj._matchFinder)) {
|
|
1156
|
-
$Flush(obj, lowBits_0(obj.nowPos64));
|
|
1157
|
-
return;
|
|
1158
|
-
}
|
|
1159
|
-
$ReadMatchDistances(obj);
|
|
1160
|
-
posState = lowBits_0(obj.nowPos64) & obj._posStateMask;
|
|
1161
|
-
$Encode_3(obj._rangeEncoder, obj._isMatch, (obj._state << 4) + posState, 0);
|
|
1162
|
-
obj._state = StateUpdateChar(obj._state);
|
|
1163
|
-
curByte = $GetIndexByte(obj._matchFinder, -obj._additionalOffset);
|
|
1164
|
-
$Encode_1($GetSubCoder(obj._literalEncoder, lowBits_0(obj.nowPos64), obj._previousByte), obj._rangeEncoder, curByte);
|
|
1165
|
-
obj._previousByte = curByte;
|
|
1166
|
-
obj._additionalOffset -= 1;
|
|
1167
|
-
obj.nowPos64 = add(obj.nowPos64, P1_longLit);
|
|
1168
|
-
}
|
|
1180
|
+
let baseVal, complexState, curByte, distance, footerBits, i, len, lenToPosState, matchByte, pos, posReduced, posSlot, posState, progressPosValuePrev, subCoder;
|
|
1181
|
+
inSize[0] = P0_longLit;
|
|
1182
|
+
outSize[0] = P0_longLit;
|
|
1183
|
+
finished[0] = 1;
|
|
1184
|
+
if (obj._inStream) {
|
|
1185
|
+
obj._matchFinder._stream = obj._inStream;
|
|
1186
|
+
$Init_5(obj._matchFinder);
|
|
1187
|
+
obj._needReleaseMFStream = 1;
|
|
1188
|
+
obj._inStream = null;
|
|
1189
|
+
}
|
|
1190
|
+
if (obj._finished) {
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
obj._finished = 1;
|
|
1194
|
+
progressPosValuePrev = obj.nowPos64;
|
|
1195
|
+
if (eq(obj.nowPos64, P0_longLit)) {
|
|
1169
1196
|
if (!$GetNumAvailableBytes(obj._matchFinder)) {
|
|
1197
|
+
$Flush(obj, lowBits_0(obj.nowPos64));
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
$ReadMatchDistances(obj);
|
|
1201
|
+
posState = lowBits_0(obj.nowPos64) & obj._posStateMask;
|
|
1202
|
+
$Encode_3(
|
|
1203
|
+
obj._rangeEncoder,
|
|
1204
|
+
obj._isMatch,
|
|
1205
|
+
(obj._state << 4) + posState,
|
|
1206
|
+
0
|
|
1207
|
+
);
|
|
1208
|
+
obj._state = StateUpdateChar(obj._state);
|
|
1209
|
+
curByte = $GetIndexByte(
|
|
1210
|
+
obj._matchFinder,
|
|
1211
|
+
-obj._additionalOffset
|
|
1212
|
+
);
|
|
1213
|
+
$Encode_1(
|
|
1214
|
+
$GetSubCoder(
|
|
1215
|
+
obj._literalEncoder,
|
|
1216
|
+
lowBits_0(obj.nowPos64),
|
|
1217
|
+
obj._previousByte
|
|
1218
|
+
),
|
|
1219
|
+
obj._rangeEncoder,
|
|
1220
|
+
curByte
|
|
1221
|
+
);
|
|
1222
|
+
obj._previousByte = curByte;
|
|
1223
|
+
obj._additionalOffset -= 1;
|
|
1224
|
+
obj.nowPos64 = add(obj.nowPos64, P1_longLit);
|
|
1225
|
+
}
|
|
1226
|
+
if (!$GetNumAvailableBytes(obj._matchFinder)) {
|
|
1227
|
+
$Flush(obj, lowBits_0(obj.nowPos64));
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
while (1) {
|
|
1231
|
+
len = $GetOptimum(obj, lowBits_0(obj.nowPos64));
|
|
1232
|
+
pos = obj.backRes;
|
|
1233
|
+
posState = lowBits_0(obj.nowPos64) & obj._posStateMask;
|
|
1234
|
+
complexState = (obj._state << 4) + posState;
|
|
1235
|
+
if (len == 1 && pos == -1) {
|
|
1236
|
+
$Encode_3(
|
|
1237
|
+
obj._rangeEncoder,
|
|
1238
|
+
obj._isMatch,
|
|
1239
|
+
complexState,
|
|
1240
|
+
0
|
|
1241
|
+
);
|
|
1242
|
+
curByte = $GetIndexByte(
|
|
1243
|
+
obj._matchFinder,
|
|
1244
|
+
-obj._additionalOffset
|
|
1245
|
+
);
|
|
1246
|
+
subCoder = $GetSubCoder(
|
|
1247
|
+
obj._literalEncoder,
|
|
1248
|
+
lowBits_0(obj.nowPos64),
|
|
1249
|
+
obj._previousByte
|
|
1250
|
+
);
|
|
1251
|
+
if (obj._state < 7) {
|
|
1252
|
+
$Encode_1(subCoder, obj._rangeEncoder, curByte);
|
|
1253
|
+
} else {
|
|
1254
|
+
matchByte = $GetIndexByte(
|
|
1255
|
+
obj._matchFinder,
|
|
1256
|
+
-obj._repDistances[0] - 1 - obj._additionalOffset
|
|
1257
|
+
);
|
|
1258
|
+
$EncodeMatched(
|
|
1259
|
+
subCoder,
|
|
1260
|
+
obj._rangeEncoder,
|
|
1261
|
+
matchByte,
|
|
1262
|
+
curByte
|
|
1263
|
+
);
|
|
1264
|
+
}
|
|
1265
|
+
obj._previousByte = curByte;
|
|
1266
|
+
obj._state = StateUpdateChar(obj._state);
|
|
1267
|
+
} else {
|
|
1268
|
+
$Encode_3(
|
|
1269
|
+
obj._rangeEncoder,
|
|
1270
|
+
obj._isMatch,
|
|
1271
|
+
complexState,
|
|
1272
|
+
1
|
|
1273
|
+
);
|
|
1274
|
+
if (pos < 4) {
|
|
1275
|
+
$Encode_3(
|
|
1276
|
+
obj._rangeEncoder,
|
|
1277
|
+
obj._isRep,
|
|
1278
|
+
obj._state,
|
|
1279
|
+
1
|
|
1280
|
+
);
|
|
1281
|
+
if (!pos) {
|
|
1282
|
+
$Encode_3(
|
|
1283
|
+
obj._rangeEncoder,
|
|
1284
|
+
obj._isRepG0,
|
|
1285
|
+
obj._state,
|
|
1286
|
+
0
|
|
1287
|
+
);
|
|
1288
|
+
if (len == 1) {
|
|
1289
|
+
$Encode_3(
|
|
1290
|
+
obj._rangeEncoder,
|
|
1291
|
+
obj._isRep0Long,
|
|
1292
|
+
complexState,
|
|
1293
|
+
0
|
|
1294
|
+
);
|
|
1295
|
+
} else {
|
|
1296
|
+
$Encode_3(
|
|
1297
|
+
obj._rangeEncoder,
|
|
1298
|
+
obj._isRep0Long,
|
|
1299
|
+
complexState,
|
|
1300
|
+
1
|
|
1301
|
+
);
|
|
1302
|
+
}
|
|
1303
|
+
} else {
|
|
1304
|
+
$Encode_3(
|
|
1305
|
+
obj._rangeEncoder,
|
|
1306
|
+
obj._isRepG0,
|
|
1307
|
+
obj._state,
|
|
1308
|
+
1
|
|
1309
|
+
);
|
|
1310
|
+
if (pos == 1) {
|
|
1311
|
+
$Encode_3(
|
|
1312
|
+
obj._rangeEncoder,
|
|
1313
|
+
obj._isRepG1,
|
|
1314
|
+
obj._state,
|
|
1315
|
+
0
|
|
1316
|
+
);
|
|
1317
|
+
} else {
|
|
1318
|
+
$Encode_3(
|
|
1319
|
+
obj._rangeEncoder,
|
|
1320
|
+
obj._isRepG1,
|
|
1321
|
+
obj._state,
|
|
1322
|
+
1
|
|
1323
|
+
);
|
|
1324
|
+
$Encode_3(
|
|
1325
|
+
obj._rangeEncoder,
|
|
1326
|
+
obj._isRepG2,
|
|
1327
|
+
obj._state,
|
|
1328
|
+
pos - 2
|
|
1329
|
+
);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
if (len == 1) {
|
|
1333
|
+
obj._state = obj._state < 7 ? 9 : 11;
|
|
1334
|
+
} else {
|
|
1335
|
+
$Encode_0(
|
|
1336
|
+
obj._repMatchLenEncoder,
|
|
1337
|
+
obj._rangeEncoder,
|
|
1338
|
+
len - 2,
|
|
1339
|
+
posState
|
|
1340
|
+
);
|
|
1341
|
+
obj._state = obj._state < 7 ? 8 : 11;
|
|
1342
|
+
}
|
|
1343
|
+
distance = obj._repDistances[pos];
|
|
1344
|
+
if (pos != 0) {
|
|
1345
|
+
for (let i2 = pos; i2 >= 1; --i2) {
|
|
1346
|
+
obj._repDistances[i2] = obj._repDistances[i2 - 1];
|
|
1347
|
+
}
|
|
1348
|
+
obj._repDistances[0] = distance;
|
|
1349
|
+
}
|
|
1350
|
+
} else {
|
|
1351
|
+
$Encode_3(
|
|
1352
|
+
obj._rangeEncoder,
|
|
1353
|
+
obj._isRep,
|
|
1354
|
+
obj._state,
|
|
1355
|
+
0
|
|
1356
|
+
);
|
|
1357
|
+
obj._state = obj._state < 7 ? 7 : 10;
|
|
1358
|
+
$Encode_0(
|
|
1359
|
+
obj._lenEncoder,
|
|
1360
|
+
obj._rangeEncoder,
|
|
1361
|
+
len - 2,
|
|
1362
|
+
posState
|
|
1363
|
+
);
|
|
1364
|
+
pos -= 4;
|
|
1365
|
+
posSlot = GetPosSlot(pos);
|
|
1366
|
+
lenToPosState = GetLenToPosState(len);
|
|
1367
|
+
$Encode_2(
|
|
1368
|
+
obj._posSlotEncoder[lenToPosState],
|
|
1369
|
+
obj._rangeEncoder,
|
|
1370
|
+
posSlot
|
|
1371
|
+
);
|
|
1372
|
+
if (posSlot >= 4) {
|
|
1373
|
+
footerBits = (posSlot >> 1) - 1;
|
|
1374
|
+
baseVal = (2 | posSlot & 1) << footerBits;
|
|
1375
|
+
posReduced = pos - baseVal;
|
|
1376
|
+
if (posSlot < 14) {
|
|
1377
|
+
ReverseEncode(
|
|
1378
|
+
obj._posEncoders,
|
|
1379
|
+
baseVal - posSlot - 1,
|
|
1380
|
+
obj._rangeEncoder,
|
|
1381
|
+
footerBits,
|
|
1382
|
+
posReduced
|
|
1383
|
+
);
|
|
1384
|
+
} else {
|
|
1385
|
+
$EncodeDirectBits(
|
|
1386
|
+
obj._rangeEncoder,
|
|
1387
|
+
posReduced >> 4,
|
|
1388
|
+
footerBits - 4
|
|
1389
|
+
);
|
|
1390
|
+
$ReverseEncode(
|
|
1391
|
+
obj._posAlignEncoder,
|
|
1392
|
+
obj._rangeEncoder,
|
|
1393
|
+
posReduced & 15
|
|
1394
|
+
);
|
|
1395
|
+
obj._alignPriceCount += 1;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
distance = pos;
|
|
1399
|
+
for (let i2 = 3; i2 >= 1; --i2) {
|
|
1400
|
+
obj._repDistances[i2] = obj._repDistances[i2 - 1];
|
|
1401
|
+
}
|
|
1402
|
+
obj._repDistances[0] = distance;
|
|
1403
|
+
obj._matchPriceCount += 1;
|
|
1404
|
+
}
|
|
1405
|
+
obj._previousByte = $GetIndexByte(
|
|
1406
|
+
obj._matchFinder,
|
|
1407
|
+
len - 1 - obj._additionalOffset
|
|
1408
|
+
);
|
|
1409
|
+
}
|
|
1410
|
+
obj._additionalOffset -= len;
|
|
1411
|
+
obj.nowPos64 = add(obj.nowPos64, fromInt(len));
|
|
1412
|
+
if (!obj._additionalOffset) {
|
|
1413
|
+
if (obj._matchPriceCount >= 128) {
|
|
1414
|
+
$FillDistancesPrices(obj);
|
|
1415
|
+
}
|
|
1416
|
+
if (obj._alignPriceCount >= 16) {
|
|
1417
|
+
$FillAlignPrices(obj);
|
|
1418
|
+
}
|
|
1419
|
+
inSize[0] = obj.nowPos64;
|
|
1420
|
+
outSize[0] = $GetProcessedSizeAdd(obj._rangeEncoder);
|
|
1421
|
+
if (!$GetNumAvailableBytes(obj._matchFinder)) {
|
|
1170
1422
|
$Flush(obj, lowBits_0(obj.nowPos64));
|
|
1171
1423
|
return;
|
|
1424
|
+
}
|
|
1425
|
+
if (compare(
|
|
1426
|
+
sub(obj.nowPos64, progressPosValuePrev),
|
|
1427
|
+
[4096, 0]
|
|
1428
|
+
) >= 0) {
|
|
1429
|
+
obj._finished = 0;
|
|
1430
|
+
finished[0] = 0;
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1172
1433
|
}
|
|
1173
|
-
|
|
1174
|
-
len = $GetOptimum(obj, lowBits_0(obj.nowPos64));
|
|
1175
|
-
pos = obj.backRes;
|
|
1176
|
-
posState = lowBits_0(obj.nowPos64) & obj._posStateMask;
|
|
1177
|
-
complexState = (obj._state << 4) + posState;
|
|
1178
|
-
if (len == 1 && pos == -1) {
|
|
1179
|
-
$Encode_3(obj._rangeEncoder, obj._isMatch, complexState, 0);
|
|
1180
|
-
curByte = $GetIndexByte(obj._matchFinder, -obj._additionalOffset);
|
|
1181
|
-
subCoder = $GetSubCoder(obj._literalEncoder, lowBits_0(obj.nowPos64), obj._previousByte);
|
|
1182
|
-
if (obj._state < 7) {
|
|
1183
|
-
$Encode_1(subCoder, obj._rangeEncoder, curByte);
|
|
1184
|
-
}
|
|
1185
|
-
else {
|
|
1186
|
-
matchByte = $GetIndexByte(obj._matchFinder, -obj._repDistances[0] - 1 - obj._additionalOffset);
|
|
1187
|
-
$EncodeMatched(subCoder, obj._rangeEncoder, matchByte, curByte);
|
|
1188
|
-
}
|
|
1189
|
-
obj._previousByte = curByte;
|
|
1190
|
-
obj._state = StateUpdateChar(obj._state);
|
|
1191
|
-
}
|
|
1192
|
-
else {
|
|
1193
|
-
$Encode_3(obj._rangeEncoder, obj._isMatch, complexState, 1);
|
|
1194
|
-
if (pos < 4) {
|
|
1195
|
-
$Encode_3(obj._rangeEncoder, obj._isRep, obj._state, 1);
|
|
1196
|
-
if (!pos) {
|
|
1197
|
-
$Encode_3(obj._rangeEncoder, obj._isRepG0, obj._state, 0);
|
|
1198
|
-
if (len == 1) {
|
|
1199
|
-
$Encode_3(obj._rangeEncoder, obj._isRep0Long, complexState, 0);
|
|
1200
|
-
}
|
|
1201
|
-
else {
|
|
1202
|
-
$Encode_3(obj._rangeEncoder, obj._isRep0Long, complexState, 1);
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
else {
|
|
1206
|
-
$Encode_3(obj._rangeEncoder, obj._isRepG0, obj._state, 1);
|
|
1207
|
-
if (pos == 1) {
|
|
1208
|
-
$Encode_3(obj._rangeEncoder, obj._isRepG1, obj._state, 0);
|
|
1209
|
-
}
|
|
1210
|
-
else {
|
|
1211
|
-
$Encode_3(obj._rangeEncoder, obj._isRepG1, obj._state, 1);
|
|
1212
|
-
$Encode_3(obj._rangeEncoder, obj._isRepG2, obj._state, pos - 2);
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
if (len == 1) {
|
|
1216
|
-
obj._state = obj._state < 7 ? 9 : 11;
|
|
1217
|
-
}
|
|
1218
|
-
else {
|
|
1219
|
-
$Encode_0(obj._repMatchLenEncoder, obj._rangeEncoder, len - 2, posState);
|
|
1220
|
-
obj._state = obj._state < 7 ? 8 : 11;
|
|
1221
|
-
}
|
|
1222
|
-
distance = obj._repDistances[pos];
|
|
1223
|
-
if (pos != 0) {
|
|
1224
|
-
for (let i = pos; i >= 1; --i) {
|
|
1225
|
-
obj._repDistances[i] = obj._repDistances[i - 1];
|
|
1226
|
-
}
|
|
1227
|
-
obj._repDistances[0] = distance;
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
else {
|
|
1231
|
-
$Encode_3(obj._rangeEncoder, obj._isRep, obj._state, 0);
|
|
1232
|
-
obj._state = obj._state < 7 ? 7 : 10;
|
|
1233
|
-
$Encode_0(obj._lenEncoder, obj._rangeEncoder, len - 2, posState);
|
|
1234
|
-
pos -= 4;
|
|
1235
|
-
posSlot = GetPosSlot(pos);
|
|
1236
|
-
lenToPosState = GetLenToPosState(len);
|
|
1237
|
-
$Encode_2(obj._posSlotEncoder[lenToPosState], obj._rangeEncoder, posSlot);
|
|
1238
|
-
if (posSlot >= 4) {
|
|
1239
|
-
footerBits = (posSlot >> 1) - 1;
|
|
1240
|
-
baseVal = (2 | posSlot & 1) << footerBits;
|
|
1241
|
-
posReduced = pos - baseVal;
|
|
1242
|
-
if (posSlot < 14) {
|
|
1243
|
-
ReverseEncode(obj._posEncoders, baseVal - posSlot - 1, obj._rangeEncoder, footerBits, posReduced);
|
|
1244
|
-
}
|
|
1245
|
-
else {
|
|
1246
|
-
$EncodeDirectBits(obj._rangeEncoder, posReduced >> 4, footerBits - 4);
|
|
1247
|
-
$ReverseEncode(obj._posAlignEncoder, obj._rangeEncoder, posReduced & 15);
|
|
1248
|
-
obj._alignPriceCount += 1;
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
distance = pos;
|
|
1252
|
-
for (let i = 3; i >= 1; --i) {
|
|
1253
|
-
obj._repDistances[i] = obj._repDistances[i - 1];
|
|
1254
|
-
}
|
|
1255
|
-
obj._repDistances[0] = distance;
|
|
1256
|
-
obj._matchPriceCount += 1;
|
|
1257
|
-
}
|
|
1258
|
-
obj._previousByte = $GetIndexByte(obj._matchFinder, len - 1 - obj._additionalOffset);
|
|
1259
|
-
}
|
|
1260
|
-
obj._additionalOffset -= len;
|
|
1261
|
-
obj.nowPos64 = add(obj.nowPos64, fromInt(len));
|
|
1262
|
-
if (!obj._additionalOffset) {
|
|
1263
|
-
if (obj._matchPriceCount >= 128) {
|
|
1264
|
-
$FillDistancesPrices(obj);
|
|
1265
|
-
}
|
|
1266
|
-
if (obj._alignPriceCount >= 16) {
|
|
1267
|
-
$FillAlignPrices(obj);
|
|
1268
|
-
}
|
|
1269
|
-
inSize[0] = obj.nowPos64;
|
|
1270
|
-
outSize[0] = $GetProcessedSizeAdd(obj._rangeEncoder);
|
|
1271
|
-
if (!$GetNumAvailableBytes(obj._matchFinder)) {
|
|
1272
|
-
$Flush(obj, lowBits_0(obj.nowPos64));
|
|
1273
|
-
return;
|
|
1274
|
-
}
|
|
1275
|
-
if (compare(sub(obj.nowPos64, progressPosValuePrev), [4096, 0]) >= 0) {
|
|
1276
|
-
obj._finished = 0;
|
|
1277
|
-
finished[0] = 0;
|
|
1278
|
-
return;
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1434
|
+
}
|
|
1282
1435
|
}
|
|
1283
1436
|
function $Create_2(obj) {
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1437
|
+
var bt, numHashBytes;
|
|
1438
|
+
if (!obj._matchFinder) {
|
|
1439
|
+
bt = {};
|
|
1440
|
+
numHashBytes = 4;
|
|
1441
|
+
if (!obj._matchFinderType) {
|
|
1442
|
+
numHashBytes = 2;
|
|
1443
|
+
}
|
|
1444
|
+
$SetType(bt, numHashBytes);
|
|
1445
|
+
obj._matchFinder = bt;
|
|
1446
|
+
}
|
|
1447
|
+
$Create_1(
|
|
1448
|
+
obj._literalEncoder,
|
|
1449
|
+
obj._numLiteralPosStateBits,
|
|
1450
|
+
obj._numLiteralContextBits
|
|
1451
|
+
);
|
|
1452
|
+
if (obj._dictionarySize == obj._dictionarySizePrev && obj._numFastBytesPrev == obj._numFastBytes) {
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1455
|
+
$Create_3(
|
|
1456
|
+
obj._matchFinder,
|
|
1457
|
+
obj._dictionarySize,
|
|
1458
|
+
4096,
|
|
1459
|
+
obj._numFastBytes,
|
|
1460
|
+
274
|
|
1461
|
+
);
|
|
1462
|
+
obj._dictionarySizePrev = obj._dictionarySize;
|
|
1463
|
+
obj._numFastBytesPrev = obj._numFastBytes;
|
|
1302
1464
|
}
|
|
1303
1465
|
function $Encoder() {
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1466
|
+
const obj = {
|
|
1467
|
+
_repDistances: initArr(4),
|
|
1468
|
+
_optimum: [],
|
|
1469
|
+
_rangeEncoder: {},
|
|
1470
|
+
_isMatch: initArr(192),
|
|
1471
|
+
_isRep: initArr(12),
|
|
1472
|
+
_isRepG0: initArr(12),
|
|
1473
|
+
_isRepG1: initArr(12),
|
|
1474
|
+
_isRepG2: initArr(12),
|
|
1475
|
+
_isRep0Long: initArr(192),
|
|
1476
|
+
_posSlotEncoder: [],
|
|
1477
|
+
_posEncoders: initArr(114),
|
|
1478
|
+
_posAlignEncoder: bitTreeEncoder({}, 4),
|
|
1479
|
+
_lenEncoder: $Encoder$LenPriceTableEncoder({}),
|
|
1480
|
+
_repMatchLenEncoder: $Encoder$LenPriceTableEncoder({}),
|
|
1481
|
+
_literalEncoder: {},
|
|
1482
|
+
_matchDistances: [],
|
|
1483
|
+
_posSlotPrices: [],
|
|
1484
|
+
_distancesPrices: [],
|
|
1485
|
+
_alignPrices: initArr(16),
|
|
1486
|
+
reps: initArr(4),
|
|
1487
|
+
repLens: initArr(4),
|
|
1488
|
+
processedInSize: [P0_longLit],
|
|
1489
|
+
processedOutSize: [P0_longLit],
|
|
1490
|
+
finished: [0],
|
|
1491
|
+
properties: initArr(5),
|
|
1492
|
+
tempPrices: initArr(128),
|
|
1493
|
+
_longestMatchLength: 0,
|
|
1494
|
+
_matchFinderType: 1,
|
|
1495
|
+
_numDistancePairs: 0,
|
|
1496
|
+
_numFastBytesPrev: -1,
|
|
1497
|
+
backRes: 0
|
|
1498
|
+
};
|
|
1499
|
+
for (let i = 0; i < 4096; ++i) {
|
|
1500
|
+
obj._optimum[i] = {};
|
|
1501
|
+
}
|
|
1502
|
+
for (let i = 0; i < 4; ++i) {
|
|
1503
|
+
obj._posSlotEncoder[i] = bitTreeEncoder({}, 6);
|
|
1504
|
+
}
|
|
1505
|
+
return obj;
|
|
1344
1506
|
}
|
|
1345
1507
|
function $FillAlignPrices(obj) {
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1508
|
+
for (let i = 0; i < 16; ++i) {
|
|
1509
|
+
obj._alignPrices[i] = $ReverseGetPrice(obj._posAlignEncoder, i);
|
|
1510
|
+
}
|
|
1511
|
+
obj._alignPriceCount = 0;
|
|
1350
1512
|
}
|
|
1351
1513
|
function $FillDistancesPrices(obj) {
|
|
1352
|
-
|
|
1514
|
+
var baseVal, encoder, footerBits, posSlot, st, st2;
|
|
1515
|
+
for (let i = 4; i < 128; ++i) {
|
|
1516
|
+
posSlot = GetPosSlot(i);
|
|
1517
|
+
footerBits = (posSlot >> 1) - 1;
|
|
1518
|
+
baseVal = (2 | posSlot & 1) << footerBits;
|
|
1519
|
+
obj.tempPrices[i] = ReverseGetPrice(
|
|
1520
|
+
obj._posEncoders,
|
|
1521
|
+
baseVal - posSlot - 1,
|
|
1522
|
+
footerBits,
|
|
1523
|
+
i - baseVal
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
for (let lenToPosState = 0; lenToPosState < 4; ++lenToPosState) {
|
|
1527
|
+
encoder = obj._posSlotEncoder[lenToPosState];
|
|
1528
|
+
st = lenToPosState << 6;
|
|
1529
|
+
for (posSlot = 0; posSlot < obj._distTableSize; posSlot += 1) {
|
|
1530
|
+
obj._posSlotPrices[st + posSlot] = $GetPrice_1(
|
|
1531
|
+
encoder,
|
|
1532
|
+
posSlot
|
|
1533
|
+
);
|
|
1534
|
+
}
|
|
1535
|
+
for (posSlot = 14; posSlot < obj._distTableSize; posSlot += 1) {
|
|
1536
|
+
obj._posSlotPrices[st + posSlot] += (posSlot >> 1) - 1 - 4 << 6;
|
|
1537
|
+
}
|
|
1538
|
+
st2 = lenToPosState * 128;
|
|
1539
|
+
for (let i = 0; i < 4; ++i) {
|
|
1540
|
+
obj._distancesPrices[st2 + i] = obj._posSlotPrices[st + i];
|
|
1541
|
+
}
|
|
1353
1542
|
for (let i = 4; i < 128; ++i) {
|
|
1354
|
-
|
|
1355
|
-
footerBits = (posSlot >> 1) - 1;
|
|
1356
|
-
baseVal = (2 | posSlot & 1) << footerBits;
|
|
1357
|
-
obj.tempPrices[i] = ReverseGetPrice(obj._posEncoders, baseVal - posSlot - 1, footerBits, i - baseVal);
|
|
1358
|
-
}
|
|
1359
|
-
for (let lenToPosState = 0; lenToPosState < 4; ++lenToPosState) {
|
|
1360
|
-
encoder = obj._posSlotEncoder[lenToPosState];
|
|
1361
|
-
st = lenToPosState << 6;
|
|
1362
|
-
for (posSlot = 0; posSlot < obj._distTableSize; posSlot += 1) {
|
|
1363
|
-
obj._posSlotPrices[st + posSlot] = $GetPrice_1(encoder, posSlot);
|
|
1364
|
-
}
|
|
1365
|
-
for (posSlot = 14; posSlot < obj._distTableSize; posSlot += 1) {
|
|
1366
|
-
obj._posSlotPrices[st + posSlot] += (posSlot >> 1) - 1 - 4 << 6;
|
|
1367
|
-
}
|
|
1368
|
-
st2 = lenToPosState * 128;
|
|
1369
|
-
for (let i = 0; i < 4; ++i) {
|
|
1370
|
-
obj._distancesPrices[st2 + i] = obj._posSlotPrices[st + i];
|
|
1371
|
-
}
|
|
1372
|
-
for (let i = 4; i < 128; ++i) {
|
|
1373
|
-
obj._distancesPrices[st2 + i] =
|
|
1374
|
-
obj._posSlotPrices[st + GetPosSlot(i)] + obj.tempPrices[i];
|
|
1375
|
-
}
|
|
1543
|
+
obj._distancesPrices[st2 + i] = obj._posSlotPrices[st + GetPosSlot(i)] + obj.tempPrices[i];
|
|
1376
1544
|
}
|
|
1377
|
-
|
|
1545
|
+
}
|
|
1546
|
+
obj._matchPriceCount = 0;
|
|
1378
1547
|
}
|
|
1379
1548
|
function $Flush(obj, nowPos) {
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1549
|
+
$ReleaseMFStream(obj);
|
|
1550
|
+
$WriteEndMarker(obj, nowPos & obj._posStateMask);
|
|
1551
|
+
for (let i = 0; i < 5; ++i) {
|
|
1552
|
+
$ShiftLow(obj._rangeEncoder);
|
|
1553
|
+
}
|
|
1385
1554
|
}
|
|
1386
1555
|
function $GetOptimum(obj, position) {
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1556
|
+
let cur, curAnd1Price, curAndLenCharPrice, curAndLenPrice, curBack, curPrice, currentByte, distance, len, lenEnd, lenMain, lenTest, lenTest2, lenTestTemp, matchByte, matchPrice, newLen, nextIsChar, nextMatchPrice, nextOptimum, nextRepMatchPrice, normalMatchPrice, numAvailableBytes, numAvailableBytesFull, numDistancePairs, offs, offset, opt, optimum, pos, posPrev, posState, posStateNext, price_4, repIndex, repLen, repMatchPrice, repMaxIndex, shortRepPrice, startLen, state, state2, t, price, price_0, price_1, price_2, price_3;
|
|
1557
|
+
if (obj._optimumEndIndex != obj._optimumCurrentIndex) {
|
|
1558
|
+
const lenRes2 = obj._optimum[obj._optimumCurrentIndex].PosPrev - obj._optimumCurrentIndex;
|
|
1559
|
+
obj.backRes = obj._optimum[obj._optimumCurrentIndex].BackPrev;
|
|
1560
|
+
obj._optimumCurrentIndex = obj._optimum[obj._optimumCurrentIndex].PosPrev;
|
|
1561
|
+
return lenRes2;
|
|
1562
|
+
}
|
|
1563
|
+
obj._optimumCurrentIndex = obj._optimumEndIndex = 0;
|
|
1564
|
+
if (obj._longestMatchWasFound) {
|
|
1565
|
+
lenMain = obj._longestMatchLength;
|
|
1566
|
+
obj._longestMatchWasFound = 0;
|
|
1567
|
+
} else {
|
|
1568
|
+
lenMain = $ReadMatchDistances(obj);
|
|
1569
|
+
}
|
|
1570
|
+
numDistancePairs = obj._numDistancePairs;
|
|
1571
|
+
numAvailableBytes = $GetNumAvailableBytes(obj._matchFinder) + 1;
|
|
1572
|
+
if (numAvailableBytes < 2) {
|
|
1573
|
+
obj.backRes = -1;
|
|
1574
|
+
return 1;
|
|
1575
|
+
}
|
|
1576
|
+
if (numAvailableBytes > 273) {
|
|
1577
|
+
numAvailableBytes = 273;
|
|
1578
|
+
}
|
|
1579
|
+
repMaxIndex = 0;
|
|
1580
|
+
for (let i = 0; i < 4; ++i) {
|
|
1581
|
+
obj.reps[i] = obj._repDistances[i];
|
|
1582
|
+
obj.repLens[i] = $GetMatchLen(
|
|
1583
|
+
obj._matchFinder,
|
|
1584
|
+
-1,
|
|
1585
|
+
obj.reps[i],
|
|
1586
|
+
273
|
|
1587
|
+
);
|
|
1588
|
+
if (obj.repLens[i] > obj.repLens[repMaxIndex]) {
|
|
1589
|
+
repMaxIndex = i;
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
if (obj.repLens[repMaxIndex] >= obj._numFastBytes) {
|
|
1593
|
+
obj.backRes = repMaxIndex;
|
|
1594
|
+
lenRes = obj.repLens[repMaxIndex];
|
|
1595
|
+
$MovePos(obj, lenRes - 1);
|
|
1596
|
+
return lenRes;
|
|
1597
|
+
}
|
|
1598
|
+
if (lenMain >= obj._numFastBytes) {
|
|
1599
|
+
obj.backRes = obj._matchDistances[numDistancePairs - 1] + 4;
|
|
1600
|
+
$MovePos(obj, lenMain - 1);
|
|
1601
|
+
return lenMain;
|
|
1602
|
+
}
|
|
1603
|
+
currentByte = $GetIndexByte(obj._matchFinder, -1);
|
|
1604
|
+
matchByte = $GetIndexByte(
|
|
1605
|
+
obj._matchFinder,
|
|
1606
|
+
-obj._repDistances[0] - 1 - 1
|
|
1607
|
+
);
|
|
1608
|
+
if (lenMain < 2 && currentByte != matchByte && obj.repLens[repMaxIndex] < 2) {
|
|
1609
|
+
obj.backRes = -1;
|
|
1610
|
+
return 1;
|
|
1611
|
+
}
|
|
1612
|
+
obj._optimum[0].State = obj._state;
|
|
1613
|
+
posState = position & obj._posStateMask;
|
|
1614
|
+
obj._optimum[1].Price = ProbPrices[obj._isMatch[(obj._state << 4) + posState] >>> 2] + $GetPrice_0(
|
|
1615
|
+
$GetSubCoder(
|
|
1616
|
+
obj._literalEncoder,
|
|
1617
|
+
position,
|
|
1618
|
+
obj._previousByte
|
|
1619
|
+
),
|
|
1620
|
+
obj._state >= 7,
|
|
1621
|
+
matchByte,
|
|
1622
|
+
currentByte
|
|
1623
|
+
);
|
|
1624
|
+
$MakeAsChar(obj._optimum[1]);
|
|
1625
|
+
matchPrice = ProbPrices[2048 - obj._isMatch[(obj._state << 4) + posState] >>> 2];
|
|
1626
|
+
repMatchPrice = matchPrice + ProbPrices[2048 - obj._isRep[obj._state] >>> 2];
|
|
1627
|
+
if (matchByte == currentByte) {
|
|
1628
|
+
shortRepPrice = repMatchPrice + $GetRepLen1Price(obj, obj._state, posState);
|
|
1629
|
+
if (shortRepPrice < obj._optimum[1].Price) {
|
|
1630
|
+
obj._optimum[1].Price = shortRepPrice;
|
|
1631
|
+
$MakeAsShortRep(obj._optimum[1]);
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
lenEnd = lenMain >= obj.repLens[repMaxIndex] ? lenMain : obj.repLens[repMaxIndex];
|
|
1635
|
+
if (lenEnd < 2) {
|
|
1636
|
+
obj.backRes = obj._optimum[1].BackPrev;
|
|
1637
|
+
return 1;
|
|
1638
|
+
}
|
|
1639
|
+
obj._optimum[1].PosPrev = 0;
|
|
1640
|
+
obj._optimum[0].Backs0 = obj.reps[0];
|
|
1641
|
+
obj._optimum[0].Backs1 = obj.reps[1];
|
|
1642
|
+
obj._optimum[0].Backs2 = obj.reps[2];
|
|
1643
|
+
obj._optimum[0].Backs3 = obj.reps[3];
|
|
1644
|
+
len = lenEnd;
|
|
1645
|
+
do {
|
|
1646
|
+
obj._optimum[len].Price = 268435455;
|
|
1647
|
+
len -= 1;
|
|
1648
|
+
} while (len >= 2);
|
|
1649
|
+
for (let i = 0; i < 4; ++i) {
|
|
1650
|
+
repLen = obj.repLens[i];
|
|
1651
|
+
if (repLen < 2) {
|
|
1652
|
+
continue;
|
|
1653
|
+
}
|
|
1654
|
+
price_4 = repMatchPrice + $GetPureRepPrice(obj, i, obj._state, posState);
|
|
1655
|
+
do {
|
|
1656
|
+
curAndLenPrice = price_4 + $GetPrice(
|
|
1657
|
+
obj._repMatchLenEncoder,
|
|
1658
|
+
repLen - 2,
|
|
1659
|
+
posState
|
|
1660
|
+
);
|
|
1661
|
+
optimum = obj._optimum[repLen];
|
|
1662
|
+
if (curAndLenPrice < optimum.Price) {
|
|
1663
|
+
optimum.Price = curAndLenPrice;
|
|
1664
|
+
optimum.PosPrev = 0;
|
|
1665
|
+
optimum.BackPrev = i;
|
|
1666
|
+
optimum.Prev1IsChar = 0;
|
|
1667
|
+
}
|
|
1668
|
+
} while ((repLen -= 1) >= 2);
|
|
1669
|
+
}
|
|
1670
|
+
normalMatchPrice = matchPrice + ProbPrices[obj._isRep[obj._state] >>> 2];
|
|
1671
|
+
len = obj.repLens[0] >= 2 ? obj.repLens[0] + 1 : 2;
|
|
1672
|
+
if (len <= lenMain) {
|
|
1673
|
+
offs = 0;
|
|
1674
|
+
while (len > obj._matchDistances[offs]) {
|
|
1675
|
+
offs += 2;
|
|
1676
|
+
}
|
|
1677
|
+
for (; ; len += 1) {
|
|
1678
|
+
distance = obj._matchDistances[offs + 1];
|
|
1679
|
+
curAndLenPrice = normalMatchPrice + $GetPosLenPrice(obj, distance, len, posState);
|
|
1680
|
+
optimum = obj._optimum[len];
|
|
1681
|
+
if (curAndLenPrice < optimum.Price) {
|
|
1682
|
+
optimum.Price = curAndLenPrice;
|
|
1683
|
+
optimum.PosPrev = 0;
|
|
1684
|
+
optimum.BackPrev = distance + 4;
|
|
1685
|
+
optimum.Prev1IsChar = 0;
|
|
1686
|
+
}
|
|
1687
|
+
if (len == obj._matchDistances[offs]) {
|
|
1688
|
+
offs += 2;
|
|
1689
|
+
if (offs == numDistancePairs) {
|
|
1690
|
+
break;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
cur = 0;
|
|
1696
|
+
while (1) {
|
|
1697
|
+
;
|
|
1698
|
+
++cur;
|
|
1699
|
+
if (cur == lenEnd) {
|
|
1700
|
+
return $Backward(obj, cur);
|
|
1403
1701
|
}
|
|
1702
|
+
newLen = $ReadMatchDistances(obj);
|
|
1404
1703
|
numDistancePairs = obj._numDistancePairs;
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
obj.
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1704
|
+
if (newLen >= obj._numFastBytes) {
|
|
1705
|
+
obj._longestMatchLength = newLen;
|
|
1706
|
+
obj._longestMatchWasFound = 1;
|
|
1707
|
+
return $Backward(obj, cur);
|
|
1708
|
+
}
|
|
1709
|
+
position += 1;
|
|
1710
|
+
posPrev = obj._optimum[cur].PosPrev;
|
|
1711
|
+
if (obj._optimum[cur].Prev1IsChar) {
|
|
1712
|
+
posPrev -= 1;
|
|
1713
|
+
if (obj._optimum[cur].Prev2) {
|
|
1714
|
+
state = obj._optimum[obj._optimum[cur].PosPrev2].State;
|
|
1715
|
+
if (obj._optimum[cur].BackPrev2 < 4) {
|
|
1716
|
+
state = state < 7 ? 8 : 11;
|
|
1717
|
+
} else {
|
|
1718
|
+
state = state < 7 ? 7 : 10;
|
|
1719
|
+
}
|
|
1720
|
+
} else {
|
|
1721
|
+
state = obj._optimum[posPrev].State;
|
|
1722
|
+
}
|
|
1723
|
+
state = StateUpdateChar(state);
|
|
1724
|
+
} else {
|
|
1725
|
+
state = obj._optimum[posPrev].State;
|
|
1726
|
+
}
|
|
1727
|
+
if (posPrev == cur - 1) {
|
|
1728
|
+
if (!obj._optimum[cur].BackPrev) {
|
|
1729
|
+
state = state < 7 ? 9 : 11;
|
|
1730
|
+
} else {
|
|
1731
|
+
state = StateUpdateChar(state);
|
|
1732
|
+
}
|
|
1733
|
+
} else {
|
|
1734
|
+
if (obj._optimum[cur].Prev1IsChar && obj._optimum[cur].Prev2) {
|
|
1735
|
+
posPrev = obj._optimum[cur].PosPrev2;
|
|
1736
|
+
pos = obj._optimum[cur].BackPrev2;
|
|
1737
|
+
state = state < 7 ? 8 : 11;
|
|
1738
|
+
} else {
|
|
1739
|
+
pos = obj._optimum[cur].BackPrev;
|
|
1740
|
+
if (pos < 4) {
|
|
1741
|
+
state = state < 7 ? 8 : 11;
|
|
1742
|
+
} else {
|
|
1743
|
+
state = state < 7 ? 7 : 10;
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
opt = obj._optimum[posPrev];
|
|
1747
|
+
if (pos < 4) {
|
|
1748
|
+
if (!pos) {
|
|
1749
|
+
obj.reps[0] = opt.Backs0;
|
|
1750
|
+
obj.reps[1] = opt.Backs1;
|
|
1751
|
+
obj.reps[2] = opt.Backs2;
|
|
1752
|
+
obj.reps[3] = opt.Backs3;
|
|
1753
|
+
} else if (pos == 1) {
|
|
1754
|
+
obj.reps[0] = opt.Backs1;
|
|
1755
|
+
obj.reps[1] = opt.Backs0;
|
|
1756
|
+
obj.reps[2] = opt.Backs2;
|
|
1757
|
+
obj.reps[3] = opt.Backs3;
|
|
1758
|
+
} else if (pos == 2) {
|
|
1759
|
+
obj.reps[0] = opt.Backs2;
|
|
1760
|
+
obj.reps[1] = opt.Backs0;
|
|
1761
|
+
obj.reps[2] = opt.Backs1;
|
|
1762
|
+
obj.reps[3] = opt.Backs3;
|
|
1763
|
+
} else {
|
|
1764
|
+
obj.reps[0] = opt.Backs3;
|
|
1765
|
+
obj.reps[1] = opt.Backs0;
|
|
1766
|
+
obj.reps[2] = opt.Backs1;
|
|
1767
|
+
obj.reps[3] = opt.Backs2;
|
|
1768
|
+
}
|
|
1769
|
+
} else {
|
|
1770
|
+
obj.reps[0] = pos - 4;
|
|
1771
|
+
obj.reps[1] = opt.Backs0;
|
|
1772
|
+
obj.reps[2] = opt.Backs1;
|
|
1773
|
+
obj.reps[3] = opt.Backs2;
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
obj._optimum[cur].State = state;
|
|
1777
|
+
obj._optimum[cur].Backs0 = obj.reps[0];
|
|
1778
|
+
obj._optimum[cur].Backs1 = obj.reps[1];
|
|
1779
|
+
obj._optimum[cur].Backs2 = obj.reps[2];
|
|
1780
|
+
obj._optimum[cur].Backs3 = obj.reps[3];
|
|
1781
|
+
curPrice = obj._optimum[cur].Price;
|
|
1432
1782
|
currentByte = $GetIndexByte(obj._matchFinder, -1);
|
|
1433
|
-
matchByte = $GetIndexByte(
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
}
|
|
1438
|
-
obj._optimum[0].State = obj._state;
|
|
1783
|
+
matchByte = $GetIndexByte(
|
|
1784
|
+
obj._matchFinder,
|
|
1785
|
+
-obj.reps[0] - 1 - 1
|
|
1786
|
+
);
|
|
1439
1787
|
posState = position & obj._posStateMask;
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
obj.
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
}
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1788
|
+
curAnd1Price = curPrice + ProbPrices[obj._isMatch[(state << 4) + posState] >>> 2] + $GetPrice_0(
|
|
1789
|
+
$GetSubCoder(
|
|
1790
|
+
obj._literalEncoder,
|
|
1791
|
+
position,
|
|
1792
|
+
$GetIndexByte(obj._matchFinder, -2)
|
|
1793
|
+
),
|
|
1794
|
+
state >= 7,
|
|
1795
|
+
matchByte,
|
|
1796
|
+
currentByte
|
|
1797
|
+
);
|
|
1798
|
+
nextOptimum = obj._optimum[cur + 1];
|
|
1799
|
+
nextIsChar = 0;
|
|
1800
|
+
if (curAnd1Price < nextOptimum.Price) {
|
|
1801
|
+
nextOptimum.Price = curAnd1Price;
|
|
1802
|
+
nextOptimum.PosPrev = cur;
|
|
1803
|
+
nextOptimum.BackPrev = -1;
|
|
1804
|
+
nextOptimum.Prev1IsChar = 0;
|
|
1805
|
+
nextIsChar = 1;
|
|
1806
|
+
}
|
|
1807
|
+
matchPrice = curPrice + ProbPrices[2048 - obj._isMatch[(state << 4) + posState] >>> 2];
|
|
1808
|
+
repMatchPrice = matchPrice + ProbPrices[2048 - obj._isRep[state] >>> 2];
|
|
1809
|
+
if (matchByte == currentByte && !(nextOptimum.PosPrev < cur && !nextOptimum.BackPrev)) {
|
|
1810
|
+
shortRepPrice = repMatchPrice + (ProbPrices[obj._isRepG0[state] >>> 2] + ProbPrices[obj._isRep0Long[(state << 4) + posState] >>> 2]);
|
|
1811
|
+
if (shortRepPrice <= nextOptimum.Price) {
|
|
1812
|
+
nextOptimum.Price = shortRepPrice;
|
|
1813
|
+
nextOptimum.PosPrev = cur;
|
|
1814
|
+
nextOptimum.BackPrev = 0;
|
|
1815
|
+
nextOptimum.Prev1IsChar = 0;
|
|
1816
|
+
nextIsChar = 1;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
numAvailableBytesFull = $GetNumAvailableBytes(obj._matchFinder) + 1;
|
|
1820
|
+
numAvailableBytesFull = 4095 - cur < numAvailableBytesFull ? 4095 - cur : numAvailableBytesFull;
|
|
1821
|
+
numAvailableBytes = numAvailableBytesFull;
|
|
1822
|
+
if (numAvailableBytes < 2) {
|
|
1823
|
+
continue;
|
|
1824
|
+
}
|
|
1825
|
+
if (numAvailableBytes > obj._numFastBytes) {
|
|
1826
|
+
numAvailableBytes = obj._numFastBytes;
|
|
1827
|
+
}
|
|
1828
|
+
if (!nextIsChar && matchByte != currentByte) {
|
|
1829
|
+
t = Math.min(numAvailableBytesFull - 1, obj._numFastBytes);
|
|
1830
|
+
lenTest2 = $GetMatchLen(
|
|
1831
|
+
obj._matchFinder,
|
|
1832
|
+
0,
|
|
1833
|
+
obj.reps[0],
|
|
1834
|
+
t
|
|
1835
|
+
);
|
|
1836
|
+
if (lenTest2 >= 2) {
|
|
1837
|
+
state2 = StateUpdateChar(state);
|
|
1838
|
+
posStateNext = position + 1 & obj._posStateMask;
|
|
1839
|
+
nextRepMatchPrice = curAnd1Price + ProbPrices[2048 - obj._isMatch[(state2 << 4) + posStateNext] >>> 2] + ProbPrices[2048 - obj._isRep[state2] >>> 2];
|
|
1840
|
+
offset = cur + 1 + lenTest2;
|
|
1841
|
+
while (lenEnd < offset) {
|
|
1842
|
+
obj._optimum[lenEnd += 1].Price = 268435455;
|
|
1843
|
+
}
|
|
1844
|
+
curAndLenPrice = nextRepMatchPrice + (price = $GetPrice(
|
|
1845
|
+
obj._repMatchLenEncoder,
|
|
1846
|
+
lenTest2 - 2,
|
|
1847
|
+
posStateNext
|
|
1848
|
+
), price + $GetPureRepPrice(
|
|
1849
|
+
obj,
|
|
1850
|
+
0,
|
|
1851
|
+
state2,
|
|
1852
|
+
posStateNext
|
|
1853
|
+
));
|
|
1854
|
+
optimum = obj._optimum[offset];
|
|
1855
|
+
if (curAndLenPrice < optimum.Price) {
|
|
1856
|
+
optimum.Price = curAndLenPrice;
|
|
1857
|
+
optimum.PosPrev = cur + 1;
|
|
1858
|
+
optimum.BackPrev = 0;
|
|
1859
|
+
optimum.Prev1IsChar = 1;
|
|
1860
|
+
optimum.Prev2 = 0;
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
startLen = 2;
|
|
1865
|
+
for (repIndex = 0; repIndex < 4; ++repIndex) {
|
|
1866
|
+
lenTest = $GetMatchLen(
|
|
1867
|
+
obj._matchFinder,
|
|
1868
|
+
-1,
|
|
1869
|
+
obj.reps[repIndex],
|
|
1870
|
+
numAvailableBytes
|
|
1871
|
+
);
|
|
1872
|
+
if (lenTest < 2) {
|
|
1873
|
+
continue;
|
|
1874
|
+
}
|
|
1875
|
+
lenTestTemp = lenTest;
|
|
1876
|
+
do {
|
|
1877
|
+
while (lenEnd < cur + lenTest) {
|
|
1878
|
+
obj._optimum[lenEnd += 1].Price = 268435455;
|
|
1879
|
+
}
|
|
1880
|
+
curAndLenPrice = repMatchPrice + (price_0 = $GetPrice(
|
|
1881
|
+
obj._repMatchLenEncoder,
|
|
1882
|
+
lenTest - 2,
|
|
1883
|
+
posState
|
|
1884
|
+
), price_0 + $GetPureRepPrice(
|
|
1885
|
+
obj,
|
|
1886
|
+
repIndex,
|
|
1887
|
+
state,
|
|
1888
|
+
posState
|
|
1889
|
+
));
|
|
1890
|
+
optimum = obj._optimum[cur + lenTest];
|
|
1891
|
+
if (curAndLenPrice < optimum.Price) {
|
|
1892
|
+
optimum.Price = curAndLenPrice;
|
|
1893
|
+
optimum.PosPrev = cur;
|
|
1894
|
+
optimum.BackPrev = repIndex;
|
|
1895
|
+
optimum.Prev1IsChar = 0;
|
|
1896
|
+
}
|
|
1897
|
+
} while ((lenTest -= 1) >= 2);
|
|
1898
|
+
lenTest = lenTestTemp;
|
|
1899
|
+
if (!repIndex) {
|
|
1900
|
+
startLen = lenTest + 1;
|
|
1901
|
+
}
|
|
1902
|
+
if (lenTest < numAvailableBytesFull) {
|
|
1903
|
+
t = Math.min(
|
|
1904
|
+
numAvailableBytesFull - 1 - lenTest,
|
|
1905
|
+
obj._numFastBytes
|
|
1906
|
+
);
|
|
1907
|
+
lenTest2 = $GetMatchLen(
|
|
1908
|
+
obj._matchFinder,
|
|
1909
|
+
lenTest,
|
|
1910
|
+
obj.reps[repIndex],
|
|
1911
|
+
t
|
|
1912
|
+
);
|
|
1913
|
+
if (lenTest2 >= 2) {
|
|
1914
|
+
state2 = state < 7 ? 8 : 11;
|
|
1915
|
+
posStateNext = position + lenTest & obj._posStateMask;
|
|
1916
|
+
curAndLenCharPrice = repMatchPrice + (price_1 = $GetPrice(
|
|
1917
|
+
obj._repMatchLenEncoder,
|
|
1918
|
+
lenTest - 2,
|
|
1919
|
+
posState
|
|
1920
|
+
), price_1 + $GetPureRepPrice(
|
|
1921
|
+
obj,
|
|
1922
|
+
repIndex,
|
|
1923
|
+
state,
|
|
1924
|
+
posState
|
|
1925
|
+
)) + ProbPrices[obj._isMatch[(state2 << 4) + posStateNext] >>> 2] + $GetPrice_0(
|
|
1926
|
+
$GetSubCoder(
|
|
1927
|
+
obj._literalEncoder,
|
|
1928
|
+
position + lenTest,
|
|
1929
|
+
$GetIndexByte(
|
|
1930
|
+
obj._matchFinder,
|
|
1931
|
+
lenTest - 1 - 1
|
|
1932
|
+
)
|
|
1933
|
+
),
|
|
1934
|
+
1,
|
|
1935
|
+
$GetIndexByte(
|
|
1936
|
+
obj._matchFinder,
|
|
1937
|
+
lenTest - 1 - (obj.reps[repIndex] + 1)
|
|
1938
|
+
),
|
|
1939
|
+
$GetIndexByte(obj._matchFinder, lenTest - 1)
|
|
1940
|
+
);
|
|
1941
|
+
state2 = StateUpdateChar(state2);
|
|
1942
|
+
posStateNext = position + lenTest + 1 & obj._posStateMask;
|
|
1943
|
+
nextMatchPrice = curAndLenCharPrice + ProbPrices[2048 - obj._isMatch[(state2 << 4) + posStateNext] >>> 2];
|
|
1944
|
+
nextRepMatchPrice = nextMatchPrice + ProbPrices[2048 - obj._isRep[state2] >>> 2];
|
|
1945
|
+
offset = lenTest + 1 + lenTest2;
|
|
1946
|
+
while (lenEnd < cur + offset) {
|
|
1947
|
+
obj._optimum[lenEnd += 1].Price = 268435455;
|
|
1948
|
+
}
|
|
1949
|
+
curAndLenPrice = nextRepMatchPrice + (price_2 = $GetPrice(
|
|
1950
|
+
obj._repMatchLenEncoder,
|
|
1951
|
+
lenTest2 - 2,
|
|
1952
|
+
posStateNext
|
|
1953
|
+
), price_2 + $GetPureRepPrice(
|
|
1954
|
+
obj,
|
|
1955
|
+
0,
|
|
1956
|
+
state2,
|
|
1957
|
+
posStateNext
|
|
1958
|
+
));
|
|
1959
|
+
optimum = obj._optimum[cur + offset];
|
|
1960
|
+
if (curAndLenPrice < optimum.Price) {
|
|
1961
|
+
optimum.Price = curAndLenPrice;
|
|
1962
|
+
optimum.PosPrev = cur + lenTest + 1;
|
|
1963
|
+
optimum.BackPrev = 0;
|
|
1964
|
+
optimum.Prev1IsChar = 1;
|
|
1965
|
+
optimum.Prev2 = 1;
|
|
1966
|
+
optimum.PosPrev2 = cur;
|
|
1967
|
+
optimum.BackPrev2 = repIndex;
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
if (newLen > numAvailableBytes) {
|
|
1973
|
+
newLen = numAvailableBytes;
|
|
1974
|
+
for (numDistancePairs = 0; newLen > obj._matchDistances[numDistancePairs]; numDistancePairs += 2) {
|
|
1975
|
+
}
|
|
1976
|
+
obj._matchDistances[numDistancePairs] = newLen;
|
|
1977
|
+
numDistancePairs += 2;
|
|
1978
|
+
}
|
|
1979
|
+
if (newLen >= startLen) {
|
|
1980
|
+
normalMatchPrice = matchPrice + ProbPrices[obj._isRep[state] >>> 2];
|
|
1981
|
+
while (lenEnd < cur + newLen) {
|
|
1982
|
+
obj._optimum[lenEnd += 1].Price = 268435455;
|
|
1983
|
+
}
|
|
1984
|
+
offs = 0;
|
|
1985
|
+
while (startLen > obj._matchDistances[offs]) {
|
|
1986
|
+
offs += 2;
|
|
1987
|
+
}
|
|
1988
|
+
for (lenTest = startLen; ; lenTest += 1) {
|
|
1989
|
+
curBack = obj._matchDistances[offs + 1];
|
|
1990
|
+
curAndLenPrice = normalMatchPrice + $GetPosLenPrice(obj, curBack, lenTest, posState);
|
|
1991
|
+
optimum = obj._optimum[cur + lenTest];
|
|
1992
|
+
if (curAndLenPrice < optimum.Price) {
|
|
1993
|
+
optimum.Price = curAndLenPrice;
|
|
1994
|
+
optimum.PosPrev = cur;
|
|
1995
|
+
optimum.BackPrev = curBack + 4;
|
|
1996
|
+
optimum.Prev1IsChar = 0;
|
|
1997
|
+
}
|
|
1998
|
+
if (lenTest == obj._matchDistances[offs]) {
|
|
1999
|
+
if (lenTest < numAvailableBytesFull) {
|
|
2000
|
+
t = Math.min(
|
|
2001
|
+
numAvailableBytesFull - 1 - lenTest,
|
|
2002
|
+
obj._numFastBytes
|
|
2003
|
+
);
|
|
2004
|
+
lenTest2 = $GetMatchLen(
|
|
2005
|
+
obj._matchFinder,
|
|
2006
|
+
lenTest,
|
|
2007
|
+
curBack,
|
|
2008
|
+
t
|
|
2009
|
+
);
|
|
1655
2010
|
if (lenTest2 >= 2) {
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
while (lenEnd < cur + lenTest) {
|
|
1684
|
-
obj._optimum[lenEnd += 1].Price = 268435455;
|
|
1685
|
-
}
|
|
1686
|
-
curAndLenPrice = repMatchPrice + (price_0 = $GetPrice(obj._repMatchLenEncoder, lenTest - 2, posState),
|
|
1687
|
-
price_0 + $GetPureRepPrice(obj, repIndex, state, posState));
|
|
1688
|
-
optimum = obj._optimum[cur + lenTest];
|
|
1689
|
-
if (curAndLenPrice < optimum.Price) {
|
|
1690
|
-
optimum.Price = curAndLenPrice;
|
|
1691
|
-
optimum.PosPrev = cur;
|
|
1692
|
-
optimum.BackPrev = repIndex;
|
|
1693
|
-
optimum.Prev1IsChar = 0;
|
|
1694
|
-
}
|
|
1695
|
-
} while ((lenTest -= 1) >= 2);
|
|
1696
|
-
lenTest = lenTestTemp;
|
|
1697
|
-
if (!repIndex) {
|
|
1698
|
-
startLen = lenTest + 1;
|
|
1699
|
-
}
|
|
1700
|
-
if (lenTest < numAvailableBytesFull) {
|
|
1701
|
-
t = Math.min(numAvailableBytesFull - 1 - lenTest, obj._numFastBytes);
|
|
1702
|
-
lenTest2 = $GetMatchLen(obj._matchFinder, lenTest, obj.reps[repIndex], t);
|
|
1703
|
-
if (lenTest2 >= 2) {
|
|
1704
|
-
state2 = state < 7 ? 8 : 11;
|
|
1705
|
-
posStateNext = position + lenTest & obj._posStateMask;
|
|
1706
|
-
curAndLenCharPrice = repMatchPrice + (price_1 = $GetPrice(obj._repMatchLenEncoder, lenTest - 2, posState),
|
|
1707
|
-
price_1 + $GetPureRepPrice(obj, repIndex, state, posState))
|
|
1708
|
-
+ ProbPrices[obj._isMatch[(state2 << 4) + posStateNext] >>> 2] + $GetPrice_0($GetSubCoder(obj._literalEncoder, position + lenTest, $GetIndexByte(obj._matchFinder, lenTest - 1 - 1)), 1, $GetIndexByte(obj._matchFinder, lenTest - 1 - (obj.reps[repIndex] + 1)), $GetIndexByte(obj._matchFinder, lenTest - 1));
|
|
1709
|
-
state2 = StateUpdateChar(state2);
|
|
1710
|
-
posStateNext = position + lenTest + 1 & obj._posStateMask;
|
|
1711
|
-
nextMatchPrice = curAndLenCharPrice + ProbPrices[2048 - obj
|
|
1712
|
-
._isMatch[(state2 << 4) + posStateNext] >>> 2];
|
|
1713
|
-
nextRepMatchPrice = nextMatchPrice
|
|
1714
|
-
+ ProbPrices[2048 - obj._isRep[state2] >>> 2];
|
|
1715
|
-
offset = lenTest + 1 + lenTest2;
|
|
1716
|
-
while (lenEnd < cur + offset) {
|
|
1717
|
-
obj._optimum[lenEnd += 1].Price = 268435455;
|
|
1718
|
-
}
|
|
1719
|
-
curAndLenPrice = nextRepMatchPrice + (price_2 = $GetPrice(obj._repMatchLenEncoder, lenTest2 - 2, posStateNext),
|
|
1720
|
-
price_2 + $GetPureRepPrice(obj, 0, state2, posStateNext));
|
|
1721
|
-
optimum = obj._optimum[cur + offset];
|
|
1722
|
-
if (curAndLenPrice < optimum.Price) {
|
|
1723
|
-
optimum.Price = curAndLenPrice;
|
|
1724
|
-
optimum.PosPrev = cur + lenTest + 1;
|
|
1725
|
-
optimum.BackPrev = 0;
|
|
1726
|
-
optimum.Prev1IsChar = 1;
|
|
1727
|
-
optimum.Prev2 = 1;
|
|
1728
|
-
optimum.PosPrev2 = cur;
|
|
1729
|
-
optimum.BackPrev2 = repIndex;
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
if (newLen > numAvailableBytes) {
|
|
1735
|
-
newLen = numAvailableBytes;
|
|
1736
|
-
for (numDistancePairs = 0; newLen > obj._matchDistances[numDistancePairs]; numDistancePairs += 2) { }
|
|
1737
|
-
obj._matchDistances[numDistancePairs] = newLen;
|
|
1738
|
-
numDistancePairs += 2;
|
|
1739
|
-
}
|
|
1740
|
-
if (newLen >= startLen) {
|
|
1741
|
-
normalMatchPrice = matchPrice + ProbPrices[obj._isRep[state] >>> 2];
|
|
1742
|
-
while (lenEnd < cur + newLen) {
|
|
2011
|
+
state2 = state < 7 ? 7 : 10;
|
|
2012
|
+
posStateNext = position + lenTest & obj._posStateMask;
|
|
2013
|
+
curAndLenCharPrice = curAndLenPrice + ProbPrices[obj._isMatch[(state2 << 4) + posStateNext] >>> 2] + $GetPrice_0(
|
|
2014
|
+
$GetSubCoder(
|
|
2015
|
+
obj._literalEncoder,
|
|
2016
|
+
position + lenTest,
|
|
2017
|
+
$GetIndexByte(
|
|
2018
|
+
obj._matchFinder,
|
|
2019
|
+
lenTest - 1 - 1
|
|
2020
|
+
)
|
|
2021
|
+
),
|
|
2022
|
+
1,
|
|
2023
|
+
$GetIndexByte(
|
|
2024
|
+
obj._matchFinder,
|
|
2025
|
+
lenTest - (curBack + 1) - 1
|
|
2026
|
+
),
|
|
2027
|
+
$GetIndexByte(
|
|
2028
|
+
obj._matchFinder,
|
|
2029
|
+
lenTest - 1
|
|
2030
|
+
)
|
|
2031
|
+
);
|
|
2032
|
+
state2 = StateUpdateChar(state2);
|
|
2033
|
+
posStateNext = position + lenTest + 1 & obj._posStateMask;
|
|
2034
|
+
nextMatchPrice = curAndLenCharPrice + ProbPrices[2048 - obj._isMatch[(state2 << 4) + posStateNext] >>> 2];
|
|
2035
|
+
nextRepMatchPrice = nextMatchPrice + ProbPrices[2048 - obj._isRep[state2] >>> 2];
|
|
2036
|
+
offset = lenTest + 1 + lenTest2;
|
|
2037
|
+
while (lenEnd < cur + offset) {
|
|
1743
2038
|
obj._optimum[lenEnd += 1].Price = 268435455;
|
|
2039
|
+
}
|
|
2040
|
+
curAndLenPrice = nextRepMatchPrice + (price_3 = $GetPrice(
|
|
2041
|
+
obj._repMatchLenEncoder,
|
|
2042
|
+
lenTest2 - 2,
|
|
2043
|
+
posStateNext
|
|
2044
|
+
), price_3 + $GetPureRepPrice(
|
|
2045
|
+
obj,
|
|
2046
|
+
0,
|
|
2047
|
+
state2,
|
|
2048
|
+
posStateNext
|
|
2049
|
+
));
|
|
2050
|
+
optimum = obj._optimum[cur + offset];
|
|
2051
|
+
if (curAndLenPrice < optimum.Price) {
|
|
2052
|
+
optimum.Price = curAndLenPrice;
|
|
2053
|
+
optimum.PosPrev = cur + lenTest + 1;
|
|
2054
|
+
optimum.BackPrev = 0;
|
|
2055
|
+
optimum.Prev1IsChar = 1;
|
|
2056
|
+
optimum.Prev2 = 1;
|
|
2057
|
+
optimum.PosPrev2 = cur;
|
|
2058
|
+
optimum.BackPrev2 = curBack + 4;
|
|
2059
|
+
}
|
|
1744
2060
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
curBack = obj._matchDistances[offs + 1];
|
|
1751
|
-
curAndLenPrice = normalMatchPrice
|
|
1752
|
-
+ $GetPosLenPrice(obj, curBack, lenTest, posState);
|
|
1753
|
-
optimum = obj._optimum[cur + lenTest];
|
|
1754
|
-
if (curAndLenPrice < optimum.Price) {
|
|
1755
|
-
optimum.Price = curAndLenPrice;
|
|
1756
|
-
optimum.PosPrev = cur;
|
|
1757
|
-
optimum.BackPrev = curBack + 4;
|
|
1758
|
-
optimum.Prev1IsChar = 0;
|
|
1759
|
-
}
|
|
1760
|
-
if (lenTest == obj._matchDistances[offs]) {
|
|
1761
|
-
if (lenTest < numAvailableBytesFull) {
|
|
1762
|
-
t = Math.min(numAvailableBytesFull - 1 - lenTest, obj._numFastBytes);
|
|
1763
|
-
lenTest2 = $GetMatchLen(obj._matchFinder, lenTest, curBack, t);
|
|
1764
|
-
if (lenTest2 >= 2) {
|
|
1765
|
-
state2 = state < 7 ? 7 : 10;
|
|
1766
|
-
posStateNext = position + lenTest
|
|
1767
|
-
& obj._posStateMask;
|
|
1768
|
-
curAndLenCharPrice = curAndLenPrice + ProbPrices[obj
|
|
1769
|
-
._isMatch[(state2 << 4) + posStateNext]
|
|
1770
|
-
>>> 2] + $GetPrice_0($GetSubCoder(obj._literalEncoder, position + lenTest, $GetIndexByte(obj._matchFinder, lenTest - 1 - 1)), 1, $GetIndexByte(obj._matchFinder, lenTest - (curBack + 1) - 1), $GetIndexByte(obj._matchFinder, lenTest - 1));
|
|
1771
|
-
state2 = StateUpdateChar(state2);
|
|
1772
|
-
posStateNext = position + lenTest + 1
|
|
1773
|
-
& obj._posStateMask;
|
|
1774
|
-
nextMatchPrice = curAndLenCharPrice + ProbPrices[2048 - obj
|
|
1775
|
-
._isMatch[(state2 << 4) + posStateNext] >>> 2];
|
|
1776
|
-
nextRepMatchPrice = nextMatchPrice + ProbPrices[2048 - obj._isRep[state2] >>> 2];
|
|
1777
|
-
offset = lenTest + 1 + lenTest2;
|
|
1778
|
-
while (lenEnd < cur + offset) {
|
|
1779
|
-
obj._optimum[lenEnd += 1].Price = 268435455;
|
|
1780
|
-
}
|
|
1781
|
-
curAndLenPrice = nextRepMatchPrice
|
|
1782
|
-
+ (price_3 = $GetPrice(obj._repMatchLenEncoder, lenTest2 - 2, posStateNext),
|
|
1783
|
-
price_3 + $GetPureRepPrice(obj, 0, state2, posStateNext));
|
|
1784
|
-
optimum = obj._optimum[cur + offset];
|
|
1785
|
-
if (curAndLenPrice < optimum.Price) {
|
|
1786
|
-
optimum.Price = curAndLenPrice;
|
|
1787
|
-
optimum.PosPrev = cur + lenTest + 1;
|
|
1788
|
-
optimum.BackPrev = 0;
|
|
1789
|
-
optimum.Prev1IsChar = 1;
|
|
1790
|
-
optimum.Prev2 = 1;
|
|
1791
|
-
optimum.PosPrev2 = cur;
|
|
1792
|
-
optimum.BackPrev2 = curBack + 4;
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
offs += 2;
|
|
1797
|
-
if (offs == numDistancePairs) {
|
|
1798
|
-
break;
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
2061
|
+
}
|
|
2062
|
+
offs += 2;
|
|
2063
|
+
if (offs == numDistancePairs) {
|
|
2064
|
+
break;
|
|
2065
|
+
}
|
|
1802
2066
|
}
|
|
2067
|
+
}
|
|
1803
2068
|
}
|
|
2069
|
+
}
|
|
1804
2070
|
}
|
|
1805
2071
|
function $GetPosLenPrice(obj, pos, len, posState) {
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
}
|
|
1814
|
-
return price + $GetPrice(obj._lenEncoder, len - 2, posState);
|
|
2072
|
+
let price, lenToPosState = GetLenToPosState(len);
|
|
2073
|
+
if (pos < 128) {
|
|
2074
|
+
price = obj._distancesPrices[lenToPosState * 128 + pos];
|
|
2075
|
+
} else {
|
|
2076
|
+
price = obj._posSlotPrices[(lenToPosState << 6) + GetPosSlot2(pos)] + obj._alignPrices[pos & 15];
|
|
2077
|
+
}
|
|
2078
|
+
return price + $GetPrice(obj._lenEncoder, len - 2, posState);
|
|
1815
2079
|
}
|
|
1816
2080
|
function $GetPureRepPrice(obj, repIndex, state, posState) {
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
}
|
|
1832
|
-
return price;
|
|
2081
|
+
var price;
|
|
2082
|
+
if (!repIndex) {
|
|
2083
|
+
price = ProbPrices[obj._isRepG0[state] >>> 2];
|
|
2084
|
+
price += ProbPrices[2048 - obj._isRep0Long[(state << 4) + posState] >>> 2];
|
|
2085
|
+
} else {
|
|
2086
|
+
price = ProbPrices[2048 - obj._isRepG0[state] >>> 2];
|
|
2087
|
+
if (repIndex == 1) {
|
|
2088
|
+
price += ProbPrices[obj._isRepG1[state] >>> 2];
|
|
2089
|
+
} else {
|
|
2090
|
+
price += ProbPrices[2048 - obj._isRepG1[state] >>> 2];
|
|
2091
|
+
price += GetPrice(obj._isRepG2[state], repIndex - 2);
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
return price;
|
|
1833
2095
|
}
|
|
1834
2096
|
function $GetRepLen1Price(obj, state, posState) {
|
|
1835
|
-
|
|
1836
|
-
+ ProbPrices[obj._isRep0Long[(state << 4) + posState] >>> 2];
|
|
2097
|
+
return ProbPrices[obj._isRepG0[state] >>> 2] + ProbPrices[obj._isRep0Long[(state << 4) + posState] >>> 2];
|
|
1837
2098
|
}
|
|
1838
2099
|
function $Init_4(obj) {
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
2100
|
+
$BaseInit(obj);
|
|
2101
|
+
$Init_9(obj._rangeEncoder);
|
|
2102
|
+
InitBitModels(obj._isMatch);
|
|
2103
|
+
InitBitModels(obj._isRep0Long);
|
|
2104
|
+
InitBitModels(obj._isRep);
|
|
2105
|
+
InitBitModels(obj._isRepG0);
|
|
2106
|
+
InitBitModels(obj._isRepG1);
|
|
2107
|
+
InitBitModels(obj._isRepG2);
|
|
2108
|
+
InitBitModels(obj._posEncoders);
|
|
2109
|
+
$Init_3(obj._literalEncoder);
|
|
2110
|
+
for (let i = 0; i < 4; ++i) {
|
|
2111
|
+
InitBitModels(obj._posSlotEncoder[i].Models);
|
|
2112
|
+
}
|
|
2113
|
+
$Init_2(obj._lenEncoder, 1 << obj._posStateBits);
|
|
2114
|
+
$Init_2(obj._repMatchLenEncoder, 1 << obj._posStateBits);
|
|
2115
|
+
InitBitModels(obj._posAlignEncoder.Models);
|
|
2116
|
+
obj._longestMatchWasFound = 0;
|
|
2117
|
+
obj._optimumEndIndex = 0;
|
|
2118
|
+
obj._optimumCurrentIndex = 0;
|
|
2119
|
+
obj._additionalOffset = 0;
|
|
1859
2120
|
}
|
|
1860
2121
|
function $MovePos(obj, num) {
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
2122
|
+
if (num > 0) {
|
|
2123
|
+
$Skip(obj._matchFinder, num);
|
|
2124
|
+
obj._additionalOffset += num;
|
|
2125
|
+
}
|
|
1865
2126
|
}
|
|
1866
2127
|
function $ReadMatchDistances(obj) {
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
2128
|
+
var lenRes2 = 0;
|
|
2129
|
+
obj._numDistancePairs = $GetMatches(
|
|
2130
|
+
obj._matchFinder,
|
|
2131
|
+
obj._matchDistances
|
|
2132
|
+
);
|
|
2133
|
+
if (obj._numDistancePairs > 0) {
|
|
2134
|
+
lenRes2 = obj._matchDistances[obj._numDistancePairs - 2];
|
|
2135
|
+
if (lenRes2 == obj._numFastBytes) {
|
|
2136
|
+
lenRes2 += $GetMatchLen(
|
|
2137
|
+
obj._matchFinder,
|
|
2138
|
+
lenRes2 - 1,
|
|
2139
|
+
obj._matchDistances[obj._numDistancePairs - 1],
|
|
2140
|
+
273 - lenRes2
|
|
2141
|
+
);
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
obj._additionalOffset += 1;
|
|
2145
|
+
return lenRes2;
|
|
1877
2146
|
}
|
|
1878
2147
|
function $ReleaseMFStream(obj) {
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
2148
|
+
if (obj._matchFinder && obj._needReleaseMFStream) {
|
|
2149
|
+
obj._matchFinder._stream = null;
|
|
2150
|
+
obj._needReleaseMFStream = 0;
|
|
2151
|
+
}
|
|
1883
2152
|
}
|
|
1884
2153
|
function $ReleaseStreams(obj) {
|
|
1885
|
-
|
|
1886
|
-
|
|
2154
|
+
$ReleaseMFStream(obj);
|
|
2155
|
+
obj._rangeEncoder.Stream = null;
|
|
1887
2156
|
}
|
|
1888
2157
|
function $SetDictionarySize_0(obj, dictionarySize) {
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
2158
|
+
obj._dictionarySize = dictionarySize;
|
|
2159
|
+
for (var dicLogSize = 0; dictionarySize > 1 << dicLogSize; ++dicLogSize)
|
|
2160
|
+
;
|
|
2161
|
+
obj._distTableSize = dicLogSize * 2;
|
|
1893
2162
|
}
|
|
1894
2163
|
function $SetMatchFinder(obj, matchFinderIndex) {
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
2164
|
+
var matchFinderIndexPrev = obj._matchFinderType;
|
|
2165
|
+
obj._matchFinderType = matchFinderIndex;
|
|
2166
|
+
if (obj._matchFinder && matchFinderIndexPrev != obj._matchFinderType) {
|
|
2167
|
+
obj._dictionarySizePrev = -1;
|
|
2168
|
+
obj._matchFinder = null;
|
|
2169
|
+
}
|
|
1901
2170
|
}
|
|
1902
2171
|
function writeHeaderProperties(obj, outStream) {
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
2172
|
+
obj.properties[0] = (obj._posStateBits * 5 + obj._numLiteralPosStateBits) * 9 + (obj._numLiteralContextBits << 24 >> 24);
|
|
2173
|
+
for (let i = 0; i < 4; ++i) {
|
|
2174
|
+
obj.properties[1 + i] = obj._dictionarySize >> 8 * (i << 24 >> 24);
|
|
2175
|
+
}
|
|
2176
|
+
$write_0(
|
|
2177
|
+
outStream,
|
|
2178
|
+
obj.properties,
|
|
2179
|
+
0,
|
|
2180
|
+
5
|
|
2181
|
+
);
|
|
1912
2182
|
}
|
|
1913
2183
|
function $WriteEndMarker(obj, posState) {
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
obj.
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
2184
|
+
$Encode_3(
|
|
2185
|
+
obj._rangeEncoder,
|
|
2186
|
+
obj._isMatch,
|
|
2187
|
+
(obj._state << 4) + posState,
|
|
2188
|
+
1
|
|
2189
|
+
);
|
|
2190
|
+
$Encode_3(
|
|
2191
|
+
obj._rangeEncoder,
|
|
2192
|
+
obj._isRep,
|
|
2193
|
+
obj._state,
|
|
2194
|
+
0
|
|
2195
|
+
);
|
|
2196
|
+
obj._state = obj._state < 7 ? 7 : 10;
|
|
2197
|
+
$Encode_0(obj._lenEncoder, obj._rangeEncoder, 0, posState);
|
|
2198
|
+
var lenToPosState = GetLenToPosState(2);
|
|
2199
|
+
$Encode_2(
|
|
2200
|
+
obj._posSlotEncoder[lenToPosState],
|
|
2201
|
+
obj._rangeEncoder,
|
|
2202
|
+
63
|
|
2203
|
+
);
|
|
2204
|
+
$EncodeDirectBits(obj._rangeEncoder, 67108863, 26);
|
|
2205
|
+
$ReverseEncode(obj._posAlignEncoder, obj._rangeEncoder, 15);
|
|
1922
2206
|
}
|
|
1923
2207
|
function GetPosSlot(pos) {
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
2208
|
+
if (pos < 2048) {
|
|
2209
|
+
return g_FastPos[pos];
|
|
2210
|
+
}
|
|
2211
|
+
if (pos < 2097152) {
|
|
2212
|
+
return g_FastPos[pos >> 10] + 20;
|
|
2213
|
+
}
|
|
2214
|
+
return g_FastPos[pos >> 20] + 40;
|
|
1931
2215
|
}
|
|
1932
2216
|
function GetPosSlot2(pos) {
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
2217
|
+
if (pos < 131072) {
|
|
2218
|
+
return g_FastPos[pos >> 6] + 12;
|
|
2219
|
+
}
|
|
2220
|
+
if (pos < 134217728) {
|
|
2221
|
+
return g_FastPos[pos >> 16] + 32;
|
|
2222
|
+
}
|
|
2223
|
+
return g_FastPos[pos >> 26] + 52;
|
|
1940
2224
|
}
|
|
1941
2225
|
function $Encode(obj, rangeEncoder, symbol, posState) {
|
|
2226
|
+
if (symbol < 8) {
|
|
2227
|
+
$Encode_3(rangeEncoder, obj._choice, 0, 0);
|
|
2228
|
+
$Encode_2(obj._lowCoder[posState], rangeEncoder, symbol);
|
|
2229
|
+
} else {
|
|
2230
|
+
symbol -= 8;
|
|
2231
|
+
$Encode_3(rangeEncoder, obj._choice, 0, 1);
|
|
1942
2232
|
if (symbol < 8) {
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
}
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
$Encode_3(rangeEncoder, obj._choice, 0, 1);
|
|
1949
|
-
if (symbol < 8) {
|
|
1950
|
-
$Encode_3(rangeEncoder, obj._choice, 1, 0);
|
|
1951
|
-
$Encode_2(obj._midCoder[posState], rangeEncoder, symbol);
|
|
1952
|
-
}
|
|
1953
|
-
else {
|
|
1954
|
-
$Encode_3(rangeEncoder, obj._choice, 1, 1);
|
|
1955
|
-
$Encode_2(obj._highCoder, rangeEncoder, symbol - 8);
|
|
1956
|
-
}
|
|
2233
|
+
$Encode_3(rangeEncoder, obj._choice, 1, 0);
|
|
2234
|
+
$Encode_2(obj._midCoder[posState], rangeEncoder, symbol);
|
|
2235
|
+
} else {
|
|
2236
|
+
$Encode_3(rangeEncoder, obj._choice, 1, 1);
|
|
2237
|
+
$Encode_2(obj._highCoder, rangeEncoder, symbol - 8);
|
|
1957
2238
|
}
|
|
2239
|
+
}
|
|
1958
2240
|
}
|
|
1959
2241
|
function $Encoder$LenEncoder(obj) {
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
2242
|
+
obj._choice = initArr(2);
|
|
2243
|
+
obj._lowCoder = initArr(16);
|
|
2244
|
+
obj._midCoder = initArr(16);
|
|
2245
|
+
obj._highCoder = bitTreeEncoder({}, 8);
|
|
2246
|
+
for (let posState = 0; posState < 16; ++posState) {
|
|
2247
|
+
obj._lowCoder[posState] = bitTreeEncoder({}, 3);
|
|
2248
|
+
obj._midCoder[posState] = bitTreeEncoder({}, 3);
|
|
2249
|
+
}
|
|
2250
|
+
return obj;
|
|
1969
2251
|
}
|
|
1970
2252
|
function $Init_2(obj, numPosStates) {
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
2253
|
+
InitBitModels(obj._choice);
|
|
2254
|
+
for (let posState = 0; posState < numPosStates; ++posState) {
|
|
2255
|
+
InitBitModels(obj._lowCoder[posState].Models);
|
|
2256
|
+
InitBitModels(obj._midCoder[posState].Models);
|
|
2257
|
+
}
|
|
2258
|
+
InitBitModels(obj._highCoder.Models);
|
|
1977
2259
|
}
|
|
1978
2260
|
function $SetPrices(obj, posState, numSymbols, prices, st) {
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2261
|
+
var a0, a1, b0, b1, i;
|
|
2262
|
+
a0 = ProbPrices[obj._choice[0] >>> 2];
|
|
2263
|
+
a1 = ProbPrices[2048 - obj._choice[0] >>> 2];
|
|
2264
|
+
b0 = a1 + ProbPrices[obj._choice[1] >>> 2];
|
|
2265
|
+
b1 = a1 + ProbPrices[2048 - obj._choice[1] >>> 2];
|
|
2266
|
+
i = 0;
|
|
2267
|
+
for (i = 0; i < 8; ++i) {
|
|
2268
|
+
if (i >= numSymbols) {
|
|
2269
|
+
return;
|
|
2270
|
+
}
|
|
2271
|
+
prices[st + i] = a0 + $GetPrice_1(obj._lowCoder[posState], i);
|
|
2272
|
+
}
|
|
2273
|
+
for (; i < 16; ++i) {
|
|
2274
|
+
if (i >= numSymbols) {
|
|
2275
|
+
return;
|
|
2276
|
+
}
|
|
2277
|
+
prices[st + i] = b0 + $GetPrice_1(obj._midCoder[posState], i - 8);
|
|
2278
|
+
}
|
|
2279
|
+
for (; i < numSymbols; ++i) {
|
|
2280
|
+
prices[st + i] = b1 + $GetPrice_1(obj._highCoder, i - 8 - 8);
|
|
2281
|
+
}
|
|
2000
2282
|
}
|
|
2001
2283
|
function $Encode_0(obj, rangeEncoder, symbol, posState) {
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2284
|
+
$Encode(obj, rangeEncoder, symbol, posState);
|
|
2285
|
+
if ((obj._counters[posState] -= 1) == 0) {
|
|
2286
|
+
$SetPrices(
|
|
2287
|
+
obj,
|
|
2288
|
+
posState,
|
|
2289
|
+
obj._tableSize,
|
|
2290
|
+
obj._prices,
|
|
2291
|
+
posState * 272
|
|
2292
|
+
);
|
|
2293
|
+
obj._counters[posState] = obj._tableSize;
|
|
2294
|
+
}
|
|
2007
2295
|
}
|
|
2008
2296
|
function $Encoder$LenPriceTableEncoder(obj) {
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2297
|
+
$Encoder$LenEncoder(obj);
|
|
2298
|
+
obj._prices = [];
|
|
2299
|
+
obj._counters = [];
|
|
2300
|
+
return obj;
|
|
2013
2301
|
}
|
|
2014
2302
|
function $GetPrice(obj, symbol, posState) {
|
|
2015
|
-
|
|
2303
|
+
return obj._prices[posState * 272 + symbol];
|
|
2016
2304
|
}
|
|
2017
2305
|
function $UpdateTables(obj, numPosStates) {
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2306
|
+
for (let posState = 0; posState < numPosStates; ++posState) {
|
|
2307
|
+
$SetPrices(
|
|
2308
|
+
obj,
|
|
2309
|
+
posState,
|
|
2310
|
+
obj._tableSize,
|
|
2311
|
+
obj._prices,
|
|
2312
|
+
posState * 272
|
|
2313
|
+
);
|
|
2314
|
+
obj._counters[posState] = obj._tableSize;
|
|
2315
|
+
}
|
|
2022
2316
|
}
|
|
2023
2317
|
function $Create_1(obj, numPosBits, numPrevBits) {
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
obj.m_Coders =
|
|
2035
|
-
|
|
2036
|
-
obj.m_Coders[i] = $Encoder$LiteralEncoder$Encoder2({});
|
|
2037
|
-
}
|
|
2318
|
+
var i, numStates;
|
|
2319
|
+
if (obj.m_Coders != null && obj.m_NumPrevBits == numPrevBits && obj.m_NumPosBits == numPosBits) {
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
obj.m_NumPosBits = numPosBits;
|
|
2323
|
+
obj.m_PosMask = (1 << numPosBits) - 1;
|
|
2324
|
+
obj.m_NumPrevBits = numPrevBits;
|
|
2325
|
+
numStates = 1 << obj.m_NumPrevBits + obj.m_NumPosBits;
|
|
2326
|
+
obj.m_Coders = initArr(numStates);
|
|
2327
|
+
for (i = 0; i < numStates; ++i) {
|
|
2328
|
+
obj.m_Coders[i] = $Encoder$LiteralEncoder$Encoder2({});
|
|
2329
|
+
}
|
|
2038
2330
|
}
|
|
2039
2331
|
function $GetSubCoder(obj, pos, prevByte) {
|
|
2040
|
-
|
|
2041
|
-
.m_Coders[((pos & obj.m_PosMask) << obj.m_NumPrevBits)
|
|
2042
|
-
+ ((prevByte & 255) >>> 8 - obj.m_NumPrevBits)];
|
|
2332
|
+
return obj.m_Coders[((pos & obj.m_PosMask) << obj.m_NumPrevBits) + ((prevByte & 255) >>> 8 - obj.m_NumPrevBits)];
|
|
2043
2333
|
}
|
|
2044
2334
|
function $Init_3(obj) {
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2335
|
+
var i, numStates = 1 << obj.m_NumPrevBits + obj.m_NumPosBits;
|
|
2336
|
+
for (i = 0; i < numStates; ++i) {
|
|
2337
|
+
InitBitModels(obj.m_Coders[i].m_Encoders);
|
|
2338
|
+
}
|
|
2049
2339
|
}
|
|
2050
2340
|
function $Encode_1(obj, rangeEncoder, symbol) {
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2341
|
+
var bit, context = 1;
|
|
2342
|
+
for (let i = 7; i >= 0; --i) {
|
|
2343
|
+
bit = symbol >> i & 1;
|
|
2344
|
+
$Encode_3(rangeEncoder, obj.m_Encoders, context, bit);
|
|
2345
|
+
context = context << 1 | bit;
|
|
2346
|
+
}
|
|
2057
2347
|
}
|
|
2058
2348
|
function $EncodeMatched(obj, rangeEncoder, matchByte, symbol) {
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2349
|
+
var bit, matchBit, state, same = true, context = 1;
|
|
2350
|
+
for (let i = 7; i >= 0; --i) {
|
|
2351
|
+
bit = symbol >> i & 1;
|
|
2352
|
+
state = context;
|
|
2353
|
+
if (same) {
|
|
2354
|
+
matchBit = matchByte >> i & 1;
|
|
2355
|
+
state += 1 + matchBit << 8;
|
|
2356
|
+
same = matchBit === bit;
|
|
2357
|
+
}
|
|
2358
|
+
$Encode_3(rangeEncoder, obj.m_Encoders, state, bit);
|
|
2359
|
+
context = context << 1 | bit;
|
|
2360
|
+
}
|
|
2071
2361
|
}
|
|
2072
2362
|
function $Encoder$LiteralEncoder$Encoder2(obj) {
|
|
2073
|
-
|
|
2074
|
-
|
|
2363
|
+
obj.m_Encoders = initArr(768);
|
|
2364
|
+
return obj;
|
|
2075
2365
|
}
|
|
2076
2366
|
function $GetPrice_0(obj, matchMode, matchByte, symbol) {
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
for (; i >= 0; --i) {
|
|
2080
|
-
matchBit = matchByte >> i & 1;
|
|
2081
|
-
bit = symbol >> i & 1;
|
|
2082
|
-
price += GetPrice(obj.m_Encoders[(1 + matchBit << 8) + context], bit);
|
|
2083
|
-
context = context << 1 | bit;
|
|
2084
|
-
if (matchBit != bit) {
|
|
2085
|
-
;
|
|
2086
|
-
--i;
|
|
2087
|
-
break;
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2367
|
+
var bit, context = 1, i = 7, matchBit, price = 0;
|
|
2368
|
+
if (matchMode) {
|
|
2091
2369
|
for (; i >= 0; --i) {
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2370
|
+
matchBit = matchByte >> i & 1;
|
|
2371
|
+
bit = symbol >> i & 1;
|
|
2372
|
+
price += GetPrice(
|
|
2373
|
+
obj.m_Encoders[(1 + matchBit << 8) + context],
|
|
2374
|
+
bit
|
|
2375
|
+
);
|
|
2376
|
+
context = context << 1 | bit;
|
|
2377
|
+
if (matchBit != bit) {
|
|
2378
|
+
;
|
|
2379
|
+
--i;
|
|
2380
|
+
break;
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
for (; i >= 0; --i) {
|
|
2385
|
+
bit = symbol >> i & 1;
|
|
2386
|
+
price += GetPrice(obj.m_Encoders[context], bit);
|
|
2387
|
+
context = context << 1 | bit;
|
|
2388
|
+
}
|
|
2389
|
+
return price;
|
|
2097
2390
|
}
|
|
2098
2391
|
function $MakeAsChar(obj) {
|
|
2099
|
-
|
|
2100
|
-
|
|
2392
|
+
obj.BackPrev = -1;
|
|
2393
|
+
obj.Prev1IsChar = 0;
|
|
2101
2394
|
}
|
|
2102
2395
|
function $MakeAsShortRep(obj) {
|
|
2103
|
-
|
|
2104
|
-
|
|
2396
|
+
obj.BackPrev = 0;
|
|
2397
|
+
obj.Prev1IsChar = 0;
|
|
2105
2398
|
}
|
|
2106
2399
|
function $BitTreeDecoder(obj, numBitLevels) {
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2400
|
+
obj.NumBitLevels = numBitLevels;
|
|
2401
|
+
obj.Models = initArr(1 << numBitLevels);
|
|
2402
|
+
return obj;
|
|
2110
2403
|
}
|
|
2111
2404
|
function $Decode_0(obj, rangeDecoder) {
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2405
|
+
var bitIndex, m = 1;
|
|
2406
|
+
for (bitIndex = obj.NumBitLevels; bitIndex != 0; bitIndex -= 1) {
|
|
2407
|
+
m = (m << 1) + decodeBit(rangeDecoder, obj.Models, m);
|
|
2408
|
+
}
|
|
2409
|
+
return m - (1 << obj.NumBitLevels);
|
|
2117
2410
|
}
|
|
2118
2411
|
function $ReverseDecode(obj, rangeDecoder) {
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2412
|
+
let symbol = 0;
|
|
2413
|
+
for (let m = 1, bitIndex = 0, bit; bitIndex < obj.NumBitLevels; ++bitIndex) {
|
|
2414
|
+
bit = decodeBit(rangeDecoder, obj.Models, m);
|
|
2415
|
+
m <<= 1;
|
|
2416
|
+
m += bit;
|
|
2417
|
+
symbol |= bit << bitIndex;
|
|
2418
|
+
}
|
|
2419
|
+
return symbol;
|
|
2127
2420
|
}
|
|
2128
2421
|
function reverseDecode(Models, startIndex, rangeDecoder, NumBitLevels) {
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2422
|
+
let symbol = 0;
|
|
2423
|
+
for (let bitIndex = 0, m = 1, bit; bitIndex < NumBitLevels; ++bitIndex) {
|
|
2424
|
+
bit = decodeBit(rangeDecoder, Models, startIndex + m);
|
|
2425
|
+
m <<= 1;
|
|
2426
|
+
m += bit;
|
|
2427
|
+
symbol |= bit << bitIndex;
|
|
2428
|
+
}
|
|
2429
|
+
return symbol;
|
|
2137
2430
|
}
|
|
2138
2431
|
function bitTreeEncoder(obj, numBitLevels) {
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2432
|
+
obj.NumBitLevels = numBitLevels;
|
|
2433
|
+
obj.Models = initArr(1 << numBitLevels);
|
|
2434
|
+
return obj;
|
|
2142
2435
|
}
|
|
2143
2436
|
function $Encode_2(obj, rangeEncoder, symbol) {
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2437
|
+
var bit, bitIndex, m = 1;
|
|
2438
|
+
for (bitIndex = obj.NumBitLevels; bitIndex != 0; ) {
|
|
2439
|
+
bitIndex -= 1;
|
|
2440
|
+
bit = symbol >>> bitIndex & 1;
|
|
2441
|
+
$Encode_3(rangeEncoder, obj.Models, m, bit);
|
|
2442
|
+
m = m << 1 | bit;
|
|
2443
|
+
}
|
|
2151
2444
|
}
|
|
2152
2445
|
function $GetPrice_1(obj, symbol) {
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2446
|
+
var bit, bitIndex, m = 1, price = 0;
|
|
2447
|
+
for (bitIndex = obj.NumBitLevels; bitIndex != 0; ) {
|
|
2448
|
+
bitIndex -= 1;
|
|
2449
|
+
bit = symbol >>> bitIndex & 1;
|
|
2450
|
+
price += GetPrice(obj.Models[m], bit);
|
|
2451
|
+
m = (m << 1) + bit;
|
|
2452
|
+
}
|
|
2453
|
+
return price;
|
|
2161
2454
|
}
|
|
2162
2455
|
function $ReverseEncode(obj, rangeEncoder, symbol) {
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2456
|
+
var bit, m = 1;
|
|
2457
|
+
for (let i = 0; i < obj.NumBitLevels; ++i) {
|
|
2458
|
+
bit = symbol & 1;
|
|
2459
|
+
$Encode_3(rangeEncoder, obj.Models, m, bit);
|
|
2460
|
+
m = m << 1 | bit;
|
|
2461
|
+
symbol >>= 1;
|
|
2462
|
+
}
|
|
2170
2463
|
}
|
|
2171
2464
|
function $ReverseGetPrice(obj, symbol) {
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2465
|
+
var bit, m = 1, price = 0;
|
|
2466
|
+
for (let i = obj.NumBitLevels; i != 0; i -= 1) {
|
|
2467
|
+
bit = symbol & 1;
|
|
2468
|
+
symbol >>>= 1;
|
|
2469
|
+
price += GetPrice(obj.Models[m], bit);
|
|
2470
|
+
m = m << 1 | bit;
|
|
2471
|
+
}
|
|
2472
|
+
return price;
|
|
2180
2473
|
}
|
|
2181
2474
|
function ReverseEncode(Models, startIndex, rangeEncoder, NumBitLevels, symbol) {
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2475
|
+
var bit, m = 1;
|
|
2476
|
+
for (let i = 0; i < NumBitLevels; ++i) {
|
|
2477
|
+
bit = symbol & 1;
|
|
2478
|
+
$Encode_3(rangeEncoder, Models, startIndex + m, bit);
|
|
2479
|
+
m = m << 1 | bit;
|
|
2480
|
+
symbol >>= 1;
|
|
2481
|
+
}
|
|
2189
2482
|
}
|
|
2190
2483
|
function ReverseGetPrice(Models, startIndex, NumBitLevels, symbol) {
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
return price;
|
|
2484
|
+
var bit, m = 1, price = 0;
|
|
2485
|
+
for (let i = NumBitLevels; i != 0; i -= 1) {
|
|
2486
|
+
bit = symbol & 1;
|
|
2487
|
+
symbol >>>= 1;
|
|
2488
|
+
price += ProbPrices[((Models[startIndex + m] - bit ^ -bit) & 2047) >>> 2];
|
|
2489
|
+
m = m << 1 | bit;
|
|
2490
|
+
}
|
|
2491
|
+
return price;
|
|
2200
2492
|
}
|
|
2201
2493
|
function decodeBit(obj, probs, index) {
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
}
|
|
2211
|
-
return 0;
|
|
2212
|
-
}
|
|
2213
|
-
else {
|
|
2214
|
-
obj.Range -= newBound;
|
|
2215
|
-
obj.Code -= newBound;
|
|
2216
|
-
probs[index] = prob - (prob >>> 5) << 16 >> 16;
|
|
2217
|
-
if (!(obj.Range & -16777216)) {
|
|
2218
|
-
obj.Code = obj.Code << 8 | $read(obj.Stream);
|
|
2219
|
-
obj.Range <<= 8;
|
|
2220
|
-
}
|
|
2221
|
-
return 1;
|
|
2494
|
+
var newBound, prob = probs[index];
|
|
2495
|
+
newBound = (obj.Range >>> 11) * prob;
|
|
2496
|
+
if ((obj.Code ^ MIN_INT32) < (newBound ^ MIN_INT32)) {
|
|
2497
|
+
obj.Range = newBound;
|
|
2498
|
+
probs[index] = prob + (2048 - prob >>> 5) << 16 >> 16;
|
|
2499
|
+
if (!(obj.Range & -16777216)) {
|
|
2500
|
+
obj.Code = obj.Code << 8 | $read(obj.Stream);
|
|
2501
|
+
obj.Range <<= 8;
|
|
2222
2502
|
}
|
|
2503
|
+
return 0;
|
|
2504
|
+
} else {
|
|
2505
|
+
obj.Range -= newBound;
|
|
2506
|
+
obj.Code -= newBound;
|
|
2507
|
+
probs[index] = prob - (prob >>> 5) << 16 >> 16;
|
|
2508
|
+
if (!(obj.Range & -16777216)) {
|
|
2509
|
+
obj.Code = obj.Code << 8 | $read(obj.Stream);
|
|
2510
|
+
obj.Range <<= 8;
|
|
2511
|
+
}
|
|
2512
|
+
return 1;
|
|
2513
|
+
}
|
|
2223
2514
|
}
|
|
2224
2515
|
function $DecodeDirectBits(obj, numTotalBits) {
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
}
|
|
2516
|
+
let result = 0;
|
|
2517
|
+
for (let i = numTotalBits; i != 0; i -= 1) {
|
|
2518
|
+
obj.Range >>>= 1;
|
|
2519
|
+
let t = obj.Code - obj.Range >>> 31;
|
|
2520
|
+
obj.Code -= obj.Range & t - 1;
|
|
2521
|
+
result = result << 1 | 1 - t;
|
|
2522
|
+
if (!(obj.Range & -16777216)) {
|
|
2523
|
+
obj.Code = obj.Code << 8 | $read(obj.Stream);
|
|
2524
|
+
obj.Range <<= 8;
|
|
2235
2525
|
}
|
|
2236
|
-
|
|
2526
|
+
}
|
|
2527
|
+
return result;
|
|
2237
2528
|
}
|
|
2238
2529
|
function $Init_8(obj) {
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2530
|
+
obj.Code = 0;
|
|
2531
|
+
obj.Range = -1;
|
|
2532
|
+
for (let i = 0; i < 5; ++i) {
|
|
2533
|
+
obj.Code = obj.Code << 8 | $read(obj.Stream);
|
|
2534
|
+
}
|
|
2244
2535
|
}
|
|
2245
2536
|
function InitBitModels(probs) {
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
}
|
|
2250
|
-
const ProbPrices = function
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2537
|
+
for (let i = probs.length - 1; i >= 0; --i) {
|
|
2538
|
+
probs[i] = 1024;
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
const ProbPrices = function() {
|
|
2542
|
+
var end, i, j, start, ProbPrices2 = [];
|
|
2543
|
+
for (i = 8; i >= 0; --i) {
|
|
2544
|
+
start = 1;
|
|
2545
|
+
start <<= 9 - i - 1;
|
|
2546
|
+
end = 1;
|
|
2547
|
+
end <<= 9 - i;
|
|
2548
|
+
for (j = start; j < end; ++j) {
|
|
2549
|
+
ProbPrices2[j] = (i << 6) + (end - j << 6 >>> 9 - i - 1);
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
return ProbPrices2;
|
|
2262
2553
|
}();
|
|
2263
2554
|
function $Encode_3(obj, probs, index, symbol) {
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2555
|
+
var newBound, prob = probs[index];
|
|
2556
|
+
newBound = (obj.Range >>> 11) * prob;
|
|
2557
|
+
if (!symbol) {
|
|
2558
|
+
obj.Range = newBound;
|
|
2559
|
+
probs[index] = prob + (2048 - prob >>> 5) << 16 >> 16;
|
|
2560
|
+
} else {
|
|
2561
|
+
obj.Low = add(
|
|
2562
|
+
obj.Low,
|
|
2563
|
+
and(fromInt(newBound), [4294967295, 0])
|
|
2564
|
+
);
|
|
2565
|
+
obj.Range -= newBound;
|
|
2566
|
+
probs[index] = prob - (prob >>> 5) << 16 >> 16;
|
|
2567
|
+
}
|
|
2568
|
+
if (!(obj.Range & -16777216)) {
|
|
2569
|
+
obj.Range <<= 8;
|
|
2570
|
+
$ShiftLow(obj);
|
|
2571
|
+
}
|
|
2279
2572
|
}
|
|
2280
2573
|
function $EncodeDirectBits(obj, v, numTotalBits) {
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
}
|
|
2286
|
-
if (!(obj.Range & -16777216)) {
|
|
2287
|
-
obj.Range <<= 8;
|
|
2288
|
-
$ShiftLow(obj);
|
|
2289
|
-
}
|
|
2574
|
+
for (let i = numTotalBits - 1; i >= 0; i -= 1) {
|
|
2575
|
+
obj.Range >>>= 1;
|
|
2576
|
+
if ((v >>> i & 1) == 1) {
|
|
2577
|
+
obj.Low = add(obj.Low, fromInt(obj.Range));
|
|
2290
2578
|
}
|
|
2579
|
+
if (!(obj.Range & -16777216)) {
|
|
2580
|
+
obj.Range <<= 8;
|
|
2581
|
+
$ShiftLow(obj);
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2291
2584
|
}
|
|
2292
2585
|
function $GetProcessedSizeAdd(obj) {
|
|
2293
|
-
|
|
2586
|
+
return add(add(fromInt(obj._cacheSize), obj._position), [4, 0]);
|
|
2294
2587
|
}
|
|
2295
2588
|
function $Init_9(obj) {
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2589
|
+
obj._position = P0_longLit;
|
|
2590
|
+
obj.Low = P0_longLit;
|
|
2591
|
+
obj.Range = -1;
|
|
2592
|
+
obj._cacheSize = 1;
|
|
2593
|
+
obj._cache = 0;
|
|
2301
2594
|
}
|
|
2302
2595
|
function $ShiftLow(obj) {
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
obj._cacheSize
|
|
2314
|
-
obj.
|
|
2596
|
+
const LowHi = lowBits_0(shru(obj.Low, 32));
|
|
2597
|
+
if (LowHi != 0 || compare(obj.Low, [4278190080, 0]) < 0) {
|
|
2598
|
+
obj._position = add(
|
|
2599
|
+
obj._position,
|
|
2600
|
+
fromInt(obj._cacheSize)
|
|
2601
|
+
);
|
|
2602
|
+
let temp = obj._cache;
|
|
2603
|
+
do {
|
|
2604
|
+
$write(obj.Stream, temp + LowHi);
|
|
2605
|
+
temp = 255;
|
|
2606
|
+
} while ((obj._cacheSize -= 1) != 0);
|
|
2607
|
+
obj._cache = lowBits_0(obj.Low) >>> 24;
|
|
2608
|
+
}
|
|
2609
|
+
obj._cacheSize += 1;
|
|
2610
|
+
obj.Low = shl(and(obj.Low, [16777215, 0]), 8);
|
|
2315
2611
|
}
|
|
2316
2612
|
function GetPrice(Prob, symbol) {
|
|
2317
|
-
|
|
2613
|
+
return ProbPrices[((Prob - symbol ^ -symbol) & 2047) >>> 2];
|
|
2318
2614
|
}
|
|
2319
2615
|
function decode(utf) {
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
charCodes[j] = ((x & 15) << 12) | ((y & 63) << 6) | (z & 63);
|
|
2364
|
-
}
|
|
2365
|
-
else {
|
|
2366
|
-
// It appears that this is binary data, so it cannot be converted to
|
|
2367
|
-
// a string, so just send it back.
|
|
2368
|
-
return utf;
|
|
2369
|
-
}
|
|
2370
|
-
if (j == 16383) {
|
|
2371
|
-
buf.push(String.fromCharCode.apply(String, charCodes));
|
|
2372
|
-
j = -1;
|
|
2373
|
-
}
|
|
2374
|
-
}
|
|
2375
|
-
if (j > 0) {
|
|
2376
|
-
charCodes.length = j;
|
|
2377
|
-
buf.push(String.fromCharCode.apply(String, charCodes));
|
|
2378
|
-
}
|
|
2379
|
-
return buf.join("");
|
|
2616
|
+
let j = 0, x, y, z, l = utf.length, buf = [], charCodes = [];
|
|
2617
|
+
for (let i = 0; i < l; ++i, ++j) {
|
|
2618
|
+
x = utf[i] & 255;
|
|
2619
|
+
if (!(x & 128)) {
|
|
2620
|
+
if (!x) {
|
|
2621
|
+
return utf;
|
|
2622
|
+
}
|
|
2623
|
+
charCodes[j] = x;
|
|
2624
|
+
} else if ((x & 224) == 192) {
|
|
2625
|
+
if (i + 1 >= l) {
|
|
2626
|
+
return utf;
|
|
2627
|
+
}
|
|
2628
|
+
y = utf[++i] & 255;
|
|
2629
|
+
if ((y & 192) != 128) {
|
|
2630
|
+
return utf;
|
|
2631
|
+
}
|
|
2632
|
+
charCodes[j] = (x & 31) << 6 | y & 63;
|
|
2633
|
+
} else if ((x & 240) == 224) {
|
|
2634
|
+
if (i + 2 >= l) {
|
|
2635
|
+
return utf;
|
|
2636
|
+
}
|
|
2637
|
+
y = utf[++i] & 255;
|
|
2638
|
+
if ((y & 192) != 128) {
|
|
2639
|
+
return utf;
|
|
2640
|
+
}
|
|
2641
|
+
z = utf[++i] & 255;
|
|
2642
|
+
if ((z & 192) != 128) {
|
|
2643
|
+
return utf;
|
|
2644
|
+
}
|
|
2645
|
+
charCodes[j] = (x & 15) << 12 | (y & 63) << 6 | z & 63;
|
|
2646
|
+
} else {
|
|
2647
|
+
return utf;
|
|
2648
|
+
}
|
|
2649
|
+
if (j == 16383) {
|
|
2650
|
+
buf.push(String.fromCharCode.apply(String, charCodes));
|
|
2651
|
+
j = -1;
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
if (j > 0) {
|
|
2655
|
+
charCodes.length = j;
|
|
2656
|
+
buf.push(String.fromCharCode.apply(String, charCodes));
|
|
2657
|
+
}
|
|
2658
|
+
return buf.join("");
|
|
2380
2659
|
}
|
|
2381
2660
|
function encode(s) {
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
data[elen++] = (224 | ch >> 12 & 15) << 24 >> 24;
|
|
2417
|
-
data[elen++] = (128 | ch >> 6 & 63) << 24 >> 24;
|
|
2418
|
-
data[elen++] = (128 | ch & 63) << 24 >> 24;
|
|
2419
|
-
}
|
|
2420
|
-
}
|
|
2421
|
-
return data;
|
|
2422
|
-
}
|
|
2423
|
-
/**
|
|
2424
|
-
* s - dictionary size
|
|
2425
|
-
* f - fb
|
|
2426
|
-
* m - matchFinder
|
|
2427
|
-
*
|
|
2428
|
-
* NOTE: Because some values are always the same, they have been removed.
|
|
2429
|
-
* lc is always 3
|
|
2430
|
-
* lp is always 0
|
|
2431
|
-
* pb is always 2
|
|
2432
|
-
*/
|
|
2661
|
+
let ch, chars = [], elen = 0, l = s.length;
|
|
2662
|
+
if (typeof s == "object") {
|
|
2663
|
+
return s;
|
|
2664
|
+
} else {
|
|
2665
|
+
$getChars(s, 0, l, chars, 0);
|
|
2666
|
+
}
|
|
2667
|
+
for (let i = 0; i < l; ++i) {
|
|
2668
|
+
ch = chars[i];
|
|
2669
|
+
if (ch >= 1 && ch <= 127) {
|
|
2670
|
+
;
|
|
2671
|
+
++elen;
|
|
2672
|
+
} else if (!ch || ch >= 128 && ch <= 2047) {
|
|
2673
|
+
elen += 2;
|
|
2674
|
+
} else {
|
|
2675
|
+
elen += 3;
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
const data = [];
|
|
2679
|
+
elen = 0;
|
|
2680
|
+
for (let i = 0; i < l; ++i) {
|
|
2681
|
+
ch = chars[i];
|
|
2682
|
+
if (ch >= 1 && ch <= 127) {
|
|
2683
|
+
data[elen++] = ch << 24 >> 24;
|
|
2684
|
+
} else if (!ch || ch >= 128 && ch <= 2047) {
|
|
2685
|
+
data[elen++] = (192 | ch >> 6 & 31) << 24 >> 24;
|
|
2686
|
+
data[elen++] = (128 | ch & 63) << 24 >> 24;
|
|
2687
|
+
} else {
|
|
2688
|
+
data[elen++] = (224 | ch >> 12 & 15) << 24 >> 24;
|
|
2689
|
+
data[elen++] = (128 | ch >> 6 & 63) << 24 >> 24;
|
|
2690
|
+
data[elen++] = (128 | ch & 63) << 24 >> 24;
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
return data;
|
|
2694
|
+
}
|
|
2433
2695
|
const ModeMap = {
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2696
|
+
1: { s: 16, f: 64, m: 0 },
|
|
2697
|
+
2: { s: 20, f: 64, m: 0 },
|
|
2698
|
+
3: { s: 19, f: 64, m: 1 },
|
|
2699
|
+
4: { s: 20, f: 64, m: 1 },
|
|
2700
|
+
5: { s: 21, f: 128, m: 1 },
|
|
2701
|
+
6: { s: 22, f: 128, m: 1 },
|
|
2702
|
+
7: { s: 23, f: 128, m: 1 },
|
|
2703
|
+
8: { s: 24, f: 255, m: 1 },
|
|
2704
|
+
9: { s: 25, f: 255, m: 1 }
|
|
2443
2705
|
};
|
|
2444
2706
|
function compress(data, mode = 5) {
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2707
|
+
const obj = {
|
|
2708
|
+
c: $LZMAByteArrayCompressor(
|
|
2709
|
+
{},
|
|
2710
|
+
encode(data),
|
|
2711
|
+
ModeMap[mode]
|
|
2712
|
+
)
|
|
2713
|
+
};
|
|
2714
|
+
while ($processChunkEncode(obj.c.chunker))
|
|
2715
|
+
;
|
|
2716
|
+
return new Int8Array($toByteArray(obj.c.output));
|
|
2451
2717
|
}
|
|
2452
|
-
exports.compress = compress;
|
|
2453
2718
|
function decompress(bytearray) {
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2719
|
+
const obj = {
|
|
2720
|
+
d: $LZMAByteArrayDecompressor({}, bytearray)
|
|
2721
|
+
};
|
|
2722
|
+
while ($processChunkDecode(obj.d.chunker)) {
|
|
2723
|
+
}
|
|
2724
|
+
const decoded = decode($toByteArray(obj.d.output));
|
|
2725
|
+
if (decoded instanceof Array) {
|
|
2726
|
+
return new Int8Array(decoded);
|
|
2727
|
+
}
|
|
2728
|
+
return decoded;
|
|
2463
2729
|
}
|
|
2464
|
-
exports.decompress = decompress;
|