aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/psplash/files/psplash_grayscale.patch
blob: 531d63a89c4c31738616b6d6581321f7fd440e44 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
diff -Nru psplash_orig/psplash-fb.c psplash/psplash-fb.c
--- psplash_orig/psplash-fb.c	2010-04-22 16:17:33.000000000 +0200
+++ psplash/psplash-fb.c	2010-05-16 15:49:40.000000000 +0200
@@ -132,7 +132,8 @@
       goto fail;
     }
 
-  if (fb_var.bits_per_pixel < 16)
+  if (fb_var.bits_per_pixel != 1 && fb_var.bits_per_pixel != 2                           
+       && fb_var.bits_per_pixel < 16) 
     {
       fprintf(stderr,
               "Error, no support currently for %i bpp frame buffers\n"
@@ -258,7 +259,18 @@
   return NULL;
 }
 
-#define OFFSET(fb,x,y) (((y) * (fb)->stride) + ((x) * ((fb)->bpp >> 3)))
+static inline int
+psplash_fb_offset(PSplashFB *fb, int x, int y)
+{
+  switch (fb->bpp)
+    {
+    /* pixel offset */
+    case 2: return (y * (fb->stride << 2)) + x;
+    case 1: return (y * (fb->stride << 3)) + x;
+    /* byte offset */
+    default: return (y * fb->stride) + (x * (fb->bpp >> 3));
+    }
+}
 
 inline void
 psplash_fb_plot_pixel (PSplashFB    *fb,
@@ -268,7 +280,7 @@
 		       uint8        green,
 		       uint8        blue)
 {
-  int off;
+  int off, shift;
 
   if (x < 0 || x > fb->width-1 || y < 0 || y > fb->height-1)
     return;
@@ -276,17 +288,17 @@
   switch (fb->angle)
     {
     case 270:
-      off = OFFSET (fb, fb->height - y - 1, x);
+      off = psplash_fb_offset (fb, fb->height - y - 1, x);
       break;
     case 180:
-      off = OFFSET (fb, fb->width - x - 1, fb->height - y - 1);
+      off = psplash_fb_offset (fb, fb->width - x - 1, fb->height - y - 1);
       break;
     case 90:
-      off = OFFSET (fb, y, fb->width - x - 1);
+      off = psplash_fb_offset (fb, y, fb->width - x - 1);
       break;
     case 0:
     default:
-      off = OFFSET (fb, x, y);
+      off = psplash_fb_offset (fb, x, y);
       break;
     }
 
@@ -303,6 +315,18 @@
         *(volatile uint16_t *) (fb->data + off)
 	  = ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
         break;
+      case 2:                                                                              
+        shift = (3 - (off & 3)) << 1;                                                      
+        *(fb->data + (off >> 2)) = (*(fb->data + (off >> 2)) & ~(3 << shift))              
+        | (((11*red + 16*green + 5*blue) >> 11) << shift);                                 
+        break;                                                                             
+      case 1:                                                                              
+        shift = 7 - (off & 7);                                                             
+        if (((11*red + 16*green + 5*blue) >> 5) >= 128)                                    
+          *(fb->data + (off >> 3)) |= (1 << shift);                                        
+        else                                                                               
+          *(fb->data + (off >> 3)) &= ~(1 << shift);                                       
+        break;  
       default:
         /* depth not supported yet */
         break;