blob: 42134c3c7ae4d540de534cf37e5b3bb7e935b759 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18#include <rdr/InStream.h>
19#include <rdr/OutStream.h>
20#include <rfb/Exception.h>
21#include <rfb/encodings.h>
22#include <rfb/Encoder.h>
23#include <rfb/ConnParams.h>
24#include <rfb/util.h>
25
26using namespace rfb;
27
28ConnParams::ConnParams()
Constantin Kaplinskyce0907d2006-09-08 12:55:37 +000029 : majorVersion(0), minorVersion(0), tightExtensionsEnabled(false),
30 width(0), height(0), useCopyRect(false),
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000031 supportsLocalCursor(false), supportsLocalXCursor(false), supportsDesktopResize(true),
32 supportsLastRect(false), customCompressLevel(false), compressLevel(6),
33 noJpeg(false), qualityLevel(-1),
34 name_(0), nEncodings_(0), encodings_(0),
35 currentEncoding_(encodingRaw), verStrPos(0)
36{
37 setName("");
38}
39
40ConnParams::~ConnParams()
41{
42 delete [] name_;
43 delete [] encodings_;
44}
45
46bool ConnParams::readVersion(rdr::InStream* is, bool* done)
47{
48 if (verStrPos >= 12) return false;
49 while (is->checkNoWait(1) && verStrPos < 12) {
50 verStr[verStrPos++] = is->readU8();
51 }
52
53 if (verStrPos < 12) {
54 *done = false;
55 return true;
56 }
57 *done = true;
58 verStr[12] = 0;
59 return (sscanf(verStr, "RFB %03d.%03d\n", &majorVersion,&minorVersion) == 2);
60}
61
62void ConnParams::writeVersion(rdr::OutStream* os)
63{
64 char str[13];
65 sprintf(str, "RFB %03d.%03d\n", majorVersion, minorVersion);
66 os->writeBytes(str, 12);
67 os->flush();
68}
69
70void ConnParams::setPF(const PixelFormat& pf)
71{
72 pf_ = pf;
73
74 if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
75 throw Exception("setPF: not 8, 16 or 32 bpp?");
76}
77
78void ConnParams::setName(const char* name)
79{
80 delete [] name_;
81 name_ = strDup(name);
82}
83
84void ConnParams::setEncodings(int nEncodings, const rdr::U32* encodings)
85{
86 if (nEncodings > nEncodings_) {
87 delete [] encodings_;
88 encodings_ = new rdr::U32[nEncodings];
89 }
90 nEncodings_ = nEncodings;
91 useCopyRect = false;
92 supportsLocalCursor = false;
93 supportsDesktopResize = false;
94 supportsLocalXCursor = false;
95 supportsLastRect = false;
96 customCompressLevel = false;
97 compressLevel = -1;
98 noJpeg = true;
99 qualityLevel = -1;
100 currentEncoding_ = encodingRaw;
101
102 for (int i = nEncodings-1; i >= 0; i--) {
103 encodings_[i] = encodings[i];
104
105 if (encodings[i] == encodingCopyRect)
106 useCopyRect = true;
107 else if (encodings[i] == pseudoEncodingCursor)
108 supportsLocalCursor = true;
109 else if (encodings[i] == pseudoEncodingXCursor)
110 supportsLocalXCursor = true;
111 else if (encodings[i] == pseudoEncodingDesktopSize)
112 supportsDesktopResize = true;
113 else if (encodings[i] == pseudoEncodingLastRect)
114 supportsLastRect = true;
115 else if (encodings[i] >= pseudoEncodingCompressLevel0 &&
116 encodings[i] <= pseudoEncodingCompressLevel9) {
117 customCompressLevel = true;
118 compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
119 } else if (encodings[i] >= pseudoEncodingQualityLevel0 &&
120 encodings[i] <= pseudoEncodingQualityLevel9) {
121 noJpeg = false;
122 qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
123 } else if (encodings[i] <= encodingMax && Encoder::supported(encodings[i]))
124 currentEncoding_ = encodings[i];
125 }
126}