Skip to content
Permalink
Browse files

10358 our console should support 256 colors

Reviewed by: Andy Fiddaman <andy@omniosce.org>
Reviewed by: Andy Stormont <astormont@racktopsystems.com>
Approved by: Robert Mustacchi <rm@joyent.com>
  • Loading branch information
tsoome committed Feb 2, 2019
1 parent 811964c commit a4e6b9b671bd0b8581ffd85bbc50cdd0bfe18b13
@@ -32,6 +32,7 @@
#include <sys/visual_io.h>
#include <sys/multiboot2.h>
#include <sys/font.h>
#include <sys/rgb.h>
#include <sys/endian.h>
#include <gfx_fb.h>
#include <pnglite.h>
@@ -156,9 +157,7 @@ gfx_parse_mode_str(char *str, int *x, int *y, int *depth)
uint32_t
gfx_fb_color_map(uint8_t index)
{
uint8_t c;
int pos, size;
uint32_t color;
rgb_t rgb;

if (gfx_fb.framebuffer_common.framebuffer_type !=
MULTIBOOT_FRAMEBUFFER_TYPE_RGB) {
@@ -168,22 +167,16 @@ gfx_fb_color_map(uint8_t index)
return (index);
}

c = cmap4_to_24.red[index];
pos = gfx_fb.u.fb2.framebuffer_red_field_position;
size = gfx_fb.u.fb2.framebuffer_red_mask_size;
color = ((c >> (8 - size)) & ((1 << size) - 1)) << pos;
rgb.red.pos = gfx_fb.u.fb2.framebuffer_red_field_position;
rgb.red.size = gfx_fb.u.fb2.framebuffer_red_mask_size;

c = cmap4_to_24.green[index];
pos = gfx_fb.u.fb2.framebuffer_green_field_position;
size = gfx_fb.u.fb2.framebuffer_green_mask_size;
color |= ((c >> (8 - size)) & ((1 << size) - 1)) << pos;
rgb.green.pos = gfx_fb.u.fb2.framebuffer_green_field_position;
rgb.green.size = gfx_fb.u.fb2.framebuffer_green_mask_size;

c = cmap4_to_24.blue[index];
pos = gfx_fb.u.fb2.framebuffer_blue_field_position;
size = gfx_fb.u.fb2.framebuffer_blue_mask_size;
color |= ((c >> (8 - size)) & ((1 << size) - 1)) << pos;
rgb.blue.pos = gfx_fb.u.fb2.framebuffer_blue_field_position;
rgb.blue.size = gfx_fb.u.fb2.framebuffer_blue_mask_size;

return (color);
return (rgb_color_map(&rgb, index));
}

static bool
@@ -228,13 +221,18 @@ color_name_to_ansi(const char *name, int *val)
static int
gfx_set_colors(struct env_var *ev, int flags, const void *value)
{
int val = 0;
int val = 0, limit;
char buf[2];
const void *evalue;

if (value == NULL)
return (CMD_OK);

if (gfx_fb.framebuffer_common.framebuffer_bpp < 24)
limit = 7;
else
limit = 255;

if (color_name_to_ansi(value, &val)) {
snprintf(buf, sizeof (buf), "%d", val);
evalue = buf;
@@ -245,16 +243,18 @@ gfx_set_colors(struct env_var *ev, int flags, const void *value)
val = (int)strtol(value, &end, 0);
if (errno != 0 || *end != '\0') {
printf("Allowed values are either ansi color name or "
"number from range [0-7].\n");
"number from range [0-7]%s.\n",
limit == 7 ? "" : " or [16-255]");
return (CMD_OK);
}
evalue = value;
}

/* invalid value? */
if (val < 0 || val > 7) {
if ((val < 0 || val > limit) || (val > 7 && val < 16)) {
printf("Allowed values are either ansi color name or "
"number from range [0-7].\n");
"number from range [0-7]%s.\n",
limit == 7 ? "" : " or [16-255]");
return (CMD_OK);
}

