@novnc/novnc 1.3.0-beta → 1.3.0-g0cb5f23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +13 -3
  2. package/core/decoders/jpeg.js +141 -0
  3. package/core/decoders/raw.js +1 -1
  4. package/core/decoders/zrle.js +185 -0
  5. package/core/display.js +12 -0
  6. package/core/encodings.js +4 -0
  7. package/core/input/keyboard.js +10 -0
  8. package/core/ra2.js +567 -0
  9. package/core/rfb.js +393 -84
  10. package/core/util/md5.js +79 -0
  11. package/docs/API.md +105 -4
  12. package/lib/base64.js +20 -34
  13. package/lib/decoders/copyrect.js +1 -11
  14. package/lib/decoders/hextile.js +14 -46
  15. package/lib/decoders/jpeg.js +146 -0
  16. package/lib/decoders/raw.js +6 -22
  17. package/lib/decoders/rre.js +1 -15
  18. package/lib/decoders/tight.js +10 -78
  19. package/lib/decoders/tightpng.js +5 -27
  20. package/lib/decoders/zrle.js +185 -0
  21. package/lib/deflator.js +5 -22
  22. package/lib/des.js +20 -36
  23. package/lib/display.js +59 -107
  24. package/lib/encodings.js +7 -8
  25. package/lib/inflator.js +2 -18
  26. package/lib/input/domkeytable.js +77 -48
  27. package/lib/input/fixedkeys.js +8 -3
  28. package/lib/input/gesturehandler.js +82 -152
  29. package/lib/input/keyboard.js +59 -90
  30. package/lib/input/keysym.js +14 -270
  31. package/lib/input/keysymdef.js +5 -7
  32. package/lib/input/util.js +44 -86
  33. package/lib/input/vkeys.js +0 -3
  34. package/lib/input/xtscancodes.js +1 -168
  35. package/lib/ra2.js +1033 -0
  36. package/lib/rfb.js +716 -922
  37. package/lib/util/browser.js +24 -29
  38. package/lib/util/cursor.js +21 -65
  39. package/lib/util/element.js +3 -5
  40. package/lib/util/events.js +25 -32
  41. package/lib/util/eventtarget.js +1 -13
  42. package/lib/util/int.js +2 -3
  43. package/lib/util/logging.js +3 -21
  44. package/lib/util/md5.js +83 -0
  45. package/lib/util/strings.js +3 -5
  46. package/lib/vendor/pako/lib/utils/common.js +10 -19
  47. package/lib/vendor/pako/lib/zlib/adler32.js +3 -7
  48. package/lib/vendor/pako/lib/zlib/constants.js +2 -5
  49. package/lib/vendor/pako/lib/zlib/crc32.js +5 -12
  50. package/lib/vendor/pako/lib/zlib/deflate.js +218 -622
  51. package/lib/vendor/pako/lib/zlib/gzheader.js +1 -13
  52. package/lib/vendor/pako/lib/zlib/inffast.js +60 -172
  53. package/lib/vendor/pako/lib/zlib/inflate.js +407 -874
  54. package/lib/vendor/pako/lib/zlib/inftrees.js +63 -169
  55. package/lib/vendor/pako/lib/zlib/messages.js +1 -11
  56. package/lib/vendor/pako/lib/zlib/trees.js +248 -590
  57. package/lib/vendor/pako/lib/zlib/zstream.js +2 -18
  58. package/lib/websock.js +33 -86
  59. package/package.json +32 -37
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ /*
11
+ * noVNC: HTML5 VNC client
12
+ * Copyright (C) 2019 The noVNC Authors
13
+ * Licensed under MPL 2.0 (see LICENSE.txt)
14
+ *
15
+ * See README.md for usage and integration instructions.
16
+ *
17
+ */
18
+ var JPEGDecoder = /*#__PURE__*/function () {
19
+ function JPEGDecoder() {
20
+ _classCallCheck(this, JPEGDecoder);
21
+ // RealVNC will reuse the quantization tables
22
+ // and Huffman tables, so we need to cache them.
23
+ this._quantTables = [];
24
+ this._huffmanTables = [];
25
+ this._cachedQuantTables = [];
26
+ this._cachedHuffmanTables = [];
27
+ this._jpegLength = 0;
28
+ this._segments = [];
29
+ }
30
+ _createClass(JPEGDecoder, [{
31
+ key: "decodeRect",
32
+ value: function decodeRect(x, y, width, height, sock, display, depth) {
33
+ // A rect of JPEG encodings is simply a JPEG file
34
+ if (!this._parseJPEG(sock.rQslice(0))) {
35
+ return false;
36
+ }
37
+ var data = sock.rQshiftBytes(this._jpegLength);
38
+ if (this._quantTables.length != 0 && this._huffmanTables.length != 0) {
39
+ // If there are quantization tables and Huffman tables in the JPEG
40
+ // image, we can directly render it.
41
+ display.imageRect(x, y, width, height, "image/jpeg", data);
42
+ return true;
43
+ } else {
44
+ // Otherwise we need to insert cached tables.
45
+ var sofIndex = this._segments.findIndex(function (x) {
46
+ return x[1] == 0xC0 || x[1] == 0xC2;
47
+ });
48
+ if (sofIndex == -1) {
49
+ throw new Error("Illegal JPEG image without SOF");
50
+ }
51
+ var segments = this._segments.slice(0, sofIndex);
52
+ segments = segments.concat(this._quantTables.length ? this._quantTables : this._cachedQuantTables);
53
+ segments.push(this._segments[sofIndex]);
54
+ segments = segments.concat(this._huffmanTables.length ? this._huffmanTables : this._cachedHuffmanTables, this._segments.slice(sofIndex + 1));
55
+ var length = 0;
56
+ for (var i = 0; i < segments.length; i++) {
57
+ length += segments[i].length;
58
+ }
59
+ var _data = new Uint8Array(length);
60
+ length = 0;
61
+ for (var _i = 0; _i < segments.length; _i++) {
62
+ _data.set(segments[_i], length);
63
+ length += segments[_i].length;
64
+ }
65
+ display.imageRect(x, y, width, height, "image/jpeg", _data);
66
+ return true;
67
+ }
68
+ }
69
+ }, {
70
+ key: "_parseJPEG",
71
+ value: function _parseJPEG(buffer) {
72
+ if (this._quantTables.length != 0) {
73
+ this._cachedQuantTables = this._quantTables;
74
+ }
75
+ if (this._huffmanTables.length != 0) {
76
+ this._cachedHuffmanTables = this._huffmanTables;
77
+ }
78
+ this._quantTables = [];
79
+ this._huffmanTables = [];
80
+ this._segments = [];
81
+ var i = 0;
82
+ var bufferLength = buffer.length;
83
+ while (true) {
84
+ var j = i;
85
+ if (j + 2 > bufferLength) {
86
+ return false;
87
+ }
88
+ if (buffer[j] != 0xFF) {
89
+ throw new Error("Illegal JPEG marker received (byte: " + buffer[j] + ")");
90
+ }
91
+ var type = buffer[j + 1];
92
+ j += 2;
93
+ if (type == 0xD9) {
94
+ this._jpegLength = j;
95
+ this._segments.push(buffer.slice(i, j));
96
+ return true;
97
+ } else if (type == 0xDA) {
98
+ // start of scan
99
+ var hasFoundEndOfScan = false;
100
+ for (var k = j + 3; k + 1 < bufferLength; k++) {
101
+ if (buffer[k] == 0xFF && buffer[k + 1] != 0x00 && !(buffer[k + 1] >= 0xD0 && buffer[k + 1] <= 0xD7)) {
102
+ j = k;
103
+ hasFoundEndOfScan = true;
104
+ break;
105
+ }
106
+ }
107
+ if (!hasFoundEndOfScan) {
108
+ return false;
109
+ }
110
+ this._segments.push(buffer.slice(i, j));
111
+ i = j;
112
+ continue;
113
+ } else if (type >= 0xD0 && type < 0xD9 || type == 0x01) {
114
+ // No length after marker
115
+ this._segments.push(buffer.slice(i, j));
116
+ i = j;
117
+ continue;
118
+ }
119
+ if (j + 2 > bufferLength) {
120
+ return false;
121
+ }
122
+ var length = (buffer[j] << 8) + buffer[j + 1] - 2;
123
+ if (length < 0) {
124
+ throw new Error("Illegal JPEG length received (length: " + length + ")");
125
+ }
126
+ j += 2;
127
+ if (j + length > bufferLength) {
128
+ return false;
129
+ }
130
+ j += length;
131
+ var segment = buffer.slice(i, j);
132
+ if (type == 0xC4) {
133
+ // Huffman tables
134
+ this._huffmanTables.push(segment);
135
+ } else if (type == 0xDB) {
136
+ // Quantization tables
137
+ this._quantTables.push(segment);
138
+ }
139
+ this._segments.push(segment);
140
+ i = j;
141
+ }
142
+ }
143
+ }]);
144
+ return JPEGDecoder;
145
+ }();
146
+ exports["default"] = JPEGDecoder;
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
-
10
8
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
11
-
12
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
13
-
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
14
10
  /*
15
11
  * noVNC: HTML5 VNC client
16
12
  * Copyright (C) 2019 The noVNC Authors
@@ -22,66 +18,54 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
22
18
  var RawDecoder = /*#__PURE__*/function () {
23
19
  function RawDecoder() {
24
20
  _classCallCheck(this, RawDecoder);
25
-
26
21
  this._lines = 0;
27
22
  }
28
-
29
23
  _createClass(RawDecoder, [{
30
24
  key: "decodeRect",
31
25
  value: function decodeRect(x, y, width, height, sock, display, depth) {
32
26
  if (width === 0 || height === 0) {
33
27
  return true;
34
28
  }
35
-
36
29
  if (this._lines === 0) {
37
30
  this._lines = height;
38
31
  }
39
-
40
32
  var pixelSize = depth == 8 ? 1 : 4;
41
33
  var bytesPerLine = width * pixelSize;
42
-
43
34
  if (sock.rQwait("RAW", bytesPerLine)) {
44
35
  return false;
45
36
  }
46
-
47
37
  var curY = y + (height - this._lines);
48
38
  var currHeight = Math.min(this._lines, Math.floor(sock.rQlen / bytesPerLine));
49
39
  var pixels = width * currHeight;
50
40
  var data = sock.rQ;
51
- var index = sock.rQi; // Convert data if needed
41
+ var index = sock.rQi;
52
42
 
43
+ // Convert data if needed
53
44
  if (depth == 8) {
54
45
  var newdata = new Uint8Array(pixels * 4);
55
-
56
46
  for (var i = 0; i < pixels; i++) {
57
47
  newdata[i * 4 + 0] = (data[index + i] >> 0 & 0x3) * 255 / 3;
58
48
  newdata[i * 4 + 1] = (data[index + i] >> 2 & 0x3) * 255 / 3;
59
49
  newdata[i * 4 + 2] = (data[index + i] >> 4 & 0x3) * 255 / 3;
60
50
  newdata[i * 4 + 3] = 255;
61
51
  }
62
-
63
52
  data = newdata;
64
53
  index = 0;
65
- } // Max sure the image is fully opaque
66
-
54
+ }
67
55
 
56
+ // Max sure the image is fully opaque
68
57
  for (var _i = 0; _i < pixels; _i++) {
69
- data[_i * 4 + 3] = 255;
58
+ data[index + _i * 4 + 3] = 255;
70
59
  }
71
-
72
60
  display.blitImage(x, curY, width, currHeight, data, index);
73
61
  sock.rQskipBytes(currHeight * bytesPerLine);
74
62
  this._lines -= currHeight;
75
-
76
63
  if (this._lines > 0) {
77
64
  return false;
78
65
  }
79
-
80
66
  return true;
81
67
  }
82
68
  }]);
