diff options
Diffstat (limited to 'UefiMonitorTest/Graphics.c')
-rw-r--r-- | UefiMonitorTest/Graphics.c | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/UefiMonitorTest/Graphics.c b/UefiMonitorTest/Graphics.c index e6dd6b6..756f085 100644 --- a/UefiMonitorTest/Graphics.c +++ b/UefiMonitorTest/Graphics.c @@ -16,16 +16,6 @@ A = B; \ B = C -#define GET_ICOLOR(Graphics, Ucolor) \ - (UINT32)( \ - (((Ucolor << Graphics->PixelShl[0]) >> Graphics->PixelShr[0]) & \ - Graphics->PixelMasks.RedMask) | \ - (((Ucolor << Graphics->PixelShl[1]) >> Graphics->PixelShr[1]) & \ - Graphics->PixelMasks.GreenMask) | \ - (((Ucolor << Graphics->PixelShl[2]) >> Graphics->PixelShr[2]) & \ - Graphics->PixelMasks.BlueMask) \ - ) - CONST EFI_PIXEL_BITMASK mRgbPixelMasks = { 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }; @@ -233,6 +223,33 @@ ForgetGraphicsInfo ( } /** + Get a color that doesn't depend on pixel format, i.e. + independent color. + + @param[in] Graphics A graphics context. + @param[in] Ucolor A GRAPHICS_PIXEL_COLOR, which is + represented as unsigned 32-bit. + + @retval UINT32 A color in independent format. +**/ +UINT32 +GetIcolor ( + IN GRAPHICS_CONTEXT *Graphics, + IN UINT32 Ucolor + ) +{ + return (UINT32)( + (((Ucolor << Graphics->PixelShl[0]) >> Graphics->PixelShr[0]) & + Graphics->PixelMasks.RedMask) | + (((Ucolor << Graphics->PixelShl[1]) >> Graphics->PixelShr[1]) & + Graphics->PixelMasks.GreenMask) | + (((Ucolor << Graphics->PixelShl[2]) >> Graphics->PixelShr[2]) & + Graphics->PixelMasks.BlueMask) + ); +} + + +/** Draw a line using Bresenham's algorithm @retval VOID @@ -255,7 +272,6 @@ DrawLine ( INT8 Direction; UINTN X, Y, Z; BOOLEAN Reverse; - UINT32 Ucolor; UINT32 Icolor; ASSERT (X0 >= 0 && X0 < Graphics->Width); @@ -285,8 +301,7 @@ DrawLine ( AbsDeltaY = ABS (DeltaY) * 2; Correction = 0; Direction = (Y1 > Y0) ? 1 : -1; - Ucolor = *(UINT32 *)Color; - Icolor = GET_ICOLOR (Graphics, Ucolor); + Icolor = GetIcolor (Graphics, GET_UCOLOR (Color)); Y = Y0; for (X = X0; X <= X1; X++) { @@ -315,7 +330,6 @@ PutRect ( ) { UINT32 *Buffer; - UINT32 Ucolor; UINT32 Icolor; UINT32 I, J; @@ -325,8 +339,7 @@ PutRect ( ASSERT (Y1 >= 0 && Y1 <= Graphics->Height && Y1 >= Y0); Buffer = Graphics->BackBuffer + Y0 * Graphics->Pitch; - Ucolor = *(UINT32 *)Color; - Icolor = GET_ICOLOR(Graphics, Ucolor); + Icolor = GetIcolor (Graphics, GET_UCOLOR (Color)); for (J = Y0; J < Y1; J++) { for (I = X0; I < X1; I++) { @@ -396,7 +409,6 @@ DrawCircle ( ) { UINT32 *Buffer; - UINT32 Ucolor; UINT32 Icolor; UINT32 I, J; @@ -406,8 +418,7 @@ DrawCircle ( ASSERT ((X0 + R) < Graphics->Width && X0 >= R); ASSERT ((Y0 + R) < Graphics->Height && Y0 >= R); - Ucolor = *(UINT32 *)Color; - Icolor = GET_ICOLOR(Graphics, Ucolor); + Icolor = GetIcolor (Graphics, GET_UCOLOR (Color)); Buffer = Graphics->BackBuffer + (Y0 - R) * Graphics->Pitch; for (J = (Y0 - R); J <= (Y0 + R); J++) { @@ -486,7 +497,6 @@ DrawStringVF ( UINTN Length; UINTN Index; UINTN OldX; - UINT32 Ucolor; UINT32 Icolor; ASSERT(FormatString != NULL); @@ -499,8 +509,7 @@ DrawStringVF ( Length = UnicodeVSPrint(FormatWalker, WalkerSize, FormatString, Marker); Index = 0; OldX = X; - Ucolor = *(UINT32 *)Color; - Icolor = GET_ICOLOR (Graphics, Ucolor); + Icolor = GetIcolor (Graphics, GET_UCOLOR (Color)); while (FormatWalker[Index] != '\0' && Index < Length) { switch (FormatWalker[Index]) { |