TianoCore EDK2 master
|
#include <Uefi.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/ShellLib.h>
#include "Compress.h"
Go to the source code of this file.
Macros | |
#define | UINT8_MAX 0xff |
#define | UINT8_BIT 8 |
#define | THRESHOLD 3 |
#define | INIT_CRC 0 |
#define | WNDBIT 13 |
#define | WNDSIZ (1U << WNDBIT) |
#define | MAXMATCH 256 |
#define | BLKSIZ (1U << 14) |
#define | PERC_FLAG 0x8000U |
#define | CODE_BIT 16 |
#define | NIL 0 |
#define | MAX_HASH_VAL (3 * WNDSIZ + (WNDSIZ / 512 + 1) * UINT8_MAX) |
#define | HASH(LoopVar7, LoopVar5) ((LoopVar7) + ((LoopVar5) << (WNDBIT - 9)) + WNDSIZ * 2) |
#define | CRCPOLY 0xA001 |
#define | UPDATE_CRC(LoopVar5) mCrc = mCrcTable[(mCrc ^ (LoopVar5)) & 0xFF] ^ (mCrc >> UINT8_BIT) |
#define | NC (UINT8_MAX + MAXMATCH + 2 - THRESHOLD) |
#define | CBIT 9 |
#define | NP (WNDBIT + 1) |
#define | PBIT 4 |
#define | NT (CODE_BIT + 3) |
#define | TBIT 5 |
#define | NPT NT |
Typedefs | |
typedef INT16 | NODE |
Functions | |
VOID | PutDword (IN UINT32 Data) |
VOID | MakeCrcTable (VOID) |
EFI_STATUS | AllocateMemory (VOID) |
VOID | FreeMemory (VOID) |
VOID | InitSlide (VOID) |
NODE | Child (IN NODE LoopVar6, IN UINT8 LoopVar5) |
VOID | MakeChild (IN NODE LoopVar6, IN UINT8 LoopVar5, IN NODE LoopVar4) |
VOID | Split (IN NODE Old) |
VOID | InsertNode (VOID) |
VOID | DeleteNode (VOID) |
INT32 | FreadCrc (OUT UINT8 *LoopVar7, IN INT32 LoopVar8) |
BOOLEAN | GetNextMatch (VOID) |
VOID | DownHeap (IN INT32 i) |
VOID | CountLen (IN INT32 LoopVar1) |
VOID | MakeLen (IN INT32 Root) |
VOID | MakeCode (IN INT32 LoopVar8, IN UINT8 Len[], OUT UINT16 Code[]) |
INT32 | MakeTree (IN INT32 NParm, IN UINT16 FreqParm[], OUT UINT8 LenParm[], OUT UINT16 CodeParm[]) |
VOID | PutBits (IN INT32 LoopVar8, IN UINT32 x) |
VOID | EncodeC (IN INT32 LoopVar5) |
VOID | EncodeP (IN UINT32 LoopVar7) |
VOID | CountTFreq (VOID) |
VOID | WritePTLen (IN INT32 LoopVar8, IN INT32 nbit, IN INT32 Special) |
VOID | WriteCLen (VOID) |
VOID | SendBlock (VOID) |
VOID | HufEncodeStart (VOID) |
VOID | CompressOutput (IN UINT32 LoopVar5, IN UINT32 LoopVar7) |
VOID | HufEncodeEnd (VOID) |
EFI_STATUS | Encode (VOID) |
EFI_STATUS | Compress (IN VOID *SrcBuffer, IN UINT64 SrcSize, IN VOID *DstBuffer, IN OUT UINT64 *DstSize) |
Main file for compression routine.
Compression routine. The compression algorithm is a mixture of LZ77 and Huffman coding. LZ77 transforms the source data into a sequence of Original Characters and Pointers to repeated strings. This sequence is further divided into Blocks and Huffman codings are applied to each Block.
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file Compress.c.
#define BLKSIZ (1U << 14) |
Definition at line 33 of file Compress.c.
#define CBIT 9 |
Definition at line 46 of file Compress.c.
#define CODE_BIT 16 |
Definition at line 35 of file Compress.c.
#define CRCPOLY 0xA001 |
Definition at line 39 of file Compress.c.
#define HASH | ( | LoopVar7, | |
LoopVar5 | |||
) | ((LoopVar7) + ((LoopVar5) << (WNDBIT - 9)) + WNDSIZ * 2) |
Definition at line 38 of file Compress.c.
#define INIT_CRC 0 |
Definition at line 29 of file Compress.c.
#define MAX_HASH_VAL (3 * WNDSIZ + (WNDSIZ / 512 + 1) * UINT8_MAX) |
Definition at line 37 of file Compress.c.
#define MAXMATCH 256 |
Definition at line 32 of file Compress.c.
#define NC (UINT8_MAX + MAXMATCH + 2 - THRESHOLD) |
Definition at line 45 of file Compress.c.
#define NIL 0 |
Definition at line 36 of file Compress.c.
#define NP (WNDBIT + 1) |
Definition at line 47 of file Compress.c.
#define NPT NT |
Definition at line 52 of file Compress.c.
#define NT (CODE_BIT + 3) |
Definition at line 49 of file Compress.c.
#define PBIT 4 |
Definition at line 48 of file Compress.c.
#define PERC_FLAG 0x8000U |
Definition at line 34 of file Compress.c.
#define TBIT 5 |
Definition at line 50 of file Compress.c.
#define THRESHOLD 3 |
Definition at line 28 of file Compress.c.
#define UINT8_BIT 8 |
Definition at line 27 of file Compress.c.
#define UINT8_MAX 0xff |
Definition at line 26 of file Compress.c.
#define UPDATE_CRC | ( | LoopVar5 | ) | mCrc = mCrcTable[(mCrc ^ (LoopVar5)) & 0xFF] ^ (mCrc >> UINT8_BIT) |
Definition at line 40 of file Compress.c.
#define WNDBIT 13 |
Definition at line 30 of file Compress.c.
#define WNDSIZ (1U << WNDBIT) |
Definition at line 31 of file Compress.c.
typedef INT16 NODE |
Definition at line 25 of file Compress.c.
EFI_STATUS AllocateMemory | ( | VOID | ) |
Allocate memory spaces for data structures used in compression process.
EFI_SUCCESS | Memory was allocated successfully. |
EFI_OUT_OF_RESOURCES | A memory allocation failed. |
Definition at line 183 of file Compress.c.
Find child node given the parent node and the edge character
[in] | LoopVar6 | The parent node. |
[in] | LoopVar5 | The edge character. |
NIL(Zero) | No child could be found. |
Definition at line 265 of file Compress.c.
EFI_STATUS Compress | ( | IN VOID * | SrcBuffer, |
IN UINT64 | SrcSize, | ||
IN VOID * | DstBuffer, | ||
IN OUT UINT64 * | DstSize | ||
) |
The compression routine.
[in] | SrcBuffer | The buffer containing the source data. |
[in] | SrcSize | Number of bytes in SrcBuffer. |
[in] | DstBuffer | The buffer to put the compressed image in. |
[in,out] | DstSize | On input the size (in bytes) of DstBuffer, on return the number of bytes placed in DstBuffer. |
EFI_SUCCESS | The compression was successful. |
EFI_BUFFER_TOO_SMALL | The buffer was too small. DstSize is required. |
Definition at line 1324 of file Compress.c.
Outputs an Original Character or a Pointer.
[in] | LoopVar5 | The original character or the 'String Length' element of a Pointer. |
[in] | LoopVar7 | The 'Position' field of a Pointer. |
Definition at line 1180 of file Compress.c.
VOID CountLen | ( | IN INT32 | LoopVar1 | ) |
Count the number of each code length for a Huffman tree.
[in] | LoopVar1 | The top node. |
Definition at line 669 of file Compress.c.
VOID CountTFreq | ( | VOID | ) |
Count the frequencies for the Extra Set.
Definition at line 934 of file Compress.c.
VOID DeleteNode | ( | VOID | ) |
Delete outdated string info. (The Usage of PERC_FLAG ensures a clean deletion).
Definition at line 472 of file Compress.c.
VOID DownHeap | ( | IN INT32 | i | ) |
Send entry LoopVar1 down the queue.
[in] | LoopVar1 | The index of the item to move. |
Definition at line 633 of file Compress.c.
EFI_STATUS Encode | ( | VOID | ) |
The main controlling routine for compression process.
EFI_SUCCESS | The compression is successful. |
EFI_OUT_0F_RESOURCES | Not enough memory for compression process. |
Definition at line 1238 of file Compress.c.
VOID EncodeC | ( | IN INT32 | LoopVar5 | ) |
Encode a signed 32 bit number.
[in] | LoopVar5 | The number to encode. |
Definition at line 895 of file Compress.c.
VOID EncodeP | ( | IN UINT32 | LoopVar7 | ) |
Encode a unsigned 32 bit number.
[in] | LoopVar7 | The number to encode. |
Definition at line 908 of file Compress.c.
Read in source data
[out] | LoopVar7 | The buffer to hold the data. |
[in] | LoopVar8 | The number of bytes to read. |
Definition at line 566 of file Compress.c.
VOID FreeMemory | ( | VOID | ) |
Called when compression is completed to free memory previously allocated.
Definition at line 216 of file Compress.c.
BOOLEAN GetNextMatch | ( | VOID | ) |
Advance the current position (read in new data if needed). Delete outdated string info. Find a match string for current position.
TRUE | The operation was successful. |
FALSE | The operation failed due to insufficient memory. |
Definition at line 598 of file Compress.c.
VOID HufEncodeEnd | ( | VOID | ) |
End the huffman encoding.
Definition at line 1219 of file Compress.c.
VOID HufEncodeStart | ( | VOID | ) |
Start the huffman encoding.
Definition at line 1159 of file Compress.c.
VOID InitSlide | ( | VOID | ) |
Initialize String Info Log data structures.
Definition at line 234 of file Compress.c.
VOID InsertNode | ( | VOID | ) |
Insert string info for current position into the String Info Log.
Definition at line 344 of file Compress.c.
Create a new child for a given parent node.
[in] | LoopVar6 | The parent node. |
[in] | LoopVar5 | The edge character. |
[in] | LoopVar4 | The child node. |
Definition at line 289 of file Compress.c.
Assign code to each symbol based on the code length array.
[in] | LoopVar8 | The number of symbols. |
[in] | Len | The code length array. |
[out] | Code | The stores codes for each symbol. |
Definition at line 744 of file Compress.c.
VOID MakeCrcTable | ( | VOID | ) |
Make a CRC table.
Definition at line 125 of file Compress.c.
VOID MakeLen | ( | IN INT32 | Root | ) |
Create code length array for a Huffman tree.
[in] | Root | The root of the tree. |
Definition at line 689 of file Compress.c.
Generates Huffman codes given a frequency distribution of symbols.
[in] | NParm | The number of symbols. |
[in] | FreqParm | The frequency of each symbol. |
[out] | LenParm | The code length for each symbol. |
[out] | CodeParm | The code for each symbol. |
Definition at line 774 of file Compress.c.
Outputs rightmost LoopVar8 bits of x
[in] | LoopVar8 | The rightmost LoopVar8 bits of the data is used. |
[in] | x | The data. |
Definition at line 857 of file Compress.c.
VOID PutDword | ( | IN UINT32 | Data | ) |
Put a dword to output stream
[in] | Data | The dword to put. |
Definition at line 155 of file Compress.c.
VOID SendBlock | ( | VOID | ) |
Huffman code the block and output it.
Definition at line 1084 of file Compress.c.
VOID Split | ( | IN NODE | Old | ) |
VOID WriteCLen | ( | VOID | ) |
Outputs the code length array for Char&Length Set.
Definition at line 1029 of file Compress.c.
Outputs the code length array for the Extra Set or the Position Set.
[in] | LoopVar8 | The number of symbols. |
[in] | nbit | The number of bits needed to represent 'LoopVar8'. |
[in] | Special | The special symbol that needs to be take care of. |
Definition at line 991 of file Compress.c.
STATIC NODE mAvail |
Definition at line 113 of file Compress.c.
STATIC INT32 mBitCount |
Definition at line 88 of file Compress.c.
STATIC UINT8* mBuf |
Definition at line 81 of file Compress.c.
STATIC UINT32 mBufSiz = 0 |
Definition at line 91 of file Compress.c.
STATIC UINT16 mCCode[NC] |
Definition at line 106 of file Compress.c.
STATIC UINT16 mCFreq[2 *NC - 1] |
Definition at line 105 of file Compress.c.
STATIC UINT8* mChildCount |
Definition at line 80 of file Compress.c.
STATIC UINT8 mCLen[NC] |
Definition at line 82 of file Compress.c.
STATIC UINT32 mCompSize |
Definition at line 96 of file Compress.c.
STATIC UINT32 mCrc |
Definition at line 95 of file Compress.c.
STATIC UINT16 mCrcTable[UINT8_MAX+1] |
Definition at line 104 of file Compress.c.
STATIC UINT8* mDst |
Definition at line 74 of file Compress.c.
STATIC UINT8* mDstUpperLimit |
Definition at line 76 of file Compress.c.
STATIC UINT16* mFreq |
Definition at line 99 of file Compress.c.
STATIC INT16 mHeap[NC+1] |
Definition at line 85 of file Compress.c.
STATIC INT32 mHeapSize |
Definition at line 89 of file Compress.c.
INT32 mHuffmanDepth = 0 |
Definition at line 118 of file Compress.c.
STATIC UINT16 mLeft[2 *NC - 1] |
Definition at line 102 of file Compress.c.
STATIC UINT8* mLen |
Definition at line 84 of file Compress.c.
STATIC UINT16 mLenCnt[17] |
Definition at line 101 of file Compress.c.
STATIC UINT8* mLevel |
Definition at line 78 of file Compress.c.
STATIC INT32 mMatchLen |
Definition at line 87 of file Compress.c.
STATIC NODE mMatchPos |
Definition at line 112 of file Compress.c.
Definition at line 117 of file Compress.c.
STATIC UINT32 mOrigSize |
Definition at line 97 of file Compress.c.
STATIC UINT32 mOutputMask |
Definition at line 93 of file Compress.c.
STATIC UINT32 mOutputPos |
Definition at line 92 of file Compress.c.
STATIC NODE* mParent |
Definition at line 115 of file Compress.c.
STATIC UINT16 mPFreq[2 *NP - 1] |
Definition at line 107 of file Compress.c.
STATIC NODE mPos |
Definition at line 111 of file Compress.c.
STATIC NODE* mPosition |
Definition at line 114 of file Compress.c.
STATIC NODE* mPrev |
Definition at line 116 of file Compress.c.
STATIC UINT16 mPTCode[NPT] |
Definition at line 108 of file Compress.c.
STATIC UINT8 mPTLen[NPT] |
Definition at line 83 of file Compress.c.
STATIC INT32 mRemainder |
Definition at line 86 of file Compress.c.
STATIC UINT16 mRight[2 *NC - 1] |
Definition at line 103 of file Compress.c.
STATIC UINT16* mSortPtr |
Definition at line 100 of file Compress.c.
STATIC UINT8* mSrc |
Definition at line 73 of file Compress.c.
STATIC UINT8* mSrcUpperLimit |
Definition at line 75 of file Compress.c.
STATIC UINT32 mSubBitBuf |
Definition at line 94 of file Compress.c.
STATIC INT32 mTempInt32 |
Definition at line 90 of file Compress.c.
STATIC UINT8* mText |
Definition at line 79 of file Compress.c.
STATIC UINT16 mTFreq[2 *NT - 1] |
Definition at line 109 of file Compress.c.