mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-23 11:35:19 +01:00
Refactor of XImage to use XArray and create accessor for pixel.
This commit is contained in:
parent
9ac41a3c9d
commit
8727ae6f54
@ -4,7 +4,6 @@ XImage::XImage()
|
||||
{
|
||||
Width = 0;
|
||||
Height = 0;
|
||||
PixelData = nullptr;
|
||||
HasAlpha = true;
|
||||
}
|
||||
|
||||
@ -13,19 +12,29 @@ XImage::XImage(UINTN W, UINTN H, bool A)
|
||||
Width = W;
|
||||
Height = H;
|
||||
HasAlpha = A;
|
||||
PixelData = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL*)Xalloc(GetSize());
|
||||
PixelData.CheckSize(GetWidth()*GetHeight());
|
||||
}
|
||||
|
||||
XImage::~XImage()
|
||||
{
|
||||
Xfree(PixelData);
|
||||
}
|
||||
|
||||
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL* XImage::GetData() const
|
||||
const XArray<EFI_GRAPHICS_OUTPUT_BLT_PIXEL>& XImage::GetData() const
|
||||
{
|
||||
return PixelData;
|
||||
}
|
||||
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* XImage::GetPixelPtr(UINTN x, UINTN y)
|
||||
{
|
||||
return &PixelData[x + y * Width];
|
||||
}
|
||||
|
||||
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& XImage::GetPixel(UINTN x, UINTN y) const
|
||||
{
|
||||
return PixelData[x + y * Width];
|
||||
}
|
||||
|
||||
|
||||
UINTN XImage::GetWidth() const
|
||||
{
|
||||
return Width;
|
||||
@ -45,7 +54,7 @@ void XImage::Fill(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color)
|
||||
{
|
||||
for (UINTN i = 0; i < Height; ++i)
|
||||
for (UINTN j = 0; j < Width; ++j)
|
||||
*PixelData++ = Color;
|
||||
PixelData[i*j] = Color;
|
||||
}
|
||||
|
||||
void XImage::FillArea(EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color, const EgRect& Rect)
|
||||
@ -65,35 +74,30 @@ void XImage::Compose(int PosX, int PosY, const XImage& TopImage, bool Lowest) //
|
||||
UINT32 RevAlpha;
|
||||
UINT32 FinalAlpha;
|
||||
UINT32 Temp;
|
||||
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL *TopPtr;
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *CompPtr;
|
||||
|
||||
for (UINTN y = PosY; y < Height && (y - PosY) < TopImage.GetHeight(); y++) {
|
||||
TopPtr = TopImage.GetData();
|
||||
CompPtr = PixelData + y * Width + PosX;
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL& CompPtr = *GetPixelPtr(PosX, y); // I assign a ref to avoid the operator ->. Compiler will produce the same anyway.
|
||||
for (UINTN x = PosX; x < Width && (x - PosX) < TopImage.GetWidth(); x++) {
|
||||
TopAlpha = TopPtr->Reserved;
|
||||
TopAlpha = TopImage.GetPixel(x-PosX, y-PosY).Reserved;
|
||||
RevAlpha = 255 - TopAlpha;
|
||||
FinalAlpha = (255*255 - RevAlpha*(255 - CompPtr->Reserved)) / 255;
|
||||
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 = (CompPtr.Blue * RevAlpha) + (TopImage.GetPixel(x-PosX, y-PosY).Blue * TopAlpha);
|
||||
CompPtr.Blue = (UINT8)(Temp / 255);
|
||||
|
||||
Temp = ((UINT8)CompPtr->Green * RevAlpha) + ((UINT8)TopPtr->Green * TopAlpha);
|
||||
CompPtr->Green = (UINT8)(Temp / 255);
|
||||
Temp = (CompPtr.Green * RevAlpha) + (TopImage.GetPixel(x-PosX, y-PosY).Green * TopAlpha);
|
||||
CompPtr.Green = (UINT8)(Temp / 255);
|
||||
|
||||
Temp = ((UINT8)CompPtr->Red * RevAlpha) + ((UINT8)TopPtr->Red * TopAlpha);
|
||||
CompPtr->Red = (UINT8)(Temp / 255);
|
||||
Temp = (CompPtr.Red * RevAlpha) + (TopImage.GetPixel(x-PosX, y-PosY).Red * TopAlpha);
|
||||
CompPtr.Red = (UINT8)(Temp / 255);
|
||||
|
||||
if (Lowest) {
|
||||
CompPtr->Reserved = (UINT8)(255);
|
||||
CompPtr.Reserved = 255;
|
||||
} else {
|
||||
CompPtr->Reserved = (UINT8)FinalAlpha;
|
||||
CompPtr.Reserved = (UINT8)FinalAlpha;
|
||||
}
|
||||
|
||||
TopPtr++, CompPtr++;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ This class will replace EG_IMAGE structure and methods
|
||||
#define __XSTRINGW_H__
|
||||
|
||||
#include "../cpp_foundation/XToolsCommon.h"
|
||||
#include "../cpp_foundation/XArray.h"
|
||||
#include <Platform.h>
|
||||
|
||||
/*
|
||||
@ -34,7 +35,7 @@ class XImage
|
||||
protected:
|
||||
UINTN Width;
|
||||
UINTN Height;
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *PixelData;
|
||||
XArray<EFI_GRAPHICS_OUTPUT_BLT_PIXEL> PixelData;
|
||||
bool HasAlpha;
|
||||
public:
|
||||
XImage();
|
||||
@ -48,7 +49,10 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetData() const;
|
||||
const XArray<EFI_GRAPHICS_OUTPUT_BLT_PIXEL>& GetData() const;
|
||||
|
||||
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& GetPixel(UINTN x, UINTN y) const;
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetPixelPtr(UINTN x, UINTN y);
|
||||
UINTN GetWidth() const;
|
||||
UINTN GetHeight() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user