summaryrefslogtreecommitdiffstats
path: root/package/fbv/0004-fix-bgr555.patch
blob: 8f185f0a37a61a80871f1cd38334e4bc1d1fde2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
[PATCH] fbv: support bgr555 format

Signed-off-by: Josh.Wu <josh.wu@atmel.com>
diff -Naur fbv-1.0b-ori/fb_display.c fbv-1.0b/fb_display.c
--- fbv-1.0b-ori/fb_display.c	2010-04-02 09:38:15.000000000 +0800
+++ fbv-1.0b/fb_display.c	2010-04-01 18:54:15.000000000 +0800
@@ -297,6 +297,14 @@
 	 ((b >> 3) & 31)        );
 }
 
+inline static unsigned short make15color_bgr(unsigned char r, unsigned char g, unsigned char b)
+{
+    return (
+	(((b >> 3) & 31) << 10) |
+	(((g >> 3) & 31) << 5)  |
+	 ((r >> 3) & 31)        );
+}
+
 inline static unsigned short make16color(unsigned char r, unsigned char g, unsigned char b)
 {
     return (
@@ -313,6 +321,14 @@
     u_int16_t *s_fbbuff;
     u_int32_t *i_fbbuff;
 
+    int is_bgr555 = 0;
+    struct fb_var_screeninfo var;
+    getVarScreenInfo(fh, &var);
+    if(var.red.offset == 0 && 
+       var.green.offset == 5 && 
+       var.blue.offset == 10)
+	is_bgr555 = 1;
+
     switch(bpp)
     {
 	case 8:
@@ -325,15 +341,23 @@
 	case 15:
 	    *cpp = 2;
 	    s_fbbuff = (unsigned short *) malloc(count * sizeof(unsigned short));
-	    for(i = 0; i < count ; i++)
-		s_fbbuff[i] = make15color(rgbbuff[i*3], rgbbuff[i*3+1], rgbbuff[i*3+2]);
+	    if(is_bgr555)
+	    	for(i = 0; i < count ; i++)
+		    s_fbbuff[i] = make15color_bgr(rgbbuff[i*3], rgbbuff[i*3+1], rgbbuff[i*3+2]);
+	    else
+	    	for(i = 0; i < count ; i++)
+		    s_fbbuff[i] = make15color(rgbbuff[i*3], rgbbuff[i*3+1], rgbbuff[i*3+2]);
 	    fbbuff = (void *) s_fbbuff;
 	    break;
 	case 16:
 	    *cpp = 2;
 	    s_fbbuff = (unsigned short *) malloc(count * sizeof(unsigned short));
-	    for(i = 0; i < count ; i++)
-		s_fbbuff[i] = make16color(rgbbuff[i*3], rgbbuff[i*3+1], rgbbuff[i*3+2]);
+	    if(is_bgr555)
+	    	for(i = 0; i < count ; i++)
+		    s_fbbuff[i] = make15color_bgr(rgbbuff[i*3], rgbbuff[i*3+1], rgbbuff[i*3+2]);
+	    else
+	    	for(i = 0; i < count ; i++)
+		    s_fbbuff[i] = make16color(rgbbuff[i*3], rgbbuff[i*3+1], rgbbuff[i*3+2]);
 	    fbbuff = (void *) s_fbbuff;
 	    break;
 	case 24:
OpenPOWER on IntegriCloud