diff --git a/Library/OcBlitLib/BlitBufferToVideo.c b/Library/OcBlitLib/BlitBufferToVideo.c index 46fcf7b0..0aceb061 100644 --- a/Library/OcBlitLib/BlitBufferToVideo.c +++ b/Library/OcBlitLib/BlitBufferToVideo.c @@ -202,7 +202,6 @@ BlitLibBufferToVideo180 ( Destination -= PixelsPerScanLine; Height--; } - return EFI_UNSUPPORTED; } return EFI_SUCCESS; diff --git a/Library/OcBlitLib/BlitInternal.h b/Library/OcBlitLib/BlitInternal.h index aee9b770..fe674294 100644 --- a/Library/OcBlitLib/BlitInternal.h +++ b/Library/OcBlitLib/BlitInternal.h @@ -136,4 +136,128 @@ BlitLibBufferToVideo270 ( IN UINTN DeltaPixels ); +/** + Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation + with extended parameters at 0 degree rotation. + + @param[in] Configure Pointer to a configuration which was successfully + created by FrameBufferBltConfigure (). + @param[out] BltBuffer Output buffer for pixel color data. + @param[in] SourceX X location within video. + @param[in] SourceY Y location within video. + @param[in] DestinationX X location within BltBuffer. + @param[in] DestinationY Y location within BltBuffer. + @param[in] Width Width (in pixels). + @param[in] Height Height. + @param[in] DeltaPixels Number of pixels in a row of BltBuffer. + + @retval RETURN_INVALID_PARAMETER Invalid parameter were passed in. + @retval RETURN_SUCCESS The Blt operation was performed successfully. +**/ +RETURN_STATUS +BlitLibVideoToBuffer0 ( + IN OC_BLIT_CONFIGURE *Configure, + OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN DeltaPixels + ); + +/** + Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation + with extended parameters at 90 degree rotation. + + @param[in] Configure Pointer to a configuration which was successfully + created by FrameBufferBltConfigure (). + @param[out] BltBuffer Output buffer for pixel color data. + @param[in] SourceX X location within video. + @param[in] SourceY Y location within video. + @param[in] DestinationX X location within BltBuffer. + @param[in] DestinationY Y location within BltBuffer. + @param[in] Width Width (in pixels). + @param[in] Height Height. + @param[in] DeltaPixels Number of pixels in a row of BltBuffer. + + @retval RETURN_INVALID_PARAMETER Invalid parameter were passed in. + @retval RETURN_SUCCESS The Blt operation was performed successfully. +**/ +RETURN_STATUS +BlitLibVideoToBuffer90 ( + IN OC_BLIT_CONFIGURE *Configure, + OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN DeltaPixels + ); + +/** + Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation + with extended parameters at 180 degree rotation. + + @param[in] Configure Pointer to a configuration which was successfully + created by FrameBufferBltConfigure (). + @param[out] BltBuffer Output buffer for pixel color data. + @param[in] SourceX X location within video. + @param[in] SourceY Y location within video. + @param[in] DestinationX X location within BltBuffer. + @param[in] DestinationY Y location within BltBuffer. + @param[in] Width Width (in pixels). + @param[in] Height Height. + @param[in] DeltaPixels Number of pixels in a row of BltBuffer. + + @retval RETURN_INVALID_PARAMETER Invalid parameter were passed in. + @retval RETURN_SUCCESS The Blt operation was performed successfully. +**/ +RETURN_STATUS +BlitLibVideoToBuffer180 ( + IN OC_BLIT_CONFIGURE *Configure, + OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN DeltaPixels + ); + +/** + Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation + with extended parameters at 270 degree rotation. + + @param[in] Configure Pointer to a configuration which was successfully + created by FrameBufferBltConfigure (). + @param[out] BltBuffer Output buffer for pixel color data. + @param[in] SourceX X location within video. + @param[in] SourceY Y location within video. + @param[in] DestinationX X location within BltBuffer. + @param[in] DestinationY Y location within BltBuffer. + @param[in] Width Width (in pixels). + @param[in] Height Height. + @param[in] DeltaPixels Number of pixels in a row of BltBuffer. + + @retval RETURN_INVALID_PARAMETER Invalid parameter were passed in. + @retval RETURN_SUCCESS The Blt operation was performed successfully. +**/ +RETURN_STATUS +BlitLibVideoToBuffer270 ( + IN OC_BLIT_CONFIGURE *Configure, + OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN DeltaPixels + ); + #endif // BLIT_INTERNAL_H diff --git a/Library/OcBlitLib/BlitVideoToBuffer.c b/Library/OcBlitLib/BlitVideoToBuffer.c new file mode 100644 index 00000000..be16449f --- /dev/null +++ b/Library/OcBlitLib/BlitVideoToBuffer.c @@ -0,0 +1,176 @@ +/** @file + OcBlitLib - Library to perform blt operations on a frame buffer. + + Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2021, vit9696. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "BlitInternal.h" + +#include +#include +#include + +RETURN_STATUS +BlitLibVideoToBuffer0 ( + IN OC_BLIT_CONFIGURE *Configure, + OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN DeltaPixels + ) +{ + UINT32 *Source; + UINT32 *Destination; + UINT32 *SourceWalker; + UINT32 *DestinationWalker; + UINTN IndexX; + UINTN WidthInBytes; + UINTN PixelsPerScanLine; + UINT32 Uint32; + + WidthInBytes = Width * BYTES_PER_PIXEL; + PixelsPerScanLine = Configure->PixelsPerScanLine; + + Destination = (UINT32 *) BltBuffer + + DestinationY * DeltaPixels + DestinationX; + Source = (UINT32 *) Configure->FrameBuffer + + SourceY * PixelsPerScanLine + SourceX; + if (Configure->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) { + while (Height > 0) { + CopyMem (Destination, Source, WidthInBytes); + Source += PixelsPerScanLine; + Destination += DeltaPixels; + Height--; + } + } else { + while (Height > 0) { + DestinationWalker = (UINT32 *) Configure->LineBuffer; + SourceWalker = (UINT32 *) Source; + for (IndexX = 0; IndexX < Width; IndexX++) { + Uint32 = *SourceWalker++; + *DestinationWalker++ = + (UINT32) ( + (((Uint32 << Configure->PixelShl[0]) >> Configure->PixelShr[0]) & + Configure->PixelMasks.RedMask) | + (((Uint32 << Configure->PixelShl[1]) >> Configure->PixelShr[1]) & + Configure->PixelMasks.GreenMask) | + (((Uint32 << Configure->PixelShl[2]) >> Configure->PixelShr[2]) & + Configure->PixelMasks.BlueMask) + ); + } + + CopyMem (Destination, Configure->LineBuffer, WidthInBytes); + Source += PixelsPerScanLine; + Destination += DeltaPixels; + Height--; + } + } + + return EFI_SUCCESS; +} + +RETURN_STATUS +BlitLibVideoToBuffer90 ( + IN OC_BLIT_CONFIGURE *Configure, + OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN DeltaPixels + ) +{ + return EFI_UNSUPPORTED; +} + +RETURN_STATUS +BlitLibVideoToBuffer180 ( + IN OC_BLIT_CONFIGURE *Configure, + OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN DeltaPixels + ) +{ + UINT32 *Source; + UINT32 *Destination; + UINT32 *SourceWalker; + UINT32 *DestinationWalker; + UINTN IndexX; + UINTN PixelsPerScanLine; + UINT32 Uint32; + + PixelsPerScanLine = Configure->PixelsPerScanLine; + + SourceX = Configure->Width - SourceX - Width; + SourceY = Configure->Height - SourceY - Height; + + Destination = (UINT32 *) BltBuffer + + DestinationY * DeltaPixels + DestinationX; + Source = (UINT32 *) Configure->FrameBuffer + + (SourceY + (Height - 1)) * PixelsPerScanLine + SourceX; + + if (Configure->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) { + while (Height > 0) { + DestinationWalker = Destination; + SourceWalker = Source + (Width - 1); + for (IndexX = 0; IndexX < Width; IndexX++) { + *DestinationWalker++ = *SourceWalker--; + } + Source -= PixelsPerScanLine; + Destination += DeltaPixels; + Height--; + } + } else { + while (Height > 0) { + DestinationWalker = Destination; + SourceWalker = Source + (Width - 1); + for (IndexX = 0; IndexX < Width; IndexX++) { + Uint32 = *SourceWalker--; + *DestinationWalker++ = + (UINT32) ( + (((Uint32 << Configure->PixelShl[0]) >> Configure->PixelShr[0]) & + Configure->PixelMasks.RedMask) | + (((Uint32 << Configure->PixelShl[1]) >> Configure->PixelShr[1]) & + Configure->PixelMasks.GreenMask) | + (((Uint32 << Configure->PixelShl[2]) >> Configure->PixelShr[2]) & + Configure->PixelMasks.BlueMask) + ); + } + Source -= PixelsPerScanLine; + Destination += DeltaPixels; + Height--; + } + } + + return EFI_SUCCESS; +} + +RETURN_STATUS +BlitLibVideoToBuffer270 ( + IN OC_BLIT_CONFIGURE *Configure, + OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN DeltaPixels + ) +{ + return EFI_UNSUPPORTED; +} diff --git a/Library/OcBlitLib/OcBlitLib.c b/Library/OcBlitLib/OcBlitLib.c index 0697f501..a64915b9 100644 --- a/Library/OcBlitLib/OcBlitLib.c +++ b/Library/OcBlitLib/OcBlitLib.c @@ -292,23 +292,6 @@ BlitLibVideoToBuffer ( IN UINTN Delta ) { - UINTN DstY; - UINTN SrcY; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; - UINT8 *Source; - UINT8 *Destination; - UINTN IndexX; - UINT32 Uint32; - UINTN Offset; - UINTN WidthInBytes; - - // - // TODO: Implement. - // - if (Configure->Rotation != 0) { - return EFI_UNSUPPORTED; - } - // // Video to BltBuffer: Source is Video, destination is BltBuffer // @@ -330,47 +313,63 @@ BlitLibVideoToBuffer ( // pixels size, the number of bytes in each row can be computed. // if (Delta == 0) { - Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL); + Delta = Width; + } else { + Delta /= BYTES_PER_PIXEL; } - WidthInBytes = Width * BYTES_PER_PIXEL; - - // - // Video to BltBuffer: Source is Video, destination is BltBuffer - // - for (SrcY = SourceY, DstY = DestinationY; - DstY < (Height + DestinationY); - SrcY++, DstY++) { - - Offset = (SrcY * Configure->PixelsPerScanLine) + SourceX; - Offset = BYTES_PER_PIXEL * Offset; - Source = Configure->FrameBuffer + Offset; - - if (Configure->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) { - Destination = (UINT8 *) BltBuffer + (DstY * Delta) + (DestinationX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); - } else { - Destination = Configure->LineBuffer; - } - - CopyMem (Destination, Source, WidthInBytes); - - if (Configure->PixelFormat != PixelBlueGreenRedReserved8BitPerColor) { - for (IndexX = 0; IndexX < Width; IndexX++) { - Blt = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) - ((UINT8 *) BltBuffer + (DstY * Delta) + - (DestinationX + IndexX) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); - Uint32 = *(UINT32*) (Configure->LineBuffer + (IndexX * BYTES_PER_PIXEL)); - *(UINT32*) Blt = - (UINT32) ( - (((Uint32 & Configure->PixelMasks.RedMask) >> - Configure->PixelShl[0]) << Configure->PixelShr[0]) | - (((Uint32 & Configure->PixelMasks.GreenMask) >> - Configure->PixelShl[1]) << Configure->PixelShr[1]) | - (((Uint32 & Configure->PixelMasks.BlueMask) >> - Configure->PixelShl[2]) << Configure->PixelShr[2]) - ); - } - } + switch (Configure->Rotation) { + case 0: + return BlitLibVideoToBuffer0 ( + Configure, + BltBuffer, + SourceX, + SourceY, + DestinationX, + DestinationY, + Width, + Height, + Delta + ); + case 90: + return BlitLibVideoToBuffer90 ( + Configure, + BltBuffer, + SourceX, + SourceY, + DestinationX, + DestinationY, + Width, + Height, + Delta + ); + case 180: + return BlitLibVideoToBuffer180 ( + Configure, + BltBuffer, + SourceX, + SourceY, + DestinationX, + DestinationY, + Width, + Height, + Delta + ); + case 270: + return BlitLibVideoToBuffer270 ( + Configure, + BltBuffer, + SourceX, + SourceY, + DestinationX, + DestinationY, + Width, + Height, + Delta + ); + default: + ASSERT (FALSE); + break; } return RETURN_SUCCESS; diff --git a/Library/OcBlitLib/OcBlitLib.inf b/Library/OcBlitLib/OcBlitLib.inf index 7d19524d..31f98f7e 100644 --- a/Library/OcBlitLib/OcBlitLib.inf +++ b/Library/OcBlitLib/OcBlitLib.inf @@ -18,6 +18,7 @@ [Sources.common] BlitBufferToVideo.c BlitInternal.h + BlitVideoToBuffer.c OcBlitLib.c [LibraryClasses]