JavaScript 65.5%
Python 17.8%
CSS 13%
HTML 3.7%
1"use strict";23Object.defineProperty(exports, "__esModule", {4 value: true5});6exports["default"] = void 0;7var _inflator = _interopRequireDefault(require("../inflator.js"));8function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }9function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }10function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }11function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }12function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }13function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }14function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*15 * noVNC: HTML5 VNC client16 * Copyright (C) 2021 The noVNC authors17 * Licensed under MPL 2.0 (see LICENSE.txt)18 *19 * See README.md for usage and integration instructions.20 *21 */22var ZRLE_TILE_WIDTH = 64;23var ZRLE_TILE_HEIGHT = 64;24var ZRLEDecoder = exports["default"] = /*#__PURE__*/function () {25 function ZRLEDecoder() {26 _classCallCheck(this, ZRLEDecoder);27 this._length = 0;28 this._inflator = new _inflator["default"]();29 this._pixelBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);30 this._tileBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);31 }32 return _createClass(ZRLEDecoder, [{33 key: "decodeRect",34 value: function decodeRect(x, y, width, height, sock, display, depth) {35 if (this._length === 0) {36 if (sock.rQwait("ZLib data length", 4)) {37 return false;38 }39 this._length = sock.rQshift32();40 }41 if (sock.rQwait("Zlib data", this._length)) {42 return false;43 }44 var data = sock.rQshiftBytes(this._length, false);45 this._inflator.setInput(data);46 for (var ty = y; ty < y + height; ty += ZRLE_TILE_HEIGHT) {47 var th = Math.min(ZRLE_TILE_HEIGHT, y + height - ty);48 for (var tx = x; tx < x + width; tx += ZRLE_TILE_WIDTH) {49 var tw = Math.min(ZRLE_TILE_WIDTH, x + width - tx);50 var tileSize = tw * th;51 var subencoding = this._inflator.inflate(1)[0];52 if (subencoding === 0) {53 // raw data54 var _data = this._readPixels(tileSize);55 display.blitImage(tx, ty, tw, th, _data, 0, false);56 } else if (subencoding === 1) {57 // solid58 var background = this._readPixels(1);59 display.fillRect(tx, ty, tw, th, [background[0], background[1], background[2]]);60 } else if (subencoding >= 2 && subencoding <= 16) {61 var _data2 = this._decodePaletteTile(subencoding, tileSize, tw, th);62 display.blitImage(tx, ty, tw, th, _data2, 0, false);63 } else if (subencoding === 128) {64 var _data3 = this._decodeRLETile(tileSize);65 display.blitImage(tx, ty, tw, th, _data3, 0, false);66 } else if (subencoding >= 130 && subencoding <= 255) {67 var _data4 = this._decodeRLEPaletteTile(subencoding - 128, tileSize);68 display.blitImage(tx, ty, tw, th, _data4, 0, false);69 } else {70 throw new Error('Unknown subencoding: ' + subencoding);71 }72 }73 }74 this._length = 0;75 return true;76 }77 }, {78 key: "_getBitsPerPixelInPalette",79 value: function _getBitsPerPixelInPalette(paletteSize) {80 if (paletteSize <= 2) {81 return 1;82 } else if (paletteSize <= 4) {83 return 2;84 } else if (paletteSize <= 16) {85 return 4;86 }87 }88 }, {89 key: "_readPixels",90 value: function _readPixels(pixels) {91 var data = this._pixelBuffer;92 var buffer = this._inflator.inflate(3 * pixels);93 for (var i = 0, j = 0; i < pixels * 4; i += 4, j += 3) {94 data[i] = buffer[j];95 data[i + 1] = buffer[j + 1];96 data[i + 2] = buffer[j + 2];97 data[i + 3] = 255; // Add the Alpha98 }99 return data;100 }101 }, {102 key: "_decodePaletteTile",103 value: function _decodePaletteTile(paletteSize, tileSize, tilew, tileh) {104 var data = this._tileBuffer;105 var palette = this._readPixels(paletteSize);106 var bitsPerPixel = this._getBitsPerPixelInPalette(paletteSize);107 var mask = (1 << bitsPerPixel) - 1;108 var offset = 0;109 var encoded = this._inflator.inflate(1)[0];110 for (var y = 0; y < tileh; y++) {111 var shift = 8 - bitsPerPixel;112 for (var x = 0; x < tilew; x++) {113 if (shift < 0) {114 shift = 8 - bitsPerPixel;115 encoded = this._inflator.inflate(1)[0];116 }117 var indexInPalette = encoded >> shift & mask;118 data[offset] = palette[indexInPalette * 4];119 data[offset + 1] = palette[indexInPalette * 4 + 1];120 data[offset + 2] = palette[indexInPalette * 4 + 2];121 data[offset + 3] = palette[indexInPalette * 4 + 3];122 offset += 4;123 shift -= bitsPerPixel;124 }125 if (shift < 8 - bitsPerPixel && y < tileh - 1) {126 encoded = this._inflator.inflate(1)[0];127 }128 }129 return data;130 }131 }, {132 key: "_decodeRLETile",133 value: function _decodeRLETile(tileSize) {134 var data = this._tileBuffer;135 var i = 0;136 while (i < tileSize) {137 var pixel = this._readPixels(1);138 var length = this._readRLELength();139 for (var j = 0; j < length; j++) {140 data[i * 4] = pixel[0];141 data[i * 4 + 1] = pixel[1];142 data[i * 4 + 2] = pixel[2];143 data[i * 4 + 3] = pixel[3];144 i++;145 }146 }147 return data;148 }149 }, {150 key: "_decodeRLEPaletteTile",151 value: function _decodeRLEPaletteTile(paletteSize, tileSize) {152 var data = this._tileBuffer;153154 // palette155 var palette = this._readPixels(paletteSize);156 var offset = 0;157 while (offset < tileSize) {158 var indexInPalette = this._inflator.inflate(1)[0];159 var length = 1;160 if (indexInPalette >= 128) {161 indexInPalette -= 128;162 length = this._readRLELength();163 }164 if (indexInPalette > paletteSize) {165 throw new Error('Too big index in palette: ' + indexInPalette + ', palette size: ' + paletteSize);166 }167 if (offset + length > tileSize) {168 throw new Error('Too big rle length in palette mode: ' + length + ', allowed length is: ' + (tileSize - offset));169 }170 for (var j = 0; j < length; j++) {171 data[offset * 4] = palette[indexInPalette * 4];172 data[offset * 4 + 1] = palette[indexInPalette * 4 + 1];173 data[offset * 4 + 2] = palette[indexInPalette * 4 + 2];174 data[offset * 4 + 3] = palette[indexInPalette * 4 + 3];175 offset++;176 }177 }178 return data;179 }180 }, {181 key: "_readRLELength",182 value: function _readRLELength() {183 var length = 0;184 var current = 0;185 do {186 current = this._inflator.inflate(1)[0];187 length += current;188 } while (current === 255);189 return length + 1;190 }191 }]);192}();