@@ -314,7 +314,7 @@ gfx_set_inverses(struct env_var *ev, int flags, const void *value)
void
gfx_framework_init(struct visual_ops *fb_ops)
{
int rc;
int rc, limit;
char *env, buf[2];
#if defined(EFI)
extern EFI_GRAPHICS_OUTPUT *gop;
@@ -326,6 +326,11 @@ gfx_framework_init(struct visual_ops *fb_ops)
}
#endif

if (gfx_fb.framebuffer_common.framebuffer_bpp < 24)
limit = 7;
else
limit = 255;

/* Add visual io callbacks */
fb_ops->cons_clear = gfx_fb_cons_clear;
fb_ops->cons_copy = gfx_fb_cons_copy;
@@ -366,15 +371,15 @@ gfx_framework_init(struct visual_ops *fb_ops)
env = getenv("tem.fg_color");
if (env != NULL) {
rc = (int)strtol(env, NULL, 0);
if (rc >= 0 && rc <= 7)
if ((rc >= 0 && rc <= limit) && (rc <= 7 || rc >= 16))
gfx_fg = rc;
unsetenv("tem.fg_color");
}

env = getenv("tem.bg_color");
if (env != NULL) {
rc = (int)strtol(env, NULL, 0);
if (rc >= 0 && rc <= 7)
if ((rc >= 0 && rc <= limit) && (rc <= 7 || rc >= 16))
gfx_bg = rc;
unsetenv("tem.bg_color");
}
@@ -1183,7 +1183,6 @@ tem_setparam(struct tem_vt_state *tem, int count, int newparam)
}
}


/*
* select graphics mode based on the param vals stored in a_params
*/
@@ -1265,6 +1264,32 @@ tem_selgraph(struct tem_vt_state *tem)
tem->tvs_flags &= ~TEM_ATTR_BRIGHT_FG;
break;

case 38:
/* We should have at least 3 parameters */
if (curparam < 3)
break;

/*
* 256 and truecolor needs depth at least 24, but
* we still need to process the sequence.
*/
count++;
curparam--;
param = tem->tvs_params[count];
switch (param) {
case 5: /* 256 colors */
count++;
curparam--;
if (tems.ts_pdepth < 24)
break;
tem->tvs_fg_color = tem->tvs_params[count];
tem->tvs_flags &= ~TEM_ATTR_BRIGHT_FG;
break;
default:
break;
}
break;

case 39:
/*
* Reset the foreground colour and brightness.
@@ -1288,6 +1313,32 @@ tem_selgraph(struct tem_vt_state *tem)
tem->tvs_flags &= ~TEM_ATTR_BRIGHT_BG;
break;

case 48:
/* We should have at least 3 parameters */
if (curparam < 3)
break;

/*
* 256 and truecolor needs depth at least 24, but
* we still need to process the sequence.
*/
count++;
curparam--;
param = tem->tvs_params[count];
switch (param) {
case 5: /* 256 colors */
count++;
curparam--;
if (tems.ts_pdepth < 24)
break;
tem->tvs_bg_color = tem->tvs_params[count];
tem->tvs_flags &= ~TEM_ATTR_BRIGHT_FG;
break;
default:
break;
}
break;

