Home | History | Annotate | Download | only in lib
      1 /*
      2    LZ4 HC - High Compression Mode of LZ4
      3    Header File
      4    Copyright (C) 2011-2014, 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 
     37 #if defined (__cplusplus)
     38 extern "C" {
     39 #endif
     40 
     41 
     42 int LZ4_compressHC (const char* source, char* dest, int inputSize);
     43 /*
     44 LZ4_compressHC :
     45     return : the number of bytes in compressed buffer dest
     46              or 0 if compression fails.
     47     note : destination buffer must be already allocated.
     48         To avoid any problem, size it to handle worst cases situations (input data not compressible)
     49         Worst case size evaluation is provided by function LZ4_compressBound() (see "lz4.h")
     50 */
     51 
     52 int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
     53 /*
     54 LZ4_compress_limitedOutput() :
     55     Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
     56     If it cannot achieve it, compression will stop, and result of the function will be zero.
     57     This function never writes outside of provided output buffer.
     58 
     59     inputSize  : Max supported value is 1 GB
     60     maxOutputSize : is maximum allowed size into the destination buffer (which must be already allocated)
     61     return : the number of output bytes written in buffer 'dest'
     62              or 0 if compression fails.
     63 */
     64 
     65 
     66 int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
     67 int LZ4_compressHC2_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
     68 /*
     69     Same functions as above, but with programmable 'compressionLevel'.
     70     Recommended values are between 4 and 9, although any value between 0 and 16 will work.
     71     'compressionLevel'==0 means use default 'compressionLevel' value.
     72     Values above 16 behave the same as 16.
     73     Equivalent variants exist for all other compression functions below.
     74 */
     75 
     76 /* Note :
     77    Decompression functions are provided within LZ4 source code (see "lz4.h") (BSD license)
     78 */
     79 
     80 
     81 /**************************************
     82    Using an external allocation
     83 **************************************/
     84 int LZ4_sizeofStateHC(void);
     85 int LZ4_compressHC_withStateHC               (void* state, const char* source, char* dest, int inputSize);
     86 int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
     87 
     88 int LZ4_compressHC2_withStateHC              (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
     89 int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
     90 
     91 /*
     92 These functions are provided should you prefer to allocate memory for compression tables with your own allocation methods.
     93 To know how much memory must be allocated for the compression tables, use :
     94 int LZ4_sizeofStateHC();
     95 
     96 Note that tables must be aligned for pointer (32 or 64 bits), otherwise compression will fail (return code 0).
     97 
     98 The allocated memory can be provided to the compression functions using 'void* state' parameter.
     99 LZ4_compress_withStateHC() and LZ4_compress_limitedOutput_withStateHC() are equivalent to previously described functions.
    100 They just use the externally allocated memory for state instead of allocating their own (on stack, or on heap).
    101 */
    102 
    103 
    104 
    105 /**************************************
    106    Experimental Streaming Functions
    107 **************************************/
    108 #define LZ4_STREAMHCSIZE_U64 32774
    109 #define LZ4_STREAMHCSIZE     (LZ4_STREAMHCSIZE_U64 * sizeof(unsigned long long))
    110 typedef struct { unsigned long long table[LZ4_STREAMHCSIZE_U64]; } LZ4_streamHC_t;
    111 /*
    112 LZ4_streamHC_t
    113 This structure allows static allocation of LZ4 HC streaming state.
    114 State must then be initialized using LZ4_resetStreamHC() before first use.
    115 
    116 Static allocation should only be used with statically linked library.
    117 If you want to use LZ4 as a DLL, please use construction functions below, which are more future-proof.
    118 */
    119 
    120 
    121 LZ4_streamHC_t* LZ4_createStreamHC(void);
    122 int             LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr);
    123 /*
    124 These functions create and release memory for LZ4 HC streaming state.
    125 Newly created states are already initialized.
    126 Existing state space can be re-used anytime using LZ4_resetStreamHC().
    127 If you use LZ4 as a DLL, please use these functions instead of direct struct allocation,
    128 to avoid size mismatch between different versions.
    129 */
    130 
    131 void LZ4_resetStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
    132 int  LZ4_loadDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, const char* dictionary, int dictSize);
    133 
    134 int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize);
    135 int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
    136 
    137 int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int maxDictSize);
    138 
    139 /*
    140 These functions compress data in successive blocks of any size, using previous blocks as dictionary.
    141 One key assumption is that each previous block will remain read-accessible while compressing next block.
    142 
    143 Before starting compression, state must be properly initialized, using LZ4_resetStreamHC().
    144 A first "fictional block" can then be designated as initial dictionary, using LZ4_loadDictHC() (Optional).
    145 
    146 Then, use LZ4_compressHC_continue() or LZ4_compressHC_limitedOutput_continue() to compress each successive block.
    147 They work like usual LZ4_compressHC() or LZ4_compressHC_limitedOutput(), but use previous memory blocks to improve compression.
    148 Previous memory blocks (including initial dictionary when present) must remain accessible and unmodified during compression.
    149 
    150 If, for any reason, previous data block can't be preserved in memory during next compression block,
    151 you must save it to a safer memory space,
    152 using LZ4_saveDictHC().
    153 */
    154 
    155 
    156 
    157 /**************************************
    158  * Deprecated Streaming Functions
    159  * ************************************/
    160 /* Note : these streaming functions follows the older model, and should no longer be used */
    161 void* LZ4_createHC (const char* inputBuffer);
    162 char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
    163 int   LZ4_freeHC (void* LZ4HC_Data);
    164 
    165 int   LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);
    166 int   LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
    167 
    168 int   LZ4_sizeofStreamStateHC(void);
    169 int   LZ4_resetStreamStateHC(void* state, const char* inputBuffer);
    170 
    171 
    172 #if defined (__cplusplus)
    173 }
    174 #endif
    175