]> code.delx.au - refind/blobdiff - libeg/screen.c
Version 0.6.5 release.
[refind] / libeg / screen.c
index 1856cbd49c74c13a035ed7f36a59089b77a692d5..378847e563e2ab6531c7ec2c5799efc343d6da44 100644 (file)
@@ -355,22 +355,51 @@ VOID egClearScreen(IN EG_PIXEL *Color)
 
 VOID egDrawImage(IN EG_IMAGE *Image, IN UINTN ScreenPosX, IN UINTN ScreenPosY)
 {
-    if (!egHasGraphics)
+    EG_IMAGE *CompImage = NULL;
+
+    // NOTE: Weird seemingly redundant tests because some placement code can "wrap around" and
+    // send "negative" values, which of course become very large unsigned ints that can then
+    // wrap around AGAIN if values are added to them.....
+    if (!egHasGraphics || ((ScreenPosX + Image->Width) > egScreenWidth) || ((ScreenPosY + Image->Height) > egScreenHeight) ||
+        (ScreenPosX > egScreenWidth) || (ScreenPosY > egScreenHeight))
         return;
 
-    if (Image->HasAlpha) {
-        Image->HasAlpha = FALSE;
-        egSetPlane(PLPTR(Image, a), 0, Image->Width * Image->Height);
+    if ((GlobalConfig.ScreenBackground == NULL) || ((Image->Width == egScreenWidth) && (Image->Height == egScreenHeight))) {
+       CompImage = Image;
+    } else if (GlobalConfig.ScreenBackground == Image) {
+       CompImage = GlobalConfig.ScreenBackground;
+    } else {
+       CompImage = egCropImage(GlobalConfig.ScreenBackground, ScreenPosX, ScreenPosY, Image->Width, Image->Height);
+       if (CompImage == NULL) {
+          Print(L"Error! Can't crop image in egDrawImage()!\n");
+          return;
+       }
+       egComposeImage(CompImage, Image, 0, 0);
     }
 
     if (GraphicsOutput != NULL) {
-        refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)Image->PixelData, EfiBltBufferToVideo,
-                            0, 0, ScreenPosX, ScreenPosY, Image->Width, Image->Height, 0);
+       refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)CompImage->PixelData,
+                            EfiBltBufferToVideo, 0, 0, ScreenPosX, ScreenPosY, CompImage->Width, CompImage->Height, 0);
     } else if (UgaDraw != NULL) {
-        refit_call10_wrapper(UgaDraw->Blt, UgaDraw, (EFI_UGA_PIXEL *)Image->PixelData, EfiUgaBltBufferToVideo,
-                     0, 0, ScreenPosX, ScreenPosY, Image->Width, Image->Height, 0);
+       refit_call10_wrapper(UgaDraw->Blt, UgaDraw, (EFI_UGA_PIXEL *)CompImage->PixelData, EfiUgaBltBufferToVideo,
+                            0, 0, ScreenPosX, ScreenPosY, CompImage->Width, CompImage->Height, 0);
     }
