]>
Commit | Line | Data |
---|---|---|
93e3992d | 1 | /** @file\r |
e90b081a | 2 | Implementation for EFI_HII_IMAGE_PROTOCOL.\r |
3 | \r | |
93e3992d | 4 | \r |
2a244a5d | 5 | Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 6 | This program and the accompanying materials\r |
93e3992d | 7 | are licensed and made available under the terms and conditions of the BSD License\r |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT 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 | 34 | EFI_HII_IMAGE_BLOCK *\r |
93e3992d | 35 | GetImageIdOrAddress (\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 | 182 | VOID\r |
183 | CopyGopToRgbPixel (\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 | 211 | VOID\r |
212 | CopyRgbToGopPixel (\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 | 242 | VOID\r |
243 | Output1bitPixel (\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 | 331 | VOID\r |
332 | Output4bitPixel (\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 | 409 | VOID\r |
410 | Output8bitPixel (\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 | 476 | VOID\r |
477 | Output24bitPixel (\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 | 520 | EFI_STATUS\r |
521 | ImageToBlt (\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 | |
572 | \r | |
573 | /**\r | |
574 | This function adds the image Image to the group of images owned by PackageList, and returns\r | |
575 | a new image identifier (ImageId).\r | |
576 | \r | |
577 | @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r | |
578 | @param PackageList Handle of the package list where this image will\r | |
579 | be added.\r | |
580 | @param ImageId On return, contains the new image id, which is\r | |
581 | unique within PackageList.\r | |
582 | @param Image Points to the image.\r | |
583 | \r | |
584 | @retval EFI_SUCCESS The new image was added successfully.\r | |
585 | @retval EFI_NOT_FOUND The specified PackageList could not be found in\r | |
586 | database.\r | |
587 | @retval EFI_OUT_OF_RESOURCES Could not add the image due to lack of resources.\r | |
588 | @retval EFI_INVALID_PARAMETER Image is NULL or ImageId is NULL.\r | |
589 | \r | |
590 | **/\r | |
591 | EFI_STATUS\r | |
592 | EFIAPI\r | |
593 | HiiNewImage (\r | |
594 | IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r | |
595 | IN EFI_HII_HANDLE PackageList,\r | |
596 | OUT EFI_IMAGE_ID *ImageId,\r | |
597 | IN CONST EFI_IMAGE_INPUT *Image\r | |
598 | )\r | |
599 | {\r | |
600 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
601 | LIST_ENTRY *Link;\r | |
602 | HII_DATABASE_RECORD *DatabaseRecord;\r | |
603 | HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r | |
604 | HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;\r | |
605 | UINT8 *ImageBlock;\r | |
606 | UINTN BlockSize;\r | |
607 | UINT8 *NewBlock;\r | |
608 | UINT8 *NewBlockPtr;\r | |
609 | UINTN NewBlockSize;\r | |
610 | EFI_IMAGE_INPUT *ImageIn;\r | |
611 | \r | |
813acf3a | 612 | if (This == NULL || ImageId == NULL || Image == NULL || Image->Bitmap == NULL) {\r |
93e3992d | 613 | return EFI_INVALID_PARAMETER;\r |
614 | }\r | |
615 | \r | |
616 | if (!IsHiiHandleValid (PackageList)) {\r | |
617 | return EFI_NOT_FOUND;\r | |
618 | }\r | |
619 | \r | |
620 | Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
621 | \r | |
622 | //\r | |
623 | // Get the specified package list\r | |
624 | //\r | |
625 | \r | |
626 | PackageListNode = NULL;\r | |
627 | \r | |
628 | for (Link = Private->DatabaseList.ForwardLink;\r | |
629 | Link != &Private->DatabaseList;\r | |
630 | Link = Link->ForwardLink\r | |
631 | ) {\r | |
632 | DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r | |
633 | if (DatabaseRecord->Handle == PackageList) {\r | |
634 | PackageListNode = DatabaseRecord->PackageList;\r | |
635 | break;\r | |
636 | }\r | |
637 | }\r | |
638 | \r | |
639 | if (PackageListNode == NULL) {\r | |
640 | return EFI_NOT_FOUND;\r | |
641 | }\r | |
642 | \r | |
643 | ImageIn = (EFI_IMAGE_INPUT *) Image;\r | |
644 | \r | |
645 | NewBlockSize = sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL) +\r | |
646 | BITMAP_LEN_24_BIT (ImageIn->Width, ImageIn->Height);\r | |
647 | \r | |
648 | //\r | |
649 | // Get the image package in the package list,\r | |
650 | // or create a new image package if image package does not exist.\r | |
651 | //\r | |
652 | if (PackageListNode->ImagePkg != NULL) {\r | |
653 | ImagePackage = PackageListNode->ImagePkg;\r | |
654 | \r | |
655 | //\r | |
656 | // Output the image id of the incoming image being inserted, which is the\r | |
657 | // image id of the EFI_HII_IIBT_END block of old image package.\r | |
658 | //\r | |
659 | *ImageId = 0;\r | |
660 | GetImageIdOrAddress (ImagePackage->ImageBlock, ImageId);\r | |
661 | \r | |
662 | //\r | |
663 | // Update the package's image block by appending the new block to the end.\r | |
664 | //\r | |
665 | BlockSize = ImagePackage->ImageBlockSize + NewBlockSize;\r | |
666 | ImageBlock = (UINT8 *) AllocateZeroPool (BlockSize);\r | |
667 | if (ImageBlock == NULL) {\r | |
668 | return EFI_OUT_OF_RESOURCES;\r | |
669 | }\r | |
670 | //\r | |
671 | // Copy the original content.\r | |
672 | //\r | |
673 | CopyMem (\r | |
674 | ImageBlock,\r | |
675 | ImagePackage->ImageBlock,\r | |
676 | ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK)\r | |
677 | );\r | |
676df92c | 678 | FreePool (ImagePackage->ImageBlock);\r |
7c28fcb8 | 679 | ImagePackage->ImageBlock = (EFI_HII_IMAGE_BLOCK *) ImageBlock;\r |
93e3992d | 680 | ImageBlock += ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK);\r |
681 | //\r | |
682 | // Temp memory to store new block.\r | |
683 | //\r | |
684 | NewBlock = AllocateZeroPool (NewBlockSize);\r | |
685 | if (NewBlock == NULL) {\r | |
676df92c | 686 | FreePool (ImagePackage->ImageBlock);\r |
93e3992d | 687 | return EFI_OUT_OF_RESOURCES;\r |
688 | }\r | |
689 | NewBlockPtr = NewBlock;\r | |
690 | \r | |
691 | //\r | |
692 | // Update the length record.\r | |
693 | //\r | |
694 | ImagePackage->ImageBlockSize = (UINT32) BlockSize;\r | |
695 | ImagePackage->ImagePkgHdr.Header.Length += (UINT32) NewBlockSize;\r | |
696 | PackageListNode->PackageListHdr.PackageLength += (UINT32) NewBlockSize;\r | |
697 | \r | |
698 | } else {\r | |
699 | //\r | |
700 | // The specified package list does not contain image package.\r | |
701 | // Create one to add this image block.\r | |
702 | //\r | |
703 | ImagePackage = (HII_IMAGE_PACKAGE_INSTANCE *) AllocateZeroPool (sizeof (HII_IMAGE_PACKAGE_INSTANCE));\r | |
704 | if (ImagePackage == NULL) {\r | |
705 | return EFI_OUT_OF_RESOURCES;\r | |
706 | }\r | |
707 | //\r | |
708 | // Output the image id of the incoming image being inserted, which is the\r | |
709 | // first image block so that id is initially to one.\r | |
710 | //\r | |
711 | *ImageId = 1;\r | |
712 | BlockSize = sizeof (EFI_HII_IIBT_END_BLOCK) + NewBlockSize;\r | |
713 | //\r | |
714 | // Fill in image package header.\r | |
715 | //\r | |
716 | ImagePackage->ImagePkgHdr.Header.Length = (UINT32) BlockSize + sizeof (EFI_HII_IMAGE_PACKAGE_HDR);\r | |
717 | ImagePackage->ImagePkgHdr.Header.Type = EFI_HII_PACKAGE_IMAGES;\r | |
718 | ImagePackage->ImagePkgHdr.ImageInfoOffset = sizeof (EFI_HII_IMAGE_PACKAGE_HDR);\r | |
719 | ImagePackage->ImagePkgHdr.PaletteInfoOffset = 0;\r | |
720 | \r | |
721 | //\r | |
722 | // Fill in palette info.\r | |
723 | //\r | |
724 | ImagePackage->PaletteBlock = NULL;\r | |
725 | ImagePackage->PaletteInfoSize = 0;\r | |
726 | \r | |
727 | //\r | |
728 | // Fill in image blocks.\r | |
729 | //\r | |
730 | ImagePackage->ImageBlockSize = (UINT32) BlockSize;\r | |
7c28fcb8 | 731 | ImagePackage->ImageBlock = AllocateZeroPool (BlockSize);\r |
93e3992d | 732 | if (ImagePackage->ImageBlock == NULL) {\r |
676df92c | 733 | FreePool (ImagePackage);\r |
93e3992d | 734 | return EFI_OUT_OF_RESOURCES;\r |
735 | }\r | |
7c28fcb8 | 736 | ImageBlock = (UINT8 *) ImagePackage->ImageBlock;\r |
93e3992d | 737 | \r |
738 | //\r | |
739 | // Temp memory to store new block.\r | |
740 | //\r | |
741 | NewBlock = AllocateZeroPool (NewBlockSize);\r | |
742 | if (NewBlock == NULL) {\r | |
676df92c | 743 | FreePool (ImagePackage->ImageBlock);\r |
744 | FreePool (ImagePackage);\r | |
93e3992d | 745 | return EFI_OUT_OF_RESOURCES;\r |
746 | }\r | |
747 | NewBlockPtr = NewBlock;\r | |
748 | \r | |
749 | //\r | |
750 | // Insert this image package.\r | |
751 | //\r | |
752 | PackageListNode->ImagePkg = ImagePackage;\r | |
753 | PackageListNode->PackageListHdr.PackageLength += ImagePackage->ImagePkgHdr.Header.Length;\r | |
754 | }\r | |
755 | \r | |
756 | //\r | |
757 | // Append the new block here\r | |
758 | //\r | |
759 | if (ImageIn->Flags == EFI_IMAGE_TRANSPARENT) {\r | |
760 | *NewBlock = EFI_HII_IIBT_IMAGE_24BIT_TRANS;\r | |
761 | } else {\r | |
762 | *NewBlock = EFI_HII_IIBT_IMAGE_24BIT;\r | |
763 | }\r | |
764 | NewBlock++;\r | |
765 | CopyMem (NewBlock, &ImageIn->Width, sizeof (UINT16));\r | |
766 | NewBlock += sizeof (UINT16);\r | |
767 | CopyMem (NewBlock, &ImageIn->Height, sizeof (UINT16));\r | |
768 | NewBlock += sizeof (UINT16);\r | |
769 | CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL *) NewBlock, ImageIn->Bitmap, ImageIn->Width * ImageIn->Height);\r | |
770 | \r | |
771 | CopyMem (ImageBlock, NewBlockPtr, NewBlockSize);\r | |
676df92c | 772 | FreePool (NewBlockPtr);\r |
93e3992d | 773 | \r |
774 | //\r | |
775 | // Append the block end\r | |
776 | //\r | |
777 | ImageBlock += NewBlockSize;\r | |
778 | ((EFI_HII_IIBT_END_BLOCK *) (ImageBlock))->Header.BlockType = EFI_HII_IIBT_END;\r | |
779 | \r | |
8a45f80e DB |
780 | //\r |
781 | // Check whether need to get the contents of HiiDataBase.\r | |
782 | // Only after ReadyToBoot to do the export.\r | |
783 | //\r | |
784 | if (gExportAfterReadyToBoot) {\r | |
785 | HiiGetDatabaseInfo(&Private->HiiDatabase);\r | |
786 | }\r | |
787 | \r | |
93e3992d | 788 | return EFI_SUCCESS;\r |
789 | }\r | |
790 | \r | |
791 | \r | |
792 | /**\r | |
793 | This function retrieves the image specified by ImageId which is associated with\r | |
794 | the specified PackageList and copies it into the buffer specified by Image.\r | |
795 | \r | |
796 | @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r | |
797 | @param PackageList Handle of the package list where this image will\r | |
798 | be searched.\r | |
ac644614 | 799 | @param ImageId The image's id,, which is unique within\r |
93e3992d | 800 | PackageList.\r |
801 | @param Image Points to the image.\r | |
93e3992d | 802 | \r |
803 | @retval EFI_SUCCESS The new image was returned successfully.\r | |
813acf3a | 804 | @retval EFI_NOT_FOUND The image specified by ImageId is not in the\r |
805 | database. The specified PackageList is not in the database.\r | |
93e3992d | 806 | @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to\r |
807 | hold the image.\r | |
808 | @retval EFI_INVALID_PARAMETER The Image or ImageSize was NULL.\r | |
813acf3a | 809 | @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there was not\r |
810 | enough memory.\r | |
93e3992d | 811 | \r |
812 | **/\r | |
813 | EFI_STATUS\r | |
814 | EFIAPI\r | |
815 | HiiGetImage (\r | |
816 | IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r | |
817 | IN EFI_HII_HANDLE PackageList,\r | |
818 | IN EFI_IMAGE_ID ImageId,\r | |
813acf3a | 819 | OUT EFI_IMAGE_INPUT *Image\r |
93e3992d | 820 | )\r |
821 | {\r | |
822 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
823 | LIST_ENTRY *Link;\r | |
824 | HII_DATABASE_RECORD *DatabaseRecord;\r | |
825 | HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r | |
826 | HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;\r | |
827 | UINT8 *ImageBlock;\r | |
828 | EFI_IMAGE_ID LocalImageId;\r | |
829 | UINT8 BlockType;\r | |
830 | EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit;\r | |
831 | UINT16 Width;\r | |
832 | UINT16 Height;\r | |
833 | UINTN ImageLength;\r | |
834 | BOOLEAN Flag;\r | |
835 | UINT8 *PaletteInfo;\r | |
836 | UINT8 PaletteIndex;\r | |
837 | UINT16 PaletteSize;\r | |
838 | \r | |
813acf3a | 839 | if (This == NULL || Image == NULL || ImageId < 1) {\r |
93e3992d | 840 | return EFI_INVALID_PARAMETER;\r |
841 | }\r | |
842 | \r | |
843 | if (!IsHiiHandleValid (PackageList)) {\r | |
844 | return EFI_NOT_FOUND;\r | |
845 | }\r | |
846 | \r | |
847 | Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
848 | \r | |
849 | //\r | |
850 | // Get the specified package list and image package.\r | |
851 | //\r | |
852 | PackageListNode = NULL;\r | |
853 | for (Link = Private->DatabaseList.ForwardLink;\r | |
854 | Link != &Private->DatabaseList;\r | |
855 | Link = Link->ForwardLink\r | |
856 | ) {\r | |
857 | DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r | |
858 | if (DatabaseRecord->Handle == PackageList) {\r | |
859 | PackageListNode = DatabaseRecord->PackageList;\r | |
860 | break;\r | |
861 | }\r | |
862 | }\r | |
863 | if (PackageListNode == NULL) {\r | |
864 | return EFI_NOT_FOUND;\r | |
865 | }\r | |
866 | ImagePackage = PackageListNode->ImagePkg;\r | |
867 | if (ImagePackage == NULL) {\r | |
868 | return EFI_NOT_FOUND;\r | |
869 | }\r | |
870 | \r | |
871 | //\r | |
872 | // Find the image block specified by ImageId\r | |
873 | //\r | |
874 | LocalImageId = ImageId;\r | |
7c28fcb8 | 875 | ImageBlock = (UINT8 *) GetImageIdOrAddress (ImagePackage->ImageBlock, &LocalImageId);\r |
93e3992d | 876 | if (ImageBlock == NULL) {\r |
877 | return EFI_NOT_FOUND;\r | |
878 | }\r | |
879 | \r | |
880 | Flag = FALSE;\r | |
881 | BlockType = *ImageBlock;\r | |
882 | \r | |
883 | switch (BlockType) {\r | |
884 | case EFI_HII_IIBT_IMAGE_JPEG:\r | |
885 | //\r | |
886 | // BUGBUG: need to be supported as soon as image tool is designed.\r | |
887 | //\r | |
888 | return EFI_UNSUPPORTED;\r | |
93e3992d | 889 | \r |
890 | case EFI_HII_IIBT_IMAGE_1BIT_TRANS:\r | |
891 | case EFI_HII_IIBT_IMAGE_4BIT_TRANS:\r | |
892 | case EFI_HII_IIBT_IMAGE_8BIT_TRANS:\r | |
893 | Flag = TRUE;\r | |
894 | //\r | |
895 | // fall through\r | |
896 | //\r | |
897 | case EFI_HII_IIBT_IMAGE_1BIT:\r | |
898 | case EFI_HII_IIBT_IMAGE_4BIT:\r | |
899 | case EFI_HII_IIBT_IMAGE_8BIT:\r | |
900 | //\r | |
901 | // Use the common block code since the definition of these structures is the same.\r | |
902 | //\r | |
903 | CopyMem (&Iibt1bit, ImageBlock, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK));\r | |
813acf3a | 904 | ImageLength = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) *\r |
905 | (Iibt1bit.Bitmap.Width * Iibt1bit.Bitmap.Height);\r | |
906 | Image->Bitmap = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (ImageLength);\r | |
907 | if (Image->Bitmap == NULL) {\r | |
908 | return EFI_OUT_OF_RESOURCES;\r | |
93e3992d | 909 | }\r |
93e3992d | 910 | \r |
911 | if (Flag) {\r | |
912 | Image->Flags = EFI_IMAGE_TRANSPARENT;\r | |
913 | }\r | |
914 | Image->Width = Iibt1bit.Bitmap.Width;\r | |
915 | Image->Height = Iibt1bit.Bitmap.Height;\r | |
916 | \r | |
917 | PaletteInfo = ImagePackage->PaletteBlock + sizeof (EFI_HII_IMAGE_PALETTE_INFO_HEADER);\r | |
918 | for (PaletteIndex = 1; PaletteIndex < Iibt1bit.PaletteIndex; PaletteIndex++) {\r | |
919 | CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));\r | |
920 | PaletteInfo += PaletteSize + sizeof (UINT16);\r | |
921 | }\r | |
922 | ASSERT (PaletteIndex == Iibt1bit.PaletteIndex);\r | |
923 | \r | |
924 | //\r | |
925 | // Output bitmap data\r | |
926 | //\r | |
927 | if (BlockType == EFI_HII_IIBT_IMAGE_1BIT || BlockType == EFI_HII_IIBT_IMAGE_1BIT_TRANS) {\r | |
928 | Output1bitPixel (\r | |
929 | Image,\r | |
6e1e5405 | 930 | (UINT8 *) ((UINTN)ImageBlock + sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK) - sizeof (UINT8)),\r |
93e3992d | 931 | (EFI_HII_IMAGE_PALETTE_INFO *) PaletteInfo\r |
932 | );\r | |
933 | } else if (BlockType == EFI_HII_IIBT_IMAGE_4BIT || BlockType == EFI_HII_IIBT_IMAGE_4BIT_TRANS) {\r | |
934 | Output4bitPixel (\r | |
935 | Image,\r | |
6e1e5405 | 936 | (UINT8 *) ((UINTN)ImageBlock + sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK) - sizeof (UINT8)),\r |
93e3992d | 937 | (EFI_HII_IMAGE_PALETTE_INFO *) PaletteInfo\r |
938 | );\r | |
939 | } else {\r | |
940 | Output8bitPixel (\r | |
941 | Image,\r | |
6e1e5405 | 942 | (UINT8 *) ((UINTN)ImageBlock + sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK) - sizeof (UINT8)),\r |
93e3992d | 943 | (EFI_HII_IMAGE_PALETTE_INFO *) PaletteInfo\r |
944 | );\r | |
945 | }\r | |
946 | \r | |
947 | return EFI_SUCCESS;\r | |
93e3992d | 948 | \r |
949 | case EFI_HII_IIBT_IMAGE_24BIT_TRANS:\r | |
950 | Flag = TRUE;\r | |
951 | //\r | |
952 | // fall through\r | |
953 | //\r | |
954 | case EFI_HII_IIBT_IMAGE_24BIT:\r | |
955 | CopyMem (&Width, ImageBlock + sizeof (EFI_HII_IMAGE_BLOCK), sizeof (UINT16));\r | |
956 | CopyMem (\r | |
957 | &Height,\r | |
958 | ImageBlock + sizeof (EFI_HII_IMAGE_BLOCK) + sizeof (UINT16),\r | |
959 | sizeof (UINT16)\r | |
960 | );\r | |
813acf3a | 961 | ImageLength = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * (Width * Height);\r |
962 | Image->Bitmap = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (ImageLength);\r | |
963 | if (Image->Bitmap == NULL) {\r | |
964 | return EFI_OUT_OF_RESOURCES;\r | |
93e3992d | 965 | }\r |
93e3992d | 966 | \r |
967 | if (Flag) {\r | |
968 | Image->Flags = EFI_IMAGE_TRANSPARENT;\r | |
969 | }\r | |
970 | Image->Width = Width;\r | |
971 | Image->Height = Height;\r | |
972 | \r | |
973 | //\r | |
974 | // Output the bimap data directly.\r | |
975 | //\r | |
976 | Output24bitPixel (\r | |
977 | Image,\r | |
978 | (EFI_HII_RGB_PIXEL *) (ImageBlock + sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL))\r | |
979 | );\r | |
980 | return EFI_SUCCESS;\r | |
93e3992d | 981 | \r |
982 | default:\r | |
983 | return EFI_NOT_FOUND;\r | |
93e3992d | 984 | }\r |
985 | }\r | |
986 | \r | |
987 | \r | |
988 | /**\r | |
989 | This function updates the image specified by ImageId in the specified PackageListHandle to\r | |
990 | the image specified by Image.\r | |
991 | \r | |
992 | @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r | |
993 | @param PackageList The package list containing the images.\r | |
ac644614 | 994 | @param ImageId The image's id,, which is unique within\r |
93e3992d | 995 | PackageList.\r |
996 | @param Image Points to the image.\r | |
997 | \r | |
998 | @retval EFI_SUCCESS The new image was updated successfully.\r | |
999 | @retval EFI_NOT_FOUND The image specified by ImageId is not in the\r | |
813acf3a | 1000 | database. The specified PackageList is not in the database. \r |
93e3992d | 1001 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r |
1002 | \r | |
1003 | **/\r | |
1004 | EFI_STATUS\r | |
1005 | EFIAPI\r | |
1006 | HiiSetImage (\r | |
1007 | IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r | |
1008 | IN EFI_HII_HANDLE PackageList,\r | |
1009 | IN EFI_IMAGE_ID ImageId,\r | |
1010 | IN CONST EFI_IMAGE_INPUT *Image\r | |
1011 | )\r | |
1012 | {\r | |
1013 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
1014 | LIST_ENTRY *Link;\r | |
1015 | HII_DATABASE_RECORD *DatabaseRecord;\r | |
1016 | HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r | |
1017 | HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;\r | |
1018 | UINT8 *ImageBlock;\r | |
1019 | EFI_IMAGE_ID LocalImageId;\r | |
1020 | UINT8 BlockType;\r | |
1021 | EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit;\r | |
1022 | EFI_HII_IIBT_IMAGE_4BIT_BLOCK Iibt4bit;\r | |
1023 | EFI_HII_IIBT_IMAGE_8BIT_BLOCK Iibt8bit;\r | |
1024 | UINT16 Width;\r | |
1025 | UINT16 Height;\r | |
1026 | UINT32 BlockSize;\r | |
1027 | UINT32 NewBlockSize;\r | |
1028 | UINT32 OldBlockSize;\r | |
1029 | EFI_IMAGE_INPUT *ImageIn;\r | |
1030 | UINT8 *NewBlock;\r | |
1031 | UINT8 *NewBlockPtr;\r | |
1032 | UINT8 *Block;\r | |
1033 | UINT8 *BlockPtr;\r | |
1034 | UINT32 Part1Size;\r | |
1035 | UINT32 Part2Size;\r | |
1036 | \r | |
813acf3a | 1037 | if (This == NULL || Image == NULL || ImageId < 1 || Image->Bitmap == NULL) {\r |
93e3992d | 1038 | return EFI_INVALID_PARAMETER;\r |
1039 | }\r | |
1040 | \r | |
1041 | if (!IsHiiHandleValid (PackageList)) {\r | |
1042 | return EFI_NOT_FOUND;\r | |
1043 | }\r | |
1044 | \r | |
1045 | Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
1046 | \r | |
1047 | //\r | |
1048 | // Get the specified package list and image package.\r | |
1049 | //\r | |
1050 | PackageListNode = NULL;\r | |
1051 | for (Link = Private->DatabaseList.ForwardLink;\r | |
1052 | Link != &Private->DatabaseList;\r | |
1053 | Link = Link->ForwardLink\r | |
1054 | ) {\r | |
1055 | DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r | |
1056 | if (DatabaseRecord->Handle == PackageList) {\r | |
1057 | PackageListNode = DatabaseRecord->PackageList;\r | |
1058 | break;\r | |
1059 | }\r | |
1060 | }\r | |
1061 | if (PackageListNode == NULL) {\r | |
1062 | return EFI_NOT_FOUND;\r | |
1063 | }\r | |
1064 | ImagePackage = PackageListNode->ImagePkg;\r | |
1065 | if (ImagePackage == NULL) {\r | |
1066 | return EFI_NOT_FOUND;\r | |
1067 | }\r | |
1068 | \r | |
1069 | //\r | |
1070 | // Find the image block specified by ImageId\r | |
1071 | //\r | |
1072 | LocalImageId = ImageId;\r | |
7c28fcb8 | 1073 | ImageBlock = (UINT8 *) GetImageIdOrAddress (ImagePackage->ImageBlock, &LocalImageId);\r |
93e3992d | 1074 | if (ImageBlock == NULL) {\r |
1075 | return EFI_NOT_FOUND;\r | |
1076 | }\r | |
1077 | \r | |
1078 | BlockType = *ImageBlock;\r | |
1079 | \r | |
1080 | //\r | |
1081 | // Get the size of original image block. Use some common block code here\r | |
1082 | // since the definition of some structures is the same.\r | |
1083 | //\r | |
1084 | switch (BlockType) {\r | |
1085 | case EFI_HII_IIBT_IMAGE_JPEG:\r | |
1086 | //\r | |
1087 | // BUGBUG: need to be supported as soon as image tool is designed.\r | |
1088 | //\r | |
1089 | return EFI_UNSUPPORTED;\r | |
93e3992d | 1090 | \r |
1091 | case EFI_HII_IIBT_IMAGE_1BIT:\r | |
1092 | case EFI_HII_IIBT_IMAGE_1BIT_TRANS:\r | |
1093 | CopyMem (&Iibt1bit, ImageBlock, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK));\r | |
1094 | OldBlockSize = sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK) - sizeof (UINT8) +\r | |
1095 | BITMAP_LEN_1_BIT (Iibt1bit.Bitmap.Width, Iibt1bit.Bitmap.Height);\r | |
1096 | break;\r | |
1097 | case EFI_HII_IIBT_IMAGE_4BIT:\r | |
1098 | case EFI_HII_IIBT_IMAGE_4BIT_TRANS:\r | |
1099 | CopyMem (&Iibt4bit, ImageBlock, sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK));\r | |
1100 | OldBlockSize = sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK) - sizeof (UINT8) +\r | |
1101 | BITMAP_LEN_4_BIT (Iibt4bit.Bitmap.Width, Iibt4bit.Bitmap.Height);\r | |
1102 | break;\r | |
1103 | case EFI_HII_IIBT_IMAGE_8BIT:\r | |
1104 | case EFI_HII_IIBT_IMAGE_8BIT_TRANS:\r | |
1105 | CopyMem (&Iibt8bit, ImageBlock, sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK));\r | |
1106 | OldBlockSize = sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK) - sizeof (UINT8) +\r | |
1107 | BITMAP_LEN_8_BIT (Iibt8bit.Bitmap.Width, Iibt8bit.Bitmap.Height);\r | |
1108 | break;\r | |
1109 | case EFI_HII_IIBT_IMAGE_24BIT:\r | |
1110 | case EFI_HII_IIBT_IMAGE_24BIT_TRANS:\r | |
1111 | CopyMem (&Width, ImageBlock + sizeof (EFI_HII_IMAGE_BLOCK), sizeof (UINT16));\r | |
1112 | CopyMem (\r | |
1113 | &Height,\r | |
1114 | ImageBlock + sizeof (EFI_HII_IMAGE_BLOCK) + sizeof (UINT16),\r | |
1115 | sizeof (UINT16)\r | |
1116 | );\r | |
1117 | OldBlockSize = sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL) +\r | |
1118 | BITMAP_LEN_24_BIT (Width , Height);\r | |
1119 | break;\r | |
1120 | default:\r | |
1121 | return EFI_NOT_FOUND;\r | |
93e3992d | 1122 | }\r |
1123 | \r | |
1124 | //\r | |
1125 | // Create the new image block according to input image.\r | |
1126 | //\r | |
1127 | ImageIn = (EFI_IMAGE_INPUT *) Image;\r | |
1128 | NewBlockSize = sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL) +\r | |
1129 | BITMAP_LEN_24_BIT (ImageIn->Width, ImageIn->Height);\r | |
1130 | NewBlock = (UINT8 *) AllocateZeroPool (NewBlockSize);\r | |
1131 | if (NewBlock == NULL) {\r | |
1132 | return EFI_OUT_OF_RESOURCES;\r | |
1133 | }\r | |
1134 | \r | |
1135 | NewBlockPtr = NewBlock;\r | |
1136 | if ((ImageIn->Flags & EFI_IMAGE_TRANSPARENT) == EFI_IMAGE_TRANSPARENT) {\r | |
1137 | *NewBlockPtr = EFI_HII_IIBT_IMAGE_24BIT_TRANS;\r | |
1138 | } else {\r | |
1139 | *NewBlockPtr = EFI_HII_IIBT_IMAGE_24BIT;\r | |
1140 | }\r | |
1141 | NewBlockPtr++;\r | |
1142 | \r | |
1143 | CopyMem (NewBlockPtr, &ImageIn->Width, sizeof (UINT16));\r | |
1144 | NewBlockPtr += sizeof (UINT16);\r | |
1145 | CopyMem (NewBlockPtr, &ImageIn->Height, sizeof (UINT16));\r | |
1146 | NewBlockPtr += sizeof (UINT16);\r | |
1147 | \r | |
1148 | CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL *) NewBlockPtr, ImageIn->Bitmap, ImageIn->Width * ImageIn->Height);\r | |
1149 | \r | |
1150 | //\r | |
1151 | // Adjust the image package to remove the original block firstly then add the new block.\r | |
1152 | //\r | |
1153 | BlockSize = ImagePackage->ImageBlockSize + NewBlockSize - OldBlockSize;\r | |
1154 | Block = (UINT8 *) AllocateZeroPool (BlockSize);\r | |
1155 | if (Block == NULL) {\r | |
676df92c | 1156 | FreePool (NewBlock);\r |
93e3992d | 1157 | return EFI_OUT_OF_RESOURCES;\r |
1158 | }\r | |
1159 | \r | |
1160 | BlockPtr = Block;\r | |
7c28fcb8 | 1161 | Part1Size = (UINT32) (ImageBlock - (UINT8 *) ImagePackage->ImageBlock);\r |
93e3992d | 1162 | Part2Size = ImagePackage->ImageBlockSize - Part1Size - OldBlockSize;\r |
1163 | CopyMem (BlockPtr, ImagePackage->ImageBlock, Part1Size);\r | |
1164 | BlockPtr += Part1Size;\r | |
1165 | CopyMem (BlockPtr, NewBlock, NewBlockSize);\r | |
1166 | BlockPtr += NewBlockSize;\r | |
1167 | CopyMem (BlockPtr, ImageBlock + OldBlockSize, Part2Size);\r | |
1168 | \r | |
676df92c | 1169 | FreePool (ImagePackage->ImageBlock);\r |
1170 | FreePool (NewBlock);\r | |
7c28fcb8 | 1171 | ImagePackage->ImageBlock = (EFI_HII_IMAGE_BLOCK *) Block;\r |
93e3992d | 1172 | ImagePackage->ImageBlockSize = BlockSize;\r |
1173 | ImagePackage->ImagePkgHdr.Header.Length += NewBlockSize - OldBlockSize;\r | |
1174 | PackageListNode->PackageListHdr.PackageLength += NewBlockSize - OldBlockSize;\r | |
1175 | \r | |
8a45f80e DB |
1176 | //\r |
1177 | // Check whether need to get the contents of HiiDataBase.\r | |
1178 | // Only after ReadyToBoot to do the export.\r | |
1179 | //\r | |
1180 | if (gExportAfterReadyToBoot) {\r | |
1181 | HiiGetDatabaseInfo(&Private->HiiDatabase);\r | |
1182 | }\r | |
1183 | \r | |
93e3992d | 1184 | return EFI_SUCCESS;\r |
1185 | \r | |
1186 | }\r | |
1187 | \r | |
1188 | \r | |
1189 | /**\r | |
1190 | This function renders an image to a bitmap or the screen using the specified\r | |
1191 | color and options. It draws the image on an existing bitmap, allocates a new\r | |
1192 | bitmap or uses the screen. The images can be clipped.\r | |
1193 | \r | |
1194 | @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r | |
1195 | @param Flags Describes how the image is to be drawn.\r | |
1196 | @param Image Points to the image to be displayed.\r | |
1197 | @param Blt If this points to a non-NULL on entry, this points\r | |
1198 | to the image, which is Width pixels wide and\r | |
1199 | Height pixels high. The image will be drawn onto\r | |
1200 | this image and EFI_HII_DRAW_FLAG_CLIP is implied.\r | |
1201 | If this points to a NULL on entry, then a buffer\r | |
1202 | will be allocated to hold the generated image and\r | |
ac644614 | 1203 | the pointer updated on exit. It is the caller's\r |
93e3992d | 1204 | responsibility to free this buffer.\r |
e90b081a | 1205 | @param BltX Specifies the offset from the left and top edge of\r |
1206 | the output image of the first pixel in the image.\r | |
93e3992d | 1207 | @param BltY Specifies the offset from the left and top edge of\r |
1208 | the output image of the first pixel in the image.\r | |
1209 | \r | |
1210 | @retval EFI_SUCCESS The image was successfully drawn.\r | |
1211 | @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.\r | |
1212 | @retval EFI_INVALID_PARAMETER The Image or Blt was NULL.\r | |
1213 | @retval EFI_INVALID_PARAMETER Any combination of Flags is invalid.\r | |
1214 | \r | |
1215 | **/\r | |
1216 | EFI_STATUS\r | |
1217 | EFIAPI\r | |
1218 | HiiDrawImage (\r | |
1219 | IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r | |
1220 | IN EFI_HII_DRAW_FLAGS Flags,\r | |
1221 | IN CONST EFI_IMAGE_INPUT *Image,\r | |
1222 | IN OUT EFI_IMAGE_OUTPUT **Blt,\r | |
1223 | IN UINTN BltX,\r | |
1224 | IN UINTN BltY\r | |
1225 | )\r | |
1226 | {\r | |
1227 | EFI_STATUS Status;\r | |
1228 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
1229 | BOOLEAN Transparent;\r | |
1230 | EFI_IMAGE_INPUT *ImageIn;\r | |
1231 | EFI_IMAGE_OUTPUT *ImageOut;\r | |
1232 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;\r | |
1233 | UINTN BufferLen;\r | |
1234 | UINTN Width;\r | |
1235 | UINTN Height;\r | |
e90b081a | 1236 | UINTN Xpos;\r |
1237 | UINTN Ypos;\r | |
93e3992d | 1238 | UINTN OffsetY1;\r |
1239 | UINTN OffsetY2;\r | |
1240 | EFI_FONT_DISPLAY_INFO *FontInfo;\r | |
1241 | UINTN Index;\r | |
93e3992d | 1242 | \r |
1243 | if (This == NULL || Image == NULL || Blt == NULL) {\r | |
1244 | return EFI_INVALID_PARAMETER;\r | |
1245 | }\r | |
1246 | \r | |
1247 | if ((Flags & EFI_HII_DRAW_FLAG_CLIP) == EFI_HII_DRAW_FLAG_CLIP && *Blt == NULL) {\r | |
1248 | return EFI_INVALID_PARAMETER;\r | |
1249 | }\r | |
1250 | \r | |
1251 | if ((Flags & EFI_HII_DRAW_FLAG_TRANSPARENT) == EFI_HII_DRAW_FLAG_TRANSPARENT) {\r | |
1252 | return EFI_INVALID_PARAMETER;\r | |
1253 | }\r | |
1254 | \r | |
523f48e7 | 1255 | FontInfo = NULL;\r |
93e3992d | 1256 | ImageIn = (EFI_IMAGE_INPUT *) Image;\r |
1257 | \r | |
1258 | //\r | |
1259 | // Check whether the image will be drawn transparently or opaquely.\r | |
1260 | //\r | |
1261 | Transparent = FALSE;\r | |
1262 | if ((Flags & EFI_HII_DRAW_FLAG_TRANSPARENT) == EFI_HII_DRAW_FLAG_FORCE_TRANS) {\r | |
1263 | Transparent = TRUE;\r | |
1264 | } else if ((Flags & EFI_HII_DRAW_FLAG_TRANSPARENT) == EFI_HII_DRAW_FLAG_FORCE_OPAQUE){\r | |
1265 | Transparent = FALSE;\r | |
1266 | } else {\r | |
1267 | //\r | |
1268 | // Now EFI_HII_DRAW_FLAG_DEFAULT is set, whether image will be drawn depending\r | |
1269 | // on the image's transparency setting.\r | |
1270 | //\r | |
1271 | if ((ImageIn->Flags & EFI_IMAGE_TRANSPARENT) == EFI_IMAGE_TRANSPARENT) {\r | |
1272 | Transparent = TRUE;\r | |
1273 | }\r | |
1274 | }\r | |
1275 | \r | |
1276 | //\r | |
1277 | // Image cannot be drawn transparently if Blt points to NULL on entry.\r | |
1278 | // Currently output to Screen transparently is not supported, either.\r | |
1279 | //\r | |
1280 | if (Transparent) {\r | |
1281 | if (*Blt == NULL) {\r | |
1282 | return EFI_INVALID_PARAMETER;\r | |
1283 | } else if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {\r | |
1284 | return EFI_INVALID_PARAMETER;\r | |
1285 | }\r | |
1286 | }\r | |
1287 | \r | |
1288 | Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
1289 | \r | |
1290 | //\r | |
1291 | // When Blt points to a non-NULL on entry, this image will be drawn onto\r | |
1292 | // this bitmap or screen pointed by "*Blt" and EFI_HII_DRAW_FLAG_CLIP is implied.\r | |
1293 | // Otherwise a new bitmap will be allocated to hold this image.\r | |
1294 | //\r | |
1295 | if (*Blt != NULL) {\r | |
1296 | //\r | |
1297 | // Clip the image by (Width, Height)\r | |
1298 | //\r | |
1299 | \r | |
1300 | Width = ImageIn->Width;\r | |
1301 | Height = ImageIn->Height;\r | |
1302 | \r | |
1303 | if (Width > (*Blt)->Width - BltX) {\r | |
1304 | Width = (*Blt)->Width - BltX;\r | |
1305 | }\r | |
1306 | if (Height > (*Blt)->Height - BltY) {\r | |
1307 | Height = (*Blt)->Height - BltY;\r | |
1308 | }\r | |
1309 | \r | |
1310 | BufferLen = Width * Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r | |
1311 | BltBuffer = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (BufferLen);\r | |
1312 | if (BltBuffer == NULL) {\r | |
1313 | return EFI_OUT_OF_RESOURCES;\r | |
1314 | }\r | |
1315 | \r | |
1316 | if (Width == ImageIn->Width && Height == ImageIn->Height) {\r | |
1317 | CopyMem (BltBuffer, ImageIn->Bitmap, BufferLen);\r | |
1318 | } else {\r | |
e90b081a | 1319 | for (Ypos = 0; Ypos < Height; Ypos++) {\r |
1320 | OffsetY1 = ImageIn->Width * Ypos;\r | |
1321 | OffsetY2 = Width * Ypos;\r | |
1322 | for (Xpos = 0; Xpos < Width; Xpos++) {\r | |
1323 | BltBuffer[OffsetY2 + Xpos] = ImageIn->Bitmap[OffsetY1 + Xpos];\r | |
93e3992d | 1324 | }\r |
1325 | }\r | |
1326 | }\r | |
1327 | \r | |
1328 | //\r | |
1329 | // Draw the image to existing bitmap or screen depending on flag.\r | |
1330 | //\r | |
1331 | if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {\r | |
3f57706f | 1332 | //\r |
1333 | // Caller should make sure the current UGA console is grarphic mode.\r | |
1334 | //\r | |
93e3992d | 1335 | \r |
93e3992d | 1336 | //\r |
1337 | // Write the image directly to the output device specified by Screen.\r | |
1338 | //\r | |
1339 | Status = (*Blt)->Image.Screen->Blt (\r | |
1340 | (*Blt)->Image.Screen,\r | |
1341 | BltBuffer,\r | |
1342 | EfiBltBufferToVideo,\r | |
1343 | 0,\r | |
1344 | 0,\r | |
1345 | BltX,\r | |
1346 | BltY,\r | |
1347 | Width,\r | |
1348 | Height,\r | |
1349 | 0\r | |
1350 | );\r | |
1351 | } else {\r | |
1352 | //\r | |
1353 | // Draw the image onto the existing bitmap specified by Bitmap.\r | |
1354 | //\r | |
1355 | Status = ImageToBlt (\r | |
1356 | BltBuffer,\r | |
1357 | BltX,\r | |
1358 | BltY,\r | |
1359 | Width,\r | |
1360 | Height,\r | |
1361 | Transparent,\r | |
1362 | Blt\r | |
1363 | );\r | |
1364 | \r | |
1365 | }\r | |
1366 | \r | |
676df92c | 1367 | FreePool (BltBuffer);\r |
93e3992d | 1368 | return Status;\r |
1369 | \r | |
1370 | } else {\r | |
1371 | //\r | |
1372 | // Allocate a new bitmap to hold the incoming image.\r | |
1373 | //\r | |
1374 | Width = ImageIn->Width + BltX;\r | |
1375 | Height = ImageIn->Height + BltY;\r | |
1376 | \r | |
1377 | BufferLen = Width * Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r | |
1378 | BltBuffer = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (BufferLen);\r | |
1379 | if (BltBuffer == NULL) {\r | |
1380 | return EFI_OUT_OF_RESOURCES;\r | |
1381 | }\r | |
1382 | \r | |
1383 | ImageOut = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r | |
1384 | if (ImageOut == NULL) {\r | |
676df92c | 1385 | FreePool (BltBuffer);\r |
93e3992d | 1386 | return EFI_OUT_OF_RESOURCES;\r |
1387 | }\r | |
1388 | ImageOut->Width = (UINT16) Width;\r | |
1389 | ImageOut->Height = (UINT16) Height;\r | |
1390 | ImageOut->Image.Bitmap = BltBuffer;\r | |
1391 | \r | |
1392 | //\r | |
1393 | // BUGBUG: Now all the "blank" pixels are filled with system default background\r | |
1394 | // color. Not sure if it need to be updated or not.\r | |
1395 | //\r | |
1396 | Status = GetSystemFont (Private, &FontInfo, NULL);\r | |
1397 | if (EFI_ERROR (Status)) {\r | |
676df92c | 1398 | FreePool (BltBuffer);\r |
1399 | FreePool (ImageOut);\r | |
93e3992d | 1400 | return Status;\r |
1401 | }\r | |
523f48e7 | 1402 | ASSERT (FontInfo != NULL);\r |
93e3992d | 1403 | for (Index = 0; Index < Width * Height; Index++) {\r |
1404 | BltBuffer[Index] = FontInfo->BackgroundColor;\r | |
1405 | }\r | |
676df92c | 1406 | FreePool (FontInfo);\r |
93e3992d | 1407 | \r |
1408 | //\r | |
1409 | // Draw the incoming image to the new created image.\r | |
1410 | //\r | |
1411 | *Blt = ImageOut;\r | |
1412 | return ImageToBlt (\r | |
1413 | ImageIn->Bitmap,\r | |
1414 | BltX,\r | |
1415 | BltY,\r | |
1416 | ImageIn->Width,\r | |
1417 | ImageIn->Height,\r | |
1418 | Transparent,\r | |
1419 | Blt\r | |
1420 | );\r | |
1421 | \r | |
1422 | }\r | |
1423 | }\r | |
1424 | \r | |
1425 | \r | |
1426 | /**\r | |
1427 | This function renders an image to a bitmap or the screen using the specified\r | |
1428 | color and options. It draws the image on an existing bitmap, allocates a new\r | |
1429 | bitmap or uses the screen. The images can be clipped.\r | |
1430 | \r | |
1431 | @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r | |
1432 | @param Flags Describes how the image is to be drawn.\r | |
1433 | @param PackageList The package list in the HII database to search for\r | |
1434 | the specified image.\r | |
1435 | @param ImageId The image's id, which is unique within\r | |
1436 | PackageList.\r | |
1437 | @param Blt If this points to a non-NULL on entry, this points\r | |
1438 | to the image, which is Width pixels wide and\r | |
1439 | Height pixels high. The image will be drawn onto\r | |
1440 | this image and\r | |
1441 | EFI_HII_DRAW_FLAG_CLIP is implied. If this points\r | |
1442 | to a NULL on entry, then a buffer will be\r | |
1443 | allocated to hold the generated image and the\r | |
ac644614 | 1444 | pointer updated on exit. It is the caller's\r |
93e3992d | 1445 | responsibility to free this buffer.\r |
e90b081a | 1446 | @param BltX Specifies the offset from the left and top edge of\r |
1447 | the output image of the first pixel in the image.\r | |
93e3992d | 1448 | @param BltY Specifies the offset from the left and top edge of\r |
1449 | the output image of the first pixel in the image.\r | |
1450 | \r | |
1451 | @retval EFI_SUCCESS The image was successfully drawn.\r | |
1452 | @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.\r | |
813acf3a | 1453 | @retval EFI_INVALID_PARAMETER The Blt was NULL.\r |
1454 | @retval EFI_NOT_FOUND The image specified by ImageId is not in the database. \r | |
1455 | The specified PackageList is not in the database. \r | |
93e3992d | 1456 | \r |
1457 | **/\r | |
1458 | EFI_STATUS\r | |
1459 | EFIAPI\r | |
1460 | HiiDrawImageId (\r | |
1461 | IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r | |
1462 | IN EFI_HII_DRAW_FLAGS Flags,\r | |
1463 | IN EFI_HII_HANDLE PackageList,\r | |
1464 | IN EFI_IMAGE_ID ImageId,\r | |
1465 | IN OUT EFI_IMAGE_OUTPUT **Blt,\r | |
1466 | IN UINTN BltX,\r | |
1467 | IN UINTN BltY\r | |
1468 | )\r | |
1469 | {\r | |
1470 | EFI_STATUS Status;\r | |
813acf3a | 1471 | EFI_IMAGE_INPUT Image;\r |
93e3992d | 1472 | \r |
1473 | //\r | |
1474 | // Check input parameter.\r | |
1475 | //\r | |
813acf3a | 1476 | if (This == NULL || Blt == NULL) {\r |
93e3992d | 1477 | return EFI_INVALID_PARAMETER;\r |
1478 | }\r | |
1479 | \r | |
1480 | if (!IsHiiHandleValid (PackageList)) {\r | |
1481 | return EFI_NOT_FOUND;\r | |
1482 | }\r | |
1483 | \r | |
1484 | //\r | |
1485 | // Get the specified Image.\r | |
1486 | //\r | |
813acf3a | 1487 | Status = HiiGetImage (This, PackageList, ImageId, &Image);\r |
1488 | if (EFI_ERROR (Status)) {\r | |
93e3992d | 1489 | return Status;\r |
1490 | }\r | |
1491 | \r | |
93e3992d | 1492 | //\r |
1493 | // Draw this image.\r | |
1494 | //\r | |
813acf3a | 1495 | Status = HiiDrawImage (This, Flags, &Image, Blt, BltX, BltY);\r |
676df92c | 1496 | if (Image.Bitmap != NULL) {\r |
1497 | FreePool (Image.Bitmap);\r | |
1498 | }\r | |
93e3992d | 1499 | return Status;\r |
1500 | }\r | |
1501 | \r |