changeset 20185:d3b17b1cf245

13347 loader: gfx_fb_putimage 8 bit color translation is not good Reviewed by: Jason King <jason.brian.king@gmail.com> Approved by: Robert Mustacchi <rm@fingolfin.org>
author Toomas Soome <tsoome@me.com>
date Sat, 05 Dec 2020 22:37:28 +0200
parents 227baaa00ea6
children 28fe0f57abf4
files usr/src/boot/Makefile.version usr/src/boot/sys/boot/common/gfx_fb.c usr/src/boot/sys/boot/i386/libi386/vbe.h usr/src/boot/sys/boot/i386/libi386/vidconsole.c
diffstat 4 files changed, 60 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/boot/Makefile.version	Thu Nov 19 09:41:34 2020 -0600
+++ b/usr/src/boot/Makefile.version	Sat Dec 05 22:37:28 2020 +0200
@@ -34,4 +34,4 @@
 # Use date like formatting here, YYYY.MM.DD.XX, without leading zeroes.
 # The version is processed from left to right, the version number can only
 # be increased.
-BOOT_VERSION = $(LOADER_VERSION)-2020.12.04.2
+BOOT_VERSION = $(LOADER_VERSION)-2020.12.05.0
--- a/usr/src/boot/sys/boot/common/gfx_fb.c	Thu Nov 19 09:41:34 2020 -0600
+++ b/usr/src/boot/sys/boot/common/gfx_fb.c	Sat Dec 05 22:37:28 2020 +0200
@@ -27,6 +27,7 @@
 #include <efilib.h>
 #else
 #include <btxv86.h>
+#include <vbe.h>
 #endif
 #include <sys/tem_impl.h>
 #include <sys/consplat.h>
@@ -1205,7 +1206,7 @@
 	struct vis_consdisplay da;
 	uint32_t i, j, x, y, fheight, fwidth, color;
 	int fbpp;
-	uint8_t r, g, b, a, *p;
+	uint8_t r, g, b, a;
 	bool scale = false;
 	bool trace = false;
 
