diff options
author | Joursoir <chat@joursoir.net> | 2022-05-03 22:32:18 +0300 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2022-05-03 22:40:32 +0300 |
commit | b64358b2306e1599f240a749dc0c5cc96694e25b (patch) | |
tree | 2f2ca45f5692bfbeeeea61eb0eec55d9b3a72e61 | |
parent | f7cabfc989d37d595f7d809090b51b7616c590e3 (diff) | |
download | umt-b64358b2306e1599f240a749dc0c5cc96694e25b.tar.gz umt-b64358b2306e1599f240a749dc0c5cc96694e25b.tar.bz2 umt-b64358b2306e1599f240a749dc0c5cc96694e25b.zip |
graphics: improve interaction with icolor and ucolor
-rw-r--r-- | UefiMonitorTest/Graphics.c | 53 | ||||
-rw-r--r-- | 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 }; @@ -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]) { 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 <Protocol/SimpleTextIn.h> #include <Protocol/SimplePointer.h> +#define GET_UCOLOR(Color) (*(UINT32 *)Color) + #define PUT_PUXEL(Graphics, X, Y, Icolor) \ Graphics->BackBuffer[X + (Y * Graphics->Pitch)] = Icolor @@ -113,6 +115,22 @@ 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 + ); + +/** Draw a line using Bresenham's algorithm @retval VOID |