This sequence is further divided into Blocks and Huffman codings\r
are applied to each Block.\r
\r
- Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
-\r
+#include <Uefi.h>\r
#include <Library/MemoryAllocationLib.h>\r
#include <Library/BaseMemoryLib.h>\r
#include <Library/DebugLib.h>\r
-#include <ShellBase.h>\r
+#include <Library/ShellLib.h>\r
+\r
+#include "Compress.h"\r
\r
//\r
// Macro Definitions\r
@param[in] Data The dword to put.\r
**/\r
VOID\r
-EFIAPI\r
PutDword(\r
IN UINT32 Data\r
);\r
\r
**/\r
VOID\r
-EFIAPI\r
MakeCrcTable (\r
VOID\r
)\r
@param[in] Data The dword to put.\r
**/\r
VOID\r
-EFIAPI\r
PutDword (\r
IN UINT32 Data\r
)\r
\r
/**\r
Allocate memory spaces for data structures used in compression process.\r
- \r
+\r
@retval EFI_SUCCESS Memory was allocated successfully.\r
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
**/\r
EFI_STATUS\r
-EFIAPI\r
AllocateMemory (\r
VOID\r
)\r
\r
**/\r
VOID\r
-EFIAPI\r
FreeMemory (\r
VOID\r
)\r
Initialize String Info Log data structures.\r
**/\r
VOID\r
-EFIAPI\r
InitSlide (\r
VOID\r
)\r
\r
**/\r
NODE\r
-EFIAPI\r
Child (\r
IN NODE LoopVar6,\r
IN UINT8 LoopVar5\r
@param[in] LoopVar4 The child node.\r
**/\r
VOID\r
-EFIAPI\r
MakeChild (\r
IN NODE LoopVar6,\r
IN UINT8 LoopVar5,\r
@param[in] Old The node to split.\r
**/\r
VOID\r
-EFIAPI\r
Split (\r
IN NODE Old\r
)\r
\r
**/\r
VOID\r
-EFIAPI\r
InsertNode (\r
VOID\r
)\r
\r
**/\r
VOID\r
-EFIAPI\r
DeleteNode (\r
VOID\r
)\r
@return The number of bytes actually read.\r
**/\r
INT32\r
-EFIAPI\r
FreadCrc (\r
OUT UINT8 *LoopVar7,\r
IN INT32 LoopVar8\r
Advance the current position (read in new data if needed).\r
Delete outdated string info. Find a match string for current position.\r
\r
+ @retval TRUE The operation was successful.\r
+ @retval FALSE The operation failed due to insufficient memory.\r
**/\r
-VOID\r
-EFIAPI\r
+BOOLEAN\r
GetNextMatch (\r
VOID\r
)\r
mPos++;\r
if (mPos == WNDSIZ * 2) {\r
Temp = AllocateZeroPool (WNDSIZ + MAXMATCH);\r
+ if (Temp == NULL) {\r
+ return (FALSE);\r
+ }\r
CopyMem (Temp, &mText[WNDSIZ], WNDSIZ + MAXMATCH);\r
CopyMem (&mText[0], Temp, WNDSIZ + MAXMATCH);\r
FreePool (Temp);\r
\r
DeleteNode ();\r
InsertNode ();\r
+\r
+ return (TRUE);\r
}\r
\r
/**\r
@param[in] LoopVar1 The index of the item to move.\r
**/\r
VOID\r
-EFIAPI\r
DownHeap (\r
IN INT32 i\r
)\r
@param[in] LoopVar1 The top node.\r
**/\r
VOID\r
-EFIAPI\r
CountLen (\r
IN INT32 LoopVar1\r
)\r
@param[in] Root The root of the tree.\r
**/\r
VOID\r
-EFIAPI\r
MakeLen (\r
IN INT32 Root\r
)\r
\r
/**\r
Assign code to each symbol based on the code length array.\r
- \r
+\r
@param[in] LoopVar8 The number of symbols.\r
@param[in] Len The code length array.\r
@param[out] Code The stores codes for each symbol.\r
**/\r
VOID\r
-EFIAPI\r
MakeCode (\r
IN INT32 LoopVar8,\r
IN UINT8 Len[ ],\r
Code[LoopVar1] = Start[Len[LoopVar1]]++;\r
}\r
}\r
- \r
+\r
/**\r
Generates Huffman codes given a frequency distribution of symbols.\r
\r
@return The root of the Huffman tree.\r
**/\r
INT32\r
-EFIAPI\r
MakeTree (\r
IN INT32 NParm,\r
IN UINT16 FreqParm[ ],\r
@param[in] x The data.\r
**/\r
VOID\r
-EFIAPI\r
PutBits (\r
IN INT32 LoopVar8,\r
IN UINT32 x\r
@param[in] LoopVar5 The number to encode.\r
**/\r
VOID\r
-EFIAPI\r
EncodeC (\r
IN INT32 LoopVar5\r
)\r
@param[in] LoopVar7 The number to encode.\r
**/\r
VOID\r
-EFIAPI\r
EncodeP (\r
IN UINT32 LoopVar7\r
)\r
\r
**/\r
VOID\r
-EFIAPI\r
CountTFreq (\r
VOID\r
)\r
\r
**/\r
VOID\r
-EFIAPI\r
WritePTLen (\r
IN INT32 LoopVar8,\r
IN INT32 nbit,\r
Outputs the code length array for Char&Length Set.\r
**/\r
VOID\r
-EFIAPI\r
WriteCLen (\r
VOID\r
)\r
\r
**/\r
VOID\r
-EFIAPI\r
SendBlock (\r
VOID\r
)\r
\r
**/\r
VOID\r
-EFIAPI\r
HufEncodeStart (\r
VOID\r
)\r
/**\r
Outputs an Original Character or a Pointer.\r
\r
- @param[in] LoopVar5 The original character or the 'String Length' element of \r
+ @param[in] LoopVar5 The original character or the 'String Length' element of\r
a Pointer.\r
@param[in] LoopVar7 The 'Position' field of a Pointer.\r
**/\r
VOID\r
-EFIAPI\r
CompressOutput (\r
IN UINT32 LoopVar5,\r
IN UINT32 LoopVar7\r
\r
**/\r
VOID\r
-EFIAPI\r
HufEncodeEnd (\r
VOID\r
)\r
@retval EFI_OUT_0F_RESOURCES Not enough memory for compression process.\r
**/\r
EFI_STATUS\r
-EFIAPI\r
Encode (\r
VOID\r
)\r
while (mRemainder > 0) {\r
LastMatchLen = mMatchLen;\r
LastMatchPos = mMatchPos;\r
- GetNextMatch ();\r
+ if (!GetNextMatch ()) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ }\r
if (mMatchLen > mRemainder) {\r
mMatchLen = mRemainder;\r
}\r
(mPos - LastMatchPos - 2) & (WNDSIZ - 1));\r
LastMatchLen--;\r
while (LastMatchLen > 0) {\r
- GetNextMatch ();\r
+ if (!GetNextMatch ()) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ }\r
LastMatchLen--;\r
}\r
\r
\r
HufEncodeEnd ();\r
FreeMemory ();\r
- return EFI_SUCCESS;\r
+ return (Status);\r
}\r
\r
/**\r
The compression routine.\r
\r
- @param[in] SrcBuffer The buffer containing the source data.\r
- @param[in] SrcSize The number of bytes in SrcBuffer.\r
- @param[in] DstBuffer The buffer to put the compressed image in.\r
- @param[in,out] DstSize On input the size (in bytes) of DstBuffer, on\r
- return the number of bytes placed in DstBuffer.\r
+ @param[in] SrcBuffer The buffer containing the source data.\r
+ @param[in] SrcSize Number of bytes in SrcBuffer.\r
+ @param[in] DstBuffer The buffer to put the compressed image in.\r
+ @param[in, out] DstSize On input the size (in bytes) of DstBuffer, on\r
+ return the number of bytes placed in DstBuffer.\r
\r
@retval EFI_SUCCESS The compression was sucessful.\r
@retval EFI_BUFFER_TOO_SMALL The buffer was too small. DstSize is required.\r
**/\r
EFI_STATUS\r
-EFIAPI\r
Compress (\r
- IN VOID *SrcBuffer,\r
- IN UINT64 SrcSize,\r
- IN VOID *DstBuffer,\r
- IN OUT UINT64 *DstSize\r
+ IN VOID *SrcBuffer,\r
+ IN UINT64 SrcSize,\r
+ IN VOID *DstBuffer,\r
+ IN OUT UINT64 *DstSize\r
)\r
{\r
EFI_STATUS Status;\r