x_ite 8.7.0 → 8.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/Makefile +4 -1
  2. package/build/bin/bump.pl +16 -0
  3. package/build/bin/version.pl +20 -17
  4. package/dist/assets/components/Annotation.js +13 -13
  5. package/dist/assets/components/Annotation.min.js +1 -1
  6. package/dist/assets/components/CADGeometry.js +13 -13
  7. package/dist/assets/components/CADGeometry.min.js +1 -1
  8. package/dist/assets/components/CubeMapTexturing.js +25 -25
  9. package/dist/assets/components/CubeMapTexturing.min.js +1 -1
  10. package/dist/assets/components/DIS.js +13 -13
  11. package/dist/assets/components/DIS.min.js +1 -1
  12. package/dist/assets/components/EventUtilities.js +9 -9
  13. package/dist/assets/components/EventUtilities.min.js +1 -1
  14. package/dist/assets/components/Geometry2D.js +19 -19
  15. package/dist/assets/components/Geometry2D.min.js +1 -1
  16. package/dist/assets/components/Geospatial.js +33 -33
  17. package/dist/assets/components/Geospatial.min.js +1 -1
  18. package/dist/assets/components/HAnim.js +18 -18
  19. package/dist/assets/components/HAnim.min.js +1 -1
  20. package/dist/assets/components/KeyDeviceSensor.js +8 -8
  21. package/dist/assets/components/KeyDeviceSensor.min.js +1 -1
  22. package/dist/assets/components/Layout.js +27 -27
  23. package/dist/assets/components/Layout.min.js +1 -1
  24. package/dist/assets/components/NURBS.js +24 -24
  25. package/dist/assets/components/NURBS.min.js +1 -1
  26. package/dist/assets/components/ParticleSystems.js +22 -22
  27. package/dist/assets/components/ParticleSystems.min.js +1 -1
  28. package/dist/assets/components/Picking.js +18 -18
  29. package/dist/assets/components/Picking.min.js +1 -1
  30. package/dist/assets/components/RigidBodyPhysics.js +18 -18
  31. package/dist/assets/components/RigidBodyPhysics.min.js +1 -1
  32. package/dist/assets/components/Scripting.js +28 -28
  33. package/dist/assets/components/Scripting.min.js +1 -1
  34. package/dist/assets/components/Text.js +24 -24
  35. package/dist/assets/components/Text.min.js +1 -1
  36. package/dist/assets/components/TextureProjector.js +14 -14
  37. package/dist/assets/components/TextureProjector.min.js +1 -1
  38. package/dist/assets/components/Texturing3D.js +1694 -1125
  39. package/dist/assets/components/Texturing3D.min.js +1 -1
  40. package/dist/assets/components/VolumeRendering.js +19 -19
  41. package/dist/assets/components/VolumeRendering.min.js +1 -1
  42. package/dist/assets/components/X_ITE.js +9 -9
  43. package/dist/assets/components/X_ITE.min.js +1 -1
  44. package/dist/x_ite.css +1 -1
  45. package/dist/x_ite.js +87 -83
  46. package/dist/x_ite.min.js +1 -1
  47. package/dist/x_ite.zip +0 -0
  48. package/docs/_config.yml +1 -1
  49. package/package.json +2 -2
  50. package/src/assets/shaders/webgl1/include/Fragment.glsl.js +4 -2
  51. package/src/assets/shaders/webgl2/include/Fragment.glsl.js +4 -2
  52. package/src/x_ite/Browser/Legacy.js +1 -1
  53. package/src/x_ite/Browser/VERSION.js +1 -1
  54. package/src/x_ite/Components/Shape/Material.js +10 -10
  55. package/src/x_ite/Components/Shape/PhysicalMaterial.js +6 -6
  56. package/src/x_ite/Components/Shape/X3DMaterialNode.js +1 -1
  57. package/src/x_ite/Components/Shape/X3DOneSidedMaterialNode.js +4 -4
