diff --git a/include/display.js b/include/display.js index 07fdcc7e..bfc9776c 100644 --- a/include/display.js +++ b/include/display.js @@ -20,7 +20,7 @@ var that = {}, // Public API methods c_forceCanvas = false, // Predefine function variables (jslint) - imageDataGet, rgbxImageData, cmapImageData, + imageDataGet, bgrxImageData, cmapImageData, setFillColor, rescale, // The full frame buffer (logical canvas) size @@ -183,13 +183,13 @@ rescale = function(factor) { }; setFillColor = function(color) { - var rgb, newStyle; + var bgr, newStyle; if (conf.true_color) { - rgb = color; + bgr = color; } else { - rgb = conf.colourMap[color[0]]; + bgr = conf.colourMap[color[0]]; } - newStyle = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")"; + newStyle = "rgb(" + bgr[2] + "," + bgr[1] + "," + bgr[0] + ")"; if (newStyle !== c_prevStyle) { c_ctx.fillStyle = newStyle; c_prevStyle = newStyle; @@ -430,7 +430,7 @@ that.copyImage = function(old_x, old_y, new_x, new_y, w, h) { // Start updating a tile that.startTile = function(x, y, width, height, color) { - var data, rgb, red, green, blue, i; + var data, bgr, red, green, blue, i; tile_x = x; tile_y = y; if ((width === 16) && (height === 16)) { @@ -441,13 +441,13 @@ that.startTile = function(x, y, width, height, color) { data = tile.data; if (conf.prefer_js) { if (conf.true_color) { - rgb = color; + bgr = color; } else { - rgb = conf.colourMap[color[0]]; + bgr = conf.colourMap[color[0]]; } - red = rgb[0]; - green = rgb[1]; - blue = rgb[2]; + red = bgr[2]; + green = bgr[1]; + blue = bgr[0]; for (i = 0; i < (width * height * 4); i+=4) { data[i ] = red; data[i + 1] = green; @@ -461,18 +461,18 @@ that.startTile = function(x, y, width, height, color) { // Update sub-rectangle of the current tile that.subTile = function(x, y, w, h, color) { - var data, p, rgb, red, green, blue, width, j, i, xend, yend; + var data, p, bgr, red, green, blue, width, j, i, xend, yend; if (conf.prefer_js) { data = tile.data; width = tile.width; if (conf.true_color) { - rgb = color; + bgr = color; } else { - rgb = conf.colourMap[color[0]]; + bgr = conf.colourMap[color[0]]; } - red = rgb[0]; - green = rgb[1]; - blue = rgb[2]; + red = bgr[2]; + green = bgr[1]; + blue = bgr[0]; xend = x + w; yend = y + h; for (j = y; j < yend; j += 1) { @@ -497,7 +497,7 @@ that.finishTile = function() { // else: No-op, if not prefer_js then already done by setSubTile }; -rgbxImageData = function(x, y, width, height, arr, offset) { +bgrxImageData = function(x, y, width, height, arr, offset) { var img, i, j, data, v = viewport; /* if ((x - v.x >= v.w) || (y - v.y >= v.h) || @@ -509,24 +509,24 @@ rgbxImageData = function(x, y, width, height, arr, offset) { img = c_ctx.createImageData(width, height); data = img.data; for (i=0, j=offset; i < (width * height * 4); i=i+4, j=j+4) { - data[i ] = arr[j ]; + data[i ] = arr[j + 2]; data[i + 1] = arr[j + 1]; - data[i + 2] = arr[j + 2]; + data[i + 2] = arr[j ]; data[i + 3] = 255; // Set Alpha } c_ctx.putImageData(img, x - v.x, y - v.y); }; cmapImageData = function(x, y, width, height, arr, offset) { - var img, i, j, data, rgb, cmap; + var img, i, j, data, bgr, cmap; img = c_ctx.createImageData(width, height); data = img.data; cmap = conf.colourMap; for (i=0, j=offset; i < (width * height * 4); i+=4, j+=1) { - rgb = cmap[arr[j]]; - data[i ] = rgb[0]; - data[i + 1] = rgb[1]; - data[i + 2] = rgb[2]; + bgr = cmap[arr[j]]; + data[i ] = bgr[2]; + data[i + 1] = bgr[1]; + data[i + 2] = bgr[0]; data[i + 3] = 255; // Set Alpha } c_ctx.putImageData(img, x - viewport.x, y - viewport.y); @@ -534,7 +534,7 @@ cmapImageData = function(x, y, width, height, arr, offset) { that.blitImage = function(x, y, width, height, arr, offset) { if (conf.true_color) { - rgbxImageData(x, y, width, height, arr, offset); + bgrxImageData(x, y, width, height, arr, offset); } else { cmapImageData(x, y, width, height, arr, offset); } diff --git a/include/rfb.js b/include/rfb.js index f2e24c28..13fdd0a6 100644 --- a/include/rfb.js +++ b/include/rfb.js @@ -819,6 +819,16 @@ init_msg = function() { ", green_shift: " + green_shift + ", blue_shift: " + blue_shift); + if (big_endian !== 0) { + Util.Warn("Server native endian is not little endian"); + } + if (red_shift !== 16) { + Util.Warn("Server native red-shift is not 16"); + } + if (blue_shift !== 0) { + Util.Warn("Server native blue-shift is not 0"); + } + /* Connection name/title */ name_length = ws.rQshift32(); fb_name = ws.rQshiftStr(name_length); @@ -893,7 +903,7 @@ normal_msg = function() { //Util.Debug("red after: " + red); green = parseInt(ws.rQshift16() / 256, 10); blue = parseInt(ws.rQshift16() / 256, 10); - display.set_colourMap([red, green, blue], first_colour + c); + display.set_colourMap([blue, green, red], first_colour + c); } Util.Debug("colourMap: " + display.get_colourMap()); Util.Info("Registered " + num_colours + " colourMap entries"); @@ -1429,9 +1439,9 @@ pixelFormat = function() { arr.push16(255); // red-max arr.push16(255); // green-max arr.push16(255); // blue-max - arr.push8(0); // red-shift + arr.push8(16); // red-shift arr.push8(8); // green-shift - arr.push8(16); // blue-shift + arr.push8(0); // blue-shift arr.push8(0); // padding arr.push8(0); // padding diff --git a/tests/canvas.html b/tests/canvas.html index b66d214f..010e8f35 100644 --- a/tests/canvas.html +++ b/tests/canvas.html @@ -9,7 +9,7 @@ - +
@@ -36,7 +36,7 @@