Atoms Crowd  7.0.0
Compression.h
1 #ifndef ATOMS_ANDROID
2 #ifndef ATOMS_PS5
3 /*
4  * ATOMS_LZ4 - Fast LZ compression algorithm
5  * Header File
6  * Copyright (C) 2011-present, Yann Collet.
7 
8  BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
9 
10  Redistribution and use in source and binary forms, with or without
11  modification, are permitted provided that the following conditions are
12  met:
13 
14  * Redistributions of source code must retain the above copyright
15  notice, this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following disclaimer
18  in the documentation and/or other materials provided with the
19  distribution.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33  You can contact the author at :
34  - ATOMS_LZ4 homepage : http://www.lz4.org
35  - ATOMS_LZ4 source repository : https://github.com/lz4/lz4
36 */
37 #if defined (__cplusplus)
38 extern "C" {
39 #endif
40 
41 #ifndef ATOMS_LZ4_H_2983827168210
42 #define ATOMS_LZ4_H_2983827168210
43 
44  /* --- Dependency --- */
45 #include <stddef.h> /* size_t */
46 
47 
78 /*^***************************************************************
79 * Export parameters
80 *****************************************************************/
81 /*
82 * ATOMS_LZ4_DLL_EXPORT :
83 * Enable exporting of functions when building a Windows DLL
84 * ATOMS_LZ4LIB_VISIBILITY :
85 * Control library symbols visibility.
86 */
87 #ifndef ATOMS_LZ4LIB_VISIBILITY
88 # if defined(__GNUC__) && (__GNUC__ >= 4)
89 # define ATOMS_LZ4LIB_VISIBILITY __attribute__ ((visibility ("default")))
90 # else
91 # define ATOMS_LZ4LIB_VISIBILITY
92 # endif
93 #endif
94 #if defined(ATOMS_LZ4_DLL_EXPORT) && (ATOMS_LZ4_DLL_EXPORT==1)
95 # define ATOMS_LZ4LIB_API __declspec(dllexport) ATOMS_LZ4LIB_VISIBILITY
96 #elif defined(ATOMS_LZ4_DLL_IMPORT) && (ATOMS_LZ4_DLL_IMPORT==1)
97 # define ATOMS_LZ4LIB_API __declspec(dllimport) ATOMS_LZ4LIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
98 #else
99 # define ATOMS_LZ4LIB_API ATOMS_LZ4LIB_VISIBILITY
100 #endif
101 
102 /*------ Version ------*/
103 #define ATOMS_LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
104 #define ATOMS_LZ4_VERSION_MINOR 9 /* for new (non-breaking) interface capabilities */
105 #define ATOMS_LZ4_VERSION_RELEASE 2 /* for tweaks, bug-fixes, or development */
106 
107 #define ATOMS_LZ4_VERSION_NUMBER (ATOMS_LZ4_VERSION_MAJOR *100*100 + ATOMS_LZ4_VERSION_MINOR *100 + ATOMS_LZ4_VERSION_RELEASE)
108 
109 #define ATOMS_LZ4_LIB_VERSION ATOMS_LZ4_VERSION_MAJOR.ATOMS_LZ4_VERSION_MINOR.ATOMS_LZ4_VERSION_RELEASE
110 #define ATOMS_LZ4_QUOTE(str) #str
111 #define ATOMS_LZ4_EXPAND_AND_QUOTE(str) ATOMS_LZ4_QUOTE(str)
112 #define ATOMS_LZ4_VERSION_STRING ATOMS_LZ4_EXPAND_AND_QUOTE(ATOMS_LZ4_LIB_VERSION)
113 
114  ATOMS_LZ4LIB_API int ATOMS_LZ4_versionNumber(void);
115  ATOMS_LZ4LIB_API const char* ATOMS_LZ4_versionString(void);
118  /*-************************************
119  * Tuning parameter
120  **************************************/
128 #ifndef ATOMS_LZ4_MEMORY_USAGE
129 # define ATOMS_LZ4_MEMORY_USAGE 14
130 #endif
131 
132 
133  /*-************************************
134  * Simple Functions
135  **************************************/
150  ATOMS_LZ4LIB_API int ATOMS_LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
151 
166  ATOMS_LZ4LIB_API int ATOMS_LZ4_decompress_safe(const char* src, char* dst, int compressedSize, int dstCapacity);
167 
168 
169  /*-************************************
170  * Advanced Functions
171  **************************************/
172 #define ATOMS_LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
173 #define ATOMS_LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)ATOMS_LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
174 
184  ATOMS_LZ4LIB_API int ATOMS_LZ4_compressBound(int inputSize);
185 
193  ATOMS_LZ4LIB_API int ATOMS_LZ4_compress_fast(const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
194 
195 
202  ATOMS_LZ4LIB_API int ATOMS_LZ4_sizeofState(void);
203  ATOMS_LZ4LIB_API int ATOMS_LZ4_compress_fast_extState(void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
204 
205 
218  ATOMS_LZ4LIB_API int ATOMS_LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targetDstSize);
219 
220 
245  ATOMS_LZ4LIB_API int ATOMS_LZ4_decompress_safe_partial(const char* src, char* dst, int srcSize, int targetOutputSize, int dstCapacity);
246 
247 
248  /*-*********************************************
249  * Streaming Compression Functions
250  ***********************************************/
251  typedef union ATOMS_LZ4_stream_u ATOMS_LZ4_stream_t; /* incomplete type (defined later) */
252 
253  ATOMS_LZ4LIB_API ATOMS_LZ4_stream_t* ATOMS_LZ4_createStream(void);
254  ATOMS_LZ4LIB_API int ATOMS_LZ4_freeStream(ATOMS_LZ4_stream_t* streamPtr);
255 
278  ATOMS_LZ4LIB_API void ATOMS_LZ4_resetStream_fast(ATOMS_LZ4_stream_t* streamPtr);
279 
291  ATOMS_LZ4LIB_API int ATOMS_LZ4_loadDict(ATOMS_LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
292 
316  ATOMS_LZ4LIB_API int ATOMS_LZ4_compress_fast_continue(ATOMS_LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
317 
325  ATOMS_LZ4LIB_API int ATOMS_LZ4_saveDict(ATOMS_LZ4_stream_t* streamPtr, char* safeBuffer, int maxDictSize);
326 
327 
328  /*-**********************************************
329  * Streaming Decompression Functions
330  * Bufferless synchronous API
331  ************************************************/
332  typedef union ATOMS_LZ4_streamDecode_u ATOMS_LZ4_streamDecode_t; /* tracking context */
333 
338  ATOMS_LZ4LIB_API ATOMS_LZ4_streamDecode_t* ATOMS_LZ4_createStreamDecode(void);
339  ATOMS_LZ4LIB_API int ATOMS_LZ4_freeStreamDecode(ATOMS_LZ4_streamDecode_t* ATOMS_LZ4_stream);
340 
348  ATOMS_LZ4LIB_API int ATOMS_LZ4_setStreamDecode(ATOMS_LZ4_streamDecode_t* ATOMS_LZ4_streamDecode, const char* dictionary, int dictSize);
349 
361  ATOMS_LZ4LIB_API int ATOMS_LZ4_decoderRingBufferSize(int maxBlockSize);
362 #define ATOMS_LZ4_DECODER_RING_BUFFER_SIZE(maxBlockSize) (65536 + 14 + (maxBlockSize)) /* for static allocation; maxBlockSize presumed valid */
363 
389  ATOMS_LZ4LIB_API int ATOMS_LZ4_decompress_safe_continue(ATOMS_LZ4_streamDecode_t* ATOMS_LZ4_streamDecode, const char* src, char* dst, int srcSize, int dstCapacity);
390 
391 
400  ATOMS_LZ4LIB_API int ATOMS_LZ4_decompress_safe_usingDict(const char* src, char* dst, int srcSize, int dstCapcity, const char* dictStart, int dictSize);
401 
402 #endif /* ATOMS_LZ4_H_2983827168210 */
403 
404 
405  /*^*************************************
406  * !!!!!! STATIC LINKING ONLY !!!!!!
407  ***************************************/
408 
409  /*-****************************************************************************
410  * Experimental section
411  *
412  * Symbols declared in this section must be considered unstable. Their
413  * signatures or semantics may change, or they may be removed altogether in the
414  * future. They are therefore only safe to depend on when the caller is
415  * statically linked against the library.
416  *
417  * To protect against unsafe usage, not only are the declarations guarded,
418  * the definitions are hidden by default
419  * when building ATOMS_LZ4 as a shared/dynamic library.
420  *
421  * In order to access these declarations,
422  * define ATOMS_LZ4_STATIC_LINKING_ONLY in your application
423  * before including ATOMS_LZ4's headers.
424  *
425  * In order to make their implementations accessible dynamically, you must
426  * define ATOMS_LZ4_PUBLISH_STATIC_FUNCTIONS when building the ATOMS_LZ4 library.
427  ******************************************************************************/
428 
429 #ifdef ATOMS_LZ4_STATIC_LINKING_ONLY
430 
431 #ifndef ATOMS_LZ4_STATIC_3504398509
432 #define ATOMS_LZ4_STATIC_3504398509
433 
434 #ifdef ATOMS_LZ4_PUBLISH_STATIC_FUNCTIONS
435 #define ATOMS_LZ4LIB_STATIC_API ATOMS_LZ4LIB_API
436 #else
437 #define ATOMS_LZ4LIB_STATIC_API
438 #endif
439 
440 
451  ATOMS_LZ4LIB_STATIC_API int ATOMS_LZ4_compress_fast_extState_fastReset(void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
452 
479  ATOMS_LZ4LIB_STATIC_API void ATOMS_LZ4_attach_dictionary(ATOMS_LZ4_stream_t* workingStream, const ATOMS_LZ4_stream_t* dictionaryStream);
480 
481 
533 #define ATOMS_LZ4_DECOMPRESS_INPLACE_MARGIN(compressedSize) (((compressedSize) >> 8) + 32)
534 #define ATOMS_LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize) ((decompressedSize) + ATOMS_LZ4_DECOMPRESS_INPLACE_MARGIN(decompressedSize))
536 #ifndef ATOMS_LZ4_DISTANCE_MAX /* history window size; can be user-defined at compile time */
537 # define ATOMS_LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
538 #endif
539 
540 #define ATOMS_LZ4_COMPRESS_INPLACE_MARGIN (ATOMS_LZ4_DISTANCE_MAX + 32) /* ATOMS_LZ4_DISTANCE_MAX can be safely replaced by srcSize when it's smaller */
541 #define ATOMS_LZ4_COMPRESS_INPLACE_BUFFER_SIZE(maxCompressedSize) ((maxCompressedSize) + ATOMS_LZ4_COMPRESS_INPLACE_MARGIN)
543 #endif /* ATOMS_LZ4_STATIC_3504398509 */
544 #endif /* ATOMS_LZ4_STATIC_LINKING_ONLY */
545 
546 
547 
548 #ifndef ATOMS_LZ4_H_98237428734687
549 #define ATOMS_LZ4_H_98237428734687
550 
551  /*-************************************************************
552  * PRIVATE DEFINITIONS
553  **************************************************************
554  * Do not use these definitions directly.
555  * They are only exposed to allow static allocation of `ATOMS_LZ4_stream_t` and `ATOMS_LZ4_streamDecode_t`.
556  * Accessing members will expose code to API and/or ABI break in future versions of the library.
557  **************************************************************/
558 #define ATOMS_LZ4_HASHLOG (ATOMS_LZ4_MEMORY_USAGE-2)
559 #define ATOMS_LZ4_HASHTABLESIZE (1 << ATOMS_LZ4_MEMORY_USAGE)
560 #define ATOMS_LZ4_HASH_SIZE_U32 (1 << ATOMS_LZ4_HASHLOG) /* required as macro for static allocation */
561 
562 #if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
563 #include <stdint.h>
564 
567  uint32_t hashTable[ATOMS_LZ4_HASH_SIZE_U32];
568  uint32_t currentOffset;
569  uint16_t dirty;
570  uint16_t tableType;
571  const uint8_t* dictionary;
572  const ATOMS_LZ4_stream_t_internal* dictCtx;
573  uint32_t dictSize;
574  };
575 
576  typedef struct {
577  const uint8_t* externalDict;
578  size_t extDictSize;
579  const uint8_t* prefixEnd;
580  size_t prefixSize;
582 
583 #else
584 
587  unsigned int hashTable[ATOMS_LZ4_HASH_SIZE_U32];
588  unsigned int currentOffset;
589  unsigned short dirty;
590  unsigned short tableType;
591  const unsigned char* dictionary;
592  const ATOMS_LZ4_stream_t_internal* dictCtx;
593  unsigned int dictSize;
594  };
595 
596  typedef struct {
597  const unsigned char* externalDict;
598  const unsigned char* prefixEnd;
599  size_t extDictSize;
600  size_t prefixSize;
602 
603 #endif
604 
614 #define ATOMS_LZ4_STREAMSIZE_U64 ((1 << (ATOMS_LZ4_MEMORY_USAGE-3)) + 4 + ((sizeof(void*)==16) ? 4 : 0) /*AS-400*/ )
615 #define ATOMS_LZ4_STREAMSIZE (ATOMS_LZ4_STREAMSIZE_U64 * sizeof(unsigned long long))
617  unsigned long long table[ATOMS_LZ4_STREAMSIZE_U64];
618  ATOMS_LZ4_stream_t_internal internal_donotuse;
619  }; /* previously typedef'd to ATOMS_LZ4_stream_t */
620 
635  ATOMS_LZ4LIB_API ATOMS_LZ4_stream_t* ATOMS_LZ4_initStream(void* buffer, size_t size);
636 
637 
645 #define ATOMS_LZ4_STREAMDECODESIZE_U64 (4 + ((sizeof(void*)==16) ? 2 : 0) /*AS-400*/ )
646 #define ATOMS_LZ4_STREAMDECODESIZE (ATOMS_LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long))
648  unsigned long long table[ATOMS_LZ4_STREAMDECODESIZE_U64];
649  ATOMS_LZ4_streamDecode_t_internal internal_donotuse;
650  }; /* previously typedef'd to ATOMS_LZ4_streamDecode_t */
651 
652 
653 
654  /*-************************************
655  * Obsolete Functions
656  **************************************/
657 
669 # define ATOMS_LZ4_DEPRECATED(message) /* disable deprecation warnings */
670 
671  /* Obsolete compression functions */
672  ATOMS_LZ4_DEPRECATED("use ATOMS_LZ4_compress_default() instead") ATOMS_LZ4LIB_API int ATOMS_LZ4_compress(const char* src, char* dest, int srcSize);
673  ATOMS_LZ4_DEPRECATED("use ATOMS_LZ4_compress_default() instead") ATOMS_LZ4LIB_API int ATOMS_LZ4_compress_limitedOutput(const char* src, char* dest, int srcSize, int maxOutputSize);
674  ATOMS_LZ4_DEPRECATED("use ATOMS_LZ4_compress_fast_extState() instead") ATOMS_LZ4LIB_API int ATOMS_LZ4_compress_withState(void* state, const char* source, char* dest, int inputSize);
675  ATOMS_LZ4_DEPRECATED("use ATOMS_LZ4_compress_fast_extState() instead") ATOMS_LZ4LIB_API int ATOMS_LZ4_compress_limitedOutput_withState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
676  ATOMS_LZ4_DEPRECATED("use ATOMS_LZ4_compress_fast_continue() instead") ATOMS_LZ4LIB_API int ATOMS_LZ4_compress_continue(ATOMS_LZ4_stream_t* ATOMS_LZ4_streamPtr, const char* source, char* dest, int inputSize);
677  ATOMS_LZ4_DEPRECATED("use ATOMS_LZ4_compress_fast_continue() instead") ATOMS_LZ4LIB_API int ATOMS_LZ4_compress_limitedOutput_continue(ATOMS_LZ4_stream_t* ATOMS_LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
678 
679  /* Obsolete decompression functions */
680  ATOMS_LZ4_DEPRECATED("use ATOMS_LZ4_decompress_fast() instead") ATOMS_LZ4LIB_API int ATOMS_LZ4_uncompress(const char* source, char* dest, int outputSize);
681  ATOMS_LZ4_DEPRECATED("use ATOMS_LZ4_decompress_safe() instead") ATOMS_LZ4LIB_API int ATOMS_LZ4_uncompress_unknownOutputSize(const char* source, char* dest, int isize, int maxOutputSize);
682 
683  /* Obsolete streaming functions; degraded functionality; do not use!
684  *
685  * In order to perform streaming compression, these functions depended on data
686  * that is no longer tracked in the state. They have been preserved as well as
687  * possible: using them will still produce a correct output. However, they don't
688  * actually retain any history between compression calls. The compression ratio
689  * achieved will therefore be no better than compressing each chunk
690  * independently.
691  */
692  ATOMS_LZ4_DEPRECATED("Use ATOMS_LZ4_createStream() instead") ATOMS_LZ4LIB_API void* ATOMS_LZ4_create(char* inputBuffer);
693  ATOMS_LZ4_DEPRECATED("Use ATOMS_LZ4_createStream() instead") ATOMS_LZ4LIB_API int ATOMS_LZ4_sizeofStreamState(void);
694  ATOMS_LZ4_DEPRECATED("Use ATOMS_LZ4_resetStream() instead") ATOMS_LZ4LIB_API int ATOMS_LZ4_resetStreamState(void* state, char* inputBuffer);
695  ATOMS_LZ4_DEPRECATED("Use ATOMS_LZ4_saveDict() instead") ATOMS_LZ4LIB_API char* ATOMS_LZ4_slideInputBuffer(void* state);
696 
697  /* Obsolete streaming decoding functions */
698  ATOMS_LZ4_DEPRECATED("use ATOMS_LZ4_decompress_safe_usingDict() instead") ATOMS_LZ4LIB_API int ATOMS_LZ4_decompress_safe_withPrefix64k(const char* src, char* dst, int compressedSize, int maxDstSize);
699  ATOMS_LZ4_DEPRECATED("use ATOMS_LZ4_decompress_fast_usingDict() instead") ATOMS_LZ4LIB_API int ATOMS_LZ4_decompress_fast_withPrefix64k(const char* src, char* dst, int originalSize);
700 
729  ATOMS_LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using ATOMS_LZ4_decompress_safe() instead")
730  ATOMS_LZ4LIB_API int ATOMS_LZ4_decompress_fast(const char* src, char* dst, int originalSize);
731  ATOMS_LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using ATOMS_LZ4_decompress_safe_continue() instead")
732  ATOMS_LZ4LIB_API int ATOMS_LZ4_decompress_fast_continue(ATOMS_LZ4_streamDecode_t* ATOMS_LZ4_streamDecode, const char* src, char* dst, int originalSize);
733  ATOMS_LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using ATOMS_LZ4_decompress_safe_usingDict() instead")
734  ATOMS_LZ4LIB_API int ATOMS_LZ4_decompress_fast_usingDict(const char* src, char* dst, int originalSize, const char* dictStart, int dictSize);
735 
742  ATOMS_LZ4LIB_API void ATOMS_LZ4_resetStream(ATOMS_LZ4_stream_t* streamPtr);
743 
744 
745 #endif /* ATOMS_LZ4_H_98237428734687 */
746 
747 
748 #if defined (__cplusplus)
749 }
750 #endif
751 #endif
752 #endif
Definition: Compression.h:586
Definition: Compression.h:596
Definition: Compression.h:616
Definition: Compression.h:647