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