Merge pull request #1 from codewithnithish/codewithnithish-feature-Support_for_non-standard_vnc_server_version

# Change Log (Step-by-Step)
1) Added support for non-standard server version `003.005` by mapping it to RFB 3.3 in the protocol negotiation switch. File: `core/rfb.js`.
2) Added a warning log when `003.005` is seen so it is clear we are forcing a 3.3 handshake. File: `core/rfb.js`.
3) Stored the server pixel format from ServerInit, and passed it through to decoders so we can decode non-24bpp pixel data safely. File: `core/rfb.js`.
4) Added a compatibility path to force 16bpp and restrict encodings to raw when the server reports non-standard 3.4/3.5. File: `core/rfb.js`.
5) Added 16bpp RAW decoding with proper bit-mask conversion to RGBA (handles 5-5-5 and 5-6-5 formats). File: `core/decoders/raw.js`.
This commit is contained in:
Nithish Anand B 2026-01-08 17:17:37 +05:30 committed by GitHub
commit e6cbc30ba7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3546 additions and 0 deletions

89
raw.js Normal file
View File

@ -0,0 +1,89 @@
/*
* noVNC: HTML5 VNC client
* Copyright (C) 2019 The noVNC authors
* Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
*
*/
export default class RawDecoder {
constructor() {
this._lines = 0;
}
decodeRect(x, y, width, height, sock, display, depth, pixelFormat) {
if ((width === 0) || (height === 0)) {
return true;
}
if (this._lines === 0) {
this._lines = height;
}
const pixelSize = depth == 8 ? 1 : (depth == 16 ? 2 : 4); // Modifications
const bytesPerLine = width * pixelSize;
while (this._lines > 0) {
if (sock.rQwait("RAW", bytesPerLine)) {
return false;
}
const curY = y + (height - this._lines);
let data = sock.rQshiftBytes(bytesPerLine, false);
// Convert data if needed
if (depth == 8) {
const newdata = new Uint8Array(width * 4);
for (let i = 0; i < width; i++) {
newdata[i * 4 + 0] = ((data[i] >> 0) & 0x3) * 255 / 3;
newdata[i * 4 + 1] = ((data[i] >> 2) & 0x3) * 255 / 3;
newdata[i * 4 + 2] = ((data[i] >> 4) & 0x3) * 255 / 3;
newdata[i * 4 + 3] = 255;
}
data = newdata;
} else if (depth == 16) { // Modifications: decode 16bpp raw
const fmt = pixelFormat || {};
const redMax = fmt.redMax !== undefined ? fmt.redMax : 31;
const greenMax = fmt.greenMax !== undefined ? fmt.greenMax : 63;
const blueMax = fmt.blueMax !== undefined ? fmt.blueMax : 31;
const redShift = fmt.redShift !== undefined ? fmt.redShift : 11;
const greenShift = fmt.greenShift !== undefined ? fmt.greenShift : 5;
const blueShift = fmt.blueShift !== undefined ? fmt.blueShift : 0;
const bigEndian = !!fmt.bigEndian;
const newdata = new Uint8Array(width * 4);
for (let i = 0; i < width; i++) {
const idx = i * 2;
let pixel;
if (bigEndian) {
pixel = (data[idx] << 8) | data[idx + 1];
} else {
pixel = data[idx] | (data[idx + 1] << 8);
}
const r = (pixel >> redShift) & redMax;
const g = (pixel >> greenShift) & greenMax;
const b = (pixel >> blueShift) & blueMax;
newdata[i * 4 + 0] = redMax ? (r * 255 / redMax) : 0;
newdata[i * 4 + 1] = greenMax ? (g * 255 / greenMax) : 0;
newdata[i * 4 + 2] = blueMax ? (b * 255 / blueMax) : 0;
newdata[i * 4 + 3] = 255;
}
data = newdata;
}
// Max sure the image is fully opaque
for (let i = 0; i < width; i++) {
data[i * 4 + 3] = 255;
}
display.blitImage(x, curY, width, 1, data, 0);
this._lines--;
}
return true;
}
}

3457
rfb.js Normal file

File diff suppressed because it is too large Load Diff