4
// Fast data compression library
5
// Copyright (C) 2006-2011 Lasse Mikkel Reinhold
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.
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.
21
#ifndef QLZ_COMPRESSION_LEVEL
22
#define QLZ_COMPRESSION_LEVEL 1
23
//#define QLZ_COMPRESSION_LEVEL 2
24
//#define QLZ_COMPRESSION_LEVEL 3
26
#define QLZ_STREAMING_BUFFER 0
27
//#define QLZ_STREAMING_BUFFER 100000
28
//#define QLZ_STREAMING_BUFFER 1000000
30
//#define QLZ_MEMORY_SAFE
33
#define QLZ_VERSION_MAJOR 1
34
#define QLZ_VERSION_MINOR 5
35
#define QLZ_VERSION_REVISION 0
37
// Using size_t, memset() and memcpy()
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
45
typedef unsigned int ui32;
46
typedef unsigned short int ui16;
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
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__
68
#if QLZ_COMPRESSION_LEVEL == 1
70
#if defined QLZ_PTR_64 && QLZ_STREAMING_BUFFER == 0
73
const unsigned char *offset;
76
const unsigned char *offset[QLZ_POINTERS];
83
#if QLZ_COMPRESSION_LEVEL == 1
84
const unsigned char *offset;
86
const unsigned char *offset[QLZ_POINTERS];
88
} qlz_hash_decompress;
94
#if QLZ_STREAMING_BUFFER > 0
95
unsigned char stream_buffer[QLZ_STREAMING_BUFFER];
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;
103
#if QLZ_COMPRESSION_LEVEL == 1 || QLZ_COMPRESSION_LEVEL == 2
106
#if QLZ_STREAMING_BUFFER > 0
107
unsigned char stream_buffer[QLZ_STREAMING_BUFFER];
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
116
#if QLZ_STREAMING_BUFFER > 0
117
unsigned char stream_buffer[QLZ_STREAMING_BUFFER];
119
#if QLZ_COMPRESSION_LEVEL <= 2
120
qlz_hash_decompress hash[QLZ_HASH_VALUES];
122
size_t stream_counter;
123
} qlz_state_decompress;
127
#if defined (__cplusplus)
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);
138
#if defined (__cplusplus)