]> git.proxmox.com Git - mirror_novnc.git/blob - core/decoders/raw.js
Merge branch 'user_getters_and_setters_in_websock' of https://github.com/juanjoDiaz...
[mirror_novnc.git] / core / decoders / raw.js
1 /*
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2012 Joel Martin
4 * Copyright (C) 2018 Samuel Mannehed for Cendio AB
5 * Copyright (C) 2018 Pierre Ossman for Cendio AB
6 * Licensed under MPL 2.0 (see LICENSE.txt)
7 *
8 * See README.md for usage and integration instructions.
9 *
10 */
11
12 export default class RawDecoder {
13 constructor() {
14 this._lines = 0;
15 }
16
17 decodeRect(x, y, width, height, sock, display, depth) {
18 if (this._lines === 0) {
19 this._lines = height;
20 }
21
22 const pixelSize = depth == 8 ? 1 : 4;
23 const bytesPerLine = width * pixelSize;
24
25 if (sock.rQwait("RAW", bytesPerLine)) {
26 return false;
27 }
28
29 const cur_y = y + (height - this._lines);
30 const curr_height = Math.min(this._lines,
31 Math.floor(sock.rQlen / bytesPerLine));
32 let data = sock.rQ;
33 let index = sock.rQi;
34
35 // Convert data if needed
36 if (depth == 8) {
37 const pixels = width * curr_height;
38 const newdata = new Uint8Array(pixels * 4);
39 for (let i = 0; i < pixels; i++) {
40 newdata[i * 4 + 0] = ((data[index + i] >> 0) & 0x3) * 255 / 3;
41 newdata[i * 4 + 1] = ((data[index + i] >> 2) & 0x3) * 255 / 3;
42 newdata[i * 4 + 2] = ((data[index + i] >> 4) & 0x3) * 255 / 3;
43 newdata[i * 4 + 4] = 0;
44 }
45 data = newdata;
46 index = 0;
47 }
48
49 display.blitImage(x, cur_y, width, curr_height, data, index);
50 sock.rQskipBytes(curr_height * bytesPerLine);
51 this._lines -= curr_height;
52 if (this._lines > 0) {
53 return false;
54 }
55
56 return true;
57 }
58 }