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