1 | #ifndef QLZ_HEADER |
2 | #define |
3 | |
4 | // Fast data compression library |
5 | // Copyright (C) 2006-2011 Lasse Mikkel Reinhold |
6 | // lar@quicklz.com |
7 | // |
8 | // QuickLZ can be used for free under the GPL 1, 2 or 3 license (where anything |
9 | // released into public must be open source) or under a commercial license if such |
10 | // has been acquired (see http://www.quicklz.com/order.html). The commercial license |
11 | // does not cover derived or ported versions created by third parties under GPL. |
12 | |
13 | // You can edit following user settings. Data must be decompressed with the same |
14 | // setting of QLZ_COMPRESSION_LEVEL and QLZ_STREAMING_BUFFER as it was compressed |
15 | // (see manual). If QLZ_STREAMING_BUFFER > 0, scratch buffers must be initially |
16 | // zeroed out (see manual). First #ifndef makes it possible to define settings from |
17 | // the outside like the compiler command line. |
18 | |
19 | // 1.5.0 final |
20 | |
21 | #ifndef QLZ_COMPRESSION_LEVEL |
22 | #define QLZ_COMPRESSION_LEVEL 1 |
23 | //#define QLZ_COMPRESSION_LEVEL 2 |
24 | //#define QLZ_COMPRESSION_LEVEL 3 |
25 | |
26 | #define QLZ_STREAMING_BUFFER 0 |
27 | //#define QLZ_STREAMING_BUFFER 100000 |
28 | //#define QLZ_STREAMING_BUFFER 1000000 |
29 | |
30 | //#define QLZ_MEMORY_SAFE |
31 | #endif |
32 | |
33 | #define QLZ_VERSION_MAJOR 1 |
34 | #define QLZ_VERSION_MINOR 5 |
35 | #define QLZ_VERSION_REVISION 0 |
36 | |
37 | // Using size_t, memset() and memcpy() |
38 | #include <string.h> |
39 | |
40 | // Verify compression level |
41 | #if QLZ_COMPRESSION_LEVEL != 1 && QLZ_COMPRESSION_LEVEL != 2 && QLZ_COMPRESSION_LEVEL != 3 |
42 | #error QLZ_COMPRESSION_LEVEL must be 1, 2 or 3 |
43 | #endif |
44 | |
45 | typedef unsigned int ui32; |
46 | typedef unsigned short int ui16; |
47 | |
48 | // Decrease QLZ_POINTERS for level 3 to increase compression speed. Do not touch any other values! |
49 | #if QLZ_COMPRESSION_LEVEL == 1 |
50 | #define QLZ_POINTERS 1 |
51 | #define QLZ_HASH_VALUES 4096 |
52 | #elif QLZ_COMPRESSION_LEVEL == 2 |
53 | #define QLZ_POINTERS 4 |
54 | #define QLZ_HASH_VALUES 2048 |
55 | #elif QLZ_COMPRESSION_LEVEL == 3 |
56 | #define QLZ_POINTERS 16 |
57 | #define QLZ_HASH_VALUES 4096 |
58 | #endif |
59 | |
60 | // Detect if pointer size is 64-bit. It's not fatal if some 64-bit target is not detected because this is only for adding an optional 64-bit optimization. |
61 | #if defined _LP64 || defined __LP64__ || defined __64BIT__ || _ADDR64 || defined _WIN64 || defined __arch64__ || __WORDSIZE == 64 || (defined __sparc && defined __sparcv9) || defined __x86_64 || defined __amd64 || defined __x86_64__ || defined _M_X64 || defined _M_IA64 || defined __ia64 || defined __IA64__ |
62 | #define QLZ_PTR_64 |
63 | #endif |
64 | |
65 | // hash entry |
66 | typedef struct |
67 | { |
68 | #if QLZ_COMPRESSION_LEVEL == 1 |
69 | ui32 cache; |
70 | #if defined QLZ_PTR_64 && QLZ_STREAMING_BUFFER == 0 |
71 | unsigned int offset; |
72 | #else |
73 | const unsigned char *offset; |
74 | #endif |
75 | #else |
76 | const unsigned char *offset[QLZ_POINTERS]; |
77 | #endif |
78 | |
79 | } qlz_hash_compress; |
80 | |
81 | typedef struct |
82 | { |
83 | #if QLZ_COMPRESSION_LEVEL == 1 |
84 | const unsigned char *offset; |
85 | #else |
86 | const unsigned char *offset[QLZ_POINTERS]; |
87 | #endif |
88 | } qlz_hash_decompress; |
89 | |
90 | |
91 | // states |
92 | typedef struct |
93 | { |
94 | #if QLZ_STREAMING_BUFFER > 0 |
95 | unsigned char stream_buffer[QLZ_STREAMING_BUFFER]; |
96 | #endif |
97 | size_t stream_counter; |
98 | qlz_hash_compress hash[QLZ_HASH_VALUES]; |
99 | unsigned char hash_counter[QLZ_HASH_VALUES]; |
100 | } qlz_state_compress; |
101 | |
102 | |
103 | #if QLZ_COMPRESSION_LEVEL == 1 || QLZ_COMPRESSION_LEVEL == 2 |
104 | typedef struct |
105 | { |
106 | #if QLZ_STREAMING_BUFFER > 0 |
107 | unsigned char stream_buffer[QLZ_STREAMING_BUFFER]; |
108 | #endif |
109 | qlz_hash_decompress hash[QLZ_HASH_VALUES]; |
110 | unsigned char hash_counter[QLZ_HASH_VALUES]; |
111 | size_t stream_counter; |
112 | } qlz_state_decompress; |
113 | #elif QLZ_COMPRESSION_LEVEL == 3 |
114 | typedef struct |
115 | { |
116 | #if QLZ_STREAMING_BUFFER > 0 |
117 | unsigned char stream_buffer[QLZ_STREAMING_BUFFER]; |
118 | #endif |
119 | #if QLZ_COMPRESSION_LEVEL <= 2 |
120 | qlz_hash_decompress hash[QLZ_HASH_VALUES]; |
121 | #endif |
122 | size_t stream_counter; |
123 | } qlz_state_decompress; |
124 | #endif |
125 | |
126 | |
127 | #if defined (__cplusplus) |
128 | extern "C" { |
129 | #endif |
130 | |
131 | // Public functions of QuickLZ |
132 | size_t qlz_size_decompressed(const char *source); |
133 | size_t qlz_size_compressed(const char *source); |
134 | size_t qlz_compress(const void *source, char *destination, size_t size, qlz_state_compress *state); |
135 | size_t qlz_decompress(const char *source, void *destination, qlz_state_decompress *state); |
136 | int qlz_get_setting(int setting); |
137 | size_t (const char *source); |
138 | |
139 | #if defined (__cplusplus) |
140 | } |
141 | #endif |
142 | |
143 | #endif |
144 | |
145 | |