mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
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:
commit
7bb066494f
7 changed files with 154 additions and 63 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue