main
1/*
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2024 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
10import Inflator from "../inflator.js";
11
12export default class ZlibDecoder {
13 constructor() {
14 this._zlib = new Inflator();
15 this._length = 0;
16 }
17
18 decodeRect(x, y, width, height, sock, display, depth) {
19 if ((width === 0) || (height === 0)) {
20 return true;
21 }
22
23 if (this._length === 0) {
24 if (sock.rQwait("ZLIB", 4)) {
25 return false;
26 }
27
28 this._length = sock.rQshift32();
29 }
30
31 if (sock.rQwait("ZLIB", this._length)) {
32 return false;
33 }
34
35 let data = new Uint8Array(sock.rQshiftBytes(this._length, false));
36 this._length = 0;
37
38 this._zlib.setInput(data);
39 data = this._zlib.inflate(width * height * 4);
40 this._zlib.setInput(null);
41
42 // Max sure the image is fully opaque
43 for (let i = 0; i < width * height; i++) {
44 data[i * 4 + 3] = 255;
45 }
46
47 display.blitImage(x, y, width, height, data, 0);
48
49 return true;
50 }
51}