Skip to content

Commit

Permalink
Support 16 bit hextile
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Liu <[email protected]>
  • Loading branch information
maxdog988 committed Mar 29, 2022
1 parent 9142f8f commit f7d03e4
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 23 deletions.
34 changes: 24 additions & 10 deletions core/decoders/hextile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export default class HextileDecoder {

let rQ = sock.rQ;
let rQi = sock.rQi;
var hbyte = 4;

if (depth == 16)
hbyte = 2;

let subencoding = rQ[rQi]; // Peek
if (subencoding > 30) { // Raw
Expand All @@ -49,13 +53,13 @@ export default class HextileDecoder {

// Figure out how much we are expecting
if (subencoding & 0x01) { // Raw
bytes += tw * th * 4;
bytes += tw * th * hbyte;
} else {
if (subencoding & 0x02) { // Background
bytes += 4;
bytes += hbyte;
}
if (subencoding & 0x04) { // Foreground
bytes += 4;
bytes += hbyte;
}
if (subencoding & 0x08) { // AnySubrects
bytes++; // Since we aren't shifting it off
Expand All @@ -66,7 +70,7 @@ export default class HextileDecoder {

let subrects = rQ[rQi + bytes - 1]; // Peek
if (subencoding & 0x10) { // SubrectsColoured
bytes += subrects * (4 + 2);
bytes += subrects * (hbyte + 2);
} else {
bytes += subrects * 2;
}
Expand All @@ -91,12 +95,18 @@ export default class HextileDecoder {
rQi += bytes - 1;
} else {
if (subencoding & 0x02) { // Background
this._background = [rQ[rQi], rQ[rQi + 1], rQ[rQi + 2], rQ[rQi + 3]];
rQi += 4;
if (depth == 16)
this._background = [rQ[rQi], rQ[rQi + 1]];
else
this._background = [rQ[rQi], rQ[rQi + 1], rQ[rQi + 2], rQ[rQi + 3]];
rQi += hbyte;
}
if (subencoding & 0x04) { // Foreground
this._foreground = [rQ[rQi], rQ[rQi + 1], rQ[rQi + 2], rQ[rQi + 3]];
rQi += 4;
if (depth == 16)
this._foreground = [rQ[rQi], rQ[rQi + 1]];
else
this._foreground = [rQ[rQi], rQ[rQi + 1], rQ[rQi + 2], rQ[rQi + 3]];
rQi += hbyte;
}

display.startTile(tx, ty, tw, th, this._background);
Expand All @@ -107,8 +117,12 @@ export default class HextileDecoder {
for (let s = 0; s < subrects; s++) {
let color;
if (subencoding & 0x10) { // SubrectsColoured
color = [rQ[rQi], rQ[rQi + 1], rQ[rQi + 2], rQ[rQi + 3]];
rQi += 4;
if (depth == 16)
color = [rQ[rQi], rQ[rQi + 1]];
else
color = [rQ[rQi], rQ[rQi + 1], rQ[rQi + 2], rQ[rQi + 3]];

rQi += hbyte;
} else {
color = this._foreground;
}
Expand Down
69 changes: 57 additions & 12 deletions core/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default class Display {

// ===== PROPERTIES =====

this._fb_depth = 24;
this._scale = 1.0;
this._clipViewport = false;

Expand Down Expand Up @@ -388,9 +389,18 @@ export default class Display {
this._tile = this._drawCtx.createImageData(width, height);
}

const red = color[2];
const green = color[1];
const blue = color[0];
var red, green, blue;

if (this._fb_depth == 16) {
var rgb16 = color[0] + (color[1] << 8);
red = (rgb16 & 0xf800) >> 8;
green = (rgb16 & 0x07e0) >> 3;
blue = (rgb16 & 0x001f) << 3;
} else {
red = color[2];
green = color[1];
blue = color[0];
}

const data = this._tile.data;
for (let i = 0; i < width * height * 4; i += 4) {
Expand All @@ -403,9 +413,19 @@ export default class Display {

// update sub-rectangle of the current tile
subTile(x, y, w, h, color) {
const red = color[2];
const green = color[1];
const blue = color[0];
var red, green, blue;

if (this._fb_depth == 16) {
var rgb16 = color[0] + (color[1] << 8);
red = (rgb16 & 0xf800) >> 8;
green = (rgb16 & 0x07e0) >> 3;
blue = (rgb16 & 0x001f) << 3;
} else {
red = color[2];
green = color[1];
blue = color[0];
}

const xend = x + w;
const yend = y + h;

Expand Down Expand Up @@ -537,7 +557,20 @@ export default class Display {
}

_setFillColor(color) {
const newStyle = 'rgb(' + color[2] + ',' + color[1] + ',' + color[0] + ')';
var red, green, blue;

if (this._fb_depth == 16) {
var rgb16 = color[0] + (color[1] << 8);
red = (rgb16 & 0xf800) >> 8;
green = (rgb16 & 0x07e0) >> 3;
blue = (rgb16 & 0x001f) << 3;
} else {
red = color[2];
green = color[1];
blue = color[0];
}

var newStyle = 'rgb(' + red + ',' + green + ',' + blue + ')';
if (newStyle !== this._prevDrawStyle) {
this._drawCtx.fillStyle = newStyle;
this._prevDrawStyle = newStyle;
Expand All @@ -560,11 +593,23 @@ export default class Display {
_bgrxImageData(x, y, width, height, arr, offset) {
const img = this._drawCtx.createImageData(width, height);
const data = img.data;
for (let i = 0, j = offset; i < width * height * 4; i += 4, j += 4) {
data[i] = arr[j + 2];
data[i + 1] = arr[j + 1];
data[i + 2] = arr[j];
data[i + 3] = 255; // Alpha

if (this._fb_depth == 16) {
for (var i = 0, j = offset; i < width * height * 4; i += 4, j += 2) {
var rgb16 = arr[j] + (arr[j + 1] << 8);

data[i] = (rgb16 & 0xf800) >> 8;
data[i + 1] = (rgb16 & 0x07e0) >> 3;
data[i + 2] = (rgb16 & 0x001f) << 3;
data[i + 3] = 255; // Alpha
}
} else {
for (var i = 0, j = offset; i < width * height * 4; i += 4, j += 4) {
data[i] = arr[j + 2];
data[i + 1] = arr[j + 1];
data[i + 2] = arr[j];
data[i + 3] = 255; // Alpha
}
}
this._drawCtx.putImageData(img, x, y);
this._damage(x, y, img.width, img.height);
Expand Down
17 changes: 16 additions & 1 deletion core/rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,13 @@ export default class RFB extends EventTargetMixin {
this._fbDepth = 8;
}

if (this._fbName === "OpenBMC IKVM" || this._fbName === "obmc iKVM") {
Log.Warn("npcm7xx hextile only supports 16 bit depths. Using low color mode.");
this._fbDepth = 16;
}

this._display._fb_depth = this._fbDepth;

RFB.messages.pixelFormat(this._sock, this._fbDepth, true);
this._sendEncodings();
RFB.messages.fbUpdateRequest(this._sock, false, 0, 0, this._fbWidth, this._fbHeight);
Expand All @@ -1757,9 +1764,12 @@ export default class RFB extends EventTargetMixin {
if (this._fbDepth == 24) {
encs.push(encodings.encodingTight);
encs.push(encodings.encodingTightPNG);
encs.push(encodings.encodingHextile);
encs.push(encodings.encodingRRE);
}

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

encs.push(encodings.encodingRaw);

// Psuedo-encoding settings
Expand Down Expand Up @@ -2878,11 +2888,16 @@ RFB.messages = {

buff[offset + 10] = 0; // green-max
buff[offset + 11] = (1 << bits) - 1; // green-max
if (depth == 16)
buff[offset + 11] = (1 << (bits + 1)) - 1; // green-max

buff[offset + 12] = 0; // blue-max
buff[offset + 13] = (1 << bits) - 1; // blue-max

buff[offset + 14] = bits * 2; // red-shift
if (depth == 16)
buff[offset + 14] = bits * 2 + 1; // red-shift

buff[offset + 15] = bits * 1; // green-shift
buff[offset + 16] = bits * 0; // blue-shift

Expand Down

0 comments on commit f7d03e4

Please sign in to comment.