@@ -1,22 +1,7 @@
1
- /* X_ITE v8.7.0 */(() => { // webpackBootstrap
1
+ /* X_ITE v8.7.2 */(() => { // webpackBootstrap
2
2
  /******/ var __webpack_modules__ = ({
3
3
 
4
- /***/ 460:
5
- /***/ ((module) => {
6
-
7
- function webpackEmptyContext(req) {
8
- var e = new Error("Cannot find module '" + req + "'");
9
- e.code = 'MODULE_NOT_FOUND';
10
- throw e;
11
- }
12
- webpackEmptyContext.keys = () => ([]);
13
- webpackEmptyContext.resolve = webpackEmptyContext;
14
- webpackEmptyContext.id = 460;
15
- module.exports = webpackEmptyContext;
16
-
17
- /***/ }),
18
-
19
- /***/ 990:
4
+ /***/ 639:
20
5
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
21
6
 
22
7
  var __dirname = "/";
@@ -53,7 +38,7 @@ var Ib=[cx,_q,cr,Yr,as,fs,hs,Hu,Su,cx,cx,cx,cx,cx,cx,cx];var Jb=[dx,si,gi,Wh,Kh,
53
38
 
54
39
  /***/ }),
55
40
 
56
- /***/ 881:
41
+ /***/ 457:
57
42
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
58
43
 
59
44
  var __dirname = "/";
@@ -87,7 +72,7 @@ var _a=[yj,od,ef,yj];var $a=[zj,Li,di,bi,Kb,Lb,Mb,Nb,Rc,Sc,Uc,jd,xd,Ye,lf,yd,zd,
87
72
 
88
73
  /***/ }),
89
74
 
90
- /***/ 615:
75
+ /***/ 554:
91
76
  /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
92
77
 
93
78
  /*! dicom-parser - 1.8.12 - 2023-02-20 | (c) 2017 Chris Hafey | https://github.com/cornerstonejs/dicomParser */
@@ -4043,7 +4028,7 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_zlib__;
4043
4028
 
4044
4029
  /***/ }),
4045
4030
 
4046
- /***/ 622:
4031
+ /***/ 90:
4047
4032
  /***/ ((module) => {
4048
4033
 
4049
4034
  /* -*- tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
@@ -5198,1183 +5183,1767 @@ function decode(jpegData, userOpts = {}) {
5198
5183
 
5199
5184
  /***/ }),
5200
5185
 
5201
- /***/ 782:
5202
- /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
5186
+ /***/ 210:
5187
+ /***/ ((module) => {
5188
+
5189
+ (function(f){if(true){module.exports=f()}else { var g; }})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=undefined;if(!u&&a)return require(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=undefined;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
5190
+ /*
5191
+ * Copyright (C) 2015 Michael Martinez
5192
+ * Changes: Added support for selection values 2-7, fixed minor bugs &
5193
+ * warnings, split into multiple class files, and general clean up.
5194
+ *
5195
+ * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
5196
+ */
5197
+
5198
+ /*
5199
+ * Copyright (C) Helmut Dersch
5200
+ *
5201
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5202
+ * of this software and associated documentation files (the "Software"), to deal
5203
+ * in the Software without restriction, including without limitation the rights
5204
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5205
+ * copies of the Software, and to permit persons to whom the Software is
5206
+ * furnished to do so, subject to the following conditions:
5207
+
5208
+ * The above copyright notice and this permission notice shall be included in
5209
+ * all copies or substantial portions of the Software.
5210
+
5211
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5212
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5213
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5214
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5215
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5216
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
5217
+ * THE SOFTWARE.
5218
+ */
5219
+
5220
+ /*jslint browser: true, node: true */
5221
+ /*global require, module */
5203
5222
 
5204
5223
  "use strict";
5205
5224
 
5206
- (() => {
5207
- var __getOwnPropNames = Object.getOwnPropertyNames;
5208
- var __require = /* @__PURE__ */ ((x) => true ? __webpack_require__(460) : 0)(function(x) {
5209
- if (true)
5210
- return __webpack_require__(460).apply(this, arguments);
5211
- throw new Error('Dynamic require of "' + x + '" is not supported');
5212
- });
5213
- var __commonJS = (cb, mod) => function __require2() {
5214
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
5215
- };
5225
+ /*** Imports ***/
5226
+ var jpeg = jpeg || {};
5227
+ jpeg.lossless = jpeg.lossless || {};
5216
5228
 
5217
- // src/component-spec.js
5218
- var require_component_spec = __commonJS({
5219
- "src/component-spec.js"(exports, module) {
5220
- "use strict";
5221
- var jpeg = jpeg || {};
5222
- jpeg.lossless = jpeg.lossless || {};
5223
- jpeg.lossless.ComponentSpec = jpeg.lossless.ComponentSpec || function() {
5224
- this.hSamp = 0;
5225
- this.quantTableSel = 0;
5226
- this.vSamp = 0;
5227
- };
5228
- var moduleType = typeof module;
5229
- if (moduleType !== "undefined" && module.exports) {
5230
- module.exports = jpeg.lossless.ComponentSpec;
5231
- }
5232
- }
5233
- });
5234
-
5235
- // src/data-stream.js
5236
- var require_data_stream = __commonJS({
5237
- "src/data-stream.js"(exports, module) {
5238
- "use strict";
5239
- var jpeg = jpeg || {};
5240
- jpeg.lossless = jpeg.lossless || {};
5241
- jpeg.lossless.DataStream = jpeg.lossless.DataStream || function(data, offset, length) {
5242
- if (offset === void 0 && length === void 0) {
5243
- this.buffer = new Uint8Array(data);
5244
- } else {
5245
- this.buffer = new Uint8Array(data, offset, length);
5246
- }
5247
- this.index = 0;
5248
- };
5249
- jpeg.lossless.DataStream.prototype.get16 = function() {
5250
- var value = (this.buffer[this.index] << 8) + this.buffer[this.index + 1];
5251
- this.index += 2;
5252
- return value;
5253
- };
5254
- jpeg.lossless.DataStream.prototype.get8 = function() {
5255
- var value = this.buffer[this.index];
5256
- this.index += 1;
5257
- return value;
5258
- };
5259
- var moduleType = typeof module;
5260
- if (moduleType !== "undefined" && module.exports) {
5261
- module.exports = jpeg.lossless.DataStream;
5262
- }
5263
- }
5264
- });
5265
-
5266
- // src/utils.js
5267
- var require_utils = __commonJS({
5268
- "src/utils.js"(exports, module) {
5269
- "use strict";
5270
- var jpeg = jpeg || {};
5271
- jpeg.lossless = jpeg.lossless || {};
5272
- jpeg.lossless.Utils = jpeg.lossless.Utils || {};
5273
- jpeg.lossless.Utils.createArray = function(length) {
5274
- var arr = new Array(length || 0), i = length;
5275
- if (arguments.length > 1) {
5276
- var args = Array.prototype.slice.call(arguments, 1);
5277
- while (i--)
5278
- arr[length - 1 - i] = jpeg.lossless.Utils.createArray.apply(this, args);
5279
- }
5280
- return arr;
5281
- };
5282
- jpeg.lossless.Utils.makeCRCTable = function() {
5283
- var c;
5284
- var crcTable = [];
5285
- for (var n = 0; n < 256; n++) {
5286
- c = n;
5287
- for (var k = 0; k < 8; k++) {
5288
- c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
5289
- }
5290
- crcTable[n] = c;
5291
- }
5292
- return crcTable;
5293
- };
5294
- jpeg.lossless.Utils.crc32 = function(dataView) {
5295
- var uint8view = new Uint8Array(dataView.buffer);
5296
- var crcTable = jpeg.lossless.Utils.crcTable || (jpeg.lossless.Utils.crcTable = jpeg.lossless.Utils.makeCRCTable());
5297
- var crc = 0 ^ -1;
5298
- for (var i = 0; i < uint8view.length; i++) {
5299
- crc = crc >>> 8 ^ crcTable[(crc ^ uint8view[i]) & 255];
5300
- }
5301
- return (crc ^ -1) >>> 0;
5302
- };
5303
- var moduleType = typeof module;
5304
- if (moduleType !== "undefined" && module.exports) {
5305
- module.exports = jpeg.lossless.Utils;
5306
- }
5307
- }
5308
- });
5309
-
5310
- // src/huffman-table.js
5311
- var require_huffman_table = __commonJS({
5312
- "src/huffman-table.js"(exports, module) {
5313
- "use strict";
5314
- var jpeg = jpeg || {};
5315
- jpeg.lossless = jpeg.lossless || {};
5316
- jpeg.lossless.DataStream = jpeg.lossless.DataStream || (typeof __require !== "undefined" ? require_data_stream() : null);
5317
- jpeg.lossless.Utils = jpeg.lossless.Utils || (typeof __require !== "undefined" ? require_utils() : null);
5318
- jpeg.lossless.HuffmanTable = jpeg.lossless.HuffmanTable || function() {
5319
- this.l = jpeg.lossless.Utils.createArray(4, 2, 16);
5320
- this.th = [];
5321
- this.v = jpeg.lossless.Utils.createArray(4, 2, 16, 200);
5322
- this.tc = jpeg.lossless.Utils.createArray(4, 2);
5323
- this.tc[0][0] = 0;
5324
- this.tc[1][0] = 0;
5325
- this.tc[2][0] = 0;
5326
- this.tc[3][0] = 0;
5327
- this.tc[0][1] = 0;
5328
- this.tc[1][1] = 0;
5329
- this.tc[2][1] = 0;
5330
- this.tc[3][1] = 0;
5331
- this.th[0] = 0;
5332
- this.th[1] = 0;
5333
- this.th[2] = 0;
5334
- this.th[3] = 0;
5335
- };
5336
- jpeg.lossless.HuffmanTable.MSB = 2147483648;
5337
- jpeg.lossless.HuffmanTable.prototype.read = function(data, HuffTab) {
5338
- var count = 0, length, temp, t, c, i, j;
5339
- length = data.get16();
5340
- count += 2;
5341
- while (count < length) {
5342
- temp = data.get8();
5343
- count += 1;
5344
- t = temp & 15;
5345
- if (t > 3) {
5346
- throw new Error("ERROR: Huffman table ID > 3");
5347
- }
5348
- c = temp >> 4;
5349
- if (c > 2) {
5350
- throw new Error("ERROR: Huffman table [Table class > 2 ]");
5351
- }
5352
- this.th[t] = 1;
5353
- this.tc[t][c] = 1;
5354
- for (i = 0; i < 16; i += 1) {
5355
- this.l[t][c][i] = data.get8();
5356
- count += 1;
5357
- }
5358
- for (i = 0; i < 16; i += 1) {
5359
- for (j = 0; j < this.l[t][c][i]; j += 1) {
5360
- if (count > length) {
5361
- throw new Error("ERROR: Huffman table format error [count>Lh]");
5362
- }
5363
- this.v[t][c][i][j] = data.get8();
5364
- count += 1;
5365
- }
5366
- }
5367
- }
5368
- if (count !== length) {
5369
- throw new Error("ERROR: Huffman table format error [count!=Lf]");
5370
- }
5371
- for (i = 0; i < 4; i += 1) {
5372
- for (j = 0; j < 2; j += 1) {
5373
- if (this.tc[i][j] !== 0) {
5374
- this.buildHuffTable(HuffTab[i][j], this.l[i][j], this.v[i][j]);
5375
- }
5376
- }
5377
- }
5378
- return 1;
5379
- };
5380
- jpeg.lossless.HuffmanTable.prototype.buildHuffTable = function(tab, L, V) {
5381
- var currentTable, temp, k, i, j, n;
5382
- temp = 256;
5383
- k = 0;
5384
- for (i = 0; i < 8; i += 1) {
5385
- for (j = 0; j < L[i]; j += 1) {
5386
- for (n = 0; n < temp >> i + 1; n += 1) {
5387
- tab[k] = V[i][j] | i + 1 << 8;
5388
- k += 1;
5389
- }
5390
- }
5391
- }
5392
- for (i = 1; k < 256; i += 1, k += 1) {
5393
- tab[k] = i | jpeg.lossless.HuffmanTable.MSB;
5394
- }
5395
- currentTable = 1;
5396
- k = 0;
5397
- for (i = 8; i < 16; i += 1) {
5398
- for (j = 0; j < L[i]; j += 1) {
5399
- for (n = 0; n < temp >> i - 7; n += 1) {
5400
- tab[currentTable * 256 + k] = V[i][j] | i + 1 << 8;
5401
- k += 1;
5402
- }
5403
- if (k >= 256) {
5404
- if (k > 256) {
5405
- throw new Error("ERROR: Huffman table error(1)!");
5406
- }
5407
- k = 0;
5408
- currentTable += 1;
5409
- }
5410
- }
5411
- }
5412
- };
5413
- var moduleType = typeof module;
5414
- if (moduleType !== "undefined" && module.exports) {
5415
- module.exports = jpeg.lossless.HuffmanTable;
5416
- }
5229
+
5230
+ /*** Constructor ***/
5231
+ jpeg.lossless.ComponentSpec = jpeg.lossless.ComponentSpec || function () {
5232
+ this.hSamp = 0; // Horizontal sampling factor
5233
+ this.quantTableSel = 0; // Quantization table destination selector
5234
+ this.vSamp = 0; // Vertical
5235
+ };
5236
+
5237
+
5238
+ /*** Exports ***/
5239
+
5240
+ var moduleType = typeof module;
5241
+ if ((moduleType !== 'undefined') && module.exports) {
5242
+ module.exports = jpeg.lossless.ComponentSpec;
5243
+ }
5244
+
5245
+ },{}],2:[function(require,module,exports){
5246
+ /*
5247
+ * Copyright (C) 2015 Michael Martinez
5248
+ * Changes: Added support for selection values 2-7, fixed minor bugs &
5249
+ * warnings, split into multiple class files, and general clean up.
5250
+ *
5251
+ * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
5252
+ */
5253
+
5254
+ /*
5255
+ * Copyright (C) Helmut Dersch
5256
+ *
5257
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5258
+ * of this software and associated documentation files (the "Software"), to deal
5259
+ * in the Software without restriction, including without limitation the rights
5260
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5261
+ * copies of the Software, and to permit persons to whom the Software is
5262
+ * furnished to do so, subject to the following conditions:
5263
+
5264
+ * The above copyright notice and this permission notice shall be included in
5265
+ * all copies or substantial portions of the Software.
5266
+
5267
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5268
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5269
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5270
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5271
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5272
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
5273
+ * THE SOFTWARE.
5274
+ */
5275
+
5276
+ /*jslint browser: true, node: true */
5277
+ /*global require, module */
5278
+
5279
+ "use strict";
5280
+
5281
+ /*** Imports ***/
5282
+ var jpeg = jpeg || {};
5283
+ jpeg.lossless = jpeg.lossless || {};
5284
+
5285
+
5286
+ /*** Constructor ***/
5287
+ jpeg.lossless.DataStream = jpeg.lossless.DataStream || function (data, offset, length) {
5288
+ if (offset === undefined && length === undefined) { // Old api
5289
+ this.buffer = new Uint8Array(data);
5290
+ } else {
5291
+ this.buffer = new Uint8Array(data, offset, length);
5417
5292
  }
5418
- });
5419
-
5420
- // src/quantization-table.js
5421
- var require_quantization_table = __commonJS({
5422
- "src/quantization-table.js"(exports, module) {
5423
- "use strict";
5424
- var jpeg = jpeg || {};
5425
- jpeg.lossless = jpeg.lossless || {};
5426
- jpeg.lossless.DataStream = jpeg.lossless.DataStream || (typeof __require !== "undefined" ? require_data_stream() : null);
5427
- jpeg.lossless.Utils = jpeg.lossless.Utils || (typeof __require !== "undefined" ? require_utils() : null);
5428
- jpeg.lossless.QuantizationTable = jpeg.lossless.QuantizationTable || function() {
5429
- this.precision = [];
5430
- this.tq = [];
5431
- this.quantTables = jpeg.lossless.Utils.createArray(4, 64);
5432
- this.tq[0] = 0;
5433
- this.tq[1] = 0;
5434
- this.tq[2] = 0;
5435
- this.tq[3] = 0;
5436
- };
5437
- jpeg.lossless.QuantizationTable.enhanceQuantizationTable = function(qtab, table) {
5438
- var i;
5439
- for (i = 0; i < 8; i += 1) {
5440
- qtab[table[0 * 8 + i]] *= 90;
5441
- qtab[table[4 * 8 + i]] *= 90;
5442
- qtab[table[2 * 8 + i]] *= 118;
5443
- qtab[table[6 * 8 + i]] *= 49;
5444
- qtab[table[5 * 8 + i]] *= 71;
5445
- qtab[table[1 * 8 + i]] *= 126;
5446
- qtab[table[7 * 8 + i]] *= 25;
5447
- qtab[table[3 * 8 + i]] *= 106;
5448
- }
5449
- for (i = 0; i < 8; i += 1) {
5450
- qtab[table[0 + 8 * i]] *= 90;
5451
- qtab[table[4 + 8 * i]] *= 90;
5452
- qtab[table[2 + 8 * i]] *= 118;
5453
- qtab[table[6 + 8 * i]] *= 49;
5454
- qtab[table[5 + 8 * i]] *= 71;
5455
- qtab[table[1 + 8 * i]] *= 126;
5456
- qtab[table[7 + 8 * i]] *= 25;
5457
- qtab[table[3 + 8 * i]] *= 106;
5458
- }
5459
- for (i = 0; i < 64; i += 1) {
5460
- qtab[i] >>= 6;
5461
- }
5462
- };
5463
- jpeg.lossless.QuantizationTable.prototype.read = function(data, table) {
5464
- var count = 0, length, temp, t, i;
5465
- length = data.get16();
5466
- count += 2;
5467
- while (count < length) {
5468
- temp = data.get8();
5469
- count += 1;
5470
- t = temp & 15;
5471
- if (t > 3) {
5472
- throw new Error("ERROR: Quantization table ID > 3");
5473
- }
5474
- this.precision[t] = temp >> 4;
5475
- if (this.precision[t] === 0) {
5476
- this.precision[t] = 8;
5477
- } else if (this.precision[t] === 1) {
5478
- this.precision[t] = 16;
5479
- } else {
5480
- throw new Error("ERROR: Quantization table precision error");
5481
- }
5482
- this.tq[t] = 1;
5483
- if (this.precision[t] === 8) {
5484
- for (i = 0; i < 64; i += 1) {
5485
- if (count > length) {
5486
- throw new Error("ERROR: Quantization table format error");
5487
- }
5488
- this.quantTables[t][i] = data.get8();
5489
- count += 1;
5490
- }
5491
- jpeg.lossless.QuantizationTable.enhanceQuantizationTable(this.quantTables[t], table);
5492
- } else {
5493
- for (i = 0; i < 64; i += 1) {
5494
- if (count > length) {
5495
- throw new Error("ERROR: Quantization table format error");
5496
- }
5497
- this.quantTables[t][i] = data.get16();
5498
- count += 2;
5499
- }
5500
- jpeg.lossless.QuantizationTable.enhanceQuantizationTable(this.quantTables[t], table);
5501
- }
5502
- }
5503
- if (count !== length) {
5504
- throw new Error("ERROR: Quantization table error [count!=Lq]");
5505
- }
5506
- return 1;
5507
- };
5508
- var moduleType = typeof module;
5509
- if (moduleType !== "undefined" && module.exports) {
5510
- module.exports = jpeg.lossless.QuantizationTable;
5511
- }
5293
+ this.index = 0;
5294
+ };
5295
+
5296
+
5297
+
5298
+ jpeg.lossless.DataStream.prototype.get16 = function () {
5299
+ // var value = this.buffer.getUint16(this.index, false);
5300
+ var value = (this.buffer[this.index] << 8) + this.buffer[this.index + 1]; // DataView is big-endian by default
5301
+ this.index += 2;
5302
+ return value;
5303
+ };
5304
+
5305
+
5306
+
5307
+ jpeg.lossless.DataStream.prototype.get8 = function () {
5308
+ // var value = this.buffer.getUint8(this.index);
5309
+ var value = this.buffer[this.index];
5310
+ this.index += 1;
5311
+ return value;
5312
+ };
5313
+
5314
+
5315
+ /*** Exports ***/
5316
+
5317
+ var moduleType = typeof module;
5318
+ if ((moduleType !== 'undefined') && module.exports) {
5319
+ module.exports = jpeg.lossless.DataStream;
5320
+ }
5321
+
5322
+ },{}],3:[function(require,module,exports){
5323
+ /*
5324
+ * Copyright (C) 2015 Michael Martinez
5325
+ * Changes: Added support for selection values 2-7, fixed minor bugs &
5326
+ * warnings, split into multiple class files, and general clean up.
5327
+ *
5328
+ * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
5329
+ */
5330
+
5331
+ /*
5332
+ * Copyright (C) Helmut Dersch
5333
+ *
5334
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5335
+ * of this software and associated documentation files (the "Software"), to deal
5336
+ * in the Software without restriction, including without limitation the rights
5337
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5338
+ * copies of the Software, and to permit persons to whom the Software is
5339
+ * furnished to do so, subject to the following conditions:
5340
+
5341
+ * The above copyright notice and this permission notice shall be included in
5342
+ * all copies or substantial portions of the Software.
5343
+
5344
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5345
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5346
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5347
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5348
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5349
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
5350
+ * THE SOFTWARE.
5351
+ */
5352
+
5353
+ /*jslint browser: true, node: true */
5354
+ /*global require, module */
5355
+
5356
+ "use strict";
5357
+
5358
+ /*** Imports ***/
5359
+ var jpeg = jpeg || {};
5360
+ jpeg.lossless = jpeg.lossless || {};
5361
+ jpeg.lossless.DataStream = jpeg.lossless.DataStream || ((typeof require !== 'undefined') ? require('./data-stream.js') : null);
5362
+ jpeg.lossless.HuffmanTable = jpeg.lossless.HuffmanTable || ((typeof require !== 'undefined') ? require('./huffman-table.js') : null);
5363
+ jpeg.lossless.QuantizationTable = jpeg.lossless.QuantizationTable || ((typeof require !== 'undefined') ? require('./quantization-table.js') : null);
5364
+ jpeg.lossless.ScanHeader = jpeg.lossless.ScanHeader || ((typeof require !== 'undefined') ? require('./scan-header.js') : null);
5365
+ jpeg.lossless.FrameHeader = jpeg.lossless.FrameHeader || ((typeof require !== 'undefined') ? require('./frame-header.js') : null);
5366
+ jpeg.lossless.Utils = jpeg.lossless.Utils || ((typeof require !== 'undefined') ? require('./utils.js') : null);
5367
+
5368
+
5369
+ /*** Constructor ***/
5370
+
5371
+ /**
5372
+ * The Decoder constructor.
5373
+ * @property {number} xDim - size of x dimension
5374
+ * @property {number} yDim - size of y dimension
5375
+ * @property {number} numComp - number of components
5376
+ * @property {number} numBytes - number of bytes per component
5377
+ * @type {Function}
5378
+ */
5379
+ jpeg.lossless.Decoder = jpeg.lossless.Decoder || function (buffer, numBytes) {
5380
+ this.buffer = buffer;
5381
+ this.frame = new jpeg.lossless.FrameHeader();
5382
+ this.huffTable = new jpeg.lossless.HuffmanTable();
5383
+ this.quantTable = new jpeg.lossless.QuantizationTable();
5384
+ this.scan = new jpeg.lossless.ScanHeader();
5385
+ this.DU = jpeg.lossless.Utils.createArray(10, 4, 64); // at most 10 data units in a MCU, at most 4 data units in one component
5386
+ this.HuffTab = jpeg.lossless.Utils.createArray(4, 2, 50 * 256);
5387
+ this.IDCT_Source = [];
5388
+ this.nBlock = []; // number of blocks in the i-th Comp in a scan
5389
+ this.acTab = jpeg.lossless.Utils.createArray(10, 1); // ac HuffTab for the i-th Comp in a scan
5390
+ this.dcTab = jpeg.lossless.Utils.createArray(10, 1); // dc HuffTab for the i-th Comp in a scan
5391
+ this.qTab = jpeg.lossless.Utils.createArray(10, 1); // quantization table for the i-th Comp in a scan
5392
+ this.marker = 0;
5393
+ this.markerIndex = 0;
5394
+ this.numComp = 0;
5395
+ this.restartInterval = 0;
5396
+ this.selection = 0;
5397
+ this.xDim = 0;
5398
+ this.yDim = 0;
5399
+ this.xLoc = 0;
5400
+ this.yLoc = 0;
5401
+ this.numBytes = 0;
5402
+ this.outputData = null;
5403
+ this.restarting = false;
5404
+ this.mask = 0;
5405
+
5406
+ if (typeof numBytes !== "undefined") {
5407
+ this.numBytes = numBytes;
5512
5408
  }
5513
- });
5514
-
5515
- // src/scan-component.js
5516
- var require_scan_component = __commonJS({
5517
- "src/scan-component.js"(exports, module) {
5518
- "use strict";
5519
- var jpeg = jpeg || {};
5520
- jpeg.lossless = jpeg.lossless || {};
5521
- jpeg.lossless.ScanComponent = jpeg.lossless.ScanComponent || function() {
5522
- this.acTabSel = 0;
5523
- this.dcTabSel = 0;
5524
- this.scanCompSel = 0;
5525
- };
5526
- var moduleType = typeof module;
5527
- if (moduleType !== "undefined" && module.exports) {
5528
- module.exports = jpeg.lossless.ScanComponent;
5529
- }
5409
+ };
5410
+
5411
+
5412
+ /*** Static Pseudo-constants ***/
5413
+
5414
+ jpeg.lossless.Decoder.IDCT_P = [0, 5, 40, 16, 45, 2, 7, 42, 21, 56, 8, 61, 18, 47, 1, 4, 41, 23, 58, 13, 32, 24, 37, 10, 63, 17, 44, 3, 6, 43, 20,
5415
+ 57, 15, 34, 29, 48, 53, 26, 39, 9, 60, 19, 46, 22, 59, 12, 33, 31, 50, 55, 25, 36, 11, 62, 14, 35, 28, 49, 52, 27, 38, 30, 51, 54];
5416
+ jpeg.lossless.Decoder.TABLE = [0, 1, 5, 6, 14, 15, 27, 28, 2, 4, 7, 13, 16, 26, 29, 42, 3, 8, 12, 17, 25, 30, 41, 43, 9, 11, 18, 24, 31, 40, 44, 53,
5417
+ 10, 19, 23, 32, 39, 45, 52, 54, 20, 22, 33, 38, 46, 51, 55, 60, 21, 34, 37, 47, 50, 56, 59, 61, 35, 36, 48, 49, 57, 58, 62, 63];
5418
+ jpeg.lossless.Decoder.MAX_HUFFMAN_SUBTREE = 50;
5419
+ jpeg.lossless.Decoder.MSB = 0x80000000;
5420
+ jpeg.lossless.Decoder.RESTART_MARKER_BEGIN = 0xFFD0;
5421
+ jpeg.lossless.Decoder.RESTART_MARKER_END = 0xFFD7;
5422
+
5423
+ /*** Prototype Methods ***/
5424
+
5425
+ /**
5426
+ * Returns decompressed data.
5427
+ * @param {ArrayBuffer} buffer
5428
+ * @param {number} [offset]
5429
+ * @param {number} [length]
5430
+ * @returns {ArrayBufer}
5431
+ */
5432
+ jpeg.lossless.Decoder.prototype.decompress = function (buffer, offset, length) {
5433
+ return this.decode(buffer, offset, length).buffer;
5434
+ };
5435
+
5436
+
5437
+
5438
+ jpeg.lossless.Decoder.prototype.decode = function (buffer, offset, length, numBytes) {
5439
+ /*jslint bitwise: true */
5440
+
5441
+ var current, scanNum = 0, pred = [], i, compN, temp = [], index = [], mcuNum;
5442
+
5443
+ if (typeof buffer !== "undefined") {
5444
+ this.buffer = buffer;
5530
5445
  }
5531
- });
5532
-
5533
- // src/scan-header.js
5534
- var require_scan_header = __commonJS({
5535
- "src/scan-header.js"(exports, module) {
5536
- "use strict";
5537
- var jpeg = jpeg || {};
5538
- jpeg.lossless = jpeg.lossless || {};
5539
- jpeg.lossless.DataStream = jpeg.lossless.DataStream || (typeof __require !== "undefined" ? require_data_stream() : null);
5540
- jpeg.lossless.ScanComponent = jpeg.lossless.ScanComponent || (typeof __require !== "undefined" ? require_scan_component() : null);
5541
- jpeg.lossless.ScanHeader = jpeg.lossless.ScanHeader || function() {
5542
- this.ah = 0;
5543
- this.al = 0;
5544
- this.numComp = 0;
5545
- this.selection = 0;
5546
- this.spectralEnd = 0;
5547
- this.components = [];
5548
- };
5549
- jpeg.lossless.ScanHeader.prototype.read = function(data) {
5550
- var count = 0, length, i, temp;
5551
- length = data.get16();
5552
- count += 2;
5553
- this.numComp = data.get8();
5554
- count += 1;
5555
- for (i = 0; i < this.numComp; i += 1) {
5556
- this.components[i] = new jpeg.lossless.ScanComponent();
5557
- if (count > length) {
5558
- throw new Error("ERROR: scan header format error");
5559
- }
5560
- this.components[i].scanCompSel = data.get8();
5561
- count += 1;
5562
- temp = data.get8();
5563
- count += 1;
5564
- this.components[i].dcTabSel = temp >> 4;
5565
- this.components[i].acTabSel = temp & 15;
5566
- }
5567
- this.selection = data.get8();
5568
- count += 1;
5569
- this.spectralEnd = data.get8();
5570
- count += 1;
5571
- temp = data.get8();
5572
- this.ah = temp >> 4;
5573
- this.al = temp & 15;
5574
- count += 1;
5575
- if (count !== length) {
5576
- throw new Error("ERROR: scan header format error [count!=Ns]");
5577
- }
5578
- return 1;
5579
- };
5580
- var moduleType = typeof module;
5581
- if (moduleType !== "undefined" && module.exports) {
5582
- module.exports = jpeg.lossless.ScanHeader;
5583
- }
5446
+
5447
+ if (typeof numBytes !== "undefined") {
5448
+ this.numBytes = numBytes;
5584
5449
  }
5585
- });
5586
-
5587
- // src/frame-header.js
5588
- var require_frame_header = __commonJS({
5589
- "src/frame-header.js"(exports, module) {
5590
- "use strict";
5591
- var jpeg = jpeg || {};
5592
- jpeg.lossless = jpeg.lossless || {};
5593
- jpeg.lossless.ComponentSpec = jpeg.lossless.ComponentSpec || (typeof __require !== "undefined" ? require_component_spec() : null);
5594
- jpeg.lossless.DataStream = jpeg.lossless.DataStream || (typeof __require !== "undefined" ? require_data_stream() : null);
5595
- jpeg.lossless.FrameHeader = jpeg.lossless.FrameHeader || function() {
5596
- this.components = [];
5597
- this.dimX = 0;
5598
- this.dimY = 0;
5599
- this.numComp = 0;
5600
- this.precision = 0;
5601
- };
5602
- jpeg.lossless.FrameHeader.prototype.read = function(data) {
5603
- var count = 0, length, i, c, temp;
5604
- length = data.get16();
5605
- count += 2;
5606
- this.precision = data.get8();
5607
- count += 1;
5608
- this.dimY = data.get16();
5609
- count += 2;
5610
- this.dimX = data.get16();
5611
- count += 2;
5612
- this.numComp = data.get8();
5613
- count += 1;
5614
- for (i = 1; i <= this.numComp; i += 1) {
5615
- if (count > length) {
5616
- throw new Error("ERROR: frame format error");
5617
- }
5618
- c = data.get8();
5619
- count += 1;
5620
- if (count >= length) {
5621
- throw new Error("ERROR: frame format error [c>=Lf]");
5622
- }
5623
- temp = data.get8();
5624
- count += 1;
5625
- if (!this.components[c]) {
5626
- this.components[c] = new jpeg.lossless.ComponentSpec();
5627
- }
5628
- this.components[c].hSamp = temp >> 4;
5629
- this.components[c].vSamp = temp & 15;
5630
- this.components[c].quantTableSel = data.get8();
5631
- count += 1;
5632
- }
5633
- if (count !== length) {
5634
- throw new Error("ERROR: frame format error [Lf!=count]");
5635
- }
5636
- return 1;
5637
- };
5638
- var moduleType = typeof module;
5639
- if (moduleType !== "undefined" && module.exports) {
5640
- module.exports = jpeg.lossless.FrameHeader;
5641
- }
5450
+
5451
+ this.stream = new jpeg.lossless.DataStream(this.buffer, offset, length);
5452
+ this.buffer = null;
5453
+
5454
+ this.xLoc = 0;
5455
+ this.yLoc = 0;
5456
+ current = this.stream.get16();
5457
+
5458
+ if (current !== 0xFFD8) { // SOI
5459
+ throw new Error("Not a JPEG file");
5642
5460
  }
5643
- });
5644
-
5645
- // src/decoder.js
5646
- var require_decoder = __commonJS({
5647
- "src/decoder.js"(exports, module) {
5648
- "use strict";
5649
- var jpeg = jpeg || {};
5650
- jpeg.lossless = jpeg.lossless || {};
5651
- jpeg.lossless.DataStream = jpeg.lossless.DataStream || (typeof __require !== "undefined" ? require_data_stream() : null);
5652
- jpeg.lossless.HuffmanTable = jpeg.lossless.HuffmanTable || (typeof __require !== "undefined" ? require_huffman_table() : null);
5653
- jpeg.lossless.QuantizationTable = jpeg.lossless.QuantizationTable || (typeof __require !== "undefined" ? require_quantization_table() : null);
5654
- jpeg.lossless.ScanHeader = jpeg.lossless.ScanHeader || (typeof __require !== "undefined" ? require_scan_header() : null);
5655
- jpeg.lossless.FrameHeader = jpeg.lossless.FrameHeader || (typeof __require !== "undefined" ? require_frame_header() : null);
5656
- jpeg.lossless.Utils = jpeg.lossless.Utils || (typeof __require !== "undefined" ? require_utils() : null);
5657
- jpeg.lossless.Decoder = jpeg.lossless.Decoder || function(buffer, numBytes) {
5658
- this.buffer = buffer;
5659
- this.frame = new jpeg.lossless.FrameHeader();
5660
- this.huffTable = new jpeg.lossless.HuffmanTable();
5661
- this.quantTable = new jpeg.lossless.QuantizationTable();
5662
- this.scan = new jpeg.lossless.ScanHeader();
5663
- this.DU = jpeg.lossless.Utils.createArray(10, 4, 64);
5664
- this.HuffTab = jpeg.lossless.Utils.createArray(4, 2, 50 * 256);
5665
- this.IDCT_Source = [];
5666
- this.nBlock = [];
5667
- this.acTab = jpeg.lossless.Utils.createArray(10, 1);
5668
- this.dcTab = jpeg.lossless.Utils.createArray(10, 1);
5669
- this.qTab = jpeg.lossless.Utils.createArray(10, 1);
5670
- this.marker = 0;
5671
- this.markerIndex = 0;
5672
- this.numComp = 0;
5673
- this.restartInterval = 0;
5674
- this.selection = 0;
5675
- this.xDim = 0;
5676
- this.yDim = 0;
5677
- this.xLoc = 0;
5678
- this.yLoc = 0;
5679
- this.numBytes = 0;
5680
- this.outputData = null;
5681
- this.restarting = false;
5682
- this.mask = 0;
5683
- if (typeof numBytes !== "undefined") {
5684
- this.numBytes = numBytes;
5685
- }
5686
- };
5687
- jpeg.lossless.Decoder.IDCT_P = [
5688
- 0,
5689
- 5,
5690
- 40,
5691
- 16,
5692
- 45,
5693
- 2,
5694
- 7,
5695
- 42,
5696
- 21,
5697
- 56,
5698
- 8,
5699
- 61,
5700
- 18,
5701
- 47,
5702
- 1,
5703
- 4,
5704
- 41,
5705
- 23,
5706
- 58,
5707
- 13,
5708
- 32,
5709
- 24,
5710
- 37,
5711
- 10,
5712
- 63,
5713
- 17,
5714
- 44,
5715
- 3,
5716
- 6,
5717
- 43,
5718
- 20,
5719
- 57,
5720
- 15,
5721
- 34,
5722
- 29,
5723
- 48,
5724
- 53,
5725
- 26,
5726
- 39,
5727
- 9,
5728
- 60,
5729
- 19,
5730
- 46,
5731
- 22,
5732
- 59,
5733
- 12,
5734
- 33,
5735
- 31,
5736
- 50,
5737
- 55,
5738
- 25,
5739
- 36,
5740
- 11,
5741
- 62,
5742
- 14,
5743
- 35,
5744
- 28,
5745
- 49,
5746
- 52,
5747
- 27,
5748
- 38,
5749
- 30,
5750
- 51,
5751
- 54
5752
- ];
5753
- jpeg.lossless.Decoder.TABLE = [
5754
- 0,
5755
- 1,
5756
- 5,
5757
- 6,
5758
- 14,
5759
- 15,
5760
- 27,
5761
- 28,
5762
- 2,
5763
- 4,
5764
- 7,
5765
- 13,
5766
- 16,
5767
- 26,
5768
- 29,
5769
- 42,
5770
- 3,
5771
- 8,
5772
- 12,
5773
- 17,
5774
- 25,
5775
- 30,
5776
- 41,
5777
- 43,
5778
- 9,
5779
- 11,
5780
- 18,
5781
- 24,
5782
- 31,
5783
- 40,
5784
- 44,
5785
- 53,
5786
- 10,
5787
- 19,
5788
- 23,
5789
- 32,
5790
- 39,
5791
- 45,
5792
- 52,
5793
- 54,
5794
- 20,
5795
- 22,
5796
- 33,
5797
- 38,
5798
- 46,
5799
- 51,
5800
- 55,
5801
- 60,
5802
- 21,
5803
- 34,
5804
- 37,
5805
- 47,
5806
- 50,
5807
- 56,
5808
- 59,
5809
- 61,
5810
- 35,
5811
- 36,
5812
- 48,
5813
- 49,
5814
- 57,
5815
- 58,
5816
- 62,
5817
- 63
5818
- ];
5819
- jpeg.lossless.Decoder.MAX_HUFFMAN_SUBTREE = 50;
5820
- jpeg.lossless.Decoder.MSB = 2147483648;
5821
- jpeg.lossless.Decoder.RESTART_MARKER_BEGIN = 65488;
5822
- jpeg.lossless.Decoder.RESTART_MARKER_END = 65495;
5823
- jpeg.lossless.Decoder.prototype.decompress = function(buffer, offset, length) {
5824
- return this.decode(buffer, offset, length).buffer;
5825
- };
5826
- jpeg.lossless.Decoder.prototype.decode = function(buffer, offset, length, numBytes) {
5827
- var current, scanNum = 0, pred = [], i, compN, temp = [], index = [], mcuNum;
5828
- if (typeof buffer !== "undefined") {
5829
- this.buffer = buffer;
5830
- }
5831
- if (typeof numBytes !== "undefined") {
5832
- this.numBytes = numBytes;
5833
- }
5834
- this.stream = new jpeg.lossless.DataStream(this.buffer, offset, length);
5835
- this.buffer = null;
5836
- this.xLoc = 0;
5837
- this.yLoc = 0;
5838
- current = this.stream.get16();
5839
- if (current !== 65496) {
5840
- throw new Error("Not a JPEG file");
5841
- }
5842
- current = this.stream.get16();
5843
- while (current >> 4 !== 4092 || current === 65476) {
5844
- switch (current) {
5845
- case 65476:
5846
- this.huffTable.read(this.stream, this.HuffTab);
5847
- break;
5848
- case 65484:
5849
- throw new Error("Program doesn't support arithmetic coding. (format throw new IOException)");
5850
- case 65499:
5851
- this.quantTable.read(this.stream, jpeg.lossless.Decoder.TABLE);
5852
- break;
5853
- case 65501:
5854
- this.restartInterval = this.readNumber();
5855
- break;
5856
- case 65504:
5857
- case 65505:
5858
- case 65506:
5859
- case 65507:
5860
- case 65508:
5861
- case 65509:
5862
- case 65510:
5863
- case 65511:
5864
- case 65512:
5865
- case 65513:
5866
- case 65514:
5867
- case 65515:
5868
- case 65516:
5869
- case 65517:
5870
- case 65518:
5871
- case 65519:
5872
- this.readApp();
5873
- break;
5874
- case 65534:
5875
- this.readComment();
5876
- break;
5877
- default:
5878
- if (current >> 8 !== 255) {
5879
- throw new Error("ERROR: format throw new IOException! (decode)");
5880
- }
5881
- }
5882
- current = this.stream.get16();
5883
- }
5884
- if (current < 65472 || current > 65479) {
5885
- throw new Error("ERROR: could not handle arithmetic code!");
5886
- }
5887
- this.frame.read(this.stream);
5888
- current = this.stream.get16();
5889
- do {
5890
- while (current !== 65498) {
5891
- switch (current) {
5892
- case 65476:
5461
+
5462
+ current = this.stream.get16();
5463
+
5464
+ while ((((current >> 4) !== 0x0FFC) || (current === 0xFFC4))) { // SOF 0~15
5465
+ switch (current) {
5466
+ case 0xFFC4: // DHT
5893
5467
  this.huffTable.read(this.stream, this.HuffTab);
5894
5468
  break;
5895
- case 65484:
5469
+ case 0xFFCC: // DAC
5896
5470
  throw new Error("Program doesn't support arithmetic coding. (format throw new IOException)");
5897
- case 65499:
5471
+ case 0xFFDB:
5898
5472
  this.quantTable.read(this.stream, jpeg.lossless.Decoder.TABLE);
5899
5473
  break;
5900
- case 65501:
5474
+ case 0xFFDD:
5901
5475
  this.restartInterval = this.readNumber();
5902
5476
  break;
5903
- case 65504:
5904
- case 65505:
5905
- case 65506:
5906
- case 65507:
5907
- case 65508:
5908
- case 65509:
5909
- case 65510:
5910
- case 65511:
5911
- case 65512:
5912
- case 65513:
5913
- case 65514:
5914
- case 65515:
5915
- case 65516:
5916
- case 65517:
5917
- case 65518:
5918
- case 65519:
5477
+ case 0xFFE0:
5478
+ case 0xFFE1:
5479
+ case 0xFFE2:
5480
+ case 0xFFE3:
5481
+ case 0xFFE4:
5482
+ case 0xFFE5:
5483
+ case 0xFFE6:
5484
+ case 0xFFE7:
5485
+ case 0xFFE8:
5486
+ case 0xFFE9:
5487
+ case 0xFFEA:
5488
+ case 0xFFEB:
5489
+ case 0xFFEC:
5490
+ case 0xFFED:
5491
+ case 0xFFEE:
5492
+ case 0xFFEF:
5919
5493
  this.readApp();
5920
5494
  break;
5921
- case 65534:
5495
+ case 0xFFFE:
5922
5496
  this.readComment();
5923
5497
  break;
5924
- default:
5925
- if (current >> 8 !== 255) {
5926
- throw new Error("ERROR: format throw new IOException! (Parser.decode)");
5498
+ default:
5499
+ if ((current >> 8) !== 0xFF) {
5500
+ throw new Error("ERROR: format throw new IOException! (decode)");
5927
5501
  }
5502
+ }
5503
+
5504
+ current = this.stream.get16();
5505
+ }
5506
+
5507
+ if ((current < 0xFFC0) || (current > 0xFFC7)) {
5508
+ throw new Error("ERROR: could not handle arithmetic code!");
5509
+ }
5510
+
5511
+ this.frame.read(this.stream);
5512
+ current = this.stream.get16();
5513
+
5514
+ do {
5515
+ while (current !== 0x0FFDA) { // SOS
5516
+ switch (current) {
5517
+ case 0xFFC4: // DHT
5518
+ this.huffTable.read(this.stream, this.HuffTab);
5519
+ break;
5520
+ case 0xFFCC: // DAC
5521
+ throw new Error("Program doesn't support arithmetic coding. (format throw new IOException)");
5522
+ case 0xFFDB:
5523
+ this.quantTable.read(this.stream, jpeg.lossless.Decoder.TABLE);
5524
+ break;
5525
+ case 0xFFDD:
5526
+ this.restartInterval = this.readNumber();
5527
+ break;
5528
+ case 0xFFE0:
5529
+ case 0xFFE1:
5530
+ case 0xFFE2:
5531
+ case 0xFFE3:
5532
+ case 0xFFE4:
5533
+ case 0xFFE5:
5534
+ case 0xFFE6:
5535
+ case 0xFFE7:
5536
+ case 0xFFE8:
5537
+ case 0xFFE9:
5538
+ case 0xFFEA:
5539
+ case 0xFFEB:
5540
+ case 0xFFEC:
5541
+ case 0xFFED:
5542
+ case 0xFFEE:
5543
+ case 0xFFEF:
5544
+ this.readApp();
5545
+ break;
5546
+ case 0xFFFE:
5547
+ this.readComment();
5548
+ break;
5549
+ default:
5550
+ if ((current >> 8) !== 0xFF) {
5551
+ throw new Error("ERROR: format throw new IOException! (Parser.decode)");
5552
+ }
5928
5553
  }
5554
+
5929
5555
  current = this.stream.get16();
5930
- }
5931
- this.precision = this.frame.precision;
5932
- this.components = this.frame.components;
5933
- if (!this.numBytes) {
5556
+ }
5557
+
5558
+ this.precision = this.frame.precision;
5559
+ this.components = this.frame.components;
5560
+
5561
+ if (!this.numBytes) {
5934
5562
  this.numBytes = parseInt(Math.ceil(this.precision / 8));
5935
- }
5936
- if (this.numBytes == 1) {
5937
- this.mask = 255;
5938
- } else {
5939
- this.mask = 65535;
5940
- }
5941
- this.scan.read(this.stream);
5942
- this.numComp = this.scan.numComp;
5943
- this.selection = this.scan.selection;
5944
- if (this.numBytes === 1) {
5563
+ }
5564
+
5565
+ if (this.numBytes == 1) {
5566
+ this.mask = 0xFF;
5567
+ } else {
5568
+ this.mask = 0xFFFF;
5569
+ }
5570
+
5571
+ this.scan.read(this.stream);
5572
+ this.numComp = this.scan.numComp;
5573
+ this.selection = this.scan.selection;
5574
+
5575
+ if (this.numBytes === 1) {
5945
5576
  if (this.numComp === 3) {
5946
- this.getter = this.getValueRGB;
5947
- this.setter = this.setValueRGB;
5948
- this.output = this.outputRGB;
5577
+ this.getter = this.getValueRGB;
5578
+ this.setter = this.setValueRGB;
5579
+ this.output = this.outputRGB;
5949
5580
  } else {
5950
- this.getter = this.getValue8;
5951
- this.setter = this.setValue8;
5952
- this.output = this.outputSingle;
5581
+ this.getter = this.getValue8;
5582
+ this.setter = this.setValue8;
5583
+ this.output = this.outputSingle;
5953
5584
  }
5954
- } else {
5585
+ } else {
5955
5586
  this.getter = this.getValue16;
5956
5587
  this.setter = this.setValue16;
5957
5588
  this.output = this.outputSingle;
5958
- }
5959
- switch (this.selection) {
5589
+ }
5590
+
5591
+ switch (this.selection) {
5960
5592
  case 2:
5961
- this.selector = this.select2;
5962
- break;
5593
+ this.selector = this.select2;
5594
+ break;
5963
5595
  case 3:
5964
- this.selector = this.select3;
5965
- break;
5596
+ this.selector = this.select3;
5597
+ break;
5966
5598
  case 4:
5967
- this.selector = this.select4;
5968
- break;
5599
+ this.selector = this.select4;
5600
+ break;
5969
5601
  case 5:
5970
- this.selector = this.select5;
5971
- break;
5602
+ this.selector = this.select5;
5603
+ break;
5972
5604
  case 6:
5973
- this.selector = this.select6;
5974
- break;
5605
+ this.selector = this.select6;
5606
+ break;
5975
5607
  case 7:
5976
- this.selector = this.select7;
5977
- break;
5608
+ this.selector = this.select7;
5609
+ break;
5978
5610
  default:
5979
- this.selector = this.select1;
5980
- break;
5981
- }
5982
- this.scanComps = this.scan.components;
5983
- this.quantTables = this.quantTable.quantTables;
5984
- for (i = 0; i < this.numComp; i += 1) {
5611
+ this.selector = this.select1;
5612
+ break;
5613
+ }
5614
+
5615
+ this.scanComps = this.scan.components;
5616
+ this.quantTables = this.quantTable.quantTables;
5617
+
5618
+ for (i = 0; i < this.numComp; i+=1) {
5985
5619
  compN = this.scanComps[i].scanCompSel;
5986
5620
  this.qTab[i] = this.quantTables[this.components[compN].quantTableSel];
5987
5621
  this.nBlock[i] = this.components[compN].vSamp * this.components[compN].hSamp;
5988
5622
  this.dcTab[i] = this.HuffTab[this.scanComps[i].dcTabSel][0];
5989
5623
  this.acTab[i] = this.HuffTab[this.scanComps[i].acTabSel][1];
5990
- }
5991
- this.xDim = this.frame.dimX;
5992
- this.yDim = this.frame.dimY;
5993
- if (this.numBytes == 1) {
5624
+ }
5625
+
5626
+ this.xDim = this.frame.dimX;
5627
+ this.yDim = this.frame.dimY;
5628
+ if (this.numBytes == 1) {
5994
5629
  this.outputData = new Uint8Array(new ArrayBuffer(this.xDim * this.yDim * this.numBytes * this.numComp));
5995
- } else {
5630
+ } else {
5996
5631
  this.outputData = new Uint16Array(new ArrayBuffer(this.xDim * this.yDim * this.numBytes * this.numComp));
5997
- }
5998
- scanNum += 1;
5999
- while (true) {
5632
+ }
5633
+
5634
+ scanNum+=1;
5635
+
5636
+ while (true) { // Decode one scan
6000
5637
  temp[0] = 0;
6001
5638
  index[0] = 0;
6002
- for (i = 0; i < 10; i += 1) {
6003
- pred[i] = 1 << this.precision - 1;
5639
+
5640
+ for (i = 0; i < 10; i+=1) {
5641
+ pred[i] = (1 << (this.precision - 1));
6004
5642
  }
5643
+
6005
5644
  if (this.restartInterval === 0) {
6006
- current = this.decodeUnit(pred, temp, index);
6007
- while (current === 0 && (this.xLoc < this.xDim && this.yLoc < this.yDim)) {
6008
- this.output(pred);
6009
5645
  current = this.decodeUnit(pred, temp, index);
6010
- }
6011
- break;
5646
+
5647
+ while ((current === 0) && ((this.xLoc < this.xDim) && (this.yLoc < this.yDim))) {
5648
+ this.output(pred);
5649
+ current = this.decodeUnit(pred, temp, index);
5650
+ }
5651
+
5652
+ break; //current=MARKER
6012
5653
  }
6013
- for (mcuNum = 0; mcuNum < this.restartInterval; mcuNum += 1) {
6014
- this.restarting = mcuNum == 0;
6015
- current = this.decodeUnit(pred, temp, index);
6016
- this.output(pred);
6017
- if (current !== 0) {
6018
- break;
6019
- }
5654
+
5655
+ for (mcuNum = 0; mcuNum < this.restartInterval; mcuNum+=1) {
5656
+ this.restarting = (mcuNum == 0);
5657
+ current = this.decodeUnit(pred, temp, index);
5658
+ this.output(pred);
5659
+
5660
+ if (current !== 0) {
5661
+ break;
5662
+ }
6020
5663
  }
5664
+
6021
5665
  if (current === 0) {
6022
- if (this.markerIndex !== 0) {
6023
- current = 65280 | this.marker;
6024
- this.markerIndex = 0;
6025
- } else {
6026
- current = this.stream.get16();
6027
- }
5666
+ if (this.markerIndex !== 0) {
5667
+ current = (0xFF00 | this.marker);
5668
+ this.markerIndex = 0;
5669
+ } else {
5670
+ current = this.stream.get16();
5671
+ }
6028
5672
  }
6029
- if (!(current >= jpeg.lossless.Decoder.RESTART_MARKER_BEGIN && current <= jpeg.lossless.Decoder.RESTART_MARKER_END)) {
6030
- break;
5673
+
5674
+ if (!((current >= jpeg.lossless.Decoder.RESTART_MARKER_BEGIN) &&
5675
+ (current <= jpeg.lossless.Decoder.RESTART_MARKER_END))) {
5676
+ break; //current=MARKER
6031
5677
  }
6032
- }
6033
- if (current === 65500 && scanNum === 1) {
5678
+ }
5679
+
5680
+ if ((current === 0xFFDC) && (scanNum === 1)) { //DNL
6034
5681
  this.readNumber();
6035
5682
  current = this.stream.get16();
6036
- }
6037
- } while (current !== 65497 && (this.xLoc < this.xDim && this.yLoc < this.yDim) && scanNum === 0);
6038
- return this.outputData;
6039
- };
6040
- jpeg.lossless.Decoder.prototype.decodeUnit = function(prev, temp, index) {
6041
- if (this.numComp == 1) {
6042
- return this.decodeSingle(prev, temp, index);
6043
- } else if (this.numComp == 3) {
6044
- return this.decodeRGB(prev, temp, index);
6045
- } else {
6046
- return -1;
6047
5683
  }
6048
- };
6049
- jpeg.lossless.Decoder.prototype.select1 = function(compOffset) {
6050
- return this.getPreviousX(compOffset);
6051
- };
6052
- jpeg.lossless.Decoder.prototype.select2 = function(compOffset) {
6053
- return this.getPreviousY(compOffset);
6054
- };
6055
- jpeg.lossless.Decoder.prototype.select3 = function(compOffset) {
6056
- return this.getPreviousXY(compOffset);
6057
- };
6058
- jpeg.lossless.Decoder.prototype.select4 = function(compOffset) {
6059
- return this.getPreviousX(compOffset) + this.getPreviousY(compOffset) - this.getPreviousXY(compOffset);
6060
- };
6061
- jpeg.lossless.Decoder.prototype.select5 = function(compOffset) {
6062
- return this.getPreviousX(compOffset) + (this.getPreviousY(compOffset) - this.getPreviousXY(compOffset) >> 1);
6063
- };
6064
- jpeg.lossless.Decoder.prototype.select6 = function(compOffset) {
6065
- return this.getPreviousY(compOffset) + (this.getPreviousX(compOffset) - this.getPreviousXY(compOffset) >> 1);
6066
- };
6067
- jpeg.lossless.Decoder.prototype.select7 = function(compOffset) {
6068
- return (this.getPreviousX(compOffset) + this.getPreviousY(compOffset)) / 2;
6069
- };
6070
- jpeg.lossless.Decoder.prototype.decodeRGB = function(prev, temp, index) {
6071
- var value, actab, dctab, qtab, ctrC, i, k, j;
6072
- prev[0] = this.selector(0);
6073
- prev[1] = this.selector(1);
6074
- prev[2] = this.selector(2);
6075
- for (ctrC = 0; ctrC < this.numComp; ctrC += 1) {
6076
- qtab = this.qTab[ctrC];
6077
- actab = this.acTab[ctrC];
6078
- dctab = this.dcTab[ctrC];
6079
- for (i = 0; i < this.nBlock[ctrC]; i += 1) {
6080
- for (k = 0; k < this.IDCT_Source.length; k += 1) {
6081
- this.IDCT_Source[k] = 0;
5684
+ } while ((current !== 0xFFD9) && ((this.xLoc < this.xDim) && (this.yLoc < this.yDim)) && (scanNum === 0));
5685
+
5686
+ return this.outputData;
5687
+ };
5688
+
5689
+
5690
+
5691
+ jpeg.lossless.Decoder.prototype.decodeUnit = function (prev, temp, index) {
5692
+ if (this.numComp == 1) {
5693
+ return this.decodeSingle(prev, temp, index);
5694
+ } else if (this.numComp == 3) {
5695
+ return this.decodeRGB(prev, temp, index);
5696
+ } else {
5697
+ return -1;
5698
+ }
5699
+ };
5700
+
5701
+
5702
+
5703
+ jpeg.lossless.Decoder.prototype.select1 = function (compOffset) {
5704
+ return this.getPreviousX(compOffset);
5705
+ };
5706
+
5707
+
5708
+
5709
+ jpeg.lossless.Decoder.prototype.select2 = function (compOffset) {
5710
+ return this.getPreviousY(compOffset);
5711
+ };
5712
+
5713
+
5714
+
5715
+ jpeg.lossless.Decoder.prototype.select3 = function (compOffset) {
5716
+ return this.getPreviousXY(compOffset);
5717
+ };
5718
+
5719
+
5720
+
5721
+ jpeg.lossless.Decoder.prototype.select4 = function (compOffset) {
5722
+ return (this.getPreviousX(compOffset) + this.getPreviousY(compOffset)) - this.getPreviousXY(compOffset);
5723
+ };
5724
+
5725
+
5726
+
5727
+ jpeg.lossless.Decoder.prototype.select5 = function (compOffset) {
5728
+ return this.getPreviousX(compOffset) + ((this.getPreviousY(compOffset) - this.getPreviousXY(compOffset)) >> 1);
5729
+ };
5730
+
5731
+
5732
+
5733
+ jpeg.lossless.Decoder.prototype.select6 = function (compOffset) {
5734
+ return this.getPreviousY(compOffset) + ((this.getPreviousX(compOffset) - this.getPreviousXY(compOffset)) >> 1);
5735
+ };
5736
+
5737
+
5738
+
5739
+ jpeg.lossless.Decoder.prototype.select7 = function (compOffset) {
5740
+ return ((this.getPreviousX(compOffset) + this.getPreviousY(compOffset)) / 2);
5741
+ };
5742
+
5743
+
5744
+
5745
+ jpeg.lossless.Decoder.prototype.decodeRGB = function (prev, temp, index) {
5746
+ /*jslint bitwise: true */
5747
+
5748
+ var value, actab, dctab, qtab, ctrC, i, k, j;
5749
+
5750
+ prev[0] = this.selector(0);
5751
+ prev[1] = this.selector(1);
5752
+ prev[2] = this.selector(2);
5753
+
5754
+ for (ctrC = 0; ctrC < this.numComp; ctrC+=1) {
5755
+ qtab = this.qTab[ctrC];
5756
+ actab = this.acTab[ctrC];
5757
+ dctab = this.dcTab[ctrC];
5758
+ for (i = 0; i < this.nBlock[ctrC]; i+=1) {
5759
+ for (k = 0; k < this.IDCT_Source.length; k+=1) {
5760
+ this.IDCT_Source[k] = 0;
6082
5761
  }
5762
+
6083
5763
  value = this.getHuffmanValue(dctab, temp, index);
6084
- if (value >= 65280) {
6085
- return value;
5764
+
5765
+ if (value >= 0xFF00) {
5766
+ return value;
6086
5767
  }
5768
+
6087
5769
  prev[ctrC] = this.IDCT_Source[0] = prev[ctrC] + this.getn(index, value, temp, index);
6088
5770
  this.IDCT_Source[0] *= qtab[0];
6089
- for (j = 1; j < 64; j += 1) {
6090
- value = this.getHuffmanValue(actab, temp, index);
6091
- if (value >= 65280) {
6092
- return value;
6093
- }
6094
- j += value >> 4;
6095
- if ((value & 15) === 0) {
6096
- if (value >> 4 === 0) {
6097
- break;
5771
+
5772
+ for (j = 1; j < 64; j+=1) {
5773
+ value = this.getHuffmanValue(actab, temp, index);
5774
+
5775
+ if (value >= 0xFF00) {
5776
+ return value;
5777
+ }
5778
+
5779
+ j += (value >> 4);
5780
+
5781
+ if ((value & 0x0F) === 0) {
5782
+ if ((value >> 4) === 0) {
5783
+ break;
5784
+ }
5785
+ } else {
5786
+ this.IDCT_Source[jpeg.lossless.Decoder.IDCT_P[j]] = this.getn(index, value & 0x0F, temp, index) * qtab[j];
6098
5787
  }
6099
- } else {
6100
- this.IDCT_Source[jpeg.lossless.Decoder.IDCT_P[j]] = this.getn(index, value & 15, temp, index) * qtab[j];
6101
- }
6102
5788
  }
6103
- }
6104
- }
6105
- return 0;
6106
- };
6107
- jpeg.lossless.Decoder.prototype.decodeSingle = function(prev, temp, index) {
6108
- var value, i, n, nRestart;
6109
- if (this.restarting) {
6110
- this.restarting = false;
6111
- prev[0] = 1 << this.frame.precision - 1;
6112
- } else {
6113
- prev[0] = this.selector();
6114
5789
  }
6115
- for (i = 0; i < this.nBlock[0]; i += 1) {
6116
- value = this.getHuffmanValue(this.dcTab[0], temp, index);
6117
- if (value >= 65280) {
5790
+ }
5791
+
5792
+ return 0;
5793
+ };
5794
+
5795
+
5796
+
5797
+ jpeg.lossless.Decoder.prototype.decodeSingle = function (prev, temp, index) {
5798
+ /*jslint bitwise: true */
5799
+
5800
+ var value, i, n, nRestart;
5801
+
5802
+ if (this.restarting) {
5803
+ this.restarting = false;
5804
+ prev[0] = (1 << (this.frame.precision - 1));
5805
+ } else {
5806
+ prev[0] = this.selector();
5807
+ }
5808
+
5809
+ for (i = 0; i < this.nBlock[0]; i+=1) {
5810
+ value = this.getHuffmanValue(this.dcTab[0], temp, index);
5811
+ if (value >= 0xFF00) {
6118
5812
  return value;
6119
- }
6120
- n = this.getn(prev, value, temp, index);
6121
- nRestart = n >> 8;
6122
- if (nRestart >= jpeg.lossless.Decoder.RESTART_MARKER_BEGIN && nRestart <= jpeg.lossless.Decoder.RESTART_MARKER_END) {
5813
+ }
5814
+
5815
+ n = this.getn(prev, value, temp, index);
5816
+ nRestart = (n >> 8);
5817
+
5818
+ if ((nRestart >= jpeg.lossless.Decoder.RESTART_MARKER_BEGIN) && (nRestart <= jpeg.lossless.Decoder.RESTART_MARKER_END)) {
6123
5819
  return nRestart;
6124
- }
6125
- prev[0] += n;
6126
5820
  }
6127
- return 0;
6128
- };
6129
- jpeg.lossless.Decoder.prototype.getHuffmanValue = function(table, temp, index) {
6130
- var code, input, mask;
6131
- mask = 65535;
6132
- if (index[0] < 8) {
6133
- temp[0] <<= 8;
6134
- input = this.stream.get8();
6135
- if (input === 255) {
5821
+
5822
+ prev[0] += n;
5823
+ }
5824
+
5825
+ return 0;
5826
+ };
5827
+
5828
+
5829
+
5830
+ // Huffman table for fast search: (HuffTab) 8-bit Look up table 2-layer search architecture, 1st-layer represent 256 node (8 bits) if codeword-length > 8
5831
+ // bits, then the entry of 1st-layer = (# of 2nd-layer table) | MSB and it is stored in the 2nd-layer Size of tables in each layer are 256.
5832
+ // HuffTab[*][*][0-256] is always the only 1st-layer table.
5833
+ //
5834
+ // An entry can be: (1) (# of 2nd-layer table) | MSB , for code length > 8 in 1st-layer (2) (Code length) << 8 | HuffVal
5835
+ //
5836
+ // HuffmanValue(table HuffTab[x][y] (ex) HuffmanValue(HuffTab[1][0],...)
5837
+ // ):
5838
+ // return: Huffman Value of table
5839
+ // 0xFF?? if it receives a MARKER
5840
+ // Parameter: table HuffTab[x][y] (ex) HuffmanValue(HuffTab[1][0],...)
5841
+ // temp temp storage for remainded bits
5842
+ // index index to bit of temp
5843
+ // in FILE pointer
5844
+ // Effect:
5845
+ // temp store new remainded bits
5846
+ // index change to new index
5847
+ // in change to new position
5848
+ // NOTE:
5849
+ // Initial by temp=0; index=0;
5850
+ // NOTE: (explain temp and index)
5851
+ // temp: is always in the form at calling time or returning time
5852
+ // | byte 4 | byte 3 | byte 2 | byte 1 |
5853
+ // | 0 | 0 | 00000000 | 00000??? | if not a MARKER
5854
+ // ^index=3 (from 0 to 15)
5855
+ // 321
5856
+ // NOTE (marker and marker_index):
5857
+ // If get a MARKER from 'in', marker=the low-byte of the MARKER
5858
+ // and marker_index=9
5859
+ // If marker_index=9 then index is always > 8, or HuffmanValue()
5860
+ // will not be called
5861
+ jpeg.lossless.Decoder.prototype.getHuffmanValue = function (table, temp, index) {
5862
+ /*jslint bitwise: true */
5863
+
5864
+ var code, input, mask;
5865
+ mask = 0xFFFF;
5866
+
5867
+ if (index[0] < 8) {
5868
+ temp[0] <<= 8;
5869
+ input = this.stream.get8();
5870
+ if (input === 0xFF) {
6136
5871
  this.marker = this.stream.get8();
6137
5872
  if (this.marker !== 0) {
6138
- this.markerIndex = 9;
5873
+ this.markerIndex = 9;
6139
5874
  }
6140
- }
6141
- temp[0] |= input;
6142
- } else {
6143
- index[0] -= 8;
6144
5875
  }
6145
- code = table[temp[0] >> index[0]];
6146
- if ((code & jpeg.lossless.Decoder.MSB) !== 0) {
6147
- if (this.markerIndex !== 0) {
5876
+ temp[0] |= input;
5877
+ } else {
5878
+ index[0] -= 8;
5879
+ }
5880
+
5881
+ code = table[temp[0] >> index[0]];
5882
+
5883
+ if ((code & jpeg.lossless.Decoder.MSB) !== 0) {
5884
+ if (this.markerIndex !== 0) {
6148
5885
  this.markerIndex = 0;
6149
- return 65280 | this.marker;
6150
- }
6151
- temp[0] &= mask >> 16 - index[0];
6152
- temp[0] <<= 8;
6153
- input = this.stream.get8();
6154
- if (input === 255) {
5886
+ return 0xFF00 | this.marker;
5887
+ }
5888
+
5889
+ temp[0] &= (mask >> (16 - index[0]));
5890
+ temp[0] <<= 8;
5891
+ input = this.stream.get8();
5892
+
5893
+ if (input === 0xFF) {
6155
5894
  this.marker = this.stream.get8();
6156
5895
  if (this.marker !== 0) {
6157
- this.markerIndex = 9;
5896
+ this.markerIndex = 9;
6158
5897
  }
6159
- }
6160
- temp[0] |= input;
6161
- code = table[(code & 255) * 256 + (temp[0] >> index[0])];
6162
- index[0] += 8;
6163
- }
6164
- index[0] += 8 - (code >> 8);
6165
- if (index[0] < 0) {
6166
- throw new Error("index=" + index[0] + " temp=" + temp[0] + " code=" + code + " in HuffmanValue()");
6167
- }
6168
- if (index[0] < this.markerIndex) {
6169
- this.markerIndex = 0;
6170
- return 65280 | this.marker;
6171
- }
6172
- temp[0] &= mask >> 16 - index[0];
6173
- return code & 255;
6174
- };
6175
- jpeg.lossless.Decoder.prototype.getn = function(PRED, n, temp, index) {
6176
- var result, one, n_one, mask, input;
6177
- one = 1;
6178
- n_one = -1;
6179
- mask = 65535;
6180
- if (n === 0) {
6181
- return 0;
6182
5898
  }
6183
- if (n === 16) {
6184
- if (PRED[0] >= 0) {
5899
+
5900
+ temp[0] |= input;
5901
+ code = table[((code & 0xFF) * 256) + (temp[0] >> index[0])];
5902
+ index[0] += 8;
5903
+ }
5904
+
5905
+ index[0] += 8 - (code >> 8);
5906
+
5907
+ if (index[0] < 0) {
5908
+ throw new Error("index=" + index[0] + " temp=" + temp[0] + " code=" + code + " in HuffmanValue()");
5909
+ }
5910
+
5911
+ if (index[0] < this.markerIndex) {
5912
+ this.markerIndex = 0;
5913
+ return 0xFF00 | this.marker;
5914
+ }
5915
+
5916
+ temp[0] &= (mask >> (16 - index[0]));
5917
+ return code & 0xFF;
5918
+ };
5919
+
5920
+
5921
+
5922
+ jpeg.lossless.Decoder.prototype.getn = function (PRED, n, temp, index) {
5923
+ /*jslint bitwise: true */
5924
+
5925
+ var result, one, n_one, mask, input;
5926
+ one = 1;
5927
+ n_one = -1;
5928
+ mask = 0xFFFF;
5929
+
5930
+ if (n === 0) {
5931
+ return 0;
5932
+ }
5933
+
5934
+ if (n === 16) {
5935
+ if (PRED[0] >= 0) {
6185
5936
  return -32768;
6186
- } else {
5937
+ } else {
6187
5938
  return 32768;
6188
- }
6189
5939
  }
6190
- index[0] -= n;
6191
- if (index[0] >= 0) {
6192
- if (index[0] < this.markerIndex && !this.isLastPixel()) {
5940
+ }
5941
+
5942
+ index[0] -= n;
5943
+
5944
+ if (index[0] >= 0) {
5945
+ if ((index[0] < this.markerIndex) && !this.isLastPixel()) { // this was corrupting the last pixel in some cases
6193
5946
  this.markerIndex = 0;
6194
- return (65280 | this.marker) << 8;
6195
- }
6196
- result = temp[0] >> index[0];
6197
- temp[0] &= mask >> 16 - index[0];
6198
- } else {
6199
- temp[0] <<= 8;
6200
- input = this.stream.get8();
6201
- if (input === 255) {
5947
+ return (0xFF00 | this.marker) << 8;
5948
+ }
5949
+
5950
+ result = temp[0] >> index[0];
5951
+ temp[0] &= (mask >> (16 - index[0]));
5952
+ } else {
5953
+ temp[0] <<= 8;
5954
+ input = this.stream.get8();
5955
+
5956
+ if (input === 0xFF) {
6202
5957
  this.marker = this.stream.get8();
6203
5958
  if (this.marker !== 0) {
6204
- this.markerIndex = 9;
5959
+ this.markerIndex = 9;
6205
5960
  }
6206
- }
6207
- temp[0] |= input;
6208
- index[0] += 8;
6209
- if (index[0] < 0) {
5961
+ }
5962
+
5963
+ temp[0] |= input;
5964
+ index[0] += 8;
5965
+
5966
+ if (index[0] < 0) {
6210
5967
  if (this.markerIndex !== 0) {
6211
- this.markerIndex = 0;
6212
- return (65280 | this.marker) << 8;
5968
+ this.markerIndex = 0;
5969
+ return (0xFF00 | this.marker) << 8;
6213
5970
  }
5971
+
6214
5972
  temp[0] <<= 8;
6215
5973
  input = this.stream.get8();
6216
- if (input === 255) {
6217
- this.marker = this.stream.get8();
6218
- if (this.marker !== 0) {
6219
- this.markerIndex = 9;
6220
- }
5974
+
5975
+ if (input === 0xFF) {
5976
+ this.marker = this.stream.get8();
5977
+ if (this.marker !== 0) {
5978
+ this.markerIndex = 9;
5979
+ }
6221
5980
  }
5981
+
6222
5982
  temp[0] |= input;
6223
5983
  index[0] += 8;
6224
- }
6225
- if (index[0] < 0) {
6226
- throw new Error("index=" + index[0] + " in getn()");
6227
- }
6228
- if (index[0] < this.markerIndex) {
6229
- this.markerIndex = 0;
6230
- return (65280 | this.marker) << 8;
6231
- }
6232
- result = temp[0] >> index[0];
6233
- temp[0] &= mask >> 16 - index[0];
6234
- }
6235
- if (result < one << n - 1) {
6236
- result += (n_one << n) + 1;
6237
- }
6238
- return result;
6239
- };
6240
- jpeg.lossless.Decoder.prototype.getPreviousX = function(compOffset) {
6241
- if (this.xLoc > 0) {
6242
- return this.getter(this.yLoc * this.xDim + this.xLoc - 1, compOffset);
6243
- } else if (this.yLoc > 0) {
6244
- return this.getPreviousY(compOffset);
6245
- } else {
6246
- return 1 << this.frame.precision - 1;
6247
- }
6248
- };
6249
- jpeg.lossless.Decoder.prototype.getPreviousXY = function(compOffset) {
6250
- if (this.xLoc > 0 && this.yLoc > 0) {
6251
- return this.getter((this.yLoc - 1) * this.xDim + this.xLoc - 1, compOffset);
6252
- } else {
6253
- return this.getPreviousY(compOffset);
6254
- }
6255
- };
6256
- jpeg.lossless.Decoder.prototype.getPreviousY = function(compOffset) {
6257
- if (this.yLoc > 0) {
6258
- return this.getter((this.yLoc - 1) * this.xDim + this.xLoc, compOffset);
6259
- } else {
6260
- return this.getPreviousX(compOffset);
6261
- }
6262
- };
6263
- jpeg.lossless.Decoder.prototype.isLastPixel = function() {
6264
- return this.xLoc === this.xDim - 1 && this.yLoc === this.yDim - 1;
6265
- };
6266
- jpeg.lossless.Decoder.prototype.outputSingle = function(PRED) {
6267
- if (this.xLoc < this.xDim && this.yLoc < this.yDim) {
6268
- this.setter(this.yLoc * this.xDim + this.xLoc, this.mask & PRED[0]);
6269
- this.xLoc += 1;
6270
- if (this.xLoc >= this.xDim) {
6271
- this.yLoc += 1;
6272
- this.xLoc = 0;
6273
- }
6274
- }
6275
- };
6276
- jpeg.lossless.Decoder.prototype.outputRGB = function(PRED) {
6277
- var offset = this.yLoc * this.xDim + this.xLoc;
6278
- if (this.xLoc < this.xDim && this.yLoc < this.yDim) {
6279
- this.setter(offset, PRED[0], 0);
6280
- this.setter(offset, PRED[1], 1);
6281
- this.setter(offset, PRED[2], 2);
6282
- this.xLoc += 1;
6283
- if (this.xLoc >= this.xDim) {
6284
- this.yLoc += 1;
6285
- this.xLoc = 0;
6286
- }
6287
- }
6288
- };
6289
- jpeg.lossless.Decoder.prototype.setValue8 = function(index, val) {
6290
- this.outputData[index] = val;
6291
- };
6292
- jpeg.lossless.Decoder.prototype.getValue8 = function(index) {
6293
- return this.outputData[index];
6294
- };
6295
- var littleEndian = function() {
6296
- var buffer = new ArrayBuffer(2);
6297
- new DataView(buffer).setInt16(
6298
- 0,
6299
- 256,
6300
- true
6301
- /* littleEndian */
6302
- );
6303
- return new Int16Array(buffer)[0] === 256;
6304
- }();
6305
- if (littleEndian) {
6306
- jpeg.lossless.Decoder.prototype.setValue16 = jpeg.lossless.Decoder.prototype.setValue8;
6307
- jpeg.lossless.Decoder.prototype.getValue16 = jpeg.lossless.Decoder.prototype.getValue8;
6308
- } else {
6309
- jpeg.lossless.Decoder.prototype.setValue16 = function(index, val) {
6310
- this.outputData[index] = (val & 255) << 8 | val >> 8 & 255;
6311
- };
6312
- jpeg.lossless.Decoder.prototype.getValue16 = function(index) {
6313
- var val = this.outputData[index];
6314
- return (val & 255) << 8 | val >> 8 & 255;
6315
- };
6316
- }
6317
- jpeg.lossless.Decoder.prototype.setValueRGB = function(index, val, compOffset) {
6318
- this.outputData[index * 3 + compOffset] = val;
6319
- };
6320
- jpeg.lossless.Decoder.prototype.getValueRGB = function(index, compOffset) {
6321
- return this.outputData[index * 3 + compOffset];
6322
- };
6323
- jpeg.lossless.Decoder.prototype.readApp = function() {
6324
- var count = 0, length = this.stream.get16();
6325
- count += 2;
6326
- while (count < length) {
6327
- this.stream.get8();
6328
- count += 1;
6329
5984
  }
6330
- return length;
6331
- };
6332
- jpeg.lossless.Decoder.prototype.readComment = function() {
6333
- var sb = "", count = 0, length;
6334
- length = this.stream.get16();
6335
- count += 2;
6336
- while (count < length) {
6337
- sb += this.stream.get8();
6338
- count += 1;
5985
+
5986
+ if (index[0] < 0) {
5987
+ throw new Error("index=" + index[0] + " in getn()");
6339
5988
  }
6340
- return sb;
6341
- };
6342
- jpeg.lossless.Decoder.prototype.readNumber = function() {
6343
- var Ld = this.stream.get16();
6344
- if (Ld !== 4) {
6345
- throw new Error("ERROR: Define number format throw new IOException [Ld!=4]");
5989
+
5990
+ if (index[0] < this.markerIndex) {
5991
+ this.markerIndex = 0;
5992
+ return (0xFF00 | this.marker) << 8;
6346
5993
  }
6347
- return this.stream.get16();
6348
- };
6349
- var moduleType = typeof module;
6350
- if (moduleType !== "undefined" && module.exports) {
6351
- module.exports = jpeg.lossless.Decoder;
6352
- }
5994
+
5995
+ result = temp[0] >> index[0];
5996
+ temp[0] &= (mask >> (16 - index[0]));
6353
5997
  }
6354
- });
6355
-
6356
- // src/main.js
6357
- var require_main = __commonJS({
6358
- "src/main.js"(exports, module) {
6359
- var jpeg = jpeg || {};
6360
- jpeg.lossless = jpeg.lossless || {};
6361
- jpeg.lossless.ComponentSpec = jpeg.lossless.ComponentSpec || (typeof __require !== "undefined" ? require_component_spec() : null);
6362
- jpeg.lossless.DataStream = jpeg.lossless.DataStream || (typeof __require !== "undefined" ? require_data_stream() : null);
6363
- jpeg.lossless.Decoder = jpeg.lossless.Decoder || (typeof __require !== "undefined" ? require_decoder() : null);
6364
- jpeg.lossless.FrameHeader = jpeg.lossless.FrameHeader || (typeof __require !== "undefined" ? require_frame_header() : null);
6365
- jpeg.lossless.HuffmanTable = jpeg.lossless.HuffmanTable || (typeof __require !== "undefined" ? require_huffman_table() : null);
6366
- jpeg.lossless.QuantizationTable = jpeg.lossless.QuantizationTable || (typeof __require !== "undefined" ? require_quantization_table() : null);
6367
- jpeg.lossless.ScanComponent = jpeg.lossless.ScanComponent || (typeof __require !== "undefined" ? require_scan_component() : null);
6368
- jpeg.lossless.ScanHeader = jpeg.lossless.ScanHeader || (typeof __require !== "undefined" ? require_scan_header() : null);
6369
- jpeg.lossless.Utils = jpeg.lossless.Utils || (typeof __require !== "undefined" ? require_utils() : null);
6370
- var moduleType = typeof module;
6371
- if (moduleType !== "undefined" && module.exports) {
6372
- module.exports = jpeg;
6373
- }
5998
+
5999
+ if (result < (one << (n - 1))) {
6000
+ result += (n_one << n) + 1;
6374
6001
  }
6375
- });
6376
- require_main();
6377
- })();
6002
+
6003
+ return result;
6004
+ };
6005
+
6006
+
6007
+
6008
+ jpeg.lossless.Decoder.prototype.getPreviousX = function (compOffset) {
6009
+ /*jslint bitwise: true */
6010
+
6011
+ if (this.xLoc > 0) {
6012
+ return this.getter((((this.yLoc * this.xDim) + this.xLoc) - 1), compOffset);
6013
+ } else if (this.yLoc > 0) {
6014
+ return this.getPreviousY(compOffset);
6015
+ } else {
6016
+ return (1 << (this.frame.precision - 1));
6017
+ }
6018
+ };
6019
+
6020
+
6021
+
6022
+ jpeg.lossless.Decoder.prototype.getPreviousXY = function (compOffset) {
6023
+ /*jslint bitwise: true */
6024
+
6025
+ if ((this.xLoc > 0) && (this.yLoc > 0)) {
6026
+ return this.getter(((((this.yLoc - 1) * this.xDim) + this.xLoc) - 1), compOffset);
6027
+ } else {
6028
+ return this.getPreviousY(compOffset);
6029
+ }
6030
+ };
6031
+
6032
+
6033
+
6034
+ jpeg.lossless.Decoder.prototype.getPreviousY = function (compOffset) {
6035
+ /*jslint bitwise: true */
6036
+
6037
+ if (this.yLoc > 0) {
6038
+ return this.getter((((this.yLoc - 1) * this.xDim) + this.xLoc), compOffset);
6039
+ } else {
6040
+ return this.getPreviousX(compOffset);
6041
+ }
6042
+ };
6043
+
6044
+
6045
+
6046
+ jpeg.lossless.Decoder.prototype.isLastPixel = function () {
6047
+ return (this.xLoc === (this.xDim - 1)) && (this.yLoc === (this.yDim - 1));
6048
+ };
6049
+
6050
+
6051
+
6052
+ jpeg.lossless.Decoder.prototype.outputSingle = function (PRED) {
6053
+ if ((this.xLoc < this.xDim) && (this.yLoc < this.yDim)) {
6054
+ this.setter((((this.yLoc * this.xDim) + this.xLoc)), this.mask & PRED[0]);
6055
+
6056
+ this.xLoc+=1;
6057
+
6058
+ if (this.xLoc >= this.xDim) {
6059
+ this.yLoc+=1;
6060
+ this.xLoc = 0;
6061
+ }
6062
+ }
6063
+ };
6064
+
6065
+
6066
+
6067
+ jpeg.lossless.Decoder.prototype.outputRGB = function (PRED) {
6068
+ var offset = ((this.yLoc * this.xDim) + this.xLoc);
6069
+
6070
+ if ((this.xLoc < this.xDim) && (this.yLoc < this.yDim)) {
6071
+ this.setter(offset, PRED[0], 0);
6072
+ this.setter(offset, PRED[1], 1);
6073
+ this.setter(offset, PRED[2], 2);
6074
+
6075
+ this.xLoc+=1;
6076
+
6077
+ if (this.xLoc >= this.xDim) {
6078
+ this.yLoc+=1;
6079
+ this.xLoc = 0;
6080
+ }
6081
+ }
6082
+ };
6083
+
6084
+ jpeg.lossless.Decoder.prototype.setValue8 = function (index, val) {
6085
+ this.outputData[index] = val;
6086
+ };
6087
+
6088
+ jpeg.lossless.Decoder.prototype.getValue8 = function (index) {
6089
+ return this.outputData[index]; // mask should not be necessary because outputData is either Int8Array or Int16Array
6090
+ };
6091
+
6092
+ var littleEndian = (function() {
6093
+ var buffer = new ArrayBuffer(2);
6094
+ new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
6095
+ // Int16Array uses the platform's endianness.
6096
+ return new Int16Array(buffer)[0] === 256;
6097
+ })();
6098
+
6099
+ if (littleEndian) {
6100
+ // just reading from an array is fine then. Int16Array will use platform endianness.
6101
+ jpeg.lossless.Decoder.prototype.setValue16 = jpeg.lossless.Decoder.prototype.setValue8;
6102
+ jpeg.lossless.Decoder.prototype.getValue16 = jpeg.lossless.Decoder.prototype.getValue8;
6103
+ }
6104
+ else {
6105
+ // If platform is big-endian, we will need to convert to little-endian
6106
+ jpeg.lossless.Decoder.prototype.setValue16 = function (index, val) {
6107
+ this.outputData[index] = ((val & 0xFF) << 8) | ((val >> 8) & 0xFF);
6108
+ };
6109
+
6110
+ jpeg.lossless.Decoder.prototype.getValue16 = function (index) {
6111
+ var val = this.outputData[index];
6112
+ return ((val & 0xFF) << 8) | ((val >> 8) & 0xFF);
6113
+ };
6114
+ }
6115
+
6116
+ jpeg.lossless.Decoder.prototype.setValueRGB = function (index, val, compOffset) {
6117
+ // this.outputData.setUint8(index * 3 + compOffset, val);
6118
+ this.outputData[index * 3 + compOffset] = val;
6119
+ };
6120
+
6121
+ jpeg.lossless.Decoder.prototype.getValueRGB = function (index, compOffset) {
6122
+ // return this.outputData.getUint8(index * 3 + compOffset);
6123
+ return this.outputData[index * 3 + compOffset];
6124
+ };
6125
+
6126
+
6127
+
6128
+ jpeg.lossless.Decoder.prototype.readApp = function() {
6129
+ var count = 0, length = this.stream.get16();
6130
+ count += 2;
6131
+
6132
+ while (count < length) {
6133
+ this.stream.get8();
6134
+ count+=1;
6135
+ }
6136
+
6137
+ return length;
6138
+ };
6139
+
6140
+
6141
+
6142
+ jpeg.lossless.Decoder.prototype.readComment = function () {
6143
+ var sb = "", count = 0, length;
6144
+
6145
+ length = this.stream.get16();
6146
+ count += 2;
6147
+
6148
+ while (count < length) {
6149
+ sb += this.stream.get8();
6150
+ count+=1;
6151
+ }
6152
+
6153
+ return sb;
6154
+ };
6155
+
6156
+
6157
+
6158
+ jpeg.lossless.Decoder.prototype.readNumber = function() {
6159
+ var Ld = this.stream.get16();
6160
+
6161
+ if (Ld !== 4) {
6162
+ throw new Error("ERROR: Define number format throw new IOException [Ld!=4]");
6163
+ }
6164
+
6165
+ return this.stream.get16();
6166
+ };
6167
+
6168
+
6169
+
6170
+ /*** Exports ***/
6171
+
6172
+ var moduleType = typeof module;
6173
+ if ((moduleType !== 'undefined') && module.exports) {
6174
+ module.exports = jpeg.lossless.Decoder;
6175
+ }
6176
+
6177
+ },{"./data-stream.js":2,"./frame-header.js":4,"./huffman-table.js":5,"./quantization-table.js":7,"./scan-header.js":9,"./utils.js":10}],4:[function(require,module,exports){
6178
+ /*
6179
+ * Copyright (C) 2015 Michael Martinez
6180
+ * Changes: Added support for selection values 2-7, fixed minor bugs &
6181
+ * warnings, split into multiple class files, and general clean up.
6182
+ *
6183
+ * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
6184
+ */
6185
+
6186
+ /*
6187
+ * Copyright (C) Helmut Dersch
6188
+ *
6189
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6190
+ * of this software and associated documentation files (the "Software"), to deal
6191
+ * in the Software without restriction, including without limitation the rights
6192
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6193
+ * copies of the Software, and to permit persons to whom the Software is
6194
+ * furnished to do so, subject to the following conditions:
6195
+
6196
+ * The above copyright notice and this permission notice shall be included in
6197
+ * all copies or substantial portions of the Software.
6198
+
6199
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6200
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6201
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6202
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6203
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
6204
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
6205
+ * THE SOFTWARE.
6206
+ */
6207
+
6208
+ /*jslint browser: true, node: true */
6209
+ /*global require, module */
6210
+
6211
+ "use strict";
6212
+
6213
+ /*** Imports ***/
6214
+ var jpeg = jpeg || {};
6215
+ jpeg.lossless = jpeg.lossless || {};
6216
+ jpeg.lossless.ComponentSpec = jpeg.lossless.ComponentSpec || ((typeof require !== 'undefined') ? require('./component-spec.js') : null);
6217
+ jpeg.lossless.DataStream = jpeg.lossless.DataStream || ((typeof require !== 'undefined') ? require('./data-stream.js') : null);
6218
+
6219
+
6220
+ /*** Constructor ***/
6221
+ jpeg.lossless.FrameHeader = jpeg.lossless.FrameHeader || function () {
6222
+ this.components = []; // Components
6223
+ this.dimX = 0; // Number of samples per line
6224
+ this.dimY = 0; // Number of lines
6225
+ this.numComp = 0; // Number of component in the frame
6226
+ this.precision = 0; // Sample Precision (from the original image)
6227
+ };
6228
+
6229
+
6230
+
6231
+ /*** Prototype Methods ***/
6232
+
6233
+ jpeg.lossless.FrameHeader.prototype.read = function (data) {
6234
+ /*jslint bitwise: true */
6235
+
6236
+ var count = 0, length, i, c, temp;
6237
+
6238
+ length = data.get16();
6239
+ count += 2;
6240
+
6241
+ this.precision = data.get8();
6242
+ count+=1;
6243
+
6244
+ this.dimY = data.get16();
6245
+ count += 2;
6246
+
6247
+ this.dimX = data.get16();
6248
+ count += 2;
6249
+
6250
+ this.numComp = data.get8();
6251
+ count+=1;
6252
+ for (i = 1; i <= this.numComp; i+=1) {
6253
+ if (count > length) {
6254
+ throw new Error("ERROR: frame format error");
6255
+ }
6256
+
6257
+ c = data.get8();
6258
+ count+=1;
6259
+
6260
+ if (count >= length) {
6261
+ throw new Error("ERROR: frame format error [c>=Lf]");
6262
+ }
6263
+
6264
+ temp = data.get8();
6265
+ count+=1;
6266
+
6267
+ if (!this.components[c]) {
6268
+ this.components[c] = new jpeg.lossless.ComponentSpec();
6269
+ }
6270
+
6271
+ this.components[c].hSamp = temp >> 4;
6272
+ this.components[c].vSamp = temp & 0x0F;
6273
+ this.components[c].quantTableSel = data.get8();
6274
+ count+=1;
6275
+ }
6276
+
6277
+ if (count !== length) {
6278
+ throw new Error("ERROR: frame format error [Lf!=count]");
6279
+ }
6280
+
6281
+ return 1;
6282
+ };
6283
+
6284
+
6285
+ /*** Exports ***/
6286
+
6287
+ var moduleType = typeof module;
6288
+ if ((moduleType !== 'undefined') && module.exports) {
6289
+ module.exports = jpeg.lossless.FrameHeader;
6290
+ }
6291
+
6292
+ },{"./component-spec.js":1,"./data-stream.js":2}],5:[function(require,module,exports){
6293
+ /*
6294
+ * Copyright (C) 2015 Michael Martinez
6295
+ * Changes: Added support for selection values 2-7, fixed minor bugs &
6296
+ * warnings, split into multiple class files, and general clean up.
6297
+ *
6298
+ * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
6299
+ */
6300
+
6301
+ /*
6302
+ * Copyright (C) Helmut Dersch
6303
+ *
6304
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6305
+ * of this software and associated documentation files (the "Software"), to deal
6306
+ * in the Software without restriction, including without limitation the rights
6307
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6308
+ * copies of the Software, and to permit persons to whom the Software is
6309
+ * furnished to do so, subject to the following conditions:
6310
+
6311
+ * The above copyright notice and this permission notice shall be included in
6312
+ * all copies or substantial portions of the Software.
6313
+
6314
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6315
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6316
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6317
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6318
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
6319
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
6320
+ * THE SOFTWARE.
6321
+ */
6322
+
6323
+ /*jslint browser: true, node: true */
6324
+ /*global require, module */
6325
+
6326
+ "use strict";
6327
+
6328
+ /*** Imports ***/
6329
+ var jpeg = jpeg || {};
6330
+ jpeg.lossless = jpeg.lossless || {};
6331
+ jpeg.lossless.DataStream = jpeg.lossless.DataStream || ((typeof require !== 'undefined') ? require('./data-stream.js') : null);
6332
+ jpeg.lossless.Utils = jpeg.lossless.Utils || ((typeof require !== 'undefined') ? require('./utils.js') : null);
6333
+
6334
+
6335
+ /*** Constructor ***/
6336
+ jpeg.lossless.HuffmanTable = jpeg.lossless.HuffmanTable || function () {
6337
+ this.l = jpeg.lossless.Utils.createArray(4, 2, 16);
6338
+ this.th = [];
6339
+ this.v = jpeg.lossless.Utils.createArray(4, 2, 16, 200);
6340
+ this.tc = jpeg.lossless.Utils.createArray(4, 2);
6341
+
6342
+ this.tc[0][0] = 0;
6343
+ this.tc[1][0] = 0;
6344
+ this.tc[2][0] = 0;
6345
+ this.tc[3][0] = 0;
6346
+ this.tc[0][1] = 0;
6347
+ this.tc[1][1] = 0;
6348
+ this.tc[2][1] = 0;
6349
+ this.tc[3][1] = 0;
6350
+ this.th[0] = 0;
6351
+ this.th[1] = 0;
6352
+ this.th[2] = 0;
6353
+ this.th[3] = 0;
6354
+ };
6355
+
6356
+
6357
+
6358
+ /*** Static Pseudo-constants ***/
6359
+
6360
+ jpeg.lossless.HuffmanTable.MSB = 0x80000000;
6361
+
6362
+
6363
+ /*** Prototype Methods ***/
6364
+
6365
+ jpeg.lossless.HuffmanTable.prototype.read = function(data, HuffTab) {
6366
+ /*jslint bitwise: true */
6367
+
6368
+ var count = 0, length, temp, t, c, i, j;
6369
+
6370
+ length = data.get16();
6371
+ count += 2;
6372
+
6373
+ while (count < length) {
6374
+ temp = data.get8();
6375
+ count+=1;
6376
+ t = temp & 0x0F;
6377
+ if (t > 3) {
6378
+ throw new Error("ERROR: Huffman table ID > 3");
6379
+ }
6380
+
6381
+ c = temp >> 4;
6382
+ if (c > 2) {
6383
+ throw new Error("ERROR: Huffman table [Table class > 2 ]");
6384
+ }
6385
+
6386
+ this.th[t] = 1;
6387
+ this.tc[t][c] = 1;
6388
+
6389
+ for (i = 0; i < 16; i+=1) {
6390
+ this.l[t][c][i] = data.get8();
6391
+ count+=1;
6392
+ }
6393
+
6394
+ for (i = 0; i < 16; i+=1) {
6395
+ for (j = 0; j < this.l[t][c][i]; j+=1) {
6396
+ if (count > length) {
6397
+ throw new Error("ERROR: Huffman table format error [count>Lh]");
6398
+ }
6399
+
6400
+ this.v[t][c][i][j] = data.get8();
6401
+ count+=1;
6402
+ }
6403
+ }
6404
+ }
6405
+
6406
+ if (count !== length) {
6407
+ throw new Error("ERROR: Huffman table format error [count!=Lf]");
6408
+ }
6409
+
6410
+ for (i = 0; i < 4; i+=1) {
6411
+ for (j = 0; j < 2; j+=1) {
6412
+ if (this.tc[i][j] !== 0) {
6413
+ this.buildHuffTable(HuffTab[i][j], this.l[i][j], this.v[i][j]);
6414
+ }
6415
+ }
6416
+ }
6417
+
6418
+ return 1;
6419
+ };
6420
+
6421
+
6422
+
6423
+ // Build_HuffTab()
6424
+ // Parameter: t table ID
6425
+ // c table class ( 0 for DC, 1 for AC )
6426
+ // L[i] # of codewords which length is i
6427
+ // V[i][j] Huffman Value (length=i)
6428
+ // Effect:
6429
+ // build up HuffTab[t][c] using L and V.
6430
+ jpeg.lossless.HuffmanTable.prototype.buildHuffTable = function(tab, L, V) {
6431
+ /*jslint bitwise: true */
6432
+
6433
+ var currentTable, temp, k, i, j, n;
6434
+ temp = 256;
6435
+ k = 0;
6436
+
6437
+ for (i = 0; i < 8; i+=1) { // i+1 is Code length
6438
+ for (j = 0; j < L[i]; j+=1) {
6439
+ for (n = 0; n < (temp >> (i + 1)); n+=1) {
6440
+ tab[k] = V[i][j] | ((i + 1) << 8);
6441
+ k+=1;
6442
+ }
6443
+ }
6444
+ }
6445
+
6446
+ for (i = 1; k < 256; i+=1, k+=1) {
6447
+ tab[k] = i | jpeg.lossless.HuffmanTable.MSB;
6448
+ }
6449
+
6450
+ currentTable = 1;
6451
+ k = 0;
6452
+
6453
+ for (i = 8; i < 16; i+=1) { // i+1 is Code length
6454
+ for (j = 0; j < L[i]; j+=1) {
6455
+ for (n = 0; n < (temp >> (i - 7)); n+=1) {
6456
+ tab[(currentTable * 256) + k] = V[i][j] | ((i + 1) << 8);
6457
+ k+=1;
6458
+ }
6459
+
6460
+ if (k >= 256) {
6461
+ if (k > 256) {
6462
+ throw new Error("ERROR: Huffman table error(1)!");
6463
+ }
6464
+
6465
+ k = 0;
6466
+ currentTable+=1;
6467
+ }
6468
+ }
6469
+ }
6470
+ };
6471
+
6472
+
6473
+ /*** Exports ***/
6474
+
6475
+ var moduleType = typeof module;
6476
+ if ((moduleType !== 'undefined') && module.exports) {
6477
+ module.exports = jpeg.lossless.HuffmanTable;
6478
+ }
6479
+
6480
+ },{"./data-stream.js":2,"./utils.js":10}],6:[function(require,module,exports){
6481
+ /*jslint browser: true, node: true */
6482
+ /*global require, module */
6483
+
6484
+ "use strict";
6485
+
6486
+ /*** Imports ****/
6487
+
6488
+ /**
6489
+ * jpeg
6490
+ * @type {*|{}}
6491
+ */
6492
+ var jpeg = jpeg || {};
6493
+
6494
+ /**
6495
+ * jpeg.lossless
6496
+ * @type {*|{}}
6497
+ */
6498
+ jpeg.lossless = jpeg.lossless || {};
6499
+
6500
+
6501
+ jpeg.lossless.ComponentSpec = jpeg.lossless.ComponentSpec || ((typeof require !== 'undefined') ? require('./component-spec.js') : null);
6502
+ jpeg.lossless.DataStream = jpeg.lossless.DataStream || ((typeof require !== 'undefined') ? require('./data-stream.js') : null);
6503
+ jpeg.lossless.Decoder = jpeg.lossless.Decoder || ((typeof require !== 'undefined') ? require('./decoder.js') : null);
6504
+ jpeg.lossless.FrameHeader = jpeg.lossless.FrameHeader || ((typeof require !== 'undefined') ? require('./frame-header.js') : null);
6505
+ jpeg.lossless.HuffmanTable = jpeg.lossless.HuffmanTable || ((typeof require !== 'undefined') ? require('./huffman-table.js') : null);
6506
+ jpeg.lossless.QuantizationTable = jpeg.lossless.QuantizationTable || ((typeof require !== 'undefined') ? require('./quantization-table.js') : null);
6507
+ jpeg.lossless.ScanComponent = jpeg.lossless.ScanComponent || ((typeof require !== 'undefined') ? require('./scan-component.js') : null);
6508
+ jpeg.lossless.ScanHeader = jpeg.lossless.ScanHeader || ((typeof require !== 'undefined') ? require('./scan-header.js') : null);
6509
+ jpeg.lossless.Utils = jpeg.lossless.Utils || ((typeof require !== 'undefined') ? require('./utils.js') : null);
6510
+
6511
+
6512
+ /*** Exports ***/
6513
+ var moduleType = typeof module;
6514
+ if ((moduleType !== 'undefined') && module.exports) {
6515
+ module.exports = jpeg;
6516
+ }
6517
+
6518
+ },{"./component-spec.js":1,"./data-stream.js":2,"./decoder.js":3,"./frame-header.js":4,"./huffman-table.js":5,"./quantization-table.js":7,"./scan-component.js":8,"./scan-header.js":9,"./utils.js":10}],7:[function(require,module,exports){
6519
+ /*
6520
+ * Copyright (C) 2015 Michael Martinez
6521
+ * Changes: Added support for selection values 2-7, fixed minor bugs &
6522
+ * warnings, split into multiple class files, and general clean up.
6523
+ *
6524
+ * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
6525
+ */
6526
+
6527
+ /*
6528
+ * Copyright (C) Helmut Dersch
6529
+ *
6530
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6531
+ * of this software and associated documentation files (the "Software"), to deal
6532
+ * in the Software without restriction, including without limitation the rights
6533
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6534
+ * copies of the Software, and to permit persons to whom the Software is
6535
+ * furnished to do so, subject to the following conditions:
6536
+
6537
+ * The above copyright notice and this permission notice shall be included in
6538
+ * all copies or substantial portions of the Software.
6539
+
6540
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6541
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6542
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6543
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6544
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
6545
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
6546
+ * THE SOFTWARE.
6547
+ */
6548
+
6549
+ /*jslint browser: true, node: true */
6550
+ /*global require, module */
6551
+
6552
+ "use strict";
6553
+
6554
+ /*** Imports ***/
6555
+ var jpeg = jpeg || {};
6556
+ jpeg.lossless = jpeg.lossless || {};
6557
+ jpeg.lossless.DataStream = jpeg.lossless.DataStream || ((typeof require !== 'undefined') ? require('./data-stream.js') : null);
6558
+ jpeg.lossless.Utils = jpeg.lossless.Utils || ((typeof require !== 'undefined') ? require('./utils.js') : null);
6559
+
6560
+
6561
+ /*** Constructor ***/
6562
+ jpeg.lossless.QuantizationTable = jpeg.lossless.QuantizationTable || function () {
6563
+ this.precision = []; // Quantization precision 8 or 16
6564
+ this.tq = []; // 1: this table is presented
6565
+ this.quantTables = jpeg.lossless.Utils.createArray(4, 64); // Tables
6566
+
6567
+ this.tq[0] = 0;
6568
+ this.tq[1] = 0;
6569
+ this.tq[2] = 0;
6570
+ this.tq[3] = 0;
6571
+ };
6572
+
6573
+
6574
+
6575
+ /*** Static Methods ***/
6576
+
6577
+ jpeg.lossless.QuantizationTable.enhanceQuantizationTable = function(qtab, table) {
6578
+ /*jslint bitwise: true */
6579
+
6580
+ var i;
6581
+
6582
+ for (i = 0; i < 8; i+=1) {
6583
+ qtab[table[(0 * 8) + i]] *= 90;
6584
+ qtab[table[(4 * 8) + i]] *= 90;
6585
+ qtab[table[(2 * 8) + i]] *= 118;
6586
+ qtab[table[(6 * 8) + i]] *= 49;
6587
+ qtab[table[(5 * 8) + i]] *= 71;
6588
+ qtab[table[(1 * 8) + i]] *= 126;
6589
+ qtab[table[(7 * 8) + i]] *= 25;
6590
+ qtab[table[(3 * 8) + i]] *= 106;
6591
+ }
6592
+
6593
+ for (i = 0; i < 8; i+=1) {
6594
+ qtab[table[0 + (8 * i)]] *= 90;
6595
+ qtab[table[4 + (8 * i)]] *= 90;
6596
+ qtab[table[2 + (8 * i)]] *= 118;
6597
+ qtab[table[6 + (8 * i)]] *= 49;
6598
+ qtab[table[5 + (8 * i)]] *= 71;
6599
+ qtab[table[1 + (8 * i)]] *= 126;
6600
+ qtab[table[7 + (8 * i)]] *= 25;
6601
+ qtab[table[3 + (8 * i)]] *= 106;
6602
+ }
6603
+
6604
+ for (i = 0; i < 64; i+=1) {
6605
+ qtab[i] >>= 6;
6606
+ }
6607
+ };
6608
+
6609
+
6610
+ /*** Prototype Methods ***/
6611
+
6612
+ jpeg.lossless.QuantizationTable.prototype.read = function (data, table) {
6613
+ /*jslint bitwise: true */
6614
+
6615
+ var count = 0, length, temp, t, i;
6616
+
6617
+ length = data.get16();
6618
+ count += 2;
6619
+
6620
+ while (count < length) {
6621
+ temp = data.get8();
6622
+ count+=1;
6623
+ t = temp & 0x0F;
6624
+
6625
+ if (t > 3) {
6626
+ throw new Error("ERROR: Quantization table ID > 3");
6627
+ }
6628
+
6629
+ this.precision[t] = temp >> 4;
6630
+
6631
+ if (this.precision[t] === 0) {
6632
+ this.precision[t] = 8;
6633
+ } else if (this.precision[t] === 1) {
6634
+ this.precision[t] = 16;
6635
+ } else {
6636
+ throw new Error("ERROR: Quantization table precision error");
6637
+ }
6638
+
6639
+ this.tq[t] = 1;
6640
+
6641
+ if (this.precision[t] === 8) {
6642
+ for (i = 0; i < 64; i+=1) {
6643
+ if (count > length) {
6644
+ throw new Error("ERROR: Quantization table format error");
6645
+ }
6646
+
6647
+ this.quantTables[t][i] = data.get8();
6648
+ count+=1;
6649
+ }
6650
+
6651
+ jpeg.lossless.QuantizationTable.enhanceQuantizationTable(this.quantTables[t], table);
6652
+ } else {
6653
+ for (i = 0; i < 64; i+=1) {
6654
+ if (count > length) {
6655
+ throw new Error("ERROR: Quantization table format error");
6656
+ }
6657
+
6658
+ this.quantTables[t][i] = data.get16();
6659
+ count += 2;
6660
+ }
6661
+
6662
+ jpeg.lossless.QuantizationTable.enhanceQuantizationTable(this.quantTables[t], table);
6663
+ }
6664
+ }
6665
+
6666
+ if (count !== length) {
6667
+ throw new Error("ERROR: Quantization table error [count!=Lq]");
6668
+ }
6669
+
6670
+ return 1;
6671
+ };
6672
+
6673
+
6674
+
6675
+ /*** Exports ***/
6676
+
6677
+ var moduleType = typeof module;
6678
+ if ((moduleType !== 'undefined') && module.exports) {
6679
+ module.exports = jpeg.lossless.QuantizationTable;
6680
+ }
6681
+
6682
+ },{"./data-stream.js":2,"./utils.js":10}],8:[function(require,module,exports){
6683
+ /*
6684
+ * Copyright (C) 2015 Michael Martinez
6685
+ * Changes: Added support for selection values 2-7, fixed minor bugs &
6686
+ * warnings, split into multiple class files, and general clean up.
6687
+ *
6688
+ * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
6689
+ */
6690
+
6691
+ /*
6692
+ * Copyright (C) Helmut Dersch
6693
+ *
6694
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6695
+ * of this software and associated documentation files (the "Software"), to deal
6696
+ * in the Software without restriction, including without limitation the rights
6697
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6698
+ * copies of the Software, and to permit persons to whom the Software is
6699
+ * furnished to do so, subject to the following conditions:
6700
+
6701
+ * The above copyright notice and this permission notice shall be included in
6702
+ * all copies or substantial portions of the Software.
6703
+
6704
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6705
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6706
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6707
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6708
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
6709
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
6710
+ * THE SOFTWARE.
6711
+ */
6712
+
6713
+ /*jslint browser: true, node: true */
6714
+ /*global require, module */
6715
+
6716
+ "use strict";
6717
+
6718
+ /*** Imports ***/
6719
+ var jpeg = jpeg || {};
6720
+ jpeg.lossless = jpeg.lossless || {};
6721
+
6722
+
6723
+ /*** Constructor ***/
6724
+ jpeg.lossless.ScanComponent = jpeg.lossless.ScanComponent || function () {
6725
+ this.acTabSel = 0; // AC table selector
6726
+ this.dcTabSel = 0; // DC table selector
6727
+ this.scanCompSel = 0; // Scan component selector
6728
+ };
6729
+
6730
+
6731
+
6732
+ /*** Exports ***/
6733
+
6734
+ var moduleType = typeof module;
6735
+ if ((moduleType !== 'undefined') && module.exports) {
6736
+ module.exports = jpeg.lossless.ScanComponent;
6737
+ }
6738
+
6739
+ },{}],9:[function(require,module,exports){
6740
+ /*
6741
+ * Copyright (C) 2015 Michael Martinez
6742
+ * Changes: Added support for selection values 2-7, fixed minor bugs &
6743
+ * warnings, split into multiple class files, and general clean up.
6744
+ *
6745
+ * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
6746
+ */
6747
+
6748
+ /*
6749
+ * Copyright (C) Helmut Dersch
6750
+ *
6751
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6752
+ * of this software and associated documentation files (the "Software"), to deal
6753
+ * in the Software without restriction, including without limitation the rights
6754
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6755
+ * copies of the Software, and to permit persons to whom the Software is
6756
+ * furnished to do so, subject to the following conditions:
6757
+
6758
+ * The above copyright notice and this permission notice shall be included in
6759
+ * all copies or substantial portions of the Software.
6760
+
6761
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6762
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6763
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6764
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6765
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
6766
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
6767
+ * THE SOFTWARE.
6768
+ */
6769
+
6770
+ /*jslint browser: true, node: true */
6771
+ /*global require, module */
6772
+
6773
+ "use strict";
6774
+
6775
+ /*** Imports ***/
6776
+ var jpeg = jpeg || {};
6777
+ jpeg.lossless = jpeg.lossless || {};
6778
+ jpeg.lossless.DataStream = jpeg.lossless.DataStream || ((typeof require !== 'undefined') ? require('./data-stream.js') : null);
6779
+ jpeg.lossless.ScanComponent = jpeg.lossless.ScanComponent || ((typeof require !== 'undefined') ? require('./scan-component.js') : null);
6780
+
6781
+
6782
+ /*** Constructor ***/
6783
+ jpeg.lossless.ScanHeader = jpeg.lossless.ScanHeader || function () {
6784
+ this.ah = 0;
6785
+ this.al = 0;
6786
+ this.numComp = 0; // Number of components in the scan
6787
+ this.selection = 0; // Start of spectral or predictor selection
6788
+ this.spectralEnd = 0; // End of spectral selection
6789
+ this.components = [];
6790
+ };
6791
+
6792
+
6793
+ /*** Prototype Methods ***/
6794
+
6795
+ jpeg.lossless.ScanHeader.prototype.read = function(data) {
6796
+ /*jslint bitwise: true */
6797
+
6798
+ var count = 0, length, i, temp;
6799
+
6800
+ length = data.get16();
6801
+ count += 2;
6802
+
6803
+ this.numComp = data.get8();
6804
+ count+=1;
6805
+
6806
+ for (i = 0; i < this.numComp; i+=1) {
6807
+ this.components[i] = new jpeg.lossless.ScanComponent();
6808
+
6809
+ if (count > length) {
6810
+ throw new Error("ERROR: scan header format error");
6811
+ }
6812
+
6813
+ this.components[i].scanCompSel = data.get8();
6814
+ count+=1;
6815
+
6816
+ temp = data.get8();
6817
+ count+=1;
6818
+
6819
+ this.components[i].dcTabSel = (temp >> 4);
6820
+ this.components[i].acTabSel = (temp & 0x0F);
6821
+ }
6822
+
6823
+ this.selection = data.get8();
6824
+ count+=1;
6825
+
6826
+ this.spectralEnd = data.get8();
6827
+ count+=1;
6828
+
6829
+ temp = data.get8();
6830
+ this.ah = (temp >> 4);
6831
+ this.al = (temp & 0x0F);
6832
+ count+=1;
6833
+
6834
+ if (count !== length) {
6835
+ throw new Error("ERROR: scan header format error [count!=Ns]");
6836
+ }
6837
+
6838
+ return 1;
6839
+ };
6840
+
6841
+
6842
+
6843
+ /*** Exports ***/
6844
+
6845
+ var moduleType = typeof module;
6846
+ if ((moduleType !== 'undefined') && module.exports) {
6847
+ module.exports = jpeg.lossless.ScanHeader;
6848
+ }
6849
+
6850
+ },{"./data-stream.js":2,"./scan-component.js":8}],10:[function(require,module,exports){
6851
+ /*
6852
+ * Copyright (C) 2015 Michael Martinez
6853
+ * Changes: Added support for selection values 2-7, fixed minor bugs &
6854
+ * warnings, split into multiple class files, and general clean up.
6855
+ *
6856
+ * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
6857
+ */
6858
+
6859
+ /*
6860
+ * Copyright (C) Helmut Dersch
6861
+ *
6862
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6863
+ * of this software and associated documentation files (the "Software"), to deal
6864
+ * in the Software without restriction, including without limitation the rights
6865
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6866
+ * copies of the Software, and to permit persons to whom the Software is
6867
+ * furnished to do so, subject to the following conditions:
6868
+
6869
+ * The above copyright notice and this permission notice shall be included in
6870
+ * all copies or substantial portions of the Software.
6871
+
6872
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6873
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6874
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6875
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6876
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
6877
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
6878
+ * THE SOFTWARE.
6879
+ */
6880
+
6881
+ /*jslint browser: true, node: true */
6882
+ /*global require, module */
6883
+
6884
+ "use strict";
6885
+
6886
+ /*** Imports ***/
6887
+ var jpeg = jpeg || {};
6888
+ jpeg.lossless = jpeg.lossless || {};
6889
+
6890
+
6891
+ /*** Constructor ***/
6892
+ jpeg.lossless.Utils = jpeg.lossless.Utils || {};
6893
+
6894
+
6895
+ /*** Static methods ***/
6896
+
6897
+ // http://stackoverflow.com/questions/966225/how-can-i-create-a-two-dimensional-array-in-javascript
6898
+ jpeg.lossless.Utils.createArray = function (length) {
6899
+ var arr = new Array(length || 0),
6900
+ i = length;
6901
+
6902
+ if (arguments.length > 1) {
6903
+ var args = Array.prototype.slice.call(arguments, 1);
6904
+ while(i--) arr[length-1 - i] = jpeg.lossless.Utils.createArray.apply(this, args);
6905
+ }
6906
+
6907
+ return arr;
6908
+ };
6909
+
6910
+
6911
+ // http://stackoverflow.com/questions/18638900/javascript-crc32
6912
+ jpeg.lossless.Utils.makeCRCTable = function(){
6913
+ var c;
6914
+ var crcTable = [];
6915
+ for(var n =0; n < 256; n++){
6916
+ c = n;
6917
+ for(var k =0; k < 8; k++){
6918
+ c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
6919
+ }
6920
+ crcTable[n] = c;
6921
+ }
6922
+ return crcTable;
6923
+ };
6924
+
6925
+ jpeg.lossless.Utils.crc32 = function(dataView) {
6926
+ var uint8view = new Uint8Array(dataView.buffer);
6927
+ var crcTable = jpeg.lossless.Utils.crcTable || (jpeg.lossless.Utils.crcTable = jpeg.lossless.Utils.makeCRCTable());
6928
+ var crc = 0 ^ (-1);
6929
+
6930
+ for (var i = 0; i < uint8view.length; i++ ) {
6931
+ crc = (crc >>> 8) ^ crcTable[(crc ^ uint8view[i]) & 0xFF];
6932
+ }
6933
+
6934
+ return (crc ^ (-1)) >>> 0;
6935
+ };
6936
+
6937
+
6938
+ /*** Exports ***/
6939
+
6940
+ var moduleType = typeof module;
6941
+ if ((moduleType !== 'undefined') && module.exports) {
6942
+ module.exports = jpeg.lossless.Utils;
6943
+ }
6944
+
6945
+ },{}]},{},[6])(6)
6946
+ });
6378
6947
 
6379
6948
 
6380
6949
  /***/ }),
@@ -6383,7 +6952,7 @@ function decode(jpegData, userOpts = {}) {
6383
6952
  /***/ ((module) => {
6384
6953
 
6385
6954
  "use strict";
6386
- module.exports = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("lib/jquery");
6955
+ module.exports = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("lib/jquery");
6387
6956
 
6388
6957
  /***/ }),
6389
6958
 
@@ -6487,25 +7056,25 @@ var __webpack_exports__ = {};
6487
7056
  // UNUSED EXPORTS: default
6488
7057
 
6489
7058
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/Components\")"
6490
- const Components_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/Components");
7059
+ const Components_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/Components");
6491
7060
  var Components_default = /*#__PURE__*/__webpack_require__.n(Components_namespaceObject);
6492
7061
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/Fields\")"
6493
- const Fields_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/Fields");
7062
+ const Fields_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/Fields");
6494
7063
  var Fields_default = /*#__PURE__*/__webpack_require__.n(Fields_namespaceObject);
6495
7064
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/Base/X3DFieldDefinition\")"
6496
- const X3DFieldDefinition_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/Base/X3DFieldDefinition");
7065
+ const X3DFieldDefinition_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/Base/X3DFieldDefinition");
6497
7066
  var X3DFieldDefinition_default = /*#__PURE__*/__webpack_require__.n(X3DFieldDefinition_namespaceObject);
6498
7067
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/Base/FieldDefinitionArray\")"
6499
- const FieldDefinitionArray_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/Base/FieldDefinitionArray");
7068
+ const FieldDefinitionArray_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/Base/FieldDefinitionArray");
6500
7069
  var FieldDefinitionArray_default = /*#__PURE__*/__webpack_require__.n(FieldDefinitionArray_namespaceObject);
6501
7070
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/Components/Texturing/X3DSingleTextureNode\")"
6502
- const X3DSingleTextureNode_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/Components/Texturing/X3DSingleTextureNode");
7071
+ const X3DSingleTextureNode_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/Components/Texturing/X3DSingleTextureNode");
6503
7072
  var X3DSingleTextureNode_default = /*#__PURE__*/__webpack_require__.n(X3DSingleTextureNode_namespaceObject);
6504
7073
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/Base/X3DConstants\")"
6505
- const X3DConstants_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/Base/X3DConstants");
7074
+ const X3DConstants_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/Base/X3DConstants");
6506
7075
  var X3DConstants_default = /*#__PURE__*/__webpack_require__.n(X3DConstants_namespaceObject);
6507
7076
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/Namespace\")"
6508
- const Namespace_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/Namespace");
7077
+ const Namespace_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/Namespace");
6509
7078
  var Namespace_default = /*#__PURE__*/__webpack_require__.n(Namespace_namespaceObject);
6510
7079
  ;// CONCATENATED MODULE: ./src/x_ite/Components/Texturing3D/X3DTexture3DNode.js
6511
7080
  /*******************************************************************************
@@ -6673,7 +7242,7 @@ const __default__ = X3DTexture3DNode;
6673
7242
  Namespace_default().set ("x_ite/Components/Texturing3D/X3DTexture3DNode", __default__);
6674
7243
  /* harmony default export */ const Texturing3D_X3DTexture3DNode = (__default__);
6675
7244
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/Base/X3DCast\")"
6676
- const X3DCast_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/Base/X3DCast");
7245
+ const X3DCast_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/Base/X3DCast");
6677
7246
  var X3DCast_default = /*#__PURE__*/__webpack_require__.n(X3DCast_namespaceObject);
6678
7247
  ;// CONCATENATED MODULE: ./src/x_ite/Components/Texturing3D/ComposedTexture3D.js
6679
7248
  /*******************************************************************************
@@ -6871,10 +7440,10 @@ const ComposedTexture3D_default_ = ComposedTexture3D;
6871
7440
  Namespace_default().set ("x_ite/Components/Texturing3D/ComposedTexture3D", ComposedTexture3D_default_);
6872
7441
  /* harmony default export */ const Texturing3D_ComposedTexture3D = (ComposedTexture3D_default_);
6873
7442
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/Components/Networking/X3DUrlObject\")"
6874
- const X3DUrlObject_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/Components/Networking/X3DUrlObject");
7443
+ const X3DUrlObject_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/Components/Networking/X3DUrlObject");
6875
7444
  var X3DUrlObject_default = /*#__PURE__*/__webpack_require__.n(X3DUrlObject_namespaceObject);
6876
7445
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/Parser/Expressions\")"
6877
- const Expressions_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/Parser/Expressions");
7446
+ const Expressions_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/Parser/Expressions");
6878
7447
  var Expressions_default = /*#__PURE__*/__webpack_require__.n(Expressions_namespaceObject);
6879
7448
  // EXTERNAL MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"lib/jquery\")"
6880
7449
  var jquery_ = __webpack_require__(355);
@@ -7343,11 +7912,11 @@ const NRRDParser_default_ = NRRDParser;
7343
7912
  Namespace_default().set ("x_ite/Browser/Texturing3D/NRRDParser", NRRDParser_default_);
7344
7913
  /* harmony default export */ const Texturing3D_NRRDParser = (NRRDParser_default_);
7345
7914
  ;// CONCATENATED MODULE: ./src/x_ite/Browser/Texturing3D/DICOMParser.js
7346
- /* provided dependency */ var dicomParser = __webpack_require__(615);
7347
- /* provided dependency */ var JpegImage = __webpack_require__(622);
7348
- /* provided dependency */ var jpeg = __webpack_require__(782);
7349
- /* provided dependency */ var CharLS = __webpack_require__(990);
7350
- /* provided dependency */ var OpenJPEG = __webpack_require__(881);
7915
+ /* provided dependency */ var dicomParser = __webpack_require__(554);
7916
+ /* provided dependency */ var JpegImage = __webpack_require__(90);
7917
+ /* provided dependency */ var jpeg = __webpack_require__(210);
7918
+ /* provided dependency */ var CharLS = __webpack_require__(639);
7919
+ /* provided dependency */ var OpenJPEG = __webpack_require__(457);
7351
7920
  /*******************************************************************************
7352
7921
  *
7353
7922
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -8450,7 +9019,7 @@ const DICOMParser_default_ = DicomParser;
8450
9019
  Namespace_default().set ("x_ite/Browser/Texturing3D/DICOMParser", DICOMParser_default_);
8451
9020
  /* harmony default export */ const DICOMParser = (DICOMParser_default_);
8452
9021
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/InputOutput/FileLoader\")"
8453
- const FileLoader_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/InputOutput/FileLoader");
9022
+ const FileLoader_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/InputOutput/FileLoader");
8454
9023
  var FileLoader_default = /*#__PURE__*/__webpack_require__.n(FileLoader_namespaceObject);
8455
9024
  ;// CONCATENATED MODULE: ./src/x_ite/Components/Texturing3D/ImageTexture3D.js
8456
9025
  /*******************************************************************************
@@ -8630,7 +9199,7 @@ const ImageTexture3D_default_ = ImageTexture3D;
8630
9199
  Namespace_default().set ("x_ite/Components/Texturing3D/ImageTexture3D", ImageTexture3D_default_);
8631
9200
  /* harmony default export */ const Texturing3D_ImageTexture3D = (ImageTexture3D_default_);
8632
9201
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/DEBUG\")"
8633
- const DEBUG_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/DEBUG");
9202
+ const DEBUG_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/DEBUG");
8634
9203
  var DEBUG_default = /*#__PURE__*/__webpack_require__.n(DEBUG_namespaceObject);
8635
9204
  ;// CONCATENATED MODULE: ./src/x_ite/Components/Texturing3D/ImageTextureAtlas.js
8636
9205
  /* provided dependency */ var $ = __webpack_require__(355);
@@ -9088,10 +9657,10 @@ const PixelTexture3D_default_ = PixelTexture3D;
9088
9657
  Namespace_default().set ("x_ite/Components/Texturing3D/PixelTexture3D", PixelTexture3D_default_);
9089
9658
  /* harmony default export */ const Texturing3D_PixelTexture3D = (PixelTexture3D_default_);
9090
9659
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/Components/Texturing/X3DSingleTextureCoordinateNode\")"
9091
- const X3DSingleTextureCoordinateNode_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/Components/Texturing/X3DSingleTextureCoordinateNode");
9660
+ const X3DSingleTextureCoordinateNode_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/Components/Texturing/X3DSingleTextureCoordinateNode");
9092
9661
  var X3DSingleTextureCoordinateNode_default = /*#__PURE__*/__webpack_require__.n(X3DSingleTextureCoordinateNode_namespaceObject);
9093
9662
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"standard/Math/Numbers/Vector4\")"
9094
- const Vector4_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("standard/Math/Numbers/Vector4");
9663
+ const Vector4_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("standard/Math/Numbers/Vector4");
9095
9664
  ;// CONCATENATED MODULE: ./src/x_ite/Components/Texturing3D/TextureCoordinate3D.js
9096
9665
  /*******************************************************************************
9097
9666
  *
@@ -9439,16 +10008,16 @@ const TextureCoordinate4D_default_ = TextureCoordinate4D;
9439
10008
  Namespace_default().set ("x_ite/Components/Texturing3D/TextureCoordinate4D", TextureCoordinate4D_default_);
9440
10009
  /* harmony default export */ const Texturing3D_TextureCoordinate4D = (TextureCoordinate4D_default_);
9441
10010
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"x_ite/Components/Texturing/X3DSingleTextureTransformNode\")"
9442
- const X3DSingleTextureTransformNode_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("x_ite/Components/Texturing/X3DSingleTextureTransformNode");
10011
+ const X3DSingleTextureTransformNode_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("x_ite/Components/Texturing/X3DSingleTextureTransformNode");
9443
10012
  var X3DSingleTextureTransformNode_default = /*#__PURE__*/__webpack_require__.n(X3DSingleTextureTransformNode_namespaceObject);
9444
10013
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"standard/Math/Numbers/Vector3\")"
9445
- const Vector3_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("standard/Math/Numbers/Vector3");
10014
+ const Vector3_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("standard/Math/Numbers/Vector3");
9446
10015
  var Vector3_default = /*#__PURE__*/__webpack_require__.n(Vector3_namespaceObject);
9447
10016
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"standard/Math/Numbers/Rotation4\")"
9448
- const Rotation4_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("standard/Math/Numbers/Rotation4");
10017
+ const Rotation4_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("standard/Math/Numbers/Rotation4");
9449
10018
  var Rotation4_default = /*#__PURE__*/__webpack_require__.n(Rotation4_namespaceObject);
9450
10019
  ;// CONCATENATED MODULE: external "window [Symbol .for (\"X_ITE.X3D\")] .require (\"standard/Math/Numbers/Matrix4\")"
9451
- const Matrix4_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.0")] .require ("standard/Math/Numbers/Matrix4");
10020
+ const Matrix4_namespaceObject = window [Symbol .for ("X_ITE.X3D-8.7.2")] .require ("standard/Math/Numbers/Matrix4");
9452
10021
  var Matrix4_default = /*#__PURE__*/__webpack_require__.n(Matrix4_namespaceObject);
9453
10022
  ;// CONCATENATED MODULE: ./src/x_ite/Components/Texturing3D/TextureTransform3D.js
9454
10023
  /*******************************************************************************