]> code.delx.au - refind/blobdiff - refind/menu.c
Misc. changes, mostly to fix minor or rare bugs.
[refind] / refind / menu.c
index e55bcf45529415a374aea84af2e72d318b93c04c..55511be1ab93bcfc9da32ba91d2898a23ca8d277 100644 (file)
@@ -761,12 +761,13 @@ static UINT8 AverageBrightness(EG_IMAGE *Image) {
    UINTN i;
    UINTN Sum = 0;
 
-   if (Image != NULL) {
+   if ((Image != NULL) && ((Image->Width * Image->Height) != 0)) {
       for (i = 0; i < (Image->Width * Image->Height); i++) {
          Sum += (Image->PixelData[i].r + Image->PixelData[i].g + Image->PixelData[i].b);
       }
+      Sum /= (Image->Width * Image->Height * 3);
    } // if
-   return (UINT8) (Sum / (Image->Width * Image->Height * 3));
+   return (UINT8) Sum;
 } // UINT8 AverageBrightness()
 
 // Display text against the screen's background image. Special case: If Text is NULL