created XImage::Compose

Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
Sergey Isakov 2020-02-25 23:19:39 +03:00
parent 282bc531d7
commit a0b40c06dc
3 changed files with 84 additions and 55 deletions

View File

@ -26,51 +26,75 @@ EFI_GRAPHICS_OUTPUT_BLT_PIXEL* XImage::GetData()
return PixelData; return PixelData;
} }
UINTN XImage::GetWidth() UINTN XImage::GetWidth()
{ {
return Width; return Width;
}
UINTN XImage::GetHeight()
{
return Height;
} }
size_t XImage::GetSize() UINTN XImage::GetHeight()
{
return Height;
}
UINTN XImage::GetSize()
{ {
return Width * Height * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL); return Width * Height * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
} }
void XImage::Fill(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color) void XImage::Fill(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color)
{ {
for (int i = 0; i < Height; ++i) for (UINTN i = 0; i < Height; ++i)
for (int j = 0; j < Width; ++j) for (UINTN j = 0; j < Width; ++j)
*PixelData++ = Color; *PixelData++ = Color;
} }
void XImage::FillArea(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color, const EgRect& Rect) void XImage::FillArea(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color, const EgRect& Rect)
{ {
for (int y = Rect.Ypos; y < Rect.Height && y < Height; ++y) { for (UINTN y = Rect.Ypos; y < Rect.Height && y < Height; ++y) {
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* Ptr = PixelData + y * Width + Rect.Xpos; EFI_GRAPHICS_OUTPUT_BLT_PIXEL* Ptr = PixelData + y * Width + Rect.Xpos;
for (int x = Rect.Xpos; x < Rect.Width && x < Width; ++x) for (UINTN x = Rect.Xpos; x < Rect.Width && x < Width; ++x)
*PixelData++ = Color; *Ptr++ = Color;
} }
} }
void XImage::Compose(XImage& LowImage, XImage& TopImage, int PosX, int PosY, bool Lowest) //lowest image is opaque void XImage::Compose(int PosX, int PosY, XImage& TopImage, bool Lowest) //lowest image is opaque
{ {
UINT32 TopAlpha; UINT32 TopAlpha;
UINT32 RevAlpha; UINT32 RevAlpha;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *TopPtr, *CompPtr; UINT32 FinalAlpha;
UINT32 Temp;
for (int y = PosY; y < LowImage.GetHeight() && (y - PosY) < TopImage.GetHeight(); y++) { EFI_GRAPHICS_OUTPUT_BLT_PIXEL *TopPtr, *CompPtr;
TopPtr = TopImage.GetData();
CompPtr = LowImage.GetData() + y * LowImage.GetWidth() + PosX; for (UINTN y = PosY; y < Height && (y - PosY) < TopImage.GetHeight(); y++) {
for (int x = PosX; x < LowImage.GetWidth() && (x - PosX) < TopImage.GetWidth(); x++) { TopPtr = TopImage.GetData();
TopAlpha = TopPtr->Reserved; CompPtr = PixelData + y * Width + PosX;
RevAlpha = 255 - TopAlpha; for (UINTN x = PosX; x < Width && (x - PosX) < TopImage.GetWidth(); x++) {
TopAlpha = TopPtr->Reserved;
RevAlpha = 255 - TopAlpha;
FinalAlpha = (255*255 - RevAlpha*(255 - CompPtr->Reserved)) / 255;
//final alpha =(1-(1-x)*(1-y)) =(255*255-(255-topA)*(255-compA))/255
Temp = ((UINT8)CompPtr->Blue * RevAlpha) + ((UINT8)TopPtr->Blue * TopAlpha);
CompPtr->Blue = (UINT8)(Temp / 255);
Temp = ((UINT8)CompPtr->Green * RevAlpha) + ((UINT8)TopPtr->Green * TopAlpha);
CompPtr->Green = (UINT8)(Temp / 255);
Temp = ((UINT8)CompPtr->Red * RevAlpha) + ((UINT8)TopPtr->Red * TopAlpha);
CompPtr->Red = (UINT8)(Temp / 255);
if (Lowest) {
CompPtr->Reserved = (UINT8)(255);
} else {
CompPtr->Reserved = (UINT8)FinalAlpha;
}
TopPtr++, CompPtr++;
} }
} }
} }

View File

@ -1,7 +1,7 @@
/* /*
This class will replace EG_IMAGE structure and methods This class will replace EG_IMAGE structure and methods
*/ */
#if !defined(__XSTRINGW_H__) #if !defined(__XSTRINGW_H__)
#define __XSTRINGW_H__ #define __XSTRINGW_H__
@ -23,35 +23,38 @@ typedef union {
*/ */
typedef struct { typedef struct {
int Xpos; UINTN Xpos;
int Ypos; UINTN Ypos;
int Width; UINTN Width;
int Height; UINTN Height;
} EgRect; } EgRect;
class XImage class XImage
{ {
protected: protected:
UINTN Width; UINTN Width;
UINTN Height; UINTN Height;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *PixelData; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *PixelData;
bool HasAlpha; bool HasAlpha;
public: public:
XImage(); XImage();
XImage(UINTN W, UINTN H, bool HasAlpha); XImage(UINTN W, UINTN H, bool HasAlpha);
// XImage(UINTN W, UINTN H, bool HasAlpha, UINT32 Color); //egCreateFilledImage // XImage(UINTN W, UINTN H, bool HasAlpha, UINT32 Color); //egCreateFilledImage
// XImage(VOID *Data); // XImage(VOID *Data);
~XImage(); ~XImage();
public: protected:
size_t GetSize(); //in bytes UINTN GetSize(); //in bytes
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetData();
public:
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetData();
UINTN GetWidth(); UINTN GetWidth();
UINTN GetHeight(); UINTN GetHeight();
void Fill(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color = { 0, 0, 0, 0 }); void Fill(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color = { 0, 0, 0, 0 });
void FillArea(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color, const EgRect& Rect); void FillArea(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color, const EgRect& Rect);
void Compose(XImage& LowImage, XImage& TopImage, int PosX, int PosY, bool Lowest); void Compose(int PosX, int PosY, XImage& TopImage, bool Lowest);
}; };
#endif //__XSTRINGW_H__ #endif //__XSTRINGW_H__

View File

@ -81,6 +81,8 @@
libeg/VectorGraphics.cpp libeg/VectorGraphics.cpp
libeg/libeg.h libeg/libeg.h
libeg/libegint.h libeg/libegint.h
libeg/XImage.cpp
libeg/XImage.h
Platform/AcpiPatcher.cpp Platform/AcpiPatcher.cpp
Platform/ati_reg.h Platform/ati_reg.h
Platform/AmlGenerator.cpp Platform/AmlGenerator.cpp