-rw-r--r-- | noncore/comm/keypebble/krfbbuffer.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/comm/keypebble/krfbbuffer.cpp b/noncore/comm/keypebble/krfbbuffer.cpp index 4b29612..2074933 100644 --- a/noncore/comm/keypebble/krfbbuffer.cpp +++ b/noncore/comm/keypebble/krfbbuffer.cpp | |||
@@ -1,210 +1,210 @@ | |||
1 | #include "krfbdecoder.h" | 1 | #include "krfbdecoder.h" |
2 | #include "krfbbuffer.h" | 2 | #include "krfbbuffer.h" |
3 | #include "krfbconnection.h" | 3 | #include "krfbconnection.h" |
4 | #include "krfbserverinfo.h" | 4 | #include "krfbserverinfo.h" |
5 | 5 | ||
6 | /* OPIE */ | 6 | /* OPIE */ |
7 | #include <opie2/odebug.h> | 7 | #include <opie2/odebug.h> |
8 | using namespace Opie::Core; | 8 | using namespace Opie::Core; |
9 | 9 | ||
10 | /* QT */ | 10 | /* QT */ |
11 | #include <qimage.h> | 11 | #include <qimage.h> |
12 | #include <qpainter.h> | 12 | #include <qpainter.h> |
13 | #include <qapplication.h> | 13 | #include <qapplication.h> |
14 | 14 | ||
15 | /* STD */ | 15 | /* STD */ |
16 | #include <assert.h> | 16 | #include <assert.h> |
17 | 17 | ||
18 | // | 18 | // |
19 | // Endian stuff | 19 | // Endian stuff |
20 | // | 20 | // |
21 | #ifndef OPIE_NO_DEBUG | 21 | // #ifndef OPIE_NO_DEBUG |
22 | const int endianTest = 1; | 22 | const int endianTest = 1; |
23 | #endif | 23 | // #endif |
24 | 24 | ||
25 | #define Swap16IfLE(s) \ | 25 | #define Swap16IfLE(s) \ |
26 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) | 26 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) |
27 | 27 | ||
28 | #define Swap32IfLE(l) \ | 28 | #define Swap32IfLE(l) \ |
29 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ | 29 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ |
30 | (((l) & 0x00ff0000) >> 8) | \ | 30 | (((l) & 0x00ff0000) >> 8) | \ |
31 | (((l) & 0x0000ff00) << 8) | \ | 31 | (((l) & 0x0000ff00) << 8) | \ |
32 | (((l) & 0x000000ff) << 24)) : (l)) | 32 | (((l) & 0x000000ff) << 24)) : (l)) |
33 | 33 | ||
34 | KRFBBuffer::KRFBBuffer( KRFBDecoder *decoder, | 34 | KRFBBuffer::KRFBBuffer( KRFBDecoder *decoder, |
35 | QObject *parent, const char *name ) | 35 | QObject *parent, const char *name ) |
36 | : QObject( parent, name ) | 36 | : QObject( parent, name ) |
37 | { | 37 | { |
38 | assert( decoder ); | 38 | assert( decoder ); |
39 | this->decoder = decoder; | 39 | this->decoder = decoder; |
40 | pix = new QPixmap(); | 40 | pix = new QPixmap(); |
41 | } | 41 | } |
42 | 42 | ||
43 | KRFBBuffer::~KRFBBuffer() | 43 | KRFBBuffer::~KRFBBuffer() |
44 | { | 44 | { |
45 | delete pix; | 45 | delete pix; |
46 | } | 46 | } |
47 | 47 | ||
48 | void KRFBBuffer::resize( int w, int h ) | 48 | void KRFBBuffer::resize( int w, int h ) |
49 | { | 49 | { |
50 | owarn << "Resizing buffer" << oendl; | 50 | owarn << "Resizing buffer" << oendl; |
51 | 51 | ||
52 | pix->resize( w, h ); | 52 | pix->resize( w, h ); |
53 | 53 | ||
54 | QPalette pal = qApp->palette(); | 54 | QPalette pal = qApp->palette(); |
55 | pix->fill( pal.active().base() ); | 55 | pix->fill( pal.active().base() ); |
56 | 56 | ||
57 | emit sizeChanged( w, h ); | 57 | emit sizeChanged( w, h ); |
58 | } | 58 | } |
59 | 59 | ||
60 | void KRFBBuffer::soundBell() | 60 | void KRFBBuffer::soundBell() |
61 | { | 61 | { |
62 | emit bell(); | 62 | emit bell(); |
63 | } | 63 | } |
64 | 64 | ||
65 | void KRFBBuffer::mouseEvent( QMouseEvent *e ) | 65 | void KRFBBuffer::mouseEvent( QMouseEvent *e ) |
66 | { | 66 | { |
67 | decoder->sendMouseEvent( e ); | 67 | decoder->sendMouseEvent( e ); |
68 | } | 68 | } |
69 | 69 | ||
70 | void KRFBBuffer::keyPressEvent( QKeyEvent *e ) | 70 | void KRFBBuffer::keyPressEvent( QKeyEvent *e ) |
71 | { | 71 | { |
72 | owarn << "Buffer got a key" << oendl; | 72 | owarn << "Buffer got a key" << oendl; |
73 | 73 | ||
74 | decoder->sendKeyPressEvent( e ); | 74 | decoder->sendKeyPressEvent( e ); |
75 | } | 75 | } |
76 | 76 | ||
77 | void KRFBBuffer::keyReleaseEvent( QKeyEvent *e ) | 77 | void KRFBBuffer::keyReleaseEvent( QKeyEvent *e ) |
78 | { | 78 | { |
79 | decoder->sendKeyReleaseEvent( e ); | 79 | decoder->sendKeyReleaseEvent( e ); |
80 | } | 80 | } |
81 | 81 | ||
82 | void KRFBBuffer::copyRect( int srcX, int srcY, | 82 | void KRFBBuffer::copyRect( int srcX, int srcY, |
83 | int destX, int destY, int w, int h ) | 83 | int destX, int destY, int w, int h ) |
84 | { | 84 | { |
85 | // owarn << "Got copy rect" << oendl; | 85 | // owarn << "Got copy rect" << oendl; |
86 | bitBlt( pix, destX, destY, pix, srcX, srcY, w, h, CopyROP ); | 86 | bitBlt( pix, destX, destY, pix, srcX, srcY, w, h, CopyROP ); |
87 | 87 | ||
88 | emit updated( destX, destY, w, h ); | 88 | emit updated( destX, destY, w, h ); |
89 | } | 89 | } |
90 | 90 | ||
91 | void KRFBBuffer::drawRawRectChunk( void *data, | 91 | void KRFBBuffer::drawRawRectChunk( void *data, |
92 | int x, int y, int w, int h ) | 92 | int x, int y, int w, int h ) |
93 | { | 93 | { |
94 | QImage img( w, h, 32 ); | 94 | QImage img( w, h, 32 ); |
95 | 95 | ||
96 | int scaleFactor=decoder->con->options()->scaleFactor; | 96 | int scaleFactor=decoder->con->options()->scaleFactor; |
97 | int redMax = Swap16IfLE( decoder->format->redMax ); | 97 | int redMax = Swap16IfLE( decoder->format->redMax ); |
98 | int greenMax = Swap16IfLE( decoder->format->greenMax ); | 98 | int greenMax = Swap16IfLE( decoder->format->greenMax ); |
99 | int blueMax = Swap16IfLE( decoder->format->blueMax ); | 99 | int blueMax = Swap16IfLE( decoder->format->blueMax ); |
100 | 100 | ||
101 | QPainter p( pix ); | 101 | QPainter p( pix ); |
102 | 102 | ||
103 | if ( decoder->format->bpp == 8 ) { | 103 | if ( decoder->format->bpp == 8 ) { |
104 | uchar *d = (unsigned char *) data; | 104 | uchar *d = (unsigned char *) data; |
105 | 105 | ||
106 | uint r,g,b; | 106 | uint r,g,b; |
107 | 107 | ||
108 | 108 | ||
109 | for ( int j = 0; j < h; j++) { | 109 | for ( int j = 0; j < h; j++) { |
110 | for ( int i = 0; i < w ; i++ ) { | 110 | for ( int i = 0; i < w ; i++ ) { |
111 | r = d[ j * w + i ]; | 111 | r = d[ j * w + i ]; |
112 | r = r >> decoder->format->redShift; | 112 | r = r >> decoder->format->redShift; |
113 | r = r & redMax; | 113 | r = r & redMax; |
114 | 114 | ||
115 | g = d[ j * w + i ]; | 115 | g = d[ j * w + i ]; |
116 | g = g >> decoder->format->greenShift; | 116 | g = g >> decoder->format->greenShift; |
117 | g = g & greenMax; | 117 | g = g & greenMax; |
118 | 118 | ||
119 | b = d[ j * w + i ]; | 119 | b = d[ j * w + i ]; |
120 | b = b >> decoder->format->blueShift; | 120 | b = b >> decoder->format->blueShift; |
121 | b = b & blueMax; | 121 | b = b & blueMax; |
122 | 122 | ||
123 | r = ( r * 255 ) / redMax; | 123 | r = ( r * 255 ) / redMax; |
124 | g = ( g * 255 ) / greenMax; | 124 | g = ( g * 255 ) / greenMax; |
125 | b = ( b * 255 ) / blueMax; | 125 | b = ( b * 255 ) / blueMax; |
126 | 126 | ||
127 | uint *p = ( uint * ) img.scanLine( j ) + i; | 127 | uint *p = ( uint * ) img.scanLine( j ) + i; |
128 | *p = qRgb( r,g,b ); | 128 | *p = qRgb( r,g,b ); |
129 | } | 129 | } |
130 | } | 130 | } |
131 | } | 131 | } |
132 | else if ( decoder->format->bpp == 32 ) { | 132 | else if ( decoder->format->bpp == 32 ) { |
133 | ulong *d = (ulong *) data; | 133 | ulong *d = (ulong *) data; |
134 | 134 | ||
135 | ulong r,g,b; | 135 | ulong r,g,b; |
136 | 136 | ||
137 | for ( int j = 0; j < h; j++ ) { | 137 | for ( int j = 0; j < h; j++ ) { |
138 | for ( int i = 0; i < w ; i++ ) { | 138 | for ( int i = 0; i < w ; i++ ) { |
139 | ulong pixel = d[ j * w + i ]; | 139 | ulong pixel = d[ j * w + i ]; |
140 | pixel = Swap32IfLE( pixel ); | 140 | pixel = Swap32IfLE( pixel ); |
141 | 141 | ||
142 | r = pixel; | 142 | r = pixel; |
143 | r = r >> decoder->format->redShift; | 143 | r = r >> decoder->format->redShift; |
144 | r = r & redMax; | 144 | r = r & redMax; |
145 | 145 | ||
146 | g = pixel; | 146 | g = pixel; |
147 | g = g >> decoder->format->greenShift; | 147 | g = g >> decoder->format->greenShift; |
148 | g = g & greenMax; | 148 | g = g & greenMax; |
149 | 149 | ||
150 | b = pixel; | 150 | b = pixel; |
151 | b = b >> decoder->format->blueShift; | 151 | b = b >> decoder->format->blueShift; |
152 | b = b & blueMax; | 152 | b = b & blueMax; |
153 | 153 | ||
154 | r = ( r * 255 ) / redMax; | 154 | r = ( r * 255 ) / redMax; |
155 | g = ( g * 255 ) / greenMax; | 155 | g = ( g * 255 ) / greenMax; |
156 | b = ( b * 255 ) / blueMax; | 156 | b = ( b * 255 ) / blueMax; |
157 | 157 | ||
158 | uint *p = ( uint * ) img.scanLine( j ) + i; | 158 | uint *p = ( uint * ) img.scanLine( j ) + i; |
159 | *p = qRgb( r,g,b ); | 159 | *p = qRgb( r,g,b ); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | } else if (decoder->format->bpp == 16 ) { | 162 | } else if (decoder->format->bpp == 16 ) { |
163 | 163 | ||
164 | CARD16 *d = (CARD16 *) data; | 164 | CARD16 *d = (CARD16 *) data; |
165 | 165 | ||
166 | uint r,g,b; | 166 | uint r,g,b; |
167 | 167 | ||
168 | for ( int j = 0; j < h; j++ ) { | 168 | for ( int j = 0; j < h; j++ ) { |
169 | for ( int i = 0; i < w ; i++ ) { | 169 | for ( int i = 0; i < w ; i++ ) { |
170 | CARD16 pixel = d[ j * w + i ]; | 170 | CARD16 pixel = d[ j * w + i ]; |
171 | pixel = Swap16IfLE( pixel ); | 171 | pixel = Swap16IfLE( pixel ); |
172 | 172 | ||
173 | r = pixel; | 173 | r = pixel; |
174 | r = r >> decoder->format->redShift; | 174 | r = r >> decoder->format->redShift; |
175 | r = r & redMax; | 175 | r = r & redMax; |
176 | 176 | ||
177 | g = pixel; | 177 | g = pixel; |
178 | g = g >> decoder->format->greenShift; | 178 | g = g >> decoder->format->greenShift; |
179 | g = g & greenMax; | 179 | g = g & greenMax; |
180 | 180 | ||
181 | b = pixel; | 181 | b = pixel; |
182 | b = b >> decoder->format->blueShift; | 182 | b = b >> decoder->format->blueShift; |
183 | b = b & blueMax; | 183 | b = b & blueMax; |
184 | 184 | ||
185 | r = ( r * 255 ) / redMax; | 185 | r = ( r * 255 ) / redMax; |
186 | g = ( g * 255 ) / greenMax; | 186 | g = ( g * 255 ) / greenMax; |
187 | b = ( b * 255 ) / blueMax; | 187 | b = ( b * 255 ) / blueMax; |
188 | 188 | ||
189 | ulong *p = ( ulong * ) img.scanLine( j ) + i; | 189 | ulong *p = ( ulong * ) img.scanLine( j ) + i; |
190 | *p = qRgb( r,g,b ); | 190 | *p = qRgb( r,g,b ); |
191 | } | 191 | } |
192 | } | 192 | } |
193 | } | 193 | } |
194 | else { | 194 | else { |
195 | p.setBrush( QBrush( Qt::black ) ); | 195 | p.setBrush( QBrush( Qt::black ) ); |
196 | p.drawRect( x, y, w, h ); | 196 | p.drawRect( x, y, w, h ); |
197 | } | 197 | } |
198 | 198 | ||
199 | if (scaleFactor > 1) { | 199 | if (scaleFactor > 1) { |
200 | /* FIXME: proper zero width/height handling */ | 200 | /* FIXME: proper zero width/height handling */ |
201 | if (w/scaleFactor != 0) | 201 | if (w/scaleFactor != 0) |
202 | p.drawImage( x/scaleFactor, y/scaleFactor, img.smoothScale(w/scaleFactor,h/scaleFactor) ); | 202 | p.drawImage( x/scaleFactor, y/scaleFactor, img.smoothScale(w/scaleFactor,h/scaleFactor) ); |
203 | emit updated( x/scaleFactor, y/scaleFactor, w/scaleFactor, h/scaleFactor ); | 203 | emit updated( x/scaleFactor, y/scaleFactor, w/scaleFactor, h/scaleFactor ); |
204 | } | 204 | } |
205 | else { | 205 | else { |
206 | p.drawImage( x, y, img); | 206 | p.drawImage( x, y, img); |
207 | emit updated( x, y, w, h ); | 207 | emit updated( x, y, w, h ); |
208 | } | 208 | } |
209 | } | 209 | } |
210 | 210 | ||