]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
Roll back changes to apply GetBestLanguage() in HiiDataBase. Exact language match...
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / Image.c
index 06d783a8804cd39e0db0867ae1b4ee1d4d97d858..8c74e8e424d2cf6572d0ffbd2c408157dfeec67c 100644 (file)
@@ -1,6 +1,8 @@
 /** @file\r
+Implementation for EFI_HII_IMAGE_PROTOCOL.\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. 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
@@ -9,46 +11,31 @@ http://opensource.org/licenses/bsd-license.php
 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
 \r
-Module Name:\r
-\r
-    Image.c\r
-\r
-Abstract:\r
+**/\r
 \r
-    Implementation for EFI_HII_IMAGE_PROTOCOL.\r
 \r
-Revision History\r
+#include "HiiDatabase.h"\r
 \r
 \r
-**/\r
+/**\r
+  Get the imageid of last image block: EFI_HII_IIBT_END_BLOCK when input\r
+  ImageId is zero, otherwise return the address of the\r
+  corresponding image block with identifier specified by ImageId.\r
 \r
+  This is a internal function.\r
 \r
-#include "HiiDatabase.h"\r
+  @param ImageBlock      Points to the beginning of a series of image blocks stored in order.\r
+  @param ImageId         If input ImageId is 0, output the image id of the EFI_HII_IIBT_END_BLOCK;\r
+                         else use this id to find its corresponding image block address.\r
 \r
-#ifndef DISABLE_UNUSED_HII_PROTOCOLS\r
+  @return The image block address when input ImageId is not zero; otherwise return NULL.\r
 \r
-STATIC\r
+**/\r
 UINT8*\r
 GetImageIdOrAddress (\r
   IN  UINT8           *ImageBlock,\r
   IN OUT EFI_IMAGE_ID *ImageId\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Get the imageid of last image block: EFI_HII_IIBT_END_BLOCK when input\r
-    ImageId is zero, otherwise return the address of the\r
-    corresponding image block with identifier specified by ImageId.\r
-\r
-  Arguments:\r
-    ImageBlock     - Points to the beginning of a series of image blocks stored in order.\r
-    ImageId        - If input ImageId is 0, output the image id of the EFI_HII_IIBT_END_BLOCK;\r
-                     else use this id to find its corresponding image block address.\r
-\r
-  Returns:\r
-    The image block address when input ImageId is not zero; otherwise return NULL.\r
-\r
---*/\r
 {\r
   EFI_IMAGE_ID                   ImageIdCurrent;\r
   UINT8                          *ImageBlockHdr;\r
@@ -199,13 +186,15 @@ GetImageIdOrAddress (
 /**\r
   Convert pixels from EFI_GRAPHICS_OUTPUT_BLT_PIXEL to EFI_HII_RGB_PIXEL style.\r
 \r
+  This is a internal function.\r
+\r
+\r
   @param  BitMapOut              Pixels in EFI_HII_RGB_PIXEL format.\r
   @param  BitMapIn               Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format.\r
   @param  PixelNum               The number of pixels to be converted.\r
 \r
 \r
 **/\r
-STATIC\r
 VOID\r
 CopyGopToRgbPixel (\r
   OUT EFI_HII_RGB_PIXEL              *BitMapOut,\r
@@ -226,13 +215,15 @@ CopyGopToRgbPixel (
 /**\r
   Convert pixels from EFI_HII_RGB_PIXEL to EFI_GRAPHICS_OUTPUT_BLT_PIXEL style.\r
 \r
+  This is a internal function.\r
+\r
+\r
   @param  BitMapOut              Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format.\r
   @param  BitMapIn               Pixels in EFI_HII_RGB_PIXEL format.\r
   @param  PixelNum               The number of pixels to be converted.\r
 \r
 \r
 **/\r
-STATIC\r
 VOID\r
 CopyRgbToGopPixel (\r
   OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL  *BitMapOut,\r
@@ -253,6 +244,9 @@ CopyRgbToGopPixel (
 /**\r
   Output pixels in "1 bit per pixel" format to an image.\r
 \r
+  This is a internal function.\r
+\r
+\r
   @param  Image                  Points to the image which will store the pixels.\r
   @param  Data                   Stores the value of output pixels, 0 or 1.\r
   @param  PaletteInfo            PaletteInfo which stores the color of the output\r
@@ -261,7 +255,6 @@ CopyRgbToGopPixel (
 \r
 \r
 **/\r
-STATIC\r
 VOID\r
 Output1bitPixel (\r
   IN OUT EFI_IMAGE_INPUT             *Image,\r
@@ -269,8 +262,8 @@ Output1bitPixel (
   IN EFI_HII_IMAGE_PALETTE_INFO      *PaletteInfo\r
   )\r
 {\r
-  UINT16                             X;\r
-  UINT16                             Y;\r
+  UINT16                             Xpos;\r
+  UINT16                             Ypos;\r
   UINTN                              OffsetY;\r
   UINT8                              Index;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      *BitMapPtr;\r
@@ -295,23 +288,23 @@ Output1bitPixel (
   ZeroMem (PaletteValue, sizeof (PaletteValue));\r
   CopyRgbToGopPixel (&PaletteValue[0], &Palette->PaletteValue[0], 1);\r
   CopyRgbToGopPixel (&PaletteValue[1], &Palette->PaletteValue[1], 1);\r
-  SafeFreePool (Palette);\r
+  FreePool (Palette);\r
 \r
   //\r
   // Convert the pixel from one bit to corresponding color.\r
   //\r
-  for (Y = 0; Y < Image->Height; Y++) {\r
-    OffsetY = BITMAP_LEN_1_BIT (Image->Width, Y);\r
+  for (Ypos = 0; Ypos < Image->Height; Ypos++) {\r
+    OffsetY = BITMAP_LEN_1_BIT (Image->Width, Ypos);\r
     //\r
     // All bits in these bytes are meaningful\r
     //\r
-    for (X = 0; X < Image->Width / 8; X++) {\r
-      Byte = *(Data + OffsetY + X);\r
+    for (Xpos = 0; Xpos < Image->Width / 8; Xpos++) {\r
+      Byte = *(Data + OffsetY + Xpos);\r
       for (Index = 0; Index < 8; Index++) {\r
         if ((Byte & (1 << Index)) != 0) {\r
-          BitMapPtr[Y * Image->Width + X * 8 + (8 - Index - 1)] = PaletteValue[1];\r
+          BitMapPtr[Ypos * Image->Width + Xpos * 8 + (8 - Index - 1)] = PaletteValue[1];\r
         } else {\r
-          BitMapPtr[Y * Image->Width + X * 8 + (8 - Index - 1)] = PaletteValue[0];\r
+          BitMapPtr[Ypos * Image->Width + Xpos * 8 + (8 - Index - 1)] = PaletteValue[0];\r
         }\r
       }\r
     }\r
@@ -320,12 +313,12 @@ Output1bitPixel (
       //\r
       // Padding bits in this byte should be ignored.\r
       //\r
-      Byte = *(Data + OffsetY + X);\r
+      Byte = *(Data + OffsetY + Xpos);\r
       for (Index = 0; Index < Image->Width % 8; Index++) {\r
         if ((Byte & (1 << (8 - Index - 1))) != 0) {\r
-          BitMapPtr[Y * Image->Width + X * 8 + Index] = PaletteValue[1];\r
+          BitMapPtr[Ypos * Image->Width + Xpos * 8 + Index] = PaletteValue[1];\r
         } else {\r
-          BitMapPtr[Y * Image->Width + X * 8 + Index] = PaletteValue[0];\r
+          BitMapPtr[Ypos * Image->Width + Xpos * 8 + Index] = PaletteValue[0];\r
         }\r
       }\r
     }\r
@@ -336,15 +329,17 @@ Output1bitPixel (
 /**\r
   Output pixels in "4 bit per pixel" format to an image.\r
 \r
+  This is a internal function.\r
+\r
+\r
   @param  Image                  Points to the image which will store the pixels.\r
   @param  Data                   Stores the value of output pixels, 0 ~ 15.\r
-  @param  PaletteInfo            PaletteInfo which stores the color of the output\r
+  @param[in]  PaletteInfo            PaletteInfo which stores the color of the output\r
                                  pixels. Each entry corresponds to a color within\r
                                  [0, 15].\r
 \r
 \r
 **/\r
-STATIC\r
 VOID\r
 Output4bitPixel (\r
   IN OUT EFI_IMAGE_INPUT             *Image,\r
@@ -352,8 +347,8 @@ Output4bitPixel (
   IN EFI_HII_IMAGE_PALETTE_INFO      *PaletteInfo\r
   )\r
 {\r
-  UINT16                             X;\r
-  UINT16                             Y;\r
+  UINT16                             Xpos;\r
+  UINT16                             Ypos;\r
   UINTN                              OffsetY;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      *BitMapPtr;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      PaletteValue[16];\r
@@ -378,28 +373,28 @@ Output4bitPixel (
 \r
   ZeroMem (PaletteValue, sizeof (PaletteValue));\r
   CopyRgbToGopPixel (PaletteValue, Palette->PaletteValue, PaletteNum);\r
-  SafeFreePool (Palette);\r
+  FreePool (Palette);\r
 \r
   //\r
   // Convert the pixel from 4 bit to corresponding color.\r
   //\r
-  for (Y = 0; Y < Image->Height; Y++) {\r
-    OffsetY = BITMAP_LEN_4_BIT (Image->Width, Y);\r
+  for (Ypos = 0; Ypos < Image->Height; Ypos++) {\r
+    OffsetY = BITMAP_LEN_4_BIT (Image->Width, Ypos);\r
     //\r
     // All bits in these bytes are meaningful\r
     //\r
-    for (X = 0; X < Image->Width / 2; X++) {\r
-      Byte = *(Data + OffsetY + X);\r
-      BitMapPtr[Y * Image->Width + X * 2]     = PaletteValue[Byte >> 4];\r
-      BitMapPtr[Y * Image->Width + X * 2 + 1] = PaletteValue[Byte & 0x0F];\r
+    for (Xpos = 0; Xpos < Image->Width / 2; Xpos++) {\r
+      Byte = *(Data + OffsetY + Xpos);\r
+      BitMapPtr[Ypos * Image->Width + Xpos * 2]     = PaletteValue[Byte >> 4];\r
+      BitMapPtr[Ypos * Image->Width + Xpos * 2 + 1] = PaletteValue[Byte & 0x0F];\r
     }\r
 \r
     if (Image->Width % 2 != 0) {\r
       //\r
       // Padding bits in this byte should be ignored.\r
       //\r
-      Byte = *(Data + OffsetY + X);\r
-      BitMapPtr[Y * Image->Width + X * 2]     = PaletteValue[Byte >> 4];\r
+      Byte = *(Data + OffsetY + Xpos);\r
+      BitMapPtr[Ypos * Image->Width + Xpos * 2]     = PaletteValue[Byte >> 4];\r
     }\r
   }\r
 }\r
@@ -408,15 +403,17 @@ Output4bitPixel (
 /**\r
   Output pixels in "8 bit per pixel" format to an image.\r
 \r
+  This is a internal function.\r
+\r
+\r
   @param  Image                  Points to the image which will store the pixels.\r
   @param  Data                   Stores the value of output pixels, 0 ~ 255.\r
-  @param  PaletteInfo            PaletteInfo which stores the color of the output\r
+  @param[in]  PaletteInfo        PaletteInfo which stores the color of the output\r
                                  pixels. Each entry corresponds to a color within\r
                                  [0, 255].\r
 \r
 \r
 **/\r
-STATIC\r
 VOID\r
 Output8bitPixel (\r
   IN OUT EFI_IMAGE_INPUT             *Image,\r
@@ -424,8 +421,8 @@ Output8bitPixel (
   IN EFI_HII_IMAGE_PALETTE_INFO      *PaletteInfo\r
   )\r
 {\r
-  UINT16                             X;\r
-  UINT16                             Y;\r
+  UINT16                             Xpos;\r
+  UINT16                             Ypos;\r
   UINTN                              OffsetY;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      *BitMapPtr;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      PaletteValue[256];\r
@@ -449,19 +446,19 @@ Output8bitPixel (
   PaletteNum = (UINT16)(Palette->PaletteSize / sizeof (EFI_HII_RGB_PIXEL));\r
   ZeroMem (PaletteValue, sizeof (PaletteValue));\r
   CopyRgbToGopPixel (PaletteValue, Palette->PaletteValue, PaletteNum);\r
-  SafeFreePool (Palette);\r
+  FreePool (Palette);\r
 \r
   //\r
   // Convert the pixel from 8 bits to corresponding color.\r
   //\r
-  for (Y = 0; Y < Image->Height; Y++) {\r
-    OffsetY = BITMAP_LEN_8_BIT (Image->Width, Y);\r
+  for (Ypos = 0; Ypos < Image->Height; Ypos++) {\r
+    OffsetY = BITMAP_LEN_8_BIT (Image->Width, Ypos);\r
     //\r
     // All bits are meaningful since the bitmap is 8 bits per pixel.\r
     //\r
-    for (X = 0; X < Image->Width; X++) {\r
-      Byte = *(Data + OffsetY + X);\r
-      BitMapPtr[OffsetY + X] = PaletteValue[Byte];\r
+    for (Xpos = 0; Xpos < Image->Width; Xpos++) {\r
+      Byte = *(Data + OffsetY + Xpos);\r
+      BitMapPtr[OffsetY + Xpos] = PaletteValue[Byte];\r
     }\r
   }\r
 \r
@@ -471,20 +468,22 @@ Output8bitPixel (
 /**\r
   Output pixels in "24 bit per pixel" format to an image.\r
 \r
+  This is a internal function.\r
+\r
+\r
   @param  Image                  Points to the image which will store the pixels.\r
   @param  Data                   Stores the color of output pixels, allowing 16.8\r
                                  millions colors.\r
 \r
 \r
 **/\r
-STATIC\r
 VOID\r
 Output24bitPixel (\r
   IN OUT EFI_IMAGE_INPUT             *Image,\r
   IN EFI_HII_RGB_PIXEL               *Data\r
   )\r
 {\r
-  UINT16                             Y;\r
+  UINT16                             Ypos;\r
   UINTN                              OffsetY;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      *BitMapPtr;\r
 \r
@@ -492,8 +491,8 @@ Output24bitPixel (
 \r
   BitMapPtr = Image->Bitmap;\r
 \r
-  for (Y = 0; Y < Image->Height; Y++) {\r
-    OffsetY = BITMAP_LEN_8_BIT (Image->Width, Y);\r
+  for (Ypos = 0; Ypos < Image->Height; Ypos++) {\r
+    OffsetY = BITMAP_LEN_8_BIT (Image->Width, Ypos);\r
     CopyRgbToGopPixel (&BitMapPtr[OffsetY], &Data[OffsetY], Image->Width);\r
   }\r
 \r
@@ -503,7 +502,12 @@ Output24bitPixel (
 /**\r
   Convert the image from EFI_IMAGE_INPUT to EFI_IMAGE_OUTPUT format.\r
 \r
+  This is a internal function.\r
+\r
+\r
   @param  BltBuffer              Buffer points to bitmap data of incoming image.\r
+  @param  BltX                   Specifies the offset from the left and top edge of\r
+                                  the output image of the first pixel in the image.\r
   @param  BltY                   Specifies the offset from the left and top edge of\r
                                   the output image of the first pixel in the image.\r
   @param  Width                  Width of the incoming image, in pixels.\r
@@ -517,7 +521,6 @@ Output24bitPixel (
   @retval EFI_INVALID_PARAMETER  Any incoming parameter is invalid.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ImageToBlt (\r
   IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,\r
@@ -530,8 +533,8 @@ ImageToBlt (
   )\r
 {\r
   EFI_IMAGE_OUTPUT                   *ImageOut;\r
-  UINTN                              X;\r
-  UINTN                              Y;\r
+  UINTN                              Xpos;\r
+  UINTN                              Ypos;\r
   UINTN                              OffsetY1; // src buffer\r
   UINTN                              OffsetY2; // dest buffer\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      SrcPixel;\r
@@ -552,17 +555,17 @@ ImageToBlt (
 \r
   ZeroMem (&ZeroPixel, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
 \r
-  for (Y = 0; Y < Height; Y++) {\r
-    OffsetY1 = Width * Y;\r
-    OffsetY2 = ImageOut->Width * (BltY + Y);\r
-    for (X = 0; X < Width; X++) {\r
-      SrcPixel = BltBuffer[OffsetY1 + X];\r
+  for (Ypos = 0; Ypos < Height; Ypos++) {\r
+    OffsetY1 = Width * Ypos;\r
+    OffsetY2 = ImageOut->Width * (BltY + Ypos);\r
+    for (Xpos = 0; Xpos < Width; Xpos++) {\r
+      SrcPixel = BltBuffer[OffsetY1 + Xpos];\r
       if (Transparent) {\r
         if (CompareMem (&SrcPixel, &ZeroPixel, 3) != 0) {\r
-          ImageOut->Image.Bitmap[OffsetY2 + BltX + X] = SrcPixel;\r
+          ImageOut->Image.Bitmap[OffsetY2 + BltX + Xpos] = SrcPixel;\r
         }\r
       } else {\r
-        ImageOut->Image.Bitmap[OffsetY2 + BltX + X] = SrcPixel;\r
+        ImageOut->Image.Bitmap[OffsetY2 + BltX + Xpos] = SrcPixel;\r
       }\r
     }\r
   }\r
@@ -610,7 +613,7 @@ HiiNewImage (
   UINTN                               NewBlockSize;\r
   EFI_IMAGE_INPUT                     *ImageIn;\r
 \r
-  if (This == NULL || ImageId == NULL || Image == NULL || PackageList == NULL) {\r
+  if (This == NULL || ImageId == NULL || Image == NULL || Image->Bitmap == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -676,7 +679,7 @@ HiiNewImage (
       ImagePackage->ImageBlock,\r
       ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK)\r
       );\r
-    SafeFreePool (ImagePackage->ImageBlock);\r
+    FreePool (ImagePackage->ImageBlock);\r
     ImagePackage->ImageBlock = ImageBlock;\r
     ImageBlock += ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK);\r
     //\r
@@ -684,8 +687,7 @@ HiiNewImage (
     //\r
     NewBlock = AllocateZeroPool (NewBlockSize);\r
     if (NewBlock == NULL) {\r
-      SafeFreePool (ImagePackage->ImageBlock);\r
-      ImagePackage->ImageBlock = NULL;\r
+      FreePool (ImagePackage->ImageBlock);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
     NewBlockPtr = NewBlock;\r
@@ -732,7 +734,7 @@ HiiNewImage (
     ImagePackage->ImageBlockSize = (UINT32) BlockSize;\r
     ImagePackage->ImageBlock = (UINT8 *) AllocateZeroPool (BlockSize);\r
     if (ImagePackage->ImageBlock == NULL) {\r
-      SafeFreePool (ImagePackage);\r
+      FreePool (ImagePackage);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
     ImageBlock = ImagePackage->ImageBlock;\r
@@ -742,8 +744,8 @@ HiiNewImage (
     //\r
     NewBlock = AllocateZeroPool (NewBlockSize);\r
     if (NewBlock == NULL) {\r
-      SafeFreePool (ImagePackage->ImageBlock);\r
-      SafeFreePool (ImagePackage);\r
+      FreePool (ImagePackage->ImageBlock);\r
+      FreePool (ImagePackage);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
     NewBlockPtr = NewBlock;\r
@@ -771,7 +773,7 @@ HiiNewImage (
   CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL *) NewBlock, ImageIn->Bitmap, ImageIn->Width * ImageIn->Height);\r
 \r
   CopyMem (ImageBlock, NewBlockPtr, NewBlockSize);\r
-  SafeFreePool (NewBlockPtr);\r
+  FreePool (NewBlockPtr);\r
 \r
   //\r
   // Append the block end\r
@@ -790,18 +792,18 @@ HiiNewImage (
   @param  This                   A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r
   @param  PackageList            Handle of the package list where this image will\r
                                  be searched.\r
-  @param  ImageId                The image¡¯s id,, which is unique within\r
+  @param  ImageId                The image's id,, which is unique within\r
                                  PackageList.\r
   @param  Image                  Points to the image.\r
-  @param  ImageSize              On entry, points to the size of the buffer pointed\r
-                                 to by Image, in bytes.  On return, points to the\r
-                                 length of the image, in bytes.\r
 \r
   @retval EFI_SUCCESS            The new image was returned successfully.\r
-  @retval EFI_NOT_FOUND          The image specified by ImageId is not available.\r
+  @retval EFI_NOT_FOUND           The image specified by ImageId is not in the\r
+                                                database. The specified PackageList is not in the database.\r
   @retval EFI_BUFFER_TOO_SMALL   The buffer specified by ImageSize is too small to\r
                                  hold the image.\r
   @retval EFI_INVALID_PARAMETER  The Image or ImageSize was NULL.\r
+  @retval EFI_OUT_OF_RESOURCES   The bitmap could not be retrieved because there was not\r
+                                                     enough memory.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -810,8 +812,7 @@ HiiGetImage (
   IN  CONST EFI_HII_IMAGE_PROTOCOL   *This,\r
   IN  EFI_HII_HANDLE                 PackageList,\r
   IN  EFI_IMAGE_ID                   ImageId,\r
-  OUT EFI_IMAGE_INPUT                *Image,\r
-  OUT UINTN                          *ImageSize\r
+  OUT EFI_IMAGE_INPUT                *Image\r
   )\r
 {\r
   HII_DATABASE_PRIVATE_DATA           *Private;\r
@@ -831,7 +832,7 @@ HiiGetImage (
   UINT8                               PaletteIndex;\r
   UINT16                              PaletteSize;\r
 \r
-  if (This == NULL || ImageSize == NULL || Image == NULL || ImageId < 1 || PackageList == NULL) {\r
+  if (This == NULL || Image == NULL || ImageId < 1) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -897,13 +898,12 @@ HiiGetImage (
     // Use the common block code since the definition of these structures is the same.\r
     //\r
     CopyMem (&Iibt1bit, ImageBlock, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK));\r
-    ImageLength = sizeof (EFI_IMAGE_INPUT) + sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) *\r
-                  (Iibt1bit.Bitmap.Width * Iibt1bit.Bitmap.Height - 1);\r
-    if (*ImageSize < ImageLength) {\r
-      *ImageSize = ImageLength;\r
-      return EFI_BUFFER_TOO_SMALL;\r
+    ImageLength = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) *\r
+                  (Iibt1bit.Bitmap.Width * Iibt1bit.Bitmap.Height);\r
+    Image->Bitmap = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (ImageLength);\r
+    if (Image->Bitmap == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
     }\r
-    ZeroMem (Image, ImageLength);\r
 \r
     if (Flag) {\r
       Image->Flags = EFI_IMAGE_TRANSPARENT;\r
@@ -956,13 +956,11 @@ HiiGetImage (
       ImageBlock + sizeof (EFI_HII_IMAGE_BLOCK) + sizeof (UINT16),\r
       sizeof (UINT16)\r
       );\r
-    ImageLength = sizeof (EFI_IMAGE_INPUT) +\r
-                  sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * (Width * Height - 1);\r
-    if (*ImageSize < ImageLength) {\r
-      *ImageSize = ImageLength;\r
-      return EFI_BUFFER_TOO_SMALL;\r
+    ImageLength = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * (Width * Height);\r
+    Image->Bitmap = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (ImageLength);\r
+    if (Image->Bitmap == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
     }\r
-    ZeroMem (Image, ImageLength);\r
 \r
     if (Flag) {\r
       Image->Flags = EFI_IMAGE_TRANSPARENT;\r
@@ -993,13 +991,13 @@ HiiGetImage (
 \r
   @param  This                   A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r
   @param  PackageList            The package list containing the images.\r
-  @param  ImageId                The image¡¯s id,, which is unique within\r
+  @param  ImageId                The image's id,, which is unique within\r
                                  PackageList.\r
   @param  Image                  Points to the image.\r
 \r
   @retval EFI_SUCCESS            The new image was updated successfully.\r
   @retval EFI_NOT_FOUND          The image specified by ImageId is not in the\r
-                                 database.\r
+                                                database. The specified PackageList is not in the database.    \r
   @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
 \r
 **/\r
@@ -1036,7 +1034,7 @@ HiiSetImage (
   UINT32                               Part1Size;\r
   UINT32                               Part2Size;\r
 \r
-  if (This == NULL || Image == NULL || ImageId < 1 || PackageList == NULL) {\r
+  if (This == NULL || Image == NULL || ImageId < 1 || Image->Bitmap == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -1157,7 +1155,7 @@ HiiSetImage (
   BlockSize = ImagePackage->ImageBlockSize + NewBlockSize - OldBlockSize;\r
   Block = (UINT8 *) AllocateZeroPool (BlockSize);\r
   if (Block == NULL) {\r
-    SafeFreePool (NewBlock);\r
+    FreePool (NewBlock);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
@@ -1170,8 +1168,8 @@ HiiSetImage (
   BlockPtr += NewBlockSize;\r
   CopyMem (BlockPtr, ImageBlock + OldBlockSize, Part2Size);\r
 \r
-  SafeFreePool (ImagePackage->ImageBlock);\r
-  SafeFreePool (NewBlock);\r
+  FreePool (ImagePackage->ImageBlock);\r
+  FreePool (NewBlock);\r
   ImagePackage->ImageBlock     = Block;\r
   ImagePackage->ImageBlockSize = BlockSize;\r
   ImagePackage->ImagePkgHdr.Header.Length += NewBlockSize - OldBlockSize;\r
@@ -1196,8 +1194,10 @@ HiiSetImage (
                                  this image and  EFI_HII_DRAW_FLAG_CLIP is implied.\r
                                  If this points to a  NULL on entry, then a buffer\r
                                  will be allocated to hold  the generated image and\r
-                                 the pointer updated on exit. It is the caller¡¯s\r
+                                 the pointer updated on exit. It is the caller's\r
                                  responsibility to free this buffer.\r
+  @param  BltX                   Specifies the offset from the left and top edge of\r
+                                 the  output image of the first pixel in the image.\r
   @param  BltY                   Specifies the offset from the left and top edge of\r
                                  the  output image of the first pixel in the image.\r
 \r
@@ -1227,13 +1227,12 @@ HiiDrawImage (
   UINTN                               BufferLen;\r
   UINTN                               Width;\r
   UINTN                               Height;\r
-  UINTN                               X;\r
-  UINTN                               Y;\r
+  UINTN                               Xpos;\r
+  UINTN                               Ypos;\r
   UINTN                               OffsetY1;\r
   UINTN                               OffsetY2;\r
   EFI_FONT_DISPLAY_INFO               *FontInfo;\r
   UINTN                               Index;\r
-  EFI_CONSOLE_CONTROL_PROTOCOL        *Console;\r
 \r
   if (This == NULL || Image == NULL || Blt == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1310,11 +1309,11 @@ HiiDrawImage (
     if (Width == ImageIn->Width && Height == ImageIn->Height) {\r
       CopyMem (BltBuffer, ImageIn->Bitmap, BufferLen);\r
     } else {\r
-      for (Y = 0; Y < Height; Y++) {\r
-        OffsetY1 = ImageIn->Width * Y;\r
-        OffsetY2 = Width * Y;\r
-        for (X = 0; X < Width; X++) {\r
-          BltBuffer[OffsetY2 + X] = ImageIn->Bitmap[OffsetY1 + X];\r
+      for (Ypos = 0; Ypos < Height; Ypos++) {\r
+        OffsetY1 = ImageIn->Width * Ypos;\r
+        OffsetY2 = Width * Ypos;\r
+        for (Xpos = 0; Xpos < Width; Xpos++) {\r
+          BltBuffer[OffsetY2 + Xpos] = ImageIn->Bitmap[OffsetY1 + Xpos];\r
         }\r
       }\r
     }\r
@@ -1323,17 +1322,10 @@ HiiDrawImage (
     // Draw the image to existing bitmap or screen depending on flag.\r
     //\r
     if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {\r
-      Status = gBS->LocateProtocol (\r
-                      &gEfiConsoleControlProtocolGuid,\r
-                      NULL,\r
-                      (VOID **) &Console\r
-                      );\r
-\r
-      if (EFI_ERROR (Status)) {\r
-        return Status;\r
-      }\r
+      //\r
+      // Caller should make sure the current UGA console is grarphic mode.\r
+      //\r
 \r
-      Console->SetMode (Console, EfiConsoleControlScreenGraphics);\r
       //\r
       // Write the image directly to the output device specified by Screen.\r
       //\r
@@ -1365,7 +1357,7 @@ HiiDrawImage (
 \r
     }\r
 \r
-    SafeFreePool (BltBuffer);\r
+    FreePool (BltBuffer);\r
     return Status;\r
 \r
   } else {\r
@@ -1383,7 +1375,7 @@ HiiDrawImage (
 \r
     ImageOut = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r
     if (ImageOut == NULL) {\r
-      SafeFreePool (BltBuffer);\r
+      FreePool (BltBuffer);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
     ImageOut->Width        = (UINT16) Width;\r
@@ -1396,14 +1388,14 @@ HiiDrawImage (
     //\r
     Status = GetSystemFont (Private, &FontInfo, NULL);\r
     if (EFI_ERROR (Status)) {\r
-      SafeFreePool (BltBuffer);\r
-      SafeFreePool (ImageOut);\r
+      FreePool (BltBuffer);\r
+      FreePool (ImageOut);\r
       return Status;\r
     }\r
     for (Index = 0; Index < Width * Height; Index++) {\r
       BltBuffer[Index] = FontInfo->BackgroundColor;\r
     }\r
-    SafeFreePool (FontInfo);\r
+    FreePool (FontInfo);\r
 \r
     //\r
     // Draw the incoming image to the new created image.\r
@@ -1441,16 +1433,18 @@ HiiDrawImage (
                                  EFI_HII_DRAW_FLAG_CLIP is implied. If this points\r
                                  to a  NULL on entry, then a buffer will be\r
                                  allocated to hold  the generated image and the\r
-                                 pointer updated on exit. It is the caller¡¯s\r
+                                 pointer updated on exit. It is the caller's\r
                                  responsibility to free this buffer.\r
+  @param  BltX                   Specifies the offset from the left and top edge of\r
+                                 the  output image of the first pixel in the image.\r
   @param  BltY                   Specifies the offset from the left and top edge of\r
                                  the  output image of the first pixel in the image.\r
 \r
   @retval EFI_SUCCESS            The image was successfully drawn.\r
   @retval EFI_OUT_OF_RESOURCES   Unable to allocate an output buffer for Blt.\r
-  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
-  @retval EFI_NOT_FOUND          The specified packagelist could not be found in\r
-                                 current database.\r
+  @retval EFI_INVALID_PARAMETER  The Blt was NULL.\r
+  @retval EFI_NOT_FOUND          The image specified by ImageId is not in the database. \r
+                           The specified PackageList is not in the database.                             \r
 \r
 **/\r
 EFI_STATUS\r
@@ -1466,14 +1460,12 @@ HiiDrawImageId (
   )\r
 {\r
   EFI_STATUS                          Status;\r
-  EFI_IMAGE_INPUT                     ImageTemp;\r
-  EFI_IMAGE_INPUT                     *Image;\r
-  UINTN                               ImageSize;\r
+  EFI_IMAGE_INPUT                     Image;\r
 \r
   //\r
   // Check input parameter.\r
   //\r
-  if (This == NULL || PackageList == NULL || Blt == NULL || PackageList == NULL) {\r
+  if (This == NULL || Blt == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -1484,26 +1476,18 @@ HiiDrawImageId (
   //\r
   // Get the specified Image.\r
   //\r
-  ImageSize = 0;\r
-  Status = HiiGetImage (This, PackageList, ImageId, &ImageTemp, &ImageSize);\r
-  if (Status != EFI_BUFFER_TOO_SMALL) {\r
+  Status = HiiGetImage (This, PackageList, ImageId, &Image);\r
+  if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  Image = (EFI_IMAGE_INPUT *) AllocateZeroPool (ImageSize);\r
-  if (Image == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  Status = HiiGetImage (This, PackageList, ImageId, Image, &ImageSize);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   //\r
   // Draw this image.\r
   //\r
-  Status = HiiDrawImage (This, Flags, Image, Blt, BltX, BltY);\r
-  SafeFreePool (Image);\r
+  Status = HiiDrawImage (This, Flags, &Image, Blt, BltX, BltY);\r
+  if (Image.Bitmap != NULL) {\r
+    FreePool (Image.Bitmap);\r
+  }\r
   return Status;\r
 }\r
 \r
-#endif\r
-\r