]> code.delx.au - refind/blob - refind/icns.c
Looks for refind_linux.conf first, then linux.conf, for Linux kernel configuration...
[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
42 //
43 // well-known icons
44 //
45
46 typedef struct {
47 EG_IMAGE *Image;
48 CHAR16 *Path;
49 UINTN PixelSize;
50 } BUILTIN_ICON;
51
52 BUILTIN_ICON BuiltinIconTable[BUILTIN_ICON_COUNT] = {
53 { NULL, L"icons\\func_about.icns", 48 },
54 { NULL, L"icons\\func_reset.icns", 48 },
55 { NULL, L"icons\\func_shutdown.icns", 48 },
56 { NULL, L"icons\\tool_shell.icns", 48 },
57 { NULL, L"icons\\tool_part.icns", 48 },
58 { NULL, L"icons\\tool_rescue.icns", 48 },
59 { NULL, L"icons\\vol_internal.icns", 32 },
60 { NULL, L"icons\\vol_external.icns", 32 },
61 { NULL, L"icons\\vol_optical.icns", 32 },
62 };
63
64 EG_IMAGE * BuiltinIcon(IN UINTN Id)
65 {
66 if (Id >= BUILTIN_ICON_COUNT)
67 return NULL;
68
69 if (BuiltinIconTable[Id].Image == NULL)
70 BuiltinIconTable[Id].Image = LoadIcnsFallback(SelfDir, BuiltinIconTable[Id].Path, BuiltinIconTable[Id].PixelSize);
71
72 return BuiltinIconTable[Id].Image;
73 }
74
75 //
76 // Load an icon for an operating system
77 //
78
79 // Load an OS icon from among the comma-delimited list provided in OSIconName.
80 EG_IMAGE * LoadOSIcon(IN CHAR16 *OSIconName OPTIONAL, IN CHAR16 *FallbackIconName, BOOLEAN BootLogo)
81 {
82 EG_IMAGE *Image;
83 CHAR16 *CutoutName;
84 CHAR16 FileName[256];
85 UINTN Index = 0;
86
87 if (GlobalConfig.TextOnly) // skip loading if it's not used anyway
88 return NULL;
89
90 // try the names from OSIconName
91 while ((CutoutName = FindCommaDelimited(OSIconName, Index++)) != NULL) {
92 SPrint(FileName, 255, L"icons\\%s_%s.icns", BootLogo ? L"boot" : L"os", CutoutName);
93
94 // try to load it
95 Image = egLoadIcon(SelfDir, FileName, 128);
96 if (Image != NULL)
97 return Image;
98 FreePool(CutoutName);
99 } // while
100
101 // try the fallback name
102 SPrint(FileName, 255, L"icons\\%s_%s.icns", BootLogo ? L"boot" : L"os", FallbackIconName);
103 Image = egLoadIcon(SelfDir, FileName, 128);
104 if (Image != NULL)
105 return Image;
106
107 // try the fallback name with os_ instead of boot_
108 if (BootLogo)
109 return LoadOSIcon(NULL, FallbackIconName, FALSE);
110
111 return DummyImage(128);
112 } /* EG_IMAGE * LoadOSIcon() */
113
114 //
115 // Load an image from a .icns file
116 //
117
118 EG_IMAGE * LoadIcns(IN EFI_FILE_HANDLE BaseDir, IN CHAR16 *FileName, IN UINTN PixelSize)
119 {
120 if (GlobalConfig.TextOnly) // skip loading if it's not used anyway
121 return NULL;
122 return egLoadIcon(BaseDir, FileName, PixelSize);
123 }
124
125 static EG_PIXEL BlackPixel = { 0x00, 0x00, 0x00, 0 };
126 //static EG_PIXEL YellowPixel = { 0x00, 0xff, 0xff, 0 };
127
128 EG_IMAGE * DummyImage(IN UINTN PixelSize)
129 {
130 EG_IMAGE *Image;
131 UINTN x, y, LineOffset;
132 CHAR8 *Ptr, *YPtr;
133
134 Image = egCreateFilledImage(PixelSize, PixelSize, TRUE, &BlackPixel);
135
136 LineOffset = PixelSize * 4;
137
138 YPtr = (CHAR8 *)Image->PixelData + ((PixelSize - 32) >> 1) * (LineOffset + 4);
139 for (y = 0; y < 32; y++) {
140 Ptr = YPtr;
141 for (x = 0; x < 32; x++) {
142 if (((x + y) % 12) < 6) {
143 *Ptr++ = 0;
144 *Ptr++ = 0;
145 *Ptr++ = 0;
146 } else {
147 *Ptr++ = 0;
148 *Ptr++ = 255;
149 *Ptr++ = 255;
150 }
151 *Ptr++ = 144;
152 }
153 YPtr += LineOffset;
154 }
155
156 return Image;
157 }
158
159 EG_IMAGE * LoadIcnsFallback(IN EFI_FILE_HANDLE BaseDir, IN CHAR16 *FileName, IN UINTN PixelSize)
160 {
161 EG_IMAGE *Image;
162 if (GlobalConfig.TextOnly) // skip loading if it's not used anyway
163 return NULL;
164
165 Image = LoadIcns(BaseDir, FileName, PixelSize);
166 if (Image == NULL) {
167 Image = DummyImage(PixelSize);
168 }
169 return Image;
170 }