2 Implementation for EFI_HII_IMAGE_PROTOCOL.
5 Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "HiiDatabase.h"
21 Get the imageid of last image block: EFI_HII_IIBT_END_BLOCK when input
22 ImageId is zero, otherwise return the address of the
23 corresponding image block with identifier specified by ImageId.
25 This is a internal function.
27 @param ImageBlock Points to the beginning of a series of image blocks stored in order.
28 @param ImageId If input ImageId is 0, output the image id of the EFI_HII_IIBT_END_BLOCK;
29 else use this id to find its corresponding image block address.
31 @return The image block address when input ImageId is not zero; otherwise return NULL.
37 IN OUT EFI_IMAGE_ID
*ImageId
40 EFI_IMAGE_ID ImageIdCurrent
;
45 EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit
;
46 EFI_HII_IIBT_IMAGE_4BIT_BLOCK Iibt4bit
;
47 EFI_HII_IIBT_IMAGE_8BIT_BLOCK Iibt8bit
;
51 ASSERT (ImageBlock
!= NULL
&& ImageId
!= NULL
);
53 ImageBlockHdr
= ImageBlock
;
56 while (((EFI_HII_IMAGE_BLOCK
*) ImageBlock
)->BlockType
!= EFI_HII_IIBT_END
) {
58 if (*ImageId
== ImageIdCurrent
) {
60 // If the found image block is a duplicate block, update the ImageId to
61 // find the previous defined image block.
63 if (((EFI_HII_IMAGE_BLOCK
*) ImageBlock
)->BlockType
== EFI_HII_IIBT_DUPLICATE
) {
64 CopyMem (ImageId
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (EFI_IMAGE_ID
));
65 ASSERT (*ImageId
!= ImageIdCurrent
);
66 ImageBlock
= ImageBlockHdr
;
73 if (*ImageId
< ImageIdCurrent
) {
75 // Can not find the specified image block in this image.
80 switch (((EFI_HII_IMAGE_BLOCK
*) ImageBlock
)->BlockType
) {
81 case EFI_HII_IIBT_EXT1
:
82 Length8
= *(UINT8
*)((UINTN
)ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT8
));
83 ImageBlock
+= Length8
;
85 case EFI_HII_IIBT_EXT2
:
88 (UINT8
*)((UINTN
)ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT8
)),
91 ImageBlock
+= Length16
;
93 case EFI_HII_IIBT_EXT4
:
96 (UINT8
*)((UINTN
)ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT8
)),
99 ImageBlock
+= Length32
;
102 case EFI_HII_IIBT_IMAGE_1BIT
:
103 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
104 CopyMem (&Iibt1bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
));
105 ImageBlock
+= sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
) - sizeof (UINT8
) +
106 BITMAP_LEN_1_BIT (Iibt1bit
.Bitmap
.Width
, Iibt1bit
.Bitmap
.Height
);
110 case EFI_HII_IIBT_IMAGE_4BIT
:
111 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
112 CopyMem (&Iibt4bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
));
113 ImageBlock
+= sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
) - sizeof (UINT8
) +
114 BITMAP_LEN_4_BIT (Iibt4bit
.Bitmap
.Width
, Iibt4bit
.Bitmap
.Height
);
118 case EFI_HII_IIBT_IMAGE_8BIT
:
119 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
120 CopyMem (&Iibt8bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
));
121 ImageBlock
+= sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
) - sizeof (UINT8
) +
122 BITMAP_LEN_8_BIT (Iibt8bit
.Bitmap
.Width
, Iibt8bit
.Bitmap
.Height
);
126 case EFI_HII_IIBT_IMAGE_24BIT
:
127 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
128 CopyMem (&Width
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (UINT16
));
131 ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT16
),
134 ImageBlock
+= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
135 BITMAP_LEN_24_BIT (Width
, Height
);
139 case EFI_HII_IIBT_DUPLICATE
:
140 ImageBlock
+= sizeof (EFI_HII_IIBT_DUPLICATE_BLOCK
);
144 case EFI_HII_IIBT_IMAGE_JPEG
:
145 CopyMem (&Length32
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (UINT32
));
146 ImageBlock
+= Length32
;
150 case EFI_HII_IIBT_SKIP1
:
151 Length8
= *(ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
));
152 ImageBlock
+= sizeof (EFI_HII_IIBT_SKIP1_BLOCK
);
153 ImageIdCurrent
= (UINT16
) (ImageIdCurrent
+ Length8
);
156 case EFI_HII_IIBT_SKIP2
:
157 CopyMem (&Length16
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (UINT16
));
158 ImageBlock
+= sizeof (EFI_HII_IIBT_SKIP2_BLOCK
);
159 ImageIdCurrent
= (UINT16
) (ImageIdCurrent
+ Length16
);
164 // Unknown image blocks can not be skipped, processing halts.
171 // When ImageId is zero, return the imageid of last image block: EFI_HII_IIBT_END_BLOCK.
174 *ImageId
= ImageIdCurrent
;
184 Convert pixels from EFI_GRAPHICS_OUTPUT_BLT_PIXEL to EFI_HII_RGB_PIXEL style.
186 This is a internal function.
189 @param BitMapOut Pixels in EFI_HII_RGB_PIXEL format.
190 @param BitMapIn Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format.
191 @param PixelNum The number of pixels to be converted.
197 OUT EFI_HII_RGB_PIXEL
*BitMapOut
,
198 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapIn
,
204 ASSERT (BitMapOut
!= NULL
&& BitMapIn
!= NULL
);
206 for (Index
= 0; Index
< PixelNum
; Index
++) {
207 CopyMem (BitMapOut
+ Index
, BitMapIn
+ Index
, sizeof (EFI_HII_RGB_PIXEL
));
213 Convert pixels from EFI_HII_RGB_PIXEL to EFI_GRAPHICS_OUTPUT_BLT_PIXEL style.
215 This is a internal function.
218 @param BitMapOut Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format.
219 @param BitMapIn Pixels in EFI_HII_RGB_PIXEL format.
220 @param PixelNum The number of pixels to be converted.
226 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapOut
,
227 IN EFI_HII_RGB_PIXEL
*BitMapIn
,
233 ASSERT (BitMapOut
!= NULL
&& BitMapIn
!= NULL
);
235 for (Index
= 0; Index
< PixelNum
; Index
++) {
236 CopyMem (BitMapOut
+ Index
, BitMapIn
+ Index
, sizeof (EFI_HII_RGB_PIXEL
));
242 Output pixels in "1 bit per pixel" format to an image.
244 This is a internal function.
247 @param Image Points to the image which will store the pixels.
248 @param Data Stores the value of output pixels, 0 or 1.
249 @param PaletteInfo PaletteInfo which stores the color of the output
250 pixels. First entry corresponds to color 0 and
251 second one to color 1.
257 IN OUT EFI_IMAGE_INPUT
*Image
,
259 IN EFI_HII_IMAGE_PALETTE_INFO
*PaletteInfo
266 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
267 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue
[2];
268 EFI_HII_IMAGE_PALETTE_INFO
*Palette
;
272 ASSERT (Image
!= NULL
&& Data
!= NULL
&& PaletteInfo
!= NULL
);
274 BitMapPtr
= Image
->Bitmap
;
277 // First entry corresponds to color 0 and second entry corresponds to color 1.
280 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
281 PaletteSize
+= sizeof (UINT16
);
282 Palette
= AllocateZeroPool (PaletteSize
);
283 ASSERT (Palette
!= NULL
);
284 if (Palette
== NULL
) {
287 CopyMem (Palette
, PaletteInfo
, PaletteSize
);
289 ZeroMem (PaletteValue
, sizeof (PaletteValue
));
290 CopyRgbToGopPixel (&PaletteValue
[0], &Palette
->PaletteValue
[0], 1);
291 CopyRgbToGopPixel (&PaletteValue
[1], &Palette
->PaletteValue
[1], 1);
295 // Convert the pixel from one bit to corresponding color.
297 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
298 OffsetY
= BITMAP_LEN_1_BIT (Image
->Width
, Ypos
);
300 // All bits in these bytes are meaningful
302 for (Xpos
= 0; Xpos
< Image
->Width
/ 8; Xpos
++) {
303 Byte
= *(Data
+ OffsetY
+ Xpos
);
304 for (Index
= 0; Index
< 8; Index
++) {
305 if ((Byte
& (1 << Index
)) != 0) {
306 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 8 + (8 - Index
- 1)] = PaletteValue
[1];
308 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 8 + (8 - Index
- 1)] = PaletteValue
[0];
313 if (Image
->Width
% 8 != 0) {
315 // Padding bits in this byte should be ignored.
317 Byte
= *(Data
+ OffsetY
+ Xpos
);
318 for (Index
= 0; Index
< Image
->Width
% 8; Index
++) {
319 if ((Byte
& (1 << (8 - Index
- 1))) != 0) {
320 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 8 + Index
] = PaletteValue
[1];
322 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 8 + Index
] = PaletteValue
[0];
331 Output pixels in "4 bit per pixel" format to an image.
333 This is a internal function.
336 @param Image Points to the image which will store the pixels.
337 @param Data Stores the value of output pixels, 0 ~ 15.
338 @param[in] PaletteInfo PaletteInfo which stores the color of the output
339 pixels. Each entry corresponds to a color within
346 IN OUT EFI_IMAGE_INPUT
*Image
,
348 IN EFI_HII_IMAGE_PALETTE_INFO
*PaletteInfo
354 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
355 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue
[16];
356 EFI_HII_IMAGE_PALETTE_INFO
*Palette
;
361 ASSERT (Image
!= NULL
&& Data
!= NULL
&& PaletteInfo
!= NULL
);
363 BitMapPtr
= Image
->Bitmap
;
366 // The bitmap should allocate each color index starting from 0.
369 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
370 PaletteSize
+= sizeof (UINT16
);
371 Palette
= AllocateZeroPool (PaletteSize
);
372 ASSERT (Palette
!= NULL
);
373 if (Palette
== NULL
) {
376 CopyMem (Palette
, PaletteInfo
, PaletteSize
);
377 PaletteNum
= (UINT16
)(Palette
->PaletteSize
/ sizeof (EFI_HII_RGB_PIXEL
));
379 ZeroMem (PaletteValue
, sizeof (PaletteValue
));
380 CopyRgbToGopPixel (PaletteValue
, Palette
->PaletteValue
, PaletteNum
);
384 // Convert the pixel from 4 bit to corresponding color.
386 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
387 OffsetY
= BITMAP_LEN_4_BIT (Image
->Width
, Ypos
);
389 // All bits in these bytes are meaningful
391 for (Xpos
= 0; Xpos
< Image
->Width
/ 2; Xpos
++) {
392 Byte
= *(Data
+ OffsetY
+ Xpos
);
393 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 2] = PaletteValue
[Byte
>> 4];
394 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 2 + 1] = PaletteValue
[Byte
& 0x0F];
397 if (Image
->Width
% 2 != 0) {
399 // Padding bits in this byte should be ignored.
401 Byte
= *(Data
+ OffsetY
+ Xpos
);
402 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 2] = PaletteValue
[Byte
>> 4];
409 Output pixels in "8 bit per pixel" format to an image.
411 This is a internal function.
414 @param Image Points to the image which will store the pixels.
415 @param Data Stores the value of output pixels, 0 ~ 255.
416 @param[in] PaletteInfo PaletteInfo which stores the color of the output
417 pixels. Each entry corresponds to a color within
424 IN OUT EFI_IMAGE_INPUT
*Image
,
426 IN EFI_HII_IMAGE_PALETTE_INFO
*PaletteInfo
432 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
433 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue
[256];
434 EFI_HII_IMAGE_PALETTE_INFO
*Palette
;
439 ASSERT (Image
!= NULL
&& Data
!= NULL
&& PaletteInfo
!= NULL
);
441 BitMapPtr
= Image
->Bitmap
;
444 // The bitmap should allocate each color index starting from 0.
447 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
448 PaletteSize
+= sizeof (UINT16
);
449 Palette
= AllocateZeroPool (PaletteSize
);
450 ASSERT (Palette
!= NULL
);
451 if (Palette
== NULL
) {
454 CopyMem (Palette
, PaletteInfo
, PaletteSize
);
455 PaletteNum
= (UINT16
)(Palette
->PaletteSize
/ sizeof (EFI_HII_RGB_PIXEL
));
456 ZeroMem (PaletteValue
, sizeof (PaletteValue
));
457 CopyRgbToGopPixel (PaletteValue
, Palette
->PaletteValue
, PaletteNum
);
461 // Convert the pixel from 8 bits to corresponding color.
463 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
464 OffsetY
= BITMAP_LEN_8_BIT (Image
->Width
, Ypos
);
466 // All bits are meaningful since the bitmap is 8 bits per pixel.
468 for (Xpos
= 0; Xpos
< Image
->Width
; Xpos
++) {
469 Byte
= *(Data
+ OffsetY
+ Xpos
);
470 BitMapPtr
[OffsetY
+ Xpos
] = PaletteValue
[Byte
];
478 Output pixels in "24 bit per pixel" format to an image.
480 This is a internal function.
483 @param Image Points to the image which will store the pixels.
484 @param Data Stores the color of output pixels, allowing 16.8
491 IN OUT EFI_IMAGE_INPUT
*Image
,
492 IN EFI_HII_RGB_PIXEL
*Data
497 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
499 ASSERT (Image
!= NULL
&& Data
!= NULL
);
501 BitMapPtr
= Image
->Bitmap
;
503 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
504 OffsetY
= BITMAP_LEN_8_BIT (Image
->Width
, Ypos
);
505 CopyRgbToGopPixel (&BitMapPtr
[OffsetY
], &Data
[OffsetY
], Image
->Width
);
512 Convert the image from EFI_IMAGE_INPUT to EFI_IMAGE_OUTPUT format.
514 This is a internal function.
517 @param BltBuffer Buffer points to bitmap data of incoming image.
518 @param BltX Specifies the offset from the left and top edge of
519 the output image of the first pixel in the image.
520 @param BltY Specifies the offset from the left and top edge of
521 the output image of the first pixel in the image.
522 @param Width Width of the incoming image, in pixels.
523 @param Height Height of the incoming image, in pixels.
524 @param Transparent If TRUE, all "off" pixels in the image will be
525 drawn using the pixel value from blt and all other
526 pixels will be copied.
527 @param Blt Buffer points to bitmap data of output image.
529 @retval EFI_SUCCESS The image was successfully converted.
530 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
535 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
,
540 IN BOOLEAN Transparent
,
541 IN OUT EFI_IMAGE_OUTPUT
**Blt
544 EFI_IMAGE_OUTPUT
*ImageOut
;
547 UINTN OffsetY1
; // src buffer
548 UINTN OffsetY2
; // dest buffer
549 EFI_GRAPHICS_OUTPUT_BLT_PIXEL SrcPixel
;
550 EFI_GRAPHICS_OUTPUT_BLT_PIXEL ZeroPixel
;
552 if (BltBuffer
== NULL
|| Blt
== NULL
|| *Blt
== NULL
) {
553 return EFI_INVALID_PARAMETER
;
558 if (Width
+ BltX
> ImageOut
->Width
) {
559 return EFI_INVALID_PARAMETER
;
561 if (Height
+ BltY
> ImageOut
->Height
) {
562 return EFI_INVALID_PARAMETER
;
565 ZeroMem (&ZeroPixel
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
567 for (Ypos
= 0; Ypos
< Height
; Ypos
++) {
568 OffsetY1
= Width
* Ypos
;
569 OffsetY2
= ImageOut
->Width
* (BltY
+ Ypos
);
570 for (Xpos
= 0; Xpos
< Width
; Xpos
++) {
571 SrcPixel
= BltBuffer
[OffsetY1
+ Xpos
];
573 if (CompareMem (&SrcPixel
, &ZeroPixel
, 3) != 0) {
574 ImageOut
->Image
.Bitmap
[OffsetY2
+ BltX
+ Xpos
] = SrcPixel
;
577 ImageOut
->Image
.Bitmap
[OffsetY2
+ BltX
+ Xpos
] = SrcPixel
;
587 This function adds the image Image to the group of images owned by PackageList, and returns
588 a new image identifier (ImageId).
590 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
591 @param PackageList Handle of the package list where this image will
593 @param ImageId On return, contains the new image id, which is
594 unique within PackageList.
595 @param Image Points to the image.
597 @retval EFI_SUCCESS The new image was added successfully.
598 @retval EFI_NOT_FOUND The specified PackageList could not be found in
600 @retval EFI_OUT_OF_RESOURCES Could not add the image due to lack of resources.
601 @retval EFI_INVALID_PARAMETER Image is NULL or ImageId is NULL.
607 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
608 IN EFI_HII_HANDLE PackageList
,
609 OUT EFI_IMAGE_ID
*ImageId
,
610 IN CONST EFI_IMAGE_INPUT
*Image
613 HII_DATABASE_PRIVATE_DATA
*Private
;
615 HII_DATABASE_RECORD
*DatabaseRecord
;
616 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
617 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
623 EFI_IMAGE_INPUT
*ImageIn
;
625 if (This
== NULL
|| ImageId
== NULL
|| Image
== NULL
|| Image
->Bitmap
== NULL
) {
626 return EFI_INVALID_PARAMETER
;
629 if (!IsHiiHandleValid (PackageList
)) {
630 return EFI_NOT_FOUND
;
633 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
636 // Get the specified package list
639 PackageListNode
= NULL
;
641 for (Link
= Private
->DatabaseList
.ForwardLink
;
642 Link
!= &Private
->DatabaseList
;
643 Link
= Link
->ForwardLink
645 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
646 if (DatabaseRecord
->Handle
== PackageList
) {
647 PackageListNode
= DatabaseRecord
->PackageList
;
652 if (PackageListNode
== NULL
) {
653 return EFI_NOT_FOUND
;
656 ImageIn
= (EFI_IMAGE_INPUT
*) Image
;
658 NewBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
659 BITMAP_LEN_24_BIT (ImageIn
->Width
, ImageIn
->Height
);
662 // Get the image package in the package list,
663 // or create a new image package if image package does not exist.
665 if (PackageListNode
->ImagePkg
!= NULL
) {
666 ImagePackage
= PackageListNode
->ImagePkg
;
669 // Output the image id of the incoming image being inserted, which is the
670 // image id of the EFI_HII_IIBT_END block of old image package.
673 GetImageIdOrAddress (ImagePackage
->ImageBlock
, ImageId
);
676 // Update the package's image block by appending the new block to the end.
678 BlockSize
= ImagePackage
->ImageBlockSize
+ NewBlockSize
;
679 ImageBlock
= (UINT8
*) AllocateZeroPool (BlockSize
);
680 if (ImageBlock
== NULL
) {
681 return EFI_OUT_OF_RESOURCES
;
684 // Copy the original content.
688 ImagePackage
->ImageBlock
,
689 ImagePackage
->ImageBlockSize
- sizeof (EFI_HII_IIBT_END_BLOCK
)
691 FreePool (ImagePackage
->ImageBlock
);
692 ImagePackage
->ImageBlock
= ImageBlock
;
693 ImageBlock
+= ImagePackage
->ImageBlockSize
- sizeof (EFI_HII_IIBT_END_BLOCK
);
695 // Temp memory to store new block.
697 NewBlock
= AllocateZeroPool (NewBlockSize
);
698 if (NewBlock
== NULL
) {
699 FreePool (ImagePackage
->ImageBlock
);
700 return EFI_OUT_OF_RESOURCES
;
702 NewBlockPtr
= NewBlock
;
705 // Update the length record.
707 ImagePackage
->ImageBlockSize
= (UINT32
) BlockSize
;
708 ImagePackage
->ImagePkgHdr
.Header
.Length
+= (UINT32
) NewBlockSize
;
709 PackageListNode
->PackageListHdr
.PackageLength
+= (UINT32
) NewBlockSize
;
713 // The specified package list does not contain image package.
714 // Create one to add this image block.
716 ImagePackage
= (HII_IMAGE_PACKAGE_INSTANCE
*) AllocateZeroPool (sizeof (HII_IMAGE_PACKAGE_INSTANCE
));
717 if (ImagePackage
== NULL
) {
718 return EFI_OUT_OF_RESOURCES
;
721 // Output the image id of the incoming image being inserted, which is the
722 // first image block so that id is initially to one.
725 BlockSize
= sizeof (EFI_HII_IIBT_END_BLOCK
) + NewBlockSize
;
727 // Fill in image package header.
729 ImagePackage
->ImagePkgHdr
.Header
.Length
= (UINT32
) BlockSize
+ sizeof (EFI_HII_IMAGE_PACKAGE_HDR
);
730 ImagePackage
->ImagePkgHdr
.Header
.Type
= EFI_HII_PACKAGE_IMAGES
;
731 ImagePackage
->ImagePkgHdr
.ImageInfoOffset
= sizeof (EFI_HII_IMAGE_PACKAGE_HDR
);
732 ImagePackage
->ImagePkgHdr
.PaletteInfoOffset
= 0;
735 // Fill in palette info.
737 ImagePackage
->PaletteBlock
= NULL
;
738 ImagePackage
->PaletteInfoSize
= 0;
741 // Fill in image blocks.
743 ImagePackage
->ImageBlockSize
= (UINT32
) BlockSize
;
744 ImagePackage
->ImageBlock
= (UINT8
*) AllocateZeroPool (BlockSize
);
745 if (ImagePackage
->ImageBlock
== NULL
) {
746 FreePool (ImagePackage
);
747 return EFI_OUT_OF_RESOURCES
;
749 ImageBlock
= ImagePackage
->ImageBlock
;
752 // Temp memory to store new block.
754 NewBlock
= AllocateZeroPool (NewBlockSize
);
755 if (NewBlock
== NULL
) {
756 FreePool (ImagePackage
->ImageBlock
);
757 FreePool (ImagePackage
);
758 return EFI_OUT_OF_RESOURCES
;
760 NewBlockPtr
= NewBlock
;
763 // Insert this image package.
765 PackageListNode
->ImagePkg
= ImagePackage
;
766 PackageListNode
->PackageListHdr
.PackageLength
+= ImagePackage
->ImagePkgHdr
.Header
.Length
;
770 // Append the new block here
772 if (ImageIn
->Flags
== EFI_IMAGE_TRANSPARENT
) {
773 *NewBlock
= EFI_HII_IIBT_IMAGE_24BIT_TRANS
;
775 *NewBlock
= EFI_HII_IIBT_IMAGE_24BIT
;
778 CopyMem (NewBlock
, &ImageIn
->Width
, sizeof (UINT16
));
779 NewBlock
+= sizeof (UINT16
);
780 CopyMem (NewBlock
, &ImageIn
->Height
, sizeof (UINT16
));
781 NewBlock
+= sizeof (UINT16
);
782 CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL
*) NewBlock
, ImageIn
->Bitmap
, ImageIn
->Width
* ImageIn
->Height
);
784 CopyMem (ImageBlock
, NewBlockPtr
, NewBlockSize
);
785 FreePool (NewBlockPtr
);
788 // Append the block end
790 ImageBlock
+= NewBlockSize
;
791 ((EFI_HII_IIBT_END_BLOCK
*) (ImageBlock
))->Header
.BlockType
= EFI_HII_IIBT_END
;
798 This function retrieves the image specified by ImageId which is associated with
799 the specified PackageList and copies it into the buffer specified by Image.
801 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
802 @param PackageList Handle of the package list where this image will
804 @param ImageId The image's id,, which is unique within
806 @param Image Points to the image.
808 @retval EFI_SUCCESS The new image was returned successfully.
809 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
810 database. The specified PackageList is not in the database.
811 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to
813 @retval EFI_INVALID_PARAMETER The Image or ImageSize was NULL.
814 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there was not
821 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
822 IN EFI_HII_HANDLE PackageList
,
823 IN EFI_IMAGE_ID ImageId
,
824 OUT EFI_IMAGE_INPUT
*Image
827 HII_DATABASE_PRIVATE_DATA
*Private
;
829 HII_DATABASE_RECORD
*DatabaseRecord
;
830 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
831 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
833 EFI_IMAGE_ID LocalImageId
;
835 EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit
;
844 if (This
== NULL
|| Image
== NULL
|| ImageId
< 1) {
845 return EFI_INVALID_PARAMETER
;
848 if (!IsHiiHandleValid (PackageList
)) {
849 return EFI_NOT_FOUND
;
852 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
855 // Get the specified package list and image package.
857 PackageListNode
= NULL
;
858 for (Link
= Private
->DatabaseList
.ForwardLink
;
859 Link
!= &Private
->DatabaseList
;
860 Link
= Link
->ForwardLink
862 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
863 if (DatabaseRecord
->Handle
== PackageList
) {
864 PackageListNode
= DatabaseRecord
->PackageList
;
868 if (PackageListNode
== NULL
) {
869 return EFI_NOT_FOUND
;
871 ImagePackage
= PackageListNode
->ImagePkg
;
872 if (ImagePackage
== NULL
) {
873 return EFI_NOT_FOUND
;
877 // Find the image block specified by ImageId
879 LocalImageId
= ImageId
;
880 ImageBlock
= GetImageIdOrAddress (ImagePackage
->ImageBlock
, &LocalImageId
);
881 if (ImageBlock
== NULL
) {
882 return EFI_NOT_FOUND
;
886 BlockType
= *ImageBlock
;
889 case EFI_HII_IIBT_IMAGE_JPEG
:
891 // BUGBUG: need to be supported as soon as image tool is designed.
893 return EFI_UNSUPPORTED
;
895 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
896 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
897 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
902 case EFI_HII_IIBT_IMAGE_1BIT
:
903 case EFI_HII_IIBT_IMAGE_4BIT
:
904 case EFI_HII_IIBT_IMAGE_8BIT
:
906 // Use the common block code since the definition of these structures is the same.
908 CopyMem (&Iibt1bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
));
909 ImageLength
= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) *
910 (Iibt1bit
.Bitmap
.Width
* Iibt1bit
.Bitmap
.Height
);
911 Image
->Bitmap
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (ImageLength
);
912 if (Image
->Bitmap
== NULL
) {
913 return EFI_OUT_OF_RESOURCES
;
917 Image
->Flags
= EFI_IMAGE_TRANSPARENT
;
919 Image
->Width
= Iibt1bit
.Bitmap
.Width
;
920 Image
->Height
= Iibt1bit
.Bitmap
.Height
;
922 PaletteInfo
= ImagePackage
->PaletteBlock
+ sizeof (EFI_HII_IMAGE_PALETTE_INFO_HEADER
);
923 for (PaletteIndex
= 1; PaletteIndex
< Iibt1bit
.PaletteIndex
; PaletteIndex
++) {
924 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
925 PaletteInfo
+= PaletteSize
+ sizeof (UINT16
);
927 ASSERT (PaletteIndex
== Iibt1bit
.PaletteIndex
);
930 // Output bitmap data
932 if (BlockType
== EFI_HII_IIBT_IMAGE_1BIT
|| BlockType
== EFI_HII_IIBT_IMAGE_1BIT_TRANS
) {
935 (UINT8
*) ((UINTN
)ImageBlock
+ sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
) - sizeof (UINT8
)),
936 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
938 } else if (BlockType
== EFI_HII_IIBT_IMAGE_4BIT
|| BlockType
== EFI_HII_IIBT_IMAGE_4BIT_TRANS
) {
941 (UINT8
*) ((UINTN
)ImageBlock
+ sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
) - sizeof (UINT8
)),
942 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
947 (UINT8
*) ((UINTN
)ImageBlock
+ sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
) - sizeof (UINT8
)),
948 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
954 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
959 case EFI_HII_IIBT_IMAGE_24BIT
:
960 CopyMem (&Width
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (UINT16
));
963 ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT16
),
966 ImageLength
= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * (Width
* Height
);
967 Image
->Bitmap
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (ImageLength
);
968 if (Image
->Bitmap
== NULL
) {
969 return EFI_OUT_OF_RESOURCES
;
973 Image
->Flags
= EFI_IMAGE_TRANSPARENT
;
975 Image
->Width
= Width
;
976 Image
->Height
= Height
;
979 // Output the bimap data directly.
983 (EFI_HII_RGB_PIXEL
*) (ImageBlock
+ sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
))
988 return EFI_NOT_FOUND
;
994 This function updates the image specified by ImageId in the specified PackageListHandle to
995 the image specified by Image.
997 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
998 @param PackageList The package list containing the images.
999 @param ImageId The image's id,, which is unique within
1001 @param Image Points to the image.
1003 @retval EFI_SUCCESS The new image was updated successfully.
1004 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
1005 database. The specified PackageList is not in the database.
1006 @retval EFI_INVALID_PARAMETER The Image was NULL.
1012 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1013 IN EFI_HII_HANDLE PackageList
,
1014 IN EFI_IMAGE_ID ImageId
,
1015 IN CONST EFI_IMAGE_INPUT
*Image
1018 HII_DATABASE_PRIVATE_DATA
*Private
;
1020 HII_DATABASE_RECORD
*DatabaseRecord
;
1021 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1022 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
1024 EFI_IMAGE_ID LocalImageId
;
1026 EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit
;
1027 EFI_HII_IIBT_IMAGE_4BIT_BLOCK Iibt4bit
;
1028 EFI_HII_IIBT_IMAGE_8BIT_BLOCK Iibt8bit
;
1032 UINT32 NewBlockSize
;
1033 UINT32 OldBlockSize
;
1034 EFI_IMAGE_INPUT
*ImageIn
;
1042 if (This
== NULL
|| Image
== NULL
|| ImageId
< 1 || Image
->Bitmap
== NULL
) {
1043 return EFI_INVALID_PARAMETER
;
1046 if (!IsHiiHandleValid (PackageList
)) {
1047 return EFI_NOT_FOUND
;
1050 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1053 // Get the specified package list and image package.
1055 PackageListNode
= NULL
;
1056 for (Link
= Private
->DatabaseList
.ForwardLink
;
1057 Link
!= &Private
->DatabaseList
;
1058 Link
= Link
->ForwardLink
1060 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1061 if (DatabaseRecord
->Handle
== PackageList
) {
1062 PackageListNode
= DatabaseRecord
->PackageList
;
1066 if (PackageListNode
== NULL
) {
1067 return EFI_NOT_FOUND
;
1069 ImagePackage
= PackageListNode
->ImagePkg
;
1070 if (ImagePackage
== NULL
) {
1071 return EFI_NOT_FOUND
;
1075 // Find the image block specified by ImageId
1077 LocalImageId
= ImageId
;
1078 ImageBlock
= GetImageIdOrAddress (ImagePackage
->ImageBlock
, &LocalImageId
);
1079 if (ImageBlock
== NULL
) {
1080 return EFI_NOT_FOUND
;
1083 BlockType
= *ImageBlock
;
1086 // Get the size of original image block. Use some common block code here
1087 // since the definition of some structures is the same.
1089 switch (BlockType
) {
1090 case EFI_HII_IIBT_IMAGE_JPEG
:
1092 // BUGBUG: need to be supported as soon as image tool is designed.
1094 return EFI_UNSUPPORTED
;
1096 case EFI_HII_IIBT_IMAGE_1BIT
:
1097 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
1098 CopyMem (&Iibt1bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
));
1099 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
) - sizeof (UINT8
) +
1100 BITMAP_LEN_1_BIT (Iibt1bit
.Bitmap
.Width
, Iibt1bit
.Bitmap
.Height
);
1102 case EFI_HII_IIBT_IMAGE_4BIT
:
1103 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
1104 CopyMem (&Iibt4bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
));
1105 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
) - sizeof (UINT8
) +
1106 BITMAP_LEN_4_BIT (Iibt4bit
.Bitmap
.Width
, Iibt4bit
.Bitmap
.Height
);
1108 case EFI_HII_IIBT_IMAGE_8BIT
:
1109 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
1110 CopyMem (&Iibt8bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
));
1111 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
) - sizeof (UINT8
) +
1112 BITMAP_LEN_8_BIT (Iibt8bit
.Bitmap
.Width
, Iibt8bit
.Bitmap
.Height
);
1114 case EFI_HII_IIBT_IMAGE_24BIT
:
1115 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
1116 CopyMem (&Width
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (UINT16
));
1119 ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT16
),
1122 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
1123 BITMAP_LEN_24_BIT (Width
, Height
);
1126 return EFI_NOT_FOUND
;
1130 // Create the new image block according to input image.
1132 ImageIn
= (EFI_IMAGE_INPUT
*) Image
;
1133 NewBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
1134 BITMAP_LEN_24_BIT (ImageIn
->Width
, ImageIn
->Height
);
1135 NewBlock
= (UINT8
*) AllocateZeroPool (NewBlockSize
);
1136 if (NewBlock
== NULL
) {
1137 return EFI_OUT_OF_RESOURCES
;
1140 NewBlockPtr
= NewBlock
;
1141 if ((ImageIn
->Flags
& EFI_IMAGE_TRANSPARENT
) == EFI_IMAGE_TRANSPARENT
) {
1142 *NewBlockPtr
= EFI_HII_IIBT_IMAGE_24BIT_TRANS
;
1144 *NewBlockPtr
= EFI_HII_IIBT_IMAGE_24BIT
;
1148 CopyMem (NewBlockPtr
, &ImageIn
->Width
, sizeof (UINT16
));
1149 NewBlockPtr
+= sizeof (UINT16
);
1150 CopyMem (NewBlockPtr
, &ImageIn
->Height
, sizeof (UINT16
));
1151 NewBlockPtr
+= sizeof (UINT16
);
1153 CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL
*) NewBlockPtr
, ImageIn
->Bitmap
, ImageIn
->Width
* ImageIn
->Height
);
1156 // Adjust the image package to remove the original block firstly then add the new block.
1158 BlockSize
= ImagePackage
->ImageBlockSize
+ NewBlockSize
- OldBlockSize
;
1159 Block
= (UINT8
*) AllocateZeroPool (BlockSize
);
1160 if (Block
== NULL
) {
1161 FreePool (NewBlock
);
1162 return EFI_OUT_OF_RESOURCES
;
1166 Part1Size
= (UINT32
) (ImageBlock
- ImagePackage
->ImageBlock
);
1167 Part2Size
= ImagePackage
->ImageBlockSize
- Part1Size
- OldBlockSize
;
1168 CopyMem (BlockPtr
, ImagePackage
->ImageBlock
, Part1Size
);
1169 BlockPtr
+= Part1Size
;
1170 CopyMem (BlockPtr
, NewBlock
, NewBlockSize
);
1171 BlockPtr
+= NewBlockSize
;
1172 CopyMem (BlockPtr
, ImageBlock
+ OldBlockSize
, Part2Size
);
1174 FreePool (ImagePackage
->ImageBlock
);
1175 FreePool (NewBlock
);
1176 ImagePackage
->ImageBlock
= Block
;
1177 ImagePackage
->ImageBlockSize
= BlockSize
;
1178 ImagePackage
->ImagePkgHdr
.Header
.Length
+= NewBlockSize
- OldBlockSize
;
1179 PackageListNode
->PackageListHdr
.PackageLength
+= NewBlockSize
- OldBlockSize
;
1187 This function renders an image to a bitmap or the screen using the specified
1188 color and options. It draws the image on an existing bitmap, allocates a new
1189 bitmap or uses the screen. The images can be clipped.
1191 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1192 @param Flags Describes how the image is to be drawn.
1193 @param Image Points to the image to be displayed.
1194 @param Blt If this points to a non-NULL on entry, this points
1195 to the image, which is Width pixels wide and
1196 Height pixels high. The image will be drawn onto
1197 this image and EFI_HII_DRAW_FLAG_CLIP is implied.
1198 If this points to a NULL on entry, then a buffer
1199 will be allocated to hold the generated image and
1200 the pointer updated on exit. It is the caller's
1201 responsibility to free this buffer.
1202 @param BltX Specifies the offset from the left and top edge of
1203 the output image of the first pixel in the image.
1204 @param BltY Specifies the offset from the left and top edge of
1205 the output image of the first pixel in the image.
1207 @retval EFI_SUCCESS The image was successfully drawn.
1208 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.
1209 @retval EFI_INVALID_PARAMETER The Image or Blt was NULL.
1210 @retval EFI_INVALID_PARAMETER Any combination of Flags is invalid.
1216 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1217 IN EFI_HII_DRAW_FLAGS Flags
,
1218 IN CONST EFI_IMAGE_INPUT
*Image
,
1219 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
1225 HII_DATABASE_PRIVATE_DATA
*Private
;
1226 BOOLEAN Transparent
;
1227 EFI_IMAGE_INPUT
*ImageIn
;
1228 EFI_IMAGE_OUTPUT
*ImageOut
;
1229 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
1237 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1240 if (This
== NULL
|| Image
== NULL
|| Blt
== NULL
) {
1241 return EFI_INVALID_PARAMETER
;
1244 if ((Flags
& EFI_HII_DRAW_FLAG_CLIP
) == EFI_HII_DRAW_FLAG_CLIP
&& *Blt
== NULL
) {
1245 return EFI_INVALID_PARAMETER
;
1248 if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_TRANSPARENT
) {
1249 return EFI_INVALID_PARAMETER
;
1253 ImageIn
= (EFI_IMAGE_INPUT
*) Image
;
1256 // Check whether the image will be drawn transparently or opaquely.
1258 Transparent
= FALSE
;
1259 if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_FORCE_TRANS
) {
1261 } else if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_FORCE_OPAQUE
){
1262 Transparent
= FALSE
;
1265 // Now EFI_HII_DRAW_FLAG_DEFAULT is set, whether image will be drawn depending
1266 // on the image's transparency setting.
1268 if ((ImageIn
->Flags
& EFI_IMAGE_TRANSPARENT
) == EFI_IMAGE_TRANSPARENT
) {
1274 // Image cannot be drawn transparently if Blt points to NULL on entry.
1275 // Currently output to Screen transparently is not supported, either.
1279 return EFI_INVALID_PARAMETER
;
1280 } else if ((Flags
& EFI_HII_DIRECT_TO_SCREEN
) == EFI_HII_DIRECT_TO_SCREEN
) {
1281 return EFI_INVALID_PARAMETER
;
1285 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1288 // When Blt points to a non-NULL on entry, this image will be drawn onto
1289 // this bitmap or screen pointed by "*Blt" and EFI_HII_DRAW_FLAG_CLIP is implied.
1290 // Otherwise a new bitmap will be allocated to hold this image.
1294 // Clip the image by (Width, Height)
1297 Width
= ImageIn
->Width
;
1298 Height
= ImageIn
->Height
;
1300 if (Width
> (*Blt
)->Width
- BltX
) {
1301 Width
= (*Blt
)->Width
- BltX
;
1303 if (Height
> (*Blt
)->Height
- BltY
) {
1304 Height
= (*Blt
)->Height
- BltY
;
1307 BufferLen
= Width
* Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
1308 BltBuffer
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (BufferLen
);
1309 if (BltBuffer
== NULL
) {
1310 return EFI_OUT_OF_RESOURCES
;
1313 if (Width
== ImageIn
->Width
&& Height
== ImageIn
->Height
) {
1314 CopyMem (BltBuffer
, ImageIn
->Bitmap
, BufferLen
);
1316 for (Ypos
= 0; Ypos
< Height
; Ypos
++) {
1317 OffsetY1
= ImageIn
->Width
* Ypos
;
1318 OffsetY2
= Width
* Ypos
;
1319 for (Xpos
= 0; Xpos
< Width
; Xpos
++) {
1320 BltBuffer
[OffsetY2
+ Xpos
] = ImageIn
->Bitmap
[OffsetY1
+ Xpos
];
1326 // Draw the image to existing bitmap or screen depending on flag.
1328 if ((Flags
& EFI_HII_DIRECT_TO_SCREEN
) == EFI_HII_DIRECT_TO_SCREEN
) {
1330 // Caller should make sure the current UGA console is grarphic mode.
1334 // Write the image directly to the output device specified by Screen.
1336 Status
= (*Blt
)->Image
.Screen
->Blt (
1337 (*Blt
)->Image
.Screen
,
1339 EfiBltBufferToVideo
,
1350 // Draw the image onto the existing bitmap specified by Bitmap.
1352 Status
= ImageToBlt (
1364 FreePool (BltBuffer
);
1369 // Allocate a new bitmap to hold the incoming image.
1371 Width
= ImageIn
->Width
+ BltX
;
1372 Height
= ImageIn
->Height
+ BltY
;
1374 BufferLen
= Width
* Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
1375 BltBuffer
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (BufferLen
);
1376 if (BltBuffer
== NULL
) {
1377 return EFI_OUT_OF_RESOURCES
;
1380 ImageOut
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1381 if (ImageOut
== NULL
) {
1382 FreePool (BltBuffer
);
1383 return EFI_OUT_OF_RESOURCES
;
1385 ImageOut
->Width
= (UINT16
) Width
;
1386 ImageOut
->Height
= (UINT16
) Height
;
1387 ImageOut
->Image
.Bitmap
= BltBuffer
;
1390 // BUGBUG: Now all the "blank" pixels are filled with system default background
1391 // color. Not sure if it need to be updated or not.
1393 Status
= GetSystemFont (Private
, &FontInfo
, NULL
);
1394 if (EFI_ERROR (Status
)) {
1395 FreePool (BltBuffer
);
1396 FreePool (ImageOut
);
1399 ASSERT (FontInfo
!= NULL
);
1400 for (Index
= 0; Index
< Width
* Height
; Index
++) {
1401 BltBuffer
[Index
] = FontInfo
->BackgroundColor
;
1403 FreePool (FontInfo
);
1406 // Draw the incoming image to the new created image.
1424 This function renders an image to a bitmap or the screen using the specified
1425 color and options. It draws the image on an existing bitmap, allocates a new
1426 bitmap or uses the screen. The images can be clipped.
1428 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1429 @param Flags Describes how the image is to be drawn.
1430 @param PackageList The package list in the HII database to search for
1431 the specified image.
1432 @param ImageId The image's id, which is unique within
1434 @param Blt If this points to a non-NULL on entry, this points
1435 to the image, which is Width pixels wide and
1436 Height pixels high. The image will be drawn onto
1438 EFI_HII_DRAW_FLAG_CLIP is implied. If this points
1439 to a NULL on entry, then a buffer will be
1440 allocated to hold the generated image and the
1441 pointer updated on exit. It is the caller's
1442 responsibility to free this buffer.
1443 @param BltX Specifies the offset from the left and top edge of
1444 the output image of the first pixel in the image.
1445 @param BltY Specifies the offset from the left and top edge of
1446 the output image of the first pixel in the image.
1448 @retval EFI_SUCCESS The image was successfully drawn.
1449 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.
1450 @retval EFI_INVALID_PARAMETER The Blt was NULL.
1451 @retval EFI_NOT_FOUND The image specified by ImageId is not in the database.
1452 The specified PackageList is not in the database.
1458 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1459 IN EFI_HII_DRAW_FLAGS Flags
,
1460 IN EFI_HII_HANDLE PackageList
,
1461 IN EFI_IMAGE_ID ImageId
,
1462 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
1468 EFI_IMAGE_INPUT Image
;
1471 // Check input parameter.
1473 if (This
== NULL
|| Blt
== NULL
) {
1474 return EFI_INVALID_PARAMETER
;
1477 if (!IsHiiHandleValid (PackageList
)) {
1478 return EFI_NOT_FOUND
;
1482 // Get the specified Image.
1484 Status
= HiiGetImage (This
, PackageList
, ImageId
, &Image
);
1485 if (EFI_ERROR (Status
)) {
1492 Status
= HiiDrawImage (This
, Flags
, &Image
, Blt
, BltX
, BltY
);
1493 if (Image
.Bitmap
!= NULL
) {
1494 FreePool (Image
.Bitmap
);