2014-03-12 14:51:59 +00:00
|
|
|
/*
|
|
|
|
LZ4 HC - High Compression Mode of LZ4
|
|
|
|
Header File
|
2015-03-13 01:24:08 +00:00
|
|
|
Copyright (C) 2011-2015, Yann Collet.
|
2014-03-12 14:51:59 +00:00
|
|
|
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
You can contact the author at :
|
2015-03-13 01:24:08 +00:00
|
|
|
- LZ4 source repository : https://github.com/Cyan4973/lz4
|
|
|
|
- LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
|
2014-03-12 14:51:59 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-04-11 11:28:09 +00:00
|
|
|
/*****************************
|
|
|
|
* Includes
|
|
|
|
*****************************/
|
|
|
|
#include <stddef.h> /* size_t */
|
|
|
|
|
2014-03-12 14:51:59 +00:00
|
|
|
|
2015-04-11 11:28:09 +00:00
|
|
|
/**************************************
|
|
|
|
* Block Compression
|
|
|
|
**************************************/
|
|
|
|
int LZ4_compressHC_safe (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
2014-03-12 14:51:59 +00:00
|
|
|
/*
|
2015-04-11 11:28:09 +00:00
|
|
|
LZ4_compressHC_safe :
|
2014-03-12 14:51:59 +00:00
|
|
|
return : the number of bytes in compressed buffer dest
|
|
|
|
or 0 if compression fails.
|
|
|
|
note : destination buffer must be already allocated.
|
2015-04-11 11:28:09 +00:00
|
|
|
To guarantee compression completion, size it to handle worst cases situations (data not compressible)
|
2014-03-12 14:51:59 +00:00
|
|
|
Worst case size evaluation is provided by function LZ4_compressBound() (see "lz4.h")
|
2015-04-11 11:28:09 +00:00
|
|
|
inputSize : Max supported value is LZ4_MAX_INPUT_SIZE (see "lz4.h")
|
|
|
|
compressionLevel : Recommended values are between 4 and 9, although any value between 0 and 16 will work.
|
|
|
|
0 means use default 'compressionLevel' value.
|
|
|
|
Values >16 behave the same as 16.
|
2014-03-12 14:51:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* Note :
|
2014-10-18 10:18:14 +00:00
|
|
|
Decompression functions are provided within LZ4 source code (see "lz4.h") (BSD license)
|
2014-03-12 14:51:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
int LZ4_sizeofStateHC(void);
|
2015-04-11 11:28:09 +00:00
|
|
|
int LZ4_compressHC_safe_extStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
2014-03-12 14:51:59 +00:00
|
|
|
|
|
|
|
/*
|
2015-04-11 11:28:09 +00:00
|
|
|
This function is provided should you prefer to allocate memory for compression tables with your own allocation methods.
|
2014-03-12 14:51:59 +00:00
|
|
|
To know how much memory must be allocated for the compression tables, use :
|
|
|
|
int LZ4_sizeofStateHC();
|
|
|
|
|
|
|
|
Note that tables must be aligned for pointer (32 or 64 bits), otherwise compression will fail (return code 0).
|
|
|
|
|
2014-10-19 16:41:42 +00:00
|
|
|
The allocated memory can be provided to the compression functions using 'void* state' parameter.
|
2015-04-11 11:28:09 +00:00
|
|
|
LZ4_compressHC_safe_extStateHC() is equivalent to previously described function.
|
|
|
|
It just uses externally allocated memory for stateHC instead of allocating their own (on stack, or on heap).
|
2014-03-12 14:51:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2014-10-18 10:18:14 +00:00
|
|
|
/**************************************
|
2015-04-11 11:28:09 +00:00
|
|
|
* Streaming Compression
|
2014-10-18 10:18:14 +00:00
|
|
|
**************************************/
|
2015-03-25 17:06:40 +00:00
|
|
|
#define LZ4_STREAMHCSIZE 262192
|
|
|
|
#define LZ4_STREAMHCSIZE_SIZET (LZ4_STREAMHCSIZE / sizeof(size_t))
|
|
|
|
typedef struct { size_t table[LZ4_STREAMHCSIZE_SIZET]; } LZ4_streamHC_t;
|
2014-10-18 10:18:14 +00:00
|
|
|
/*
|
2014-12-03 22:19:11 +00:00
|
|
|
LZ4_streamHC_t
|
2014-10-18 10:18:14 +00:00
|
|
|
This structure allows static allocation of LZ4 HC streaming state.
|
|
|
|
State must then be initialized using LZ4_resetStreamHC() before first use.
|
|
|
|
|
2014-12-03 22:19:11 +00:00
|
|
|
Static allocation should only be used with statically linked library.
|
|
|
|
If you want to use LZ4 as a DLL, please use construction functions below, which are more future-proof.
|
2014-10-18 10:18:14 +00:00
|
|
|
*/
|
|
|
|
|
2014-12-03 22:19:11 +00:00
|
|
|
|
2014-10-18 10:18:14 +00:00
|
|
|
LZ4_streamHC_t* LZ4_createStreamHC(void);
|
|
|
|
int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr);
|
|
|
|
/*
|
|
|
|
These functions create and release memory for LZ4 HC streaming state.
|
|
|
|
Newly created states are already initialized.
|
|
|
|
Existing state space can be re-used anytime using LZ4_resetStreamHC().
|
2014-12-03 22:19:11 +00:00
|
|
|
If you use LZ4 as a DLL, please use these functions instead of direct struct allocation,
|
|
|
|
to avoid size mismatch between different versions.
|
2014-10-18 10:18:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
void LZ4_resetStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
|
|
|
|
int LZ4_loadDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, const char* dictionary, int dictSize);
|
|
|
|
|
2015-04-11 11:28:09 +00:00
|
|
|
int LZ4_compressHC_safe_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
|
2014-10-18 10:18:14 +00:00
|
|
|
|
|
|
|
int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int maxDictSize);
|
|
|
|
|
|
|
|
/*
|
|
|
|
These functions compress data in successive blocks of any size, using previous blocks as dictionary.
|
2014-10-25 19:52:10 +00:00
|
|
|
One key assumption is that each previous block will remain read-accessible while compressing next block.
|
2014-10-18 10:18:14 +00:00
|
|
|
|
|
|
|
Before starting compression, state must be properly initialized, using LZ4_resetStreamHC().
|
|
|
|
A first "fictional block" can then be designated as initial dictionary, using LZ4_loadDictHC() (Optional).
|
|
|
|
|
2015-04-11 11:28:09 +00:00
|
|
|
Then, use LZ4_compressHC_safe_continue() to compress each successive block.
|
|
|
|
It works like LZ4_compressHC_safe(), but use previous memory blocks to improve compression.
|
2014-10-18 10:18:14 +00:00
|
|
|
Previous memory blocks (including initial dictionary when present) must remain accessible and unmodified during compression.
|
|
|
|
|
2014-10-25 19:52:10 +00:00
|
|
|
If, for any reason, previous data block can't be preserved in memory during next compression block,
|
2014-11-02 21:32:12 +00:00
|
|
|
you must save it to a safer memory space,
|
2014-10-18 10:18:14 +00:00
|
|
|
using LZ4_saveDictHC().
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-12 14:51:59 +00:00
|
|
|
/**************************************
|
2015-04-11 11:28:09 +00:00
|
|
|
* Deprecated Functions
|
2014-12-03 22:19:11 +00:00
|
|
|
* ************************************/
|
2015-04-11 18:12:03 +00:00
|
|
|
/* Deprecate Warnings */
|
|
|
|
/* Should these warnings messages be a problem,
|
|
|
|
it is generally possible to disable them,
|
|
|
|
with -Wno-deprecated-declarations for gcc
|
|
|
|
or _CRT_SECURE_NO_WARNINGS in Visual for example.
|
2015-04-12 08:28:53 +00:00
|
|
|
You can also define LZ4_DEPRECATE_WARNING_DEFBLOCK. */
|
|
|
|
#ifndef LZ4_DEPRECATE_WARNING_DEFBLOCK
|
|
|
|
# define LZ4_DEPRECATE_WARNING_DEFBLOCK
|
2015-04-11 18:12:03 +00:00
|
|
|
# define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
|
|
|
# if (GCC_VERSION >= 405) || defined(__clang__)
|
2015-04-12 08:28:53 +00:00
|
|
|
# define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
|
2015-04-11 18:12:03 +00:00
|
|
|
# elif (GCC_VERSION >= 301)
|
2015-04-12 08:28:53 +00:00
|
|
|
# define LZ4_DEPRECATED(message) __attribute__((deprecated))
|
2015-04-11 18:12:03 +00:00
|
|
|
# elif defined(_MSC_VER)
|
2015-04-12 08:28:53 +00:00
|
|
|
# define LZ4_DEPRECATED(message) __declspec(deprecated(message))
|
2015-04-11 18:12:03 +00:00
|
|
|
# else
|
2015-04-12 08:28:53 +00:00
|
|
|
# pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler")
|
|
|
|
# define LZ4_DEPRECATED
|
2015-04-11 18:12:03 +00:00
|
|
|
# endif
|
2015-04-12 08:28:53 +00:00
|
|
|
#endif // LZ4_DEPRECATE_WARNING_DEFBLOCK
|
2015-04-11 11:28:09 +00:00
|
|
|
|
|
|
|
/* compression functions */
|
2015-04-11 18:12:03 +00:00
|
|
|
/* these functions are planned to trigger warning messages by r131 approximately */
|
2015-04-11 11:28:09 +00:00
|
|
|
int LZ4_compressHC (const char* source, char* dest, int inputSize);
|
|
|
|
int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
|
|
|
|
int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
|
|
|
|
int LZ4_compressHC2_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
|
|
|
int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize);
|
|
|
|
int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
|
|
|
|
int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
|
|
|
|
int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
|
|
|
int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize);
|
|
|
|
int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
|
|
|
|
|
|
|
|
/* Streaming functions following the older model; should no longer be used */
|
2015-04-12 08:28:53 +00:00
|
|
|
LZ4_DEPRECATED("use LZ4_createStreamHC() instead") void* LZ4_createHC (const char* inputBuffer);
|
|
|
|
LZ4_DEPRECATED("use LZ4_saveDictHC() instead") char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
|
|
|
|
LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") int LZ4_freeHC (void* LZ4HC_Data);
|
|
|
|
LZ4_DEPRECATED("use LZ4_compressHC_safe_continue() instead") int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);
|
|
|
|
LZ4_DEPRECATED("use LZ4_compressHC_safe_continue() instead") int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
|
|
|
LZ4_DEPRECATED("use LZ4_createStreamHC() instead") int LZ4_sizeofStreamStateHC(void);
|
|
|
|
LZ4_DEPRECATED("use LZ4_resetStreamHC() instead") int LZ4_resetStreamStateHC(void* state, const char* inputBuffer);
|
2014-03-12 14:51:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|