@novnc/novnc 1.2.0 → 1.3.0-g65d6357
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 +9 -4
- package/core/decoders/copyrect.js +5 -0
- package/core/decoders/hextile.js +57 -3
- 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 +9 -151
- package/core/encodings.js +2 -0
- package/core/input/domkeytable.js +25 -21
- package/core/input/keyboard.js +12 -127
- package/core/input/util.js +18 -35
- package/core/input/vkeys.js +0 -1
- package/core/input/xtscancodes.js +5 -3
- package/core/rfb.js +119 -109
- package/core/util/browser.js +0 -17
- package/core/util/cursor.js +1 -11
- package/core/util/events.js +0 -4
- package/core/websock.js +76 -17
- package/docs/API.md +10 -3
- package/docs/LIBRARY.md +3 -7
- package/lib/base64.js +4 -4
- package/lib/decoders/copyrect.js +7 -2
- package/lib/decoders/hextile.js +63 -7
- package/lib/decoders/raw.js +13 -4
- package/lib/decoders/rre.js +2 -2
- package/lib/decoders/tight.js +38 -20
- package/lib/decoders/tightpng.js +8 -8
- package/lib/decoders/zrle.js +234 -0
- package/lib/deflator.js +4 -4
- package/lib/des.js +2 -2
- package/lib/display.js +45 -212
- package/lib/encodings.js +4 -0
- package/lib/inflator.js +4 -4
- package/lib/input/domkeytable.js +197 -194
- package/lib/input/fixedkeys.js +2 -2
- package/lib/input/gesturehandler.js +2 -2
- package/lib/input/keyboard.js +38 -158
- package/lib/input/keysym.js +2 -2
- package/lib/input/keysymdef.js +2 -2
- package/lib/input/util.js +34 -79
- package/lib/input/vkeys.js +2 -4
- package/lib/input/xtscancodes.js +11 -5
- package/lib/rfb.js +295 -285
- package/lib/util/browser.js +8 -26
- package/lib/util/cursor.js +4 -16
- package/lib/util/events.js +3 -5
- package/lib/util/eventtarget.js +3 -3
- package/lib/util/int.js +1 -1
- package/lib/util/logging.js +2 -2
- package/lib/vendor/pako/lib/utils/common.js +2 -2
- package/lib/vendor/pako/lib/zlib/adler32.js +1 -1
- package/lib/vendor/pako/lib/zlib/constants.js +2 -2
- package/lib/vendor/pako/lib/zlib/crc32.js +1 -1
- package/lib/vendor/pako/lib/zlib/deflate.js +113 -112
- package/lib/vendor/pako/lib/zlib/gzheader.js +1 -1
- package/lib/vendor/pako/lib/zlib/inffast.js +5 -5
- package/lib/vendor/pako/lib/zlib/inflate.js +50 -48
- package/lib/vendor/pako/lib/zlib/inftrees.js +3 -3
- package/lib/vendor/pako/lib/zlib/messages.js +2 -2
- package/lib/vendor/pako/lib/zlib/trees.js +4 -4
- package/lib/vendor/pako/lib/zlib/zstream.js +1 -1
- package/lib/websock.js +105 -44
- package/package.json +2 -7
- package/core/util/polyfill.js +0 -61
- package/lib/util/polyfill.js +0 -72
- package/lib/vendor/promise.js +0 -255
package/LICENSE.txt
CHANGED
|
@@ -42,12 +42,6 @@ licenses (all MPL 2.0 compatible):
|
|
|
42
42
|
|
|
43
43
|
vendor/pako/ : MIT
|
|
44
44
|
|
|
45
|
-
vendor/browser-es-module-loader/src/ : MIT
|
|
46
|
-
|
|
47
|
-
vendor/browser-es-module-loader/dist/ : Various BSD style licenses
|
|
48
|
-
|
|
49
|
-
vendor/promise.js : MIT
|
|
50
|
-
|
|
51
45
|
Any other files not mentioned above are typically marked with
|
|
52
46
|
a copyright/license header at the top of the file. The default noVNC
|
|
53
47
|
license is MPL-2.0.
|
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ noVNC uses many modern web technologies so a formal requirement list is
|
|
|
91
91
|
not available. However these are the minimum versions we are currently
|
|
92
92
|
aware of:
|
|
93
93
|
|
|
94
|
-
* Chrome
|
|
94
|
+
* Chrome 64, Firefox 79, Safari 13.4, Opera 51, Edge 79
|
|
95
95
|
|
|
96
96
|
|
|
97
97
|
### Server Requirements
|
|
@@ -108,13 +108,18 @@ proxy.
|
|
|
108
108
|
|
|
109
109
|
### Quick Start
|
|
110
110
|
|
|
111
|
-
* Use the
|
|
111
|
+
* Use the `novnc_proxy` script to automatically download and start websockify, which
|
|
112
112
|
includes a mini-webserver and the WebSockets proxy. The `--vnc` option is
|
|
113
113
|
used to specify the location of a running VNC server:
|
|
114
114
|
|
|
115
|
-
`./utils/
|
|
115
|
+
`./utils/novnc_proxy --vnc localhost:5901`
|
|
116
|
+
|
|
117
|
+
* If you don't need to expose the web server to public internet, you can
|
|
118
|
+
bind to localhost:
|
|
119
|
+
|
|
120
|
+
`./utils/novnc_proxy --vnc localhost:5901 --listen localhost:6081`
|
|
116
121
|
|
|
117
|
-
* Point your browser to the cut-and-paste URL that is output by the
|
|
122
|
+
* Point your browser to the cut-and-paste URL that is output by the `novnc_proxy`
|
|
118
123
|
script. Hit the Connect button, enter a password if the VNC server has one
|
|
119
124
|
configured, and enjoy!
|
|
120
125
|
|
|
@@ -15,6 +15,11 @@ export default class CopyRectDecoder {
|
|
|
15
15
|
|
|
16
16
|
let deltaX = sock.rQshift16();
|
|
17
17
|
let deltaY = sock.rQshift16();
|
|
18
|
+
|
|
19
|
+
if ((width === 0) || (height === 0)) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
display.copyImage(deltaX, deltaY, x, y, width, height);
|
|
19
24
|
|
|
20
25
|
return true;
|
package/core/decoders/hextile.js
CHANGED
|
@@ -13,6 +13,7 @@ export default class HextileDecoder {
|
|
|
13
13
|
constructor() {
|
|
14
14
|
this._tiles = 0;
|
|
15
15
|
this._lastsubencoding = 0;
|
|
16
|
+
this._tileBuffer = new Uint8Array(16 * 16 * 4);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
decodeRect(x, y, width, height, sock, display, depth) {
|
|
@@ -87,6 +88,11 @@ export default class HextileDecoder {
|
|
|
87
88
|
display.fillRect(tx, ty, tw, th, this._background);
|
|
88
89
|
}
|
|
89
90
|
} else if (subencoding & 0x01) { // Raw
|
|
91
|
+
let pixels = tw * th;
|
|
92
|
+
// Max sure the image is fully opaque
|
|
93
|
+
for (let i = 0;i < pixels;i++) {
|
|
94
|
+
rQ[rQi + i * 4 + 3] = 255;
|
|
95
|
+
}
|
|
90
96
|
display.blitImage(tx, ty, tw, th, rQ, rQi);
|
|
91
97
|
rQi += bytes - 1;
|
|
92
98
|
} else {
|
|
@@ -99,7 +105,7 @@ export default class HextileDecoder {
|
|
|
99
105
|
rQi += 4;
|
|
100
106
|
}
|
|
101
107
|
|
|
102
|
-
|
|
108
|
+
this._startTile(tx, ty, tw, th, this._background);
|
|
103
109
|
if (subencoding & 0x08) { // AnySubrects
|
|
104
110
|
let subrects = rQ[rQi];
|
|
105
111
|
rQi++;
|
|
@@ -122,10 +128,10 @@ export default class HextileDecoder {
|
|
|
122
128
|
const sw = (wh >> 4) + 1;
|
|
123
129
|
const sh = (wh & 0x0f) + 1;
|
|
124
130
|
|
|
125
|
-
|
|
131
|
+
this._subTile(sx, sy, sw, sh, color);
|
|
126
132
|
}
|
|
127
133
|
}
|
|
128
|
-
|
|
134
|
+
this._finishTile(display);
|
|
129
135
|
}
|
|
130
136
|
sock.rQi = rQi;
|
|
131
137
|
this._lastsubencoding = subencoding;
|
|
@@ -134,4 +140,52 @@ export default class HextileDecoder {
|
|
|
134
140
|
|
|
135
141
|
return true;
|
|
136
142
|
}
|
|
143
|
+
|
|
144
|
+
// start updating a tile
|
|
145
|
+
_startTile(x, y, width, height, color) {
|
|
146
|
+
this._tileX = x;
|
|
147
|
+
this._tileY = y;
|
|
148
|
+
this._tileW = width;
|
|
149
|
+
this._tileH = height;
|
|
150
|
+
|
|
151
|
+
const red = color[0];
|
|
152
|
+
const green = color[1];
|
|
153
|
+
const blue = color[2];
|
|
154
|
+
|
|
155
|
+
const data = this._tileBuffer;
|
|
156
|
+
for (let i = 0; i < width * height * 4; i += 4) {
|
|
157
|
+
data[i] = red;
|
|
158
|
+
data[i + 1] = green;
|
|
159
|
+
data[i + 2] = blue;
|
|
160
|
+
data[i + 3] = 255;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// update sub-rectangle of the current tile
|
|
165
|
+
_subTile(x, y, w, h, color) {
|
|
166
|
+
const red = color[0];
|
|
167
|
+
const green = color[1];
|
|
168
|
+
const blue = color[2];
|
|
169
|
+
const xend = x + w;
|
|
170
|
+
const yend = y + h;
|
|
171
|
+
|
|
172
|
+
const data = this._tileBuffer;
|
|
173
|
+
const width = this._tileW;
|
|
174
|
+
for (let j = y; j < yend; j++) {
|
|
175
|
+
for (let i = x; i < xend; i++) {
|
|
176
|
+
const p = (i + (j * width)) * 4;
|
|
177
|
+
data[p] = red;
|
|
178
|
+
data[p + 1] = green;
|
|
179
|
+
data[p + 2] = blue;
|
|
180
|
+
data[p + 3] = 255;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// draw the current tile to the screen
|
|
186
|
+
_finishTile(display) {
|
|
187
|
+
display.blitImage(this._tileX, this._tileY,
|
|
188
|
+
this._tileW, this._tileH,
|
|
189
|
+
this._tileBuffer, 0);
|
|
190
|
+
}
|
|
137
191
|
}
|
package/core/decoders/raw.js
CHANGED
|
@@ -13,6 +13,10 @@ export default class RawDecoder {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
decodeRect(x, y, width, height, sock, display, depth) {
|
|
16
|
+
if ((width === 0) || (height === 0)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
16
20
|
if (this._lines === 0) {
|
|
17
21
|
this._lines = height;
|
|
18
22
|
}
|
|
@@ -27,23 +31,29 @@ export default class RawDecoder {
|
|
|
27
31
|
const curY = y + (height - this._lines);
|
|
28
32
|
const currHeight = Math.min(this._lines,
|
|
29
33
|
Math.floor(sock.rQlen / bytesPerLine));
|
|
34
|
+
const pixels = width * currHeight;
|
|
35
|
+
|
|
30
36
|
let data = sock.rQ;
|
|
31
37
|
let index = sock.rQi;
|
|
32
38
|
|
|
33
39
|
// Convert data if needed
|
|
34
40
|
if (depth == 8) {
|
|
35
|
-
const pixels = width * currHeight;
|
|
36
41
|
const newdata = new Uint8Array(pixels * 4);
|
|
37
42
|
for (let i = 0; i < pixels; i++) {
|
|
38
43
|
newdata[i * 4 + 0] = ((data[index + i] >> 0) & 0x3) * 255 / 3;
|
|
39
44
|
newdata[i * 4 + 1] = ((data[index + i] >> 2) & 0x3) * 255 / 3;
|
|
40
45
|
newdata[i * 4 + 2] = ((data[index + i] >> 4) & 0x3) * 255 / 3;
|
|
41
|
-
newdata[i * 4 +
|
|
46
|
+
newdata[i * 4 + 3] = 255;
|
|
42
47
|
}
|
|
43
48
|
data = newdata;
|
|
44
49
|
index = 0;
|
|
45
50
|
}
|
|
46
51
|
|
|
52
|
+
// Max sure the image is fully opaque
|
|
53
|
+
for (let i = 0; i < pixels; i++) {
|
|
54
|
+
data[i * 4 + 3] = 255;
|
|
55
|
+
}
|
|
56
|
+
|
|
47
57
|
display.blitImage(x, curY, width, currHeight, data, index);
|
|
48
58
|
sock.rQskipBytes(currHeight * bytesPerLine);
|
|
49
59
|
this._lines -= currHeight;
|
package/core/decoders/tight.js
CHANGED
|
@@ -56,7 +56,7 @@ export default class TightDecoder {
|
|
|
56
56
|
} else if (this._ctl === 0x0A) {
|
|
57
57
|
ret = this._pngRect(x, y, width, height,
|
|
58
58
|
sock, display, depth);
|
|
59
|
-
} else if ((this._ctl &
|
|
59
|
+
} else if ((this._ctl & 0x08) == 0) {
|
|
60
60
|
ret = this._basicRect(this._ctl, x, y, width, height,
|
|
61
61
|
sock, display, depth);
|
|
62
62
|
} else {
|
|
@@ -80,7 +80,7 @@ export default class TightDecoder {
|
|
|
80
80
|
const rQ = sock.rQ;
|
|
81
81
|
|
|
82
82
|
display.fillRect(x, y, width, height,
|
|
83
|
-
[rQ[rQi
|
|
83
|
+
[rQ[rQi], rQ[rQi + 1], rQ[rQi + 2]], false);
|
|
84
84
|
sock.rQskipBytes(3);
|
|
85
85
|
|
|
86
86
|
return true;
|
|
@@ -148,6 +148,10 @@ export default class TightDecoder {
|
|
|
148
148
|
const uncompressedSize = width * height * 3;
|
|
149
149
|
let data;
|
|
150
150
|
|
|
151
|
+
if (uncompressedSize === 0) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
|
|
151
155
|
if (uncompressedSize < 12) {
|
|
152
156
|
if (sock.rQwait("TIGHT", uncompressedSize)) {
|
|
153
157
|
return false;
|
|
@@ -165,7 +169,15 @@ export default class TightDecoder {
|
|
|
165
169
|
this._zlibs[streamId].setInput(null);
|
|
166
170
|
}
|
|
167
171
|
|
|
168
|
-
|
|
172
|
+
let rgbx = new Uint8Array(width * height * 4);
|
|
173
|
+
for (let i = 0, j = 0; i < width * height * 4; i += 4, j += 3) {
|
|
174
|
+
rgbx[i] = data[j];
|
|
175
|
+
rgbx[i + 1] = data[j + 1];
|
|
176
|
+
rgbx[i + 2] = data[j + 2];
|
|
177
|
+
rgbx[i + 3] = 255; // Alpha
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
display.blitImage(x, y, width, height, rgbx, 0, false);
|
|
169
181
|
|
|
170
182
|
return true;
|
|
171
183
|
}
|
|
@@ -195,6 +207,10 @@ export default class TightDecoder {
|
|
|
195
207
|
|
|
196
208
|
let data;
|
|
197
209
|
|
|
210
|
+
if (uncompressedSize === 0) {
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
|
|
198
214
|
if (uncompressedSize < 12) {
|
|
199
215
|
if (sock.rQwait("TIGHT", uncompressedSize)) {
|
|
200
216
|
return false;
|
|
@@ -237,7 +253,7 @@ export default class TightDecoder {
|
|
|
237
253
|
for (let b = 7; b >= 0; b--) {
|
|
238
254
|
dp = (y * width + x * 8 + 7 - b) * 4;
|
|
239
255
|
sp = (data[y * w + x] >> b & 1) * 3;
|
|
240
|
-
dest[dp]
|
|
256
|
+
dest[dp] = palette[sp];
|
|
241
257
|
dest[dp + 1] = palette[sp + 1];
|
|
242
258
|
dest[dp + 2] = palette[sp + 2];
|
|
243
259
|
dest[dp + 3] = 255;
|
|
@@ -247,14 +263,14 @@ export default class TightDecoder {
|
|
|
247
263
|
for (let b = 7; b >= 8 - width % 8; b--) {
|
|
248
264
|
dp = (y * width + x * 8 + 7 - b) * 4;
|
|
249
265
|
sp = (data[y * w + x] >> b & 1) * 3;
|
|
250
|
-
dest[dp]
|
|
266
|
+
dest[dp] = palette[sp];
|
|
251
267
|
dest[dp + 1] = palette[sp + 1];
|
|
252
268
|
dest[dp + 2] = palette[sp + 2];
|
|
253
269
|
dest[dp + 3] = 255;
|
|
254
270
|
}
|
|
255
271
|
}
|
|
256
272
|
|
|
257
|
-
display.
|
|
273
|
+
display.blitImage(x, y, width, height, dest, 0, false);
|
|
258
274
|
}
|
|
259
275
|
|
|
260
276
|
_paletteRect(x, y, width, height, data, palette, display) {
|
|
@@ -263,13 +279,13 @@ export default class TightDecoder {
|
|
|
263
279
|
const total = width * height * 4;
|
|
264
280
|
for (let i = 0, j = 0; i < total; i += 4, j++) {
|
|
265
281
|
const sp = data[j] * 3;
|
|
266
|
-
dest[i]
|
|
282
|
+
dest[i] = palette[sp];
|
|
267
283
|
dest[i + 1] = palette[sp + 1];
|
|
268
284
|
dest[i + 2] = palette[sp + 2];
|
|
269
285
|
dest[i + 3] = 255;
|
|
270
286
|
}
|
|
271
287
|
|
|
272
|
-
display.
|
|
288
|
+
display.blitImage(x, y, width, height, dest, 0, false);
|
|
273
289
|
}
|
|
274
290
|
|
|
275
291
|
_gradientFilter(streamId, x, y, width, height, sock, display, depth) {
|
|
@@ -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/display.js
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
import * as Log from './util/logging.js';
|
|
10
10
|
import Base64 from "./base64.js";
|
|
11
|
-
import { supportsImageMetadata } from './util/browser.js';
|
|
12
11
|
import { toSigned32bit } from './util/int.js';
|
|
13
12
|
|
|
14
13
|
export default class Display {
|
|
@@ -23,10 +22,6 @@ export default class Display {
|
|
|
23
22
|
this._fbHeight = 0;
|
|
24
23
|
|
|
25
24
|
this._prevDrawStyle = "";
|
|
26
|
-
this._tile = null;
|
|
27
|
-
this._tile16x16 = null;
|
|
28
|
-
this._tileX = 0;
|
|
29
|
-
this._tileY = 0;
|
|
30
25
|
|
|
31
26
|
Log.Debug(">> Display.constructor");
|
|
32
27
|
|
|
@@ -60,12 +55,6 @@ export default class Display {
|
|
|
60
55
|
|
|
61
56
|
Log.Debug("User Agent: " + navigator.userAgent);
|
|
62
57
|
|
|
63
|
-
// Check canvas features
|
|
64
|
-
if (!('createImageData' in this._drawCtx)) {
|
|
65
|
-
throw new Error("Canvas does not support createImageData");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
this._tile16x16 = this._drawCtx.createImageData(16, 16);
|
|
69
58
|
Log.Debug("<< Display.constructor");
|
|
70
59
|
|
|
71
60
|
// ===== PROPERTIES =====
|
|
@@ -378,57 +367,6 @@ export default class Display {
|
|
|
378
367
|
});
|
|
379
368
|
}
|
|
380
369
|
|
|
381
|
-
// start updating a tile
|
|
382
|
-
startTile(x, y, width, height, color) {
|
|
383
|
-
this._tileX = x;
|
|
384
|
-
this._tileY = y;
|
|
385
|
-
if (width === 16 && height === 16) {
|
|
386
|
-
this._tile = this._tile16x16;
|
|
387
|
-
} else {
|
|
388
|
-
this._tile = this._drawCtx.createImageData(width, height);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
const red = color[2];
|
|
392
|
-
const green = color[1];
|
|
393
|
-
const blue = color[0];
|
|
394
|
-
|
|
395
|
-
const data = this._tile.data;
|
|
396
|
-
for (let i = 0; i < width * height * 4; i += 4) {
|
|
397
|
-
data[i] = red;
|
|
398
|
-
data[i + 1] = green;
|
|
399
|
-
data[i + 2] = blue;
|
|
400
|
-
data[i + 3] = 255;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// update sub-rectangle of the current tile
|
|
405
|
-
subTile(x, y, w, h, color) {
|
|
406
|
-
const red = color[2];
|
|
407
|
-
const green = color[1];
|
|
408
|
-
const blue = color[0];
|
|
409
|
-
const xend = x + w;
|
|
410
|
-
const yend = y + h;
|
|
411
|
-
|
|
412
|
-
const data = this._tile.data;
|
|
413
|
-
const width = this._tile.width;
|
|
414
|
-
for (let j = y; j < yend; j++) {
|
|
415
|
-
for (let i = x; i < xend; i++) {
|
|
416
|
-
const p = (i + (j * width)) * 4;
|
|
417
|
-
data[p] = red;
|
|
418
|
-
data[p + 1] = green;
|
|
419
|
-
data[p + 2] = blue;
|
|
420
|
-
data[p + 3] = 255;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// draw the current tile to the screen
|
|
426
|
-
finishTile() {
|
|
427
|
-
this._drawCtx.putImageData(this._tile, this._tileX, this._tileY);
|
|
428
|
-
this._damage(this._tileX, this._tileY,
|
|
429
|
-
this._tile.width, this._tile.height);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
370
|
blitImage(x, y, width, height, arr, offset, fromQueue) {
|
|
433
371
|
if (this._renderQ.length !== 0 && !fromQueue) {
|
|
434
372
|
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
|
@@ -445,47 +383,13 @@ export default class Display {
|
|
|
445
383
|
'height': height,
|
|
446
384
|
});
|
|
447
385
|
} else {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
|
456
|
-
// this probably isn't getting called *nearly* as much
|
|
457
|
-
const newArr = new Uint8Array(width * height * 3);
|
|
458
|
-
newArr.set(new Uint8Array(arr.buffer, 0, newArr.length));
|
|
459
|
-
this._renderQPush({
|
|
460
|
-
'type': 'blitRgb',
|
|
461
|
-
'data': newArr,
|
|
462
|
-
'x': x,
|
|
463
|
-
'y': y,
|
|
464
|
-
'width': width,
|
|
465
|
-
'height': height,
|
|
466
|
-
});
|
|
467
|
-
} else {
|
|
468
|
-
this._rgbImageData(x, y, width, height, arr, offset);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
blitRgbxImage(x, y, width, height, arr, offset, fromQueue) {
|
|
473
|
-
if (this._renderQ.length !== 0 && !fromQueue) {
|
|
474
|
-
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
|
475
|
-
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
|
476
|
-
// this probably isn't getting called *nearly* as much
|
|
477
|
-
const newArr = new Uint8Array(width * height * 4);
|
|
478
|
-
newArr.set(new Uint8Array(arr.buffer, 0, newArr.length));
|
|
479
|
-
this._renderQPush({
|
|
480
|
-
'type': 'blitRgbx',
|
|
481
|
-
'data': newArr,
|
|
482
|
-
'x': x,
|
|
483
|
-
'y': y,
|
|
484
|
-
'width': width,
|
|
485
|
-
'height': height,
|
|
486
|
-
});
|
|
487
|
-
} else {
|
|
488
|
-
this._rgbxImageData(x, y, width, height, arr, offset);
|
|
386
|
+
// NB(directxman12): arr must be an Type Array view
|
|
387
|
+
let data = new Uint8ClampedArray(arr.buffer,
|
|
388
|
+
arr.byteOffset + offset,
|
|
389
|
+
width * height * 4);
|
|
390
|
+
let img = new ImageData(data, width, height);
|
|
391
|
+
this._drawCtx.putImageData(img, x, y);
|
|
392
|
+
this._damage(x, y, width, height);
|
|
489
393
|
}
|
|
490
394
|
}
|
|
491
395
|
|
|
@@ -537,52 +441,13 @@ export default class Display {
|
|
|
537
441
|
}
|
|
538
442
|
|
|
539
443
|
_setFillColor(color) {
|
|
540
|
-
const newStyle = 'rgb(' + color[
|
|
444
|
+
const newStyle = 'rgb(' + color[0] + ',' + color[1] + ',' + color[2] + ')';
|
|
541
445
|
if (newStyle !== this._prevDrawStyle) {
|
|
542
446
|
this._drawCtx.fillStyle = newStyle;
|
|
543
447
|
this._prevDrawStyle = newStyle;
|
|
544
448
|
}
|
|
545
449
|
}
|
|
546
450
|
|
|
547
|
-
_rgbImageData(x, y, width, height, arr, offset) {
|
|
548
|
-
const img = this._drawCtx.createImageData(width, height);
|
|
549
|
-
const data = img.data;
|
|
550
|
-
for (let i = 0, j = offset; i < width * height * 4; i += 4, j += 3) {
|
|
551
|
-
data[i] = arr[j];
|
|
552
|
-
data[i + 1] = arr[j + 1];
|
|
553
|
-
data[i + 2] = arr[j + 2];
|
|
554
|
-
data[i + 3] = 255; // Alpha
|
|
555
|
-
}
|
|
556
|
-
this._drawCtx.putImageData(img, x, y);
|
|
557
|
-
this._damage(x, y, img.width, img.height);
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
_bgrxImageData(x, y, width, height, arr, offset) {
|
|
561
|
-
const img = this._drawCtx.createImageData(width, height);
|
|
562
|
-
const data = img.data;
|
|
563
|
-
for (let i = 0, j = offset; i < width * height * 4; i += 4, j += 4) {
|
|
564
|
-
data[i] = arr[j + 2];
|
|
565
|
-
data[i + 1] = arr[j + 1];
|
|
566
|
-
data[i + 2] = arr[j];
|
|
567
|
-
data[i + 3] = 255; // Alpha
|
|
568
|
-
}
|
|
569
|
-
this._drawCtx.putImageData(img, x, y);
|
|
570
|
-
this._damage(x, y, img.width, img.height);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
_rgbxImageData(x, y, width, height, arr, offset) {
|
|
574
|
-
// NB(directxman12): arr must be an Type Array view
|
|
575
|
-
let img;
|
|
576
|
-
if (supportsImageMetadata) {
|
|
577
|
-
img = new ImageData(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4), width, height);
|
|
578
|
-
} else {
|
|
579
|
-
img = this._drawCtx.createImageData(width, height);
|
|
580
|
-
img.data.set(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4));
|
|
581
|
-
}
|
|
582
|
-
this._drawCtx.putImageData(img, x, y);
|
|
583
|
-
this._damage(x, y, img.width, img.height);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
451
|
_renderQPush(action) {
|
|
587
452
|
this._renderQ.push(action);
|
|
588
453
|
if (this._renderQ.length === 1) {
|
|
@@ -616,15 +481,8 @@ export default class Display {
|
|
|
616
481
|
case 'blit':
|
|
617
482
|
this.blitImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
|
618
483
|
break;
|
|
619
|
-
case 'blitRgb':
|
|
620
|
-
this.blitRgbImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
|
621
|
-
break;
|
|
622
|
-
case 'blitRgbx':
|
|
623
|
-
this.blitRgbxImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
|
624
|
-
break;
|
|
625
484
|
case 'img':
|
|
626
|
-
|
|
627
|
-
if (a.img.complete && (a.img.width !== 0) && (a.img.height !== 0)) {
|
|
485
|
+
if (a.img.complete) {
|
|
628
486
|
if (a.img.width !== a.width || a.img.height !== a.height) {
|
|
629
487
|
Log.Error("Decoded image has incorrect dimensions. Got " +
|
|
630
488
|
a.img.width + "x" + a.img.height + ". Expected " +
|