case 49:
/*
* Reset the background colour and brightness.
@@ -2233,6 +2284,9 @@ tem_pix_bit2pix(struct tem_vt_state *tem, term_char_t c)
void (*fp)(struct tem_vt_state *, tem_char_t,
unsigned char, unsigned char);

fg = DEFAULT_ANSI_FOREGROUND;
bg = DEFAULT_ANSI_BACKGROUND;

tem_get_color(&fg, &bg, c);
switch (tems.ts_pdepth) {
case 4:
@@ -2334,6 +2388,8 @@ tem_cls(struct tem_vt_state *tem)
TEM_ATTR_SCREEN_REVERSE);
c.tc_char = TEM_ATTR(attr);

fg_color = DEFAULT_ANSI_FOREGROUND;
bg_color = DEFAULT_ANSI_BACKGROUND;
tem_get_color(&fg_color, &bg_color, c);
cl.bg_color = bg_color;
(void)tems_cls(&cl);
@@ -2587,6 +2643,8 @@ tem_pix_cursor(struct tem_vt_state *tem, short action)
TEM_ATTR_REVERSE);
c.tc_char = TEM_ATTR(attr);

fg = DEFAULT_ANSI_FOREGROUND;
bg = DEFAULT_ANSI_BACKGROUND;
tem_get_color(&fg, &bg, c);

switch (tems.ts_pdepth) {
@@ -2733,15 +2791,24 @@ tem_get_attr(struct tem_vt_state *tem, text_color_t *fg,
static void
tem_get_color(text_color_t *fg, text_color_t *bg, term_char_t c)
{
if (TEM_CHAR_ATTR(c.tc_char) & (TEM_ATTR_BRIGHT_FG | TEM_ATTR_BOLD))
*fg = brt_xlate[c.tc_fg_color];
else
*fg = dim_xlate[c.tc_fg_color];
if (c.tc_fg_color < 16) {
if (TEM_CHAR_ATTR(c.tc_char) &
(TEM_ATTR_BRIGHT_FG | TEM_ATTR_BOLD))
*fg = brt_xlate[c.tc_fg_color];
else
*fg = dim_xlate[c.tc_fg_color];
} else {
*fg = c.tc_fg_color;
}

if (TEM_CHAR_ATTR(c.tc_char) & TEM_ATTR_BRIGHT_BG)
*bg = brt_xlate[c.tc_bg_color];
else
*bg = dim_xlate[c.tc_bg_color];
if (c.tc_bg_color < 16) {
if (TEM_CHAR_ATTR(c.tc_char) & TEM_ATTR_BRIGHT_BG)
*bg = brt_xlate[c.tc_bg_color];
else
*bg = dim_xlate[c.tc_bg_color];
} else {
*bg = c.tc_bg_color;
}
}

void
@@ -640,7 +640,6 @@ vidc_init(struct console *cp, int arg)
return (0);

vidc_started = 1;
gfx_framework_init(&fb_ops);

/*
* Check Miscellaneous Output Register (Read at 3CCh, Write at 3C2h)
@@ -676,6 +675,7 @@ vidc_init(struct console *cp, int arg)
}
}

gfx_framework_init(&fb_ops);
rc = tem_info_init(cp);

if (rc != 0) {
@@ -87,6 +87,69 @@ const text_cmap_t cmap4_to_24 = {
};
/* END CSTYLED */

static uint32_t
rgb_to_color(const rgb_t *rgb, uint8_t r, uint8_t g, uint8_t b)
{
uint32_t color;
int pos, size;

pos = rgb->red.pos;
size = rgb->red.size;
color = ((r >> (8 - size)) & ((1 << size) - 1)) << pos;

pos = rgb->green.pos;
size = rgb->green.size;
color |= ((g >> (8 - size)) & ((1 << size) - 1)) << pos;

pos = rgb->blue.pos;
size = rgb->blue.size;
color |= ((b >> (8 - size)) & ((1 << size) - 1)) << pos;

return (color);
}

uint32_t
rgb_color_map(const rgb_t *rgb, uint8_t index)
{
uint32_t color, code, gray, level;

if (index < 16) {
color = rgb_to_color(rgb, cmap4_to_24.red[index],
cmap4_to_24.green[index], cmap4_to_24.blue[index]);
return (color);
}

/* 6x6x6 color cube */
if (index > 15 && index < 232) {
uint32_t red, green, blue;

for (red = 0; red < 6; red++) {
for (green = 0; green < 6; green++) {
for (blue = 0; blue < 6; blue++) {
code = 16 + (red * 36) +
(green * 6) + blue;
if (code != index)
continue;
red = red ? (red * 40 + 55) : 0;
green = green ? (green * 40 + 55) : 0;
blue = blue ? (blue * 40 + 55) : 0;
color = rgb_to_color(rgb, red, green,
blue);
return (color);
}
}
}
}

/* colors 232-255 are a grayscale ramp */
for (gray = 0; gray < 24; gray++) {
level = (gray * 10) + 8;
code = 232 + gray;
if (code == index)
break;
}
return (rgb_to_color(rgb, level, level, level));
}
/*
* Fonts are statically linked with this module. At some point an
* RFE might be desireable to allow dynamic font loading. The

0 comments on commit a4e6b9b

Please sign in to comment.
You can’t perform that action at this time.