2 Implementation for EFI_HII_IMAGE_EX_PROTOCOL.
5 Copyright (c) 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"
20 The prototype of this extension function is the same with EFI_HII_IMAGE_PROTOCOL.NewImage().
21 This protocol invokes EFI_HII_IMAGE_PROTOCOL.NewImage() implicitly.
23 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.
24 @param PackageList Handle of the package list where this image will
26 @param ImageId On return, contains the new image id, which is
27 unique within PackageList.
28 @param Image Points to the image.
30 @retval EFI_SUCCESS The new image was added successfully.
31 @retval EFI_NOT_FOUND The PackageList could not be found.
32 @retval EFI_OUT_OF_RESOURCES Could not add the image due to lack of resources.
33 @retval EFI_INVALID_PARAMETER Image is NULL or ImageId is NULL.
38 IN CONST EFI_HII_IMAGE_EX_PROTOCOL
*This
,
39 IN EFI_HII_HANDLE PackageList
,
40 OUT EFI_IMAGE_ID
*ImageId
,
41 IN CONST EFI_IMAGE_INPUT
*Image
44 HII_DATABASE_PRIVATE_DATA
*Private
;
46 Private
= HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
47 return HiiNewImage (&Private
->HiiImage
, PackageList
, ImageId
, Image
);
51 Return the information about the image, associated with the package list.
52 The prototype of this extension function is the same with EFI_HII_IMAGE_PROTOCOL.GetImage().
54 This function is similar to EFI_HII_IMAGE_PROTOCOL.GetImage().The difference is that
55 this function will locate all EFI_HII_IMAGE_DECODER_PROTOCOL instances installed in the
56 system if the decoder of the certain image type is not supported by the
57 EFI_HII_IMAGE_EX_PROTOCOL. The function will attempt to decode the image to the
58 EFI_IMAGE_INPUT using the first EFI_HII_IMAGE_DECODER_PROTOCOL instance that
59 supports the requested image type.
61 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.
62 @param PackageList The package list in the HII database to search for the
64 @param ImageId The image's id, which is unique within PackageList.
65 @param Image Points to the image.
67 @retval EFI_SUCCESS The new image was returned successfully.
68 @retval EFI_NOT_FOUND The image specified by ImageId is not available. The specified
69 PackageList is not in the Database.
70 @retval EFI_INVALID_PARAMETER Image was NULL or ImageId was 0.
71 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there
72 was not enough memory.
78 IN CONST EFI_HII_IMAGE_EX_PROTOCOL
*This
,
79 IN EFI_HII_HANDLE PackageList
,
80 IN EFI_IMAGE_ID ImageId
,
81 OUT EFI_IMAGE_INPUT
*Image
84 HII_DATABASE_PRIVATE_DATA
*Private
;
86 Private
= HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
87 return IGetImage (&Private
->DatabaseList
, PackageList
, ImageId
, Image
, FALSE
);
92 Change the information about the image.
94 Same with EFI_HII_IMAGE_PROTOCOL.SetImage(),this protocol invokes
95 EFI_HII_IMAGE_PROTOCOL.SetImage()implicitly.
97 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.
98 @param PackageList The package list containing the images.
99 @param ImageId The image's id, which is unique within PackageList.
100 @param Image Points to the image.
102 @retval EFI_SUCCESS The new image was successfully updated.
103 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
104 database. The specified PackageList is not in
106 @retval EFI_INVALID_PARAMETER The Image was NULL, the ImageId was 0 or
107 the Image->Bitmap was NULL.
113 IN CONST EFI_HII_IMAGE_EX_PROTOCOL
*This
,
114 IN EFI_HII_HANDLE PackageList
,
115 IN EFI_IMAGE_ID ImageId
,
116 IN CONST EFI_IMAGE_INPUT
*Image
119 HII_DATABASE_PRIVATE_DATA
*Private
;
120 Private
= HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
121 return HiiSetImage (&Private
->HiiImage
, PackageList
, ImageId
, Image
);
126 Renders an image to a bitmap or to the display.
128 The prototype of this extension function is the same with
129 EFI_HII_IMAGE_PROTOCOL.DrawImage(). This protocol invokes
130 EFI_HII_IMAGE_PROTOCOL.DrawImage() implicitly.
132 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.
133 @param Flags Describes how the image is to be drawn.
134 @param Image Points to the image to be displayed.
135 @param Blt If this points to a non-NULL on entry, this points
136 to the image, which is Width pixels wide and
137 Height pixels high. The image will be drawn onto
138 this image and EFI_HII_DRAW_FLAG_CLIP is implied.
139 If this points to a NULL on entry, then a buffer
140 will be allocated to hold the generated image and
141 the pointer updated on exit. It is the caller's
142 responsibility to free this buffer.
143 @param BltX Specifies the offset from the left and top edge of
144 the output image of the first pixel in the image.
145 @param BltY Specifies the offset from the left and top edge of
146 the output image of the first pixel in the image.
148 @retval EFI_SUCCESS The image was successfully drawn.
149 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.
150 @retval EFI_INVALID_PARAMETER The Image or Blt was NULL.
156 IN CONST EFI_HII_IMAGE_EX_PROTOCOL
*This
,
157 IN EFI_HII_DRAW_FLAGS Flags
,
158 IN CONST EFI_IMAGE_INPUT
*Image
,
159 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
164 HII_DATABASE_PRIVATE_DATA
*Private
;
165 Private
= HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
166 return HiiDrawImage (&Private
->HiiImage
, Flags
, Image
, Blt
, BltX
, BltY
);
171 Renders an image to a bitmap or the screen containing the contents of the specified
174 This function is similar to EFI_HII_IMAGE_PROTOCOL.DrawImageId(). The difference is that
175 this function will locate all EFI_HII_IMAGE_DECODER_PROTOCOL instances installed in the
176 system if the decoder of the certain image type is not supported by the
177 EFI_HII_IMAGE_EX_PROTOCOL. The function will attempt to decode the image to the
178 EFI_IMAGE_INPUT using the first EFI_HII_IMAGE_DECODER_PROTOCOL instance that
179 supports the requested image type.
181 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.
182 @param Flags Describes how the image is to be drawn.
183 @param PackageList The package list in the HII database to search for
185 @param ImageId The image's id, which is unique within PackageList.
186 @param Blt If this points to a non-NULL on entry, this points
187 to the image, which is Width pixels wide and
188 Height pixels high. The image will be drawn onto
189 this image and EFI_HII_DRAW_FLAG_CLIP is implied.
190 If this points to a NULL on entry, then a buffer
191 will be allocated to hold the generated image
192 and the pointer updated on exit. It is the caller's
193 responsibility to free this buffer.
194 @param BltX Specifies the offset from the left and top edge of
195 the output image of the first pixel in the image.
196 @param BltY Specifies the offset from the left and top edge of
197 the output image of the first pixel in the image.
199 @retval EFI_SUCCESS The image was successfully drawn.
200 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.
201 @retval EFI_INVALID_PARAMETER The Blt was NULL or ImageId was 0.
202 @retval EFI_NOT_FOUND The image specified by ImageId is not in the database.
203 The specified PackageList is not in the database.
209 IN CONST EFI_HII_IMAGE_EX_PROTOCOL
*This
,
210 IN EFI_HII_DRAW_FLAGS Flags
,
211 IN EFI_HII_HANDLE PackageList
,
212 IN EFI_IMAGE_ID ImageId
,
213 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
219 EFI_IMAGE_INPUT Image
;
222 // Check input parameter.
224 if (This
== NULL
|| Blt
== NULL
) {
225 return EFI_INVALID_PARAMETER
;
229 // Get the specified Image.
231 Status
= HiiGetImageEx (This
, PackageList
, ImageId
, &Image
);
232 if (EFI_ERROR (Status
)) {
239 Status
= HiiDrawImageEx (This
, Flags
, &Image
, Blt
, BltX
, BltY
);
240 if (Image
.Bitmap
!= NULL
) {
241 FreePool (Image
.Bitmap
);
247 Return the first HII image decoder instance which supports the DecoderName.
249 @param BlockType The image block type.
251 @retval Pointer to the HII image decoder instance.
253 EFI_HII_IMAGE_DECODER_PROTOCOL
*
254 LocateHiiImageDecoder (
259 EFI_HII_IMAGE_DECODER_PROTOCOL
*Decoder
;
263 EFI_GUID
*DecoderNames
;
264 UINT16 NumberOfDecoderName
;
265 UINT16 DecoderNameIndex
;
266 EFI_GUID
*DecoderName
;
269 case EFI_HII_IIBT_IMAGE_JPEG
:
270 DecoderName
= &gEfiHiiImageDecoderNameJpegGuid
;
273 case EFI_HII_IIBT_IMAGE_PNG
:
274 DecoderName
= &gEfiHiiImageDecoderNamePngGuid
;
282 Status
= gBS
->LocateHandleBuffer (ByProtocol
, &gEfiHiiImageDecoderProtocolGuid
, NULL
, &HandleNum
, &Handles
);
283 if (EFI_ERROR (Status
)) {
286 for (Index
= 0; Index
< HandleNum
; Index
++) {
287 Status
= gBS
->HandleProtocol (Handles
[Index
], &gEfiHiiImageDecoderProtocolGuid
, (VOID
**) &Decoder
);
288 if (EFI_ERROR (Status
)) {
292 Status
= Decoder
->GetImageDecoderName (Decoder
, &DecoderNames
, &NumberOfDecoderName
);
293 if (EFI_ERROR (Status
)) {
296 for (DecoderNameIndex
= 0; DecoderNameIndex
< NumberOfDecoderName
; DecoderNameIndex
++) {
297 if (CompareGuid (DecoderName
, &DecoderNames
[DecoderNameIndex
])) {
307 This function returns the image information to EFI_IMAGE_OUTPUT. Only the width
308 and height are returned to the EFI_IMAGE_OUTPUT instead of decoding the image
309 to the buffer. This function is used to get the geometry of the image. This function
310 will try to locate all of the EFI_HII_IMAGE_DECODER_PROTOCOL installed on the
311 system if the decoder of image type is not supported by the EFI_HII_IMAGE_EX_PROTOCOL.
313 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.
314 @param PackageList Handle of the package list where this image will
316 @param ImageId The image's id, which is unique within PackageList.
317 @param Image Points to the image.
319 @retval EFI_SUCCESS The new image was returned successfully.
320 @retval EFI_NOT_FOUND The image specified by ImageId is not in the
321 database. The specified PackageList is not in the database.
322 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to
324 @retval EFI_INVALID_PARAMETER The Image was NULL or the ImageId was 0.
325 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there
326 was not enough memory.
332 IN CONST EFI_HII_IMAGE_EX_PROTOCOL
*This
,
333 IN EFI_HII_HANDLE PackageList
,
334 IN EFI_IMAGE_ID ImageId
,
335 OUT EFI_IMAGE_OUTPUT
*Image
339 HII_DATABASE_PRIVATE_DATA
*Private
;
340 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
341 HII_IMAGE_PACKAGE_INSTANCE
*ImagePackage
;
342 EFI_HII_IMAGE_BLOCK
*CurrentImageBlock
;
343 EFI_HII_IMAGE_DECODER_PROTOCOL
*Decoder
;
344 EFI_HII_IMAGE_DECODER_IMAGE_INFO_HEADER
*ImageInfo
;
346 if (Image
== NULL
|| ImageId
== 0) {
347 return EFI_INVALID_PARAMETER
;
350 Private
= HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
351 PackageListNode
= LocatePackageList (&Private
->DatabaseList
, PackageList
);
352 if (PackageListNode
== NULL
) {
353 return EFI_NOT_FOUND
;
355 ImagePackage
= PackageListNode
->ImagePkg
;
356 if (ImagePackage
== NULL
) {
357 return EFI_NOT_FOUND
;
361 // Find the image block specified by ImageId
363 CurrentImageBlock
= GetImageIdOrAddress (ImagePackage
->ImageBlock
, &ImageId
);
364 if (CurrentImageBlock
== NULL
) {
365 return EFI_NOT_FOUND
;
368 switch (CurrentImageBlock
->BlockType
) {
369 case EFI_HII_IIBT_IMAGE_JPEG
:
370 case EFI_HII_IIBT_IMAGE_PNG
:
371 Decoder
= LocateHiiImageDecoder (CurrentImageBlock
->BlockType
);
372 if (Decoder
== NULL
) {
373 return EFI_UNSUPPORTED
;
376 // Use the common block code since the definition of two structures is the same.
378 ASSERT (OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK
, Data
) == OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK
, Data
));
379 ASSERT (sizeof (((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Data
) ==
380 sizeof (((EFI_HII_IIBT_PNG_BLOCK
*) CurrentImageBlock
)->Data
));
381 ASSERT (OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK
, Size
) == OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK
, Size
));
382 ASSERT (sizeof (((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Size
) ==
383 sizeof (((EFI_HII_IIBT_PNG_BLOCK
*) CurrentImageBlock
)->Size
));
384 Status
= Decoder
->GetImageInfo (
386 ((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Data
,
387 ((EFI_HII_IIBT_JPEG_BLOCK
*) CurrentImageBlock
)->Size
,
392 // Spec requires to use the first capable image decoder instance.
393 // The first image decoder instance may fail to decode the image.
395 if (!EFI_ERROR (Status
)) {
396 Image
->Height
= ImageInfo
->ImageHeight
;
397 Image
->Width
= ImageInfo
->ImageWidth
;
398 Image
->Image
.Bitmap
= NULL
;
399 FreePool (ImageInfo
);
403 case EFI_HII_IIBT_IMAGE_1BIT_TRANS
:
404 case EFI_HII_IIBT_IMAGE_4BIT_TRANS
:
405 case EFI_HII_IIBT_IMAGE_8BIT_TRANS
:
406 case EFI_HII_IIBT_IMAGE_1BIT
:
407 case EFI_HII_IIBT_IMAGE_4BIT
:
408 case EFI_HII_IIBT_IMAGE_8BIT
:
410 // Use the common block code since the definition of these structures is the same.
412 Image
->Width
= ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
);
413 Image
->Height
= ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
);
414 Image
->Image
.Bitmap
= NULL
;
417 case EFI_HII_IIBT_IMAGE_24BIT_TRANS
:
418 case EFI_HII_IIBT_IMAGE_24BIT
:
419 Image
->Width
= ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Width
);
420 Image
->Height
= ReadUnaligned16 ((VOID
*) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK
*) CurrentImageBlock
)->Bitmap
.Height
);
421 Image
->Image
.Bitmap
= NULL
;
425 return EFI_NOT_FOUND
;