repair background scaling

Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
Sergey Isakov 2020-04-12 21:53:27 +03:00
parent c572e50ec6
commit 12990aacd1
3 changed files with 24 additions and 13 deletions

View File

@ -66,12 +66,6 @@ XImage& XImage::operator= (const XImage& other)
return *this;
}
UINT8 XImage::Smooth(const UINT8* p, int a01, int a10, int a21, int a12, int dx, int dy, float scale)
{
return (UINT8)((*(p + a01) * (scale - dx) * 3.f + *(p + a10) * (scale - dy) * 3.f + *(p + a21) * dx * 3.f +
*(p + a12) * dy * 3.f + *(p) * 2.f *scale) / (scale * 8.f));
}
XImage::XImage(const XImage& Image, float scale)
{
UINTN SrcWidth = Image.GetWidth();
@ -228,6 +222,13 @@ void XImage::FillArea(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color, EG_RECT& Rect)
}
}
UINT8 XImage::Smooth(const UINT8* p, int a01, int a10, int a21, int a12, float dx, float dy, float scale)
{
return (UINT8)((*(p + a01) * (scale - dx) * 3.f + *(p + a10) * (scale - dy) * 3.f + *(p + a21) * dx * 3.f +
*(p + a12) * dy * 3.f + *(p) * 2.f *scale) / (scale * 8.f));
}
//sizes remain as were assumed input image is large enough?
void XImage::CopyScaled(const XImage& Image, float scale)
{
@ -240,14 +241,14 @@ void XImage::CopyScaled(const XImage& Image, float scale)
const XArray<EFI_GRAPHICS_OUTPUT_BLT_PIXEL>& Source = Image.GetData();
for (INTN y = 0; y < H; y++)
for (INTN y = 0; y < H; y++) //destination coordinates
{
int ly = (int)(y / scale);
int dy = (int)(y - ly * scale);
int ly = (int)(y / scale); //integer part of src coord
float dy = y - ly * scale; //fractional part
for (INTN x = 0; x < W; x++)
{
int lx = (int)(x / scale);
int dx = (int)(x - lx * scale);
float dx = x - lx * scale;
int a01 = (x == 0) ? 0 : -Pixel;
int a10 = (y == 0) ? 0 : -Row;
int a21 = (x == W - 1) ? 0 : Pixel;

View File

@ -113,7 +113,7 @@ public:
void EnsureImageSize(IN UINTN NewWidth, IN UINTN NewHeight);
void DummyImage(IN UINTN PixelSize);
protected:
UINT8 Smooth(const UINT8* p, int a01, int a10, int a21, int a12, int dx, int dy, float scale);
UINT8 Smooth(const UINT8* p, int a01, int a10, int a21, int a12, float dx, float dy, float scale);
};
#endif //__XSTRINGW_H__

View File

@ -454,6 +454,7 @@ void XTheme::FillByEmbedded()
void XTheme::ClearScreen() //and restore background and banner
{
EFI_GRAPHICS_OUTPUT_BLT_PIXEL FirstBannerPixel = MenuBackgroundPixel;
if (BanHeight < 2) {
BanHeight = ((UGAHeight - (int)(LayoutHeight * Scale)) >> 1);
}
@ -461,6 +462,8 @@ void XTheme::ClearScreen() //and restore background and banner
if (!(HideUIFlags & HIDEUI_FLAG_BANNER)) {
//Banner image prepared before
if (!Banner.isEmpty()) {
FirstBannerPixel = Banner.GetPixel(0,0);
BannerPlace.Width = Banner.GetWidth();
BannerPlace.Height = (BanHeight >= Banner.GetHeight()) ? Banner.GetHeight() : BanHeight;
BannerPlace.XPos = BannerPosX;
@ -501,15 +504,22 @@ void XTheme::ClearScreen() //and restore background and banner
} else {
BlueBackgroundPixel = DarkEmbeddedBackgroundPixel;
}
} else {
BlueBackgroundPixel = FirstBannerPixel;
}
Background.Fill(BlueBackgroundPixel); //blue opaque. May be better to set black opaque?
}
// now we are sure Background has UGA sizes
float BigScale;
float BigScaleY;
if (!BigBack.isEmpty()) {
switch (BackgroundScale) {
case imScale:
// DBG("back copy scaled\n");
Background = XImage(BigBack, Scale);
// DBG("back copy scaled\n");
// Background.setSizeInPixels(UGAWidth, UGAHeight); //anyway set
BigScale = (float)UGAWidth/BigBack.GetWidth();
BigScaleY = (float)UGAHeight/BigBack.GetHeight();
Background.CopyScaled(BigBack, MAX(BigScale, BigScaleY));
break;
case imCrop:
{