]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Implementation for EFI_HII_IMAGE_PROTOCOL.\r | |
3 | \r | |
4 | \r | |
5 | Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
6 | This program and the accompanying materials\r | |
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 | |
14 | **/\r | |
15 | \r | |
16 | \r | |
17 | #include "HiiDatabase.h"\r | |
18 | \r | |
19 | \r | |
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 | |
24 | \r | |
25 | This is a internal function.\r | |
26 | \r | |
27 | @param ImageBlocks Points to the beginning of a series of image blocks stored in order.\r | |
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 | |
30 | \r | |
31 | @return The image block address when input ImageId is not zero; otherwise return NULL.\r | |
32 | \r | |
33 | **/\r | |
34 | EFI_HII_IMAGE_BLOCK *\r | |
35 | GetImageIdOrAddress (\r | |
36 | IN EFI_HII_IMAGE_BLOCK *ImageBlocks,\r | |
37 | IN OUT EFI_IMAGE_ID *ImageId\r | |
38 | )\r | |
39 | {\r | |
40 | EFI_IMAGE_ID ImageIdCurrent;\r | |
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 | |
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 | |
55 | if (CurrentImageBlock->BlockType == EFI_HII_IIBT_DUPLICATE) {\r | |
56 | *ImageId = ReadUnaligned16 ((VOID *) &((EFI_HII_IIBT_DUPLICATE_BLOCK *) CurrentImageBlock)->ImageId);\r | |
57 | ASSERT (*ImageId != ImageIdCurrent);\r | |
58 | ASSERT (*ImageId != 0);\r | |
59 | CurrentImageBlock = ImageBlocks;\r | |
60 | ImageIdCurrent = 1;\r | |
61 | continue;\r | |
62 | }\r | |
63 | \r | |
64 | return CurrentImageBlock;\r | |
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 | |
73 | switch (CurrentImageBlock->BlockType) {\r | |
74 | case EFI_HII_IIBT_EXT1:\r | |
75 | Length = ((EFI_HII_IIBT_EXT1_BLOCK *) CurrentImageBlock)->Length;\r | |
76 | break;\r | |
77 | case EFI_HII_IIBT_EXT2:\r | |
78 | Length = ReadUnaligned16 (&((EFI_HII_IIBT_EXT2_BLOCK *) CurrentImageBlock)->Length);\r | |
79 | break;\r | |
80 | case EFI_HII_IIBT_EXT4:\r | |
81 | Length = ReadUnaligned32 ((VOID *) &((EFI_HII_IIBT_EXT4_BLOCK *) CurrentImageBlock)->Length);\r | |
82 | break;\r | |
83 | \r | |
84 | case EFI_HII_IIBT_IMAGE_1BIT:\r | |
85 | case EFI_HII_IIBT_IMAGE_1BIT_TRANS:\r | |
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 | |
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 | |
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 | |
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 | |
106 | Length = sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK) - sizeof (UINT8) +\r | |
107 | BITMAP_LEN_8_BIT (\r | |
108 | (UINT32) 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 | |
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 | |
116 | Length = sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL) +\r | |
117 | BITMAP_LEN_24_BIT (\r | |
118 | (UINT32) 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 | |
121 | ImageIdCurrent++;\r | |
122 | break;\r | |
123 | \r | |
124 | case EFI_HII_IIBT_DUPLICATE:\r | |
125 | Length = sizeof (EFI_HII_IIBT_DUPLICATE_BLOCK);\r | |
126 | ImageIdCurrent++;\r | |
127 | break;\r | |
128 | \r | |
129 | case EFI_HII_IIBT_IMAGE_JPEG:\r | |
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 | |
136 | ImageIdCurrent++;\r | |
137 | break;\r | |
138 | \r | |
139 | case EFI_HII_IIBT_SKIP1:\r | |
140 | Length = sizeof (EFI_HII_IIBT_SKIP1_BLOCK);\r | |
141 | ImageIdCurrent += ((EFI_HII_IIBT_SKIP1_BLOCK *) CurrentImageBlock)->SkipCount;\r | |
142 | break;\r | |
143 | \r | |
144 | case EFI_HII_IIBT_SKIP2:\r | |
145 | Length = sizeof (EFI_HII_IIBT_SKIP2_BLOCK);\r | |
146 | ImageIdCurrent += ReadUnaligned16 ((VOID *) &((EFI_HII_IIBT_SKIP2_BLOCK *) CurrentImageBlock)->SkipCount);\r | |
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 | |
154 | Length = 0;\r | |
155 | break;\r | |
156 | }\r | |
157 | \r | |
158 | CurrentImageBlock = (EFI_HII_IMAGE_BLOCK *) ((UINT8 *) CurrentImageBlock + Length);\r | |
159 | \r | |
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 | |
167 | return CurrentImageBlock;\r | |
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 | |
178 | This is a internal function.\r | |
179 | \r | |
180 | \r | |
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 | |
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 | |
207 | This is a internal function.\r | |
208 | \r | |
209 | \r | |
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 | |
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 | |
236 | This is a internal function.\r | |
237 | \r | |
238 | \r | |
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 | |
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 | |
254 | UINT16 Xpos;\r | |
255 | UINT16 Ypos;\r | |
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 | |
261 | UINTN PaletteSize;\r | |
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 | |
271 | PaletteSize = 0;\r | |
272 | CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));\r | |
273 | PaletteSize += sizeof (UINT16);\r | |
274 | Palette = AllocateZeroPool (PaletteSize);\r | |
275 | ASSERT (Palette != NULL);\r | |
276 | if (Palette == NULL) {\r | |
277 | return;\r | |
278 | }\r | |
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 | |
284 | FreePool (Palette);\r | |
285 | \r | |
286 | //\r | |
287 | // Convert the pixel from one bit to corresponding color.\r | |
288 | //\r | |
289 | for (Ypos = 0; Ypos < Image->Height; Ypos++) {\r | |
290 | OffsetY = BITMAP_LEN_1_BIT (Image->Width, Ypos);\r | |
291 | //\r | |
292 | // All bits in these bytes are meaningful\r | |
293 | //\r | |
294 | for (Xpos = 0; Xpos < Image->Width / 8; Xpos++) {\r | |
295 | Byte = *(Data + OffsetY + Xpos);\r | |
296 | for (Index = 0; Index < 8; Index++) {\r | |
297 | if ((Byte & (1 << Index)) != 0) {\r | |
298 | BitMapPtr[Ypos * Image->Width + Xpos * 8 + (8 - Index - 1)] = PaletteValue[1];\r | |
299 | } else {\r | |
300 | BitMapPtr[Ypos * Image->Width + Xpos * 8 + (8 - Index - 1)] = PaletteValue[0];\r | |
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 | |
309 | Byte = *(Data + OffsetY + Xpos);\r | |
310 | for (Index = 0; Index < Image->Width % 8; Index++) {\r | |
311 | if ((Byte & (1 << (8 - Index - 1))) != 0) {\r | |
312 | BitMapPtr[Ypos * Image->Width + Xpos * 8 + Index] = PaletteValue[1];\r | |
313 | } else {\r | |
314 | BitMapPtr[Ypos * Image->Width + Xpos * 8 + Index] = PaletteValue[0];\r | |
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 | |
325 | This is a internal function.\r | |
326 | \r | |
327 | \r | |
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 | |
330 | @param[in] PaletteInfo PaletteInfo which stores the color of the output\r | |
331 | pixels. Each entry corresponds to a color within\r | |
332 | [0, 15].\r | |
333 | \r | |
334 | \r | |
335 | **/\r | |
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 | |
343 | UINT16 Xpos;\r | |
344 | UINT16 Ypos;\r | |
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 | |
349 | UINTN PaletteSize;\r | |
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 | |
360 | PaletteSize = 0;\r | |
361 | CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));\r | |
362 | PaletteSize += sizeof (UINT16);\r | |
363 | Palette = AllocateZeroPool (PaletteSize);\r | |
364 | ASSERT (Palette != NULL);\r | |
365 | if (Palette == NULL) {\r | |
366 | return;\r | |
367 | }\r | |
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 | |
373 | FreePool (Palette);\r | |
374 | \r | |
375 | //\r | |
376 | // Convert the pixel from 4 bit to corresponding color.\r | |
377 | //\r | |
378 | for (Ypos = 0; Ypos < Image->Height; Ypos++) {\r | |
379 | OffsetY = BITMAP_LEN_4_BIT (Image->Width, Ypos);\r | |
380 | //\r | |
381 | // All bits in these bytes are meaningful\r | |
382 | //\r | |
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 | |
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 | |
393 | Byte = *(Data + OffsetY + Xpos);\r | |
394 | BitMapPtr[Ypos * Image->Width + Xpos * 2] = PaletteValue[Byte >> 4];\r | |
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 | |
403 | This is a internal function.\r | |
404 | \r | |
405 | \r | |
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 | |
408 | @param[in] PaletteInfo PaletteInfo which stores the color of the output\r | |
409 | pixels. Each entry corresponds to a color within\r | |
410 | [0, 255].\r | |
411 | \r | |
412 | \r | |
413 | **/\r | |
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 | |
421 | UINT16 Xpos;\r | |
422 | UINT16 Ypos;\r | |
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 | |
427 | UINTN PaletteSize;\r | |
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 | |
438 | PaletteSize = 0;\r | |
439 | CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));\r | |
440 | PaletteSize += sizeof (UINT16);\r | |
441 | Palette = AllocateZeroPool (PaletteSize);\r | |
442 | ASSERT (Palette != NULL);\r | |
443 | if (Palette == NULL) {\r | |
444 | return;\r | |
445 | }\r | |
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 | |
450 | FreePool (Palette);\r | |
451 | \r | |
452 | //\r | |
453 | // Convert the pixel from 8 bits to corresponding color.\r | |
454 | //\r | |
455 | for (Ypos = 0; Ypos < Image->Height; Ypos++) {\r | |
456 | OffsetY = BITMAP_LEN_8_BIT ((UINT32) Image->Width, Ypos);\r | |
457 | //\r | |
458 | // All bits are meaningful since the bitmap is 8 bits per pixel.\r | |
459 | //\r | |
460 | for (Xpos = 0; Xpos < Image->Width; Xpos++) {\r | |
461 | Byte = *(Data + OffsetY + Xpos);\r | |
462 | BitMapPtr[OffsetY + Xpos] = PaletteValue[Byte];\r | |
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 | |
472 | This is a internal function.\r | |
473 | \r | |
474 | \r | |
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 | |
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 | |
487 | UINT16 Ypos;\r | |
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 | |
495 | for (Ypos = 0; Ypos < Image->Height; Ypos++) {\r | |
496 | OffsetY = BITMAP_LEN_8_BIT ((UINT32) Image->Width, Ypos);\r | |
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 | |
506 | This is a internal function.\r | |
507 | \r | |
508 | \r | |
509 | @param BltBuffer Buffer points to bitmap data of incoming image.\r | |
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 | |
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 | |
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 | |
537 | UINTN Xpos;\r | |
538 | UINTN Ypos;\r | |
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 | |
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 | |
564 | if (Transparent) {\r | |
565 | if (CompareMem (&SrcPixel, &ZeroPixel, 3) != 0) {\r | |
566 | ImageOut->Image.Bitmap[OffsetY2 + BltX + Xpos] = SrcPixel;\r | |
567 | }\r | |
568 | } else {\r | |
569 | ImageOut->Image.Bitmap[OffsetY2 + BltX + Xpos] = SrcPixel;\r | |
570 | }\r | |
571 | }\r | |
572 | }\r | |
573 | \r | |
574 | return EFI_SUCCESS;\r | |
575 | }\r | |
576 | \r | |
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 | |
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 | |
637 | HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r | |
638 | HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;\r | |
639 | EFI_HII_IMAGE_BLOCK *ImageBlocks;\r | |
640 | UINT32 NewBlockSize;\r | |
641 | \r | |
642 | if (This == NULL || ImageId == NULL || Image == NULL || Image->Bitmap == NULL) {\r | |
643 | return EFI_INVALID_PARAMETER;\r | |
644 | }\r | |
645 | \r | |
646 | Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
647 | PackageListNode = LocatePackageList (&Private->DatabaseList, PackageList);\r | |
648 | if (PackageListNode == NULL) {\r | |
649 | return EFI_NOT_FOUND;\r | |
650 | }\r | |
651 | \r | |
652 | NewBlockSize = sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL) +\r | |
653 | BITMAP_LEN_24_BIT ((UINT32) Image->Width, Image->Height);\r | |
654 | \r | |
655 | //\r | |
656 | // Get the image package in the package list,\r | |
657 | // or create a new image package if image package does not exist.\r | |
658 | //\r | |
659 | if (PackageListNode->ImagePkg != NULL) {\r | |
660 | ImagePackage = PackageListNode->ImagePkg;\r | |
661 | \r | |
662 | //\r | |
663 | // Output the image id of the incoming image being inserted, which is the\r | |
664 | // image id of the EFI_HII_IIBT_END block of old image package.\r | |
665 | //\r | |
666 | *ImageId = 0;\r | |
667 | GetImageIdOrAddress (ImagePackage->ImageBlock, ImageId);\r | |
668 | \r | |
669 | //\r | |
670 | // Update the package's image block by appending the new block to the end.\r | |
671 | //\r | |
672 | ImageBlocks = AllocatePool (ImagePackage->ImageBlockSize + NewBlockSize);\r | |
673 | if (ImageBlocks == NULL) {\r | |
674 | return EFI_OUT_OF_RESOURCES;\r | |
675 | }\r | |
676 | //\r | |
677 | // Copy the original content.\r | |
678 | //\r | |
679 | CopyMem (\r | |
680 | ImageBlocks,\r | |
681 | ImagePackage->ImageBlock,\r | |
682 | ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK)\r | |
683 | );\r | |
684 | FreePool (ImagePackage->ImageBlock);\r | |
685 | ImagePackage->ImageBlock = ImageBlocks;\r | |
686 | \r | |
687 | //\r | |
688 | // Point to the very last block.\r | |
689 | //\r | |
690 | ImageBlocks = (EFI_HII_IMAGE_BLOCK *) (\r | |
691 | (UINT8 *) ImageBlocks + ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK)\r | |
692 | );\r | |
693 | //\r | |
694 | // Update the length record.\r | |
695 | //\r | |
696 | ImagePackage->ImageBlockSize += NewBlockSize;\r | |
697 | ImagePackage->ImagePkgHdr.Header.Length += NewBlockSize;\r | |
698 | PackageListNode->PackageListHdr.PackageLength += NewBlockSize;\r | |
699 | \r | |
700 | } else {\r | |
701 | //\r | |
702 | // The specified package list does not contain image package.\r | |
703 | // Create one to add this image block.\r | |
704 | //\r | |
705 | ImagePackage = (HII_IMAGE_PACKAGE_INSTANCE *) AllocateZeroPool (sizeof (HII_IMAGE_PACKAGE_INSTANCE));\r | |
706 | if (ImagePackage == NULL) {\r | |
707 | return EFI_OUT_OF_RESOURCES;\r | |
708 | }\r | |
709 | //\r | |
710 | // Output the image id of the incoming image being inserted, which is the\r | |
711 | // first image block so that id is initially to one.\r | |
712 | //\r | |
713 | *ImageId = 1;\r | |
714 | //\r | |
715 | // Fill in image package header.\r | |
716 | //\r | |
717 | ImagePackage->ImagePkgHdr.Header.Length = sizeof (EFI_HII_IMAGE_PACKAGE_HDR) + NewBlockSize + sizeof (EFI_HII_IIBT_END_BLOCK);\r | |
718 | ImagePackage->ImagePkgHdr.Header.Type = EFI_HII_PACKAGE_IMAGES;\r | |
719 | ImagePackage->ImagePkgHdr.ImageInfoOffset = sizeof (EFI_HII_IMAGE_PACKAGE_HDR);\r | |
720 | ImagePackage->ImagePkgHdr.PaletteInfoOffset = 0;\r | |
721 | \r | |
722 | //\r | |
723 | // Fill in palette info.\r | |
724 | //\r | |
725 | ImagePackage->PaletteBlock = NULL;\r | |
726 | ImagePackage->PaletteInfoSize = 0;\r | |
727 | \r | |
728 | //\r | |
729 | // Fill in image blocks.\r | |
730 | //\r | |
731 | ImagePackage->ImageBlockSize = NewBlockSize + sizeof (EFI_HII_IIBT_END_BLOCK);\r | |
732 | ImagePackage->ImageBlock = AllocateZeroPool (NewBlockSize + sizeof (EFI_HII_IIBT_END_BLOCK));\r | |
733 | if (ImagePackage->ImageBlock == NULL) {\r | |
734 | FreePool (ImagePackage);\r | |
735 | return EFI_OUT_OF_RESOURCES;\r | |
736 | }\r | |
737 | ImageBlocks = ImagePackage->ImageBlock;\r | |
738 | \r | |
739 | //\r | |
740 | // Insert this image package.\r | |
741 | //\r | |
742 | PackageListNode->ImagePkg = ImagePackage;\r | |
743 | PackageListNode->PackageListHdr.PackageLength += ImagePackage->ImagePkgHdr.Header.Length;\r | |
744 | }\r | |
745 | \r | |
746 | //\r | |
747 | // Append the new block here\r | |
748 | //\r | |
749 | if (Image->Flags == EFI_IMAGE_TRANSPARENT) {\r | |
750 | ImageBlocks->BlockType = EFI_HII_IIBT_IMAGE_24BIT_TRANS;\r | |
751 | } else {\r | |
752 | ImageBlocks->BlockType = EFI_HII_IIBT_IMAGE_24BIT;\r | |
753 | }\r | |
754 | WriteUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) ImageBlocks)->Bitmap.Width, Image->Width);\r | |
755 | WriteUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) ImageBlocks)->Bitmap.Height, Image->Height);\r | |
756 | CopyGopToRgbPixel (((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) ImageBlocks)->Bitmap.Bitmap, Image->Bitmap, (UINT32) Image->Width * Image->Height);\r | |
757 | \r | |
758 | //\r | |
759 | // Append the block end\r | |
760 | //\r | |
761 | ImageBlocks = (EFI_HII_IMAGE_BLOCK *) ((UINT8 *) ImageBlocks + NewBlockSize);\r | |
762 | ImageBlocks->BlockType = EFI_HII_IIBT_END;\r | |
763 | \r | |
764 | //\r | |
765 | // Check whether need to get the contents of HiiDataBase.\r | |
766 | // Only after ReadyToBoot to do the export.\r | |
767 | //\r | |
768 | if (gExportAfterReadyToBoot) {\r | |
769 | HiiGetDatabaseInfo(&Private->HiiDatabase);\r | |
770 | }\r | |
771 | \r | |
772 | return EFI_SUCCESS;\r | |
773 | }\r | |
774 | \r | |
775 | \r | |
776 | /**\r | |
777 | This function retrieves the image specified by ImageId which is associated with\r | |
778 | the specified PackageList and copies it into the buffer specified by Image.\r | |
779 | \r | |
780 | @param Database A pointer to the database list header.\r | |
781 | @param PackageList Handle of the package list where this image will\r | |
782 | be searched.\r | |
783 | @param ImageId The image's id,, which is unique within\r | |
784 | PackageList.\r | |
785 | @param Image Points to the image.\r | |
786 | @param BitmapOnly TRUE to only return the bitmap type image.\r | |
787 | FALSE to locate image decoder instance to decode image.\r | |
788 | \r | |
789 | @retval EFI_SUCCESS The new image was returned successfully.\r | |
790 | @retval EFI_NOT_FOUND The image specified by ImageId is not in the\r | |
791 | database. The specified PackageList is not in the database.\r | |
792 | @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to\r | |
793 | hold the image.\r | |
794 | @retval EFI_INVALID_PARAMETER The Image or ImageSize was NULL.\r | |
795 | @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there was not\r | |
796 | enough memory.\r | |
797 | **/\r | |
798 | EFI_STATUS\r | |
799 | IGetImage (\r | |
800 | IN LIST_ENTRY *Database,\r | |
801 | IN EFI_HII_HANDLE PackageList,\r | |
802 | IN EFI_IMAGE_ID ImageId,\r | |
803 | OUT EFI_IMAGE_INPUT *Image,\r | |
804 | IN BOOLEAN BitmapOnly\r | |
805 | )\r | |
806 | {\r | |
807 | EFI_STATUS Status;\r | |
808 | HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r | |
809 | HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;\r | |
810 | EFI_HII_IMAGE_BLOCK *CurrentImageBlock;\r | |
811 | EFI_HII_IIBT_IMAGE_1BIT_BLOCK Iibt1bit;\r | |
812 | UINT16 Width;\r | |
813 | UINT16 Height;\r | |
814 | UINTN ImageLength;\r | |
815 | UINT8 *PaletteInfo;\r | |
816 | UINT8 PaletteIndex;\r | |
817 | UINT16 PaletteSize;\r | |
818 | EFI_HII_IMAGE_DECODER_PROTOCOL *Decoder;\r | |
819 | EFI_IMAGE_OUTPUT *ImageOut;\r | |
820 | \r | |
821 | if (Image == NULL || ImageId == 0) {\r | |
822 | return EFI_INVALID_PARAMETER;\r | |
823 | }\r | |
824 | \r | |
825 | PackageListNode = LocatePackageList (Database, PackageList);\r | |
826 | if (PackageListNode == NULL) {\r | |
827 | return EFI_NOT_FOUND;\r | |
828 | }\r | |
829 | ImagePackage = PackageListNode->ImagePkg;\r | |
830 | if (ImagePackage == NULL) {\r | |
831 | return EFI_NOT_FOUND;\r | |
832 | }\r | |
833 | \r | |
834 | //\r | |
835 | // Find the image block specified by ImageId\r | |
836 | //\r | |
837 | CurrentImageBlock = GetImageIdOrAddress (ImagePackage->ImageBlock, &ImageId);\r | |
838 | if (CurrentImageBlock == NULL) {\r | |
839 | return EFI_NOT_FOUND;\r | |
840 | }\r | |
841 | \r | |
842 | Image->Flags = 0;\r | |
843 | switch (CurrentImageBlock->BlockType) {\r | |
844 | case EFI_HII_IIBT_IMAGE_JPEG:\r | |
845 | case EFI_HII_IIBT_IMAGE_PNG:\r | |
846 | if (BitmapOnly) {\r | |
847 | return EFI_UNSUPPORTED;\r | |
848 | }\r | |
849 | \r | |
850 | ImageOut = NULL;\r | |
851 | Decoder = LocateHiiImageDecoder (CurrentImageBlock->BlockType);\r | |
852 | if (Decoder == NULL) {\r | |
853 | return EFI_UNSUPPORTED;\r | |
854 | }\r | |
855 | //\r | |
856 | // Use the common block code since the definition of two structures is the same.\r | |
857 | //\r | |
858 | ASSERT (OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK, Data) == OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK, Data));\r | |
859 | ASSERT (sizeof (((EFI_HII_IIBT_JPEG_BLOCK *) CurrentImageBlock)->Data) ==\r | |
860 | sizeof (((EFI_HII_IIBT_PNG_BLOCK *) CurrentImageBlock)->Data));\r | |
861 | ASSERT (OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK, Size) == OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK, Size));\r | |
862 | ASSERT (sizeof (((EFI_HII_IIBT_JPEG_BLOCK *) CurrentImageBlock)->Size) ==\r | |
863 | sizeof (((EFI_HII_IIBT_PNG_BLOCK *) CurrentImageBlock)->Size));\r | |
864 | Status = Decoder->DecodeImage (\r | |
865 | Decoder,\r | |
866 | ((EFI_HII_IIBT_JPEG_BLOCK *) CurrentImageBlock)->Data,\r | |
867 | ((EFI_HII_IIBT_JPEG_BLOCK *) CurrentImageBlock)->Size,\r | |
868 | &ImageOut,\r | |
869 | FALSE\r | |
870 | );\r | |
871 | \r | |
872 | //\r | |
873 | // Spec requires to use the first capable image decoder instance.\r | |
874 | // The first image decoder instance may fail to decode the image.\r | |
875 | //\r | |
876 | if (!EFI_ERROR (Status)) {\r | |
877 | Image->Bitmap = ImageOut->Image.Bitmap;\r | |
878 | Image->Height = ImageOut->Height;\r | |
879 | Image->Width = ImageOut->Width;\r | |
880 | FreePool (ImageOut);\r | |
881 | }\r | |
882 | return Status;\r | |
883 | \r | |
884 | case EFI_HII_IIBT_IMAGE_1BIT_TRANS:\r | |
885 | case EFI_HII_IIBT_IMAGE_4BIT_TRANS:\r | |
886 | case EFI_HII_IIBT_IMAGE_8BIT_TRANS:\r | |
887 | Image->Flags = EFI_IMAGE_TRANSPARENT;\r | |
888 | //\r | |
889 | // fall through\r | |
890 | //\r | |
891 | case EFI_HII_IIBT_IMAGE_1BIT:\r | |
892 | case EFI_HII_IIBT_IMAGE_4BIT:\r | |
893 | case EFI_HII_IIBT_IMAGE_8BIT:\r | |
894 | //\r | |
895 | // Use the common block code since the definition of these structures is the same.\r | |
896 | //\r | |
897 | CopyMem (&Iibt1bit, CurrentImageBlock, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK));\r | |
898 | ImageLength = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) *\r | |
899 | ((UINT32) Iibt1bit.Bitmap.Width * Iibt1bit.Bitmap.Height);\r | |
900 | Image->Bitmap = AllocateZeroPool (ImageLength);\r | |
901 | if (Image->Bitmap == NULL) {\r | |
902 | return EFI_OUT_OF_RESOURCES;\r | |
903 | }\r | |
904 | \r | |
905 | Image->Width = Iibt1bit.Bitmap.Width;\r | |
906 | Image->Height = Iibt1bit.Bitmap.Height;\r | |
907 | \r | |
908 | PaletteInfo = ImagePackage->PaletteBlock + sizeof (EFI_HII_IMAGE_PALETTE_INFO_HEADER);\r | |
909 | for (PaletteIndex = 1; PaletteIndex < Iibt1bit.PaletteIndex; PaletteIndex++) {\r | |
910 | CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));\r | |
911 | PaletteInfo += PaletteSize + sizeof (UINT16);\r | |
912 | }\r | |
913 | ASSERT (PaletteIndex == Iibt1bit.PaletteIndex);\r | |
914 | \r | |
915 | //\r | |
916 | // Output bitmap data\r | |
917 | //\r | |
918 | if (CurrentImageBlock->BlockType == EFI_HII_IIBT_IMAGE_1BIT ||\r | |
919 | CurrentImageBlock->BlockType == EFI_HII_IIBT_IMAGE_1BIT_TRANS) {\r | |
920 | Output1bitPixel (\r | |
921 | Image,\r | |
922 | ((EFI_HII_IIBT_IMAGE_1BIT_BLOCK *) CurrentImageBlock)->Bitmap.Data,\r | |
923 | (EFI_HII_IMAGE_PALETTE_INFO *) PaletteInfo\r | |
924 | );\r | |
925 | } else if (CurrentImageBlock->BlockType == EFI_HII_IIBT_IMAGE_4BIT ||\r | |
926 | CurrentImageBlock->BlockType == EFI_HII_IIBT_IMAGE_4BIT_TRANS) {\r | |
927 | Output4bitPixel (\r | |
928 | Image,\r | |
929 | ((EFI_HII_IIBT_IMAGE_4BIT_BLOCK *) CurrentImageBlock)->Bitmap.Data,\r | |
930 | (EFI_HII_IMAGE_PALETTE_INFO *) PaletteInfo\r | |
931 | );\r | |
932 | } else {\r | |
933 | Output8bitPixel (\r | |
934 | Image,\r | |
935 | ((EFI_HII_IIBT_IMAGE_8BIT_BLOCK *) CurrentImageBlock)->Bitmap.Data,\r | |
936 | (EFI_HII_IMAGE_PALETTE_INFO *) PaletteInfo\r | |
937 | );\r | |
938 | }\r | |
939 | \r | |
940 | return EFI_SUCCESS;\r | |
941 | \r | |
942 | case EFI_HII_IIBT_IMAGE_24BIT_TRANS:\r | |
943 | Image->Flags = EFI_IMAGE_TRANSPARENT;\r | |
944 | //\r | |
945 | // fall through\r | |
946 | //\r | |
947 | case EFI_HII_IIBT_IMAGE_24BIT:\r | |
948 | Width = ReadUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) CurrentImageBlock)->Bitmap.Width);\r | |
949 | Height = ReadUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) CurrentImageBlock)->Bitmap.Height);\r | |
950 | ImageLength = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * ((UINT32) Width * Height);\r | |
951 | Image->Bitmap = AllocateZeroPool (ImageLength);\r | |
952 | if (Image->Bitmap == NULL) {\r | |
953 | return EFI_OUT_OF_RESOURCES;\r | |
954 | }\r | |
955 | \r | |
956 | Image->Width = Width;\r | |
957 | Image->Height = Height;\r | |
958 | \r | |
959 | //\r | |
960 | // Output the bitmap data directly.\r | |
961 | //\r | |
962 | Output24bitPixel (\r | |
963 | Image,\r | |
964 | ((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) CurrentImageBlock)->Bitmap.Bitmap\r | |
965 | );\r | |
966 | return EFI_SUCCESS;\r | |
967 | \r | |
968 | default:\r | |
969 | return EFI_NOT_FOUND;\r | |
970 | }\r | |
971 | }\r | |
972 | \r | |
973 | /**\r | |
974 | This function retrieves the image specified by ImageId which is associated with\r | |
975 | the specified PackageList and copies it into the buffer specified by Image.\r | |
976 | \r | |
977 | @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r | |
978 | @param PackageList Handle of the package list where this image will\r | |
979 | be searched.\r | |
980 | @param ImageId The image's id,, which is unique within\r | |
981 | PackageList.\r | |
982 | @param Image Points to the image.\r | |
983 | \r | |
984 | @retval EFI_SUCCESS The new image was returned successfully.\r | |
985 | @retval EFI_NOT_FOUND The image specified by ImageId is not in the\r | |
986 | database. The specified PackageList is not in the database.\r | |
987 | @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to\r | |
988 | hold the image.\r | |
989 | @retval EFI_INVALID_PARAMETER The Image or ImageSize was NULL.\r | |
990 | @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there was not\r | |
991 | enough memory.\r | |
992 | \r | |
993 | **/\r | |
994 | EFI_STATUS\r | |
995 | EFIAPI\r | |
996 | HiiGetImage (\r | |
997 | IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r | |
998 | IN EFI_HII_HANDLE PackageList,\r | |
999 | IN EFI_IMAGE_ID ImageId,\r | |
1000 | OUT EFI_IMAGE_INPUT *Image\r | |
1001 | )\r | |
1002 | {\r | |
1003 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
1004 | Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
1005 | return IGetImage (&Private->DatabaseList, PackageList, ImageId, Image, TRUE);\r | |
1006 | }\r | |
1007 | \r | |
1008 | \r | |
1009 | /**\r | |
1010 | This function updates the image specified by ImageId in the specified PackageListHandle to\r | |
1011 | the image specified by Image.\r | |
1012 | \r | |
1013 | @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r | |
1014 | @param PackageList The package list containing the images.\r | |
1015 | @param ImageId The image's id,, which is unique within\r | |
1016 | PackageList.\r | |
1017 | @param Image Points to the image.\r | |
1018 | \r | |
1019 | @retval EFI_SUCCESS The new image was updated successfully.\r | |
1020 | @retval EFI_NOT_FOUND The image specified by ImageId is not in the\r | |
1021 | database. The specified PackageList is not in the database.\r | |
1022 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r | |
1023 | \r | |
1024 | **/\r | |
1025 | EFI_STATUS\r | |
1026 | EFIAPI\r | |
1027 | HiiSetImage (\r | |
1028 | IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r | |
1029 | IN EFI_HII_HANDLE PackageList,\r | |
1030 | IN EFI_IMAGE_ID ImageId,\r | |
1031 | IN CONST EFI_IMAGE_INPUT *Image\r | |
1032 | )\r | |
1033 | {\r | |
1034 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
1035 | HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r | |
1036 | HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;\r | |
1037 | EFI_HII_IMAGE_BLOCK *CurrentImageBlock;\r | |
1038 | EFI_HII_IMAGE_BLOCK *ImageBlocks;\r | |
1039 | EFI_HII_IMAGE_BLOCK *NewImageBlock;\r | |
1040 | UINT32 NewBlockSize;\r | |
1041 | UINT32 OldBlockSize;\r | |
1042 | UINT32 Part1Size;\r | |
1043 | UINT32 Part2Size;\r | |
1044 | \r | |
1045 | if (This == NULL || Image == NULL || ImageId == 0 || Image->Bitmap == NULL) {\r | |
1046 | return EFI_INVALID_PARAMETER;\r | |
1047 | }\r | |
1048 | \r | |
1049 | Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
1050 | PackageListNode = LocatePackageList (&Private->DatabaseList, PackageList);\r | |
1051 | if (PackageListNode == NULL) {\r | |
1052 | return EFI_NOT_FOUND;\r | |
1053 | }\r | |
1054 | ImagePackage = PackageListNode->ImagePkg;\r | |
1055 | if (ImagePackage == NULL) {\r | |
1056 | return EFI_NOT_FOUND;\r | |
1057 | }\r | |
1058 | \r | |
1059 | //\r | |
1060 | // Find the image block specified by ImageId\r | |
1061 | //\r | |
1062 | CurrentImageBlock = GetImageIdOrAddress (ImagePackage->ImageBlock, &ImageId);\r | |
1063 | if (CurrentImageBlock == NULL) {\r | |
1064 | return EFI_NOT_FOUND;\r | |
1065 | }\r | |
1066 | \r | |
1067 | //\r | |
1068 | // Get the size of original image block. Use some common block code here\r | |
1069 | // since the definition of some structures is the same.\r | |
1070 | //\r | |
1071 | switch (CurrentImageBlock->BlockType) {\r | |
1072 | case EFI_HII_IIBT_IMAGE_JPEG:\r | |
1073 | OldBlockSize = OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK, Data) + ReadUnaligned32 ((VOID *) &((EFI_HII_IIBT_JPEG_BLOCK *) CurrentImageBlock)->Size);\r | |
1074 | break;\r | |
1075 | case EFI_HII_IIBT_IMAGE_PNG:\r | |
1076 | OldBlockSize = OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK, Data) + ReadUnaligned32 ((VOID *) &((EFI_HII_IIBT_PNG_BLOCK *) CurrentImageBlock)->Size);\r | |
1077 | break;\r | |
1078 | case EFI_HII_IIBT_IMAGE_1BIT:\r | |
1079 | case EFI_HII_IIBT_IMAGE_1BIT_TRANS:\r | |
1080 | OldBlockSize = sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK) - sizeof (UINT8) +\r | |
1081 | BITMAP_LEN_1_BIT (\r | |
1082 | ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK *) CurrentImageBlock)->Bitmap.Width),\r | |
1083 | ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK *) CurrentImageBlock)->Bitmap.Height)\r | |
1084 | );\r | |
1085 | break;\r | |
1086 | case EFI_HII_IIBT_IMAGE_4BIT:\r | |
1087 | case EFI_HII_IIBT_IMAGE_4BIT_TRANS:\r | |
1088 | OldBlockSize = sizeof (EFI_HII_IIBT_IMAGE_4BIT_BLOCK) - sizeof (UINT8) +\r | |
1089 | BITMAP_LEN_4_BIT (\r | |
1090 | ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_4BIT_BLOCK *) CurrentImageBlock)->Bitmap.Width),\r | |
1091 | ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_4BIT_BLOCK *) CurrentImageBlock)->Bitmap.Height)\r | |
1092 | );\r | |
1093 | break;\r | |
1094 | case EFI_HII_IIBT_IMAGE_8BIT:\r | |
1095 | case EFI_HII_IIBT_IMAGE_8BIT_TRANS:\r | |
1096 | OldBlockSize = sizeof (EFI_HII_IIBT_IMAGE_8BIT_BLOCK) - sizeof (UINT8) +\r | |
1097 | BITMAP_LEN_8_BIT (\r | |
1098 | (UINT32) ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_8BIT_BLOCK *) CurrentImageBlock)->Bitmap.Width),\r | |
1099 | ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_8BIT_BLOCK *) CurrentImageBlock)->Bitmap.Height)\r | |
1100 | );\r | |
1101 | break;\r | |
1102 | case EFI_HII_IIBT_IMAGE_24BIT:\r | |
1103 | case EFI_HII_IIBT_IMAGE_24BIT_TRANS:\r | |
1104 | OldBlockSize = sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL) +\r | |
1105 | BITMAP_LEN_24_BIT (\r | |
1106 | (UINT32) ReadUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) CurrentImageBlock)->Bitmap.Width),\r | |
1107 | ReadUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) CurrentImageBlock)->Bitmap.Height)\r | |
1108 | );\r | |
1109 | break;\r | |
1110 | default:\r | |
1111 | return EFI_NOT_FOUND;\r | |
1112 | }\r | |
1113 | \r | |
1114 | //\r | |
1115 | // Create the new image block according to input image.\r | |
1116 | //\r | |
1117 | NewBlockSize = sizeof (EFI_HII_IIBT_IMAGE_24BIT_BLOCK) - sizeof (EFI_HII_RGB_PIXEL) +\r | |
1118 | BITMAP_LEN_24_BIT ((UINT32) Image->Width, Image->Height);\r | |
1119 | //\r | |
1120 | // Adjust the image package to remove the original block firstly then add the new block.\r | |
1121 | //\r | |
1122 | ImageBlocks = AllocateZeroPool (ImagePackage->ImageBlockSize + NewBlockSize - OldBlockSize);\r | |
1123 | if (ImageBlocks == NULL) {\r | |
1124 | return EFI_OUT_OF_RESOURCES;\r | |
1125 | }\r | |
1126 | \r | |
1127 | Part1Size = (UINT32) ((UINTN) CurrentImageBlock - (UINTN) ImagePackage->ImageBlock);\r | |
1128 | Part2Size = ImagePackage->ImageBlockSize - Part1Size - OldBlockSize;\r | |
1129 | CopyMem (ImageBlocks, ImagePackage->ImageBlock, Part1Size);\r | |
1130 | \r | |
1131 | //\r | |
1132 | // Set the new image block\r | |
1133 | //\r | |
1134 | NewImageBlock = (EFI_HII_IMAGE_BLOCK *) ((UINT8 *) ImageBlocks + Part1Size);\r | |
1135 | if ((Image->Flags & EFI_IMAGE_TRANSPARENT) == EFI_IMAGE_TRANSPARENT) {\r | |
1136 | NewImageBlock->BlockType= EFI_HII_IIBT_IMAGE_24BIT_TRANS;\r | |
1137 | } else {\r | |
1138 | NewImageBlock->BlockType = EFI_HII_IIBT_IMAGE_24BIT;\r | |
1139 | }\r | |
1140 | WriteUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) NewImageBlock)->Bitmap.Width, Image->Width);\r | |
1141 | WriteUnaligned16 ((VOID *) &((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) NewImageBlock)->Bitmap.Height, Image->Height);\r | |
1142 | CopyGopToRgbPixel (((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *) NewImageBlock)->Bitmap.Bitmap,\r | |
1143 | Image->Bitmap, (UINT32) Image->Width * Image->Height);\r | |
1144 | \r | |
1145 | CopyMem ((UINT8 *) NewImageBlock + NewBlockSize, (UINT8 *) CurrentImageBlock + OldBlockSize, Part2Size);\r | |
1146 | \r | |
1147 | FreePool (ImagePackage->ImageBlock);\r | |
1148 | ImagePackage->ImageBlock = ImageBlocks;\r | |
1149 | ImagePackage->ImageBlockSize += NewBlockSize - OldBlockSize;\r | |
1150 | ImagePackage->ImagePkgHdr.Header.Length += NewBlockSize - OldBlockSize;\r | |
1151 | PackageListNode->PackageListHdr.PackageLength += NewBlockSize - OldBlockSize;\r | |
1152 | \r | |
1153 | //\r | |
1154 | // Check whether need to get the contents of HiiDataBase.\r | |
1155 | // Only after ReadyToBoot to do the export.\r | |
1156 | //\r | |
1157 | if (gExportAfterReadyToBoot) {\r | |
1158 | HiiGetDatabaseInfo(&Private->HiiDatabase);\r | |
1159 | }\r | |
1160 | \r | |
1161 | return EFI_SUCCESS;\r | |
1162 | \r | |
1163 | }\r | |
1164 | \r | |
1165 | \r | |
1166 | /**\r | |
1167 | This function renders an image to a bitmap or the screen using the specified\r | |
1168 | color and options. It draws the image on an existing bitmap, allocates a new\r | |
1169 | bitmap or uses the screen. The images can be clipped.\r | |
1170 | \r | |
1171 | @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r | |
1172 | @param Flags Describes how the image is to be drawn.\r | |
1173 | @param Image Points to the image to be displayed.\r | |
1174 | @param Blt If this points to a non-NULL on entry, this points\r | |
1175 | to the image, which is Width pixels wide and\r | |
1176 | Height pixels high. The image will be drawn onto\r | |
1177 | this image and EFI_HII_DRAW_FLAG_CLIP is implied.\r | |
1178 | If this points to a NULL on entry, then a buffer\r | |
1179 | will be allocated to hold the generated image and\r | |
1180 | the pointer updated on exit. It is the caller's\r | |
1181 | responsibility to free this buffer.\r | |
1182 | @param BltX Specifies the offset from the left and top edge of\r | |
1183 | the output image of the first pixel in the image.\r | |
1184 | @param BltY Specifies the offset from the left and top edge of\r | |
1185 | the output image of the first pixel in the image.\r | |
1186 | \r | |
1187 | @retval EFI_SUCCESS The image was successfully drawn.\r | |
1188 | @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.\r | |
1189 | @retval EFI_INVALID_PARAMETER The Image or Blt was NULL.\r | |
1190 | @retval EFI_INVALID_PARAMETER Any combination of Flags is invalid.\r | |
1191 | \r | |
1192 | **/\r | |
1193 | EFI_STATUS\r | |
1194 | EFIAPI\r | |
1195 | HiiDrawImage (\r | |
1196 | IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r | |
1197 | IN EFI_HII_DRAW_FLAGS Flags,\r | |
1198 | IN CONST EFI_IMAGE_INPUT *Image,\r | |
1199 | IN OUT EFI_IMAGE_OUTPUT **Blt,\r | |
1200 | IN UINTN BltX,\r | |
1201 | IN UINTN BltY\r | |
1202 | )\r | |
1203 | {\r | |
1204 | EFI_STATUS Status;\r | |
1205 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
1206 | BOOLEAN Transparent;\r | |
1207 | EFI_IMAGE_OUTPUT *ImageOut;\r | |
1208 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;\r | |
1209 | UINTN BufferLen;\r | |
1210 | UINTN Width;\r | |
1211 | UINTN Height;\r | |
1212 | UINTN Xpos;\r | |
1213 | UINTN Ypos;\r | |
1214 | UINTN OffsetY1;\r | |
1215 | UINTN OffsetY2;\r | |
1216 | EFI_FONT_DISPLAY_INFO *FontInfo;\r | |
1217 | UINTN Index;\r | |
1218 | \r | |
1219 | if (This == NULL || Image == NULL || Blt == NULL) {\r | |
1220 | return EFI_INVALID_PARAMETER;\r | |
1221 | }\r | |
1222 | \r | |
1223 | if ((Flags & EFI_HII_DRAW_FLAG_CLIP) == EFI_HII_DRAW_FLAG_CLIP && *Blt == NULL) {\r | |
1224 | return EFI_INVALID_PARAMETER;\r | |
1225 | }\r | |
1226 | \r | |
1227 | if ((Flags & EFI_HII_DRAW_FLAG_TRANSPARENT) == EFI_HII_DRAW_FLAG_TRANSPARENT) {\r | |
1228 | return EFI_INVALID_PARAMETER;\r | |
1229 | }\r | |
1230 | \r | |
1231 | FontInfo = NULL;\r | |
1232 | \r | |
1233 | //\r | |
1234 | // Check whether the image will be drawn transparently or opaquely.\r | |
1235 | //\r | |
1236 | Transparent = FALSE;\r | |
1237 | if ((Flags & EFI_HII_DRAW_FLAG_TRANSPARENT) == EFI_HII_DRAW_FLAG_FORCE_TRANS) {\r | |
1238 | Transparent = TRUE;\r | |
1239 | } else if ((Flags & EFI_HII_DRAW_FLAG_TRANSPARENT) == EFI_HII_DRAW_FLAG_FORCE_OPAQUE){\r | |
1240 | Transparent = FALSE;\r | |
1241 | } else {\r | |
1242 | //\r | |
1243 | // Now EFI_HII_DRAW_FLAG_DEFAULT is set, whether image will be drawn depending\r | |
1244 | // on the image's transparency setting.\r | |
1245 | //\r | |
1246 | if ((Image->Flags & EFI_IMAGE_TRANSPARENT) == EFI_IMAGE_TRANSPARENT) {\r | |
1247 | Transparent = TRUE;\r | |
1248 | }\r | |
1249 | }\r | |
1250 | \r | |
1251 | //\r | |
1252 | // Image cannot be drawn transparently if Blt points to NULL on entry.\r | |
1253 | // Currently output to Screen transparently is not supported, either.\r | |
1254 | //\r | |
1255 | if (Transparent) {\r | |
1256 | if (*Blt == NULL) {\r | |
1257 | return EFI_INVALID_PARAMETER;\r | |
1258 | } else if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {\r | |
1259 | return EFI_INVALID_PARAMETER;\r | |
1260 | }\r | |
1261 | }\r | |
1262 | \r | |
1263 | Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
1264 | \r | |
1265 | //\r | |
1266 | // When Blt points to a non-NULL on entry, this image will be drawn onto\r | |
1267 | // this bitmap or screen pointed by "*Blt" and EFI_HII_DRAW_FLAG_CLIP is implied.\r | |
1268 | // Otherwise a new bitmap will be allocated to hold this image.\r | |
1269 | //\r | |
1270 | if (*Blt != NULL) {\r | |
1271 | //\r | |
1272 | // Clip the image by (Width, Height)\r | |
1273 | //\r | |
1274 | \r | |
1275 | Width = Image->Width;\r | |
1276 | Height = Image->Height;\r | |
1277 | \r | |
1278 | if (Width > (*Blt)->Width - BltX) {\r | |
1279 | Width = (*Blt)->Width - BltX;\r | |
1280 | }\r | |
1281 | if (Height > (*Blt)->Height - BltY) {\r | |
1282 | Height = (*Blt)->Height - BltY;\r | |
1283 | }\r | |
1284 | \r | |
1285 | BufferLen = Width * Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r | |
1286 | BltBuffer = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (BufferLen);\r | |
1287 | if (BltBuffer == NULL) {\r | |
1288 | return EFI_OUT_OF_RESOURCES;\r | |
1289 | }\r | |
1290 | \r | |
1291 | if (Width == Image->Width && Height == Image->Height) {\r | |
1292 | CopyMem (BltBuffer, Image->Bitmap, BufferLen);\r | |
1293 | } else {\r | |
1294 | for (Ypos = 0; Ypos < Height; Ypos++) {\r | |
1295 | OffsetY1 = Image->Width * Ypos;\r | |
1296 | OffsetY2 = Width * Ypos;\r | |
1297 | for (Xpos = 0; Xpos < Width; Xpos++) {\r | |
1298 | BltBuffer[OffsetY2 + Xpos] = Image->Bitmap[OffsetY1 + Xpos];\r | |
1299 | }\r | |
1300 | }\r | |
1301 | }\r | |
1302 | \r | |
1303 | //\r | |
1304 | // Draw the image to existing bitmap or screen depending on flag.\r | |
1305 | //\r | |
1306 | if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {\r | |
1307 | //\r | |
1308 | // Caller should make sure the current UGA console is grarphic mode.\r | |
1309 | //\r | |
1310 | \r | |
1311 | //\r | |
1312 | // Write the image directly to the output device specified by Screen.\r | |
1313 | //\r | |
1314 | Status = (*Blt)->Image.Screen->Blt (\r | |
1315 | (*Blt)->Image.Screen,\r | |
1316 | BltBuffer,\r | |
1317 | EfiBltBufferToVideo,\r | |
1318 | 0,\r | |
1319 | 0,\r | |
1320 | BltX,\r | |
1321 | BltY,\r | |
1322 | Width,\r | |
1323 | Height,\r | |
1324 | 0\r | |
1325 | );\r | |
1326 | } else {\r | |
1327 | //\r | |
1328 | // Draw the image onto the existing bitmap specified by Bitmap.\r | |
1329 | //\r | |
1330 | Status = ImageToBlt (\r | |
1331 | BltBuffer,\r | |
1332 | BltX,\r | |
1333 | BltY,\r | |
1334 | Width,\r | |
1335 | Height,\r | |
1336 | Transparent,\r | |
1337 | Blt\r | |
1338 | );\r | |
1339 | \r | |
1340 | }\r | |
1341 | \r | |
1342 | FreePool (BltBuffer);\r | |
1343 | return Status;\r | |
1344 | \r | |
1345 | } else {\r | |
1346 | //\r | |
1347 | // Allocate a new bitmap to hold the incoming image.\r | |
1348 | //\r | |
1349 | Width = Image->Width + BltX;\r | |
1350 | Height = Image->Height + BltY;\r | |
1351 | \r | |
1352 | BufferLen = Width * Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r | |
1353 | BltBuffer = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (BufferLen);\r | |
1354 | if (BltBuffer == NULL) {\r | |
1355 | return EFI_OUT_OF_RESOURCES;\r | |
1356 | }\r | |
1357 | \r | |
1358 | ImageOut = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r | |
1359 | if (ImageOut == NULL) {\r | |
1360 | FreePool (BltBuffer);\r | |
1361 | return EFI_OUT_OF_RESOURCES;\r | |
1362 | }\r | |
1363 | ImageOut->Width = (UINT16) Width;\r | |
1364 | ImageOut->Height = (UINT16) Height;\r | |
1365 | ImageOut->Image.Bitmap = BltBuffer;\r | |
1366 | \r | |
1367 | //\r | |
1368 | // BUGBUG: Now all the "blank" pixels are filled with system default background\r | |
1369 | // color. Not sure if it need to be updated or not.\r | |
1370 | //\r | |
1371 | Status = GetSystemFont (Private, &FontInfo, NULL);\r | |
1372 | if (EFI_ERROR (Status)) {\r | |
1373 | FreePool (BltBuffer);\r | |
1374 | FreePool (ImageOut);\r | |
1375 | return Status;\r | |
1376 | }\r | |
1377 | ASSERT (FontInfo != NULL);\r | |
1378 | for (Index = 0; Index < Width * Height; Index++) {\r | |
1379 | BltBuffer[Index] = FontInfo->BackgroundColor;\r | |
1380 | }\r | |
1381 | FreePool (FontInfo);\r | |
1382 | \r | |
1383 | //\r | |
1384 | // Draw the incoming image to the new created image.\r | |
1385 | //\r | |
1386 | *Blt = ImageOut;\r | |
1387 | return ImageToBlt (\r | |
1388 | Image->Bitmap,\r | |
1389 | BltX,\r | |
1390 | BltY,\r | |
1391 | Image->Width,\r | |
1392 | Image->Height,\r | |
1393 | Transparent,\r | |
1394 | Blt\r | |
1395 | );\r | |
1396 | \r | |
1397 | }\r | |
1398 | }\r | |
1399 | \r | |
1400 | \r | |
1401 | /**\r | |
1402 | This function renders an image to a bitmap or the screen using the specified\r | |
1403 | color and options. It draws the image on an existing bitmap, allocates a new\r | |
1404 | bitmap or uses the screen. The images can be clipped.\r | |
1405 | \r | |
1406 | @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance.\r | |
1407 | @param Flags Describes how the image is to be drawn.\r | |
1408 | @param PackageList The package list in the HII database to search for\r | |
1409 | the specified image.\r | |
1410 | @param ImageId The image's id, which is unique within\r | |
1411 | PackageList.\r | |
1412 | @param Blt If this points to a non-NULL on entry, this points\r | |
1413 | to the image, which is Width pixels wide and\r | |
1414 | Height pixels high. The image will be drawn onto\r | |
1415 | this image and\r | |
1416 | EFI_HII_DRAW_FLAG_CLIP is implied. If this points\r | |
1417 | to a NULL on entry, then a buffer will be\r | |
1418 | allocated to hold the generated image and the\r | |
1419 | pointer updated on exit. It is the caller's\r | |
1420 | responsibility to free this buffer.\r | |
1421 | @param BltX Specifies the offset from the left and top edge of\r | |
1422 | the output image of the first pixel in the image.\r | |
1423 | @param BltY Specifies the offset from the left and top edge of\r | |
1424 | the output image of the first pixel in the image.\r | |
1425 | \r | |
1426 | @retval EFI_SUCCESS The image was successfully drawn.\r | |
1427 | @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.\r | |
1428 | @retval EFI_INVALID_PARAMETER The Blt was NULL.\r | |
1429 | @retval EFI_NOT_FOUND The image specified by ImageId is not in the database.\r | |
1430 | The specified PackageList is not in the database.\r | |
1431 | \r | |
1432 | **/\r | |
1433 | EFI_STATUS\r | |
1434 | EFIAPI\r | |
1435 | HiiDrawImageId (\r | |
1436 | IN CONST EFI_HII_IMAGE_PROTOCOL *This,\r | |
1437 | IN EFI_HII_DRAW_FLAGS Flags,\r | |
1438 | IN EFI_HII_HANDLE PackageList,\r | |
1439 | IN EFI_IMAGE_ID ImageId,\r | |
1440 | IN OUT EFI_IMAGE_OUTPUT **Blt,\r | |
1441 | IN UINTN BltX,\r | |
1442 | IN UINTN BltY\r | |
1443 | )\r | |
1444 | {\r | |
1445 | EFI_STATUS Status;\r | |
1446 | EFI_IMAGE_INPUT Image;\r | |
1447 | \r | |
1448 | //\r | |
1449 | // Check input parameter.\r | |
1450 | //\r | |
1451 | if (This == NULL || Blt == NULL) {\r | |
1452 | return EFI_INVALID_PARAMETER;\r | |
1453 | }\r | |
1454 | \r | |
1455 | //\r | |
1456 | // Get the specified Image.\r | |
1457 | //\r | |
1458 | Status = HiiGetImage (This, PackageList, ImageId, &Image);\r | |
1459 | if (EFI_ERROR (Status)) {\r | |
1460 | return Status;\r | |
1461 | }\r | |
1462 | \r | |
1463 | //\r | |
1464 | // Draw this image.\r | |
1465 | //\r | |
1466 | Status = HiiDrawImage (This, Flags, &Image, Blt, BltX, BltY);\r | |
1467 | if (Image.Bitmap != NULL) {\r | |
1468 | FreePool (Image.Bitmap);\r | |
1469 | }\r | |
1470 | return Status;\r | |
1471 | }\r | |
1472 | \r |