extlzham 0.0.1.PROTOTYPE3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +27 -0
- data/README.md +74 -0
- data/Rakefile +152 -0
- data/contrib/lzham/LICENSE +22 -0
- data/contrib/lzham/README.md +209 -0
- data/contrib/lzham/include/lzham.h +781 -0
- data/contrib/lzham/lzhamcomp/lzham_comp.h +38 -0
- data/contrib/lzham/lzhamcomp/lzham_lzbase.cpp +244 -0
- data/contrib/lzham/lzhamcomp/lzham_lzbase.h +45 -0
- data/contrib/lzham/lzhamcomp/lzham_lzcomp.cpp +608 -0
- data/contrib/lzham/lzhamcomp/lzham_lzcomp_internal.cpp +1966 -0
- data/contrib/lzham/lzhamcomp/lzham_lzcomp_internal.h +472 -0
- data/contrib/lzham/lzhamcomp/lzham_lzcomp_state.cpp +1413 -0
- data/contrib/lzham/lzhamcomp/lzham_match_accel.cpp +562 -0
- data/contrib/lzham/lzhamcomp/lzham_match_accel.h +146 -0
- data/contrib/lzham/lzhamcomp/lzham_null_threading.h +97 -0
- data/contrib/lzham/lzhamcomp/lzham_pthreads_threading.cpp +229 -0
- data/contrib/lzham/lzhamcomp/lzham_pthreads_threading.h +520 -0
- data/contrib/lzham/lzhamcomp/lzham_threading.h +12 -0
- data/contrib/lzham/lzhamcomp/lzham_win32_threading.cpp +220 -0
- data/contrib/lzham/lzhamcomp/lzham_win32_threading.h +368 -0
- data/contrib/lzham/lzhamdecomp/lzham_assert.cpp +66 -0
- data/contrib/lzham/lzhamdecomp/lzham_assert.h +40 -0
- data/contrib/lzham/lzhamdecomp/lzham_checksum.cpp +73 -0
- data/contrib/lzham/lzhamdecomp/lzham_checksum.h +13 -0
- data/contrib/lzham/lzhamdecomp/lzham_config.h +23 -0
- data/contrib/lzham/lzhamdecomp/lzham_core.h +264 -0
- data/contrib/lzham/lzhamdecomp/lzham_decomp.h +37 -0
- data/contrib/lzham/lzhamdecomp/lzham_helpers.h +54 -0
- data/contrib/lzham/lzhamdecomp/lzham_huffman_codes.cpp +262 -0
- data/contrib/lzham/lzhamdecomp/lzham_huffman_codes.h +14 -0
- data/contrib/lzham/lzhamdecomp/lzham_lzdecomp.cpp +1527 -0
- data/contrib/lzham/lzhamdecomp/lzham_lzdecompbase.cpp +131 -0
- data/contrib/lzham/lzhamdecomp/lzham_lzdecompbase.h +89 -0
- data/contrib/lzham/lzhamdecomp/lzham_math.h +142 -0
- data/contrib/lzham/lzhamdecomp/lzham_mem.cpp +284 -0
- data/contrib/lzham/lzhamdecomp/lzham_mem.h +112 -0
- data/contrib/lzham/lzhamdecomp/lzham_platform.cpp +157 -0
- data/contrib/lzham/lzhamdecomp/lzham_platform.h +284 -0
- data/contrib/lzham/lzhamdecomp/lzham_prefix_coding.cpp +351 -0
- data/contrib/lzham/lzhamdecomp/lzham_prefix_coding.h +146 -0
- data/contrib/lzham/lzhamdecomp/lzham_symbol_codec.cpp +1484 -0
- data/contrib/lzham/lzhamdecomp/lzham_symbol_codec.h +556 -0
- data/contrib/lzham/lzhamdecomp/lzham_timer.cpp +147 -0
- data/contrib/lzham/lzhamdecomp/lzham_timer.h +99 -0
- data/contrib/lzham/lzhamdecomp/lzham_traits.h +141 -0
- data/contrib/lzham/lzhamdecomp/lzham_types.h +97 -0
- data/contrib/lzham/lzhamdecomp/lzham_utils.h +58 -0
- data/contrib/lzham/lzhamdecomp/lzham_vector.cpp +75 -0
- data/contrib/lzham/lzhamdecomp/lzham_vector.h +588 -0
- data/contrib/lzham/lzhamlib/lzham_lib.cpp +179 -0
- data/examples/basic.rb +48 -0
- data/ext/constants.c +64 -0
- data/ext/decoder.c +313 -0
- data/ext/depend +5 -0
- data/ext/encoder.c +372 -0
- data/ext/error.c +80 -0
- data/ext/extconf.rb +29 -0
- data/ext/extlzham.c +34 -0
- data/ext/extlzham.h +62 -0
- data/gemstub.rb +22 -0
- data/lib/2.0/extlzham.so +0 -0
- data/lib/2.1/extlzham.so +0 -0
- data/lib/2.2/extlzham.so +0 -0
- data/lib/extlzham.rb +158 -0
- data/lib/extlzham/version.rb +5 -0
- data/test/test_extlzham.rb +35 -0
- metadata +156 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
// File: lzham_comp.h
|
2
|
+
// See Copyright Notice and license at the end of include/lzham.h
|
3
|
+
#pragma once
|
4
|
+
#include "lzham.h"
|
5
|
+
|
6
|
+
namespace lzham
|
7
|
+
{
|
8
|
+
lzham_compress_state_ptr LZHAM_CDECL lzham_lib_compress_init(const lzham_compress_params *pParams);
|
9
|
+
|
10
|
+
lzham_compress_state_ptr LZHAM_CDECL lzham_lib_compress_reinit(lzham_compress_state_ptr p);
|
11
|
+
|
12
|
+
lzham_uint32 LZHAM_CDECL lzham_lib_compress_deinit(lzham_compress_state_ptr p);
|
13
|
+
|
14
|
+
lzham_compress_status_t LZHAM_CDECL lzham_lib_compress(
|
15
|
+
lzham_compress_state_ptr p,
|
16
|
+
const lzham_uint8 *pIn_buf, size_t *pIn_buf_size,
|
17
|
+
lzham_uint8 *pOut_buf, size_t *pOut_buf_size,
|
18
|
+
lzham_bool no_more_input_bytes_flag);
|
19
|
+
|
20
|
+
lzham_compress_status_t LZHAM_CDECL lzham_lib_compress2(
|
21
|
+
lzham_compress_state_ptr p,
|
22
|
+
const lzham_uint8 *pIn_buf, size_t *pIn_buf_size,
|
23
|
+
lzham_uint8 *pOut_buf, size_t *pOut_buf_size,
|
24
|
+
lzham_flush_t flush_type);
|
25
|
+
|
26
|
+
lzham_compress_status_t LZHAM_CDECL lzham_lib_compress_memory(const lzham_compress_params *pParams, lzham_uint8* pDst_buf, size_t *pDst_len, const lzham_uint8* pSrc_buf, size_t src_len, lzham_uint32 *pAdler32);
|
27
|
+
|
28
|
+
int lzham_lib_z_deflateInit(lzham_z_streamp pStream, int level);
|
29
|
+
int lzham_lib_z_deflateInit2(lzham_z_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
|
30
|
+
int lzham_lib_z_deflateReset(lzham_z_streamp pStream);
|
31
|
+
int lzham_lib_z_deflate(lzham_z_streamp pStream, int flush);
|
32
|
+
int lzham_lib_z_deflateEnd(lzham_z_streamp pStream);
|
33
|
+
lzham_z_ulong lzham_lib_z_deflateBound(lzham_z_streamp pStream, lzham_z_ulong source_len);
|
34
|
+
int lzham_lib_z_compress2(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len, int level);
|
35
|
+
int lzham_lib_z_compress(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len);
|
36
|
+
lzham_z_ulong lzham_lib_z_compressBound(lzham_z_ulong source_len);
|
37
|
+
|
38
|
+
} // namespace lzham
|
@@ -0,0 +1,244 @@
|
|
1
|
+
// File: lzham_lzbase.cpp
|
2
|
+
// See Copyright Notice and license at the end of include/lzham.h
|
3
|
+
#include "lzham_core.h"
|
4
|
+
#include "lzham_lzbase.h"
|
5
|
+
|
6
|
+
namespace lzham
|
7
|
+
{
|
8
|
+
uint8 CLZBase::m_slot_tab0[4096] =
|
9
|
+
{
|
10
|
+
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
|
11
|
+
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
12
|
+
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
13
|
+
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
14
|
+
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
15
|
+
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
16
|
+
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
17
|
+
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
18
|
+
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
19
|
+
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
20
|
+
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
21
|
+
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
22
|
+
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
23
|
+
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
24
|
+
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
25
|
+
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
26
|
+
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
|
27
|
+
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
|
28
|
+
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
|
29
|
+
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
|
30
|
+
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
|
31
|
+
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
|
32
|
+
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
|
33
|
+
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
|
34
|
+
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
35
|
+
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
36
|
+
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
37
|
+
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
38
|
+
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
39
|
+
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
40
|
+
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
41
|
+
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
42
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
43
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
44
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
45
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
46
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
47
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
48
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
49
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
50
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
51
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
52
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
53
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
54
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
55
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
56
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
57
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
58
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
59
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
60
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
61
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
62
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
63
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
64
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
65
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
66
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
67
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
68
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
69
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
70
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
71
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
72
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
73
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
74
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
75
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
76
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
77
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
78
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
79
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
80
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
81
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
82
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
83
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
84
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
85
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
86
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
87
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
88
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
89
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
90
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
91
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
92
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
93
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
94
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
95
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
96
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
97
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
98
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
99
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
100
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
101
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
102
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
103
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
104
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
105
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
106
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
107
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
108
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
109
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
110
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
111
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
112
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
113
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
114
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
115
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
116
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
117
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
118
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
119
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
120
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
121
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
122
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
123
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
124
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
125
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
126
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
127
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
128
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
129
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
130
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
131
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
132
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
133
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
134
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
135
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
136
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
137
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23
|
138
|
+
};
|
139
|
+
|
140
|
+
uint8 CLZBase::m_slot_tab1[512] =
|
141
|
+
{
|
142
|
+
0, 0, 24, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31,
|
143
|
+
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
|
144
|
+
34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
|
145
|
+
35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
|
146
|
+
36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
|
147
|
+
36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
|
148
|
+
37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
|
149
|
+
37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
|
150
|
+
38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
151
|
+
38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
152
|
+
38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
153
|
+
38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
154
|
+
39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
|
155
|
+
39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
|
156
|
+
39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
|
157
|
+
39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39
|
158
|
+
};
|
159
|
+
|
160
|
+
uint8 CLZBase::m_slot_tab2[256] =
|
161
|
+
{
|
162
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 40, 40, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41,
|
163
|
+
42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
|
164
|
+
44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
|
165
|
+
45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
166
|
+
46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
|
167
|
+
46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
|
168
|
+
47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
|
169
|
+
47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47
|
170
|
+
};
|
171
|
+
|
172
|
+
void CLZBase::init_slot_tabs()
|
173
|
+
{
|
174
|
+
#if 0
|
175
|
+
for (uint i = 0; i < m_num_lzx_slots; i++)
|
176
|
+
{
|
177
|
+
//printf("%u: 0x%08X - 0x%08X, %u\n", i, m_lzx_position_base[i], m_lzx_position_base[i] + (1 << m_lzx_position_extra_bits[i]) - 1, m_lzx_position_extra_bits[i]);
|
178
|
+
|
179
|
+
uint lo = m_lzx_position_base[i];
|
180
|
+
uint hi = lo + m_lzx_position_extra_mask[i];
|
181
|
+
|
182
|
+
uint8* pTab;
|
183
|
+
uint shift;
|
184
|
+
uint n; LZHAM_NOTE_UNUSED(n);
|
185
|
+
|
186
|
+
if (hi < 0x1000)
|
187
|
+
{
|
188
|
+
pTab = m_slot_tab0;
|
189
|
+
shift = 0;
|
190
|
+
n = sizeof(m_slot_tab0);
|
191
|
+
}
|
192
|
+
else if (hi < 0x100000)
|
193
|
+
{
|
194
|
+
pTab = m_slot_tab1;
|
195
|
+
shift = 11;
|
196
|
+
n = sizeof(m_slot_tab1);
|
197
|
+
}
|
198
|
+
else if (hi < 0x1000000)
|
199
|
+
{
|
200
|
+
pTab = m_slot_tab2;
|
201
|
+
shift = 16;
|
202
|
+
n = sizeof(m_slot_tab2);
|
203
|
+
}
|
204
|
+
else
|
205
|
+
break;
|
206
|
+
|
207
|
+
lo >>= shift;
|
208
|
+
hi >>= shift;
|
209
|
+
|
210
|
+
LZHAM_ASSERT(hi < n);
|
211
|
+
memset(pTab + lo, (uint8)i, hi - lo + 1);
|
212
|
+
}
|
213
|
+
|
214
|
+
for (uint i = 0; i < 256; i++)
|
215
|
+
{
|
216
|
+
printf("%u, ", m_slot_tab2[i]);
|
217
|
+
if ((i & 31) == 31) printf("\n");
|
218
|
+
}
|
219
|
+
#endif
|
220
|
+
|
221
|
+
#ifdef LZHAM_BUILD_DEBUG
|
222
|
+
uint slot, ofs;
|
223
|
+
for (uint i = 1; i < m_num_lzx_slots; i++)
|
224
|
+
{
|
225
|
+
compute_lzx_position_slot(m_lzx_position_base[i], slot, ofs);
|
226
|
+
LZHAM_ASSERT(slot == i);
|
227
|
+
|
228
|
+
compute_lzx_position_slot(m_lzx_position_base[i] + m_lzx_position_extra_mask[i], slot, ofs);
|
229
|
+
LZHAM_ASSERT(slot == i);
|
230
|
+
}
|
231
|
+
|
232
|
+
for (uint i = 1; i <= (m_dict_size-1); i += 512U*1024U)
|
233
|
+
{
|
234
|
+
compute_lzx_position_slot(i, slot, ofs);
|
235
|
+
LZHAM_ASSERT(i == m_lzx_position_base[slot] + ofs);
|
236
|
+
}
|
237
|
+
|
238
|
+
compute_lzx_position_slot(m_dict_size - 1, slot, ofs);
|
239
|
+
LZHAM_ASSERT((m_dict_size - 1) == m_lzx_position_base[slot] + ofs);
|
240
|
+
#endif
|
241
|
+
}
|
242
|
+
|
243
|
+
} //namespace lzham
|
244
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
// File: lzham_lzbase.h
|
2
|
+
// See Copyright Notice and license at the end of include/lzham.h
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "lzham_lzdecompbase.h"
|
6
|
+
|
7
|
+
//#define LZHAM_LZVERIFY
|
8
|
+
//#define LZHAM_DISABLE_RAW_BLOCKS
|
9
|
+
|
10
|
+
namespace lzham
|
11
|
+
{
|
12
|
+
struct CLZBase : CLZDecompBase
|
13
|
+
{
|
14
|
+
static uint8 m_slot_tab0[4096];
|
15
|
+
static uint8 m_slot_tab1[512];
|
16
|
+
static uint8 m_slot_tab2[256];
|
17
|
+
|
18
|
+
void init_slot_tabs();
|
19
|
+
|
20
|
+
inline void compute_lzx_position_slot(uint dist, uint& slot, uint& ofs)
|
21
|
+
{
|
22
|
+
uint s;
|
23
|
+
if (dist < 0x1000)
|
24
|
+
s = m_slot_tab0[dist];
|
25
|
+
else if (dist < 0x100000)
|
26
|
+
s = m_slot_tab1[dist >> 11];
|
27
|
+
else if (dist < 0x1000000)
|
28
|
+
s = m_slot_tab2[dist >> 16];
|
29
|
+
else if (dist < 0x2000000)
|
30
|
+
s = 48 + ((dist - 0x1000000) >> 23);
|
31
|
+
else if (dist < 0x4000000)
|
32
|
+
s = 50 + ((dist - 0x2000000) >> 24);
|
33
|
+
else
|
34
|
+
s = 52 + ((dist - 0x4000000) >> 25);
|
35
|
+
|
36
|
+
ofs = (dist - m_lzx_position_base[s]) & m_lzx_position_extra_mask[s];
|
37
|
+
slot = s;
|
38
|
+
|
39
|
+
LZHAM_ASSERT(s < m_num_lzx_slots);
|
40
|
+
LZHAM_ASSERT((m_lzx_position_base[slot] + ofs) == dist);
|
41
|
+
LZHAM_ASSERT(ofs < (1U << m_lzx_position_extra_bits[slot]));
|
42
|
+
}
|
43
|
+
};
|
44
|
+
|
45
|
+
} // namespace lzham
|
@@ -0,0 +1,608 @@
|
|
1
|
+
// File: lzham_lzcomp.cpp
|
2
|
+
// See Copyright Notice and license at the end of include/lzham.h
|
3
|
+
#include "lzham_core.h"
|
4
|
+
#include "lzham.h"
|
5
|
+
#include "lzham_comp.h"
|
6
|
+
#include "lzham_lzcomp_internal.h"
|
7
|
+
|
8
|
+
using namespace lzham;
|
9
|
+
|
10
|
+
namespace lzham
|
11
|
+
{
|
12
|
+
struct lzham_compress_state
|
13
|
+
{
|
14
|
+
// task_pool requires 8 or 16 alignment
|
15
|
+
task_pool m_tp;
|
16
|
+
lzcompressor m_compressor;
|
17
|
+
|
18
|
+
uint m_dict_size_log2;
|
19
|
+
|
20
|
+
const uint8 *m_pIn_buf;
|
21
|
+
size_t *m_pIn_buf_size;
|
22
|
+
uint8 *m_pOut_buf;
|
23
|
+
size_t *m_pOut_buf_size;
|
24
|
+
|
25
|
+
size_t m_comp_data_ofs;
|
26
|
+
|
27
|
+
bool m_finished_compression;
|
28
|
+
|
29
|
+
lzham_compress_params m_params;
|
30
|
+
|
31
|
+
lzham_compress_status_t m_status;
|
32
|
+
};
|
33
|
+
|
34
|
+
static lzham_compress_status_t create_internal_init_params(lzcompressor::init_params &internal_params, const lzham_compress_params *pParams)
|
35
|
+
{
|
36
|
+
if ((pParams->m_dict_size_log2 < CLZBase::cMinDictSizeLog2) || (pParams->m_dict_size_log2 > CLZBase::cMaxDictSizeLog2))
|
37
|
+
return LZHAM_COMP_STATUS_INVALID_PARAMETER;
|
38
|
+
|
39
|
+
internal_params.m_dict_size_log2 = pParams->m_dict_size_log2;
|
40
|
+
|
41
|
+
if (pParams->m_max_helper_threads < 0)
|
42
|
+
internal_params.m_max_helper_threads = lzham_get_max_helper_threads();
|
43
|
+
else
|
44
|
+
internal_params.m_max_helper_threads = pParams->m_max_helper_threads;
|
45
|
+
internal_params.m_max_helper_threads = LZHAM_MIN(LZHAM_MAX_HELPER_THREADS, internal_params.m_max_helper_threads);
|
46
|
+
|
47
|
+
internal_params.m_lzham_compress_flags = pParams->m_compress_flags;
|
48
|
+
|
49
|
+
if (pParams->m_num_seed_bytes)
|
50
|
+
{
|
51
|
+
if ((!pParams->m_pSeed_bytes) || (pParams->m_num_seed_bytes > (1U << pParams->m_dict_size_log2)))
|
52
|
+
return LZHAM_COMP_STATUS_INVALID_PARAMETER;
|
53
|
+
|
54
|
+
internal_params.m_num_seed_bytes = pParams->m_num_seed_bytes;
|
55
|
+
internal_params.m_pSeed_bytes = pParams->m_pSeed_bytes;
|
56
|
+
}
|
57
|
+
|
58
|
+
switch (pParams->m_level)
|
59
|
+
{
|
60
|
+
case LZHAM_COMP_LEVEL_FASTEST: internal_params.m_compression_level = cCompressionLevelFastest; break;
|
61
|
+
case LZHAM_COMP_LEVEL_FASTER: internal_params.m_compression_level = cCompressionLevelFaster; break;
|
62
|
+
case LZHAM_COMP_LEVEL_DEFAULT: internal_params.m_compression_level = cCompressionLevelDefault; break;
|
63
|
+
case LZHAM_COMP_LEVEL_BETTER: internal_params.m_compression_level = cCompressionLevelBetter; break;
|
64
|
+
case LZHAM_COMP_LEVEL_UBER: internal_params.m_compression_level = cCompressionLevelUber; break;
|
65
|
+
default:
|
66
|
+
return LZHAM_COMP_STATUS_INVALID_PARAMETER;
|
67
|
+
};
|
68
|
+
|
69
|
+
if (pParams->m_table_max_update_interval || pParams->m_table_update_interval_slow_rate)
|
70
|
+
{
|
71
|
+
internal_params.m_table_max_update_interval = pParams->m_table_max_update_interval;
|
72
|
+
internal_params.m_table_update_interval_slow_rate = pParams->m_table_update_interval_slow_rate;
|
73
|
+
}
|
74
|
+
else
|
75
|
+
{
|
76
|
+
uint rate = pParams->m_table_update_rate;
|
77
|
+
if (!rate)
|
78
|
+
rate = LZHAM_DEFAULT_TABLE_UPDATE_RATE;
|
79
|
+
rate = math::clamp<uint>(rate, 1, LZHAM_FASTEST_TABLE_UPDATE_RATE) - 1;
|
80
|
+
internal_params.m_table_max_update_interval = g_table_update_settings[rate].m_max_update_interval;
|
81
|
+
internal_params.m_table_update_interval_slow_rate = g_table_update_settings[rate].m_slow_rate;
|
82
|
+
}
|
83
|
+
|
84
|
+
return LZHAM_COMP_STATUS_SUCCESS;
|
85
|
+
}
|
86
|
+
|
87
|
+
lzham_compress_state_ptr LZHAM_CDECL lzham_lib_compress_init(const lzham_compress_params *pParams)
|
88
|
+
{
|
89
|
+
if ((!pParams) || (pParams->m_struct_size != sizeof(lzham_compress_params)))
|
90
|
+
return NULL;
|
91
|
+
|
92
|
+
if ((pParams->m_dict_size_log2 < CLZBase::cMinDictSizeLog2) || (pParams->m_dict_size_log2 > CLZBase::cMaxDictSizeLog2))
|
93
|
+
return NULL;
|
94
|
+
|
95
|
+
lzcompressor::init_params internal_params;
|
96
|
+
lzham_compress_status_t status = create_internal_init_params(internal_params, pParams);
|
97
|
+
if (status != LZHAM_COMP_STATUS_SUCCESS)
|
98
|
+
return NULL;
|
99
|
+
|
100
|
+
lzham_compress_state *pState = lzham_new<lzham_compress_state>();
|
101
|
+
if (!pState)
|
102
|
+
return NULL;
|
103
|
+
|
104
|
+
pState->m_params = *pParams;
|
105
|
+
|
106
|
+
pState->m_pIn_buf = NULL;
|
107
|
+
pState->m_pIn_buf_size = NULL;
|
108
|
+
pState->m_pOut_buf = NULL;
|
109
|
+
pState->m_pOut_buf_size = NULL;
|
110
|
+
pState->m_status = LZHAM_COMP_STATUS_NOT_FINISHED;
|
111
|
+
pState->m_comp_data_ofs = 0;
|
112
|
+
pState->m_finished_compression = false;
|
113
|
+
|
114
|
+
if (internal_params.m_max_helper_threads)
|
115
|
+
{
|
116
|
+
if (!pState->m_tp.init(internal_params.m_max_helper_threads))
|
117
|
+
{
|
118
|
+
lzham_delete(pState);
|
119
|
+
return NULL;
|
120
|
+
}
|
121
|
+
if (pState->m_tp.get_num_threads() >= internal_params.m_max_helper_threads)
|
122
|
+
{
|
123
|
+
internal_params.m_pTask_pool = &pState->m_tp;
|
124
|
+
}
|
125
|
+
else
|
126
|
+
{
|
127
|
+
internal_params.m_max_helper_threads = 0;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
if (!pState->m_compressor.init(internal_params))
|
132
|
+
{
|
133
|
+
lzham_delete(pState);
|
134
|
+
return NULL;
|
135
|
+
}
|
136
|
+
|
137
|
+
return pState;
|
138
|
+
}
|
139
|
+
|
140
|
+
lzham_compress_state_ptr LZHAM_CDECL lzham_lib_compress_reinit(lzham_compress_state_ptr p)
|
141
|
+
{
|
142
|
+
lzham_compress_state *pState = static_cast<lzham_compress_state*>(p);
|
143
|
+
if (pState)
|
144
|
+
{
|
145
|
+
if (!pState->m_compressor.reset())
|
146
|
+
return NULL;
|
147
|
+
|
148
|
+
pState->m_pIn_buf = NULL;
|
149
|
+
pState->m_pIn_buf_size = NULL;
|
150
|
+
pState->m_pOut_buf = NULL;
|
151
|
+
pState->m_pOut_buf_size = NULL;
|
152
|
+
pState->m_status = LZHAM_COMP_STATUS_NOT_FINISHED;
|
153
|
+
pState->m_comp_data_ofs = 0;
|
154
|
+
pState->m_finished_compression = false;
|
155
|
+
}
|
156
|
+
|
157
|
+
return pState;
|
158
|
+
}
|
159
|
+
|
160
|
+
lzham_uint32 LZHAM_CDECL lzham_lib_compress_deinit(lzham_compress_state_ptr p)
|
161
|
+
{
|
162
|
+
lzham_compress_state *pState = static_cast<lzham_compress_state *>(p);
|
163
|
+
if (!pState)
|
164
|
+
return 0;
|
165
|
+
|
166
|
+
uint32 adler32 = pState->m_compressor.get_src_adler32();
|
167
|
+
|
168
|
+
lzham_delete(pState);
|
169
|
+
|
170
|
+
return adler32;
|
171
|
+
}
|
172
|
+
|
173
|
+
lzham_compress_status_t LZHAM_CDECL lzham_lib_compress(
|
174
|
+
lzham_compress_state_ptr p,
|
175
|
+
const lzham_uint8 *pIn_buf, size_t *pIn_buf_size,
|
176
|
+
lzham_uint8 *pOut_buf, size_t *pOut_buf_size,
|
177
|
+
lzham_bool no_more_input_bytes_flag)
|
178
|
+
{
|
179
|
+
return lzham_lib_compress2(p, pIn_buf, pIn_buf_size, pOut_buf, pOut_buf_size, no_more_input_bytes_flag ? LZHAM_FINISH : LZHAM_NO_FLUSH);
|
180
|
+
}
|
181
|
+
|
182
|
+
lzham_compress_status_t LZHAM_CDECL lzham_lib_compress2(
|
183
|
+
lzham_compress_state_ptr p,
|
184
|
+
const lzham_uint8 *pIn_buf, size_t *pIn_buf_size,
|
185
|
+
lzham_uint8 *pOut_buf, size_t *pOut_buf_size,
|
186
|
+
lzham_flush_t flush_type)
|
187
|
+
{
|
188
|
+
lzham_compress_state *pState = static_cast<lzham_compress_state*>(p);
|
189
|
+
|
190
|
+
if ((!pState) || (!pState->m_params.m_dict_size_log2) || (pState->m_status >= LZHAM_COMP_STATUS_FIRST_SUCCESS_OR_FAILURE_CODE) || (!pIn_buf_size) || (!pOut_buf_size))
|
191
|
+
return LZHAM_COMP_STATUS_INVALID_PARAMETER;
|
192
|
+
|
193
|
+
if ((*pIn_buf_size) && (!pIn_buf))
|
194
|
+
return LZHAM_COMP_STATUS_INVALID_PARAMETER;
|
195
|
+
|
196
|
+
if ((!*pOut_buf_size) || (!pOut_buf))
|
197
|
+
return LZHAM_COMP_STATUS_INVALID_PARAMETER;
|
198
|
+
|
199
|
+
byte_vec &comp_data = pState->m_compressor.get_compressed_data();
|
200
|
+
size_t num_bytes_written_to_out_buf = 0;
|
201
|
+
if (pState->m_comp_data_ofs < comp_data.size())
|
202
|
+
{
|
203
|
+
size_t n = LZHAM_MIN(comp_data.size() - pState->m_comp_data_ofs, *pOut_buf_size);
|
204
|
+
|
205
|
+
memcpy(pOut_buf, comp_data.get_ptr() + pState->m_comp_data_ofs, n);
|
206
|
+
|
207
|
+
pState->m_comp_data_ofs += n;
|
208
|
+
|
209
|
+
const bool has_no_more_output = (pState->m_comp_data_ofs >= comp_data.size());
|
210
|
+
if (has_no_more_output)
|
211
|
+
{
|
212
|
+
pOut_buf += n;
|
213
|
+
*pOut_buf_size -= n;
|
214
|
+
num_bytes_written_to_out_buf += n;
|
215
|
+
}
|
216
|
+
else
|
217
|
+
{
|
218
|
+
*pIn_buf_size = 0;
|
219
|
+
*pOut_buf_size = n;
|
220
|
+
pState->m_status = LZHAM_COMP_STATUS_HAS_MORE_OUTPUT;
|
221
|
+
return pState->m_status;
|
222
|
+
}
|
223
|
+
}
|
224
|
+
|
225
|
+
comp_data.try_resize(0);
|
226
|
+
pState->m_comp_data_ofs = 0;
|
227
|
+
|
228
|
+
if (pState->m_finished_compression)
|
229
|
+
{
|
230
|
+
if ((*pIn_buf_size) || (flush_type != LZHAM_FINISH))
|
231
|
+
{
|
232
|
+
pState->m_status = LZHAM_COMP_STATUS_INVALID_PARAMETER;
|
233
|
+
return pState->m_status;
|
234
|
+
}
|
235
|
+
|
236
|
+
*pIn_buf_size = 0;
|
237
|
+
*pOut_buf_size = num_bytes_written_to_out_buf;
|
238
|
+
|
239
|
+
pState->m_status = LZHAM_COMP_STATUS_SUCCESS;
|
240
|
+
return pState->m_status;
|
241
|
+
}
|
242
|
+
|
243
|
+
const size_t cMaxBytesToPutPerIteration = 4*1024*1024;
|
244
|
+
size_t bytes_to_put = LZHAM_MIN(cMaxBytesToPutPerIteration, *pIn_buf_size);
|
245
|
+
const bool consumed_entire_input_buf = (bytes_to_put == *pIn_buf_size);
|
246
|
+
|
247
|
+
if (bytes_to_put)
|
248
|
+
{
|
249
|
+
if (!pState->m_compressor.put_bytes(pIn_buf, (uint)bytes_to_put))
|
250
|
+
{
|
251
|
+
*pIn_buf_size = 0;
|
252
|
+
*pOut_buf_size = num_bytes_written_to_out_buf;
|
253
|
+
pState->m_status = LZHAM_COMP_STATUS_FAILED;
|
254
|
+
return pState->m_status;
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
if ((consumed_entire_input_buf) && (flush_type != LZHAM_NO_FLUSH))
|
259
|
+
{
|
260
|
+
if ((flush_type == LZHAM_SYNC_FLUSH) || (flush_type == LZHAM_FULL_FLUSH) || (flush_type == LZHAM_TABLE_FLUSH))
|
261
|
+
{
|
262
|
+
if (!pState->m_compressor.flush(flush_type))
|
263
|
+
{
|
264
|
+
*pIn_buf_size = 0;
|
265
|
+
*pOut_buf_size = num_bytes_written_to_out_buf;
|
266
|
+
pState->m_status = LZHAM_COMP_STATUS_FAILED;
|
267
|
+
return pState->m_status;
|
268
|
+
}
|
269
|
+
}
|
270
|
+
else if (!pState->m_finished_compression)
|
271
|
+
{
|
272
|
+
if (!pState->m_compressor.put_bytes(NULL, 0))
|
273
|
+
{
|
274
|
+
*pIn_buf_size = 0;
|
275
|
+
*pOut_buf_size = num_bytes_written_to_out_buf;
|
276
|
+
pState->m_status = LZHAM_COMP_STATUS_FAILED;
|
277
|
+
return pState->m_status;
|
278
|
+
}
|
279
|
+
pState->m_finished_compression = true;
|
280
|
+
}
|
281
|
+
}
|
282
|
+
|
283
|
+
size_t num_comp_bytes_to_output = LZHAM_MIN(comp_data.size() - pState->m_comp_data_ofs, *pOut_buf_size);
|
284
|
+
if (num_comp_bytes_to_output)
|
285
|
+
{
|
286
|
+
memcpy(pOut_buf, comp_data.get_ptr() + pState->m_comp_data_ofs, num_comp_bytes_to_output);
|
287
|
+
|
288
|
+
pState->m_comp_data_ofs += num_comp_bytes_to_output;
|
289
|
+
}
|
290
|
+
|
291
|
+
*pIn_buf_size = bytes_to_put;
|
292
|
+
*pOut_buf_size = num_bytes_written_to_out_buf + num_comp_bytes_to_output;
|
293
|
+
|
294
|
+
const bool has_no_more_output = (pState->m_comp_data_ofs >= comp_data.size());
|
295
|
+
if ((has_no_more_output) && (flush_type == LZHAM_FINISH) && (pState->m_finished_compression))
|
296
|
+
pState->m_status = LZHAM_COMP_STATUS_SUCCESS;
|
297
|
+
else if ((has_no_more_output) && (consumed_entire_input_buf) && (flush_type == LZHAM_NO_FLUSH))
|
298
|
+
pState->m_status = LZHAM_COMP_STATUS_NEEDS_MORE_INPUT;
|
299
|
+
else
|
300
|
+
pState->m_status = has_no_more_output ? LZHAM_COMP_STATUS_NOT_FINISHED : LZHAM_COMP_STATUS_HAS_MORE_OUTPUT;
|
301
|
+
|
302
|
+
return pState->m_status;
|
303
|
+
}
|
304
|
+
|
305
|
+
lzham_compress_status_t LZHAM_CDECL lzham_lib_compress_memory(const lzham_compress_params *pParams, lzham_uint8* pDst_buf, size_t *pDst_len, const lzham_uint8* pSrc_buf, size_t src_len, lzham_uint32 *pAdler32)
|
306
|
+
{
|
307
|
+
if ((!pParams) || (!pDst_len))
|
308
|
+
return LZHAM_COMP_STATUS_INVALID_PARAMETER;
|
309
|
+
|
310
|
+
if (src_len)
|
311
|
+
{
|
312
|
+
if (!pSrc_buf)
|
313
|
+
return LZHAM_COMP_STATUS_INVALID_PARAMETER;
|
314
|
+
}
|
315
|
+
|
316
|
+
if (sizeof(size_t) > sizeof(uint32))
|
317
|
+
{
|
318
|
+
if (src_len > UINT32_MAX)
|
319
|
+
return LZHAM_COMP_STATUS_INVALID_PARAMETER;
|
320
|
+
}
|
321
|
+
|
322
|
+
lzcompressor::init_params internal_params;
|
323
|
+
lzham_compress_status_t status = create_internal_init_params(internal_params, pParams);
|
324
|
+
if (status != LZHAM_COMP_STATUS_SUCCESS)
|
325
|
+
return status;
|
326
|
+
|
327
|
+
task_pool *pTP = NULL;
|
328
|
+
if (internal_params.m_max_helper_threads)
|
329
|
+
{
|
330
|
+
pTP = lzham_new<task_pool>();
|
331
|
+
if (!pTP->init(internal_params.m_max_helper_threads))
|
332
|
+
return LZHAM_COMP_STATUS_FAILED;
|
333
|
+
|
334
|
+
internal_params.m_pTask_pool = pTP;
|
335
|
+
}
|
336
|
+
|
337
|
+
lzcompressor *pCompressor = lzham_new<lzcompressor>();
|
338
|
+
if (!pCompressor)
|
339
|
+
{
|
340
|
+
lzham_delete(pTP);
|
341
|
+
return LZHAM_COMP_STATUS_FAILED;
|
342
|
+
}
|
343
|
+
|
344
|
+
if (!pCompressor->init(internal_params))
|
345
|
+
{
|
346
|
+
lzham_delete(pTP);
|
347
|
+
lzham_delete(pCompressor);
|
348
|
+
return LZHAM_COMP_STATUS_INVALID_PARAMETER;
|
349
|
+
}
|
350
|
+
|
351
|
+
if (src_len)
|
352
|
+
{
|
353
|
+
if (!pCompressor->put_bytes(pSrc_buf, static_cast<uint32>(src_len)))
|
354
|
+
{
|
355
|
+
*pDst_len = 0;
|
356
|
+
lzham_delete(pTP);
|
357
|
+
lzham_delete(pCompressor);
|
358
|
+
return LZHAM_COMP_STATUS_FAILED;
|
359
|
+
}
|
360
|
+
}
|
361
|
+
|
362
|
+
if (!pCompressor->put_bytes(NULL, 0))
|
363
|
+
{
|
364
|
+
*pDst_len = 0;
|
365
|
+
lzham_delete(pTP);
|
366
|
+
lzham_delete(pCompressor);
|
367
|
+
return LZHAM_COMP_STATUS_FAILED;
|
368
|
+
}
|
369
|
+
|
370
|
+
const byte_vec &comp_data = pCompressor->get_compressed_data();
|
371
|
+
|
372
|
+
size_t dst_buf_size = *pDst_len;
|
373
|
+
*pDst_len = comp_data.size();
|
374
|
+
|
375
|
+
if (pAdler32)
|
376
|
+
*pAdler32 = pCompressor->get_src_adler32();
|
377
|
+
|
378
|
+
if (comp_data.size() > dst_buf_size)
|
379
|
+
{
|
380
|
+
lzham_delete(pTP);
|
381
|
+
lzham_delete(pCompressor);
|
382
|
+
return LZHAM_COMP_STATUS_OUTPUT_BUF_TOO_SMALL;
|
383
|
+
}
|
384
|
+
|
385
|
+
memcpy(pDst_buf, comp_data.get_ptr(), comp_data.size());
|
386
|
+
|
387
|
+
lzham_delete(pTP);
|
388
|
+
lzham_delete(pCompressor);
|
389
|
+
return LZHAM_COMP_STATUS_SUCCESS;
|
390
|
+
}
|
391
|
+
|
392
|
+
// ----------------- zlib-style API's
|
393
|
+
|
394
|
+
int lzham_lib_z_deflateInit(lzham_z_streamp pStream, int level)
|
395
|
+
{
|
396
|
+
return lzham_lib_z_deflateInit2(pStream, level, LZHAM_Z_LZHAM, LZHAM_Z_DEFAULT_WINDOW_BITS, 9, LZHAM_Z_DEFAULT_STRATEGY);
|
397
|
+
}
|
398
|
+
|
399
|
+
int lzham_lib_z_deflateInit2(lzham_z_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy)
|
400
|
+
{
|
401
|
+
LZHAM_NOTE_UNUSED(strategy);
|
402
|
+
|
403
|
+
if (!pStream)
|
404
|
+
return LZHAM_Z_STREAM_ERROR;
|
405
|
+
if ((mem_level < 1) || (mem_level > 9))
|
406
|
+
return LZHAM_Z_PARAM_ERROR;
|
407
|
+
if ((method != LZHAM_Z_DEFLATED) && (method != LZHAM_Z_LZHAM))
|
408
|
+
return LZHAM_Z_PARAM_ERROR;
|
409
|
+
|
410
|
+
if (level == LZHAM_Z_DEFAULT_COMPRESSION)
|
411
|
+
level = 9;
|
412
|
+
|
413
|
+
if (method == LZHAM_Z_DEFLATED)
|
414
|
+
{
|
415
|
+
// Force Deflate to LZHAM with default window_bits.
|
416
|
+
method = LZHAM_Z_LZHAM;
|
417
|
+
window_bits = LZHAM_Z_DEFAULT_WINDOW_BITS;
|
418
|
+
}
|
419
|
+
|
420
|
+
#ifdef LZHAM_Z_API_FORCE_WINDOW_BITS
|
421
|
+
window_bits = LZHAM_Z_API_FORCE_WINDOW_BITS;
|
422
|
+
#endif
|
423
|
+
|
424
|
+
int max_window_bits = LZHAM_64BIT_POINTERS ? LZHAM_MAX_DICT_SIZE_LOG2_X64 : LZHAM_MAX_DICT_SIZE_LOG2_X86;
|
425
|
+
if ((labs(window_bits) < LZHAM_MIN_DICT_SIZE_LOG2) || (labs(window_bits) > max_window_bits))
|
426
|
+
return LZHAM_Z_PARAM_ERROR;
|
427
|
+
|
428
|
+
lzham_compress_params comp_params;
|
429
|
+
|
430
|
+
utils::zero_object(comp_params);
|
431
|
+
comp_params.m_struct_size = sizeof(lzham_compress_params);
|
432
|
+
|
433
|
+
comp_params.m_level = LZHAM_COMP_LEVEL_UBER;
|
434
|
+
if (level <= 1)
|
435
|
+
comp_params.m_level = LZHAM_COMP_LEVEL_FASTEST;
|
436
|
+
else if (level <= 3)
|
437
|
+
comp_params.m_level = LZHAM_COMP_LEVEL_FASTER;
|
438
|
+
else if (level <= 5)
|
439
|
+
comp_params.m_level = LZHAM_COMP_LEVEL_DEFAULT;
|
440
|
+
else if (level <= 7)
|
441
|
+
comp_params.m_level = LZHAM_COMP_LEVEL_BETTER;
|
442
|
+
|
443
|
+
if (level == 10)
|
444
|
+
comp_params.m_compress_flags |= LZHAM_COMP_FLAG_EXTREME_PARSING;
|
445
|
+
|
446
|
+
// Use all CPU's. TODO: This is not always the best idea depending on the dictionary size and the # of bytes to compress.
|
447
|
+
comp_params.m_max_helper_threads = -1;
|
448
|
+
|
449
|
+
comp_params.m_dict_size_log2 = static_cast<lzham_uint32>(labs(window_bits));
|
450
|
+
|
451
|
+
if (window_bits > 0)
|
452
|
+
comp_params.m_compress_flags |= LZHAM_COMP_FLAG_WRITE_ZLIB_STREAM;
|
453
|
+
|
454
|
+
pStream->data_type = 0;
|
455
|
+
pStream->adler = LZHAM_Z_ADLER32_INIT;
|
456
|
+
pStream->msg = NULL;
|
457
|
+
pStream->reserved = 0;
|
458
|
+
pStream->total_in = 0;
|
459
|
+
pStream->total_out = 0;
|
460
|
+
|
461
|
+
lzham_compress_state_ptr pComp = lzham_lib_compress_init(&comp_params);
|
462
|
+
if (!pComp)
|
463
|
+
return LZHAM_Z_PARAM_ERROR;
|
464
|
+
|
465
|
+
pStream->state = (struct lzham_z_internal_state *)pComp;
|
466
|
+
|
467
|
+
return LZHAM_Z_OK;
|
468
|
+
}
|
469
|
+
|
470
|
+
int lzham_lib_z_deflateReset(lzham_z_streamp pStream)
|
471
|
+
{
|
472
|
+
if (!pStream)
|
473
|
+
return LZHAM_Z_STREAM_ERROR;
|
474
|
+
|
475
|
+
lzham_compress_state_ptr pComp = (lzham_compress_state_ptr)pStream->state;
|
476
|
+
if (!pComp)
|
477
|
+
return LZHAM_Z_STREAM_ERROR;
|
478
|
+
|
479
|
+
pComp = lzham_lib_compress_reinit(pComp);
|
480
|
+
if (!pComp)
|
481
|
+
return LZHAM_Z_STREAM_ERROR;
|
482
|
+
|
483
|
+
pStream->state = (struct lzham_z_internal_state *)pComp;
|
484
|
+
|
485
|
+
return LZHAM_Z_OK;
|
486
|
+
}
|
487
|
+
|
488
|
+
int lzham_lib_z_deflate(lzham_z_streamp pStream, int flush)
|
489
|
+
{
|
490
|
+
if ((!pStream) || (!pStream->state) || (flush < 0) || (flush > LZHAM_Z_FINISH) || (!pStream->next_out))
|
491
|
+
return LZHAM_Z_STREAM_ERROR;
|
492
|
+
|
493
|
+
if (!pStream->avail_out)
|
494
|
+
return LZHAM_Z_BUF_ERROR;
|
495
|
+
|
496
|
+
if (flush == LZHAM_Z_PARTIAL_FLUSH)
|
497
|
+
flush = LZHAM_Z_SYNC_FLUSH;
|
498
|
+
|
499
|
+
int lzham_status = LZHAM_Z_OK;
|
500
|
+
lzham_z_ulong orig_total_in = pStream->total_in, orig_total_out = pStream->total_out;
|
501
|
+
for ( ; ; )
|
502
|
+
{
|
503
|
+
size_t in_bytes = pStream->avail_in, out_bytes = pStream->avail_out;
|
504
|
+
|
505
|
+
lzham_compress_state_ptr pComp = (lzham_compress_state_ptr)pStream->state;
|
506
|
+
lzham_compress_state *pState = static_cast<lzham_compress_state*>(pComp);
|
507
|
+
|
508
|
+
lzham_compress_status_t status = lzham_lib_compress2(
|
509
|
+
pComp,
|
510
|
+
pStream->next_in, &in_bytes,
|
511
|
+
pStream->next_out, &out_bytes,
|
512
|
+
(lzham_flush_t)flush);
|
513
|
+
|
514
|
+
pStream->next_in += (uint)in_bytes;
|
515
|
+
pStream->avail_in -= (uint)in_bytes;
|
516
|
+
pStream->total_in += (uint)in_bytes;
|
517
|
+
|
518
|
+
pStream->next_out += (uint)out_bytes;
|
519
|
+
pStream->avail_out -= (uint)out_bytes;
|
520
|
+
pStream->total_out += (uint)out_bytes;
|
521
|
+
|
522
|
+
pStream->adler = pState->m_compressor.get_src_adler32();
|
523
|
+
|
524
|
+
if (status >= LZHAM_COMP_STATUS_FIRST_FAILURE_CODE)
|
525
|
+
{
|
526
|
+
lzham_status = LZHAM_Z_STREAM_ERROR;
|
527
|
+
break;
|
528
|
+
}
|
529
|
+
else if (status == LZHAM_COMP_STATUS_SUCCESS)
|
530
|
+
{
|
531
|
+
lzham_status = LZHAM_Z_STREAM_END;
|
532
|
+
break;
|
533
|
+
}
|
534
|
+
else if (!pStream->avail_out)
|
535
|
+
break;
|
536
|
+
else if ((!pStream->avail_in) && (flush != LZHAM_Z_FINISH))
|
537
|
+
{
|
538
|
+
if ((flush) || (pStream->total_in != orig_total_in) || (pStream->total_out != orig_total_out))
|
539
|
+
break;
|
540
|
+
return LZHAM_Z_BUF_ERROR; // Can't make forward progress without some input.
|
541
|
+
}
|
542
|
+
}
|
543
|
+
return lzham_status;
|
544
|
+
}
|
545
|
+
|
546
|
+
int lzham_lib_z_deflateEnd(lzham_z_streamp pStream)
|
547
|
+
{
|
548
|
+
if (!pStream)
|
549
|
+
return LZHAM_Z_STREAM_ERROR;
|
550
|
+
|
551
|
+
lzham_compress_state_ptr pComp = (lzham_compress_state_ptr)pStream->state;
|
552
|
+
if (pComp)
|
553
|
+
{
|
554
|
+
pStream->adler = lzham_lib_compress_deinit(pComp);
|
555
|
+
|
556
|
+
pStream->state = NULL;
|
557
|
+
}
|
558
|
+
|
559
|
+
return LZHAM_Z_OK;
|
560
|
+
}
|
561
|
+
|
562
|
+
lzham_z_ulong lzham_lib_z_deflateBound(lzham_z_streamp pStream, lzham_z_ulong source_len)
|
563
|
+
{
|
564
|
+
LZHAM_NOTE_UNUSED(pStream);
|
565
|
+
return 64 + source_len + ((source_len + 4095) / 4096) * 4;
|
566
|
+
}
|
567
|
+
|
568
|
+
int lzham_lib_z_compress2(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len, int level)
|
569
|
+
{
|
570
|
+
int status;
|
571
|
+
lzham_z_stream stream;
|
572
|
+
memset(&stream, 0, sizeof(stream));
|
573
|
+
|
574
|
+
// In case lzham_z_ulong is 64-bits (argh I hate longs).
|
575
|
+
if ((source_len | *pDest_len) > 0xFFFFFFFFU)
|
576
|
+
return LZHAM_Z_PARAM_ERROR;
|
577
|
+
|
578
|
+
stream.next_in = pSource;
|
579
|
+
stream.avail_in = (uint)source_len;
|
580
|
+
stream.next_out = pDest;
|
581
|
+
stream.avail_out = (uint)*pDest_len;
|
582
|
+
|
583
|
+
status = lzham_lib_z_deflateInit(&stream, level);
|
584
|
+
if (status != LZHAM_Z_OK)
|
585
|
+
return status;
|
586
|
+
|
587
|
+
status = lzham_lib_z_deflate(&stream, LZHAM_Z_FINISH);
|
588
|
+
if (status != LZHAM_Z_STREAM_END)
|
589
|
+
{
|
590
|
+
lzham_lib_z_deflateEnd(&stream);
|
591
|
+
return (status == LZHAM_Z_OK) ? LZHAM_Z_BUF_ERROR : status;
|
592
|
+
}
|
593
|
+
|
594
|
+
*pDest_len = stream.total_out;
|
595
|
+
return lzham_lib_z_deflateEnd(&stream);
|
596
|
+
}
|
597
|
+
|
598
|
+
int lzham_lib_z_compress(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len)
|
599
|
+
{
|
600
|
+
return lzham_lib_z_compress2(pDest, pDest_len, pSource, source_len, (int)LZHAM_Z_DEFAULT_COMPRESSION);
|
601
|
+
}
|
602
|
+
|
603
|
+
lzham_z_ulong lzham_lib_z_compressBound(lzham_z_ulong source_len)
|
604
|
+
{
|
605
|
+
return lzham_lib_z_deflateBound(NULL, source_len);
|
606
|
+
}
|
607
|
+
|
608
|
+
} // namespace lzham
|