]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.fastlz/native/lz4.h
Sync git svn branch with SVN repository r33382.
[simantics/platform.git] / bundles / org.simantics.fastlz / native / lz4.h
1 /*\r
2    LZ4 - Fast LZ compression algorithm\r
3    Header File\r
4    Copyright (C) 2011-2012, Yann Collet.\r
5    BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)\r
6 \r
7    Redistribution and use in source and binary forms, with or without\r
8    modification, are permitted provided that the following conditions are\r
9    met:\r
10 \r
11        * Redistributions of source code must retain the above copyright\r
12    notice, this list of conditions and the following disclaimer.\r
13        * Redistributions in binary form must reproduce the above\r
14    copyright notice, this list of conditions and the following disclaimer\r
15    in the documentation and/or other materials provided with the\r
16    distribution.\r
17 \r
18    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
19    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
20    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
21    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
22    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
23    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
24    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
25    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
26    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
27    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
28    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
29 \r
30    You can contact the author at :\r
31    - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html\r
32    - LZ4 source repository : http://code.google.com/p/lz4/\r
33 */\r
34 #pragma once\r
35 \r
36 #if defined (__cplusplus)\r
37 extern "C" {\r
38 #endif\r
39 \r
40 \r
41 //****************************\r
42 // Simple Functions\r
43 //****************************\r
44 \r
45 int LZ4_compress   (const char* source, char* dest, int isize);\r
46 int LZ4_uncompress (const char* source, char* dest, int osize);\r
47 \r
48 /*\r
49 LZ4_compress() :\r
50         isize  : is the input size. Max supported value is ~1.9GB\r
51         return : the number of bytes written in buffer dest\r
52                          or 0 if the compression fails (if LZ4_COMPRESSMIN is set)\r
53         note : destination buffer must be already allocated.\r
54                 destination buffer must be sized to handle worst cases situations (input data not compressible)\r
55                 worst case size evaluation is provided by function LZ4_compressBound()\r
56 \r
57 LZ4_uncompress() :\r
58         osize  : is the output size, therefore the original size\r
59         return : the number of bytes read in the source buffer\r
60                          If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction\r
61                          This function never writes beyond dest + osize, and is therefore protected against malicious data packets\r
62         note : destination buffer must be already allocated\r
63 */\r
64 \r
65 \r
66 //****************************\r
67 // Advanced Functions\r
68 //****************************\r
69 \r
70 int LZ4_compressBound(int isize);\r
71 \r
72 /*\r
73 LZ4_compressBound() :\r
74         Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)\r
75         primarily useful for memory allocation of output buffer.\r
76 \r
77         isize  : is the input size. Max supported value is ~1.9GB\r
78         return : maximum output size in a "worst case" scenario\r
79         note : this function is limited by "int" range (2^31-1)\r
80 */\r
81 \r
82 \r
83 int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);\r
84 \r
85 /*\r
86 LZ4_uncompress_unknownOutputSize() :\r
87         isize  : is the input size, therefore the compressed size\r
88         maxOutputSize : is the size of the destination buffer (which must be already allocated)\r
89         return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)\r
90                          If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction\r
91                          This function never writes beyond dest + maxOutputSize, and is therefore protected against malicious data packets\r
92         note   : Destination buffer must be already allocated.\r
93                  This version is slightly slower than LZ4_uncompress()\r
94 */\r
95 \r
96 \r
97 int LZ4_compressCtx(void** ctx, const char* source,  char* dest, int isize);\r
98 int LZ4_compress64kCtx(void** ctx, const char* source,  char* dest, int isize);\r
99 \r
100 /*\r
101 LZ4_compressCtx() :\r
102         This function explicitly handles the CTX memory structure.\r
103         It avoids allocating/deallocating memory between each call, improving performance when malloc is heavily invoked.\r
104         This function is only useful when memory is allocated into the heap (HASH_LOG value beyond STACK_LIMIT)\r
105         Performance difference will be noticeable only when repetitively calling the compression function over many small segments.\r
106         Note : by default, memory is allocated into the stack, therefore "malloc" is not invoked.\r
107 LZ4_compress64kCtx() :\r
108         Same as LZ4_compressCtx(), but specific to small inputs (<64KB).\r
109         isize *Must* be <64KB, otherwise the output will be corrupted.\r
110 \r
111         On first call : provide a *ctx=NULL; It will be automatically allocated.\r
112         On next calls : reuse the same ctx pointer.\r
113         Use different pointers for different threads when doing multi-threading.\r
114 \r
115 */\r
116 \r
117 \r
118 #if defined (__cplusplus)\r
119 }\r
120 #endif\r