pdfjs-dist 2.0.550 → 2.3.200
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.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/bower.json +1 -1
- package/build/pdf.js +21618 -14369
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +22758 -11399
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/image_decoders/pdf.image_decoders.js +11500 -0
- package/image_decoders/pdf.image_decoders.js.map +1 -0
- package/image_decoders/pdf.image_decoders.min.js +1 -0
- package/lib/core/annotation.js +767 -258
- package/lib/core/arithmetic_decoder.js +275 -245
- package/lib/core/bidi.js +65 -6
- package/lib/core/ccitt.js +173 -18
- package/lib/core/ccitt_stream.js +15 -6
- package/lib/core/cff_parser.js +433 -61
- package/lib/core/charsets.js +5 -4
- package/lib/core/chunked_stream.js +428 -157
- package/lib/core/cmap.js +326 -87
- package/lib/core/colorspace.js +874 -594
- package/lib/core/core_utils.js +173 -0
- package/lib/core/crypto.js +290 -45
- package/lib/core/document.js +575 -272
- package/lib/core/encodings.js +19 -10
- package/lib/core/evaluator.js +1032 -351
- package/lib/core/font_renderer.js +331 -97
- package/lib/core/fonts.js +813 -196
- package/lib/core/function.js +253 -27
- package/lib/core/glyphlist.js +5 -3
- package/lib/core/image.js +169 -62
- package/lib/core/image_utils.js +111 -0
- package/lib/core/jbig2.js +502 -72
- package/lib/core/jbig2_stream.js +19 -8
- package/lib/core/jpeg_stream.js +38 -13
- package/lib/core/jpg.js +293 -52
- package/lib/core/jpx.js +419 -12
- package/lib/core/jpx_stream.js +18 -6
- package/lib/core/metrics.js +15 -15
- package/lib/core/murmurhash3.js +56 -34
- package/lib/core/obj.js +1368 -500
- package/lib/core/operator_list.js +159 -43
- package/lib/core/parser.js +544 -199
- package/lib/core/pattern.js +170 -21
- package/lib/core/pdf_manager.js +324 -134
- package/lib/core/primitives.js +169 -61
- package/lib/core/ps_parser.js +134 -45
- package/lib/core/standard_fonts.js +17 -17
- package/lib/core/stream.js +327 -34
- package/lib/core/type1_parser.js +148 -8
- package/lib/core/unicode.js +32 -5
- package/lib/core/worker.js +215 -229
- package/lib/core/worker_stream.js +277 -0
- package/lib/display/annotation_layer.js +618 -192
- package/lib/display/api.js +1798 -882
- package/lib/display/api_compatibility.js +5 -10
- package/lib/display/canvas.js +366 -45
- package/lib/display/content_disposition.js +71 -24
- package/lib/display/display_utils.js +777 -0
- package/lib/display/fetch_stream.js +205 -87
- package/lib/display/font_loader.js +468 -236
- package/lib/display/metadata.js +38 -16
- package/lib/display/network.js +635 -428
- package/lib/display/network_utils.js +38 -19
- package/lib/display/node_stream.js +367 -175
- package/lib/display/pattern_helper.js +103 -36
- package/lib/display/svg.js +1232 -519
- package/lib/display/text_layer.js +208 -75
- package/lib/display/transport_stream.js +345 -94
- package/lib/display/webgl.js +64 -18
- package/lib/display/worker_options.js +5 -4
- package/lib/display/xml_parser.js +166 -53
- package/lib/examples/node/domstubs.js +60 -4
- package/lib/pdf.js +35 -14
- package/lib/pdf.worker.js +5 -3
- package/lib/shared/compatibility.js +170 -572
- package/lib/shared/global_scope.js +2 -2
- package/lib/shared/is_node.js +4 -4
- package/lib/shared/message_handler.js +216 -163
- package/lib/shared/streams_polyfill.js +21 -17
- package/lib/shared/util.js +495 -385
- package/lib/test/unit/annotation_spec.js +1464 -401
- package/lib/test/unit/api_spec.js +718 -361
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +54 -11
- package/lib/test/unit/clitests_helper.js +9 -10
- package/lib/test/unit/cmap_spec.js +95 -41
- package/lib/test/unit/colorspace_spec.js +115 -63
- package/lib/test/unit/core_utils_spec.js +191 -0
- package/lib/test/unit/crypto_spec.js +17 -5
- package/lib/test/unit/custom_spec.js +43 -55
- package/lib/test/unit/display_svg_spec.js +34 -18
- package/lib/test/unit/display_utils_spec.js +273 -0
- package/lib/test/unit/document_spec.js +8 -13
- package/lib/test/unit/encodings_spec.js +25 -45
- package/lib/test/unit/evaluator_spec.js +59 -20
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +17 -5
- package/lib/test/unit/jasmine-boot.js +33 -20
- package/lib/test/unit/message_handler_spec.js +30 -13
- package/lib/test/unit/metadata_spec.js +71 -11
- package/lib/test/unit/murmurhash3_spec.js +3 -3
- package/lib/test/unit/network_spec.js +22 -55
- package/lib/test/unit/network_utils_spec.js +105 -14
- package/lib/test/unit/node_stream_spec.js +58 -34
- package/lib/test/unit/parser_spec.js +162 -71
- package/lib/test/unit/pdf_find_controller_spec.js +230 -0
- package/lib/test/unit/pdf_find_utils_spec.js +63 -0
- package/lib/test/unit/pdf_history_spec.js +21 -9
- package/lib/test/unit/primitives_spec.js +55 -22
- package/lib/test/unit/stream_spec.js +12 -4
- package/lib/test/unit/test_utils.js +273 -56
- package/lib/test/unit/testreporter.js +21 -3
- package/lib/test/unit/type1_parser_spec.js +9 -7
- package/lib/test/unit/ui_utils_spec.js +236 -36
- package/lib/test/unit/unicode_spec.js +18 -15
- package/lib/test/unit/util_spec.js +87 -128
- package/lib/web/annotation_layer_builder.js +39 -22
- package/lib/web/app.js +1252 -609
- package/lib/web/app_options.js +103 -65
- package/lib/web/base_viewer.js +522 -242
- package/lib/web/chromecom.js +259 -117
- package/lib/web/debugger.js +166 -22
- package/lib/web/download_manager.js +31 -12
- package/lib/web/firefox_print_service.js +27 -14
- package/lib/web/firefoxcom.js +318 -78
- package/lib/web/genericcom.js +89 -30
- package/lib/web/genericl10n.js +142 -30
- package/lib/web/grab_to_pan.js +28 -4
- package/lib/web/interfaces.js +174 -47
- package/lib/web/overlay_manager.js +235 -85
- package/lib/web/password_prompt.js +22 -14
- package/lib/web/pdf_attachment_viewer.js +38 -18
- package/lib/web/pdf_cursor_tools.js +39 -16
- package/lib/web/pdf_document_properties.js +255 -136
- package/lib/web/pdf_find_bar.js +84 -40
- package/lib/web/pdf_find_controller.js +495 -184
- package/lib/web/pdf_find_utils.js +111 -0
- package/lib/web/pdf_history.js +190 -53
- package/lib/web/pdf_link_service.js +144 -79
- package/lib/web/pdf_outline_viewer.js +124 -47
- package/lib/web/pdf_page_view.js +194 -74
- package/lib/web/pdf_presentation_mode.js +99 -34
- package/lib/web/pdf_print_service.js +59 -13
- package/lib/web/pdf_rendering_queue.js +28 -9
- package/lib/web/pdf_sidebar.js +144 -81
- package/lib/web/pdf_sidebar_resizer.js +42 -16
- package/lib/web/pdf_single_page_viewer.js +74 -66
- package/lib/web/pdf_thumbnail_view.js +104 -33
- package/lib/web/pdf_thumbnail_viewer.js +66 -26
- package/lib/web/pdf_viewer.component.js +112 -32
- package/lib/web/pdf_viewer.js +82 -87
- package/lib/web/preferences.js +284 -91
- package/lib/web/secondary_toolbar.js +132 -59
- package/lib/web/text_layer_builder.js +134 -59
- package/lib/web/toolbar.js +80 -43
- package/lib/web/ui_utils.js +400 -134
- package/lib/web/view_history.js +215 -67
- package/lib/web/viewer_compatibility.js +3 -8
- package/package.json +3 -2
- package/web/pdf_viewer.css +23 -15
- package/web/pdf_viewer.js +3429 -1245
- package/web/pdf_viewer.js.map +1 -1
- package/external/streams/streams-lib.js +0 -3962
- package/lib/display/dom_utils.js +0 -429
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/test/unit/fonts_spec.js +0 -81
- package/lib/web/dom_events.js +0 -137
package/lib/core/jpx.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,26 +19,45 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.JpxImage =
|
27
|
+
exports.JpxImage = void 0;
|
28
28
|
|
29
|
-
var _util = require(
|
29
|
+
var _util = require("../shared/util");
|
30
30
|
|
31
|
-
var _arithmetic_decoder = require(
|
31
|
+
var _arithmetic_decoder = require("./arithmetic_decoder");
|
32
|
+
|
33
|
+
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
34
|
+
|
35
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
36
|
+
|
37
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
38
|
+
|
39
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
40
|
+
|
41
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
42
|
+
|
43
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
44
|
+
|
45
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
46
|
+
|
47
|
+
var JpxError =
|
48
|
+
/*#__PURE__*/
|
49
|
+
function (_BaseException) {
|
50
|
+
_inherits(JpxError, _BaseException);
|
32
51
|
|
33
|
-
var JpxError = function JpxErrorClosure() {
|
34
52
|
function JpxError(msg) {
|
35
|
-
this
|
53
|
+
_classCallCheck(this, JpxError);
|
54
|
+
|
55
|
+
return _possibleConstructorReturn(this, _getPrototypeOf(JpxError).call(this, "JPX error: ".concat(msg)));
|
36
56
|
}
|
37
|
-
|
38
|
-
JpxError.prototype.name = 'JpxError';
|
39
|
-
JpxError.constructor = JpxError;
|
57
|
+
|
40
58
|
return JpxError;
|
41
|
-
}();
|
59
|
+
}(_util.BaseException);
|
60
|
+
|
42
61
|
var JpxImage = function JpxImageClosure() {
|
43
62
|
var SubbandsGainLog2 = {
|
44
63
|
'LL': 0,
|
@@ -46,49 +65,63 @@ var JpxImage = function JpxImageClosure() {
|
|
46
65
|
'HL': 1,
|
47
66
|
'HH': 2
|
48
67
|
};
|
68
|
+
|
49
69
|
function JpxImage() {
|
50
70
|
this.failOnCorruptedImage = false;
|
51
71
|
}
|
72
|
+
|
52
73
|
JpxImage.prototype = {
|
53
74
|
parse: function JpxImage_parse(data) {
|
54
75
|
var head = (0, _util.readUint16)(data, 0);
|
76
|
+
|
55
77
|
if (head === 0xFF4F) {
|
56
78
|
this.parseCodestream(data, 0, data.length);
|
57
79
|
return;
|
58
80
|
}
|
81
|
+
|
59
82
|
var position = 0,
|
60
83
|
length = data.length;
|
84
|
+
|
61
85
|
while (position < length) {
|
62
86
|
var headerSize = 8;
|
63
87
|
var lbox = (0, _util.readUint32)(data, position);
|
64
88
|
var tbox = (0, _util.readUint32)(data, position + 4);
|
65
89
|
position += headerSize;
|
90
|
+
|
66
91
|
if (lbox === 1) {
|
67
92
|
lbox = (0, _util.readUint32)(data, position) * 4294967296 + (0, _util.readUint32)(data, position + 4);
|
68
93
|
position += 8;
|
69
94
|
headerSize += 8;
|
70
95
|
}
|
96
|
+
|
71
97
|
if (lbox === 0) {
|
72
98
|
lbox = length - position + headerSize;
|
73
99
|
}
|
100
|
+
|
74
101
|
if (lbox < headerSize) {
|
75
102
|
throw new JpxError('Invalid box field size');
|
76
103
|
}
|
104
|
+
|
77
105
|
var dataLength = lbox - headerSize;
|
78
106
|
var jumpDataLength = true;
|
107
|
+
|
79
108
|
switch (tbox) {
|
80
109
|
case 0x6A703268:
|
81
110
|
jumpDataLength = false;
|
82
111
|
break;
|
112
|
+
|
83
113
|
case 0x636F6C72:
|
84
114
|
var method = data[position];
|
115
|
+
|
85
116
|
if (method === 1) {
|
86
117
|
var colorspace = (0, _util.readUint32)(data, position + 3);
|
118
|
+
|
87
119
|
switch (colorspace) {
|
88
120
|
case 16:
|
89
121
|
case 17:
|
90
122
|
case 18:
|
91
123
|
break;
|
124
|
+
|
92
125
|
default:
|
93
126
|
(0, _util.warn)('Unknown colorspace ' + colorspace);
|
94
127
|
break;
|
@@ -96,26 +129,33 @@ var JpxImage = function JpxImageClosure() {
|
|
96
129
|
} else if (method === 2) {
|
97
130
|
(0, _util.info)('ICC profile not supported');
|
98
131
|
}
|
132
|
+
|
99
133
|
break;
|
134
|
+
|
100
135
|
case 0x6A703263:
|
101
136
|
this.parseCodestream(data, position, position + dataLength);
|
102
137
|
break;
|
138
|
+
|
103
139
|
case 0x6A502020:
|
104
140
|
if ((0, _util.readUint32)(data, position) !== 0x0d0a870a) {
|
105
141
|
(0, _util.warn)('Invalid JP2 signature');
|
106
142
|
}
|
143
|
+
|
107
144
|
break;
|
145
|
+
|
108
146
|
case 0x6A501A1A:
|
109
147
|
case 0x66747970:
|
110
148
|
case 0x72726571:
|
111
149
|
case 0x72657320:
|
112
150
|
case 0x69686472:
|
113
151
|
break;
|
152
|
+
|
114
153
|
default:
|
115
154
|
var headerType = String.fromCharCode(tbox >> 24 & 0xFF, tbox >> 16 & 0xFF, tbox >> 8 & 0xFF, tbox & 0xFF);
|
116
155
|
(0, _util.warn)('Unsupported header type ' + tbox + ' (' + headerType + ')');
|
117
156
|
break;
|
118
157
|
}
|
158
|
+
|
119
159
|
if (jumpDataLength) {
|
120
160
|
position += dataLength;
|
121
161
|
}
|
@@ -123,10 +163,12 @@ var JpxImage = function JpxImageClosure() {
|
|
123
163
|
},
|
124
164
|
parseImageProperties: function JpxImage_parseImageProperties(stream) {
|
125
165
|
var newByte = stream.getByte();
|
166
|
+
|
126
167
|
while (newByte >= 0) {
|
127
168
|
var oldByte = newByte;
|
128
169
|
newByte = stream.getByte();
|
129
170
|
var code = oldByte << 8 | newByte;
|
171
|
+
|
130
172
|
if (code === 0xFF51) {
|
131
173
|
stream.skip(4);
|
132
174
|
var Xsiz = stream.getInt32() >>> 0;
|
@@ -142,13 +184,16 @@ var JpxImage = function JpxImageClosure() {
|
|
142
184
|
return;
|
143
185
|
}
|
144
186
|
}
|
187
|
+
|
145
188
|
throw new JpxError('No size marker found in JPX stream');
|
146
189
|
},
|
147
190
|
parseCodestream: function JpxImage_parseCodestream(data, start, end) {
|
148
191
|
var context = {};
|
149
192
|
var doNotRecover = false;
|
193
|
+
|
150
194
|
try {
|
151
195
|
var position = start;
|
196
|
+
|
152
197
|
while (position + 1 < end) {
|
153
198
|
var code = (0, _util.readUint16)(data, position);
|
154
199
|
position += 2;
|
@@ -159,12 +204,15 @@ var JpxImage = function JpxImageClosure() {
|
|
159
204
|
spqcdSize,
|
160
205
|
scalarExpounded,
|
161
206
|
tile;
|
207
|
+
|
162
208
|
switch (code) {
|
163
209
|
case 0xFF4F:
|
164
210
|
context.mainHeader = true;
|
165
211
|
break;
|
212
|
+
|
166
213
|
case 0xFFD9:
|
167
214
|
break;
|
215
|
+
|
168
216
|
case 0xFF51:
|
169
217
|
length = (0, _util.readUint16)(data, position);
|
170
218
|
var siz = {};
|
@@ -180,6 +228,7 @@ var JpxImage = function JpxImageClosure() {
|
|
180
228
|
siz.Csiz = componentsCount;
|
181
229
|
var components = [];
|
182
230
|
j = position + 38;
|
231
|
+
|
183
232
|
for (var i = 0; i < componentsCount; i++) {
|
184
233
|
var component = {
|
185
234
|
precision: (data[j] & 0x7F) + 1,
|
@@ -191,39 +240,48 @@ var JpxImage = function JpxImageClosure() {
|
|
191
240
|
calculateComponentDimensions(component, siz);
|
192
241
|
components.push(component);
|
193
242
|
}
|
243
|
+
|
194
244
|
context.SIZ = siz;
|
195
245
|
context.components = components;
|
196
246
|
calculateTileGrids(context, components);
|
197
247
|
context.QCC = [];
|
198
248
|
context.COC = [];
|
199
249
|
break;
|
250
|
+
|
200
251
|
case 0xFF5C:
|
201
252
|
length = (0, _util.readUint16)(data, position);
|
202
253
|
var qcd = {};
|
203
254
|
j = position + 2;
|
204
255
|
sqcd = data[j++];
|
256
|
+
|
205
257
|
switch (sqcd & 0x1F) {
|
206
258
|
case 0:
|
207
259
|
spqcdSize = 8;
|
208
260
|
scalarExpounded = true;
|
209
261
|
break;
|
262
|
+
|
210
263
|
case 1:
|
211
264
|
spqcdSize = 16;
|
212
265
|
scalarExpounded = false;
|
213
266
|
break;
|
267
|
+
|
214
268
|
case 2:
|
215
269
|
spqcdSize = 16;
|
216
270
|
scalarExpounded = true;
|
217
271
|
break;
|
272
|
+
|
218
273
|
default:
|
219
274
|
throw new Error('Invalid SQcd value ' + sqcd);
|
220
275
|
}
|
276
|
+
|
221
277
|
qcd.noQuantization = spqcdSize === 8;
|
222
278
|
qcd.scalarExpounded = scalarExpounded;
|
223
279
|
qcd.guardBits = sqcd >> 5;
|
224
280
|
spqcds = [];
|
281
|
+
|
225
282
|
while (j < length + position) {
|
226
283
|
var spqcd = {};
|
284
|
+
|
227
285
|
if (spqcdSize === 8) {
|
228
286
|
spqcd.epsilon = data[j++] >> 3;
|
229
287
|
spqcd.mu = 0;
|
@@ -232,50 +290,64 @@ var JpxImage = function JpxImageClosure() {
|
|
232
290
|
spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
|
233
291
|
j += 2;
|
234
292
|
}
|
293
|
+
|
235
294
|
spqcds.push(spqcd);
|
236
295
|
}
|
296
|
+
|
237
297
|
qcd.SPqcds = spqcds;
|
298
|
+
|
238
299
|
if (context.mainHeader) {
|
239
300
|
context.QCD = qcd;
|
240
301
|
} else {
|
241
302
|
context.currentTile.QCD = qcd;
|
242
303
|
context.currentTile.QCC = [];
|
243
304
|
}
|
305
|
+
|
244
306
|
break;
|
307
|
+
|
245
308
|
case 0xFF5D:
|
246
309
|
length = (0, _util.readUint16)(data, position);
|
247
310
|
var qcc = {};
|
248
311
|
j = position + 2;
|
249
312
|
var cqcc;
|
313
|
+
|
250
314
|
if (context.SIZ.Csiz < 257) {
|
251
315
|
cqcc = data[j++];
|
252
316
|
} else {
|
253
317
|
cqcc = (0, _util.readUint16)(data, j);
|
254
318
|
j += 2;
|
255
319
|
}
|
320
|
+
|
256
321
|
sqcd = data[j++];
|
322
|
+
|
257
323
|
switch (sqcd & 0x1F) {
|
258
324
|
case 0:
|
259
325
|
spqcdSize = 8;
|
260
326
|
scalarExpounded = true;
|
261
327
|
break;
|
328
|
+
|
262
329
|
case 1:
|
263
330
|
spqcdSize = 16;
|
264
331
|
scalarExpounded = false;
|
265
332
|
break;
|
333
|
+
|
266
334
|
case 2:
|
267
335
|
spqcdSize = 16;
|
268
336
|
scalarExpounded = true;
|
269
337
|
break;
|
338
|
+
|
270
339
|
default:
|
271
340
|
throw new Error('Invalid SQcd value ' + sqcd);
|
272
341
|
}
|
342
|
+
|
273
343
|
qcc.noQuantization = spqcdSize === 8;
|
274
344
|
qcc.scalarExpounded = scalarExpounded;
|
275
345
|
qcc.guardBits = sqcd >> 5;
|
276
346
|
spqcds = [];
|
347
|
+
|
277
348
|
while (j < length + position) {
|
278
349
|
spqcd = {};
|
350
|
+
|
279
351
|
if (spqcdSize === 8) {
|
280
352
|
spqcd.epsilon = data[j++] >> 3;
|
281
353
|
spqcd.mu = 0;
|
@@ -284,15 +356,20 @@ var JpxImage = function JpxImageClosure() {
|
|
284
356
|
spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
|
285
357
|
j += 2;
|
286
358
|
}
|
359
|
+
|
287
360
|
spqcds.push(spqcd);
|
288
361
|
}
|
362
|
+
|
289
363
|
qcc.SPqcds = spqcds;
|
364
|
+
|
290
365
|
if (context.mainHeader) {
|
291
366
|
context.QCC[cqcc] = qcc;
|
292
367
|
} else {
|
293
368
|
context.currentTile.QCC[cqcc] = qcc;
|
294
369
|
}
|
370
|
+
|
295
371
|
break;
|
372
|
+
|
296
373
|
case 0xFF52:
|
297
374
|
length = (0, _util.readUint16)(data, position);
|
298
375
|
var cod = {};
|
@@ -316,8 +393,10 @@ var JpxImage = function JpxImageClosure() {
|
|
316
393
|
cod.predictableTermination = !!(blockStyle & 16);
|
317
394
|
cod.segmentationSymbolUsed = !!(blockStyle & 32);
|
318
395
|
cod.reversibleTransformation = data[j++];
|
396
|
+
|
319
397
|
if (cod.entropyCoderWithCustomPrecincts) {
|
320
398
|
var precinctsSizes = [];
|
399
|
+
|
321
400
|
while (j < length + position) {
|
322
401
|
var precinctsSize = data[j++];
|
323
402
|
precinctsSizes.push({
|
@@ -325,35 +404,46 @@ var JpxImage = function JpxImageClosure() {
|
|
325
404
|
PPy: precinctsSize >> 4
|
326
405
|
});
|
327
406
|
}
|
407
|
+
|
328
408
|
cod.precinctsSizes = precinctsSizes;
|
329
409
|
}
|
410
|
+
|
330
411
|
var unsupported = [];
|
412
|
+
|
331
413
|
if (cod.selectiveArithmeticCodingBypass) {
|
332
414
|
unsupported.push('selectiveArithmeticCodingBypass');
|
333
415
|
}
|
416
|
+
|
334
417
|
if (cod.resetContextProbabilities) {
|
335
418
|
unsupported.push('resetContextProbabilities');
|
336
419
|
}
|
420
|
+
|
337
421
|
if (cod.terminationOnEachCodingPass) {
|
338
422
|
unsupported.push('terminationOnEachCodingPass');
|
339
423
|
}
|
424
|
+
|
340
425
|
if (cod.verticallyStripe) {
|
341
426
|
unsupported.push('verticallyStripe');
|
342
427
|
}
|
428
|
+
|
343
429
|
if (cod.predictableTermination) {
|
344
430
|
unsupported.push('predictableTermination');
|
345
431
|
}
|
432
|
+
|
346
433
|
if (unsupported.length > 0) {
|
347
434
|
doNotRecover = true;
|
348
435
|
throw new Error('Unsupported COD options (' + unsupported.join(', ') + ')');
|
349
436
|
}
|
437
|
+
|
350
438
|
if (context.mainHeader) {
|
351
439
|
context.COD = cod;
|
352
440
|
} else {
|
353
441
|
context.currentTile.COD = cod;
|
354
442
|
context.currentTile.COC = [];
|
355
443
|
}
|
444
|
+
|
356
445
|
break;
|
446
|
+
|
357
447
|
case 0xFF90:
|
358
448
|
length = (0, _util.readUint16)(data, position);
|
359
449
|
tile = {};
|
@@ -363,34 +453,43 @@ var JpxImage = function JpxImageClosure() {
|
|
363
453
|
tile.partIndex = data[position + 8];
|
364
454
|
tile.partsCount = data[position + 9];
|
365
455
|
context.mainHeader = false;
|
456
|
+
|
366
457
|
if (tile.partIndex === 0) {
|
367
458
|
tile.COD = context.COD;
|
368
459
|
tile.COC = context.COC.slice(0);
|
369
460
|
tile.QCD = context.QCD;
|
370
461
|
tile.QCC = context.QCC.slice(0);
|
371
462
|
}
|
463
|
+
|
372
464
|
context.currentTile = tile;
|
373
465
|
break;
|
466
|
+
|
374
467
|
case 0xFF93:
|
375
468
|
tile = context.currentTile;
|
469
|
+
|
376
470
|
if (tile.partIndex === 0) {
|
377
471
|
initializeTile(context, tile.index);
|
378
472
|
buildPackets(context);
|
379
473
|
}
|
474
|
+
|
380
475
|
length = tile.dataEnd - position;
|
381
476
|
parseTilePackets(context, data, position, length);
|
382
477
|
break;
|
478
|
+
|
383
479
|
case 0xFF55:
|
384
480
|
case 0xFF57:
|
385
481
|
case 0xFF58:
|
386
482
|
case 0xFF64:
|
387
483
|
length = (0, _util.readUint16)(data, position);
|
388
484
|
break;
|
485
|
+
|
389
486
|
case 0xFF53:
|
390
487
|
throw new Error('Codestream code 0xFF53 (COC) is ' + 'not implemented');
|
488
|
+
|
391
489
|
default:
|
392
490
|
throw new Error('Unknown codestream code: ' + code.toString(16));
|
393
491
|
}
|
492
|
+
|
394
493
|
position += length;
|
395
494
|
}
|
396
495
|
} catch (e) {
|
@@ -400,12 +499,14 @@ var JpxImage = function JpxImageClosure() {
|
|
400
499
|
(0, _util.warn)('JPX: Trying to recover from: ' + e.message);
|
401
500
|
}
|
402
501
|
}
|
502
|
+
|
403
503
|
this.tiles = transformComponents(context);
|
404
504
|
this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
|
405
505
|
this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
|
406
506
|
this.componentsCount = context.SIZ.Csiz;
|
407
507
|
}
|
408
508
|
};
|
509
|
+
|
409
510
|
function calculateComponentDimensions(component, siz) {
|
410
511
|
component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
|
411
512
|
component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
|
@@ -414,12 +515,14 @@ var JpxImage = function JpxImageClosure() {
|
|
414
515
|
component.width = component.x1 - component.x0;
|
415
516
|
component.height = component.y1 - component.y0;
|
416
517
|
}
|
518
|
+
|
417
519
|
function calculateTileGrids(context, components) {
|
418
520
|
var siz = context.SIZ;
|
419
521
|
var tile,
|
420
522
|
tiles = [];
|
421
523
|
var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
|
422
524
|
var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
|
525
|
+
|
423
526
|
for (var q = 0; q < numYtiles; q++) {
|
424
527
|
for (var p = 0; p < numXtiles; p++) {
|
425
528
|
tile = {};
|
@@ -433,10 +536,13 @@ var JpxImage = function JpxImageClosure() {
|
|
433
536
|
tiles.push(tile);
|
434
537
|
}
|
435
538
|
}
|
539
|
+
|
436
540
|
context.tiles = tiles;
|
437
541
|
var componentsCount = siz.Csiz;
|
542
|
+
|
438
543
|
for (var i = 0, ii = componentsCount; i < ii; i++) {
|
439
544
|
var component = components[i];
|
545
|
+
|
440
546
|
for (var j = 0, jj = tiles.length; j < jj; j++) {
|
441
547
|
var tileComponent = {};
|
442
548
|
tile = tiles[j];
|
@@ -450,9 +556,11 @@ var JpxImage = function JpxImageClosure() {
|
|
450
556
|
}
|
451
557
|
}
|
452
558
|
}
|
559
|
+
|
453
560
|
function getBlocksDimensions(context, component, r) {
|
454
561
|
var codOrCoc = component.codingStyleParameters;
|
455
562
|
var result = {};
|
563
|
+
|
456
564
|
if (!codOrCoc.entropyCoderWithCustomPrecincts) {
|
457
565
|
result.PPx = 15;
|
458
566
|
result.PPy = 15;
|
@@ -460,10 +568,12 @@ var JpxImage = function JpxImageClosure() {
|
|
460
568
|
result.PPx = codOrCoc.precinctsSizes[r].PPx;
|
461
569
|
result.PPy = codOrCoc.precinctsSizes[r].PPy;
|
462
570
|
}
|
571
|
+
|
463
572
|
result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx);
|
464
573
|
result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy);
|
465
574
|
return result;
|
466
575
|
}
|
576
|
+
|
467
577
|
function buildPrecincts(context, resolution, dimensions) {
|
468
578
|
var precinctWidth = 1 << dimensions.PPx;
|
469
579
|
var precinctHeight = 1 << dimensions.PPy;
|
@@ -483,6 +593,7 @@ var JpxImage = function JpxImageClosure() {
|
|
483
593
|
precinctHeightInSubband: precinctHeightInSubband
|
484
594
|
};
|
485
595
|
}
|
596
|
+
|
486
597
|
function buildCodeblocks(context, subband, dimensions) {
|
487
598
|
var xcb_ = dimensions.xcb_;
|
488
599
|
var ycb_ = dimensions.ycb_;
|
@@ -496,6 +607,7 @@ var JpxImage = function JpxImageClosure() {
|
|
496
607
|
var codeblocks = [];
|
497
608
|
var precincts = [];
|
498
609
|
var i, j, codeblock, precinctNumber;
|
610
|
+
|
499
611
|
for (j = cby0; j < cby1; j++) {
|
500
612
|
for (i = cbx0; i < cbx1; i++) {
|
501
613
|
codeblock = {
|
@@ -516,17 +628,21 @@ var JpxImage = function JpxImageClosure() {
|
|
516
628
|
codeblock.precinctNumber = precinctNumber;
|
517
629
|
codeblock.subbandType = subband.type;
|
518
630
|
codeblock.Lblock = 3;
|
631
|
+
|
519
632
|
if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) {
|
520
633
|
continue;
|
521
634
|
}
|
635
|
+
|
522
636
|
codeblocks.push(codeblock);
|
523
637
|
var precinct = precincts[precinctNumber];
|
638
|
+
|
524
639
|
if (precinct !== undefined) {
|
525
640
|
if (i < precinct.cbxMin) {
|
526
641
|
precinct.cbxMin = i;
|
527
642
|
} else if (i > precinct.cbxMax) {
|
528
643
|
precinct.cbxMax = i;
|
529
644
|
}
|
645
|
+
|
530
646
|
if (j < precinct.cbyMin) {
|
531
647
|
precinct.cbxMin = j;
|
532
648
|
} else if (j > precinct.cbyMax) {
|
@@ -540,9 +656,11 @@ var JpxImage = function JpxImageClosure() {
|
|
540
656
|
cbyMax: j
|
541
657
|
};
|
542
658
|
}
|
659
|
+
|
543
660
|
codeblock.precinct = precinct;
|
544
661
|
}
|
545
662
|
}
|
663
|
+
|
546
664
|
subband.codeblockParameters = {
|
547
665
|
codeblockWidth: xcb_,
|
548
666
|
codeblockHeight: ycb_,
|
@@ -552,25 +670,32 @@ var JpxImage = function JpxImageClosure() {
|
|
552
670
|
subband.codeblocks = codeblocks;
|
553
671
|
subband.precincts = precincts;
|
554
672
|
}
|
673
|
+
|
555
674
|
function createPacket(resolution, precinctNumber, layerNumber) {
|
556
675
|
var precinctCodeblocks = [];
|
557
676
|
var subbands = resolution.subbands;
|
677
|
+
|
558
678
|
for (var i = 0, ii = subbands.length; i < ii; i++) {
|
559
679
|
var subband = subbands[i];
|
560
680
|
var codeblocks = subband.codeblocks;
|
681
|
+
|
561
682
|
for (var j = 0, jj = codeblocks.length; j < jj; j++) {
|
562
683
|
var codeblock = codeblocks[j];
|
684
|
+
|
563
685
|
if (codeblock.precinctNumber !== precinctNumber) {
|
564
686
|
continue;
|
565
687
|
}
|
688
|
+
|
566
689
|
precinctCodeblocks.push(codeblock);
|
567
690
|
}
|
568
691
|
}
|
692
|
+
|
569
693
|
return {
|
570
694
|
layerNumber: layerNumber,
|
571
695
|
codeblocks: precinctCodeblocks
|
572
696
|
};
|
573
697
|
}
|
698
|
+
|
574
699
|
function LayerResolutionComponentPositionIterator(context) {
|
575
700
|
var siz = context.SIZ;
|
576
701
|
var tileIndex = context.currentTile.index;
|
@@ -578,37 +703,48 @@ var JpxImage = function JpxImageClosure() {
|
|
578
703
|
var layersCount = tile.codingStyleDefaultParameters.layersCount;
|
579
704
|
var componentsCount = siz.Csiz;
|
580
705
|
var maxDecompositionLevelsCount = 0;
|
706
|
+
|
581
707
|
for (var q = 0; q < componentsCount; q++) {
|
582
708
|
maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
|
583
709
|
}
|
710
|
+
|
584
711
|
var l = 0,
|
585
712
|
r = 0,
|
586
713
|
i = 0,
|
587
714
|
k = 0;
|
715
|
+
|
588
716
|
this.nextPacket = function JpxImage_nextPacket() {
|
589
717
|
for (; l < layersCount; l++) {
|
590
718
|
for (; r <= maxDecompositionLevelsCount; r++) {
|
591
719
|
for (; i < componentsCount; i++) {
|
592
720
|
var component = tile.components[i];
|
721
|
+
|
593
722
|
if (r > component.codingStyleParameters.decompositionLevelsCount) {
|
594
723
|
continue;
|
595
724
|
}
|
725
|
+
|
596
726
|
var resolution = component.resolutions[r];
|
597
727
|
var numprecincts = resolution.precinctParameters.numprecincts;
|
728
|
+
|
598
729
|
for (; k < numprecincts;) {
|
599
730
|
var packet = createPacket(resolution, k, l);
|
600
731
|
k++;
|
601
732
|
return packet;
|
602
733
|
}
|
734
|
+
|
603
735
|
k = 0;
|
604
736
|
}
|
737
|
+
|
605
738
|
i = 0;
|
606
739
|
}
|
740
|
+
|
607
741
|
r = 0;
|
608
742
|
}
|
743
|
+
|
609
744
|
throw new JpxError('Out of packets');
|
610
745
|
};
|
611
746
|
}
|
747
|
+
|
612
748
|
function ResolutionLayerComponentPositionIterator(context) {
|
613
749
|
var siz = context.SIZ;
|
614
750
|
var tileIndex = context.currentTile.index;
|
@@ -616,37 +752,48 @@ var JpxImage = function JpxImageClosure() {
|
|
616
752
|
var layersCount = tile.codingStyleDefaultParameters.layersCount;
|
617
753
|
var componentsCount = siz.Csiz;
|
618
754
|
var maxDecompositionLevelsCount = 0;
|
755
|
+
|
619
756
|
for (var q = 0; q < componentsCount; q++) {
|
620
757
|
maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
|
621
758
|
}
|
759
|
+
|
622
760
|
var r = 0,
|
623
761
|
l = 0,
|
624
762
|
i = 0,
|
625
763
|
k = 0;
|
764
|
+
|
626
765
|
this.nextPacket = function JpxImage_nextPacket() {
|
627
766
|
for (; r <= maxDecompositionLevelsCount; r++) {
|
628
767
|
for (; l < layersCount; l++) {
|
629
768
|
for (; i < componentsCount; i++) {
|
630
769
|
var component = tile.components[i];
|
770
|
+
|
631
771
|
if (r > component.codingStyleParameters.decompositionLevelsCount) {
|
632
772
|
continue;
|
633
773
|
}
|
774
|
+
|
634
775
|
var resolution = component.resolutions[r];
|
635
776
|
var numprecincts = resolution.precinctParameters.numprecincts;
|
777
|
+
|
636
778
|
for (; k < numprecincts;) {
|
637
779
|
var packet = createPacket(resolution, k, l);
|
638
780
|
k++;
|
639
781
|
return packet;
|
640
782
|
}
|
783
|
+
|
641
784
|
k = 0;
|
642
785
|
}
|
786
|
+
|
643
787
|
i = 0;
|
644
788
|
}
|
789
|
+
|
645
790
|
l = 0;
|
646
791
|
}
|
792
|
+
|
647
793
|
throw new JpxError('Out of packets');
|
648
794
|
};
|
649
795
|
}
|
796
|
+
|
650
797
|
function ResolutionPositionComponentLayerIterator(context) {
|
651
798
|
var siz = context.SIZ;
|
652
799
|
var tileIndex = context.currentTile.index;
|
@@ -655,52 +802,69 @@ var JpxImage = function JpxImageClosure() {
|
|
655
802
|
var componentsCount = siz.Csiz;
|
656
803
|
var l, r, c, p;
|
657
804
|
var maxDecompositionLevelsCount = 0;
|
805
|
+
|
658
806
|
for (c = 0; c < componentsCount; c++) {
|
659
807
|
var component = tile.components[c];
|
660
808
|
maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
|
661
809
|
}
|
810
|
+
|
662
811
|
var maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1);
|
812
|
+
|
663
813
|
for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
|
664
814
|
var maxNumPrecincts = 0;
|
815
|
+
|
665
816
|
for (c = 0; c < componentsCount; ++c) {
|
666
817
|
var resolutions = tile.components[c].resolutions;
|
818
|
+
|
667
819
|
if (r < resolutions.length) {
|
668
820
|
maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts);
|
669
821
|
}
|
670
822
|
}
|
823
|
+
|
671
824
|
maxNumPrecinctsInLevel[r] = maxNumPrecincts;
|
672
825
|
}
|
826
|
+
|
673
827
|
l = 0;
|
674
828
|
r = 0;
|
675
829
|
c = 0;
|
676
830
|
p = 0;
|
831
|
+
|
677
832
|
this.nextPacket = function JpxImage_nextPacket() {
|
678
833
|
for (; r <= maxDecompositionLevelsCount; r++) {
|
679
834
|
for (; p < maxNumPrecinctsInLevel[r]; p++) {
|
680
835
|
for (; c < componentsCount; c++) {
|
681
836
|
var component = tile.components[c];
|
837
|
+
|
682
838
|
if (r > component.codingStyleParameters.decompositionLevelsCount) {
|
683
839
|
continue;
|
684
840
|
}
|
841
|
+
|
685
842
|
var resolution = component.resolutions[r];
|
686
843
|
var numprecincts = resolution.precinctParameters.numprecincts;
|
844
|
+
|
687
845
|
if (p >= numprecincts) {
|
688
846
|
continue;
|
689
847
|
}
|
848
|
+
|
690
849
|
for (; l < layersCount;) {
|
691
850
|
var packet = createPacket(resolution, p, l);
|
692
851
|
l++;
|
693
852
|
return packet;
|
694
853
|
}
|
854
|
+
|
695
855
|
l = 0;
|
696
856
|
}
|
857
|
+
|
697
858
|
c = 0;
|
698
859
|
}
|
860
|
+
|
699
861
|
p = 0;
|
700
862
|
}
|
863
|
+
|
701
864
|
throw new JpxError('Out of packets');
|
702
865
|
};
|
703
866
|
}
|
867
|
+
|
704
868
|
function PositionComponentResolutionLayerIterator(context) {
|
705
869
|
var siz = context.SIZ;
|
706
870
|
var tileIndex = context.currentTile.index;
|
@@ -714,35 +878,45 @@ var JpxImage = function JpxImageClosure() {
|
|
714
878
|
c = 0,
|
715
879
|
px = 0,
|
716
880
|
py = 0;
|
881
|
+
|
717
882
|
this.nextPacket = function JpxImage_nextPacket() {
|
718
883
|
for (; py < precinctsIterationSizes.maxNumHigh; py++) {
|
719
884
|
for (; px < precinctsIterationSizes.maxNumWide; px++) {
|
720
885
|
for (; c < componentsCount; c++) {
|
721
886
|
var component = tile.components[c];
|
722
887
|
var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
|
888
|
+
|
723
889
|
for (; r <= decompositionLevelsCount; r++) {
|
724
890
|
var resolution = component.resolutions[r];
|
725
891
|
var sizeInImageScale = precinctsSizes.components[c].resolutions[r];
|
726
892
|
var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
|
893
|
+
|
727
894
|
if (k === null) {
|
728
895
|
continue;
|
729
896
|
}
|
897
|
+
|
730
898
|
for (; l < layersCount;) {
|
731
899
|
var packet = createPacket(resolution, k, l);
|
732
900
|
l++;
|
733
901
|
return packet;
|
734
902
|
}
|
903
|
+
|
735
904
|
l = 0;
|
736
905
|
}
|
906
|
+
|
737
907
|
r = 0;
|
738
908
|
}
|
909
|
+
|
739
910
|
c = 0;
|
740
911
|
}
|
912
|
+
|
741
913
|
px = 0;
|
742
914
|
}
|
915
|
+
|
743
916
|
throw new JpxError('Out of packets');
|
744
917
|
};
|
745
918
|
}
|
919
|
+
|
746
920
|
function ComponentPositionResolutionLayerIterator(context) {
|
747
921
|
var siz = context.SIZ;
|
748
922
|
var tileIndex = context.currentTile.index;
|
@@ -755,45 +929,58 @@ var JpxImage = function JpxImageClosure() {
|
|
755
929
|
c = 0,
|
756
930
|
px = 0,
|
757
931
|
py = 0;
|
932
|
+
|
758
933
|
this.nextPacket = function JpxImage_nextPacket() {
|
759
934
|
for (; c < componentsCount; ++c) {
|
760
935
|
var component = tile.components[c];
|
761
936
|
var precinctsIterationSizes = precinctsSizes.components[c];
|
762
937
|
var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
|
938
|
+
|
763
939
|
for (; py < precinctsIterationSizes.maxNumHigh; py++) {
|
764
940
|
for (; px < precinctsIterationSizes.maxNumWide; px++) {
|
765
941
|
for (; r <= decompositionLevelsCount; r++) {
|
766
942
|
var resolution = component.resolutions[r];
|
767
943
|
var sizeInImageScale = precinctsIterationSizes.resolutions[r];
|
768
944
|
var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
|
945
|
+
|
769
946
|
if (k === null) {
|
770
947
|
continue;
|
771
948
|
}
|
949
|
+
|
772
950
|
for (; l < layersCount;) {
|
773
951
|
var packet = createPacket(resolution, k, l);
|
774
952
|
l++;
|
775
953
|
return packet;
|
776
954
|
}
|
955
|
+
|
777
956
|
l = 0;
|
778
957
|
}
|
958
|
+
|
779
959
|
r = 0;
|
780
960
|
}
|
961
|
+
|
781
962
|
px = 0;
|
782
963
|
}
|
964
|
+
|
783
965
|
py = 0;
|
784
966
|
}
|
967
|
+
|
785
968
|
throw new JpxError('Out of packets');
|
786
969
|
};
|
787
970
|
}
|
971
|
+
|
788
972
|
function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
|
789
973
|
var posX = pxIndex * precinctIterationSizes.minWidth;
|
790
974
|
var posY = pyIndex * precinctIterationSizes.minHeight;
|
975
|
+
|
791
976
|
if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) {
|
792
977
|
return null;
|
793
978
|
}
|
979
|
+
|
794
980
|
var startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide;
|
795
981
|
return posX / sizeInImageScale.height + startPrecinctRowIndex;
|
796
982
|
}
|
983
|
+
|
797
984
|
function getPrecinctSizesInImageScale(tile) {
|
798
985
|
var componentsCount = tile.components.length;
|
799
986
|
var minWidth = Number.MAX_VALUE;
|
@@ -801,6 +988,7 @@ var JpxImage = function JpxImageClosure() {
|
|
801
988
|
var maxNumWide = 0;
|
802
989
|
var maxNumHigh = 0;
|
803
990
|
var sizePerComponent = new Array(componentsCount);
|
991
|
+
|
804
992
|
for (var c = 0; c < componentsCount; c++) {
|
805
993
|
var component = tile.components[c];
|
806
994
|
var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
|
@@ -810,6 +998,7 @@ var JpxImage = function JpxImageClosure() {
|
|
810
998
|
var maxNumWideCurrentComponent = 0;
|
811
999
|
var maxNumHighCurrentComponent = 0;
|
812
1000
|
var scale = 1;
|
1001
|
+
|
813
1002
|
for (var r = decompositionLevelsCount; r >= 0; --r) {
|
814
1003
|
var resolution = component.resolutions[r];
|
815
1004
|
var widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth;
|
@@ -824,6 +1013,7 @@ var JpxImage = function JpxImageClosure() {
|
|
824
1013
|
};
|
825
1014
|
scale <<= 1;
|
826
1015
|
}
|
1016
|
+
|
827
1017
|
minWidth = Math.min(minWidth, minWidthCurrentComponent);
|
828
1018
|
minHeight = Math.min(minHeight, minHeightCurrentComponent);
|
829
1019
|
maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
|
@@ -836,6 +1026,7 @@ var JpxImage = function JpxImageClosure() {
|
|
836
1026
|
maxNumHigh: maxNumHighCurrentComponent
|
837
1027
|
};
|
838
1028
|
}
|
1029
|
+
|
839
1030
|
return {
|
840
1031
|
components: sizePerComponent,
|
841
1032
|
minWidth: minWidth,
|
@@ -844,16 +1035,19 @@ var JpxImage = function JpxImageClosure() {
|
|
844
1035
|
maxNumHigh: maxNumHigh
|
845
1036
|
};
|
846
1037
|
}
|
1038
|
+
|
847
1039
|
function buildPackets(context) {
|
848
1040
|
var siz = context.SIZ;
|
849
1041
|
var tileIndex = context.currentTile.index;
|
850
1042
|
var tile = context.tiles[tileIndex];
|
851
1043
|
var componentsCount = siz.Csiz;
|
1044
|
+
|
852
1045
|
for (var c = 0; c < componentsCount; c++) {
|
853
1046
|
var component = tile.components[c];
|
854
1047
|
var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
|
855
1048
|
var resolutions = [];
|
856
1049
|
var subbands = [];
|
1050
|
+
|
857
1051
|
for (var r = 0; r <= decompositionLevelsCount; r++) {
|
858
1052
|
var blocksDimensions = getBlocksDimensions(context, component, r);
|
859
1053
|
var resolution = {};
|
@@ -866,6 +1060,7 @@ var JpxImage = function JpxImageClosure() {
|
|
866
1060
|
buildPrecincts(context, resolution, blocksDimensions);
|
867
1061
|
resolutions.push(resolution);
|
868
1062
|
var subband;
|
1063
|
+
|
869
1064
|
if (r === 0) {
|
870
1065
|
subband = {};
|
871
1066
|
subband.type = 'LL';
|
@@ -913,39 +1108,50 @@ var JpxImage = function JpxImageClosure() {
|
|
913
1108
|
resolution.subbands = resolutionSubbands;
|
914
1109
|
}
|
915
1110
|
}
|
1111
|
+
|
916
1112
|
component.resolutions = resolutions;
|
917
1113
|
component.subbands = subbands;
|
918
1114
|
}
|
1115
|
+
|
919
1116
|
var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
|
1117
|
+
|
920
1118
|
switch (progressionOrder) {
|
921
1119
|
case 0:
|
922
1120
|
tile.packetsIterator = new LayerResolutionComponentPositionIterator(context);
|
923
1121
|
break;
|
1122
|
+
|
924
1123
|
case 1:
|
925
1124
|
tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context);
|
926
1125
|
break;
|
1126
|
+
|
927
1127
|
case 2:
|
928
1128
|
tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context);
|
929
1129
|
break;
|
1130
|
+
|
930
1131
|
case 3:
|
931
1132
|
tile.packetsIterator = new PositionComponentResolutionLayerIterator(context);
|
932
1133
|
break;
|
1134
|
+
|
933
1135
|
case 4:
|
934
1136
|
tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context);
|
935
1137
|
break;
|
1138
|
+
|
936
1139
|
default:
|
937
|
-
throw new JpxError(
|
1140
|
+
throw new JpxError("Unsupported progression order ".concat(progressionOrder));
|
938
1141
|
}
|
939
1142
|
}
|
1143
|
+
|
940
1144
|
function parseTilePackets(context, data, offset, dataLength) {
|
941
1145
|
var position = 0;
|
942
1146
|
var buffer,
|
943
1147
|
bufferSize = 0,
|
944
1148
|
skipNextBit = false;
|
1149
|
+
|
945
1150
|
function readBits(count) {
|
946
1151
|
while (bufferSize < count) {
|
947
1152
|
var b = data[offset + position];
|
948
1153
|
position++;
|
1154
|
+
|
949
1155
|
if (skipNextBit) {
|
950
1156
|
buffer = buffer << 7 | b;
|
951
1157
|
bufferSize += 7;
|
@@ -954,13 +1160,16 @@ var JpxImage = function JpxImageClosure() {
|
|
954
1160
|
buffer = buffer << 8 | b;
|
955
1161
|
bufferSize += 8;
|
956
1162
|
}
|
1163
|
+
|
957
1164
|
if (b === 0xFF) {
|
958
1165
|
skipNextBit = true;
|
959
1166
|
}
|
960
1167
|
}
|
1168
|
+
|
961
1169
|
bufferSize -= count;
|
962
1170
|
return buffer >>> bufferSize & (1 << count) - 1;
|
963
1171
|
}
|
1172
|
+
|
964
1173
|
function skipMarkerIfEqual(value) {
|
965
1174
|
if (data[offset + position - 1] === 0xFF && data[offset + position] === value) {
|
966
1175
|
skipBytes(1);
|
@@ -969,53 +1178,71 @@ var JpxImage = function JpxImageClosure() {
|
|
969
1178
|
skipBytes(2);
|
970
1179
|
return true;
|
971
1180
|
}
|
1181
|
+
|
972
1182
|
return false;
|
973
1183
|
}
|
1184
|
+
|
974
1185
|
function skipBytes(count) {
|
975
1186
|
position += count;
|
976
1187
|
}
|
1188
|
+
|
977
1189
|
function alignToByte() {
|
978
1190
|
bufferSize = 0;
|
1191
|
+
|
979
1192
|
if (skipNextBit) {
|
980
1193
|
position++;
|
981
1194
|
skipNextBit = false;
|
982
1195
|
}
|
983
1196
|
}
|
1197
|
+
|
984
1198
|
function readCodingpasses() {
|
985
1199
|
if (readBits(1) === 0) {
|
986
1200
|
return 1;
|
987
1201
|
}
|
1202
|
+
|
988
1203
|
if (readBits(1) === 0) {
|
989
1204
|
return 2;
|
990
1205
|
}
|
1206
|
+
|
991
1207
|
var value = readBits(2);
|
1208
|
+
|
992
1209
|
if (value < 3) {
|
993
1210
|
return value + 3;
|
994
1211
|
}
|
1212
|
+
|
995
1213
|
value = readBits(5);
|
1214
|
+
|
996
1215
|
if (value < 31) {
|
997
1216
|
return value + 6;
|
998
1217
|
}
|
1218
|
+
|
999
1219
|
value = readBits(7);
|
1000
1220
|
return value + 37;
|
1001
1221
|
}
|
1222
|
+
|
1002
1223
|
var tileIndex = context.currentTile.index;
|
1003
1224
|
var tile = context.tiles[tileIndex];
|
1004
1225
|
var sopMarkerUsed = context.COD.sopMarkerUsed;
|
1005
1226
|
var ephMarkerUsed = context.COD.ephMarkerUsed;
|
1006
1227
|
var packetsIterator = tile.packetsIterator;
|
1228
|
+
|
1007
1229
|
while (position < dataLength) {
|
1008
1230
|
alignToByte();
|
1231
|
+
|
1009
1232
|
if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
|
1010
1233
|
skipBytes(4);
|
1011
1234
|
}
|
1235
|
+
|
1012
1236
|
var packet = packetsIterator.nextPacket();
|
1237
|
+
|
1013
1238
|
if (!readBits(1)) {
|
1014
1239
|
continue;
|
1015
1240
|
}
|
1241
|
+
|
1016
1242
|
var layerNumber = packet.layerNumber;
|
1017
1243
|
var queue = [],
|
1018
1244
|
codeblock;
|
1245
|
+
|
1019
1246
|
for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
|
1020
1247
|
codeblock = packet.codeblocks[i];
|
1021
1248
|
var precinct = codeblock.precinct;
|
@@ -1024,11 +1251,13 @@ var JpxImage = function JpxImageClosure() {
|
|
1024
1251
|
var codeblockIncluded = false;
|
1025
1252
|
var firstTimeInclusion = false;
|
1026
1253
|
var valueReady;
|
1254
|
+
|
1027
1255
|
if (codeblock['included'] !== undefined) {
|
1028
1256
|
codeblockIncluded = !!readBits(1);
|
1029
1257
|
} else {
|
1030
1258
|
precinct = codeblock.precinct;
|
1031
1259
|
var inclusionTree, zeroBitPlanesTree;
|
1260
|
+
|
1032
1261
|
if (precinct['inclusionTree'] !== undefined) {
|
1033
1262
|
inclusionTree = precinct.inclusionTree;
|
1034
1263
|
} else {
|
@@ -1039,10 +1268,12 @@ var JpxImage = function JpxImageClosure() {
|
|
1039
1268
|
precinct.inclusionTree = inclusionTree;
|
1040
1269
|
precinct.zeroBitPlanesTree = zeroBitPlanesTree;
|
1041
1270
|
}
|
1271
|
+
|
1042
1272
|
if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
|
1043
1273
|
while (true) {
|
1044
1274
|
if (readBits(1)) {
|
1045
1275
|
valueReady = !inclusionTree.nextLevel();
|
1276
|
+
|
1046
1277
|
if (valueReady) {
|
1047
1278
|
codeblock.included = true;
|
1048
1279
|
codeblockIncluded = firstTimeInclusion = true;
|
@@ -1055,15 +1286,19 @@ var JpxImage = function JpxImageClosure() {
|
|
1055
1286
|
}
|
1056
1287
|
}
|
1057
1288
|
}
|
1289
|
+
|
1058
1290
|
if (!codeblockIncluded) {
|
1059
1291
|
continue;
|
1060
1292
|
}
|
1293
|
+
|
1061
1294
|
if (firstTimeInclusion) {
|
1062
1295
|
zeroBitPlanesTree = precinct.zeroBitPlanesTree;
|
1063
1296
|
zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
|
1297
|
+
|
1064
1298
|
while (true) {
|
1065
1299
|
if (readBits(1)) {
|
1066
1300
|
valueReady = !zeroBitPlanesTree.nextLevel();
|
1301
|
+
|
1067
1302
|
if (valueReady) {
|
1068
1303
|
break;
|
1069
1304
|
}
|
@@ -1071,12 +1306,16 @@ var JpxImage = function JpxImageClosure() {
|
|
1071
1306
|
zeroBitPlanesTree.incrementValue();
|
1072
1307
|
}
|
1073
1308
|
}
|
1309
|
+
|
1074
1310
|
codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
|
1075
1311
|
}
|
1312
|
+
|
1076
1313
|
var codingpasses = readCodingpasses();
|
1314
|
+
|
1077
1315
|
while (readBits(1)) {
|
1078
1316
|
codeblock.Lblock++;
|
1079
1317
|
}
|
1318
|
+
|
1080
1319
|
var codingpassesLog2 = (0, _util.log2)(codingpasses);
|
1081
1320
|
var bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
|
1082
1321
|
var codedDataLength = readBits(bits);
|
@@ -1086,16 +1325,21 @@ var JpxImage = function JpxImageClosure() {
|
|
1086
1325
|
dataLength: codedDataLength
|
1087
1326
|
});
|
1088
1327
|
}
|
1328
|
+
|
1089
1329
|
alignToByte();
|
1330
|
+
|
1090
1331
|
if (ephMarkerUsed) {
|
1091
1332
|
skipMarkerIfEqual(0x92);
|
1092
1333
|
}
|
1334
|
+
|
1093
1335
|
while (queue.length > 0) {
|
1094
1336
|
var packetItem = queue.shift();
|
1095
1337
|
codeblock = packetItem.codeblock;
|
1338
|
+
|
1096
1339
|
if (codeblock['data'] === undefined) {
|
1097
1340
|
codeblock.data = [];
|
1098
1341
|
}
|
1342
|
+
|
1099
1343
|
codeblock.data.push({
|
1100
1344
|
data: data,
|
1101
1345
|
start: offset + position,
|
@@ -1105,8 +1349,10 @@ var JpxImage = function JpxImageClosure() {
|
|
1105
1349
|
position += packetItem.dataLength;
|
1106
1350
|
}
|
1107
1351
|
}
|
1352
|
+
|
1108
1353
|
return position;
|
1109
1354
|
}
|
1355
|
+
|
1110
1356
|
function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed) {
|
1111
1357
|
var x0 = subband.tbx0;
|
1112
1358
|
var y0 = subband.tby0;
|
@@ -1114,16 +1360,20 @@ var JpxImage = function JpxImageClosure() {
|
|
1114
1360
|
var codeblocks = subband.codeblocks;
|
1115
1361
|
var right = subband.type.charAt(0) === 'H' ? 1 : 0;
|
1116
1362
|
var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
|
1363
|
+
|
1117
1364
|
for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
|
1118
1365
|
var codeblock = codeblocks[i];
|
1119
1366
|
var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
|
1120
1367
|
var blockHeight = codeblock.tby1_ - codeblock.tby0_;
|
1368
|
+
|
1121
1369
|
if (blockWidth === 0 || blockHeight === 0) {
|
1122
1370
|
continue;
|
1123
1371
|
}
|
1372
|
+
|
1124
1373
|
if (codeblock['data'] === undefined) {
|
1125
1374
|
continue;
|
1126
1375
|
}
|
1376
|
+
|
1127
1377
|
var bitModel, currentCodingpassType;
|
1128
1378
|
bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb);
|
1129
1379
|
currentCodingpassType = 2;
|
@@ -1131,38 +1381,49 @@ var JpxImage = function JpxImageClosure() {
|
|
1131
1381
|
totalLength = 0,
|
1132
1382
|
codingpasses = 0;
|
1133
1383
|
var j, jj, dataItem;
|
1384
|
+
|
1134
1385
|
for (j = 0, jj = data.length; j < jj; j++) {
|
1135
1386
|
dataItem = data[j];
|
1136
1387
|
totalLength += dataItem.end - dataItem.start;
|
1137
1388
|
codingpasses += dataItem.codingpasses;
|
1138
1389
|
}
|
1390
|
+
|
1139
1391
|
var encodedData = new Uint8Array(totalLength);
|
1140
1392
|
var position = 0;
|
1393
|
+
|
1141
1394
|
for (j = 0, jj = data.length; j < jj; j++) {
|
1142
1395
|
dataItem = data[j];
|
1143
1396
|
var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
|
1144
1397
|
encodedData.set(chunk, position);
|
1145
1398
|
position += chunk.length;
|
1146
1399
|
}
|
1400
|
+
|
1147
1401
|
var decoder = new _arithmetic_decoder.ArithmeticDecoder(encodedData, 0, totalLength);
|
1148
1402
|
bitModel.setDecoder(decoder);
|
1403
|
+
|
1149
1404
|
for (j = 0; j < codingpasses; j++) {
|
1150
1405
|
switch (currentCodingpassType) {
|
1151
1406
|
case 0:
|
1152
1407
|
bitModel.runSignificancePropagationPass();
|
1153
1408
|
break;
|
1409
|
+
|
1154
1410
|
case 1:
|
1155
1411
|
bitModel.runMagnitudeRefinementPass();
|
1156
1412
|
break;
|
1413
|
+
|
1157
1414
|
case 2:
|
1158
1415
|
bitModel.runCleanupPass();
|
1416
|
+
|
1159
1417
|
if (segmentationSymbolUsed) {
|
1160
1418
|
bitModel.checkSegmentationSymbol();
|
1161
1419
|
}
|
1420
|
+
|
1162
1421
|
break;
|
1163
1422
|
}
|
1423
|
+
|
1164
1424
|
currentCodingpassType = (currentCodingpassType + 1) % 3;
|
1165
1425
|
}
|
1426
|
+
|
1166
1427
|
var offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width;
|
1167
1428
|
var sign = bitModel.coefficentsSign;
|
1168
1429
|
var magnitude = bitModel.coefficentsMagnitude;
|
@@ -1171,31 +1432,40 @@ var JpxImage = function JpxImageClosure() {
|
|
1171
1432
|
var k, n, nb;
|
1172
1433
|
position = 0;
|
1173
1434
|
var interleave = subband.type !== 'LL';
|
1435
|
+
|
1174
1436
|
for (j = 0; j < blockHeight; j++) {
|
1175
1437
|
var row = offset / width | 0;
|
1176
1438
|
var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
|
1439
|
+
|
1177
1440
|
for (k = 0; k < blockWidth; k++) {
|
1178
1441
|
n = magnitude[position];
|
1442
|
+
|
1179
1443
|
if (n !== 0) {
|
1180
1444
|
n = (n + magnitudeCorrection) * delta;
|
1445
|
+
|
1181
1446
|
if (sign[position] !== 0) {
|
1182
1447
|
n = -n;
|
1183
1448
|
}
|
1449
|
+
|
1184
1450
|
nb = bitsDecoded[position];
|
1185
1451
|
var pos = interleave ? levelOffset + (offset << 1) : offset;
|
1452
|
+
|
1186
1453
|
if (reversible && nb >= mb) {
|
1187
1454
|
coefficients[pos] = n;
|
1188
1455
|
} else {
|
1189
1456
|
coefficients[pos] = n * (1 << mb - nb);
|
1190
1457
|
}
|
1191
1458
|
}
|
1459
|
+
|
1192
1460
|
offset++;
|
1193
1461
|
position++;
|
1194
1462
|
}
|
1463
|
+
|
1195
1464
|
offset += width - blockWidth;
|
1196
1465
|
}
|
1197
1466
|
}
|
1198
1467
|
}
|
1468
|
+
|
1199
1469
|
function transformTile(context, tile, c) {
|
1200
1470
|
var component = tile.components[c];
|
1201
1471
|
var codingStyleParameters = component.codingStyleParameters;
|
@@ -1210,13 +1480,16 @@ var JpxImage = function JpxImageClosure() {
|
|
1210
1480
|
var transform = reversible ? new ReversibleTransform() : new IrreversibleTransform();
|
1211
1481
|
var subbandCoefficients = [];
|
1212
1482
|
var b = 0;
|
1483
|
+
|
1213
1484
|
for (var i = 0; i <= decompositionLevelsCount; i++) {
|
1214
1485
|
var resolution = component.resolutions[i];
|
1215
1486
|
var width = resolution.trx1 - resolution.trx0;
|
1216
1487
|
var height = resolution.try1 - resolution.try0;
|
1217
1488
|
var coefficients = new Float32Array(width * height);
|
1489
|
+
|
1218
1490
|
for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
|
1219
1491
|
var mu, epsilon;
|
1492
|
+
|
1220
1493
|
if (!scalarExpounded) {
|
1221
1494
|
mu = spqcds[0].mu;
|
1222
1495
|
epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
|
@@ -1225,18 +1498,21 @@ var JpxImage = function JpxImageClosure() {
|
|
1225
1498
|
epsilon = spqcds[b].epsilon;
|
1226
1499
|
b++;
|
1227
1500
|
}
|
1501
|
+
|
1228
1502
|
var subband = resolution.subbands[j];
|
1229
1503
|
var gainLog2 = SubbandsGainLog2[subband.type];
|
1230
1504
|
var delta = reversible ? 1 : Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048);
|
1231
1505
|
var mb = guardBits + epsilon - 1;
|
1232
1506
|
copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed);
|
1233
1507
|
}
|
1508
|
+
|
1234
1509
|
subbandCoefficients.push({
|
1235
1510
|
width: width,
|
1236
1511
|
height: height,
|
1237
1512
|
items: coefficients
|
1238
1513
|
});
|
1239
1514
|
}
|
1515
|
+
|
1240
1516
|
var result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0);
|
1241
1517
|
return {
|
1242
1518
|
left: component.tcx0,
|
@@ -1246,18 +1522,22 @@ var JpxImage = function JpxImageClosure() {
|
|
1246
1522
|
items: result.items
|
1247
1523
|
};
|
1248
1524
|
}
|
1525
|
+
|
1249
1526
|
function transformComponents(context) {
|
1250
1527
|
var siz = context.SIZ;
|
1251
1528
|
var components = context.components;
|
1252
1529
|
var componentsCount = siz.Csiz;
|
1253
1530
|
var resultImages = [];
|
1531
|
+
|
1254
1532
|
for (var i = 0, ii = context.tiles.length; i < ii; i++) {
|
1255
1533
|
var tile = context.tiles[i];
|
1256
1534
|
var transformedTiles = [];
|
1257
1535
|
var c;
|
1536
|
+
|
1258
1537
|
for (c = 0; c < componentsCount; c++) {
|
1259
1538
|
transformedTiles[c] = transformTile(context, tile, c);
|
1260
1539
|
}
|
1540
|
+
|
1261
1541
|
var tile0 = transformedTiles[0];
|
1262
1542
|
var out = new Uint8ClampedArray(tile0.items.length * componentsCount);
|
1263
1543
|
var result = {
|
@@ -1274,6 +1554,7 @@ var JpxImage = function JpxImageClosure() {
|
|
1274
1554
|
y0,
|
1275
1555
|
y1,
|
1276
1556
|
y2;
|
1557
|
+
|
1277
1558
|
if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
|
1278
1559
|
var fourComponents = componentsCount === 4;
|
1279
1560
|
var y0items = transformedTiles[0].items;
|
@@ -1285,6 +1566,7 @@ var JpxImage = function JpxImageClosure() {
|
|
1285
1566
|
var component0 = tile.components[0];
|
1286
1567
|
var alpha01 = componentsCount - 3;
|
1287
1568
|
jj = y0items.length;
|
1569
|
+
|
1288
1570
|
if (!component0.codingStyleParameters.reversibleTransformation) {
|
1289
1571
|
for (j = 0; j < jj; j++, pos += alpha01) {
|
1290
1572
|
y0 = y0items[j] + offset;
|
@@ -1305,6 +1587,7 @@ var JpxImage = function JpxImageClosure() {
|
|
1305
1587
|
out[pos++] = g + y1 >> shift;
|
1306
1588
|
}
|
1307
1589
|
}
|
1590
|
+
|
1308
1591
|
if (fourComponents) {
|
1309
1592
|
for (j = 0, pos = 3; j < jj; j++, pos += 4) {
|
1310
1593
|
out[pos] = y3items[j] + offset >> shift;
|
@@ -1315,20 +1598,25 @@ var JpxImage = function JpxImageClosure() {
|
|
1315
1598
|
var items = transformedTiles[c].items;
|
1316
1599
|
shift = components[c].precision - 8;
|
1317
1600
|
offset = (128 << shift) + 0.5;
|
1601
|
+
|
1318
1602
|
for (pos = c, j = 0, jj = items.length; j < jj; j++) {
|
1319
1603
|
out[pos] = items[j] + offset >> shift;
|
1320
1604
|
pos += componentsCount;
|
1321
1605
|
}
|
1322
1606
|
}
|
1323
1607
|
}
|
1608
|
+
|
1324
1609
|
resultImages.push(result);
|
1325
1610
|
}
|
1611
|
+
|
1326
1612
|
return resultImages;
|
1327
1613
|
}
|
1614
|
+
|
1328
1615
|
function initializeTile(context, tileIndex) {
|
1329
1616
|
var siz = context.SIZ;
|
1330
1617
|
var componentsCount = siz.Csiz;
|
1331
1618
|
var tile = context.tiles[tileIndex];
|
1619
|
+
|
1332
1620
|
for (var c = 0; c < componentsCount; c++) {
|
1333
1621
|
var component = tile.components[c];
|
1334
1622
|
var qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD;
|
@@ -1336,12 +1624,15 @@ var JpxImage = function JpxImageClosure() {
|
|
1336
1624
|
var codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD;
|
1337
1625
|
component.codingStyleParameters = codOrCoc;
|
1338
1626
|
}
|
1627
|
+
|
1339
1628
|
tile.codingStyleDefaultParameters = context.currentTile.COD;
|
1340
1629
|
}
|
1630
|
+
|
1341
1631
|
var TagTree = function TagTreeClosure() {
|
1342
1632
|
function TagTree(width, height) {
|
1343
1633
|
var levelsLength = (0, _util.log2)(Math.max(width, height)) + 1;
|
1344
1634
|
this.levels = [];
|
1635
|
+
|
1345
1636
|
for (var i = 0; i < levelsLength; i++) {
|
1346
1637
|
var level = {
|
1347
1638
|
width: width,
|
@@ -1353,23 +1644,28 @@ var JpxImage = function JpxImageClosure() {
|
|
1353
1644
|
height = Math.ceil(height / 2);
|
1354
1645
|
}
|
1355
1646
|
}
|
1647
|
+
|
1356
1648
|
TagTree.prototype = {
|
1357
1649
|
reset: function TagTree_reset(i, j) {
|
1358
1650
|
var currentLevel = 0,
|
1359
1651
|
value = 0,
|
1360
1652
|
level;
|
1653
|
+
|
1361
1654
|
while (currentLevel < this.levels.length) {
|
1362
1655
|
level = this.levels[currentLevel];
|
1363
1656
|
var index = i + j * level.width;
|
1657
|
+
|
1364
1658
|
if (level.items[index] !== undefined) {
|
1365
1659
|
value = level.items[index];
|
1366
1660
|
break;
|
1367
1661
|
}
|
1662
|
+
|
1368
1663
|
level.index = index;
|
1369
1664
|
i >>= 1;
|
1370
1665
|
j >>= 1;
|
1371
1666
|
currentLevel++;
|
1372
1667
|
}
|
1668
|
+
|
1373
1669
|
currentLevel--;
|
1374
1670
|
level = this.levels[currentLevel];
|
1375
1671
|
level.items[level.index] = value;
|
@@ -1385,10 +1681,12 @@ var JpxImage = function JpxImageClosure() {
|
|
1385
1681
|
var level = this.levels[currentLevel];
|
1386
1682
|
var value = level.items[level.index];
|
1387
1683
|
currentLevel--;
|
1684
|
+
|
1388
1685
|
if (currentLevel < 0) {
|
1389
1686
|
this.value = value;
|
1390
1687
|
return false;
|
1391
1688
|
}
|
1689
|
+
|
1392
1690
|
this.currentLevel = currentLevel;
|
1393
1691
|
level = this.levels[currentLevel];
|
1394
1692
|
level.items[level.index] = value;
|
@@ -1397,15 +1695,19 @@ var JpxImage = function JpxImageClosure() {
|
|
1397
1695
|
};
|
1398
1696
|
return TagTree;
|
1399
1697
|
}();
|
1698
|
+
|
1400
1699
|
var InclusionTree = function InclusionTreeClosure() {
|
1401
1700
|
function InclusionTree(width, height, defaultValue) {
|
1402
1701
|
var levelsLength = (0, _util.log2)(Math.max(width, height)) + 1;
|
1403
1702
|
this.levels = [];
|
1703
|
+
|
1404
1704
|
for (var i = 0; i < levelsLength; i++) {
|
1405
1705
|
var items = new Uint8Array(width * height);
|
1706
|
+
|
1406
1707
|
for (var j = 0, jj = items.length; j < jj; j++) {
|
1407
1708
|
items[j] = defaultValue;
|
1408
1709
|
}
|
1710
|
+
|
1409
1711
|
var level = {
|
1410
1712
|
width: width,
|
1411
1713
|
height: height,
|
@@ -1416,26 +1718,32 @@ var JpxImage = function JpxImageClosure() {
|
|
1416
1718
|
height = Math.ceil(height / 2);
|
1417
1719
|
}
|
1418
1720
|
}
|
1721
|
+
|
1419
1722
|
InclusionTree.prototype = {
|
1420
1723
|
reset: function InclusionTree_reset(i, j, stopValue) {
|
1421
1724
|
var currentLevel = 0;
|
1725
|
+
|
1422
1726
|
while (currentLevel < this.levels.length) {
|
1423
1727
|
var level = this.levels[currentLevel];
|
1424
1728
|
var index = i + j * level.width;
|
1425
1729
|
level.index = index;
|
1426
1730
|
var value = level.items[index];
|
1731
|
+
|
1427
1732
|
if (value === 0xFF) {
|
1428
1733
|
break;
|
1429
1734
|
}
|
1735
|
+
|
1430
1736
|
if (value > stopValue) {
|
1431
1737
|
this.currentLevel = currentLevel;
|
1432
1738
|
this.propagateValues();
|
1433
1739
|
return false;
|
1434
1740
|
}
|
1741
|
+
|
1435
1742
|
i >>= 1;
|
1436
1743
|
j >>= 1;
|
1437
1744
|
currentLevel++;
|
1438
1745
|
}
|
1746
|
+
|
1439
1747
|
this.currentLevel = currentLevel - 1;
|
1440
1748
|
return true;
|
1441
1749
|
},
|
@@ -1448,6 +1756,7 @@ var JpxImage = function JpxImageClosure() {
|
|
1448
1756
|
var levelIndex = this.currentLevel;
|
1449
1757
|
var level = this.levels[levelIndex];
|
1450
1758
|
var currentValue = level.items[level.index];
|
1759
|
+
|
1451
1760
|
while (--levelIndex >= 0) {
|
1452
1761
|
level = this.levels[levelIndex];
|
1453
1762
|
level.items[level.index] = currentValue;
|
@@ -1459,9 +1768,11 @@ var JpxImage = function JpxImageClosure() {
|
|
1459
1768
|
var value = level.items[level.index];
|
1460
1769
|
level.items[level.index] = 0xFF;
|
1461
1770
|
currentLevel--;
|
1771
|
+
|
1462
1772
|
if (currentLevel < 0) {
|
1463
1773
|
return false;
|
1464
1774
|
}
|
1775
|
+
|
1465
1776
|
this.currentLevel = currentLevel;
|
1466
1777
|
level = this.levels[currentLevel];
|
1467
1778
|
level.items[level.index] = value;
|
@@ -1470,12 +1781,14 @@ var JpxImage = function JpxImageClosure() {
|
|
1470
1781
|
};
|
1471
1782
|
return InclusionTree;
|
1472
1783
|
}();
|
1784
|
+
|
1473
1785
|
var BitModel = function BitModelClosure() {
|
1474
1786
|
var UNIFORM_CONTEXT = 17;
|
1475
1787
|
var RUNLENGTH_CONTEXT = 18;
|
1476
1788
|
var LLAndLHContextsLabel = new Uint8Array([0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8]);
|
1477
1789
|
var HLContextLabel = new Uint8Array([0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8]);
|
1478
1790
|
var HHContextLabel = new Uint8Array([0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5, 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8]);
|
1791
|
+
|
1479
1792
|
function BitModel(width, height, subband, zeroBitPlanes, mb) {
|
1480
1793
|
this.width = width;
|
1481
1794
|
this.height = height;
|
@@ -1486,14 +1799,17 @@ var JpxImage = function JpxImageClosure() {
|
|
1486
1799
|
this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) : mb > 6 ? new Uint16Array(coefficientCount) : new Uint8Array(coefficientCount);
|
1487
1800
|
this.processingFlags = new Uint8Array(coefficientCount);
|
1488
1801
|
var bitsDecoded = new Uint8Array(coefficientCount);
|
1802
|
+
|
1489
1803
|
if (zeroBitPlanes !== 0) {
|
1490
1804
|
for (var i = 0; i < coefficientCount; i++) {
|
1491
1805
|
bitsDecoded[i] = zeroBitPlanes;
|
1492
1806
|
}
|
1493
1807
|
}
|
1808
|
+
|
1494
1809
|
this.bitsDecoded = bitsDecoded;
|
1495
1810
|
this.reset();
|
1496
1811
|
}
|
1812
|
+
|
1497
1813
|
BitModel.prototype = {
|
1498
1814
|
setDecoder: function BitModel_setDecoder(decoder) {
|
1499
1815
|
this.decoder = decoder;
|
@@ -1511,32 +1827,43 @@ var JpxImage = function JpxImageClosure() {
|
|
1511
1827
|
var left = column > 0;
|
1512
1828
|
var right = column + 1 < width;
|
1513
1829
|
var i;
|
1830
|
+
|
1514
1831
|
if (row > 0) {
|
1515
1832
|
i = index - width;
|
1833
|
+
|
1516
1834
|
if (left) {
|
1517
1835
|
neighborsSignificance[i - 1] += 0x10;
|
1518
1836
|
}
|
1837
|
+
|
1519
1838
|
if (right) {
|
1520
1839
|
neighborsSignificance[i + 1] += 0x10;
|
1521
1840
|
}
|
1841
|
+
|
1522
1842
|
neighborsSignificance[i] += 0x04;
|
1523
1843
|
}
|
1844
|
+
|
1524
1845
|
if (row + 1 < height) {
|
1525
1846
|
i = index + width;
|
1847
|
+
|
1526
1848
|
if (left) {
|
1527
1849
|
neighborsSignificance[i - 1] += 0x10;
|
1528
1850
|
}
|
1851
|
+
|
1529
1852
|
if (right) {
|
1530
1853
|
neighborsSignificance[i + 1] += 0x10;
|
1531
1854
|
}
|
1855
|
+
|
1532
1856
|
neighborsSignificance[i] += 0x04;
|
1533
1857
|
}
|
1858
|
+
|
1534
1859
|
if (left) {
|
1535
1860
|
neighborsSignificance[index - 1] += 0x01;
|
1536
1861
|
}
|
1862
|
+
|
1537
1863
|
if (right) {
|
1538
1864
|
neighborsSignificance[index + 1] += 0x01;
|
1539
1865
|
}
|
1866
|
+
|
1540
1867
|
neighborsSignificance[index] |= 0x80;
|
1541
1868
|
},
|
1542
1869
|
runSignificancePropagationPass: function BitModel_runSignificancePropagationPass() {
|
@@ -1553,20 +1880,27 @@ var JpxImage = function JpxImageClosure() {
|
|
1553
1880
|
var processedInverseMask = ~1;
|
1554
1881
|
var processedMask = 1;
|
1555
1882
|
var firstMagnitudeBitMask = 2;
|
1883
|
+
|
1556
1884
|
for (var i0 = 0; i0 < height; i0 += 4) {
|
1557
1885
|
for (var j = 0; j < width; j++) {
|
1558
1886
|
var index = i0 * width + j;
|
1887
|
+
|
1559
1888
|
for (var i1 = 0; i1 < 4; i1++, index += width) {
|
1560
1889
|
var i = i0 + i1;
|
1890
|
+
|
1561
1891
|
if (i >= height) {
|
1562
1892
|
break;
|
1563
1893
|
}
|
1894
|
+
|
1564
1895
|
processingFlags[index] &= processedInverseMask;
|
1896
|
+
|
1565
1897
|
if (coefficentsMagnitude[index] || !neighborsSignificance[index]) {
|
1566
1898
|
continue;
|
1567
1899
|
}
|
1900
|
+
|
1568
1901
|
var contextLabel = labels[neighborsSignificance[index]];
|
1569
1902
|
var decision = decoder.readBit(contexts, contextLabel);
|
1903
|
+
|
1570
1904
|
if (decision) {
|
1571
1905
|
var sign = this.decodeSignBit(i, j, index);
|
1572
1906
|
coefficentsSign[index] = sign;
|
@@ -1574,6 +1908,7 @@ var JpxImage = function JpxImageClosure() {
|
|
1574
1908
|
this.setNeighborsSignificance(i, j, index);
|
1575
1909
|
processingFlags[index] |= firstMagnitudeBitMask;
|
1576
1910
|
}
|
1911
|
+
|
1577
1912
|
bitsDecoded[index]++;
|
1578
1913
|
processingFlags[index] |= processedMask;
|
1579
1914
|
}
|
@@ -1588,8 +1923,10 @@ var JpxImage = function JpxImageClosure() {
|
|
1588
1923
|
var contribution, sign0, sign1, significance1;
|
1589
1924
|
var contextLabel, decoded;
|
1590
1925
|
significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0;
|
1926
|
+
|
1591
1927
|
if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
|
1592
1928
|
sign1 = coefficentsSign[index + 1];
|
1929
|
+
|
1593
1930
|
if (significance1) {
|
1594
1931
|
sign0 = coefficentsSign[index - 1];
|
1595
1932
|
contribution = 1 - sign1 - sign0;
|
@@ -1602,10 +1939,13 @@ var JpxImage = function JpxImageClosure() {
|
|
1602
1939
|
} else {
|
1603
1940
|
contribution = 0;
|
1604
1941
|
}
|
1942
|
+
|
1605
1943
|
var horizontalContribution = 3 * contribution;
|
1606
1944
|
significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0;
|
1945
|
+
|
1607
1946
|
if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
|
1608
1947
|
sign1 = coefficentsSign[index + width];
|
1948
|
+
|
1609
1949
|
if (significance1) {
|
1610
1950
|
sign0 = coefficentsSign[index - width];
|
1611
1951
|
contribution = 1 - sign1 - sign0 + horizontalContribution;
|
@@ -1618,6 +1958,7 @@ var JpxImage = function JpxImageClosure() {
|
|
1618
1958
|
} else {
|
1619
1959
|
contribution = horizontalContribution;
|
1620
1960
|
}
|
1961
|
+
|
1621
1962
|
if (contribution >= 0) {
|
1622
1963
|
contextLabel = 9 + contribution;
|
1623
1964
|
decoded = this.decoder.readBit(this.contexts, contextLabel);
|
@@ -1625,6 +1966,7 @@ var JpxImage = function JpxImageClosure() {
|
|
1625
1966
|
contextLabel = 9 - contribution;
|
1626
1967
|
decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
|
1627
1968
|
}
|
1969
|
+
|
1628
1970
|
return decoded;
|
1629
1971
|
},
|
1630
1972
|
runMagnitudeRefinementPass: function BitModel_runMagnitudeRefinementPass() {
|
@@ -1640,19 +1982,24 @@ var JpxImage = function JpxImageClosure() {
|
|
1640
1982
|
var firstMagnitudeBitMask = 2;
|
1641
1983
|
var length = width * height;
|
1642
1984
|
var width4 = width * 4;
|
1985
|
+
|
1643
1986
|
for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
|
1644
1987
|
indexNext = Math.min(length, index0 + width4);
|
1988
|
+
|
1645
1989
|
for (var j = 0; j < width; j++) {
|
1646
1990
|
for (var index = index0 + j; index < indexNext; index += width) {
|
1647
1991
|
if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
|
1648
1992
|
continue;
|
1649
1993
|
}
|
1994
|
+
|
1650
1995
|
var contextLabel = 16;
|
1996
|
+
|
1651
1997
|
if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
|
1652
1998
|
processingFlags[index] ^= firstMagnitudeBitMask;
|
1653
1999
|
var significance = neighborsSignificance[index] & 127;
|
1654
2000
|
contextLabel = significance === 0 ? 15 : 14;
|
1655
2001
|
}
|
2002
|
+
|
1656
2003
|
var bit = decoder.readBit(contexts, contextLabel);
|
1657
2004
|
coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit;
|
1658
2005
|
bitsDecoded[index]++;
|
@@ -1678,10 +2025,12 @@ var JpxImage = function JpxImageClosure() {
|
|
1678
2025
|
var twoRowsDown = width * 2;
|
1679
2026
|
var threeRowsDown = width * 3;
|
1680
2027
|
var iNext;
|
2028
|
+
|
1681
2029
|
for (var i0 = 0; i0 < height; i0 = iNext) {
|
1682
2030
|
iNext = Math.min(i0 + 4, height);
|
1683
2031
|
var indexBase = i0 * width;
|
1684
2032
|
var checkAllEmpty = i0 + 3 < height;
|
2033
|
+
|
1685
2034
|
for (var j = 0; j < width; j++) {
|
1686
2035
|
var index0 = indexBase + j;
|
1687
2036
|
var allEmpty = checkAllEmpty && processingFlags[index0] === 0 && processingFlags[index0 + oneRowDown] === 0 && processingFlags[index0 + twoRowsDown] === 0 && processingFlags[index0 + threeRowsDown] === 0 && neighborsSignificance[index0] === 0 && neighborsSignificance[index0 + oneRowDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0;
|
@@ -1689,8 +2038,10 @@ var JpxImage = function JpxImageClosure() {
|
|
1689
2038
|
index = index0;
|
1690
2039
|
var i = i0,
|
1691
2040
|
sign;
|
2041
|
+
|
1692
2042
|
if (allEmpty) {
|
1693
2043
|
var hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT);
|
2044
|
+
|
1694
2045
|
if (!hasSignificantCoefficent) {
|
1695
2046
|
bitsDecoded[index0]++;
|
1696
2047
|
bitsDecoded[index0 + oneRowDown]++;
|
@@ -1698,28 +2049,36 @@ var JpxImage = function JpxImageClosure() {
|
|
1698
2049
|
bitsDecoded[index0 + threeRowsDown]++;
|
1699
2050
|
continue;
|
1700
2051
|
}
|
2052
|
+
|
1701
2053
|
i1 = decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
|
2054
|
+
|
1702
2055
|
if (i1 !== 0) {
|
1703
2056
|
i = i0 + i1;
|
1704
2057
|
index += i1 * width;
|
1705
2058
|
}
|
2059
|
+
|
1706
2060
|
sign = this.decodeSignBit(i, j, index);
|
1707
2061
|
coefficentsSign[index] = sign;
|
1708
2062
|
coefficentsMagnitude[index] = 1;
|
1709
2063
|
this.setNeighborsSignificance(i, j, index);
|
1710
2064
|
processingFlags[index] |= firstMagnitudeBitMask;
|
1711
2065
|
index = index0;
|
2066
|
+
|
1712
2067
|
for (var i2 = i0; i2 <= i; i2++, index += width) {
|
1713
2068
|
bitsDecoded[index]++;
|
1714
2069
|
}
|
2070
|
+
|
1715
2071
|
i1++;
|
1716
2072
|
}
|
2073
|
+
|
1717
2074
|
for (i = i0 + i1; i < iNext; i++, index += width) {
|
1718
2075
|
if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
|
1719
2076
|
continue;
|
1720
2077
|
}
|
2078
|
+
|
1721
2079
|
var contextLabel = labels[neighborsSignificance[index]];
|
1722
2080
|
var decision = decoder.readBit(contexts, contextLabel);
|
2081
|
+
|
1723
2082
|
if (decision === 1) {
|
1724
2083
|
sign = this.decodeSignBit(i, j, index);
|
1725
2084
|
coefficentsSign[index] = sign;
|
@@ -1727,6 +2086,7 @@ var JpxImage = function JpxImageClosure() {
|
|
1727
2086
|
this.setNeighborsSignificance(i, j, index);
|
1728
2087
|
processingFlags[index] |= firstMagnitudeBitMask;
|
1729
2088
|
}
|
2089
|
+
|
1730
2090
|
bitsDecoded[index]++;
|
1731
2091
|
}
|
1732
2092
|
}
|
@@ -1736,6 +2096,7 @@ var JpxImage = function JpxImageClosure() {
|
|
1736
2096
|
var decoder = this.decoder;
|
1737
2097
|
var contexts = this.contexts;
|
1738
2098
|
var symbol = decoder.readBit(contexts, UNIFORM_CONTEXT) << 3 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 2 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
|
2099
|
+
|
1739
2100
|
if (symbol !== 0xA) {
|
1740
2101
|
throw new JpxError('Invalid segmentation symbol');
|
1741
2102
|
}
|
@@ -1743,15 +2104,20 @@ var JpxImage = function JpxImageClosure() {
|
|
1743
2104
|
};
|
1744
2105
|
return BitModel;
|
1745
2106
|
}();
|
2107
|
+
|
1746
2108
|
var Transform = function TransformClosure() {
|
1747
2109
|
function Transform() {}
|
2110
|
+
|
1748
2111
|
Transform.prototype.calculate = function transformCalculate(subbands, u0, v0) {
|
1749
2112
|
var ll = subbands[0];
|
2113
|
+
|
1750
2114
|
for (var i = 1, ii = subbands.length; i < ii; i++) {
|
1751
2115
|
ll = this.iterate(ll, subbands[i], u0, v0);
|
1752
2116
|
}
|
2117
|
+
|
1753
2118
|
return ll;
|
1754
2119
|
};
|
2120
|
+
|
1755
2121
|
Transform.prototype.extend = function extend(buffer, offset, size) {
|
1756
2122
|
var i1 = offset - 1,
|
1757
2123
|
j1 = offset + 1;
|
@@ -1766,6 +2132,7 @@ var JpxImage = function JpxImageClosure() {
|
|
1766
2132
|
buffer[i1] = buffer[j1];
|
1767
2133
|
buffer[j2] = buffer[i2];
|
1768
2134
|
};
|
2135
|
+
|
1769
2136
|
Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh, u0, v0) {
|
1770
2137
|
var llWidth = ll.width,
|
1771
2138
|
llHeight = ll.height,
|
@@ -1774,15 +2141,19 @@ var JpxImage = function JpxImageClosure() {
|
|
1774
2141
|
var height = hl_lh_hh.height;
|
1775
2142
|
var items = hl_lh_hh.items;
|
1776
2143
|
var i, j, k, l, u, v;
|
2144
|
+
|
1777
2145
|
for (k = 0, i = 0; i < llHeight; i++) {
|
1778
2146
|
l = i * 2 * width;
|
2147
|
+
|
1779
2148
|
for (j = 0; j < llWidth; j++, k++, l += 2) {
|
1780
2149
|
items[l] = llItems[k];
|
1781
2150
|
}
|
1782
2151
|
}
|
2152
|
+
|
1783
2153
|
llItems = ll.items = null;
|
1784
2154
|
var bufferPadding = 4;
|
1785
2155
|
var rowBuffer = new Float32Array(width + 2 * bufferPadding);
|
2156
|
+
|
1786
2157
|
if (width === 1) {
|
1787
2158
|
if ((u0 & 1) !== 0) {
|
1788
2159
|
for (v = 0, k = 0; v < height; v++, k += width) {
|
@@ -1797,14 +2168,18 @@ var JpxImage = function JpxImageClosure() {
|
|
1797
2168
|
items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k);
|
1798
2169
|
}
|
1799
2170
|
}
|
2171
|
+
|
1800
2172
|
var numBuffers = 16;
|
1801
2173
|
var colBuffers = [];
|
2174
|
+
|
1802
2175
|
for (i = 0; i < numBuffers; i++) {
|
1803
2176
|
colBuffers.push(new Float32Array(height + 2 * bufferPadding));
|
1804
2177
|
}
|
2178
|
+
|
1805
2179
|
var b,
|
1806
2180
|
currentBuffer = 0;
|
1807
2181
|
ll = bufferPadding + height;
|
2182
|
+
|
1808
2183
|
if (height === 1) {
|
1809
2184
|
if ((v0 & 1) !== 0) {
|
1810
2185
|
for (u = 0; u < width; u++) {
|
@@ -1815,19 +2190,24 @@ var JpxImage = function JpxImageClosure() {
|
|
1815
2190
|
for (u = 0; u < width; u++) {
|
1816
2191
|
if (currentBuffer === 0) {
|
1817
2192
|
numBuffers = Math.min(width - u, numBuffers);
|
2193
|
+
|
1818
2194
|
for (k = u, l = bufferPadding; l < ll; k += width, l++) {
|
1819
2195
|
for (b = 0; b < numBuffers; b++) {
|
1820
2196
|
colBuffers[b][l] = items[k + b];
|
1821
2197
|
}
|
1822
2198
|
}
|
2199
|
+
|
1823
2200
|
currentBuffer = numBuffers;
|
1824
2201
|
}
|
2202
|
+
|
1825
2203
|
currentBuffer--;
|
1826
2204
|
var buffer = colBuffers[currentBuffer];
|
1827
2205
|
this.extend(buffer, bufferPadding, height);
|
1828
2206
|
this.filter(buffer, bufferPadding, height);
|
2207
|
+
|
1829
2208
|
if (currentBuffer === 0) {
|
1830
2209
|
k = u - numBuffers + 1;
|
2210
|
+
|
1831
2211
|
for (l = bufferPadding; l < ll; k += width, l++) {
|
1832
2212
|
for (b = 0; b < numBuffers; b++) {
|
1833
2213
|
items[k + b] = colBuffers[b][l];
|
@@ -1836,19 +2216,24 @@ var JpxImage = function JpxImageClosure() {
|
|
1836
2216
|
}
|
1837
2217
|
}
|
1838
2218
|
}
|
2219
|
+
|
1839
2220
|
return {
|
1840
2221
|
width: width,
|
1841
2222
|
height: height,
|
1842
2223
|
items: items
|
1843
2224
|
};
|
1844
2225
|
};
|
2226
|
+
|
1845
2227
|
return Transform;
|
1846
2228
|
}();
|
2229
|
+
|
1847
2230
|
var IrreversibleTransform = function IrreversibleTransformClosure() {
|
1848
2231
|
function IrreversibleTransform() {
|
1849
2232
|
Transform.call(this);
|
1850
2233
|
}
|
2234
|
+
|
1851
2235
|
IrreversibleTransform.prototype = Object.create(Transform.prototype);
|
2236
|
+
|
1852
2237
|
IrreversibleTransform.prototype.filter = function irreversibleTransformFilter(x, offset, length) {
|
1853
2238
|
var len = length >> 1;
|
1854
2239
|
offset = offset | 0;
|
@@ -1860,14 +2245,18 @@ var JpxImage = function JpxImageClosure() {
|
|
1860
2245
|
var K = 1.230174104914001;
|
1861
2246
|
var K_ = 1 / K;
|
1862
2247
|
j = offset - 3;
|
2248
|
+
|
1863
2249
|
for (n = len + 4; n--; j += 2) {
|
1864
2250
|
x[j] *= K_;
|
1865
2251
|
}
|
2252
|
+
|
1866
2253
|
j = offset - 2;
|
1867
2254
|
current = delta * x[j - 1];
|
2255
|
+
|
1868
2256
|
for (n = len + 3; n--; j += 2) {
|
1869
2257
|
next = delta * x[j + 1];
|
1870
2258
|
x[j] = K * x[j] - current - next;
|
2259
|
+
|
1871
2260
|
if (n--) {
|
1872
2261
|
j += 2;
|
1873
2262
|
current = delta * x[j + 1];
|
@@ -1876,11 +2265,14 @@ var JpxImage = function JpxImageClosure() {
|
|
1876
2265
|
break;
|
1877
2266
|
}
|
1878
2267
|
}
|
2268
|
+
|
1879
2269
|
j = offset - 1;
|
1880
2270
|
current = gamma * x[j - 1];
|
2271
|
+
|
1881
2272
|
for (n = len + 2; n--; j += 2) {
|
1882
2273
|
next = gamma * x[j + 1];
|
1883
2274
|
x[j] -= current + next;
|
2275
|
+
|
1884
2276
|
if (n--) {
|
1885
2277
|
j += 2;
|
1886
2278
|
current = gamma * x[j + 1];
|
@@ -1889,11 +2281,14 @@ var JpxImage = function JpxImageClosure() {
|
|
1889
2281
|
break;
|
1890
2282
|
}
|
1891
2283
|
}
|
2284
|
+
|
1892
2285
|
j = offset;
|
1893
2286
|
current = beta * x[j - 1];
|
2287
|
+
|
1894
2288
|
for (n = len + 1; n--; j += 2) {
|
1895
2289
|
next = beta * x[j + 1];
|
1896
2290
|
x[j] -= current + next;
|
2291
|
+
|
1897
2292
|
if (n--) {
|
1898
2293
|
j += 2;
|
1899
2294
|
current = beta * x[j + 1];
|
@@ -1902,12 +2297,15 @@ var JpxImage = function JpxImageClosure() {
|
|
1902
2297
|
break;
|
1903
2298
|
}
|
1904
2299
|
}
|
2300
|
+
|
1905
2301
|
if (len !== 0) {
|
1906
2302
|
j = offset + 1;
|
1907
2303
|
current = alpha * x[j - 1];
|
2304
|
+
|
1908
2305
|
for (n = len; n--; j += 2) {
|
1909
2306
|
next = alpha * x[j + 1];
|
1910
2307
|
x[j] -= current + next;
|
2308
|
+
|
1911
2309
|
if (n--) {
|
1912
2310
|
j += 2;
|
1913
2311
|
current = alpha * x[j + 1];
|
@@ -1918,26 +2316,35 @@ var JpxImage = function JpxImageClosure() {
|
|
1918
2316
|
}
|
1919
2317
|
}
|
1920
2318
|
};
|
2319
|
+
|
1921
2320
|
return IrreversibleTransform;
|
1922
2321
|
}();
|
2322
|
+
|
1923
2323
|
var ReversibleTransform = function ReversibleTransformClosure() {
|
1924
2324
|
function ReversibleTransform() {
|
1925
2325
|
Transform.call(this);
|
1926
2326
|
}
|
2327
|
+
|
1927
2328
|
ReversibleTransform.prototype = Object.create(Transform.prototype);
|
2329
|
+
|
1928
2330
|
ReversibleTransform.prototype.filter = function reversibleTransformFilter(x, offset, length) {
|
1929
2331
|
var len = length >> 1;
|
1930
2332
|
offset = offset | 0;
|
1931
2333
|
var j, n;
|
2334
|
+
|
1932
2335
|
for (j = offset, n = len + 1; n--; j += 2) {
|
1933
2336
|
x[j] -= x[j - 1] + x[j + 1] + 2 >> 2;
|
1934
2337
|
}
|
2338
|
+
|
1935
2339
|
for (j = offset + 1, n = len; n--; j += 2) {
|
1936
2340
|
x[j] += x[j - 1] + x[j + 1] >> 1;
|
1937
2341
|
}
|
1938
2342
|
};
|
2343
|
+
|
1939
2344
|
return ReversibleTransform;
|
1940
2345
|
}();
|
2346
|
+
|
1941
2347
|
return JpxImage;
|
1942
2348
|
}();
|
2349
|
+
|
1943
2350
|
exports.JpxImage = JpxImage;
|