Convert images when installing

This commit is contained in:
Lauri Kenttä
2023-08-27 13:27:19 +03:00
parent dfadf67a21
commit 990f245ac9
3 changed files with 33 additions and 6 deletions

View File

@@ -19,7 +19,6 @@ When booting on a UEFI-based computer, Windows may show a vendor-defined logo wh
* Start `setup.exe` and follow the instructions.
* You may need to manually disable Secure Boot and then retry.
* The installer will launch Paint for editing the image.
* Be sure to always use the 24-bit BMP/DIB format.
* If Windows later restores the original boot loader, just reinstall.
* If you wish to change the image or other configuration, just reinstall.
* For advanced settings, edit `config.txt` before installing. No extra support provided!
@@ -48,9 +47,9 @@ The configuration options are described in `config.txt`, which the installer cop
The image path can be changed in the configuration file. The default path is `[EFI System Partition]\EFI\HackBGRT\splash.bmp`.
The image must be a 24-bit BMP file with a 54-byte header. That's a TrueColor BMP3 in Imagemagick, or 24-bit BMP/DIB in Microsoft Paint.
If you copy the file to ESP manually, note that the image must be a 24-bit BMP file with a 54-byte header. That's a TrueColor BMP3 in Imagemagick, or 24-bit BMP/DIB in Microsoft Paint.
Advanced users may edit the `config.txt` to define multiple images, in which case one is picked at random. The installer copies files whose `path` starts with `\EFI\HackBGRT\`.
Advanced users may edit the `config.txt` to define multiple images, in which case one is picked at random. The installer copies and converts files whose `path` starts with `\EFI\HackBGRT\`.
## Recovery

View File

@@ -16,8 +16,8 @@ boot=\EFI\HackBGRT\bootmgfw-original.efi
# - "remove" to remove the BGRT. Makes x and y meaningless.
# - "black" to use only a black image. Makes x and y meaningless.
# - "path=..." to read a BMP file.
# * NOTE: The installer will only install files with path=\EFI\HackBGRT\*.
# * NOTE: The file must be a 24-bit BMP file with a 54-byte header.
# * NOTE: For path=\EFI\HackBGRT\*, the installer will copy and convert the file if necessary.
# * NOTE: For other paths, make sure that the file is a 24-bit BMP file with a 54-byte header.
# * NOTE: The file must be on the EFI System Partition. Do not add a drive letter!
# Examples:
# - image=remove

View File

@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
/**
@@ -134,6 +136,32 @@ public class Setup: SetupHelper {
Console.WriteLine($"Installed {name} to {newName}.");
}
/**
* Install a single image file, with conversion to 24-bit BMP.
*/
protected void InstallImageFile(string name) {
var newName = Path.Combine(InstallPath, name);
// Load the image to check if it's valid.
Bitmap img;
try {
img = new Bitmap(name);
} catch {
throw new SetupException($"Failed to load image {name}.");
}
// Copy the bitmap into an empty 24-bit image (required by EFI).
using (Bitmap bmp = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb)) {
using (Graphics g = Graphics.FromImage(bmp)) {
g.DrawImageUnscaledAndClipped(img, new Rectangle(Point.Empty, img.Size));
}
try {
bmp.Save(newName, ImageFormat.Bmp);
} catch {
throw new SetupException($"Failed to install image {name} to {newName}.");
}
}
Console.WriteLine($"Installed image {name} to {newName}.");
}
/**
* Install files to ESP.
*/
@@ -162,7 +190,7 @@ public class Setup: SetupHelper {
var delim = "path=\\EFI\\HackBGRT\\";
var i = line.IndexOf(delim);
if (i > 0) {
InstallFile(line.Substring(i + delim.Length));
InstallImageFile(line.Substring(i + delim.Length));
}
}
if (!MsLoader.ReplaceWith(NewLoader)) {