MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / Encode

Function Encode

BaseTools/Source/C/LzmaCompress/LzmaCompress.c:90–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize)
91{
92 SRes res;
93 size_t inSize = (size_t)fileSize;
94 Byte *inBuffer = 0;
95 Byte *outBuffer = 0;
96 Byte *filteredStream = 0;
97 size_t outSize;
98 CLzmaEncProps props;
99
100 LzmaEncProps_Init(&props);
101 LzmaEncProps_Normalize(&props);
102
103 if (inSize != 0) {
104 inBuffer = (Byte *)MyAlloc(inSize);
105 if (inBuffer == 0)
106 return SZ_ERROR_MEM;
107 } else {
108 return SZ_ERROR_INPUT_EOF;
109 }
110
111 if (SeqInStream_Read(inStream, inBuffer, inSize) != SZ_OK) {
112 res = SZ_ERROR_READ;
113 goto Done;
114 }
115
116 // we allocate 105% of original size + 64KB for output buffer
117 outSize = (size_t)fileSize / 20 * 21 + (1 << 16);
118 outBuffer = (Byte *)MyAlloc(outSize);
119 if (outBuffer == 0) {
120 res = SZ_ERROR_MEM;
121 goto Done;
122 }
123
124 {
125 int i;
126 for (i = 0; i < 8; i++)
127 outBuffer[i + LZMA_PROPS_SIZE] = (Byte)(fileSize >> (8 * i));
128 }
129
130 if (mConType != NoConverter)
131 {
132 filteredStream = (Byte *)MyAlloc(inSize);
133 if (filteredStream == 0) {
134 res = SZ_ERROR_MEM;
135 goto Done;
136 }
137 memcpy(filteredStream, inBuffer, inSize);
138
139 if (mConType == X86Converter) {
140 {
141 UInt32 x86State;
142 x86_Convert_Init(x86State);
143 x86_Convert(filteredStream, (SizeT) inSize, 0, &x86State, 1);
144 }
145 }
146 }
147

Callers 4

main2Function · 0.70
TianoCompressFunction · 0.50
EfiCompressFunction · 0.50
TianoCompressFunction · 0.50

Calls 10

SeqInStream_ReadFunction · 0.85
LzmaEncProps_InitFunction · 0.50
LzmaEncProps_NormalizeFunction · 0.50
MyAllocFunction · 0.50
memcpyFunction · 0.50
x86_Convert_InitFunction · 0.50
x86_ConvertFunction · 0.50
LzmaEncodeFunction · 0.50
MyFreeFunction · 0.50
WriteMethod · 0.45

Tested by

no test coverage detected