From 507d749384846c2302c4749729ad2cc156d8cc12 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Sun, 27 Mar 2022 10:14:27 +0300 Subject: main: make ParseGraphicsPixelFormat() --- UefiMonitorTest/UefiMonitorTest.c | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'UefiMonitorTest') diff --git a/UefiMonitorTest/UefiMonitorTest.c b/UefiMonitorTest/UefiMonitorTest.c index 084a8b9..f84c00a 100644 --- a/UefiMonitorTest/UefiMonitorTest.c +++ b/UefiMonitorTest/UefiMonitorTest.c @@ -20,6 +20,51 @@ CONST EFI_PIXEL_BITMASK mBgrPixelMasks = { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }; +STATIC +VOID +ParseGraphicsPixelFormat ( + IN CONST EFI_PIXEL_BITMASK *BitMask, + OUT UINT32 *PixelWidth, + OUT INT8 *PixelShl, + OUT INT8 *PixelShr + ) +{ + UINT8 Index; + UINT32 *Masks; + UINT32 MergedMasks; + + MergedMasks = 0; + Masks = (UINT32 *)BitMask; + for (Index = 0; Index < 3; Index++) { + ASSERT ((MergedMasks & Masks[Index]) == 0); + + PixelShl[Index] = (INT8)HighBitSet32 (Masks[Index]) - 23 + (Index * 8); + if (PixelShl[Index] < 0) { + PixelShr[Index] = -PixelShl[Index]; + PixelShl[Index] = 0; + } else { + PixelShr[Index] = 0; + } + + DEBUG (( + DEBUG_INFO, + "Index %d: shl:%d shr:%d mask:%08x\n", + Index, + PixelShl[Index], + PixelShr[Index], + Masks[Index] + )); + + MergedMasks = (UINT32)(MergedMasks | Masks[Index]); + } + + MergedMasks = (UINT32)(MergedMasks | Masks[3]); + + ASSERT (MergedMasks != 0); + *PixelWidth = (UINT32)((HighBitSet32 (MergedMasks) + 7) / 8); + DEBUG ((DEBUG_INFO, "Bytes per pixel: %d\n", *PixelWidth)); +} + STATIC VOID PrepareGraphicsInfo ( -- cgit v1.2.3-18-g5258