@novnc/novnc 1.3.0-g1691617 → 1.3.0-gbfb6ac2

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.
@@ -0,0 +1,185 @@
1
+ /*
2
+ * noVNC: HTML5 VNC client
3
+ * Copyright (C) 2021 The noVNC Authors
4
+ * Licensed under MPL 2.0 (see LICENSE.txt)
5
+ *
6
+ * See README.md for usage and integration instructions.
7
+ *
8
+ */
9
+
10
+ import Inflate from "../inflator.js";
11
+
12
+ const ZRLE_TILE_WIDTH = 64;
13
+ const ZRLE_TILE_HEIGHT = 64;
14
+
15
+ export default class ZRLEDecoder {
16
+ constructor() {
17
+ this._length = 0;
18
+ this._inflator = new Inflate();
19
+
20
+ this._pixelBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
21
+ this._tileBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
22
+ }
23
+
24
+ decodeRect(x, y, width, height, sock, display, depth) {
25
+ if (this._length === 0) {
26
+ if (sock.rQwait("ZLib data length", 4)) {
27
+ return false;
28
+ }
29
+ this._length = sock.rQshift32();
30
+ }
31
+ if (sock.rQwait("Zlib data", this._length)) {
32
+ return false;
33
+ }
34
+
35
+ const data = sock.rQshiftBytes(this._length);
36
+
37
+ this._inflator.setInput(data);
38
+
39
+ for (let ty = y; ty < y + height; ty += ZRLE_TILE_HEIGHT) {
40
+ let th = Math.min(ZRLE_TILE_HEIGHT, y + height - ty);
41
+
42
+ for (let tx = x; tx < x + width; tx += ZRLE_TILE_WIDTH) {
43
+ let tw = Math.min(ZRLE_TILE_WIDTH, x + width - tx);
44
+
45
+ const tileSize = tw * th;
46
+ const subencoding = this._inflator.inflate(1)[0];
47
+ if (subencoding === 0) {
48
+ // raw data
49
+ const data = this._readPixels(tileSize);
50
+ display.blitImage(tx, ty, tw, th, data, 0, false);
51
+ } else if (subencoding === 1) {
52
+ // solid
53
+ const background = this._readPixels(1);
54
+ display.fillRect(tx, ty, tw, th, [background[0], background[1], background[2]]);
55
+ } else if (subencoding >= 2 && subencoding <= 16) {
56
+ const data = this._decodePaletteTile(subencoding, tileSize, tw, th);
57
+ display.blitImage(tx, ty, tw, th, data, 0, false);
58
+ } else if (subencoding === 128) {
59
+ const data = this._decodeRLETile(tileSize);
60
+ display.blitImage(tx, ty, tw, th, data, 0, false);
61
+ } else if (subencoding >= 130 && subencoding <= 255) {
62
+ const data = this._decodeRLEPaletteTile(subencoding - 128, tileSize);
63
+ display.blitImage(tx, ty, tw, th, data, 0, false);
64
+ } else {
65
+ throw new Error('Unknown subencoding: ' + subencoding);
66
+ }
67
+ }
68
+ }
69
+ this._length = 0;
70
+ return true;
71
+ }
72
+
73
+ _getBitsPerPixelInPalette(paletteSize) {
74
+ if (paletteSize <= 2) {
75
+ return 1;
76
+ } else if (paletteSize <= 4) {
77
+ return 2;
78
+ } else if (paletteSize <= 16) {
79
+ return 4;
80
+ }
81
+ }
82
+
83
+ _readPixels(pixels) {
84
+ let data = this._pixelBuffer;
85
+ const buffer = this._inflator.inflate(3*pixels);
86
+ for (let i = 0, j = 0; i < pixels*4; i += 4, j += 3) {
87
+ data[i] = buffer[j];
88
+ data[i + 1] = buffer[j + 1];
89
+ data[i + 2] = buffer[j + 2];
90
+ data[i + 3] = 255; // Add the Alpha
91
+ }
92
+ return data;
93
+ }
94
+
95
+ _decodePaletteTile(paletteSize, tileSize, tilew, tileh) {
96
+ const data = this._tileBuffer;
97
+ const palette = this._readPixels(paletteSize);
98
+ const bitsPerPixel = this._getBitsPerPixelInPalette(paletteSize);
99
+ const mask = (1 << bitsPerPixel) - 1;
100
+
101
+ let offset = 0;
102
+ let encoded = this._inflator.inflate(1)[0];
103
+
104
+ for (let y=0; y<tileh; y++) {
105
+ let shift = 8-bitsPerPixel;
106
+ for (let x=0; x<tilew; x++) {
107
+ if (shift<0) {
108
+ shift=8-bitsPerPixel;
109
+ encoded = this._inflator.inflate(1)[0];
110
+ }
111
+ let indexInPalette = (encoded>>shift) & mask;
112
+
113
+ data[offset] = palette[indexInPalette * 4];
114
+ data[offset + 1] = palette[indexInPalette * 4 + 1];
115
+ data[offset + 2] = palette[indexInPalette * 4 + 2];
116
+ data[offset + 3] = palette[indexInPalette * 4 + 3];
117
+ offset += 4;
118
+ shift-=bitsPerPixel;
119
+ }
120
+ if (shift<8-bitsPerPixel && y<tileh-1) {
121
+ encoded = this._inflator.inflate(1)[0];
122
+ }
123
+ }
124
+ return data;
125
+ }
126
+
127
+ _decodeRLETile(tileSize) {
128
+ const data = this._tileBuffer;
129
+ let i = 0;
130
+ while (i < tileSize) {
131
+ const pixel = this._readPixels(1);
132
+ const length = this._readRLELength();
133
+ for (let j = 0; j < length; j++) {
134
+ data[i * 4] = pixel[0];
135
+ data[i * 4 + 1] = pixel[1];
136
+ data[i * 4 + 2] = pixel[2];
137
+ data[i * 4 + 3] = pixel[3];
138
+ i++;
139
+ }
140
+ }
141
+ return data;
142
+ }
143
+
144
+ _decodeRLEPaletteTile(paletteSize, tileSize) {
145
+ const data = this._tileBuffer;
146
+
147
+ // palette
148
+ const palette = this._readPixels(paletteSize);
149
+
150
+ let offset = 0;
151
+ while (offset < tileSize) {
152
+ let indexInPalette = this._inflator.inflate(1)[0];
153
+ let length = 1;
154
+ if (indexInPalette >= 128) {
155
+ indexInPalette -= 128;
156
+ length = this._readRLELength();
157
+ }
158
+ if (indexInPalette > paletteSize) {
159
+ throw new Error('Too big index in palette: ' + indexInPalette + ', palette size: ' + paletteSize);
160
+ }
161
+ if (offset + length > tileSize) {
162
+ throw new Error('Too big rle length in palette mode: ' + length + ', allowed length is: ' + (tileSize - offset));
163
+ }
164
+
165
+ for (let j = 0; j < length; j++) {
166
+ data[offset * 4] = palette[indexInPalette * 4];
167
+ data[offset * 4 + 1] = palette[indexInPalette * 4 + 1];
168
+ data[offset * 4 + 2] = palette[indexInPalette * 4 + 2];
169
+ data[offset * 4 + 3] = palette[indexInPalette * 4 + 3];
170
+ offset++;
171
+ }
172
+ }
173
+ return data;
174
+ }
175
+
176
+ _readRLELength() {
177
+ let length = 0;
178
+ let current = 0;
179
+ do {
180
+ current = this._inflator.inflate(1)[0];
181
+ length += current;
182
+ } while (current === 255);
183
+ return length + 1;
184
+ }
185
+ }
package/core/rfb.js CHANGED
@@ -32,6 +32,7 @@ import RREDecoder from "./decoders/rre.js";
32
32
  import HextileDecoder from "./decoders/hextile.js";
