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