summaryrefslogtreecommitdiff
path: root/util/cbfstool/lzma/lzma.hh
blob: 5e00ef2d438a3f6d240425e6baa1bd2bd037eab0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef HHlzmaHH
#define HHlzmaHH

#include <vector>

extern int LZMA_verbose;

extern unsigned LZMA_NumFastBytes;
extern unsigned LZMA_AlgorithmNo;
extern unsigned LZMA_PosStateBits;
extern unsigned LZMA_LiteralPosStateBits;
extern unsigned LZMA_LiteralContextBits;

/* decompress LZMA-compressed data. */
const std::vector<unsigned char> LZMADeCompress
    (const unsigned char* data, std::size_t length);

const std::vector<unsigned char> LZMADeCompress
    (const unsigned char* data, std::size_t length, bool& ok);

static inline const std::vector<unsigned char> LZMADeCompress
    (const std::vector<unsigned char>& buf)
    { return LZMADeCompress(&buf[0], buf.size()); }

static inline const std::vector<unsigned char> LZMADeCompress
    (const std::vector<unsigned char>& buf, bool& ok)
    { return LZMADeCompress(&buf[0], buf.size(), ok); }

/* LZMA-compress data with current settings. */
const std::vector<unsigned char> LZMACompress
    (const unsigned char* data, std::size_t length);

static inline const std::vector<unsigned char> LZMACompress
    (const std::vector<unsigned char>& buf)
        { return LZMACompress(&buf[0], buf.size()); }

/* LZMA-compress data with given settings. */
const std::vector<unsigned char> LZMACompress
    (const unsigned char* data, std::size_t length,
     unsigned pb,
     unsigned lp,
     unsigned lc);

static inline const std::vector<unsigned char> LZMACompress
    (const std::vector<unsigned char>& buf,
     unsigned pb,
     unsigned lp,
     unsigned lc)
     { return LZMACompress(&buf[0], buf.size(), pb,lp,lc); }

const std::vector<unsigned char> LZMACompress(
    const unsigned char* data, std::size_t length,
    unsigned pb,
    unsigned lp,
    unsigned lc,
    unsigned dictionarysize);

static inline const std::vector<unsigned char> LZMACompress(
    const std::vector<unsigned char>& buf,
    unsigned pb,
    unsigned lp,
    unsigned lc,
    unsigned dictionarysize)
    { return LZMACompress(&buf[0], buf.size(), pb,lp,lc,dictionarysize); }

/* LZMA-compress data with every settings (5*5*9 times), taking the best.
 * It will consume a lot of time and output useful statistics,
 * so a context parameter ("why") is also given.
 */
const std::vector<unsigned char> LZMACompressHeavy
    (const unsigned char* data, std::size_t length,
     const char* why = "?");

const std::vector<unsigned char> LZMACompressAuto
    (const unsigned char* data, std::size_t length,
     const char* why = "?");

static inline const std::vector<unsigned char> LZMACompressHeavy
    (const std::vector<unsigned char>& buf,
     const char* why = "?")
     { return LZMACompressHeavy(&buf[0],buf.size(),why); }

static inline const std::vector<unsigned char> LZMACompressAuto
    (const std::vector<unsigned char>& buf,
     const char* why = "?")
     { return LZMACompressAuto(&buf[0],buf.size(),why); }

const std::vector<unsigned char>
    DoLZMACompress(int HeavyLevel,
        const unsigned char* data,
        std::size_t          length,
        const char* why = "?");

static inline const std::vector<unsigned char>
    DoLZMACompress(int HeavyLevel,
        const std::vector<unsigned char>& data, const char* why = "?")
    { return DoLZMACompress(HeavyLevel, &data[0], data.size(), why); }


/*
LZMA compressed file format
 ---------------------------
 Offset Size Description
   0     1   Special LZMA properties for compressed data
   1     4   Dictionary size (little endian)
   5     8   Uncompressed size (little endian). -1 means unknown size
  13         Compressed data
*/
#endif