Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
lz4.h
Go to the documentation of this file.
1 /*
2  LZ4 - Fast LZ compression algorithm
3  Header File
4  Copyright (C) 2011-2013, Yann Collet.
5  BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions are
9  met:
10 
11  * Redistributions of source code must retain the above copyright
12  notice, this list of conditions and the following disclaimer.
13  * Redistributions in binary form must reproduce the above
14  copyright notice, this list of conditions and the following disclaimer
15  in the documentation and/or other materials provided with the
16  distribution.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30  You can contact the author at :
31  - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
32  - LZ4 source repository : http://code.google.com/p/lz4/
33 */
34 #pragma once
35 
36 #include "../coreconfig.h"
37 
38 #ifdef LZ4_FUNC
39  #define LZ4_compress LZ4_FUNC(LZ4_compress)
40  #define LZ4_uncompress LZ4_FUNC(LZ4_uncompress)
41  #define LZ4_compressBound LZ4_FUNC(LZ4_compressBound)
42  #define LZ4_compress_limitedOutput LZ4_FUNC(LZ4_compress_limitedOutput)
43  #define LZ4_uncompress_unknownOutputSize LZ4_FUNC(LZ4_uncompress_unknownOutputSize)
44 #endif
45 
46 #if defined (__cplusplus)
47 extern "C" {
48 #endif
49 
50 //**************************************
51 // Compiler Options
52 //**************************************
53 #if defined(_MSC_VER) && !defined(__cplusplus) // Visual Studio
54 # define inline __inline // Visual is not C99, but supports some kind of inline
55 #endif
56 
57 //****************************
58 // Simple Functions
59 //****************************
60 
61 CORE_EXPORT( int ) LZ4_compress (const char* source, char* dest, int inputSize);
62 CORE_EXPORT( int ) LZ4_uncompress (const char* source, char* dest, int outputSize);
63 
64 /*
65 LZ4_compress() :
66  Compresses 'inputSize' bytes from 'source' into 'dest'.
67  Destination buffer must be already allocated,
68  and must be sized to handle worst cases situations (input data not compressible)
69  Worst case size evaluation is provided by function LZ4_compressBound()
70  inputSize : Max supported value is ~1.9GB
71  return : the number of bytes written in buffer dest
72  or 0 if the compression fails
73 
74 LZ4_uncompress() :
75  outputSize : is the original (uncompressed) size
76  return : the number of bytes read in the source buffer (in other words, the compressed size)
77  If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction.
78  note : This function never writes outside of provided buffers, and never modifies input buffer.
79  Destination buffer must be already allocated.
80  Its size must be a minimum of 'output_size' bytes.
81 */
82 
83 //****************************
84 // Advanced Functions
85 //****************************
86 
87 static inline int LZ4_compressBound(int isize) { return ((isize) + ((isize)/255) + 16); }
88 #define LZ4_COMPRESSBOUND(isize) ((isize) + ((isize)/255) + 16)
89 
90 /*
91 LZ4_compressBound() :
92  Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)
93  primarily useful for memory allocation of output buffer.
94  inline function is recommended for the general case,
95  but macro is also provided when results need to be evaluated at compile time (such as table size allocation).
96 
97  isize : is the input size. Max supported value is ~1.9GB
98  return : maximum output size in a "worst case" scenario
99  note : this function is limited by "int" range (2^31-1)
100 */
101 
102 
103 CORE_EXPORT( int ) LZ4_compress_limitedOutput (const char* source, char* dest, int isize, int maxOutputSize);
104 
105 /*
106 LZ4_compress_limitedOutput() :
107  Compress 'isize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
108  If it cannot achieve it, compression will stop, and result of the function will be zero.
109  This function never writes outside of provided output buffer.
110 
111  isize : is the input size. Max supported value is ~1.9GB
112  maxOutputSize : is the size of the destination buffer (which must be already allocated)
113  return : the number of bytes written in buffer 'dest'
114  or 0 if the compression fails
115 */
116 
117 
118 CORE_EXPORT( int ) LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
119 
120 /*
121 LZ4_uncompress_unknownOutputSize() :
122  isize : is the input size, therefore the compressed size
123  maxOutputSize : is the size of the destination buffer (which must be already allocated)
124  return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
125  If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
126  This function never writes beyond dest + maxOutputSize, and is therefore protected against malicious data packets
127  note : Destination buffer must be already allocated.
128  This version is slightly slower than LZ4_uncompress()
129 */
130 
131 
132 #if defined (__cplusplus)
133 }
134 #endif
CORE_EXPORT(int) LZ4_compress(const char *source
char int outputSize
Definition: lz4.h:62
char int isize
Definition: lz4.h:103
char int int maxOutputSize
Definition: lz4.h:103
static int LZ4_compressBound(int isize)
Definition: lz4.h:87
char * dest
Definition: lz4.h:61
char int inputSize
Definition: lz4.h:61