]> code.delx.au - refind/commitdiff
Support for auto-selecting text color (white or black) depending on
authorsrs5694 <srs5694@users.sourceforge.net>
Wed, 16 Jan 2013 07:09:29 +0000 (02:09 -0500)
committersrs5694 <srs5694@users.sourceforge.net>
Wed, 16 Jan 2013 07:09:29 +0000 (02:09 -0500)
background color.

NEWS.txt
libeg/libeg.h
libeg/screen.c
libeg/text.c
mkdistrib
refind.spec
refind/main.c
refind/menu.c

index 6b940ff70070160ef53dac360ebde4d270ed89fd..d8b20a14690713344f1666d711447c8e345cd4fe 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -1,6 +1,9 @@
 0.6.5 (1/??/2013):
 ------------------
 
+- Improved text color support: rEFInd now uses black text against light
+  backgrounds and white text against dark backgrounds.
+
 - Added support for PNGs as banners, icons, and selectors.
 
 - Added icon for ALT Linux.
index 088afdd8813d645907e2709328d54552947dcee2..7e2c99045c6f26ffd83bd6b7821e0973160ef613 100644 (file)
 
 /* types */
 
+typedef enum ColorTypes {
+   white,
+   black
+} Colors;
+
 /* This should be compatible with EFI_UGA_PIXEL */
 typedef struct {
     UINT8 b, g, r, a;
@@ -115,7 +120,7 @@ VOID egFillImageArea(IN OUT EG_IMAGE *CompImage,
 VOID egComposeImage(IN OUT EG_IMAGE *CompImage, IN EG_IMAGE *TopImage, IN UINTN PosX, IN UINTN PosY);
 
 VOID egMeasureText(IN CHAR16 *Text, OUT UINTN *Width, OUT UINTN *Height);
-VOID egRenderText(IN CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN UINTN PosX, IN UINTN PosY);
+VOID egRenderText(IN CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN UINTN PosX, IN UINTN PosY, IN UINT8 BGBrightness);
 
 VOID egClearScreen(IN EG_PIXEL *Color);
 VOID egDrawImage(IN EG_IMAGE *Image, IN UINTN ScreenPosX, IN UINTN ScreenPosY);
index 9f159e14d784d776497cab57b9f097e83c9a8717..cd973975f05e3862ff8dc860445db6da295b303e 100644 (file)
@@ -446,7 +446,7 @@ VOID egDisplayMessage(IN CHAR16 *Text, EG_PIXEL *BGColor) {
          BoxWidth = egScreenWidth;
       BoxHeight = 2 * FONT_CELL_HEIGHT;
       Box = egCreateFilledImage(BoxWidth, BoxHeight, FALSE, BGColor);
-      egRenderText(Text, Box, FONT_CELL_WIDTH, FONT_CELL_HEIGHT / 2);
+      egRenderText(Text, Box, FONT_CELL_WIDTH, FONT_CELL_HEIGHT / 2, (BGColor->r + BGColor->g + BGColor->b) / 3);
       egDrawImage(Box, (egScreenWidth - BoxWidth) / 2, (egScreenHeight - BoxHeight) / 2);
    } // if non-NULL inputs
 } // VOID egDisplayMessage()
index 93551b2b082558d615166eb3b392cfa2a83d2e50..c723710411a583f9230c10070c205f29d6f5f6cf 100644 (file)
@@ -41,7 +41,8 @@
 #define FONT_CELL_WIDTH (7)
 #define FONT_CELL_HEIGHT (12)
 
-static EG_IMAGE *FontImage = NULL;
+static EG_IMAGE *BlackFontImage = NULL;
+static EG_IMAGE *WhiteFontImage = NULL;
 
 //
 // Text rendering
@@ -55,8 +56,9 @@ VOID egMeasureText(IN CHAR16 *Text, OUT UINTN *Width, OUT UINTN *Height)
         *Height = FONT_CELL_HEIGHT;
 }
 
