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
= OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK
, Data
) + ReadUnaligned32 ((VOID
*) &((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Size
);
134 case EFI_HII_IIBT_IMAGE_PNG
:
135 Length
= OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK
, Data
) + ReadUnaligned32 ((VOID
*) &((EFI_HII_IIBT_PNG_BLOCK
*) CurrentImageBlock
)->Size
);
139 case EFI_HII_IIBT_SKIP1
:
140 Length
= sizeof (EFI_HII_IIBT_SKIP1_BLOCK
);
141 ImageIdCurrent
+= ((EFI_HII_IIBT_SKIP1_BLOCK
*) CurrentImageBlock
)->SkipCount
;
144 case EFI_HII_IIBT_SKIP2
:
145 Length
= sizeof (EFI_HII_IIBT_SKIP2_BLOCK
);
146 ImageIdCurrent
+= ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_SKIP2_BLOCK
*) CurrentImageBlock
)->SkipCount
);
151 // Unknown image blocks can not be skipped, processing halts.
158 CurrentImageBlock
= (EFI_HII_IMAGE_BLOCK
*) ((UINT8
*) CurrentImageBlock
+ Length
);
163 // When ImageId is zero, return the imageid of last image block: EFI_HII_IIBT_END_BLOCK.
166 *ImageId
= ImageIdCurrent
;
167 return CurrentImageBlock
;
176 Convert pixels from EFI_GRAPHICS_OUTPUT_BLT_PIXEL to EFI_HII_RGB_PIXEL style.
178 This is a internal function.
181 @param BitMapOut Pixels in EFI_HII_RGB_PIXEL format.
182 @param BitMapIn Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format.
183 @param PixelNum The number of pixels to be converted.
189 OUT EFI_HII_RGB_PIXEL
*BitMapOut
,
190 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapIn
,
196 ASSERT (BitMapOut
!= NULL
&& BitMapIn
!= NULL
);
198 for (Index
= 0; Index
< PixelNum
; Index
++) {
199 CopyMem (BitMapOut
+ Index
, BitMapIn
+ Index
, sizeof (EFI_HII_RGB_PIXEL
));
205 Convert pixels from EFI_HII_RGB_PIXEL to EFI_GRAPHICS_OUTPUT_BLT_PIXEL style.
207 This is a internal function.
210 @param BitMapOut Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format.
211 @param BitMapIn Pixels in EFI_HII_RGB_PIXEL format.
212 @param PixelNum The number of pixels to be converted.
218 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapOut
,
219 IN EFI_HII_RGB_PIXEL
*BitMapIn
,
225 ASSERT (BitMapOut
!= NULL
&& BitMapIn
!= NULL
);
227 for (Index
= 0; Index
< PixelNum
; Index
++) {
228 CopyMem (BitMapOut
+ Index
, BitMapIn
+ Index
, sizeof (EFI_HII_RGB_PIXEL
));
234 Output pixels in "1 bit per pixel" format to an image.
236 This is a internal function.
239 @param Image Points to the image which will store the pixels.
240 @param Data Stores the value of output pixels, 0 or 1.
241 @param PaletteInfo PaletteInfo which stores the color of the output
242 pixels. First entry corresponds to color 0 and
243 second one to color 1.
249 IN OUT EFI_IMAGE_INPUT
*Image
,
251 IN EFI_HII_IMAGE_PALETTE_INFO
*PaletteInfo
258 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
259 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue
[2];
260 EFI_HII_IMAGE_PALETTE_INFO
*Palette
;
264 ASSERT (Image
!= NULL
&& Data
!= NULL
&& PaletteInfo
!= NULL
);
266 BitMapPtr
= Image
->Bitmap
;
269 // First entry corresponds to color 0 and second entry corresponds to color 1.
272 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
273 PaletteSize
+= sizeof (UINT16
);
274 Palette
= AllocateZeroPool (PaletteSize
);
275 ASSERT (Palette
!= NULL
);
276 if (Palette
== NULL
) {
279 CopyMem (Palette
, PaletteInfo
, PaletteSize
);
281 ZeroMem (PaletteValue
, sizeof (PaletteValue
));
282 CopyRgbToGopPixel (&PaletteValue
[0], &Palette
->PaletteValue
[0], 1);
283 CopyRgbToGopPixel (&PaletteValue
[1], &Palette
->PaletteValue
[1], 1);
287 // Convert the pixel from one bit to corresponding color.
289 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
290 OffsetY
= BITMAP_LEN_1_BIT (Image
->Width
, Ypos
);
292 // All bits in these bytes are meaningful
294 for (Xpos
= 0; Xpos
< Image
->Width
/ 8; Xpos
++) {
295 Byte
= *(Data
+ OffsetY
+ Xpos
);
296 for (Index
= 0; Index
< 8; Index
++) {
297 if ((Byte
& (1 << Index
)) != 0) {
298 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 8 + (8 - Index
- 1)] = PaletteValue
[1];
300 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 8 + (8 - Index
- 1)] = PaletteValue
[0];
305 if (Image
->Width
% 8 != 0) {
307 // Padding bits in this byte should be ignored.
309 Byte
= *(Data
+ OffsetY
+ Xpos
);
310 for (Index
= 0; Index
< Image
->Width
% 8; Index
++) {
311 if ((Byte
& (1 << (8 - Index
- 1))) != 0) {
312 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 8 + Index
] = PaletteValue
[1];
314 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 8 + Index
] = PaletteValue
[0];
323 Output pixels in "4 bit per pixel" format to an image.
325 This is a internal function.
328 @param Image Points to the image which will store the pixels.
329 @param Data Stores the value of output pixels, 0 ~ 15.
330 @param[in] PaletteInfo PaletteInfo which stores the color of the output
331 pixels. Each entry corresponds to a color within
338 IN OUT EFI_IMAGE_INPUT
*Image
,
340 IN EFI_HII_IMAGE_PALETTE_INFO
*PaletteInfo
346 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
347 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue
[16];
348 EFI_HII_IMAGE_PALETTE_INFO
*Palette
;
353 ASSERT (Image
!= NULL
&& Data
!= NULL
&& PaletteInfo
!= NULL
);
355 BitMapPtr
= Image
->Bitmap
;
358 // The bitmap should allocate each color index starting from 0.
361 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
362 PaletteSize
+= sizeof (UINT16
);
363 Palette
= AllocateZeroPool (PaletteSize
);
364 ASSERT (Palette
!= NULL
);
365 if (Palette
== NULL
) {
368 CopyMem (Palette
, PaletteInfo
, PaletteSize
);
369 PaletteNum
= (UINT16
)(Palette
->PaletteSize
/ sizeof (EFI_HII_RGB_PIXEL
));
371 ZeroMem (PaletteValue
, sizeof (PaletteValue
));
372 CopyRgbToGopPixel (PaletteValue
, Palette
->PaletteValue
, PaletteNum
);
376 // Convert the pixel from 4 bit to corresponding color.
378 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
379 OffsetY
= BITMAP_LEN_4_BIT (Image
->Width
, Ypos
);
381 // All bits in these bytes are meaningful
383 for (Xpos
= 0; Xpos
< Image
->Width
/ 2; Xpos
++) {
384 Byte
= *(Data
+ OffsetY
+ Xpos
);
385 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 2] = PaletteValue
[Byte
>> 4];
386 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 2 + 1] = PaletteValue
[Byte
& 0x0F];
389 if (Image
->Width
% 2 != 0) {
391 // Padding bits in this byte should be ignored.
393 Byte
= *(Data
+ OffsetY
+ Xpos
);
394 BitMapPtr
[Ypos
* Image
->Width
+ Xpos
* 2] = PaletteValue
[Byte
>> 4];
401 Output pixels in "8 bit per pixel" format to an image.
403 This is a internal function.
406 @param Image Points to the image which will store the pixels.
407 @param Data Stores the value of output pixels, 0 ~ 255.
408 @param[in] PaletteInfo PaletteInfo which stores the color of the output
409 pixels. Each entry corresponds to a color within
416 IN OUT EFI_IMAGE_INPUT
*Image
,
418 IN EFI_HII_IMAGE_PALETTE_INFO
*PaletteInfo
424 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
425 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue
[256];
426 EFI_HII_IMAGE_PALETTE_INFO
*Palette
;
431 ASSERT (Image
!= NULL
&& Data
!= NULL
&& PaletteInfo
!= NULL
);
433 BitMapPtr
= Image
->Bitmap
;
436 // The bitmap should allocate each color index starting from 0.
439 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
440 PaletteSize
+= sizeof (UINT16
);
441 Palette
= AllocateZeroPool (PaletteSize
);
442 ASSERT (Palette
!= NULL
);
443 if (Palette
== NULL
) {
446 CopyMem (Palette
, PaletteInfo
, PaletteSize
);
447 PaletteNum
= (UINT16
)(Palette
->PaletteSize
/ sizeof (EFI_HII_RGB_PIXEL
));
448 ZeroMem (PaletteValue
, sizeof (PaletteValue
));
449 CopyRgbToGopPixel (PaletteValue
, Palette
->PaletteValue
, PaletteNum
);
453 // Convert the pixel from 8 bits to corresponding color.
455 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
456 OffsetY
= BITMAP_LEN_8_BIT (Image
->Width
, Ypos
);
458 // All bits are meaningful since the bitmap is 8 bits per pixel.
460 for (Xpos
= 0; Xpos
< Image
->Width
; Xpos
++) {
461 Byte
= *(Data
+ OffsetY
+ Xpos
);
462 BitMapPtr
[OffsetY
+ Xpos
] = PaletteValue
[Byte
];
470 Output pixels in "24 bit per pixel" format to an image.
472 This is a internal function.
475 @param Image Points to the image which will store the pixels.
476 @param Data Stores the color of output pixels, allowing 16.8
483 IN OUT EFI_IMAGE_INPUT
*Image
,
484 IN EFI_HII_RGB_PIXEL
*Data
489 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
491 ASSERT (Image
!= NULL
&& Data
!= NULL
);
493 BitMapPtr
= Image
->Bitmap
;
495 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
496 OffsetY
= BITMAP_LEN_8_BIT (Image
->Width
, Ypos
);
497 CopyRgbToGopPixel (&BitMapPtr
[OffsetY
], &Data
[OffsetY
], Image
->Width
);
504 Convert the image from EFI_IMAGE_INPUT to EFI_IMAGE_OUTPUT format.
506 This is a internal function.
509 @param BltBuffer Buffer points to bitmap data of incoming image.
510 @param BltX Specifies the offset from the left and top edge of
511 the output image of the first pixel in the image.
512 @param BltY Specifies the offset from the left and top edge of
513 the output image of the first pixel in the image.
514 @param Width Width of the incoming image, in pixels.
515 @param Height Height of the incoming image, in pixels.
516 @param Transparent If TRUE, all "off" pixels in the image will be
517 drawn using the pixel value from blt and all other
518 pixels will be copied.
519 @param Blt Buffer points to bitmap data of output image.
521 @retval EFI_SUCCESS The image was successfully converted.
522 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
527 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
,
532 IN BOOLEAN Transparent
,
533 IN OUT EFI_IMAGE_OUTPUT
**Blt
536 EFI_IMAGE_OUTPUT
*ImageOut
;
539 UINTN OffsetY1
; // src buffer
540 UINTN OffsetY2
; // dest buffer
541 EFI_GRAPHICS_OUTPUT_BLT_PIXEL SrcPixel
;
542 EFI_GRAPHICS_OUTPUT_BLT_PIXEL ZeroPixel
;
544 if (BltBuffer
== NULL
|| Blt
== NULL
|| *Blt
== NULL
) {
545 return EFI_INVALID_PARAMETER
;
550 if (Width
+ BltX
> ImageOut
->Width
) {
551 return EFI_INVALID_PARAMETER
;
553 if (Height
+ BltY
> ImageOut
->Height
) {
554 return EFI_INVALID_PARAMETER
;
557 ZeroMem (&ZeroPixel
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
559 for (Ypos
= 0; Ypos
< Height
; Ypos
++) {
560 OffsetY1
= Width
* Ypos
;
561 OffsetY2
= ImageOut
->Width
* (BltY
+ Ypos
);
562 for (Xpos
= 0; Xpos
< Width
; Xpos
++) {
563 SrcPixel
= BltBuffer
[OffsetY1
+ Xpos
];
565 if (CompareMem (&SrcPixel
, &ZeroPixel
, 3) != 0) {
566 ImageOut
->Image
.Bitmap
[OffsetY2
+ BltX
+ Xpos
] = SrcPixel
;
569 ImageOut
->Image
.Bitmap
[OffsetY2
+ BltX
+ Xpos
] = SrcPixel
;
578 Return the HII package list identified by PackageList HII handle.
580 @param Database Pointer to HII database list header.
581 @param PackageList HII handle of the package list to locate.
583 @retval The HII package list instance.
585 HII_DATABASE_PACKAGE_LIST_INSTANCE
*
587 IN LIST_ENTRY
*Database
,
588 IN EFI_HII_HANDLE PackageList
592 HII_DATABASE_RECORD
*Record
;
595 // Get the specified package list and image package.
597 for (Link
= GetFirstNode (Database
);
598 !IsNull (Database
, Link
);
599 Link
= GetNextNode (Database
, Link
)
601 Record
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
602 if (Record
->Handle
== PackageList
) {
603 return Record
->PackageList
;
610 This function adds the image Image to the group of images owned by PackageList, and returns
611 a new image identifier (ImageId).
613 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
614 @param PackageList Handle of the package list where this image will
616 @param ImageId On return, contains the new image id, which is
617 unique within PackageList.
618 @param Image Points to the image.
620 @retval EFI_SUCCESS The new image was added successfully.
621 @retval EFI_NOT_FOUND The specified PackageList could not be found in
623 @retval EFI_OUT_OF_RESOURCES Could not add the image due to lack of resources.
624 @retval EFI_INVALID_PARAMETER Image is NULL or ImageId is NULL.
630 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
631 IN EFI_HII_HANDLE PackageList
,
632 OUT EFI_IMAGE_ID
*ImageId
,
633 IN CONST EFI_IMAGE_INPUT
*Image
636 HII_DATABASE_PRIVATE_DATA
*Private
;
637 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
638 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
639 EFI_HII_IMAGE_BLOCK
*ImageBlocks
;
642 if (This
== NULL
|| ImageId
== NULL
|| Image
== NULL
|| Image
->Bitmap
== NULL
) {
643 return EFI_INVALID_PARAMETER
;
646 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
647 PackageListNode
= LocatePackageList (&Private
->DatabaseList
, PackageList
);
648 if (PackageListNode
== NULL
) {
649 return EFI_NOT_FOUND
;
652 NewBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
653 BITMAP_LEN_24_BIT (Image
->Width
, Image
->Height
);
656 // Get the image package in the package list,
657 // or create a new image package if image package does not exist.
659 if (PackageListNode
->ImagePkg
!= NULL
) {
660 ImagePackage
= PackageListNode
->ImagePkg
;
663 // Output the image id of the incoming image being inserted, which is the
664 // image id of the EFI_HII_IIBT_END block of old image package.
667 GetImageIdOrAddress (ImagePackage
->ImageBlock
, ImageId
);
670 // Update the package's image block by appending the new block to the end.
672 ImageBlocks
= AllocatePool (ImagePackage
->ImageBlockSize
+ NewBlockSize
);
673 if (ImageBlocks
== NULL
) {
674 return EFI_OUT_OF_RESOURCES
;
677 // Copy the original content.
681 ImagePackage
->ImageBlock
,
682 ImagePackage
->ImageBlockSize
- sizeof (EFI_HII_IIBT_END_BLOCK
)
684 FreePool (ImagePackage
->ImageBlock
);
685 ImagePackage
->ImageBlock
= ImageBlocks
;
688 // Point to the very last block.
690 ImageBlocks
= (EFI_HII_IMAGE_BLOCK
*) (
691 (UINT8
*) ImageBlocks
+ ImagePackage
->ImageBlockSize
- sizeof (EFI_HII_IIBT_END_BLOCK
)
694 // Update the length record.
696 ImagePackage
->ImageBlockSize
+= NewBlockSize
;
697 ImagePackage
->ImagePkgHdr
.Header
.Length
+= NewBlockSize
;
698 PackageListNode
->PackageListHdr
.PackageLength
+= NewBlockSize
;
702 // The specified package list does not contain image package.
703 // Create one to add this image block.
705 ImagePackage
= (HII_IMAGE_PACKAGE_INSTANCE
*) AllocateZeroPool (sizeof (HII_IMAGE_PACKAGE_INSTANCE
));
706 if (ImagePackage
== NULL
) {
707 return EFI_OUT_OF_RESOURCES
;
710 // Output the image id of the incoming image being inserted, which is the
711 // first image block so that id is initially to one.
715 // Fill in image package header.
717 ImagePackage
->ImagePkgHdr
.Header
.Length
= sizeof (EFI_HII_IMAGE_PACKAGE_HDR
) + NewBlockSize
+ sizeof (EFI_HII_IIBT_END_BLOCK
);
718 ImagePackage
->ImagePkgHdr
.Header
.Type
= EFI_HII_PACKAGE_IMAGES
;
719 ImagePackage
->ImagePkgHdr
.ImageInfoOffset
= sizeof (EFI_HII_IMAGE_PACKAGE_HDR
);
720 ImagePackage
->ImagePkgHdr
.PaletteInfoOffset
= 0;
723 // Fill in palette info.
725 ImagePackage
->PaletteBlock
= NULL
;
726 ImagePackage
->PaletteInfoSize
= 0;
729 // Fill in image blocks.
731 ImagePackage
->ImageBlockSize
= NewBlockSize
+ sizeof (EFI_HII_IIBT_END_BLOCK
);
732 ImagePackage
->ImageBlock
= AllocateZeroPool (NewBlockSize
+ sizeof (EFI_HII_IIBT_END_BLOCK
));
733 if (ImagePackage
->ImageBlock
== NULL
) {
734 FreePool (ImagePackage
);
735 return EFI_OUT_OF_RESOURCES
;
737 ImageBlocks
= ImagePackage
->ImageBlock
;
740 // Insert this image package.
742 PackageListNode
->ImagePkg
= ImagePackage
;
743 PackageListNode
->PackageListHdr
.PackageLength
+= ImagePackage
->ImagePkgHdr
.Header
.Length
;
747 // Append the new block here
749 if (Image
->Flags
== EFI_IMAGE_TRANSPARENT
) {
750 ImageBlocks
->BlockType
= EFI_HII_IIBT_IMAGE_24BIT_TRANS
;
752 ImageBlocks
->BlockType
= EFI_HII_IIBT_IMAGE_24BIT
;
754 WriteUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) ImageBlocks
)->Bitmap
.Width
, Image
->Width
);
755 WriteUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) ImageBlocks
)->Bitmap
.Height
, Image
->Height
);
756 CopyGopToRgbPixel (((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) ImageBlocks
)->Bitmap
.Bitmap
, Image
->Bitmap
, Image
->Width
* Image
->Height
);
759 // Append the block end
761 ImageBlocks
= (EFI_HII_IMAGE_BLOCK
*) ((UINT8
*) ImageBlocks
+ NewBlockSize
);
762 ImageBlocks
->BlockType
= EFI_HII_IIBT_END
;
765 // Check whether need to get the contents of HiiDataBase.
766 // Only after ReadyToBoot to do the export.
768 if (gExportAfterReadyToBoot
) {
769 HiiGetDatabaseInfo(&Private
->HiiDatabase
);
777 This function retrieves the image specified by ImageId which is associated with
778 the specified PackageList and copies it into the buffer specified by Image.
780 @param Database A pointer to the database list header.
781 @param PackageList Handle of the package list where this image will
783 @param ImageId The image's id,, which is unique within
785 @param Image Points to the image.
786 @param BitmapOnly TRUE to only return the bitmap type image.
787 FALSE to locate image decoder instance to decode image.
789 @retval EFI_SUCCESS The new image was returned successfully.
790 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
791 database. The specified PackageList is not in the database.
792 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to
794 @retval EFI_INVALID_PARAMETER The Image or ImageSize was NULL.
795 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there was not
800 IN LIST_ENTRY
*Database
,
801 IN EFI_HII_HANDLE PackageList
,
802 IN EFI_IMAGE_ID ImageId
,
803 OUT EFI_IMAGE_INPUT
*Image
,
804 IN BOOLEAN BitmapOnly
808 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
809 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
810 EFI_HII_IMAGE_BLOCK
*CurrentImageBlock
;
811 EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit
;
818 EFI_HII_IMAGE_DECODER_PROTOCOL
*Decoder
;
819 EFI_IMAGE_OUTPUT
*ImageOut
;
821 if (Image
== NULL
|| ImageId
== 0) {
822 return EFI_INVALID_PARAMETER
;
825 PackageListNode
= LocatePackageList (Database
, PackageList
);
826 if (PackageListNode
== NULL
) {
827 return EFI_NOT_FOUND
;
829 ImagePackage
= PackageListNode
->ImagePkg
;
830 if (ImagePackage
== NULL
) {
831 return EFI_NOT_FOUND
;
835 // Find the image block specified by ImageId
837 CurrentImageBlock
= GetImageIdOrAddress (ImagePackage
->ImageBlock
, &ImageId
);
838 if (CurrentImageBlock
== NULL
) {
839 return EFI_NOT_FOUND
;
843 switch (CurrentImageBlock
->BlockType
) {
844 case EFI_HII_IIBT_IMAGE_JPEG
:
845 case EFI_HII_IIBT_IMAGE_PNG
:
847 return EFI_UNSUPPORTED
;
851 Decoder
= LocateHiiImageDecoder (CurrentImageBlock
->BlockType
);
852 if (Decoder
== NULL
) {
853 return EFI_UNSUPPORTED
;
856 // Use the common block code since the definition of two structures is the same.
858 ASSERT (OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK
, Data
) == OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK
, Data
));
859 ASSERT (sizeof (((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Data
) ==
860 sizeof (((EFI_HII_IIBT_PNG_BLOCK
*) CurrentImageBlock
)->Data
));
861 ASSERT (OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK
, Size
) == OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK
, Size
));
862 ASSERT (sizeof (((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Size
) ==
863 sizeof (((EFI_HII_IIBT_PNG_BLOCK
*) CurrentImageBlock
)->Size
));
864 Status
= Decoder
->DecodeImage (
866 ((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Data
,
867 ((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Size
,
873 // Spec requires to use the first capable image decoder instance.
874 // The first image decoder instance may fail to decode the image.
876 if (!EFI_ERROR (Status
)) {
877 Image
->Bitmap
= ImageOut
->Image
.Bitmap
;
878 Image
->Height
= ImageOut
->Height
;
879 Image
->Width
= ImageOut
->Width
;
884 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
885 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
886 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
887 Image
->Flags
= EFI_IMAGE_TRANSPARENT
;
891 case EFI_HII_IIBT_IMAGE_1BIT
:
892 case EFI_HII_IIBT_IMAGE_4BIT
:
893 case EFI_HII_IIBT_IMAGE_8BIT
:
895 // Use the common block code since the definition of these structures is the same.
897 CopyMem (&Iibt1bit
, CurrentImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
));
898 ImageLength
= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) *
899 (Iibt1bit
.Bitmap
.Width
* Iibt1bit
.Bitmap
.Height
);
900 Image
->Bitmap
= AllocateZeroPool (ImageLength
);
901 if (Image
->Bitmap
== NULL
) {
902 return EFI_OUT_OF_RESOURCES
;
905 Image
->Width
= Iibt1bit
.Bitmap
.Width
;
906 Image
->Height
= Iibt1bit
.Bitmap
.Height
;
908 PaletteInfo
= ImagePackage
->PaletteBlock
+ sizeof (EFI_HII_IMAGE_PALETTE_INFO_HEADER
);
909 for (PaletteIndex
= 1; PaletteIndex
< Iibt1bit
.PaletteIndex
; PaletteIndex
++) {
910 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
911 PaletteInfo
+= PaletteSize
+ sizeof (UINT16
);
913 ASSERT (PaletteIndex
== Iibt1bit
.PaletteIndex
);
916 // Output bitmap data
918 if (CurrentImageBlock
->BlockType
== EFI_HII_IIBT_IMAGE_1BIT
||
919 CurrentImageBlock
->BlockType
== EFI_HII_IIBT_IMAGE_1BIT_TRANS
) {
922 ((EFI_HII_IIBT_IMAGE_1BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Data
,
923 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
925 } else if (CurrentImageBlock
->BlockType
== EFI_HII_IIBT_IMAGE_4BIT
||
926 CurrentImageBlock
->BlockType
== EFI_HII_IIBT_IMAGE_4BIT_TRANS
) {
929 ((EFI_HII_IIBT_IMAGE_4BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Data
,
930 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
935 ((EFI_HII_IIBT_IMAGE_8BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Data
,
936 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
942 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
943 Image
->Flags
= EFI_IMAGE_TRANSPARENT
;
947 case EFI_HII_IIBT_IMAGE_24BIT
:
948 Width
= ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
);
949 Height
= ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
);
950 ImageLength
= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * (Width
* Height
);
951 Image
->Bitmap
= AllocateZeroPool (ImageLength
);
952 if (Image
->Bitmap
== NULL
) {
953 return EFI_OUT_OF_RESOURCES
;
956 Image
->Width
= Width
;
957 Image
->Height
= Height
;
960 // Output the bitmap data directly.
964 ((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Bitmap
969 return EFI_NOT_FOUND
;
974 This function retrieves the image specified by ImageId which is associated with
975 the specified PackageList and copies it into the buffer specified by Image.
977 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
978 @param PackageList Handle of the package list where this image will
980 @param ImageId The image's id,, which is unique within
982 @param Image Points to the image.
984 @retval EFI_SUCCESS The new image was returned successfully.
985 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
986 database. The specified PackageList is not in the database.
987 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to
989 @retval EFI_INVALID_PARAMETER The Image or ImageSize was NULL.
990 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there was not
997 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
998 IN EFI_HII_HANDLE PackageList
,
999 IN EFI_IMAGE_ID ImageId
,
1000 OUT EFI_IMAGE_INPUT
*Image
1003 HII_DATABASE_PRIVATE_DATA
*Private
;
1004 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1005 return IGetImage (&Private
->DatabaseList
, PackageList
, ImageId
, Image
, TRUE
);
1010 This function updates the image specified by ImageId in the specified PackageListHandle to
1011 the image specified by Image.
1013 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1014 @param PackageList The package list containing the images.
1015 @param ImageId The image's id,, which is unique within
1017 @param Image Points to the image.
1019 @retval EFI_SUCCESS The new image was updated successfully.
1020 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
1021 database. The specified PackageList is not in the database.
1022 @retval EFI_INVALID_PARAMETER The Image was NULL.
1028 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1029 IN EFI_HII_HANDLE PackageList
,
1030 IN EFI_IMAGE_ID ImageId
,
1031 IN CONST EFI_IMAGE_INPUT
*Image
1034 HII_DATABASE_PRIVATE_DATA
*Private
;
1035 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1036 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
1037 EFI_HII_IMAGE_BLOCK
*CurrentImageBlock
;
1038 EFI_HII_IMAGE_BLOCK
*ImageBlocks
;
1039 EFI_HII_IMAGE_BLOCK
*NewImageBlock
;
1040 UINT32 NewBlockSize
;
1041 UINT32 OldBlockSize
;
1045 if (This
== NULL
|| Image
== NULL
|| ImageId
== 0 || Image
->Bitmap
== NULL
) {
1046 return EFI_INVALID_PARAMETER
;
1049 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1050 PackageListNode
= LocatePackageList (&Private
->DatabaseList
, PackageList
);
1051 if (PackageListNode
== NULL
) {
1052 return EFI_NOT_FOUND
;
1054 ImagePackage
= PackageListNode
->ImagePkg
;
1055 if (ImagePackage
== NULL
) {
1056 return EFI_NOT_FOUND
;
1060 // Find the image block specified by ImageId
1062 CurrentImageBlock
= GetImageIdOrAddress (ImagePackage
->ImageBlock
, &ImageId
);
1063 if (CurrentImageBlock
== NULL
) {
1064 return EFI_NOT_FOUND
;
1068 // Get the size of original image block. Use some common block code here
1069 // since the definition of some structures is the same.
1071 switch (CurrentImageBlock
->BlockType
) {
1072 case EFI_HII_IIBT_IMAGE_JPEG
:
1073 OldBlockSize
= OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK
, Data
) + ReadUnaligned32 ((VOID
*) &((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Size
);
1075 case EFI_HII_IIBT_IMAGE_PNG
:
1076 OldBlockSize
= OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK
, Data
) + ReadUnaligned32 ((VOID
*) &((EFI_HII_IIBT_PNG_BLOCK
*) CurrentImageBlock
)->Size
);
1078 case EFI_HII_IIBT_IMAGE_1BIT
:
1079 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
1080 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
) - sizeof (UINT8
) +
1082 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
1083 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
1086 case EFI_HII_IIBT_IMAGE_4BIT
:
1087 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
1088 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
) - sizeof (UINT8
) +
1090 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_4BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
1091 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_4BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
1094 case EFI_HII_IIBT_IMAGE_8BIT
:
1095 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
1096 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
) - sizeof (UINT8
) +
1098 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_8BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
1099 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_8BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
1102 case EFI_HII_IIBT_IMAGE_24BIT
:
1103 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
1104 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
1106 ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
1107 ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
1111 return EFI_NOT_FOUND
;
1115 // Create the new image block according to input image.
1117 NewBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
1118 BITMAP_LEN_24_BIT (Image
->Width
, Image
->Height
);
1120 // Adjust the image package to remove the original block firstly then add the new block.
1122 ImageBlocks
= AllocateZeroPool (ImagePackage
->ImageBlockSize
+ NewBlockSize
- OldBlockSize
);
1123 if (ImageBlocks
== NULL
) {
1124 return EFI_OUT_OF_RESOURCES
;
1127 Part1Size
= (UINT32
) (UINTN
) ((UINT8
*) CurrentImageBlock
- (UINT8
*) ImagePackage
->ImageBlock
);
1128 Part2Size
= ImagePackage
->ImageBlockSize
- Part1Size
- OldBlockSize
;
1129 CopyMem (ImageBlocks
, ImagePackage
->ImageBlock
, Part1Size
);
1132 // Set the new image block
1134 NewImageBlock
= (EFI_HII_IMAGE_BLOCK
*) ((UINT8
*) ImageBlocks
+ Part1Size
);
1135 if ((Image
->Flags
& EFI_IMAGE_TRANSPARENT
) == EFI_IMAGE_TRANSPARENT
) {
1136 NewImageBlock
->BlockType
= EFI_HII_IIBT_IMAGE_24BIT_TRANS
;
1138 NewImageBlock
->BlockType
= EFI_HII_IIBT_IMAGE_24BIT
;
1140 WriteUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) NewImageBlock
)->Bitmap
.Width
, Image
->Width
);
1141 WriteUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) NewImageBlock
)->Bitmap
.Height
, Image
->Height
);
1142 CopyGopToRgbPixel (((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) NewImageBlock
)->Bitmap
.Bitmap
,
1143 Image
->Bitmap
, Image
->Width
* Image
->Height
);
1145 CopyMem ((UINT8
*) NewImageBlock
+ NewBlockSize
, (UINT8
*) CurrentImageBlock
+ OldBlockSize
, Part2Size
);
1147 FreePool (ImagePackage
->ImageBlock
);
1148 ImagePackage
->ImageBlock
= ImageBlocks
;
1149 ImagePackage
->ImageBlockSize
+= NewBlockSize
- OldBlockSize
;
1150 ImagePackage
->ImagePkgHdr
.Header
.Length
+= NewBlockSize
- OldBlockSize
;
1151 PackageListNode
->PackageListHdr
.PackageLength
+= NewBlockSize
- OldBlockSize
;
1154 // Check whether need to get the contents of HiiDataBase.
1155 // Only after ReadyToBoot to do the export.
1157 if (gExportAfterReadyToBoot
) {
1158 HiiGetDatabaseInfo(&Private
->HiiDatabase
);
1167 This function renders an image to a bitmap or the screen using the specified
1168 color and options. It draws the image on an existing bitmap, allocates a new
1169 bitmap or uses the screen. The images can be clipped.
1171 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1172 @param Flags Describes how the image is to be drawn.
1173 @param Image Points to the image to be displayed.
1174 @param Blt If this points to a non-NULL on entry, this points
1175 to the image, which is Width pixels wide and
1176 Height pixels high. The image will be drawn onto
1177 this image and EFI_HII_DRAW_FLAG_CLIP is implied.
1178 If this points to a NULL on entry, then a buffer
1179 will be allocated to hold the generated image and
1180 the pointer updated on exit. It is the caller's
1181 responsibility to free this buffer.
1182 @param BltX Specifies the offset from the left and top edge of
1183 the output image of the first pixel in the image.
1184 @param BltY Specifies the offset from the left and top edge of
1185 the output image of the first pixel in the image.
1187 @retval EFI_SUCCESS The image was successfully drawn.
1188 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.
1189 @retval EFI_INVALID_PARAMETER The Image or Blt was NULL.
1190 @retval EFI_INVALID_PARAMETER Any combination of Flags is invalid.
1196 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1197 IN EFI_HII_DRAW_FLAGS Flags
,
1198 IN CONST EFI_IMAGE_INPUT
*Image
,
1199 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
1205 HII_DATABASE_PRIVATE_DATA
*Private
;
1206 BOOLEAN Transparent
;
1207 EFI_IMAGE_OUTPUT
*ImageOut
;
1208 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
1216 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1219 if (This
== NULL
|| Image
== NULL
|| Blt
== NULL
) {
1220 return EFI_INVALID_PARAMETER
;
1223 if ((Flags
& EFI_HII_DRAW_FLAG_CLIP
) == EFI_HII_DRAW_FLAG_CLIP
&& *Blt
== NULL
) {
1224 return EFI_INVALID_PARAMETER
;
1227 if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_TRANSPARENT
) {
1228 return EFI_INVALID_PARAMETER
;
1234 // Check whether the image will be drawn transparently or opaquely.
1236 Transparent
= FALSE
;
1237 if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_FORCE_TRANS
) {
1239 } else if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_FORCE_OPAQUE
){
1240 Transparent
= FALSE
;
1243 // Now EFI_HII_DRAW_FLAG_DEFAULT is set, whether image will be drawn depending
1244 // on the image's transparency setting.
1246 if ((Image
->Flags
& EFI_IMAGE_TRANSPARENT
) == EFI_IMAGE_TRANSPARENT
) {
1252 // Image cannot be drawn transparently if Blt points to NULL on entry.
1253 // Currently output to Screen transparently is not supported, either.
1257 return EFI_INVALID_PARAMETER
;
1258 } else if ((Flags
& EFI_HII_DIRECT_TO_SCREEN
) == EFI_HII_DIRECT_TO_SCREEN
) {
1259 return EFI_INVALID_PARAMETER
;
1263 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1266 // When Blt points to a non-NULL on entry, this image will be drawn onto
1267 // this bitmap or screen pointed by "*Blt" and EFI_HII_DRAW_FLAG_CLIP is implied.
1268 // Otherwise a new bitmap will be allocated to hold this image.
1272 // Clip the image by (Width, Height)
1275 Width
= Image
->Width
;
1276 Height
= Image
->Height
;
1278 if (Width
> (*Blt
)->Width
- BltX
) {
1279 Width
= (*Blt
)->Width
- BltX
;
1281 if (Height
> (*Blt
)->Height
- BltY
) {
1282 Height
= (*Blt
)->Height
- BltY
;
1285 BufferLen
= Width
* Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
1286 BltBuffer
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (BufferLen
);
1287 if (BltBuffer
== NULL
) {
1288 return EFI_OUT_OF_RESOURCES
;
1291 if (Width
== Image
->Width
&& Height
== Image
->Height
) {
1292 CopyMem (BltBuffer
, Image
->Bitmap
, BufferLen
);
1294 for (Ypos
= 0; Ypos
< Height
; Ypos
++) {
1295 OffsetY1
= Image
->Width
* Ypos
;
1296 OffsetY2
= Width
* Ypos
;
1297 for (Xpos
= 0; Xpos
< Width
; Xpos
++) {
1298 BltBuffer
[OffsetY2
+ Xpos
] = Image
->Bitmap
[OffsetY1
+ Xpos
];
1304 // Draw the image to existing bitmap or screen depending on flag.
1306 if ((Flags
& EFI_HII_DIRECT_TO_SCREEN
) == EFI_HII_DIRECT_TO_SCREEN
) {
1308 // Caller should make sure the current UGA console is grarphic mode.
1312 // Write the image directly to the output device specified by Screen.
1314 Status
= (*Blt
)->Image
.Screen
->Blt (
1315 (*Blt
)->Image
.Screen
,
1317 EfiBltBufferToVideo
,
1328 // Draw the image onto the existing bitmap specified by Bitmap.
1330 Status
= ImageToBlt (
1342 FreePool (BltBuffer
);
1347 // Allocate a new bitmap to hold the incoming image.
1349 Width
= Image
->Width
+ BltX
;
1350 Height
= Image
->Height
+ BltY
;
1352 BufferLen
= Width
* Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
1353 BltBuffer
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (BufferLen
);
1354 if (BltBuffer
== NULL
) {
1355 return EFI_OUT_OF_RESOURCES
;
1358 ImageOut
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1359 if (ImageOut
== NULL
) {
1360 FreePool (BltBuffer
);
1361 return EFI_OUT_OF_RESOURCES
;
1363 ImageOut
->Width
= (UINT16
) Width
;
1364 ImageOut
->Height
= (UINT16
) Height
;
1365 ImageOut
->Image
.Bitmap
= BltBuffer
;
1368 // BUGBUG: Now all the "blank" pixels are filled with system default background
1369 // color. Not sure if it need to be updated or not.
1371 Status
= GetSystemFont (Private
, &FontInfo
, NULL
);
1372 if (EFI_ERROR (Status
)) {
1373 FreePool (BltBuffer
);
1374 FreePool (ImageOut
);
1377 ASSERT (FontInfo
!= NULL
);
1378 for (Index
= 0; Index
< Width
* Height
; Index
++) {
1379 BltBuffer
[Index
] = FontInfo
->BackgroundColor
;
1381 FreePool (FontInfo
);
1384 // Draw the incoming image to the new created image.
1402 This function renders an image to a bitmap or the screen using the specified
1403 color and options. It draws the image on an existing bitmap, allocates a new
1404 bitmap or uses the screen. The images can be clipped.
1406 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1407 @param Flags Describes how the image is to be drawn.
1408 @param PackageList The package list in the HII database to search for
1409 the specified image.
1410 @param ImageId The image's id, which is unique within
1412 @param Blt If this points to a non-NULL on entry, this points
1413 to the image, which is Width pixels wide and
1414 Height pixels high. The image will be drawn onto
1416 EFI_HII_DRAW_FLAG_CLIP is implied. If this points
1417 to a NULL on entry, then a buffer will be
1418 allocated to hold the generated image and the
1419 pointer updated on exit. It is the caller's
1420 responsibility to free this buffer.
1421 @param BltX Specifies the offset from the left and top edge of
1422 the output image of the first pixel in the image.
1423 @param BltY Specifies the offset from the left and top edge of
1424 the output image of the first pixel in the image.
1426 @retval EFI_SUCCESS The image was successfully drawn.
1427 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.
1428 @retval EFI_INVALID_PARAMETER The Blt was NULL.
1429 @retval EFI_NOT_FOUND The image specified by ImageId is not in the database.
1430 The specified PackageList is not in the database.
1436 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1437 IN EFI_HII_DRAW_FLAGS Flags
,
1438 IN EFI_HII_HANDLE PackageList
,
1439 IN EFI_IMAGE_ID ImageId
,
1440 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
1446 EFI_IMAGE_INPUT Image
;
1449 // Check input parameter.
1451 if (This
== NULL
|| Blt
== NULL
) {
1452 return EFI_INVALID_PARAMETER
;
1456 // Get the specified Image.
1458 Status
= HiiGetImage (This
, PackageList
, ImageId
, &Image
);
1459 if (EFI_ERROR (Status
)) {
1466 Status
= HiiDrawImage (This
, Flags
, &Image
, Blt
, BltX
, BltY
);
1467 if (Image
.Bitmap
!= NULL
) {
1468 FreePool (Image
.Bitmap
);