TianoCore EDK2 master
Loading...
Searching...
No Matches
ImageEx.c
Go to the documentation of this file.
1
10#include "HiiDatabase.h"
11
29EFIAPI
32 IN EFI_HII_HANDLE PackageList,
33 OUT EFI_IMAGE_ID *ImageId,
35 )
36{
38
39 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);
40 return HiiNewImage (&Private->HiiImage, PackageList, ImageId, Image);
41}
42
69EFIAPI
72 IN EFI_HII_HANDLE PackageList,
73 IN EFI_IMAGE_ID ImageId,
74 OUT EFI_IMAGE_INPUT *Image
75 )
76{
78
79 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);
80 return IGetImage (&Private->DatabaseList, PackageList, ImageId, Image, FALSE);
81}
82
103EFIAPI
106 IN EFI_HII_HANDLE PackageList,
107 IN EFI_IMAGE_ID ImageId,
109 )
110{
112
113 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);
114 return HiiSetImage (&Private->HiiImage, PackageList, ImageId, Image);
115}
116
146EFIAPI
150 IN CONST EFI_IMAGE_INPUT *Image,
151 IN OUT EFI_IMAGE_OUTPUT **Blt,
152 IN UINTN BltX,
153 IN UINTN BltY
154 )
155{
157
158 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);
159 return HiiDrawImage (&Private->HiiImage, Flags, Image, Blt, BltX, BltY);
160}
161
199EFIAPI
203 IN EFI_HII_HANDLE PackageList,
204 IN EFI_IMAGE_ID ImageId,
205 IN OUT EFI_IMAGE_OUTPUT **Blt,
206 IN UINTN BltX,
207 IN UINTN BltY
208 )
209{
210 EFI_STATUS Status;
211 EFI_IMAGE_INPUT Image;
212
213 //
214 // Check input parameter.
215 //
216 if ((This == NULL) || (Blt == NULL)) {
217 return EFI_INVALID_PARAMETER;
218 }
219
220 //
221 // Get the specified Image.
222 //
223 Status = HiiGetImageEx (This, PackageList, ImageId, &Image);
224 if (EFI_ERROR (Status)) {
225 return Status;
226 }
227
228 //
229 // Draw this image.
230 //
231 Status = HiiDrawImageEx (This, Flags, &Image, Blt, BltX, BltY);
232 if (Image.Bitmap != NULL) {
233 FreePool (Image.Bitmap);
234 }
235
236 return Status;
237}
238
248 UINT8 BlockType
249 )
250{
251 EFI_STATUS Status;
253 EFI_HANDLE *Handles;
254 UINTN HandleNum;
255 UINTN Index;
256 EFI_GUID *DecoderNames;
257 UINT16 NumberOfDecoderName;
258 UINT16 DecoderNameIndex;
259 EFI_GUID *DecoderName;
260
261 switch (BlockType) {
262 case EFI_HII_IIBT_IMAGE_JPEG:
263 DecoderName = &gEfiHiiImageDecoderNameJpegGuid;
264 break;
265
266 case EFI_HII_IIBT_IMAGE_PNG:
267 DecoderName = &gEfiHiiImageDecoderNamePngGuid;
268 break;
269
270 default:
271 ASSERT (FALSE);
272 return NULL;
273 }
274
275 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiHiiImageDecoderProtocolGuid, NULL, &HandleNum, &Handles);
276 if (EFI_ERROR (Status)) {
277 return NULL;
278 }
279
280 for (Index = 0; Index < HandleNum; Index++) {
281 Status = gBS->HandleProtocol (Handles[Index], &gEfiHiiImageDecoderProtocolGuid, (VOID **)&Decoder);
282 if (EFI_ERROR (Status)) {
283 continue;
284 }
285
286 Status = Decoder->GetImageDecoderName (Decoder, &DecoderNames, &NumberOfDecoderName);
287 if (EFI_ERROR (Status)) {
288 continue;
289 }
290
291 for (DecoderNameIndex = 0; DecoderNameIndex < NumberOfDecoderName; DecoderNameIndex++) {
292 if (CompareGuid (DecoderName, &DecoderNames[DecoderNameIndex])) {
293 return Decoder;
294 }
295 }
296 }
297
298 return NULL;
299}
300
325EFIAPI
328 IN EFI_HII_HANDLE PackageList,
329 IN EFI_IMAGE_ID ImageId,
330 OUT EFI_IMAGE_OUTPUT *Image
331 )
332{
333 EFI_STATUS Status;
335 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;
336 HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;
337 EFI_HII_IMAGE_BLOCK *CurrentImageBlock;
340
341 if ((Image == NULL) || (ImageId == 0)) {
342 return EFI_INVALID_PARAMETER;
343 }
344
345 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);
346 PackageListNode = LocatePackageList (&Private->DatabaseList, PackageList);
347 if (PackageListNode == NULL) {
348 return EFI_NOT_FOUND;
349 }
350
351 ImagePackage = PackageListNode->ImagePkg;
352 if (ImagePackage == NULL) {
353 return EFI_NOT_FOUND;
354 }
355
356 //
357 // Find the image block specified by ImageId
358 //
359 CurrentImageBlock = GetImageIdOrAddress (ImagePackage->ImageBlock, &ImageId);
360 if (CurrentImageBlock == NULL) {
361 return EFI_NOT_FOUND;
362 }
363
364 switch (CurrentImageBlock->BlockType) {
365 case EFI_HII_IIBT_IMAGE_JPEG:
366 case EFI_HII_IIBT_IMAGE_PNG:
367 Decoder = LocateHiiImageDecoder (CurrentImageBlock->BlockType);
368 if (Decoder == NULL) {
369 return EFI_UNSUPPORTED;
370 }
371
372 //
373 // Use the common block code since the definition of two structures is the same.
374 //
376 ASSERT (
377 sizeof (((EFI_HII_IIBT_JPEG_BLOCK *)CurrentImageBlock)->Data) ==
378 sizeof (((EFI_HII_IIBT_PNG_BLOCK *)CurrentImageBlock)->Data)
379 );
381 ASSERT (
382 sizeof (((EFI_HII_IIBT_JPEG_BLOCK *)CurrentImageBlock)->Size) ==
383 sizeof (((EFI_HII_IIBT_PNG_BLOCK *)CurrentImageBlock)->Size)
384 );
385 Status = Decoder->GetImageInfo (
386 Decoder,
387 ((EFI_HII_IIBT_JPEG_BLOCK *)CurrentImageBlock)->Data,
388 ((EFI_HII_IIBT_JPEG_BLOCK *)CurrentImageBlock)->Size,
389 &ImageInfo
390 );
391
392 //
393 // Spec requires to use the first capable image decoder instance.
394 // The first image decoder instance may fail to decode the image.
395 //
396 if (!EFI_ERROR (Status)) {
397 Image->Height = ImageInfo->ImageHeight;
398 Image->Width = ImageInfo->ImageWidth;
399 Image->Image.Bitmap = NULL;
400 FreePool (ImageInfo);
401 }
402
403 return Status;
404
405 case EFI_HII_IIBT_IMAGE_1BIT_TRANS:
406 case EFI_HII_IIBT_IMAGE_4BIT_TRANS:
407 case EFI_HII_IIBT_IMAGE_8BIT_TRANS:
408 case EFI_HII_IIBT_IMAGE_1BIT:
409 case EFI_HII_IIBT_IMAGE_4BIT:
410 case EFI_HII_IIBT_IMAGE_8BIT:
411 //
412 // Use the common block code since the definition of these structures is the same.
413 //
414 Image->Width = ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK *)CurrentImageBlock)->Bitmap.Width);
415 Image->Height = ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK *)CurrentImageBlock)->Bitmap.Height);
416 Image->Image.Bitmap = NULL;
417 return EFI_SUCCESS;
418
419 case EFI_HII_IIBT_IMAGE_24BIT_TRANS:
420 case EFI_HII_IIBT_IMAGE_24BIT:
421 Image->Width = ReadUnaligned16 ((VOID *)&((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *)CurrentImageBlock)->Bitmap.Width);
422 Image->Height = ReadUnaligned16 ((VOID *)&((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *)CurrentImageBlock)->Bitmap.Height);
423 Image->Image.Bitmap = NULL;
424 return EFI_SUCCESS;
425
426 default:
427 return EFI_NOT_FOUND;
428 }
429}
UINT64 UINTN
UINT16 EFIAPI ReadUnaligned16(IN CONST UINT16 *Buffer)
Definition: Unaligned.c:29
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
VOID EFIAPI FreePool(IN VOID *Buffer)
UINT32 EFI_HII_DRAW_FLAGS
Definition: HiiImage.h:163
EFI_STATUS EFIAPI HiiGetImageEx(IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This, IN EFI_HII_HANDLE PackageList, IN EFI_IMAGE_ID ImageId, OUT EFI_IMAGE_INPUT *Image)
Definition: ImageEx.c:70
EFI_STATUS EFIAPI HiiDrawImageIdEx(IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This, IN EFI_HII_DRAW_FLAGS Flags, IN EFI_HII_HANDLE PackageList, IN EFI_IMAGE_ID ImageId, IN OUT EFI_IMAGE_OUTPUT **Blt, IN UINTN BltX, IN UINTN BltY)
Definition: ImageEx.c:200
EFI_STATUS EFIAPI HiiSetImageEx(IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This, IN EFI_HII_HANDLE PackageList, IN EFI_IMAGE_ID ImageId, IN CONST EFI_IMAGE_INPUT *Image)
Definition: ImageEx.c:104
EFI_STATUS EFIAPI HiiGetImageInfo(IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This, IN EFI_HII_HANDLE PackageList, IN EFI_IMAGE_ID ImageId, OUT EFI_IMAGE_OUTPUT *Image)
Definition: ImageEx.c:326
EFI_STATUS EFIAPI HiiNewImageEx(IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This, IN EFI_HII_HANDLE PackageList, OUT EFI_IMAGE_ID *ImageId, IN CONST EFI_IMAGE_INPUT *Image)
Definition: ImageEx.c:30
EFI_HII_IMAGE_DECODER_PROTOCOL * LocateHiiImageDecoder(UINT8 BlockType)
Definition: ImageEx.c:247
EFI_STATUS EFIAPI HiiDrawImageEx(IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This, IN EFI_HII_DRAW_FLAGS Flags, IN CONST EFI_IMAGE_INPUT *Image, IN OUT EFI_IMAGE_OUTPUT **Blt, IN UINTN BltX, IN UINTN BltY)
Definition: ImageEx.c:147
EFI_HII_IMAGE_BLOCK * GetImageIdOrAddress(IN EFI_HII_IMAGE_BLOCK *ImageBlocks, IN OUT EFI_IMAGE_ID *ImageId)
Definition: Image.c:29
EFI_STATUS IGetImage(IN LIST_ENTRY *Database, IN EFI_HII_HANDLE PackageList, IN EFI_IMAGE_ID ImageId, OUT EFI_IMAGE_INPUT *Image, IN BOOLEAN BitmapOnly)
Definition: Image.c:832
HII_DATABASE_PACKAGE_LIST_INSTANCE * LocatePackageList(IN LIST_ENTRY *Database, IN EFI_HII_HANDLE PackageList)
Definition: Image.c:575
EFI_STATUS EFIAPI HiiDrawImage(IN CONST EFI_HII_IMAGE_PROTOCOL *This, IN EFI_HII_DRAW_FLAGS Flags, IN CONST EFI_IMAGE_INPUT *Image, IN OUT EFI_IMAGE_OUTPUT **Blt, IN UINTN BltX, IN UINTN BltY)
Definition: Image.c:1274
EFI_STATUS EFIAPI HiiNewImage(IN CONST EFI_HII_IMAGE_PROTOCOL *This, IN EFI_HII_HANDLE PackageList, OUT EFI_IMAGE_ID *ImageId, IN CONST EFI_IMAGE_INPUT *Image)
Definition: Image.c:620
EFI_STATUS EFIAPI HiiSetImage(IN CONST EFI_HII_IMAGE_PROTOCOL *This, IN EFI_HII_HANDLE PackageList, IN EFI_IMAGE_ID ImageId, IN CONST EFI_IMAGE_INPUT *Image)
Definition: Image.c:1079
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OFFSET_OF(TYPE, Field)
Definition: Base.h:758
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
VOID * EFI_HII_HANDLE
@ ByProtocol
Definition: UefiSpec.h:1518
Definition: Base.h:213