CMSIS2000  0.0.7
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lz4.h
Go to the documentation of this file.
1 /*
2  LZ4 - Fast LZ compression algorithm
3  Header File
4  Copyright (C) 2011-2012, 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 #if defined (__cplusplus)
37 extern "C" {
38 #endif
39 
40 
41 //**************************************
42 // Compiler Options
43 //**************************************
44 #if defined(_MSC_VER) && !defined(__cplusplus) // Visual Studio
45 # define inline __inline // Visual is not C99, but supports some kind of inline
46 #endif
47 
48 
49 //****************************
50 // Simple Functions
51 //****************************
52 
53 int LZ4_compress (const char* source, char* dest, int isize);
54 int LZ4_uncompress (const char* source, char* dest, int osize);
55 
56 /*
57 LZ4_compress() :
58  Compresses 'isize' bytes from 'source' into 'dest'.
59  Destination buffer must be already allocated,
60  and must be sized to handle worst cases situations (input data not compressible)
61  Worst case size evaluation is provided by function LZ4_compressBound()
62 
63  isize : is the input size. Max supported value is ~1.9GB
64  return : the number of bytes written in buffer dest
65 
66 
67 LZ4_uncompress() :
68  osize : is the output size, therefore the original size
69  return : the number of bytes read in the source buffer
70  If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
71  This function never writes outside of provided buffers, and never modifies input buffer.
72  note : destination buffer must be already allocated.
73  its size must be a minimum of 'osize' bytes.
74 */
75 
76 
77 //****************************
78 // Advanced Functions
79 //****************************
80 
81 static inline int LZ4_compressBound(int isize) { return ((isize) + ((isize)/255) + 16); }
82 #define LZ4_COMPRESSBOUND( isize) ((isize) + ((isize)/255) + 16)
83 
84 /*
85 LZ4_compressBound() :
86  Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)
87  primarily useful for memory allocation of output buffer.
88  inline function is recommended for the general case,
89  but macro is also provided when results need to be evaluated at compile time (such as table size allocation).
90 
91  isize : is the input size. Max supported value is ~1.9GB
92  return : maximum output size in a "worst case" scenario
93  note : this function is limited by "int" range (2^31-1)
94 */
95 
96 
97 int LZ4_compress_limitedOutput (const char* source, char* dest, int isize, int maxOutputSize);
98 
99 /*
100 LZ4_compress_limitedOutput() :
101  Compress 'isize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
102  If it cannot achieve it, compression will stop, and result of the function will be zero.
103  This function never writes outside of provided output buffer.
104 
105  isize : is the input size. Max supported value is ~1.9GB
106  maxOutputSize : is the size of the destination buffer (which must be already allocated)
107  return : the number of bytes written in buffer 'dest'
108  or 0 if the compression fails
109 */
110 
111 
112 int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
113 
114 /*
115 LZ4_uncompress_unknownOutputSize() :
116  isize : is the input size, therefore the compressed size
117  maxOutputSize : is the size of the destination buffer (which must be already allocated)
118  return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
119  If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
120  This function never writes beyond dest + maxOutputSize, and is therefore protected against malicious data packets
121  note : Destination buffer must be already allocated.
122  This version is slightly slower than LZ4_uncompress()
123 */
124 
125 
126 #if defined (__cplusplus)
127 }
128 #endif