2 * Copyright (c) 2013 The FreeBSD Foundation
5 * This software was developed by Aleksandr Rybalko under sponsorship from the
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
35 #include <dev/vt/colors/vt_termcolors.h>
38 unsigned char r; /* Red percentage value. */
39 unsigned char g; /* Green percentage value. */
40 unsigned char b; /* Blue percentage value. */
42 {0, 0, 0}, /* black */
43 {50, 0, 0}, /* dark red */
44 {0, 50, 0}, /* dark green */
45 {77, 63, 0}, /* dark yellow */
46 {20, 40, 64}, /* dark blue */
47 {50, 0, 50}, /* dark magenta */
48 {0, 50, 50}, /* dark cyan */
49 {75, 75, 75}, /* light gray */
51 {18, 20, 21}, /* dark gray */
52 {100, 0, 0}, /* light red */
53 {0, 100, 0}, /* light green */
54 {100, 100, 0}, /* light yellow */
55 {45, 62, 81}, /* light blue */
56 {100, 0, 100}, /* light magenta */
57 {0, 100, 100}, /* light cyan */
58 {100, 100, 100}, /* white */
62 * Between console's palette and VGA's one:
63 * - blue and red are swapped (1 <-> 4)
64 * - yellow ad cyan are swapped (3 <-> 6)
66 static const int cons_to_vga_colors[16] = {
67 0, 4, 2, 6, 1, 5, 3, 7,
68 0, 4, 2, 6, 1, 5, 3, 7
72 vt_generate_cons_palette(uint32_t *palette, int format, uint32_t rmax,
73 int roffset, uint32_t gmax, int goffset, uint32_t bmax, int boffset)
77 #define CF(_f, _i) ((_f ## max * color_def[(_i)]._f / 100) << _f ## offset)
78 for (i = 0; i < 16; i++) {
80 case COLOR_FORMAT_VGA:
81 palette[i] = cons_to_vga_colors[i];
83 case COLOR_FORMAT_RGB:
84 palette[i] = CF(r, i) | CF(g, i) | CF(b, i);