roxify 1.12.11 → 1.13.1
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/Cargo.toml +98 -98
- package/dist/cli.js +134 -92
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/pack.js +1 -1
- package/dist/{roxify_native → roxify-cli} +0 -0
- package/dist/utils/decoder.js +59 -7
- package/dist/utils/encoder.js +12 -23
- package/dist/utils/optimization.js +2 -24
- package/dist/utils/rust-cli-wrapper.d.ts +3 -0
- package/dist/utils/rust-cli-wrapper.js +85 -55
- package/dist/utils/zstd.js +1 -1
- package/native/bwt.rs +56 -56
- package/native/context_mixing.rs +117 -117
- package/native/core.rs +423 -382
- package/native/encoder.rs +635 -629
- package/native/gpu.rs +116 -116
- package/native/hybrid.rs +287 -287
- package/native/lib.rs +489 -489
- package/native/main.rs +527 -534
- package/native/mtf.rs +106 -106
- package/native/packer.rs +447 -447
- package/native/png_utils.rs +538 -538
- package/native/rans_byte.rs +286 -286
- package/native/streaming.rs +212 -212
- package/native/streaming_encode.rs +7 -4
- package/native/test_small_bwt.rs +31 -31
- package/package.json +114 -114
- package/roxify_native-x86_64-unknown-linux-gnu.node +0 -0
package/native/mtf.rs
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
pub fn mtf_encode(data: &[u8]) -> Vec<u8> {
|
|
2
|
-
let mut table = [0u8; 256];
|
|
3
|
-
for i in 0..256 {
|
|
4
|
-
table[i] = i as u8;
|
|
5
|
-
}
|
|
6
|
-
let mut output = Vec::with_capacity(data.len());
|
|
7
|
-
|
|
8
|
-
for &byte in data {
|
|
9
|
-
let pos =
|
|
10
|
-
output.push(pos as u8);
|
|
11
|
-
if pos > 0 {
|
|
12
|
-
let val = table[pos];
|
|
13
|
-
table.copy_within(0..pos, 1);
|
|
14
|
-
table[0] = val;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
output
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
pub fn mtf_decode(data: &[u8]) -> Vec<u8> {
|
|
22
|
-
let mut table = [0u8; 256];
|
|
23
|
-
for i in 0..256 {
|
|
24
|
-
table[i] = i as u8;
|
|
25
|
-
}
|
|
26
|
-
let mut output = Vec::with_capacity(data.len());
|
|
27
|
-
|
|
28
|
-
for &idx in data {
|
|
29
|
-
let pos = idx as usize;
|
|
30
|
-
let byte = table[pos];
|
|
31
|
-
output.push(byte);
|
|
32
|
-
if pos > 0 {
|
|
33
|
-
let val = table[pos];
|
|
34
|
-
table.copy_within(0..pos, 1);
|
|
35
|
-
table[0] = val;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
output
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
pub fn rle0_encode(data: &[u8]) -> Vec<u8> {
|
|
43
|
-
let mut output = Vec::with_capacity(data.len());
|
|
44
|
-
let mut i = 0;
|
|
45
|
-
|
|
46
|
-
while i < data.len() {
|
|
47
|
-
if data[i] == 0 {
|
|
48
|
-
let mut run = 0u32;
|
|
49
|
-
while i < data.len() && data[i] == 0 {
|
|
50
|
-
run += 1;
|
|
51
|
-
i += 1;
|
|
52
|
-
}
|
|
53
|
-
output.push(0);
|
|
54
|
-
if run <= 127 {
|
|
55
|
-
output.push(run as u8);
|
|
56
|
-
} else if run <= 16383 {
|
|
57
|
-
output.push(0x80 | ((run >> 8) as u8));
|
|
58
|
-
output.push((run & 0xFF) as u8);
|
|
59
|
-
} else {
|
|
60
|
-
output.push(0xC0 | ((run >> 16) as u8));
|
|
61
|
-
output.push(((run >> 8) & 0xFF) as u8);
|
|
62
|
-
output.push((run & 0xFF) as u8);
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
output.push(data[i]);
|
|
66
|
-
i += 1;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
output
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
pub fn rle0_decode(data: &[u8]) -> Vec<u8> {
|
|
74
|
-
let mut output = Vec::with_capacity(data.len() * 2);
|
|
75
|
-
let mut i = 0;
|
|
76
|
-
|
|
77
|
-
while i < data.len() {
|
|
78
|
-
if data[i] == 0 {
|
|
79
|
-
i += 1;
|
|
80
|
-
if i >= data.len() {
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
let run;
|
|
84
|
-
if data[i] & 0xC0 == 0xC0 {
|
|
85
|
-
let hi = (data[i] & 0x3F) as u32;
|
|
86
|
-
run = (hi << 16) | ((data[i + 1] as u32) << 8) | (data[i + 2] as u32);
|
|
87
|
-
i += 3;
|
|
88
|
-
} else if data[i] & 0x80 != 0 {
|
|
89
|
-
let hi = (data[i] & 0x7F) as u32;
|
|
90
|
-
run = (hi << 8) | (data[i + 1] as u32);
|
|
91
|
-
i += 2;
|
|
92
|
-
} else {
|
|
93
|
-
run = data[i] as u32;
|
|
94
|
-
i += 1;
|
|
95
|
-
}
|
|
96
|
-
for _ in 0..run {
|
|
97
|
-
output.push(0);
|
|
98
|
-
}
|
|
99
|
-
} else {
|
|
100
|
-
output.push(data[i]);
|
|
101
|
-
i += 1;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
output
|
|
106
|
-
}
|
|
1
|
+
pub fn mtf_encode(data: &[u8]) -> Vec<u8> {
|
|
2
|
+
let mut table = [0u8; 256];
|
|
3
|
+
for i in 0..256 {
|
|
4
|
+
table[i] = i as u8;
|
|
5
|
+
}
|
|
6
|
+
let mut output = Vec::with_capacity(data.len());
|
|
7
|
+
|
|
8
|
+
for &byte in data {
|
|
9
|
+
let pos = table.iter().position(|&b| b == byte).unwrap();
|
|
10
|
+
output.push(pos as u8);
|
|
11
|
+
if pos > 0 {
|
|
12
|
+
let val = table[pos];
|
|
13
|
+
table.copy_within(0..pos, 1);
|
|
14
|
+
table[0] = val;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
output
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
pub fn mtf_decode(data: &[u8]) -> Vec<u8> {
|
|
22
|
+
let mut table = [0u8; 256];
|
|
23
|
+
for i in 0..256 {
|
|
24
|
+
table[i] = i as u8;
|
|
25
|
+
}
|
|
26
|
+
let mut output = Vec::with_capacity(data.len());
|
|
27
|
+
|
|
28
|
+
for &idx in data {
|
|
29
|
+
let pos = idx as usize;
|
|
30
|
+
let byte = table[pos];
|
|
31
|
+
output.push(byte);
|
|
32
|
+
if pos > 0 {
|
|
33
|
+
let val = table[pos];
|
|
34
|
+
table.copy_within(0..pos, 1);
|
|
35
|
+
table[0] = val;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
output
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
pub fn rle0_encode(data: &[u8]) -> Vec<u8> {
|
|
43
|
+
let mut output = Vec::with_capacity(data.len());
|
|
44
|
+
let mut i = 0;
|
|
45
|
+
|
|
46
|
+
while i < data.len() {
|
|
47
|
+
if data[i] == 0 {
|
|
48
|
+
let mut run = 0u32;
|
|
49
|
+
while i < data.len() && data[i] == 0 {
|
|
50
|
+
run += 1;
|
|
51
|
+
i += 1;
|
|
52
|
+
}
|
|
53
|
+
output.push(0);
|
|
54
|
+
if run <= 127 {
|
|
55
|
+
output.push(run as u8);
|
|
56
|
+
} else if run <= 16383 {
|
|
57
|
+
output.push(0x80 | ((run >> 8) as u8));
|
|
58
|
+
output.push((run & 0xFF) as u8);
|
|
59
|
+
} else {
|
|
60
|
+
output.push(0xC0 | ((run >> 16) as u8));
|
|
61
|
+
output.push(((run >> 8) & 0xFF) as u8);
|
|
62
|
+
output.push((run & 0xFF) as u8);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
output.push(data[i]);
|
|
66
|
+
i += 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
output
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
pub fn rle0_decode(data: &[u8]) -> Vec<u8> {
|
|
74
|
+
let mut output = Vec::with_capacity(data.len() * 2);
|
|
75
|
+
let mut i = 0;
|
|
76
|
+
|
|
77
|
+
while i < data.len() {
|
|
78
|
+
if data[i] == 0 {
|
|
79
|
+
i += 1;
|
|
80
|
+
if i >= data.len() {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
let run;
|
|
84
|
+
if data[i] & 0xC0 == 0xC0 {
|
|
85
|
+
let hi = (data[i] & 0x3F) as u32;
|
|
86
|
+
run = (hi << 16) | ((data[i + 1] as u32) << 8) | (data[i + 2] as u32);
|
|
87
|
+
i += 3;
|
|
88
|
+
} else if data[i] & 0x80 != 0 {
|
|
89
|
+
let hi = (data[i] & 0x7F) as u32;
|
|
90
|
+
run = (hi << 8) | (data[i + 1] as u32);
|
|
91
|
+
i += 2;
|
|
92
|
+
} else {
|
|
93
|
+
run = data[i] as u32;
|
|
94
|
+
i += 1;
|
|
95
|
+
}
|
|
96
|
+
for _ in 0..run {
|
|
97
|
+
output.push(0);
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
output.push(data[i]);
|
|
101
|
+
i += 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
output
|
|
106
|
+
}
|