From f61d46411b0fc9c70b49c452e0e1080ad03bcbdb Mon Sep 17 00:00:00 2001 From: Sergey Isakov Date: Sat, 4 Apr 2020 05:59:17 +0300 Subject: [PATCH] x,y have to be signed int Signed-off-by: Sergey Isakov --- rEFIt_UEFI/Platform/Settings.cpp | 95 ++++++++++++++++---------------- rEFIt_UEFI/libeg/XImage.cpp | 51 ++++++++++------- rEFIt_UEFI/libeg/XImage.h | 12 ++-- 3 files changed, 82 insertions(+), 76 deletions(-) diff --git a/rEFIt_UEFI/Platform/Settings.cpp b/rEFIt_UEFI/Platform/Settings.cpp index 0499357be..2218d4d16 100644 --- a/rEFIt_UEFI/Platform/Settings.cpp +++ b/rEFIt_UEFI/Platform/Settings.cpp @@ -4946,61 +4946,58 @@ TagPtr LoadTheme (const CHAR16 *TestTheme) CHAR8 *ThemePtr = NULL; UINTN Size = 0; - if (TestTheme != NULL) { - if (ThemePath != NULL) { - FreePool (ThemePath); + if (TestTheme == NULL) { + return NULL; + } + if (ThemePath != NULL) { + FreePool (ThemePath); + } + if (UGAHeight > HEIGHT_2K) { + ThemePath = PoolPrint(L"EFI\\CLOVER\\themes\\%s@2x", TestTheme); + } else { + ThemePath = PoolPrint(L"EFI\\CLOVER\\themes\\%s", TestTheme); + } + Status = SelfRootDir->Open(SelfRootDir, &ThemeDir, ThemePath, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + if (ThemeDir != NULL) { + ThemeDir->Close (ThemeDir); + ThemeDir = NULL; } - if (UGAHeight > HEIGHT_2K) { - ThemePath = PoolPrint(L"EFI\\CLOVER\\themes\\%s@2x", TestTheme); - } else { - ThemePath = PoolPrint(L"EFI\\CLOVER\\themes\\%s", TestTheme); - } - DBG("look for %ls\n", ThemePath); - if (ThemePath != NULL) { - //why this??? - Status = SelfRootDir->Open(SelfRootDir, &ThemeDir, ThemePath, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - if (ThemeDir != NULL) { - ThemeDir->Close (ThemeDir); - ThemeDir = NULL; - } - FreePool (ThemePath); - ThemePath = PoolPrint(L"EFI\\CLOVER\\themes\\%s", TestTheme); - Status = SelfRootDir->Open(SelfRootDir, &ThemeDir, ThemePath, EFI_FILE_MODE_READ, 0); - } + FreePool (ThemePath); + ThemePath = PoolPrint(L"EFI\\CLOVER\\themes\\%s", TestTheme); + Status = SelfRootDir->Open(SelfRootDir, &ThemeDir, ThemePath, EFI_FILE_MODE_READ, 0); + } - if (!EFI_ERROR (Status)) { - Status = egLoadFile(ThemeDir, CONFIG_THEME_SVG, (UINT8**)&ThemePtr, &Size); - if (!EFI_ERROR(Status) && (ThemePtr != NULL) && (Size != 0)) { + if (!EFI_ERROR (Status)) { + Status = egLoadFile(ThemeDir, CONFIG_THEME_SVG, (UINT8**)&ThemePtr, &Size); + if (!EFI_ERROR(Status) && (ThemePtr != NULL) && (Size != 0)) { #if USE_XTHEME - Status = ParseSVGXTheme((const CHAR8*)ThemePtr); - if (EFI_ERROR(Status)) { - ThemeDict = NULL; - } else { - ThemeDict = (__typeof__(ThemeDict))AllocateZeroPool(sizeof(TagStruct)); - ThemeDict->type = kTagTypeNone; - } + Status = ParseSVGXTheme((const CHAR8*)ThemePtr); + if (EFI_ERROR(Status)) { + ThemeDict = NULL; + } else { + ThemeDict = (__typeof__(ThemeDict))AllocateZeroPool(sizeof(TagStruct)); + ThemeDict->type = kTagTypeNone; + } #else - Status = ParseSVGTheme((const CHAR8*)ThemePtr, &ThemeDict); + Status = ParseSVGTheme((const CHAR8*)ThemePtr, &ThemeDict); #endif - if (ThemeDict == NULL) { - DBG("svg file %ls not parsed\n", CONFIG_THEME_SVG); - } else { - DBG("Using vector theme '%ls' (%ls)\n", TestTheme, ThemePath); - } + if (ThemeDict == NULL) { + DBG("svg file %ls not parsed\n", CONFIG_THEME_SVG); + } else { + DBG("Using vector theme '%ls' (%ls)\n", TestTheme, ThemePath); + } + } else { + Status = egLoadFile(ThemeDir, CONFIG_THEME_FILENAME, (UINT8**)&ThemePtr, &Size); + if (!EFI_ERROR (Status) && (ThemePtr != NULL) && (Size != 0)) { + Status = ParseXML((const CHAR8*)ThemePtr, &ThemeDict, 0); + if (EFI_ERROR (Status)) { + ThemeDict = NULL; + } + if (ThemeDict == NULL) { + DBG ("xml file %ls not parsed\n", CONFIG_THEME_FILENAME); } else { - Status = egLoadFile(ThemeDir, CONFIG_THEME_FILENAME, (UINT8**)&ThemePtr, &Size); - if (!EFI_ERROR (Status) && (ThemePtr != NULL) && (Size != 0)) { - Status = ParseXML((const CHAR8*)ThemePtr, &ThemeDict, 0); - if (EFI_ERROR (Status)) { - ThemeDict = NULL; - } - if (ThemeDict == NULL) { - DBG ("xml file %ls not parsed\n", CONFIG_THEME_FILENAME); - } else { - DBG ("Using theme '%ls' (%ls)\n", TestTheme, ThemePath); - } - } + DBG ("Using theme '%ls' (%ls)\n", TestTheme, ThemePath); } } } diff --git a/rEFIt_UEFI/libeg/XImage.cpp b/rEFIt_UEFI/libeg/XImage.cpp index e0ad00219..fe1b95516 100644 --- a/rEFIt_UEFI/libeg/XImage.cpp +++ b/rEFIt_UEFI/libeg/XImage.cpp @@ -163,22 +163,22 @@ const XArray& XImage::GetData() const return PixelData; } -EFI_GRAPHICS_OUTPUT_BLT_PIXEL* XImage::GetPixelPtr(UINTN x, UINTN y) +EFI_GRAPHICS_OUTPUT_BLT_PIXEL* XImage::GetPixelPtr(INTN x, INTN y) { return &PixelData[x + y * Width]; } -const EFI_GRAPHICS_OUTPUT_BLT_PIXEL* XImage::GetPixelPtr(UINTN x, UINTN y) const +const EFI_GRAPHICS_OUTPUT_BLT_PIXEL* XImage::GetPixelPtr(INTN x, INTN y) const { return &PixelData[x + y * Width]; } -const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& XImage::GetPixel(UINTN x, UINTN y) const +const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& XImage::GetPixel(INTN x, INTN y) const { return PixelData[x + y * Width]; } - +/* UINTN XImage::GetWidth() const { return Width; @@ -188,7 +188,7 @@ UINTN XImage::GetHeight() const { return Height; } - +*/ UINTN XImage::GetSizeInBytes() const { return PixelData.size() * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL); @@ -220,34 +220,37 @@ void XImage::FillArea(const EG_PIXEL* Color, EG_RECT& Rect) void XImage::FillArea(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color, EG_RECT& Rect) { - for (INTN y = Rect.YPos; y < (INTN)Height && (y - Rect.YPos) < Rect.Height; ++y) { - for (INTN x = Rect.XPos; x < (INTN)Width && (x - Rect.XPos) < Rect.Width; ++x) + for (INTN y = Rect.YPos; y < GetHeight() && (y - Rect.YPos) < Rect.Height; ++y) { + for (INTN x = Rect.XPos; x < GetWidth() && (x - Rect.XPos) < Rect.Width; ++x) { PixelData[y * Width + x] = Color; + } } } //sizes remain as were assumed input image is large enough? void XImage::CopyScaled(const XImage& Image, float scale) { - UINTN SrcWidth = Image.GetWidth(); + int SrcWidth = (int)Image.GetWidth(); //because Source[] requires int argument, why not long long int? int Pixel = sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL); - int Row = (int)SrcWidth * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL); + int Row = SrcWidth * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL); + int W = (int)GetWidth(); + int H = (int)GetHeight(); const XArray& Source = Image.GetData(); - for (UINTN y = 0; y < Height; y++) + for (INTN y = 0; y < H; y++) { int ly = (int)(y / scale); int dy = (int)(y - ly * scale); - for (UINTN x = 0; x < Width; x++) + for (INTN x = 0; x < W; x++) { int lx = (int)(x / scale); int dx = (int)(x - lx * scale); int a01 = (x == 0) ? 0 : -Pixel; int a10 = (y == 0) ? 0 : -Row; - int a21 = (x == Width - 1) ? 0 : Pixel; - int a12 = (y == Height - 1) ? 0 : Row; + int a21 = (x == W - 1) ? 0 : Pixel; + int a12 = (y == H - 1) ? 0 : Row; EFI_GRAPHICS_OUTPUT_BLT_PIXEL& dst = *GetPixelPtr(x, y); dst.Blue = Smooth(&Source[lx + ly * SrcWidth].Blue, a01, a10, a21, a12, dx, dy, scale); dst.Green = Smooth(&Source[lx + ly * SrcWidth].Green, a01, a10, a21, a12, dx, dy, scale); @@ -270,10 +273,10 @@ void XImage::Compose(INTN PosX, INTN PosY, const XImage& TopImage, bool Lowest) UINT32 TempAlpha; UINT32 Temp; //change only affected pixels - for (UINTN y = PosY; y < Height && (y - PosY) < TopImage.GetHeight(); ++y) { + for (INTN y = PosY; y < GetHeight() && (y - PosY) < TopImage.GetHeight(); ++y) { // EFI_GRAPHICS_OUTPUT_BLT_PIXEL& CompPtr = *GetPixelPtr(PosX, y); // I assign a ref to avoid the operator ->. Compiler will produce the same anyway. EFI_GRAPHICS_OUTPUT_BLT_PIXEL* CompPtr = GetPixelPtr(PosX, y); - for (UINTN x = PosX; x < Width && (x - PosX) < TopImage.GetWidth(); ++x) { + for (INTN x = PosX; x < GetWidth() && (x - PosX) < TopImage.GetWidth(); ++x) { //------ // test compAlpha = 255; TopAlpha = 0 -> only Comp, TopAplha = 255 -> only Top TopAlpha = TopImage.GetPixel(x-PosX, y-PosY).Reserved & 0xFF; //0, 255 @@ -282,9 +285,8 @@ void XImage::Compose(INTN PosX, INTN PosY, const XImage& TopImage, bool Lowest) TempAlpha = CompAlpha * RevAlpha; //2<<16; 255*255, 0 TopAlpha *= 255; //2<<16; 0, 255*255 FinalAlpha = TopAlpha + TempAlpha; //2<<16; 255*255, 255*255 - // if (FinalAlpha == 0) FinalAlpha = 255 * 255; //impossible, - //final alpha =(1-(1-x)*(1-y)) =(255*255-(255-topA)*(255-compA))/255 = topA+compA*(1-topA) + if (FinalAlpha != 0) { Temp = (CompPtr->Blue * TempAlpha) + (TopImage.GetPixel(x-PosX, y-PosY).Blue * TopAlpha); CompPtr->Blue = (UINT8)(Temp / FinalAlpha); @@ -670,19 +672,26 @@ void XImage::DummyImage(IN UINTN PixelSize) void XImage::CopyRect(const XImage& Image, INTN XPos, INTN YPos) { - for (UINTN y = 0; y < Height && (y + YPos) < Image.GetHeight(); ++y) { - for (UINTN x = 0; x < Width && (x + XPos) < Image.GetWidth(); ++x) { + for (INTN y = 0; y < GetHeight() && (y + YPos) < Image.GetHeight(); ++y) { + for (INTN x = 0; x < GetWidth() && (x + XPos) < Image.GetWidth(); ++x) { PixelData[y * Width + x] = Image.GetPixel(x + XPos, y + YPos); } } } +/* + * copy rect InputRect from the input Image and place to OwnRect in this image + * width and height will be the smaller of the two rect + * taking into account boundary intersect + */ void XImage::CopyRect(const XImage& Image, const EG_RECT& OwnPlace, const EG_RECT& InputRect) { INTN Dx = OwnPlace.XPos - InputRect.XPos; INTN Dy = OwnPlace.YPos - InputRect.YPos; - for (INTN y = OwnPlace.YPos; y < (INTN)Height && (y - Dy) < (INTN)Image.GetHeight(); ++y) { - for (INTN x = OwnPlace.XPos; x < (INTN)Width && (x - Dx) < (INTN)Image.GetWidth(); ++x) { + INTN W = MIN(OwnPlace.Width, InputRect.Width); + INTN H = MIN(OwnPlace.Height, InputRect.Height); + for (INTN y = OwnPlace.YPos; y - OwnPlace.YPos < H && y < GetHeight() && (y - Dy) < Image.GetHeight(); ++y) { + for (INTN x = OwnPlace.XPos; x - OwnPlace.XPos < W && x < GetWidth() && (x - Dx) < Image.GetWidth(); ++x) { PixelData[y * Width + x] = Image.GetPixel(x - Dx, y - Dy); } } diff --git a/rEFIt_UEFI/libeg/XImage.h b/rEFIt_UEFI/libeg/XImage.h index 434db62f5..b91c35291 100644 --- a/rEFIt_UEFI/libeg/XImage.h +++ b/rEFIt_UEFI/libeg/XImage.h @@ -46,7 +46,7 @@ typedef struct { class XImage { protected: - size_t Width; + size_t Width; //may be better to use INTN - signed integer as it always compared with expressions size_t Height; XArray PixelData; @@ -68,11 +68,11 @@ public: const XArray& GetData() const; - const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& GetPixel(UINTN x, UINTN y) const; - const EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetPixelPtr(UINTN x, UINTN y) const ; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetPixelPtr(UINTN x, UINTN y); - UINTN GetWidth() const; - UINTN GetHeight() const; + const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& GetPixel(INTN x, INTN y) const; + const EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetPixelPtr(INTN x, INTN y) const ; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetPixelPtr(INTN x, INTN y); + INTN GetWidth() const { return (INTN)Width; } + INTN GetHeight() const { return (INTN)Height; } void setZero() { SetMem( (void*)GetPixelPtr(0, 0), GetSizeInBytes(), 0); }