OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
Bmf.c
Go to the documentation of this file.
1
8#include <UserFile.h>
9
10#include <Base.h>
11#include <Library/MemoryAllocationLib.h>
12#include <Library/DebugLib.h>
13#include <Library/BmpSupportLib.h>
14
15#include "BmfLib.h"
16
17EFI_STATUS
19 IN OUT GUI_IMAGE *Image,
20 IN VOID *BmpImage,
21 IN UINTN BmpImageSize
22 )
23{
24 EFI_STATUS Status;
25 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Buffer;
26 UINTN BufferSize;
27 UINTN BmpHeight;
28 UINTN BmpWidth;
29
30 ASSERT (Image != NULL);
31 ASSERT (BmpImage != NULL);
32 ASSERT (BmpImageSize > 0);
33
34 Buffer = NULL;
35 Status = TranslateBmpToGopBlt (
36 BmpImage,
37 BmpImageSize,
38 &Buffer,
39 &BufferSize,
40 &BmpHeight,
41 &BmpWidth
42 );
43 if (EFI_ERROR (Status)) {
44 return Status;
45 }
46
47 // TODO: Update the lib?
48 ASSERT ((UINT32)BmpHeight == BmpHeight);
49 ASSERT ((UINT32)BmpWidth == BmpWidth);
50
51 Image->Height = (UINT32)BmpHeight;
52 Image->Width = (UINT32)BmpWidth;
53 Image->Buffer = Buffer;
54 return EFI_SUCCESS;
55}
56
57int
59 int argc,
60 char *argv[]
61 )
62{
63 BOOLEAN Result;
64 GUI_FONT_CONTEXT Context;
65 UINT8 *FontImage;
66 UINT32 FontImageSize;
67 UINT8 *FontMetrics;
68 UINT32 FontMetricsSize;
69 GUI_IMAGE Label;
70 EFI_STATUS Status;
71 VOID *BmpImage;
72 UINT32 BmpImageSize;
73
74 if (argc != 3) {
75 DEBUG ((DEBUG_ERROR, "./Bmf <FontImage> <FontMetrics>"));
76 return -1;
77 }
78
79 FontImage = UserReadFile (argv[1], &FontImageSize);
80 FontMetrics = UserReadFile (argv[2], &FontMetricsSize);
81 Result = GuiFontConstruct (&Context, FontImage, FontImageSize, FontMetrics, FontMetricsSize, 1);
82 if (!Result) {
83 DEBUG ((DEBUG_WARN, "BMF: Helvetica failed\n"));
84 return -1;
85 }
86
87 Result = GuiGetLabel (&Label, &Context, L"Time Machine HD", L_STR_LEN ("Time Machine HD"), FALSE);
88 if (!Result) {
89 DEBUG ((DEBUG_WARN, "BMF: label failed\n"));
90 return -1;
91 }
92
93 DEBUG ((DEBUG_WARN, "Result: %u %u\n", Label.Height, Label.Width));
94
95 BmpImage = NULL;
96 BmpImageSize = 0;
97 Status = TranslateGopBltToBmp (
98 Label.Buffer,
99 Label.Height,
100 Label.Width,
101 &BmpImage,
102 &BmpImageSize
103 );
104 if (EFI_ERROR (Status)) {
105 return -1;
106 }
107
108 UserWriteFile ("Label.bmp", BmpImage, BmpImageSize);
109
110 FreePool (BmpImage);
111
112 FreePool (Context.FontImage.Buffer);
113 FreePool (Label.Buffer);
114
115 return 0;
116}
BOOLEAN GuiFontConstruct(OUT GUI_FONT_CONTEXT *Context, IN VOID *FontImage, IN UINTN FontImageSize, IN VOID *FileBuffer, IN UINT32 FileSize, IN UINT8 Scale)
Definition BitmapFont.c:718
BOOLEAN GuiGetLabel(OUT GUI_IMAGE *LabelImage, IN CONST GUI_FONT_CONTEXT *Context, IN CONST CHAR16 *String, IN UINTN StringLen, IN BOOLEAN Inverted)
Definition BitmapFont.c:609
EFI_STATUS GuiBmpToImage(IN OUT GUI_IMAGE *Image, IN VOID *BmpImage, IN UINTN BmpImageSize)
Definition Bmf.c:18
#define L_STR_LEN(String)
Definition OcStringLib.h:26
OC_TYPING_BUFFER_ENTRY Buffer[OC_TYPING_BUFFER_SIZE]
Definition OcTypingLib.h:42
UINT8 * UserReadFile(IN CONST CHAR8 *FileName, OUT UINT32 *Size)
Definition UserFile.c:62
VOID UserWriteFile(IN CONST CHAR8 *FileName, IN CONST VOID *Data, IN UINT32 Size)
Definition UserFile.c:116
#define ASSERT(x)
Definition coder.h:55
int ENTRY_POINT(void)
GUI_IMAGE FontImage
Definition BmfLib.h:26
UINT32 Height
Definition OpenCanopy.h:128
EFI_GRAPHICS_OUTPUT_BLT_PIXEL * Buffer
Definition OpenCanopy.h:129
UINT32 Width
Definition OpenCanopy.h:127