@@ -1433,40 +1434,74 @@
 			    << gfx_fb.u.fb2.framebuffer_blue_field_position;
 
 			switch (gfx_fb.framebuffer_common.framebuffer_bpp) {
+#if !defined(EFI)
 			case 8: {
 				uint32_t best, dist, k;
 				int diff;
 
+				/* if alpha is 0, use screen bg color */
+				if (a == 0) {
+					text_color_t fg, bg;
+
+					tem_get_colors(
+					    (tem_vt_state_t)tems.ts_active,
+					    &fg, &bg);
+					da.data[j] = gfx_fb_color_map(bg);
+					break;
+				}
+
 				color = 0;
-				best = 256 * 256 * 256;
-				for (k = 0; k < 16; k++) {
-					diff = r - cmap4_to_24.red[k];
+				best = CMAP_SIZE * CMAP_SIZE * CMAP_SIZE;
+				for (k = 0; k < CMAP_SIZE; k++) {
+					diff = r - pe8[k].Red;
 					dist = diff * diff;
-					diff = g - cmap4_to_24.green[k];
+					diff = g - pe8[k].Green;
+					dist += diff * diff;
+					diff = b - pe8[k].Blue;
 					dist += diff * diff;
-					diff = b - cmap4_to_24.blue[k];
-					dist += diff * diff;
+
+					if (dist == 0)
+						break;
 
 					if (dist < best) {
 						color = k;
 						best = dist;
-						if (dist == 0)
-							break;
 					}
 				}
-				da.data[j] = solaris_color_to_pc_color[color];
+				if (k == CMAP_SIZE)
+					k = color;
+				da.data[j] = (k < 16) ?
+				    solaris_color_to_pc_color[k] : k;
 				break;
 			}
 			case 15:
 			case 16:
+				/* if alpha is 0, use screen bg color */
+				if (a == 0) {
+					text_color_t fg, bg;
+
+					tem_get_colors(
+					    (tem_vt_state_t)tems.ts_active,
+					    &fg, &bg);
+					color = gfx_fb_color_map(bg);
+				}
 				*(uint16_t *)(da.data+j) = color;
 				break;
 			case 24:
-				p = (uint8_t *)&color;
-				da.data[j] = p[0];
-				da.data[j+1] = p[1];
-				da.data[j+2] = p[2];
+				/* if alpha is 0, use screen bg color */
+				if (a == 0) {
+					text_color_t fg, bg;
+
+					tem_get_colors(
+					    (tem_vt_state_t)tems.ts_active,
+					    &fg, &bg);
+					color = gfx_fb_color_map(bg);
+				}
+				da.data[j] = ((uint8_t *)&color)[0];
+				da.data[j + 1] = ((uint8_t *)&color)[1];
+				da.data[j + 2] = ((uint8_t *)&color)[2];
 				break;
+#endif
 			case 32:
 				color |= a << 24;
 				*(uint32_t *)(da.data+j) = color;
--- a/usr/src/boot/sys/boot/i386/libi386/vbe.h	Thu Nov 19 09:41:34 2020 -0600
+++ b/usr/src/boot/sys/boot/i386/libi386/vbe.h	Sat Dec 05 22:37:28 2020 +0200
@@ -142,6 +142,7 @@
 
 #define	CMAP_SIZE		256	/* Number of colors in palette */
 
+extern struct paletteentry pe8[CMAP_SIZE];
 extern int palette_format;
 
 /* high-level VBE helpers, from vbe.c */
--- a/usr/src/boot/sys/boot/i386/libi386/vidconsole.c	Thu Nov 19 09:41:34 2020 -0600
+++ b/usr/src/boot/sys/boot/i386/libi386/vidconsole.c	Sat Dec 05 22:37:28 2020 +0200
@@ -78,6 +78,9 @@
 static struct vis_modechg_arg *modechg_arg;
 static tem_vt_state_t tem;
 
+/* RGB colors for 8-bit depth */
+struct paletteentry pe8[CMAP_SIZE];
+
 #define	KEYBUFSZ	10
 #define	DEFAULT_FGCOLOR	7
 #define	DEFAULT_BGCOLOR	0
@@ -542,7 +545,6 @@
 vidc_vbe_cons_put_cmap(struct vis_cmap *cm)
 {
 	int i, rc;
-	struct paletteentry pe;
 	rgb_t rgb;
 	uint32_t c;
 
@@ -568,8 +570,6 @@
 	rgb.blue.pos = gfx_fb.u.fb2.framebuffer_blue_field_position;
 	rgb.blue.size = gfx_fb.u.fb2.framebuffer_blue_mask_size;
 
-	pe.Alignment = 0;
-
 	/*
 	 * The first 16 colors need to be in VGA color order.
 	 */
@@ -582,10 +582,12 @@
 		} else {
 			c = rgb_color_map(&rgb, i);
 		}
-		pe.Red = (c >> rgb.red.pos) & ((1 << rgb.red.size) - 1);
-		pe.Green = (c >> rgb.green.pos) & ((1 << rgb.green.size) - 1);
-		pe.Blue = (c >> rgb.blue.pos) & ((1 << rgb.blue.size) - 1);
-		rc = vbe_set_palette(&pe, i);
+		pe8[i].Red = (c >> rgb.red.pos) & ((1 << rgb.red.size) - 1);
+		pe8[i].Green =
+		    (c >> rgb.green.pos) & ((1 << rgb.green.size) - 1);
+		pe8[i].Blue = (c >> rgb.blue.pos) & ((1 << rgb.blue.size) - 1);
+		pe8[i].Alignment = 0;
+		rc = vbe_set_palette(&pe8[i], i);
 	}
 	return (rc);
 }