strigi/src/streams
LzmaDec.h
Go to the documentation of this file.00001 /* LzmaDec.h -- LZMA Decoder 00002 2008-10-04 : Igor Pavlov : Public domain */ 00003 00004 #ifndef __LZMADEC_H 00005 #define __LZMADEC_H 00006 00007 #include "Types.h" 00008 00009 /* #define _LZMA_PROB32 */ 00010 /* _LZMA_PROB32 can increase the speed on some CPUs, 00011 but memory usage for CLzmaDec::probs will be doubled in that case */ 00012 00013 #ifdef _LZMA_PROB32 00014 #define CLzmaProb UInt32 00015 #else 00016 #define CLzmaProb UInt16 00017 #endif 00018 00019 00020 /* ---------- LZMA Properties ---------- */ 00021 00022 #define LZMA_PROPS_SIZE 5 00023 00024 typedef struct _CLzmaProps 00025 { 00026 unsigned lc, lp, pb; 00027 UInt32 dicSize; 00028 } CLzmaProps; 00029 00030 /* LzmaProps_Decode - decodes properties 00031 Returns: 00032 SZ_OK 00033 SZ_ERROR_UNSUPPORTED - Unsupported properties 00034 */ 00035 00036 SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size); 00037 00038 00039 /* ---------- LZMA Decoder state ---------- */ 00040 00041 /* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case. 00042 Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */ 00043 00044 #define LZMA_REQUIRED_INPUT_MAX 20 00045 00046 typedef struct 00047 { 00048 CLzmaProps prop; 00049 CLzmaProb *probs; 00050 Byte *dic; 00051 const Byte *buf; 00052 UInt32 range, code; 00053 SizeT dicPos; 00054 SizeT dicBufSize; 00055 UInt32 processedPos; 00056 UInt32 checkDicSize; 00057 unsigned state; 00058 UInt32 reps[4]; 00059 unsigned remainLen; 00060 int needFlush; 00061 int needInitState; 00062 UInt32 numProbs; 00063 unsigned tempBufSize; 00064 Byte tempBuf[LZMA_REQUIRED_INPUT_MAX]; 00065 } CLzmaDec; 00066 00067 #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; } 00068 00069 void LzmaDec_Init(CLzmaDec *p); 00070 00071 /* There are two types of LZMA streams: 00072 0) Stream with end mark. That end mark adds about 6 bytes to compressed size. 00073 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */ 00074 00075 typedef enum 00076 { 00077 LZMA_FINISH_ANY, /* finish at any point */ 00078 LZMA_FINISH_END /* block must be finished at the end */ 00079 } ELzmaFinishMode; 00080 00081 /* ELzmaFinishMode has meaning only if the decoding reaches output limit !!! 00082 00083 You must use LZMA_FINISH_END, when you know that current output buffer 00084 covers last bytes of block. In other cases you must use LZMA_FINISH_ANY. 00085 00086 If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK, 00087 and output value of destLen will be less than output buffer size limit. 00088 You can check status result also. 00089 00090 You can use multiple checks to test data integrity after full decompression: 00091 1) Check Result and "status" variable. 00092 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize. 00093 3) Check that output(srcLen) = compressedSize, if you know real compressedSize. 00094 You must use correct finish mode in that case. */ 00095 00096 typedef enum 00097 { 00098 LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */ 00099 LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */ 00100 LZMA_STATUS_NOT_FINISHED, /* stream was not finished */ 00101 LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */ 00102 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */ 00103 } ELzmaStatus; 00104 00105 /* ELzmaStatus is used only as output value for function call */ 00106 00107 00108 /* ---------- Interfaces ---------- */ 00109 00110 /* There are 3 levels of interfaces: 00111 1) Dictionary Interface 00112 2) Buffer Interface 00113 3) One Call Interface 00114 You can select any of these interfaces, but don't mix functions from different 00115 groups for same object. */ 00116 00117 00118 /* There are two variants to allocate state for Dictionary Interface: 00119 1) LzmaDec_Allocate / LzmaDec_Free 00120 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs 00121 You can use variant 2, if you set dictionary buffer manually. 00122 For Buffer Interface you must always use variant 1. 00123 00124 LzmaDec_Allocate* can return: 00125 SZ_OK 00126 SZ_ERROR_MEM - Memory allocation error 00127 SZ_ERROR_UNSUPPORTED - Unsupported properties 00128 */ 00129 00130 SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc); 00131 void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc); 00132 00133 SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc); 00134 void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc); 00135 00136 /* ---------- Dictionary Interface ---------- */ 00137 00138 /* You can use it, if you want to eliminate the overhead for data copying from 00139 dictionary to some other external buffer. 00140 You must work with CLzmaDec variables directly in this interface. 00141 00142 STEPS: 00143 LzmaDec_Constr() 00144 LzmaDec_Allocate() 00145 for (each new stream) 00146 { 00147 LzmaDec_Init() 00148 while (it needs more decompression) 00149 { 00150 LzmaDec_DecodeToDic() 00151 use data from CLzmaDec::dic and update CLzmaDec::dicPos 00152 } 00153 } 00154 LzmaDec_Free() 00155 */ 00156 00157 /* LzmaDec_DecodeToDic 00158 00159 The decoding to internal dictionary buffer (CLzmaDec::dic). 00160 You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!! 00161 00162 finishMode: 00163 It has meaning only if the decoding reaches output limit (dicLimit). 00164 LZMA_FINISH_ANY - Decode just dicLimit bytes. 00165 LZMA_FINISH_END - Stream must be finished after dicLimit. 00166 00167 Returns: 00168 SZ_OK 00169 status: 00170 LZMA_STATUS_FINISHED_WITH_MARK 00171 LZMA_STATUS_NOT_FINISHED 00172 LZMA_STATUS_NEEDS_MORE_INPUT 00173 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK 00174 SZ_ERROR_DATA - Data error 00175 */ 00176 00177 SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, 00178 const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); 00179 00180 00181 /* ---------- Buffer Interface ---------- */ 00182 00183 /* It's zlib-like interface. 00184 See LzmaDec_DecodeToDic description for information about STEPS and return results, 00185 but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need 00186 to work with CLzmaDec variables manually. 00187 00188 finishMode: 00189 It has meaning only if the decoding reaches output limit (*destLen). 00190 LZMA_FINISH_ANY - Decode just destLen bytes. 00191 LZMA_FINISH_END - Stream must be finished after (*destLen). 00192 */ 00193 00194 SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, 00195 const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); 00196 00197 00198 /* ---------- One Call Interface ---------- */ 00199 00200 /* LzmaDecode 00201 00202 finishMode: 00203 It has meaning only if the decoding reaches output limit (*destLen). 00204 LZMA_FINISH_ANY - Decode just destLen bytes. 00205 LZMA_FINISH_END - Stream must be finished after (*destLen). 00206 00207 Returns: 00208 SZ_OK 00209 status: 00210 LZMA_STATUS_FINISHED_WITH_MARK 00211 LZMA_STATUS_NOT_FINISHED 00212 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK 00213 SZ_ERROR_DATA - Data error 00214 SZ_ERROR_MEM - Memory allocation error 00215 SZ_ERROR_UNSUPPORTED - Unsupported properties 00216 SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). 00217 */ 00218 00219 SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, 00220 const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, 00221 ELzmaStatus *status, ISzAlloc *alloc); 00222 00223 #endif
KDE 4.4 API Reference