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

@ -57,7 +57,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
isEvalSupported: true,
};
function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
function NativeImageDecoder({ xref, resources, handler,
forceDataSchema = false, }) {
this.xref = xref;
this.resources = resources;
this.handler = handler;
@ -86,8 +87,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
* Checks if the image can be decoded and displayed by the browser without any
* further processing such as color space conversions.
*/
NativeImageDecoder.isSupported =
function NativeImageDecoder_isSupported(image, xref, res) {
NativeImageDecoder.isSupported = function(image, xref, res) {
var dict = image.dict;
if (dict.has('DecodeParms') || dict.has('DP')) {
return false;
@ -99,8 +99,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
/**
* Checks if the image can be decoded by the browser.
*/
NativeImageDecoder.isDecodable =
function NativeImageDecoder_isDecodable(image, xref, res) {
NativeImageDecoder.isDecodable = function(image, xref, res) {
var dict = image.dict;
if (dict.has('DecodeParms') || dict.has('DP')) {
return false;
@ -368,11 +367,14 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var bitStrideLength = (width + 7) >> 3;
var imgArray = image.getBytes(bitStrideLength * height);
var decode = dict.getArray('Decode', 'D');
var inverseDecode = (!!decode && decode[0] > 0);
imgData = PDFImage.createMask(imgArray, width, height,
image instanceof DecodeStream,
inverseDecode);
imgData = PDFImage.createMask({
imgArray,
width,
height,
imageIsFromDecodeStream: image instanceof DecodeStream,
inverseDecode: (!!decode && decode[0] > 0),
});
imgData.cached = true;
args = [imgData];
operatorList.addOp(OPS.paintImageMaskXObject, args);
@ -392,8 +394,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// Inlining small images into the queue as RGB data
if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
(w + h) < SMALL_IMAGE_DIMENSIONS) {
var imageObj = new PDFImage(this.xref, resources, image,
inline, null, null);
let imageObj = new PDFImage({
xref: this.xref,
res: resources,
image,
});
// We force the use of RGBA_32BPP images here, because we can't handle
// any other kind.
imgData = imageObj.createImageData(/* forceRGBA = */ true);
@ -429,12 +434,21 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (nativeImageDecoderSupport === NativeImageDecoding.DECODE &&
(image instanceof JpegStream || mask instanceof JpegStream ||
softMask instanceof JpegStream)) {
nativeImageDecoder = new NativeImageDecoder(this.xref, resources,
this.handler, this.options.forceDataSchema);
nativeImageDecoder = new NativeImageDecoder({
xref: this.xref,
resources,
handler: this.handler,
forceDataSchema: this.options.forceDataSchema,
});
}
PDFImage.buildImage(this.handler, this.xref, resources, image, inline,
nativeImageDecoder).then((imageObj) => {
PDFImage.buildImage({
handler: this.handler,
xref: this.xref,
res: resources,
image,
nativeDecoder: nativeImageDecoder,
}).then((imageObj) => {
var imgData = imageObj.createImageData(/* forceRGBA = */ false);
this.handler.send('obj', [objId, this.pageIndex, 'Image', imgData],
[imgData.data.buffer]);