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