]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
MdeModulePkg/HiiDatabase: Move common code to LocatePackageList()
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / Image.c
CommitLineData
93e3992d 1/** @file\r
e90b081a 2Implementation for EFI_HII_IMAGE_PROTOCOL.\r
3\r
93e3992d 4\r
2a244a5d 5Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 6This program and the accompanying materials\r
93e3992d 7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
e90b081a 14**/\r
93e3992d 15\r
93e3992d 16\r
e90b081a 17#include "HiiDatabase.h"\r
93e3992d 18\r
19\r
e90b081a 20/**\r
21 Get the imageid of last image block: EFI_HII_IIBT_END_BLOCK when input\r
22 ImageId is zero, otherwise return the address of the\r
23 corresponding image block with identifier specified by ImageId.\r
93e3992d 24\r
e90b081a 25 This is a internal function.\r
93e3992d 26\r
7c28fcb8 27 @param ImageBlocks Points to the beginning of a series of image blocks stored in order.\r
e90b081a 28 @param ImageId If input ImageId is 0, output the image id of the EFI_HII_IIBT_END_BLOCK;\r
29 else use this id to find its corresponding image block address.\r
93e3992d 30\r
e90b081a 31 @return The image block address when input ImageId is not zero; otherwise return NULL.\r
93e3992d 32\r
e90b081a 33**/\r
7c28fcb8 34EFI_HII_IMAGE_BLOCK *\r
93e3992d 35GetImageIdOrAddress (\r
7c28fcb8
RN
36 IN EFI_HII_IMAGE_BLOCK *ImageBlocks,\r
37 IN OUT EFI_IMAGE_ID *ImageId\r
93e3992d 38 )\r
93e3992d 39{\r
40 EFI_IMAGE_ID ImageIdCurrent;\r
7c28fcb8
RN
41 EFI_HII_IMAGE_BLOCK *CurrentImageBlock;\r
42 UINTN Length;\r
43\r
44 ASSERT (ImageBlocks != NULL && ImageId != NULL);\r
45 CurrentImageBlock = ImageBlocks;\r
46 ImageIdCurrent = 1;\r
47\r
48 while (CurrentImageBlock->BlockType != EFI_HII_IIBT_END) {\r
49 if (*ImageId != 0) {\r
93e3992d 50 if (*ImageId == ImageIdCurrent) {\r
51 //\r
52 // If the found image block is a duplicate block, update the ImageId to\r
53 // find the previous defined image block.\r
54 //\r
7c28fcb8
RN
55 if (CurrentImageBlock->BlockType == EFI_HII_IIBT_DUPLICATE) {\r
56 *ImageId = ReadUnaligned16 ((VOID *) &((EFI_HII_IIBT_DUPLICATE_BLOCK *) CurrentImageBlock)->ImageId);\r
93e3992d 57 ASSERT (*ImageId != ImageIdCurrent);\r
7c28fcb8
RN
58 ASSERT (*ImageId != 0);\r
59 CurrentImageBlock = ImageBlocks;\r
93e3992d 60 ImageIdCurrent = 1;\r
61 continue;\r
62 }\r
63\r
7c28fcb8 64 return CurrentImageBlock;\r
93e3992d 65 }\r
66 if (*ImageId < ImageIdCurrent) {\r
67 //\r
68 // Can not find the specified image block in this image.\r
69 //\r
70 return NULL;\r
71 }\r
72 }\r
7c28fcb8 73 switch (CurrentImageBlock->BlockType) {\r
93e3992d 74 case EFI_HII_IIBT_EXT1:\r
7c28fcb8 75 Length = ((EFI_HII_IIBT_EXT1_BLOCK *) CurrentImageBlock)->Length;\r
93e3992d 76 break;\r
77 case EFI_HII_IIBT_EXT2:\r
7c28fcb8 78 Length = ReadUnaligned16 (&((EFI_HII_IIBT_EXT2_BLOCK *) CurrentImageBlock)->Length);\r
93e3992d 79 break;\r
80 case EFI_HII_IIBT_EXT4:\r
7c28fcb8 81 Length = ReadUnaligned32 ((VOID *) &((EFI_HII_IIBT_EXT4_BLOCK *) CurrentImageBlock)->Length);\r
93e3992d 82 break;\r
83\r
84 case EFI_HII_IIBT_IMAGE_1BIT:\r
85 case EFI_HII_IIBT_IMAGE_1BIT_TRANS:\r
7c28fcb8
RN
86 Length = sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK) - sizeof (UINT8) +\r
87 BITMAP_LEN_1_BIT (\r
88 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK *) CurrentImageBlock)->Bitmap.Width),\r
89 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK *) CurrentImageBlock)->Bitmap.Height)\r
90 );\r
93e3992d 91 ImageIdCurrent++;\r
92 break;\r
93\r
94 case EFI_HII_IIBT_IMAGE_4BIT:\r
95 case EFI_HII_IIBT_IMAGE_4BIT_TRANS:\r
7c28fcb8
RN
96 Length = sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK) - sizeof (UINT8) +\r
97 BITMAP_LEN_4_BIT (\r
98 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_4BIT_BLOCK *) CurrentImageBlock)->Bitmap.Width),\r
99 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_4BIT_BLOCK *) CurrentImageBlock)->Bitmap.Height)\r
100 );\r
93e3992d 101 ImageIdCurrent++;\r
102 break;\r
103\r
104 case EFI_HII_IIBT_IMAGE_8BIT:\r
105 case EFI_HII_IIBT_IMAGE_8BIT_TRANS:\r
7c28fcb8
RN
106 Length = sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK) - sizeof (UINT8) +\r
107 BITMAP_LEN_8_BIT (\r
108 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_8BIT_BLOCK *) CurrentImageBlock)->Bitmap.Width),\r
109 ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_8BIT_BLOCK *) CurrentImageBlock)->Bitmap.Height)\r
110 );\r
93e3992d 111 ImageIdCurrent++;\r
112 break;\r
113\r
114 case EFI_HII_IIBT_IMAGE_24BIT:\r
115 case EFI_HII_IIBT_IMAGE_24BIT_TRANS:\r
7c28fcb8
RN
116 Length = sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL) +\r
117 BITMAP_LEN_24_BIT (\r
118 ReadUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) CurrentImageBlock)->Bitmap.Width),\r
119 ReadUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) CurrentImageBlock)->Bitmap.Height)\r
120 );\r
93e3992d 121 ImageIdCurrent++;\r
122 break;\r
123\r
124 case EFI_HII_IIBT_DUPLICATE:\r
7c28fcb8 125 Length = sizeof (EFI_HII_IIBT_DUPLICATE_BLOCK);\r
93e3992d 126 ImageIdCurrent++;\r
127 break;\r
128\r
129 case EFI_HII_IIBT_IMAGE_JPEG:\r
7c28fcb8 130 Length = ReadUnaligned32 ((VOID *) &((EFI_HII_IIBT_JPEG_BLOCK *) CurrentImageBlock)->Size);\r
93e3992d 131 ImageIdCurrent++;\r
132 break;\r
133\r
134 case EFI_HII_IIBT_SKIP1:\r
7c28fcb8
RN
135 Length = sizeof (EFI_HII_IIBT_SKIP1_BLOCK);\r
136 ImageIdCurrent += ((EFI_HII_IIBT_SKIP1_BLOCK *) CurrentImageBlock)->SkipCount;\r
93e3992d 137 break;\r
138\r
139 case EFI_HII_IIBT_SKIP2:\r
7c28fcb8
RN
140 Length = sizeof (EFI_HII_IIBT_SKIP2_BLOCK);\r
141 ImageIdCurrent += ReadUnaligned16 ((VOID *) &((EFI_HII_IIBT_SKIP2_BLOCK *) CurrentImageBlock)->SkipCount);\r
93e3992d 142 break;\r
143\r
144 default:\r
145 //\r
146 // Unknown image blocks can not be skipped, processing halts.\r
147 //\r
148 ASSERT (FALSE);\r
7c28fcb8
RN
149 Length = 0;\r
150 break;\r
93e3992d 151 }\r
7c28fcb8
RN
152\r
153 CurrentImageBlock = (EFI_HII_IMAGE_BLOCK *) ((UINT8 *) CurrentImageBlock + Length);\r
154\r
93e3992d 155 }\r
156\r
157 //\r
158 // When ImageId is zero, return the imageid of last image block: EFI_HII_IIBT_END_BLOCK.\r
159 //\r
160 if (*ImageId == 0) {\r
161 *ImageId = ImageIdCurrent;\r
7c28fcb8 162 return CurrentImageBlock;\r
93e3992d 163 }\r
164\r
165 return NULL;\r
166}\r
167\r
168\r
169\r
170/**\r
171 Convert pixels from EFI_GRAPHICS_OUTPUT_BLT_PIXEL to EFI_HII_RGB_PIXEL style.\r
172\r
e90b081a 173 This is a internal function.\r
174\r
175\r
93e3992d 176 @param BitMapOut Pixels in EFI_HII_RGB_PIXEL format.\r
177 @param BitMapIn Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format.\r
178 @param PixelNum The number of pixels to be converted.\r
179\r
180\r
181**/\r
93e3992d 182VOID\r
183CopyGopToRgbPixel (\r
184 OUT EFI_HII_RGB_PIXEL *BitMapOut,\r
185 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapIn,\r
186 IN UINTN PixelNum\r
187 )\r
188{\r
189 UINTN Index;\r
190\r
191 ASSERT (BitMapOut != NULL && BitMapIn != NULL);\r
192\r
193 for (Index = 0; Index < PixelNum; Index++) {\r
194 CopyMem (BitMapOut + Index, BitMapIn + Index, sizeof (EFI_HII_RGB_PIXEL));\r
195 }\r
196}\r
197\r
198\r
199/**\r
200 Convert pixels from EFI_HII_RGB_PIXEL to EFI_GRAPHICS_OUTPUT_BLT_PIXEL style.\r
201\r
e90b081a 202 This is a internal function.\r
203\r
204\r
93e3992d 205 @param BitMapOut Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format.\r
206 @param BitMapIn Pixels in EFI_HII_RGB_PIXEL format.\r
207 @param PixelNum The number of pixels to be converted.\r
208\r
209\r
210**/\r
93e3992d 211VOID\r
212CopyRgbToGopPixel (\r
213 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapOut,\r
214 IN EFI_HII_RGB_PIXEL *BitMapIn,\r
215 IN UINTN PixelNum\r
216 )\r
217{\r
218 UINTN Index;\r
219\r
220 ASSERT (BitMapOut != NULL && BitMapIn != NULL);\r
221\r
222 for (Index = 0; Index < PixelNum; Index++) {\r
223 CopyMem (BitMapOut + Index, BitMapIn + Index, sizeof (EFI_HII_RGB_PIXEL));\r
224 }\r
225}\r
226\r
227\r
228/**\r
229 Output pixels in "1 bit per pixel" format to an image.\r
230\r
e90b081a 231 This is a internal function.\r
232\r
233\r
93e3992d 234 @param Image Points to the image which will store the pixels.\r
235 @param Data Stores the value of output pixels, 0 or 1.\r
236 @param PaletteInfo PaletteInfo which stores the color of the output\r
237 pixels. First entry corresponds to color 0 and\r
238 second one to color 1.\r
239\r
240\r
241**/\r
93e3992d 242VOID\r
243Output1bitPixel (\r
244 IN OUT EFI_IMAGE_INPUT *Image,\r
245 IN UINT8 *Data,\r
246 IN EFI_HII_IMAGE_PALETTE_INFO *PaletteInfo\r
247 )\r
248{\r
e90b081a 249 UINT16 Xpos;\r
250 UINT16 Ypos;\r
93e3992d 251 UINTN OffsetY;\r
252 UINT8 Index;\r
253 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapPtr;\r
254 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue[2];\r
255 EFI_HII_IMAGE_PALETTE_INFO *Palette;\r
2a244a5d 256 UINTN PaletteSize;\r
93e3992d 257 UINT8 Byte;\r
258\r
259 ASSERT (Image != NULL && Data != NULL && PaletteInfo != NULL);\r
260\r
261 BitMapPtr = Image->Bitmap;\r
262\r
263 //\r
264 // First entry corresponds to color 0 and second entry corresponds to color 1.\r
265 //\r
2a244a5d 266 PaletteSize = 0;\r
93e3992d 267 CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));\r
268 PaletteSize += sizeof (UINT16);\r
269 Palette = AllocateZeroPool (PaletteSize);\r
270 ASSERT (Palette != NULL);\r
2a244a5d
ED
271 if (Palette == NULL) {\r
272 return;\r
273 }\r
93e3992d 274 CopyMem (Palette, PaletteInfo, PaletteSize);\r
275\r
276 ZeroMem (PaletteValue, sizeof (PaletteValue));\r
277 CopyRgbToGopPixel (&PaletteValue[0], &Palette->PaletteValue[0], 1);\r
278 CopyRgbToGopPixel (&PaletteValue[1], &Palette->PaletteValue[1], 1);\r
676df92c 279 FreePool (Palette);\r
93e3992d 280\r
281 //\r
282 // Convert the pixel from one bit to corresponding color.\r
283 //\r
e90b081a 284 for (Ypos = 0; Ypos < Image->Height; Ypos++) {\r
285 OffsetY = BITMAP_LEN_1_BIT (Image->Width, Ypos);\r
93e3992d 286 //\r
287 // All bits in these bytes are meaningful\r
288 //\r
e90b081a 289 for (Xpos = 0; Xpos < Image->Width / 8; Xpos++) {\r
290 Byte = *(Data + OffsetY + Xpos);\r
93e3992d 291 for (Index = 0; Index < 8; Index++) {\r
292 if ((Byte & (1 << Index)) != 0) {\r
e90b081a 293 BitMapPtr[Ypos * Image->Width + Xpos * 8 + (8 - Index - 1)] = PaletteValue[1];\r
93e3992d 294 } else {\r
e90b081a 295 BitMapPtr[Ypos * Image->Width + Xpos * 8 + (8 - Index - 1)] = PaletteValue[0];\r
93e3992d 296 }\r
297 }\r
298 }\r
299\r
300 if (Image->Width % 8 != 0) {\r
301 //\r
302 // Padding bits in this byte should be ignored.\r
303 //\r
e90b081a 304 Byte = *(Data + OffsetY + Xpos);\r
93e3992d 305 for (Index = 0; Index < Image->Width % 8; Index++) {\r
306 if ((Byte & (1 << (8 - Index - 1))) != 0) {\r
e90b081a 307 BitMapPtr[Ypos * Image->Width + Xpos * 8 + Index] = PaletteValue[1];\r
93e3992d 308 } else {\r
e90b081a 309 BitMapPtr[Ypos * Image->Width + Xpos * 8 + Index] = PaletteValue[0];\r
93e3992d 310 }\r
311 }\r
312 }\r
313 }\r
314}\r
315\r
316\r
317/**\r
318 Output pixels in "4 bit per pixel" format to an image.\r
319\r
e90b081a 320 This is a internal function.\r
321\r
322\r
93e3992d 323 @param Image Points to the image which will store the pixels.\r
324 @param Data Stores the value of output pixels, 0 ~ 15.\r
e90b081a 325 @param[in] PaletteInfo PaletteInfo which stores the color of the output\r
93e3992d 326 pixels. Each entry corresponds to a color within\r
327 [0, 15].\r
328\r
329\r
330**/\r
93e3992d 331VOID\r
332Output4bitPixel (\r
333 IN OUT EFI_IMAGE_INPUT *Image,\r
334 IN UINT8 *Data,\r
335 IN EFI_HII_IMAGE_PALETTE_INFO *PaletteInfo\r
336 )\r
337{\r
e90b081a 338 UINT16 Xpos;\r
339 UINT16 Ypos;\r
93e3992d 340 UINTN OffsetY;\r
341 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapPtr;\r
342 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue[16];\r
343 EFI_HII_IMAGE_PALETTE_INFO *Palette;\r
2a244a5d 344 UINTN PaletteSize;\r
93e3992d 345 UINT16 PaletteNum;\r
346 UINT8 Byte;\r
347\r
348 ASSERT (Image != NULL && Data != NULL && PaletteInfo != NULL);\r
349\r
350 BitMapPtr = Image->Bitmap;\r
351\r
352 //\r
353 // The bitmap should allocate each color index starting from 0.\r
354 //\r
2a244a5d 355 PaletteSize = 0;\r
93e3992d 356 CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));\r
357 PaletteSize += sizeof (UINT16);\r
358 Palette = AllocateZeroPool (PaletteSize);\r
359 ASSERT (Palette != NULL);\r
2a244a5d
ED
360 if (Palette == NULL) {\r
361 return;\r
362 }\r
93e3992d 363 CopyMem (Palette, PaletteInfo, PaletteSize);\r
364 PaletteNum = (UINT16)(Palette->PaletteSize / sizeof (EFI_HII_RGB_PIXEL));\r
365\r
366 ZeroMem (PaletteValue, sizeof (PaletteValue));\r
367 CopyRgbToGopPixel (PaletteValue, Palette->PaletteValue, PaletteNum);\r
676df92c 368 FreePool (Palette);\r
93e3992d 369\r
370 //\r
371 // Convert the pixel from 4 bit to corresponding color.\r
372 //\r
e90b081a 373 for (Ypos = 0; Ypos < Image->Height; Ypos++) {\r
374 OffsetY = BITMAP_LEN_4_BIT (Image->Width, Ypos);\r
93e3992d 375 //\r
376 // All bits in these bytes are meaningful\r
377 //\r
e90b081a 378 for (Xpos = 0; Xpos < Image->Width / 2; Xpos++) {\r
379 Byte = *(Data + OffsetY + Xpos);\r
380 BitMapPtr[Ypos * Image->Width + Xpos * 2] = PaletteValue[Byte >> 4];\r
381 BitMapPtr[Ypos * Image->Width + Xpos * 2 + 1] = PaletteValue[Byte & 0x0F];\r
93e3992d 382 }\r
383\r
384 if (Image->Width % 2 != 0) {\r
385 //\r
386 // Padding bits in this byte should be ignored.\r
387 //\r
e90b081a 388 Byte = *(Data + OffsetY + Xpos);\r
389 BitMapPtr[Ypos * Image->Width + Xpos * 2] = PaletteValue[Byte >> 4];\r
93e3992d 390 }\r
391 }\r
392}\r
393\r
394\r
395/**\r
396 Output pixels in "8 bit per pixel" format to an image.\r
397\r
e90b081a 398 This is a internal function.\r
399\r
400\r
93e3992d 401 @param Image Points to the image which will store the pixels.\r
402 @param Data Stores the value of output pixels, 0 ~ 255.\r
e90b081a 403 @param[in] PaletteInfo PaletteInfo which stores the color of the output\r
93e3992d 404 pixels. Each entry corresponds to a color within\r
405 [0, 255].\r
406\r
407\r
408**/\r
93e3992d 409VOID\r
410Output8bitPixel (\r
411 IN OUT EFI_IMAGE_INPUT *Image,\r
412 IN UINT8 *Data,\r
413 IN EFI_HII_IMAGE_PALETTE_INFO *PaletteInfo\r
414 )\r
415{\r
e90b081a 416 UINT16 Xpos;\r
417 UINT16 Ypos;\r
93e3992d 418 UINTN OffsetY;\r
419 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapPtr;\r
420 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue[256];\r
421 EFI_HII_IMAGE_PALETTE_INFO *Palette;\r
2a244a5d 422 UINTN PaletteSize;\r
93e3992d 423 UINT16 PaletteNum;\r
424 UINT8 Byte;\r
425\r
426 ASSERT (Image != NULL && Data != NULL && PaletteInfo != NULL);\r
427\r
428 BitMapPtr = Image->Bitmap;\r
429\r
430 //\r
431 // The bitmap should allocate each color index starting from 0.\r
432 //\r
2a244a5d 433 PaletteSize = 0;\r
93e3992d 434 CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));\r
435 PaletteSize += sizeof (UINT16);\r
436 Palette = AllocateZeroPool (PaletteSize);\r
437 ASSERT (Palette != NULL);\r
2a244a5d
ED
438 if (Palette == NULL) {\r
439 return;\r
440 }\r
93e3992d 441 CopyMem (Palette, PaletteInfo, PaletteSize);\r
442 PaletteNum = (UINT16)(Palette->PaletteSize / sizeof (EFI_HII_RGB_PIXEL));\r
443 ZeroMem (PaletteValue, sizeof (PaletteValue));\r
444 CopyRgbToGopPixel (PaletteValue, Palette->PaletteValue, PaletteNum);\r
676df92c 445 FreePool (Palette);\r
93e3992d 446\r
447 //\r
448 // Convert the pixel from 8 bits to corresponding color.\r
449 //\r
e90b081a 450 for (Ypos = 0; Ypos < Image->Height; Ypos++) {\r
451 OffsetY = BITMAP_LEN_8_BIT (Image->Width, Ypos);\r
93e3992d 452 //\r
453 // All bits are meaningful since the bitmap is 8 bits per pixel.\r
454 //\r
e90b081a 455 for (Xpos = 0; Xpos < Image->Width; Xpos++) {\r
456 Byte = *(Data + OffsetY + Xpos);\r
457 BitMapPtr[OffsetY + Xpos] = PaletteValue[Byte];\r
93e3992d 458 }\r
459 }\r
460\r
461}\r
462\r
463\r
464/**\r
465 Output pixels in "24 bit per pixel" format to an image.\r
466\r
e90b081a 467 This is a internal function.\r
468\r
469\r
93e3992d 470 @param Image Points to the image which will store the pixels.\r
471 @param Data Stores the color of output pixels, allowing 16.8\r
472 millions colors.\r
473\r
474\r
475**/\r
93e3992d 476VOID\r
477Output24bitPixel (\r
478 IN OUT EFI_IMAGE_INPUT *Image,\r
479 IN EFI_HII_RGB_PIXEL *Data\r
480 )\r
481{\r
e90b081a 482 UINT16 Ypos;\r
93e3992d 483 UINTN OffsetY;\r
484 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapPtr;\r
485\r
486 ASSERT (Image != NULL && Data != NULL);\r
487\r
488 BitMapPtr = Image->Bitmap;\r
489\r
e90b081a 490 for (Ypos = 0; Ypos < Image->Height; Ypos++) {\r
491 OffsetY = BITMAP_LEN_8_BIT (Image->Width, Ypos);\r
93e3992d 492 CopyRgbToGopPixel (&BitMapPtr[OffsetY], &Data[OffsetY], Image->Width);\r
493 }\r
494\r
495}\r
496\r
497\r
498/**\r
499 Convert the image from EFI_IMAGE_INPUT to EFI_IMAGE_OUTPUT format.\r
500\r
e90b081a 501 This is a internal function.\r
502\r
503\r
93e3992d 504 @param BltBuffer Buffer points to bitmap data of incoming image.\r
e90b081a 505 @param BltX Specifies the offset from the left and top edge of\r
506 the output image of the first pixel in the image.\r
93e3992d 507 @param BltY Specifies the offset from the left and top edge of\r
508 the output image of the first pixel in the image.\r
509 @param Width Width of the incoming image, in pixels.\r
510 @param Height Height of the incoming image, in pixels.\r
511 @param Transparent If TRUE, all "off" pixels in the image will be\r
512 drawn using the pixel value from blt and all other\r
513 pixels will be copied.\r
514 @param Blt Buffer points to bitmap data of output image.\r
515\r
516 @retval EFI_SUCCESS The image was successfully converted.\r
517 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.\r
518\r
519**/\r
93e3992d 520EFI_STATUS\r
521ImageToBlt (\r
522 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,\r
523 IN UINTN BltX,\r
524 IN UINTN BltY,\r
525 IN UINTN Width,\r
526 IN UINTN Height,\r
527 IN BOOLEAN Transparent,\r
528 IN OUT EFI_IMAGE_OUTPUT **Blt\r
529 )\r
530{\r
531 EFI_IMAGE_OUTPUT *ImageOut;\r
e90b081a 532 UINTN Xpos;\r
533 UINTN Ypos;\r
93e3992d 534 UINTN OffsetY1; // src buffer\r
535 UINTN OffsetY2; // dest buffer\r
536 EFI_GRAPHICS_OUTPUT_BLT_PIXEL SrcPixel;\r
537 EFI_GRAPHICS_OUTPUT_BLT_PIXEL ZeroPixel;\r
538\r
539 if (BltBuffer == NULL || Blt == NULL || *Blt == NULL) {\r
540 return EFI_INVALID_PARAMETER;\r
541 }\r
542\r
543 ImageOut = *Blt;\r
544\r
545 if (Width + BltX > ImageOut->Width) {\r
546 return EFI_INVALID_PARAMETER;\r
547 }\r
548 if (Height + BltY > ImageOut->Height) {\r
549 return EFI_INVALID_PARAMETER;\r
550 }\r
551\r
552 ZeroMem (&ZeroPixel, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
553\r
e90b081a 554 for (Ypos = 0; Ypos < Height; Ypos++) {\r
555 OffsetY1 = Width * Ypos;\r
556 OffsetY2 = ImageOut->Width * (BltY + Ypos);\r
557 for (Xpos = 0; Xpos < Width; Xpos++) {\r
558 SrcPixel = BltBuffer[OffsetY1 + Xpos];\r
93e3992d 559 if (Transparent) {\r
560 if (CompareMem (&SrcPixel, &ZeroPixel, 3) != 0) {\r
e90b081a 561 ImageOut->Image.Bitmap[OffsetY2 + BltX + Xpos] = SrcPixel;\r
93e3992d 562 }\r
563 } else {\r
e90b081a 564 ImageOut->Image.Bitmap[OffsetY2 + BltX + Xpos] = SrcPixel;\r
93e3992d 565 }\r
566 }\r
567 }\r
568\r
569 return EFI_SUCCESS;\r
570}\r
571\r
9d91ff0e
RN
572/**\r
573 Return the HII package list identified by PackageList HII handle.\r
574\r
575 @param Database Pointer to HII database list header.\r
576 @param PackageList HII handle of the package list to locate.\r
577\r
578 @retval The HII package list instance.\r
579**/\r
580HII_DATABASE_PACKAGE_LIST_INSTANCE *\r
581LocatePackageList (\r
582 IN LIST_ENTRY *Database,\r
583 IN EFI_HII_HANDLE PackageList\r
584 )\r
585{\r
586 LIST_ENTRY *Link;\r
587 HII_DATABASE_RECORD *Record;\r
588\r
589 //\r
590 // Get the specified package list and image package.\r
591 //\r
592 for (Link = GetFirstNode (Database);\r
593 !IsNull (Database, Link);\r
594 Link = GetNextNode (Database, Link)\r
595 ) {\r
596 Record = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r
597 if (Record->Handle == PackageList) {\r
598 return Record->PackageList;\r
599 }\r
600 }\r
601 return NULL;\r
602}\r
93e3992d 603\r
604/**\r
605 This function adds the image Image to the group of images owned by PackageList, and returns\r
606 a new image identifier (ImageId).\r
607\r
608 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r
609 @param PackageList Handle of the package list where this image will\r
610 be added.\r
611 @param ImageId On return, contains the new image id, which is\r
612 unique within PackageList.\r
613 @param Image Points to the image.\r
614\r
615 @retval EFI_SUCCESS The new image was added successfully.\r
616 @retval EFI_NOT_FOUND The specified PackageList could not be found in\r
617 database.\r
618 @retval EFI_OUT_OF_RESOURCES Could not add the image due to lack of resources.\r
619 @retval EFI_INVALID_PARAMETER Image is NULL or ImageId is NULL.\r
620\r
621**/\r
622EFI_STATUS\r
623EFIAPI\r
624HiiNewImage (\r
625 IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r
626 IN EFI_HII_HANDLE PackageList,\r
627 OUT EFI_IMAGE_ID *ImageId,\r
628 IN CONST EFI_IMAGE_INPUT *Image\r
629 )\r
630{\r
631 HII_DATABASE_PRIVATE_DATA *Private;\r
93e3992d 632 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r
633 HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;\r
634 UINT8 *ImageBlock;\r
635 UINTN BlockSize;\r
636 UINT8 *NewBlock;\r
637 UINT8 *NewBlockPtr;\r
638 UINTN NewBlockSize;\r
639 EFI_IMAGE_INPUT *ImageIn;\r
640\r
813acf3a 641 if (This == NULL || ImageId == NULL || Image == NULL || Image->Bitmap == NULL) {\r
93e3992d 642 return EFI_INVALID_PARAMETER;\r
643 }\r
644\r
645 if (!IsHiiHandleValid (PackageList)) {\r
646 return EFI_NOT_FOUND;\r
647 }\r
648\r
649 Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
9d91ff0e 650 PackageListNode = LocatePackageList (&Private->DatabaseList, PackageList);\r
93e3992d 651 if (PackageListNode == NULL) {\r
652 return EFI_NOT_FOUND;\r
653 }\r
654\r
655 ImageIn = (EFI_IMAGE_INPUT *) Image;\r
656\r
657 NewBlockSize = sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL) +\r
658 BITMAP_LEN_24_BIT (ImageIn->Width, ImageIn->Height);\r
659\r
660 //\r
661 // Get the image package in the package list,\r
662 // or create a new image package if image package does not exist.\r
663 //\r
664 if (PackageListNode->ImagePkg != NULL) {\r
665 ImagePackage = PackageListNode->ImagePkg;\r
666\r
667 //\r
668 // Output the image id of the incoming image being inserted, which is the\r
669 // image id of the EFI_HII_IIBT_END block of old image package.\r
670 //\r
671 *ImageId = 0;\r
672 GetImageIdOrAddress (ImagePackage->ImageBlock, ImageId);\r
673\r
674 //\r
675 // Update the package's image block by appending the new block to the end.\r
676 //\r
677 BlockSize = ImagePackage->ImageBlockSize + NewBlockSize;\r
678 ImageBlock = (UINT8 *) AllocateZeroPool (BlockSize);\r
679 if (ImageBlock == NULL) {\r
680 return EFI_OUT_OF_RESOURCES;\r
681 }\r
682 //\r
683 // Copy the original content.\r
684 //\r
685 CopyMem (\r
686 ImageBlock,\r
687 ImagePackage->ImageBlock,\r
688 ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK)\r
689 );\r
676df92c 690 FreePool (ImagePackage->ImageBlock);\r
7c28fcb8 691 ImagePackage->ImageBlock = (EFI_HII_IMAGE_BLOCK *) ImageBlock;\r
93e3992d 692 ImageBlock += ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK);\r
693 //\r
694 // Temp memory to store new block.\r
695 //\r
696 NewBlock = AllocateZeroPool (NewBlockSize);\r
697 if (NewBlock == NULL) {\r
676df92c 698 FreePool (ImagePackage->ImageBlock);\r
93e3992d 699 return EFI_OUT_OF_RESOURCES;\r
700 }\r
701 NewBlockPtr = NewBlock;\r
702\r
703 //\r
704 // Update the length record.\r
705 //\r
706 ImagePackage->ImageBlockSize = (UINT32) BlockSize;\r
707 ImagePackage->ImagePkgHdr.Header.Length += (UINT32) NewBlockSize;\r
708 PackageListNode->PackageListHdr.PackageLength += (UINT32) NewBlockSize;\r
709\r
710 } else {\r
711 //\r
712 // The specified package list does not contain image package.\r
713 // Create one to add this image block.\r
714 //\r
715 ImagePackage = (HII_IMAGE_PACKAGE_INSTANCE *) AllocateZeroPool (sizeof (HII_IMAGE_PACKAGE_INSTANCE));\r
716 if (ImagePackage == NULL) {\r
717 return EFI_OUT_OF_RESOURCES;\r
718 }\r
719 //\r
720 // Output the image id of the incoming image being inserted, which is the\r
721 // first image block so that id is initially to one.\r
722 //\r
723 *ImageId = 1;\r
724 BlockSize = sizeof (EFI_HII_IIBT_END_BLOCK) + NewBlockSize;\r
725 //\r
726 // Fill in image package header.\r
727 //\r
728 ImagePackage->ImagePkgHdr.Header.Length = (UINT32) BlockSize + sizeof (EFI_HII_IMAGE_PACKAGE_HDR);\r
729 ImagePackage->ImagePkgHdr.Header.Type = EFI_HII_PACKAGE_IMAGES;\r
730 ImagePackage->ImagePkgHdr.ImageInfoOffset = sizeof (EFI_HII_IMAGE_PACKAGE_HDR);\r
731 ImagePackage->ImagePkgHdr.PaletteInfoOffset = 0;\r
732\r
733 //\r
734 // Fill in palette info.\r
735 //\r
736 ImagePackage->PaletteBlock = NULL;\r
737 ImagePackage->PaletteInfoSize = 0;\r
738\r
739 //\r
740 // Fill in image blocks.\r
741 //\r
742 ImagePackage->ImageBlockSize = (UINT32) BlockSize;\r
7c28fcb8 743 ImagePackage->ImageBlock = AllocateZeroPool (BlockSize);\r
93e3992d 744 if (ImagePackage->ImageBlock == NULL) {\r
676df92c 745 FreePool (ImagePackage);\r
93e3992d 746 return EFI_OUT_OF_RESOURCES;\r
747 }\r
7c28fcb8 748 ImageBlock = (UINT8 *) ImagePackage->ImageBlock;\r
93e3992d 749\r
750 //\r
751 // Temp memory to store new block.\r
752 //\r
753 NewBlock = AllocateZeroPool (NewBlockSize);\r
754 if (NewBlock == NULL) {\r
676df92c 755 FreePool (ImagePackage->ImageBlock);\r
756 FreePool (ImagePackage);\r
93e3992d 757 return EFI_OUT_OF_RESOURCES;\r
758 }\r
759 NewBlockPtr = NewBlock;\r
760\r
761 //\r
762 // Insert this image package.\r
763 //\r
764 PackageListNode->ImagePkg = ImagePackage;\r
765 PackageListNode->PackageListHdr.PackageLength += ImagePackage->ImagePkgHdr.Header.Length;\r
766 }\r
767\r
768 //\r
769 // Append the new block here\r
770 //\r
771 if (ImageIn->Flags == EFI_IMAGE_TRANSPARENT) {\r
772 *NewBlock = EFI_HII_IIBT_IMAGE_24BIT_TRANS;\r
773 } else {\r
774 *NewBlock = EFI_HII_IIBT_IMAGE_24BIT;\r
775 }\r
776 NewBlock++;\r
777 CopyMem (NewBlock, &ImageIn->Width, sizeof (UINT16));\r
778 NewBlock += sizeof (UINT16);\r
779 CopyMem (NewBlock, &ImageIn->Height, sizeof (UINT16));\r
780 NewBlock += sizeof (UINT16);\r
781 CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL *) NewBlock, ImageIn->Bitmap, ImageIn->Width * ImageIn->Height);\r
782\r
783 CopyMem (ImageBlock, NewBlockPtr, NewBlockSize);\r
676df92c 784 FreePool (NewBlockPtr);\r
93e3992d 785\r
786 //\r
787 // Append the block end\r
788 //\r
789 ImageBlock += NewBlockSize;\r
790 ((EFI_HII_IIBT_END_BLOCK *) (ImageBlock))->Header.BlockType = EFI_HII_IIBT_END;\r
791\r
8a45f80e
DB
792 //\r
793 // Check whether need to get the contents of HiiDataBase.\r
794 // Only after ReadyToBoot to do the export.\r
795 //\r
796 if (gExportAfterReadyToBoot) {\r
797 HiiGetDatabaseInfo(&Private->HiiDatabase);\r
798 }\r
799\r
93e3992d 800 return EFI_SUCCESS;\r
801}\r
802\r
803\r
804/**\r
805 This function retrieves the image specified by ImageId which is associated with\r
806 the specified PackageList and copies it into the buffer specified by Image.\r
807\r
808 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r
809 @param PackageList Handle of the package list where this image will\r
810 be searched.\r
ac644614 811 @param ImageId The image's id,, which is unique within\r
93e3992d 812 PackageList.\r
813 @param Image Points to the image.\r
93e3992d 814\r
815 @retval EFI_SUCCESS The new image was returned successfully.\r
813acf3a 816 @retval EFI_NOT_FOUND The image specified by ImageId is not in the\r
817 database. The specified PackageList is not in the database.\r
93e3992d 818 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to\r
819 hold the image.\r
820 @retval EFI_INVALID_PARAMETER The Image or ImageSize was NULL.\r
813acf3a 821 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there was not\r
822 enough memory.\r
93e3992d 823\r
824**/\r
825EFI_STATUS\r
826EFIAPI\r
827HiiGetImage (\r
828 IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r
829 IN EFI_HII_HANDLE PackageList,\r
830 IN EFI_IMAGE_ID ImageId,\r
813acf3a 831 OUT EFI_IMAGE_INPUT *Image\r
93e3992d 832 )\r
833{\r
834 HII_DATABASE_PRIVATE_DATA *Private;\r
93e3992d 835 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r
836 HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;\r
837 UINT8 *ImageBlock;\r
838 EFI_IMAGE_ID LocalImageId;\r
839 UINT8 BlockType;\r
840 EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit;\r
841 UINT16 Width;\r
842 UINT16 Height;\r
843 UINTN ImageLength;\r
844 BOOLEAN Flag;\r
845 UINT8 *PaletteInfo;\r
846 UINT8 PaletteIndex;\r
847 UINT16 PaletteSize;\r
848\r
813acf3a 849 if (This == NULL || Image == NULL || ImageId < 1) {\r
93e3992d 850 return EFI_INVALID_PARAMETER;\r
851 }\r
852\r
853 if (!IsHiiHandleValid (PackageList)) {\r
854 return EFI_NOT_FOUND;\r
855 }\r
856\r
857 Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
9d91ff0e 858 PackageListNode = LocatePackageList (&Private->DatabaseList, PackageList);\r
93e3992d 859 if (PackageListNode == NULL) {\r
860 return EFI_NOT_FOUND;\r
861 }\r
862 ImagePackage = PackageListNode->ImagePkg;\r
863 if (ImagePackage == NULL) {\r
864 return EFI_NOT_FOUND;\r
865 }\r
866\r
867 //\r
868 // Find the image block specified by ImageId\r
869 //\r
870 LocalImageId = ImageId;\r
7c28fcb8 871 ImageBlock = (UINT8 *) GetImageIdOrAddress (ImagePackage->ImageBlock, &LocalImageId);\r
93e3992d 872 if (ImageBlock == NULL) {\r
873 return EFI_NOT_FOUND;\r
874 }\r
875\r
876 Flag = FALSE;\r
877 BlockType = *ImageBlock;\r
878\r
879 switch (BlockType) {\r
880 case EFI_HII_IIBT_IMAGE_JPEG:\r
881 //\r
882 // BUGBUG: need to be supported as soon as image tool is designed.\r
883 //\r
884 return EFI_UNSUPPORTED;\r
93e3992d 885\r
886 case EFI_HII_IIBT_IMAGE_1BIT_TRANS:\r
887 case EFI_HII_IIBT_IMAGE_4BIT_TRANS:\r
888 case EFI_HII_IIBT_IMAGE_8BIT_TRANS:\r
889 Flag = TRUE;\r
890 //\r
891 // fall through\r
892 //\r
893 case EFI_HII_IIBT_IMAGE_1BIT:\r
894 case EFI_HII_IIBT_IMAGE_4BIT:\r
895 case EFI_HII_IIBT_IMAGE_8BIT:\r
896 //\r
897 // Use the common block code since the definition of these structures is the same.\r
898 //\r
899 CopyMem (&Iibt1bit, ImageBlock, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK));\r
813acf3a 900 ImageLength = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) *\r
901 (Iibt1bit.Bitmap.Width * Iibt1bit.Bitmap.Height);\r
902 Image->Bitmap = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (ImageLength);\r
903 if (Image->Bitmap == NULL) {\r
904 return EFI_OUT_OF_RESOURCES;\r
93e3992d 905 }\r
93e3992d 906\r
907 if (Flag) {\r
908 Image->Flags = EFI_IMAGE_TRANSPARENT;\r
909 }\r
910 Image->Width = Iibt1bit.Bitmap.Width;\r
911 Image->Height = Iibt1bit.Bitmap.Height;\r
912\r
913 PaletteInfo = ImagePackage->PaletteBlock + sizeof (EFI_HII_IMAGE_PALETTE_INFO_HEADER);\r
914 for (PaletteIndex = 1; PaletteIndex < Iibt1bit.PaletteIndex; PaletteIndex++) {\r
915 CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));\r
916 PaletteInfo += PaletteSize + sizeof (UINT16);\r
917 }\r
918 ASSERT (PaletteIndex == Iibt1bit.PaletteIndex);\r
919\r
920 //\r
921 // Output bitmap data\r
922 //\r
923 if (BlockType == EFI_HII_IIBT_IMAGE_1BIT || BlockType == EFI_HII_IIBT_IMAGE_1BIT_TRANS) {\r
924 Output1bitPixel (\r
925 Image,\r
6e1e5405 926 (UINT8 *) ((UINTN)ImageBlock + sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK) - sizeof (UINT8)),\r
93e3992d 927 (EFI_HII_IMAGE_PALETTE_INFO *) PaletteInfo\r
928 );\r
929 } else if (BlockType == EFI_HII_IIBT_IMAGE_4BIT || BlockType == EFI_HII_IIBT_IMAGE_4BIT_TRANS) {\r
930 Output4bitPixel (\r
931 Image,\r
6e1e5405 932 (UINT8 *) ((UINTN)ImageBlock + sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK) - sizeof (UINT8)),\r
93e3992d 933 (EFI_HII_IMAGE_PALETTE_INFO *) PaletteInfo\r
934 );\r
935 } else {\r
936 Output8bitPixel (\r
937 Image,\r
6e1e5405 938 (UINT8 *) ((UINTN)ImageBlock + sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK) - sizeof (UINT8)),\r
93e3992d 939 (EFI_HII_IMAGE_PALETTE_INFO *) PaletteInfo\r
940 );\r
941 }\r
942\r
943 return EFI_SUCCESS;\r
93e3992d 944\r
945 case EFI_HII_IIBT_IMAGE_24BIT_TRANS:\r
946 Flag = TRUE;\r
947 //\r
948 // fall through\r
949 //\r
950 case EFI_HII_IIBT_IMAGE_24BIT:\r
951 CopyMem (&Width, ImageBlock + sizeof (EFI_HII_IMAGE_BLOCK), sizeof (UINT16));\r
952 CopyMem (\r
953 &Height,\r
954 ImageBlock + sizeof (EFI_HII_IMAGE_BLOCK) + sizeof (UINT16),\r
955 sizeof (UINT16)\r
956 );\r
813acf3a 957 ImageLength = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * (Width * Height);\r
958 Image->Bitmap = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (ImageLength);\r
959 if (Image->Bitmap == NULL) {\r
960 return EFI_OUT_OF_RESOURCES;\r
93e3992d 961 }\r
93e3992d 962\r
963 if (Flag) {\r
964 Image->Flags = EFI_IMAGE_TRANSPARENT;\r
965 }\r
966 Image->Width = Width;\r
967 Image->Height = Height;\r
968\r
969 //\r
970 // Output the bimap data directly.\r
971 //\r
972 Output24bitPixel (\r
973 Image,\r
974 (EFI_HII_RGB_PIXEL *) (ImageBlock + sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL))\r
975 );\r
976 return EFI_SUCCESS;\r
93e3992d 977\r
978 default:\r
979 return EFI_NOT_FOUND;\r
93e3992d 980 }\r
981}\r
982\r
983\r
984/**\r
985 This function updates the image specified by ImageId in the specified PackageListHandle to\r
986 the image specified by Image.\r
987\r
988 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r
989 @param PackageList The package list containing the images.\r
ac644614 990 @param ImageId The image's id,, which is unique within\r
93e3992d 991 PackageList.\r
992 @param Image Points to the image.\r
993\r
994 @retval EFI_SUCCESS The new image was updated successfully.\r
995 @retval EFI_NOT_FOUND The image specified by ImageId is not in the\r
813acf3a 996 database. The specified PackageList is not in the database. \r
93e3992d 997 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
998\r
999**/\r
1000EFI_STATUS\r
1001EFIAPI\r
1002HiiSetImage (\r
1003 IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r
1004 IN EFI_HII_HANDLE PackageList,\r
1005 IN EFI_IMAGE_ID ImageId,\r
1006 IN CONST EFI_IMAGE_INPUT *Image\r
1007 )\r
1008{\r
1009 HII_DATABASE_PRIVATE_DATA *Private;\r
93e3992d 1010 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r
1011 HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;\r
1012 UINT8 *ImageBlock;\r
1013 EFI_IMAGE_ID LocalImageId;\r
1014 UINT8 BlockType;\r
1015 EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit;\r
1016 EFI_HII_IIBT_IMAGE_4BIT_BLOCK Iibt4bit;\r
1017 EFI_HII_IIBT_IMAGE_8BIT_BLOCK Iibt8bit;\r
1018 UINT16 Width;\r
1019 UINT16 Height;\r
1020 UINT32 BlockSize;\r
1021 UINT32 NewBlockSize;\r
1022 UINT32 OldBlockSize;\r
1023 EFI_IMAGE_INPUT *ImageIn;\r
1024 UINT8 *NewBlock;\r
1025 UINT8 *NewBlockPtr;\r
1026 UINT8 *Block;\r
1027 UINT8 *BlockPtr;\r
1028 UINT32 Part1Size;\r
1029 UINT32 Part2Size;\r
1030\r
813acf3a 1031 if (This == NULL || Image == NULL || ImageId < 1 || Image->Bitmap == NULL) {\r
93e3992d 1032 return EFI_INVALID_PARAMETER;\r
1033 }\r
1034\r
1035 if (!IsHiiHandleValid (PackageList)) {\r
1036 return EFI_NOT_FOUND;\r
1037 }\r
1038\r
1039 Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
9d91ff0e 1040 PackageListNode = LocatePackageList (&Private->DatabaseList, PackageList);\r
93e3992d 1041 if (PackageListNode == NULL) {\r
1042 return EFI_NOT_FOUND;\r
1043 }\r
1044 ImagePackage = PackageListNode->ImagePkg;\r
1045 if (ImagePackage == NULL) {\r
1046 return EFI_NOT_FOUND;\r
1047 }\r
1048\r
1049 //\r
1050 // Find the image block specified by ImageId\r
1051 //\r
1052 LocalImageId = ImageId;\r
7c28fcb8 1053 ImageBlock = (UINT8 *) GetImageIdOrAddress (ImagePackage->ImageBlock, &LocalImageId);\r
93e3992d 1054 if (ImageBlock == NULL) {\r
1055 return EFI_NOT_FOUND;\r
1056 }\r
1057\r
1058 BlockType = *ImageBlock;\r
1059\r
1060 //\r
1061 // Get the size of original image block. Use some common block code here\r
1062 // since the definition of some structures is the same.\r
1063 //\r
1064 switch (BlockType) {\r
1065 case EFI_HII_IIBT_IMAGE_JPEG:\r
1066 //\r
1067 // BUGBUG: need to be supported as soon as image tool is designed.\r
1068 //\r
1069 return EFI_UNSUPPORTED;\r
93e3992d 1070\r
1071 case EFI_HII_IIBT_IMAGE_1BIT:\r
1072 case EFI_HII_IIBT_IMAGE_1BIT_TRANS:\r
1073 CopyMem (&Iibt1bit, ImageBlock, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK));\r
1074 OldBlockSize = sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK) - sizeof (UINT8) +\r
1075 BITMAP_LEN_1_BIT (Iibt1bit.Bitmap.Width, Iibt1bit.Bitmap.Height);\r
1076 break;\r
1077 case EFI_HII_IIBT_IMAGE_4BIT:\r
1078 case EFI_HII_IIBT_IMAGE_4BIT_TRANS:\r
1079 CopyMem (&Iibt4bit, ImageBlock, sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK));\r
1080 OldBlockSize = sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK) - sizeof (UINT8) +\r
1081 BITMAP_LEN_4_BIT (Iibt4bit.Bitmap.Width, Iibt4bit.Bitmap.Height);\r
1082 break;\r
1083 case EFI_HII_IIBT_IMAGE_8BIT:\r
1084 case EFI_HII_IIBT_IMAGE_8BIT_TRANS:\r
1085 CopyMem (&Iibt8bit, ImageBlock, sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK));\r
1086 OldBlockSize = sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK) - sizeof (UINT8) +\r
1087 BITMAP_LEN_8_BIT (Iibt8bit.Bitmap.Width, Iibt8bit.Bitmap.Height);\r
1088 break;\r
1089 case EFI_HII_IIBT_IMAGE_24BIT:\r
1090 case EFI_HII_IIBT_IMAGE_24BIT_TRANS:\r
1091 CopyMem (&Width, ImageBlock + sizeof (EFI_HII_IMAGE_BLOCK), sizeof (UINT16));\r
1092 CopyMem (\r
1093 &Height,\r
1094 ImageBlock + sizeof (EFI_HII_IMAGE_BLOCK) + sizeof (UINT16),\r
1095 sizeof (UINT16)\r
1096 );\r
1097 OldBlockSize = sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL) +\r
1098 BITMAP_LEN_24_BIT (Width , Height);\r
1099 break;\r
1100 default:\r
1101 return EFI_NOT_FOUND;\r
93e3992d 1102 }\r
1103\r
1104 //\r
1105 // Create the new image block according to input image.\r
1106 //\r
1107 ImageIn = (EFI_IMAGE_INPUT *) Image;\r
1108 NewBlockSize = sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL) +\r
1109 BITMAP_LEN_24_BIT (ImageIn->Width, ImageIn->Height);\r
1110 NewBlock = (UINT8 *) AllocateZeroPool (NewBlockSize);\r
1111 if (NewBlock == NULL) {\r
1112 return EFI_OUT_OF_RESOURCES;\r
1113 }\r
1114\r
1115 NewBlockPtr = NewBlock;\r
1116 if ((ImageIn->Flags & EFI_IMAGE_TRANSPARENT) == EFI_IMAGE_TRANSPARENT) {\r
1117 *NewBlockPtr = EFI_HII_IIBT_IMAGE_24BIT_TRANS;\r
1118 } else {\r
1119 *NewBlockPtr = EFI_HII_IIBT_IMAGE_24BIT;\r
1120 }\r
1121 NewBlockPtr++;\r
1122\r
1123 CopyMem (NewBlockPtr, &ImageIn->Width, sizeof (UINT16));\r
1124 NewBlockPtr += sizeof (UINT16);\r
1125 CopyMem (NewBlockPtr, &ImageIn->Height, sizeof (UINT16));\r
1126 NewBlockPtr += sizeof (UINT16);\r
1127\r
1128 CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL *) NewBlockPtr, ImageIn->Bitmap, ImageIn->Width * ImageIn->Height);\r
1129\r
1130 //\r
1131 // Adjust the image package to remove the original block firstly then add the new block.\r
1132 //\r
1133 BlockSize = ImagePackage->ImageBlockSize + NewBlockSize - OldBlockSize;\r
1134 Block = (UINT8 *) AllocateZeroPool (BlockSize);\r
1135 if (Block == NULL) {\r
676df92c 1136 FreePool (NewBlock);\r
93e3992d 1137 return EFI_OUT_OF_RESOURCES;\r
1138 }\r
1139\r
1140 BlockPtr = Block;\r
7c28fcb8 1141 Part1Size = (UINT32) (ImageBlock - (UINT8 *) ImagePackage->ImageBlock);\r
93e3992d 1142 Part2Size = ImagePackage->ImageBlockSize - Part1Size - OldBlockSize;\r
1143 CopyMem (BlockPtr, ImagePackage->ImageBlock, Part1Size);\r
1144 BlockPtr += Part1Size;\r
1145 CopyMem (BlockPtr, NewBlock, NewBlockSize);\r
1146 BlockPtr += NewBlockSize;\r
1147 CopyMem (BlockPtr, ImageBlock + OldBlockSize, Part2Size);\r
1148\r
676df92c 1149 FreePool (ImagePackage->ImageBlock);\r
1150 FreePool (NewBlock);\r
7c28fcb8 1151 ImagePackage->ImageBlock = (EFI_HII_IMAGE_BLOCK *) Block;\r
93e3992d 1152 ImagePackage->ImageBlockSize = BlockSize;\r
1153 ImagePackage->ImagePkgHdr.Header.Length += NewBlockSize - OldBlockSize;\r
1154 PackageListNode->PackageListHdr.PackageLength += NewBlockSize - OldBlockSize;\r
1155\r
8a45f80e
DB
1156 //\r
1157 // Check whether need to get the contents of HiiDataBase.\r
1158 // Only after ReadyToBoot to do the export.\r
1159 //\r
1160 if (gExportAfterReadyToBoot) {\r
1161 HiiGetDatabaseInfo(&Private->HiiDatabase);\r
1162 }\r
1163\r
93e3992d 1164 return EFI_SUCCESS;\r
1165\r
1166}\r
1167\r
1168\r
1169/**\r
1170 This function renders an image to a bitmap or the screen using the specified\r
1171 color and options. It draws the image on an existing bitmap, allocates a new\r
1172 bitmap or uses the screen. The images can be clipped.\r
1173\r
1174 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r
1175 @param Flags Describes how the image is to be drawn.\r
1176 @param Image Points to the image to be displayed.\r
1177 @param Blt If this points to a non-NULL on entry, this points\r
1178 to the image, which is Width pixels wide and\r
1179 Height pixels high. The image will be drawn onto\r
1180 this image and EFI_HII_DRAW_FLAG_CLIP is implied.\r
1181 If this points to a NULL on entry, then a buffer\r
1182 will be allocated to hold the generated image and\r
ac644614 1183 the pointer updated on exit. It is the caller's\r
93e3992d 1184 responsibility to free this buffer.\r
e90b081a 1185 @param BltX Specifies the offset from the left and top edge of\r
1186 the output image of the first pixel in the image.\r
93e3992d 1187 @param BltY Specifies the offset from the left and top edge of\r
1188 the output image of the first pixel in the image.\r
1189\r
1190 @retval EFI_SUCCESS The image was successfully drawn.\r
1191 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.\r
1192 @retval EFI_INVALID_PARAMETER The Image or Blt was NULL.\r
1193 @retval EFI_INVALID_PARAMETER Any combination of Flags is invalid.\r
1194\r
1195**/\r
1196EFI_STATUS\r
1197EFIAPI\r
1198HiiDrawImage (\r
1199 IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r
1200 IN EFI_HII_DRAW_FLAGS Flags,\r
1201 IN CONST EFI_IMAGE_INPUT *Image,\r
1202 IN OUT EFI_IMAGE_OUTPUT **Blt,\r
1203 IN UINTN BltX,\r
1204 IN UINTN BltY\r
1205 )\r
1206{\r
1207 EFI_STATUS Status;\r
1208 HII_DATABASE_PRIVATE_DATA *Private;\r
1209 BOOLEAN Transparent;\r
1210 EFI_IMAGE_INPUT *ImageIn;\r
1211 EFI_IMAGE_OUTPUT *ImageOut;\r
1212 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;\r
1213 UINTN BufferLen;\r
1214 UINTN Width;\r
1215 UINTN Height;\r
e90b081a 1216 UINTN Xpos;\r
1217 UINTN Ypos;\r
93e3992d 1218 UINTN OffsetY1;\r
1219 UINTN OffsetY2;\r
1220 EFI_FONT_DISPLAY_INFO *FontInfo;\r
1221 UINTN Index;\r
93e3992d 1222\r
1223 if (This == NULL || Image == NULL || Blt == NULL) {\r
1224 return EFI_INVALID_PARAMETER;\r
1225 }\r
1226\r
1227 if ((Flags & EFI_HII_DRAW_FLAG_CLIP) == EFI_HII_DRAW_FLAG_CLIP && *Blt == NULL) {\r
1228 return EFI_INVALID_PARAMETER;\r
1229 }\r
1230\r
1231 if ((Flags & EFI_HII_DRAW_FLAG_TRANSPARENT) == EFI_HII_DRAW_FLAG_TRANSPARENT) {\r
1232 return EFI_INVALID_PARAMETER;\r
1233 }\r
1234\r
523f48e7 1235 FontInfo = NULL;\r
93e3992d 1236 ImageIn = (EFI_IMAGE_INPUT *) Image;\r
1237\r
1238 //\r
1239 // Check whether the image will be drawn transparently or opaquely.\r
1240 //\r
1241 Transparent = FALSE;\r
1242 if ((Flags & EFI_HII_DRAW_FLAG_TRANSPARENT) == EFI_HII_DRAW_FLAG_FORCE_TRANS) {\r
1243 Transparent = TRUE;\r
1244 } else if ((Flags & EFI_HII_DRAW_FLAG_TRANSPARENT) == EFI_HII_DRAW_FLAG_FORCE_OPAQUE){\r
1245 Transparent = FALSE;\r
1246 } else {\r
1247 //\r
1248 // Now EFI_HII_DRAW_FLAG_DEFAULT is set, whether image will be drawn depending\r
1249 // on the image's transparency setting.\r
1250 //\r
1251 if ((ImageIn->Flags & EFI_IMAGE_TRANSPARENT) == EFI_IMAGE_TRANSPARENT) {\r
1252 Transparent = TRUE;\r
1253 }\r
1254 }\r
1255\r
1256 //\r
1257 // Image cannot be drawn transparently if Blt points to NULL on entry.\r
1258 // Currently output to Screen transparently is not supported, either.\r
1259 //\r
1260 if (Transparent) {\r
1261 if (*Blt == NULL) {\r
1262 return EFI_INVALID_PARAMETER;\r
1263 } else if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {\r
1264 return EFI_INVALID_PARAMETER;\r
1265 }\r
1266 }\r
1267\r
1268 Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
1269\r
1270 //\r
1271 // When Blt points to a non-NULL on entry, this image will be drawn onto\r
1272 // this bitmap or screen pointed by "*Blt" and EFI_HII_DRAW_FLAG_CLIP is implied.\r
1273 // Otherwise a new bitmap will be allocated to hold this image.\r
1274 //\r
1275 if (*Blt != NULL) {\r
1276 //\r
1277 // Clip the image by (Width, Height)\r
1278 //\r
1279\r
1280 Width = ImageIn->Width;\r
1281 Height = ImageIn->Height;\r
1282\r
1283 if (Width > (*Blt)->Width - BltX) {\r
1284 Width = (*Blt)->Width - BltX;\r
1285 }\r
1286 if (Height > (*Blt)->Height - BltY) {\r
1287 Height = (*Blt)->Height - BltY;\r
1288 }\r
1289\r
1290 BufferLen = Width * Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
1291 BltBuffer = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (BufferLen);\r
1292 if (BltBuffer == NULL) {\r
1293 return EFI_OUT_OF_RESOURCES;\r
1294 }\r
1295\r
1296 if (Width == ImageIn->Width && Height == ImageIn->Height) {\r
1297 CopyMem (BltBuffer, ImageIn->Bitmap, BufferLen);\r
1298 } else {\r
e90b081a 1299 for (Ypos = 0; Ypos < Height; Ypos++) {\r
1300 OffsetY1 = ImageIn->Width * Ypos;\r
1301 OffsetY2 = Width * Ypos;\r
1302 for (Xpos = 0; Xpos < Width; Xpos++) {\r
1303 BltBuffer[OffsetY2 + Xpos] = ImageIn->Bitmap[OffsetY1 + Xpos];\r
93e3992d 1304 }\r
1305 }\r
1306 }\r
1307\r
1308 //\r
1309 // Draw the image to existing bitmap or screen depending on flag.\r
1310 //\r
1311 if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {\r
3f57706f 1312 //\r
1313 // Caller should make sure the current UGA console is grarphic mode.\r
1314 //\r
93e3992d 1315\r
93e3992d 1316 //\r
1317 // Write the image directly to the output device specified by Screen.\r
1318 //\r
1319 Status = (*Blt)->Image.Screen->Blt (\r
1320 (*Blt)->Image.Screen,\r
1321 BltBuffer,\r
1322 EfiBltBufferToVideo,\r
1323 0,\r
1324 0,\r
1325 BltX,\r
1326 BltY,\r
1327 Width,\r
1328 Height,\r
1329 0\r
1330 );\r
1331 } else {\r
1332 //\r
1333 // Draw the image onto the existing bitmap specified by Bitmap.\r
1334 //\r
1335 Status = ImageToBlt (\r
1336 BltBuffer,\r
1337 BltX,\r
1338 BltY,\r
1339 Width,\r
1340 Height,\r
1341 Transparent,\r
1342 Blt\r
1343 );\r
1344\r
1345 }\r
1346\r
676df92c 1347 FreePool (BltBuffer);\r
93e3992d 1348 return Status;\r
1349\r
1350 } else {\r
1351 //\r
1352 // Allocate a new bitmap to hold the incoming image.\r
1353 //\r
1354 Width = ImageIn->Width + BltX;\r
1355 Height = ImageIn->Height + BltY;\r
1356\r
1357 BufferLen = Width * Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
1358 BltBuffer = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (BufferLen);\r
1359 if (BltBuffer == NULL) {\r
1360 return EFI_OUT_OF_RESOURCES;\r
1361 }\r
1362\r
1363 ImageOut = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r
1364 if (ImageOut == NULL) {\r
676df92c 1365 FreePool (BltBuffer);\r
93e3992d 1366 return EFI_OUT_OF_RESOURCES;\r
1367 }\r
1368 ImageOut->Width = (UINT16) Width;\r
1369 ImageOut->Height = (UINT16) Height;\r
1370 ImageOut->Image.Bitmap = BltBuffer;\r
1371\r
1372 //\r
1373 // BUGBUG: Now all the "blank" pixels are filled with system default background\r
1374 // color. Not sure if it need to be updated or not.\r
1375 //\r
1376 Status = GetSystemFont (Private, &FontInfo, NULL);\r
1377 if (EFI_ERROR (Status)) {\r
676df92c 1378 FreePool (BltBuffer);\r
1379 FreePool (ImageOut);\r
93e3992d 1380 return Status;\r
1381 }\r
523f48e7 1382 ASSERT (FontInfo != NULL);\r
93e3992d 1383 for (Index = 0; Index < Width * Height; Index++) {\r
1384 BltBuffer[Index] = FontInfo->BackgroundColor;\r
1385 }\r
676df92c 1386 FreePool (FontInfo);\r
93e3992d 1387\r
1388 //\r
1389 // Draw the incoming image to the new created image.\r
1390 //\r
1391 *Blt = ImageOut;\r
1392 return ImageToBlt (\r
1393 ImageIn->Bitmap,\r
1394 BltX,\r
1395 BltY,\r
1396 ImageIn->Width,\r
1397 ImageIn->Height,\r
1398 Transparent,\r
1399 Blt\r
1400 );\r
1401\r
1402 }\r
1403}\r
1404\r
1405\r
1406/**\r
1407 This function renders an image to a bitmap or the screen using the specified\r
1408 color and options. It draws the image on an existing bitmap, allocates a new\r
1409 bitmap or uses the screen. The images can be clipped.\r
1410\r
1411 @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r
1412 @param Flags Describes how the image is to be drawn.\r
1413 @param PackageList The package list in the HII database to search for\r
1414 the specified image.\r
1415 @param ImageId The image's id, which is unique within\r
1416 PackageList.\r
1417 @param Blt If this points to a non-NULL on entry, this points\r
1418 to the image, which is Width pixels wide and\r
1419 Height pixels high. The image will be drawn onto\r
1420 this image and\r
1421 EFI_HII_DRAW_FLAG_CLIP is implied. If this points\r
1422 to a NULL on entry, then a buffer will be\r
1423 allocated to hold the generated image and the\r
ac644614 1424 pointer updated on exit. It is the caller's\r
93e3992d 1425 responsibility to free this buffer.\r
e90b081a 1426 @param BltX Specifies the offset from the left and top edge of\r
1427 the output image of the first pixel in the image.\r
93e3992d 1428 @param BltY Specifies the offset from the left and top edge of\r
1429 the output image of the first pixel in the image.\r
1430\r
1431 @retval EFI_SUCCESS The image was successfully drawn.\r
1432 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.\r
813acf3a 1433 @retval EFI_INVALID_PARAMETER The Blt was NULL.\r
1434 @retval EFI_NOT_FOUND The image specified by ImageId is not in the database. \r
1435 The specified PackageList is not in the database. \r
93e3992d 1436\r
1437**/\r
1438EFI_STATUS\r
1439EFIAPI\r
1440HiiDrawImageId (\r
1441 IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r
1442 IN EFI_HII_DRAW_FLAGS Flags,\r
1443 IN EFI_HII_HANDLE PackageList,\r
1444 IN EFI_IMAGE_ID ImageId,\r
1445 IN OUT EFI_IMAGE_OUTPUT **Blt,\r
1446 IN UINTN BltX,\r
1447 IN UINTN BltY\r
1448 )\r
1449{\r
1450 EFI_STATUS Status;\r
813acf3a 1451 EFI_IMAGE_INPUT Image;\r
93e3992d 1452\r
1453 //\r
1454 // Check input parameter.\r
1455 //\r
813acf3a 1456 if (This == NULL || Blt == NULL) {\r
93e3992d 1457 return EFI_INVALID_PARAMETER;\r
1458 }\r
1459\r
1460 if (!IsHiiHandleValid (PackageList)) {\r
1461 return EFI_NOT_FOUND;\r
1462 }\r
1463\r
1464 //\r
1465 // Get the specified Image.\r
1466 //\r
813acf3a 1467 Status = HiiGetImage (This, PackageList, ImageId, &Image);\r
1468 if (EFI_ERROR (Status)) {\r
93e3992d 1469 return Status;\r
1470 }\r
1471\r
93e3992d 1472 //\r
1473 // Draw this image.\r
1474 //\r
813acf3a 1475 Status = HiiDrawImage (This, Flags, &Image, Blt, BltX, BltY);\r
676df92c 1476 if (Image.Bitmap != NULL) {\r
1477 FreePool (Image.Bitmap);\r
1478 }\r
93e3992d 1479 return Status;\r
1480}\r
1481\r