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 v2 03/19] MdeModulePkg/HiiDatabase: Refine HiiNewImage()
Date: Mon, 26 Sep 2016 17:30:19 +0800 [thread overview]
Message-ID: <20160926093035.350612-4-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20160926093035.350612-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 | 83 +++++++++------------------
1 file changed, 27 insertions(+), 56 deletions(-)
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
index 6ff397d..d73269c 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
@@ -631,12 +631,8 @@ HiiNewImage (
HII_DATABASE_PRIVATE_DATA *Private;
HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;
HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;
- UINT8 *ImageBlock;
- UINTN BlockSize;
- UINT8 *NewBlock;
- UINT8 *NewBlockPtr;
- UINTN NewBlockSize;
- EFI_IMAGE_INPUT *ImageIn;
+ EFI_HII_IMAGE_BLOCK *ImageBlocks;
+ UINT32 NewBlockSize;
if (This == NULL || ImageId == NULL || Image == NULL || Image->Bitmap == NULL) {
return EFI_INVALID_PARAMETER;
@@ -652,10 +648,8 @@ HiiNewImage (
return EFI_NOT_FOUND;
}
- ImageIn = (EFI_IMAGE_INPUT *) Image;
-
NewBlockSize = sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL) +
- BITMAP_LEN_24_BIT (ImageIn->Width, ImageIn->Height);
+ BITMAP_LEN_24_BIT (Image->Width, Image->Height);
//
// Get the image package in the package list,
@@ -674,38 +668,33 @@ HiiNewImage (
//
// Update the package's image block by appending the new block to the end.
//
- BlockSize = ImagePackage->ImageBlockSize + NewBlockSize;
- ImageBlock = (UINT8 *) AllocateZeroPool (BlockSize);
- if (ImageBlock == NULL) {
+ ImageBlocks = AllocatePool (ImagePackage->ImageBlockSize + NewBlockSize);
+ if (ImageBlocks == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Copy the original content.
//
CopyMem (
- ImageBlock,
+ ImageBlocks,
ImagePackage->ImageBlock,
ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK)
);
FreePool (ImagePackage->ImageBlock);
- ImagePackage->ImageBlock = (EFI_HII_IMAGE_BLOCK *) ImageBlock;
- ImageBlock += ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK);
+ ImagePackage->ImageBlock = ImageBlocks;
+
//
- // Temp memory to store new block.
+ // Point to the very last block.
//
- NewBlock = AllocateZeroPool (NewBlockSize);
- if (NewBlock == NULL) {
- FreePool (ImagePackage->ImageBlock);
- return EFI_OUT_OF_RESOURCES;
- }
- NewBlockPtr = NewBlock;
-
+ ImageBlocks = (EFI_HII_IMAGE_BLOCK *) (
+ (UINT8 *) ImageBlocks + ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK)
+ );
//
// Update the length record.
//
- ImagePackage->ImageBlockSize = (UINT32) BlockSize;
- ImagePackage->ImagePkgHdr.Header.Length += (UINT32) NewBlockSize;
- PackageListNode->PackageListHdr.PackageLength += (UINT32) NewBlockSize;
+ ImagePackage->ImageBlockSize += NewBlockSize;
+ ImagePackage->ImagePkgHdr.Header.Length += NewBlockSize;
+ PackageListNode->PackageListHdr.PackageLength += NewBlockSize;
} else {
//
@@ -721,11 +710,10 @@ HiiNewImage (
// first image block so that id is initially to one.
//
*ImageId = 1;
- BlockSize = sizeof (EFI_HII_IIBT_END_BLOCK) + NewBlockSize;
//
// Fill in image package header.
//
- ImagePackage->ImagePkgHdr.Header.Length = (UINT32) BlockSize + sizeof (EFI_HII_IMAGE_PACKAGE_HDR);
+ ImagePackage->ImagePkgHdr.Header.Length = sizeof (EFI_HII_IMAGE_PACKAGE_HDR) + NewBlockSize + sizeof (EFI_HII_IIBT_END_BLOCK);
ImagePackage->ImagePkgHdr.Header.Type = EFI_HII_PACKAGE_IMAGES;
ImagePackage->ImagePkgHdr.ImageInfoOffset = sizeof (EFI_HII_IMAGE_PACKAGE_HDR);
ImagePackage->ImagePkgHdr.PaletteInfoOffset = 0;
@@ -739,24 +727,13 @@ HiiNewImage (
//
// Fill in image blocks.
//
- ImagePackage->ImageBlockSize = (UINT32) BlockSize;
- ImagePackage->ImageBlock = AllocateZeroPool (BlockSize);
+ ImagePackage->ImageBlockSize = NewBlockSize + sizeof (EFI_HII_IIBT_END_BLOCK);
+ ImagePackage->ImageBlock = AllocateZeroPool (NewBlockSize + sizeof (EFI_HII_IIBT_END_BLOCK));
if (ImagePackage->ImageBlock == NULL) {
FreePool (ImagePackage);
return EFI_OUT_OF_RESOURCES;
}
- ImageBlock = (UINT8 *) ImagePackage->ImageBlock;
-
- //
- // Temp memory to store new block.
- //
- NewBlock = AllocateZeroPool (NewBlockSize);
- if (NewBlock == NULL) {
- FreePool (ImagePackage->ImageBlock);
- FreePool (ImagePackage);
- return EFI_OUT_OF_RESOURCES;
- }
- NewBlockPtr = NewBlock;
+ ImageBlocks = ImagePackage->ImageBlock;
//
// Insert this image package.
@@ -768,26 +745,20 @@ HiiNewImage (
//
// Append the new block here
//
- if (ImageIn->Flags == EFI_IMAGE_TRANSPARENT) {
- *NewBlock = EFI_HII_IIBT_IMAGE_24BIT_TRANS;
+ if (Image->Flags == EFI_IMAGE_TRANSPARENT) {
+ ImageBlocks->BlockType = EFI_HII_IIBT_IMAGE_24BIT_TRANS;
} else {
- *NewBlock = EFI_HII_IIBT_IMAGE_24BIT;
+ ImageBlocks->BlockType = EFI_HII_IIBT_IMAGE_24BIT;
}
- NewBlock++;
- CopyMem (NewBlock, &ImageIn->Width, sizeof (UINT16));
- NewBlock += sizeof (UINT16);
- CopyMem (NewBlock, &ImageIn->Height, sizeof (UINT16));
- NewBlock += sizeof (UINT16);
- CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL *) NewBlock, ImageIn->Bitmap, ImageIn->Width * ImageIn->Height);
-
- CopyMem (ImageBlock, NewBlockPtr, NewBlockSize);
- FreePool (NewBlockPtr);
+ WriteUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) ImageBlocks)->Bitmap.Width, Image->Width);
+ WriteUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) ImageBlocks)->Bitmap.Height, Image->Height);
+ CopyGopToRgbPixel (((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) ImageBlocks)->Bitmap.Bitmap, Image->Bitmap, Image->Width * Image->Height);
//
// Append the block end
//
- ImageBlock += NewBlockSize;
- ((EFI_HII_IIBT_END_BLOCK *) (ImageBlock))->Header.BlockType = EFI_HII_IIBT_END;
+ ImageBlocks = (EFI_HII_IMAGE_BLOCK *) ((UINT8 *) ImageBlocks + NewBlockSize);
+ ImageBlocks->BlockType = EFI_HII_IIBT_END;
//
// Check whether need to get the contents of HiiDataBase.
--
2.9.0.windows.1
next prev parent reply other threads:[~2016-09-26 9:30 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-26 9:30 [PATCH v2 00/19] Add HiiImageEx implementations Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 01/19] MdeModulePkg/HiiDatabase: Refine GetImageIdOrAddress Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 02/19] MdeModulePkg/HiiDatabase: Move common code to LocatePackageList() Ruiyu Ni
2016-09-26 9:30 ` Ruiyu Ni [this message]
2016-09-26 9:30 ` [PATCH v2 04/19] MdeModulePkg/HiiDatabase: Refine HiiGetImage() Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 05/19] MdeModulePkg/HiiDatabase: Refine HiiSetImage() Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 06/19] MdeModulePkg/HiiDatabase: Refine HiiDrawImage() Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 07/19] MdemodulePkg/HiiDatabase: Correct typo in comments Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 08/19] MdePkg/HiiImage.h: Include GraphicsOutput.h Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 09/19] MdeModulePkg/HiiDatabase: Update HiiImage to support PNG/JPEG Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 10/19] MdePkg/HiiImageDecoder.h: Add HiiImageDecoder protocol header file Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 11/19] MdeModulePkg/HiiDatabase: Add HiiImageEx implementation Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 12/19] Nt32Pkg/PlatformBds: Do not call BootLogoEnableLogo Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 13/19] ArmVirtPkg/PlatformBds: " Ruiyu Ni
2016-09-26 10:06 ` Laszlo Ersek
2016-09-26 12:56 ` Ard Biesheuvel
2016-09-26 9:30 ` [PATCH v2 14/19] OvmfPkg/PlatformBds: " Ruiyu Ni
2016-09-26 10:06 ` Laszlo Ersek
2016-09-26 9:30 ` [PATCH v2 15/19] MdeModulePkg/BootLogoLib&PlatformLogo: Use HII data types in parameters Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 16/19] MdeModulePkg/Logo: Add LogoDxe module Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 17/19] Nt32Pkg: Use the new LogoDxe driver Ruiyu Ni
2016-09-26 9:30 ` [PATCH v2 18/19] ArmVirtPkg: " Ruiyu Ni
2016-09-26 10:06 ` Laszlo Ersek
2016-09-26 12:56 ` Ard Biesheuvel
2016-09-26 9:30 ` [PATCH v2 19/19] OvmfPkg: " Ruiyu Ni
2016-09-26 10:06 ` Laszlo Ersek
2016-09-28 8:12 ` [PATCH v2 00/19] Add HiiImageEx implementations 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=20160926093035.350612-4-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