diff options
Diffstat (limited to 'webclients/novnc/include/display.js')
-rw-r--r-- | webclients/novnc/include/display.js | 85 |
1 files changed, 57 insertions, 28 deletions
diff --git a/webclients/novnc/include/display.js b/webclients/novnc/include/display.js index 2cf262d..f2ecdba 100644 --- a/webclients/novnc/include/display.js +++ b/webclients/novnc/include/display.js @@ -20,7 +20,7 @@ var that = {}, // Public API methods c_forceCanvas = false, // Predefine function variables (jslint) - imageDataGet, rgbxImageData, cmapImageData, + imageDataGet, rgbImageData, 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; @@ -386,10 +386,10 @@ that.getCleanDirtyReset = function() { // Translate viewport coordinates to absolute coordinates that.absX = function(x) { return x + viewport.x; -} +}; that.absY = function(y) { return y + viewport.y; -} +}; that.resize = function(width, height) { @@ -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) { @@ -492,12 +492,12 @@ that.subTile = function(x, y, w, h, color) { // Draw the current tile to the screen that.finishTile = function() { if (conf.prefer_js) { - c_ctx.putImageData(tile, tile_x - viewport.x, tile_y - viewport.y) + c_ctx.putImageData(tile, tile_x - viewport.x, tile_y - viewport.y); } // else: No-op, if not prefer_js then already done by setSubTile }; -rgbxImageData = function(x, y, width, height, arr, offset) { +rgbImageData = 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) || @@ -508,7 +508,7 @@ 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) { + for (i=0, j=offset; i < (width * height * 4); i=i+4, j=j+3) { data[i ] = arr[j ]; data[i + 1] = arr[j + 1]; data[i + 2] = arr[j + 2]; @@ -517,16 +517,36 @@ rgbxImageData = function(x, y, width, height, arr, offset) { c_ctx.putImageData(img, x - v.x, y - v.y); }; +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) || + (x - v.x + width < 0) || (y - v.y + height < 0)) { + // Skipping because outside of viewport + return; + } + */ + 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 + 2]; + data[i + 1] = arr[j + 1]; + 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,8 +554,17 @@ 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); + } +}; + +that.blitRgbImage = function(x, y, width, height, arr, offset) { + if (conf.true_color) { + rgbImageData(x, y, width, height, arr, offset); } else { + // prolly wrong... cmapImageData(x, y, width, height, arr, offset); } }; |