33
33
  import TightDecoder from "./decoders/tight.js";
34
34
  import TightPNGDecoder from "./decoders/tightpng.js";
35
+ import ZRLEDecoder from "./decoders/zrle.js";
35
36
 
36
37
  // How many seconds to wait for a disconnect to finish
37
38
  const DISCONNECT_TIMEOUT = 3;
@@ -218,6 +219,7 @@ export default class RFB extends EventTargetMixin {
218
219
  this._decoders[encodings.encodingHextile] = new HextileDecoder();
219
220
  this._decoders[encodings.encodingTight] = new TightDecoder();
220
221
  this._decoders[encodings.encodingTightPNG] = new TightPNGDecoder();
222
+ this._decoders[encodings.encodingZRLE] = new ZRLEDecoder();
221
223
 
222
224
  // NB: nothing that needs explicit teardown should be done
223
225
  // before this point, since this can throw an exception
@@ -1772,6 +1774,7 @@ export default class RFB extends EventTargetMixin {
1772
1774
  if (this._fbDepth == 24) {
1773
1775
  encs.push(encodings.encodingTight);
1774
1776
  encs.push(encodings.encodingTightPNG);
1777
+ encs.push(encodings.encodingZRLE);
1775
1778
  encs.push(encodings.encodingHextile);
1776
1779
  encs.push(encodings.encodingRRE);
1777
1780
  }
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _inflator = _interopRequireDefault(require("../inflator.js"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+
12
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
+
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); } }
15
+
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
17
+
18
+ var ZRLE_TILE_WIDTH = 64;
19
+ var ZRLE_TILE_HEIGHT = 64;
20
+
21
+ var ZRLEDecoder = /*#__PURE__*/function () {
22
+ function ZRLEDecoder() {
23
+ _classCallCheck(this, ZRLEDecoder);
24
+
25
+ this._length = 0;
26
+ this._inflator = new _inflator["default"]();
27
+ this._pixelBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
28
+ this._tileBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
29
+ }
30
+
31
+ _createClass(ZRLEDecoder, [{
32
+ key: "decodeRect",
33
+ value: function decodeRect(x, y, width, height, sock, display, depth) {
34
+ if (this._length === 0) {
35
+ if (sock.rQwait("ZLib data length", 4)) {
36
+ return false;
37
+ }
38
+
39
+ this._length = sock.rQshift32();
40
+ }
41
+
42
+ if (sock.rQwait("Zlib data", this._length)) {
43
+ return false;
44
+ }
45
+
46
+ var data = sock.rQshiftBytes(this._length);
47
+
48
+ this._inflator.setInput(data);
49
+
50
+ for (var ty = y; ty < y + height; ty += ZRLE_TILE_HEIGHT) {
51
+ var th = Math.min(ZRLE_TILE_HEIGHT, y + height - ty);
52
+
53
+ for (var tx = x; tx < x + width; tx += ZRLE_TILE_WIDTH) {
54
+ var tw = Math.min(ZRLE_TILE_WIDTH, x + width - tx);
55
+ var tileSize = tw * th;
56
+
57
+ var subencoding = this._inflator.inflate(1)[0];
58
+
59
+ if (subencoding === 0) {
60
+ // raw data
61
+ var _data = this._readPixels(tileSize);
62
+
63
+ display.blitImage(tx, ty, tw, th, _data, 0, false);
64
+ } else if (subencoding === 1) {
65
+ // solid
66
+ var background = this._readPixels(1);
67
+
68
+ display.fillRect(tx, ty, tw, th, [background[0], background[1], background[2]]);
69
+ } else if (subencoding >= 2 && subencoding <= 16) {
70
+ var _data2 = this._decodePaletteTile(subencoding, tileSize, tw, th);
71
+
72
+ display.blitImage(tx, ty, tw, th, _data2, 0, false);
73
+ } else if (subencoding === 128) {
74
+ var _data3 = this._decodeRLETile(tileSize);
75
+
76
+ display.blitImage(tx, ty, tw, th, _data3, 0, false);
77
+ } else if (subencoding >= 130 && subencoding <= 255) {
78
+ var _data4 = this._decodeRLEPaletteTile(subencoding - 128, tileSize);
79
+
80
+ display.blitImage(tx, ty, tw, th, _data4, 0, false);
81
+ } else {
82
+ throw new Error('Unknown subencoding: ' + subencoding);
83
+ }
84
+ }
85
+ }
86
+
87
+ this._length = 0;
88
+ return true;
89
+ }
90
+ }, {
91
+ key: "_getBitsPerPixelInPalette",
92
+ value: function _getBitsPerPixelInPalette(paletteSize) {
93
+ if (paletteSize <= 2) {
94
+ return 1;
95
+ } else if (paletteSize <= 4) {
96
+ return 2;
97
+ } else if (paletteSize <= 16) {
98
+ return 4;
99
+ }
100
+ }
101
+ }, {
102
+ key: "_readPixels",
103
+ value: function _readPixels(pixels) {
104
+ var data = this._pixelBuffer;
105
+
106
+ var buffer = this._inflator.inflate(3 * pixels);
107
+
108
+ for (var i = 0, j = 0; i < pixels * 4; i += 4, j += 3) {
109
+ data[i] = buffer[j];
110
+ data[i + 1] = buffer[j + 1];
111
+ data[i + 2] = buffer[j + 2];
112
+ data[i + 3] = 255; // Add the Alpha
113
+ }
114
+
115
+ return data;
116
+ }
117
+ }, {
118
+ key: "_decodePaletteTile",
119
+ value: function _decodePaletteTile(paletteSize, tileSize, tilew, tileh) {
120
+ var data = this._tileBuffer;
121
+
122
+ var palette = this._readPixels(paletteSize);
123
+
124
+ var bitsPerPixel = this._getBitsPerPixelInPalette(paletteSize);
125
+
126
+ var mask = (1 << bitsPerPixel) - 1;
127
+ var offset = 0;
128
+
129
+ var encoded = this._inflator.inflate(1)[0];
130
+
131
+ for (var y = 0; y < tileh; y++) {
132
+ var shift = 8 - bitsPerPixel;
133
+
134
+ for (var x = 0; x < tilew; x++) {
135
+ if (shift < 0) {
136
+ shift = 8 - bitsPerPixel;
137
+ encoded = this._inflator.inflate(1)[0];
138
+ }
139
+
140
+ var indexInPalette = encoded >> shift & mask;
141
+ data[offset] = palette[indexInPalette * 4];
142
+ data[offset + 1] = palette[indexInPalette * 4 + 1];
143
+ data[offset + 2] = palette[indexInPalette * 4 + 2];
144
+ data[offset + 3] = palette[indexInPalette * 4 + 3];
145
+ offset += 4;
146
+ shift -= bitsPerPixel;
147
+ }
148
+
149
+ if (shift < 8 - bitsPerPixel && y < tileh - 1) {
150
+ encoded = this._inflator.inflate(1)[0];
151
+ }
152
+ }
153
+
154
+ return data;
155
+ }
156
+ }, {
157
+ key: "_decodeRLETile",
158
+ value: function _decodeRLETile(tileSize) {
159
+ var data = this._tileBuffer;
160
+ var i = 0;
161
+
162
+ while (i < tileSize) {
163
+ var pixel = this._readPixels(1);
164
+
165
+ var length = this._readRLELength();
166
+
167
+ for (var j = 0; j < length; j++) {
168
+ data[i * 4] = pixel[0];
169
+ data[i * 4 + 1] = pixel[1];
170
+ data[i * 4 + 2] = pixel[2];
171
+ data[i * 4 + 3] = pixel[3];
172
+ i++;
173
+ }
174
+ }
175
+
176
+ return data;
177
+ }
178
+ }, {
179
+ key: "_decodeRLEPaletteTile",
180
+ value: function _decodeRLEPaletteTile(paletteSize, tileSize) {
181
+ var data = this._tileBuffer; // palette
182
+
183
+ var palette = this._readPixels(paletteSize);
184
+
185
+ var offset = 0;
186
+
187
+ while (offset < tileSize) {
188
+ var indexInPalette = this._inflator.inflate(1)[0];
189
+
190
+ var length = 1;
191
+
192
+ if (indexInPalette >= 128) {
193
+ indexInPalette -= 128;
194
+ length = this._readRLELength();
195
+ }
196
+
197
+ if (indexInPalette > paletteSize) {
198
+ throw new Error('Too big index in palette: ' + indexInPalette + ', palette size: ' + paletteSize);
199
+ }
200
+
201
+ if (offset + length > tileSize) {
202
+ throw new Error('Too big rle length in palette mode: ' + length + ', allowed length is: ' + (tileSize - offset));
203
+ }
204
+
205
+ for (var j = 0; j < length; j++) {
206
+ data[offset * 4] = palette[indexInPalette * 4];
207
+ data[offset * 4 + 1] = palette[indexInPalette * 4 + 1];
208
+ data[offset * 4 + 2] = palette[indexInPalette * 4 + 2];
209
+ data[offset * 4 + 3] = palette[indexInPalette * 4 + 3];
210
+ offset++;
211
+ }
212
+ }
213
+
214
+ return data;
215
+ }
216
+ }, {
217
+ key: "_readRLELength",
218
+ value: function _readRLELength() {
219
+ var length = 0;
220
+ var current = 0;
221
+
222
+ do {
223
+ current = this._inflator.inflate(1)[0];
224
+ length += current;
225
+ } while (current === 255);
226
+
227
+ return length + 1;
228
+ }
229
+ }]);
230
+
231
+ return ZRLEDecoder;
232
+ }();
233
+
234
+ exports["default"] = ZRLEDecoder;
package/lib/rfb.js CHANGED
@@ -55,6 +55,8 @@ var _tight = _interopRequireDefault(require("./decoders/tight.js"));
55
55
 
56
56
  var _tightpng = _interopRequireDefault(require("./decoders/tightpng.js"));
57
57
 
58
+ var _zrle = _interopRequireDefault(require("./decoders/zrle.js"));
59
+
58
60
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
59
61
 
60
62
  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); }
