1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

Remove the unused inline parameter from various methods/functions in PDFImage, and change a couple of methods to use Objects rather than plain parameters

The `inline` parameter is passed to a number of methods/functions in `PDFImage`, despite not actually being used. Its value is never checked, nor is it ever assigned to the current `PDFImage` instance (i.e. no `this.inline = inline` exists).
Looking briefly at the history of this code, I was also unable to find a point in time where `inline` was being used.

As far as I'm concerned, `inline` does nothing more than add clutter to already very unwieldy method/function signatures, hence why I'm proposing that we just remove it.
To further simplify call-sites using `PDFImage`/`NativeImageDecoder`, a number of methods/functions are changed to take Objects rather than a bunch of (somewhat) randomly ordered parameters.
This commit is contained in:
Jonas Jenwald 2017-09-21 12:14:05 +02:00
parent f206ee56bf
commit 5c961c76bb
2 changed files with 61 additions and 39 deletions

View file

@ -74,7 +74,8 @@ var PDFImage = (function PDFImageClosure() {
return dest;
}
function PDFImage(xref, res, image, inline, smask, mask, isMask) {
function PDFImage({ xref, res, image, smask = null, mask = null,
isMask = false, }) {
this.image = image;
var dict = image.dict;
if (dict.has('Filter')) {
@ -160,14 +161,23 @@ var PDFImage = (function PDFImageClosure() {
}
if (smask) {
this.smask = new PDFImage(xref, res, smask, false);
this.smask = new PDFImage({
xref,
res,
image: smask,
});
} else if (mask) {
if (isStream(mask)) {
var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
if (!imageMask) {
warn('Ignoring /Mask in image without /ImageMask.');
} else {
this.mask = new PDFImage(xref, res, mask, false, null, null, true);
this.mask = new PDFImage({
xref,
res,
image: mask,
isMask: true,
});
}
} else {
// Color key mask (just an array).
@ -179,9 +189,8 @@ var PDFImage = (function PDFImageClosure() {
* Handles processing of image data and returns the Promise that is resolved
* with a PDFImage when the image is ready to be used.
*/
PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
res, image, inline,
nativeDecoder) {
PDFImage.buildImage = function({ handler, xref, res, image,
nativeDecoder = null, }) {
var imagePromise = handleImageData(image, nativeDecoder);
var smaskPromise;
var maskPromise;
@ -208,17 +217,19 @@ var PDFImage = (function PDFImageClosure() {
}
}
return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
function(results) {
var imageData = results[0];
var smaskData = results[1];
var maskData = results[2];
return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
function([imageData, smaskData, maskData]) {
return new PDFImage({
xref,
res,
image: imageData,
smask: smaskData,
mask: maskData,
});
});
};
PDFImage.createMask =
function PDFImage_createMask(imgArray, width, height,
imageIsFromDecodeStream, inverseDecode) {
PDFImage.createMask = function({ imgArray, width, height,
imageIsFromDecodeStream, inverseDecode, }) {
// |imgArray| might not contain full data for every pixel of the mask, so
// we need to distinguish between |computedLength| and |actualLength|.
@ -271,7 +282,7 @@ var PDFImage = (function PDFImageClosure() {
this.mask && this.mask.height || 0);
},
decodeBuffer: function PDFImage_decodeBuffer(buffer) {
decodeBuffer(buffer) {
var bpc = this.bpc;
var numComps = this.numComps;
@ -297,7 +308,7 @@ var PDFImage = (function PDFImageClosure() {
}
},
getComponents: function PDFImage_getComponents(buffer) {
getComponents(buffer) {
var bpc = this.bpc;
// This image doesn't require any extra work.
@ -374,8 +385,7 @@ var PDFImage = (function PDFImageClosure() {
return output;
},
fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
actualHeight, image) {
fillOpacity(rgbaBuf, width, height, actualHeight, image) {
var smask = this.smask;
var mask = this.mask;
var alphaBuf, sw, sh, i, ii, j;
@ -441,7 +451,7 @@ var PDFImage = (function PDFImageClosure() {
}
},
undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
undoPreblend(buffer, width, height) {
var matte = this.smask && this.smask.matte;
if (!matte) {
return;
@ -472,7 +482,7 @@ var PDFImage = (function PDFImageClosure() {
}
},
createImageData: function PDFImage_createImageData(forceRGBA) {
createImageData(forceRGBA = false) {
var drawWidth = this.drawWidth;
var drawHeight = this.drawHeight;
var imgData = { // other fields are filled in below
@ -581,7 +591,7 @@ var PDFImage = (function PDFImageClosure() {
return imgData;
},
fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
fillGrayBuffer(buffer) {
var numComps = this.numComps;
if (numComps !== 1) {
throw new FormatError(
@ -627,9 +637,7 @@ var PDFImage = (function PDFImageClosure() {
}
},
getImageBytes: function PDFImage_getImageBytes(length,
drawWidth, drawHeight,
forceRGB) {
getImageBytes(length, drawWidth, drawHeight, forceRGB = false) {
this.image.reset();
this.image.drawWidth = drawWidth || this.width;
this.image.drawHeight = drawHeight || this.height;