public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>,
	Eric Dong <eric.dong@intel.com>, Dandan Bi <dandan.bi@intel.com>
Subject: [PATCH 04/13] MdeModulePkg/HiiDatabase: Refine HiiGetImage()
Date: Fri, 23 Sep 2016 16:25:12 +0800	[thread overview]
Message-ID: <20160923082521.99872-5-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20160923082521.99872-1-ruiyu.ni@intel.com>

Contributed-under: TianoCore Contribution Agreement 1.0
Cc: Liming Gao <liming.gao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
---
 MdeModulePkg/Universal/HiiDatabaseDxe/Image.c | 55 ++++++++++-----------------
 1 file changed, 20 insertions(+), 35 deletions(-)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
index 9175ec9..9b7e3af 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
@@ -805,19 +805,16 @@ HiiGetImage (
   HII_DATABASE_PRIVATE_DATA           *Private;
   HII_DATABASE_PACKAGE_LIST_INSTANCE  *PackageListNode;
   HII_IMAGE_PACKAGE_INSTANCE          *ImagePackage;
-  UINT8                               *ImageBlock;
-  EFI_IMAGE_ID                        LocalImageId;
-  UINT8                               BlockType;
+  EFI_HII_IMAGE_BLOCK                 *CurrentImageBlock;
   EFI_HII_IIBT_IMAGE_1BIT_BLOCK       Iibt1bit;
   UINT16                              Width;
   UINT16                              Height;
   UINTN                               ImageLength;
-  BOOLEAN                             Flag;
   UINT8                               *PaletteInfo;
   UINT8                               PaletteIndex;
   UINT16                              PaletteSize;
 
-  if (This == NULL || Image == NULL || ImageId < 1) {
+  if (This == NULL || Image == NULL || ImageId == 0) {
     return EFI_INVALID_PARAMETER;
   }
 
@@ -838,16 +835,12 @@ HiiGetImage (
   //
   // Find the image block specified by ImageId
   //
-  LocalImageId = ImageId;
-  ImageBlock = (UINT8 *) GetImageIdOrAddress (ImagePackage->ImageBlock, &LocalImageId);
-  if (ImageBlock == NULL) {
+  CurrentImageBlock = GetImageIdOrAddress (ImagePackage->ImageBlock, &ImageId);
+  if (CurrentImageBlock == NULL) {
     return EFI_NOT_FOUND;
   }
 
-  Flag      = FALSE;
-  BlockType = *ImageBlock;
-
-  switch (BlockType) {
+  switch (CurrentImageBlock->BlockType) {
   case EFI_HII_IIBT_IMAGE_JPEG:
     //
     // BUGBUG: need to be supported as soon as image tool is designed.
@@ -857,7 +850,7 @@ HiiGetImage (
   case EFI_HII_IIBT_IMAGE_1BIT_TRANS:
   case EFI_HII_IIBT_IMAGE_4BIT_TRANS:
   case EFI_HII_IIBT_IMAGE_8BIT_TRANS:
-    Flag = TRUE;
+    Image->Flags = EFI_IMAGE_TRANSPARENT;
     //
     // fall through
     //
@@ -867,7 +860,7 @@ HiiGetImage (
     //
     // Use the common block code since the definition of these structures is the same.
     //
-    CopyMem (&Iibt1bit, ImageBlock, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK));
+    CopyMem (&Iibt1bit, CurrentImageBlock, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK));
     ImageLength = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) *
                   (Iibt1bit.Bitmap.Width * Iibt1bit.Bitmap.Height);
     Image->Bitmap = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (ImageLength);
@@ -875,9 +868,6 @@ HiiGetImage (
       return EFI_OUT_OF_RESOURCES;
     }
 
-    if (Flag) {
-      Image->Flags = EFI_IMAGE_TRANSPARENT;
-    }
     Image->Width  = Iibt1bit.Bitmap.Width;
     Image->Height = Iibt1bit.Bitmap.Height;
 
@@ -891,22 +881,24 @@ HiiGetImage (
     //
     // Output bitmap data
     //
-    if (BlockType == EFI_HII_IIBT_IMAGE_1BIT || BlockType == EFI_HII_IIBT_IMAGE_1BIT_TRANS) {
+    if (CurrentImageBlock->BlockType == EFI_HII_IIBT_IMAGE_1BIT ||
+        CurrentImageBlock->BlockType == EFI_HII_IIBT_IMAGE_1BIT_TRANS) {
       Output1bitPixel (
         Image,
-        (UINT8 *) ((UINTN)ImageBlock + sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK) - sizeof (UINT8)),
+        ((EFI_HII_IIBT_IMAGE_1BIT_BLOCK *) CurrentImageBlock)->Bitmap.Data,
         (EFI_HII_IMAGE_PALETTE_INFO *) PaletteInfo
         );
-    } else if (BlockType == EFI_HII_IIBT_IMAGE_4BIT || BlockType == EFI_HII_IIBT_IMAGE_4BIT_TRANS) {
+    } else if (CurrentImageBlock->BlockType == EFI_HII_IIBT_IMAGE_4BIT ||
+               CurrentImageBlock->BlockType == EFI_HII_IIBT_IMAGE_4BIT_TRANS) {
       Output4bitPixel (
         Image,
-        (UINT8 *) ((UINTN)ImageBlock + sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK) - sizeof (UINT8)),
+        ((EFI_HII_IIBT_IMAGE_4BIT_BLOCK *) CurrentImageBlock)->Bitmap.Data,
         (EFI_HII_IMAGE_PALETTE_INFO *) PaletteInfo
         );
     } else {
       Output8bitPixel (
         Image,
-        (UINT8 *) ((UINTN)ImageBlock + sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK) - sizeof (UINT8)),
+        ((EFI_HII_IIBT_IMAGE_8BIT_BLOCK *) CurrentImageBlock)->Bitmap.Data,
         (EFI_HII_IMAGE_PALETTE_INFO *) PaletteInfo
         );
     }
@@ -914,35 +906,28 @@ HiiGetImage (
     return EFI_SUCCESS;
 
   case EFI_HII_IIBT_IMAGE_24BIT_TRANS:
-    Flag = TRUE;
+    Image->Flags = EFI_IMAGE_TRANSPARENT;
     //
     // fall through
     //
   case EFI_HII_IIBT_IMAGE_24BIT:
-    CopyMem (&Width, ImageBlock + sizeof (EFI_HII_IMAGE_BLOCK), sizeof (UINT16));
-    CopyMem (
-      &Height,
-      ImageBlock + sizeof (EFI_HII_IMAGE_BLOCK) + sizeof (UINT16),
-      sizeof (UINT16)
-      );
+    Width = ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) CurrentImageBlock)->Bitmap.Width);
+    Height = ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) CurrentImageBlock)->Bitmap.Height);
     ImageLength = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * (Width * Height);
