X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FHiiDatabaseDxe%2FImage.c;h=8c74e8e424d2cf6572d0ffbd2c408157dfeec67c;hp=6b6a72002dc2e6b22a71bf7eb0ac987d5c4d91fc;hb=f324bf4dbeda4d64b769bd005331e8f9404b692d;hpb=813acf3a9a99e97ab200c7e222ee96810a9aa3fd diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c index 6b6a72002d..8c74e8e424 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c @@ -1,4 +1,6 @@ /** @file +Implementation for EFI_HII_IMAGE_PROTOCOL. + Copyright (c) 2007 - 2008, Intel Corporation All rights reserved. This program and the accompanying materials @@ -9,46 +11,31 @@ http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - Image.c - -Abstract: +**/ - Implementation for EFI_HII_IMAGE_PROTOCOL. -Revision History +#include "HiiDatabase.h" -**/ +/** + Get the imageid of last image block: EFI_HII_IIBT_END_BLOCK when input + ImageId is zero, otherwise return the address of the + corresponding image block with identifier specified by ImageId. + This is a internal function. -#include "HiiDatabase.h" + @param ImageBlock Points to the beginning of a series of image blocks stored in order. + @param ImageId If input ImageId is 0, output the image id of the EFI_HII_IIBT_END_BLOCK; + else use this id to find its corresponding image block address. -#ifndef DISABLE_UNUSED_HII_PROTOCOLS + @return The image block address when input ImageId is not zero; otherwise return NULL. -STATIC +**/ UINT8* GetImageIdOrAddress ( IN UINT8 *ImageBlock, IN OUT EFI_IMAGE_ID *ImageId ) -/*++ - - Routine Description: - Get the imageid of last image block: EFI_HII_IIBT_END_BLOCK when input - ImageId is zero, otherwise return the address of the - corresponding image block with identifier specified by ImageId. - - Arguments: - ImageBlock - Points to the beginning of a series of image blocks stored in order. - ImageId - If input ImageId is 0, output the image id of the EFI_HII_IIBT_END_BLOCK; - else use this id to find its corresponding image block address. - - Returns: - The image block address when input ImageId is not zero; otherwise return NULL. - ---*/ { EFI_IMAGE_ID ImageIdCurrent; UINT8 *ImageBlockHdr; @@ -199,13 +186,15 @@ GetImageIdOrAddress ( /** Convert pixels from EFI_GRAPHICS_OUTPUT_BLT_PIXEL to EFI_HII_RGB_PIXEL style. + This is a internal function. + + @param BitMapOut Pixels in EFI_HII_RGB_PIXEL format. @param BitMapIn Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format. @param PixelNum The number of pixels to be converted. **/ -STATIC VOID CopyGopToRgbPixel ( OUT EFI_HII_RGB_PIXEL *BitMapOut, @@ -226,13 +215,15 @@ CopyGopToRgbPixel ( /** Convert pixels from EFI_HII_RGB_PIXEL to EFI_GRAPHICS_OUTPUT_BLT_PIXEL style. + This is a internal function. + + @param BitMapOut Pixels in EFI_GRAPHICS_OUTPUT_BLT_PIXEL format. @param BitMapIn Pixels in EFI_HII_RGB_PIXEL format. @param PixelNum The number of pixels to be converted. **/ -STATIC VOID CopyRgbToGopPixel ( OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapOut, @@ -253,6 +244,9 @@ CopyRgbToGopPixel ( /** Output pixels in "1 bit per pixel" format to an image. + This is a internal function. + + @param Image Points to the image which will store the pixels. @param Data Stores the value of output pixels, 0 or 1. @param PaletteInfo PaletteInfo which stores the color of the output @@ -261,7 +255,6 @@ CopyRgbToGopPixel ( **/ -STATIC VOID Output1bitPixel ( IN OUT EFI_IMAGE_INPUT *Image, @@ -269,8 +262,8 @@ Output1bitPixel ( IN EFI_HII_IMAGE_PALETTE_INFO *PaletteInfo ) { - UINT16 X; - UINT16 Y; + UINT16 Xpos; + UINT16 Ypos; UINTN OffsetY; UINT8 Index; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapPtr; @@ -295,23 +288,23 @@ Output1bitPixel ( ZeroMem (PaletteValue, sizeof (PaletteValue)); CopyRgbToGopPixel (&PaletteValue[0], &Palette->PaletteValue[0], 1); CopyRgbToGopPixel (&PaletteValue[1], &Palette->PaletteValue[1], 1); - SafeFreePool (Palette); + FreePool (Palette); // // Convert the pixel from one bit to corresponding color. // - for (Y = 0; Y < Image->Height; Y++) { - OffsetY = BITMAP_LEN_1_BIT (Image->Width, Y); + for (Ypos = 0; Ypos < Image->Height; Ypos++) { + OffsetY = BITMAP_LEN_1_BIT (Image->Width, Ypos); // // All bits in these bytes are meaningful // - for (X = 0; X < Image->Width / 8; X++) { - Byte = *(Data + OffsetY + X); + for (Xpos = 0; Xpos < Image->Width / 8; Xpos++) { + Byte = *(Data + OffsetY + Xpos); for (Index = 0; Index < 8; Index++) { if ((Byte & (1 << Index)) != 0) { - BitMapPtr[Y * Image->Width + X * 8 + (8 - Index - 1)] = PaletteValue[1]; + BitMapPtr[Ypos * Image->Width + Xpos * 8 + (8 - Index - 1)] = PaletteValue[1]; } else { - BitMapPtr[Y * Image->Width + X * 8 + (8 - Index - 1)] = PaletteValue[0]; + BitMapPtr[Ypos * Image->Width + Xpos * 8 + (8 - Index - 1)] = PaletteValue[0]; } } } @@ -320,12 +313,12 @@ Output1bitPixel ( // // Padding bits in this byte should be ignored. // - Byte = *(Data + OffsetY + X); + Byte = *(Data + OffsetY + Xpos); for (Index = 0; Index < Image->Width % 8; Index++) { if ((Byte & (1 << (8 - Index - 1))) != 0) { - BitMapPtr[Y * Image->Width + X * 8 + Index] = PaletteValue[1]; + BitMapPtr[Ypos * Image->Width + Xpos * 8 + Index] = PaletteValue[1]; } else { - BitMapPtr[Y * Image->Width + X * 8 + Index] = PaletteValue[0]; + BitMapPtr[Ypos * Image->Width + Xpos * 8 + Index] = PaletteValue[0]; } } } @@ -336,15 +329,17 @@ Output1bitPixel ( /** Output pixels in "4 bit per pixel" format to an image. + This is a internal function. + + @param Image Points to the image which will store the pixels. @param Data Stores the value of output pixels, 0 ~ 15. - @param PaletteInfo PaletteInfo which stores the color of the output + @param[in] PaletteInfo PaletteInfo which stores the color of the output pixels. Each entry corresponds to a color within [0, 15]. **/ -STATIC VOID Output4bitPixel ( IN OUT EFI_IMAGE_INPUT *Image, @@ -352,8 +347,8 @@ Output4bitPixel ( IN EFI_HII_IMAGE_PALETTE_INFO *PaletteInfo ) { - UINT16 X; - UINT16 Y; + UINT16 Xpos; + UINT16 Ypos; UINTN OffsetY; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapPtr; EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue[16]; @@ -378,28 +373,28 @@ Output4bitPixel ( ZeroMem (PaletteValue, sizeof (PaletteValue)); CopyRgbToGopPixel (PaletteValue, Palette->PaletteValue, PaletteNum); - SafeFreePool (Palette); + FreePool (Palette); // // Convert the pixel from 4 bit to corresponding color. // - for (Y = 0; Y < Image->Height; Y++) { - OffsetY = BITMAP_LEN_4_BIT (Image->Width, Y); + for (Ypos = 0; Ypos < Image->Height; Ypos++) { + OffsetY = BITMAP_LEN_4_BIT (Image->Width, Ypos); // // All bits in these bytes are meaningful // - for (X = 0; X < Image->Width / 2; X++) { - Byte = *(Data + OffsetY + X); - BitMapPtr[Y * Image->Width + X * 2] = PaletteValue[Byte >> 4]; - BitMapPtr[Y * Image->Width + X * 2 + 1] = PaletteValue[Byte & 0x0F]; + for (Xpos = 0; Xpos < Image->Width / 2; Xpos++) { + Byte = *(Data + OffsetY + Xpos); + BitMapPtr[Ypos * Image->Width + Xpos * 2] = PaletteValue[Byte >> 4]; + BitMapPtr[Ypos * Image->Width + Xpos * 2 + 1] = PaletteValue[Byte & 0x0F]; } if (Image->Width % 2 != 0) { // // Padding bits in this byte should be ignored. // - Byte = *(Data + OffsetY + X); - BitMapPtr[Y * Image->Width + X * 2] = PaletteValue[Byte >> 4]; + Byte = *(Data + OffsetY + Xpos); + BitMapPtr[Ypos * Image->Width + Xpos * 2] = PaletteValue[Byte >> 4]; } } } @@ -408,15 +403,17 @@ Output4bitPixel ( /** Output pixels in "8 bit per pixel" format to an image. + This is a internal function. + + @param Image Points to the image which will store the pixels. @param Data Stores the value of output pixels, 0 ~ 255. - @param PaletteInfo PaletteInfo which stores the color of the output + @param[in] PaletteInfo PaletteInfo which stores the color of the output pixels. Each entry corresponds to a color within [0, 255]. **/ -STATIC VOID Output8bitPixel ( IN OUT EFI_IMAGE_INPUT *Image, @@ -424,8 +421,8 @@ Output8bitPixel ( IN EFI_HII_IMAGE_PALETTE_INFO *PaletteInfo ) { - UINT16 X; - UINT16 Y; + UINT16 Xpos; + UINT16 Ypos; UINTN OffsetY; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapPtr; EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue[256]; @@ -449,19 +446,19 @@ Output8bitPixel ( PaletteNum = (UINT16)(Palette->PaletteSize / sizeof (EFI_HII_RGB_PIXEL)); ZeroMem (PaletteValue, sizeof (PaletteValue)); CopyRgbToGopPixel (PaletteValue, Palette->PaletteValue, PaletteNum); - SafeFreePool (Palette); + FreePool (Palette); // // Convert the pixel from 8 bits to corresponding color. // - for (Y = 0; Y < Image->Height; Y++) { - OffsetY = BITMAP_LEN_8_BIT (Image->Width, Y); + for (Ypos = 0; Ypos < Image->Height; Ypos++) { + OffsetY = BITMAP_LEN_8_BIT (Image->Width, Ypos); // // All bits are meaningful since the bitmap is 8 bits per pixel. // - for (X = 0; X < Image->Width; X++) { - Byte = *(Data + OffsetY + X); - BitMapPtr[OffsetY + X] = PaletteValue[Byte]; + for (Xpos = 0; Xpos < Image->Width; Xpos++) { + Byte = *(Data + OffsetY + Xpos); + BitMapPtr[OffsetY + Xpos] = PaletteValue[Byte]; } } @@ -471,20 +468,22 @@ Output8bitPixel ( /** Output pixels in "24 bit per pixel" format to an image. + This is a internal function. + + @param Image Points to the image which will store the pixels. @param Data Stores the color of output pixels, allowing 16.8 millions colors. **/ -STATIC VOID Output24bitPixel ( IN OUT EFI_IMAGE_INPUT *Image, IN EFI_HII_RGB_PIXEL *Data ) { - UINT16 Y; + UINT16 Ypos; UINTN OffsetY; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapPtr; @@ -492,8 +491,8 @@ Output24bitPixel ( BitMapPtr = Image->Bitmap; - for (Y = 0; Y < Image->Height; Y++) { - OffsetY = BITMAP_LEN_8_BIT (Image->Width, Y); + for (Ypos = 0; Ypos < Image->Height; Ypos++) { + OffsetY = BITMAP_LEN_8_BIT (Image->Width, Ypos); CopyRgbToGopPixel (&BitMapPtr[OffsetY], &Data[OffsetY], Image->Width); } @@ -503,7 +502,12 @@ Output24bitPixel ( /** Convert the image from EFI_IMAGE_INPUT to EFI_IMAGE_OUTPUT format. + This is a internal function. + + @param BltBuffer Buffer points to bitmap data of incoming image. + @param BltX Specifies the offset from the left and top edge of + the output image of the first pixel in the image. @param BltY Specifies the offset from the left and top edge of the output image of the first pixel in the image. @param Width Width of the incoming image, in pixels. @@ -517,7 +521,6 @@ Output24bitPixel ( @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid. **/ -STATIC EFI_STATUS ImageToBlt ( IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, @@ -530,8 +533,8 @@ ImageToBlt ( ) { EFI_IMAGE_OUTPUT *ImageOut; - UINTN X; - UINTN Y; + UINTN Xpos; + UINTN Ypos; UINTN OffsetY1; // src buffer UINTN OffsetY2; // dest buffer EFI_GRAPHICS_OUTPUT_BLT_PIXEL SrcPixel; @@ -552,17 +555,17 @@ ImageToBlt ( ZeroMem (&ZeroPixel, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); - for (Y = 0; Y < Height; Y++) { - OffsetY1 = Width * Y; - OffsetY2 = ImageOut->Width * (BltY + Y); - for (X = 0; X < Width; X++) { - SrcPixel = BltBuffer[OffsetY1 + X]; + for (Ypos = 0; Ypos < Height; Ypos++) { + OffsetY1 = Width * Ypos; + OffsetY2 = ImageOut->Width * (BltY + Ypos); + for (Xpos = 0; Xpos < Width; Xpos++) { + SrcPixel = BltBuffer[OffsetY1 + Xpos]; if (Transparent) { if (CompareMem (&SrcPixel, &ZeroPixel, 3) != 0) { - ImageOut->Image.Bitmap[OffsetY2 + BltX + X] = SrcPixel; + ImageOut->Image.Bitmap[OffsetY2 + BltX + Xpos] = SrcPixel; } } else { - ImageOut->Image.Bitmap[OffsetY2 + BltX + X] = SrcPixel; + ImageOut->Image.Bitmap[OffsetY2 + BltX + Xpos] = SrcPixel; } } } @@ -676,7 +679,7 @@ HiiNewImage ( ImagePackage->ImageBlock, ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK) ); - SafeFreePool (ImagePackage->ImageBlock); + FreePool (ImagePackage->ImageBlock); ImagePackage->ImageBlock = ImageBlock; ImageBlock += ImagePackage->ImageBlockSize - sizeof (EFI_HII_IIBT_END_BLOCK); // @@ -684,8 +687,7 @@ HiiNewImage ( // NewBlock = AllocateZeroPool (NewBlockSize); if (NewBlock == NULL) { - SafeFreePool (ImagePackage->ImageBlock); - ImagePackage->ImageBlock = NULL; + FreePool (ImagePackage->ImageBlock); return EFI_OUT_OF_RESOURCES; } NewBlockPtr = NewBlock; @@ -732,7 +734,7 @@ HiiNewImage ( ImagePackage->ImageBlockSize = (UINT32) BlockSize; ImagePackage->ImageBlock = (UINT8 *) AllocateZeroPool (BlockSize); if (ImagePackage->ImageBlock == NULL) { - SafeFreePool (ImagePackage); + FreePool (ImagePackage); return EFI_OUT_OF_RESOURCES; } ImageBlock = ImagePackage->ImageBlock; @@ -742,8 +744,8 @@ HiiNewImage ( // NewBlock = AllocateZeroPool (NewBlockSize); if (NewBlock == NULL) { - SafeFreePool (ImagePackage->ImageBlock); - SafeFreePool (ImagePackage); + FreePool (ImagePackage->ImageBlock); + FreePool (ImagePackage); return EFI_OUT_OF_RESOURCES; } NewBlockPtr = NewBlock; @@ -771,7 +773,7 @@ HiiNewImage ( CopyGopToRgbPixel ((EFI_HII_RGB_PIXEL *) NewBlock, ImageIn->Bitmap, ImageIn->Width * ImageIn->Height); CopyMem (ImageBlock, NewBlockPtr, NewBlockSize); - SafeFreePool (NewBlockPtr); + FreePool (NewBlockPtr); // // Append the block end @@ -793,9 +795,6 @@ HiiNewImage ( @param ImageId The image's id,, which is unique within PackageList. @param Image Points to the image. - @param ImageSize On entry, points to the size of the buffer pointed - to by Image, in bytes. On return, points to the - length of the image, in bytes. @retval EFI_SUCCESS The new image was returned successfully. @retval EFI_NOT_FOUND The image specified by ImageId is not in the @@ -1156,7 +1155,7 @@ HiiSetImage ( BlockSize = ImagePackage->ImageBlockSize + NewBlockSize - OldBlockSize; Block = (UINT8 *) AllocateZeroPool (BlockSize); if (Block == NULL) { - SafeFreePool (NewBlock); + FreePool (NewBlock); return EFI_OUT_OF_RESOURCES; } @@ -1169,8 +1168,8 @@ HiiSetImage ( BlockPtr += NewBlockSize; CopyMem (BlockPtr, ImageBlock + OldBlockSize, Part2Size); - SafeFreePool (ImagePackage->ImageBlock); - SafeFreePool (NewBlock); + FreePool (ImagePackage->ImageBlock); + FreePool (NewBlock); ImagePackage->ImageBlock = Block; ImagePackage->ImageBlockSize = BlockSize; ImagePackage->ImagePkgHdr.Header.Length += NewBlockSize - OldBlockSize; @@ -1197,6 +1196,8 @@ HiiSetImage ( will be allocated to hold the generated image and the pointer updated on exit. It is the caller's responsibility to free this buffer. + @param BltX Specifies the offset from the left and top edge of + the output image of the first pixel in the image. @param BltY Specifies the offset from the left and top edge of the output image of the first pixel in the image. @@ -1226,13 +1227,12 @@ HiiDrawImage ( UINTN BufferLen; UINTN Width; UINTN Height; - UINTN X; - UINTN Y; + UINTN Xpos; + UINTN Ypos; UINTN OffsetY1; UINTN OffsetY2; EFI_FONT_DISPLAY_INFO *FontInfo; UINTN Index; - EFI_CONSOLE_CONTROL_PROTOCOL *Console; if (This == NULL || Image == NULL || Blt == NULL) { return EFI_INVALID_PARAMETER; @@ -1309,11 +1309,11 @@ HiiDrawImage ( if (Width == ImageIn->Width && Height == ImageIn->Height) { CopyMem (BltBuffer, ImageIn->Bitmap, BufferLen); } else { - for (Y = 0; Y < Height; Y++) { - OffsetY1 = ImageIn->Width * Y; - OffsetY2 = Width * Y; - for (X = 0; X < Width; X++) { - BltBuffer[OffsetY2 + X] = ImageIn->Bitmap[OffsetY1 + X]; + for (Ypos = 0; Ypos < Height; Ypos++) { + OffsetY1 = ImageIn->Width * Ypos; + OffsetY2 = Width * Ypos; + for (Xpos = 0; Xpos < Width; Xpos++) { + BltBuffer[OffsetY2 + Xpos] = ImageIn->Bitmap[OffsetY1 + Xpos]; } } } @@ -1322,17 +1322,10 @@ HiiDrawImage ( // Draw the image to existing bitmap or screen depending on flag. // if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) { - Status = gBS->LocateProtocol ( - &gEfiConsoleControlProtocolGuid, - NULL, - (VOID **) &Console - ); - - if (EFI_ERROR (Status)) { - return Status; - } + // + // Caller should make sure the current UGA console is grarphic mode. + // - Console->SetMode (Console, EfiConsoleControlScreenGraphics); // // Write the image directly to the output device specified by Screen. // @@ -1364,7 +1357,7 @@ HiiDrawImage ( } - SafeFreePool (BltBuffer); + FreePool (BltBuffer); return Status; } else { @@ -1382,7 +1375,7 @@ HiiDrawImage ( ImageOut = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT)); if (ImageOut == NULL) { - SafeFreePool (BltBuffer); + FreePool (BltBuffer); return EFI_OUT_OF_RESOURCES; } ImageOut->Width = (UINT16) Width; @@ -1395,14 +1388,14 @@ HiiDrawImage ( // Status = GetSystemFont (Private, &FontInfo, NULL); if (EFI_ERROR (Status)) { - SafeFreePool (BltBuffer); - SafeFreePool (ImageOut); + FreePool (BltBuffer); + FreePool (ImageOut); return Status; } for (Index = 0; Index < Width * Height; Index++) { BltBuffer[Index] = FontInfo->BackgroundColor; } - SafeFreePool (FontInfo); + FreePool (FontInfo); // // Draw the incoming image to the new created image. @@ -1442,6 +1435,8 @@ HiiDrawImage ( allocated to hold the generated image and the pointer updated on exit. It is the caller's responsibility to free this buffer. + @param BltX Specifies the offset from the left and top edge of + the output image of the first pixel in the image. @param BltY Specifies the offset from the left and top edge of the output image of the first pixel in the image. @@ -1490,9 +1485,9 @@ HiiDrawImageId ( // Draw this image. // Status = HiiDrawImage (This, Flags, &Image, Blt, BltX, BltY); - SafeFreePool (Image.Bitmap); + if (Image.Bitmap != NULL) { + FreePool (Image.Bitmap); + } return Status; } -#endif -