Fix the remaining no-var failures, which couldn't be handled automatically, in the src/core/jpg.js file

This commit is contained in:
Jonas Jenwald 2021-05-05 12:36:52 +02:00
parent 1e5a179600
commit d0a299713c

View File

@ -81,14 +81,13 @@ const JpegImage = (function JpegImageClosure() {
function buildHuffmanTable(codeLengths, values) { function buildHuffmanTable(codeLengths, values) {
let k = 0, let k = 0,
code = [],
i, i,
j, j,
length = 16; length = 16;
while (length > 0 && !codeLengths[length - 1]) { while (length > 0 && !codeLengths[length - 1]) {
length--; length--;
} }
code.push({ children: [], index: 0 }); const code = [{ children: [], index: 0 }];
let p = code[0], let p = code[0],
q; q;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
@ -267,8 +266,8 @@ const JpegImage = (function JpegImageClosure() {
eobrun--; eobrun--;
return; return;
} }
let k = spectralStart, let k = spectralStart;
e = spectralEnd; const e = spectralEnd;
while (k <= e) { while (k <= e) {
const rs = decodeHuffman(component.huffmanTableAC); const rs = decodeHuffman(component.huffmanTableAC);
const s = rs & 15, const s = rs & 15,
@ -774,8 +773,8 @@ const JpegImage = (function JpegImageClosure() {
function prepareComponents(frame) { function prepareComponents(frame) {
const mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH); const mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
const mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV); const mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
for (let i = 0; i < frame.components.length; i++) { for (let i = 0, ii = frame.components.length; i < ii; i++) {
component = frame.components[i]; const component = frame.components[i];
const blocksPerLine = Math.ceil( const blocksPerLine = Math.ceil(
(Math.ceil(frame.samplesPerLine / 8) * component.h) / frame.maxH (Math.ceil(frame.samplesPerLine / 8) * component.h) / frame.maxH
); );
@ -795,7 +794,7 @@ const JpegImage = (function JpegImageClosure() {
frame.mcusPerColumn = mcusPerColumn; frame.mcusPerColumn = mcusPerColumn;
} }
var offset = 0; let offset = 0;
let jfif = null; let jfif = null;
let adobe = null; let adobe = null;
let frame, resetInterval; let frame, resetInterval;
@ -813,7 +812,7 @@ const JpegImage = (function JpegImageClosure() {
offset += 2; offset += 2;
markerLoop: while (fileMarker !== /* EOI (End of Image) = */ 0xffd9) { markerLoop: while (fileMarker !== /* EOI (End of Image) = */ 0xffd9) {
var i, j, l; let i, j, l;
switch (fileMarker) { switch (fileMarker) {
case 0xffe0: // APP0 (Application Specific) case 0xffe0: // APP0 (Application Specific)
case 0xffe1: // APP1 case 0xffe1: // APP1
@ -832,7 +831,7 @@ const JpegImage = (function JpegImageClosure() {
case 0xffee: // APP14 case 0xffee: // APP14
case 0xffef: // APP15 case 0xffef: // APP15
case 0xfffe: // COM (Comment) case 0xfffe: // COM (Comment)
var appData = readDataBlock(); const appData = readDataBlock();
if (fileMarker === 0xffe0) { if (fileMarker === 0xffe0) {
// 'JFIF\x00' // 'JFIF\x00'
@ -880,8 +879,8 @@ const JpegImage = (function JpegImageClosure() {
case 0xffdb: // DQT (Define Quantization Tables) case 0xffdb: // DQT (Define Quantization Tables)
const quantizationTablesLength = readUint16(data, offset); const quantizationTablesLength = readUint16(data, offset);
offset += 2; offset += 2;
var quantizationTablesEnd = quantizationTablesLength + offset - 2; const quantizationTablesEnd = quantizationTablesLength + offset - 2;
var z; let z;
while (offset < quantizationTablesEnd) { while (offset < quantizationTablesEnd) {
const quantizationTableSpec = data[offset++]; const quantizationTableSpec = data[offset++];
const tableData = new Uint16Array(64); const tableData = new Uint16Array(64);
@ -924,12 +923,11 @@ const JpegImage = (function JpegImageClosure() {
offset += 2; offset += 2;
frame.components = []; frame.components = [];
frame.componentIds = {}; frame.componentIds = {};
var componentsCount = data[offset++], const componentsCount = data[offset++];
componentId; let maxH = 0,
var maxH = 0,
maxV = 0; maxV = 0;
for (i = 0; i < componentsCount; i++) { for (i = 0; i < componentsCount; i++) {
componentId = data[offset]; const componentId = data[offset];
const h = data[offset + 1] >> 4; const h = data[offset + 1] >> 4;
const v = data[offset + 1] & 15; const v = data[offset + 1] & 15;
if (maxH < h) { if (maxH < h) {
@ -991,22 +989,21 @@ const JpegImage = (function JpegImageClosure() {
offset += 2; // Skip marker length. offset += 2; // Skip marker length.
var selectorsCount = data[offset++]; const selectorsCount = data[offset++],
var components = [], components = [];
component;
for (i = 0; i < selectorsCount; i++) { for (i = 0; i < selectorsCount; i++) {
const index = data[offset++]; const index = data[offset++];
const componentIndex = frame.componentIds[index]; const componentIndex = frame.componentIds[index];
component = frame.components[componentIndex]; const component = frame.components[componentIndex];
component.index = index; component.index = index;
const tableSpec = data[offset++]; const tableSpec = data[offset++];
component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4]; component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
component.huffmanTableAC = huffmanTablesAC[tableSpec & 15]; component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
components.push(component); components.push(component);
} }
var spectralStart = data[offset++]; const spectralStart = data[offset++],
var spectralEnd = data[offset++]; spectralEnd = data[offset++],
var successiveApproximation = data[offset++]; successiveApproximation = data[offset++];
try { try {
const processed = decodeScan( const processed = decodeScan(
data, data,
@ -1082,8 +1079,8 @@ const JpegImage = (function JpegImageClosure() {
this.jfif = jfif; this.jfif = jfif;
this.adobe = adobe; this.adobe = adobe;
this.components = []; this.components = [];
for (i = 0; i < frame.components.length; i++) { for (let i = 0, ii = frame.components.length; i < ii; i++) {
component = frame.components[i]; const component = frame.components[i];
// Prevent errors when DQT markers are placed after SOF{n} markers, // Prevent errors when DQT markers are placed after SOF{n} markers,
// by assigning the `quantizationTable` entry after the entire image // by assigning the `quantizationTable` entry after the entire image