]> code.delx.au - refind/blob - refind/icns.c
New "Reboot to Firmware User Interface" feature.
[refind] / refind / icns.c
1 /*
2 * refit/icns.c
3 * Loader for .icns icon files
4 *
5 * Copyright (c) 2006-2007 Christoph Pfisterer
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the
18 * distribution.
19 *
20 * * Neither the name of Christoph Pfisterer nor the names of the
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #include "global.h"
38 #include "lib.h"
39 #include "icns.h"
40 #include "config.h"
41 #include "../refind/screen.h"
42
43 //
44 // well-known icons
45 //
46
47 typedef struct {
48 EG_IMAGE *Image;
49 CHAR16 *FileName;
50 UINTN PixelSize;
51 } BUILTIN_ICON;
52
53 BUILTIN_ICON BuiltinIconTable[BUILTIN_ICON_COUNT] = {
54 { NULL, L"func_about", 48 },
55 { NULL, L"func_reset", 48 },
56 { NULL, L"func_shutdown", 48 },
57 { NULL, L"func_exit", 48 },
58 { NULL, L"func_firmware", 48 },
59 { NULL, L"tool_shell", 48 },
60 { NULL, L"tool_part", 48 },
61 { NULL, L"tool_rescue", 48 },
62 { NULL, L"tool_apple_rescue", 48 },
63 { NULL, L"tool_mok_tool", 48 },
64 { NULL, L"vol_internal", 32 },
65 { NULL, L"vol_external", 32 },
66 { NULL, L"vol_optical", 32 },
67 };
68
69 EG_IMAGE * BuiltinIcon(IN UINTN Id)
70 {
71 if (Id >= BUILTIN_ICON_COUNT)
72 return NULL;
73
74 if (BuiltinIconTable[Id].Image == NULL) {
75 BuiltinIconTable[Id].Image = egFindIcon(BuiltinIconTable[Id].FileName, BuiltinIconTable[Id].PixelSize);
76 if (BuiltinIconTable[Id].Image == NULL)
77 BuiltinIconTable[Id].Image = DummyImage(BuiltinIconTable[Id].PixelSize);
78 } // if
79
80 return BuiltinIconTable[Id].Image;
81 }
82
83 //
84 // Load an icon for an operating system
85 //
86
87 // Load an OS icon from among the comma-delimited list provided in OSIconName.
88 // Searches for icons with extensions in the ICON_EXTENSIONS list (via
89 // egFindIcon()).
90 // Returns image data. On failure, returns an ugly "dummy" icon.
91 EG_IMAGE * LoadOSIcon(IN CHAR16 *OSIconName OPTIONAL, IN CHAR16 *FallbackIconName, BOOLEAN BootLogo)
92 {
93 EG_IMAGE *Image = NULL;
94 CHAR16 *CutoutName, BaseName[256];
95 UINTN Index = 0;
96
97 if (GlobalConfig.TextOnly) // skip loading if it's not used anyway
98 return NULL;
99
100 // First, try to find an icon from the OSIconName list....
101 while (((CutoutName = FindCommaDelimited(OSIconName, Index++)) != NULL) && (Image == NULL)) {
102 SPrint(BaseName, 255, L"%s_%s", BootLogo ? L"boot" : L"os", CutoutName);
103 Image = egFindIcon(BaseName, 128);
104 }
105
106 // If that fails, try again using the FallbackIconName....
107 if (Image == NULL) {
108 SPrint(BaseName, 255, L"%s_%s", BootLogo ? L"boot" : L"os", FallbackIconName);
109 Image = egFindIcon(BaseName, 128);
110 }
111
112 // If that fails and if BootLogo was set, try again using the "os_" start of the name....
113 if (BootLogo && (Image == NULL)) {
114 SPrint(BaseName, 255, L"os_%s", FallbackIconName);
115 Image = egFindIcon(BaseName, 128);
116 }
117
118 // If all of these fail, return the dummy image....
119 if (Image == NULL)
120 Image = DummyImage(128);
121
122 return Image;
123 } /* EG_IMAGE * LoadOSIcon() */
124
125
126 static EG_PIXEL BlackPixel = { 0x00, 0x00, 0x00, 0 };
127 //static EG_PIXEL YellowPixel = { 0x00, 0xff, 0xff, 0 };
128
129 EG_IMAGE * DummyImage(IN UINTN PixelSize)
130 {
131 EG_IMAGE *Image;
132 UINTN x, y, LineOffset;
133 CHAR8 *Ptr, *YPtr;
134
135 Image = egCreateFilledImage(PixelSize, PixelSize, TRUE, &BlackPixel);
136
137 LineOffset = PixelSize * 4;
138
139 YPtr = (CHAR8 *)Image->PixelData + ((PixelSize - 32) >> 1) * (LineOffset + 4);
140 for (y = 0; y < 32; y++) {
141 Ptr = YPtr;
142 for (x = 0; x < 32; x++) {
143 if (((x + y) % 12) < 6) {
144 *Ptr++ = 0;
145 *Ptr++ = 0;
146 *Ptr++ = 0;
147 } else {
148 *Ptr++ = 0;
149 *Ptr++ = 255;
150 *Ptr++ = 255;
151 }
152 *Ptr++ = 144;
153 }
154 YPtr += LineOffset;
155 }
156
157 return Image;
158 }