From 51811724986a4cf8b8cab1dc44ab756af626bc08 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 12 Sep 2018 11:30:59 +0200 Subject: [PATCH] Slightly improve the `isSourcePDF` parameter handling in `JpegImage` (PR 10031 follow-up) Currently there's only a single spot in the code-base where `JpegImage.getData` is called, however it nonetheless seem like a good idea to ensure during tests that the `isSourcePDF` parameter is correctly set. (Especially considering that the PDF use-cases will break without it.) Additionally, in `JpegImage._getLinearizedBlockData`, the code can be made a tiny bit more efficient by checking the value of `isSourcePDF` *first* to avoid useless checks (for the default PDF use-cases). --- src/core/jpg.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/jpg.js b/src/core/jpg.js index 3d97c7687..7d10b291a 100644 --- a/src/core/jpg.js +++ b/src/core/jpg.js @@ -14,7 +14,7 @@ */ /* eslint-disable no-multi-spaces */ -import { warn } from '../shared/util'; +import { assert, warn } from '../shared/util'; let JpegError = (function JpegErrorClosure() { function JpegError(msg) { @@ -1026,7 +1026,7 @@ var JpegImage = (function JpegImageClosure() { // out-of-box behaviour when `JpegImage` is used standalone, default to // inverting JPEG (CMYK) images if and only if the image data does *not* // come from a PDF file and no `decodeTransform` was passed by the user. - if (!transform && numComponents === 4 && !isSourcePDF) { + if (!isSourcePDF && numComponents === 4 && !transform) { transform = new Int32Array([ -256, 255, -256, 255, -256, 255, -256, 255]); } @@ -1180,6 +1180,10 @@ var JpegImage = (function JpegImageClosure() { }, getData({ width, height, forceRGB = false, isSourcePDF = false, }) { + if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('TESTING && !LIB')) { + assert(isSourcePDF === true, + 'JpegImage.getData: Unexpected "isSourcePDF" value for PDF files.'); + } if (this.numComponents > 4) { throw new JpegError('Unsupported color mode'); }