SPB Git forge

spb/admin-ka

Public
41commits 1branches 0releases
172.9 MBsize
maindefault branch
19 days agolast push
JavaScript 65.5% Python 17.8% CSS 13% HTML 3.7%
8.0 KB · 175 lines javascript
Raw Blame History
1"use strict";23Object.defineProperty(exports, "__esModule", {4  value: true5});6exports["default"] = void 0;7function _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); }8function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }9function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }10function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }11function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }12function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }13function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }14function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }15function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }16function _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); } }17function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }18function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }19function _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); }20/*21 * noVNC: HTML5 VNC client22 * Copyright (C) 2019 The noVNC authors23 * Licensed under MPL 2.0 (see LICENSE.txt)24 *25 * See README.md for usage and integration instructions.26 *27 */28var JPEGDecoder = exports["default"] = /*#__PURE__*/function () {29  function JPEGDecoder() {30    _classCallCheck(this, JPEGDecoder);31    // RealVNC will reuse the quantization tables32    // and Huffman tables, so we need to cache them.33    this._cachedQuantTables = [];34    this._cachedHuffmanTables = [];35    this._segments = [];36  }37  return _createClass(JPEGDecoder, [{38    key: "decodeRect",39    value: function decodeRect(x, y, width, height, sock, display, depth) {40      // A rect of JPEG encodings is simply a JPEG file41      while (true) {42        var segment = this._readSegment(sock);43        if (segment === null) {44          return false;45        }46        this._segments.push(segment);47        // End of image?48        if (segment[1] === 0xD9) {49          break;50        }51      }52      var huffmanTables = [];53      var quantTables = [];54      var _iterator = _createForOfIteratorHelper(this._segments),55        _step;56      try {57        for (_iterator.s(); !(_step = _iterator.n()).done;) {58          var _segment = _step.value;59          var type = _segment[1];60          if (type === 0xC4) {61            // Huffman tables62            huffmanTables.push(_segment);63          } else if (type === 0xDB) {64            // Quantization tables65            quantTables.push(_segment);66          }67        }68      } catch (err) {69        _iterator.e(err);70      } finally {71        _iterator.f();72      }73      var sofIndex = this._segments.findIndex(function (x) {74        return x[1] == 0xC0 || x[1] == 0xC2;75      });76      if (sofIndex == -1) {77        throw new Error("Illegal JPEG image without SOF");78      }79      if (quantTables.length === 0) {80        var _this$_segments;81        (_this$_segments = this._segments).splice.apply(_this$_segments, [sofIndex + 1, 0].concat(_toConsumableArray(this._cachedQuantTables)));82      }83      if (huffmanTables.length === 0) {84        var _this$_segments2;85        (_this$_segments2 = this._segments).splice.apply(_this$_segments2, [sofIndex + 1, 0].concat(_toConsumableArray(this._cachedHuffmanTables)));86      }87      var length = 0;88      var _iterator2 = _createForOfIteratorHelper(this._segments),89        _step2;90      try {91        for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {92          var _segment2 = _step2.value;93          length += _segment2.length;94        }95      } catch (err) {96        _iterator2.e(err);97      } finally {98        _iterator2.f();99      }100      var data = new Uint8Array(length);101      length = 0;102      var _iterator3 = _createForOfIteratorHelper(this._segments),103        _step3;104      try {105        for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {106          var _segment3 = _step3.value;107          data.set(_segment3, length);108          length += _segment3.length;109        }110      } catch (err) {111        _iterator3.e(err);112      } finally {113        _iterator3.f();114      }115      display.imageRect(x, y, width, height, "image/jpeg", data);116      if (huffmanTables.length !== 0) {117        this._cachedHuffmanTables = huffmanTables;118      }119      if (quantTables.length !== 0) {120        this._cachedQuantTables = quantTables;121      }122      this._segments = [];123      return true;124    }125  }, {126    key: "_readSegment",127    value: function _readSegment(sock) {128      if (sock.rQwait("JPEG", 2)) {129        return null;130      }131      var marker = sock.rQshift8();132      if (marker != 0xFF) {133        throw new Error("Illegal JPEG marker received (byte: " + marker + ")");134      }135      var type = sock.rQshift8();136      if (type >= 0xD0 && type <= 0xD9 || type == 0x01) {137        // No length after marker138        return new Uint8Array([marker, type]);139      }140      if (sock.rQwait("JPEG", 2, 2)) {141        return null;142      }143      var length = sock.rQshift16();144      if (length < 2) {145        throw new Error("Illegal JPEG length received (length: " + length + ")");146      }147      if (sock.rQwait("JPEG", length - 2, 4)) {148        return null;149      }150      var extra = 0;151      if (type === 0xDA) {152        // start of scan153        extra += 2;154        while (true) {155          if (sock.rQwait("JPEG", length - 2 + extra, 4)) {156            return null;157          }158          var data = sock.rQpeekBytes(length - 2 + extra, false);159          if (data.at(-2) === 0xFF && data.at(-1) !== 0x00 && !(data.at(-1) >= 0xD0 && data.at(-1) <= 0xD7)) {160            extra -= 2;161            break;162          }163          extra++;164        }165      }166      var segment = new Uint8Array(2 + length + extra);167      segment[0] = marker;168      segment[1] = type;169      segment[2] = length >> 8;170      segment[3] = length;171      segment.set(sock.rQshiftBytes(length - 2 + extra, false), 4);172      return segment;173    }174  }]);175}();