Skip to content

Commit

Permalink
Support depth 16 pseudoEncodingCursor
Browse files Browse the repository at this point in the history
Signed-off-by: Marvin Lin <milkfafa@gmail.com>
  • Loading branch information
linkunfa authored and maxdog988 committed May 15, 2024
1 parent f619657 commit c83563a
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions core/rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,7 @@ export default class RFB extends EventTargetMixin {

if (this._fbDepth >= 16) {
encs.push(encodings.encodingHextile);
encs.push(encodings.pseudoEncodingCursor);
}

encs.push(encodings.encodingRaw);
Expand All @@ -2176,7 +2177,6 @@ export default class RFB extends EventTargetMixin {

if (this._fbDepth == 24) {
encs.push(encodings.pseudoEncodingVMwareCursor);
encs.push(encodings.pseudoEncodingCursor);
}

RFB.messages.clientEncodings(this._sock, encs);
Expand Down Expand Up @@ -2723,13 +2723,32 @@ export default class RFB extends EventTargetMixin {
return true;
}

// extract color components of rgb565
_extractRgb565(color) {
let rgb565 = color[0] + (color[1] << 8);
let red, green, blue;

red = (rgb565 & 0xf800) >> 8;
green = (rgb565 & 0x07e0) >> 3;
blue = (rgb565 & 0x001f) << 3;

return [red, green, blue];
}

_handleCursor() {
const hotx = this._FBU.x; // hotspot-x
const hoty = this._FBU.y; // hotspot-y
const w = this._FBU.width;
const h = this._FBU.height;
var bytesPerPix;

if (this._fbDepth == 16) {
bytesPerPix = 2;
} else {
bytesPerPix = 4;
}

const pixelslength = w * h * 4;
const pixelslength = w * h * bytesPerPix;
const masklength = Math.ceil(w / 8) * h;

let bytes = pixelslength + masklength;
Expand All @@ -2743,14 +2762,27 @@ export default class RFB extends EventTargetMixin {
let rgba = new Uint8Array(w * h * 4);

let pixIdx = 0;
let dep16Idx = 0;

for (let y = 0; y < h; y++) {
for (let x = 0; x < w; x++) {
let maskIdx = y * Math.ceil(w / 8) + Math.floor(x / 8);
let alpha = (mask[maskIdx] << (x % 8)) & 0x80 ? 255 : 0;
rgba[pixIdx ] = pixels[pixIdx + 2];
rgba[pixIdx + 1] = pixels[pixIdx + 1];
rgba[pixIdx + 2] = pixels[pixIdx];
rgba[pixIdx + 3] = alpha;

if (this._fbDepth == 16) {
let color = this._extractRgb565([pixels[dep16Idx], pixels[dep16Idx + 1]]);
rgba[pixIdx ] = color[0];
rgba[pixIdx + 1] = color[1];
rgba[pixIdx + 2] = color[2];
rgba[pixIdx + 3] = alpha;

dep16Idx += 2;
} else {
rgba[pixIdx ] = pixels[pixIdx + 2];
rgba[pixIdx + 1] = pixels[pixIdx + 1];
rgba[pixIdx + 2] = pixels[pixIdx];
rgba[pixIdx + 3] = alpha;
}
pixIdx += 4;
}
}
Expand Down

0 comments on commit c83563a

Please sign in to comment.