From b64358b2306e1599f240a749dc0c5cc96694e25b Mon Sep 17 00:00:00 2001 From: Joursoir Date: Tue, 3 May 2022 22:32:18 +0300 Subject: graphics: improve interaction with icolor and ucolor --- UefiMonitorTest/Graphics.c | 53 +++++++++++++++++++++++++++------------------- UefiMonitorTest/Graphics.h | 18 ++++++++++++++++ 2 files changed, 49 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 }; @@ -232,6 +222,33 @@ ForgetGraphicsInfo ( FreePool (Graphics->BackBuffer); } +/** + 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 @@ -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]) { diff --git a/UefiMonitorTest/Graphics.h b/UefiMonitorTest/Graphics.h index d822e0e..37484b0 100644 --- a/UefiMonitorTest/Graphics.h +++ b/UefiMonitorTest/Graphics.h @@ -7,6 +7,8 @@ #include #include +#define GET_UCOLOR(Color) (*(UINT32 *)Color) + #define PUT_PUXEL(Graphics, X, Y, Icolor) \ Graphics->BackBuffer[X + (Y * Graphics->Pitch)] = Icolor @@ -112,6 +114,22 @@ ForgetGraphicsInfo ( IN GRAPHICS_CONTEXT *Graphics ); +/** + 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 + ); + /** Draw a line using Bresenham's algorithm -- cgit v1.2.3-18-g5258