-}
+    if ((CompImage != GlobalConfig.ScreenBackground) && (CompImage != Image))
+       egFreeImage(CompImage);
+} /* VOID egDrawImage() */
+
+// Display an unselected icon on the screen, so that the background image shows
+// through the transparency areas. The BadgeImage may be NULL, in which case
+// it's not composited in.
+VOID egDrawImageWithTransparency(EG_IMAGE *Image, EG_IMAGE *BadgeImage, UINTN XPos, UINTN YPos, UINTN Width, UINTN Height) {
+   EG_IMAGE *Background;
+
+   Background = egCropImage(GlobalConfig.ScreenBackground, XPos, YPos, Width, Height);
+   if (Background != NULL) {
+      BltImageCompositeBadge(Background, Image, BadgeImage, XPos, YPos);
+      egFreeImage(Background);
+   }
+} // VOID DrawImageWithTransparency()
 
 VOID egDrawImageArea(IN EG_IMAGE *Image,
                      IN UINTN AreaPosX, IN UINTN AreaPosY,
@@ -384,17 +413,13 @@ VOID egDrawImageArea(IN EG_IMAGE *Image,
     if (AreaWidth == 0)
         return;
 
-    if (Image->HasAlpha) {
-        Image->HasAlpha = FALSE;
-        egSetPlane(PLPTR(Image, a), 0, Image->Width * Image->Height);
-    }
-
     if (GraphicsOutput != NULL) {
-        refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)Image->PixelData, EfiBltBufferToVideo,
-                            AreaPosX, AreaPosY, ScreenPosX, ScreenPosY, AreaWidth, AreaHeight, Image->Width * 4);
+        refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)Image->PixelData,
+                             EfiBltBufferToVideo, AreaPosX, AreaPosY, ScreenPosX, ScreenPosY, AreaWidth, AreaHeight,
+                             Image->Width * 4);
     } else if (UgaDraw != NULL) {
         refit_call10_wrapper(UgaDraw->Blt, UgaDraw, (EFI_UGA_PIXEL *)Image->PixelData, EfiUgaBltBufferToVideo,
-                     AreaPosX, AreaPosY, ScreenPosX, ScreenPosY, AreaWidth, AreaHeight, Image->Width * 4);
+                             AreaPosX, AreaPosY, ScreenPosX, ScreenPosY, AreaWidth, AreaHeight, Image->Width * 4);
     }
 }
 
@@ -411,11 +436,36 @@ 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()
 
+// Copy the current contents of the display into an EG_IMAGE....
+// Returns pointer if successful, NULL if not.
+EG_IMAGE * egCopyScreen(VOID) {
+   EG_IMAGE *Image = NULL;
+
+   if (!egHasGraphics)
+      return NULL;
+
+   // allocate a buffer for the whole screen
+   Image = egCreateImage(egScreenWidth, egScreenHeight, FALSE);
+   if (Image == NULL) {
+      return NULL;
+   }
+
+   // get full screen image
+   if (GraphicsOutput != NULL) {
+      refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)Image->PixelData,
+                           EfiBltVideoToBltBuffer, 0, 0, 0, 0, Image->Width, Image->Height, 0);
+   } else if (UgaDraw != NULL) {
+      refit_call10_wrapper(UgaDraw->Blt, UgaDraw, (EFI_UGA_PIXEL *)Image->PixelData, EfiUgaVideoToBltBuffer,
+                           0, 0, 0, 0, Image->Width, Image->Height, 0);
+   }
+   return Image;
+} // EG_IMAGE * egCopyScreen()
+
 //
 // Make a screenshot
 //
@@ -428,23 +478,10 @@ VOID egScreenShot(VOID)
     UINTN           FileDataLength;
     UINTN           Index;
 
-    if (!egHasGraphics)
-        return;
-
-    // allocate a buffer for the whole screen
-    Image = egCreateImage(egScreenWidth, egScreenHeight, FALSE);
+    Image = egCopyScreen();
     if (Image == NULL) {
-        Print(L"Error egCreateImage returned NULL\n");
-        goto bailout_wait;
-    }
-
-    // get full screen image
-    if (GraphicsOutput != NULL) {
-        refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)Image->PixelData, EfiBltVideoToBltBuffer,
-                            0, 0, 0, 0, Image->Width, Image->Height, 0);
-    } else if (UgaDraw != NULL) {
-        refit_call10_wrapper(UgaDraw->Blt, UgaDraw, (EFI_UGA_PIXEL *)Image->PixelData, EfiUgaVideoToBltBuffer,
-                     0, 0, 0, 0, Image->Width, Image->Height, 0);
+       Print(L"Error: Unable to take screen shot\n");
+       goto bailout_wait;
     }
 
     // encode as BMP