]>
Commit | Line | Data |
---|---|---|
30fdf114 | 1 | /** @file\r |
99e55970 | 2 | Internal include file for Tiano Decompress Library.\r |
30fdf114 | 3 | \r |
97fa0ee9 | 4 | Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r |
40d841f6 | 5 | This program and the accompanying materials\r |
30fdf114 LG |
6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
30fdf114 LG |
13 | **/\r |
14 | \r | |
15 | #ifndef __TIANO_DECOMPRESS_H__\r | |
16 | #define __TIANO_DECOMPRESS_H__\r | |
17 | \r | |
18 | #include <stdio.h>\r | |
19 | #include <assert.h>\r | |
20 | #include <Common/UefiBaseTypes.h>\r | |
21 | \r | |
22 | \r | |
23 | //\r | |
24 | // Decompression algorithm begins here\r | |
25 | //\r | |
26 | #define UTILITY_NAME "TianoCompress"\r | |
27 | #define UTILITY_MAJOR_VERSION 0\r | |
28 | #define UTILITY_MINOR_VERSION 1\r | |
29 | \r | |
30 | //\r | |
31 | // Default output file name\r | |
32 | //\r | |
33 | #define DEFAULT_OUTPUT_FILE "file.tmp"\r | |
34 | \r | |
35 | #define BITBUFSIZ 32\r | |
36 | #define MAXMATCH 256\r | |
37 | #define THRESHOLD 3\r | |
38 | #define CODE_BIT 16\r | |
39 | #define BAD_TABLE - 1\r | |
40 | \r | |
41 | typedef INT32 NODE;\r | |
42 | \r | |
43 | //\r | |
44 | // C: Char&Len Set; P: Position Set; T: exTra Set\r | |
45 | //\r | |
46 | #define NC (0xff + MAXMATCH + 2 - THRESHOLD)\r | |
47 | #define CBIT 9\r | |
48 | #define MAXPBIT 5\r | |
49 | #define TBIT 5\r | |
50 | #define MAXNP ((1U << MAXPBIT) - 1)\r | |
51 | #define NT (CODE_BIT + 3)\r | |
52 | #if NT > MAXNP\r | |
53 | #define NPT NT\r | |
54 | #else\r | |
55 | #define NPT MAXNP\r | |
56 | #endif\r | |
57 | \r | |
58 | typedef struct {\r | |
59 | UINT8 *mSrcBase; // Starting address of compressed data\r | |
60 | UINT8 *mDstBase; // Starting address of decompressed data\r | |
61 | UINT32 mOutBuf;\r | |
62 | UINT32 mInBuf;\r | |
63 | \r | |
64 | UINT16 mBitCount;\r | |
65 | UINT32 mBitBuf;\r | |
66 | UINT32 mSubBitBuf;\r | |
67 | UINT16 mBlockSize;\r | |
68 | UINT32 mCompSize;\r | |
69 | UINT32 mOrigSize;\r | |
70 | \r | |
71 | UINT16 mBadTableFlag;\r | |
72 | \r | |
73 | UINT16 mLeft[2 * NC - 1];\r | |
74 | UINT16 mRight[2 * NC - 1];\r | |
75 | UINT8 mCLen[NC];\r | |
76 | UINT8 mPTLen[NPT];\r | |
77 | UINT16 mCTable[4096];\r | |
78 | UINT16 mPTTable[256];\r | |
79 | \r | |
80 | //\r | |
81 | // The length of the field 'Position Set Code Length Array Size' in Block Header.\r | |
82 | // For EFI 1.1 de/compression algorithm, mPBit = 4\r | |
83 | // For Tiano de/compression algorithm, mPBit = 5\r | |
84 | //\r | |
85 | UINT8 mPBit;\r | |
86 | } SCRATCH_DATA;\r | |
87 | \r | |
88 | //\r | |
89 | // Function Prototypes\r | |
90 | //\r | |
91 | \r | |
92 | EFI_STATUS\r | |
93 | GetFileContents (\r | |
94 | IN char *InputFileName,\r | |
95 | OUT UINT8 *FileBuffer,\r | |
96 | OUT UINT32 *BufferLength\r | |
97 | );\r | |
98 | \r | |
99 | STATIC\r | |
100 | VOID\r | |
101 | PutDword(\r | |
102 | IN UINT32 Data\r | |
103 | );\r | |
104 | \r | |
105 | STATIC\r | |
106 | EFI_STATUS\r | |
107 | AllocateMemory (\r | |
108 | VOID\r | |
109 | );\r | |
110 | \r | |
111 | STATIC\r | |
112 | VOID\r | |
113 | FreeMemory (\r | |
114 | VOID\r | |
115 | );\r | |
116 | \r | |
117 | STATIC\r | |
118 | VOID\r | |
119 | InitSlide (\r | |
120 | VOID\r | |
121 | );\r | |
122 | \r | |
123 | STATIC\r | |
124 | NODE\r | |
125 | Child (\r | |
126 | IN NODE NodeQ,\r | |
127 | IN UINT8 CharC\r | |
128 | );\r | |
129 | \r | |
130 | STATIC\r | |
131 | VOID\r | |
132 | MakeChild (\r | |
133 | IN NODE NodeQ,\r | |
134 | IN UINT8 CharC,\r | |
135 | IN NODE NodeR\r | |
136 | );\r | |
137 | \r | |
138 | STATIC\r | |
139 | VOID\r | |
140 | Split (\r | |
141 | IN NODE Old\r | |
142 | );\r | |
143 | \r | |
144 | STATIC\r | |
145 | VOID\r | |
146 | InsertNode (\r | |
147 | VOID\r | |
148 | );\r | |
149 | \r | |
150 | STATIC\r | |
151 | VOID\r | |
152 | DeleteNode (\r | |
153 | VOID\r | |
154 | );\r | |
155 | \r | |
156 | STATIC\r | |
157 | VOID\r | |
158 | GetNextMatch (\r | |
159 | VOID\r | |
160 | );\r | |
161 | \r | |
162 | STATIC\r | |
163 | EFI_STATUS\r | |
164 | Encode (\r | |
165 | VOID\r | |
166 | );\r | |
167 | \r | |
168 | STATIC\r | |
169 | VOID\r | |
170 | CountTFreq (\r | |
171 | VOID\r | |
172 | );\r | |
173 | \r | |
174 | STATIC\r | |
175 | VOID\r | |
176 | WritePTLen (\r | |
177 | IN INT32 Number,\r | |
178 | IN INT32 nbit,\r | |
179 | IN INT32 Special\r | |
180 | );\r | |
181 | \r | |
182 | STATIC\r | |
183 | VOID\r | |
184 | WriteCLen (\r | |
185 | VOID\r | |
186 | );\r | |
187 | \r | |
188 | STATIC\r | |
189 | VOID\r | |
190 | EncodeC (\r | |
191 | IN INT32 Value\r | |
192 | );\r | |
193 | \r | |
194 | STATIC\r | |
195 | VOID\r | |
196 | EncodeP (\r | |
197 | IN UINT32 Value\r | |
198 | );\r | |
199 | \r | |
200 | STATIC\r | |
201 | VOID\r | |
202 | SendBlock (\r | |
203 | VOID\r | |
204 | );\r | |
205 | \r | |
206 | STATIC\r | |
207 | VOID\r | |
208 | Output (\r | |
209 | IN UINT32 c,\r | |
210 | IN UINT32 p\r | |
211 | );\r | |
212 | \r | |
213 | STATIC\r | |
214 | VOID\r | |
215 | HufEncodeStart (\r | |
216 | VOID\r | |
217 | );\r | |
218 | \r | |
219 | STATIC\r | |
220 | VOID\r | |
221 | HufEncodeEnd (\r | |
222 | VOID\r | |
223 | );\r | |
224 | \r | |
225 | STATIC\r | |
226 | VOID\r | |
227 | MakeCrcTable (\r | |
228 | VOID\r | |
229 | );\r | |
230 | \r | |
231 | \r | |
232 | STATIC\r | |
233 | VOID\r | |
234 | PutBits (\r | |
235 | IN INT32 Number,\r | |
236 | IN UINT32 Value\r | |
237 | );\r | |
238 | \r | |
239 | STATIC\r | |
240 | INT32\r | |
241 | FreadCrc (\r | |
242 | OUT UINT8 *Pointer,\r | |
243 | IN INT32 Number\r | |
244 | );\r | |
245 | \r | |
246 | STATIC\r | |
247 | VOID\r | |
248 | InitPutBits (\r | |
249 | VOID\r | |
250 | );\r | |
251 | \r | |
252 | STATIC\r | |
253 | VOID\r | |
254 | CountLen (\r | |
255 | IN INT32 Index\r | |
256 | );\r | |
257 | \r | |
258 | STATIC\r | |
259 | VOID\r | |
260 | MakeLen (\r | |
261 | IN INT32 Root\r | |
262 | );\r | |
263 | \r | |
264 | STATIC\r | |
265 | VOID\r | |
266 | DownHeap (\r | |
267 | IN INT32 Index\r | |
268 | );\r | |
269 | \r | |
270 | STATIC\r | |
271 | VOID\r | |
272 | MakeCode (\r | |
273 | IN INT32 Number,\r | |
274 | IN UINT8 Len[ ],\r | |
275 | OUT UINT16 Code[]\r | |
276 | );\r | |
277 | \r | |
278 | STATIC\r | |
279 | INT32\r | |
280 | MakeTree (\r | |
281 | IN INT32 NParm,\r | |
282 | IN UINT16 FreqParm[],\r | |
283 | OUT UINT8 LenParm[ ],\r | |
284 | OUT UINT16 CodeParm[]\r | |
285 | );\r | |
286 | \r | |
287 | /**\r | |
288 | Read NumOfBit of bits from source into mBitBuf\r | |
289 | \r | |
290 | Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r | |
291 | \r | |
292 | @param Sd The global scratch data\r | |
293 | @param NumOfBits The number of bits to shift and read.\r | |
294 | \r | |
295 | **/\r | |
296 | VOID\r | |
297 | FillBuf (\r | |
298 | IN SCRATCH_DATA *Sd,\r | |
299 | IN UINT16 NumOfBits\r | |
300 | );\r | |
301 | \r | |
302 | /**\r | |
303 | Get NumOfBits of bits out from mBitBuf\r | |
304 | \r | |
305 | Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent \r | |
306 | NumOfBits of bits from source. Returns NumOfBits of bits that are \r | |
307 | popped out.\r | |
308 | \r | |
309 | @param Sd The global scratch data.\r | |
310 | @param NumOfBits The number of bits to pop and read.\r | |
311 | \r | |
312 | @return The bits that are popped out.\r | |
313 | \r | |
314 | **/\r | |
315 | UINT32\r | |
316 | GetBits (\r | |
317 | IN SCRATCH_DATA *Sd,\r | |
318 | IN UINT16 NumOfBits\r | |
319 | );\r | |
320 | \r | |
321 | /**\r | |
322 | Creates Huffman Code mapping table according to code length array.\r | |
323 | \r | |
324 | Creates Huffman Code mapping table for Extra Set, Char&Len Set \r | |
325 | and Position Set according to code length array.\r | |
326 | \r | |
327 | @param Sd The global scratch data\r | |
328 | @param NumOfChar Number of symbols in the symbol set\r | |
329 | @param BitLen Code length array\r | |
330 | @param TableBits The width of the mapping table\r | |
331 | @param Table The table\r | |
332 | \r | |
333 | @retval 0 OK.\r | |
334 | @retval BAD_TABLE The table is corrupted.\r | |
335 | \r | |
336 | **/\r | |
337 | UINT16\r | |
338 | MakeTable (\r | |
339 | IN SCRATCH_DATA *Sd,\r | |
340 | IN UINT16 NumOfChar,\r | |
341 | IN UINT8 *BitLen,\r | |
342 | IN UINT16 TableBits,\r | |
343 | OUT UINT16 *Table\r | |
344 | );\r | |
345 | \r | |
346 | /**\r | |
347 | Decodes a position value.\r | |
348 | \r | |
349 | Get a position value according to Position Huffman Table.\r | |
350 | \r | |
351 | @param Sd the global scratch data\r | |
352 | \r | |
353 | @return The position value decoded.\r | |
354 | \r | |
355 | **/\r | |
356 | UINT32\r | |
357 | DecodeP (\r | |
358 | IN SCRATCH_DATA *Sd\r | |
359 | );\r | |
360 | \r | |
361 | /**\r | |
362 | Reads code lengths for the Extra Set or the Position Set.\r | |
363 | \r | |
99e55970 | 364 | Read in the Extra Set or Position Set Length Array, then\r |
30fdf114 LG |
365 | generate the Huffman code mapping for them.\r |
366 | \r | |
367 | @param Sd The global scratch data.\r | |
368 | @param nn Number of symbols.\r | |
369 | @param nbit Number of bits needed to represent nn.\r | |
370 | @param Special The special symbol that needs to be taken care of.\r | |
371 | \r | |
372 | @retval 0 OK.\r | |
373 | @retval BAD_TABLE Table is corrupted.\r | |
374 | \r | |
375 | **/\r | |
376 | UINT16\r | |
377 | ReadPTLen (\r | |
378 | IN SCRATCH_DATA *Sd,\r | |
379 | IN UINT16 nn,\r | |
380 | IN UINT16 nbit,\r | |
381 | IN UINT16 Special\r | |
382 | );\r | |
383 | \r | |
384 | /**\r | |
385 | Reads code lengths for Char&Len Set.\r | |
386 | \r | |
387 | Read in and decode the Char&Len Set Code Length Array, then\r | |
388 | generate the Huffman Code mapping table for the Char&Len Set.\r | |
389 | \r | |
390 | @param Sd the global scratch data\r | |
391 | \r | |
392 | **/\r | |
393 | VOID\r | |
394 | ReadCLen (\r | |
395 | SCRATCH_DATA *Sd\r | |
396 | );\r | |
397 | \r | |
398 | /**\r | |
399 | Decode a character/length value.\r | |
400 | \r | |
401 | Read one value from mBitBuf, Get one code from mBitBuf. If it is at block boundary, generates\r | |
402 | Huffman code mapping table for Extra Set, Code&Len Set and\r | |
403 | Position Set.\r | |
404 | \r | |
405 | @param Sd The global scratch data.\r | |
406 | \r | |
407 | @return The value decoded.\r | |
408 | \r | |
409 | **/\r | |
410 | UINT16\r | |
411 | DecodeC (\r | |
412 | SCRATCH_DATA *Sd\r | |
413 | );\r | |
414 | \r | |
415 | /**\r | |
416 | Decode the source data and put the resulting data into the destination buffer.\r | |
417 | \r | |
418 | Decode the source data and put the resulting data into the destination buffer.\r | |
419 | \r | |
420 | @param Sd The global scratch data\r | |
421 | \r | |
422 | **/\r | |
423 | VOID\r | |
424 | Decode (\r | |
425 | SCRATCH_DATA *Sd\r | |
426 | );\r | |
427 | \r | |
428 | RETURN_STATUS\r | |
429 | EFIAPI\r | |
430 | Decompress (\r | |
431 | IN VOID *Source,\r | |
432 | IN OUT VOID *Destination,\r | |
433 | IN OUT VOID *Scratch,\r | |
434 | IN UINT32 Version\r | |
435 | );\r | |
436 | \r | |
437 | #endif\r |