]>
git.proxmox.com Git - mirror_novnc.git/blob - core/decoders/hextile.js
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2019 The noVNC Authors
4 * Licensed under MPL 2.0 (see LICENSE.txt)
6 * See README.md for usage and integration instructions.
10 import * as Log
from '../util/logging.js';
12 export default class HextileDecoder
{
15 this._lastsubencoding
= 0;
18 decodeRect(x
, y
, width
, height
, sock
, display
, depth
) {
19 if (this._tiles
=== 0) {
20 this._tilesX
= Math
.ceil(width
/ 16);
21 this._tilesY
= Math
.ceil(height
/ 16);
22 this._totalTiles
= this._tilesX
* this._tilesY
;
23 this._tiles
= this._totalTiles
;
26 while (this._tiles
> 0) {
29 if (sock
.rQwait("HEXTILE", bytes
)) {
36 let subencoding
= rQ
[rQi
]; // Peek
37 if (subencoding
> 30) { // Raw
38 throw new Error("Illegal hextile subencoding (subencoding: " +
42 const currTile
= this._totalTiles
- this._tiles
;
43 const tileX
= currTile
% this._tilesX
;
44 const tileY
= Math
.floor(currTile
/ this._tilesX
);
45 const tx
= x
+ tileX
* 16;
46 const ty
= y
+ tileY
* 16;
47 const tw
= Math
.min(16, (x
+ width
) - tx
);
48 const th
= Math
.min(16, (y
+ height
) - ty
);
50 // Figure out how much we are expecting
51 if (subencoding
& 0x01) { // Raw
54 if (subencoding
& 0x02) { // Background
57 if (subencoding
& 0x04) { // Foreground
60 if (subencoding
& 0x08) { // AnySubrects
61 bytes
++; // Since we aren't shifting it off
63 if (sock
.rQwait("HEXTILE", bytes
)) {
67 let subrects
= rQ
[rQi
+ bytes
- 1]; // Peek
68 if (subencoding
& 0x10) { // SubrectsColoured
69 bytes
+= subrects
* (4 + 2);
71 bytes
+= subrects
* 2;
76 if (sock
.rQwait("HEXTILE", bytes
)) {
80 // We know the encoding and have a whole tile
82 if (subencoding
=== 0) {
83 if (this._lastsubencoding
& 0x01) {
84 // Weird: ignore blanks are RAW
85 Log
.Debug(" Ignoring blank after RAW");
87 display
.fillRect(tx
, ty
, tw
, th
, this._background
);
89 } else if (subencoding
& 0x01) { // Raw
90 display
.blitImage(tx
, ty
, tw
, th
, rQ
, rQi
);
93 if (subencoding
& 0x02) { // Background
94 this._background
= [rQ
[rQi
], rQ
[rQi
+ 1], rQ
[rQi
+ 2], rQ
[rQi
+ 3]];
97 if (subencoding
& 0x04) { // Foreground
98 this._foreground
= [rQ
[rQi
], rQ
[rQi
+ 1], rQ
[rQi
+ 2], rQ
[rQi
+ 3]];
102 display
.startTile(tx
, ty
, tw
, th
, this._background
);
103 if (subencoding
& 0x08) { // AnySubrects
104 let subrects
= rQ
[rQi
];
107 for (let s
= 0; s
< subrects
; s
++) {
109 if (subencoding
& 0x10) { // SubrectsColoured
110 color
= [rQ
[rQi
], rQ
[rQi
+ 1], rQ
[rQi
+ 2], rQ
[rQi
+ 3]];
113 color
= this._foreground
;
117 const sx
= (xy
>> 4);
118 const sy
= (xy
& 0x0f);
122 const sw
= (wh
>> 4) + 1;
123 const sh
= (wh
& 0x0f) + 1;
125 display
.subTile(sx
, sy
, sw
, sh
, color
);
128 display
.finishTile();
131 this._lastsubencoding
= subencoding
;