re-enable alphablend
[enigma2.git] / lib / gdi / lcd.cpp
1 #include <lib/gdi/lcd.h>
2
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <sys/ioctl.h>
6
7 #include <dbox/fp.h>
8 #include <dbox/lcd-ks0713.h>
9
10 #include <lib/gdi/esize.h>
11 #include <lib/base/init.h>
12 #include <lib/base/init_num.h>
13 #include <lib/gdi/glcddc.h>
14
15 eDBoxLCD *eDBoxLCD::instance;
16
17 eLCD::eLCD(eSize size): res(size)
18 {
19         locked=0;
20         _buffer=new unsigned char[res.height()*res.width()];
21         memset(_buffer, 0, res.height()*res.width());
22         _stride=res.width();
23 }
24
25 eLCD::~eLCD()
26 {
27         delete [] _buffer;
28 }
29
30 int eLCD::lock()
31 {
32         if (locked)
33                 return -1;
34
35         locked=1;
36         return lcdfd;
37 }
38
39 void eLCD::unlock()
40 {
41         locked=0;
42 }
43
44 eDBoxLCD::eDBoxLCD(): eLCD(eSize(132, 64))
45 {
46 #ifndef NO_LCD
47         lcdfd = open("/dev/dbox/oled0", O_RDWR);
48         if (lcdfd < 0)
49         {
50                 lcdfd = open("/dev/dbox/lcd0", O_RDWR);
51                 is_oled = 0;
52         } else
53         {
54                 eDebug("found OLED display!");
55                 is_oled = 1;
56         }
57 #else
58         lcdfd = -1;
59 #endif
60         instance=this;
61
62         if (lcdfd<0)
63                 eDebug("couldn't open LCD - load lcd.o!");
64         else
65         {
66                 int i=LCD_MODE_BIN;
67                 ioctl(lcdfd, LCD_IOCTL_ASC_MODE, &i);
68                 inverted=0;
69         }
70 }
71
72 void eDBoxLCD::setInverted(unsigned char inv)
73 {
74         inverted=inv;
75         update();       
76 }
77
78 int eDBoxLCD::setLCDContrast(int contrast)
79 {
80         int fp;
81         if((fp=open("/dev/dbox/fp0", O_RDWR))<=0)
82         {
83                 eDebug("[LCD] can't open /dev/dbox/fp0");
84                 return(-1);
85         }
86
87         if(ioctl(lcdfd, LCD_IOCTL_SRV, &contrast))
88         {
89                 eDebug("[LCD] can't set lcd contrast");
90         }
91         close(fp);
92         return(0);
93 }
94
95 int eDBoxLCD::setLCDBrightness(int brightness)
96 {
97         int fp;
98         if((fp=open("/dev/dbox/fp0", O_RDWR))<=0)
99         {
100                 eDebug("[LCD] can't open /dev/dbox/fp0");
101                 return(-1);
102         }
103
104         if(ioctl(fp, FP_IOCTL_LCD_DIMM, &brightness))
105         {
106                 eDebug("[LCD] can't set lcd brightness");
107         }
108         close(fp);
109         return(0);
110 }
111
112 eDBoxLCD::~eDBoxLCD()
113 {
114         if (lcdfd>0)
115         {
116                 close(lcdfd);
117                 lcdfd=0;
118         }
119 }
120
121 eDBoxLCD *eDBoxLCD::getInstance()
122 {
123         return instance;
124 }
125
126 void eDBoxLCD::update()
127 {
128         if (!is_oled)
129         {
130                 unsigned char raw[132*8];
131                 int x, y, yy;
132                 for (y=0; y<8; y++)
133                 {
134                         for (x=0; x<132; x++)
135                         {
136                                 int pix=0;
137                                 for (yy=0; yy<8; yy++)
138                                 {
139                                         pix|=(_buffer[(y*8+yy)*132+x]>=108)<<yy;
140                                 }
141                                 raw[y*132+x]=(pix^inverted);
142                         }
143                 }
144                 if (lcdfd>0)
145                         write(lcdfd, raw, 132*8);
146         } else
147         {
148                 unsigned char raw[64*64];
149                 int x, y;
150                 memset(raw, 0, 64*64);
151                 for (y=0; y<64; y++)
152                 {
153                         for (x=0; x<128 / 2; x++)
154                                 raw[y*64+x] = (_buffer[y*132 + x * 2 + 2] & 0xF0) |(_buffer[y*132 + x * 2 + 1 + 2] >> 4);
155                 }
156                 if (lcdfd > 0)
157                         write(lcdfd, raw, 64*64);
158         }
159 }
160