pdfjs-dist 2.4.456 → 2.5.207
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/bower.json +1 -1
- package/build/pdf.js +4447 -4379
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +8549 -8507
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/es5/build/pdf.js +14755 -14540
- package/es5/build/pdf.js.map +1 -1
- package/es5/build/pdf.worker.js +9830 -9469
- package/es5/build/pdf.worker.js.map +1 -1
- package/es5/web/pdf_viewer.css +5 -9
- package/es5/web/pdf_viewer.js +157 -172
- package/es5/web/pdf_viewer.js.map +1 -1
- package/image_decoders/pdf.image_decoders.js +107 -93
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +1 -1
- package/lib/README.md +2 -2
- package/lib/core/ccitt.js +7 -7
- package/lib/core/cff_parser.js +1 -1
- package/lib/core/chunked_stream.js +5 -5
- package/lib/core/cmap.js +13 -0
- package/lib/core/document.js +22 -18
- package/lib/core/evaluator.js +285 -247
- package/lib/core/font_renderer.js +7 -7
- package/lib/core/fonts.js +163 -147
- package/lib/core/function.js +4 -5
- package/lib/core/glyphlist.js +4523 -4523
- package/lib/core/image.js +19 -44
- package/lib/core/image_utils.js +123 -47
- package/lib/core/jpeg_stream.js +2 -116
- package/lib/core/jpg.js +47 -55
- package/lib/core/jpx.js +6 -6
- package/lib/core/metrics.js +2916 -2916
- package/lib/core/obj.js +18 -7
- package/lib/core/operator_list.js +5 -0
- package/lib/core/parser.js +1 -1
- package/lib/core/pdf_manager.js +2 -2
- package/lib/core/primitives.js +4 -0
- package/lib/core/standard_fonts.js +103 -103
- package/lib/core/type1_parser.js +6 -6
- package/lib/core/worker.js +31 -24
- package/lib/core/worker_stream.js +1 -1
- package/lib/display/annotation_layer.js +3 -0
- package/lib/display/api.js +29 -137
- package/lib/display/api_compatibility.js +11 -18
- package/lib/display/canvas.js +7 -34
- package/lib/display/content_disposition.js +4 -4
- package/lib/display/display_utils.js +6 -15
- package/lib/display/fetch_stream.js +3 -1
- package/lib/display/font_loader.js +2 -2
- package/lib/display/network.js +1 -1
- package/lib/display/node_stream.js +10 -8
- package/lib/display/pattern_helper.js +1 -1
- package/lib/display/svg.js +61 -31
- package/lib/display/text_layer.js +44 -32
- package/lib/display/transport_stream.js +3 -3
- package/lib/pdf.js +210 -48
- package/lib/pdf.worker.js +12 -4
- package/lib/shared/compatibility.js +2 -0
- package/lib/shared/is_node.js +1 -1
- package/lib/shared/message_handler.js +6 -6
- package/lib/shared/util.js +15 -9
- package/lib/test/unit/api_spec.js +165 -95
- package/lib/test/unit/cff_parser_spec.js +12 -12
- package/lib/test/unit/clitests_helper.js +1 -1
- package/lib/test/unit/display_svg_spec.js +1 -5
- package/lib/test/unit/jasmine-boot.js +2 -2
- package/lib/test/unit/node_stream_spec.js +5 -3
- package/lib/test/unit/parser_spec.js +3 -3
- package/lib/test/unit/test_utils.js +1 -1
- package/lib/test/unit/testreporter.js +4 -4
- package/lib/test/unit/ui_utils_spec.js +1 -55
- package/lib/test/unit/unicode_spec.js +1 -1
- package/lib/web/app.js +247 -159
- package/lib/web/app_options.js +16 -10
- package/lib/web/base_viewer.js +14 -6
- package/lib/web/download_manager.js +3 -1
- package/lib/web/firefox_print_service.js +1 -1
- package/lib/web/firefoxcom.js +16 -4
- package/lib/web/pdf_attachment_viewer.js +14 -7
- package/lib/web/pdf_document_properties.js +11 -16
- package/lib/web/pdf_find_bar.js +3 -3
- package/lib/web/pdf_find_controller.js +3 -3
- package/lib/web/pdf_history.js +7 -5
- package/lib/web/pdf_link_service.js +7 -8
- package/lib/web/pdf_page_view.js +1 -1
- package/lib/web/pdf_presentation_mode.js +6 -2
- package/lib/web/pdf_print_service.js +1 -1
- package/lib/web/pdf_single_page_viewer.js +2 -2
- package/lib/web/pdf_viewer.component.js +2 -2
- package/lib/web/pdf_viewer.js +2 -2
- package/lib/web/preferences.js +4 -1
- package/lib/web/text_layer_builder.js +1 -3
- package/lib/web/ui_utils.js +3 -55
- package/lib/web/view_history.js +8 -9
- package/lib/web/viewer_compatibility.js +14 -1
- package/package.json +1 -1
- package/web/pdf_viewer.css +5 -9
- package/web/pdf_viewer.js +97 -127
- package/web/pdf_viewer.js.map +1 -1
package/lib/core/image.js
CHANGED
@@ -39,17 +39,6 @@ var _jpeg_stream = require("./jpeg_stream.js");
|
|
39
39
|
var _jpx = require("./jpx.js");
|
40
40
|
|
41
41
|
var PDFImage = function PDFImageClosure() {
|
42
|
-
function handleImageData(image, nativeDecoder) {
|
43
|
-
if (nativeDecoder && nativeDecoder.canDecode(image)) {
|
44
|
-
return nativeDecoder.decode(image).catch(reason => {
|
45
|
-
(0, _util.warn)("Native image decoding failed -- trying to recover: " + (reason && reason.message));
|
46
|
-
return image;
|
47
|
-
});
|
48
|
-
}
|
49
|
-
|
50
|
-
return Promise.resolve(image);
|
51
|
-
}
|
52
|
-
|
53
42
|
function decodeAndClamp(value, addend, coefficient, max) {
|
54
43
|
value = addend + value * coefficient;
|
55
44
|
|
@@ -246,51 +235,37 @@ var PDFImage = function PDFImageClosure() {
|
|
246
235
|
}
|
247
236
|
|
248
237
|
PDFImage.buildImage = function ({
|
249
|
-
handler,
|
250
238
|
xref,
|
251
239
|
res,
|
252
240
|
image,
|
253
241
|
isInline = false,
|
254
|
-
nativeDecoder = null,
|
255
242
|
pdfFunctionFactory
|
256
243
|
}) {
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
244
|
+
const imageData = image;
|
245
|
+
let smaskData = null;
|
246
|
+
let maskData = null;
|
247
|
+
const smask = image.dict.get("SMask");
|
248
|
+
const mask = image.dict.get("Mask");
|
262
249
|
|
263
250
|
if (smask) {
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
if (mask) {
|
270
|
-
if ((0, _primitives.isStream)(mask)) {
|
271
|
-
maskPromise = handleImageData(mask, nativeDecoder);
|
272
|
-
} else if (Array.isArray(mask)) {
|
273
|
-
maskPromise = Promise.resolve(mask);
|
274
|
-
} else {
|
275
|
-
(0, _util.warn)("Unsupported mask format.");
|
276
|
-
maskPromise = Promise.resolve(null);
|
277
|
-
}
|
251
|
+
smaskData = smask;
|
252
|
+
} else if (mask) {
|
253
|
+
if ((0, _primitives.isStream)(mask) || Array.isArray(mask)) {
|
254
|
+
maskData = mask;
|
278
255
|
} else {
|
279
|
-
|
256
|
+
(0, _util.warn)("Unsupported mask format.");
|
280
257
|
}
|
281
258
|
}
|
282
259
|
|
283
|
-
return Promise.
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
});
|
293
|
-
});
|
260
|
+
return Promise.resolve(new PDFImage({
|
261
|
+
xref,
|
262
|
+
res,
|
263
|
+
image: imageData,
|
264
|
+
isInline,
|
265
|
+
smask: smaskData,
|
266
|
+
mask: maskData,
|
267
|
+
pdfFunctionFactory
|
268
|
+
}));
|
294
269
|
};
|
295
270
|
|
296
271
|
PDFImage.createMask = function ({
|
package/lib/core/image_utils.js
CHANGED
@@ -24,71 +24,147 @@
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.
|
28
|
-
|
29
|
-
var
|
30
|
-
|
31
|
-
var
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
resources,
|
39
|
-
handler,
|
40
|
-
forceDataSchema = false,
|
41
|
-
pdfFunctionFactory
|
42
|
-
}) {
|
43
|
-
this.xref = xref;
|
44
|
-
this.resources = resources;
|
45
|
-
this.handler = handler;
|
46
|
-
this.forceDataSchema = forceDataSchema;
|
47
|
-
this.pdfFunctionFactory = pdfFunctionFactory;
|
27
|
+
exports.GlobalImageCache = exports.LocalImageCache = void 0;
|
28
|
+
|
29
|
+
var _util = require("../shared/util.js");
|
30
|
+
|
31
|
+
var _primitives = require("./primitives.js");
|
32
|
+
|
33
|
+
class LocalImageCache {
|
34
|
+
constructor() {
|
35
|
+
this._nameRefMap = new Map();
|
36
|
+
this._imageMap = new Map();
|
37
|
+
this._imageCache = new _primitives.RefSetCache();
|
48
38
|
}
|
49
39
|
|
50
|
-
|
51
|
-
|
40
|
+
getByName(name) {
|
41
|
+
const ref = this._nameRefMap.get(name);
|
42
|
+
|
43
|
+
if (ref) {
|
44
|
+
return this.getByRef(ref);
|
45
|
+
}
|
46
|
+
|
47
|
+
return this._imageMap.get(name) || null;
|
52
48
|
}
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
let colorSpace = dict.get("ColorSpace", "CS");
|
57
|
-
colorSpace = _colorspace.ColorSpace.parse(colorSpace, this.xref, this.resources, this.pdfFunctionFactory);
|
58
|
-
return this.handler.sendWithPromise("JpegDecode", [image.getIR(this.forceDataSchema), colorSpace.numComps]).then(function ({
|
59
|
-
data,
|
60
|
-
width,
|
61
|
-
height
|
62
|
-
}) {
|
63
|
-
return new _stream.Stream(data, 0, data.length, dict);
|
64
|
-
});
|
50
|
+
getByRef(ref) {
|
51
|
+
return this._imageCache.get(ref) || null;
|
65
52
|
}
|
66
53
|
|
67
|
-
|
68
|
-
|
54
|
+
set(name, ref = null, data) {
|
55
|
+
if (!name) {
|
56
|
+
throw new Error('LocalImageCache.set - expected "name" argument.');
|
57
|
+
}
|
69
58
|
|
70
|
-
if (
|
71
|
-
|
59
|
+
if (ref) {
|
60
|
+
if (this._imageCache.has(ref)) {
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
|
64
|
+
this._nameRefMap.set(name, ref);
|
65
|
+
|
66
|
+
this._imageCache.put(ref, data);
|
67
|
+
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
|
71
|
+
if (this._imageMap.has(name)) {
|
72
|
+
return;
|
72
73
|
}
|
73
74
|
|
74
|
-
|
75
|
+
this._imageMap.set(name, data);
|
76
|
+
}
|
77
|
+
|
78
|
+
}
|
79
|
+
|
80
|
+
exports.LocalImageCache = LocalImageCache;
|
75
81
|
|
76
|
-
|
82
|
+
class GlobalImageCache {
|
83
|
+
static get NUM_PAGES_THRESHOLD() {
|
84
|
+
return (0, _util.shadow)(this, "NUM_PAGES_THRESHOLD", 2);
|
77
85
|
}
|
78
86
|
|
79
|
-
static
|
80
|
-
|
87
|
+
static get MAX_IMAGES_TO_CACHE() {
|
88
|
+
return (0, _util.shadow)(this, "MAX_IMAGES_TO_CACHE", 10);
|
89
|
+
}
|
90
|
+
|
91
|
+
constructor() {
|
92
|
+
this._refCache = new _primitives.RefSetCache();
|
93
|
+
this._imageCache = new _primitives.RefSetCache();
|
94
|
+
}
|
81
95
|
|
82
|
-
|
96
|
+
shouldCache(ref, pageIndex) {
|
97
|
+
const pageIndexSet = this._refCache.get(ref);
|
98
|
+
|
99
|
+
const numPages = pageIndexSet ? pageIndexSet.size + (pageIndexSet.has(pageIndex) ? 0 : 1) : 1;
|
100
|
+
|
101
|
+
if (numPages < GlobalImageCache.NUM_PAGES_THRESHOLD) {
|
102
|
+
return false;
|
103
|
+
}
|
104
|
+
|
105
|
+
if (!this._imageCache.has(ref) && this._imageCache.size >= GlobalImageCache.MAX_IMAGES_TO_CACHE) {
|
83
106
|
return false;
|
84
107
|
}
|
85
108
|
|
86
|
-
|
109
|
+
return true;
|
110
|
+
}
|
111
|
+
|
112
|
+
addPageIndex(ref, pageIndex) {
|
113
|
+
let pageIndexSet = this._refCache.get(ref);
|
114
|
+
|
115
|
+
if (!pageIndexSet) {
|
116
|
+
pageIndexSet = new Set();
|
117
|
+
|
118
|
+
this._refCache.put(ref, pageIndexSet);
|
119
|
+
}
|
120
|
+
|
121
|
+
pageIndexSet.add(pageIndex);
|
122
|
+
}
|
123
|
+
|
124
|
+
getData(ref, pageIndex) {
|
125
|
+
if (!this._refCache.has(ref)) {
|
126
|
+
return null;
|
127
|
+
}
|
128
|
+
|
129
|
+
const pageIndexSet = this._refCache.get(ref);
|
130
|
+
|
131
|
+
if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) {
|
132
|
+
return null;
|
133
|
+
}
|
134
|
+
|
135
|
+
if (!this._imageCache.has(ref)) {
|
136
|
+
return null;
|
137
|
+
}
|
138
|
+
|
139
|
+
pageIndexSet.add(pageIndex);
|
140
|
+
return this._imageCache.get(ref);
|
141
|
+
}
|
142
|
+
|
143
|
+
setData(ref, data) {
|
144
|
+
if (!this._refCache.has(ref)) {
|
145
|
+
throw new Error('GlobalImageCache.setData - expected "addPageIndex" to have been called.');
|
146
|
+
}
|
147
|
+
|
148
|
+
if (this._imageCache.has(ref)) {
|
149
|
+
return;
|
150
|
+
}
|
151
|
+
|
152
|
+
if (this._imageCache.size >= GlobalImageCache.MAX_IMAGES_TO_CACHE) {
|
153
|
+
(0, _util.info)("GlobalImageCache.setData - ignoring image above MAX_IMAGES_TO_CACHE.");
|
154
|
+
return;
|
155
|
+
}
|
156
|
+
|
157
|
+
this._imageCache.put(ref, data);
|
158
|
+
}
|
159
|
+
|
160
|
+
clear(onlyData = false) {
|
161
|
+
if (!onlyData) {
|
162
|
+
this._refCache.clear();
|
163
|
+
}
|
87
164
|
|
88
|
-
|
89
|
-
return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray("Decode", "D"), bpc);
|
165
|
+
this._imageCache.clear();
|
90
166
|
}
|
91
167
|
|
92
168
|
}
|
93
169
|
|
94
|
-
exports.
|
170
|
+
exports.GlobalImageCache = GlobalImageCache;
|
package/lib/core/jpeg_stream.js
CHANGED
@@ -26,14 +26,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
26
26
|
});
|
27
27
|
exports.JpegStream = void 0;
|
28
28
|
|
29
|
-
var _util = require("../shared/util.js");
|
30
|
-
|
31
29
|
var _stream = require("./stream.js");
|
32
30
|
|
33
31
|
var _primitives = require("./primitives.js");
|
34
32
|
|
35
33
|
var _jpg = require("./jpg.js");
|
36
34
|
|
35
|
+
var _util = require("../shared/util.js");
|
36
|
+
|
37
37
|
const JpegStream = function JpegStreamClosure() {
|
38
38
|
function JpegStream(stream, maybeLength, dict, params) {
|
39
39
|
let ch;
|
@@ -116,120 +116,6 @@ const JpegStream = function JpegStreamClosure() {
|
|
116
116
|
this.eof = true;
|
117
117
|
};
|
118
118
|
|
119
|
-
Object.defineProperty(JpegStream.prototype, "maybeValidDimensions", {
|
120
|
-
get: function JpegStream_maybeValidDimensions() {
|
121
|
-
const {
|
122
|
-
dict,
|
123
|
-
stream
|
124
|
-
} = this;
|
125
|
-
const dictHeight = dict.get("Height", "H");
|
126
|
-
const startPos = stream.pos;
|
127
|
-
let validDimensions = true,
|
128
|
-
foundSOF = false,
|
129
|
-
b;
|
130
|
-
|
131
|
-
while ((b = stream.getByte()) !== -1) {
|
132
|
-
if (b !== 0xff) {
|
133
|
-
continue;
|
134
|
-
}
|
135
|
-
|
136
|
-
switch (stream.getByte()) {
|
137
|
-
case 0xc0:
|
138
|
-
case 0xc1:
|
139
|
-
case 0xc2:
|
140
|
-
foundSOF = true;
|
141
|
-
stream.pos += 2;
|
142
|
-
stream.pos += 1;
|
143
|
-
const scanLines = stream.getUint16();
|
144
|
-
|
145
|
-
if (scanLines === dictHeight) {
|
146
|
-
break;
|
147
|
-
}
|
148
|
-
|
149
|
-
if (scanLines === 0) {
|
150
|
-
validDimensions = false;
|
151
|
-
break;
|
152
|
-
}
|
153
|
-
|
154
|
-
if (scanLines > dictHeight * 10) {
|
155
|
-
validDimensions = false;
|
156
|
-
break;
|
157
|
-
}
|
158
|
-
|
159
|
-
break;
|
160
|
-
|
161
|
-
case 0xc3:
|
162
|
-
case 0xc5:
|
163
|
-
case 0xc6:
|
164
|
-
case 0xc7:
|
165
|
-
case 0xc9:
|
166
|
-
case 0xca:
|
167
|
-
case 0xcb:
|
168
|
-
case 0xcd:
|
169
|
-
case 0xce:
|
170
|
-
case 0xcf:
|
171
|
-
foundSOF = true;
|
172
|
-
break;
|
173
|
-
|
174
|
-
case 0xc4:
|
175
|
-
case 0xcc:
|
176
|
-
case 0xda:
|
177
|
-
case 0xdb:
|
178
|
-
case 0xdc:
|
179
|
-
case 0xdd:
|
180
|
-
case 0xde:
|
181
|
-
case 0xdf:
|
182
|
-
case 0xe0:
|
183
|
-
case 0xe1:
|
184
|
-
case 0xe2:
|
185
|
-
case 0xe3:
|
186
|
-
case 0xe4:
|
187
|
-
case 0xe5:
|
188
|
-
case 0xe6:
|
189
|
-
case 0xe7:
|
190
|
-
case 0xe8:
|
191
|
-
case 0xe9:
|
192
|
-
case 0xea:
|
193
|
-
case 0xeb:
|
194
|
-
case 0xec:
|
195
|
-
case 0xed:
|
196
|
-
case 0xee:
|
197
|
-
case 0xef:
|
198
|
-
case 0xfe:
|
199
|
-
const markerLength = stream.getUint16();
|
200
|
-
|
201
|
-
if (markerLength > 2) {
|
202
|
-
stream.skip(markerLength - 2);
|
203
|
-
} else {
|
204
|
-
stream.skip(-2);
|
205
|
-
}
|
206
|
-
|
207
|
-
break;
|
208
|
-
|
209
|
-
case 0xff:
|
210
|
-
stream.skip(-1);
|
211
|
-
break;
|
212
|
-
|
213
|
-
case 0xd9:
|
214
|
-
foundSOF = true;
|
215
|
-
break;
|
216
|
-
}
|
217
|
-
|
218
|
-
if (foundSOF) {
|
219
|
-
break;
|
220
|
-
}
|
221
|
-
}
|
222
|
-
|
223
|
-
stream.pos = startPos;
|
224
|
-
return (0, _util.shadow)(this, "maybeValidDimensions", validDimensions);
|
225
|
-
},
|
226
|
-
configurable: true
|
227
|
-
});
|
228
|
-
|
229
|
-
JpegStream.prototype.getIR = function (forceDataSchema = false) {
|
230
|
-
return (0, _util.createObjectURL)(this.bytes, "image/jpeg", forceDataSchema);
|
231
|
-
};
|
232
|
-
|
233
119
|
return JpegStream;
|
234
120
|
}();
|
235
121
|
|
package/lib/core/jpg.js
CHANGED
@@ -128,8 +128,8 @@ var JpegImage = function JpegImageClosure() {
|
|
128
128
|
function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive, parseDNLMarker = false) {
|
129
129
|
var mcusPerLine = frame.mcusPerLine;
|
130
130
|
var progressive = frame.progressive;
|
131
|
-
|
132
|
-
|
131
|
+
const startOffset = offset;
|
132
|
+
let bitsData = 0,
|
133
133
|
bitsCount = 0;
|
134
134
|
|
135
135
|
function readBit() {
|
@@ -215,10 +215,10 @@ var JpegImage = function JpegImageClosure() {
|
|
215
215
|
return n + (-1 << length) + 1;
|
216
216
|
}
|
217
217
|
|
218
|
-
function decodeBaseline(component,
|
218
|
+
function decodeBaseline(component, blockOffset) {
|
219
219
|
var t = decodeHuffman(component.huffmanTableDC);
|
220
220
|
var diff = t === 0 ? 0 : receiveAndExtend(t);
|
221
|
-
component.blockData[
|
221
|
+
component.blockData[blockOffset] = component.pred += diff;
|
222
222
|
var k = 1;
|
223
223
|
|
224
224
|
while (k < 64) {
|
@@ -237,24 +237,24 @@ var JpegImage = function JpegImageClosure() {
|
|
237
237
|
|
238
238
|
k += r;
|
239
239
|
var z = dctZigZag[k];
|
240
|
-
component.blockData[
|
240
|
+
component.blockData[blockOffset + z] = receiveAndExtend(s);
|
241
241
|
k++;
|
242
242
|
}
|
243
243
|
}
|
244
244
|
|
245
|
-
function decodeDCFirst(component,
|
245
|
+
function decodeDCFirst(component, blockOffset) {
|
246
246
|
var t = decodeHuffman(component.huffmanTableDC);
|
247
247
|
var diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
|
248
|
-
component.blockData[
|
248
|
+
component.blockData[blockOffset] = component.pred += diff;
|
249
249
|
}
|
250
250
|
|
251
|
-
function decodeDCSuccessive(component,
|
252
|
-
component.blockData[
|
251
|
+
function decodeDCSuccessive(component, blockOffset) {
|
252
|
+
component.blockData[blockOffset] |= readBit() << successive;
|
253
253
|
}
|
254
254
|
|
255
255
|
var eobrun = 0;
|
256
256
|
|
257
|
-
function decodeACFirst(component,
|
257
|
+
function decodeACFirst(component, blockOffset) {
|
258
258
|
if (eobrun > 0) {
|
259
259
|
eobrun--;
|
260
260
|
return;
|
@@ -280,7 +280,7 @@ var JpegImage = function JpegImageClosure() {
|
|
280
280
|
|
281
281
|
k += r;
|
282
282
|
var z = dctZigZag[k];
|
283
|
-
component.blockData[
|
283
|
+
component.blockData[blockOffset + z] = receiveAndExtend(s) * (1 << successive);
|
284
284
|
k++;
|
285
285
|
}
|
286
286
|
}
|
@@ -288,7 +288,7 @@ var JpegImage = function JpegImageClosure() {
|
|
288
288
|
var successiveACState = 0,
|
289
289
|
successiveACNextValue;
|
290
290
|
|
291
|
-
function decodeACSuccessive(component,
|
291
|
+
function decodeACSuccessive(component, blockOffset) {
|
292
292
|
var k = spectralStart;
|
293
293
|
var e = spectralEnd;
|
294
294
|
var r = 0;
|
@@ -296,7 +296,7 @@ var JpegImage = function JpegImageClosure() {
|
|
296
296
|
var rs;
|
297
297
|
|
298
298
|
while (k <= e) {
|
299
|
-
const offsetZ =
|
299
|
+
const offsetZ = blockOffset + dctZigZag[k];
|
300
300
|
const sign = component.blockData[offsetZ] < 0 ? -1 : 1;
|
301
301
|
|
302
302
|
switch (successiveACState) {
|
@@ -375,15 +375,15 @@ var JpegImage = function JpegImageClosure() {
|
|
375
375
|
var mcuCol = mcu % mcusPerLine;
|
376
376
|
blockRow = mcuRow * component.v + row;
|
377
377
|
var blockCol = mcuCol * component.h + col;
|
378
|
-
|
379
|
-
decode(component,
|
378
|
+
const blockOffset = getBlockBufferOffset(component, blockRow, blockCol);
|
379
|
+
decode(component, blockOffset);
|
380
380
|
}
|
381
381
|
|
382
382
|
function decodeBlock(component, decode, mcu) {
|
383
383
|
blockRow = mcu / component.blocksPerLine | 0;
|
384
384
|
var blockCol = mcu % component.blocksPerLine;
|
385
|
-
|
386
|
-
decode(component,
|
385
|
+
const blockOffset = getBlockBufferOffset(component, blockRow, blockCol);
|
386
|
+
decode(component, blockOffset);
|
387
387
|
}
|
388
388
|
|
389
389
|
var componentsLength = components.length;
|
@@ -412,37 +412,39 @@ var JpegImage = function JpegImageClosure() {
|
|
412
412
|
|
413
413
|
var h, v;
|
414
414
|
|
415
|
-
while (mcu
|
415
|
+
while (mcu <= mcuExpected) {
|
416
416
|
var mcuToRead = resetInterval ? Math.min(mcuExpected - mcu, resetInterval) : mcuExpected;
|
417
417
|
|
418
|
-
|
419
|
-
|
420
|
-
|
418
|
+
if (mcuToRead > 0) {
|
419
|
+
for (i = 0; i < componentsLength; i++) {
|
420
|
+
components[i].pred = 0;
|
421
|
+
}
|
421
422
|
|
422
|
-
|
423
|
+
eobrun = 0;
|
423
424
|
|
424
|
-
|
425
|
-
|
425
|
+
if (componentsLength === 1) {
|
426
|
+
component = components[0];
|
426
427
|
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
428
|
+
for (n = 0; n < mcuToRead; n++) {
|
429
|
+
decodeBlock(component, decodeFn, mcu);
|
430
|
+
mcu++;
|
431
|
+
}
|
432
|
+
} else {
|
433
|
+
for (n = 0; n < mcuToRead; n++) {
|
434
|
+
for (i = 0; i < componentsLength; i++) {
|
435
|
+
component = components[i];
|
436
|
+
h = component.h;
|
437
|
+
v = component.v;
|
438
|
+
|
439
|
+
for (j = 0; j < v; j++) {
|
440
|
+
for (k = 0; k < h; k++) {
|
441
|
+
decodeMcu(component, decodeFn, mcu, j, k);
|
442
|
+
}
|
441
443
|
}
|
442
444
|
}
|
443
|
-
}
|
444
445
|
|
445
|
-
|
446
|
+
mcu++;
|
447
|
+
}
|
446
448
|
}
|
447
449
|
}
|
448
450
|
|
@@ -451,31 +453,21 @@ var JpegImage = function JpegImageClosure() {
|
|
451
453
|
|
452
454
|
if (!fileMarker) {
|
453
455
|
break;
|
454
|
-
} else if (fileMarker.invalid) {
|
455
|
-
(0, _util.warn)("decodeScan - unexpected MCU data, current marker is: " + fileMarker.invalid);
|
456
|
-
offset = fileMarker.offset;
|
457
456
|
}
|
458
457
|
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
458
|
+
if (fileMarker.invalid) {
|
459
|
+
const partialMsg = mcuToRead > 0 ? "unexpected" : "excessive";
|
460
|
+
(0, _util.warn)(`decodeScan - ${partialMsg} MCU data, current marker is: ${fileMarker.invalid}`);
|
461
|
+
offset = fileMarker.offset;
|
463
462
|
}
|
464
463
|
|
465
|
-
if (marker >= 0xffd0 && marker <= 0xffd7) {
|
464
|
+
if (fileMarker.marker >= 0xffd0 && fileMarker.marker <= 0xffd7) {
|
466
465
|
offset += 2;
|
467
466
|
} else {
|
468
467
|
break;
|
469
468
|
}
|
470
469
|
}
|
471
470
|
|
472
|
-
fileMarker = findNextFileMarker(data, offset);
|
473
|
-
|
474
|
-
if (fileMarker && fileMarker.invalid) {
|
475
|
-
(0, _util.warn)("decodeScan - unexpected Scan data, current marker is: " + fileMarker.invalid);
|
476
|
-
offset = fileMarker.offset;
|
477
|
-
}
|
478
|
-
|
479
471
|
return offset - startOffset;
|
480
472
|
}
|
481
473
|
|
package/lib/core/jpx.js
CHANGED
@@ -785,7 +785,7 @@ var JpxImage = function JpxImageClosure() {
|
|
785
785
|
var maxDecompositionLevelsCount = 0;
|
786
786
|
|
787
787
|
for (c = 0; c < componentsCount; c++) {
|
788
|
-
|
788
|
+
const component = tile.components[c];
|
789
789
|
maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
|
790
790
|
}
|
791
791
|
|
@@ -814,7 +814,7 @@ var JpxImage = function JpxImageClosure() {
|
|
814
814
|
for (; r <= maxDecompositionLevelsCount; r++) {
|
815
815
|
for (; p < maxNumPrecinctsInLevel[r]; p++) {
|
816
816
|
for (; c < componentsCount; c++) {
|
817
|
-
|
817
|
+
const component = tile.components[c];
|
818
818
|
|
819
819
|
if (r > component.codingStyleParameters.decompositionLevelsCount) {
|
820
820
|
continue;
|
@@ -1233,13 +1233,13 @@ var JpxImage = function JpxImageClosure() {
|
|
1233
1233
|
var firstTimeInclusion = false;
|
1234
1234
|
var valueReady;
|
1235
1235
|
|
1236
|
-
if (codeblock
|
1236
|
+
if (codeblock.included !== undefined) {
|
1237
1237
|
codeblockIncluded = !!readBits(1);
|
1238
1238
|
} else {
|
1239
1239
|
precinct = codeblock.precinct;
|
1240
1240
|
var inclusionTree, zeroBitPlanesTree;
|
1241
1241
|
|
1242
|
-
if (precinct
|
1242
|
+
if (precinct.inclusionTree !== undefined) {
|
1243
1243
|
inclusionTree = precinct.inclusionTree;
|
1244
1244
|
} else {
|
1245
1245
|
var width = precinct.cbxMax - precinct.cbxMin + 1;
|
@@ -1317,7 +1317,7 @@ var JpxImage = function JpxImageClosure() {
|
|
1317
1317
|
var packetItem = queue.shift();
|
1318
1318
|
codeblock = packetItem.codeblock;
|
1319
1319
|
|
1320
|
-
if (codeblock
|
1320
|
+
if (codeblock.data === undefined) {
|
1321
1321
|
codeblock.data = [];
|
1322
1322
|
}
|
1323
1323
|
|
@@ -1351,7 +1351,7 @@ var JpxImage = function JpxImageClosure() {
|
|
1351
1351
|
continue;
|
1352
1352
|
}
|
1353
1353
|
|
1354
|
-
if (codeblock
|
1354
|
+
if (codeblock.data === undefined) {
|
1355
1355
|
continue;
|
1356
1356
|
}
|
1357
1357
|
|