]> code.delx.au - refind/blobdiff - libeg/text.c
Support for auto-selecting text color (white or black) depending on
[refind] / libeg / text.c
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;