2 Implementation for EFI_HII_IMAGE_PROTOCOL.
5 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "HiiDatabase.h"
13 #define MAX_UINT24 0xFFFFFF
16 Get the imageid of last image block: EFI_HII_IIBT_END_BLOCK when input
17 ImageId is zero, otherwise return the address of the
18 corresponding image block with identifier specified by ImageId.
20 This is a internal function.
22 @param ImageBlocks Points to the beginning of a series of image blocks stored in order.
23 @param ImageId If input ImageId is 0, output the image id of the EFI_HII_IIBT_END_BLOCK;
24 else use this id to find its corresponding image block address.
26 @return The image block address when input ImageId is not zero; otherwise return NULL.
31 IN EFI_HII_IMAGE_BLOCK
*ImageBlocks
,
32 IN OUT EFI_IMAGE_ID
*ImageId
35 EFI_IMAGE_ID ImageIdCurrent
;
36 EFI_HII_IMAGE_BLOCK
*CurrentImageBlock
;
39 ASSERT (ImageBlocks
!= NULL
&& ImageId
!= NULL
);
40 CurrentImageBlock
= ImageBlocks
;
43 while (CurrentImageBlock
->BlockType
!= EFI_HII_IIBT_END
) {
45 if (*ImageId
== ImageIdCurrent
) {
47 // If the found image block is a duplicate block, update the ImageId to
48 // find the previous defined image block.
50 if (CurrentImageBlock
->BlockType
== EFI_HII_IIBT_DUPLICATE
) {
51 *ImageId
= ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_DUPLICATE_BLOCK
*) CurrentImageBlock
)->ImageId
);
52 ASSERT (*ImageId
!= ImageIdCurrent
);
53 ASSERT (*ImageId
!= 0);
54 CurrentImageBlock
= ImageBlocks
;
59 return CurrentImageBlock
;
61 if (*ImageId
< ImageIdCurrent
) {
63 // Can not find the specified image block in this image.
68 switch (CurrentImageBlock
->BlockType
) {
69 case EFI_HII_IIBT_EXT1
:
70 Length
= ((EFI_HII_IIBT_EXT1_BLOCK
*) CurrentImageBlock
)->Length
;
72 case EFI_HII_IIBT_EXT2
:
73 Length
= ReadUnaligned16 (&((EFI_HII_IIBT_EXT2_BLOCK
*) CurrentImageBlock
)->Length
);
75 case EFI_HII_IIBT_EXT4
:
76 Length
= ReadUnaligned32 ((VOID
*) &((EFI_HII_IIBT_EXT4_BLOCK
*) CurrentImageBlock
)->Length
);
79 case EFI_HII_IIBT_IMAGE_1BIT
:
80 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
81 Length
= sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
) - sizeof (UINT8
) +
83 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
84 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
89 case EFI_HII_IIBT_IMAGE_4BIT
:
90 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
91 Length
= sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
) - sizeof (UINT8
) +
93 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_4BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
94 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_4BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
99 case EFI_HII_IIBT_IMAGE_8BIT
:
100 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
101 Length
= sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
) - sizeof (UINT8
) +
103 (UINT32
) ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_8BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
104 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_8BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
109 case EFI_HII_IIBT_IMAGE_24BIT
:
110 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
111 Length
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
113 (UINT32
) ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
114 ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
119 case EFI_HII_IIBT_DUPLICATE
:
120 Length
= sizeof (EFI_HII_IIBT_DUPLICATE_BLOCK
);
124 case EFI_HII_IIBT_IMAGE_JPEG
:
125 Length
= OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK
, Data
) + ReadUnaligned32 ((VOID
*) &((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Size
);
129 case EFI_HII_IIBT_IMAGE_PNG
:
130 Length
= OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK
, Data
) + ReadUnaligned32 ((VOID
*) &((EFI_HII_IIBT_PNG_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
, MIN (PaletteNum
, ARRAY_SIZE (PaletteValue
)));
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
, MIN (PaletteNum
, ARRAY_SIZE (PaletteValue
)));
448 // Convert the pixel from 8 bits to corresponding color.
450 for (Ypos
= 0; Ypos
< Image
->Height
; Ypos
++) {
451 OffsetY
= BITMAP_LEN_8_BIT ((UINT32
) 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 ((UINT32
) 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
;
634 EFI_HII_IMAGE_BLOCK
*ImageBlocks
;
637 if (This
== NULL
|| ImageId
== NULL
|| Image
== NULL
|| Image
->Bitmap
== NULL
) {
638 return EFI_INVALID_PARAMETER
;
641 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
642 PackageListNode
= LocatePackageList (&Private
->DatabaseList
, PackageList
);
643 if (PackageListNode
== NULL
) {
644 return EFI_NOT_FOUND
;
647 EfiAcquireLock (&mHiiDatabaseLock
);
650 // Calcuate the size of new image.
651 // Make sure the size doesn't overflow UINT32.
652 // Note: 24Bit BMP occpuies 3 bytes per pixel.
654 NewBlockSize
= (UINT32
)Image
->Width
* Image
->Height
;
655 if (NewBlockSize
> (MAX_UINT32
- (sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
))) / 3) {
656 return EFI_OUT_OF_RESOURCES
;
658 NewBlockSize
= NewBlockSize
* 3 + (sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
));
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.
679 // Make sure the final package length doesn't overflow.
680 // Length of the package header is represented using 24 bits. So MAX length is MAX_UINT24.
682 if (NewBlockSize
> MAX_UINT24
- ImagePackage
->ImagePkgHdr
.Header
.Length
) {
683 return EFI_OUT_OF_RESOURCES
;
686 // Because ImagePackage->ImageBlockSize < ImagePackage->ImagePkgHdr.Header.Length,
687 // So (ImagePackage->ImageBlockSize + NewBlockSize) <= MAX_UINT24
689 ImageBlocks
= AllocatePool (ImagePackage
->ImageBlockSize
+ NewBlockSize
);
690 if (ImageBlocks
== NULL
) {
691 EfiReleaseLock (&mHiiDatabaseLock
);
692 return EFI_OUT_OF_RESOURCES
;
695 // Copy the original content.
699 ImagePackage
->ImageBlock
,
700 ImagePackage
->ImageBlockSize
- sizeof (EFI_HII_IIBT_END_BLOCK
)
702 FreePool (ImagePackage
->ImageBlock
);
703 ImagePackage
->ImageBlock
= ImageBlocks
;
706 // Point to the very last block.
708 ImageBlocks
= (EFI_HII_IMAGE_BLOCK
*) (
709 (UINT8
*) ImageBlocks
+ ImagePackage
->ImageBlockSize
- sizeof (EFI_HII_IIBT_END_BLOCK
)
712 // Update the length record.
714 ImagePackage
->ImageBlockSize
+= NewBlockSize
;
715 ImagePackage
->ImagePkgHdr
.Header
.Length
+= NewBlockSize
;
716 PackageListNode
->PackageListHdr
.PackageLength
+= NewBlockSize
;
720 // Make sure the final package length doesn't overflow.
721 // Length of the package header is represented using 24 bits. So MAX length is MAX_UINT24.
723 if (NewBlockSize
> MAX_UINT24
- (sizeof (EFI_HII_IMAGE_PACKAGE_HDR
) + sizeof (EFI_HII_IIBT_END_BLOCK
))) {
724 return EFI_OUT_OF_RESOURCES
;
727 // The specified package list does not contain image package.
728 // Create one to add this image block.
730 ImagePackage
= (HII_IMAGE_PACKAGE_INSTANCE
*) AllocateZeroPool (sizeof (HII_IMAGE_PACKAGE_INSTANCE
));
731 if (ImagePackage
== NULL
) {
732 EfiReleaseLock (&mHiiDatabaseLock
);
733 return EFI_OUT_OF_RESOURCES
;
736 // Output the image id of the incoming image being inserted, which is the
737 // first image block so that id is initially to one.
741 // Fill in image package header.
743 ImagePackage
->ImagePkgHdr
.Header
.Length
= sizeof (EFI_HII_IMAGE_PACKAGE_HDR
) + NewBlockSize
+ sizeof (EFI_HII_IIBT_END_BLOCK
);
744 ImagePackage
->ImagePkgHdr
.Header
.Type
= EFI_HII_PACKAGE_IMAGES
;
745 ImagePackage
->ImagePkgHdr
.ImageInfoOffset
= sizeof (EFI_HII_IMAGE_PACKAGE_HDR
);
746 ImagePackage
->ImagePkgHdr
.PaletteInfoOffset
= 0;
749 // Fill in palette info.
751 ImagePackage
->PaletteBlock
= NULL
;
752 ImagePackage
->PaletteInfoSize
= 0;
755 // Fill in image blocks.
757 ImagePackage
->ImageBlockSize
= NewBlockSize
+ sizeof (EFI_HII_IIBT_END_BLOCK
);
758 ImagePackage
->ImageBlock
= AllocateZeroPool (NewBlockSize
+ sizeof (EFI_HII_IIBT_END_BLOCK
));
759 if (ImagePackage
->ImageBlock
== NULL
) {
760 FreePool (ImagePackage
);
761 EfiReleaseLock (&mHiiDatabaseLock
);
762 return EFI_OUT_OF_RESOURCES
;
764 ImageBlocks
= ImagePackage
->ImageBlock
;
767 // Insert this image package.
769 PackageListNode
->ImagePkg
= ImagePackage
;
770 PackageListNode
->PackageListHdr
.PackageLength
+= ImagePackage
->ImagePkgHdr
.Header
.Length
;
774 // Append the new block here
776 if (Image
->Flags
== EFI_IMAGE_TRANSPARENT
) {
777 ImageBlocks
->BlockType
= EFI_HII_IIBT_IMAGE_24BIT_TRANS
;
779 ImageBlocks
->BlockType
= EFI_HII_IIBT_IMAGE_24BIT
;
781 WriteUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) ImageBlocks
)->Bitmap
.Width
, Image
->Width
);
782 WriteUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) ImageBlocks
)->Bitmap
.Height
, Image
->Height
);
783 CopyGopToRgbPixel (((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) ImageBlocks
)->Bitmap
.Bitmap
, Image
->Bitmap
, (UINT32
) Image
->Width
* Image
->Height
);
786 // Append the block end
788 ImageBlocks
= (EFI_HII_IMAGE_BLOCK
*) ((UINT8
*) ImageBlocks
+ NewBlockSize
);
789 ImageBlocks
->BlockType
= EFI_HII_IIBT_END
;
792 // Check whether need to get the contents of HiiDataBase.
793 // Only after ReadyToBoot to do the export.
795 if (gExportAfterReadyToBoot
) {
796 HiiGetDatabaseInfo(&Private
->HiiDatabase
);
799 EfiReleaseLock (&mHiiDatabaseLock
);
806 This function retrieves the image specified by ImageId which is associated with
807 the specified PackageList and copies it into the buffer specified by Image.
809 @param Database A pointer to the database list header.
810 @param PackageList Handle of the package list where this image will
812 @param ImageId The image's id,, which is unique within
814 @param Image Points to the image.
815 @param BitmapOnly TRUE to only return the bitmap type image.
816 FALSE to locate image decoder instance to decode image.
818 @retval EFI_SUCCESS The new image was returned successfully.
819 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
820 database. The specified PackageList is not in the database.
821 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to
823 @retval EFI_INVALID_PARAMETER The Image or ImageSize was NULL.
824 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there was not
829 IN LIST_ENTRY
*Database
,
830 IN EFI_HII_HANDLE PackageList
,
831 IN EFI_IMAGE_ID ImageId
,
832 OUT EFI_IMAGE_INPUT
*Image
,
833 IN BOOLEAN BitmapOnly
837 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
838 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
839 EFI_HII_IMAGE_BLOCK
*CurrentImageBlock
;
840 EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit
;
847 EFI_HII_IMAGE_DECODER_PROTOCOL
*Decoder
;
848 EFI_IMAGE_OUTPUT
*ImageOut
;
850 if (Image
== NULL
|| ImageId
== 0) {
851 return EFI_INVALID_PARAMETER
;
854 PackageListNode
= LocatePackageList (Database
, PackageList
);
855 if (PackageListNode
== NULL
) {
856 return EFI_NOT_FOUND
;
858 ImagePackage
= PackageListNode
->ImagePkg
;
859 if (ImagePackage
== NULL
) {
860 return EFI_NOT_FOUND
;
864 // Find the image block specified by ImageId
866 CurrentImageBlock
= GetImageIdOrAddress (ImagePackage
->ImageBlock
, &ImageId
);
867 if (CurrentImageBlock
== NULL
) {
868 return EFI_NOT_FOUND
;
872 switch (CurrentImageBlock
->BlockType
) {
873 case EFI_HII_IIBT_IMAGE_JPEG
:
874 case EFI_HII_IIBT_IMAGE_PNG
:
876 return EFI_UNSUPPORTED
;
880 Decoder
= LocateHiiImageDecoder (CurrentImageBlock
->BlockType
);
881 if (Decoder
== NULL
) {
882 return EFI_UNSUPPORTED
;
885 // Use the common block code since the definition of two structures is the same.
887 ASSERT (OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK
, Data
) == OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK
, Data
));
888 ASSERT (sizeof (((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Data
) ==
889 sizeof (((EFI_HII_IIBT_PNG_BLOCK
*) CurrentImageBlock
)->Data
));
890 ASSERT (OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK
, Size
) == OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK
, Size
));
891 ASSERT (sizeof (((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Size
) ==
892 sizeof (((EFI_HII_IIBT_PNG_BLOCK
*) CurrentImageBlock
)->Size
));
893 Status
= Decoder
->DecodeImage (
895 ((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Data
,
896 ((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Size
,
902 // Spec requires to use the first capable image decoder instance.
903 // The first image decoder instance may fail to decode the image.
905 if (!EFI_ERROR (Status
)) {
906 Image
->Bitmap
= ImageOut
->Image
.Bitmap
;
907 Image
->Height
= ImageOut
->Height
;
908 Image
->Width
= ImageOut
->Width
;
913 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
914 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
915 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
916 Image
->Flags
= EFI_IMAGE_TRANSPARENT
;
920 case EFI_HII_IIBT_IMAGE_1BIT
:
921 case EFI_HII_IIBT_IMAGE_4BIT
:
922 case EFI_HII_IIBT_IMAGE_8BIT
:
924 // Use the common block code since the definition of these structures is the same.
926 CopyMem (&Iibt1bit
, CurrentImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
));
927 ImageLength
= (UINTN
) Iibt1bit
.Bitmap
.Width
* Iibt1bit
.Bitmap
.Height
;
928 if (ImageLength
> MAX_UINTN
/ sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)) {
929 return EFI_OUT_OF_RESOURCES
;
931 ImageLength
*= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
932 Image
->Bitmap
= AllocateZeroPool (ImageLength
);
933 if (Image
->Bitmap
== NULL
) {
934 return EFI_OUT_OF_RESOURCES
;
937 Image
->Width
= Iibt1bit
.Bitmap
.Width
;
938 Image
->Height
= Iibt1bit
.Bitmap
.Height
;
940 PaletteInfo
= ImagePackage
->PaletteBlock
+ sizeof (EFI_HII_IMAGE_PALETTE_INFO_HEADER
);
941 for (PaletteIndex
= 1; PaletteIndex
< Iibt1bit
.PaletteIndex
; PaletteIndex
++) {
942 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
943 PaletteInfo
+= PaletteSize
+ sizeof (UINT16
);
945 ASSERT (PaletteIndex
== Iibt1bit
.PaletteIndex
);
948 // Output bitmap data
950 if (CurrentImageBlock
->BlockType
== EFI_HII_IIBT_IMAGE_1BIT
||
951 CurrentImageBlock
->BlockType
== EFI_HII_IIBT_IMAGE_1BIT_TRANS
) {
954 ((EFI_HII_IIBT_IMAGE_1BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Data
,
955 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
957 } else if (CurrentImageBlock
->BlockType
== EFI_HII_IIBT_IMAGE_4BIT
||
958 CurrentImageBlock
->BlockType
== EFI_HII_IIBT_IMAGE_4BIT_TRANS
) {
961 ((EFI_HII_IIBT_IMAGE_4BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Data
,
962 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
967 ((EFI_HII_IIBT_IMAGE_8BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Data
,
968 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
974 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
975 Image
->Flags
= EFI_IMAGE_TRANSPARENT
;
979 case EFI_HII_IIBT_IMAGE_24BIT
:
980 Width
= ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
);
981 Height
= ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
);
982 ImageLength
= (UINTN
)Width
* Height
;
983 if (ImageLength
> MAX_UINTN
/ sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)) {
984 return EFI_OUT_OF_RESOURCES
;
986 ImageLength
*= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
987 Image
->Bitmap
= AllocateZeroPool (ImageLength
);
988 if (Image
->Bitmap
== NULL
) {
989 return EFI_OUT_OF_RESOURCES
;
992 Image
->Width
= Width
;
993 Image
->Height
= Height
;
996 // Output the bitmap data directly.
1000 ((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Bitmap
1005 return EFI_NOT_FOUND
;
1010 This function retrieves the image specified by ImageId which is associated with
1011 the specified PackageList and copies it into the buffer specified by Image.
1013 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1014 @param PackageList Handle of the package list where this image will
1016 @param ImageId The image's id,, which is unique within
1018 @param Image Points to the image.
1020 @retval EFI_SUCCESS The new image was returned successfully.
1021 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
1022 database. The specified PackageList is not in the database.
1023 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to
1025 @retval EFI_INVALID_PARAMETER The Image or ImageSize was NULL.
1026 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there was not
1033 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1034 IN EFI_HII_HANDLE PackageList
,
1035 IN EFI_IMAGE_ID ImageId
,
1036 OUT EFI_IMAGE_INPUT
*Image
1039 HII_DATABASE_PRIVATE_DATA
*Private
;
1040 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1041 return IGetImage (&Private
->DatabaseList
, PackageList
, ImageId
, Image
, TRUE
);
1046 This function updates the image specified by ImageId in the specified PackageListHandle to
1047 the image specified by Image.
1049 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1050 @param PackageList The package list containing the images.
1051 @param ImageId The image's id,, which is unique within
1053 @param Image Points to the image.
1055 @retval EFI_SUCCESS The new image was updated successfully.
1056 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
1057 database. The specified PackageList is not in the database.
1058 @retval EFI_INVALID_PARAMETER The Image was NULL.
1064 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1065 IN EFI_HII_HANDLE PackageList
,
1066 IN EFI_IMAGE_ID ImageId
,
1067 IN CONST EFI_IMAGE_INPUT
*Image
1070 HII_DATABASE_PRIVATE_DATA
*Private
;
1071 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1072 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
1073 EFI_HII_IMAGE_BLOCK
*CurrentImageBlock
;
1074 EFI_HII_IMAGE_BLOCK
*ImageBlocks
;
1075 EFI_HII_IMAGE_BLOCK
*NewImageBlock
;
1076 UINT32 NewBlockSize
;
1077 UINT32 OldBlockSize
;
1081 if (This
== NULL
|| Image
== NULL
|| ImageId
== 0 || Image
->Bitmap
== NULL
) {
1082 return EFI_INVALID_PARAMETER
;
1085 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1086 PackageListNode
= LocatePackageList (&Private
->DatabaseList
, PackageList
);
1087 if (PackageListNode
== NULL
) {
1088 return EFI_NOT_FOUND
;
1090 ImagePackage
= PackageListNode
->ImagePkg
;
1091 if (ImagePackage
== NULL
) {
1092 return EFI_NOT_FOUND
;
1096 // Find the image block specified by ImageId
1098 CurrentImageBlock
= GetImageIdOrAddress (ImagePackage
->ImageBlock
, &ImageId
);
1099 if (CurrentImageBlock
== NULL
) {
1100 return EFI_NOT_FOUND
;
1103 EfiAcquireLock (&mHiiDatabaseLock
);
1106 // Get the size of original image block. Use some common block code here
1107 // since the definition of some structures is the same.
1109 switch (CurrentImageBlock
->BlockType
) {
1110 case EFI_HII_IIBT_IMAGE_JPEG
:
1111 OldBlockSize
= OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK
, Data
) + ReadUnaligned32 ((VOID
*) &((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Size
);
1113 case EFI_HII_IIBT_IMAGE_PNG
:
1114 OldBlockSize
= OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK
, Data
) + ReadUnaligned32 ((VOID
*) &((EFI_HII_IIBT_PNG_BLOCK
*) CurrentImageBlock
)->Size
);
1116 case EFI_HII_IIBT_IMAGE_1BIT
:
1117 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
1118 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
) - sizeof (UINT8
) +
1120 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
1121 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
1124 case EFI_HII_IIBT_IMAGE_4BIT
:
1125 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
1126 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
) - sizeof (UINT8
) +
1128 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_4BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
1129 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_4BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
1132 case EFI_HII_IIBT_IMAGE_8BIT
:
1133 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
1134 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
) - sizeof (UINT8
) +
1136 (UINT32
) ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_8BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
1137 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_8BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
1140 case EFI_HII_IIBT_IMAGE_24BIT
:
1141 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
1142 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
1144 (UINT32
) ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
),
1145 ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
)
1149 EfiReleaseLock (&mHiiDatabaseLock
);
1150 return EFI_NOT_FOUND
;
1154 // Create the new image block according to input image.
1158 // Make sure the final package length doesn't overflow.
1159 // Length of the package header is represented using 24 bits. So MAX length is MAX_UINT24.
1160 // 24Bit BMP occpuies 3 bytes per pixel.
1162 NewBlockSize
= (UINT32
)Image
->Width
* Image
->Height
;
1163 if (NewBlockSize
> (MAX_UINT32
- (sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
))) / 3) {
1164 return EFI_OUT_OF_RESOURCES
;
1166 NewBlockSize
= NewBlockSize
* 3 + (sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
));
1167 if ((NewBlockSize
> OldBlockSize
) &&
1168 (NewBlockSize
- OldBlockSize
> MAX_UINT24
- ImagePackage
->ImagePkgHdr
.Header
.Length
)
1170 return EFI_OUT_OF_RESOURCES
;
1174 // Adjust the image package to remove the original block firstly then add the new block.
1176 ImageBlocks
= AllocateZeroPool (ImagePackage
->ImageBlockSize
+ NewBlockSize
- OldBlockSize
);
1177 if (ImageBlocks
== NULL
) {
1178 EfiReleaseLock (&mHiiDatabaseLock
);
1179 return EFI_OUT_OF_RESOURCES
;
1182 Part1Size
= (UINT32
) ((UINTN
) CurrentImageBlock
- (UINTN
) ImagePackage
->ImageBlock
);
1183 Part2Size
= ImagePackage
->ImageBlockSize
- Part1Size
- OldBlockSize
;
1184 CopyMem (ImageBlocks
, ImagePackage
->ImageBlock
, Part1Size
);
1187 // Set the new image block
1189 NewImageBlock
= (EFI_HII_IMAGE_BLOCK
*) ((UINT8
*) ImageBlocks
+ Part1Size
);
1190 if ((Image
->Flags
& EFI_IMAGE_TRANSPARENT
) == EFI_IMAGE_TRANSPARENT
) {
1191 NewImageBlock
->BlockType
= EFI_HII_IIBT_IMAGE_24BIT_TRANS
;
1193 NewImageBlock
->BlockType
= EFI_HII_IIBT_IMAGE_24BIT
;
1195 WriteUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) NewImageBlock
)->Bitmap
.Width
, Image
->Width
);
1196 WriteUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) NewImageBlock
)->Bitmap
.Height
, Image
->Height
);
1197 CopyGopToRgbPixel (((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) NewImageBlock
)->Bitmap
.Bitmap
,
1198 Image
->Bitmap
, (UINT32
) Image
->Width
* Image
->Height
);
1200 CopyMem ((UINT8
*) NewImageBlock
+ NewBlockSize
, (UINT8
*) CurrentImageBlock
+ OldBlockSize
, Part2Size
);
1202 FreePool (ImagePackage
->ImageBlock
);
1203 ImagePackage
->ImageBlock
= ImageBlocks
;
1204 ImagePackage
->ImageBlockSize
+= NewBlockSize
- OldBlockSize
;
1205 ImagePackage
->ImagePkgHdr
.Header
.Length
+= NewBlockSize
- OldBlockSize
;
1206 PackageListNode
->PackageListHdr
.PackageLength
+= NewBlockSize
- OldBlockSize
;
1209 // Check whether need to get the contents of HiiDataBase.
1210 // Only after ReadyToBoot to do the export.
1212 if (gExportAfterReadyToBoot
) {
1213 HiiGetDatabaseInfo(&Private
->HiiDatabase
);
1216 EfiReleaseLock (&mHiiDatabaseLock
);
1223 This function renders an image to a bitmap or the screen using the specified
1224 color and options. It draws the image on an existing bitmap, allocates a new
1225 bitmap or uses the screen. The images can be clipped.
1227 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1228 @param Flags Describes how the image is to be drawn.
1229 @param Image Points to the image to be displayed.
1230 @param Blt If this points to a non-NULL on entry, this points
1231 to the image, which is Width pixels wide and
1232 Height pixels high. The image will be drawn onto
1233 this image and EFI_HII_DRAW_FLAG_CLIP is implied.
1234 If this points to a NULL on entry, then a buffer
1235 will be allocated to hold the generated image and
1236 the pointer updated on exit. It is the caller's
1237 responsibility to free this buffer.
1238 @param BltX Specifies the offset from the left and top edge of
1239 the output image of the first pixel in the image.
1240 @param BltY Specifies the offset from the left and top edge of
1241 the output image of the first pixel in the image.
1243 @retval EFI_SUCCESS The image was successfully drawn.
1244 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.
1245 @retval EFI_INVALID_PARAMETER The Image or Blt was NULL.
1246 @retval EFI_INVALID_PARAMETER Any combination of Flags is invalid.
1252 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1253 IN EFI_HII_DRAW_FLAGS Flags
,
1254 IN CONST EFI_IMAGE_INPUT
*Image
,
1255 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
1261 HII_DATABASE_PRIVATE_DATA
*Private
;
1262 BOOLEAN Transparent
;
1263 EFI_IMAGE_OUTPUT
*ImageOut
;
1264 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
1272 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1275 if (This
== NULL
|| Image
== NULL
|| Blt
== NULL
) {
1276 return EFI_INVALID_PARAMETER
;
1279 if ((Flags
& EFI_HII_DRAW_FLAG_CLIP
) == EFI_HII_DRAW_FLAG_CLIP
&& *Blt
== NULL
) {
1280 return EFI_INVALID_PARAMETER
;
1283 if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_TRANSPARENT
) {
1284 return EFI_INVALID_PARAMETER
;
1290 // Check whether the image will be drawn transparently or opaquely.
1292 Transparent
= FALSE
;
1293 if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_FORCE_TRANS
) {
1295 } else if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_FORCE_OPAQUE
){
1296 Transparent
= FALSE
;
1299 // Now EFI_HII_DRAW_FLAG_DEFAULT is set, whether image will be drawn depending
1300 // on the image's transparency setting.
1302 if ((Image
->Flags
& EFI_IMAGE_TRANSPARENT
) == EFI_IMAGE_TRANSPARENT
) {
1308 // Image cannot be drawn transparently if Blt points to NULL on entry.
1309 // Currently output to Screen transparently is not supported, either.
1313 return EFI_INVALID_PARAMETER
;
1314 } else if ((Flags
& EFI_HII_DIRECT_TO_SCREEN
) == EFI_HII_DIRECT_TO_SCREEN
) {
1315 return EFI_INVALID_PARAMETER
;
1319 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1322 // When Blt points to a non-NULL on entry, this image will be drawn onto
1323 // this bitmap or screen pointed by "*Blt" and EFI_HII_DRAW_FLAG_CLIP is implied.
1324 // Otherwise a new bitmap will be allocated to hold this image.
1328 // Make sure the BltX and BltY is inside the Blt area.
1330 if ((BltX
>= (*Blt
)->Width
) || (BltY
>= (*Blt
)->Height
)) {
1331 return EFI_INVALID_PARAMETER
;
1335 // Clip the image by (Width, Height)
1338 Width
= Image
->Width
;
1339 Height
= Image
->Height
;
1341 if (Width
> (*Blt
)->Width
- (UINT16
)BltX
) {
1342 Width
= (*Blt
)->Width
- (UINT16
)BltX
;
1344 if (Height
> (*Blt
)->Height
- (UINT16
)BltY
) {
1345 Height
= (*Blt
)->Height
- (UINT16
)BltY
;
1349 // Prepare the buffer for the temporary image.
1350 // Make sure the buffer size doesn't overflow UINTN.
1352 BufferLen
= Width
* Height
;
1353 if (BufferLen
> MAX_UINTN
/ sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)) {
1354 return EFI_OUT_OF_RESOURCES
;
1356 BufferLen
*= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
1357 BltBuffer
= AllocateZeroPool (BufferLen
);
1358 if (BltBuffer
== NULL
) {
1359 return EFI_OUT_OF_RESOURCES
;
1362 if (Width
== Image
->Width
&& Height
== Image
->Height
) {
1363 CopyMem (BltBuffer
, Image
->Bitmap
, BufferLen
);
1365 for (Ypos
= 0; Ypos
< Height
; Ypos
++) {
1366 OffsetY1
= Image
->Width
* Ypos
;
1367 OffsetY2
= Width
* Ypos
;
1368 for (Xpos
= 0; Xpos
< Width
; Xpos
++) {
1369 BltBuffer
[OffsetY2
+ Xpos
] = Image
->Bitmap
[OffsetY1
+ Xpos
];
1375 // Draw the image to existing bitmap or screen depending on flag.
1377 if ((Flags
& EFI_HII_DIRECT_TO_SCREEN
) == EFI_HII_DIRECT_TO_SCREEN
) {
1379 // Caller should make sure the current UGA console is grarphic mode.
1383 // Write the image directly to the output device specified by Screen.
1385 Status
= (*Blt
)->Image
.Screen
->Blt (
1386 (*Blt
)->Image
.Screen
,
1388 EfiBltBufferToVideo
,
1399 // Draw the image onto the existing bitmap specified by Bitmap.
1401 Status
= ImageToBlt (
1413 FreePool (BltBuffer
);
1418 // Allocate a new bitmap to hold the incoming image.
1422 // Make sure the final width and height doesn't overflow UINT16.
1424 if ((BltX
> (UINTN
)MAX_UINT16
- Image
->Width
) || (BltY
> (UINTN
)MAX_UINT16
- Image
->Height
)) {
1425 return EFI_INVALID_PARAMETER
;
1428 Width
= Image
->Width
+ (UINT16
)BltX
;
1429 Height
= Image
->Height
+ (UINT16
)BltY
;
1432 // Make sure the output image size doesn't overflow UINTN.
1434 BufferLen
= Width
* Height
;
1435 if (BufferLen
> MAX_UINTN
/ sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)) {
1436 return EFI_OUT_OF_RESOURCES
;
1438 BufferLen
*= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
1439 BltBuffer
= AllocateZeroPool (BufferLen
);
1440 if (BltBuffer
== NULL
) {
1441 return EFI_OUT_OF_RESOURCES
;
1444 ImageOut
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1445 if (ImageOut
== NULL
) {
1446 FreePool (BltBuffer
);
1447 return EFI_OUT_OF_RESOURCES
;
1449 ImageOut
->Width
= Width
;
1450 ImageOut
->Height
= Height
;
1451 ImageOut
->Image
.Bitmap
= BltBuffer
;
1454 // BUGBUG: Now all the "blank" pixels are filled with system default background
1455 // color. Not sure if it need to be updated or not.
1457 Status
= GetSystemFont (Private
, &FontInfo
, NULL
);
1458 if (EFI_ERROR (Status
)) {
1459 FreePool (BltBuffer
);
1460 FreePool (ImageOut
);
1463 ASSERT (FontInfo
!= NULL
);
1464 for (Index
= 0; Index
< (UINTN
)Width
* Height
; Index
++) {
1465 BltBuffer
[Index
] = FontInfo
->BackgroundColor
;
1467 FreePool (FontInfo
);
1470 // Draw the incoming image to the new created image.
1488 This function renders an image to a bitmap or the screen using the specified
1489 color and options. It draws the image on an existing bitmap, allocates a new
1490 bitmap or uses the screen. The images can be clipped.
1492 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1493 @param Flags Describes how the image is to be drawn.
1494 @param PackageList The package list in the HII database to search for
1495 the specified image.
1496 @param ImageId The image's id, which is unique within
1498 @param Blt If this points to a non-NULL on entry, this points
1499 to the image, which is Width pixels wide and
1500 Height pixels high. The image will be drawn onto
1502 EFI_HII_DRAW_FLAG_CLIP is implied. If this points
1503 to a NULL on entry, then a buffer will be
1504 allocated to hold the generated image and the
1505 pointer updated on exit. It is the caller's
1506 responsibility to free this buffer.
1507 @param BltX Specifies the offset from the left and top edge of
1508 the output image of the first pixel in the image.
1509 @param BltY Specifies the offset from the left and top edge of
1510 the output image of the first pixel in the image.
1512 @retval EFI_SUCCESS The image was successfully drawn.
1513 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.
1514 @retval EFI_INVALID_PARAMETER The Blt was NULL.
1515 @retval EFI_NOT_FOUND The image specified by ImageId is not in the database.
1516 The specified PackageList is not in the database.
1522 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1523 IN EFI_HII_DRAW_FLAGS Flags
,
1524 IN EFI_HII_HANDLE PackageList
,
1525 IN EFI_IMAGE_ID ImageId
,
1526 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
1532 EFI_IMAGE_INPUT Image
;
1535 // Check input parameter.
1537 if (This
== NULL
|| Blt
== NULL
) {
1538 return EFI_INVALID_PARAMETER
;
1542 // Get the specified Image.
1544 Status
= HiiGetImage (This
, PackageList
, ImageId
, &Image
);
1545 if (EFI_ERROR (Status
)) {
1552 Status
= HiiDrawImage (This
, Flags
, &Image
, Blt
, BltX
, BltY
);
1553 if (Image
.Bitmap
!= NULL
) {
1554 FreePool (Image
.Bitmap
);