1370b324cSopenharmony_ci/* Lzma86.h -- LZMA + x86 (BCJ) Filter 2370b324cSopenharmony_ci2023-03-03 : Igor Pavlov : Public domain */ 3370b324cSopenharmony_ci 4370b324cSopenharmony_ci#ifndef ZIP7_INC_LZMA86_H 5370b324cSopenharmony_ci#define ZIP7_INC_LZMA86_H 6370b324cSopenharmony_ci 7370b324cSopenharmony_ci#include "7zTypes.h" 8370b324cSopenharmony_ci 9370b324cSopenharmony_ciEXTERN_C_BEGIN 10370b324cSopenharmony_ci 11370b324cSopenharmony_ci#define LZMA86_SIZE_OFFSET (1 + 5) 12370b324cSopenharmony_ci#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8) 13370b324cSopenharmony_ci 14370b324cSopenharmony_ci/* 15370b324cSopenharmony_ciIt's an example for LZMA + x86 Filter use. 16370b324cSopenharmony_ciYou can use .lzma86 extension, if you write that stream to file. 17370b324cSopenharmony_ci.lzma86 header adds one additional byte to standard .lzma header. 18370b324cSopenharmony_ci.lzma86 header (14 bytes): 19370b324cSopenharmony_ci Offset Size Description 20370b324cSopenharmony_ci 0 1 = 0 - no filter, pure LZMA 21370b324cSopenharmony_ci = 1 - x86 filter + LZMA 22370b324cSopenharmony_ci 1 1 lc, lp and pb in encoded form 23370b324cSopenharmony_ci 2 4 dictSize (little endian) 24370b324cSopenharmony_ci 6 8 uncompressed size (little endian) 25370b324cSopenharmony_ci 26370b324cSopenharmony_ci 27370b324cSopenharmony_ciLzma86_Encode 28370b324cSopenharmony_ci------------- 29370b324cSopenharmony_cilevel - compression level: 0 <= level <= 9, the default value for "level" is 5. 30370b324cSopenharmony_ci 31370b324cSopenharmony_cidictSize - The dictionary size in bytes. The maximum value is 32370b324cSopenharmony_ci 128 MB = (1 << 27) bytes for 32-bit version 33370b324cSopenharmony_ci 1 GB = (1 << 30) bytes for 64-bit version 34370b324cSopenharmony_ci The default value is 16 MB = (1 << 24) bytes, for level = 5. 35370b324cSopenharmony_ci It's recommended to use the dictionary that is larger than 4 KB and 36370b324cSopenharmony_ci that can be calculated as (1 << N) or (3 << N) sizes. 37370b324cSopenharmony_ci For better compression ratio dictSize must be >= inSize. 38370b324cSopenharmony_ci 39370b324cSopenharmony_cifilterMode: 40370b324cSopenharmony_ci SZ_FILTER_NO - no Filter 41370b324cSopenharmony_ci SZ_FILTER_YES - x86 Filter 42370b324cSopenharmony_ci SZ_FILTER_AUTO - it tries both alternatives to select best. 43370b324cSopenharmony_ci Encoder will use 2 or 3 passes: 44370b324cSopenharmony_ci 2 passes when FILTER_NO provides better compression. 45370b324cSopenharmony_ci 3 passes when FILTER_YES provides better compression. 46370b324cSopenharmony_ci 47370b324cSopenharmony_ciLzma86Encode allocates Data with MyAlloc functions. 48370b324cSopenharmony_ciRAM Requirements for compressing: 49370b324cSopenharmony_ci RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize 50370b324cSopenharmony_ci filterMode FilterBlockSize 51370b324cSopenharmony_ci SZ_FILTER_NO 0 52370b324cSopenharmony_ci SZ_FILTER_YES inSize 53370b324cSopenharmony_ci SZ_FILTER_AUTO inSize 54370b324cSopenharmony_ci 55370b324cSopenharmony_ci 56370b324cSopenharmony_ciReturn code: 57370b324cSopenharmony_ci SZ_OK - OK 58370b324cSopenharmony_ci SZ_ERROR_MEM - Memory allocation error 59370b324cSopenharmony_ci SZ_ERROR_PARAM - Incorrect paramater 60370b324cSopenharmony_ci SZ_ERROR_OUTPUT_EOF - output buffer overflow 61370b324cSopenharmony_ci SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 62370b324cSopenharmony_ci*/ 63370b324cSopenharmony_ci 64370b324cSopenharmony_cienum ESzFilterMode 65370b324cSopenharmony_ci{ 66370b324cSopenharmony_ci SZ_FILTER_NO, 67370b324cSopenharmony_ci SZ_FILTER_YES, 68370b324cSopenharmony_ci SZ_FILTER_AUTO 69370b324cSopenharmony_ci}; 70370b324cSopenharmony_ci 71370b324cSopenharmony_ciSRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, 72370b324cSopenharmony_ci int level, UInt32 dictSize, int filterMode); 73370b324cSopenharmony_ci 74370b324cSopenharmony_ci 75370b324cSopenharmony_ci/* 76370b324cSopenharmony_ciLzma86_GetUnpackSize: 77370b324cSopenharmony_ci In: 78370b324cSopenharmony_ci src - input data 79370b324cSopenharmony_ci srcLen - input data size 80370b324cSopenharmony_ci Out: 81370b324cSopenharmony_ci unpackSize - size of uncompressed stream 82370b324cSopenharmony_ci Return code: 83370b324cSopenharmony_ci SZ_OK - OK 84370b324cSopenharmony_ci SZ_ERROR_INPUT_EOF - Error in headers 85370b324cSopenharmony_ci*/ 86370b324cSopenharmony_ci 87370b324cSopenharmony_ciSRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize); 88370b324cSopenharmony_ci 89370b324cSopenharmony_ci/* 90370b324cSopenharmony_ciLzma86_Decode: 91370b324cSopenharmony_ci In: 92370b324cSopenharmony_ci dest - output data 93370b324cSopenharmony_ci destLen - output data size 94370b324cSopenharmony_ci src - input data 95370b324cSopenharmony_ci srcLen - input data size 96370b324cSopenharmony_ci Out: 97370b324cSopenharmony_ci destLen - processed output size 98370b324cSopenharmony_ci srcLen - processed input size 99370b324cSopenharmony_ci Return code: 100370b324cSopenharmony_ci SZ_OK - OK 101370b324cSopenharmony_ci SZ_ERROR_DATA - Data error 102370b324cSopenharmony_ci SZ_ERROR_MEM - Memory allocation error 103370b324cSopenharmony_ci SZ_ERROR_UNSUPPORTED - unsupported file 104370b324cSopenharmony_ci SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer 105370b324cSopenharmony_ci*/ 106370b324cSopenharmony_ci 107370b324cSopenharmony_ciSRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen); 108370b324cSopenharmony_ci 109370b324cSopenharmony_ciEXTERN_C_END 110370b324cSopenharmony_ci 111370b324cSopenharmony_ci#endif 112