@novnc/novnc 1.2.0 → 1.3.0-g0ef7582
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 +1 -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 +6 -11
- package/lib/decoders/hextile.js +68 -44
- package/lib/decoders/jpeg.js +146 -0
- package/lib/decoders/raw.js +14 -21
- package/lib/decoders/rre.js +3 -17
- package/lib/decoders/tight.js +43 -93
- package/lib/decoders/tightpng.js +11 -33
- package/lib/decoders/zrle.js +185 -0
- package/lib/deflator.js +9 -26
- package/lib/des.js +22 -38
- package/lib/display.js +100 -315
- package/lib/encodings.js +7 -8
- package/lib/inflator.js +6 -22
- package/lib/input/domkeytable.js +240 -208
- package/lib/input/fixedkeys.js +10 -5
- package/lib/input/gesturehandler.js +84 -154
- package/lib/input/keyboard.js +87 -238
- 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 +1033 -0
- package/lib/rfb.js +947 -1149
- package/lib/util/browser.js +25 -52
- package/lib/util/cursor.js +25 -81
- package/lib/util/element.js +3 -5
- package/lib/util/events.js +26 -35
- package/lib/util/eventtarget.js +4 -16
- 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 +119 -111
- package/package.json +2 -10
- 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,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
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
|
-
exports
|
|
9
|
-
|
|
7
|
+
exports["default"] = void 0;
|
|
10
8
|
var Log = _interopRequireWildcard(require("../util/logging.js"));
|
|
11
|
-
|
|
12
9
|
var _inflator = _interopRequireDefault(require("../inflator.js"));
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
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
|
-
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
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); }
|
|
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; }
|
|
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
|
-
this._zlibs[i] = new _inflator
|
|
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,39 +33,34 @@ 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
|
-
|
|
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
|
-
}
|
|
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) {
|
|
70
53
|
ret = this._jpegRect(x, y, width, height, sock, display, depth);
|
|
71
54
|
} else if (this._ctl === 0x0A) {
|
|
72
55
|
ret = this._pngRect(x, y, width, height, sock, display, depth);
|
|
73
|
-
} else if ((this._ctl &
|
|
56
|
+
} else if ((this._ctl & 0x08) == 0) {
|
|
74
57
|
ret = this._basicRect(this._ctl, x, y, width, height, sock, display, depth);
|
|
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,10 +69,9 @@ 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
|
-
display.fillRect(x, y, width, height, [rQ[rQi
|
|
74
|
+
display.fillRect(x, y, width, height, [rQ[rQi], rQ[rQi + 1], rQ[rQi + 2]], false);
|
|
95
75
|
sock.rQskipBytes(3);
|
|
96
76
|
return true;
|
|
97
77
|
}
|
|
@@ -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,28 +132,32 @@ 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
|
-
|
|
135
|
+
if (uncompressedSize === 0) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
166
138
|
if (uncompressedSize < 12) {
|
|
167
139
|
if (sock.rQwait("TIGHT", uncompressedSize)) {
|
|
168
140
|
return false;
|
|
169
141
|
}
|
|
170
|
-
|
|
171
142
|
data = sock.rQshiftBytes(uncompressedSize);
|
|
172
143
|
} else {
|
|
173
144
|
data = this._readData(sock);
|
|
174
|
-
|
|
175
145
|
if (data === null) {
|
|
176
146
|
return false;
|
|
177
147
|
}
|
|
178
|
-
|
|
179
148
|
this._zlibs[streamId].setInput(data);
|
|
180
|
-
|
|
181
149
|
data = this._zlibs[streamId].inflate(uncompressedSize);
|
|
182
|
-
|
|
183
150
|
this._zlibs[streamId].setInput(null);
|
|
184
151
|
}
|
|
152
|
+
var rgbx = new Uint8Array(width * height * 4);
|
|
153
|
+
for (var i = 0, j = 0; i < width * height * 4; i += 4, j += 3) {
|
|
154
|
+
rgbx[i] = data[j];
|
|
155
|
+
rgbx[i + 1] = data[j + 1];
|
|
156
|
+
rgbx[i + 2] = data[j + 2];
|
|
157
|
+
rgbx[i + 3] = 255; // Alpha
|
|
158
|
+
}
|
|
185
159
|
|
|
186
|
-
display.
|
|
160
|
+
display.blitImage(x, y, width, height, rgbx, 0, false);
|
|
187
161
|
return true;
|
|
188
162
|
}
|
|
189
163
|
}, {
|
|
@@ -193,51 +167,43 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
193
167
|
if (sock.rQwait("TIGHT palette", 1)) {
|
|
194
168
|
return false;
|
|
195
169
|
}
|
|
196
|
-
|
|
197
170
|
var numColors = sock.rQpeek8() + 1;
|
|
198
171
|
var paletteSize = numColors * 3;
|
|
199
|
-
|
|
200
172
|
if (sock.rQwait("TIGHT palette", 1 + paletteSize)) {
|
|
201
173
|
return false;
|
|
202
174
|
}
|
|
203
|
-
|
|
204
175
|
this._numColors = numColors;
|
|
205
176
|
sock.rQskipBytes(1);
|
|
206
177
|
sock.rQshiftTo(this._palette, paletteSize);
|
|
207
178
|
}
|
|
208
|
-
|
|
209
179
|
var bpp = this._numColors <= 2 ? 1 : 8;
|
|
210
180
|
var rowSize = Math.floor((width * bpp + 7) / 8);
|
|
211
181
|
var uncompressedSize = rowSize * height;
|
|
212
182
|
var data;
|
|
213
|
-
|
|
183
|
+
if (uncompressedSize === 0) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
214
186
|
if (uncompressedSize < 12) {
|
|
215
187
|
if (sock.rQwait("TIGHT", uncompressedSize)) {
|
|
216
188
|
return false;
|
|
217
189
|
}
|
|
218
|
-
|
|
219
190
|
data = sock.rQshiftBytes(uncompressedSize);
|
|
220
191
|
} else {
|
|
221
192
|
data = this._readData(sock);
|
|
222
|
-
|
|
223
193
|
if (data === null) {
|
|
224
194
|
return false;
|
|
225
195
|
}
|
|
226
|
-
|
|
227
196
|
this._zlibs[streamId].setInput(data);
|
|
228
|
-
|
|
229
197
|
data = this._zlibs[streamId].inflate(uncompressedSize);
|
|
230
|
-
|
|
231
198
|
this._zlibs[streamId].setInput(null);
|
|
232
|
-
}
|
|
233
|
-
|
|
199
|
+
}
|
|
234
200
|
|
|
201
|
+
// Convert indexed (palette based) image data to RGB
|
|
235
202
|
if (this._numColors == 2) {
|
|
236
203
|
this._monoRect(x, y, width, height, data, this._palette, display);
|
|
237
204
|
} else {
|
|
238
205
|
this._paletteRect(x, y, width, height, data, this._palette, display);
|
|
239
206
|
}
|
|
240
|
-
|
|
241
207
|
this._numColors = 0;
|
|
242
208
|
return true;
|
|
243
209
|
}
|
|
@@ -247,15 +213,12 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
247
213
|
// Convert indexed (palette based) image data to RGB
|
|
248
214
|
// TODO: reduce number of calculations inside loop
|
|
249
215
|
var dest = this._getScratchBuffer(width * height * 4);
|
|
250
|
-
|
|
251
216
|
var w = Math.floor((width + 7) / 8);
|
|
252
217
|
var w1 = Math.floor(width / 8);
|
|
253
|
-
|
|
254
218
|
for (var _y = 0; _y < height; _y++) {
|
|
255
219
|
var dp = void 0,
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
220
|
+
sp = void 0,
|
|
221
|
+
_x = void 0;
|
|
259
222
|
for (_x = 0; _x < w1; _x++) {
|
|
260
223
|
for (var b = 7; b >= 0; b--) {
|
|
261
224
|
dp = (_y * width + _x * 8 + 7 - b) * 4;
|
|
@@ -266,7 +229,6 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
266
229
|
dest[dp + 3] = 255;
|
|
267
230
|
}
|
|
268
231
|
}
|
|
269
|
-
|
|
270
232
|
for (var _b = 7; _b >= 8 - width % 8; _b--) {
|
|
271
233
|
dp = (_y * width + _x * 8 + 7 - _b) * 4;
|
|
272
234
|
sp = (data[_y * w + _x] >> _b & 1) * 3;
|
|
@@ -276,17 +238,14 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
276
238
|
dest[dp + 3] = 255;
|
|
277
239
|
}
|
|
278
240
|
}
|
|
279
|
-
|
|
280
|
-
display.blitRgbxImage(x, y, width, height, dest, 0, false);
|
|
241
|
+
display.blitImage(x, y, width, height, dest, 0, false);
|
|
281
242
|
}
|
|
282
243
|
}, {
|
|
283
244
|
key: "_paletteRect",
|
|
284
245
|
value: function _paletteRect(x, y, width, height, data, palette, display) {
|
|
285
246
|
// Convert indexed (palette based) image data to RGB
|
|
286
247
|
var dest = this._getScratchBuffer(width * height * 4);
|
|
287
|
-
|
|
288
248
|
var total = width * height * 4;
|
|
289
|
-
|
|
290
249
|
for (var i = 0, j = 0; i < total; i += 4, j++) {
|
|
291
250
|
var sp = data[j] * 3;
|
|
292
251
|
dest[i] = palette[sp];
|
|
@@ -294,8 +253,7 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
294
253
|
dest[i + 2] = palette[sp + 2];
|
|
295
254
|
dest[i + 3] = 255;
|
|
296
255
|
}
|
|
297
|
-
|
|
298
|
-
display.blitRgbxImage(x, y, width, height, dest, 0, false);
|
|
256
|
+
display.blitImage(x, y, width, height, dest, 0, false);
|
|
299
257
|
}
|
|
300
258
|
}, {
|
|
301
259
|
key: "_gradientFilter",
|
|
@@ -309,26 +267,21 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
309
267
|
if (sock.rQwait("TIGHT", 3)) {
|
|
310
268
|
return null;
|
|
311
269
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if (byte & 0x80) {
|
|
322
|
-
byte = sock.rQshift8();
|
|
323
|
-
this._len |= byte << 14;
|
|
270
|
+
var _byte;
|
|
271
|
+
_byte = sock.rQshift8();
|
|
272
|
+
this._len = _byte & 0x7f;
|
|
273
|
+
if (_byte & 0x80) {
|
|
274
|
+
_byte = sock.rQshift8();
|
|
275
|
+
this._len |= (_byte & 0x7f) << 7;
|
|
276
|
+
if (_byte & 0x80) {
|
|
277
|
+
_byte = sock.rQshift8();
|
|
278
|
+
this._len |= _byte << 14;
|
|
324
279
|
}
|
|
325
280
|
}
|
|
326
281
|
}
|
|
327
|
-
|
|
328
282
|
if (sock.rQwait("TIGHT", this._len)) {
|
|
329
283
|
return null;
|
|
330
284
|
}
|
|
331
|
-
|
|
332
285
|
var data = sock.rQshiftBytes(this._len);
|
|
333
286
|
this._len = 0;
|
|
334
287
|
return data;
|
|
@@ -339,12 +292,9 @@ var TightDecoder = /*#__PURE__*/function () {
|
|
|
339
292
|
if (!this._scratchBuffer || this._scratchBuffer.length < size) {
|
|
340
293
|
this._scratchBuffer = new Uint8Array(size);
|
|
341
294
|
}
|
|
342
|
-
|
|
343
295
|
return this._scratchBuffer;
|
|
344
296
|
}
|
|
345
297
|
}]);
|
|
346
|
-
|
|
347
298
|
return TightDecoder;
|
|
348
299
|
}();
|
|
349
|
-
|
|
350
|
-
exports.default = TightDecoder;
|
|
300
|
+
exports["default"] = TightDecoder;
|
package/lib/decoders/tightpng.js
CHANGED
|
@@ -1,56 +1,36 @@
|
|
|
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
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, descriptor.key, descriptor); } }
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
21
|
-
|
|
22
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
23
|
-
|
|
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 _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); }
|
|
14
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
24
15
|
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
|
-
|
|
16
|
+
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
17
|
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
|
-
|
|
18
|
+
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; } }
|
|
19
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
34
20
|
var TightPNGDecoder = /*#__PURE__*/function (_TightDecoder) {
|
|
35
21
|
_inherits(TightPNGDecoder, _TightDecoder);
|
|
36
|
-
|
|
37
22
|
var _super = _createSuper(TightPNGDecoder);
|
|
38
|
-
|
|
39
23
|
function TightPNGDecoder() {
|
|
40
24
|
_classCallCheck(this, TightPNGDecoder);
|
|
41
|
-
|
|
42
25
|
return _super.apply(this, arguments);
|
|
43
26
|
}
|
|
44
|
-
|
|
45
27
|
_createClass(TightPNGDecoder, [{
|
|
46
28
|
key: "_pngRect",
|
|
47
29
|
value: function _pngRect(x, y, width, height, sock, display, depth) {
|
|
48
30
|
var data = this._readData(sock);
|
|
49
|
-
|
|
50
31
|
if (data === null) {
|
|
51
32
|
return false;
|
|
52
33
|
}
|
|
53
|
-
|
|
54
34
|
display.imageRect(x, y, width, height, "image/png", data);
|
|
55
35
|
return true;
|
|
56
36
|
}
|
|
@@ -60,8 +40,6 @@ var TightPNGDecoder = /*#__PURE__*/function (_TightDecoder) {
|
|
|
60
40
|
throw new Error("BasicCompression received in TightPNG rect");
|
|
61
41
|
}
|
|
62
42
|
}]);
|
|
63
|
-
|
|
64
43
|
return TightPNGDecoder;
|
|
65
|
-
}(_tight
|
|
66
|
-
|
|
67
|
-
exports.default = TightPNGDecoder;
|
|
44
|
+
}(_tight["default"]);
|
|
45
|
+
exports["default"] = TightPNGDecoder;
|
|
@@ -0,0 +1,185 @@
|
|
|
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
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
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
var ZRLE_TILE_WIDTH = 64;
|
|
13
|
+
var ZRLE_TILE_HEIGHT = 64;
|
|
14
|
+
var ZRLEDecoder = /*#__PURE__*/function () {
|
|
15
|
+
function ZRLEDecoder() {
|
|
16
|
+
_classCallCheck(this, ZRLEDecoder);
|
|
17
|
+
this._length = 0;
|
|
18
|
+
this._inflator = new _inflator["default"]();
|
|
19
|
+
this._pixelBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
|
|
20
|
+
this._tileBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
|
|
21
|
+
}
|
|
22
|
+
_createClass(ZRLEDecoder, [{
|
|
23
|
+
key: "decodeRect",
|
|
24
|
+
value: function 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
|
+
var data = sock.rQshiftBytes(this._length);
|
|
35
|
+
this._inflator.setInput(data);
|
|
36
|
+
for (var ty = y; ty < y + height; ty += ZRLE_TILE_HEIGHT) {
|
|
37
|
+
var th = Math.min(ZRLE_TILE_HEIGHT, y + height - ty);
|
|
38
|
+
for (var tx = x; tx < x + width; tx += ZRLE_TILE_WIDTH) {
|
|
39
|
+
var tw = Math.min(ZRLE_TILE_WIDTH, x + width - tx);
|
|
40
|
+
var tileSize = tw * th;
|
|
41
|
+
var subencoding = this._inflator.inflate(1)[0];
|
|
42
|
+
if (subencoding === 0) {
|
|
43
|
+
// raw data
|
|
44
|
+
var _data = this._readPixels(tileSize);
|
|
45
|
+
display.blitImage(tx, ty, tw, th, _data, 0, false);
|
|
46
|
+
} else if (subencoding === 1) {
|
|
47
|
+
// solid
|
|
48
|
+
var background = this._readPixels(1);
|
|
49
|
+
display.fillRect(tx, ty, tw, th, [background[0], background[1], background[2]]);
|
|
50
|
+
} else if (subencoding >= 2 && subencoding <= 16) {
|
|
51
|
+
var _data2 = this._decodePaletteTile(subencoding, tileSize, tw, th);
|
|
52
|
+
display.blitImage(tx, ty, tw, th, _data2, 0, false);
|
|
53
|
+
} else if (subencoding === 128) {
|
|
54
|
+
var _data3 = this._decodeRLETile(tileSize);
|
|
55
|
+
display.blitImage(tx, ty, tw, th, _data3, 0, false);
|
|
56
|
+
} else if (subencoding >= 130 && subencoding <= 255) {
|
|
57
|
+
var _data4 = this._decodeRLEPaletteTile(subencoding - 128, tileSize);
|
|
58
|
+
display.blitImage(tx, ty, tw, th, _data4, 0, false);
|
|
59
|
+
} else {
|
|
60
|
+
throw new Error('Unknown subencoding: ' + subencoding);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
this._length = 0;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "_getBitsPerPixelInPalette",
|
|
69
|
+
value: function _getBitsPerPixelInPalette(paletteSize) {
|
|
70
|
+
if (paletteSize <= 2) {
|
|
71
|
+
return 1;
|
|
72
|
+
} else if (paletteSize <= 4) {
|
|
73
|
+
return 2;
|
|
74
|
+
} else if (paletteSize <= 16) {
|
|
75
|
+
return 4;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}, {
|
|
79
|
+
key: "_readPixels",
|
|
80
|
+
value: function _readPixels(pixels) {
|
|
81
|
+
var data = this._pixelBuffer;
|
|
82
|
+
var buffer = this._inflator.inflate(3 * pixels);
|
|
83
|
+
for (var i = 0, j = 0; i < pixels * 4; i += 4, j += 3) {
|
|
84
|
+
data[i] = buffer[j];
|
|
85
|
+
data[i + 1] = buffer[j + 1];
|
|
86
|
+
data[i + 2] = buffer[j + 2];
|
|
87
|
+
data[i + 3] = 255; // Add the Alpha
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
}, {
|
|
93
|
+
key: "_decodePaletteTile",
|
|
94
|
+
value: function _decodePaletteTile(paletteSize, tileSize, tilew, tileh) {
|
|
95
|
+
var data = this._tileBuffer;
|
|
96
|
+
var palette = this._readPixels(paletteSize);
|
|
97
|
+
var bitsPerPixel = this._getBitsPerPixelInPalette(paletteSize);
|
|
98
|
+
var mask = (1 << bitsPerPixel) - 1;
|
|
99
|
+
var offset = 0;
|
|
100
|
+
var encoded = this._inflator.inflate(1)[0];
|
|
101
|
+
for (var y = 0; y < tileh; y++) {
|
|
102
|
+
var shift = 8 - bitsPerPixel;
|
|
103
|
+
for (var x = 0; x < tilew; x++) {
|
|
104
|
+
if (shift < 0) {
|
|
105
|
+
shift = 8 - bitsPerPixel;
|
|
106
|
+
encoded = this._inflator.inflate(1)[0];
|
|
107
|
+
}
|
|
108
|
+
var indexInPalette = encoded >> shift & mask;
|
|
109
|
+
data[offset] = palette[indexInPalette * 4];
|
|
110
|
+
data[offset + 1] = palette[indexInPalette * 4 + 1];
|
|
111
|
+
data[offset + 2] = palette[indexInPalette * 4 + 2];
|
|
112
|
+
data[offset + 3] = palette[indexInPalette * 4 + 3];
|
|
113
|
+
offset += 4;
|
|
114
|
+
shift -= bitsPerPixel;
|
|
115
|
+
}
|
|
116
|
+
if (shift < 8 - bitsPerPixel && y < tileh - 1) {
|
|
117
|
+
encoded = this._inflator.inflate(1)[0];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return data;
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
123
|
+
key: "_decodeRLETile",
|
|
124
|
+
value: function _decodeRLETile(tileSize) {
|
|
125
|
+
var data = this._tileBuffer;
|
|
126
|
+
var i = 0;
|
|
127
|
+
while (i < tileSize) {
|
|
128
|
+
var pixel = this._readPixels(1);
|
|
129
|
+
var length = this._readRLELength();
|
|
130
|
+
for (var j = 0; j < length; j++) {
|
|
131
|
+
data[i * 4] = pixel[0];
|
|
132
|
+
data[i * 4 + 1] = pixel[1];
|
|
133
|
+
data[i * 4 + 2] = pixel[2];
|
|
134
|
+
data[i * 4 + 3] = pixel[3];
|
|
135
|
+
i++;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return data;
|
|
139
|
+
}
|
|
140
|
+
}, {
|
|
141
|
+
key: "_decodeRLEPaletteTile",
|
|
142
|
+
value: function _decodeRLEPaletteTile(paletteSize, tileSize) {
|
|
143
|
+
var data = this._tileBuffer;
|
|
144
|
+
|
|
145
|
+
// palette
|
|
146
|
+
var palette = this._readPixels(paletteSize);
|
|
147
|
+
var offset = 0;
|
|
148
|
+
while (offset < tileSize) {
|
|
149
|
+
var indexInPalette = this._inflator.inflate(1)[0];
|
|
150
|
+
var length = 1;
|
|
151
|
+
if (indexInPalette >= 128) {
|
|
152
|
+
indexInPalette -= 128;
|
|
153
|
+
length = this._readRLELength();
|
|
154
|
+
}
|
|
155
|
+
if (indexInPalette > paletteSize) {
|
|
156
|
+
throw new Error('Too big index in palette: ' + indexInPalette + ', palette size: ' + paletteSize);
|
|
157
|
+
}
|
|
158
|
+
if (offset + length > tileSize) {
|
|
159
|
+
throw new Error('Too big rle length in palette mode: ' + length + ', allowed length is: ' + (tileSize - offset));
|
|
160
|
+
}
|
|
161
|
+
for (var j = 0; j < length; j++) {
|
|
162
|
+
data[offset * 4] = palette[indexInPalette * 4];
|
|
163
|
+
data[offset * 4 + 1] = palette[indexInPalette * 4 + 1];
|
|
164
|
+
data[offset * 4 + 2] = palette[indexInPalette * 4 + 2];
|
|
165
|
+
data[offset * 4 + 3] = palette[indexInPalette * 4 + 3];
|
|
166
|
+
offset++;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return data;
|
|
170
|
+
}
|
|
171
|
+
}, {
|
|
172
|
+
key: "_readRLELength",
|
|
173
|
+
value: function _readRLELength() {
|
|
174
|
+
var length = 0;
|
|
175
|
+
var current = 0;
|
|
176
|
+
do {
|
|
177
|
+
current = this._inflator.inflate(1)[0];
|
|
178
|
+
length += current;
|
|
179
|
+
} while (current === 255);
|
|
180
|
+
return length + 1;
|
|
181
|
+
}
|
|
182
|
+
}]);
|
|
183
|
+
return ZRLEDecoder;
|
|
184
|
+
}();
|
|
185
|
+
exports["default"] = ZRLEDecoder;
|