Force BGR

This commit is contained in:
f-trycua 2025-04-27 14:59:20 -07:00
parent 82bd567f6d
commit 8d555eb100
2 changed files with 37 additions and 46 deletions

View File

@ -12,25 +12,13 @@ import * as Log from '../util/logging.js';
export default class RawDecoder {
constructor() {
this._lines = 0;
this._serverName = null;
}
decodeRect(x, y, width, height, sock, display, depth, bgrMode = false) {
// Check if we're connecting to a Virtualization server
if (!this._serverName && sock._rfb && sock._rfb._fbName) {
this._serverName = sock._rfb._fbName;
Log.Info("RawDecoder: Connected to server: " + this._serverName);
}
// Special handling for known BGR servers that don't honor pixel format
const forceSwap = this._serverName === 'Virtualization';
// Always log if we're using BGR mode or forcing a swap
// Always log BGR mode to confirm it's being used
if (this._lines === 0) {
Log.Info("RawDecoder: Processing rectangle with " +
(bgrMode ? "BGR" : "RGB") + " mode" +
(forceSwap ? " (FORCING BGR swap for Virtualization server)" : "") +
", depth: " + depth);
(bgrMode ? "BGR" : "RGB") + " mode, depth: " + depth);
}
if ((width === 0) || (height === 0)) {
@ -53,21 +41,6 @@ export default class RawDecoder {
let data = sock.rQshiftBytes(bytesPerLine, false);
// For debugging - show a sample of the data for the first rect
if (this._lines === height && curY === y) {
let sample = "";
for (let i = 0; i < Math.min(16, width); i++) {
if (pixelSize === 4) {
sample += "[" + data[i*4] + "," + data[i*4+1] + "," +
data[i*4+2] + "," + data[i*4+3] + "] ";
} else {
sample += data[i] + " ";
}
}
Log.Info("RawDecoder: First " + Math.min(16, width) +
" pixels (before processing): " + sample);
}
// Convert data if needed
if (depth == 8) {
const newdata = new Uint8Array(width * 4);
@ -78,17 +51,37 @@ export default class RawDecoder {
newdata[i * 4 + 3] = 255;
}
data = newdata;
} else if (bgrMode || forceSwap) {
// In bgrMode or when forced we need to switch the red and blue bytes
// so that the data is in RGB order
Log.Info("RawDecoder: Applying BGR swap for line " + curY +
(forceSwap ? " (FORCED)" : ""));
} else if (bgrMode) {
// Log when we're performing BGR swap
if (curY === y) {
Log.Info("RawDecoder: Applying BGR swap for line " + curY);
// Log sample data before swap
let beforeSample = "";
for (let i = 0; i < Math.min(4, width); i++) {
beforeSample += "[" + data[i*4] + "," + data[i*4+1] + "," +
data[i*4+2] + "] ";
}
Log.Info("Before swap sample: " + beforeSample);
}
// In bgrMode we need to switch the red and blue bytes
for (let i = 0; i < width; i++) {
let j = i * 4;
let red = data[j];
data[j] = data[j + 2];
data[j + 2] = red;
}
// Log sample data after swap for the first line
if (curY === y) {
let afterSample = "";
for (let i = 0; i < Math.min(4, width); i++) {
afterSample += "[" + data[i*4] + "," + data[i*4+1] + "," +
data[i*4+2] + "] ";
}
Log.Info("After swap sample: " + afterSample);
}
} else {
// Make sure the image is fully opaque
for (let i = 0; i < width; i++) {
@ -96,17 +89,6 @@ export default class RawDecoder {
}
}
// For debugging - show processed data for the first rect
if (this._lines === height && curY === y) {
let sample = "";
for (let i = 0; i < Math.min(16, width); i++) {
sample += "[" + data[i*4] + "," + data[i*4+1] + "," +
data[i*4+2] + "," + data[i*4+3] + "] ";
}
Log.Info("RawDecoder: First " + Math.min(16, width) +
" pixels (after processing): " + sample);
}
display.blitImage(x, curY, width, 1, data, 0);
this._lines--;
}

View File

@ -3010,11 +3010,20 @@ export default class RFB extends EventTargetMixin {
return false;
}
// Force BGR mode for specific server types
const forceBGR = this._fbName === "Virtualization" ||
(this._fbName && this._fbName.indexOf("Virtualization") !== -1);
if (forceBGR) {
Log.Info("Forcing BGR mode for Virtualization server");
}
try {
return decoder.decodeRect(this._FBU.x, this._FBU.y,
this._FBU.width, this._FBU.height,
this._sock, this._display,
this._fbDepth, this._BGRmode);
this._fbDepth,
this._BGRmode || forceBGR); // Always enable BGR mode for Virtualization
} catch (err) {
this._fail("Error decoding rect: " + err);
return false;