Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/lzma/include/Lzma2Dec.h
4253 views
1
/* Lzma2Dec.h -- LZMA2 Decoder
2
2023-03-03 : Igor Pavlov : Public domain */
3
4
#ifndef ZIP7_INC_LZMA2_DEC_H
5
#define ZIP7_INC_LZMA2_DEC_H
6
7
#include "LzmaDec.h"
8
9
EXTERN_C_BEGIN
10
11
/* ---------- State Interface ---------- */
12
13
typedef struct
14
{
15
unsigned state;
16
Byte control;
17
Byte needInitLevel;
18
Byte isExtraMode;
19
Byte _pad_;
20
UInt32 packSize;
21
UInt32 unpackSize;
22
CLzmaDec decoder;
23
} CLzma2Dec;
24
25
#define Lzma2Dec_CONSTRUCT(p) LzmaDec_CONSTRUCT(&(p)->decoder)
26
#define Lzma2Dec_Construct(p) Lzma2Dec_CONSTRUCT(p)
27
#define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc)
28
#define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc)
29
30
SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAllocPtr alloc);
31
SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAllocPtr alloc);
32
void Lzma2Dec_Init(CLzma2Dec *p);
33
34
/*
35
finishMode:
36
It has meaning only if the decoding reaches output limit (*destLen or dicLimit).
37
LZMA_FINISH_ANY - use smallest number of input bytes
38
LZMA_FINISH_END - read EndOfStream marker after decoding
39
40
Returns:
41
SZ_OK
42
status:
43
LZMA_STATUS_FINISHED_WITH_MARK
44
LZMA_STATUS_NOT_FINISHED
45
LZMA_STATUS_NEEDS_MORE_INPUT
46
SZ_ERROR_DATA - Data error
47
*/
48
49
SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
50
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
51
52
SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen,
53
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
54
55
56
/* ---------- LZMA2 block and chunk parsing ---------- */
57
58
/*
59
Lzma2Dec_Parse() parses compressed data stream up to next independent block or next chunk data.
60
It can return LZMA_STATUS_* code or LZMA2_PARSE_STATUS_* code:
61
- LZMA2_PARSE_STATUS_NEW_BLOCK - there is new block, and 1 additional byte (control byte of next block header) was read from input.
62
- LZMA2_PARSE_STATUS_NEW_CHUNK - there is new chunk, and only lzma2 header of new chunk was read.
63
CLzma2Dec::unpackSize contains unpack size of that chunk
64
*/
65
66
typedef enum
67
{
68
/*
69
LZMA_STATUS_NOT_SPECIFIED // data error
70
LZMA_STATUS_FINISHED_WITH_MARK
71
LZMA_STATUS_NOT_FINISHED //
72
LZMA_STATUS_NEEDS_MORE_INPUT
73
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK // unused
74
*/
75
LZMA2_PARSE_STATUS_NEW_BLOCK = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK + 1,
76
LZMA2_PARSE_STATUS_NEW_CHUNK
77
} ELzma2ParseStatus;
78
79
ELzma2ParseStatus Lzma2Dec_Parse(CLzma2Dec *p,
80
SizeT outSize, // output size
81
const Byte *src, SizeT *srcLen,
82
int checkFinishBlock // set (checkFinishBlock = 1), if it must read full input data, if decoder.dicPos reaches blockMax position.
83
);
84
85
/*
86
LZMA2 parser doesn't decode LZMA chunks, so we must read
87
full input LZMA chunk to decode some part of LZMA chunk.
88
89
Lzma2Dec_GetUnpackExtra() returns the value that shows
90
max possible number of output bytes that can be output by decoder
91
at current input positon.
92
*/
93
94
#define Lzma2Dec_GetUnpackExtra(p) ((p)->isExtraMode ? (p)->unpackSize : 0)
95
96
97
/* ---------- One Call Interface ---------- */
98
99
/*
100
finishMode:
101
It has meaning only if the decoding reaches output limit (*destLen).
102
LZMA_FINISH_ANY - use smallest number of input bytes
103
LZMA_FINISH_END - read EndOfStream marker after decoding
104
105
Returns:
106
SZ_OK
107
status:
108
LZMA_STATUS_FINISHED_WITH_MARK
109
LZMA_STATUS_NOT_FINISHED
110
SZ_ERROR_DATA - Data error
111
SZ_ERROR_MEM - Memory allocation error
112
SZ_ERROR_UNSUPPORTED - Unsupported properties
113
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
114
*/
115
116
SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
117
Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAllocPtr alloc);
118
119
EXTERN_C_END
120
121
#endif
122
123