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 ImageBlocks 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.
36 IN EFI_HII_IMAGE_BLOCK
*ImageBlocks
,
37 IN OUT EFI_IMAGE_ID
*ImageId
40 EFI_IMAGE_ID ImageIdCurrent
;
41 EFI_HII_IMAGE_BLOCK
*CurrentImageBlock
;
44 ASSERT (ImageBlocks
!= NULL
&& ImageId
!= NULL
);
45 CurrentImageBlock
= ImageBlocks
;
48 while (CurrentImageBlock
->BlockType
!= EFI_HII_IIBT_END
) {
50 if (*ImageId
== ImageIdCurrent
) {
52 // If the found image block is a duplicate block, update the ImageId to
53 // find the previous defined image block.
55 if (CurrentImageBlock
->BlockType
== EFI_HII_IIBT_DUPLICATE
) {
56 *ImageId
= ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_DUPLICATE_BLOCK
*) CurrentImageBlock
)->ImageId
);
57 ASSERT (*ImageId
!= ImageIdCurrent
);
58 ASSERT (*ImageId
!= 0);
59 CurrentImageBlock
= ImageBlocks
;
64 return CurrentImageBlock
;
66 if (*ImageId
< ImageIdCurrent
) {
68 // Can not find the specified image block in this image.
73 switch (CurrentImageBlock
->BlockType
) {
74 case EFI_HII_IIBT_EXT1
:
75 Length
= ((EFI_HII_IIBT_EXT1_BLOCK
*) CurrentImageBlock
)->Length
;
77 case EFI_HII_IIBT_EXT2
:
78 Length
= ReadUnaligned16 (&((EFI_HII_IIBT_EXT2_BLOCK
*) CurrentImageBlock
)->Length
);
80 case EFI_HII_IIBT_EXT4
:
81 Length
= ReadUnaligned32 ((VOID
*) &((EFI_HII_IIBT_EXT4_BLOCK
*) CurrentImageBlock
)->Length
);
84 case EFI_HII_IIBT_IMAGE_1BIT
:
85 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
86 Length
= sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
) - sizeof (UINT8
) +
88 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
89 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
94 case EFI_HII_IIBT_IMAGE_4BIT
:
95 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
96 Length
= sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
) - sizeof (UINT8
) +
98 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_4BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
99 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_4BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
104 case EFI_HII_IIBT_IMAGE_8BIT
:
105 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
106 Length
= sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
) - sizeof (UINT8
) +
108 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_8BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
109 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_8BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
114 case EFI_HII_IIBT_IMAGE_24BIT
:
115 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
116 Length
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
118 ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
119 ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
124 case EFI_HII_IIBT_DUPLICATE
:
125 Length
= sizeof (EFI_HII_IIBT_DUPLICATE_BLOCK
);
129 case EFI_HII_IIBT_IMAGE_JPEG
:
130 Length
= ReadUnaligned32 ((VOID
*) &((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Size
);
134 case EFI_HII_IIBT_SKIP1
:
135 Length
= sizeof (EFI_HII_IIBT_SKIP1_BLOCK
);
136 ImageIdCurrent
+= ((EFI_HII_IIBT_SKIP1_BLOCK
*) CurrentImageBlock
)->SkipCount
;
139 case EFI_HII_IIBT_SKIP2
:
140 Length
= sizeof (EFI_HII_IIBT_SKIP2_BLOCK
);
141 ImageIdCurrent
+= ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_SKIP2_BLOCK
*) CurrentImageBlock
)->SkipCount
);
146 // Unknown image blocks can not be skipped, processing halts.
153 CurrentImageBlock
= (EFI_HII_IMAGE_BLOCK
*) ((UINT8
*) CurrentImageBlock
+ Length
);
158 // When ImageId is zero, return the imageid of last image block: EFI_HII_IIBT_END_BLOCK.
161 *ImageId
= ImageIdCurrent
;
162 return CurrentImageBlock
;
171 Convert pixels from EFI_GRAPHICS_OUTPUT_BLT_PIXEL to EFI_HII_RGB_PIXEL style.
173 This is a internal function.
176 @param BitMapOut Pixels in EFI_HII_RGB_PIXEL format.
177 @param BitMapIn Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format.
178 @param PixelNum The number of pixels to be converted.
184 OUT EFI_HII_RGB_PIXEL
*BitMapOut
,
185 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapIn
,
191 ASSERT (BitMapOut
!= NULL
&& BitMapIn
!= NULL
);
193 for (Index
= 0; Index
< PixelNum
; Index
++) {
194 CopyMem (BitMapOut
+ Index
, BitMapIn
+ Index
, sizeof (EFI_HII_RGB_PIXEL
));
200 Convert pixels from EFI_HII_RGB_PIXEL to EFI_GRAPHICS_OUTPUT_BLT_PIXEL style.
202 This is a internal function.
205 @param BitMapOut Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format.
206 @param BitMapIn Pixels in EFI_HII_RGB_PIXEL format.
207 @param PixelNum The number of pixels to be converted.
213 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapOut
,
214 IN EFI_HII_RGB_PIXEL
*BitMapIn
,
220 ASSERT (BitMapOut
!= NULL
&& BitMapIn
!= NULL
);
222 for (Index
= 0; Index
< PixelNum
; Index
++) {
223 CopyMem (BitMapOut
+ Index
, BitMapIn
+ Index
, sizeof (EFI_HII_RGB_PIXEL
));
229 Output pixels in "1 bit per pixel" format to an image.
231 This is a internal function.
234 @param Image Points to the image which will store the pixels.
235 @param Data Stores the value of output pixels, 0 or 1.
236 @param PaletteInfo PaletteInfo which stores the color of the output
237 pixels. First entry corresponds to color 0 and
238 second one to color 1.
244 IN OUT EFI_IMAGE_INPUT
*Image
,
246 IN EFI_HII_IMAGE_PALETTE_INFO
*PaletteInfo
253 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
254 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue
[2];
255 EFI_HII_IMAGE_PALETTE_INFO
*Palette
;
259 ASSERT (Image
!= NULL
&& Data
!= NULL
&& PaletteInfo
!= NULL
);
261 BitMapPtr
= Image
->Bitmap
;
264 // First entry corresponds to color 0 and second entry corresponds to color 1.
267 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
268 PaletteSize
+= sizeof (UINT16
);
269 Palette
= AllocateZeroPool (PaletteSize
);
270 ASSERT (Palette
!= NULL
);
271 if (Palette
== NULL
) {
274 CopyMem (Palette
, PaletteInfo
, PaletteSize
);
276 ZeroMem (PaletteValue
, sizeof (PaletteValue
));
277 CopyRgbToGopPixel (&PaletteValue
[0], &Palette
->PaletteValue
[0], 1);
278 CopyRgbToGopPixel (&PaletteValue
[1], &Palette
->PaletteValue
[1], 1);
282 // Convert the pixel from one bit to corresponding color.
284 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
285 OffsetY
= BITMAP_LEN_1_BIT (Image
->Width
, Ypos
);
287 // All bits in these bytes are meaningful
289 for (Xpos
= 0; Xpos
< Image
->Width
/ 8; Xpos
++) {
290 Byte
= *(Data
+ OffsetY
+ Xpos
);
291 for (Index
= 0; Index
< 8; Index
++) {
292 if ((Byte
& (1 << Index
)) != 0) {
293 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 8 + (8 - Index
- 1)] = PaletteValue
[1];
295 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 8 + (8 - Index
- 1)] = PaletteValue
[0];
300 if (Image
->Width
% 8 != 0) {
302 // Padding bits in this byte should be ignored.
304 Byte
= *(Data
+ OffsetY
+ Xpos
);
305 for (Index
= 0; Index
< Image
->Width
% 8; Index
++) {
306 if ((Byte
& (1 << (8 - Index
- 1))) != 0) {
307 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 8 + Index
] = PaletteValue
[1];
309 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 8 + Index
] = PaletteValue
[0];
318 Output pixels in "4 bit per pixel" format to an image.
320 This is a internal function.
323 @param Image Points to the image which will store the pixels.
324 @param Data Stores the value of output pixels, 0 ~ 15.
325 @param[in] PaletteInfo PaletteInfo which stores the color of the output
326 pixels. Each entry corresponds to a color within
333 IN OUT EFI_IMAGE_INPUT
*Image
,
335 IN EFI_HII_IMAGE_PALETTE_INFO
*PaletteInfo
341 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
342 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue
[16];
343 EFI_HII_IMAGE_PALETTE_INFO
*Palette
;
348 ASSERT (Image
!= NULL
&& Data
!= NULL
&& PaletteInfo
!= NULL
);
350 BitMapPtr
= Image
->Bitmap
;
353 // The bitmap should allocate each color index starting from 0.
356 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
357 PaletteSize
+= sizeof (UINT16
);
358 Palette
= AllocateZeroPool (PaletteSize
);
359 ASSERT (Palette
!= NULL
);
360 if (Palette
== NULL
) {
363 CopyMem (Palette
, PaletteInfo
, PaletteSize
);
364 PaletteNum
= (UINT16
)(Palette
->PaletteSize
/ sizeof (EFI_HII_RGB_PIXEL
));
366 ZeroMem (PaletteValue
, sizeof (PaletteValue
));
367 CopyRgbToGopPixel (PaletteValue
, Palette
->PaletteValue
, PaletteNum
);
371 // Convert the pixel from 4 bit to corresponding color.
373 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
374 OffsetY
= BITMAP_LEN_4_BIT (Image
->Width
, Ypos
);
376 // All bits in these bytes are meaningful
378 for (Xpos
= 0; Xpos
< Image
->Width
/ 2; Xpos
++) {
379 Byte
= *(Data
+ OffsetY
+ Xpos
);
380 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 2] = PaletteValue
[Byte
>> 4];
381 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 2 + 1] = PaletteValue
[Byte
& 0x0F];
384 if (Image
->Width
% 2 != 0) {
386 // Padding bits in this byte should be ignored.
388 Byte
= *(Data
+ OffsetY
+ Xpos
);
389 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 2] = PaletteValue
[Byte
>> 4];
396 Output pixels in "8 bit per pixel" format to an image.
398 This is a internal function.
401 @param Image Points to the image which will store the pixels.
402 @param Data Stores the value of output pixels, 0 ~ 255.
403 @param[in] PaletteInfo PaletteInfo which stores the color of the output
404 pixels. Each entry corresponds to a color within
411 IN OUT EFI_IMAGE_INPUT
*Image
,
413 IN EFI_HII_IMAGE_PALETTE_INFO
*PaletteInfo
419 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
420 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue
[256];
421 EFI_HII_IMAGE_PALETTE_INFO
*Palette
;
426 ASSERT (Image
!= NULL
&& Data
!= NULL
&& PaletteInfo
!= NULL
);
428 BitMapPtr
= Image
->Bitmap
;
431 // The bitmap should allocate each color index starting from 0.
434 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
435 PaletteSize
+= sizeof (UINT16
);
436 Palette
= AllocateZeroPool (PaletteSize
);
437 ASSERT (Palette
!= NULL
);
438 if (Palette
== NULL
) {
441 CopyMem (Palette
, PaletteInfo
, PaletteSize
);
442 PaletteNum
= (UINT16
)(Palette
->PaletteSize
/ sizeof (EFI_HII_RGB_PIXEL
));
443 ZeroMem (PaletteValue
, sizeof (PaletteValue
));
444 CopyRgbToGopPixel (PaletteValue
, Palette
->PaletteValue
, PaletteNum
);
448 // Convert the pixel from 8 bits to corresponding color.
450 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
451 OffsetY
= BITMAP_LEN_8_BIT (Image
->Width
, Ypos
);
453 // All bits are meaningful since the bitmap is 8 bits per pixel.
455 for (Xpos
= 0; Xpos
< Image
->Width
; Xpos
++) {
456 Byte
= *(Data
+ OffsetY
+ Xpos
);
457 BitMapPtr
[OffsetY
+ Xpos
] = PaletteValue
[Byte
];
465 Output pixels in "24 bit per pixel" format to an image.
467 This is a internal function.
470 @param Image Points to the image which will store the pixels.
471 @param Data Stores the color of output pixels, allowing 16.8
478 IN OUT EFI_IMAGE_INPUT
*Image
,
479 IN EFI_HII_RGB_PIXEL
*Data
484 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
486 ASSERT (Image
!= NULL
&& Data
!= NULL
);
488 BitMapPtr
= Image
->Bitmap
;
490 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
491 OffsetY
= BITMAP_LEN_8_BIT (Image
->Width
, Ypos
);
492 CopyRgbToGopPixel (&BitMapPtr
[OffsetY
], &Data
[OffsetY
], Image
->Width
);
499 Convert the image from EFI_IMAGE_INPUT to EFI_IMAGE_OUTPUT format.
501 This is a internal function.
504 @param BltBuffer Buffer points to bitmap data of incoming image.
505 @param BltX Specifies the offset from the left and top edge of
506 the output image of the first pixel in the image.
507 @param BltY Specifies the offset from the left and top edge of
508 the output image of the first pixel in the image.
509 @param Width Width of the incoming image, in pixels.
510 @param Height Height of the incoming image, in pixels.
511 @param Transparent If TRUE, all "off" pixels in the image will be
512 drawn using the pixel value from blt and all other
513 pixels will be copied.
514 @param Blt Buffer points to bitmap data of output image.
516 @retval EFI_SUCCESS The image was successfully converted.
517 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
522 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
,
527 IN BOOLEAN Transparent
,
528 IN OUT EFI_IMAGE_OUTPUT
**Blt
531 EFI_IMAGE_OUTPUT
*ImageOut
;
534 UINTN OffsetY1
; // src buffer
535 UINTN OffsetY2
; // dest buffer
536 EFI_GRAPHICS_OUTPUT_BLT_PIXEL SrcPixel
;
537 EFI_GRAPHICS_OUTPUT_BLT_PIXEL ZeroPixel
;
539 if (BltBuffer
== NULL
|| Blt
== NULL
|| *Blt
== NULL
) {
540 return EFI_INVALID_PARAMETER
;
545 if (Width
+ BltX
> ImageOut
->Width
) {
546 return EFI_INVALID_PARAMETER
;
548 if (Height
+ BltY
> ImageOut
->Height
) {
549 return EFI_INVALID_PARAMETER
;
552 ZeroMem (&ZeroPixel
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
554 for (Ypos
= 0; Ypos
< Height
; Ypos
++) {
555 OffsetY1
= Width
* Ypos
;
556 OffsetY2
= ImageOut
->Width
* (BltY
+ Ypos
);
557 for (Xpos
= 0; Xpos
< Width
; Xpos
++) {
558 SrcPixel
= BltBuffer
[OffsetY1
+ Xpos
];
560 if (CompareMem (&SrcPixel
, &ZeroPixel
, 3) != 0) {
561 ImageOut
->Image
.Bitmap
[OffsetY2
+ BltX
+ Xpos
] = SrcPixel
;
564 ImageOut
->Image
.Bitmap
[OffsetY2
+ BltX
+ Xpos
] = SrcPixel
;
573 Return the HII package list identified by PackageList HII handle.
575 @param Database Pointer to HII database list header.
576 @param PackageList HII handle of the package list to locate.
578 @retval The HII package list instance.
580 HII_DATABASE_PACKAGE_LIST_INSTANCE
*
582 IN LIST_ENTRY
*Database
,
583 IN EFI_HII_HANDLE PackageList
587 HII_DATABASE_RECORD
*Record
;
590 // Get the specified package list and image package.
592 for (Link
= GetFirstNode (Database
);
593 !IsNull (Database
, Link
);
594 Link
= GetNextNode (Database
, Link
)
596 Record
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
597 if (Record
->Handle
== PackageList
) {
598 return Record
->PackageList
;
605 This function adds the image Image to the group of images owned by PackageList, and returns
606 a new image identifier (ImageId).
608 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
609 @param PackageList Handle of the package list where this image will
611 @param ImageId On return, contains the new image id, which is
612 unique within PackageList.
613 @param Image Points to the image.
615 @retval EFI_SUCCESS The new image was added successfully.
616 @retval EFI_NOT_FOUND The specified PackageList could not be found in
618 @retval EFI_OUT_OF_RESOURCES Could not add the image due to lack of resources.
619 @retval EFI_INVALID_PARAMETER Image is NULL or ImageId is NULL.
625 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
626 IN EFI_HII_HANDLE PackageList
,
627 OUT EFI_IMAGE_ID
*ImageId
,
628 IN CONST EFI_IMAGE_INPUT
*Image
631 HII_DATABASE_PRIVATE_DATA
*Private
;
632 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
633 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
639 EFI_IMAGE_INPUT
*ImageIn
;
641 if (This
== NULL
|| ImageId
== NULL
|| Image
== NULL
|| Image
->Bitmap
== NULL
) {
642 return EFI_INVALID_PARAMETER
;
645 if (!IsHiiHandleValid (PackageList
)) {
646 return EFI_NOT_FOUND
;
649 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
650 PackageListNode
= LocatePackageList (&Private
->DatabaseList
, PackageList
);
651 if (PackageListNode
== NULL
) {
652 return EFI_NOT_FOUND
;
655 ImageIn
= (EFI_IMAGE_INPUT
*) Image
;
657 NewBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
658 BITMAP_LEN_24_BIT (ImageIn
->Width
, ImageIn
->Height
);
661 // Get the image package in the package list,
662 // or create a new image package if image package does not exist.
664 if (PackageListNode
->ImagePkg
!= NULL
) {
665 ImagePackage
= PackageListNode
->ImagePkg
;
668 // Output the image id of the incoming image being inserted, which is the
669 // image id of the EFI_HII_IIBT_END block of old image package.
672 GetImageIdOrAddress (ImagePackage
->ImageBlock
, ImageId
);
675 // Update the package's image block by appending the new block to the end.
677 BlockSize
= ImagePackage
->ImageBlockSize
+ NewBlockSize
;
678 ImageBlock
= (UINT8
*) AllocateZeroPool (BlockSize
);
679 if (ImageBlock
== NULL
) {
680 return EFI_OUT_OF_RESOURCES
;
683 // Copy the original content.
687 ImagePackage
->ImageBlock
,
688 ImagePackage
->ImageBlockSize
- sizeof (EFI_HII_IIBT_END_BLOCK
)
690 FreePool (ImagePackage
->ImageBlock
);
691 ImagePackage
->ImageBlock
= (EFI_HII_IMAGE_BLOCK
*) ImageBlock
;
692 ImageBlock
+= ImagePackage
->ImageBlockSize
- sizeof (EFI_HII_IIBT_END_BLOCK
);
694 // Temp memory to store new block.
696 NewBlock
= AllocateZeroPool (NewBlockSize
);
697 if (NewBlock
== NULL
) {
698 FreePool (ImagePackage
->ImageBlock
);
699 return EFI_OUT_OF_RESOURCES
;
701 NewBlockPtr
= NewBlock
;
704 // Update the length record.
706 ImagePackage
->ImageBlockSize
= (UINT32
) BlockSize
;
707 ImagePackage
->ImagePkgHdr
.Header
.Length
+= (UINT32
) NewBlockSize
;
708 PackageListNode
->PackageListHdr
.PackageLength
+= (UINT32
) NewBlockSize
;
712 // The specified package list does not contain image package.
713 // Create one to add this image block.
715 ImagePackage
= (HII_IMAGE_PACKAGE_INSTANCE
*) AllocateZeroPool (sizeof (HII_IMAGE_PACKAGE_INSTANCE
));
716 if (ImagePackage
== NULL
) {
717 return EFI_OUT_OF_RESOURCES
;
720 // Output the image id of the incoming image being inserted, which is the
721 // first image block so that id is initially to one.
724 BlockSize
= sizeof (EFI_HII_IIBT_END_BLOCK
) + NewBlockSize
;
726 // Fill in image package header.
728 ImagePackage
->ImagePkgHdr
.Header
.Length
= (UINT32
) BlockSize
+ sizeof (EFI_HII_IMAGE_PACKAGE_HDR
);
729 ImagePackage
->ImagePkgHdr
.Header
.Type
= EFI_HII_PACKAGE_IMAGES
;
730 ImagePackage
->ImagePkgHdr
.ImageInfoOffset
= sizeof (EFI_HII_IMAGE_PACKAGE_HDR
);
731 ImagePackage
->ImagePkgHdr
.PaletteInfoOffset
= 0;
734 // Fill in palette info.
736 ImagePackage
->PaletteBlock
= NULL
;
737 ImagePackage
->PaletteInfoSize
= 0;
740 // Fill in image blocks.
742 ImagePackage
->ImageBlockSize
= (UINT32
) BlockSize
;
743 ImagePackage
->ImageBlock
= AllocateZeroPool (BlockSize
);
744 if (ImagePackage
->ImageBlock
== NULL
) {
745 FreePool (ImagePackage
);
746 return EFI_OUT_OF_RESOURCES
;
748 ImageBlock
= (UINT8
*) ImagePackage
->ImageBlock
;
751 // Temp memory to store new block.
753 NewBlock
= AllocateZeroPool (NewBlockSize
);
754 if (NewBlock
== NULL
) {
755 FreePool (ImagePackage
->ImageBlock
);
756 FreePool (ImagePackage
);
757 return EFI_OUT_OF_RESOURCES
;
759 NewBlockPtr
= NewBlock
;
762 // Insert this image package.
764 PackageListNode
->ImagePkg
= ImagePackage
;
765 PackageListNode
->PackageListHdr
.PackageLength
+= ImagePackage
->ImagePkgHdr
.Header
.Length
;
769 // Append the new block here
771 if (ImageIn
->Flags
== EFI_IMAGE_TRANSPARENT
) {
772 *NewBlock
= EFI_HII_IIBT_IMAGE_24BIT_TRANS
;
774 *NewBlock
= EFI_HII_IIBT_IMAGE_24BIT
;
777 CopyMem (NewBlock
, &ImageIn
->Width
, sizeof (UINT16
));
778 NewBlock
+= sizeof (UINT16
);
779 CopyMem (NewBlock
, &ImageIn
->Height
, sizeof (UINT16
));
780 NewBlock
+= sizeof (UINT16
);
781 CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL
*) NewBlock
, ImageIn
->Bitmap
, ImageIn
->Width
* ImageIn
->Height
);
783 CopyMem (ImageBlock
, NewBlockPtr
, NewBlockSize
);
784 FreePool (NewBlockPtr
);
787 // Append the block end
789 ImageBlock
+= NewBlockSize
;
790 ((EFI_HII_IIBT_END_BLOCK
*) (ImageBlock
))->Header
.BlockType
= EFI_HII_IIBT_END
;
793 // Check whether need to get the contents of HiiDataBase.
794 // Only after ReadyToBoot to do the export.
796 if (gExportAfterReadyToBoot
) {
797 HiiGetDatabaseInfo(&Private
->HiiDatabase
);
805 This function retrieves the image specified by ImageId which is associated with
806 the specified PackageList and copies it into the buffer specified by Image.
808 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
809 @param PackageList Handle of the package list where this image will
811 @param ImageId The image's id,, which is unique within
813 @param Image Points to the image.
815 @retval EFI_SUCCESS The new image was returned successfully.
816 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
817 database. The specified PackageList is not in the database.
818 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to
820 @retval EFI_INVALID_PARAMETER The Image or ImageSize was NULL.
821 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there was not
828 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
829 IN EFI_HII_HANDLE PackageList
,
830 IN EFI_IMAGE_ID ImageId
,
831 OUT EFI_IMAGE_INPUT
*Image
834 HII_DATABASE_PRIVATE_DATA
*Private
;
835 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
836 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
838 EFI_IMAGE_ID LocalImageId
;
840 EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit
;
849 if (This
== NULL
|| Image
== NULL
|| ImageId
< 1) {
850 return EFI_INVALID_PARAMETER
;
853 if (!IsHiiHandleValid (PackageList
)) {
854 return EFI_NOT_FOUND
;
857 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
858 PackageListNode
= LocatePackageList (&Private
->DatabaseList
, PackageList
);
859 if (PackageListNode
== NULL
) {
860 return EFI_NOT_FOUND
;
862 ImagePackage
= PackageListNode
->ImagePkg
;
863 if (ImagePackage
== NULL
) {
864 return EFI_NOT_FOUND
;
868 // Find the image block specified by ImageId
870 LocalImageId
= ImageId
;
871 ImageBlock
= (UINT8
*) GetImageIdOrAddress (ImagePackage
->ImageBlock
, &LocalImageId
);
872 if (ImageBlock
== NULL
) {
873 return EFI_NOT_FOUND
;
877 BlockType
= *ImageBlock
;
880 case EFI_HII_IIBT_IMAGE_JPEG
:
882 // BUGBUG: need to be supported as soon as image tool is designed.
884 return EFI_UNSUPPORTED
;
886 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
887 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
888 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
893 case EFI_HII_IIBT_IMAGE_1BIT
:
894 case EFI_HII_IIBT_IMAGE_4BIT
:
895 case EFI_HII_IIBT_IMAGE_8BIT
:
897 // Use the common block code since the definition of these structures is the same.
899 CopyMem (&Iibt1bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
));
900 ImageLength
= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) *
901 (Iibt1bit
.Bitmap
.Width
* Iibt1bit
.Bitmap
.Height
);
902 Image
->Bitmap
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (ImageLength
);
903 if (Image
->Bitmap
== NULL
) {
904 return EFI_OUT_OF_RESOURCES
;
908 Image
->Flags
= EFI_IMAGE_TRANSPARENT
;
910 Image
->Width
= Iibt1bit
.Bitmap
.Width
;
911 Image
->Height
= Iibt1bit
.Bitmap
.Height
;
913 PaletteInfo
= ImagePackage
->PaletteBlock
+ sizeof (EFI_HII_IMAGE_PALETTE_INFO_HEADER
);
914 for (PaletteIndex
= 1; PaletteIndex
< Iibt1bit
.PaletteIndex
; PaletteIndex
++) {
915 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
916 PaletteInfo
+= PaletteSize
+ sizeof (UINT16
);
918 ASSERT (PaletteIndex
== Iibt1bit
.PaletteIndex
);
921 // Output bitmap data
923 if (BlockType
== EFI_HII_IIBT_IMAGE_1BIT
|| BlockType
== EFI_HII_IIBT_IMAGE_1BIT_TRANS
) {
926 (UINT8
*) ((UINTN
)ImageBlock
+ sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
) - sizeof (UINT8
)),
927 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
929 } else if (BlockType
== EFI_HII_IIBT_IMAGE_4BIT
|| BlockType
== EFI_HII_IIBT_IMAGE_4BIT_TRANS
) {
932 (UINT8
*) ((UINTN
)ImageBlock
+ sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
) - sizeof (UINT8
)),
933 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
938 (UINT8
*) ((UINTN
)ImageBlock
+ sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
) - sizeof (UINT8
)),
939 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
945 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
950 case EFI_HII_IIBT_IMAGE_24BIT
:
951 CopyMem (&Width
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (UINT16
));
954 ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT16
),
957 ImageLength
= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * (Width
* Height
);
958 Image
->Bitmap
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (ImageLength
);
959 if (Image
->Bitmap
== NULL
) {
960 return EFI_OUT_OF_RESOURCES
;
964 Image
->Flags
= EFI_IMAGE_TRANSPARENT
;
966 Image
->Width
= Width
;
967 Image
->Height
= Height
;
970 // Output the bimap data directly.
974 (EFI_HII_RGB_PIXEL
*) (ImageBlock
+ sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
))
979 return EFI_NOT_FOUND
;
985 This function updates the image specified by ImageId in the specified PackageListHandle to
986 the image specified by Image.
988 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
989 @param PackageList The package list containing the images.
990 @param ImageId The image's id,, which is unique within
992 @param Image Points to the image.
994 @retval EFI_SUCCESS The new image was updated successfully.
995 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
996 database. The specified PackageList is not in the database.
997 @retval EFI_INVALID_PARAMETER The Image was NULL.
1003 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1004 IN EFI_HII_HANDLE PackageList
,
1005 IN EFI_IMAGE_ID ImageId
,
1006 IN CONST EFI_IMAGE_INPUT
*Image
1009 HII_DATABASE_PRIVATE_DATA
*Private
;
1010 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1011 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
1013 EFI_IMAGE_ID LocalImageId
;
1015 EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit
;
1016 EFI_HII_IIBT_IMAGE_4BIT_BLOCK Iibt4bit
;
1017 EFI_HII_IIBT_IMAGE_8BIT_BLOCK Iibt8bit
;
1021 UINT32 NewBlockSize
;
1022 UINT32 OldBlockSize
;
1023 EFI_IMAGE_INPUT
*ImageIn
;
1031 if (This
== NULL
|| Image
== NULL
|| ImageId
< 1 || Image
->Bitmap
== NULL
) {
1032 return EFI_INVALID_PARAMETER
;
1035 if (!IsHiiHandleValid (PackageList
)) {
1036 return EFI_NOT_FOUND
;
1039 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1040 PackageListNode
= LocatePackageList (&Private
->DatabaseList
, PackageList
);
1041 if (PackageListNode
== NULL
) {
1042 return EFI_NOT_FOUND
;
1044 ImagePackage
= PackageListNode
->ImagePkg
;
1045 if (ImagePackage
== NULL
) {
1046 return EFI_NOT_FOUND
;
1050 // Find the image block specified by ImageId
1052 LocalImageId
= ImageId
;
1053 ImageBlock
= (UINT8
*) GetImageIdOrAddress (ImagePackage
->ImageBlock
, &LocalImageId
);
1054 if (ImageBlock
== NULL
) {
1055 return EFI_NOT_FOUND
;
1058 BlockType
= *ImageBlock
;
1061 // Get the size of original image block. Use some common block code here
1062 // since the definition of some structures is the same.
1064 switch (BlockType
) {
1065 case EFI_HII_IIBT_IMAGE_JPEG
:
1067 // BUGBUG: need to be supported as soon as image tool is designed.
1069 return EFI_UNSUPPORTED
;
1071 case EFI_HII_IIBT_IMAGE_1BIT
:
1072 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
1073 CopyMem (&Iibt1bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
));
1074 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
) - sizeof (UINT8
) +
1075 BITMAP_LEN_1_BIT (Iibt1bit
.Bitmap
.Width
, Iibt1bit
.Bitmap
.Height
);
1077 case EFI_HII_IIBT_IMAGE_4BIT
:
1078 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
1079 CopyMem (&Iibt4bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
));
1080 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
) - sizeof (UINT8
) +
1081 BITMAP_LEN_4_BIT (Iibt4bit
.Bitmap
.Width
, Iibt4bit
.Bitmap
.Height
);
1083 case EFI_HII_IIBT_IMAGE_8BIT
:
1084 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
1085 CopyMem (&Iibt8bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
));
1086 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
) - sizeof (UINT8
) +
1087 BITMAP_LEN_8_BIT (Iibt8bit
.Bitmap
.Width
, Iibt8bit
.Bitmap
.Height
);
1089 case EFI_HII_IIBT_IMAGE_24BIT
:
1090 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
1091 CopyMem (&Width
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (UINT16
));
1094 ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT16
),
1097 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
1098 BITMAP_LEN_24_BIT (Width
, Height
);
1101 return EFI_NOT_FOUND
;
1105 // Create the new image block according to input image.
1107 ImageIn
= (EFI_IMAGE_INPUT
*) Image
;
1108 NewBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
1109 BITMAP_LEN_24_BIT (ImageIn
->Width
, ImageIn
->Height
);
1110 NewBlock
= (UINT8
*) AllocateZeroPool (NewBlockSize
);
1111 if (NewBlock
== NULL
) {
1112 return EFI_OUT_OF_RESOURCES
;
1115 NewBlockPtr
= NewBlock
;
1116 if ((ImageIn
->Flags
& EFI_IMAGE_TRANSPARENT
) == EFI_IMAGE_TRANSPARENT
) {
1117 *NewBlockPtr
= EFI_HII_IIBT_IMAGE_24BIT_TRANS
;
1119 *NewBlockPtr
= EFI_HII_IIBT_IMAGE_24BIT
;
1123 CopyMem (NewBlockPtr
, &ImageIn
->Width
, sizeof (UINT16
));
1124 NewBlockPtr
+= sizeof (UINT16
);
1125 CopyMem (NewBlockPtr
, &ImageIn
->Height
, sizeof (UINT16
));
1126 NewBlockPtr
+= sizeof (UINT16
);
1128 CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL
*) NewBlockPtr
, ImageIn
->Bitmap
, ImageIn
->Width
* ImageIn
->Height
);
1131 // Adjust the image package to remove the original block firstly then add the new block.
1133 BlockSize
= ImagePackage
->ImageBlockSize
+ NewBlockSize
- OldBlockSize
;
1134 Block
= (UINT8
*) AllocateZeroPool (BlockSize
);
1135 if (Block
== NULL
) {
1136 FreePool (NewBlock
);
1137 return EFI_OUT_OF_RESOURCES
;
1141 Part1Size
= (UINT32
) (ImageBlock
- (UINT8
*) ImagePackage
->ImageBlock
);
1142 Part2Size
= ImagePackage
->ImageBlockSize
- Part1Size
- OldBlockSize
;
1143 CopyMem (BlockPtr
, ImagePackage
->ImageBlock
, Part1Size
);
1144 BlockPtr
+= Part1Size
;
1145 CopyMem (BlockPtr
, NewBlock
, NewBlockSize
);
1146 BlockPtr
+= NewBlockSize
;
1147 CopyMem (BlockPtr
, ImageBlock
+ OldBlockSize
, Part2Size
);
1149 FreePool (ImagePackage
->ImageBlock
);
1150 FreePool (NewBlock
);
1151 ImagePackage
->ImageBlock
= (EFI_HII_IMAGE_BLOCK
*) Block
;
1152 ImagePackage
->ImageBlockSize
= BlockSize
;
1153 ImagePackage
->ImagePkgHdr
.Header
.Length
+= NewBlockSize
- OldBlockSize
;
1154 PackageListNode
->PackageListHdr
.PackageLength
+= NewBlockSize
- OldBlockSize
;
1157 // Check whether need to get the contents of HiiDataBase.
1158 // Only after ReadyToBoot to do the export.
1160 if (gExportAfterReadyToBoot
) {
1161 HiiGetDatabaseInfo(&Private
->HiiDatabase
);
1170 This function renders an image to a bitmap or the screen using the specified
1171 color and options. It draws the image on an existing bitmap, allocates a new
1172 bitmap or uses the screen. The images can be clipped.
1174 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1175 @param Flags Describes how the image is to be drawn.
1176 @param Image Points to the image to be displayed.
1177 @param Blt If this points to a non-NULL on entry, this points
1178 to the image, which is Width pixels wide and
1179 Height pixels high. The image will be drawn onto
1180 this image and EFI_HII_DRAW_FLAG_CLIP is implied.
1181 If this points to a NULL on entry, then a buffer
1182 will be allocated to hold the generated image and
1183 the pointer updated on exit. It is the caller's
1184 responsibility to free this buffer.
1185 @param BltX Specifies the offset from the left and top edge of
1186 the output image of the first pixel in the image.
1187 @param BltY Specifies the offset from the left and top edge of
1188 the output image of the first pixel in the image.
1190 @retval EFI_SUCCESS The image was successfully drawn.
1191 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.
1192 @retval EFI_INVALID_PARAMETER The Image or Blt was NULL.
1193 @retval EFI_INVALID_PARAMETER Any combination of Flags is invalid.
1199 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1200 IN EFI_HII_DRAW_FLAGS Flags
,
1201 IN CONST EFI_IMAGE_INPUT
*Image
,
1202 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
1208 HII_DATABASE_PRIVATE_DATA
*Private
;
1209 BOOLEAN Transparent
;
1210 EFI_IMAGE_INPUT
*ImageIn
;
1211 EFI_IMAGE_OUTPUT
*ImageOut
;
1212 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
1220 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1223 if (This
== NULL
|| Image
== NULL
|| Blt
== NULL
) {
1224 return EFI_INVALID_PARAMETER
;
1227 if ((Flags
& EFI_HII_DRAW_FLAG_CLIP
) == EFI_HII_DRAW_FLAG_CLIP
&& *Blt
== NULL
) {
1228 return EFI_INVALID_PARAMETER
;
1231 if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_TRANSPARENT
) {
1232 return EFI_INVALID_PARAMETER
;
1236 ImageIn
= (EFI_IMAGE_INPUT
*) Image
;
1239 // Check whether the image will be drawn transparently or opaquely.
1241 Transparent
= FALSE
;
1242 if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_FORCE_TRANS
) {
1244 } else if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_FORCE_OPAQUE
){
1245 Transparent
= FALSE
;
1248 // Now EFI_HII_DRAW_FLAG_DEFAULT is set, whether image will be drawn depending
1249 // on the image's transparency setting.
1251 if ((ImageIn
->Flags
& EFI_IMAGE_TRANSPARENT
) == EFI_IMAGE_TRANSPARENT
) {
1257 // Image cannot be drawn transparently if Blt points to NULL on entry.
1258 // Currently output to Screen transparently is not supported, either.
1262 return EFI_INVALID_PARAMETER
;
1263 } else if ((Flags
& EFI_HII_DIRECT_TO_SCREEN
) == EFI_HII_DIRECT_TO_SCREEN
) {
1264 return EFI_INVALID_PARAMETER
;
1268 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1271 // When Blt points to a non-NULL on entry, this image will be drawn onto
1272 // this bitmap or screen pointed by "*Blt" and EFI_HII_DRAW_FLAG_CLIP is implied.
1273 // Otherwise a new bitmap will be allocated to hold this image.
1277 // Clip the image by (Width, Height)
1280 Width
= ImageIn
->Width
;
1281 Height
= ImageIn
->Height
;
1283 if (Width
> (*Blt
)->Width
- BltX
) {
1284 Width
= (*Blt
)->Width
- BltX
;
1286 if (Height
> (*Blt
)->Height
- BltY
) {
1287 Height
= (*Blt
)->Height
- BltY
;
1290 BufferLen
= Width
* Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
1291 BltBuffer
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (BufferLen
);
1292 if (BltBuffer
== NULL
) {
1293 return EFI_OUT_OF_RESOURCES
;
1296 if (Width
== ImageIn
->Width
&& Height
== ImageIn
->Height
) {
1297 CopyMem (BltBuffer
, ImageIn
->Bitmap
, BufferLen
);
1299 for (Ypos
= 0; Ypos
< Height
; Ypos
++) {
1300 OffsetY1
= ImageIn
->Width
* Ypos
;
1301 OffsetY2
= Width
* Ypos
;
1302 for (Xpos
= 0; Xpos
< Width
; Xpos
++) {
1303 BltBuffer
[OffsetY2
+ Xpos
] = ImageIn
->Bitmap
[OffsetY1
+ Xpos
];
1309 // Draw the image to existing bitmap or screen depending on flag.
1311 if ((Flags
& EFI_HII_DIRECT_TO_SCREEN
) == EFI_HII_DIRECT_TO_SCREEN
) {
1313 // Caller should make sure the current UGA console is grarphic mode.
1317 // Write the image directly to the output device specified by Screen.
1319 Status
= (*Blt
)->Image
.Screen
->Blt (
1320 (*Blt
)->Image
.Screen
,
1322 EfiBltBufferToVideo
,
1333 // Draw the image onto the existing bitmap specified by Bitmap.
1335 Status
= ImageToBlt (
1347 FreePool (BltBuffer
);
1352 // Allocate a new bitmap to hold the incoming image.
1354 Width
= ImageIn
->Width
+ BltX
;
1355 Height
= ImageIn
->Height
+ BltY
;
1357 BufferLen
= Width
* Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
1358 BltBuffer
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (BufferLen
);
1359 if (BltBuffer
== NULL
) {
1360 return EFI_OUT_OF_RESOURCES
;
1363 ImageOut
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1364 if (ImageOut
== NULL
) {
1365 FreePool (BltBuffer
);
1366 return EFI_OUT_OF_RESOURCES
;
1368 ImageOut
->Width
= (UINT16
) Width
;
1369 ImageOut
->Height
= (UINT16
) Height
;
1370 ImageOut
->Image
.Bitmap
= BltBuffer
;
1373 // BUGBUG: Now all the "blank" pixels are filled with system default background
1374 // color. Not sure if it need to be updated or not.
1376 Status
= GetSystemFont (Private
, &FontInfo
, NULL
);
1377 if (EFI_ERROR (Status
)) {
1378 FreePool (BltBuffer
);
1379 FreePool (ImageOut
);
1382 ASSERT (FontInfo
!= NULL
);
1383 for (Index
= 0; Index
< Width
* Height
; Index
++) {
1384 BltBuffer
[Index
] = FontInfo
->BackgroundColor
;
1386 FreePool (FontInfo
);
1389 // Draw the incoming image to the new created image.
1407 This function renders an image to a bitmap or the screen using the specified
1408 color and options. It draws the image on an existing bitmap, allocates a new
1409 bitmap or uses the screen. The images can be clipped.
1411 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1412 @param Flags Describes how the image is to be drawn.
1413 @param PackageList The package list in the HII database to search for
1414 the specified image.
1415 @param ImageId The image's id, which is unique within
1417 @param Blt If this points to a non-NULL on entry, this points
1418 to the image, which is Width pixels wide and
1419 Height pixels high. The image will be drawn onto
1421 EFI_HII_DRAW_FLAG_CLIP is implied. If this points
1422 to a NULL on entry, then a buffer will be
1423 allocated to hold the generated image and the
1424 pointer updated on exit. It is the caller's
1425 responsibility to free this buffer.
1426 @param BltX Specifies the offset from the left and top edge of
1427 the output image of the first pixel in the image.
1428 @param BltY Specifies the offset from the left and top edge of
1429 the output image of the first pixel in the image.
1431 @retval EFI_SUCCESS The image was successfully drawn.
1432 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.
1433 @retval EFI_INVALID_PARAMETER The Blt was NULL.
1434 @retval EFI_NOT_FOUND The image specified by ImageId is not in the database.
1435 The specified PackageList is not in the database.
1441 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1442 IN EFI_HII_DRAW_FLAGS Flags
,
1443 IN EFI_HII_HANDLE PackageList
,
1444 IN EFI_IMAGE_ID ImageId
,
1445 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
1451 EFI_IMAGE_INPUT Image
;
1454 // Check input parameter.
1456 if (This
== NULL
|| Blt
== NULL
) {
1457 return EFI_INVALID_PARAMETER
;
1460 if (!IsHiiHandleValid (PackageList
)) {
1461 return EFI_NOT_FOUND
;
1465 // Get the specified Image.
1467 Status
= HiiGetImage (This
, PackageList
, ImageId
, &Image
);
1468 if (EFI_ERROR (Status
)) {
1475 Status
= HiiDrawImage (This
, Flags
, &Image
, Blt
, BltX
, BltY
);
1476 if (Image
.Bitmap
!= NULL
) {
1477 FreePool (Image
.Bitmap
);