]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / Image.c
index 6b6a72002dc2e6b22a71bf7eb0ac987d5c4d91fc..db008a0bde7d223e4b70338dab089cf20034b529 100644 (file)
@@ -1,7 +1,9 @@
 /** @file\r
+Implementation for EFI_HII_IMAGE_PROTOCOL.\r
 \r
-Copyright (c) 2007 - 2008, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+\r
+Copyright (c) 2007 - 2008, 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
@@ -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
@@ -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
@@ -793,9 +795,6 @@ HiiNewImage (
   @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 in the\r
@@ -1156,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
@@ -1169,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
@@ -1197,6 +1196,8 @@ HiiSetImage (
                                  will be allocated to hold  the generated image and\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
@@ -1226,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
@@ -1309,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
@@ -1322,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
@@ -1364,7 +1357,7 @@ HiiDrawImage (
 \r
     }\r
 \r
-    SafeFreePool (BltBuffer);\r
+    FreePool (BltBuffer);\r
     return Status;\r
 \r
   } else {\r
@@ -1382,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
@@ -1395,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
@@ -1442,6 +1435,8 @@ HiiDrawImage (
                                  allocated to hold  the generated image and the\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
@@ -1490,9 +1485,9 @@ HiiDrawImageId (
   // Draw this image.\r
   //\r
   Status = HiiDrawImage (This, Flags, &Image, Blt, BltX, BltY);\r
-  SafeFreePool (Image.Bitmap);\r
+  if (Image.Bitmap != NULL) {\r
+    FreePool (Image.Bitmap);\r
+  }\r
   return Status;\r
 }\r
 \r
-#endif\r
-\r