]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/HiiDatabaseDxe/ImageEx.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / ImageEx.c
CommitLineData
101a1122
RN
1/** @file\r
2Implementation for EFI_HII_IMAGE_EX_PROTOCOL.\r
3\r
4\r
5Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
9d510e61 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
101a1122
RN
7\r
8**/\r
9\r
10\r
11#include "HiiDatabase.h"\r
12\r
13/**\r
14 The prototype of this extension function is the same with EFI_HII_IMAGE_PROTOCOL.NewImage().\r
15 This protocol invokes EFI_HII_IMAGE_PROTOCOL.NewImage() implicitly.\r
16\r
17 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.\r
18 @param PackageList Handle of the package list where this image will\r
19 be added.\r
20 @param ImageId On return, contains the new image id, which is\r
21 unique within PackageList.\r
22 @param Image Points to the image.\r
23\r
24 @retval EFI_SUCCESS The new image was added successfully.\r
25 @retval EFI_NOT_FOUND The PackageList could not be found.\r
26 @retval EFI_OUT_OF_RESOURCES Could not add the image due to lack of resources.\r
27 @retval EFI_INVALID_PARAMETER Image is NULL or ImageId is NULL.\r
28**/\r
29EFI_STATUS\r
30EFIAPI\r
31HiiNewImageEx (\r
32 IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This,\r
33 IN EFI_HII_HANDLE PackageList,\r
34 OUT EFI_IMAGE_ID *ImageId,\r
35 IN CONST EFI_IMAGE_INPUT *Image\r
36 )\r
37{\r
38 HII_DATABASE_PRIVATE_DATA *Private;\r
39\r
40 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
41 return HiiNewImage (&Private->HiiImage, PackageList, ImageId, Image);\r
42}\r
43\r
44/**\r
45 Return the information about the image, associated with the package list.\r
46 The prototype of this extension function is the same with EFI_HII_IMAGE_PROTOCOL.GetImage().\r
47\r
48 This function is similar to EFI_HII_IMAGE_PROTOCOL.GetImage().The difference is that\r
49 this function will locate all EFI_HII_IMAGE_DECODER_PROTOCOL instances installed in the\r
50 system if the decoder of the certain image type is not supported by the\r
51 EFI_HII_IMAGE_EX_PROTOCOL. The function will attempt to decode the image to the\r
52 EFI_IMAGE_INPUT using the first EFI_HII_IMAGE_DECODER_PROTOCOL instance that\r
53 supports the requested image type.\r
54\r
55 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.\r
56 @param PackageList The package list in the HII database to search for the\r
57 specified image.\r
58 @param ImageId The image's id, which is unique within PackageList.\r
59 @param Image Points to the image.\r
60\r
61 @retval EFI_SUCCESS The new image was returned successfully.\r
62 @retval EFI_NOT_FOUND The image specified by ImageId is not available. The specified\r
63 PackageList is not in the Database.\r
64 @retval EFI_INVALID_PARAMETER Image was NULL or ImageId was 0.\r
65 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there\r
66 was not enough memory.\r
67\r
68**/\r
69EFI_STATUS\r
70EFIAPI\r
71HiiGetImageEx (\r
72 IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This,\r
73 IN EFI_HII_HANDLE PackageList,\r
74 IN EFI_IMAGE_ID ImageId,\r
75 OUT EFI_IMAGE_INPUT *Image\r
76 )\r
77{\r
78 HII_DATABASE_PRIVATE_DATA *Private;\r
79\r
80 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
81 return IGetImage (&Private->DatabaseList, PackageList, ImageId, Image, FALSE);\r
82}\r
83\r
84\r
85/**\r
86 Change the information about the image.\r
87\r
88 Same with EFI_HII_IMAGE_PROTOCOL.SetImage(),this protocol invokes\r
89 EFI_HII_IMAGE_PROTOCOL.SetImage()implicitly.\r
90\r
91 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.\r
92 @param PackageList The package list containing the images.\r
93 @param ImageId The image's id, which is unique within PackageList.\r
94 @param Image Points to the image.\r
95\r
96 @retval EFI_SUCCESS The new image was successfully updated.\r
97 @retval EFI_NOT_FOUND The image specified by ImageId is not in the\r
98 database. The specified PackageList is not in\r
99 the database.\r
100 @retval EFI_INVALID_PARAMETER The Image was NULL, the ImageId was 0 or\r
101 the Image->Bitmap was NULL.\r
102\r
103**/\r
104EFI_STATUS\r
105EFIAPI\r
106HiiSetImageEx (\r
107 IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This,\r
108 IN EFI_HII_HANDLE PackageList,\r
109 IN EFI_IMAGE_ID ImageId,\r
110 IN CONST EFI_IMAGE_INPUT *Image\r
111 )\r
112{\r
113 HII_DATABASE_PRIVATE_DATA *Private;\r
114 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
115 return HiiSetImage (&Private->HiiImage, PackageList, ImageId, Image);\r
116}\r
117\r
118\r
119/**\r
120 Renders an image to a bitmap or to the display.\r
121\r
122 The prototype of this extension function is the same with\r
123 EFI_HII_IMAGE_PROTOCOL.DrawImage(). This protocol invokes\r
124 EFI_HII_IMAGE_PROTOCOL.DrawImage() implicitly.\r
125\r
126 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.\r
127 @param Flags Describes how the image is to be drawn.\r
128 @param Image Points to the image to be displayed.\r
129 @param Blt If this points to a non-NULL on entry, this points\r
130 to the image, which is Width pixels wide and\r
131 Height pixels high. The image will be drawn onto\r
132 this image and EFI_HII_DRAW_FLAG_CLIP is implied.\r
133 If this points to a NULL on entry, then a buffer\r
134 will be allocated to hold the generated image and\r
135 the pointer updated on exit. It is the caller's\r
136 responsibility to free this buffer.\r
137 @param BltX Specifies the offset from the left and top edge of\r
138 the output image of the first pixel in the image.\r
139 @param BltY Specifies the offset from the left and top edge of\r
140 the output image of the first pixel in the image.\r
141\r
142 @retval EFI_SUCCESS The image was successfully drawn.\r
143 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.\r
144 @retval EFI_INVALID_PARAMETER The Image or Blt was NULL.\r
145\r
146**/\r
147EFI_STATUS\r
148EFIAPI\r
149HiiDrawImageEx (\r
150 IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This,\r
151 IN EFI_HII_DRAW_FLAGS Flags,\r
152 IN CONST EFI_IMAGE_INPUT *Image,\r
153 IN OUT EFI_IMAGE_OUTPUT **Blt,\r
154 IN UINTN BltX,\r
155 IN UINTN BltY\r
156 )\r
157{\r
158 HII_DATABASE_PRIVATE_DATA *Private;\r
159 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
160 return HiiDrawImage (&Private->HiiImage, Flags, Image, Blt, BltX, BltY);\r
161}\r
162\r
163\r
164/**\r
165 Renders an image to a bitmap or the screen containing the contents of the specified\r
166 image.\r
167\r
168 This function is similar to EFI_HII_IMAGE_PROTOCOL.DrawImageId(). The difference is that\r
169 this function will locate all EFI_HII_IMAGE_DECODER_PROTOCOL instances installed in the\r
170 system if the decoder of the certain image type is not supported by the\r
171 EFI_HII_IMAGE_EX_PROTOCOL. The function will attempt to decode the image to the\r
172 EFI_IMAGE_INPUT using the first EFI_HII_IMAGE_DECODER_PROTOCOL instance that\r
173 supports the requested image type.\r
174\r
175 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.\r
176 @param Flags Describes how the image is to be drawn.\r
177 @param PackageList The package list in the HII database to search for\r
178 the specified image.\r
179 @param ImageId The image's id, which is unique within PackageList.\r
180 @param Blt If this points to a non-NULL on entry, this points\r
181 to the image, which is Width pixels wide and\r
182 Height pixels high. The image will be drawn onto\r
183 this image and EFI_HII_DRAW_FLAG_CLIP is implied.\r
184 If this points to a NULL on entry, then a buffer\r
185 will be allocated to hold the generated image\r
186 and the pointer updated on exit. It is the caller's\r
187 responsibility to free this buffer.\r
188 @param BltX Specifies the offset from the left and top edge of\r
189 the output image of the first pixel in the image.\r
190 @param BltY Specifies the offset from the left and top edge of\r
191 the output image of the first pixel in the image.\r
192\r
193 @retval EFI_SUCCESS The image was successfully drawn.\r
194 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.\r
195 @retval EFI_INVALID_PARAMETER The Blt was NULL or ImageId was 0.\r
196 @retval EFI_NOT_FOUND The image specified by ImageId is not in the database.\r
197 The specified PackageList is not in the database.\r
198\r
199**/\r
200EFI_STATUS\r
201EFIAPI\r
202HiiDrawImageIdEx (\r
203 IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This,\r
204 IN EFI_HII_DRAW_FLAGS Flags,\r
205 IN EFI_HII_HANDLE PackageList,\r
206 IN EFI_IMAGE_ID ImageId,\r
207 IN OUT EFI_IMAGE_OUTPUT **Blt,\r
208 IN UINTN BltX,\r
209 IN UINTN BltY\r
210 )\r
211{\r
212 EFI_STATUS Status;\r
213 EFI_IMAGE_INPUT Image;\r
214\r
215 //\r
216 // Check input parameter.\r
217 //\r
218 if (This == NULL || Blt == NULL) {\r
219 return EFI_INVALID_PARAMETER;\r
220 }\r
221\r
222 //\r
223 // Get the specified Image.\r
224 //\r
225 Status = HiiGetImageEx (This, PackageList, ImageId, &Image);\r
226 if (EFI_ERROR (Status)) {\r
227 return Status;\r
228 }\r
229\r
230 //\r
231 // Draw this image.\r
232 //\r
233 Status = HiiDrawImageEx (This, Flags, &Image, Blt, BltX, BltY);\r
234 if (Image.Bitmap != NULL) {\r
235 FreePool (Image.Bitmap);\r
236 }\r
237 return Status;\r
238}\r
239\r
240/**\r
241 Return the first HII image decoder instance which supports the DecoderName.\r
242\r
243 @param BlockType The image block type.\r
244\r
245 @retval Pointer to the HII image decoder instance.\r
246**/\r
247EFI_HII_IMAGE_DECODER_PROTOCOL *\r
248LocateHiiImageDecoder (\r
249 UINT8 BlockType\r
250 )\r
251{\r
252 EFI_STATUS Status;\r
253 EFI_HII_IMAGE_DECODER_PROTOCOL *Decoder;\r
254 EFI_HANDLE *Handles;\r
255 UINTN HandleNum;\r
256 UINTN Index;\r
257 EFI_GUID *DecoderNames;\r
258 UINT16 NumberOfDecoderName;\r
259 UINT16 DecoderNameIndex;\r
260 EFI_GUID *DecoderName;\r
261\r
262 switch (BlockType) {\r
263 case EFI_HII_IIBT_IMAGE_JPEG:\r
264 DecoderName = &gEfiHiiImageDecoderNameJpegGuid;\r
265 break;\r
266\r
267 case EFI_HII_IIBT_IMAGE_PNG:\r
268 DecoderName = &gEfiHiiImageDecoderNamePngGuid;\r
269 break;\r
270\r
271 default:\r
272 ASSERT (FALSE);\r
273 return NULL;\r
274 }\r
275\r
276 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiHiiImageDecoderProtocolGuid, NULL, &HandleNum, &Handles);\r
277 if (EFI_ERROR (Status)) {\r
278 return NULL;\r
279 }\r
280 for (Index = 0; Index < HandleNum; Index++) {\r
281 Status = gBS->HandleProtocol (Handles[Index], &gEfiHiiImageDecoderProtocolGuid, (VOID **) &Decoder);\r
282 if (EFI_ERROR (Status)) {\r
283 continue;\r
284 }\r
285\r
286 Status = Decoder->GetImageDecoderName (Decoder, &DecoderNames, &NumberOfDecoderName);\r
287 if (EFI_ERROR (Status)) {\r
288 continue;\r
289 }\r
290 for (DecoderNameIndex = 0; DecoderNameIndex < NumberOfDecoderName; DecoderNameIndex++) {\r
291 if (CompareGuid (DecoderName, &DecoderNames[DecoderNameIndex])) {\r
292 return Decoder;\r
293 }\r
294 }\r
295 }\r
296\r
297 return NULL;\r
298}\r
299\r
300/**\r
301 This function returns the image information to EFI_IMAGE_OUTPUT. Only the width\r
302 and height are returned to the EFI_IMAGE_OUTPUT instead of decoding the image\r
303 to the buffer. This function is used to get the geometry of the image. This function\r
304 will try to locate all of the EFI_HII_IMAGE_DECODER_PROTOCOL installed on the\r
305 system if the decoder of image type is not supported by the EFI_HII_IMAGE_EX_PROTOCOL.\r
306\r
307 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.\r
308 @param PackageList Handle of the package list where this image will\r
309 be searched.\r
310 @param ImageId The image's id, which is unique within PackageList.\r
311 @param Image Points to the image.\r
312\r
313 @retval EFI_SUCCESS The new image was returned successfully.\r
314 @retval EFI_NOT_FOUND The image specified by ImageId is not in the\r
315 database. The specified PackageList is not in the database.\r
316 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to\r
317 hold the image.\r
318 @retval EFI_INVALID_PARAMETER The Image was NULL or the ImageId was 0.\r
319 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there\r
320 was not enough memory.\r
321\r
322**/\r
323EFI_STATUS\r
324EFIAPI\r
325HiiGetImageInfo (\r
326 IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This,\r
327 IN EFI_HII_HANDLE PackageList,\r
328 IN EFI_IMAGE_ID ImageId,\r
329 OUT EFI_IMAGE_OUTPUT *Image\r
330 )\r
331{\r
332 EFI_STATUS Status;\r
333 HII_DATABASE_PRIVATE_DATA *Private;\r
334 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r
335 HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;\r
336 EFI_HII_IMAGE_BLOCK *CurrentImageBlock;\r
337 EFI_HII_IMAGE_DECODER_PROTOCOL *Decoder;\r
338 EFI_HII_IMAGE_DECODER_IMAGE_INFO_HEADER *ImageInfo;\r
339\r
340 if (Image == NULL || ImageId == 0) {\r
341 return EFI_INVALID_PARAMETER;\r
342 }\r
343\r
344 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
345 PackageListNode = LocatePackageList (&Private->DatabaseList, PackageList);\r
346 if (PackageListNode == NULL) {\r
347 return EFI_NOT_FOUND;\r
348 }\r
349 ImagePackage = PackageListNode->ImagePkg;\r
350 if (ImagePackage == NULL) {\r
351 return EFI_NOT_FOUND;\r
352 }\r
353\r
354 //\r
355 // Find the image block specified by ImageId\r
356 //\r
357 CurrentImageBlock = GetImageIdOrAddress (ImagePackage->ImageBlock, &ImageId);\r
4558491f
RN
358 if (CurrentImageBlock == NULL) {\r
359 return EFI_NOT_FOUND;\r
360 }\r
361\r
101a1122
RN
362 switch (CurrentImageBlock->BlockType) {\r
363 case EFI_HII_IIBT_IMAGE_JPEG:\r
364 case EFI_HII_IIBT_IMAGE_PNG:\r
365 Decoder = LocateHiiImageDecoder (CurrentImageBlock->BlockType);\r
366 if (Decoder == NULL) {\r
367 return EFI_UNSUPPORTED;\r
368 }\r
369 //\r
370 // Use the common block code since the definition of two structures is the same.\r
371 //\r
372 ASSERT (OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK, Data) == OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK, Data));\r
373 ASSERT (sizeof (((EFI_HII_IIBT_JPEG_BLOCK *) CurrentImageBlock)->Data) ==\r
374 sizeof (((EFI_HII_IIBT_PNG_BLOCK *) CurrentImageBlock)->Data));\r
375 ASSERT (OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK, Size) == OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK, Size));\r
376 ASSERT (sizeof (((EFI_HII_IIBT_JPEG_BLOCK *) CurrentImageBlock)->Size) ==\r
377 sizeof (((EFI_HII_IIBT_PNG_BLOCK *) CurrentImageBlock)->Size));\r
378 Status = Decoder->GetImageInfo (\r
379 Decoder,\r
380 ((EFI_HII_IIBT_JPEG_BLOCK *) CurrentImageBlock)->Data,\r
381 ((EFI_HII_IIBT_JPEG_BLOCK *) CurrentImageBlock)->Size,\r
382 &ImageInfo\r
383 );\r
384\r
385 //\r
386 // Spec requires to use the first capable image decoder instance.\r
387 // The first image decoder instance may fail to decode the image.\r
388 //\r
389 if (!EFI_ERROR (Status)) {\r
390 Image->Height = ImageInfo->ImageHeight;\r
391 Image->Width = ImageInfo->ImageWidth;\r
392 Image->Image.Bitmap = NULL;\r
393 FreePool (ImageInfo);\r
394 }\r
395 return Status;\r
396\r
397 case EFI_HII_IIBT_IMAGE_1BIT_TRANS:\r
398 case EFI_HII_IIBT_IMAGE_4BIT_TRANS:\r
399 case EFI_HII_IIBT_IMAGE_8BIT_TRANS:\r
400 case EFI_HII_IIBT_IMAGE_1BIT:\r
401 case EFI_HII_IIBT_IMAGE_4BIT:\r
402 case EFI_HII_IIBT_IMAGE_8BIT:\r
403 //\r
404 // Use the common block code since the definition of these structures is the same.\r
405 //\r
406 Image->Width = ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK *) CurrentImageBlock)->Bitmap.Width);\r
407 Image->Height = ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK *) CurrentImageBlock)->Bitmap.Height);\r
408 Image->Image.Bitmap = NULL;\r
409 return EFI_SUCCESS;\r
410\r
411 case EFI_HII_IIBT_IMAGE_24BIT_TRANS:\r
412 case EFI_HII_IIBT_IMAGE_24BIT:\r
413 Image->Width = ReadUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) CurrentImageBlock)->Bitmap.Width);\r
414 Image->Height = ReadUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) CurrentImageBlock)->Bitmap.Height);\r
415 Image->Image.Bitmap = NULL;\r
416 return EFI_SUCCESS;\r
417\r
418 default:\r
419 return EFI_NOT_FOUND;\r
420 }\r
421}\r