3 * Loader for .icns icon files
5 * Copyright (c) 2006-2007 Christoph Pfisterer
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
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.
41 #include "mystrings.h"
42 #include "../refind/screen.h"
54 BUILTIN_ICON BuiltinIconTable
[BUILTIN_ICON_COUNT
] = {
55 { NULL
, L
"func_about", ICON_SIZE_SMALL
},
56 { NULL
, L
"func_reset", ICON_SIZE_SMALL
},
57 { NULL
, L
"func_shutdown", ICON_SIZE_SMALL
},
58 { NULL
, L
"func_exit", ICON_SIZE_SMALL
},
59 { NULL
, L
"func_firmware", ICON_SIZE_SMALL
},
60 { NULL
, L
"func_csr_rotate", ICON_SIZE_SMALL
},
61 { NULL
, L
"tool_shell", ICON_SIZE_SMALL
},
62 { NULL
, L
"tool_part", ICON_SIZE_SMALL
},
63 { NULL
, L
"tool_rescue", ICON_SIZE_SMALL
},
64 { NULL
, L
"tool_apple_rescue", ICON_SIZE_SMALL
},
65 { NULL
, L
"tool_windows_rescue", ICON_SIZE_SMALL
},
66 { NULL
, L
"tool_mok_tool", ICON_SIZE_SMALL
},
67 { NULL
, L
"tool_fwupdate", ICON_SIZE_SMALL
},
68 { NULL
, L
"tool_memtest", ICON_SIZE_SMALL
},
69 { NULL
, L
"tool_netboot", ICON_SIZE_SMALL
},
70 { NULL
, L
"vol_internal", ICON_SIZE_BADGE
},
71 { NULL
, L
"vol_external", ICON_SIZE_BADGE
},
72 { NULL
, L
"vol_optical", ICON_SIZE_BADGE
},
73 { NULL
, L
"vol_net", ICON_SIZE_BADGE
},
76 EG_IMAGE
* BuiltinIcon(IN UINTN Id
)
78 if (Id
>= BUILTIN_ICON_COUNT
)
81 if (BuiltinIconTable
[Id
].Image
== NULL
) {
82 BuiltinIconTable
[Id
].Image
= egFindIcon(BuiltinIconTable
[Id
].FileName
, GlobalConfig
.IconSizes
[BuiltinIconTable
[Id
].IconSize
]);
83 if (BuiltinIconTable
[Id
].Image
== NULL
)
84 BuiltinIconTable
[Id
].Image
= DummyImage(GlobalConfig
.IconSizes
[BuiltinIconTable
[Id
].IconSize
]);
87 return BuiltinIconTable
[Id
].Image
;
91 // Load an icon for an operating system
94 // Load an OS icon from among the comma-delimited list provided in OSIconName.
95 // Searches for icons with extensions in the ICON_EXTENSIONS list (via
97 // Returns image data. On failure, returns an ugly "dummy" icon.
98 EG_IMAGE
* LoadOSIcon(IN CHAR16
*OSIconName OPTIONAL
, IN CHAR16
*FallbackIconName
, BOOLEAN BootLogo
)
100 EG_IMAGE
*Image
= NULL
;
101 CHAR16
*CutoutName
, BaseName
[256];
104 if (GlobalConfig
.TextOnly
) // skip loading if it's not used anyway
107 // First, try to find an icon from the OSIconName list....
108 while (((CutoutName
= FindCommaDelimited(OSIconName
, Index
++)) != NULL
) && (Image
== NULL
)) {
109 SPrint(BaseName
, 255, L
"%s_%s", BootLogo
? L
"boot" : L
"os", CutoutName
);
110 Image
= egFindIcon(BaseName
, GlobalConfig
.IconSizes
[ICON_SIZE_BIG
]);
113 // If that fails, try again using the FallbackIconName....
115 SPrint(BaseName
, 255, L
"%s_%s", BootLogo
? L
"boot" : L
"os", FallbackIconName
);
116 Image
= egFindIcon(BaseName
, GlobalConfig
.IconSizes
[ICON_SIZE_BIG
]);
119 // If that fails and if BootLogo was set, try again using the "os_" start of the name....
120 if (BootLogo
&& (Image
== NULL
)) {
121 SPrint(BaseName
, 255, L
"os_%s", FallbackIconName
);
122 Image
= egFindIcon(BaseName
, GlobalConfig
.IconSizes
[ICON_SIZE_BIG
]);
125 // If all of these fail, return the dummy image....
127 Image
= DummyImage(GlobalConfig
.IconSizes
[ICON_SIZE_BIG
]);
130 } /* EG_IMAGE * LoadOSIcon() */
133 static EG_PIXEL BlackPixel
= { 0x00, 0x00, 0x00, 0 };
134 //static EG_PIXEL YellowPixel = { 0x00, 0xff, 0xff, 0 };
136 EG_IMAGE
* DummyImage(IN UINTN PixelSize
)
139 UINTN x
, y
, LineOffset
;
142 Image
= egCreateFilledImage(PixelSize
, PixelSize
, TRUE
, &BlackPixel
);
144 LineOffset
= PixelSize
* 4;
146 YPtr
= (CHAR8
*)Image
->PixelData
+ ((PixelSize
- 32) >> 1) * (LineOffset
+ 4);
147 for (y
= 0; y
< 32; y
++) {
149 for (x
= 0; x
< 32; x
++) {
150 if (((x
+ y
) % 12) < 6) {