-VOID egRenderText(IN CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN UINTN PosX, IN UINTN PosY)
+VOID egRenderText(IN CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN UINTN PosX, IN UINTN PosY, IN UINT8 BGBrightness)
 {
+    EG_IMAGE        *FontImage;
     EG_PIXEL        *BufferPtr;
     EG_PIXEL        *FontPixelData;
     UINTN           BufferLineOffset, FontLineOffset;
@@ -72,9 +74,31 @@ VOID egRenderText(IN CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN UINTN PosX, IN
     if (TextLength * FONT_CELL_WIDTH + PosX > CompImage->Width)
         TextLength = (CompImage->Width - PosX) / FONT_CELL_WIDTH;
 
-    // load the font
-    if (FontImage == NULL)
-        FontImage = egPrepareEmbeddedImage(&egemb_font, TRUE);
+    if (BGBrightness < 128) {
+       if (WhiteFontImage == NULL) {
+          WhiteFontImage = egPrepareEmbeddedImage(&egemb_font, TRUE);
+          if (WhiteFontImage == NULL)
+             return;
+          for (i = 0; i < (WhiteFontImage->Width * WhiteFontImage->Height); i++) {
+             WhiteFontImage->PixelData[i].r = 255 - WhiteFontImage->PixelData[i].r;
+             WhiteFontImage->PixelData[i].g = 255 - WhiteFontImage->PixelData[i].g;
+             WhiteFontImage->PixelData[i].b = 255 - WhiteFontImage->PixelData[i].b;
+//             WhiteFontImage->PixelData[i].a = 255 - WhiteFontImage->PixelData[i].a;
+          } // for
+       } // if
+       FontImage = WhiteFontImage;
+    } else {
+       if (BlackFontImage == NULL)
+          BlackFontImage = egPrepareEmbeddedImage(&egemb_font, TRUE);
+       if (BlackFontImage == NULL)
+          return;
+       FontImage = BlackFontImage;
+    } // if/else
+
+//     // load the font
+//     if (FontImage == NULL) {
+//         FontImage = egPrepareEmbeddedImage(&egemb_font, TRUE);
+//     } // if font not yet loaded.
 
     // render it
     BufferPtr = CompImage->PixelData;
index af3ed1dba2ac26c608ba2644af39164c7d4490b0..52d07ffb1a98b3050f6c82cd40412cfb2e9411cf 100755 (executable)
--- a/mkdistrib
+++ b/mkdistrib
@@ -46,7 +46,7 @@ make clean
 
 # Prepare a place and copy files there....
 mkdir -p ../snapshots/$1/refind-$1/icons
-cp --preserve=timestamps icons/*.icns icons/*.png ../snapshots/$1/refind-$1/icons/
+cp --preserve=timestamps icons/*.icns ../snapshots/$1/refind-$1/icons/
 cp -a docs images keys include EfiLib libeg mok refind filesystems refind.spec install.sh mkrlconf.sh mvrefind.sh CREDITS.txt NEWS.txt BUILDING.txt COPYING.txt LICENSE.txt README.txt refind.inf Make.tiano Make.common Makefile refind.conf-sample ../snapshots/$1/refind-$1
 
 # Go there and prepare a souce code zip file....
index ed0ccff8639f3a7248d5f6884273c3bb5f271e54..24dfd910d6a36baeb991d78d0e642be12792c0f6 100644 (file)
@@ -1,6 +1,6 @@
 Summary: EFI boot manager software
 Name: refind
-Version: 0.6.4.2
+Version: 0.6.4.7
 Release: 1%{?dist}
 License: GPLv3
 URL: http://www.rodsbooks.com/refind/
index 4638a62938a843266d6c2391ee2c8d54b82eace3..4de35d87edb6585e138b4e1b39999c849448242d 100644 (file)
@@ -128,7 +128,7 @@ static VOID AboutrEFInd(VOID)
 
     if (AboutMenu.EntryCount == 0) {
         AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
-        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.6.4.6");
+        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.6.4.7");
         AddMenuInfoLine(&AboutMenu, L"");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012 Roderick W. Smith");
index 39c9020141903f5ff40e073026ef47db6275e205..cf2bafdd704edce95a692d8006f376eaf79ef074 100644 (file)
@@ -636,26 +636,46 @@ static VOID TextMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State,
 
 
 // Display a submenu
-static VOID DrawSubmenuText(IN CHAR16 *Text, IN BOOLEAN Selected, IN UINTN FieldWidth, IN UINTN XPos, IN UINTN YPos)
+static VOID DrawText(IN CHAR16 *Text, IN BOOLEAN Selected, IN UINTN FieldWidth, IN UINTN XPos, IN UINTN YPos)
 {
-//   UINTN TextWidth = TEXT_XMARGIN * 2 + StrLen(Text) * FONT_CELL_WIDTH;
    EG_IMAGE *TextBuffer;
+   EG_PIXEL Bg;
 
    TextBuffer = egCreateImage(FieldWidth, TEXT_LINE_HEIGHT, FALSE);
 
    egFillImage(TextBuffer, &MenuBackgroundPixel);
+   Bg = MenuBackgroundPixel;
    if (Selected) {
        // draw selection bar background
        egFillImageArea(TextBuffer, 0, 0, FieldWidth, TextBuffer->Height, &SelectionBackgroundPixel);
+       Bg = SelectionBackgroundPixel;
    }
 
    // render the text
-   egRenderText(Text, TextBuffer, TEXT_XMARGIN, TEXT_YMARGIN);
+   egRenderText(Text, TextBuffer, TEXT_XMARGIN, TEXT_YMARGIN, (Bg.r + Bg.g + Bg.b) / 3);
    egDrawImageWithTransparency(TextBuffer, NULL, XPos, YPos, TextBuffer->Width, TextBuffer->Height);
 //    BltImage(TextBuffer, XPos, YPos);
 }
 
-static VOID DrawMainMenuText(IN CHAR16 *Text, IN UINTN XPos, IN UINTN YPos)
+// Finds the average brightness of the input Image.
+// NOTE: Passing an Image that covers the whole screen can strain the
+// capacity of a UINTN on a 32-bit system with a very large display.
+// As the intended use for this function is to handle a single text
+// string's background, this shouldn't be a problem, but it may need
+// addressing if it's applied more broadly....
+static UINT8 AverageBrightness(EG_IMAGE *Image) {
+   UINTN i;
+   UINTN Sum = 0;
+
+   if (Image != NULL) {
+      for (i = 0; i < (Image->Width * Image->Height); i++) {
+         Sum += (Image->PixelData[i].r + Image->PixelData[i].g + Image->PixelData[i].b);
+      }
+   } // if
+   return (UINT8) (Sum / (Image->Width * Image->Height * 3));
+} // UINT8 AverageBrightness()
+
+static VOID DrawTextWithTransparency(IN CHAR16 *Text, IN UINTN XPos, IN UINTN YPos)
 {
     UINTN TextWidth, TextPosX;
     EG_IMAGE *TextBuffer;
@@ -668,7 +688,7 @@ static VOID DrawMainMenuText(IN CHAR16 *Text, IN UINTN XPos, IN UINTN YPos)
        TextPosX = 0;
     else
        TextPosX = (TextBuffer->Width - TextWidth) / 2;
-    egRenderText(Text, TextBuffer, TextPosX, 0);
+    egRenderText(Text, TextBuffer, TextPosX, 0, AverageBrightness(TextBuffer));
     egDrawImageWithTransparency(TextBuffer, NULL, XPos, YPos, TextBuffer->Width, TextBuffer->Height);
 }
 
@@ -762,8 +782,8 @@ static VOID GraphicsMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *Sta
             Window = egCreateFilledImage(MenuWidth, MenuHeight, FALSE, BackgroundPixel);
             egDrawImage(Window, EntriesPosX, EntriesPosY);
             egMeasureText(Screen->Title, &ItemWidth, NULL);
-            DrawSubmenuText(Screen->Title, FALSE, (StrLen(Screen->Title) + 2) * FONT_CELL_WIDTH,
-                            EntriesPosX + (MenuWidth - ItemWidth) / 2, EntriesPosY += TEXT_LINE_HEIGHT);
+            DrawText(Screen->Title, FALSE, (StrLen(Screen->Title) + 2) * FONT_CELL_WIDTH,
+                     EntriesPosX + (MenuWidth - ItemWidth) / 2, EntriesPosY += TEXT_LINE_HEIGHT);
             if (Screen->TitleImage) {
                BltImageAlpha(Screen->TitleImage, EntriesPosX, EntriesPosY + TEXT_LINE_HEIGHT * 2, BackgroundPixel);
                EntriesPosX += (Screen->TitleImage->Width + TITLEICON_SPACING);
@@ -771,7 +791,7 @@ static VOID GraphicsMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *Sta
             EntriesPosY += (TEXT_LINE_HEIGHT * 2);
             if (Screen->InfoLineCount > 0) {
                 for (i = 0; i < (INTN)Screen->InfoLineCount; i++) {
-                    DrawSubmenuText(Screen->InfoLines[i], FALSE, LineWidth, EntriesPosX, EntriesPosY);
+                    DrawText(Screen->InfoLines[i], FALSE, LineWidth, EntriesPosX, EntriesPosY);
                     EntriesPosY += TEXT_LINE_HEIGHT;
                 }
                 EntriesPosY += TEXT_LINE_HEIGHT;  // also add a blank line
@@ -785,27 +805,27 @@ static VOID GraphicsMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *Sta
 
         case MENU_FUNCTION_PAINT_ALL:
             for (i = 0; i <= State->MaxIndex; i++) {
-               DrawSubmenuText(Screen->Entries[i]->Title, (i == State->CurrentSelection), LineWidth,
-                               EntriesPosX, EntriesPosY + i * TEXT_LINE_HEIGHT);
+               DrawText(Screen->Entries[i]->Title, (i == State->CurrentSelection), LineWidth, EntriesPosX,
+                        EntriesPosY + i * TEXT_LINE_HEIGHT);
             }
             if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
                if ((Screen->Hint1 != NULL) && (StrLen(Screen->Hint1) > 0))
-                  DrawMainMenuText(Screen->Hint1, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3));
+                  DrawTextWithTransparency(Screen->Hint1, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3));
                if ((Screen->Hint2 != NULL) && (StrLen(Screen->Hint2) > 0))
-                  DrawMainMenuText(Screen->Hint2, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2));
+                  DrawTextWithTransparency(Screen->Hint2, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2));
             } // if
             break;
 
         case MENU_FUNCTION_PAINT_SELECTION:
             // redraw selection cursor
-            DrawSubmenuText(Screen->Entries[State->PreviousSelection]->Title, FALSE, LineWidth,
-                         EntriesPosX, EntriesPosY + State->PreviousSelection * TEXT_LINE_HEIGHT);
-            DrawSubmenuText(Screen->Entries[State->CurrentSelection]->Title, TRUE, LineWidth,
-                         EntriesPosX, EntriesPosY + State->CurrentSelection * TEXT_LINE_HEIGHT);
+            DrawText(Screen->Entries[State->PreviousSelection]->Title, FALSE, LineWidth,
+                     EntriesPosX, EntriesPosY + State->PreviousSelection * TEXT_LINE_HEIGHT);
+            DrawText(Screen->Entries[State->CurrentSelection]->Title, TRUE, LineWidth,
+                     EntriesPosX, EntriesPosY + State->CurrentSelection * TEXT_LINE_HEIGHT);
             break;
 
         case MENU_FUNCTION_PAINT_TIMEOUT:
-            DrawSubmenuText(ParamText, FALSE, LineWidth, EntriesPosX, TimeoutPosY);
+            DrawText(ParamText, FALSE, LineWidth, EntriesPosX, TimeoutPosY);
             break;
 
     }
@@ -849,12 +869,12 @@ static VOID PaintAll(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, UINTN
       }
    }
    if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
-      DrawMainMenuText(Screen->Entries[State->CurrentSelection]->Title,
+      DrawTextWithTransparency(Screen->Entries[State->CurrentSelection]->Title,
                        (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY);
 
    if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
-      DrawMainMenuText(Screen->Hint1, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3));
-      DrawMainMenuText(Screen->Hint2, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2));
+      DrawTextWithTransparency(Screen->Hint1, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3));
+      DrawTextWithTransparency(Screen->Hint2, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2));
    } // if
 } // static VOID PaintAll()
 
@@ -882,7 +902,7 @@ static VOID PaintSelection(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State,
       DrawMainMenuEntry(Screen->Entries[State->PreviousSelection], FALSE, itemPosX[XSelectPrev], YPosPrev);
       DrawMainMenuEntry(Screen->Entries[State->CurrentSelection], TRUE, itemPosX[XSelectCur], YPosCur);
       if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
-         DrawMainMenuText(Screen->Entries[State->CurrentSelection]->Title,
+         DrawTextWithTransparency(Screen->Entries[State->CurrentSelection]->Title,
                           (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY);
    } else { // Current selection not visible; must redraw the menu....
       MainMenuStyle(Screen, State, MENU_FUNCTION_PAINT_ALL, NULL);
@@ -1021,7 +1041,7 @@ VOID MainMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINT
 
         case MENU_FUNCTION_PAINT_TIMEOUT:
             if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
-                DrawMainMenuText(ParamText, (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY + TEXT_LINE_HEIGHT);
+                DrawTextWithTransparency(ParamText, (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY + TEXT_LINE_HEIGHT);
             break;
 
     }