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