2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2010,2012,2013 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
22 #include <grub/util/misc.h>
23 #include <grub/util/install.h>
24 #include <grub/i18n.h>
25 #include <grub/term.h>
26 #include <grub/font.h>
27 #include <grub/gfxmenu_view.h>
28 #include <grub/color.h>
29 #include <grub/emu/hostdisk.h>
46 static struct grub_video_palette_data ieee1275_palette
[256];
49 grub_util_render_label (const char *label_font
,
50 const char *label_bgcolor
,
51 const char *label_color
,
57 int i
, j
, k
, cptr
= 0;
60 const grub_uint8_t vals
[] = { 0xff, 0xda, 0xb3, 0x87, 0x54, 0x00 };
61 const grub_uint8_t vals2
[] = { 0xf3, 0xe7, 0xcd, 0xc0, 0xa5, 0x96,
62 0x77, 0x66, 0x3f, 0x27 };
65 struct grub_video_mode_info mode_info
;
67 grub_video_rgba_color_t fgcolor
;
68 grub_video_rgba_color_t bgcolor
;
71 out
= grub_util_fopen (output
, "wb");
76 grub_util_error (_("cannot open `%s': %s"), output
? : "stdout",
82 err
= grub_video_parse_color (label_color
, &fgcolor
);
84 grub_util_error (_("invalid color specification `%s'"), label_color
);
96 err
= grub_video_parse_color (label_bgcolor
, &bgcolor
);
98 grub_util_error (_("invalid color specification `%s'"), label_bgcolor
);
103 bgcolor
.green
= 0xff;
105 bgcolor
.alpha
= 0xff;
108 for (i
= 0; i
< 256; i
++)
109 ieee1275_palette
[i
].a
= 0xff;
111 for (i
= 0; i
< 6; i
++)
112 for (j
= 0; j
< 6; j
++)
113 for (k
= 0; k
< 6; k
++)
115 ieee1275_palette
[cptr
].r
= vals
[i
];
116 ieee1275_palette
[cptr
].g
= vals
[j
];
117 ieee1275_palette
[cptr
].b
= vals
[k
];
118 ieee1275_palette
[cptr
].a
= 0xff;
122 for (i
= 0; i
< 10; i
++)
124 ieee1275_palette
[cptr
].r
= vals2
[i
];
125 ieee1275_palette
[cptr
].g
= 0;
126 ieee1275_palette
[cptr
].b
= 0;
127 ieee1275_palette
[cptr
].a
= 0xff;
130 for (i
= 0; i
< 10; i
++)
132 ieee1275_palette
[cptr
].r
= 0;
133 ieee1275_palette
[cptr
].g
= vals2
[i
];
134 ieee1275_palette
[cptr
].b
= 0;
135 ieee1275_palette
[cptr
].a
= 0xff;
138 for (i
= 0; i
< 10; i
++)
140 ieee1275_palette
[cptr
].r
= 0;
141 ieee1275_palette
[cptr
].g
= 0;
142 ieee1275_palette
[cptr
].b
= vals2
[i
];
143 ieee1275_palette
[cptr
].a
= 0xff;
146 for (i
= 0; i
< 10; i
++)
148 ieee1275_palette
[cptr
].r
= vals2
[i
];
149 ieee1275_palette
[cptr
].g
= vals2
[i
];
150 ieee1275_palette
[cptr
].b
= vals2
[i
];
151 ieee1275_palette
[cptr
].a
= 0xff;
154 ieee1275_palette
[cptr
].r
= 0;
155 ieee1275_palette
[cptr
].g
= 0;
156 ieee1275_palette
[cptr
].b
= 0;
157 ieee1275_palette
[cptr
].a
= 0xff;
160 t
= canonicalize_file_name (label_font
);
163 grub_util_error (_("cannot open `%s': %s"), label_font
,
167 fontfull
= xasprintf ("(host)/%s", t
);
170 grub_font_loader_init ();
171 font
= grub_font_load (fontfull
);
174 grub_util_error (_("cannot open `%s': %s"), label_font
,
178 width
= grub_font_get_string_width (font
, text
) + 10;
179 height
= grub_font_get_height (font
);
181 mode_info
.width
= width
;
182 mode_info
.height
= height
;
183 mode_info
.pitch
= width
;
185 mode_info
.mode_type
= GRUB_VIDEO_MODE_TYPE_INDEX_COLOR
;
187 mode_info
.bytes_per_pixel
= 1;
188 mode_info
.number_of_colors
= 256;
190 grub_video_capture_start (&mode_info
, ieee1275_palette
,
191 ARRAY_SIZE (ieee1275_palette
));
193 fg
= grub_video_map_rgb (fgcolor
.red
,
196 bg
= grub_video_map_rgb (bgcolor
.red
,
200 grub_memset (grub_video_capture_get_framebuffer (), bg
, height
* width
);
201 grub_font_draw_string (text
, font
, fg
,
202 5, grub_font_get_ascent (font
));
205 head
.width
= grub_cpu_to_be16 (width
);
206 head
.height
= grub_cpu_to_be16 (height
);
207 fwrite (&head
, 1, sizeof (head
), out
);
208 fwrite (grub_video_capture_get_framebuffer (), 1, width
* height
, out
);
210 grub_video_capture_end ();