UNPKG

@abasb75/jpeg-lossless-decoder

Version:
91 lines (90 loc) 2.92 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { ComponentSpec } from './component-spec'; var FrameHeader = /** @class */ (function () { function FrameHeader() { Object.defineProperty(this, "dimX", { enumerable: true, configurable: true, writable: true, value: 0 }); Object.defineProperty(this, "dimY", { enumerable: true, configurable: true, writable: true, value: 0 }); Object.defineProperty(this, "numComp", { enumerable: true, configurable: true, writable: true, value: 0 }); Object.defineProperty(this, "precision", { enumerable: true, configurable: true, writable: true, value: 0 }); Object.defineProperty(this, "components", { enumerable: true, configurable: true, writable: true, value: [] }); } Object.defineProperty(FrameHeader.prototype, "read", { enumerable: false, configurable: true, writable: true, value: function (data) { var count = 0; var temp; var length = data.get16(); count += 2; this.precision = data.get8(); count += 1; this.dimY = data.get16(); count += 2; this.dimX = data.get16(); count += 2; this.numComp = data.get8(); count += 1; for (var i = 1; i <= this.numComp; i += 1) { if (count > length) { throw new Error('ERROR: frame format error'); } var c = data.get8(); count += 1; if (count >= length) { throw new Error('ERROR: frame format error [c>=Lf]'); } temp = data.get8(); count += 1; if (!this.components[c]) { this.components[c] = __assign({}, ComponentSpec); } this.components[c].hSamp = temp >> 4; this.components[c].vSamp = temp & 0x0f; this.components[c].quantTableSel = data.get8(); count += 1; } if (count !== length) { throw new Error('ERROR: frame format error [Lf!=count]'); } return 1; } }); return FrameHeader; }()); export { FrameHeader };