@cornerstonejs/dicom-image-loader 0.2.0 → 0.2.1

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.
@@ -1,2075 +0,0 @@
1
- (self["webpackChunk_name_"] = self["webpackChunk_name_"] || []).push([["codecs_jpegLossless_js"],{
2
-
3
- /***/ "../codecs/jpegLossless.js":
4
- /*!*********************************!*\
5
- !*** ../codecs/jpegLossless.js ***!
6
- \*********************************/
7
- /***/ (function(module, exports) {
8
-
9
- /* eslint-disable */
10
-
11
- (function (f) {
12
- if (typeof exports === 'object' && typeof module !== 'undefined') {
13
- module.exports = f();
14
- } else if (typeof define === 'function' && define.amd) {
15
- define([], f);
16
- } else {
17
- var g;
18
-
19
- if (typeof window !== 'undefined') {
20
- g = window;
21
- } else if (typeof global !== 'undefined') {
22
- g = global;
23
- } else if (typeof self !== 'undefined') {
24
- g = self;
25
- } else {
26
- g = this;
27
- }
28
- g.jpeg = f();
29
- }
30
- })(function () {
31
- var define, module, exports;
32
-
33
- return (function e(t, n, r) {
34
- function s(o, u) {
35
- if (!n[o]) {
36
- if (!t[o]) {
37
- var a = typeof require === 'function' && require;
38
-
39
- if (!u && a) {
40
- return a(o, !0);
41
- }
42
- if (i) {
43
- return i(o, !0);
44
- }
45
- var f = new Error("Cannot find module '" + o + "'");
46
-
47
- throw ((f.code = 'MODULE_NOT_FOUND'), f);
48
- }
49
- var l = (n[o] = { exports: {} });
50
-
51
- t[o][0].call(
52
- l.exports,
53
- function (e) {
54
- var n = t[o][1][e];
55
-
56
- return s(n ? n : e);
57
- },
58
- l,
59
- l.exports,
60
- e,
61
- t,
62
- n,
63
- r
64
- );
65
- }
66
-
67
- return n[o].exports;
68
- }
69
- var i = typeof require === 'function' && require;
70
-
71
- for (var o = 0; o < r.length; o++) {
72
- s(r[o]);
73
- }
74
-
75
- return s;
76
- })(
77
- {
78
- 1: [
79
- function (require, module, exports) {
80
- /*
81
- * Copyright (C) 2015 Michael Martinez
82
- * Changes: Added support for selection values 2-7, fixed minor bugs &
83
- * warnings, split into multiple class files, and general clean up.
84
- *
85
- * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
86
- */
87
-
88
- /*
89
- * Copyright (C) Helmut Dersch
90
- *
91
- * Permission is hereby granted, free of charge, to any person obtaining a copy
92
- * of this software and associated documentation files (the "Software"), to deal
93
- * in the Software without restriction, including without limitation the rights
94
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
95
- * copies of the Software, and to permit persons to whom the Software is
96
- * furnished to do so, subject to the following conditions:
97
-
98
- * The above copyright notice and this permission notice shall be included in
99
- * all copies or substantial portions of the Software.
100
-
101
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
102
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
103
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
104
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
105
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
106
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
107
- * THE SOFTWARE.
108
- */
109
-
110
- /*jslint browser: true, node: true */
111
- /*global require, module */
112
-
113
- /*** Imports ***/
114
- var jpeg = jpeg || {};
115
-
116
- jpeg.lossless = jpeg.lossless || {};
117
-
118
- /*** Constructor ***/
119
- jpeg.lossless.ComponentSpec =
120
- jpeg.lossless.ComponentSpec ||
121
- function () {
122
- this.hSamp = 0; // Horizontal sampling factor
123
- this.quantTableSel = 0; // Quantization table destination selector
124
- this.vSamp = 0; // Vertical
125
- };
126
-
127
- /*** Exports ***/
128
-
129
- var moduleType = typeof module;
130
-
131
- if (moduleType !== 'undefined' && module.exports) {
132
- module.exports = jpeg.lossless.ComponentSpec;
133
- }
134
- },
135
- {},
136
- ],
137
- 2: [
138
- function (require, module, exports) {
139
- /*
140
- * Copyright (C) 2015 Michael Martinez
141
- * Changes: Added support for selection values 2-7, fixed minor bugs &
142
- * warnings, split into multiple class files, and general clean up.
143
- *
144
- * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
145
- */
146
-
147
- /*
148
- * Copyright (C) Helmut Dersch
149
- *
150
- * Permission is hereby granted, free of charge, to any person obtaining a copy
151
- * of this software and associated documentation files (the "Software"), to deal
152
- * in the Software without restriction, including without limitation the rights
153
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
154
- * copies of the Software, and to permit persons to whom the Software is
155
- * furnished to do so, subject to the following conditions:
156
-
157
- * The above copyright notice and this permission notice shall be included in
158
- * all copies or substantial portions of the Software.
159
-
160
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
162
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
163
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
164
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
165
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
166
- * THE SOFTWARE.
167
- */
168
-
169
- /*jslint browser: true, node: true */
170
- /*global require, module */
171
- /*** Imports ***/
172
- var jpeg = jpeg || {};
173
-
174
- jpeg.lossless = jpeg.lossless || {};
175
-
176
- /*** Constructor ***/
177
- jpeg.lossless.DataStream =
178
- jpeg.lossless.DataStream ||
179
- function (data, offset, length) {
180
- // Note: DataView is much slower than Int8Array
181
- // this.buffer = new DataView(data, offset, length);
182
- this.buffer = new Uint8Array(data, offset, length);
183
- this.index = 0;
184
- };
185
- jpeg.lossless.DataStream.prototype.get16 = function () {
186
- // var value = this.buffer.getUint16(this.index, false);
187
- var value =
188
- (this.buffer[this.index] << 8) + this.buffer[this.index + 1]; // DataView is big-endian by default
189
-
190
- this.index += 2;
191
-
192
- return value;
193
- };
194
- jpeg.lossless.DataStream.prototype.get8 = function () {
195
- // var value = this.buffer.getUint8(this.index);
196
- var value = this.buffer[this.index];
197
-
198
- this.index += 1;
199
-
200
- return value;
201
- };
202
-
203
- /*** Exports ***/
204
-
205
- var moduleType = typeof module;
206
-
207
- if (moduleType !== 'undefined' && module.exports) {
208
- module.exports = jpeg.lossless.DataStream;
209
- }
210
- },
211
- {},
212
- ],
213
- 3: [
214
- function (require, module, exports) {
215
- /*
216
- * Copyright (C) 2015 Michael Martinez
217
- * Changes: Added support for selection values 2-7, fixed minor bugs &
218
- * warnings, split into multiple class files, and general clean up.
219
- *
220
- * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
221
- */
222
-
223
- /*
224
- * Copyright (C) Helmut Dersch
225
- *
226
- * Permission is hereby granted, free of charge, to any person obtaining a copy
227
- * of this software and associated documentation files (the "Software"), to deal
228
- * in the Software without restriction, including without limitation the rights
229
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
230
- * copies of the Software, and to permit persons to whom the Software is
231
- * furnished to do so, subject to the following conditions:
232
-
233
- * The above copyright notice and this permission notice shall be included in
234
- * all copies or substantial portions of the Software.
235
-
236
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
237
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
238
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
239
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
240
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
241
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
242
- * THE SOFTWARE.
243
- */
244
-
245
- /*jslint browser: true, node: true */
246
- /*global require, module */
247
- /*** Imports ***/
248
- var jpeg = jpeg || {};
249
-
250
- jpeg.lossless = jpeg.lossless || {};
251
- jpeg.lossless.DataStream =
252
- jpeg.lossless.DataStream ||
253
- (typeof require !== 'undefined'
254
- ? require('./data-stream.js')
255
- : null);
256
- jpeg.lossless.HuffmanTable =
257
- jpeg.lossless.HuffmanTable ||
258
- (typeof require !== 'undefined'
259
- ? require('./huffman-table.js')
260
- : null);
261
- jpeg.lossless.QuantizationTable =
262
- jpeg.lossless.QuantizationTable ||
263
- (typeof require !== 'undefined'
264
- ? require('./quantization-table.js')
265
- : null);
266
- jpeg.lossless.ScanHeader =
267
- jpeg.lossless.ScanHeader ||
268
- (typeof require !== 'undefined'
269
- ? require('./scan-header.js')
270
- : null);
271
- jpeg.lossless.FrameHeader =
272
- jpeg.lossless.FrameHeader ||
273
- (typeof require !== 'undefined'
274
- ? require('./frame-header.js')
275
- : null);
276
- jpeg.lossless.Utils =
277
- jpeg.lossless.Utils ||
278
- (typeof require !== 'undefined' ? require('./utils.js') : null);
279
-
280
- /*** Constructor ***/
281
-
282
- /**
283
- * The Decoder constructor.
284
- * @property {number} xDim - size of x dimension
285
- * @property {number} yDim - size of y dimension
286
- * @property {number} numComp - number of components
287
- * @property {number} numBytes - number of bytes per component
288
- * @type {Function}
289
- */
290
- jpeg.lossless.Decoder =
291
- jpeg.lossless.Decoder ||
292
- function (buffer, numBytes) {
293
- this.buffer = buffer;
294
- this.frame = new jpeg.lossless.FrameHeader();
295
- this.huffTable = new jpeg.lossless.HuffmanTable();
296
- this.quantTable = new jpeg.lossless.QuantizationTable();
297
- this.scan = new jpeg.lossless.ScanHeader();
298
- 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
299
- this.HuffTab = jpeg.lossless.Utils.createArray(4, 2, 50 * 256);
300
- this.IDCT_Source = [];
301
- this.nBlock = []; // number of blocks in the i-th Comp in a scan
302
- this.acTab = jpeg.lossless.Utils.createArray(10, 1); // ac HuffTab for the i-th Comp in a scan
303
- this.dcTab = jpeg.lossless.Utils.createArray(10, 1); // dc HuffTab for the i-th Comp in a scan
304
- this.qTab = jpeg.lossless.Utils.createArray(10, 1); // quantization table for the i-th Comp in a scan
305
- this.marker = 0;
306
- this.markerIndex = 0;
307
- this.numComp = 0;
308
- this.restartInterval = 0;
309
- this.selection = 0;
310
- this.xDim = 0;
311
- this.yDim = 0;
312
- this.xLoc = 0;
313
- this.yLoc = 0;
314
- this.numBytes = 0;
315
- this.outputData = null;
316
- this.restarting = false;
317
- this.mask = 0;
318
-
319
- if (typeof numBytes !== 'undefined') {
320
- this.numBytes = numBytes;
321
- }
322
- };
323
-
324
- /*** Static Pseudo-constants ***/
325
-
326
- jpeg.lossless.Decoder.IDCT_P = [
327
- 0, 5, 40, 16, 45, 2, 7, 42, 21, 56, 8, 61, 18, 47, 1, 4, 41, 23, 58,
328
- 13, 32, 24, 37, 10, 63, 17, 44, 3, 6, 43, 20, 57, 15, 34, 29, 48,
329
- 53, 26, 39, 9, 60, 19, 46, 22, 59, 12, 33, 31, 50, 55, 25, 36, 11,
330
- 62, 14, 35, 28, 49, 52, 27, 38, 30, 51, 54,
331
- ];
332
- jpeg.lossless.Decoder.TABLE = [
333
- 0, 1, 5, 6, 14, 15, 27, 28, 2, 4, 7, 13, 16, 26, 29, 42, 3, 8, 12,
334
- 17, 25, 30, 41, 43, 9, 11, 18, 24, 31, 40, 44, 53, 10, 19, 23, 32,
335
- 39, 45, 52, 54, 20, 22, 33, 38, 46, 51, 55, 60, 21, 34, 37, 47, 50,
336
- 56, 59, 61, 35, 36, 48, 49, 57, 58, 62, 63,
337
- ];
338
- jpeg.lossless.Decoder.MAX_HUFFMAN_SUBTREE = 50;
339
- jpeg.lossless.Decoder.MSB = 0x80000000;
340
- jpeg.lossless.Decoder.RESTART_MARKER_BEGIN = 0xffd0;
341
- jpeg.lossless.Decoder.RESTART_MARKER_END = 0xffd7;
342
-
343
- /*** Prototype Methods ***/
344
-
345
- /**
346
- * Returns decompressed data.
347
- * @param {ArrayBuffer} buffer
348
- * @param {number} [offset]
349
- * @param {number} [length]
350
- * @returns {ArrayBufer}
351
- */
352
- jpeg.lossless.Decoder.prototype.decompress = function (
353
- buffer,
354
- offset,
355
- length
356
- ) {
357
- return this.decode(buffer, offset, length).buffer;
358
- };
359
- jpeg.lossless.Decoder.prototype.decode = function (
360
- buffer,
361
- offset,
362
- length,
363
- numBytes
364
- ) {
365
- /*jslint bitwise: true */
366
-
367
- var current,
368
- scanNum = 0,
369
- pred = [],
370
- i,
371
- compN,
372
- temp = [],
373
- index = [],
374
- mcuNum;
375
-
376
- if (typeof buffer !== 'undefined') {
377
- this.buffer = buffer;
378
- }
379
-
380
- if (typeof numBytes !== 'undefined') {
381
- this.numBytes = numBytes;
382
- }
383
-
384
- this.stream = new jpeg.lossless.DataStream(
385
- this.buffer,
386
- offset,
387
- length
388
- );
389
- this.buffer = null;
390
-
391
- this.xLoc = 0;
392
- this.yLoc = 0;
393
- current = this.stream.get16();
394
-
395
- if (current !== 0xffd8) {
396
- // SOI
397
- throw new Error('Not a JPEG file');
398
- }
399
-
400
- current = this.stream.get16();
401
-
402
- while (current >> 4 !== 0x0ffc || current === 0xffc4) {
403
- // SOF 0~15
404
- switch (current) {
405
- case 0xffc4: // DHT
406
- this.huffTable.read(this.stream, this.HuffTab);
407
- break;
408
- case 0xffcc: // DAC
409
- throw new Error(
410
- "Program doesn't support arithmetic coding. (format throw new IOException)"
411
- );
412
- case 0xffdb:
413
- this.quantTable.read(
414
- this.stream,
415
- jpeg.lossless.Decoder.TABLE
416
- );
417
- break;
418
- case 0xffdd:
419
- this.restartInterval = this.readNumber();
420
- break;
421
- case 0xffe0:
422
- case 0xffe1:
423
- case 0xffe2:
424
- case 0xffe3:
425
- case 0xffe4:
426
- case 0xffe5:
427
- case 0xffe6:
428
- case 0xffe7:
429
- case 0xffe8:
430
- case 0xffe9:
431
- case 0xffea:
432
- case 0xffeb:
433
- case 0xffec:
434
- case 0xffed:
435
- case 0xffee:
436
- case 0xffef:
437
- this.readApp();
438
- break;
439
- case 0xfffe:
440
- this.readComment();
441
- break;
442
- default:
443
- if (current >> 8 !== 0xff) {
444
- throw new Error(
445
- 'ERROR: format throw new IOException! (decode)'
446
- );
447
- }
448
- }
449
-
450
- current = this.stream.get16();
451
- }
452
-
453
- if (current < 0xffc0 || current > 0xffc7) {
454
- throw new Error('ERROR: could not handle arithmetic code!');
455
- }
456
-
457
- this.frame.read(this.stream);
458
- current = this.stream.get16();
459
-
460
- do {
461
- while (current !== 0x0ffda) {
462
- // SOS
463
- switch (current) {
464
- case 0xffc4: // DHT
465
- this.huffTable.read(this.stream, this.HuffTab);
466
- break;
467
- case 0xffcc: // DAC
468
- throw new Error(
469
- "Program doesn't support arithmetic coding. (format throw new IOException)"
470
- );
471
- case 0xffdb:
472
- this.quantTable.read(
473
- this.stream,
474
- jpeg.lossless.Decoder.TABLE
475
- );
476
- break;
477
- case 0xffdd:
478
- this.restartInterval = this.readNumber();
479
- break;
480
- case 0xffe0:
481
- case 0xffe1:
482
- case 0xffe2:
483
- case 0xffe3:
484
- case 0xffe4:
485
- case 0xffe5:
486
- case 0xffe6:
487
- case 0xffe7:
488
- case 0xffe8:
489
- case 0xffe9:
490
- case 0xffea:
491
- case 0xffeb:
492
- case 0xffec:
493
- case 0xffed:
494
- case 0xffee:
495
- case 0xffef:
496
- this.readApp();
497
- break;
498
- case 0xfffe:
499
- this.readComment();
500
- break;
501
- default:
502
- if (current >> 8 !== 0xff) {
503
- throw new Error(
504
- 'ERROR: format throw new IOException! (Parser.decode)'
505
- );
506
- }
507
- }
508
-
509
- current = this.stream.get16();
510
- }
511
-
512
- this.precision = this.frame.precision;
513
- this.components = this.frame.components;
514
-
515
- if (!this.numBytes) {
516
- this.numBytes = parseInt(Math.ceil(this.precision / 8));
517
- }
518
-
519
- if (this.numBytes == 1) {
520
- this.mask = 0xff;
521
- } else {
522
- this.mask = 0xffff;
523
- }
524
-
525
- this.scan.read(this.stream);
526
- this.numComp = this.scan.numComp;
527
- this.selection = this.scan.selection;
528
-
529
- if (this.numBytes === 1) {
530
- if (this.numComp === 3) {
531
- this.getter = this.getValueRGB;
532
- this.setter = this.setValueRGB;
533
- this.output = this.outputRGB;
534
- } else {
535
- this.getter = this.getValue8;
536
- this.setter = this.setValue8;
537
- this.output = this.outputSingle;
538
- }
539
- } else {
540
- this.getter = this.getValue16;
541
- this.setter = this.setValue16;
542
- this.output = this.outputSingle;
543
- }
544
-
545
- switch (this.selection) {
546
- case 2:
547
- this.selector = this.select2;
548
- break;
549
- case 3:
550
- this.selector = this.select3;
551
- break;
552
- case 4:
553
- this.selector = this.select4;
554
- break;
555
- case 5:
556
- this.selector = this.select5;
557
- break;
558
- case 6:
559
- this.selector = this.select6;
560
- break;
561
- case 7:
562
- this.selector = this.select7;
563
- break;
564
- default:
565
- this.selector = this.select1;
566
- break;
567
- }
568
-
569
- this.scanComps = this.scan.components;
570
- this.quantTables = this.quantTable.quantTables;
571
-
572
- for (i = 0; i < this.numComp; i += 1) {
573
- compN = this.scanComps[i].scanCompSel;
574
- this.qTab[i] =
575
- this.quantTables[this.components[compN].quantTableSel];
576
- this.nBlock[i] =
577
- this.components[compN].vSamp * this.components[compN].hSamp;
578
- this.dcTab[i] = this.HuffTab[this.scanComps[i].dcTabSel][0];
579
- this.acTab[i] = this.HuffTab[this.scanComps[i].acTabSel][1];
580
- }
581
-
582
- this.xDim = this.frame.dimX;
583
- this.yDim = this.frame.dimY;
584
- if (this.numBytes == 1) {
585
- this.outputData = new Uint8Array(
586
- new ArrayBuffer(
587
- this.xDim * this.yDim * this.numBytes * this.numComp
588
- )
589
- );
590
- } else {
591
- this.outputData = new Uint16Array(
592
- new ArrayBuffer(
593
- this.xDim * this.yDim * this.numBytes * this.numComp
594
- )
595
- );
596
- }
597
-
598
- scanNum += 1;
599
-
600
- while (true) {
601
- // Decode one scan
602
- temp[0] = 0;
603
- index[0] = 0;
604
-
605
- for (i = 0; i < 10; i += 1) {
606
- pred[i] = 1 << (this.precision - 1);
607
- }
608
-
609
- if (this.restartInterval === 0) {
610
- current = this.decodeUnit(pred, temp, index);
611
-
612
- while (
613
- current === 0 &&
614
- this.xLoc < this.xDim &&
615
- this.yLoc < this.yDim
616
- ) {
617
- this.output(pred);
618
- current = this.decodeUnit(pred, temp, index);
619
- }
620
-
621
- break; //current=MARKER
622
- }
623
-
624
- for (mcuNum = 0; mcuNum < this.restartInterval; mcuNum += 1) {
625
- this.restarting = mcuNum == 0;
626
- current = this.decodeUnit(pred, temp, index);
627
- this.output(pred);
628
-
629
- if (current !== 0) {
630
- break;
631
- }
632
- }
633
-
634
- if (current === 0) {
635
- if (this.markerIndex !== 0) {
636
- current = 0xff00 | this.marker;
637
- this.markerIndex = 0;
638
- } else {
639
- current = this.stream.get16();
640
- }
641
- }
642
-
643
- if (
644
- !(
645
- current >= jpeg.lossless.Decoder.RESTART_MARKER_BEGIN &&
646
- current <= jpeg.lossless.Decoder.RESTART_MARKER_END
647
- )
648
- ) {
649
- break; //current=MARKER
650
- }
651
- }
652
-
653
- if (current === 0xffdc && scanNum === 1) {
654
- //DNL
655
- this.readNumber();
656
- current = this.stream.get16();
657
- }
658
- } while (
659
- current !== 0xffd9 &&
660
- this.xLoc < this.xDim &&
661
- this.yLoc < this.yDim &&
662
- scanNum === 0
663
- );
664
-
665
- return this.outputData;
666
- };
667
- jpeg.lossless.Decoder.prototype.decodeUnit = function (
668
- prev,
669
- temp,
670
- index
671
- ) {
672
- if (this.numComp == 1) {
673
- return this.decodeSingle(prev, temp, index);
674
- } else if (this.numComp == 3) {
675
- return this.decodeRGB(prev, temp, index);
676
- }
677
-
678
- return -1;
679
- };
680
- jpeg.lossless.Decoder.prototype.select1 = function (compOffset) {
681
- return this.getPreviousX(compOffset);
682
- };
683
- jpeg.lossless.Decoder.prototype.select2 = function (compOffset) {
684
- return this.getPreviousY(compOffset);
685
- };
686
- jpeg.lossless.Decoder.prototype.select3 = function (compOffset) {
687
- return this.getPreviousXY(compOffset);
688
- };
689
- jpeg.lossless.Decoder.prototype.select4 = function (compOffset) {
690
- return (
691
- this.getPreviousX(compOffset) +
692
- this.getPreviousY(compOffset) -
693
- this.getPreviousXY(compOffset)
694
- );
695
- };
696
- jpeg.lossless.Decoder.prototype.select5 = function (compOffset) {
697
- return (
698
- this.getPreviousX(compOffset) +
699
- ((this.getPreviousY(compOffset) -
700
- this.getPreviousXY(compOffset)) >>
701
- 1)
702
- );
703
- };
704
- jpeg.lossless.Decoder.prototype.select6 = function (compOffset) {
705
- return (
706
- this.getPreviousY(compOffset) +
707
- ((this.getPreviousX(compOffset) -
708
- this.getPreviousXY(compOffset)) >>
709
- 1)
710
- );
711
- };
712
- jpeg.lossless.Decoder.prototype.select7 = function (compOffset) {
713
- return (
714
- (this.getPreviousX(compOffset) + this.getPreviousY(compOffset)) /
715
- 2
716
- );
717
- };
718
- jpeg.lossless.Decoder.prototype.decodeRGB = function (
719
- prev,
720
- temp,
721
- index
722
- ) {
723
- /*jslint bitwise: true */
724
-
725
- var value, actab, dctab, qtab, ctrC, i, k, j;
726
-
727
- prev[0] = this.selector(0);
728
- prev[1] = this.selector(1);
729
- prev[2] = this.selector(2);
730
-
731
- for (ctrC = 0; ctrC < this.numComp; ctrC += 1) {
732
- qtab = this.qTab[ctrC];
733
- actab = this.acTab[ctrC];
734
- dctab = this.dcTab[ctrC];
735
- for (i = 0; i < this.nBlock[ctrC]; i += 1) {
736
- for (k = 0; k < this.IDCT_Source.length; k += 1) {
737
- this.IDCT_Source[k] = 0;
738
- }
739
-
740
- value = this.getHuffmanValue(dctab, temp, index);
741
-
742
- if (value >= 0xff00) {
743
- return value;
744
- }
745
-
746
- prev[ctrC] = this.IDCT_Source[0] =
747
- prev[ctrC] + this.getn(index, value, temp, index);
748
- this.IDCT_Source[0] *= qtab[0];
749
-
750
- for (j = 1; j < 64; j += 1) {
751
- value = this.getHuffmanValue(actab, temp, index);
752
-
753
- if (value >= 0xff00) {
754
- return value;
755
- }
756
-
757
- j += value >> 4;
758
-
759
- if ((value & 0x0f) === 0) {
760
- if (value >> 4 === 0) {
761
- break;
762
- }
763
- } else {
764
- this.IDCT_Source[jpeg.lossless.Decoder.IDCT_P[j]] =
765
- this.getn(index, value & 0x0f, temp, index) * qtab[j];
766
- }
767
- }
768
- }
769
- }
770
-
771
- return 0;
772
- };
773
- jpeg.lossless.Decoder.prototype.decodeSingle = function (
774
- prev,
775
- temp,
776
- index
777
- ) {
778
- /*jslint bitwise: true */
779
-
780
- var value, i, n, nRestart;
781
-
782
- if (this.restarting) {
783
- this.restarting = false;
784
- prev[0] = 1 << (this.frame.precision - 1);
785
- } else {
786
- prev[0] = this.selector();
787
- }
788
-
789
- for (i = 0; i < this.nBlock[0]; i += 1) {
790
- value = this.getHuffmanValue(this.dcTab[0], temp, index);
791
- if (value >= 0xff00) {
792
- return value;
793
- }
794
-
795
- n = this.getn(prev, value, temp, index);
796
- nRestart = n >> 8;
797
-
798
- if (
799
- nRestart >= jpeg.lossless.Decoder.RESTART_MARKER_BEGIN &&
800
- nRestart <= jpeg.lossless.Decoder.RESTART_MARKER_END
801
- ) {
802
- return nRestart;
803
- }
804
-
805
- prev[0] += n;
806
- }
807
-
808
- return 0;
809
- };
810
- // 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
811
- // 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.
812
- // HuffTab[*][*][0-256] is always the only 1st-layer table.
813
- //
814
- // An entry can be: (1) (# of 2nd-layer table) | MSB , for code length > 8 in 1st-layer (2) (Code length) << 8 | HuffVal
815
- //
816
- // HuffmanValue(table HuffTab[x][y] (ex) HuffmanValue(HuffTab[1][0],...)
817
- // ):
818
- // return: Huffman Value of table
819
- // 0xFF?? if it receives a MARKER
820
- // Parameter: table HuffTab[x][y] (ex) HuffmanValue(HuffTab[1][0],...)
821
- // temp temp storage for remainded bits
822
- // index index to bit of temp
823
- // in FILE pointer
824
- // Effect:
825
- // temp store new remainded bits
826
- // index change to new index
827
- // in change to new position
828
- // NOTE:
829
- // Initial by temp=0; index=0;
830
- // NOTE: (explain temp and index)
831
- // temp: is always in the form at calling time or returning time
832
- // | byte 4 | byte 3 | byte 2 | byte 1 |
833
- // | 0 | 0 | 00000000 | 00000??? | if not a MARKER
834
- // ^index=3 (from 0 to 15)
835
- // 321
836
- // NOTE (marker and marker_index):
837
- // If get a MARKER from 'in', marker=the low-byte of the MARKER
838
- // and marker_index=9
839
- // If marker_index=9 then index is always > 8, or HuffmanValue()
840
- // will not be called
841
- jpeg.lossless.Decoder.prototype.getHuffmanValue = function (
842
- table,
843
- temp,
844
- index
845
- ) {
846
- /*jslint bitwise: true */
847
-
848
- var code, input, mask;
849
-
850
- mask = 0xffff;
851
-
852
- if (index[0] < 8) {
853
- temp[0] <<= 8;
854
- input = this.stream.get8();
855
- if (input === 0xff) {
856
- this.marker = this.stream.get8();
857
- if (this.marker !== 0) {
858
- this.markerIndex = 9;
859
- }
860
- }
861
- temp[0] |= input;
862
- } else {
863
- index[0] -= 8;
864
- }
865
-
866
- code = table[temp[0] >> index[0]];
867
-
868
- if ((code & jpeg.lossless.Decoder.MSB) !== 0) {
869
- if (this.markerIndex !== 0) {
870
- this.markerIndex = 0;
871
-
872
- return 0xff00 | this.marker;
873
- }
874
-
875
- temp[0] &= mask >> (16 - index[0]);
876
- temp[0] <<= 8;
877
- input = this.stream.get8();
878
-
879
- if (input === 0xff) {
880
- this.marker = this.stream.get8();
881
- if (this.marker !== 0) {
882
- this.markerIndex = 9;
883
- }
884
- }
885
-
886
- temp[0] |= input;
887
- code = table[(code & 0xff) * 256 + (temp[0] >> index[0])];
888
- index[0] += 8;
889
- }
890
-
891
- index[0] += 8 - (code >> 8);
892
-
893
- if (index[0] < 0) {
894
- throw new Error(
895
- `index=${index[0]} temp=${temp[0]} code=${code} in HuffmanValue()`
896
- );
897
- }
898
-
899
- if (index[0] < this.markerIndex) {
900
- this.markerIndex = 0;
901
-
902
- return 0xff00 | this.marker;
903
- }
904
-
905
- temp[0] &= mask >> (16 - index[0]);
906
-
907
- return code & 0xff;
908
- };
909
- jpeg.lossless.Decoder.prototype.getn = function (
910
- PRED,
911
- n,
912
- temp,
913
- index
914
- ) {
915
- /*jslint bitwise: true */
916
-
917
- var result, one, n_one, mask, input;
918
-
919
- one = 1;
920
- n_one = -1;
921
- mask = 0xffff;
922
-
923
- if (n === 0) {
924
- return 0;
925
- }
926
-
927
- if (n === 16) {
928
- if (PRED[0] >= 0) {
929
- return -32768;
930
- }
931
-
932
- return 32768;
933
- }
934
-
935
- index[0] -= n;
936
-
937
- if (index[0] >= 0) {
938
- if (index[0] < this.markerIndex && !this.isLastPixel()) {
939
- // this was corrupting the last pixel in some cases
940
- this.markerIndex = 0;
941
-
942
- return (0xff00 | this.marker) << 8;
943
- }
944
-
945
- result = temp[0] >> index[0];
946
- temp[0] &= mask >> (16 - index[0]);
947
- } else {
948
- temp[0] <<= 8;
949
- input = this.stream.get8();
950
-
951
- if (input === 0xff) {
952
- this.marker = this.stream.get8();
953
- if (this.marker !== 0) {
954
- this.markerIndex = 9;
955
- }
956
- }
957
-
958
- temp[0] |= input;
959
- index[0] += 8;
960
-
961
- if (index[0] < 0) {
962
- if (this.markerIndex !== 0) {
963
- this.markerIndex = 0;
964
-
965
- return (0xff00 | this.marker) << 8;
966
- }
967
-
968
- temp[0] <<= 8;
969
- input = this.stream.get8();
970
-
971
- if (input === 0xff) {
972
- this.marker = this.stream.get8();
973
- if (this.marker !== 0) {
974
- this.markerIndex = 9;
975
- }
976
- }
977
-
978
- temp[0] |= input;
979
- index[0] += 8;
980
- }
981
-
982
- if (index[0] < 0) {
983
- throw new Error(`index=${index[0]} in getn()`);
984
- }
985
-
986
- if (index[0] < this.markerIndex) {
987
- this.markerIndex = 0;
988
-
989
- return (0xff00 | this.marker) << 8;
990
- }
991
-
992
- result = temp[0] >> index[0];
993
- temp[0] &= mask >> (16 - index[0]);
994
- }
995
-
996
- if (result < one << (n - 1)) {
997
- result += (n_one << n) + 1;
998
- }
999
-
1000
- return result;
1001
- };
1002
- jpeg.lossless.Decoder.prototype.getPreviousX = function (compOffset) {
1003
- /*jslint bitwise: true */
1004
-
1005
- if (this.xLoc > 0) {
1006
- return this.getter(
1007
- this.yLoc * this.xDim + this.xLoc - 1,
1008
- compOffset
1009
- );
1010
- } else if (this.yLoc > 0) {
1011
- return this.getPreviousY(compOffset);
1012
- }
1013
-
1014
- return 1 << (this.frame.precision - 1);
1015
- };
1016
-
1017
- jpeg.lossless.Decoder.prototype.getPreviousXY = function (
1018
- compOffset
1019
- ) {
1020
- /*jslint bitwise: true */
1021
-
1022
- if (this.xLoc > 0 && this.yLoc > 0) {
1023
- return this.getter(
1024
- (this.yLoc - 1) * this.xDim + this.xLoc - 1,
1025
- compOffset
1026
- );
1027
- }
1028
-
1029
- return this.getPreviousY(compOffset);
1030
- };
1031
- jpeg.lossless.Decoder.prototype.getPreviousY = function (compOffset) {
1032
- /*jslint bitwise: true */
1033
-
1034
- if (this.yLoc > 0) {
1035
- return this.getter(
1036
- (this.yLoc - 1) * this.xDim + this.xLoc,
1037
- compOffset
1038
- );
1039
- }
1040
-
1041
- return this.getPreviousX(compOffset);
1042
- };
1043
- jpeg.lossless.Decoder.prototype.isLastPixel = function () {
1044
- return this.xLoc === this.xDim - 1 && this.yLoc === this.yDim - 1;
1045
- };
1046
- jpeg.lossless.Decoder.prototype.outputSingle = function (PRED) {
1047
- if (this.xLoc < this.xDim && this.yLoc < this.yDim) {
1048
- this.setter(
1049
- this.yLoc * this.xDim + this.xLoc,
1050
- this.mask & PRED[0]
1051
- );
1052
-
1053
- this.xLoc += 1;
1054
-
1055
- if (this.xLoc >= this.xDim) {
1056
- this.yLoc += 1;
1057
- this.xLoc = 0;
1058
- }
1059
- }
1060
- };
1061
- jpeg.lossless.Decoder.prototype.outputRGB = function (PRED) {
1062
- var offset = this.yLoc * this.xDim + this.xLoc;
1063
-
1064
- if (this.xLoc < this.xDim && this.yLoc < this.yDim) {
1065
- this.setter(offset, PRED[0], 0);
1066
- this.setter(offset, PRED[1], 1);
1067
- this.setter(offset, PRED[2], 2);
1068
-
1069
- this.xLoc += 1;
1070
-
1071
- if (this.xLoc >= this.xDim) {
1072
- this.yLoc += 1;
1073
- this.xLoc = 0;
1074
- }
1075
- }
1076
- };
1077
-
1078
- jpeg.lossless.Decoder.prototype.setValue8 = function (index, val) {
1079
- this.outputData[index] = val;
1080
- };
1081
-
1082
- jpeg.lossless.Decoder.prototype.getValue8 = function (index) {
1083
- return this.outputData[index]; // mask should not be necessary because outputData is either Int8Array or Int16Array
1084
- };
1085
-
1086
- var littleEndian = (function () {
1087
- var buffer = new ArrayBuffer(2);
1088
-
1089
- new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
1090
- // Int16Array uses the platform's endianness.
1091
- return new Int16Array(buffer)[0] === 256;
1092
- })();
1093
-
1094
- if (littleEndian) {
1095
- // just reading from an array is fine then. Int16Array will use platform endianness.
1096
- jpeg.lossless.Decoder.prototype.setValue16 =
1097
- jpeg.lossless.Decoder.prototype.setValue8;
1098
- jpeg.lossless.Decoder.prototype.getValue16 =
1099
- jpeg.lossless.Decoder.prototype.getValue8;
1100
- } else {
1101
- // If platform is big-endian, we will need to convert to little-endian
1102
- jpeg.lossless.Decoder.prototype.setValue16 = function (index, val) {
1103
- this.outputData[index] =
1104
- ((val & 0xff) << 8) | ((val >> 8) & 0xff);
1105
- };
1106
-
1107
- jpeg.lossless.Decoder.prototype.getValue16 = function (index) {
1108
- var val = this.outputData[index];
1109
-
1110
- return ((val & 0xff) << 8) | ((val >> 8) & 0xff);
1111
- };
1112
- }
1113
-
1114
- jpeg.lossless.Decoder.prototype.setValueRGB = function (
1115
- index,
1116
- val,
1117
- compOffset
1118
- ) {
1119
- // this.outputData.setUint8(index * 3 + compOffset, val);
1120
- this.outputData[index * 3 + compOffset] = val;
1121
- };
1122
-
1123
- jpeg.lossless.Decoder.prototype.getValueRGB = function (
1124
- index,
1125
- compOffset
1126
- ) {
1127
- // return this.outputData.getUint8(index * 3 + compOffset);
1128
- return this.outputData[index * 3 + compOffset];
1129
- };
1130
- jpeg.lossless.Decoder.prototype.readApp = function () {
1131
- var count = 0,
1132
- length = this.stream.get16();
1133
-
1134
- count += 2;
1135
-
1136
- while (count < length) {
1137
- this.stream.get8();
1138
- count += 1;
1139
- }
1140
-
1141
- return length;
1142
- };
1143
- jpeg.lossless.Decoder.prototype.readComment = function () {
1144
- var sb = '',
1145
- count = 0,
1146
- length;
1147
-
1148
- length = this.stream.get16();
1149
- count += 2;
1150
-
1151
- while (count < length) {
1152
- sb += this.stream.get8();
1153
- count += 1;
1154
- }
1155
-
1156
- return sb;
1157
- };
1158
- jpeg.lossless.Decoder.prototype.readNumber = function () {
1159
- var Ld = this.stream.get16();
1160
-
1161
- if (Ld !== 4) {
1162
- throw new Error(
1163
- 'ERROR: Define number format throw new IOException [Ld!=4]'
1164
- );
1165
- }
1166
-
1167
- return this.stream.get16();
1168
- };
1169
- /*** Exports ***/
1170
-
1171
- var moduleType = typeof module;
1172
-
1173
- if (moduleType !== 'undefined' && module.exports) {
1174
- module.exports = jpeg.lossless.Decoder;
1175
- }
1176
- },
1177
- {
1178
- './data-stream.js': 2,
1179
- './frame-header.js': 4,
1180
- './huffman-table.js': 5,
1181
- './quantization-table.js': 7,
1182
- './scan-header.js': 9,
1183
- './utils.js': 10,
1184
- },
1185
- ],
1186
- 4: [
1187
- function (require, module, exports) {
1188
- /*
1189
- * Copyright (C) 2015 Michael Martinez
1190
- * Changes: Added support for selection values 2-7, fixed minor bugs &
1191
- * warnings, split into multiple class files, and general clean up.
1192
- *
1193
- * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
1194
- */
1195
-
1196
- /*
1197
- * Copyright (C) Helmut Dersch
1198
- *
1199
- * Permission is hereby granted, free of charge, to any person obtaining a copy
1200
- * of this software and associated documentation files (the "Software"), to deal
1201
- * in the Software without restriction, including without limitation the rights
1202
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1203
- * copies of the Software, and to permit persons to whom the Software is
1204
- * furnished to do so, subject to the following conditions:
1205
-
1206
- * The above copyright notice and this permission notice shall be included in
1207
- * all copies or substantial portions of the Software.
1208
-
1209
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1210
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1211
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1212
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1213
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1214
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1215
- * THE SOFTWARE.
1216
- */
1217
-
1218
- /*jslint browser: true, node: true */
1219
- /*global require, module */
1220
- /*** Imports ***/
1221
- var jpeg = jpeg || {};
1222
-
1223
- jpeg.lossless = jpeg.lossless || {};
1224
- jpeg.lossless.ComponentSpec =
1225
- jpeg.lossless.ComponentSpec ||
1226
- (typeof require !== 'undefined'
1227
- ? require('./component-spec.js')
1228
- : null);
1229
- jpeg.lossless.DataStream =
1230
- jpeg.lossless.DataStream ||
1231
- (typeof require !== 'undefined'
1232
- ? require('./data-stream.js')
1233
- : null);
1234
-
1235
- /*** Constructor ***/
1236
- jpeg.lossless.FrameHeader =
1237
- jpeg.lossless.FrameHeader ||
1238
- function () {
1239
- this.components = []; // Components
1240
- this.dimX = 0; // Number of samples per line
1241
- this.dimY = 0; // Number of lines
1242
- this.numComp = 0; // Number of component in the frame
1243
- this.precision = 0; // Sample Precision (from the original image)
1244
- };
1245
- /*** Prototype Methods ***/
1246
-
1247
- jpeg.lossless.FrameHeader.prototype.read = function (data) {
1248
- /*jslint bitwise: true */
1249
-
1250
- var count = 0,
1251
- length,
1252
- i,
1253
- c,
1254
- temp;
1255
-
1256
- length = data.get16();
1257
- count += 2;
1258
-
1259
- this.precision = data.get8();
1260
- count += 1;
1261
-
1262
- this.dimY = data.get16();
1263
- count += 2;
1264
-
1265
- this.dimX = data.get16();
1266
- count += 2;
1267
-
1268
- this.numComp = data.get8();
1269
- count += 1;
1270
- for (i = 1; i <= this.numComp; i += 1) {
1271
- if (count > length) {
1272
- throw new Error('ERROR: frame format error');
1273
- }
1274
-
1275
- c = data.get8();
1276
- count += 1;
1277
-
1278
- if (count >= length) {
1279
- throw new Error('ERROR: frame format error [c>=Lf]');
1280
- }
1281
-
1282
- temp = data.get8();
1283
- count += 1;
1284
-
1285
- if (!this.components[c]) {
1286
- this.components[c] = new jpeg.lossless.ComponentSpec();
1287
- }
1288
-
1289
- this.components[c].hSamp = temp >> 4;
1290
- this.components[c].vSamp = temp & 0x0f;
1291
- this.components[c].quantTableSel = data.get8();
1292
- count += 1;
1293
- }
1294
-
1295
- if (count !== length) {
1296
- throw new Error('ERROR: frame format error [Lf!=count]');
1297
- }
1298
-
1299
- return 1;
1300
- };
1301
-
1302
- /*** Exports ***/
1303
-
1304
- var moduleType = typeof module;
1305
-
1306
- if (moduleType !== 'undefined' && module.exports) {
1307
- module.exports = jpeg.lossless.FrameHeader;
1308
- }
1309
- },
1310
- { './component-spec.js': 1, './data-stream.js': 2 },
1311
- ],
1312
- 5: [
1313
- function (require, module, exports) {
1314
- /*
1315
- * Copyright (C) 2015 Michael Martinez
1316
- * Changes: Added support for selection values 2-7, fixed minor bugs &
1317
- * warnings, split into multiple class files, and general clean up.
1318
- *
1319
- * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
1320
- */
1321
-
1322
- /*
1323
- * Copyright (C) Helmut Dersch
1324
- *
1325
- * Permission is hereby granted, free of charge, to any person obtaining a copy
1326
- * of this software and associated documentation files (the "Software"), to deal
1327
- * in the Software without restriction, including without limitation the rights
1328
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1329
- * copies of the Software, and to permit persons to whom the Software is
1330
- * furnished to do so, subject to the following conditions:
1331
-
1332
- * The above copyright notice and this permission notice shall be included in
1333
- * all copies or substantial portions of the Software.
1334
-
1335
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1336
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1337
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1338
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1339
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1340
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1341
- * THE SOFTWARE.
1342
- */
1343
-
1344
- /*jslint browser: true, node: true */
1345
- /*global require, module */
1346
-
1347
- /*** Imports ***/
1348
- var jpeg = jpeg || {};
1349
-
1350
- jpeg.lossless = jpeg.lossless || {};
1351
- jpeg.lossless.DataStream =
1352
- jpeg.lossless.DataStream ||
1353
- (typeof require !== 'undefined'
1354
- ? require('./data-stream.js')
1355
- : null);
1356
- jpeg.lossless.Utils =
1357
- jpeg.lossless.Utils ||
1358
- (typeof require !== 'undefined' ? require('./utils.js') : null);
1359
-
1360
- /*** Constructor ***/
1361
- jpeg.lossless.HuffmanTable =
1362
- jpeg.lossless.HuffmanTable ||
1363
- function () {
1364
- this.l = jpeg.lossless.Utils.createArray(4, 2, 16);
1365
- this.th = [];
1366
- this.v = jpeg.lossless.Utils.createArray(4, 2, 16, 200);
1367
- this.tc = jpeg.lossless.Utils.createArray(4, 2);
1368
-
1369
- this.tc[0][0] = 0;
1370
- this.tc[1][0] = 0;
1371
- this.tc[2][0] = 0;
1372
- this.tc[3][0] = 0;
1373
- this.tc[0][1] = 0;
1374
- this.tc[1][1] = 0;
1375
- this.tc[2][1] = 0;
1376
- this.tc[3][1] = 0;
1377
- this.th[0] = 0;
1378
- this.th[1] = 0;
1379
- this.th[2] = 0;
1380
- this.th[3] = 0;
1381
- };
1382
- /*** Static Pseudo-constants ***/
1383
-
1384
- jpeg.lossless.HuffmanTable.MSB = 0x80000000;
1385
-
1386
- /*** Prototype Methods ***/
1387
-
1388
- jpeg.lossless.HuffmanTable.prototype.read = function (data, HuffTab) {
1389
- /*jslint bitwise: true */
1390
-
1391
- var count = 0,
1392
- length,
1393
- temp,
1394
- t,
1395
- c,
1396
- i,
1397
- j;
1398
-
1399
- length = data.get16();
1400
- count += 2;
1401
-
1402
- while (count < length) {
1403
- temp = data.get8();
1404
- count += 1;
1405
- t = temp & 0x0f;
1406
- if (t > 3) {
1407
- throw new Error('ERROR: Huffman table ID > 3');
1408
- }
1409
-
1410
- c = temp >> 4;
1411
- if (c > 2) {
1412
- throw new Error('ERROR: Huffman table [Table class > 2 ]');
1413
- }
1414
-
1415
- this.th[t] = 1;
1416
- this.tc[t][c] = 1;
1417
-
1418
- for (i = 0; i < 16; i += 1) {
1419
- this.l[t][c][i] = data.get8();
1420
- count += 1;
1421
- }
1422
-
1423
- for (i = 0; i < 16; i += 1) {
1424
- for (j = 0; j < this.l[t][c][i]; j += 1) {
1425
- if (count > length) {
1426
- throw new Error(
1427
- 'ERROR: Huffman table format error [count>Lh]'
1428
- );
1429
- }
1430
-
1431
- this.v[t][c][i][j] = data.get8();
1432
- count += 1;
1433
- }
1434
- }
1435
- }
1436
-
1437
- if (count !== length) {
1438
- throw new Error('ERROR: Huffman table format error [count!=Lf]');
1439
- }
1440
-
1441
- for (i = 0; i < 4; i += 1) {
1442
- for (j = 0; j < 2; j += 1) {
1443
- if (this.tc[i][j] !== 0) {
1444
- this.buildHuffTable(
1445
- HuffTab[i][j],
1446
- this.l[i][j],
1447
- this.v[i][j]
1448
- );
1449
- }
1450
- }
1451
- }
1452
-
1453
- return 1;
1454
- };
1455
- // Build_HuffTab()
1456
- // Parameter: t table ID
1457
- // c table class ( 0 for DC, 1 for AC )
1458
- // L[i] # of codewords which length is i
1459
- // V[i][j] Huffman Value (length=i)
1460
- // Effect:
1461
- // build up HuffTab[t][c] using L and V.
1462
- jpeg.lossless.HuffmanTable.prototype.buildHuffTable = function (
1463
- tab,
1464
- L,
1465
- V
1466
- ) {
1467
- /*jslint bitwise: true */
1468
-
1469
- var currentTable, temp, k, i, j, n;
1470
-
1471
- temp = 256;
1472
- k = 0;
1473
-
1474
- for (i = 0; i < 8; i += 1) {
1475
- // i+1 is Code length
1476
- for (j = 0; j < L[i]; j += 1) {
1477
- for (n = 0; n < temp >> (i + 1); n += 1) {
1478
- tab[k] = V[i][j] | ((i + 1) << 8);
1479
- k += 1;
1480
- }
1481
- }
1482
- }
1483
-
1484
- for (i = 1; k < 256; i += 1, k += 1) {
1485
- tab[k] = i | jpeg.lossless.HuffmanTable.MSB;
1486
- }
1487
-
1488
- currentTable = 1;
1489
- k = 0;
1490
-
1491
- for (i = 8; i < 16; i += 1) {
1492
- // i+1 is Code length
1493
- for (j = 0; j < L[i]; j += 1) {
1494
- for (n = 0; n < temp >> (i - 7); n += 1) {
1495
- tab[currentTable * 256 + k] = V[i][j] | ((i + 1) << 8);
1496
- k += 1;
1497
- }
1498
-
1499
- if (k >= 256) {
1500
- if (k > 256) {
1501
- throw new Error('ERROR: Huffman table error(1)!');
1502
- }
1503
-
1504
- k = 0;
1505
- currentTable += 1;
1506
- }
1507
- }
1508
- }
1509
- };
1510
-
1511
- /*** Exports ***/
1512
-
1513
- var moduleType = typeof module;
1514
-
1515
- if (moduleType !== 'undefined' && module.exports) {
1516
- module.exports = jpeg.lossless.HuffmanTable;
1517
- }
1518
- },
1519
- { './data-stream.js': 2, './utils.js': 10 },
1520
- ],
1521
- 6: [
1522
- function (require, module, exports) {
1523
- /*jslint browser: true, node: true */
1524
- /*global require, module */
1525
-
1526
- /*** Imports ****/
1527
-
1528
- /**
1529
- * jpeg
1530
- * @type {*|{}}
1531
- */
1532
- var jpeg = jpeg || {};
1533
-
1534
- /**
1535
- * jpeg.lossless
1536
- * @type {*|{}}
1537
- */
1538
- jpeg.lossless = jpeg.lossless || {};
1539
-
1540
- jpeg.lossless.ComponentSpec =
1541
- jpeg.lossless.ComponentSpec ||
1542
- (typeof require !== 'undefined'
1543
- ? require('./component-spec.js')
1544
- : null);
1545
- jpeg.lossless.DataStream =
1546
- jpeg.lossless.DataStream ||
1547
- (typeof require !== 'undefined'
1548
- ? require('./data-stream.js')
1549
- : null);
1550
- jpeg.lossless.Decoder =
1551
- jpeg.lossless.Decoder ||
1552
- (typeof require !== 'undefined' ? require('./decoder.js') : null);
1553
- jpeg.lossless.FrameHeader =
1554
- jpeg.lossless.FrameHeader ||
1555
- (typeof require !== 'undefined'
1556
- ? require('./frame-header.js')
1557
- : null);
1558
- jpeg.lossless.HuffmanTable =
1559
- jpeg.lossless.HuffmanTable ||
1560
- (typeof require !== 'undefined'
1561
- ? require('./huffman-table.js')
1562
- : null);
1563
- jpeg.lossless.QuantizationTable =
1564
- jpeg.lossless.QuantizationTable ||
1565
- (typeof require !== 'undefined'
1566
- ? require('./quantization-table.js')
1567
- : null);
1568
- jpeg.lossless.ScanComponent =
1569
- jpeg.lossless.ScanComponent ||
1570
- (typeof require !== 'undefined'
1571
- ? require('./scan-component.js')
1572
- : null);
1573
- jpeg.lossless.ScanHeader =
1574
- jpeg.lossless.ScanHeader ||
1575
- (typeof require !== 'undefined'
1576
- ? require('./scan-header.js')
1577
- : null);
1578
- jpeg.lossless.Utils =
1579
- jpeg.lossless.Utils ||
1580
- (typeof require !== 'undefined' ? require('./utils.js') : null);
1581
-
1582
- /*** Exports ***/
1583
- var moduleType = typeof module;
1584
-
1585
- if (moduleType !== 'undefined' && module.exports) {
1586
- module.exports = jpeg;
1587
- }
1588
- },
1589
- {
1590
- './component-spec.js': 1,
1591
- './data-stream.js': 2,
1592
- './decoder.js': 3,
1593
- './frame-header.js': 4,
1594
- './huffman-table.js': 5,
1595
- './quantization-table.js': 7,
1596
- './scan-component.js': 8,
1597
- './scan-header.js': 9,
1598
- './utils.js': 10,
1599
- },
1600
- ],
1601
- 7: [
1602
- function (require, module, exports) {
1603
- /*
1604
- * Copyright (C) 2015 Michael Martinez
1605
- * Changes: Added support for selection values 2-7, fixed minor bugs &
1606
- * warnings, split into multiple class files, and general clean up.
1607
- *
1608
- * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
1609
- */
1610
-
1611
- /*
1612
- * Copyright (C) Helmut Dersch
1613
- *
1614
- * Permission is hereby granted, free of charge, to any person obtaining a copy
1615
- * of this software and associated documentation files (the "Software"), to deal
1616
- * in the Software without restriction, including without limitation the rights
1617
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1618
- * copies of the Software, and to permit persons to whom the Software is
1619
- * furnished to do so, subject to the following conditions:
1620
-
1621
- * The above copyright notice and this permission notice shall be included in
1622
- * all copies or substantial portions of the Software.
1623
-
1624
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1625
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1626
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1627
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1628
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1629
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1630
- * THE SOFTWARE.
1631
- */
1632
-
1633
- /*jslint browser: true, node: true */
1634
- /*global require, module */
1635
- /*** Imports ***/
1636
- var jpeg = jpeg || {};
1637
-
1638
- jpeg.lossless = jpeg.lossless || {};
1639
- jpeg.lossless.DataStream =
1640
- jpeg.lossless.DataStream ||
1641
- (typeof require !== 'undefined'
1642
- ? require('./data-stream.js')
1643
- : null);
1644
- jpeg.lossless.Utils =
1645
- jpeg.lossless.Utils ||
1646
- (typeof require !== 'undefined' ? require('./utils.js') : null);
1647
-
1648
- /*** Constructor ***/
1649
- jpeg.lossless.QuantizationTable =
1650
- jpeg.lossless.QuantizationTable ||
1651
- function () {
1652
- this.precision = []; // Quantization precision 8 or 16
1653
- this.tq = []; // 1: this table is presented
1654
- this.quantTables = jpeg.lossless.Utils.createArray(4, 64); // Tables
1655
-
1656
- this.tq[0] = 0;
1657
- this.tq[1] = 0;
1658
- this.tq[2] = 0;
1659
- this.tq[3] = 0;
1660
- };
1661
- /*** Static Methods ***/
1662
-
1663
- jpeg.lossless.QuantizationTable.enhanceQuantizationTable = function (
1664
- qtab,
1665
- table
1666
- ) {
1667
- /*jslint bitwise: true */
1668
-
1669
- var i;
1670
-
1671
- for (i = 0; i < 8; i += 1) {
1672
- qtab[table[0 * 8 + i]] *= 90;
1673
- qtab[table[4 * 8 + i]] *= 90;
1674
- qtab[table[2 * 8 + i]] *= 118;
1675
- qtab[table[6 * 8 + i]] *= 49;
1676
- qtab[table[5 * 8 + i]] *= 71;
1677
- qtab[table[1 * 8 + i]] *= 126;
1678
- qtab[table[7 * 8 + i]] *= 25;
1679
- qtab[table[3 * 8 + i]] *= 106;
1680
- }
1681
-
1682
- for (i = 0; i < 8; i += 1) {
1683
- qtab[table[0 + 8 * i]] *= 90;
1684
- qtab[table[4 + 8 * i]] *= 90;
1685
- qtab[table[2 + 8 * i]] *= 118;
1686
- qtab[table[6 + 8 * i]] *= 49;
1687
- qtab[table[5 + 8 * i]] *= 71;
1688
- qtab[table[1 + 8 * i]] *= 126;
1689
- qtab[table[7 + 8 * i]] *= 25;
1690
- qtab[table[3 + 8 * i]] *= 106;
1691
- }
1692
-
1693
- for (i = 0; i < 64; i += 1) {
1694
- qtab[i] >>= 6;
1695
- }
1696
- };
1697
-
1698
- /*** Prototype Methods ***/
1699
-
1700
- jpeg.lossless.QuantizationTable.prototype.read = function (
1701
- data,
1702
- table
1703
- ) {
1704
- /*jslint bitwise: true */
1705
-
1706
- var count = 0,
1707
- length,
1708
- temp,
1709
- t,
1710
- i;
1711
-
1712
- length = data.get16();
1713
- count += 2;
1714
-
1715
- while (count < length) {
1716
- temp = data.get8();
1717
- count += 1;
1718
- t = temp & 0x0f;
1719
-
1720
- if (t > 3) {
1721
- throw new Error('ERROR: Quantization table ID > 3');
1722
- }
1723
-
1724
- this.precision[t] = temp >> 4;
1725
-
1726
- if (this.precision[t] === 0) {
1727
- this.precision[t] = 8;
1728
- } else if (this.precision[t] === 1) {
1729
- this.precision[t] = 16;
1730
- } else {
1731
- throw new Error('ERROR: Quantization table precision error');
1732
- }
1733
-
1734
- this.tq[t] = 1;
1735
-
1736
- if (this.precision[t] === 8) {
1737
- for (i = 0; i < 64; i += 1) {
1738
- if (count > length) {
1739
- throw new Error('ERROR: Quantization table format error');
1740
- }
1741
-
1742
- this.quantTables[t][i] = data.get8();
1743
- count += 1;
1744
- }
1745
-
1746
- jpeg.lossless.QuantizationTable.enhanceQuantizationTable(
1747
- this.quantTables[t],
1748
- table
1749
- );
1750
- } else {
1751
- for (i = 0; i < 64; i += 1) {
1752
- if (count > length) {
1753
- throw new Error('ERROR: Quantization table format error');
1754
- }
1755
-
1756
- this.quantTables[t][i] = data.get16();
1757
- count += 2;
1758
- }
1759
-
1760
- jpeg.lossless.QuantizationTable.enhanceQuantizationTable(
1761
- this.quantTables[t],
1762
- table
1763
- );
1764
- }
1765
- }
1766
-
1767
- if (count !== length) {
1768
- throw new Error('ERROR: Quantization table error [count!=Lq]');
1769
- }
1770
-
1771
- return 1;
1772
- };
1773
- /*** Exports ***/
1774
-
1775
- var moduleType = typeof module;
1776
-
1777
- if (moduleType !== 'undefined' && module.exports) {
1778
- module.exports = jpeg.lossless.QuantizationTable;
1779
- }
1780
- },
1781
- { './data-stream.js': 2, './utils.js': 10 },
1782
- ],
1783
- 8: [
1784
- function (require, module, exports) {
1785
- /*
1786
- * Copyright (C) 2015 Michael Martinez
1787
- * Changes: Added support for selection values 2-7, fixed minor bugs &
1788
- * warnings, split into multiple class files, and general clean up.
1789
- *
1790
- * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
1791
- */
1792
-
1793
- /*
1794
- * Copyright (C) Helmut Dersch
1795
- *
1796
- * Permission is hereby granted, free of charge, to any person obtaining a copy
1797
- * of this software and associated documentation files (the "Software"), to deal
1798
- * in the Software without restriction, including without limitation the rights
1799
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1800
- * copies of the Software, and to permit persons to whom the Software is
1801
- * furnished to do so, subject to the following conditions:
1802
-
1803
- * The above copyright notice and this permission notice shall be included in
1804
- * all copies or substantial portions of the Software.
1805
-
1806
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1807
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1808
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1809
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1810
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1811
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1812
- * THE SOFTWARE.
1813
- */
1814
-
1815
- /*jslint browser: true, node: true */
1816
- /*global require, module */
1817
- /*** Imports ***/
1818
- var jpeg = jpeg || {};
1819
-
1820
- jpeg.lossless = jpeg.lossless || {};
1821
-
1822
- /*** Constructor ***/
1823
- jpeg.lossless.ScanComponent =
1824
- jpeg.lossless.ScanComponent ||
1825
- function () {
1826
- this.acTabSel = 0; // AC table selector
1827
- this.dcTabSel = 0; // DC table selector
1828
- this.scanCompSel = 0; // Scan component selector
1829
- };
1830
- /*** Exports ***/
1831
-
1832
- var moduleType = typeof module;
1833
-
1834
- if (moduleType !== 'undefined' && module.exports) {
1835
- module.exports = jpeg.lossless.ScanComponent;
1836
- }
1837
- },
1838
- {},
1839
- ],
1840
- 9: [
1841
- function (require, module, exports) {
1842
- /*
1843
- * Copyright (C) 2015 Michael Martinez
1844
- * Changes: Added support for selection values 2-7, fixed minor bugs &
1845
- * warnings, split into multiple class files, and general clean up.
1846
- *
1847
- * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
1848
- */
1849
-
1850
- /*
1851
- * Copyright (C) Helmut Dersch
1852
- *
1853
- * Permission is hereby granted, free of charge, to any person obtaining a copy
1854
- * of this software and associated documentation files (the "Software"), to deal
1855
- * in the Software without restriction, including without limitation the rights
1856
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1857
- * copies of the Software, and to permit persons to whom the Software is
1858
- * furnished to do so, subject to the following conditions:
1859
-
1860
- * The above copyright notice and this permission notice shall be included in
1861
- * all copies or substantial portions of the Software.
1862
-
1863
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1864
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1865
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1866
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1867
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1868
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1869
- * THE SOFTWARE.
1870
- */
1871
-
1872
- /*jslint browser: true, node: true */
1873
- /*global require, module */
1874
- /*** Imports ***/
1875
- var jpeg = jpeg || {};
1876
-
1877
- jpeg.lossless = jpeg.lossless || {};
1878
- jpeg.lossless.DataStream =
1879
- jpeg.lossless.DataStream ||
1880
- (typeof require !== 'undefined'
1881
- ? require('./data-stream.js')
1882
- : null);
1883
- jpeg.lossless.ScanComponent =
1884
- jpeg.lossless.ScanComponent ||
1885
- (typeof require !== 'undefined'
1886
- ? require('./scan-component.js')
1887
- : null);
1888
-
1889
- /*** Constructor ***/
1890
- jpeg.lossless.ScanHeader =
1891
- jpeg.lossless.ScanHeader ||
1892
- function () {
1893
- this.ah = 0;
1894
- this.al = 0;
1895
- this.numComp = 0; // Number of components in the scan
1896
- this.selection = 0; // Start of spectral or predictor selection
1897
- this.spectralEnd = 0; // End of spectral selection
1898
- this.components = [];
1899
- };
1900
-
1901
- /*** Prototype Methods ***/
1902
-
1903
- jpeg.lossless.ScanHeader.prototype.read = function (data) {
1904
- /*jslint bitwise: true */
1905
-
1906
- var count = 0,
1907
- length,
1908
- i,
1909
- temp;
1910
-
1911
- length = data.get16();
1912
- count += 2;
1913
-
1914
- this.numComp = data.get8();
1915
- count += 1;
1916
-
1917
- for (i = 0; i < this.numComp; i += 1) {
1918
- this.components[i] = new jpeg.lossless.ScanComponent();
1919
-
1920
- if (count > length) {
1921
- throw new Error('ERROR: scan header format error');
1922
- }
1923
-
1924
- this.components[i].scanCompSel = data.get8();
1925
- count += 1;
1926
-
1927
- temp = data.get8();
1928
- count += 1;
1929
-
1930
- this.components[i].dcTabSel = temp >> 4;
1931
- this.components[i].acTabSel = temp & 0x0f;
1932
- }
1933
-
1934
- this.selection = data.get8();
1935
- count += 1;
1936
-
1937
- this.spectralEnd = data.get8();
1938
- count += 1;
1939
-
1940
- temp = data.get8();
1941
- this.ah = temp >> 4;
1942
- this.al = temp & 0x0f;
1943
- count += 1;
1944
-
1945
- if (count !== length) {
1946
- throw new Error('ERROR: scan header format error [count!=Ns]');
1947
- }
1948
-
1949
- return 1;
1950
- };
1951
- /*** Exports ***/
1952
-
1953
- var moduleType = typeof module;
1954
-
1955
- if (moduleType !== 'undefined' && module.exports) {
1956
- module.exports = jpeg.lossless.ScanHeader;
1957
- }
1958
- },
1959
- { './data-stream.js': 2, './scan-component.js': 8 },
1960
- ],
1961
- 10: [
1962
- function (require, module, exports) {
1963
- /*
1964
- * Copyright (C) 2015 Michael Martinez
1965
- * Changes: Added support for selection values 2-7, fixed minor bugs &
1966
- * warnings, split into multiple class files, and general clean up.
1967
- *
1968
- * 08-25-2015: Helmut Dersch agreed to a license change from LGPL to MIT.
1969
- */
1970
-
1971
- /*
1972
- * Copyright (C) Helmut Dersch
1973
- *
1974
- * Permission is hereby granted, free of charge, to any person obtaining a copy
1975
- * of this software and associated documentation files (the "Software"), to deal
1976
- * in the Software without restriction, including without limitation the rights
1977
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1978
- * copies of the Software, and to permit persons to whom the Software is
1979
- * furnished to do so, subject to the following conditions:
1980
-
1981
- * The above copyright notice and this permission notice shall be included in
1982
- * all copies or substantial portions of the Software.
1983
-
1984
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1985
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1986
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1987
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1988
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1989
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1990
- * THE SOFTWARE.
1991
- */
1992
-
1993
- /*jslint browser: true, node: true */
1994
- /*global require, module */
1995
- /*** Imports ***/
1996
- var jpeg = jpeg || {};
1997
-
1998
- jpeg.lossless = jpeg.lossless || {};
1999
-
2000
- /*** Constructor ***/
2001
- jpeg.lossless.Utils = jpeg.lossless.Utils || {};
2002
-
2003
- /*** Static methods ***/
2004
-
2005
- // http://stackoverflow.com/questions/966225/how-can-i-create-a-two-dimensional-array-in-javascript
2006
- jpeg.lossless.Utils.createArray = function (length) {
2007
- var arr = new Array(length || 0),
2008
- i = length;
2009
-
2010
- if (arguments.length > 1) {
2011
- var args = Array.prototype.slice.call(arguments, 1);
2012
-
2013
- while (i--) {
2014
- arr[length - 1 - i] = jpeg.lossless.Utils.createArray.apply(
2015
- this,
2016
- args
2017
- );
2018
- }
2019
- }
2020
-
2021
- return arr;
2022
- };
2023
-
2024
- // http://stackoverflow.com/questions/18638900/javascript-crc32
2025
- jpeg.lossless.Utils.makeCRCTable = function () {
2026
- var c;
2027
- var crcTable = [];
2028
-
2029
- for (var n = 0; n < 256; n++) {
2030
- c = n;
2031
- for (var k = 0; k < 8; k++) {
2032
- c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
2033
- }
2034
- crcTable[n] = c;
2035
- }
2036
-
2037
- return crcTable;
2038
- };
2039
-
2040
- jpeg.lossless.Utils.crc32 = function (dataView) {
2041
- var uint8view = new Uint8Array(dataView.buffer);
2042
- var crcTable =
2043
- jpeg.lossless.Utils.crcTable ||
2044
- (jpeg.lossless.Utils.crcTable =
2045
- jpeg.lossless.Utils.makeCRCTable());
2046
- var crc = 0 ^ -1;
2047
-
2048
- for (var i = 0; i < uint8view.length; i++) {
2049
- crc = (crc >>> 8) ^ crcTable[(crc ^ uint8view[i]) & 0xff];
2050
- }
2051
-
2052
- return (crc ^ -1) >>> 0;
2053
- };
2054
-
2055
- /*** Exports ***/
2056
-
2057
- var moduleType = typeof module;
2058
-
2059
- if (moduleType !== 'undefined' && module.exports) {
2060
- module.exports = jpeg.lossless.Utils;
2061
- }
2062
- },
2063
- {},
2064
- ],
2065
- },
2066
- {},
2067
- [6]
2068
- )(6);
2069
- });
2070
-
2071
-
2072
- /***/ })
2073
-
2074
- }]);
2075
- //# sourceMappingURL=codecs_jpegLossless_js.min.worker.js.map