Enable the no-var rule in the src/core/predictor_stream.js file

This commit is contained in:
Jonas Jenwald 2021-04-27 13:43:18 +02:00
parent 66d9d83dcb
commit b08f9a8182

View File

@ -12,19 +12,18 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable no-var */
import { DecodeStream } from "./stream.js"; import { DecodeStream } from "./stream.js";
import { FormatError } from "../shared/util.js"; import { FormatError } from "../shared/util.js";
import { isDict } from "./primitives.js"; import { isDict } from "./primitives.js";
var PredictorStream = (function PredictorStreamClosure() { const PredictorStream = (function PredictorStreamClosure() {
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
function PredictorStream(str, maybeLength, params) { function PredictorStream(str, maybeLength, params) {
if (!isDict(params)) { if (!isDict(params)) {
return str; // no prediction return str; // no prediction
} }
var predictor = (this.predictor = params.get("Predictor") || 1); const predictor = (this.predictor = params.get("Predictor") || 1);
if (predictor <= 1) { if (predictor <= 1) {
return str; // no prediction return str; // no prediction
@ -42,9 +41,9 @@ var PredictorStream = (function PredictorStreamClosure() {
this.str = str; this.str = str;
this.dict = str.dict; this.dict = str.dict;
var colors = (this.colors = params.get("Colors") || 1); const colors = (this.colors = params.get("Colors") || 1);
var bits = (this.bits = params.get("BitsPerComponent") || 8); const bits = (this.bits = params.get("BitsPerComponent") || 8);
var columns = (this.columns = params.get("Columns") || 1); const columns = (this.columns = params.get("Columns") || 1);
this.pixBytes = (colors * bits + 7) >> 3; this.pixBytes = (colors * bits + 7) >> 3;
this.rowBytes = (columns * colors * bits + 7) >> 3; this.rowBytes = (columns * colors * bits + 7) >> 3;
@ -56,32 +55,32 @@ var PredictorStream = (function PredictorStreamClosure() {
PredictorStream.prototype = Object.create(DecodeStream.prototype); PredictorStream.prototype = Object.create(DecodeStream.prototype);
PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() { PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
var rowBytes = this.rowBytes; const rowBytes = this.rowBytes;
var bufferLength = this.bufferLength; const bufferLength = this.bufferLength;
var buffer = this.ensureBuffer(bufferLength + rowBytes); const buffer = this.ensureBuffer(bufferLength + rowBytes);
var bits = this.bits; const bits = this.bits;
var colors = this.colors; const colors = this.colors;
var rawBytes = this.str.getBytes(rowBytes); const rawBytes = this.str.getBytes(rowBytes);
this.eof = !rawBytes.length; this.eof = !rawBytes.length;
if (this.eof) { if (this.eof) {
return; return;
} }
var inbuf = 0, let inbuf = 0,
outbuf = 0; outbuf = 0;
var inbits = 0, let inbits = 0,
outbits = 0; outbits = 0;
var pos = bufferLength; let pos = bufferLength;
var i; let i;
if (bits === 1 && colors === 1) { if (bits === 1 && colors === 1) {
// Optimized version of the loop in the "else"-branch // Optimized version of the loop in the "else"-branch
// for 1 bit-per-component and 1 color TIFF images. // for 1 bit-per-component and 1 color TIFF images.
for (i = 0; i < rowBytes; ++i) { for (i = 0; i < rowBytes; ++i) {
var c = rawBytes[i] ^ inbuf; let c = rawBytes[i] ^ inbuf;
c ^= c >> 1; c ^= c >> 1;
c ^= c >> 2; c ^= c >> 2;
c ^= c >> 4; c ^= c >> 4;
@ -97,12 +96,12 @@ var PredictorStream = (function PredictorStreamClosure() {
pos++; pos++;
} }
} else if (bits === 16) { } else if (bits === 16) {
var bytesPerPixel = colors * 2; const bytesPerPixel = colors * 2;
for (i = 0; i < bytesPerPixel; ++i) { for (i = 0; i < bytesPerPixel; ++i) {
buffer[pos++] = rawBytes[i]; buffer[pos++] = rawBytes[i];
} }
for (; i < rowBytes; i += 2) { for (; i < rowBytes; i += 2) {
var sum = const sum =
((rawBytes[i] & 0xff) << 8) + ((rawBytes[i] & 0xff) << 8) +
(rawBytes[i + 1] & 0xff) + (rawBytes[i + 1] & 0xff) +
((buffer[pos - bytesPerPixel] & 0xff) << 8) + ((buffer[pos - bytesPerPixel] & 0xff) << 8) +
@ -111,13 +110,13 @@ var PredictorStream = (function PredictorStreamClosure() {
buffer[pos++] = sum & 0xff; buffer[pos++] = sum & 0xff;
} }
} else { } else {
var compArray = new Uint8Array(colors + 1); const compArray = new Uint8Array(colors + 1);
var bitMask = (1 << bits) - 1; const bitMask = (1 << bits) - 1;
var j = 0, let j = 0,
k = bufferLength; k = bufferLength;
var columns = this.columns; const columns = this.columns;
for (i = 0; i < columns; ++i) { for (i = 0; i < columns; ++i) {
for (var kk = 0; kk < colors; ++kk) { for (let kk = 0; kk < colors; ++kk) {
if (inbits < bits) { if (inbits < bits) {
inbuf = (inbuf << 8) | (rawBytes[j++] & 0xff); inbuf = (inbuf << 8) | (rawBytes[j++] & 0xff);
inbits += 8; inbits += 8;
@ -142,25 +141,25 @@ var PredictorStream = (function PredictorStreamClosure() {
}; };
PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() { PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
var rowBytes = this.rowBytes; const rowBytes = this.rowBytes;
var pixBytes = this.pixBytes; const pixBytes = this.pixBytes;
var predictor = this.str.getByte(); const predictor = this.str.getByte();
var rawBytes = this.str.getBytes(rowBytes); const rawBytes = this.str.getBytes(rowBytes);
this.eof = !rawBytes.length; this.eof = !rawBytes.length;
if (this.eof) { if (this.eof) {
return; return;
} }
var bufferLength = this.bufferLength; const bufferLength = this.bufferLength;
var buffer = this.ensureBuffer(bufferLength + rowBytes); const buffer = this.ensureBuffer(bufferLength + rowBytes);
var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength); let prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
if (prevRow.length === 0) { if (prevRow.length === 0) {
prevRow = new Uint8Array(rowBytes); prevRow = new Uint8Array(rowBytes);
} }
var i, let i,
j = bufferLength, j = bufferLength,
up, up,
c; c;
@ -204,19 +203,19 @@ var PredictorStream = (function PredictorStreamClosure() {
} }
for (; i < rowBytes; ++i) { for (; i < rowBytes; ++i) {
up = prevRow[i]; up = prevRow[i];
var upLeft = prevRow[i - pixBytes]; const upLeft = prevRow[i - pixBytes];
var left = buffer[j - pixBytes]; const left = buffer[j - pixBytes];
var p = left + up - upLeft; const p = left + up - upLeft;
var pa = p - left; let pa = p - left;
if (pa < 0) { if (pa < 0) {
pa = -pa; pa = -pa;
} }
var pb = p - up; let pb = p - up;
if (pb < 0) { if (pb < 0) {
pb = -pb; pb = -pb;
} }
var pc = p - upLeft; let pc = p - upLeft;
if (pc < 0) { if (pc < 0) {
pc = -pc; pc = -pc;
} }