3 Copyright (c) 2007 - 2008, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Implementation for EFI_HII_IMAGE_PROTOCOL.
26 #include "HiiDatabase.h"
28 #ifndef DISABLE_UNUSED_HII_PROTOCOLS
34 IN OUT EFI_IMAGE_ID
*ImageId
39 Get the imageid of last image block: EFI_HII_IIBT_END_BLOCK when input
40 ImageId is zero, otherwise return the address of the
41 corresponding image block with identifier specified by ImageId.
44 ImageBlock - Points to the beginning of a series of image blocks stored in order.
45 ImageId - If input ImageId is 0, output the image id of the EFI_HII_IIBT_END_BLOCK;
46 else use this id to find its corresponding image block address.
49 The image block address when input ImageId is not zero; otherwise return NULL.
53 EFI_IMAGE_ID ImageIdCurrent
;
58 EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit
;
59 EFI_HII_IIBT_IMAGE_4BIT_BLOCK Iibt4bit
;
60 EFI_HII_IIBT_IMAGE_8BIT_BLOCK Iibt8bit
;
64 ASSERT (ImageBlock
!= NULL
&& ImageId
!= NULL
);
66 ImageBlockHdr
= ImageBlock
;
69 while (((EFI_HII_IMAGE_BLOCK
*) ImageBlock
)->BlockType
!= EFI_HII_IIBT_END
) {
71 if (*ImageId
== ImageIdCurrent
) {
73 // If the found image block is a duplicate block, update the ImageId to
74 // find the previous defined image block.
76 if (((EFI_HII_IMAGE_BLOCK
*) ImageBlock
)->BlockType
== EFI_HII_IIBT_DUPLICATE
) {
77 CopyMem (ImageId
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (EFI_IMAGE_ID
));
78 ASSERT (*ImageId
!= ImageIdCurrent
);
79 ImageBlock
= ImageBlockHdr
;
86 if (*ImageId
< ImageIdCurrent
) {
88 // Can not find the specified image block in this image.
93 switch (((EFI_HII_IMAGE_BLOCK
*) ImageBlock
)->BlockType
) {
94 case EFI_HII_IIBT_EXT1
:
95 Length8
= *(ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT8
));
96 ImageBlock
+= Length8
;
99 case EFI_HII_IIBT_EXT2
:
102 ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT8
),
105 ImageBlock
+= Length16
;
108 case EFI_HII_IIBT_EXT4
:
111 ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT8
),
114 ImageBlock
+= Length32
;
118 case EFI_HII_IIBT_IMAGE_1BIT
:
119 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
120 CopyMem (&Iibt1bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
));
121 ImageBlock
+= sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
) - sizeof (UINT8
) +
122 BITMAP_LEN_1_BIT (Iibt1bit
.Bitmap
.Width
, Iibt1bit
.Bitmap
.Height
);
126 case EFI_HII_IIBT_IMAGE_4BIT
:
127 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
128 CopyMem (&Iibt4bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
));
129 ImageBlock
+= sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
) - sizeof (UINT8
) +
130 BITMAP_LEN_4_BIT (Iibt4bit
.Bitmap
.Width
, Iibt4bit
.Bitmap
.Height
);
134 case EFI_HII_IIBT_IMAGE_8BIT
:
135 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
136 CopyMem (&Iibt8bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
));
137 ImageBlock
+= sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
) - sizeof (UINT8
) +
138 BITMAP_LEN_8_BIT (Iibt8bit
.Bitmap
.Width
, Iibt8bit
.Bitmap
.Height
);
142 case EFI_HII_IIBT_IMAGE_24BIT
:
143 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
144 CopyMem (&Width
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (UINT16
));
147 ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT16
),
150 ImageBlock
+= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
151 BITMAP_LEN_24_BIT (Width
, Height
);
155 case EFI_HII_IIBT_DUPLICATE
:
156 ImageBlock
+= sizeof (EFI_HII_IIBT_DUPLICATE_BLOCK
);
160 case EFI_HII_IIBT_IMAGE_JPEG
:
161 CopyMem (&Length32
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (UINT32
));
162 ImageBlock
+= Length32
;
166 case EFI_HII_IIBT_SKIP1
:
167 Length8
= *(ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
));
168 ImageBlock
+= sizeof (EFI_HII_IIBT_SKIP1_BLOCK
);
169 ImageIdCurrent
= (UINT16
) (ImageIdCurrent
+ Length8
);
172 case EFI_HII_IIBT_SKIP2
:
173 CopyMem (&Length16
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (UINT16
));
174 ImageBlock
+= sizeof (EFI_HII_IIBT_SKIP2_BLOCK
);
175 ImageIdCurrent
= (UINT16
) (ImageIdCurrent
+ Length16
);
180 // Unknown image blocks can not be skipped, processing halts.
187 // When ImageId is zero, return the imageid of last image block: EFI_HII_IIBT_END_BLOCK.
190 *ImageId
= ImageIdCurrent
;
200 Convert pixels from EFI_GRAPHICS_OUTPUT_BLT_PIXEL to EFI_HII_RGB_PIXEL style.
202 @param BitMapOut Pixels in EFI_HII_RGB_PIXEL format.
203 @param BitMapIn Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format.
204 @param PixelNum The number of pixels to be converted.
211 OUT EFI_HII_RGB_PIXEL
*BitMapOut
,
212 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapIn
,
218 ASSERT (BitMapOut
!= NULL
&& BitMapIn
!= NULL
);
220 for (Index
= 0; Index
< PixelNum
; Index
++) {
221 CopyMem (BitMapOut
+ Index
, BitMapIn
+ Index
, sizeof (EFI_HII_RGB_PIXEL
));
227 Convert pixels from EFI_HII_RGB_PIXEL to EFI_GRAPHICS_OUTPUT_BLT_PIXEL style.
229 @param BitMapOut Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format.
230 @param BitMapIn Pixels in EFI_HII_RGB_PIXEL format.
231 @param PixelNum The number of pixels to be converted.
238 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapOut
,
239 IN EFI_HII_RGB_PIXEL
*BitMapIn
,
245 ASSERT (BitMapOut
!= NULL
&& BitMapIn
!= NULL
);
247 for (Index
= 0; Index
< PixelNum
; Index
++) {
248 CopyMem (BitMapOut
+ Index
, BitMapIn
+ Index
, sizeof (EFI_HII_RGB_PIXEL
));
254 Output pixels in "1 bit per pixel" format to an image.
256 @param Image Points to the image which will store the pixels.
257 @param Data Stores the value of output pixels, 0 or 1.
258 @param PaletteInfo PaletteInfo which stores the color of the output
259 pixels. First entry corresponds to color 0 and
260 second one to color 1.
267 IN OUT EFI_IMAGE_INPUT
*Image
,
269 IN EFI_HII_IMAGE_PALETTE_INFO
*PaletteInfo
276 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
277 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue
[2];
278 EFI_HII_IMAGE_PALETTE_INFO
*Palette
;
282 ASSERT (Image
!= NULL
&& Data
!= NULL
&& PaletteInfo
!= NULL
);
284 BitMapPtr
= Image
->Bitmap
;
287 // First entry corresponds to color 0 and second entry corresponds to color 1.
289 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
290 PaletteSize
+= sizeof (UINT16
);
291 Palette
= AllocateZeroPool (PaletteSize
);
292 ASSERT (Palette
!= NULL
);
293 CopyMem (Palette
, PaletteInfo
, PaletteSize
);
295 ZeroMem (PaletteValue
, sizeof (PaletteValue
));
296 CopyRgbToGopPixel (&PaletteValue
[0], &Palette
->PaletteValue
[0], 1);
297 CopyRgbToGopPixel (&PaletteValue
[1], &Palette
->PaletteValue
[1], 1);
298 SafeFreePool (Palette
);
301 // Convert the pixel from one bit to corresponding color.
303 for (Y
= 0; Y
< Image
->Height
; Y
++) {
304 OffsetY
= BITMAP_LEN_1_BIT (Image
->Width
, Y
);
306 // All bits in these bytes are meaningful
308 for (X
= 0; X
< Image
->Width
/ 8; X
++) {
309 Byte
= *(Data
+ OffsetY
+ X
);
310 for (Index
= 0; Index
< 8; Index
++) {
311 if ((Byte
& (1 << Index
)) != 0) {
312 BitMapPtr
[Y
* Image
->Width
+ X
* 8 + (8 - Index
- 1)] = PaletteValue
[1];
314 BitMapPtr
[Y
* Image
->Width
+ X
* 8 + (8 - Index
- 1)] = PaletteValue
[0];
319 if (Image
->Width
% 8 != 0) {
321 // Padding bits in this byte should be ignored.
323 Byte
= *(Data
+ OffsetY
+ X
);
324 for (Index
= 0; Index
< Image
->Width
% 8; Index
++) {
325 if ((Byte
& (1 << (8 - Index
- 1))) != 0) {
326 BitMapPtr
[Y
* Image
->Width
+ X
* 8 + Index
] = PaletteValue
[1];
328 BitMapPtr
[Y
* Image
->Width
+ X
* 8 + Index
] = PaletteValue
[0];
337 Output pixels in "4 bit per pixel" format to an image.
339 @param Image Points to the image which will store the pixels.
340 @param Data Stores the value of output pixels, 0 ~ 15.
341 @param PaletteInfo PaletteInfo which stores the color of the output
342 pixels. Each entry corresponds to a color within
350 IN OUT EFI_IMAGE_INPUT
*Image
,
352 IN EFI_HII_IMAGE_PALETTE_INFO
*PaletteInfo
358 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
359 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue
[16];
360 EFI_HII_IMAGE_PALETTE_INFO
*Palette
;
365 ASSERT (Image
!= NULL
&& Data
!= NULL
&& PaletteInfo
!= NULL
);
367 BitMapPtr
= Image
->Bitmap
;
370 // The bitmap should allocate each color index starting from 0.
372 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
373 PaletteSize
+= sizeof (UINT16
);
374 Palette
= AllocateZeroPool (PaletteSize
);
375 ASSERT (Palette
!= NULL
);
376 CopyMem (Palette
, PaletteInfo
, PaletteSize
);
377 PaletteNum
= (UINT16
)(Palette
->PaletteSize
/ sizeof (EFI_HII_RGB_PIXEL
));
379 ZeroMem (PaletteValue
, sizeof (PaletteValue
));
380 CopyRgbToGopPixel (PaletteValue
, Palette
->PaletteValue
, PaletteNum
);
381 SafeFreePool (Palette
);
384 // Convert the pixel from 4 bit to corresponding color.
386 for (Y
= 0; Y
< Image
->Height
; Y
++) {
387 OffsetY
= BITMAP_LEN_4_BIT (Image
->Width
, Y
);
389 // All bits in these bytes are meaningful
391 for (X
= 0; X
< Image
->Width
/ 2; X
++) {
392 Byte
= *(Data
+ OffsetY
+ X
);
393 BitMapPtr
[Y
* Image
->Width
+ X
* 2] = PaletteValue
[Byte
>> 4];
394 BitMapPtr
[Y
* Image
->Width
+ X
* 2 + 1] = PaletteValue
[Byte
& 0x0F];
397 if (Image
->Width
% 2 != 0) {
399 // Padding bits in this byte should be ignored.
401 Byte
= *(Data
+ OffsetY
+ X
);
402 BitMapPtr
[Y
* Image
->Width
+ X
* 2] = PaletteValue
[Byte
>> 4];
409 Output pixels in "8 bit per pixel" format to an image.
411 @param Image Points to the image which will store the pixels.
412 @param Data Stores the value of output pixels, 0 ~ 255.
413 @param PaletteInfo PaletteInfo which stores the color of the output
414 pixels. Each entry corresponds to a color within
422 IN OUT EFI_IMAGE_INPUT
*Image
,
424 IN EFI_HII_IMAGE_PALETTE_INFO
*PaletteInfo
430 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BitMapPtr
;
431 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue
[256];
432 EFI_HII_IMAGE_PALETTE_INFO
*Palette
;
437 ASSERT (Image
!= NULL
&& Data
!= NULL
&& PaletteInfo
!= NULL
);
439 BitMapPtr
= Image
->Bitmap
;
442 // The bitmap should allocate each color index starting from 0.
444 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
445 PaletteSize
+= sizeof (UINT16
);
446 Palette
= AllocateZeroPool (PaletteSize
);
447 ASSERT (Palette
!= NULL
);
448 CopyMem (Palette
, PaletteInfo
, PaletteSize
);
449 PaletteNum
= (UINT16
)(Palette
->PaletteSize
/ sizeof (EFI_HII_RGB_PIXEL
));
450 ZeroMem (PaletteValue
, sizeof (PaletteValue
));
451 CopyRgbToGopPixel (PaletteValue
, Palette
->PaletteValue
, PaletteNum
);
452 SafeFreePool (Palette
);
455 // Convert the pixel from 8 bits to corresponding color.
457 for (Y
= 0; Y
< Image
->Height
; Y
++) {
458 OffsetY
= BITMAP_LEN_8_BIT (Image
->Width
, Y
);
460 // All bits are meaningful since the bitmap is 8 bits per pixel.
462 for (X
= 0; X
< Image
->Width
; X
++) {
463 Byte
= *(Data
+ OffsetY
+ X
);
464 BitMapPtr
[OffsetY
+ X
] = PaletteValue
[Byte
];
472 Output pixels in "24 bit per pixel" format to an image.
474 @param Image Points to the image which will store the pixels.
475 @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 (Y
= 0; Y
< Image
->Height
; Y
++) {
496 OffsetY
= BITMAP_LEN_8_BIT (Image
->Width
, Y
);
497 CopyRgbToGopPixel (&BitMapPtr
[OffsetY
], &Data
[OffsetY
], Image
->Width
);
504 Convert the image from EFI_IMAGE_INPUT to EFI_IMAGE_OUTPUT format.
506 @param BltBuffer Buffer points to bitmap data of incoming 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.
523 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
,
528 IN BOOLEAN Transparent
,
529 IN OUT EFI_IMAGE_OUTPUT
**Blt
532 EFI_IMAGE_OUTPUT
*ImageOut
;
535 UINTN OffsetY1
; // src buffer
536 UINTN OffsetY2
; // dest buffer
537 EFI_GRAPHICS_OUTPUT_BLT_PIXEL SrcPixel
;
538 EFI_GRAPHICS_OUTPUT_BLT_PIXEL ZeroPixel
;
540 if (BltBuffer
== NULL
|| Blt
== NULL
|| *Blt
== NULL
) {
541 return EFI_INVALID_PARAMETER
;
546 if (Width
+ BltX
> ImageOut
->Width
) {
547 return EFI_INVALID_PARAMETER
;
549 if (Height
+ BltY
> ImageOut
->Height
) {
550 return EFI_INVALID_PARAMETER
;
553 ZeroMem (&ZeroPixel
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
555 for (Y
= 0; Y
< Height
; Y
++) {
556 OffsetY1
= Width
* Y
;
557 OffsetY2
= ImageOut
->Width
* (BltY
+ Y
);
558 for (X
= 0; X
< Width
; X
++) {
559 SrcPixel
= BltBuffer
[OffsetY1
+ X
];
561 if (CompareMem (&SrcPixel
, &ZeroPixel
, 3) != 0) {
562 ImageOut
->Image
.Bitmap
[OffsetY2
+ BltX
+ X
] = SrcPixel
;
565 ImageOut
->Image
.Bitmap
[OffsetY2
+ BltX
+ X
] = SrcPixel
;
575 This function adds the image Image to the group of images owned by PackageList, and returns
576 a new image identifier (ImageId).
578 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
579 @param PackageList Handle of the package list where this image will
581 @param ImageId On return, contains the new image id, which is
582 unique within PackageList.
583 @param Image Points to the image.
585 @retval EFI_SUCCESS The new image was added successfully.
586 @retval EFI_NOT_FOUND The specified PackageList could not be found in
588 @retval EFI_OUT_OF_RESOURCES Could not add the image due to lack of resources.
589 @retval EFI_INVALID_PARAMETER Image is NULL or ImageId is NULL.
595 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
596 IN EFI_HII_HANDLE PackageList
,
597 OUT EFI_IMAGE_ID
*ImageId
,
598 IN CONST EFI_IMAGE_INPUT
*Image
601 HII_DATABASE_PRIVATE_DATA
*Private
;
603 HII_DATABASE_RECORD
*DatabaseRecord
;
604 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
605 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
611 EFI_IMAGE_INPUT
*ImageIn
;
613 if (This
== NULL
|| ImageId
== NULL
|| Image
== NULL
|| Image
->Bitmap
== NULL
) {
614 return EFI_INVALID_PARAMETER
;
617 if (!IsHiiHandleValid (PackageList
)) {
618 return EFI_NOT_FOUND
;
621 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
624 // Get the specified package list
627 PackageListNode
= NULL
;
629 for (Link
= Private
->DatabaseList
.ForwardLink
;
630 Link
!= &Private
->DatabaseList
;
631 Link
= Link
->ForwardLink
633 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
634 if (DatabaseRecord
->Handle
== PackageList
) {
635 PackageListNode
= DatabaseRecord
->PackageList
;
640 if (PackageListNode
== NULL
) {
641 return EFI_NOT_FOUND
;
644 ImageIn
= (EFI_IMAGE_INPUT
*) Image
;
646 NewBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
647 BITMAP_LEN_24_BIT (ImageIn
->Width
, ImageIn
->Height
);
650 // Get the image package in the package list,
651 // or create a new image package if image package does not exist.
653 if (PackageListNode
->ImagePkg
!= NULL
) {
654 ImagePackage
= PackageListNode
->ImagePkg
;
657 // Output the image id of the incoming image being inserted, which is the
658 // image id of the EFI_HII_IIBT_END block of old image package.
661 GetImageIdOrAddress (ImagePackage
->ImageBlock
, ImageId
);
664 // Update the package's image block by appending the new block to the end.
666 BlockSize
= ImagePackage
->ImageBlockSize
+ NewBlockSize
;
667 ImageBlock
= (UINT8
*) AllocateZeroPool (BlockSize
);
668 if (ImageBlock
== NULL
) {
669 return EFI_OUT_OF_RESOURCES
;
672 // Copy the original content.
676 ImagePackage
->ImageBlock
,
677 ImagePackage
->ImageBlockSize
- sizeof (EFI_HII_IIBT_END_BLOCK
)
679 SafeFreePool (ImagePackage
->ImageBlock
);
680 ImagePackage
->ImageBlock
= ImageBlock
;
681 ImageBlock
+= ImagePackage
->ImageBlockSize
- sizeof (EFI_HII_IIBT_END_BLOCK
);
683 // Temp memory to store new block.
685 NewBlock
= AllocateZeroPool (NewBlockSize
);
686 if (NewBlock
== NULL
) {
687 SafeFreePool (ImagePackage
->ImageBlock
);
688 ImagePackage
->ImageBlock
= NULL
;
689 return EFI_OUT_OF_RESOURCES
;
691 NewBlockPtr
= NewBlock
;
694 // Update the length record.
696 ImagePackage
->ImageBlockSize
= (UINT32
) BlockSize
;
697 ImagePackage
->ImagePkgHdr
.Header
.Length
+= (UINT32
) NewBlockSize
;
698 PackageListNode
->PackageListHdr
.PackageLength
+= (UINT32
) 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.
714 BlockSize
= sizeof (EFI_HII_IIBT_END_BLOCK
) + NewBlockSize
;
716 // Fill in image package header.
718 ImagePackage
->ImagePkgHdr
.Header
.Length
= (UINT32
) BlockSize
+ sizeof (EFI_HII_IMAGE_PACKAGE_HDR
);
719 ImagePackage
->ImagePkgHdr
.Header
.Type
= EFI_HII_PACKAGE_IMAGES
;
720 ImagePackage
->ImagePkgHdr
.ImageInfoOffset
= sizeof (EFI_HII_IMAGE_PACKAGE_HDR
);
721 ImagePackage
->ImagePkgHdr
.PaletteInfoOffset
= 0;
724 // Fill in palette info.
726 ImagePackage
->PaletteBlock
= NULL
;
727 ImagePackage
->PaletteInfoSize
= 0;
730 // Fill in image blocks.
732 ImagePackage
->ImageBlockSize
= (UINT32
) BlockSize
;
733 ImagePackage
->ImageBlock
= (UINT8
*) AllocateZeroPool (BlockSize
);
734 if (ImagePackage
->ImageBlock
== NULL
) {
735 SafeFreePool (ImagePackage
);
736 return EFI_OUT_OF_RESOURCES
;
738 ImageBlock
= ImagePackage
->ImageBlock
;
741 // Temp memory to store new block.
743 NewBlock
= AllocateZeroPool (NewBlockSize
);
744 if (NewBlock
== NULL
) {
745 SafeFreePool (ImagePackage
->ImageBlock
);
746 SafeFreePool (ImagePackage
);
747 return EFI_OUT_OF_RESOURCES
;
749 NewBlockPtr
= NewBlock
;
752 // Insert this image package.
754 PackageListNode
->ImagePkg
= ImagePackage
;
755 PackageListNode
->PackageListHdr
.PackageLength
+= ImagePackage
->ImagePkgHdr
.Header
.Length
;
759 // Append the new block here
761 if (ImageIn
->Flags
== EFI_IMAGE_TRANSPARENT
) {
762 *NewBlock
= EFI_HII_IIBT_IMAGE_24BIT_TRANS
;
764 *NewBlock
= EFI_HII_IIBT_IMAGE_24BIT
;
767 CopyMem (NewBlock
, &ImageIn
->Width
, sizeof (UINT16
));
768 NewBlock
+= sizeof (UINT16
);
769 CopyMem (NewBlock
, &ImageIn
->Height
, sizeof (UINT16
));
770 NewBlock
+= sizeof (UINT16
);
771 CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL
*) NewBlock
, ImageIn
->Bitmap
, ImageIn
->Width
* ImageIn
->Height
);
773 CopyMem (ImageBlock
, NewBlockPtr
, NewBlockSize
);
774 SafeFreePool (NewBlockPtr
);
777 // Append the block end
779 ImageBlock
+= NewBlockSize
;
780 ((EFI_HII_IIBT_END_BLOCK
*) (ImageBlock
))->Header
.BlockType
= EFI_HII_IIBT_END
;
787 This function retrieves the image specified by ImageId which is associated with
788 the specified PackageList and copies it into the buffer specified by Image.
790 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
791 @param PackageList Handle of the package list where this image will
793 @param ImageId The image's id,, which is unique within
795 @param Image Points to the image.
796 @param ImageSize On entry, points to the size of the buffer pointed
797 to by Image, in bytes. On return, points to the
798 length of the image, in bytes.
800 @retval EFI_SUCCESS The new image was returned successfully.
801 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
802 database. The specified PackageList is not in the database.
803 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to
805 @retval EFI_INVALID_PARAMETER The Image or ImageSize was NULL.
806 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there was not
813 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
814 IN EFI_HII_HANDLE PackageList
,
815 IN EFI_IMAGE_ID ImageId
,
816 OUT EFI_IMAGE_INPUT
*Image
819 HII_DATABASE_PRIVATE_DATA
*Private
;
821 HII_DATABASE_RECORD
*DatabaseRecord
;
822 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
823 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
825 EFI_IMAGE_ID LocalImageId
;
827 EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit
;
836 if (This
== NULL
|| Image
== NULL
|| ImageId
< 1) {
837 return EFI_INVALID_PARAMETER
;
840 if (!IsHiiHandleValid (PackageList
)) {
841 return EFI_NOT_FOUND
;
844 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
847 // Get the specified package list and image package.
849 PackageListNode
= NULL
;
850 for (Link
= Private
->DatabaseList
.ForwardLink
;
851 Link
!= &Private
->DatabaseList
;
852 Link
= Link
->ForwardLink
854 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
855 if (DatabaseRecord
->Handle
== PackageList
) {
856 PackageListNode
= DatabaseRecord
->PackageList
;
860 if (PackageListNode
== NULL
) {
861 return EFI_NOT_FOUND
;
863 ImagePackage
= PackageListNode
->ImagePkg
;
864 if (ImagePackage
== NULL
) {
865 return EFI_NOT_FOUND
;
869 // Find the image block specified by ImageId
871 LocalImageId
= ImageId
;
872 ImageBlock
= GetImageIdOrAddress (ImagePackage
->ImageBlock
, &LocalImageId
);
873 if (ImageBlock
== NULL
) {
874 return EFI_NOT_FOUND
;
878 BlockType
= *ImageBlock
;
881 case EFI_HII_IIBT_IMAGE_JPEG
:
883 // BUGBUG: need to be supported as soon as image tool is designed.
885 return EFI_UNSUPPORTED
;
888 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
889 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
890 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
895 case EFI_HII_IIBT_IMAGE_1BIT
:
896 case EFI_HII_IIBT_IMAGE_4BIT
:
897 case EFI_HII_IIBT_IMAGE_8BIT
:
899 // Use the common block code since the definition of these structures is the same.
901 CopyMem (&Iibt1bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
));
902 ImageLength
= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) *
903 (Iibt1bit
.Bitmap
.Width
* Iibt1bit
.Bitmap
.Height
);
904 Image
->Bitmap
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (ImageLength
);
905 if (Image
->Bitmap
== NULL
) {
906 return EFI_OUT_OF_RESOURCES
;
910 Image
->Flags
= EFI_IMAGE_TRANSPARENT
;
912 Image
->Width
= Iibt1bit
.Bitmap
.Width
;
913 Image
->Height
= Iibt1bit
.Bitmap
.Height
;
915 PaletteInfo
= ImagePackage
->PaletteBlock
+ sizeof (EFI_HII_IMAGE_PALETTE_INFO_HEADER
);
916 for (PaletteIndex
= 1; PaletteIndex
< Iibt1bit
.PaletteIndex
; PaletteIndex
++) {
917 CopyMem (&PaletteSize
, PaletteInfo
, sizeof (UINT16
));
918 PaletteInfo
+= PaletteSize
+ sizeof (UINT16
);
920 ASSERT (PaletteIndex
== Iibt1bit
.PaletteIndex
);
923 // Output bitmap data
925 if (BlockType
== EFI_HII_IIBT_IMAGE_1BIT
|| BlockType
== EFI_HII_IIBT_IMAGE_1BIT_TRANS
) {
928 (UINT8
*) (ImageBlock
+ sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
) - sizeof (UINT8
)),
929 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
931 } else if (BlockType
== EFI_HII_IIBT_IMAGE_4BIT
|| BlockType
== EFI_HII_IIBT_IMAGE_4BIT_TRANS
) {
934 (UINT8
*) (ImageBlock
+ sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
) - sizeof (UINT8
)),
935 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
940 (UINT8
*) (ImageBlock
+ sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
) - sizeof (UINT8
)),
941 (EFI_HII_IMAGE_PALETTE_INFO
*) PaletteInfo
948 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
953 case EFI_HII_IIBT_IMAGE_24BIT
:
954 CopyMem (&Width
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (UINT16
));
957 ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT16
),
960 ImageLength
= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * (Width
* Height
);
961 Image
->Bitmap
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (ImageLength
);
962 if (Image
->Bitmap
== NULL
) {
963 return EFI_OUT_OF_RESOURCES
;
967 Image
->Flags
= EFI_IMAGE_TRANSPARENT
;
969 Image
->Width
= Width
;
970 Image
->Height
= Height
;
973 // Output the bimap data directly.
977 (EFI_HII_RGB_PIXEL
*) (ImageBlock
+ sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
))
983 return EFI_NOT_FOUND
;
990 This function updates the image specified by ImageId in the specified PackageListHandle to
991 the image specified by Image.
993 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
994 @param PackageList The package list containing the images.
995 @param ImageId The image's id,, which is unique within
997 @param Image Points to the image.
999 @retval EFI_SUCCESS The new image was updated successfully.
1000 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
1001 database. The specified PackageList is not in the database.
1002 @retval EFI_INVALID_PARAMETER The Image was NULL.
1008 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1009 IN EFI_HII_HANDLE PackageList
,
1010 IN EFI_IMAGE_ID ImageId
,
1011 IN CONST EFI_IMAGE_INPUT
*Image
1014 HII_DATABASE_PRIVATE_DATA
*Private
;
1016 HII_DATABASE_RECORD
*DatabaseRecord
;
1017 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1018 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
1020 EFI_IMAGE_ID LocalImageId
;
1022 EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit
;
1023 EFI_HII_IIBT_IMAGE_4BIT_BLOCK Iibt4bit
;
1024 EFI_HII_IIBT_IMAGE_8BIT_BLOCK Iibt8bit
;
1028 UINT32 NewBlockSize
;
1029 UINT32 OldBlockSize
;
1030 EFI_IMAGE_INPUT
*ImageIn
;
1038 if (This
== NULL
|| Image
== NULL
|| ImageId
< 1 || Image
->Bitmap
== NULL
) {
1039 return EFI_INVALID_PARAMETER
;
1042 if (!IsHiiHandleValid (PackageList
)) {
1043 return EFI_NOT_FOUND
;
1046 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1049 // Get the specified package list and image package.
1051 PackageListNode
= NULL
;
1052 for (Link
= Private
->DatabaseList
.ForwardLink
;
1053 Link
!= &Private
->DatabaseList
;
1054 Link
= Link
->ForwardLink
1056 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1057 if (DatabaseRecord
->Handle
== PackageList
) {
1058 PackageListNode
= DatabaseRecord
->PackageList
;
1062 if (PackageListNode
== NULL
) {
1063 return EFI_NOT_FOUND
;
1065 ImagePackage
= PackageListNode
->ImagePkg
;
1066 if (ImagePackage
== NULL
) {
1067 return EFI_NOT_FOUND
;
1071 // Find the image block specified by ImageId
1073 LocalImageId
= ImageId
;
1074 ImageBlock
= GetImageIdOrAddress (ImagePackage
->ImageBlock
, &LocalImageId
);
1075 if (ImageBlock
== NULL
) {
1076 return EFI_NOT_FOUND
;
1079 BlockType
= *ImageBlock
;
1082 // Get the size of original image block. Use some common block code here
1083 // since the definition of some structures is the same.
1085 switch (BlockType
) {
1086 case EFI_HII_IIBT_IMAGE_JPEG
:
1088 // BUGBUG: need to be supported as soon as image tool is designed.
1090 return EFI_UNSUPPORTED
;
1093 case EFI_HII_IIBT_IMAGE_1BIT
:
1094 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
1095 CopyMem (&Iibt1bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
));
1096 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK
) - sizeof (UINT8
) +
1097 BITMAP_LEN_1_BIT (Iibt1bit
.Bitmap
.Width
, Iibt1bit
.Bitmap
.Height
);
1099 case EFI_HII_IIBT_IMAGE_4BIT
:
1100 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
1101 CopyMem (&Iibt4bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
));
1102 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK
) - sizeof (UINT8
) +
1103 BITMAP_LEN_4_BIT (Iibt4bit
.Bitmap
.Width
, Iibt4bit
.Bitmap
.Height
);
1105 case EFI_HII_IIBT_IMAGE_8BIT
:
1106 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
1107 CopyMem (&Iibt8bit
, ImageBlock
, sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
));
1108 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK
) - sizeof (UINT8
) +
1109 BITMAP_LEN_8_BIT (Iibt8bit
.Bitmap
.Width
, Iibt8bit
.Bitmap
.Height
);
1111 case EFI_HII_IIBT_IMAGE_24BIT
:
1112 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
1113 CopyMem (&Width
, ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
), sizeof (UINT16
));
1116 ImageBlock
+ sizeof (EFI_HII_IMAGE_BLOCK
) + sizeof (UINT16
),
1119 OldBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
1120 BITMAP_LEN_24_BIT (Width
, Height
);
1123 return EFI_NOT_FOUND
;
1128 // Create the new image block according to input image.
1130 ImageIn
= (EFI_IMAGE_INPUT
*) Image
;
1131 NewBlockSize
= sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK
) - sizeof (EFI_HII_RGB_PIXEL
) +
1132 BITMAP_LEN_24_BIT (ImageIn
->Width
, ImageIn
->Height
);
1133 NewBlock
= (UINT8
*) AllocateZeroPool (NewBlockSize
);
1134 if (NewBlock
== NULL
) {
1135 return EFI_OUT_OF_RESOURCES
;
1138 NewBlockPtr
= NewBlock
;
1139 if ((ImageIn
->Flags
& EFI_IMAGE_TRANSPARENT
) == EFI_IMAGE_TRANSPARENT
) {
1140 *NewBlockPtr
= EFI_HII_IIBT_IMAGE_24BIT_TRANS
;
1142 *NewBlockPtr
= EFI_HII_IIBT_IMAGE_24BIT
;
1146 CopyMem (NewBlockPtr
, &ImageIn
->Width
, sizeof (UINT16
));
1147 NewBlockPtr
+= sizeof (UINT16
);
1148 CopyMem (NewBlockPtr
, &ImageIn
->Height
, sizeof (UINT16
));
1149 NewBlockPtr
+= sizeof (UINT16
);
1151 CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL
*) NewBlockPtr
, ImageIn
->Bitmap
, ImageIn
->Width
* ImageIn
->Height
);
1154 // Adjust the image package to remove the original block firstly then add the new block.
1156 BlockSize
= ImagePackage
->ImageBlockSize
+ NewBlockSize
- OldBlockSize
;
1157 Block
= (UINT8
*) AllocateZeroPool (BlockSize
);
1158 if (Block
== NULL
) {
1159 SafeFreePool (NewBlock
);
1160 return EFI_OUT_OF_RESOURCES
;
1164 Part1Size
= (UINT32
) (ImageBlock
- ImagePackage
->ImageBlock
);
1165 Part2Size
= ImagePackage
->ImageBlockSize
- Part1Size
- OldBlockSize
;
1166 CopyMem (BlockPtr
, ImagePackage
->ImageBlock
, Part1Size
);
1167 BlockPtr
+= Part1Size
;
1168 CopyMem (BlockPtr
, NewBlock
, NewBlockSize
);
1169 BlockPtr
+= NewBlockSize
;
1170 CopyMem (BlockPtr
, ImageBlock
+ OldBlockSize
, Part2Size
);
1172 SafeFreePool (ImagePackage
->ImageBlock
);
1173 SafeFreePool (NewBlock
);
1174 ImagePackage
->ImageBlock
= Block
;
1175 ImagePackage
->ImageBlockSize
= BlockSize
;
1176 ImagePackage
->ImagePkgHdr
.Header
.Length
+= NewBlockSize
- OldBlockSize
;
1177 PackageListNode
->PackageListHdr
.PackageLength
+= NewBlockSize
- OldBlockSize
;
1185 This function renders an image to a bitmap or the screen using the specified
1186 color and options. It draws the image on an existing bitmap, allocates a new
1187 bitmap or uses the screen. The images can be clipped.
1189 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1190 @param Flags Describes how the image is to be drawn.
1191 @param Image Points to the image to be displayed.
1192 @param Blt If this points to a non-NULL on entry, this points
1193 to the image, which is Width pixels wide and
1194 Height pixels high. The image will be drawn onto
1195 this image and EFI_HII_DRAW_FLAG_CLIP is implied.
1196 If this points to a NULL on entry, then a buffer
1197 will be allocated to hold the generated image and
1198 the pointer updated on exit. It is the caller's
1199 responsibility to free this buffer.
1200 @param BltY Specifies the offset from the left and top edge of
1201 the output image of the first pixel in the image.
1203 @retval EFI_SUCCESS The image was successfully drawn.
1204 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.
1205 @retval EFI_INVALID_PARAMETER The Image or Blt was NULL.
1206 @retval EFI_INVALID_PARAMETER Any combination of Flags is invalid.
1212 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1213 IN EFI_HII_DRAW_FLAGS Flags
,
1214 IN CONST EFI_IMAGE_INPUT
*Image
,
1215 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
1221 HII_DATABASE_PRIVATE_DATA
*Private
;
1222 BOOLEAN Transparent
;
1223 EFI_IMAGE_INPUT
*ImageIn
;
1224 EFI_IMAGE_OUTPUT
*ImageOut
;
1225 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
1233 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1235 EFI_CONSOLE_CONTROL_PROTOCOL
*Console
;
1237 if (This
== NULL
|| Image
== NULL
|| Blt
== NULL
) {
1238 return EFI_INVALID_PARAMETER
;
1241 if ((Flags
& EFI_HII_DRAW_FLAG_CLIP
) == EFI_HII_DRAW_FLAG_CLIP
&& *Blt
== NULL
) {
1242 return EFI_INVALID_PARAMETER
;
1245 if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_TRANSPARENT
) {
1246 return EFI_INVALID_PARAMETER
;
1249 ImageIn
= (EFI_IMAGE_INPUT
*) Image
;
1252 // Check whether the image will be drawn transparently or opaquely.
1254 Transparent
= FALSE
;
1255 if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_FORCE_TRANS
) {
1257 } else if ((Flags
& EFI_HII_DRAW_FLAG_TRANSPARENT
) == EFI_HII_DRAW_FLAG_FORCE_OPAQUE
){
1258 Transparent
= FALSE
;
1261 // Now EFI_HII_DRAW_FLAG_DEFAULT is set, whether image will be drawn depending
1262 // on the image's transparency setting.
1264 if ((ImageIn
->Flags
& EFI_IMAGE_TRANSPARENT
) == EFI_IMAGE_TRANSPARENT
) {
1270 // Image cannot be drawn transparently if Blt points to NULL on entry.
1271 // Currently output to Screen transparently is not supported, either.
1275 return EFI_INVALID_PARAMETER
;
1276 } else if ((Flags
& EFI_HII_DIRECT_TO_SCREEN
) == EFI_HII_DIRECT_TO_SCREEN
) {
1277 return EFI_INVALID_PARAMETER
;
1281 Private
= HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1284 // When Blt points to a non-NULL on entry, this image will be drawn onto
1285 // this bitmap or screen pointed by "*Blt" and EFI_HII_DRAW_FLAG_CLIP is implied.
1286 // Otherwise a new bitmap will be allocated to hold this image.
1290 // Clip the image by (Width, Height)
1293 Width
= ImageIn
->Width
;
1294 Height
= ImageIn
->Height
;
1296 if (Width
> (*Blt
)->Width
- BltX
) {
1297 Width
= (*Blt
)->Width
- BltX
;
1299 if (Height
> (*Blt
)->Height
- BltY
) {
1300 Height
= (*Blt
)->Height
- BltY
;
1303 BufferLen
= Width
* Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
1304 BltBuffer
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (BufferLen
);
1305 if (BltBuffer
== NULL
) {
1306 return EFI_OUT_OF_RESOURCES
;
1309 if (Width
== ImageIn
->Width
&& Height
== ImageIn
->Height
) {
1310 CopyMem (BltBuffer
, ImageIn
->Bitmap
, BufferLen
);
1312 for (Y
= 0; Y
< Height
; Y
++) {
1313 OffsetY1
= ImageIn
->Width
* Y
;
1314 OffsetY2
= Width
* Y
;
1315 for (X
= 0; X
< Width
; X
++) {
1316 BltBuffer
[OffsetY2
+ X
] = ImageIn
->Bitmap
[OffsetY1
+ X
];
1322 // Draw the image to existing bitmap or screen depending on flag.
1324 if ((Flags
& EFI_HII_DIRECT_TO_SCREEN
) == EFI_HII_DIRECT_TO_SCREEN
) {
1325 Status
= gBS
->LocateProtocol (
1326 &gEfiConsoleControlProtocolGuid
,
1331 if (EFI_ERROR (Status
)) {
1335 Console
->SetMode (Console
, EfiConsoleControlScreenGraphics
);
1337 // Write the image directly to the output device specified by Screen.
1339 Status
= (*Blt
)->Image
.Screen
->Blt (
1340 (*Blt
)->Image
.Screen
,
1342 EfiBltBufferToVideo
,
1353 // Draw the image onto the existing bitmap specified by Bitmap.
1355 Status
= ImageToBlt (
1367 SafeFreePool (BltBuffer
);
1372 // Allocate a new bitmap to hold the incoming image.
1374 Width
= ImageIn
->Width
+ BltX
;
1375 Height
= ImageIn
->Height
+ BltY
;
1377 BufferLen
= Width
* Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
1378 BltBuffer
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) AllocateZeroPool (BufferLen
);
1379 if (BltBuffer
== NULL
) {
1380 return EFI_OUT_OF_RESOURCES
;
1383 ImageOut
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1384 if (ImageOut
== NULL
) {
1385 SafeFreePool (BltBuffer
);
1386 return EFI_OUT_OF_RESOURCES
;
1388 ImageOut
->Width
= (UINT16
) Width
;
1389 ImageOut
->Height
= (UINT16
) Height
;
1390 ImageOut
->Image
.Bitmap
= BltBuffer
;
1393 // BUGBUG: Now all the "blank" pixels are filled with system default background
1394 // color. Not sure if it need to be updated or not.
1396 Status
= GetSystemFont (Private
, &FontInfo
, NULL
);
1397 if (EFI_ERROR (Status
)) {
1398 SafeFreePool (BltBuffer
);
1399 SafeFreePool (ImageOut
);
1402 for (Index
= 0; Index
< Width
* Height
; Index
++) {
1403 BltBuffer
[Index
] = FontInfo
->BackgroundColor
;
1405 SafeFreePool (FontInfo
);
1408 // Draw the incoming image to the new created image.
1426 This function renders an image to a bitmap or the screen using the specified
1427 color and options. It draws the image on an existing bitmap, allocates a new
1428 bitmap or uses the screen. The images can be clipped.
1430 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.
1431 @param Flags Describes how the image is to be drawn.
1432 @param PackageList The package list in the HII database to search for
1433 the specified image.
1434 @param ImageId The image's id, which is unique within
1436 @param Blt If this points to a non-NULL on entry, this points
1437 to the image, which is Width pixels wide and
1438 Height pixels high. The image will be drawn onto
1440 EFI_HII_DRAW_FLAG_CLIP is implied. If this points
1441 to a NULL on entry, then a buffer will be
1442 allocated to hold the generated image and the
1443 pointer updated on exit. It is the caller's
1444 responsibility to free this buffer.
1445 @param BltY Specifies the offset from the left and top edge of
1446 the output image of the first pixel in the image.
1448 @retval EFI_SUCCESS The image was successfully drawn.
1449 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.
1450 @retval EFI_INVALID_PARAMETER The Blt was NULL.
1451 @retval EFI_NOT_FOUND The image specified by ImageId is not in the database.
1452 The specified PackageList is not in the database.
1458 IN CONST EFI_HII_IMAGE_PROTOCOL
*This
,
1459 IN EFI_HII_DRAW_FLAGS Flags
,
1460 IN EFI_HII_HANDLE PackageList
,
1461 IN EFI_IMAGE_ID ImageId
,
1462 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
1468 EFI_IMAGE_INPUT Image
;
1471 // Check input parameter.
1473 if (This
== NULL
|| Blt
== NULL
) {
1474 return EFI_INVALID_PARAMETER
;
1477 if (!IsHiiHandleValid (PackageList
)) {
1478 return EFI_NOT_FOUND
;
1482 // Get the specified Image.
1484 Status
= HiiGetImage (This
, PackageList
, ImageId
, &Image
);
1485 if (EFI_ERROR (Status
)) {
1492 Status
= HiiDrawImage (This
, Flags
, &Image
, Blt
, BltX
, BltY
);
1493 SafeFreePool (Image
.Bitmap
);