83
-
84
69
  return RawDecoder;
85
70
  }();
86
-
87
71
  exports["default"] = RawDecoder;
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
-
10
8
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
11
-
12
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
13
-
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
14
10
  /*
15
11
  * noVNC: HTML5 VNC client
16
12
  * Copyright (C) 2019 The noVNC Authors
@@ -22,10 +18,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
22
18
  var RREDecoder = /*#__PURE__*/function () {
23
19
  function RREDecoder() {
24
20
  _classCallCheck(this, RREDecoder);
25
-
26
21
  this._subrects = 0;
27
22
  }
28
-
29
23
  _createClass(RREDecoder, [{
30
24
  key: "decodeRect",
31
25
  value: function decodeRect(x, y, width, height, sock, display, depth) {
@@ -33,20 +27,15 @@ var RREDecoder = /*#__PURE__*/function () {
33
27
  if (sock.rQwait("RRE", 4 + 4)) {
34
28
  return false;
35
29
  }
36
-
37
30
  this._subrects = sock.rQshift32();
38
31
  var color = sock.rQshiftBytes(4); // Background
39
-
40
32
  display.fillRect(x, y, width, height, color);
41
33
  }
42
-
43
34
  while (this._subrects > 0) {
44
35
  if (sock.rQwait("RRE", 4 + 8)) {
45
36
  return false;
46
37
  }
47
-
48
38
  var _color = sock.rQshiftBytes(4);
49
-
50
39
  var sx = sock.rQshift16();
51
40
  var sy = sock.rQshift16();
52
41
  var swidth = sock.rQshift16();
@@ -54,12 +43,9 @@ var RREDecoder = /*#__PURE__*/function () {
54
43
  display.fillRect(x + sx, y + sy, swidth, sheight, _color);
55
44
  this._subrects--;
56
45
  }
57
-
58
46
  return true;
59
47
  }
60
48
  }]);
61
-
62
49
  return RREDecoder;
63
50
  }();
64
-
65
51
  exports["default"] = RREDecoder;
@@ -1,45 +1,31 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
-
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = void 0;
9
-
10
8
  var Log = _interopRequireWildcard(require("../util/logging.js"));
11
-
12
9
  var _inflator = _interopRequireDefault(require("../inflator.js"));
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
11
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
12
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
13
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
-
22
14
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
23
-
24
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
25
-
15
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
26
16
  var TightDecoder = /*#__PURE__*/function () {
27
17
  function TightDecoder() {
28
18
  _classCallCheck(this, TightDecoder);
29
-
30
19
  this._ctl = null;
31
20
  this._filter = null;
32
21
  this._numColors = 0;
33
22
  this._palette = new Uint8Array(1024); // 256 * 4 (max palette size * max bytes-per-pixel)
34
-
35
23
  this._len = 0;
36
24
  this._zlibs = [];
37
-
38
25
  for (var i = 0; i < 4; i++) {
39
26
  this._zlibs[i] = new _inflator["default"]();
40
27
  }
41
28
  }
42
-
43
29
  _createClass(TightDecoder, [{
44
30
  key: "decodeRect",
45
31
  value: function decodeRect(x, y, width, height, sock, display, depth) {
@@ -47,23 +33,20 @@ var TightDecoder = /*#__PURE__*/function () {
47
33
  if (sock.rQwait("TIGHT compression-control", 1)) {
48
34
  return false;
49
35
  }
36
+ this._ctl = sock.rQshift8();
50
37
 
51
- this._ctl = sock.rQshift8(); // Reset streams if the server requests it
52
-
38
+ // Reset streams if the server requests it
53
39
  for (var i = 0; i < 4; i++) {
54
40
  if (this._ctl >> i & 1) {
55
41
  this._zlibs[i].reset();
56
-
57
42
  Log.Info("Reset zlib stream " + i);
58
43
  }
59
- } // Figure out filter
60
-
44
+ }
61
45
 
46
+ // Figure out filter
62
47
  this._ctl = this._ctl >> 4;
63
48
  }
64
-
65
49
  var ret;
66
-
67
50
  if (this._ctl === 0x08) {
68
51
  ret = this._fillRect(x, y, width, height, sock, display, depth);
69
52
  } else if (this._ctl === 0x09) {
@@ -75,11 +58,9 @@ var TightDecoder = /*#__PURE__*/function () {
75
58
  } else {
76
59
  throw new Error("Illegal tight compression received (ctl: " + this._ctl + ")");
77
60
  }
78
-
79
61
  if (ret) {
80
62
  this._ctl = null;
81
63
  }
82
-
83
64
  return ret;
84
65
  }
85
66
  }, {
@@ -88,7 +69,6 @@ var TightDecoder = /*#__PURE__*/function () {
88
69
  if (sock.rQwait("TIGHT", 3)) {
89
70
  return false;
90
71
  }
91
-
92
72
  var rQi = sock.rQi;
93
73
  var rQ = sock.rQ;
94
74
  display.fillRect(x, y, width, height, [rQ[rQi], rQ[rQi + 1], rQ[rQi + 2]], false);
@@ -99,11 +79,9 @@ var TightDecoder = /*#__PURE__*/function () {
99
79
  key: "_jpegRect",
100
80
  value: function _jpegRect(x, y, width, height, sock, display, depth) {
101
81
  var data = this._readData(sock);
102
-
103
82
  if (data === null) {
104
83
  return false;
105
84
  }
106
-
107
85
  display.imageRect(x, y, width, height, "image/jpeg", data);
108
86
  return true;
109
87
  }
@@ -120,41 +98,33 @@ var TightDecoder = /*#__PURE__*/function () {
120
98
  if (sock.rQwait("TIGHT", 1)) {
121
99
  return false;
122
100
  }
123
-
124
101
  this._filter = sock.rQshift8();
125
102
  } else {
126
103
  // Implicit CopyFilter
127
104
  this._filter = 0;
128
105
  }
129
106
  }
130
-
131
107
  var streamId = ctl & 0x3;
132
108
  var ret;
133
-
134
109
  switch (this._filter) {
135
110
  case 0:
136
111
  // CopyFilter
137
112
  ret = this._copyFilter(streamId, x, y, width, height, sock, display, depth);
138
113
  break;
139
-
140
114
  case 1:
141
115
  // PaletteFilter
142
116
  ret = this._paletteFilter(streamId, x, y, width, height, sock, display, depth);
143
117
  break;
144
-
145
118
  case 2:
146
119
  // GradientFilter
147
120
  ret = this._gradientFilter(streamId, x, y, width, height, sock, display, depth);
148
121
  break;
149
-
150
122
  default:
151
123
  throw new Error("Illegal tight filter received (ctl: " + this._filter + ")");
152
124
  }
153
-
154
125
  if (ret) {
155
126
  this._filter = null;
156
127
  }
157
-
158
128
  return ret;
159
129
  }
160
130
  }, {
@@ -162,33 +132,24 @@ var TightDecoder = /*#__PURE__*/function () {
162
132
  value: function _copyFilter(streamId, x, y, width, height, sock, display, depth) {
163
133
  var uncompressedSize = width * height * 3;
164
134
  var data;
165
-
166
135
  if (uncompressedSize === 0) {
167
136
  return true;
168
137
  }
169
-
170
138
  if (uncompressedSize < 12) {
171
139
  if (sock.rQwait("TIGHT", uncompressedSize)) {
172
140
  return false;
173
141
  }
174
-
175
142
  data = sock.rQshiftBytes(uncompressedSize);
176
143
  } else {
177
144
  data = this._readData(sock);
178
-
179
145
  if (data === null) {
180
146
  return false;
181
147
  }
182
-
183
148
  this._zlibs[streamId].setInput(data);
184
-
185
149
  data = this._zlibs[streamId].inflate(uncompressedSize);
186
-
187
150
  this._zlibs[streamId].setInput(null);
188
151
  }
189
-
190
152
  var rgbx = new Uint8Array(width * height * 4);
191
-
192
153
  for (var i = 0, j = 0; i < width * height * 4; i += 4, j += 3) {
193
154
  rgbx[i] = data[j];
194
155
  rgbx[i + 1] = data[j + 1];
@@ -206,55 +167,43 @@ var TightDecoder = /*#__PURE__*/function () {
206
167
  if (sock.rQwait("TIGHT palette", 1)) {
207
168
  return false;
208
169
  }
209
-
210
170
  var numColors = sock.rQpeek8() + 1;
211
171
  var paletteSize = numColors * 3;
212
-
213
172
  if (sock.rQwait("TIGHT palette", 1 + paletteSize)) {
214
173
  return false;
215
174
  }
216
-
217
175
  this._numColors = numColors;
218
176
  sock.rQskipBytes(1);
219
177
  sock.rQshiftTo(this._palette, paletteSize);
220
178
  }
221
-
222
179
  var bpp = this._numColors <= 2 ? 1 : 8;
223
180
  var rowSize = Math.floor((width * bpp + 7) / 8);
224
181
  var uncompressedSize = rowSize * height;
225
182
  var data;
226
-
227
183
  if (uncompressedSize === 0) {
228
184
  return true;
229
185
  }
230
-
231
186
  if (uncompressedSize < 12) {
232
187
  if (sock.rQwait("TIGHT", uncompressedSize)) {
233
188
  return false;
234
189
  }
235
-
236
190
  data = sock.rQshiftBytes(uncompressedSize);
237
191
  } else {
238
192
  data = this._readData(sock);
239
-
240
193
  if (data === null) {
241
194
  return false;
242
195
  }
243
-
244
196
  this._zlibs[streamId].setInput(data);
245
-
246
197
  data = this._zlibs[streamId].inflate(uncompressedSize);
247
-
248
198
  this._zlibs[streamId].setInput(null);
249
- } // Convert indexed (palette based) image data to RGB
250
-
199
+ }
251
200
 
201
+ // Convert indexed (palette based) image data to RGB
252
202
  if (this._numColors == 2) {
253
203
  this._monoRect(x, y, width, height, data, this._palette, display);
254
204
  } else {
255
205
  this._paletteRect(x, y, width, height, data, this._palette, display);
256
206
  }
257
-
258
207
  this._numColors = 0;
259
208
  return true;
260
209
  }
@@ -264,15 +213,12 @@ var TightDecoder = /*#__PURE__*/function () {
264
213
  // Convert indexed (palette based) image data to RGB
265
214
  // TODO: reduce number of calculations inside loop
266
215
  var dest = this._getScratchBuffer(width * height * 4);
267
-
268
216
  var w = Math.floor((width + 7) / 8);
269
217
  var w1 = Math.floor(width / 8);
270
-
271
218
  for (var _y = 0; _y < height; _y++) {
272
219
  var dp = void 0,
273
- sp = void 0,
274
- _x = void 0;
275
-
220
+ sp = void 0,
221
+ _x = void 0;
276
222
  for (_x = 0; _x < w1; _x++) {
277
223
  for (var b = 7; b >= 0; b--) {
278
224
  dp = (_y * width + _x * 8 + 7 - b) * 4;
@@ -283,7 +229,6 @@ var TightDecoder = /*#__PURE__*/function () {
283
229
  dest[dp + 3] = 255;
284
230
  }
285
231
  }
286
-
287
232
  for (var _b = 7; _b >= 8 - width % 8; _b--) {
288
233
  dp = (_y * width + _x * 8 + 7 - _b) * 4;
289
234
  sp = (data[_y * w + _x] >> _b & 1) * 3;
@@ -293,7 +238,6 @@ var TightDecoder = /*#__PURE__*/function () {
293
238
  dest[dp + 3] = 255;
294
239
  }
295
240
  }
296
-
297
241
  display.blitImage(x, y, width, height, dest, 0, false);
298
242
  }
299
243
  }, {
@@ -301,9 +245,7 @@ var TightDecoder = /*#__PURE__*/function () {
301
245
  value: function _paletteRect(x, y, width, height, data, palette, display) {
302
246
  // Convert indexed (palette based) image data to RGB
303
247
  var dest = this._getScratchBuffer(width * height * 4);
304
-
305
248
  var total = width * height * 4;
306
-
307
249
  for (var i = 0, j = 0; i < total; i += 4, j++) {
308
250
  var sp = data[j] * 3;
309
251
  dest[i] = palette[sp];
@@ -311,7 +253,6 @@ var TightDecoder = /*#__PURE__*/function () {
311
253
  dest[i + 2] = palette[sp + 2];
312
254
  dest[i + 3] = 255;
313
255
  }
314
-
315
256
  display.blitImage(x, y, width, height, dest, 0, false);
316
257
  }
317
258
  }, {
@@ -326,27 +267,21 @@ var TightDecoder = /*#__PURE__*/function () {
326
267
  if (sock.rQwait("TIGHT", 3)) {
327
268
  return null;
328
269
  }
329
-
330
270
  var _byte;
331
-
332
271
  _byte = sock.rQshift8();
333
272
  this._len = _byte & 0x7f;
334
-
335
273
  if (_byte & 0x80) {
336
274
  _byte = sock.rQshift8();
337
275
  this._len |= (_byte & 0x7f) << 7;
338
-
339
276
  if (_byte & 0x80) {
340
277
  _byte = sock.rQshift8();
341
278
  this._len |= _byte << 14;
342
279
  }
343
280
  }
344
281
  }
345
-
346
282
  if (sock.rQwait("TIGHT", this._len)) {
347
283
  return null;
348
284
  }
349
-
350
285
  var data = sock.rQshiftBytes(this._len);
351
286
  this._len = 0;
352
287
  return data;
@@ -357,12 +292,9 @@ var TightDecoder = /*#__PURE__*/function () {
357
292
  if (!this._scratchBuffer || this._scratchBuffer.length < size) {
358
293
  this._scratchBuffer = new Uint8Array(size);
359
294
  }
360
-
361
295
  return this._scratchBuffer;
362
296
  }
363
297
  }]);
364
-
365
298
  return TightDecoder;
366
299
  }();
367
-
368
300
  exports["default"] = TightDecoder;