]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/TianoCompress/TianoCompress.h
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / C / TianoCompress / TianoCompress.h
CommitLineData
30fdf114 1/** @file\r
99e55970 2 Internal include file for Tiano Decompress Library.\r
30fdf114 3\r
f7496d71 4 Copyright (c) 2006 - 2018, 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
41typedef 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
58typedef 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
92EFI_STATUS\r
93GetFileContents (\r
94 IN char *InputFileName,\r
95 OUT UINT8 *FileBuffer,\r
96 OUT UINT32 *BufferLength\r
97 );\r
f7496d71 98\r
30fdf114
LG
99STATIC\r
100VOID\r
101PutDword(\r
102 IN UINT32 Data\r
103 );\r
104\r
105STATIC\r
106EFI_STATUS\r
107AllocateMemory (\r
108 VOID\r
109 );\r
110\r
111STATIC\r
112VOID\r
113FreeMemory (\r
114 VOID\r
115 );\r
116\r
117STATIC\r
118VOID\r
119InitSlide (\r
120 VOID\r
121 );\r
122\r
123STATIC\r
124NODE\r
125Child (\r
126 IN NODE NodeQ,\r
127 IN UINT8 CharC\r
128 );\r
129\r
130STATIC\r
131VOID\r
132MakeChild (\r
133 IN NODE NodeQ,\r
134 IN UINT8 CharC,\r
135 IN NODE NodeR\r
136 );\r
137\r
138STATIC\r
139VOID\r
140Split (\r
141 IN NODE Old\r
142 );\r
143\r
144STATIC\r
145VOID\r
146InsertNode (\r
147 VOID\r
148 );\r
149\r
150STATIC\r
151VOID\r
152DeleteNode (\r
153 VOID\r
154 );\r
155\r
156STATIC\r
157VOID\r
158GetNextMatch (\r
159 VOID\r
160 );\r
161\r
162STATIC\r
163EFI_STATUS\r
164Encode (\r
165 VOID\r
166 );\r
167\r
168STATIC\r
169VOID\r
170CountTFreq (\r
171 VOID\r
172 );\r
173\r
174STATIC\r
175VOID\r
176WritePTLen (\r
177 IN INT32 Number,\r
178 IN INT32 nbit,\r
179 IN INT32 Special\r
180 );\r
181\r
182STATIC\r
183VOID\r
184WriteCLen (\r
185 VOID\r
186 );\r
187\r
188STATIC\r
189VOID\r
190EncodeC (\r
191 IN INT32 Value\r
192 );\r
193\r
194STATIC\r
195VOID\r
196EncodeP (\r
197 IN UINT32 Value\r
198 );\r
199\r
200STATIC\r
201VOID\r
202SendBlock (\r
203 VOID\r
204 );\r
205\r
206STATIC\r
207VOID\r
208Output (\r
209 IN UINT32 c,\r
210 IN UINT32 p\r
211 );\r
212\r
213STATIC\r
214VOID\r
215HufEncodeStart (\r
216 VOID\r
217 );\r
218\r
219STATIC\r
220VOID\r
221HufEncodeEnd (\r
222 VOID\r
223 );\r
224\r
225STATIC\r
226VOID\r
227MakeCrcTable (\r
228 VOID\r
229 );\r
230\r
f7496d71 231\r
30fdf114
LG
232STATIC\r
233VOID\r
234PutBits (\r
235 IN INT32 Number,\r
236 IN UINT32 Value\r
237 );\r
238\r
239STATIC\r
240INT32\r
241FreadCrc (\r
242 OUT UINT8 *Pointer,\r
243 IN INT32 Number\r
244 );\r
245\r
246STATIC\r
247VOID\r
248InitPutBits (\r
249 VOID\r
250 );\r
251\r
252STATIC\r
253VOID\r
254CountLen (\r
255 IN INT32 Index\r
256 );\r
257\r
258STATIC\r
259VOID\r
260MakeLen (\r
261 IN INT32 Root\r
262 );\r
263\r
264STATIC\r
265VOID\r
266DownHeap (\r
267 IN INT32 Index\r
268 );\r
269\r
270STATIC\r
271VOID\r
272MakeCode (\r
273 IN INT32 Number,\r
274 IN UINT8 Len[ ],\r
275 OUT UINT16 Code[]\r
276 );\r
277\r
278STATIC\r
279INT32\r
280MakeTree (\r
281 IN INT32 NParm,\r
282 IN UINT16 FreqParm[],\r
283 OUT UINT8 LenParm[ ],\r
284 OUT UINT16 CodeParm[]\r
285 );\r
f7496d71 286\r
30fdf114
LG
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
296VOID\r
297FillBuf (\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
f7496d71
LG
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
30fdf114
LG
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
315UINT32\r
316GetBits (\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
f7496d71 324 Creates Huffman Code mapping table for Extra Set, Char&Len Set\r
30fdf114
LG
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
337UINT16\r
338MakeTable (\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
f7496d71 350\r
30fdf114
LG
351 @param Sd the global scratch data\r
352\r
353 @return The position value decoded.\r
354\r
355**/\r
356UINT32\r
357DecodeP (\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
376UINT16\r
377ReadPTLen (\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
f7496d71 386\r
30fdf114
LG
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
393VOID\r
394ReadCLen (\r
395 SCRATCH_DATA *Sd\r
396 );\r
397\r
398/**\r
399 Decode a character/length value.\r
f7496d71 400\r
30fdf114
LG
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
410UINT16\r
411DecodeC (\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
f7496d71 419\r
30fdf114
LG
420 @param Sd The global scratch data\r
421\r
422**/\r
423VOID\r
424Decode (\r
425 SCRATCH_DATA *Sd\r
426 );\r
427\r
428RETURN_STATUS\r
429EFIAPI\r
430Decompress (\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