Patch for fbterm 1.5, related to the ben lcd

Lluís Batlle i Rossell viric at viric.name
Sat Jan 7 07:04:40 EST 2012


Hello,

I wrote a patch for fbterm, so text looks a bit better on it.

It simply balances the green on every odd row between two pixels, as explained
in http://en.qi-hardware.com/wiki/LCD#Specifications. This means there is
a low-pass filter on the green channel, and so the text less sharp.

So, apply if you want it.

Any ideas to get sharper text, welcome. :)

Regards,
Lluís.
-------------- next part --------------
Patch to get the fbterm 1.5 display somewhat better the gliphs on the Ben LCD.

Author: Lluís Batlle i Rossell

diff --git a/src/screen.cpp b/src/screen.cpp
index 08a8e89..115d946 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -469,7 +469,8 @@ void Screen::drawGlyph(u32 x, u32 y, u8 fc, u8 bc, u16 code, bool dw, bool clip)
 		u8 *pm = pixmap + (rects[num].sy - y) * glyph->pitch + (rects[num].sx - x);
 
 		for (; h--; pm += glyph->pitch) {
-			draw(xoffset + offsetY(rects[num].sy++), pm, w, fc, bc);
+			draw(xoffset + offsetY(rects[num].sy), rects[num].sy, pm, w, fc, bc);
+            rects[num].sy++;
 		}
 	}
 
diff --git a/src/screen_render.cpp b/src/screen_render.cpp
index 3bf1bdb..7fc17de 100644
--- a/src/screen_render.cpp
+++ b/src/screen_render.cpp
@@ -28,7 +28,7 @@
 #define fb_writel(addr, val) (*(volatile u32 *)(addr) = (val))
 
 typedef void (*fillFun)(u32 offset, u32 width, u8 color);
-typedef void (*drawFun)(u32 offset, u8 *pixmap, u32 width, u8 fc, u8 bc);
+typedef void (*drawFun)(u32 offset, u32 y, u8 *pixmap, u32 width, u8 fc, u8 bc);
 
 static fillFun fill;
 static drawFun draw;
@@ -160,7 +160,7 @@ static void fillXBg(u32 offset, u32 width, u8 color)
 	}
 }
 
-static void draw8(u32 offset, u8 *pixmap, u32 width, u8 fc, u8 bc)
+static void draw8(u32 offset, u32 y, u8 *pixmap, u32 width, u8 fc, u8 bc)
 {
 	bool isfg;
 	u8 *dst = fbdev_mem + offset;
@@ -171,10 +171,10 @@ static void draw8(u32 offset, u8 *pixmap, u32 width, u8 fc, u8 bc)
 	}
 }
 
-static void draw8Bg(u32 offset, u8 *pixmap, u32 width, u8 fc, u8 bc)
+static void draw8Bg(u32 offset, u32 y, u8 *pixmap, u32 width, u8 fc, u8 bc)
 {
 	if (bc != bgcolor) {
-		draw8(offset, pixmap, width, fc, bc);
+		draw8(offset, y, pixmap, width, fc, bc);
 		return;
 	}
 
@@ -190,7 +190,7 @@ static void draw8Bg(u32 offset, u8 *pixmap, u32 width, u8 fc, u8 bc)
 
 #define drawX(bits, lred, lgreen, lblue, type, fbwrite) \
  \
-static void draw##bits(u32 offset, u8 *pixmap, u32 width, u8 fc, u8 bc) \
+static void draw##bits(u32 offset, u32 y, u8 *pixmap, u32 width, u8 fc, u8 bc) \
 { \
 	u8 red, green, blue; \
 	u8 pixel; \
@@ -215,14 +215,46 @@ static void draw##bits(u32 offset, u8 *pixmap, u32 width, u8 fc, u8 bc) \
 
 drawX(15, 5, 5, 5, u16, fb_writew)
 drawX(16, 5, 6, 5, u16, fb_writew)
-drawX(32, 8, 8, 8, u32, fb_writel)
+
+static void draw32(u32 offset, u32 y, u8 *pixmap, u32 width, u8 fc, u8 bc)
+{
+    /* This code takes into account the Ben Nanonote LCD, that has the distribution:
+     *   0:   RR  GG  BB  RR  GG  BB
+     *   1: GG  BB  RR  GG  BB  RR  
+     *   2:   RR  GG  BB  RR  GG  BB
+     *   3: ...
+     *
+     *   We display the odd rows as 50% green in the current pixel, 50% in the next */ 
+	u8 red, green, blue;
+	u8 pixel;
+	u32 color;
+	u32 *dst = (u32 *)(fbdev_mem + offset);
+    /* To work with white background, we ensure to paint the first pixel */
+    u8 prevgreen = palette[bc].green/2;
+
+	for (; width--; pixmap++, dst++) {
+        u8 newgreen;
+		pixel = *pixmap;
+
+        red = palette[bc].red + (((palette[fc].red - palette[bc].red) * pixel) >> 8);
+        newgreen = palette[bc].green + (((palette[fc].green - palette[bc].green) * pixel) >> 8);
+        blue = palette[bc].blue + (((palette[fc].blue - palette[bc].blue) * pixel) >> 8);
+
+        /* width == 0 is the special case for the last byte, where we paint full green.
+         * That's relevant for white background, like when running 'top'. */
+        green = ((y & 1) == 0 || width == 0) ? newgreen : (newgreen/2 + prevgreen);
+        color = (red << 16) | (green << 8) | (blue);
+        fb_writel(dst, color);
+        prevgreen = newgreen/2;
+	}
+}
 
 #define drawXBg(bits, lred, lgreen, lblue, type, fbwrite) \
  \
-static void draw##bits##Bg(u32 offset, u8 *pixmap, u32 width, u8 fc, u8 bc) \
+static void draw##bits##Bg(u32 offset, u32 y, u8 *pixmap, u32 width, u8 fc, u8 bc) \
 { \
 	if (bc != bgcolor) { \
-		draw##bits(offset, pixmap, width, fc, bc); \
+		draw##bits(offset, y, pixmap, width, fc, bc); \
 		return; \
 	} \
  \


More information about the discussion mailing list


interactive