@novnc/novnc 1.2.0 → 1.3.0-g05baf14
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.
- package/LICENSE.txt +0 -6
- package/README.md +16 -6
- package/core/decoders/copyrect.js +5 -0
- package/core/decoders/hextile.js +57 -3
- package/core/decoders/jpeg.js +141 -0
- package/core/decoders/raw.js +12 -2
- package/core/decoders/tight.js +24 -8
- package/core/decoders/zrle.js +185 -0
- package/core/display.js +21 -151
- package/core/encodings.js +4 -0
- package/core/input/domkeytable.js +25 -21
- package/core/input/keyboard.js +22 -127
- package/core/input/util.js +18 -35
- package/core/input/vkeys.js +0 -1
- package/core/input/xtscancodes.js +5 -3
- package/core/ra2.js +567 -0
- package/core/rfb.js +487 -171
- package/core/util/browser.js +0 -17
- package/core/util/cursor.js +5 -11
- package/core/util/events.js +0 -4
- package/core/util/md5.js +79 -0
- package/core/websock.js +76 -17
- package/docs/API.md +107 -6
- package/docs/LIBRARY.md +3 -7
- package/lib/base64.js +24 -38
- package/lib/decoders/copyrect.js +10 -12
- package/lib/decoders/hextile.js +71 -45
- package/lib/decoders/jpeg.js +149 -0
- package/lib/decoders/raw.js +18 -22
- package/lib/decoders/rre.js +7 -18
- package/lib/decoders/tight.js +46 -94
- package/lib/decoders/tightpng.js +14 -34
- package/lib/decoders/zrle.js +188 -0
- package/lib/deflator.js +13 -27
- package/lib/des.js +26 -39
- package/lib/display.js +103 -316
- package/lib/encodings.js +7 -8
- package/lib/inflator.js +10 -23
- package/lib/input/domkeytable.js +240 -208
- package/lib/input/fixedkeys.js +10 -5
- package/lib/input/gesturehandler.js +88 -155
- package/lib/input/keyboard.js +90 -239
- package/lib/input/keysym.js +16 -272
- package/lib/input/keysymdef.js +7 -9
- package/lib/input/util.js +69 -156
- package/lib/input/vkeys.js +2 -7
- package/lib/input/xtscancodes.js +10 -171
- package/lib/ra2.js +1035 -0
- package/lib/rfb.js +950 -1150
- package/lib/util/browser.js +25 -52
- package/lib/util/cursor.js +33 -82
- package/lib/util/element.js +3 -5
- package/lib/util/events.js +26 -35
- package/lib/util/eventtarget.js +8 -17
- package/lib/util/int.js +2 -3
- package/lib/util/logging.js +3 -21
- package/lib/util/md5.js +83 -0
- package/lib/util/strings.js +3 -5
- package/lib/vendor/pako/lib/utils/common.js +10 -19
- package/lib/vendor/pako/lib/zlib/adler32.js +4 -8
- package/lib/vendor/pako/lib/zlib/constants.js +4 -7
- package/lib/vendor/pako/lib/zlib/crc32.js +6 -13
- package/lib/vendor/pako/lib/zlib/deflate.js +304 -708
- package/lib/vendor/pako/lib/zlib/gzheader.js +2 -14
- package/lib/vendor/pako/lib/zlib/inffast.js +61 -177
- package/lib/vendor/pako/lib/zlib/inflate.js +421 -909
- package/lib/vendor/pako/lib/zlib/inftrees.js +66 -172
- package/lib/vendor/pako/lib/zlib/messages.js +3 -13
- package/lib/vendor/pako/lib/zlib/trees.js +250 -592
- package/lib/vendor/pako/lib/zlib/zstream.js +3 -19
- package/lib/websock.js +122 -112
- package/package.json +32 -40
- package/core/util/polyfill.js +0 -61
- package/lib/util/polyfill.js +0 -72
- package/lib/vendor/promise.js +0 -255
package/lib/decoders/tight.js
CHANGED
|
@@ -1,45 +1,33 @@
|
|
|
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
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
|
-
exports
|
|
9
|
-
|
|
6
|
+
exports["default"] = void 0;
|
|
10
7
|
var Log = _interopRequireWildcard(require("../util/logging.js"));
|
|
11
|
-
|
|
12
8
|
var _inflator = _interopRequireDefault(require("../inflator.js"));
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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
|
-
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
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); }
|
|
20
13
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
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; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
17
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
26
18
|
var TightDecoder = /*#__PURE__*/function () {
|
|
27
19
|
function TightDecoder() {
|
|
28
20
|
_classCallCheck(this, TightDecoder);
|
|
29
|
-
|
|
30
21
|
this._ctl = null;
|
|
31
22
|
this._filter = null;
|
|
32
23
|
this._numColors = 0;
|
|
33
24
|
this._palette = new Uint8Array(1024); // 256 * 4 (max palette size * max bytes-per-pixel)
|
|
34
|
-
|
|
35
25
|
this._len = 0;
|
|
36
26
|
this._zlibs = [];
|
|
37
|
-
|
|
38
27
|
for (var i = 0; i < 4; i++) {
|
|
39
|
-
this._zlibs[i] = new _inflator
|
|
28
|
+
this._zlibs[i] = new _inflator["default"]();
|
|
40
29
|
}
|
|
41
30
|
}
|
|
42
|
-
|
|
43
31
|
_createClass(TightDecoder, [{
|
|
44
32
|
key: "decodeRect",
|
|
45
33
|
value: function decodeRect(x, y, width, height, sock, display, depth) {
|
|
@@ -47,39 +35,34 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
47
35
|
if (sock.rQwait("TIGHT compression-control", 1)) {
|
|
48
36
|
return false;
|
|
49
37
|
}
|
|
38
|
+
this._ctl = sock.rQshift8();
|
|
50
39
|
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
// Reset streams if the server requests it
|
|
53
41
|
for (var i = 0; i < 4; i++) {
|
|
54
42
|
if (this._ctl >> i & 1) {
|
|
55
43
|
this._zlibs[i].reset();
|
|
56
|
-
|
|
57
44
|
Log.Info("Reset zlib stream " + i);
|
|
58
45
|
}
|
|
59
|
-
}
|
|
60
|
-
|
|
46
|
+
}
|
|
61
47
|
|
|
48
|
+
// Figure out filter
|
|
62
49
|
this._ctl = this._ctl >> 4;
|
|
63
50
|
}
|
|
64
|
-
|
|
65
51
|
var ret;
|
|
66
|
-
|
|
67
52
|
if (this._ctl === 0x08) {
|
|
68
53
|
ret = this._fillRect(x, y, width, height, sock, display, depth);
|
|
69
54
|
} else if (this._ctl === 0x09) {
|
|
70
55
|
ret = this._jpegRect(x, y, width, height, sock, display, depth);
|
|
71
56
|
} else if (this._ctl === 0x0A) {
|
|
72
57
|
ret = this._pngRect(x, y, width, height, sock, display, depth);
|
|
73
|
-
} else if ((this._ctl &
|
|
58
|
+
} else if ((this._ctl & 0x08) == 0) {
|
|
74
59
|
ret = this._basicRect(this._ctl, x, y, width, height, sock, display, depth);
|
|
75
60
|
} else {
|
|
76
61
|
throw new Error("Illegal tight compression received (ctl: " + this._ctl + ")");
|
|
77
62
|
}
|
|
78
|
-
|
|
79
63
|
if (ret) {
|
|
80
64
|
this._ctl = null;
|
|
81
65
|
}
|
|
82
|
-
|
|
83
66
|
return ret;
|
|
84
67
|
}
|
|
85
68
|
}, {
|
|
@@ -88,10 +71,9 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
88
71
|
if (sock.rQwait("TIGHT", 3)) {
|
|
89
72
|
return false;
|
|
90
73
|
}
|
|
91
|
-
|
|
92
74
|
var rQi = sock.rQi;
|
|
93
75
|
var rQ = sock.rQ;
|
|
94
|
-
display.fillRect(x, y, width, height, [rQ[rQi
|
|
76
|
+
display.fillRect(x, y, width, height, [rQ[rQi], rQ[rQi + 1], rQ[rQi + 2]], false);
|
|
95
77
|
sock.rQskipBytes(3);
|
|
96
78
|
return true;
|
|
97
79
|
}
|
|
@@ -99,11 +81,9 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
99
81
|
key: "_jpegRect",
|
|
100
82
|
value: function _jpegRect(x, y, width, height, sock, display, depth) {
|
|
101
83
|
var data = this._readData(sock);
|
|
102
|
-
|
|
103
84
|
if (data === null) {
|
|
104
85
|
return false;
|
|
105
86
|
}
|
|
106
|
-
|
|
107
87
|
display.imageRect(x, y, width, height, "image/jpeg", data);
|
|
108
88
|
return true;
|
|
109
89
|
}
|
|
@@ -120,41 +100,33 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
120
100
|
if (sock.rQwait("TIGHT", 1)) {
|
|
121
101
|
return false;
|
|
122
102
|
}
|
|
123
|
-
|
|
124
103
|
this._filter = sock.rQshift8();
|
|
125
104
|
} else {
|
|
126
105
|
// Implicit CopyFilter
|
|
127
106
|
this._filter = 0;
|
|
128
107
|
}
|
|
129
108
|
}
|
|
130
|
-
|
|
131
109
|
var streamId = ctl & 0x3;
|
|
132
110
|
var ret;
|
|
133
|
-
|
|
134
111
|
switch (this._filter) {
|
|
135
112
|
case 0:
|
|
136
113
|
// CopyFilter
|
|
137
114
|
ret = this._copyFilter(streamId, x, y, width, height, sock, display, depth);
|
|
138
115
|
break;
|
|
139
|
-
|
|
140
116
|
case 1:
|
|
141
117
|
// PaletteFilter
|
|
142
118
|
ret = this._paletteFilter(streamId, x, y, width, height, sock, display, depth);
|
|
143
119
|
break;
|
|
144
|
-
|
|
145
120
|
case 2:
|
|
146
121
|
// GradientFilter
|
|
147
122
|
ret = this._gradientFilter(streamId, x, y, width, height, sock, display, depth);
|
|
148
123
|
break;
|
|
149
|
-
|
|
150
124
|
default:
|
|
151
125
|
throw new Error("Illegal tight filter received (ctl: " + this._filter + ")");
|
|
152
126
|
}
|
|
153
|
-
|
|
154
127
|
if (ret) {
|
|
155
128
|
this._filter = null;
|
|
156
129
|
}
|
|
157
|
-
|
|
158
130
|
return ret;
|
|
159
131
|
}
|
|
160
132
|
}, {
|
|
@@ -162,28 +134,32 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
162
134
|
value: function _copyFilter(streamId, x, y, width, height, sock, display, depth) {
|
|
163
135
|
var uncompressedSize = width * height * 3;
|
|
164
136
|
var data;
|
|
165
|
-
|
|
137
|
+
if (uncompressedSize === 0) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
166
140
|
if (uncompressedSize < 12) {
|
|
167
141
|
if (sock.rQwait("TIGHT", uncompressedSize)) {
|
|
168
142
|
return false;
|
|
169
143
|
}
|
|
170
|
-
|
|
171
144
|
data = sock.rQshiftBytes(uncompressedSize);
|
|
172
145
|
} else {
|
|
173
146
|
data = this._readData(sock);
|
|
174
|
-
|
|
175
147
|
if (data === null) {
|
|
176
148
|
return false;
|
|
177
149
|
}
|
|
178
|
-
|
|
179
150
|
this._zlibs[streamId].setInput(data);
|
|
180
|
-
|
|
181
151
|
data = this._zlibs[streamId].inflate(uncompressedSize);
|
|
182
|
-
|
|
183
152
|
this._zlibs[streamId].setInput(null);
|
|
184
153
|
}
|
|
154
|
+
var rgbx = new Uint8Array(width * height * 4);
|
|
155
|
+
for (var i = 0, j = 0; i < width * height * 4; i += 4, j += 3) {
|
|
156
|
+
rgbx[i] = data[j];
|
|
157
|
+
rgbx[i + 1] = data[j + 1];
|
|
158
|
+
rgbx[i + 2] = data[j + 2];
|
|
159
|
+
rgbx[i + 3] = 255; // Alpha
|
|
160
|
+
}
|
|
185
161
|
|
|
186
|
-
display.
|
|
162
|
+
display.blitImage(x, y, width, height, rgbx, 0, false);
|
|
187
163
|
return true;
|
|
188
164
|
}
|
|
189
165
|
}, {
|
|
@@ -193,51 +169,43 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
193
169
|
if (sock.rQwait("TIGHT palette", 1)) {
|
|
194
170
|
return false;
|
|
195
171
|
}
|
|
196
|
-
|
|
197
172
|
var numColors = sock.rQpeek8() + 1;
|
|
198
173
|
var paletteSize = numColors * 3;
|
|
199
|
-
|
|
200
174
|
if (sock.rQwait("TIGHT palette", 1 + paletteSize)) {
|
|
201
175
|
return false;
|
|
202
176
|
}
|
|
203
|
-
|
|
204
177
|
this._numColors = numColors;
|
|
205
178
|
sock.rQskipBytes(1);
|
|
206
179
|
sock.rQshiftTo(this._palette, paletteSize);
|
|
207
180
|
}
|
|
208
|
-
|
|
209
181
|
var bpp = this._numColors <= 2 ? 1 : 8;
|
|
210
182
|
var rowSize = Math.floor((width * bpp + 7) / 8);
|
|
211
183
|
var uncompressedSize = rowSize * height;
|
|
212
184
|
var data;
|
|
213
|
-
|
|
185
|
+
if (uncompressedSize === 0) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
214
188
|
if (uncompressedSize < 12) {
|
|
215
189
|
if (sock.rQwait("TIGHT", uncompressedSize)) {
|
|
216
190
|
return false;
|
|
217
191
|
}
|
|
218
|
-
|
|
219
192
|
data = sock.rQshiftBytes(uncompressedSize);
|
|
220
193
|
} else {
|
|
221
194
|
data = this._readData(sock);
|
|
222
|
-
|
|
223
195
|
if (data === null) {
|
|
224
196
|
return false;
|
|
225
197
|
}
|
|
226
|
-
|
|
227
198
|
this._zlibs[streamId].setInput(data);
|
|
228
|
-
|
|
229
199
|
data = this._zlibs[streamId].inflate(uncompressedSize);
|
|
230
|
-
|
|
231
200
|
this._zlibs[streamId].setInput(null);
|
|
232
|
-
}
|
|
233
|
-
|
|
201
|
+
}
|
|
234
202
|
|
|
203
|
+
// Convert indexed (palette based) image data to RGB
|
|
235
204
|
if (this._numColors == 2) {
|
|
236
205
|
this._monoRect(x, y, width, height, data, this._palette, display);
|
|
237
206
|
} else {
|
|
238
207
|
this._paletteRect(x, y, width, height, data, this._palette, display);
|
|
239
208
|
}
|
|
240
|
-
|
|
241
209
|
this._numColors = 0;
|
|
242
210
|
return true;
|
|
243
211
|
}
|
|
@@ -247,15 +215,12 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
247
215
|
// Convert indexed (palette based) image data to RGB
|
|
248
216
|
// TODO: reduce number of calculations inside loop
|
|
249
217
|
var dest = this._getScratchBuffer(width * height * 4);
|
|
250
|
-
|
|
251
218
|
var w = Math.floor((width + 7) / 8);
|
|
252
219
|
var w1 = Math.floor(width / 8);
|
|
253
|
-
|
|
254
220
|
for (var _y = 0; _y < height; _y++) {
|
|
255
221
|
var dp = void 0,
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
222
|
+
sp = void 0,
|
|
223
|
+
_x = void 0;
|
|
259
224
|
for (_x = 0; _x < w1; _x++) {
|
|
260
225
|
for (var b = 7; b >= 0; b--) {
|
|
261
226
|
dp = (_y * width + _x * 8 + 7 - b) * 4;
|
|
@@ -266,7 +231,6 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
266
231
|
dest[dp + 3] = 255;
|
|
267
232
|
}
|
|
268
233
|
}
|
|
269
|
-
|
|
270
234
|
for (var _b = 7; _b >= 8 - width % 8; _b--) {
|
|
271
235
|
dp = (_y * width + _x * 8 + 7 - _b) * 4;
|
|
272
236
|
sp = (data[_y * w + _x] >> _b & 1) * 3;
|
|
@@ -276,17 +240,14 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
276
240
|
dest[dp + 3] = 255;
|
|
277
241
|
}
|
|
278
242
|
}
|
|
279
|
-
|
|
280
|
-
display.blitRgbxImage(x, y, width, height, dest, 0, false);
|
|
243
|
+
display.blitImage(x, y, width, height, dest, 0, false);
|
|
281
244
|
}
|
|
282
245
|
}, {
|
|
283
246
|
key: "_paletteRect",
|
|
284
247
|
value: function _paletteRect(x, y, width, height, data, palette, display) {
|
|
285
248
|
// Convert indexed (palette based) image data to RGB
|
|
286
249
|
var dest = this._getScratchBuffer(width * height * 4);
|
|
287
|
-
|
|
288
250
|
var total = width * height * 4;
|
|
289
|
-
|
|
290
251
|
for (var i = 0, j = 0; i < total; i += 4, j++) {
|
|
291
252
|
var sp = data[j] * 3;
|
|
292
253
|
dest[i] = palette[sp];
|
|
@@ -294,8 +255,7 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
294
255
|
dest[i + 2] = palette[sp + 2];
|
|
295
256
|
dest[i + 3] = 255;
|
|
296
257
|
}
|
|
297
|
-
|
|
298
|
-
display.blitRgbxImage(x, y, width, height, dest, 0, false);
|
|
258
|
+
display.blitImage(x, y, width, height, dest, 0, false);
|
|
299
259
|
}
|
|
300
260
|
}, {
|
|
301
261
|
key: "_gradientFilter",
|
|
@@ -309,26 +269,21 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
309
269
|
if (sock.rQwait("TIGHT", 3)) {
|
|
310
270
|
return null;
|
|
311
271
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if (byte & 0x80) {
|
|
322
|
-
byte = sock.rQshift8();
|
|
323
|
-
this._len |= byte << 14;
|
|
272
|
+
var _byte;
|
|
273
|
+
_byte = sock.rQshift8();
|
|
274
|
+
this._len = _byte & 0x7f;
|
|
275
|
+
if (_byte & 0x80) {
|
|
276
|
+
_byte = sock.rQshift8();
|
|
277
|
+
this._len |= (_byte & 0x7f) << 7;
|
|
278
|
+
if (_byte & 0x80) {
|
|
279
|
+
_byte = sock.rQshift8();
|
|
280
|
+
this._len |= _byte << 14;
|
|
324
281
|
}
|
|
325
282
|
}
|
|
326
283
|
}
|
|
327
|
-
|
|
328
284
|
if (sock.rQwait("TIGHT", this._len)) {
|
|
329
285
|
return null;
|
|
330
286
|
}
|
|
331
|
-
|
|
332
287
|
var data = sock.rQshiftBytes(this._len);
|
|
333
288
|
this._len = 0;
|
|
334
289
|
return data;
|
|
@@ -339,12 +294,9 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
339
294
|
if (!this._scratchBuffer || this._scratchBuffer.length < size) {
|
|
340
295
|
this._scratchBuffer = new Uint8Array(size);
|
|
341
296
|
}
|
|
342
|
-
|
|
343
297
|
return this._scratchBuffer;
|
|
344
298
|
}
|
|
345
299
|
}]);
|
|
346
|
-
|
|
347
300
|
return TightDecoder;
|
|
348
301
|
}();
|
|
349
|
-
|
|
350
|
-
exports.default = TightDecoder;
|
|
302
|
+
exports["default"] = TightDecoder;
|
package/lib/decoders/tightpng.js
CHANGED
|
@@ -1,56 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
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); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
7
|
+
exports["default"] = void 0;
|
|
8
8
|
var _tight = _interopRequireDefault(require("./tight.js"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
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); }
|
|
13
|
-
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
23
|
-
|
|
11
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
16
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
24
17
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
25
|
-
|
|
26
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
27
|
-
|
|
18
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
28
19
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
33
|
-
|
|
20
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
21
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
34
22
|
var TightPNGDecoder = /*#__PURE__*/function (_TightDecoder) {
|
|
35
23
|
_inherits(TightPNGDecoder, _TightDecoder);
|
|
36
|
-
|
|
37
24
|
var _super = _createSuper(TightPNGDecoder);
|
|
38
|
-
|
|
39
25
|
function TightPNGDecoder() {
|
|
40
26
|
_classCallCheck(this, TightPNGDecoder);
|
|
41
|
-
|
|
42
27
|
return _super.apply(this, arguments);
|
|
43
28
|
}
|
|
44
|
-
|
|
45
29
|
_createClass(TightPNGDecoder, [{
|
|
46
30
|
key: "_pngRect",
|
|
47
31
|
value: function _pngRect(x, y, width, height, sock, display, depth) {
|
|
48
32
|
var data = this._readData(sock);
|
|
49
|
-
|
|
50
33
|
if (data === null) {
|
|
51
34
|
return false;
|
|
52
35
|
}
|
|
53
|
-
|
|
54
36
|
display.imageRect(x, y, width, height, "image/png", data);
|
|
55
37
|
return true;
|
|
56
38
|
}
|
|
@@ -60,8 +42,6 @@ var TightPNGDecoder = /*#__PURE__*/function (_TightDecoder) {
|
|
|
60
42
|
throw new Error("BasicCompression received in TightPNG rect");
|
|
61
43
|
}
|
|
62
44
|
}]);
|
|
63
|
-
|
|
64
45
|
return TightPNGDecoder;
|
|
65
|
-
}(_tight
|
|
66
|
-
|
|
67
|
-
exports.default = TightPNGDecoder;
|
|
46
|
+
}(_tight["default"]);
|
|
47
|
+
exports["default"] = TightPNGDecoder;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _inflator = _interopRequireDefault(require("../inflator.js"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
9
|
+
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); }
|
|
10
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
|
+
var ZRLE_TILE_WIDTH = 64;
|
|
16
|
+
var ZRLE_TILE_HEIGHT = 64;
|
|
17
|
+
var ZRLEDecoder = /*#__PURE__*/function () {
|
|
18
|
+
function ZRLEDecoder() {
|
|
19
|
+
_classCallCheck(this, ZRLEDecoder);
|
|
20
|
+
this._length = 0;
|
|
21
|
+
this._inflator = new _inflator["default"]();
|
|
22
|
+
this._pixelBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
|
|
23
|
+
this._tileBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
|
|
24
|
+
}
|
|
25
|
+
_createClass(ZRLEDecoder, [{
|
|
26
|
+
key: "decodeRect",
|
|
27
|
+
value: function decodeRect(x, y, width, height, sock, display, depth) {
|
|
28
|
+
if (this._length === 0) {
|
|
29
|
+
if (sock.rQwait("ZLib data length", 4)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
this._length = sock.rQshift32();
|
|
33
|
+
}
|
|
34
|
+
if (sock.rQwait("Zlib data", this._length)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
var data = sock.rQshiftBytes(this._length);
|
|
38
|
+
this._inflator.setInput(data);
|
|
39
|
+
for (var ty = y; ty < y + height; ty += ZRLE_TILE_HEIGHT) {
|
|
40
|
+
var th = Math.min(ZRLE_TILE_HEIGHT, y + height - ty);
|
|
41
|
+
for (var tx = x; tx < x + width; tx += ZRLE_TILE_WIDTH) {
|
|
42
|
+
var tw = Math.min(ZRLE_TILE_WIDTH, x + width - tx);
|
|
43
|
+
var tileSize = tw * th;
|
|
44
|
+
var subencoding = this._inflator.inflate(1)[0];
|
|
45
|
+
if (subencoding === 0) {
|
|
46
|
+
// raw data
|
|
47
|
+
var _data = this._readPixels(tileSize);
|
|
48
|
+
display.blitImage(tx, ty, tw, th, _data, 0, false);
|
|
49
|
+
} else if (subencoding === 1) {
|
|
50
|
+
// solid
|
|
51
|
+
var background = this._readPixels(1);
|
|
52
|
+
display.fillRect(tx, ty, tw, th, [background[0], background[1], background[2]]);
|
|
53
|
+
} else if (subencoding >= 2 && subencoding <= 16) {
|
|
54
|
+
var _data2 = this._decodePaletteTile(subencoding, tileSize, tw, th);
|
|
55
|
+
display.blitImage(tx, ty, tw, th, _data2, 0, false);
|
|
56
|
+
} else if (subencoding === 128) {
|
|
57
|
+
var _data3 = this._decodeRLETile(tileSize);
|
|
58
|
+
display.blitImage(tx, ty, tw, th, _data3, 0, false);
|
|
59
|
+
} else if (subencoding >= 130 && subencoding <= 255) {
|
|
60
|
+
var _data4 = this._decodeRLEPaletteTile(subencoding - 128, tileSize);
|
|
61
|
+
display.blitImage(tx, ty, tw, th, _data4, 0, false);
|
|
62
|
+
} else {
|
|
63
|
+
throw new Error('Unknown subencoding: ' + subencoding);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
this._length = 0;
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
key: "_getBitsPerPixelInPalette",
|
|
72
|
+
value: function _getBitsPerPixelInPalette(paletteSize) {
|
|
73
|
+
if (paletteSize <= 2) {
|
|
74
|
+
return 1;
|
|
75
|
+
} else if (paletteSize <= 4) {
|
|
76
|
+
return 2;
|
|
77
|
+
} else if (paletteSize <= 16) {
|
|
78
|
+
return 4;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
key: "_readPixels",
|
|
83
|
+
value: function _readPixels(pixels) {
|
|
84
|
+
var data = this._pixelBuffer;
|
|
85
|
+
var buffer = this._inflator.inflate(3 * pixels);
|
|
86
|
+
for (var 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
|
+
|
|
93
|
+
return data;
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: "_decodePaletteTile",
|
|
97
|
+
value: function _decodePaletteTile(paletteSize, tileSize, tilew, tileh) {
|
|
98
|
+
var data = this._tileBuffer;
|
|
99
|
+
var palette = this._readPixels(paletteSize);
|
|
100
|
+
var bitsPerPixel = this._getBitsPerPixelInPalette(paletteSize);
|
|
101
|
+
var mask = (1 << bitsPerPixel) - 1;
|
|
102
|
+
var offset = 0;
|
|
103
|
+
var encoded = this._inflator.inflate(1)[0];
|
|
104
|
+
for (var y = 0; y < tileh; y++) {
|
|
105
|
+
var shift = 8 - bitsPerPixel;
|
|
106
|
+
for (var x = 0; x < tilew; x++) {
|
|
107
|
+
if (shift < 0) {
|
|
108
|
+
shift = 8 - bitsPerPixel;
|
|
109
|
+
encoded = this._inflator.inflate(1)[0];
|
|
110
|
+
}
|
|
111
|
+
var indexInPalette = encoded >> shift & mask;
|
|
112
|
+
data[offset] = palette[indexInPalette * 4];
|
|
113
|
+
data[offset + 1] = palette[indexInPalette * 4 + 1];
|
|
114
|
+
data[offset + 2] = palette[indexInPalette * 4 + 2];
|
|
115
|
+
data[offset + 3] = palette[indexInPalette * 4 + 3];
|
|
116
|
+
offset += 4;
|
|
117
|
+
shift -= bitsPerPixel;
|
|
118
|
+
}
|
|
119
|
+
if (shift < 8 - bitsPerPixel && y < tileh - 1) {
|
|
120
|
+
encoded = this._inflator.inflate(1)[0];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return data;
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "_decodeRLETile",
|
|
127
|
+
value: function _decodeRLETile(tileSize) {
|
|
128
|
+
var data = this._tileBuffer;
|
|
129
|
+
var i = 0;
|
|
130
|
+
while (i < tileSize) {
|
|
131
|
+
var pixel = this._readPixels(1);
|
|
132
|
+
var length = this._readRLELength();
|
|
133
|
+
for (var 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
|
+
key: "_decodeRLEPaletteTile",
|
|
145
|
+
value: function _decodeRLEPaletteTile(paletteSize, tileSize) {
|
|
146
|
+
var data = this._tileBuffer;
|
|
147
|
+
|
|
148
|
+
// palette
|
|
149
|
+
var palette = this._readPixels(paletteSize);
|
|
150
|
+
var offset = 0;
|
|
151
|
+
while (offset < tileSize) {
|
|
152
|
+
var indexInPalette = this._inflator.inflate(1)[0];
|
|
153
|
+
var 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
|
+
for (var j = 0; j < length; j++) {
|
|
165
|
+
data[offset * 4] = palette[indexInPalette * 4];
|
|
166
|
+
data[offset * 4 + 1] = palette[indexInPalette * 4 + 1];
|
|
167
|
+
data[offset * 4 + 2] = palette[indexInPalette * 4 + 2];
|
|
168
|
+
data[offset * 4 + 3] = palette[indexInPalette * 4 + 3];
|
|
169
|
+
offset++;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return data;
|
|
173
|
+
}
|
|
174
|
+
}, {
|
|
175
|
+
key: "_readRLELength",
|
|
176
|
+
value: function _readRLELength() {
|
|
177
|
+
var length = 0;
|
|
178
|
+
var current = 0;
|
|
179
|
+
do {
|
|
180
|
+
current = this._inflator.inflate(1)[0];
|
|
181
|
+
length += current;
|
|
182
|
+
} while (current === 255);
|
|
183
|
+
return length + 1;
|
|
184
|
+
}
|
|
185
|
+
}]);
|
|
186
|
+
return ZRLEDecoder;
|
|
187
|
+
}();
|
|
188
|
+
exports["default"] = ZRLEDecoder;
|