-
Notifications
You must be signed in to change notification settings - Fork 9
/
rfb.h
255 lines (180 loc) · 5.63 KB
/
rfb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
* rfb.h - header file for RFB DDX implementation.
*/
/*
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
* Copyright (C) 2012, 2014 D. R. Commander. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
#ifndef __RFB_H__
#define __RFB_H__
#include <zlib.h>
typedef unsigned char CARD8;
typedef unsigned short CARD16;
typedef unsigned int CARD32;
#define CONCAT2(a,b) a##b
#define CONCAT2E(a,b) CONCAT2(a,b)
#include "rfbproto.h"
#define MAX_ENCODINGS 17
typedef int BOOL, Bool;
#define FALSE 0
#define TRUE 1
#define False 0
#define True 1
#define xalloc malloc
#define xrealloc realloc
/*
* Per-screen (framebuffer) structure. There is only one of these, since we
* don't allow the X server to have multiple screens.
*/
typedef struct
{
int width;
int paddedWidthInBytes;
int height;
int sizeInBytes;
int bitsPerPixel;
char pfbMemory[1280*1024*4];
} rfbScreenInfo, *rfbScreenInfoPtr;
typedef struct
{
int width, height;
char *data;
int bytes_per_line;
int bits_per_pixel;
} XImage;
/*
* Per-client structure.
*/
struct rfbClientRec;
typedef void (*rfbTranslateFnType)(char *table, rfbPixelFormat *in,
rfbPixelFormat *out,
char *iptr, char *optr,
int bytesBetweenInputLines,
int width, int height);
typedef struct rfbClientRec {
rfbPixelFormat format;
/* statistics */
int rfbBytesSent[MAX_ENCODINGS];
int rfbRectanglesSent[MAX_ENCODINGS];
int rfbFramebufferUpdateMessagesSent;
int rfbRawBytesEquivalent;
rfbTranslateFnType translateFn;
char *translateLookupTable;
/* ZRLE encoding */
void* zrleData;
int zywrleLevel;
int zywrleBuf[rfbZRLETileWidth * rfbZRLETileHeight];
char *zrleBeforeBuf;
void *paletteHelper;
/* tight encoding -- preserve zlib streams' state for each client */
z_stream zsStruct[4];
Bool zsActive[4];
/* For the zlib encoding, necessary compression state info per client. */
struct z_stream_s compStream;
Bool compStreamInited;
int zsLevel[4];
Bool reset;
#ifdef ICE_SUPPORTED
/* Interframe comparison */
char *compareFB;
Bool firstCompare;
#endif
char *fb;
} rfbClientRec, *rfbClientPtr;
extern rfbClientRec rfbClient;
/*
* Macros for endian swapping.
*/
#define Swap16(s) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))
#define Swap32(l) (((l) >> 24) | \
(((l) & 0x00ff0000) >> 8) | \
(((l) & 0x0000ff00) << 8) | \
((l) << 24))
/* init.c */
static const int rfbEndianTest = 1;
#define Swap16IfLE(s) (*(const char *)&rfbEndianTest ? Swap16(s) : (s))
#define Swap32IfLE(l) (*(const char *)&rfbEndianTest ? Swap32(l) : (l))
extern rfbScreenInfo rfbScreen;
/* rfbserver.c */
/*
* UPDATE_BUF_SIZE must be big enough to send at least one whole line of the
* framebuffer. So for a max screen width of say 2K with 32-bit pixels this
* means 8K minimum.
*/
#ifdef __cplusplus
extern "C" {
#endif
#define UPDATE_BUF_SIZE 30000
extern char updateBuf[UPDATE_BUF_SIZE];
extern int ublen;
extern Bool rfbSendUpdateBuf(rfbClientPtr cl);
/*
* This must be big enough to hold a single 1280x1024 raw rectangle
*/
#define SEND_BUF_SIZE (5*1024*1024)
extern char *sendBuf;
extern int sblen, sbptr;
/* translate.c */
extern rfbPixelFormat rfbServerFormat;
extern void rfbTranslateNone(char *table, rfbPixelFormat *in,
rfbPixelFormat *out,
char *iptr, char *optr,
int bytesBetweenInputLines,
int width, int height);
/* hextile.c */
extern Bool rfbSendRectEncodingHextile(rfbClientPtr cl, int x, int y, int w,
int h);
/* zrle.c */
extern Bool rfbSendRectEncodingZRLE(rfbClientPtr cl, int x, int y, int w,
int h);
void rfbFreeZrleData(rfbClientPtr cl);
/* tight.c */
/*** For tight-1.0 only ***/
#define TIGHT_MAX_RECT_WIDTH 512
#define TIGHT_MAX_RECT_HEIGHT 128
/*** For tight-1.0 only ***/
#define TIGHT_MAX_RECT_SIZE 65536
#define TVNC_SAMPOPT 4
extern Bool rfbTightDisableGradient;
extern Bool rfbSendRectEncodingTight(rfbClientPtr cl, int x,int y,int w,int h);
/* zlib.h */
/* Minimum zlib rectangle size in bytes. Anything smaller will
* not compress well due to overhead.
*/
#define VNC_ENCODE_ZLIB_MIN_COMP_SIZE (17)
/* Set maximum zlib rectangle size in pixels. Always allow at least
* two scan lines.
*/
#define ZLIB_MAX_RECT_SIZE (128*256)
#define ZLIB_MAX_SIZE(min) ((( min * 2 ) > ZLIB_MAX_RECT_SIZE ) ? ( min * 2 ) : ZLIB_MAX_RECT_SIZE )
extern Bool rfbSendRectEncodingZlib(rfbClientPtr cl, int x, int y, int w,
int h);
/* */
#ifdef ICE_SUPPORTED
extern Bool InterframeOn(rfbClientPtr cl);
#endif
extern void InitEverything (int color_depth);
extern int rfbLog (char *fmt, ...);
extern void rfbLogPerror(char *str);
extern Bool rfbSendRectEncodingRaw(rfbClientPtr cl, int x,int y,int w,int h);
extern Bool ReadFromRFBServer(char *out, unsigned int n);
extern Bool WriteToSessionCapture(char *buf, int len);
#ifdef __cplusplus
}
#endif
#endif