Merge pull request #9427 from Snuffleupagus/native-JPEG-decoding-fallback

Fallback to the built-in JPEG decoder when browser decoding fails, and attempt to handle JPEG images with DNL (Define Number of Lines) markers (issue 8614)
This commit is contained in:
Tim van der Meij 2018-02-09 21:36:08 +01:00 committed by GitHub
commit 7bb066494f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 154 additions and 63 deletions

View file

@ -16,10 +16,9 @@
import {
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
isArrayBuffer, isSameOrigin, loadJpegStream, MessageHandler,
MissingPDFException, NativeImageDecoding, PageViewport, PasswordException,
stringToBytes, UnexpectedResponseException, UnknownErrorException,
unreachable, Util, warn
isArrayBuffer, isSameOrigin, MessageHandler, MissingPDFException,
NativeImageDecoding, PageViewport, PasswordException, stringToBytes,
UnexpectedResponseException, UnknownErrorException, unreachable, Util, warn
} from '../shared/util';
import {
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, getDefaultSetting,
@ -1818,8 +1817,22 @@ var WorkerTransport = (function WorkerTransportClosure() {
switch (type) {
case 'JpegStream':
imageData = data[3];
loadJpegStream(id, imageData, pageProxy.objs);
break;
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = function() {
resolve(img);
};
img.onerror = function() {
reject(new Error('Error during JPEG image loading'));
// Note that when the browser image loading/decoding fails,
// we'll fallback to the built-in PDF.js JPEG decoder; see
// `PartialEvaluator.buildPaintImageXObject` in the
// `src/core/evaluator.js` file.
};
img.src = imageData;
}).then((img) => {
pageProxy.objs.resolve(id, img);
});
case 'Image':
imageData = data[3];
pageProxy.objs.resolve(id, imageData);