1 /* 2 * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef __LZMADECODE_H 16 #define __LZMADECODE_H 17 18 19 /* #define _LZMA_IN_CB */ 20 /* Use callback for input data */ 21 22 /* #define _LZMA_OUT_READ */ 23 /* Use read function for output data */ 24 25 /* #define _LZMA_PROB32 */ 26 /* it's not suitable for genie project, memory usage double only */ 27 /* It can increase speed on some 32-bit CPUs, 28 but memory usage will be doubled in that case */ 29 30 #ifndef UInt32 31 #ifdef _LZMA_UINT32_IS_ULONG 32 #define UInt32 unsigned long 33 #else 34 #define UInt32 unsigned int 35 #endif 36 #endif 37 38 #ifdef _LZMA_PROB32 39 #define CProb UInt32 40 #else 41 #define CProb unsigned short 42 #endif 43 44 #define LZMA_RESULT_OK 0 45 #define LZMA_RESULT_DATA_ERROR 1 46 47 #ifdef _LZMA_IN_CB 48 typedef struct _ILzmaInCallback 49 { 50 int (*Read)(void *object, const unsigned char **buffer, unsigned int *bufferSize); 51 } ILzmaInCallback; 52 #endif 53 54 #define LZMA_BASE_SIZE 1846 55 #define LZMA_LIT_SIZE 768 56 57 #define LZMA_PROPERTIES_SIZE 5 58 59 typedef struct _CLzmaProperties 60 { 61 int lc; 62 int lp; 63 int pb; 64 #ifdef _LZMA_OUT_READ 65 UInt32 DictionarySize; 66 #endif 67 }CLzmaProperties; 68 69 int bes_LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size); 70 71 #define bes_LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp))) 72 73 #define kLzmaNeedInitId (-2) 74 75 typedef struct _CLzmaDecoderState 76 { 77 CLzmaProperties Properties; 78 CProb *Probs; 79 80 #ifdef _LZMA_IN_CB 81 const unsigned char *Buffer; 82 const unsigned char *BufferLim; 83 #endif 84 85 #ifdef _LZMA_OUT_READ 86 unsigned char *Dictionary; 87 UInt32 Range; 88 UInt32 Code; 89 UInt32 DictionaryPos; 90 UInt32 GlobalPos; 91 UInt32 DistanceLimit; 92 UInt32 Reps[4]; 93 int State; 94 int RemainLen; 95 unsigned char TempDictionary[4]; 96 #endif 97 } CLzmaDecoderState; 98 99 #ifdef _LZMA_OUT_READ 100 #define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; } 101 #endif 102 103 int bes_LzmaDecode(CLzmaDecoderState *vs, 104 #ifdef _LZMA_IN_CB 105 ILzmaInCallback *inCallback, 106 #else 107 const unsigned char *inStream, unsigned int inSize, unsigned int *inSizeProcessed, 108 #endif 109 unsigned char *outStream, unsigned int outSize, unsigned int *outSizeProcessed); 110 111 #endif 112