3 #include "LzmaRamDecode.h"
4 #ifdef _SZ_ONE_DIRECTORY
5 #include "LzmaDecode.h"
8 #include "../../../../C/Compress/Lzma/LzmaDecode.h"
9 #include "../../../../C/Compress/Branch/BranchX86.h"
12 #define LZMA_PROPS_SIZE 14
13 #define LZMA_SIZE_OFFSET 6
15 int LzmaRamGetUncompressedSize(
16 const unsigned char *inBuffer,
21 if (inSize < LZMA_PROPS_SIZE)
24 for(i = 0; i < sizeof(size_t); i++)
25 *outSize += ((size_t)inBuffer[LZMA_SIZE_OFFSET + i]) << (8 * i);
27 if (inBuffer[LZMA_SIZE_OFFSET + i] != 0)
32 #define SZE_DATA_ERROR (1)
33 #define SZE_OUTOFMEMORY (2)
35 int LzmaRamDecompress(
36 const unsigned char *inBuffer,
38 unsigned char *outBuffer,
40 size_t *outSizeProcessed,
41 void * (*allocFunc)(size_t size),
42 void (*freeFunc)(void *))
44 CLzmaDecoderState state; /* it's about 24 bytes structure, if int is 32-bit */
46 SizeT outSizeProcessedLoc;
50 if (inSize < LZMA_PROPS_SIZE)
52 useFilter = inBuffer[0];
54 *outSizeProcessed = 0;
58 if (LzmaDecodeProperties(&state.Properties, inBuffer + 1, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)
60 state.Probs = (CProb *)allocFunc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
62 return SZE_OUTOFMEMORY;
64 result = LzmaDecode(&state,
65 inBuffer + LZMA_PROPS_SIZE, (SizeT)inSize - LZMA_PROPS_SIZE, &inProcessed,
66 outBuffer, (SizeT)outSize, &outSizeProcessedLoc);
67 freeFunc(state.Probs);
68 if (result != LZMA_RESULT_OK)
70 *outSizeProcessed = (size_t)outSizeProcessedLoc;
74 x86_Convert_Init(x86State);
75 x86_Convert(outBuffer, (SizeT)outSizeProcessedLoc, 0, &x86State, 0);