dwv 0.25.2 → 0.26.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.
- package/decoders/dwv/decode-rle.js +22 -0
- package/decoders/dwv/rle.js +103 -0
- package/decoders/pdfjs/arithmetic_decoder.js +185 -185
- package/decoders/pdfjs/decode-jpeg2000.js +18 -18
- package/decoders/pdfjs/decode-jpegbaseline.js +18 -18
- package/decoders/pdfjs/jpg.js +1072 -1072
- package/decoders/pdfjs/jpx.js +2237 -2237
- package/decoders/pdfjs/readme.md +15 -15
- package/decoders/pdfjs/util.js +1588 -1588
- package/decoders/rii-mango/decode-jpegloss.js +34 -37
- package/decoders/rii-mango/lossless.js +1755 -1755
- package/decoders/rii-mango/readme.md +12 -12
- package/dist/dwv.js +27537 -27189
- package/dist/dwv.min.js +3 -3
- package/license.txt +674 -674
- package/locales/de/overlays.json +62 -62
- package/locales/de/translation.json +236 -236
- package/locales/en/overlays.json +62 -62
- package/locales/en/translation.json +236 -236
- package/locales/es/overlays.json +62 -62
- package/locales/es/translation.json +236 -236
- package/locales/fr/overlays.json +62 -62
- package/locales/fr/translation.json +236 -236
- package/locales/it/overlays.json +62 -62
- package/locales/it/translation.json +236 -236
- package/locales/jp/overlays.json +62 -62
- package/locales/jp/translation.json +236 -236
- package/locales/ro/overlays.json +62 -62
- package/locales/ro/translation.json +236 -236
- package/locales/ru/overlays.json +62 -62
- package/locales/ru/translation.json +236 -236
- package/locales/zh/overlays.json +62 -62
- package/locales/zh/translation.json +236 -236
- package/package.json +50 -51
- package/readme.md +66 -42
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RLE decoder worker.
|
|
3
|
+
*/
|
|
4
|
+
// Do not warn if these variables were not defined before.
|
|
5
|
+
/* global importScripts, self, JpxImage */
|
|
6
|
+
|
|
7
|
+
importScripts('rle.js');
|
|
8
|
+
|
|
9
|
+
self.addEventListener('message', function (event) {
|
|
10
|
+
|
|
11
|
+
// decode DICOM buffer
|
|
12
|
+
var decoder = new dwv.decoder.RleDecoder();
|
|
13
|
+
// post decoded data
|
|
14
|
+
self.postMessage([decoder.decode(
|
|
15
|
+
event.data.buffer,
|
|
16
|
+
event.data.meta.bitsAllocated,
|
|
17
|
+
event.data.meta.isSigned,
|
|
18
|
+
event.data.meta.sliceSize,
|
|
19
|
+
event.data.meta.samplesPerPixel,
|
|
20
|
+
event.data.meta.planarConfiguration )]);
|
|
21
|
+
|
|
22
|
+
}, false);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// namespaces
|
|
2
|
+
var dwv = dwv || {};
|
|
3
|
+
dwv.decoder = dwv.decoder || {};
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* RLE (Run-length encoding) decoder class.
|
|
7
|
+
* @constructor
|
|
8
|
+
*/
|
|
9
|
+
dwv.decoder.RleDecoder = function () {};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Decode a RLE buffer.
|
|
13
|
+
* @param {Array} buffer The buffer to decode.
|
|
14
|
+
* @param {Number} bitsAllocated The bits allocated per element in the buffer.
|
|
15
|
+
* @param {Boolean} isSigned Is the data signed.
|
|
16
|
+
* @param {Number} sliceSize The size of a slice
|
|
17
|
+
(number of rows per number of columns).
|
|
18
|
+
* @param {Number} samplesPerPixel The number of samples per pixel (3 for RGB).
|
|
19
|
+
* @param {Number} planarConfiguration The planar configuration.
|
|
20
|
+
* @returns The decoded buffer.
|
|
21
|
+
* @see http://dicom.nema.org/dicom/2013/output/chtml/part05/sect_G.3.html
|
|
22
|
+
*/
|
|
23
|
+
dwv.decoder.RleDecoder.prototype.decode = function ( buffer,
|
|
24
|
+
bitsAllocated, isSigned, sliceSize, samplesPerPixel, planarConfiguration ) {
|
|
25
|
+
|
|
26
|
+
// bytes per element
|
|
27
|
+
var bpe = bitsAllocated / 8;
|
|
28
|
+
|
|
29
|
+
// input
|
|
30
|
+
var inputDataView = new DataView(buffer.buffer, buffer.byteOffset);
|
|
31
|
+
var inputArray = new Int8Array(buffer.buffer, buffer.byteOffset);
|
|
32
|
+
// output
|
|
33
|
+
var outputBuffer = new ArrayBuffer(sliceSize * samplesPerPixel * bpe);
|
|
34
|
+
var outputArray = new Int8Array(outputBuffer);
|
|
35
|
+
|
|
36
|
+
// first value of the RLE header is the number of segments
|
|
37
|
+
var numberOfSegments = inputDataView.getInt32(0, true);
|
|
38
|
+
// loop on segments
|
|
39
|
+
var outputIndex = 0;
|
|
40
|
+
var outputIndexIncrement = 1;
|
|
41
|
+
if (planarConfiguration === 0) {
|
|
42
|
+
outputIndexIncrement = samplesPerPixel;
|
|
43
|
+
}
|
|
44
|
+
var inputIndex = 0;
|
|
45
|
+
for (var segment = 0; segment < numberOfSegments; ++segment) {
|
|
46
|
+
// one segment per channel, interlace them if needed
|
|
47
|
+
if (samplesPerPixel !== 1 && planarConfiguration === 0) {
|
|
48
|
+
outputIndex = segment;
|
|
49
|
+
}
|
|
50
|
+
// RLE header: list of segment sizes
|
|
51
|
+
var segmentStartIndex = inputDataView.getInt32((segment + 1) * 4, true);
|
|
52
|
+
var nextSegmentStartIndex = inputDataView.getInt32((segment + 2) * 4, true);
|
|
53
|
+
if (segment === numberOfSegments - 1 || nextSegmentStartIndex === 0) {
|
|
54
|
+
nextSegmentStartIndex = buffer.length;
|
|
55
|
+
}
|
|
56
|
+
// decode segment
|
|
57
|
+
inputIndex = segmentStartIndex;
|
|
58
|
+
var count = 0;
|
|
59
|
+
while (inputIndex < nextSegmentStartIndex) {
|
|
60
|
+
// get the count value
|
|
61
|
+
count = inputArray[inputIndex];
|
|
62
|
+
++inputIndex;
|
|
63
|
+
// store according to count
|
|
64
|
+
if (count >= 0 && count <= 127) {
|
|
65
|
+
// output the next count+1 bytes literally
|
|
66
|
+
for (var i = 0; i < count + 1; ++i) {
|
|
67
|
+
// store
|
|
68
|
+
outputArray[outputIndex * bpe] = inputArray[inputIndex];
|
|
69
|
+
// increment indexes
|
|
70
|
+
++inputIndex;
|
|
71
|
+
outputIndex += outputIndexIncrement;
|
|
72
|
+
}
|
|
73
|
+
} else if (count <= -1 && count >= -127) {
|
|
74
|
+
// output the next byte -count+1 times
|
|
75
|
+
var value = inputArray[inputIndex];
|
|
76
|
+
++inputIndex;
|
|
77
|
+
for (var j = 0; j < -count + 1; ++j) {
|
|
78
|
+
// store
|
|
79
|
+
outputArray[outputIndex * bpe] = value;
|
|
80
|
+
// increment index
|
|
81
|
+
outputIndex += outputIndexIncrement;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
var decodedBuffer = null;
|
|
88
|
+
if (bitsAllocated === 8) {
|
|
89
|
+
if (isSigned) {
|
|
90
|
+
decodedBuffer = new Int8Array(outputBuffer);
|
|
91
|
+
} else {
|
|
92
|
+
decodedBuffer = new Uint8Array(outputBuffer);
|
|
93
|
+
}
|
|
94
|
+
} else if (bitsAllocated === 16) {
|
|
95
|
+
if (isSigned) {
|
|
96
|
+
decodedBuffer = new Int16Array(outputBuffer);
|
|
97
|
+
} else {
|
|
98
|
+
decodedBuffer = new Uint16Array(outputBuffer);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return decodedBuffer;
|
|
103
|
+
};
|
|
@@ -1,185 +1,185 @@
|
|
|
1
|
-
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
2
|
-
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
|
3
|
-
/* Copyright 2012 Mozilla Foundation
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
'use strict';
|
|
19
|
-
|
|
20
|
-
/* This class implements the QM Coder decoding as defined in
|
|
21
|
-
* JPEG 2000 Part I Final Committee Draft Version 1.0
|
|
22
|
-
* Annex C.3 Arithmetic decoding procedure
|
|
23
|
-
* available at http://www.jpeg.org/public/fcd15444-1.pdf
|
|
24
|
-
*
|
|
25
|
-
* The arithmetic decoder is used in conjunction with context models to decode
|
|
26
|
-
* JPEG2000 and JBIG2 streams.
|
|
27
|
-
*/
|
|
28
|
-
var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
|
|
29
|
-
// Table C-2
|
|
30
|
-
var QeTable = [
|
|
31
|
-
{qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
|
|
32
|
-
{qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
|
|
33
|
-
{qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
|
|
34
|
-
{qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
|
|
35
|
-
{qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
|
|
36
|
-
{qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
|
|
37
|
-
{qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
|
|
38
|
-
{qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
|
|
39
|
-
{qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
|
|
40
|
-
{qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
|
|
41
|
-
{qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
|
|
42
|
-
{qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
|
|
43
|
-
{qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
|
|
44
|
-
{qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
|
|
45
|
-
{qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
|
|
46
|
-
{qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
|
|
47
|
-
{qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
|
|
48
|
-
{qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
|
|
49
|
-
{qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
|
|
50
|
-
{qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
|
|
51
|
-
{qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
|
|
52
|
-
{qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
|
|
53
|
-
{qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
|
|
54
|
-
{qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
|
|
55
|
-
{qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
|
|
56
|
-
{qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
|
|
57
|
-
{qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
|
|
58
|
-
{qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
|
|
59
|
-
{qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
|
|
60
|
-
{qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
|
|
61
|
-
{qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
|
|
62
|
-
{qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
|
|
63
|
-
{qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
|
|
64
|
-
{qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
|
|
65
|
-
{qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
|
|
66
|
-
{qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
|
|
67
|
-
{qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
|
|
68
|
-
{qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
|
|
69
|
-
{qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
|
|
70
|
-
{qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
|
|
71
|
-
{qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
|
|
72
|
-
{qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
|
|
73
|
-
{qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
|
|
74
|
-
{qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
|
|
75
|
-
{qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
|
|
76
|
-
{qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
|
|
77
|
-
{qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
|
|
78
|
-
];
|
|
79
|
-
|
|
80
|
-
// C.3.5 Initialisation of the decoder (INITDEC)
|
|
81
|
-
function ArithmeticDecoder(data, start, end) {
|
|
82
|
-
this.data = data;
|
|
83
|
-
this.bp = start;
|
|
84
|
-
this.dataEnd = end;
|
|
85
|
-
|
|
86
|
-
this.chigh = data[start];
|
|
87
|
-
this.clow = 0;
|
|
88
|
-
|
|
89
|
-
this.byteIn();
|
|
90
|
-
|
|
91
|
-
this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
|
|
92
|
-
this.clow = (this.clow << 7) & 0xFFFF;
|
|
93
|
-
this.ct -= 7;
|
|
94
|
-
this.a = 0x8000;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
ArithmeticDecoder.prototype = {
|
|
98
|
-
// C.3.4 Compressed data input (BYTEIN)
|
|
99
|
-
byteIn: function ArithmeticDecoder_byteIn() {
|
|
100
|
-
var data = this.data;
|
|
101
|
-
var bp = this.bp;
|
|
102
|
-
if (data[bp] === 0xFF) {
|
|
103
|
-
var b1 = data[bp + 1];
|
|
104
|
-
if (b1 > 0x8F) {
|
|
105
|
-
this.clow += 0xFF00;
|
|
106
|
-
this.ct = 8;
|
|
107
|
-
} else {
|
|
108
|
-
bp++;
|
|
109
|
-
this.clow += (data[bp] << 9);
|
|
110
|
-
this.ct = 7;
|
|
111
|
-
this.bp = bp;
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
bp++;
|
|
115
|
-
this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
|
|
116
|
-
this.ct = 8;
|
|
117
|
-
this.bp = bp;
|
|
118
|
-
}
|
|
119
|
-
if (this.clow > 0xFFFF) {
|
|
120
|
-
this.chigh += (this.clow >> 16);
|
|
121
|
-
this.clow &= 0xFFFF;
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
// C.3.2 Decoding a decision (DECODE)
|
|
125
|
-
readBit: function ArithmeticDecoder_readBit(contexts, pos) {
|
|
126
|
-
// contexts are packed into 1 byte:
|
|
127
|
-
// highest 7 bits carry cx.index, lowest bit carries cx.mps
|
|
128
|
-
var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
|
|
129
|
-
var qeTableIcx = QeTable[cx_index];
|
|
130
|
-
var qeIcx = qeTableIcx.qe;
|
|
131
|
-
var d;
|
|
132
|
-
var a = this.a - qeIcx;
|
|
133
|
-
|
|
134
|
-
if (this.chigh < qeIcx) {
|
|
135
|
-
// exchangeLps
|
|
136
|
-
if (a < qeIcx) {
|
|
137
|
-
a = qeIcx;
|
|
138
|
-
d = cx_mps;
|
|
139
|
-
cx_index = qeTableIcx.nmps;
|
|
140
|
-
} else {
|
|
141
|
-
a = qeIcx;
|
|
142
|
-
d = 1 ^ cx_mps;
|
|
143
|
-
if (qeTableIcx.switchFlag === 1) {
|
|
144
|
-
cx_mps = d;
|
|
145
|
-
}
|
|
146
|
-
cx_index = qeTableIcx.nlps;
|
|
147
|
-
}
|
|
148
|
-
} else {
|
|
149
|
-
this.chigh -= qeIcx;
|
|
150
|
-
if ((a & 0x8000) !== 0) {
|
|
151
|
-
this.a = a;
|
|
152
|
-
return cx_mps;
|
|
153
|
-
}
|
|
154
|
-
// exchangeMps
|
|
155
|
-
if (a < qeIcx) {
|
|
156
|
-
d = 1 ^ cx_mps;
|
|
157
|
-
if (qeTableIcx.switchFlag === 1) {
|
|
158
|
-
cx_mps = d;
|
|
159
|
-
}
|
|
160
|
-
cx_index = qeTableIcx.nlps;
|
|
161
|
-
} else {
|
|
162
|
-
d = cx_mps;
|
|
163
|
-
cx_index = qeTableIcx.nmps;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
// C.3.3 renormD;
|
|
167
|
-
do {
|
|
168
|
-
if (this.ct === 0) {
|
|
169
|
-
this.byteIn();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
a <<= 1;
|
|
173
|
-
this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
|
|
174
|
-
this.clow = (this.clow << 1) & 0xFFFF;
|
|
175
|
-
this.ct--;
|
|
176
|
-
} while ((a & 0x8000) === 0);
|
|
177
|
-
this.a = a;
|
|
178
|
-
|
|
179
|
-
contexts[pos] = cx_index << 1 | cx_mps;
|
|
180
|
-
return d;
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
return ArithmeticDecoder;
|
|
185
|
-
})();
|
|
1
|
+
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
2
|
+
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
|
3
|
+
/* Copyright 2012 Mozilla Foundation
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
/* This class implements the QM Coder decoding as defined in
|
|
21
|
+
* JPEG 2000 Part I Final Committee Draft Version 1.0
|
|
22
|
+
* Annex C.3 Arithmetic decoding procedure
|
|
23
|
+
* available at http://www.jpeg.org/public/fcd15444-1.pdf
|
|
24
|
+
*
|
|
25
|
+
* The arithmetic decoder is used in conjunction with context models to decode
|
|
26
|
+
* JPEG2000 and JBIG2 streams.
|
|
27
|
+
*/
|
|
28
|
+
var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
|
|
29
|
+
// Table C-2
|
|
30
|
+
var QeTable = [
|
|
31
|
+
{qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
|
|
32
|
+
{qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
|
|
33
|
+
{qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
|
|
34
|
+
{qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
|
|
35
|
+
{qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
|
|
36
|
+
{qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
|
|
37
|
+
{qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
|
|
38
|
+
{qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
|
|
39
|
+
{qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
|
|
40
|
+
{qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
|
|
41
|
+
{qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
|
|
42
|
+
{qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
|
|
43
|
+
{qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
|
|
44
|
+
{qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
|
|
45
|
+
{qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
|
|
46
|
+
{qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
|
|
47
|
+
{qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
|
|
48
|
+
{qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
|
|
49
|
+
{qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
|
|
50
|
+
{qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
|
|
51
|
+
{qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
|
|
52
|
+
{qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
|
|
53
|
+
{qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
|
|
54
|
+
{qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
|
|
55
|
+
{qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
|
|
56
|
+
{qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
|
|
57
|
+
{qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
|
|
58
|
+
{qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
|
|
59
|
+
{qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
|
|
60
|
+
{qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
|
|
61
|
+
{qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
|
|
62
|
+
{qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
|
|
63
|
+
{qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
|
|
64
|
+
{qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
|
|
65
|
+
{qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
|
|
66
|
+
{qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
|
|
67
|
+
{qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
|
|
68
|
+
{qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
|
|
69
|
+
{qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
|
|
70
|
+
{qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
|
|
71
|
+
{qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
|
|
72
|
+
{qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
|
|
73
|
+
{qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
|
|
74
|
+
{qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
|
|
75
|
+
{qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
|
|
76
|
+
{qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
|
|
77
|
+
{qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
// C.3.5 Initialisation of the decoder (INITDEC)
|
|
81
|
+
function ArithmeticDecoder(data, start, end) {
|
|
82
|
+
this.data = data;
|
|
83
|
+
this.bp = start;
|
|
84
|
+
this.dataEnd = end;
|
|
85
|
+
|
|
86
|
+
this.chigh = data[start];
|
|
87
|
+
this.clow = 0;
|
|
88
|
+
|
|
89
|
+
this.byteIn();
|
|
90
|
+
|
|
91
|
+
this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
|
|
92
|
+
this.clow = (this.clow << 7) & 0xFFFF;
|
|
93
|
+
this.ct -= 7;
|
|
94
|
+
this.a = 0x8000;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
ArithmeticDecoder.prototype = {
|
|
98
|
+
// C.3.4 Compressed data input (BYTEIN)
|
|
99
|
+
byteIn: function ArithmeticDecoder_byteIn() {
|
|
100
|
+
var data = this.data;
|
|
101
|
+
var bp = this.bp;
|
|
102
|
+
if (data[bp] === 0xFF) {
|
|
103
|
+
var b1 = data[bp + 1];
|
|
104
|
+
if (b1 > 0x8F) {
|
|
105
|
+
this.clow += 0xFF00;
|
|
106
|
+
this.ct = 8;
|
|
107
|
+
} else {
|
|
108
|
+
bp++;
|
|
109
|
+
this.clow += (data[bp] << 9);
|
|
110
|
+
this.ct = 7;
|
|
111
|
+
this.bp = bp;
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
bp++;
|
|
115
|
+
this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
|
|
116
|
+
this.ct = 8;
|
|
117
|
+
this.bp = bp;
|
|
118
|
+
}
|
|
119
|
+
if (this.clow > 0xFFFF) {
|
|
120
|
+
this.chigh += (this.clow >> 16);
|
|
121
|
+
this.clow &= 0xFFFF;
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
// C.3.2 Decoding a decision (DECODE)
|
|
125
|
+
readBit: function ArithmeticDecoder_readBit(contexts, pos) {
|
|
126
|
+
// contexts are packed into 1 byte:
|
|
127
|
+
// highest 7 bits carry cx.index, lowest bit carries cx.mps
|
|
128
|
+
var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
|
|
129
|
+
var qeTableIcx = QeTable[cx_index];
|
|
130
|
+
var qeIcx = qeTableIcx.qe;
|
|
131
|
+
var d;
|
|
132
|
+
var a = this.a - qeIcx;
|
|
133
|
+
|
|
134
|
+
if (this.chigh < qeIcx) {
|
|
135
|
+
// exchangeLps
|
|
136
|
+
if (a < qeIcx) {
|
|
137
|
+
a = qeIcx;
|
|
138
|
+
d = cx_mps;
|
|
139
|
+
cx_index = qeTableIcx.nmps;
|
|
140
|
+
} else {
|
|
141
|
+
a = qeIcx;
|
|
142
|
+
d = 1 ^ cx_mps;
|
|
143
|
+
if (qeTableIcx.switchFlag === 1) {
|
|
144
|
+
cx_mps = d;
|
|
145
|
+
}
|
|
146
|
+
cx_index = qeTableIcx.nlps;
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
this.chigh -= qeIcx;
|
|
150
|
+
if ((a & 0x8000) !== 0) {
|
|
151
|
+
this.a = a;
|
|
152
|
+
return cx_mps;
|
|
153
|
+
}
|
|
154
|
+
// exchangeMps
|
|
155
|
+
if (a < qeIcx) {
|
|
156
|
+
d = 1 ^ cx_mps;
|
|
157
|
+
if (qeTableIcx.switchFlag === 1) {
|
|
158
|
+
cx_mps = d;
|
|
159
|
+
}
|
|
160
|
+
cx_index = qeTableIcx.nlps;
|
|
161
|
+
} else {
|
|
162
|
+
d = cx_mps;
|
|
163
|
+
cx_index = qeTableIcx.nmps;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// C.3.3 renormD;
|
|
167
|
+
do {
|
|
168
|
+
if (this.ct === 0) {
|
|
169
|
+
this.byteIn();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
a <<= 1;
|
|
173
|
+
this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
|
|
174
|
+
this.clow = (this.clow << 1) & 0xFFFF;
|
|
175
|
+
this.ct--;
|
|
176
|
+
} while ((a & 0x8000) === 0);
|
|
177
|
+
this.a = a;
|
|
178
|
+
|
|
179
|
+
contexts[pos] = cx_index << 1 | cx_mps;
|
|
180
|
+
return d;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
return ArithmeticDecoder;
|
|
185
|
+
})();
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JPEG 2000 decoder worker.
|
|
3
|
-
*/
|
|
4
|
-
// Do not warn if these variables were not defined before.
|
|
5
|
-
/* global importScripts, self, JpxImage */
|
|
6
|
-
|
|
7
|
-
importScripts('jpx.js', 'util.js', 'arithmetic_decoder.js');
|
|
8
|
-
|
|
9
|
-
self.addEventListener('message', function (event) {
|
|
10
|
-
|
|
11
|
-
// decode DICOM buffer
|
|
12
|
-
var decoder = new JpxImage();
|
|
13
|
-
decoder.parse( event.data.buffer );
|
|
14
|
-
// post decoded data
|
|
15
|
-
var res = decoder.tiles[0].items;
|
|
16
|
-
self.postMessage([res]);
|
|
17
|
-
|
|
18
|
-
}, false);
|
|
1
|
+
/**
|
|
2
|
+
* JPEG 2000 decoder worker.
|
|
3
|
+
*/
|
|
4
|
+
// Do not warn if these variables were not defined before.
|
|
5
|
+
/* global importScripts, self, JpxImage */
|
|
6
|
+
|
|
7
|
+
importScripts('jpx.js', 'util.js', 'arithmetic_decoder.js');
|
|
8
|
+
|
|
9
|
+
self.addEventListener('message', function (event) {
|
|
10
|
+
|
|
11
|
+
// decode DICOM buffer
|
|
12
|
+
var decoder = new JpxImage();
|
|
13
|
+
decoder.parse( event.data.buffer );
|
|
14
|
+
// post decoded data
|
|
15
|
+
var res = decoder.tiles[0].items;
|
|
16
|
+
self.postMessage([res]);
|
|
17
|
+
|
|
18
|
+
}, false);
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JPEG Baseline decoder worker.
|
|
3
|
-
*/
|
|
4
|
-
// Do not warn if these variables were not defined before.
|
|
5
|
-
/* global importScripts, self, JpegImage */
|
|
6
|
-
|
|
7
|
-
importScripts('jpg.js');
|
|
8
|
-
|
|
9
|
-
self.addEventListener('message', function (event) {
|
|
10
|
-
|
|
11
|
-
// decode DICOM buffer
|
|
12
|
-
var decoder = new JpegImage();
|
|
13
|
-
decoder.parse( event.data.buffer );
|
|
14
|
-
// post decoded data
|
|
15
|
-
var res = decoder.getData(decoder.width,decoder.height);
|
|
16
|
-
self.postMessage([res]);
|
|
17
|
-
|
|
18
|
-
}, false);
|
|
1
|
+
/**
|
|
2
|
+
* JPEG Baseline decoder worker.
|
|
3
|
+
*/
|
|
4
|
+
// Do not warn if these variables were not defined before.
|
|
5
|
+
/* global importScripts, self, JpegImage */
|
|
6
|
+
|
|
7
|
+
importScripts('jpg.js');
|
|
8
|
+
|
|
9
|
+
self.addEventListener('message', function (event) {
|
|
10
|
+
|
|
11
|
+
// decode DICOM buffer
|
|
12
|
+
var decoder = new JpegImage();
|
|
13
|
+
decoder.parse( event.data.buffer );
|
|
14
|
+
// post decoded data
|
|
15
|
+
var res = decoder.getData(decoder.width,decoder.height);
|
|
16
|
+
self.postMessage([res]);
|
|
17
|
+
|
|
18
|
+
}, false);
|