Merge pull request #12059 from Snuffleupagus/image-class

Convert the code in `src/core/image.js` to use ES6 classes
This commit is contained in:
Tim van der Meij 2020-07-05 14:08:55 +02:00 committed by GitHub
commit c4255fdbfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,7 +20,6 @@ import { DecodeStream } from "./stream.js";
import { JpegStream } from "./jpeg_stream.js";
import { JpxImage } from "./jpx.js";
var PDFImage = (function PDFImageClosure() {
/**
* Decode and clamp a value. The formula is different from the spec because we
* don't decode to float range [0,1], we decode it in the [0,max] range.
@ -79,8 +78,8 @@ var PDFImage = (function PDFImageClosure() {
return dest;
}
// eslint-disable-next-line no-shadow
function PDFImage({
class PDFImage {
constructor({
xref,
res,
image,
@ -247,11 +246,12 @@ 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 = async function ({
static async buildImage({
xref,
res,
image,
@ -286,9 +286,9 @@ var PDFImage = (function PDFImageClosure() {
pdfFunctionFactory,
localColorSpaceCache,
});
};
}
PDFImage.createMask = function ({
static createMask({
imgArray,
width,
height,
@ -340,16 +340,15 @@ var PDFImage = (function PDFImageClosure() {
}
return { data, width, height };
};
}
PDFImage.prototype = {
get drawWidth() {
return Math.max(
this.width,
(this.smask && this.smask.width) || 0,
(this.mask && this.mask.width) || 0
);
},
}
get drawHeight() {
return Math.max(
@ -357,7 +356,7 @@ var PDFImage = (function PDFImageClosure() {
(this.smask && this.smask.height) || 0,
(this.mask && this.mask.height) || 0
);
},
}
decodeBuffer(buffer) {
var bpc = this.bpc;
@ -387,7 +386,7 @@ var PDFImage = (function PDFImageClosure() {
index++;
}
}
},
}
getComponents(buffer) {
var bpc = this.bpc;
@ -477,7 +476,7 @@ var PDFImage = (function PDFImageClosure() {
}
}
return output;
},
}
fillOpacity(rgbaBuf, width, height, actualHeight, image) {
if (
@ -499,14 +498,7 @@ var PDFImage = (function PDFImageClosure() {
alphaBuf = new Uint8ClampedArray(sw * sh);
smask.fillGrayBuffer(alphaBuf);
if (sw !== width || sh !== height) {
alphaBuf = resizeImageMask(
alphaBuf,
smask.bpc,
sw,
sh,
width,
height
);
alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
}
} else if (mask) {
if (mask instanceof PDFImage) {
@ -522,14 +514,7 @@ var PDFImage = (function PDFImageClosure() {
}
if (sw !== width || sh !== height) {
alphaBuf = resizeImageMask(
alphaBuf,
mask.bpc,
sw,
sh,
width,
height
);
alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
}
} else if (Array.isArray(mask)) {
// Color key mask: if any of the components are outside the range
@ -564,7 +549,7 @@ var PDFImage = (function PDFImageClosure() {
rgbaBuf[j] = 255;
}
}
},
}
undoPreblend(buffer, width, height) {
if (
@ -600,7 +585,7 @@ var PDFImage = (function PDFImageClosure() {
buffer[i + 1] = (buffer[i + 1] - matteG) * k + matteG;
buffer[i + 2] = (buffer[i + 2] - matteB) * k + matteB;
}
},
}
createImageData(forceRGBA = false) {
var drawWidth = this.drawWidth;
@ -747,7 +732,7 @@ var PDFImage = (function PDFImageClosure() {
}
return imgData;
},
}
fillGrayBuffer(buffer) {
if (
@ -803,7 +788,7 @@ var PDFImage = (function PDFImageClosure() {
for (i = 0; i < length; ++i) {
buffer[i] = scale * comps[i];
}
},
}
getImageBytes(length, drawWidth, drawHeight, forceRGB = false) {
this.image.reset();
@ -811,9 +796,7 @@ var PDFImage = (function PDFImageClosure() {
this.image.drawHeight = drawHeight || this.height;
this.image.forceRGB = !!forceRGB;
return this.image.getBytes(length, /* forceClamped = */ true);
},
};
return PDFImage;
})();
}
}
export { PDFImage };