mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-27 12:15:19 +01:00
improve setSizeInPixels
Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
parent
ce86d7f6b8
commit
c64788a19e
@ -23,30 +23,30 @@ XImage::XImage()
|
|||||||
|
|
||||||
XImage::XImage(UINTN W, UINTN H)
|
XImage::XImage(UINTN W, UINTN H)
|
||||||
{
|
{
|
||||||
Width = W;
|
// Width = W;
|
||||||
Height = H;
|
// Height = H; //included below
|
||||||
setSizeInPixels(W, H);
|
setSizeInPixels(W, H);
|
||||||
}
|
}
|
||||||
|
|
||||||
XImage::XImage(EG_IMAGE* egImage)
|
XImage::XImage(EG_IMAGE* egImage)
|
||||||
{
|
{
|
||||||
if ( egImage) {
|
if ( egImage) {
|
||||||
Width = egImage->Width;
|
// Width = egImage->Width;
|
||||||
Height = egImage->Height;
|
// Height = egImage->Height;
|
||||||
setSizeInPixels(GetWidth(), GetHeight()); // change the size, ie the number of element in the array. Reaalocate buffer if needed
|
setSizeInPixels(egImage->Width, egImage->Height); // change the size, ie the number of element in the array. Reaalocate buffer if needed
|
||||||
CopyMem(&PixelData[0], egImage->PixelData, GetSizeInBytes());
|
CopyMem(&PixelData[0], egImage->PixelData, GetSizeInBytes());
|
||||||
}else{
|
}else{
|
||||||
Width = 0;
|
// Width = 0;
|
||||||
Height = 0;
|
// Height = 0;
|
||||||
setSizeInPixels(GetWidth(), GetHeight()); // change the size, ie the number of element in the array. Reaalocate buffer if needed
|
setSizeInPixels(0, 0); // change the size, ie the number of element in the array. Reallocate buffer if needed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XImage& XImage::operator= (const XImage& other)
|
XImage& XImage::operator= (const XImage& other)
|
||||||
{
|
{
|
||||||
Width = other.GetWidth();
|
// Width = other.GetWidth();
|
||||||
Height = other.GetHeight();
|
// Height = other.GetHeight();
|
||||||
setSizeInPixels(GetWidth(), GetHeight()); // change the size, ie the number of element in the array. Reaalocate buffer if needed
|
setSizeInPixels(other.GetWidth(), other.GetHeight()); // change the size, ie the number of element in the array. Reaalocate buffer if needed
|
||||||
CopyMem(&PixelData[0], &other.PixelData[0], GetSizeInBytes());
|
CopyMem(&PixelData[0], &other.PixelData[0], GetSizeInBytes());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -63,17 +63,17 @@ XImage::XImage(const XImage& Image, float scale)
|
|||||||
UINTN SrcHeight = Image.GetHeight();
|
UINTN SrcHeight = Image.GetHeight();
|
||||||
|
|
||||||
if (scale < 1.e-4) {
|
if (scale < 1.e-4) {
|
||||||
Width = SrcWidth;
|
// Width = SrcWidth;
|
||||||
Height = SrcHeight;
|
// Height = SrcHeight;
|
||||||
setSizeInPixels(GetWidth(), GetHeight());
|
setSizeInPixels(SrcWidth, SrcHeight);
|
||||||
for (UINTN y = 0; y < Height; ++y)
|
for (UINTN y = 0; y < Height; ++y)
|
||||||
for (UINTN x = 0; x < Width; ++x)
|
for (UINTN x = 0; x < Width; ++x)
|
||||||
PixelData[y * Width + x] = Image.GetPixel(x, y);
|
PixelData[y * Width + x] = Image.GetPixel(x, y);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Width = (UINTN)(SrcWidth * scale);
|
// Width = (UINTN)(SrcWidth * scale);
|
||||||
Height = (UINTN)(SrcHeight * scale);
|
// Height = (UINTN)(SrcHeight * scale);
|
||||||
setSizeInPixels(GetWidth(), GetHeight());
|
setSizeInPixels((UINTN)(SrcWidth * scale), (UINTN)(SrcHeight * scale));
|
||||||
CopyScaled(Image, scale);
|
CopyScaled(Image, scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,8 +175,10 @@ UINTN XImage::GetSizeInBytes() const
|
|||||||
return PixelData.size() * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
|
return PixelData.size() * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XImage::setSizeInPixels(UINTN W, UINTN H)
|
void XImage::setSizeInPixels(UINTN W, UINTN H) //unused arguments?
|
||||||
{
|
{
|
||||||
|
Width = W;
|
||||||
|
Height = H;
|
||||||
PixelData.setSize(Width * Height);
|
PixelData.setSize(Width * Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,6 +268,14 @@ void XImage::Compose(INTN PosX, INTN PosY, const XImage& TopImage, bool Lowest)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Place this image over Back image at PosX,PosY
|
||||||
|
* and result will be in this image
|
||||||
|
* But pixels will be moved anyway so it's impossible without double copy
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
//void XImage::ComposeOnBack(INTN PosX, INTN PosY, const XImage& BackImage, bool Lowest)
|
||||||
|
|
||||||
|
|
||||||
void XImage::FlipRB(bool WantAlpha)
|
void XImage::FlipRB(bool WantAlpha)
|
||||||
{
|
{
|
||||||
UINTN ImageSize = (Width * Height);
|
UINTN ImageSize = (Width * Height);
|
||||||
@ -381,18 +391,24 @@ void XImage::GetArea(INTN x, INTN y, UINTN W, UINTN H)
|
|||||||
|
|
||||||
setSizeInPixels(Width, Height); // setSizeInPixels BEFORE, so &PixelData[0]
|
setSizeInPixels(Width, Height); // setSizeInPixels BEFORE, so &PixelData[0]
|
||||||
if ( Width == 0 || Height == 0 ) return; // nothing to get, area is zero. &PixelData[0] would crash
|
if ( Width == 0 || Height == 0 ) return; // nothing to get, area is zero. &PixelData[0] would crash
|
||||||
|
/*
|
||||||
|
* Blt(...Width, Height, Delta);
|
||||||
|
* if (Delta == 0) {
|
||||||
|
* Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
*/
|
||||||
if (GraphicsOutput != NULL) {
|
if (GraphicsOutput != NULL) {
|
||||||
GraphicsOutput->Blt(GraphicsOutput,
|
GraphicsOutput->Blt(GraphicsOutput,
|
||||||
&PixelData[0],
|
&PixelData[0],
|
||||||
EfiBltVideoToBltBuffer,
|
EfiBltVideoToBltBuffer,
|
||||||
x, y, 0, 0, Width, Height, Width*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
|
x, y, 0, 0, Width, Height, 0); // Width*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
|
||||||
}
|
}
|
||||||
else if (UgaDraw != NULL) {
|
else if (UgaDraw != NULL) {
|
||||||
UgaDraw->Blt(UgaDraw,
|
UgaDraw->Blt(UgaDraw,
|
||||||
(EFI_UGA_PIXEL *)GetPixelPtr(0,0),
|
(EFI_UGA_PIXEL *)GetPixelPtr(0,0),
|
||||||
EfiUgaVideoToBltBuffer,
|
EfiUgaVideoToBltBuffer,
|
||||||
x, y, 0, 0, Width, Height, Width*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
|
x, y, 0, 0, Width, Height, 0); //Width*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,11 +487,11 @@ void XImage::Draw(INTN x, INTN y, float scale)
|
|||||||
}
|
}
|
||||||
else if (UgaDraw != NULL) {
|
else if (UgaDraw != NULL) {
|
||||||
UgaDraw->Blt(UgaDraw, (EFI_UGA_PIXEL *)Background.GetPixelPtr(0, 0), EfiUgaBltBufferToVideo,
|
UgaDraw->Blt(UgaDraw, (EFI_UGA_PIXEL *)Background.GetPixelPtr(0, 0), EfiUgaBltBufferToVideo,
|
||||||
0, 0, x, y, AreaWidth, AreaHeight, 0);
|
0, 0, x, y, AreaWidth, AreaHeight, GetWidth()*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EFI_STATUS XImage::LoadImage(EFI_FILE *BaseDir, const XStringW& FileName)
|
EFI_STATUS XImage::LoadXImage(EFI_FILE *BaseDir, const XStringW& FileName)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status = EFI_NOT_FOUND;
|
EFI_STATUS Status = EFI_NOT_FOUND;
|
||||||
UINT8 *FileData = NULL;
|
UINT8 *FileData = NULL;
|
||||||
@ -504,13 +520,14 @@ EFI_STATUS XImage::LoadImage(EFI_FILE *BaseDir, const XStringW& FileName)
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//EnsureImageSize should create new object with new sizes
|
||||||
|
//while compose uses old object
|
||||||
void XImage::EnsureImageSize(IN UINTN NewWidth, IN UINTN NewHeight, IN CONST EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color)
|
void XImage::EnsureImageSize(IN UINTN NewWidth, IN UINTN NewHeight, IN CONST EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color)
|
||||||
{
|
{
|
||||||
// EG_IMAGE *NewImage;
|
// EG_IMAGE *NewImage;
|
||||||
|
|
||||||
if (isEmpty())
|
// if (isEmpty())
|
||||||
return;
|
// return;
|
||||||
if (NewWidth == Width && NewHeight == Height)
|
if (NewWidth == Width && NewHeight == Height)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -520,7 +537,11 @@ void XImage::EnsureImageSize(IN UINTN NewWidth, IN UINTN NewHeight, IN CONST EFI
|
|||||||
} */
|
} */
|
||||||
XImage NewImage(NewWidth, NewHeight);
|
XImage NewImage(NewWidth, NewHeight);
|
||||||
NewImage.Fill(Color);
|
NewImage.Fill(Color);
|
||||||
|
// Compose(0, 0, NewImage, false);
|
||||||
Compose(0, 0, NewImage, false);
|
|
||||||
// egFreeImage(NewImage);
|
// egFreeImage(NewImage);
|
||||||
|
NewImage.Compose(0, 0, (*this), false);
|
||||||
|
setSizeInPixels(NewWidth, NewHeight); //include reallocate but loose data
|
||||||
|
// CopyScaled(NewImage, 1.f);
|
||||||
|
CopyMem(&PixelData[0], &NewImage.PixelData[0], GetSizeInBytes());
|
||||||
|
//we have to copy pixels twice? because we can't return newimage instead of this
|
||||||
}
|
}
|
||||||
|
@ -91,8 +91,9 @@ public:
|
|||||||
void GetArea(INTN x, INTN y, UINTN W, UINTN H);
|
void GetArea(INTN x, INTN y, UINTN W, UINTN H);
|
||||||
void Draw(INTN x, INTN y, float scale);
|
void Draw(INTN x, INTN y, float scale);
|
||||||
void DrawWithoutCompose(INTN x, INTN y, UINTN width = 0, UINTN height = 0);
|
void DrawWithoutCompose(INTN x, INTN y, UINTN width = 0, UINTN height = 0);
|
||||||
|
//I changed the name because LoadImage is too widely used
|
||||||
EFI_STATUS LoadImage(EFI_FILE *Dir, const XStringW& FileName); //for example LoadImage(ThemeDir, L"icons\\" + Name);
|
// will be used instead of old egLoadImage
|
||||||
|
EFI_STATUS LoadXImage(EFI_FILE *Dir, const XStringW& FileName); //for example LoadImage(ThemeDir, L"icons\\" + Name);
|
||||||
void EnsureImageSize(IN UINTN Width, IN UINTN Height, IN CONST EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color);
|
void EnsureImageSize(IN UINTN Width, IN UINTN Height, IN CONST EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user