preliminary introduce image class

Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
Sergey Isakov 2020-02-25 16:55:39 +03:00
parent 0155a4bf8a
commit a4952d32de
4 changed files with 145 additions and 10 deletions

View File

@ -20,7 +20,9 @@ void* operator new (unsigned long count)
return ptr;
}
#ifdef _MSC_VER
#pragma warning(disable : 4577)
#endif
void operator delete ( void* ptr ) noexcept
{
return FreePool(ptr);

View File

@ -0,0 +1,76 @@
#include "XImage.h"
XImage::XImage()
{
Width = 0;
Height = 0;
PixelData = nullptr;
HasAlpha = true;
}
XImage::XImage(UINTN W, UINTN H, bool A)
{
Width = W;
Height = H;
HasAlpha = A;
PixelData = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL*)Xalloc(GetSize());
}
XImage::~XImage()
{
Xfree(PixelData);
}
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* XImage::GetData()
{
return PixelData;
}
UINTN XImage::GetWidth()
{
return Width;
}
UINTN XImage::GetHeight()
{
return Height;
}
size_t XImage::GetSize()
{
return Width * Height * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
}
void XImage::Fill(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color)
{
for (int i = 0; i < Height; ++i)
for (int j = 0; j < Width; ++j)
*PixelData++ = Color;
}
void XImage::FillArea(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color, const EgRect& Rect)
{
for (int y = Rect.Ypos; y < Rect.Height && y < Height; ++y) {
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* Ptr = PixelData + y * Width + Rect.Xpos;
for (int x = Rect.Xpos; x < Rect.Width && x < Width; ++x)
*PixelData++ = Color;
}
}
void XImage::Compose(XImage& LowImage, XImage& TopImage, int PosX, int PosY, bool Lowest) //lowest image is opaque
{
UINT32 TopAlpha;
UINT32 RevAlpha;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *TopPtr, *CompPtr;
for (int y = PosY; y < LowImage.GetHeight() && (y - PosY) < TopImage.GetHeight(); y++) {
TopPtr = TopImage.GetData();
CompPtr = LowImage.GetData() + y * LowImage.GetWidth() + PosX;
for (int x = PosX; x < LowImage.GetWidth() && (x - PosX) < TopImage.GetWidth(); x++) {
TopAlpha = TopPtr->Reserved;
RevAlpha = 255 - TopAlpha;
}
}
}

57
rEFIt_UEFI/libeg/XImage.h Normal file
View File

@ -0,0 +1,57 @@
/*
This class will replace EG_IMAGE structure and methods
*/
#if !defined(__XSTRINGW_H__)
#define __XSTRINGW_H__
#include "XToolsCommon.h"
#include <Platform.h>
/*
typedef struct {
UINT8 Blue;
UINT8 Green;
UINT8 Red;
UINT8 Reserved; //this is Alpha. 0 means full transparent, 0xFF means opaque
} EFI_GRAPHICS_OUTPUT_BLT_PIXEL;
typedef union {
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Pixel;
UINT32 Raw;
} EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION;
*/
typedef struct {
int Xpos;
int Ypos;
int Width;
int Height;
} EgRect;
class XImage
{
protected:
UINTN Width;
UINTN Height;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *PixelData;
bool HasAlpha;
public:
XImage();
XImage(UINTN W, UINTN H, bool HasAlpha);
// XImage(UINTN W, UINTN H, bool HasAlpha, UINT32 Color); //egCreateFilledImage
// XImage(VOID *Data);
~XImage();
public:
size_t GetSize(); //in bytes
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetData();
UINTN GetWidth();
UINTN GetHeight();
void Fill(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color = { 0, 0, 0, 0 });
void FillArea(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color, const EgRect& Rect);
void Compose(XImage& LowImage, XImage& TopImage, int PosX, int PosY, bool Lowest);
};
#endif //__XSTRINGW_H__