| 1 | /* LzmaDec.h -- LZMA Decoder |
| 2 | 2008-10-04 : Igor Pavlov : Public domain */ |
| 3 | |
| 4 | #ifndef __LZMADEC_H |
| 5 | #define __LZMADEC_Hcxx . . $ `compression/lzma/LzmaDec.h:5:9`! |
| 6 | |
| 7 | #include "Types.h"cxx . . $ `<file>/compression/lzma/Types.h`/ |
| 8 | |
| 9 | /* #define _LZMA_PROB32 */ |
| 10 | /* _LZMA_PROB32 can increase the speed on some CPUs, |
| 11 | but memory usage for CLzmaDec::probs will be doubled in that case */ |
| 12 | |
| 13 | #ifdef _LZMA_PROB32 |
| 14 | #define CLzmaProb UInt32 |
| 15 | #else |
| 16 | #define CLzmaProbcxx . . $ `compression/lzma/LzmaDec.h:16:9`! UInt16 |
| 17 | #endif |
| 18 | |
| 19 | |
| 20 | /* ---------- LZMA Properties ---------- */ |
| 21 | |
| 22 | #define LZMA_PROPS_SIZEcxx . . $ `compression/lzma/LzmaDec.h:22:9`! 5 |
| 23 | |
| 24 | typedef struct _CLzmaPropscxx . . $ _CLzmaProps# |
| 25 | { |
| 26 | unsigned lccxx . . $ _CLzmaProps#lc., lpcxx . . $ _CLzmaProps#lp., pbcxx . . $ _CLzmaProps#pb.; |
| 27 | UInt32cxx . . $ UInt32# dicSizecxx . . $ _CLzmaProps#dicSize.; |
| 28 | } CLzmaPropscxx . . $ CLzmaProps#; |
| 29 | |
| 30 | /* LzmaProps_Decode - decodes properties |
| 31 | Returns: |
| 32 | SZ_OK |
| 33 | SZ_ERROR_UNSUPPORTED - Unsupported properties |
| 34 | */ |
| 35 | |
| 36 | SRescxx . . $ SRes# LzmaProps_Decodecxx . . $ LzmaProps_Decode(97dd0c2360cf5ce6).(CLzmaPropscxx . . $ CLzmaProps# *p, const Bytecxx . . $ Byte# *data, unsigned size); |
| 37 | |
| 38 | |
| 39 | /* ---------- LZMA Decoder state ---------- */ |
| 40 | |
| 41 | /* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case. |
| 42 | Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */ |
| 43 | |
| 44 | #define LZMA_REQUIRED_INPUT_MAXcxx . . $ `compression/lzma/LzmaDec.h:44:9`! 20 |
| 45 | |
| 46 | typedef struct CLzmaDeccxx . . $ CLzmaDec# |
| 47 | { |
| 48 | CLzmaPropscxx . . $ CLzmaProps# propcxx . . $ CLzmaDec#prop.; |
| 49 | CLzmaProbcxx . . $ `compression/lzma/LzmaDec.h:16:9`! *probscxx . . $ CLzmaDec#probs.; |
| 50 | Bytecxx . . $ Byte# *diccxx . . $ CLzmaDec#dic.; |
| 51 | const Bytecxx . . $ Byte# *bufcxx . . $ CLzmaDec#buf.; |
| 52 | UInt32cxx . . $ UInt32# rangecxx . . $ CLzmaDec#range., codecxx . . $ CLzmaDec#code.; |
| 53 | SizeTcxx . . $ SizeT# dicPoscxx . . $ CLzmaDec#dicPos.; |
| 54 | SizeTcxx . . $ SizeT# dicBufSizecxx . . $ CLzmaDec#dicBufSize.; |
| 55 | UInt32cxx . . $ UInt32# processedPoscxx . . $ CLzmaDec#processedPos.; |
| 56 | UInt32cxx . . $ UInt32# checkDicSizecxx . . $ CLzmaDec#checkDicSize.; |
| 57 | unsigned statecxx . . $ CLzmaDec#state.; |
| 58 | UInt32cxx . . $ UInt32# repscxx . . $ CLzmaDec#reps.[4]; |
| 59 | unsigned remainLencxx . . $ CLzmaDec#remainLen.; |
| 60 | int needFlushcxx . . $ CLzmaDec#needFlush.; |
| 61 | int needInitStatecxx . . $ CLzmaDec#needInitState.; |
| 62 | UInt32cxx . . $ UInt32# numProbscxx . . $ CLzmaDec#numProbs.; |
| 63 | unsigned tempBufSizecxx . . $ CLzmaDec#tempBufSize.; |
| 64 | Bytecxx . . $ Byte# tempBufcxx . . $ CLzmaDec#tempBuf.[LZMA_REQUIRED_INPUT_MAXcxx . . $ `compression/lzma/LzmaDec.h:44:9`!]; |
| 65 | } CLzmaDeccxx . . $ CLzmaDec#; |
| 66 | |
| 67 | #define LzmaDec_Constructcxx . . $ `compression/lzma/LzmaDec.h:67:9`!(p) { (p)->dic = 0; (p)->probs = 0; } |
| 68 | |
| 69 | void LzmaDec_Initcxx . . $ LzmaDec_Init(79abff0c036e14c0).(CLzmaDeccxx . . $ CLzmaDec# *p); |
| 70 | |
| 71 | /* There are two types of LZMA streams: |
| 72 | 0) Stream with end mark. That end mark adds about 6 bytes to compressed size. |
| 73 | 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */ |
| 74 | |
| 75 | typedef enum ELzmaFinishModecxx . . $ ELzmaFinishMode# |
| 76 | { |
| 77 | LZMA_FINISH_ANYcxx . . $ LZMA_FINISH_ANY., /* finish at any point */ |
| 78 | LZMA_FINISH_ENDcxx . . $ LZMA_FINISH_END. /* block must be finished at the end */ |
| 79 | } ELzmaFinishModecxx . . $ ELzmaFinishMode#; |
| 80 | |
| 81 | /* ELzmaFinishMode has meaning only if the decoding reaches output limit !!! |
| 82 | |
| 83 | You must use LZMA_FINISH_END, when you know that current output buffer |
| 84 | covers last bytes of block. In other cases you must use LZMA_FINISH_ANY. |
| 85 | |
| 86 | If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK, |
| 87 | and output value of destLen will be less than output buffer size limit. |
| 88 | You can check status result also. |
| 89 | |
| 90 | You can use multiple checks to test data integrity after full decompression: |
| 91 | 1) Check Result and "status" variable. |
| 92 | 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize. |
| 93 | 3) Check that output(srcLen) = compressedSize, if you know real compressedSize. |
| 94 | You must use correct finish mode in that case. */ |
| 95 | |
| 96 | typedef enum ELzmaStatuscxx . . $ ELzmaStatus# |
| 97 | { |
| 98 | LZMA_STATUS_NOT_SPECIFIEDcxx . . $ LZMA_STATUS_NOT_SPECIFIED., /* use main error code instead */ |
| 99 | LZMA_STATUS_FINISHED_WITH_MARKcxx . . $ LZMA_STATUS_FINISHED_WITH_MARK., /* stream was finished with end mark. */ |
| 100 | LZMA_STATUS_NOT_FINISHEDcxx . . $ LZMA_STATUS_NOT_FINISHED., /* stream was not finished */ |
| 101 | LZMA_STATUS_NEEDS_MORE_INPUTcxx . . $ LZMA_STATUS_NEEDS_MORE_INPUT., /* you must provide more input bytes */ |
| 102 | LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARKcxx . . $ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK. /* there is probability that stream was finished without end mark */ |
| 103 | } ELzmaStatuscxx . . $ ELzmaStatus#; |
| 104 | |
| 105 | /* ELzmaStatus is used only as output value for function call */ |
| 106 | |
| 107 | |
| 108 | /* ---------- Interfaces ---------- */ |
| 109 | |
| 110 | /* There are 3 levels of interfaces: |
| 111 | 1) Dictionary Interface |
| 112 | 2) Buffer Interface |
| 113 | 3) One Call Interface |
| 114 | You can select any of these interfaces, but don't mix functions from different |
| 115 | groups for same object. */ |
| 116 | |
| 117 | |
| 118 | /* There are two variants to allocate state for Dictionary Interface: |
| 119 | 1) LzmaDec_Allocate / LzmaDec_Free |
| 120 | 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs |
| 121 | You can use variant 2, if you set dictionary buffer manually. |
| 122 | For Buffer Interface you must always use variant 1. |
| 123 | |
| 124 | LzmaDec_Allocate* can return: |
| 125 | SZ_OK |
| 126 | SZ_ERROR_MEM - Memory allocation error |
| 127 | SZ_ERROR_UNSUPPORTED - Unsupported properties |
| 128 | */ |
| 129 | |
| 130 | SRescxx . . $ SRes# LzmaDec_AllocateProbscxx . . $ LzmaDec_AllocateProbs(67510d72f9320c1c).(CLzmaDeccxx . . $ CLzmaDec# *p, const Bytecxx . . $ Byte# *props, unsigned propsSize, ISzAlloccxx . . $ ISzAlloc# *alloc); |
| 131 | void LzmaDec_FreeProbscxx . . $ LzmaDec_FreeProbs(75da09990452a35a).(CLzmaDeccxx . . $ CLzmaDec# *p, ISzAlloccxx . . $ ISzAlloc# *alloc); |
| 132 | |
| 133 | SRescxx . . $ SRes# LzmaDec_Allocatecxx . . $ LzmaDec_Allocate(67510d72f9320c1c).(CLzmaDeccxx . . $ CLzmaDec# *state, const Bytecxx . . $ Byte# *prop, unsigned propsSize, ISzAlloccxx . . $ ISzAlloc# *alloc); |
| 134 | void LzmaDec_Freecxx . . $ LzmaDec_Free(75da09990452a35a).(CLzmaDeccxx . . $ CLzmaDec# *state, ISzAlloccxx . . $ ISzAlloc# *alloc); |
| 135 | |
| 136 | /* ---------- Dictionary Interface ---------- */ |
| 137 | |
| 138 | /* You can use it, if you want to eliminate the overhead for data copying from |
| 139 | dictionary to some other external buffer. |
| 140 | You must work with CLzmaDec variables directly in this interface. |
| 141 | |
| 142 | STEPS: |
| 143 | LzmaDec_Constr() |
| 144 | LzmaDec_Allocate() |
| 145 | for (each new stream) |
| 146 | { |
| 147 | LzmaDec_Init() |
| 148 | while (it needs more decompression) |
| 149 | { |
| 150 | LzmaDec_DecodeToDic() |
| 151 | use data from CLzmaDec::dic and update CLzmaDec::dicPos |
| 152 | } |
| 153 | } |
| 154 | LzmaDec_Free() |
| 155 | */ |
| 156 | |
| 157 | /* LzmaDec_DecodeToDic |
| 158 | |
| 159 | The decoding to internal dictionary buffer (CLzmaDec::dic). |
| 160 | You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!! |
| 161 | |
| 162 | finishMode: |
| 163 | It has meaning only if the decoding reaches output limit (dicLimit). |
| 164 | LZMA_FINISH_ANY - Decode just dicLimit bytes. |
| 165 | LZMA_FINISH_END - Stream must be finished after dicLimit. |
| 166 | |
| 167 | Returns: |
| 168 | SZ_OK |
| 169 | status: |
| 170 | LZMA_STATUS_FINISHED_WITH_MARK |
| 171 | LZMA_STATUS_NOT_FINISHED |
| 172 | LZMA_STATUS_NEEDS_MORE_INPUT |
| 173 | LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK |
| 174 | SZ_ERROR_DATA - Data error |
| 175 | */ |
| 176 | |
| 177 | SRescxx . . $ SRes# LzmaDec_DecodeToDiccxx . . $ LzmaDec_DecodeToDic(abf922dc217052b7).(CLzmaDeccxx . . $ CLzmaDec# *p, SizeTcxx . . $ SizeT# dicLimit, |
| 178 | const Bytecxx . . $ Byte# *src, SizeTcxx . . $ SizeT# *srcLen, ELzmaFinishModecxx . . $ ELzmaFinishMode# finishMode, ELzmaStatuscxx . . $ ELzmaStatus# *status); |
| 179 | |
| 180 | |
| 181 | /* ---------- Buffer Interface ---------- */ |
| 182 | |
| 183 | /* It's zlib-like interface. |
| 184 | See LzmaDec_DecodeToDic description for information about STEPS and return results, |
| 185 | but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need |
| 186 | to work with CLzmaDec variables manually. |
| 187 | |
| 188 | finishMode: |
| 189 | It has meaning only if the decoding reaches output limit (*destLen). |
| 190 | LZMA_FINISH_ANY - Decode just destLen bytes. |
| 191 | LZMA_FINISH_END - Stream must be finished after (*destLen). |
| 192 | */ |
| 193 | |
| 194 | SRescxx . . $ SRes# LzmaDec_DecodeToBufcxx . . $ LzmaDec_DecodeToBuf(c96b3f218871e361).(CLzmaDeccxx . . $ CLzmaDec# *p, Bytecxx . . $ Byte# *dest, SizeTcxx . . $ SizeT# *destLen, |
| 195 | const Bytecxx . . $ Byte# *src, SizeTcxx . . $ SizeT# *srcLen, ELzmaFinishModecxx . . $ ELzmaFinishMode# finishMode, ELzmaStatuscxx . . $ ELzmaStatus# *status); |
| 196 | |
| 197 | |
| 198 | /* ---------- One Call Interface ---------- */ |
| 199 | |
| 200 | /* LzmaDecode |
| 201 | |
| 202 | finishMode: |
| 203 | It has meaning only if the decoding reaches output limit (*destLen). |
| 204 | LZMA_FINISH_ANY - Decode just destLen bytes. |
| 205 | LZMA_FINISH_END - Stream must be finished after (*destLen). |
| 206 | |
| 207 | Returns: |
| 208 | SZ_OK |
| 209 | status: |
| 210 | LZMA_STATUS_FINISHED_WITH_MARK |
| 211 | LZMA_STATUS_NOT_FINISHED |
| 212 | LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK |
| 213 | SZ_ERROR_DATA - Data error |
| 214 | SZ_ERROR_MEM - Memory allocation error |
| 215 | SZ_ERROR_UNSUPPORTED - Unsupported properties |
| 216 | SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). |
| 217 | */ |
| 218 | |
| 219 | SRescxx . . $ SRes# LzmaDecodecxx . . $ LzmaDecode(9978c00faa35db6d).(Bytecxx . . $ Byte# *dest, SizeTcxx . . $ SizeT# *destLen, const Bytecxx . . $ Byte# *src, SizeTcxx . . $ SizeT# *srcLen, |
| 220 | const Bytecxx . . $ Byte# *propData, unsigned propSize, ELzmaFinishModecxx . . $ ELzmaFinishMode# finishMode, |
| 221 | ELzmaStatuscxx . . $ ELzmaStatus# *status, ISzAlloccxx . . $ ISzAlloc# *alloc); |
| 222 | |
| 223 | #endif |