Enable the no-var
linting rule in src/core/image.js
This is done automatically with `gulp lint --fix` and the following manual changes: ```diff diff --git a/src/core/image.js b/src/core/image.js index 35c06b8ab..e718b9937 100644 --- a/src/core/image.js +++ b/src/core/image.js @@ -97,7 +97,7 @@ class PDFImage { if (isName(filter)) { switch (filter.name) { case "JPXDecode": - var jpxImage = new JpxImage(); + const jpxImage = new JpxImage(); jpxImage.parseImageProperties(image.stream); image.stream.reset(); ```
This commit is contained in:
parent
16efd09c9f
commit
270e56dae8
@ -12,7 +12,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* eslint-disable no-var */
|
||||
|
||||
import { assert, FormatError, ImageKind, info, warn } from "../shared/util.js";
|
||||
import { isName, isStream, Name } from "./primitives.js";
|
||||
@ -47,7 +46,7 @@ function decodeAndClamp(value, addend, coefficient, max) {
|
||||
* @returns {TypedArray} The resized image mask buffer.
|
||||
*/
|
||||
function resizeImageMask(src, bpc, w1, h1, w2, h2) {
|
||||
var length = w2 * h2;
|
||||
const length = w2 * h2;
|
||||
let dest;
|
||||
if (bpc <= 8) {
|
||||
dest = new Uint8Array(length);
|
||||
@ -56,15 +55,15 @@ function resizeImageMask(src, bpc, w1, h1, w2, h2) {
|
||||
} else {
|
||||
dest = new Uint32Array(length);
|
||||
}
|
||||
var xRatio = w1 / w2;
|
||||
var yRatio = h1 / h2;
|
||||
var i,
|
||||
const xRatio = w1 / w2;
|
||||
const yRatio = h1 / h2;
|
||||
let i,
|
||||
j,
|
||||
py,
|
||||
newIndex = 0,
|
||||
oldIndex;
|
||||
var xScaled = new Uint16Array(w2);
|
||||
var w1Scanline = w1;
|
||||
const xScaled = new Uint16Array(w2);
|
||||
const w1Scanline = w1;
|
||||
|
||||
for (i = 0; i < w2; i++) {
|
||||
xScaled[i] = Math.floor(i * xRatio);
|
||||
@ -92,13 +91,13 @@ class PDFImage {
|
||||
localColorSpaceCache,
|
||||
}) {
|
||||
this.image = image;
|
||||
var dict = image.dict;
|
||||
const dict = image.dict;
|
||||
|
||||
const filter = dict.get("Filter");
|
||||
if (isName(filter)) {
|
||||
switch (filter.name) {
|
||||
case "JPXDecode":
|
||||
var jpxImage = new JpxImage();
|
||||
const jpxImage = new JpxImage();
|
||||
jpxImage.parseImageProperties(image.stream);
|
||||
image.stream.reset();
|
||||
|
||||
@ -144,7 +143,7 @@ class PDFImage {
|
||||
this.imageMask = dict.get("ImageMask", "IM") || false;
|
||||
this.matte = dict.get("Matte") || false;
|
||||
|
||||
var bitsPerComponent = image.bitsPerComponent;
|
||||
let bitsPerComponent = image.bitsPerComponent;
|
||||
if (!bitsPerComponent) {
|
||||
bitsPerComponent = dict.get("BitsPerComponent", "BPC");
|
||||
if (!bitsPerComponent) {
|
||||
@ -201,13 +200,13 @@ class PDFImage {
|
||||
) {
|
||||
this.needsDecode = true;
|
||||
// Do some preprocessing to avoid more math.
|
||||
var max = (1 << bitsPerComponent) - 1;
|
||||
const max = (1 << bitsPerComponent) - 1;
|
||||
this.decodeCoefficients = [];
|
||||
this.decodeAddends = [];
|
||||
const isIndexed = this.colorSpace && this.colorSpace.name === "Indexed";
|
||||
for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
|
||||
var dmin = this.decode[i];
|
||||
var dmax = this.decode[i + 1];
|
||||
for (let i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
|
||||
const dmin = this.decode[i];
|
||||
const dmax = this.decode[i + 1];
|
||||
this.decodeCoefficients[j] = isIndexed
|
||||
? (dmax - dmin) / max
|
||||
: dmax - dmin;
|
||||
@ -226,7 +225,7 @@ class PDFImage {
|
||||
});
|
||||
} else if (mask) {
|
||||
if (isStream(mask)) {
|
||||
var maskDict = mask.dict,
|
||||
const maskDict = mask.dict,
|
||||
imageMask = maskDict.get("ImageMask", "IM");
|
||||
if (!imageMask) {
|
||||
warn("Ignoring /Mask in image without /ImageMask.");
|
||||
@ -310,10 +309,10 @@ class PDFImage {
|
||||
// In particular, if inverseDecode is true, then the array we return must
|
||||
// have a length of |computedLength|.
|
||||
|
||||
var computedLength = ((width + 7) >> 3) * height;
|
||||
var actualLength = imgArray.byteLength;
|
||||
var haveFullData = computedLength === actualLength;
|
||||
var data, i;
|
||||
const computedLength = ((width + 7) >> 3) * height;
|
||||
const actualLength = imgArray.byteLength;
|
||||
const haveFullData = computedLength === actualLength;
|
||||
let data, i;
|
||||
|
||||
if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
|
||||
// imgArray came from a DecodeStream and its data is in an appropriate
|
||||
@ -360,13 +359,13 @@ class PDFImage {
|
||||
}
|
||||
|
||||
decodeBuffer(buffer) {
|
||||
var bpc = this.bpc;
|
||||
var numComps = this.numComps;
|
||||
const bpc = this.bpc;
|
||||
const numComps = this.numComps;
|
||||
|
||||
var decodeAddends = this.decodeAddends;
|
||||
var decodeCoefficients = this.decodeCoefficients;
|
||||
var max = (1 << bpc) - 1;
|
||||
var i, ii;
|
||||
const decodeAddends = this.decodeAddends;
|
||||
const decodeCoefficients = this.decodeCoefficients;
|
||||
const max = (1 << bpc) - 1;
|
||||
let i, ii;
|
||||
|
||||
if (bpc === 1) {
|
||||
// If the buffer needed decode that means it just needs to be inverted.
|
||||
@ -375,9 +374,9 @@ class PDFImage {
|
||||
}
|
||||
return;
|
||||
}
|
||||
var index = 0;
|
||||
let index = 0;
|
||||
for (i = 0, ii = this.width * this.height; i < ii; i++) {
|
||||
for (var j = 0; j < numComps; j++) {
|
||||
for (let j = 0; j < numComps; j++) {
|
||||
buffer[index] = decodeAndClamp(
|
||||
buffer[index],
|
||||
decodeAddends[j],
|
||||
@ -390,19 +389,19 @@ class PDFImage {
|
||||
}
|
||||
|
||||
getComponents(buffer) {
|
||||
var bpc = this.bpc;
|
||||
const bpc = this.bpc;
|
||||
|
||||
// This image doesn't require any extra work.
|
||||
if (bpc === 8) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
var width = this.width;
|
||||
var height = this.height;
|
||||
var numComps = this.numComps;
|
||||
const width = this.width;
|
||||
const height = this.height;
|
||||
const numComps = this.numComps;
|
||||
|
||||
var length = width * height * numComps;
|
||||
var bufferPos = 0;
|
||||
const length = width * height * numComps;
|
||||
let bufferPos = 0;
|
||||
let output;
|
||||
if (bpc <= 8) {
|
||||
output = new Uint8Array(length);
|
||||
@ -411,17 +410,17 @@ class PDFImage {
|
||||
} else {
|
||||
output = new Uint32Array(length);
|
||||
}
|
||||
var rowComps = width * numComps;
|
||||
const rowComps = width * numComps;
|
||||
|
||||
var max = (1 << bpc) - 1;
|
||||
var i = 0,
|
||||
const max = (1 << bpc) - 1;
|
||||
let i = 0,
|
||||
ii,
|
||||
buf;
|
||||
|
||||
if (bpc === 1) {
|
||||
// Optimization for reading 1 bpc images.
|
||||
var mask, loop1End, loop2End;
|
||||
for (var j = 0; j < height; j++) {
|
||||
let mask, loop1End, loop2End;
|
||||
for (let j = 0; j < height; j++) {
|
||||
loop1End = i + (rowComps & ~7);
|
||||
loop2End = i + rowComps;
|
||||
|
||||
@ -451,7 +450,7 @@ class PDFImage {
|
||||
}
|
||||
} else {
|
||||
// The general case that handles all other bpc values.
|
||||
var bits = 0;
|
||||
let bits = 0;
|
||||
buf = 0;
|
||||
for (i = 0, ii = length; i < ii; ++i) {
|
||||
if (i % rowComps === 0) {
|
||||
@ -464,7 +463,7 @@ class PDFImage {
|
||||
bits += 8;
|
||||
}
|
||||
|
||||
var remainingBits = bits - bpc;
|
||||
const remainingBits = bits - bpc;
|
||||
let value = buf >> remainingBits;
|
||||
if (value < 0) {
|
||||
value = 0;
|
||||
@ -489,9 +488,9 @@ class PDFImage {
|
||||
'PDFImage.fillOpacity: Unsupported "rgbaBuf" type.'
|
||||
);
|
||||
}
|
||||
var smask = this.smask;
|
||||
var mask = this.mask;
|
||||
var alphaBuf, sw, sh, i, ii, j;
|
||||
const smask = this.smask;
|
||||
const mask = this.mask;
|
||||
let alphaBuf, sw, sh, i, ii, j;
|
||||
|
||||
if (smask) {
|
||||
sw = smask.width;
|
||||
@ -521,13 +520,13 @@ class PDFImage {
|
||||
// Color key mask: if any of the components are outside the range
|
||||
// then they should be painted.
|
||||
alphaBuf = new Uint8ClampedArray(width * height);
|
||||
var numComps = this.numComps;
|
||||
const numComps = this.numComps;
|
||||
for (i = 0, ii = width * height; i < ii; ++i) {
|
||||
var opacity = 0;
|
||||
var imageOffset = i * numComps;
|
||||
let opacity = 0;
|
||||
const imageOffset = i * numComps;
|
||||
for (j = 0; j < numComps; ++j) {
|
||||
var color = image[imageOffset + j];
|
||||
var maskOffset = j * 2;
|
||||
const color = image[imageOffset + j];
|
||||
const maskOffset = j * 2;
|
||||
if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
|
||||
opacity = 255;
|
||||
break;
|
||||
@ -562,17 +561,17 @@ class PDFImage {
|
||||
'PDFImage.undoPreblend: Unsupported "buffer" type.'
|
||||
);
|
||||
}
|
||||
var matte = this.smask && this.smask.matte;
|
||||
const matte = this.smask && this.smask.matte;
|
||||
if (!matte) {
|
||||
return;
|
||||
}
|
||||
var matteRgb = this.colorSpace.getRgb(matte, 0);
|
||||
var matteR = matteRgb[0];
|
||||
var matteG = matteRgb[1];
|
||||
var matteB = matteRgb[2];
|
||||
var length = width * height * 4;
|
||||
for (var i = 0; i < length; i += 4) {
|
||||
var alpha = buffer[i + 3];
|
||||
const matteRgb = this.colorSpace.getRgb(matte, 0);
|
||||
const matteR = matteRgb[0];
|
||||
const matteG = matteRgb[1];
|
||||
const matteB = matteRgb[2];
|
||||
const length = width * height * 4;
|
||||
for (let i = 0; i < length; i += 4) {
|
||||
const alpha = buffer[i + 3];
|
||||
if (alpha === 0) {
|
||||
// according formula we have to get Infinity in all components
|
||||
// making it white (typical paper color) should be okay
|
||||
@ -581,7 +580,7 @@ class PDFImage {
|
||||
buffer[i + 2] = 255;
|
||||
continue;
|
||||
}
|
||||
var k = 255 / alpha;
|
||||
const k = 255 / alpha;
|
||||
buffer[i] = (buffer[i] - matteR) * k + matteR;
|
||||
buffer[i + 1] = (buffer[i + 1] - matteG) * k + matteG;
|
||||
buffer[i + 2] = (buffer[i + 2] - matteB) * k + matteB;
|
||||
@ -589,9 +588,9 @@ class PDFImage {
|
||||
}
|
||||
|
||||
createImageData(forceRGBA = false) {
|
||||
var drawWidth = this.drawWidth;
|
||||
var drawHeight = this.drawHeight;
|
||||
var imgData = {
|
||||
const drawWidth = this.drawWidth;
|
||||
const drawHeight = this.drawHeight;
|
||||
const imgData = {
|
||||
width: drawWidth,
|
||||
height: drawHeight,
|
||||
kind: 0,
|
||||
@ -599,14 +598,14 @@ class PDFImage {
|
||||
// Other fields are filled in below.
|
||||
};
|
||||
|
||||
var numComps = this.numComps;
|
||||
var originalWidth = this.width;
|
||||
var originalHeight = this.height;
|
||||
var bpc = this.bpc;
|
||||
const numComps = this.numComps;
|
||||
const originalWidth = this.width;
|
||||
const originalHeight = this.height;
|
||||
const bpc = this.bpc;
|
||||
|
||||
// Rows start at byte boundary.
|
||||
var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
|
||||
var imgArray;
|
||||
const rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
|
||||
let imgArray;
|
||||
|
||||
if (!forceRGBA) {
|
||||
// If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
|
||||
@ -616,7 +615,7 @@ class PDFImage {
|
||||
//
|
||||
// Similarly, if it is a 24-bit-per pixel RGB image without any
|
||||
// complications, we avoid expanding by 1.333x to RGBA form.
|
||||
var kind;
|
||||
let kind;
|
||||
if (this.colorSpace.name === "DeviceGray" && bpc === 1) {
|
||||
kind = ImageKind.GRAYSCALE_1BPP;
|
||||
} else if (
|
||||
@ -644,7 +643,7 @@ class PDFImage {
|
||||
if (this.image instanceof DecodeStream) {
|
||||
imgData.data = imgArray;
|
||||
} else {
|
||||
var newArray = new Uint8ClampedArray(imgArray.length);
|
||||
const newArray = new Uint8ClampedArray(imgArray.length);
|
||||
newArray.set(imgArray);
|
||||
imgData.data = newArray;
|
||||
}
|
||||
@ -654,8 +653,8 @@ class PDFImage {
|
||||
kind === ImageKind.GRAYSCALE_1BPP,
|
||||
"PDFImage.createImageData: The image must be grayscale."
|
||||
);
|
||||
var buffer = imgData.data;
|
||||
for (var i = 0, ii = buffer.length; i < ii; i++) {
|
||||
const buffer = imgData.data;
|
||||
for (let i = 0, ii = buffer.length; i < ii; i++) {
|
||||
buffer[i] ^= 0xff;
|
||||
}
|
||||
}
|
||||
@ -685,14 +684,14 @@ class PDFImage {
|
||||
|
||||
imgArray = this.getImageBytes(originalHeight * rowBytes);
|
||||
// imgArray can be incomplete (e.g. after CCITT fax encoding).
|
||||
var actualHeight =
|
||||
const actualHeight =
|
||||
0 | (((imgArray.length / rowBytes) * drawHeight) / originalHeight);
|
||||
|
||||
var comps = this.getComponents(imgArray);
|
||||
const comps = this.getComponents(imgArray);
|
||||
|
||||
// If opacity data is present, use RGBA_32BPP form. Otherwise, use the
|
||||
// more compact RGB_24BPP form if allowable.
|
||||
var alpha01, maybeUndoPreblend;
|
||||
let alpha01, maybeUndoPreblend;
|
||||
if (!forceRGBA && !this.smask && !this.mask) {
|
||||
imgData.kind = ImageKind.RGB_24BPP;
|
||||
imgData.data = new Uint8ClampedArray(drawWidth * drawHeight * 3);
|
||||
@ -745,23 +744,23 @@ class PDFImage {
|
||||
'PDFImage.fillGrayBuffer: Unsupported "buffer" type.'
|
||||
);
|
||||
}
|
||||
var numComps = this.numComps;
|
||||
const numComps = this.numComps;
|
||||
if (numComps !== 1) {
|
||||
throw new FormatError(
|
||||
`Reading gray scale from a color image: ${numComps}`
|
||||
);
|
||||
}
|
||||
|
||||
var width = this.width;
|
||||
var height = this.height;
|
||||
var bpc = this.bpc;
|
||||
const width = this.width;
|
||||
const height = this.height;
|
||||
const bpc = this.bpc;
|
||||
|
||||
// rows start at byte boundary
|
||||
var rowBytes = (width * numComps * bpc + 7) >> 3;
|
||||
var imgArray = this.getImageBytes(height * rowBytes);
|
||||
const rowBytes = (width * numComps * bpc + 7) >> 3;
|
||||
const imgArray = this.getImageBytes(height * rowBytes);
|
||||
|
||||
var comps = this.getComponents(imgArray);
|
||||
var i, length;
|
||||
const comps = this.getComponents(imgArray);
|
||||
let i, length;
|
||||
|
||||
if (bpc === 1) {
|
||||
// inline decoding (= inversion) for 1 bpc images
|
||||
@ -785,7 +784,7 @@ class PDFImage {
|
||||
}
|
||||
length = width * height;
|
||||
// we aren't using a colorspace so we need to scale the value
|
||||
var scale = 255 / ((1 << bpc) - 1);
|
||||
const scale = 255 / ((1 << bpc) - 1);
|
||||
for (i = 0; i < length; ++i) {
|
||||
buffer[i] = scale * comps[i];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user