-    Image->Bitmap = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (ImageLength);
+    Image->Bitmap = AllocateZeroPool (ImageLength);
     if (Image->Bitmap == NULL) {
       return EFI_OUT_OF_RESOURCES;
     }
 
-    if (Flag) {
-      Image->Flags = EFI_IMAGE_TRANSPARENT;
-    }
     Image->Width  = Width;
     Image->Height = Height;
 
     //
-    // Output the bimap data directly.
+    // Output the bitmap data directly.
     //
     Output24bitPixel (
       Image,
-      (EFI_HII_RGB_PIXEL *) (ImageBlock + sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL))
+      ((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) CurrentImageBlock)->Bitmap.Bitmap
       );
     return EFI_SUCCESS;
 
-- 
2.9.0.windows.1



  parent reply	other threads:[~2016-09-23  8:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-23  8:25 [PATCH 00/13] Add HiiImageEx implementation and demonstrate in Nt32 Ruiyu Ni
2016-09-23  8:25 ` [PATCH 01/13] MdeModulePkg/HiiDatabase: Refine GetImageIdOrAddress Ruiyu Ni
2016-09-23  8:25 ` [PATCH 02/13] MdeModulePkg/HiiDatabase: Move common code to LocatePackageList() Ruiyu Ni
2016-09-23  8:25 ` [PATCH 03/13] MdeModulePkg/HiiDatabase: Refine HiiNewImage() Ruiyu Ni
2016-09-23  8:25 ` Ruiyu Ni [this message]
2016-09-23  8:25 ` [PATCH 05/13] MdeModulePkg/HiiDatabase: Refine HiiSetImage() Ruiyu Ni
2016-09-23  8:25 ` [PATCH 06/13] MdeModulePkg/HiiDatabase: Refine HiiDrawImage() Ruiyu Ni
2016-09-23  8:25 ` [PATCH 07/13] MdemodulePkg/HiiDatabase: Correct typo in comments Ruiyu Ni
2016-09-23  8:25 ` [PATCH 08/13] MdeModulePkg/HiiDatabase: Update HiiImage to support PNG/JPEG Ruiyu Ni
2016-09-23  8:25 ` [PATCH 09/13] MdeModulePkg/HiiDatabase: Add HiiImageEx implementation Ruiyu Ni
2016-09-23  8:25 ` [PATCH 10/13] Nt32Pkg/PlatformBds: Do not call BootLogoEnableLogo Ruiyu Ni
2016-09-23  8:25 ` [PATCH 11/13] MdeModulePkg/BootLogoLib&PlatformLogo: Use HII data types in parameters Ruiyu Ni
2016-09-23  8:25 ` [PATCH 12/13] MdeModulePkg/Logo: Add LogoDxe module Ruiyu Ni
2016-09-23  8:25 ` [PATCH 13/13] Nt32Pkg: Use the new LogoDxe driver Ruiyu Ni
2016-09-26  2:55 ` [PATCH 00/13] Add HiiImageEx implementation and demonstrate in Nt32 Gao, Liming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160923082521.99872-5-ruiyu.ni@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox