You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConnParams.cxx 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* 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 <stdio.h>
  19. #include <rdr/InStream.h>
  20. #include <rdr/OutStream.h>
  21. #include <rfb/Exception.h>
  22. #include <rfb/encodings.h>
  23. #include <rfb/Encoder.h>
  24. #include <rfb/ConnParams.h>
  25. #include <rfb/util.h>
  26. using namespace rfb;
  27. ConnParams::ConnParams()
  28. : majorVersion(0), minorVersion(0), tightExtensionsEnabled(false),
  29. width(0), height(0), useCopyRect(false),
  30. supportsLocalCursor(false), supportsLocalXCursor(false), supportsDesktopResize(true), supportsDesktopRename(false),
  31. supportsLastRect(false), customCompressLevel(false), compressLevel(6),
  32. noJpeg(false), qualityLevel(-1),
  33. name_(0), nEncodings_(0), encodings_(0),
  34. currentEncoding_(encodingRaw), verStrPos(0)
  35. {
  36. setName("");
  37. }
  38. ConnParams::~ConnParams()
  39. {
  40. delete [] name_;
  41. delete [] encodings_;
  42. }
  43. bool ConnParams::readVersion(rdr::InStream* is, bool* done)
  44. {
  45. if (verStrPos >= 12) return false;
  46. while (is->checkNoWait(1) && verStrPos < 12) {
  47. verStr[verStrPos++] = is->readU8();
  48. }
  49. if (verStrPos < 12) {
  50. *done = false;
  51. return true;
  52. }
  53. *done = true;
  54. verStr[12] = 0;
  55. return (sscanf(verStr, "RFB %03d.%03d\n", &majorVersion,&minorVersion) == 2);
  56. }
  57. void ConnParams::writeVersion(rdr::OutStream* os)
  58. {
  59. char str[13];
  60. sprintf(str, "RFB %03d.%03d\n", majorVersion, minorVersion);
  61. os->writeBytes(str, 12);
  62. os->flush();
  63. }
  64. void ConnParams::setPF(const PixelFormat& pf)
  65. {
  66. pf_ = pf;
  67. if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
  68. throw Exception("setPF: not 8, 16 or 32 bpp?");
  69. }
  70. void ConnParams::setName(const char* name)
  71. {
  72. delete [] name_;
  73. name_ = strDup(name);
  74. }
  75. void ConnParams::setEncodings(int nEncodings, const rdr::U32* encodings)
  76. {
  77. if (nEncodings > nEncodings_) {
  78. delete [] encodings_;
  79. encodings_ = new rdr::U32[nEncodings];
  80. }
  81. nEncodings_ = nEncodings;
  82. useCopyRect = false;
  83. supportsLocalCursor = false;
  84. supportsDesktopResize = false;
  85. supportsLocalXCursor = false;
  86. supportsLastRect = false;
  87. customCompressLevel = false;
  88. compressLevel = -1;
  89. noJpeg = true;
  90. qualityLevel = -1;
  91. currentEncoding_ = encodingRaw;
  92. for (int i = nEncodings-1; i >= 0; i--) {
  93. encodings_[i] = encodings[i];
  94. if (encodings[i] == encodingCopyRect)
  95. useCopyRect = true;
  96. else if (encodings[i] == pseudoEncodingCursor)
  97. supportsLocalCursor = true;
  98. else if (encodings[i] == pseudoEncodingXCursor)
  99. supportsLocalXCursor = true;
  100. else if (encodings[i] == pseudoEncodingDesktopSize)
  101. supportsDesktopResize = true;
  102. else if (encodings[i] == pseudoEncodingDesktopName)
  103. supportsDesktopRename = true;
  104. else if (encodings[i] == pseudoEncodingLastRect)
  105. supportsLastRect = true;
  106. else if (encodings[i] >= pseudoEncodingCompressLevel0 &&
  107. encodings[i] <= pseudoEncodingCompressLevel9) {
  108. customCompressLevel = true;
  109. compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
  110. } else if (encodings[i] >= pseudoEncodingQualityLevel0 &&
  111. encodings[i] <= pseudoEncodingQualityLevel9) {
  112. noJpeg = false;
  113. qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
  114. } else if (encodings[i] <= encodingMax && Encoder::supported(encodings[i]))
  115. currentEncoding_ = encodings[i];
  116. }
  117. }