author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /noncore/comm/keypebble/krfbbuffer.cpp | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'noncore/comm/keypebble/krfbbuffer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/comm/keypebble/krfbbuffer.cpp | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/noncore/comm/keypebble/krfbbuffer.cpp b/noncore/comm/keypebble/krfbbuffer.cpp new file mode 100644 index 0000000..4885261 --- a/dev/null +++ b/noncore/comm/keypebble/krfbbuffer.cpp | |||
@@ -0,0 +1,163 @@ | |||
1 | #include <assert.h> | ||
2 | #include <qpixmap.h> | ||
3 | #include <qbrush.h> | ||
4 | #include <qimage.h> | ||
5 | #include <qpainter.h> | ||
6 | #include <qapplication.h> | ||
7 | #include "krfbdecoder.h" | ||
8 | #include "krfbbuffer.h" | ||
9 | #include "krfbserverinfo.h" | ||
10 | |||
11 | // | ||
12 | // Endian stuff | ||
13 | // | ||
14 | #ifndef KDE_USE_FINAL | ||
15 | const int endianTest = 1; | ||
16 | #endif | ||
17 | |||
18 | #define Swap16IfLE(s) \ | ||
19 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) | ||
20 | |||
21 | #define Swap32IfLE(l) \ | ||
22 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ | ||
23 | (((l) & 0x00ff0000) >> 8) | \ | ||
24 | (((l) & 0x0000ff00) << 8) | \ | ||
25 | (((l) & 0x000000ff) << 24)) : (l)) | ||
26 | |||
27 | KRFBBuffer::KRFBBuffer( KRFBDecoder *decoder, | ||
28 | QObject *parent, const char *name ) | ||
29 | : QObject( parent, name ) | ||
30 | { | ||
31 | assert( decoder ); | ||
32 | this->decoder = decoder; | ||
33 | pix = new QPixmap(); | ||
34 | } | ||
35 | |||
36 | KRFBBuffer::~KRFBBuffer() | ||
37 | { | ||
38 | delete pix; | ||
39 | } | ||
40 | |||
41 | void KRFBBuffer::resize( int w, int h ) | ||
42 | { | ||
43 | qWarning( "Resizing buffer" ); | ||
44 | |||
45 | pix->resize( w, h ); | ||
46 | |||
47 | QPalette pal = qApp->palette(); | ||
48 | pix->fill( pal.active().base() ); | ||
49 | |||
50 | emit sizeChanged( w, h ); | ||
51 | } | ||
52 | |||
53 | void KRFBBuffer::soundBell() | ||
54 | { | ||
55 | emit bell(); | ||
56 | } | ||
57 | |||
58 | void KRFBBuffer::mouseEvent( QMouseEvent *e ) | ||
59 | { | ||
60 | decoder->sendMouseEvent( e ); | ||
61 | } | ||
62 | |||
63 | void KRFBBuffer::keyPressEvent( QKeyEvent *e ) | ||
64 | { | ||
65 | qWarning( "Buffer got a key" ); | ||
66 | |||
67 | decoder->sendKeyPressEvent( e ); | ||
68 | } | ||
69 | |||
70 | void KRFBBuffer::keyReleaseEvent( QKeyEvent *e ) | ||
71 | { | ||
72 | decoder->sendKeyReleaseEvent( e ); | ||
73 | } | ||
74 | |||
75 | void KRFBBuffer::copyRect( int srcX, int srcY, | ||
76 | int destX, int destY, int w, int h ) | ||
77 | { | ||
78 | // qWarning( "Got copy rect" ); | ||
79 | bitBlt( pix, destX, destY, pix, srcX, srcY, w, h, CopyROP ); | ||
80 | |||
81 | emit updated( destX, destY, w, h ); | ||
82 | } | ||
83 | |||
84 | void KRFBBuffer::drawRawRectChunk( void *data, | ||
85 | int x, int y, int w, int h ) | ||
86 | { | ||
87 | QImage img( w, h, 32 ); | ||
88 | |||
89 | int redMax = Swap16IfLE( decoder->format->redMax ); | ||
90 | int greenMax = Swap16IfLE( decoder->format->greenMax ); | ||
91 | int blueMax = Swap16IfLE( decoder->format->blueMax ); | ||
92 | |||
93 | QPainter p( pix ); | ||
94 | |||
95 | if ( decoder->format->bpp == 8 ) { | ||
96 | uchar *d = (unsigned char *) data; | ||
97 | |||
98 | uint r,g,b; | ||
99 | |||
100 | for ( int j = 0; j < h; j++ ) { | ||
101 | for ( int i = 0; i < w ; i++ ) { | ||
102 | r = d[ j * w + i ]; | ||
103 | r = r >> decoder->format->redShift; | ||
104 | r = r & redMax; | ||
105 | |||
106 | g = d[ j * w + i ]; | ||
107 | g = g >> decoder->format->greenShift; | ||
108 | g = g & greenMax; | ||
109 | |||
110 | b = d[ j * w + i ]; | ||
111 | b = b >> decoder->format->blueShift; | ||
112 | b = b & blueMax; | ||
113 | |||
114 | r = ( r * 255 ) / redMax; | ||
115 | g = ( g * 255 ) / greenMax; | ||
116 | b = ( b * 255 ) / blueMax; | ||
117 | |||
118 | uint *p = ( uint * ) img.scanLine( j ) + i; | ||
119 | *p = qRgb( r,g,b ); | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | else if ( decoder->format->bpp == 32 ) { | ||
124 | ulong *d = (ulong *) data; | ||
125 | |||
126 | ulong r,g,b; | ||
127 | |||
128 | for ( int j = 0; j < h; j++ ) { | ||
129 | for ( int i = 0; i < w ; i++ ) { | ||
130 | ulong pixel = d[ j * w + i ]; | ||
131 | pixel = Swap32IfLE( pixel ); | ||
132 | |||
133 | r = pixel; | ||
134 | r = r >> decoder->format->redShift; | ||
135 | r = r & redMax; | ||
136 | |||
137 | g = pixel; | ||
138 | g = g >> decoder->format->greenShift; | ||
139 | g = g & greenMax; | ||
140 | |||
141 | b = pixel; | ||
142 | b = b >> decoder->format->blueShift; | ||
143 | b = b & blueMax; | ||
144 | |||
145 | r = ( r * 255 ) / redMax; | ||
146 | g = ( g * 255 ) / greenMax; | ||
147 | b = ( b * 255 ) / blueMax; | ||
148 | |||
149 | uint *p = ( uint * ) img.scanLine( j ) + i; | ||
150 | *p = qRgb( r,g,b ); | ||
151 | } | ||
152 | } | ||
153 | } | ||
154 | else { | ||
155 | p.setBrush( QBrush( Qt::black ) ); | ||
156 | p.drawRect( x, y, w, h ); | ||
157 | } | ||
158 | |||
159 | p.drawImage( x, y, img ); | ||
160 | |||
161 | emit updated( x, y, w, h ); | ||
162 | } | ||
163 | |||