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