~ubuntu-branches/debian/lenny/italc/lenny

« back to all changes in this revision

Viewing changes to client/demoviewer/rfbproto.h

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-06-17 13:46:54 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080617134654-cl0gi4u524cv1ici
Tags: 1:1.0.9~rc3-1
* Package new upstream version
  - upstream ported the code to qt4.4 (Closes: #481974)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (C) 2000-2002 Constantin Kaplinsky.  All Rights Reserved.
3
 
 *  Copyright (C) 2000 Tridia Corporation.  All Rights Reserved.
4
 
 *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
5
 
 *
6
 
 *  This is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This software is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this software; if not, write to the Free Software
18
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
19
 
 *  USA.
20
 
 */
21
 
 
22
 
/*
23
 
 * rfbproto.h - header file for the RFB protocol version 3.3
24
 
 *
25
 
 * Uses types CARD<n> for an n-bit unsigned integer, INT<n> for an n-bit signed
26
 
 * integer (for n = 8, 16 and 32).
27
 
 *
28
 
 * All multiple byte integers are in big endian (network) order (most
29
 
 * significant byte first).  Unless noted otherwise there is no special
30
 
 * alignment of protocol structures.
31
 
 *
32
 
 *
33
 
 * Once the initial handshaking is done, all messages start with a type byte,
34
 
 * (usually) followed by message-specific data.  The order of definitions in
35
 
 * this file is as follows:
36
 
 *
37
 
 *  (1) Structures used in several types of message.
38
 
 *  (2) Structures used in the initial handshaking.
39
 
 *  (3) Message types.
40
 
 *  (4) Encoding types.
41
 
 *  (5) For each message type, the form of the data following the type byte.
42
 
 *      Sometimes this is defined by a single structure but the more complex
43
 
 *      messages have to be explained by comments.
44
 
 */
45
 
 
46
 
 
47
 
/*****************************************************************************
48
 
 *
49
 
 * Structures used in several messages
50
 
 *
51
 
 *****************************************************************************/
52
 
 
53
 
/*-----------------------------------------------------------------------------
54
 
 * Structure used to specify a rectangle.  This structure is a multiple of 4
55
 
 * bytes so that it can be interspersed with 32-bit pixel data without
56
 
 * affecting alignment.
57
 
 */
58
 
 
59
 
typedef struct {
60
 
    CARD16 x;
61
 
    CARD16 y;
62
 
    CARD16 w;
63
 
    CARD16 h;
64
 
} rfbRectangle;
65
 
 
66
 
#define sz_rfbRectangle 8
67
 
 
68
 
 
69
 
/*-----------------------------------------------------------------------------
70
 
 * Structure used to specify pixel format.
71
 
 */
72
 
 
73
 
typedef struct {
74
 
 
75
 
    CARD8 bitsPerPixel;         /* 8,16,32 only */
76
 
 
77
 
    CARD8 depth;                /* 8 to 32 */
78
 
 
79
 
    CARD8 bigEndian;            /* True if multi-byte pixels are interpreted
80
 
                                   as big endian, or if single-bit-per-pixel
81
 
                                   has most significant bit of the byte
82
 
                                   corresponding to first (leftmost) pixel. Of
83
 
                                   course this is meaningless for 8 bits/pix */
84
 
 
85
 
    CARD8 trueColour;           /* If false then we need a "colour map" to
86
 
                                   convert pixels to RGB.  If true, xxxMax and
87
 
                                   xxxShift specify bits used for red, green
88
 
                                   and blue */
89
 
 
90
 
    /* the following fields are only meaningful if trueColour is true */
91
 
 
92
 
    CARD16 redMax;              /* maximum red value (= 2^n - 1 where n is the
93
 
                                   number of bits used for red). Note this
94
 
                                   value is always in big endian order. */
95
 
 
96
 
    CARD16 greenMax;            /* similar for green */
97
 
 
98
 
    CARD16 blueMax;             /* and blue */
99
 
 
100
 
    CARD8 redShift;             /* number of shifts needed to get the red
101
 
                                   value in a pixel to the least significant
102
 
                                   bit. To find the red value from a given
103
 
                                   pixel, do the following:
104
 
                                   1) Swap pixel value according to bigEndian
105
 
                                      (e.g. if bigEndian is false and host byte
106
 
                                      order is big endian, then swap).
107
 
                                   2) Shift right by redShift.
108
 
                                   3) AND with redMax (in host byte order).
109
 
                                   4) You now have the red value between 0 and
110
 
                                      redMax. */
111
 
 
112
 
    CARD8 greenShift;           /* similar for green */
113
 
 
114
 
    CARD8 blueShift;            /* and blue */
115
 
 
116
 
    CARD8 pad1;
117
 
    CARD16 pad2;
118
 
 
119
 
} rfbPixelFormat;
120
 
 
121
 
#define sz_rfbPixelFormat 16
122
 
 
123
 
 
124
 
 
125
 
/*****************************************************************************
126
 
 *
127
 
 * Initial handshaking messages
128
 
 *
129
 
 *****************************************************************************/
130
 
 
131
 
/*-----------------------------------------------------------------------------
132
 
 * Protocol Version
133
 
 *
134
 
 * The server always sends 12 bytes to start which identifies the latest RFB
135
 
 * protocol version number which it supports.  These bytes are interpreted
136
 
 * as a string of 12 ASCII characters in the format "RFB xxx.yyy\n" where
137
 
 * xxx and yyy are the major and minor version numbers (for version 3.3
138
 
 * this is "RFB 003.003\n").
139
 
 *
140
 
 * The client then replies with a similar 12-byte message giving the version
141
 
 * number of the protocol which should actually be used (which may be different
142
 
 * to that quoted by the server).
143
 
 *
144
 
 * It is intended that both clients and servers may provide some level of
145
 
 * backwards compatibility by this mechanism.  Servers in particular should
146
 
 * attempt to provide backwards compatibility, and even forwards compatibility
147
 
 * to some extent.  For example if a client demands version 3.1 of the
148
 
 * protocol, a 3.0 server can probably assume that by ignoring requests for
149
 
 * encoding types it doesn't understand, everything will still work OK.  This
150
 
 * will probably not be the case for changes in the major version number.
151
 
 *
152
 
 * The format string below can be used in sprintf or sscanf to generate or
153
 
 * decode the version string respectively.
154
 
 */
155
 
 
156
 
#define rfbProtocolVersionFormat "RFB %03d.%03d\n"
157
 
#define rfbProtocolMajorVersion 3
158
 
#define rfbProtocolMinorVersion 3
159
 
 
160
 
typedef char rfbProtocolVersionMsg[13]; /* allow extra byte for null */
161
 
 
162
 
#define sz_rfbProtocolVersionMsg 12
163
 
 
164
 
 
165
 
/*-----------------------------------------------------------------------------
166
 
 * Authentication
167
 
 *
168
 
 * Once the protocol version has been decided, the server then sends a 32-bit
169
 
 * word indicating whether any authentication is needed on the connection.
170
 
 * The value of this word determines the authentication scheme in use.  For
171
 
 * version 3.0 of the protocol this may have one of the following values:
172
 
 */
173
 
 
174
 
#define rfbConnFailed 0
175
 
#define rfbNoAuth 1
176
 
#define rfbVncAuth 2
177
 
 
178
 
/*
179
 
 * rfbConnFailed:       For some reason the connection failed (e.g. the server
180
 
 *                      cannot support the desired protocol version).  This is
181
 
 *                      followed by a string describing the reason (where a
182
 
 *                      string is specified as a 32-bit length followed by that
183
 
 *                      many ASCII characters).
184
 
 *
185
 
 * rfbNoAuth:           No authentication is needed.
186
 
 *
187
 
 * rfbVncAuth:          The VNC authentication scheme is to be used.  A 16-byte
188
 
 *                      challenge follows, which the client encrypts as
189
 
 *                      appropriate using the password and sends the resulting
190
 
 *                      16-byte response.  If the response is correct, the
191
 
 *                      server sends the 32-bit word rfbVncAuthOK.  If a simple
192
 
 *                      failure happens, the server sends rfbVncAuthFailed and
193
 
 *                      closes the connection. If the server decides that too
194
 
 *                      many failures have occurred, it sends rfbVncAuthTooMany
195
 
 *                      and closes the connection.  In the latter case, the
196
 
 *                      server should not allow an immediate reconnection by
197
 
 *                      the client.
198
 
 */
199
 
 
200
 
#define rfbVncAuthOK 0
201
 
#define rfbVncAuthFailed 1
202
 
#define rfbVncAuthTooMany 2
203
 
 
204
 
 
205
 
/*-----------------------------------------------------------------------------
206
 
 * Client Initialisation Message
207
 
 *
208
 
 * Once the client and server are sure that they're happy to talk to one
209
 
 * another, the client sends an initialisation message.  At present this
210
 
 * message only consists of a boolean indicating whether the server should try
211
 
 * to share the desktop by leaving other clients connected, or give exclusive
212
 
 * access to this client by disconnecting all other clients.
213
 
 */
214
 
 
215
 
typedef struct {
216
 
    CARD8 shared;
217
 
} rfbClientInitMsg;
218
 
 
219
 
#define sz_rfbClientInitMsg 1
220
 
 
221
 
 
222
 
/*-----------------------------------------------------------------------------
223
 
 * Server Initialisation Message
224
 
 *
225
 
 * After the client initialisation message, the server sends one of its own.
226
 
 * This tells the client the width and height of the server's framebuffer,
227
 
 * its pixel format and the name associated with the desktop.
228
 
 */
229
 
 
230
 
typedef struct {
231
 
    CARD16 framebufferWidth;
232
 
    CARD16 framebufferHeight;
233
 
    rfbPixelFormat format;      /* the server's preferred pixel format */
234
 
    CARD32 nameLength;
235
 
    /* followed by char name[nameLength] */
236
 
} rfbServerInitMsg;
237
 
 
238
 
#define sz_rfbServerInitMsg (8 + sz_rfbPixelFormat)
239
 
 
240
 
 
241
 
/*
242
 
 * Following the server initialisation message it's up to the client to send
243
 
 * whichever protocol messages it wants.  Typically it will send a
244
 
 * SetPixelFormat message and a SetEncodings message, followed by a
245
 
 * FramebufferUpdateRequest.  From then on the server will send
246
 
 * FramebufferUpdate messages in response to the client's
247
 
 * FramebufferUpdateRequest messages.  The client should send
248
 
 * FramebufferUpdateRequest messages with incremental set to true when it has
249
 
 * finished processing one FramebufferUpdate and is ready to process another.
250
 
 * With a fast client, the rate at which FramebufferUpdateRequests are sent
251
 
 * should be regulated to avoid hogging the network.
252
 
 */
253
 
 
254
 
 
255
 
 
256
 
/*****************************************************************************
257
 
 *
258
 
 * Message types
259
 
 *
260
 
 *****************************************************************************/
261
 
 
262
 
/* server -> client */
263
 
 
264
 
#define rfbFramebufferUpdate 0
265
 
#define rfbSetColourMapEntries 1
266
 
#define rfbBell 2
267
 
#define rfbServerCutText 3
268
 
 
269
 
 
270
 
/* client -> server */
271
 
 
272
 
#define rfbSetPixelFormat 0
273
 
#define rfbFixColourMapEntries 1        /* not currently supported */
274
 
#define rfbSetEncodings 2
275
 
#define rfbFramebufferUpdateRequest 3
276
 
#define rfbKeyEvent 4
277
 
#define rfbPointerEvent 5
278
 
#define rfbClientCutText 6
279
 
 
280
 
 
281
 
 
282
 
 
283
 
/*****************************************************************************
284
 
 *
285
 
 * Encoding types
286
 
 *
287
 
 *****************************************************************************/
288
 
 
289
 
#define rfbEncodingRaw 0
290
 
#define rfbEncodingCopyRect 1
291
 
#define rfbEncodingRRE 2
292
 
#define rfbEncodingCoRRE 4
293
 
#define rfbEncodingHextile 5
294
 
#define rfbEncodingZlib 6
295
 
#define rfbEncodingTight 7
296
 
#define rfbEncodingZlibHex 8
297
 
 
298
 
/*
299
 
 * Special encoding numbers:
300
 
 *   0xFFFFFF00 .. 0xFFFFFF0F -- encoding-specific compression levels;
301
 
 *   0xFFFFFF10 .. 0xFFFFFF1F -- mouse cursor shape data;
302
 
 *   0xFFFFFF20 .. 0xFFFFFF2F -- various protocol extensions;
303
 
 *   0xFFFFFF30 .. 0xFFFFFFDF -- not allocated yet;
304
 
 *   0xFFFFFFE0 .. 0xFFFFFFEF -- quality level for JPEG compressor;
305
 
 *   0xFFFFFFF0 .. 0xFFFFFFFF -- cross-encoding compression levels.
306
 
 */
307
 
 
308
 
#define rfbEncodingCompressLevel0  0xFFFFFF00
309
 
#define rfbEncodingCompressLevel1  0xFFFFFF01
310
 
#define rfbEncodingCompressLevel2  0xFFFFFF02
311
 
#define rfbEncodingCompressLevel3  0xFFFFFF03
312
 
#define rfbEncodingCompressLevel4  0xFFFFFF04
313
 
#define rfbEncodingCompressLevel5  0xFFFFFF05
314
 
#define rfbEncodingCompressLevel6  0xFFFFFF06
315
 
#define rfbEncodingCompressLevel7  0xFFFFFF07
316
 
#define rfbEncodingCompressLevel8  0xFFFFFF08
317
 
#define rfbEncodingCompressLevel9  0xFFFFFF09
318
 
 
319
 
#define rfbEncodingXCursor         0xFFFFFF10
320
 
#define rfbEncodingRichCursor      0xFFFFFF11
321
 
#define rfbEncodingPointerPos      0xFFFFFF18
322
 
 
323
 
#define rfbEncodingLastRect        0xFFFFFF20
324
 
 
325
 
#define rfbEncodingQualityLevel0   0xFFFFFFE0
326
 
#define rfbEncodingQualityLevel1   0xFFFFFFE1
327
 
#define rfbEncodingQualityLevel2   0xFFFFFFE2
328
 
#define rfbEncodingQualityLevel3   0xFFFFFFE3
329
 
#define rfbEncodingQualityLevel4   0xFFFFFFE4
330
 
#define rfbEncodingQualityLevel5   0xFFFFFFE5
331
 
#define rfbEncodingQualityLevel6   0xFFFFFFE6
332
 
#define rfbEncodingQualityLevel7   0xFFFFFFE7
333
 
#define rfbEncodingQualityLevel8   0xFFFFFFE8
334
 
#define rfbEncodingQualityLevel9   0xFFFFFFE9
335
 
 
336
 
 
337
 
/*****************************************************************************
338
 
 *
339
 
 * Server -> client message definitions
340
 
 *
341
 
 *****************************************************************************/
342
 
 
343
 
 
344
 
/*-----------------------------------------------------------------------------
345
 
 * FramebufferUpdate - a block of rectangles to be copied to the framebuffer.
346
 
 *
347
 
 * This message consists of a header giving the number of rectangles of pixel
348
 
 * data followed by the rectangles themselves.  The header is padded so that
349
 
 * together with the type byte it is an exact multiple of 4 bytes (to help
350
 
 * with alignment of 32-bit pixels):
351
 
 */
352
 
 
353
 
typedef struct {
354
 
    CARD8 type;                 /* always rfbFramebufferUpdate */
355
 
    CARD8 pad;
356
 
    CARD16 nRects;
357
 
    /* followed by nRects rectangles */
358
 
} rfbFramebufferUpdateMsg;
359
 
 
360
 
#define sz_rfbFramebufferUpdateMsg 4
361
 
 
362
 
/*
363
 
 * Each rectangle of pixel data consists of a header describing the position
364
 
 * and size of the rectangle and a type word describing the encoding of the
365
 
 * pixel data, followed finally by the pixel data.  Note that if the client has
366
 
 * not sent a SetEncodings message then it will only receive raw pixel data.
367
 
 * Also note again that this structure is a multiple of 4 bytes.
368
 
 */
369
 
 
370
 
typedef struct {
371
 
    rfbRectangle r;
372
 
    CARD32 encoding;    /* one of the encoding types rfbEncoding... */
373
 
} rfbFramebufferUpdateRectHeader;
374
 
 
375
 
#define sz_rfbFramebufferUpdateRectHeader (sz_rfbRectangle + 4)
376
 
 
377
 
 
378
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
379
 
 * Raw Encoding.  Pixels are sent in top-to-bottom scanline order,
380
 
 * left-to-right within a scanline with no padding in between.
381
 
 */
382
 
 
383
 
 
384
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
385
 
 * CopyRect Encoding.  The pixels are specified simply by the x and y position
386
 
 * of the source rectangle.
387
 
 */
388
 
 
389
 
typedef struct {
390
 
    CARD16 srcX;
391
 
    CARD16 srcY;
392
 
} rfbCopyRect;
393
 
 
394
 
#define sz_rfbCopyRect 4
395
 
 
396
 
 
397
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
398
 
 * RRE - Rise-and-Run-length Encoding.  We have an rfbRREHeader structure
399
 
 * giving the number of subrectangles following.  Finally the data follows in
400
 
 * the form [<bgpixel><subrect><subrect>...] where each <subrect> is
401
 
 * [<pixel><rfbRectangle>].
402
 
 */
403
 
 
404
 
typedef struct {
405
 
    CARD32 nSubrects;
406
 
} rfbRREHeader;
407
 
 
408
 
#define sz_rfbRREHeader 4
409
 
 
410
 
 
411
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
412
 
 * CoRRE - Compact RRE Encoding.  We have an rfbRREHeader structure giving
413
 
 * the number of subrectangles following.  Finally the data follows in the form
414
 
 * [<bgpixel><subrect><subrect>...] where each <subrect> is
415
 
 * [<pixel><rfbCoRRERectangle>].  This means that
416
 
 * the whole rectangle must be at most 255x255 pixels.
417
 
 */
418
 
 
419
 
typedef struct {
420
 
    CARD8 x;
421
 
    CARD8 y;
422
 
    CARD8 w;
423
 
    CARD8 h;
424
 
} rfbCoRRERectangle;
425
 
 
426
 
#define sz_rfbCoRRERectangle 4
427
 
 
428
 
 
429
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
430
 
 * Hextile Encoding.  The rectangle is divided up into "tiles" of 16x16 pixels,
431
 
 * starting at the top left going in left-to-right, top-to-bottom order.  If
432
 
 * the width of the rectangle is not an exact multiple of 16 then the width of
433
 
 * the last tile in each row will be correspondingly smaller.  Similarly if the
434
 
 * height is not an exact multiple of 16 then the height of each tile in the
435
 
 * final row will also be smaller.  Each tile begins with a "subencoding" type
436
 
 * byte, which is a mask made up of a number of bits.  If the Raw bit is set
437
 
 * then the other bits are irrelevant; w*h pixel values follow (where w and h
438
 
 * are the width and height of the tile).  Otherwise the tile is encoded in a
439
 
 * similar way to RRE, except that the position and size of each subrectangle
440
 
 * can be specified in just two bytes.  The other bits in the mask are as
441
 
 * follows:
442
 
 *
443
 
 * BackgroundSpecified - if set, a pixel value follows which specifies
444
 
 *    the background colour for this tile.  The first non-raw tile in a
445
 
 *    rectangle must have this bit set.  If this bit isn't set then the
446
 
 *    background is the same as the last tile.
447
 
 *
448
 
 * ForegroundSpecified - if set, a pixel value follows which specifies
449
 
 *    the foreground colour to be used for all subrectangles in this tile.
450
 
 *    If this bit is set then the SubrectsColoured bit must be zero.
451
 
 *
452
 
 * AnySubrects - if set, a single byte follows giving the number of
453
 
 *    subrectangles following.  If not set, there are no subrectangles (i.e.
454
 
 *    the whole tile is just solid background colour).
455
 
 *
456
 
 * SubrectsColoured - if set then each subrectangle is preceded by a pixel
457
 
 *    value giving the colour of that subrectangle.  If not set, all
458
 
 *    subrectangles are the same colour, the foreground colour;  if the
459
 
 *    ForegroundSpecified bit wasn't set then the foreground is the same as
460
 
 *    the last tile.
461
 
 *
462
 
 * The position and size of each subrectangle is specified in two bytes.  The
463
 
 * Pack macros below can be used to generate the two bytes from x, y, w, h,
464
 
 * and the Extract macros can be used to extract the x, y, w, h values from
465
 
 * the two bytes.
466
 
 */
467
 
 
468
 
#define rfbHextileRaw                   (1 << 0)
469
 
#define rfbHextileBackgroundSpecified   (1 << 1)
470
 
#define rfbHextileForegroundSpecified   (1 << 2)
471
 
#define rfbHextileAnySubrects           (1 << 3)
472
 
#define rfbHextileSubrectsColoured      (1 << 4)
473
 
 
474
 
#define rfbHextilePackXY(x,y) (((x) << 4) | (y))
475
 
#define rfbHextilePackWH(w,h) ((((w)-1) << 4) | ((h)-1))
476
 
#define rfbHextileExtractX(byte) ((byte) >> 4)
477
 
#define rfbHextileExtractY(byte) ((byte) & 0xf)
478
 
#define rfbHextileExtractW(byte) (((byte) >> 4) + 1)
479
 
#define rfbHextileExtractH(byte) (((byte) & 0xf) + 1)
480
 
 
481
 
 
482
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
483
 
 * zlib - zlib compressed Encoding.  We have an rfbZlibHeader structure
484
 
 * giving the number of bytes following.  Finally the data follows is
485
 
 * zlib compressed version of the raw pixel data as negotiated.
486
 
 */
487
 
 
488
 
typedef struct {
489
 
    CARD32 nBytes;
490
 
} rfbZlibHeader;
491
 
 
492
 
#define sz_rfbZlibHeader 4
493
 
 
494
 
 
495
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
496
 
 * Tight Encoding.
497
 
 *
498
 
 *-- The first byte of each Tight-encoded rectangle is a "compression control
499
 
 *   byte". Its format is as follows (bit 0 is the least significant one):
500
 
 *
501
 
 *   bit 0:    if 1, then compression stream 0 should be reset;
502
 
 *   bit 1:    if 1, then compression stream 1 should be reset;
503
 
 *   bit 2:    if 1, then compression stream 2 should be reset;
504
 
 *   bit 3:    if 1, then compression stream 3 should be reset;
505
 
 *   bits 7-4: if 1000 (0x08), then the compression type is "fill",
506
 
 *             if 1001 (0x09), then the compression type is "jpeg",
507
 
 *             if 0xxx, then the compression type is "basic",
508
 
 *             values greater than 1001 are not valid.
509
 
 *
510
 
 * If the compression type is "basic", then bits 6..4 of the
511
 
 * compression control byte (those xxx in 0xxx) specify the following:
512
 
 *
513
 
 *   bits 5-4:  decimal representation is the index of a particular zlib
514
 
 *              stream which should be used for decompressing the data;
515
 
 *   bit 6:     if 1, then a "filter id" byte is following this byte.
516
 
 *
517
 
 *-- The data that follows after the compression control byte described
518
 
 * above depends on the compression type ("fill", "jpeg" or "basic").
519
 
 *
520
 
 *-- If the compression type is "fill", then the only pixel value follows, in
521
 
 * client pixel format (see NOTE 1). This value applies to all pixels of the
522
 
 * rectangle.
523
 
 *
524
 
 *-- If the compression type is "jpeg", the following data stream looks like
525
 
 * this:
526
 
 *
527
 
 *   1..3 bytes:  data size (N) in compact representation;
528
 
 *   N bytes:     JPEG image.
529
 
 *
530
 
 * Data size is compactly represented in one, two or three bytes, according
531
 
 * to the following scheme:
532
 
 *
533
 
 *  0xxxxxxx                    (for values 0..127)
534
 
 *  1xxxxxxx 0yyyyyyy           (for values 128..16383)
535
 
 *  1xxxxxxx 1yyyyyyy zzzzzzzz  (for values 16384..4194303)
536
 
 *
537
 
 * Here each character denotes one bit, xxxxxxx are the least significant 7
538
 
 * bits of the value (bits 0-6), yyyyyyy are bits 7-13, and zzzzzzzz are the
539
 
 * most significant 8 bits (bits 14-21). For example, decimal value 10000
540
 
 * should be represented as two bytes: binary 10010000 01001110, or
541
 
 * hexadecimal 90 4E.
542
 
 *
543
 
 *-- If the compression type is "basic" and bit 6 of the compression control
544
 
 * byte was set to 1, then the next (second) byte specifies "filter id" which
545
 
 * tells the decoder what filter type was used by the encoder to pre-process
546
 
 * pixel data before the compression. The "filter id" byte can be one of the
547
 
 * following:
548
 
 *
549
 
 *   0:  no filter ("copy" filter);
550
 
 *   1:  "palette" filter;
551
 
 *   2:  "gradient" filter.
552
 
 *
553
 
 *-- If bit 6 of the compression control byte is set to 0 (no "filter id"
554
 
 * byte), or if the filter id is 0, then raw pixel values in the client
555
 
 * format (see NOTE 1) will be compressed. See below details on the
556
 
 * compression.
557
 
 *
558
 
 *-- The "gradient" filter pre-processes pixel data with a simple algorithm
559
 
 * which converts each color component to a difference between a "predicted"
560
 
 * intensity and the actual intensity. Such a technique does not affect
561
 
 * uncompressed data size, but helps to compress photo-like images better. 
562
 
 * Pseudo-code for converting intensities to differences is the following:
563
 
 *
564
 
 *   P[i,j] := V[i-1,j] + V[i,j-1] - V[i-1,j-1];
565
 
 *   if (P[i,j] < 0) then P[i,j] := 0;
566
 
 *   if (P[i,j] > MAX) then P[i,j] := MAX;
567
 
 *   D[i,j] := V[i,j] - P[i,j];
568
 
 *
569
 
 * Here V[i,j] is the intensity of a color component for a pixel at
570
 
 * coordinates (i,j). MAX is the maximum value of intensity for a color
571
 
 * component.
572
 
 *
573
 
 *-- The "palette" filter converts true-color pixel data to indexed colors
574
 
 * and a palette which can consist of 2..256 colors. If the number of colors
575
 
 * is 2, then each pixel is encoded in 1 bit, otherwise 8 bits is used to
576
 
 * encode one pixel. 1-bit encoding is performed such way that the most
577
 
 * significant bits correspond to the leftmost pixels, and each raw of pixels
578
 
 * is aligned to the byte boundary. When "palette" filter is used, the
579
 
 * palette is sent before the pixel data. The palette begins with an unsigned
580
 
 * byte which value is the number of colors in the palette minus 1 (i.e. 1
581
 
 * means 2 colors, 255 means 256 colors in the palette). Then follows the
582
 
 * palette itself which consist of pixel values in client pixel format (see
583
 
 * NOTE 1).
584
 
 *
585
 
 *-- The pixel data is compressed using the zlib library. But if the data
586
 
 * size after applying the filter but before the compression is less then 12,
587
 
 * then the data is sent as is, uncompressed. Four separate zlib streams
588
 
 * (0..3) can be used and the decoder should read the actual stream id from
589
 
 * the compression control byte (see NOTE 2).
590
 
 *
591
 
 * If the compression is not used, then the pixel data is sent as is,
592
 
 * otherwise the data stream looks like this:
593
 
 *
594
 
 *   1..3 bytes:  data size (N) in compact representation;
595
 
 *   N bytes:     zlib-compressed data.
596
 
 *
597
 
 * Data size is compactly represented in one, two or three bytes, just like
598
 
 * in the "jpeg" compression method (see above).
599
 
 *
600
 
 *-- NOTE 1. If the color depth is 24, and all three color components are
601
 
 * 8-bit wide, then one pixel in Tight encoding is always represented by
602
 
 * three bytes, where the first byte is red component, the second byte is
603
 
 * green component, and the third byte is blue component of the pixel color
604
 
 * value. This applies to colors in palettes as well.
605
 
 *
606
 
 *-- NOTE 2. The decoder must reset compression streams' states before
607
 
 * decoding the rectangle, if some of bits 0,1,2,3 in the compression control
608
 
 * byte are set to 1. Note that the decoder must reset zlib streams even if
609
 
 * the compression type is "fill" or "jpeg".
610
 
 *
611
 
 *-- NOTE 3. The "gradient" filter and "jpeg" compression may be used only
612
 
 * when bits-per-pixel value is either 16 or 32, not 8.
613
 
 *
614
 
 *-- NOTE 4. The width of any Tight-encoded rectangle cannot exceed 2048
615
 
 * pixels. If a rectangle is wider, it must be split into several rectangles
616
 
 * and each one should be encoded separately.
617
 
 *
618
 
 */
619
 
 
620
 
#define rfbTightExplicitFilter         0x04
621
 
#define rfbTightFill                   0x08
622
 
#define rfbTightJpeg                   0x09
623
 
#define rfbTightMaxSubencoding         0x09
624
 
 
625
 
/* Filters to improve compression efficiency */
626
 
#define rfbTightFilterCopy             0x00
627
 
#define rfbTightFilterPalette          0x01
628
 
#define rfbTightFilterGradient         0x02
629
 
 
630
 
 
631
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
632
 
 * XCursor encoding. This is a special encoding used to transmit X-style
633
 
 * cursor shapes from server to clients. Note that for this encoding,
634
 
 * coordinates in rfbFramebufferUpdateRectHeader structure hold hotspot
635
 
 * position (r.x, r.y) and cursor size (r.w, r.h). If (w * h != 0), two RGB
636
 
 * samples are sent after header in the rfbXCursorColors structure. They
637
 
 * denote foreground and background colors of the cursor. If a client
638
 
 * supports only black-and-white cursors, it should ignore these colors and
639
 
 * assume that foreground is black and background is white. Next, two bitmaps
640
 
 * (1 bits per pixel) follow: first one with actual data (value 0 denotes
641
 
 * background color, value 1 denotes foreground color), second one with
642
 
 * transparency data (bits with zero value mean that these pixels are
643
 
 * transparent). Both bitmaps represent cursor data in a byte stream, from
644
 
 * left to right, from top to bottom, and each row is byte-aligned. Most
645
 
 * significant bits correspond to leftmost pixels. The number of bytes in
646
 
 * each row can be calculated as ((w + 7) / 8). If (w * h == 0), cursor
647
 
 * should be hidden (or default local cursor should be set by the client).
648
 
 */
649
 
 
650
 
typedef struct {
651
 
    CARD8 foreRed;
652
 
    CARD8 foreGreen;
653
 
    CARD8 foreBlue;
654
 
    CARD8 backRed;
655
 
    CARD8 backGreen;
656
 
    CARD8 backBlue;
657
 
} rfbXCursorColors;
658
 
 
659
 
#define sz_rfbXCursorColors 6
660
 
 
661
 
 
662
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
663
 
 * RichCursor encoding. This is a special encoding used to transmit cursor
664
 
 * shapes from server to clients. It is similar to the XCursor encoding but
665
 
 * uses client pixel format instead of two RGB colors to represent cursor
666
 
 * image. For this encoding, coordinates in rfbFramebufferUpdateRectHeader
667
 
 * structure hold hotspot position (r.x, r.y) and cursor size (r.w, r.h).
668
 
 * After header, two pixmaps follow: first one with cursor image in current
669
 
 * client pixel format (like in raw encoding), second with transparency data
670
 
 * (1 bit per pixel, exactly the same format as used for transparency bitmap
671
 
 * in the XCursor encoding). If (w * h == 0), cursor should be hidden (or
672
 
 * default local cursor should be set by the client).
673
 
 */
674
 
 
675
 
 
676
 
/*-----------------------------------------------------------------------------
677
 
 * SetColourMapEntries - these messages are only sent if the pixel
678
 
 * format uses a "colour map" (i.e. trueColour false) and the client has not
679
 
 * fixed the entire colour map using FixColourMapEntries.  In addition they
680
 
 * will only start being sent after the client has sent its first
681
 
 * FramebufferUpdateRequest.  So if the client always tells the server to use
682
 
 * trueColour then it never needs to process this type of message.
683
 
 */
684
 
 
685
 
typedef struct {
686
 
    CARD8 type;                 /* always rfbSetColourMapEntries */
687
 
    CARD8 pad;
688
 
    CARD16 firstColour;
689
 
    CARD16 nColours;
690
 
 
691
 
    /* Followed by nColours * 3 * CARD16
692
 
       r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
693
 
 
694
 
} rfbSetColourMapEntriesMsg;
695
 
 
696
 
#define sz_rfbSetColourMapEntriesMsg 6
697
 
 
698
 
 
699
 
 
700
 
/*-----------------------------------------------------------------------------
701
 
 * Bell - ring a bell on the client if it has one.
702
 
 */
703
 
 
704
 
typedef struct {
705
 
    CARD8 type;                 /* always rfbBell */
706
 
} rfbBellMsg;
707
 
 
708
 
#define sz_rfbBellMsg 1
709
 
 
710
 
 
711
 
 
712
 
/*-----------------------------------------------------------------------------
713
 
 * ServerCutText - the server has new text in its cut buffer.
714
 
 */
715
 
 
716
 
typedef struct {
717
 
    CARD8 type;                 /* always rfbServerCutText */
718
 
    CARD8 pad1;
719
 
    CARD16 pad2;
720
 
    CARD32 length;
721
 
    /* followed by char text[length] */
722
 
} rfbServerCutTextMsg;
723
 
 
724
 
#define sz_rfbServerCutTextMsg 8
725
 
 
726
 
 
727
 
/*-----------------------------------------------------------------------------
728
 
 * Union of all server->client messages.
729
 
 */
730
 
 
731
 
typedef union {
732
 
    CARD8 type;
733
 
    rfbFramebufferUpdateMsg fu;
734
 
    rfbSetColourMapEntriesMsg scme;
735
 
    rfbBellMsg b;
736
 
    rfbServerCutTextMsg sct;
737
 
} rfbServerToClientMsg;
738
 
 
739
 
 
740
 
 
741
 
/*****************************************************************************
742
 
 *
743
 
 * Message definitions (client -> server)
744
 
 *
745
 
 *****************************************************************************/
746
 
 
747
 
 
748
 
/*-----------------------------------------------------------------------------
749
 
 * SetPixelFormat - tell the RFB server the format in which the client wants
750
 
 * pixels sent.
751
 
 */
752
 
 
753
 
typedef struct {
754
 
    CARD8 type;                 /* always rfbSetPixelFormat */
755
 
    CARD8 pad1;
756
 
    CARD16 pad2;
757
 
    rfbPixelFormat format;
758
 
} rfbSetPixelFormatMsg;
759
 
 
760
 
#define sz_rfbSetPixelFormatMsg (sz_rfbPixelFormat + 4)
761
 
 
762
 
 
763
 
/*-----------------------------------------------------------------------------
764
 
 * FixColourMapEntries - when the pixel format uses a "colour map", fix
765
 
 * read-only colour map entries.
766
 
 *
767
 
 *    ***************** NOT CURRENTLY SUPPORTED *****************
768
 
 */
769
 
 
770
 
typedef struct {
771
 
    CARD8 type;                 /* always rfbFixColourMapEntries */
772
 
    CARD8 pad;
773
 
    CARD16 firstColour;
774
 
    CARD16 nColours;
775
 
 
776
 
    /* Followed by nColours * 3 * CARD16
777
 
       r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
778
 
 
779
 
} rfbFixColourMapEntriesMsg;
780
 
 
781
 
#define sz_rfbFixColourMapEntriesMsg 6
782
 
 
783
 
 
784
 
/*-----------------------------------------------------------------------------
785
 
 * SetEncodings - tell the RFB server which encoding types we accept.  Put them
786
 
 * in order of preference, if we have any.  We may always receive raw
787
 
 * encoding, even if we don't specify it here.
788
 
 */
789
 
 
790
 
typedef struct {
791
 
    CARD8 type;                 /* always rfbSetEncodings */
792
 
    CARD8 pad;
793
 
    CARD16 nEncodings;
794
 
    /* followed by nEncodings * CARD32 encoding types */
795
 
} rfbSetEncodingsMsg;
796
 
 
797
 
#define sz_rfbSetEncodingsMsg 4
798
 
 
799
 
 
800
 
/*-----------------------------------------------------------------------------
801
 
 * FramebufferUpdateRequest - request for a framebuffer update.  If incremental
802
 
 * is true then the client just wants the changes since the last update.  If
803
 
 * false then it wants the whole of the specified rectangle.
804
 
 */
805
 
 
806
 
typedef struct {
807
 
    CARD8 type;                 /* always rfbFramebufferUpdateRequest */
808
 
    CARD8 incremental;
809
 
    CARD16 x;
810
 
    CARD16 y;
811
 
    CARD16 w;
812
 
    CARD16 h;
813
 
} rfbFramebufferUpdateRequestMsg;
814
 
 
815
 
#define sz_rfbFramebufferUpdateRequestMsg 10
816
 
 
817
 
 
818
 
/*-----------------------------------------------------------------------------
819
 
 * KeyEvent - key press or release
820
 
 *
821
 
 * Keys are specified using the "keysym" values defined by the X Window System.
822
 
 * For most ordinary keys, the keysym is the same as the corresponding ASCII
823
 
 * value.  Other common keys are:
824
 
 *
825
 
 * BackSpace            0xff08
826
 
 * Tab                  0xff09
827
 
 * Return or Enter      0xff0d
828
 
 * Escape               0xff1b
829
 
 * Insert               0xff63
830
 
 * Delete               0xffff
831
 
 * Home                 0xff50
832
 
 * End                  0xff57
833
 
 * Page Up              0xff55
834
 
 * Page Down            0xff56
835
 
 * Left                 0xff51
836
 
 * Up                   0xff52
837
 
 * Right                0xff53
838
 
 * Down                 0xff54
839
 
 * F1                   0xffbe
840
 
 * F2                   0xffbf
841
 
 * ...                  ...
842
 
 * F12                  0xffc9
843
 
 * Shift                0xffe1
844
 
 * Control              0xffe3
845
 
 * Meta                 0xffe7
846
 
 * Alt                  0xffe9
847
 
 */
848
 
 
849
 
typedef struct {
850
 
    CARD8 type;                 /* always rfbKeyEvent */
851
 
    CARD8 down;                 /* true if down (press), false if up */
852
 
    CARD16 pad;
853
 
    CARD32 key;                 /* key is specified as an X keysym */
854
 
} rfbKeyEventMsg;
855
 
 
856
 
#define sz_rfbKeyEventMsg 8
857
 
 
858
 
 
859
 
/*-----------------------------------------------------------------------------
860
 
 * PointerEvent - mouse/pen move and/or button press.
861
 
 */
862
 
 
863
 
typedef struct {
864
 
    CARD8 type;                 /* always rfbPointerEvent */
865
 
    CARD8 buttonMask;           /* bits 0-7 are buttons 1-8, 0=up, 1=down */
866
 
    CARD16 x;
867
 
    CARD16 y;
868
 
} rfbPointerEventMsg;
869
 
 
870
 
#define rfbButton1Mask 1
871
 
#define rfbButton2Mask 2
872
 
#define rfbButton3Mask 4
873
 
 
874
 
#define sz_rfbPointerEventMsg 6
875
 
 
876
 
 
877
 
 
878
 
/*-----------------------------------------------------------------------------
879
 
 * ClientCutText - the client has new text in its cut buffer.
880
 
 */
881
 
 
882
 
typedef struct {
883
 
    CARD8 type;                 /* always rfbClientCutText */
884
 
    CARD8 pad1;
885
 
    CARD16 pad2;
886
 
    CARD32 length;
887
 
    /* followed by char text[length] */
888
 
} rfbClientCutTextMsg;
889
 
 
890
 
#define sz_rfbClientCutTextMsg 8
891
 
 
892
 
 
893
 
 
894
 
/*-----------------------------------------------------------------------------
895
 
 * Union of all client->server messages.
896
 
 */
897
 
 
898
 
typedef union {
899
 
    CARD8 type;
900
 
    rfbSetPixelFormatMsg spf;
901
 
    rfbFixColourMapEntriesMsg fcme;
902
 
    rfbSetEncodingsMsg se;
903
 
    rfbFramebufferUpdateRequestMsg fur;
904
 
    rfbKeyEventMsg ke;
905
 
    rfbPointerEventMsg pe;
906
 
    rfbClientCutTextMsg cct;
907
 
} rfbClientToServerMsg;