@@ -262,7 +264,8 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
262
264
  _this._decoders[_encodings.encodings.encodingRRE] = new _rre["default"]();
263
265
  _this._decoders[_encodings.encodings.encodingHextile] = new _hextile["default"]();
264
266
  _this._decoders[_encodings.encodings.encodingTight] = new _tight["default"]();
265
- _this._decoders[_encodings.encodings.encodingTightPNG] = new _tightpng["default"](); // NB: nothing that needs explicit teardown should be done
267
+ _this._decoders[_encodings.encodings.encodingTightPNG] = new _tightpng["default"]();
268
+ _this._decoders[_encodings.encodings.encodingZRLE] = new _zrle["default"](); // NB: nothing that needs explicit teardown should be done
266
269
  // before this point, since this can throw an exception
267
270
 
268
271
  try {
@@ -2152,6 +2155,7 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2152
2155
  if (this._fbDepth == 24) {
2153
2156
  encs.push(_encodings.encodings.encodingTight);
2154
2157
  encs.push(_encodings.encodings.encodingTightPNG);
2158
+ encs.push(_encodings.encodings.encodingZRLE);
2155
2159
  encs.push(_encodings.encodings.encodingHextile);
2156
2160
  encs.push(_encodings.encodings.encodingRRE);
2157
2161
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novnc/novnc",
3
- "version": "1.3.0-g1691617",
3
+ "version": "1.3.0-gbfb6ac2",
4
4
  "description": "An HTML5 VNC client",
5
5
  "browser": "lib/rfb",
6
6
  "directories": {