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