From a273599a126752948f7f2b1942b9a8f50cc95c68 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 5 May 2021 12:46:08 +0200 Subject: [PATCH] Enable the `no-var` rule in the `src/core/jpx.js` file These changes were made automatically, using `gulp lint --fix`. --- src/core/jpx.js | 810 ++++++++++++++++++++++++------------------------ 1 file changed, 405 insertions(+), 405 deletions(-) diff --git a/src/core/jpx.js b/src/core/jpx.js index cdd96c41b..ade3d8bfb 100644 --- a/src/core/jpx.js +++ b/src/core/jpx.js @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* eslint-disable no-var */ import { BaseException, info, warn } from "../shared/util.js"; import { log2, readUint16, readUint32 } from "./core_utils.js"; @@ -24,9 +23,9 @@ class JpxError extends BaseException { } } -var JpxImage = (function JpxImageClosure() { +const JpxImage = (function JpxImageClosure() { // Table E.1 - var SubbandsGainLog2 = { + const SubbandsGainLog2 = { LL: 0, LH: 1, HL: 1, @@ -39,19 +38,19 @@ var JpxImage = (function JpxImageClosure() { } JpxImage.prototype = { parse: function JpxImage_parse(data) { - var head = readUint16(data, 0); + const head = readUint16(data, 0); // No box header, immediate start of codestream (SOC) if (head === 0xff4f) { this.parseCodestream(data, 0, data.length); return; } - var position = 0, + let position = 0, length = data.length; while (position < length) { - var headerSize = 8; - var lbox = readUint32(data, position); - var tbox = readUint32(data, position + 4); + let headerSize = 8; + let lbox = readUint32(data, position); + const tbox = readUint32(data, position + 4); position += headerSize; if (lbox === 1) { // XLBox: read UInt64 according to spec. @@ -68,8 +67,8 @@ var JpxImage = (function JpxImageClosure() { if (lbox < headerSize) { throw new JpxError("Invalid box field size"); } - var dataLength = lbox - headerSize; - var jumpDataLength = true; + const dataLength = lbox - headerSize; + let jumpDataLength = true; switch (tbox) { case 0x6a703268: // 'jp2h' jumpDataLength = false; // parsing child boxes @@ -79,7 +78,7 @@ var JpxImage = (function JpxImageClosure() { var method = data[position]; if (method === 1) { // enumerated colorspace - var colorspace = readUint32(data, position + 3); + const colorspace = readUint32(data, position + 3); switch (colorspace) { case 16: // this indicates a sRGB colorspace case 17: // this indicates a grayscale colorspace @@ -124,20 +123,20 @@ var JpxImage = (function JpxImageClosure() { } }, parseImageProperties: function JpxImage_parseImageProperties(stream) { - var newByte = stream.getByte(); + let newByte = stream.getByte(); while (newByte >= 0) { - var oldByte = newByte; + const oldByte = newByte; newByte = stream.getByte(); - var code = (oldByte << 8) | newByte; + const code = (oldByte << 8) | newByte; // Image and tile size (SIZ) if (code === 0xff51) { stream.skip(4); - var Xsiz = stream.getInt32() >>> 0; // Byte 4 - var Ysiz = stream.getInt32() >>> 0; // Byte 8 - var XOsiz = stream.getInt32() >>> 0; // Byte 12 - var YOsiz = stream.getInt32() >>> 0; // Byte 16 + const Xsiz = stream.getInt32() >>> 0; // Byte 4 + const Ysiz = stream.getInt32() >>> 0; // Byte 8 + const XOsiz = stream.getInt32() >>> 0; // Byte 12 + const YOsiz = stream.getInt32() >>> 0; // Byte 16 stream.skip(16); - var Csiz = stream.getUint16(); // Byte 36 + const Csiz = stream.getUint16(); // Byte 36 this.width = Xsiz - XOsiz; this.height = Ysiz - YOsiz; this.componentsCount = Csiz; @@ -149,12 +148,12 @@ var JpxImage = (function JpxImageClosure() { throw new JpxError("No size marker found in JPX stream"); }, parseCodestream: function JpxImage_parseCodestream(data, start, end) { - var context = {}; - var doNotRecover = false; + const context = {}; + let doNotRecover = false; try { - var position = start; + let position = start; while (position + 1 < end) { - var code = readUint16(data, position); + const code = readUint16(data, position); position += 2; var length = 0, @@ -185,8 +184,8 @@ var JpxImage = (function JpxImageClosure() { siz.Csiz = componentsCount; var components = []; j = position + 38; - for (var i = 0; i < componentsCount; i++) { - var component = { + for (let i = 0; i < componentsCount; i++) { + const component = { precision: (data[j] & 0x7f) + 1, isSigned: !!(data[j] & 0x80), XRsiz: data[j + 1], @@ -323,9 +322,9 @@ var JpxImage = (function JpxImageClosure() { cod.segmentationSymbolUsed = !!(blockStyle & 32); cod.reversibleTransformation = data[j++]; if (cod.entropyCoderWithCustomPrecincts) { - var precinctsSizes = []; + const precinctsSizes = []; while (j < length + position) { - var precinctsSize = data[j++]; + const precinctsSize = data[j++]; precinctsSizes.push({ PPx: precinctsSize & 0xf, PPy: precinctsSize >> 4, @@ -430,14 +429,14 @@ var JpxImage = (function JpxImageClosure() { component.height = component.y1 - component.y0; } function calculateTileGrids(context, components) { - var siz = context.SIZ; + const siz = context.SIZ; // Section B.3 Division into tile and tile-components - var tile, + let tile, tiles = []; - var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz); - var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz); - for (var q = 0; q < numYtiles; q++) { - for (var p = 0; p < numXtiles; p++) { + const numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz); + const numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz); + for (let q = 0; q < numYtiles; q++) { + for (let p = 0; p < numXtiles; p++) { tile = {}; tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz); tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz); @@ -451,11 +450,11 @@ var JpxImage = (function JpxImageClosure() { } context.tiles = tiles; - var componentsCount = siz.Csiz; - for (var i = 0, ii = componentsCount; i < ii; i++) { - var component = components[i]; - for (var j = 0, jj = tiles.length; j < jj; j++) { - var tileComponent = {}; + const componentsCount = siz.Csiz; + for (let i = 0, ii = componentsCount; i < ii; i++) { + const component = components[i]; + for (let j = 0, jj = tiles.length; j < jj; j++) { + const tileComponent = {}; tile = tiles[j]; tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz); tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz); @@ -468,8 +467,8 @@ var JpxImage = (function JpxImageClosure() { } } function getBlocksDimensions(context, component, r) { - var codOrCoc = component.codingStyleParameters; - var result = {}; + const codOrCoc = component.codingStyleParameters; + const result = {}; if (!codOrCoc.entropyCoderWithCustomPrecincts) { result.PPx = 15; result.PPy = 15; @@ -490,8 +489,8 @@ var JpxImage = (function JpxImageClosure() { } function buildPrecincts(context, resolution, dimensions) { // Section B.6 Division resolution to precincts - var precinctWidth = 1 << dimensions.PPx; - var precinctHeight = 1 << dimensions.PPy; + const precinctWidth = 1 << dimensions.PPx; + const precinctHeight = 1 << dimensions.PPy; // Jasper introduces codeblock groups for mapping each subband codeblocks // to precincts. Precinct partition divides a resolution according to width // and height parameters. The subband that belongs to the resolution level @@ -506,20 +505,21 @@ var JpxImage = (function JpxImageClosure() { // level. This is accomplished by using the coordinate transformation // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the // coordinates of a point in the LL band and child subband, respectively. - var isZeroRes = resolution.resLevel === 0; - var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1)); - var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1)); - var numprecinctswide = + const isZeroRes = resolution.resLevel === 0; + const precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1)); + const precinctHeightInSubband = + 1 << (dimensions.PPy + (isZeroRes ? 0 : -1)); + const numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0; - var numprecinctshigh = + const numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0; - var numprecincts = numprecinctswide * numprecinctshigh; + const numprecincts = numprecinctswide * numprecinctshigh; resolution.precinctParameters = { precinctWidth, @@ -533,18 +533,18 @@ var JpxImage = (function JpxImageClosure() { } function buildCodeblocks(context, subband, dimensions) { // Section B.7 Division sub-band into code-blocks - var xcb_ = dimensions.xcb_; - var ycb_ = dimensions.ycb_; - var codeblockWidth = 1 << xcb_; - var codeblockHeight = 1 << ycb_; - var cbx0 = subband.tbx0 >> xcb_; - var cby0 = subband.tby0 >> ycb_; - var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_; - var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_; - var precinctParameters = subband.resolution.precinctParameters; - var codeblocks = []; - var precincts = []; - var i, j, codeblock, precinctNumber; + const xcb_ = dimensions.xcb_; + const ycb_ = dimensions.ycb_; + const codeblockWidth = 1 << xcb_; + const codeblockHeight = 1 << ycb_; + const cbx0 = subband.tbx0 >> xcb_; + const cby0 = subband.tby0 >> ycb_; + const cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_; + const cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_; + const precinctParameters = subband.resolution.precinctParameters; + const codeblocks = []; + const precincts = []; + let i, j, codeblock, precinctNumber; for (j = cby0; j < cby1; j++) { for (i = cbx0; i < cbx1; i++) { codeblock = { @@ -564,11 +564,11 @@ var JpxImage = (function JpxImageClosure() { // Calculate precinct number for this codeblock, codeblock position // should be relative to its subband, use actual dimension and position // See comment about codeblock group width and height - var pi = Math.floor( + const pi = Math.floor( (codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband ); - var pj = Math.floor( + const pj = Math.floor( (codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband ); @@ -586,7 +586,7 @@ var JpxImage = (function JpxImageClosure() { } codeblocks.push(codeblock); // building precinct for the sub-band - var precinct = precincts[precinctNumber]; + let precinct = precincts[precinctNumber]; if (precinct !== undefined) { if (i < precinct.cbxMin) { precinct.cbxMin = i; @@ -619,15 +619,15 @@ var JpxImage = (function JpxImageClosure() { subband.precincts = precincts; } function createPacket(resolution, precinctNumber, layerNumber) { - var precinctCodeblocks = []; + const precinctCodeblocks = []; // Section B.10.8 Order of info in packet - var subbands = resolution.subbands; + const subbands = resolution.subbands; // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence - for (var i = 0, ii = subbands.length; i < ii; i++) { - var subband = subbands[i]; - var codeblocks = subband.codeblocks; - for (var j = 0, jj = codeblocks.length; j < jj; j++) { - var codeblock = codeblocks[j]; + for (let i = 0, ii = subbands.length; i < ii; i++) { + const subband = subbands[i]; + const codeblocks = subband.codeblocks; + for (let j = 0, jj = codeblocks.length; j < jj; j++) { + const codeblock = codeblocks[j]; if (codeblock.precinctNumber !== precinctNumber) { continue; } @@ -640,20 +640,20 @@ var JpxImage = (function JpxImageClosure() { }; } function LayerResolutionComponentPositionIterator(context) { - var siz = context.SIZ; - var tileIndex = context.currentTile.index; - var tile = context.tiles[tileIndex]; - var layersCount = tile.codingStyleDefaultParameters.layersCount; - var componentsCount = siz.Csiz; - var maxDecompositionLevelsCount = 0; - for (var q = 0; q < componentsCount; q++) { + const siz = context.SIZ; + const tileIndex = context.currentTile.index; + const tile = context.tiles[tileIndex]; + const layersCount = tile.codingStyleDefaultParameters.layersCount; + const componentsCount = siz.Csiz; + let maxDecompositionLevelsCount = 0; + for (let q = 0; q < componentsCount; q++) { maxDecompositionLevelsCount = Math.max( maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount ); } - var l = 0, + let l = 0, r = 0, i = 0, k = 0; @@ -663,15 +663,15 @@ var JpxImage = (function JpxImageClosure() { for (; l < layersCount; l++) { for (; r <= maxDecompositionLevelsCount; r++) { for (; i < componentsCount; i++) { - var component = tile.components[i]; + const component = tile.components[i]; if (r > component.codingStyleParameters.decompositionLevelsCount) { continue; } - var resolution = component.resolutions[r]; - var numprecincts = resolution.precinctParameters.numprecincts; + const resolution = component.resolutions[r]; + const numprecincts = resolution.precinctParameters.numprecincts; for (; k < numprecincts; ) { - var packet = createPacket(resolution, k, l); + const packet = createPacket(resolution, k, l); k++; return packet; } @@ -685,20 +685,20 @@ var JpxImage = (function JpxImageClosure() { }; } function ResolutionLayerComponentPositionIterator(context) { - var siz = context.SIZ; - var tileIndex = context.currentTile.index; - var tile = context.tiles[tileIndex]; - var layersCount = tile.codingStyleDefaultParameters.layersCount; - var componentsCount = siz.Csiz; - var maxDecompositionLevelsCount = 0; - for (var q = 0; q < componentsCount; q++) { + const siz = context.SIZ; + const tileIndex = context.currentTile.index; + const tile = context.tiles[tileIndex]; + const layersCount = tile.codingStyleDefaultParameters.layersCount; + const componentsCount = siz.Csiz; + let maxDecompositionLevelsCount = 0; + for (let q = 0; q < componentsCount; q++) { maxDecompositionLevelsCount = Math.max( maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount ); } - var r = 0, + let r = 0, l = 0, i = 0, k = 0; @@ -708,15 +708,15 @@ var JpxImage = (function JpxImageClosure() { for (; r <= maxDecompositionLevelsCount; r++) { for (; l < layersCount; l++) { for (; i < componentsCount; i++) { - var component = tile.components[i]; + const component = tile.components[i]; if (r > component.codingStyleParameters.decompositionLevelsCount) { continue; } - var resolution = component.resolutions[r]; - var numprecincts = resolution.precinctParameters.numprecincts; + const resolution = component.resolutions[r]; + const numprecincts = resolution.precinctParameters.numprecincts; for (; k < numprecincts; ) { - var packet = createPacket(resolution, k, l); + const packet = createPacket(resolution, k, l); k++; return packet; } @@ -730,13 +730,13 @@ var JpxImage = (function JpxImageClosure() { }; } function ResolutionPositionComponentLayerIterator(context) { - var siz = context.SIZ; - var tileIndex = context.currentTile.index; - var tile = context.tiles[tileIndex]; - var layersCount = tile.codingStyleDefaultParameters.layersCount; - var componentsCount = siz.Csiz; - var l, r, c, p; - var maxDecompositionLevelsCount = 0; + const siz = context.SIZ; + const tileIndex = context.currentTile.index; + const tile = context.tiles[tileIndex]; + const layersCount = tile.codingStyleDefaultParameters.layersCount; + const componentsCount = siz.Csiz; + let l, r, c, p; + let maxDecompositionLevelsCount = 0; for (c = 0; c < componentsCount; c++) { const component = tile.components[c]; maxDecompositionLevelsCount = Math.max( @@ -744,13 +744,13 @@ var JpxImage = (function JpxImageClosure() { component.codingStyleParameters.decompositionLevelsCount ); } - var maxNumPrecinctsInLevel = new Int32Array( + const maxNumPrecinctsInLevel = new Int32Array( maxDecompositionLevelsCount + 1 ); for (r = 0; r <= maxDecompositionLevelsCount; ++r) { - var maxNumPrecincts = 0; + let maxNumPrecincts = 0; for (c = 0; c < componentsCount; ++c) { - var resolutions = tile.components[c].resolutions; + const resolutions = tile.components[c].resolutions; if (r < resolutions.length) { maxNumPrecincts = Math.max( maxNumPrecincts, @@ -774,13 +774,13 @@ var JpxImage = (function JpxImageClosure() { if (r > component.codingStyleParameters.decompositionLevelsCount) { continue; } - var resolution = component.resolutions[r]; - var numprecincts = resolution.precinctParameters.numprecincts; + const resolution = component.resolutions[r]; + const numprecincts = resolution.precinctParameters.numprecincts; if (p >= numprecincts) { continue; } for (; l < layersCount; ) { - var packet = createPacket(resolution, p, l); + const packet = createPacket(resolution, p, l); l++; return packet; } @@ -794,14 +794,14 @@ var JpxImage = (function JpxImageClosure() { }; } function PositionComponentResolutionLayerIterator(context) { - var siz = context.SIZ; - var tileIndex = context.currentTile.index; - var tile = context.tiles[tileIndex]; - var layersCount = tile.codingStyleDefaultParameters.layersCount; - var componentsCount = siz.Csiz; - var precinctsSizes = getPrecinctSizesInImageScale(tile); - var precinctsIterationSizes = precinctsSizes; - var l = 0, + const siz = context.SIZ; + const tileIndex = context.currentTile.index; + const tile = context.tiles[tileIndex]; + const layersCount = tile.codingStyleDefaultParameters.layersCount; + const componentsCount = siz.Csiz; + const precinctsSizes = getPrecinctSizesInImageScale(tile); + const precinctsIterationSizes = precinctsSizes; + let l = 0, r = 0, c = 0, px = 0, @@ -812,14 +812,14 @@ var JpxImage = (function JpxImageClosure() { for (; py < precinctsIterationSizes.maxNumHigh; py++) { for (; px < precinctsIterationSizes.maxNumWide; px++) { for (; c < componentsCount; c++) { - var component = tile.components[c]; - var decompositionLevelsCount = + const component = tile.components[c]; + const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; for (; r <= decompositionLevelsCount; r++) { - var resolution = component.resolutions[r]; - var sizeInImageScale = + const resolution = component.resolutions[r]; + const sizeInImageScale = precinctsSizes.components[c].resolutions[r]; - var k = getPrecinctIndexIfExist( + const k = getPrecinctIndexIfExist( px, py, sizeInImageScale, @@ -830,7 +830,7 @@ var JpxImage = (function JpxImageClosure() { continue; } for (; l < layersCount; ) { - var packet = createPacket(resolution, k, l); + const packet = createPacket(resolution, k, l); l++; return packet; } @@ -846,13 +846,13 @@ var JpxImage = (function JpxImageClosure() { }; } function ComponentPositionResolutionLayerIterator(context) { - var siz = context.SIZ; - var tileIndex = context.currentTile.index; - var tile = context.tiles[tileIndex]; - var layersCount = tile.codingStyleDefaultParameters.layersCount; - var componentsCount = siz.Csiz; - var precinctsSizes = getPrecinctSizesInImageScale(tile); - var l = 0, + const siz = context.SIZ; + const tileIndex = context.currentTile.index; + const tile = context.tiles[tileIndex]; + const layersCount = tile.codingStyleDefaultParameters.layersCount; + const componentsCount = siz.Csiz; + const precinctsSizes = getPrecinctSizesInImageScale(tile); + let l = 0, r = 0, c = 0, px = 0, @@ -861,16 +861,16 @@ var JpxImage = (function JpxImageClosure() { this.nextPacket = function JpxImage_nextPacket() { // Section B.12.1.5 Component-position-resolution-layer for (; c < componentsCount; ++c) { - var component = tile.components[c]; - var precinctsIterationSizes = precinctsSizes.components[c]; - var decompositionLevelsCount = + const component = tile.components[c]; + const precinctsIterationSizes = precinctsSizes.components[c]; + const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; for (; py < precinctsIterationSizes.maxNumHigh; py++) { for (; px < precinctsIterationSizes.maxNumWide; px++) { for (; r <= decompositionLevelsCount; r++) { - var resolution = component.resolutions[r]; - var sizeInImageScale = precinctsIterationSizes.resolutions[r]; - var k = getPrecinctIndexIfExist( + const resolution = component.resolutions[r]; + const sizeInImageScale = precinctsIterationSizes.resolutions[r]; + const k = getPrecinctIndexIfExist( px, py, sizeInImageScale, @@ -881,7 +881,7 @@ var JpxImage = (function JpxImageClosure() { continue; } for (; l < layersCount; ) { - var packet = createPacket(resolution, k, l); + const packet = createPacket(resolution, k, l); l++; return packet; } @@ -903,41 +903,41 @@ var JpxImage = (function JpxImageClosure() { precinctIterationSizes, resolution ) { - var posX = pxIndex * precinctIterationSizes.minWidth; - var posY = pyIndex * precinctIterationSizes.minHeight; + const posX = pxIndex * precinctIterationSizes.minWidth; + const posY = pyIndex * precinctIterationSizes.minHeight; if ( posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0 ) { return null; } - var startPrecinctRowIndex = + const startPrecinctRowIndex = (posY / sizeInImageScale.width) * resolution.precinctParameters.numprecinctswide; return posX / sizeInImageScale.height + startPrecinctRowIndex; } function getPrecinctSizesInImageScale(tile) { - var componentsCount = tile.components.length; - var minWidth = Number.MAX_VALUE; - var minHeight = Number.MAX_VALUE; - var maxNumWide = 0; - var maxNumHigh = 0; - var sizePerComponent = new Array(componentsCount); - for (var c = 0; c < componentsCount; c++) { - var component = tile.components[c]; - var decompositionLevelsCount = + const componentsCount = tile.components.length; + let minWidth = Number.MAX_VALUE; + let minHeight = Number.MAX_VALUE; + let maxNumWide = 0; + let maxNumHigh = 0; + const sizePerComponent = new Array(componentsCount); + for (let c = 0; c < componentsCount; c++) { + const component = tile.components[c]; + const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; - var sizePerResolution = new Array(decompositionLevelsCount + 1); - var minWidthCurrentComponent = Number.MAX_VALUE; - var minHeightCurrentComponent = Number.MAX_VALUE; - var maxNumWideCurrentComponent = 0; - var maxNumHighCurrentComponent = 0; - var scale = 1; - for (var r = decompositionLevelsCount; r >= 0; --r) { - var resolution = component.resolutions[r]; - var widthCurrentResolution = + const sizePerResolution = new Array(decompositionLevelsCount + 1); + let minWidthCurrentComponent = Number.MAX_VALUE; + let minHeightCurrentComponent = Number.MAX_VALUE; + let maxNumWideCurrentComponent = 0; + let maxNumHighCurrentComponent = 0; + let scale = 1; + for (let r = decompositionLevelsCount; r >= 0; --r) { + const resolution = component.resolutions[r]; + const widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth; - var heightCurrentResolution = + const heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight; minWidthCurrentComponent = Math.min( minWidthCurrentComponent, @@ -982,22 +982,22 @@ var JpxImage = (function JpxImageClosure() { }; } function buildPackets(context) { - var siz = context.SIZ; - var tileIndex = context.currentTile.index; - var tile = context.tiles[tileIndex]; - var componentsCount = siz.Csiz; + const siz = context.SIZ; + const tileIndex = context.currentTile.index; + const tile = context.tiles[tileIndex]; + const componentsCount = siz.Csiz; // Creating resolutions and sub-bands for each component - for (var c = 0; c < componentsCount; c++) { - var component = tile.components[c]; - var decompositionLevelsCount = + for (let c = 0; c < componentsCount; c++) { + const component = tile.components[c]; + const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; // Section B.5 Resolution levels and sub-bands - var resolutions = []; - var subbands = []; - for (var r = 0; r <= decompositionLevelsCount; r++) { - var blocksDimensions = getBlocksDimensions(context, component, r); - var resolution = {}; - var scale = 1 << (decompositionLevelsCount - r); + const resolutions = []; + const subbands = []; + for (let r = 0; r <= decompositionLevelsCount; r++) { + const blocksDimensions = getBlocksDimensions(context, component, r); + const resolution = {}; + const scale = 1 << (decompositionLevelsCount - r); resolution.trx0 = Math.ceil(component.tcx0 / scale); resolution.try0 = Math.ceil(component.tcy0 / scale); resolution.trx1 = Math.ceil(component.tcx1 / scale); @@ -1020,8 +1020,8 @@ var JpxImage = (function JpxImageClosure() { subbands.push(subband); resolution.subbands = [subband]; } else { - var bscale = 1 << (decompositionLevelsCount - r + 1); - var resolutionSubbands = []; + const bscale = 1 << (decompositionLevelsCount - r + 1); + const resolutionSubbands = []; // three sub-bands (HL, LH and HH) with rest of decompositions subband = {}; subband.type = "HL"; @@ -1063,7 +1063,7 @@ var JpxImage = (function JpxImageClosure() { component.subbands = subbands; } // Generate the packets sequence - var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder; + const progressionOrder = tile.codingStyleDefaultParameters.progressionOrder; switch (progressionOrder) { case 0: tile.packetsIterator = new LayerResolutionComponentPositionIterator( @@ -1095,13 +1095,13 @@ var JpxImage = (function JpxImageClosure() { } } function parseTilePackets(context, data, offset, dataLength) { - var position = 0; - var buffer, + let position = 0; + let buffer, bufferSize = 0, skipNextBit = false; function readBits(count) { while (bufferSize < count) { - var b = data[offset + position]; + const b = data[offset + position]; position++; if (skipNextBit) { buffer = (buffer << 7) | b; @@ -1151,7 +1151,7 @@ var JpxImage = (function JpxImageClosure() { if (readBits(1) === 0) { return 2; } - var value = readBits(2); + let value = readBits(2); if (value < 3) { return value + 3; } @@ -1162,31 +1162,31 @@ var JpxImage = (function JpxImageClosure() { value = readBits(7); return value + 37; } - var tileIndex = context.currentTile.index; - var tile = context.tiles[tileIndex]; - var sopMarkerUsed = context.COD.sopMarkerUsed; - var ephMarkerUsed = context.COD.ephMarkerUsed; - var packetsIterator = tile.packetsIterator; + const tileIndex = context.currentTile.index; + const tile = context.tiles[tileIndex]; + const sopMarkerUsed = context.COD.sopMarkerUsed; + const ephMarkerUsed = context.COD.ephMarkerUsed; + const packetsIterator = tile.packetsIterator; while (position < dataLength) { alignToByte(); if (sopMarkerUsed && skipMarkerIfEqual(0x91)) { // Skip also marker segment length and packet sequence ID skipBytes(4); } - var packet = packetsIterator.nextPacket(); + const packet = packetsIterator.nextPacket(); if (!readBits(1)) { continue; } - var layerNumber = packet.layerNumber; + const layerNumber = packet.layerNumber; var queue = [], codeblock; - for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) { + for (let i = 0, ii = packet.codeblocks.length; i < ii; i++) { codeblock = packet.codeblocks[i]; - var precinct = codeblock.precinct; - var codeblockColumn = codeblock.cbx - precinct.cbxMin; - var codeblockRow = codeblock.cby - precinct.cbyMin; - var codeblockIncluded = false; - var firstTimeInclusion = false; + let precinct = codeblock.precinct; + const codeblockColumn = codeblock.cbx - precinct.cbxMin; + const codeblockRow = codeblock.cby - precinct.cbyMin; + let codeblockIncluded = false; + let firstTimeInclusion = false; var valueReady; if (codeblock.included !== undefined) { codeblockIncluded = !!readBits(1); @@ -1198,8 +1198,8 @@ var JpxImage = (function JpxImageClosure() { inclusionTree = precinct.inclusionTree; } else { // building inclusion and zero bit-planes trees - var width = precinct.cbxMax - precinct.cbxMin + 1; - var height = precinct.cbyMax - precinct.cbyMin + 1; + const width = precinct.cbxMax - precinct.cbxMin + 1; + const height = precinct.cbyMax - precinct.cbyMin + 1; inclusionTree = new InclusionTree(width, height, layerNumber); zeroBitPlanesTree = new TagTree(width, height); precinct.inclusionTree = inclusionTree; @@ -1240,17 +1240,17 @@ var JpxImage = (function JpxImageClosure() { } codeblock.zeroBitPlanes = zeroBitPlanesTree.value; } - var codingpasses = readCodingpasses(); + const codingpasses = readCodingpasses(); while (readBits(1)) { codeblock.Lblock++; } - var codingpassesLog2 = log2(codingpasses); + const codingpassesLog2 = log2(codingpasses); // rounding down log2 - var bits = + const bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock; - var codedDataLength = readBits(bits); + const codedDataLength = readBits(bits); queue.push({ codeblock, codingpasses, @@ -1262,7 +1262,7 @@ var JpxImage = (function JpxImageClosure() { skipMarkerIfEqual(0x92); } while (queue.length > 0) { - var packetItem = queue.shift(); + const packetItem = queue.shift(); codeblock = packetItem.codeblock; if (codeblock.data === undefined) { codeblock.data = []; @@ -1288,17 +1288,17 @@ var JpxImage = (function JpxImageClosure() { reversible, segmentationSymbolUsed ) { - var x0 = subband.tbx0; - var y0 = subband.tby0; - var width = subband.tbx1 - subband.tbx0; - var codeblocks = subband.codeblocks; - var right = subband.type.charAt(0) === "H" ? 1 : 0; - var bottom = subband.type.charAt(1) === "H" ? levelWidth : 0; + const x0 = subband.tbx0; + const y0 = subband.tby0; + const width = subband.tbx1 - subband.tbx0; + const codeblocks = subband.codeblocks; + const right = subband.type.charAt(0) === "H" ? 1 : 0; + const bottom = subband.type.charAt(1) === "H" ? levelWidth : 0; - for (var i = 0, ii = codeblocks.length; i < ii; ++i) { - var codeblock = codeblocks[i]; - var blockWidth = codeblock.tbx1_ - codeblock.tbx0_; - var blockHeight = codeblock.tby1_ - codeblock.tby0_; + for (let i = 0, ii = codeblocks.length; i < ii; ++i) { + const codeblock = codeblocks[i]; + const blockWidth = codeblock.tbx1_ - codeblock.tbx0_; + const blockHeight = codeblock.tby1_ - codeblock.tby0_; if (blockWidth === 0 || blockHeight === 0) { continue; } @@ -1317,7 +1317,7 @@ var JpxImage = (function JpxImageClosure() { currentCodingpassType = 2; // first bit plane starts from cleanup // collect data - var data = codeblock.data, + let data = codeblock.data, totalLength = 0, codingpasses = 0; var j, jj, dataItem; @@ -1326,16 +1326,16 @@ var JpxImage = (function JpxImageClosure() { totalLength += dataItem.end - dataItem.start; codingpasses += dataItem.codingpasses; } - var encodedData = new Uint8Array(totalLength); - var position = 0; + const encodedData = new Uint8Array(totalLength); + let position = 0; for (j = 0, jj = data.length; j < jj; j++) { dataItem = data[j]; - var chunk = dataItem.data.subarray(dataItem.start, dataItem.end); + const chunk = dataItem.data.subarray(dataItem.start, dataItem.end); encodedData.set(chunk, position); position += chunk.length; } // decoding the item - var decoder = new ArithmeticDecoder(encodedData, 0, totalLength); + const decoder = new ArithmeticDecoder(encodedData, 0, totalLength); bitModel.setDecoder(decoder); for (j = 0; j < codingpasses; j++) { @@ -1356,19 +1356,19 @@ var JpxImage = (function JpxImageClosure() { currentCodingpassType = (currentCodingpassType + 1) % 3; } - var offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width; - var sign = bitModel.coefficentsSign; - var magnitude = bitModel.coefficentsMagnitude; - var bitsDecoded = bitModel.bitsDecoded; - var magnitudeCorrection = reversible ? 0 : 0.5; + let offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width; + const sign = bitModel.coefficentsSign; + const magnitude = bitModel.coefficentsMagnitude; + const bitsDecoded = bitModel.bitsDecoded; + const magnitudeCorrection = reversible ? 0 : 0.5; var k, n, nb; position = 0; // Do the interleaving of Section F.3.3 here, so we do not need // to copy later. LL level is not interleaved, just copied. - var interleave = subband.type !== "LL"; + const interleave = subband.type !== "LL"; for (j = 0; j < blockHeight; j++) { - var row = (offset / width) | 0; // row in the non-interleaved subband - var levelOffset = 2 * row * (levelWidth - width) + right + bottom; + const row = (offset / width) | 0; // row in the non-interleaved subband + const levelOffset = 2 * row * (levelWidth - width) + right + bottom; for (k = 0; k < blockWidth; k++) { n = magnitude[position]; if (n !== 0) { @@ -1377,7 +1377,7 @@ var JpxImage = (function JpxImageClosure() { n = -n; } nb = bitsDecoded[position]; - var pos = interleave ? levelOffset + (offset << 1) : offset; + const pos = interleave ? levelOffset + (offset << 1) : offset; if (reversible && nb >= mb) { coefficients[pos] = n; } else { @@ -1392,33 +1392,33 @@ var JpxImage = (function JpxImageClosure() { } } function transformTile(context, tile, c) { - var component = tile.components[c]; - var codingStyleParameters = component.codingStyleParameters; - var quantizationParameters = component.quantizationParameters; - var decompositionLevelsCount = + const component = tile.components[c]; + const codingStyleParameters = component.codingStyleParameters; + const quantizationParameters = component.quantizationParameters; + const decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount; - var spqcds = quantizationParameters.SPqcds; - var scalarExpounded = quantizationParameters.scalarExpounded; - var guardBits = quantizationParameters.guardBits; - var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed; - var precision = context.components[c].precision; + const spqcds = quantizationParameters.SPqcds; + const scalarExpounded = quantizationParameters.scalarExpounded; + const guardBits = quantizationParameters.guardBits; + const segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed; + const precision = context.components[c].precision; - var reversible = codingStyleParameters.reversibleTransformation; - var transform = reversible + const reversible = codingStyleParameters.reversibleTransformation; + const transform = reversible ? new ReversibleTransform() : new IrreversibleTransform(); - var subbandCoefficients = []; - var b = 0; - for (var i = 0; i <= decompositionLevelsCount; i++) { - var resolution = component.resolutions[i]; + const subbandCoefficients = []; + let b = 0; + for (let i = 0; i <= decompositionLevelsCount; i++) { + const resolution = component.resolutions[i]; - var width = resolution.trx1 - resolution.trx0; - var height = resolution.try1 - resolution.try0; + const width = resolution.trx1 - resolution.trx0; + const height = resolution.try1 - resolution.try0; // Allocate space for the whole sublevel. - var coefficients = new Float32Array(width * height); + const coefficients = new Float32Array(width * height); - for (var j = 0, jj = resolution.subbands.length; j < jj; j++) { + for (let j = 0, jj = resolution.subbands.length; j < jj; j++) { var mu, epsilon; if (!scalarExpounded) { // formula E-5 @@ -1430,14 +1430,14 @@ var JpxImage = (function JpxImageClosure() { b++; } - var subband = resolution.subbands[j]; - var gainLog2 = SubbandsGainLog2[subband.type]; + const subband = resolution.subbands[j]; + const gainLog2 = SubbandsGainLog2[subband.type]; // calculate quantization coefficient (Section E.1.1.1) - var delta = reversible + const delta = reversible ? 1 : 2 ** (precision + gainLog2 - epsilon) * (1 + mu / 2048); - var mb = guardBits + epsilon - 1; + const mb = guardBits + epsilon - 1; // In the first resolution level, copyCoefficients will fill the // whole array with coefficients. In the succeeding passes, @@ -1462,7 +1462,7 @@ var JpxImage = (function JpxImageClosure() { }); } - var result = transform.calculate( + const result = transform.calculate( subbandCoefficients, component.tcx0, component.tcy0 @@ -1476,20 +1476,20 @@ var JpxImage = (function JpxImageClosure() { }; } function transformComponents(context) { - var siz = context.SIZ; - var components = context.components; - var componentsCount = siz.Csiz; - var resultImages = []; - for (var i = 0, ii = context.tiles.length; i < ii; i++) { - var tile = context.tiles[i]; - var transformedTiles = []; + const siz = context.SIZ; + const components = context.components; + const componentsCount = siz.Csiz; + const resultImages = []; + for (let i = 0, ii = context.tiles.length; i < ii; i++) { + const tile = context.tiles[i]; + const transformedTiles = []; var c; for (c = 0; c < componentsCount; c++) { transformedTiles[c] = transformTile(context, tile, c); } - var tile0 = transformedTiles[0]; - var out = new Uint8ClampedArray(tile0.items.length * componentsCount); - var result = { + const tile0 = transformedTiles[0]; + const out = new Uint8ClampedArray(tile0.items.length * componentsCount); + const result = { left: tile0.left, top: tile0.top, width: tile0.width, @@ -1506,11 +1506,11 @@ var JpxImage = (function JpxImageClosure() { y1, y2; if (tile.codingStyleDefaultParameters.multipleComponentTransform) { - var fourComponents = componentsCount === 4; - var y0items = transformedTiles[0].items; - var y1items = transformedTiles[1].items; - var y2items = transformedTiles[2].items; - var y3items = fourComponents ? transformedTiles[3].items : null; + const fourComponents = componentsCount === 4; + const y0items = transformedTiles[0].items; + const y1items = transformedTiles[1].items; + const y2items = transformedTiles[2].items; + const y3items = fourComponents ? transformedTiles[3].items : null; // HACK: The multiple component transform formulas below assume that // all components have the same precision. With this in mind, we @@ -1518,8 +1518,8 @@ var JpxImage = (function JpxImageClosure() { shift = components[0].precision - 8; offset = (128 << shift) + 0.5; - var component0 = tile.components[0]; - var alpha01 = componentsCount - 3; + const component0 = tile.components[0]; + const alpha01 = componentsCount - 3; jj = y0items.length; if (!component0.codingStyleParameters.reversibleTransformation) { // inverse irreversible multiple component transform @@ -1552,7 +1552,7 @@ var JpxImage = (function JpxImageClosure() { } else { // no multi-component transform for (c = 0; c < componentsCount; c++) { - var items = transformedTiles[c].items; + const items = transformedTiles[c].items; shift = components[c].precision - 8; offset = (128 << shift) + 0.5; for (pos = c, j = 0, jj = items.length; j < jj; j++) { @@ -1566,17 +1566,17 @@ var JpxImage = (function JpxImageClosure() { return resultImages; } function initializeTile(context, tileIndex) { - var siz = context.SIZ; - var componentsCount = siz.Csiz; - var tile = context.tiles[tileIndex]; - for (var c = 0; c < componentsCount; c++) { - var component = tile.components[c]; - var qcdOrQcc = + const siz = context.SIZ; + const componentsCount = siz.Csiz; + const tile = context.tiles[tileIndex]; + for (let c = 0; c < componentsCount; c++) { + const component = tile.components[c]; + const qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD; component.quantizationParameters = qcdOrQcc; - var codOrCoc = + const codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD; @@ -1589,10 +1589,10 @@ var JpxImage = (function JpxImageClosure() { var TagTree = (function TagTreeClosure() { // eslint-disable-next-line no-shadow function TagTree(width, height) { - var levelsLength = log2(Math.max(width, height)) + 1; + const levelsLength = log2(Math.max(width, height)) + 1; this.levels = []; - for (var i = 0; i < levelsLength; i++) { - var level = { + for (let i = 0; i < levelsLength; i++) { + const level = { width, height, items: [], @@ -1604,12 +1604,12 @@ var JpxImage = (function JpxImageClosure() { } TagTree.prototype = { reset: function TagTree_reset(i, j) { - var currentLevel = 0, + let currentLevel = 0, value = 0, level; while (currentLevel < this.levels.length) { level = this.levels[currentLevel]; - var index = i + j * level.width; + const index = i + j * level.width; if (level.items[index] !== undefined) { value = level.items[index]; break; @@ -1626,13 +1626,13 @@ var JpxImage = (function JpxImageClosure() { delete this.value; }, incrementValue: function TagTree_incrementValue() { - var level = this.levels[this.currentLevel]; + const level = this.levels[this.currentLevel]; level.items[level.index]++; }, nextLevel: function TagTree_nextLevel() { - var currentLevel = this.currentLevel; - var level = this.levels[currentLevel]; - var value = level.items[level.index]; + let currentLevel = this.currentLevel; + let level = this.levels[currentLevel]; + const value = level.items[level.index]; currentLevel--; if (currentLevel < 0) { this.value = value; @@ -1651,15 +1651,15 @@ var JpxImage = (function JpxImageClosure() { var InclusionTree = (function InclusionTreeClosure() { // eslint-disable-next-line no-shadow function InclusionTree(width, height, defaultValue) { - var levelsLength = log2(Math.max(width, height)) + 1; + const levelsLength = log2(Math.max(width, height)) + 1; this.levels = []; - for (var i = 0; i < levelsLength; i++) { - var items = new Uint8Array(width * height); - for (var j = 0, jj = items.length; j < jj; j++) { + for (let i = 0; i < levelsLength; i++) { + const items = new Uint8Array(width * height); + for (let j = 0, jj = items.length; j < jj; j++) { items[j] = defaultValue; } - var level = { + const level = { width, height, items, @@ -1672,12 +1672,12 @@ var JpxImage = (function JpxImageClosure() { } InclusionTree.prototype = { reset: function InclusionTree_reset(i, j, stopValue) { - var currentLevel = 0; + let currentLevel = 0; while (currentLevel < this.levels.length) { - var level = this.levels[currentLevel]; - var index = i + j * level.width; + const level = this.levels[currentLevel]; + const index = i + j * level.width; level.index = index; - var value = level.items[index]; + const value = level.items[index]; if (value === 0xff) { break; @@ -1698,23 +1698,23 @@ var JpxImage = (function JpxImageClosure() { return true; }, incrementValue: function InclusionTree_incrementValue(stopValue) { - var level = this.levels[this.currentLevel]; + const level = this.levels[this.currentLevel]; level.items[level.index] = stopValue + 1; this.propagateValues(); }, propagateValues: function InclusionTree_propagateValues() { - var levelIndex = this.currentLevel; - var level = this.levels[levelIndex]; - var currentValue = level.items[level.index]; + let levelIndex = this.currentLevel; + let level = this.levels[levelIndex]; + const currentValue = level.items[level.index]; while (--levelIndex >= 0) { level = this.levels[levelIndex]; level.items[level.index] = currentValue; } }, nextLevel: function InclusionTree_nextLevel() { - var currentLevel = this.currentLevel; - var level = this.levels[currentLevel]; - var value = level.items[level.index]; + let currentLevel = this.currentLevel; + let level = this.levels[currentLevel]; + const value = level.items[level.index]; level.items[level.index] = 0xff; currentLevel--; if (currentLevel < 0) { @@ -1732,25 +1732,25 @@ var JpxImage = (function JpxImageClosure() { // Section D. Coefficient bit modeling var BitModel = (function BitModelClosure() { - var UNIFORM_CONTEXT = 17; - var RUNLENGTH_CONTEXT = 18; + const UNIFORM_CONTEXT = 17; + const RUNLENGTH_CONTEXT = 18; // Table D-1 // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4), // vv - sum of Vi (0..2), and hh - sum of Hi (0..2) // prettier-ignore - var LLAndLHContextsLabel = new Uint8Array([ + const LLAndLHContextsLabel = new Uint8Array([ 0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8 ]); // prettier-ignore - var HLContextLabel = new Uint8Array([ + const HLContextLabel = new Uint8Array([ 0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8 ]); // prettier-ignore - var HHContextLabel = new Uint8Array([ + const HHContextLabel = new Uint8Array([ 0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5, 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8 @@ -1771,7 +1771,7 @@ var JpxImage = (function JpxImageClosure() { } this.contextLabelTable = contextLabelTable; - var coefficientCount = width * height; + const coefficientCount = width * height; // coefficients outside the encoding region treated as insignificant // add border state cells for significanceState @@ -1788,9 +1788,9 @@ var JpxImage = (function JpxImageClosure() { this.coefficentsMagnitude = coefficentsMagnitude; this.processingFlags = new Uint8Array(coefficientCount); - var bitsDecoded = new Uint8Array(coefficientCount); + const bitsDecoded = new Uint8Array(coefficientCount); if (zeroBitPlanes !== 0) { - for (var i = 0; i < coefficientCount; i++) { + for (let i = 0; i < coefficientCount; i++) { bitsDecoded[i] = zeroBitPlanes; } } @@ -1819,12 +1819,12 @@ var JpxImage = (function JpxImageClosure() { column, index ) { - var neighborsSignificance = this.neighborsSignificance; - var width = this.width, + const neighborsSignificance = this.neighborsSignificance; + const width = this.width, height = this.height; - var left = column > 0; - var right = column + 1 < width; - var i; + const left = column > 0; + const right = column + 1 < width; + let i; if (row > 0) { i = index - width; @@ -1857,25 +1857,25 @@ var JpxImage = (function JpxImageClosure() { neighborsSignificance[index] |= 0x80; }, runSignificancePropagationPass: function BitModel_runSignificancePropagationPass() { - var decoder = this.decoder; - var width = this.width, + const decoder = this.decoder; + const width = this.width, height = this.height; - var coefficentsMagnitude = this.coefficentsMagnitude; - var coefficentsSign = this.coefficentsSign; - var neighborsSignificance = this.neighborsSignificance; - var processingFlags = this.processingFlags; - var contexts = this.contexts; - var labels = this.contextLabelTable; - var bitsDecoded = this.bitsDecoded; - var processedInverseMask = ~1; - var processedMask = 1; - var firstMagnitudeBitMask = 2; + const coefficentsMagnitude = this.coefficentsMagnitude; + const coefficentsSign = this.coefficentsSign; + const neighborsSignificance = this.neighborsSignificance; + const processingFlags = this.processingFlags; + const contexts = this.contexts; + const labels = this.contextLabelTable; + const bitsDecoded = this.bitsDecoded; + const processedInverseMask = ~1; + const processedMask = 1; + const firstMagnitudeBitMask = 2; - for (var i0 = 0; i0 < height; i0 += 4) { - for (var j = 0; j < width; j++) { - var index = i0 * width + j; - for (var i1 = 0; i1 < 4; i1++, index += width) { - var i = i0 + i1; + for (let i0 = 0; i0 < height; i0 += 4) { + for (let j = 0; j < width; j++) { + let index = i0 * width + j; + for (let i1 = 0; i1 < 4; i1++, index += width) { + const i = i0 + i1; if (i >= height) { break; } @@ -1889,10 +1889,10 @@ var JpxImage = (function JpxImageClosure() { continue; } - var contextLabel = labels[neighborsSignificance[index]]; - var decision = decoder.readBit(contexts, contextLabel); + const contextLabel = labels[neighborsSignificance[index]]; + const decision = decoder.readBit(contexts, contextLabel); if (decision) { - var sign = this.decodeSignBit(i, j, index); + const sign = this.decodeSignBit(i, j, index); coefficentsSign[index] = sign; coefficentsMagnitude[index] = 1; this.setNeighborsSignificance(i, j, index); @@ -1905,12 +1905,12 @@ var JpxImage = (function JpxImageClosure() { } }, decodeSignBit: function BitModel_decodeSignBit(row, column, index) { - var width = this.width, + const width = this.width, height = this.height; - var coefficentsMagnitude = this.coefficentsMagnitude; - var coefficentsSign = this.coefficentsSign; - var contribution, sign0, sign1, significance1; - var contextLabel, decoded; + const coefficentsMagnitude = this.coefficentsMagnitude; + const coefficentsSign = this.coefficentsSign; + let contribution, sign0, sign1, significance1; + let contextLabel, decoded; // calculate horizontal contribution significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0; @@ -1928,7 +1928,7 @@ var JpxImage = (function JpxImageClosure() { } else { contribution = 0; } - var horizontalContribution = 3 * contribution; + const horizontalContribution = 3 * contribution; // calculate vertical contribution and combine with the horizontal significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0; @@ -1957,23 +1957,23 @@ var JpxImage = (function JpxImageClosure() { return decoded; }, runMagnitudeRefinementPass: function BitModel_runMagnitudeRefinementPass() { - var decoder = this.decoder; - var width = this.width, + const decoder = this.decoder; + const width = this.width, height = this.height; - var coefficentsMagnitude = this.coefficentsMagnitude; - var neighborsSignificance = this.neighborsSignificance; - var contexts = this.contexts; - var bitsDecoded = this.bitsDecoded; - var processingFlags = this.processingFlags; - var processedMask = 1; - var firstMagnitudeBitMask = 2; - var length = width * height; - var width4 = width * 4; + const coefficentsMagnitude = this.coefficentsMagnitude; + const neighborsSignificance = this.neighborsSignificance; + const contexts = this.contexts; + const bitsDecoded = this.bitsDecoded; + const processingFlags = this.processingFlags; + const processedMask = 1; + const firstMagnitudeBitMask = 2; + const length = width * height; + const width4 = width * 4; for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) { indexNext = Math.min(length, index0 + width4); - for (var j = 0; j < width; j++) { - for (var index = index0 + j; index < indexNext; index += width) { + for (let j = 0; j < width; j++) { + for (let index = index0 + j; index < indexNext; index += width) { // significant but not those that have just become if ( !coefficentsMagnitude[index] || @@ -1982,15 +1982,15 @@ var JpxImage = (function JpxImageClosure() { continue; } - var contextLabel = 16; + let contextLabel = 16; if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) { processingFlags[index] ^= firstMagnitudeBitMask; // first refinement - var significance = neighborsSignificance[index] & 127; + const significance = neighborsSignificance[index] & 127; contextLabel = significance === 0 ? 15 : 14; } - var bit = decoder.readBit(contexts, contextLabel); + const bit = decoder.readBit(contexts, contextLabel); coefficentsMagnitude[index] = (coefficentsMagnitude[index] << 1) | bit; bitsDecoded[index]++; @@ -2000,31 +2000,31 @@ var JpxImage = (function JpxImageClosure() { } }, runCleanupPass: function BitModel_runCleanupPass() { - var decoder = this.decoder; - var width = this.width, + const decoder = this.decoder; + const width = this.width, height = this.height; - var neighborsSignificance = this.neighborsSignificance; - var coefficentsMagnitude = this.coefficentsMagnitude; - var coefficentsSign = this.coefficentsSign; - var contexts = this.contexts; - var labels = this.contextLabelTable; - var bitsDecoded = this.bitsDecoded; - var processingFlags = this.processingFlags; - var processedMask = 1; - var firstMagnitudeBitMask = 2; - var oneRowDown = width; - var twoRowsDown = width * 2; - var threeRowsDown = width * 3; - var iNext; - for (var i0 = 0; i0 < height; i0 = iNext) { + const neighborsSignificance = this.neighborsSignificance; + const coefficentsMagnitude = this.coefficentsMagnitude; + const coefficentsSign = this.coefficentsSign; + const contexts = this.contexts; + const labels = this.contextLabelTable; + const bitsDecoded = this.bitsDecoded; + const processingFlags = this.processingFlags; + const processedMask = 1; + const firstMagnitudeBitMask = 2; + const oneRowDown = width; + const twoRowsDown = width * 2; + const threeRowsDown = width * 3; + let iNext; + for (let i0 = 0; i0 < height; i0 = iNext) { iNext = Math.min(i0 + 4, height); - var indexBase = i0 * width; - var checkAllEmpty = i0 + 3 < height; - for (var j = 0; j < width; j++) { - var index0 = indexBase + j; + const indexBase = i0 * width; + const checkAllEmpty = i0 + 3 < height; + for (let j = 0; j < width; j++) { + const index0 = indexBase + j; // using the property: labels[neighborsSignificance[index]] === 0 // when neighborsSignificance[index] === 0 - var allEmpty = + const allEmpty = checkAllEmpty && processingFlags[index0] === 0 && processingFlags[index0 + oneRowDown] === 0 && @@ -2034,12 +2034,12 @@ var JpxImage = (function JpxImageClosure() { neighborsSignificance[index0 + oneRowDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0; - var i1 = 0, + let i1 = 0, index = index0; var i = i0, sign; if (allEmpty) { - var hasSignificantCoefficent = decoder.readBit( + const hasSignificantCoefficent = decoder.readBit( contexts, RUNLENGTH_CONTEXT ); @@ -2065,7 +2065,7 @@ var JpxImage = (function JpxImageClosure() { processingFlags[index] |= firstMagnitudeBitMask; index = index0; - for (var i2 = i0; i2 <= i; i2++, index += width) { + for (let i2 = i0; i2 <= i; i2++, index += width) { bitsDecoded[index]++; } @@ -2079,8 +2079,8 @@ var JpxImage = (function JpxImageClosure() { continue; } - var contextLabel = labels[neighborsSignificance[index]]; - var decision = decoder.readBit(contexts, contextLabel); + const contextLabel = labels[neighborsSignificance[index]]; + const decision = decoder.readBit(contexts, contextLabel); if (decision === 1) { sign = this.decodeSignBit(i, j, index); coefficentsSign[index] = sign; @@ -2094,9 +2094,9 @@ var JpxImage = (function JpxImageClosure() { } }, checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() { - var decoder = this.decoder; - var contexts = this.contexts; - var symbol = + const decoder = this.decoder; + const contexts = this.contexts; + const symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) | (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) | (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) | @@ -2111,7 +2111,7 @@ var JpxImage = (function JpxImageClosure() { })(); // Section F, Discrete wavelet transformation - var Transform = (function TransformClosure() { + const Transform = (function TransformClosure() { // eslint-disable-next-line no-shadow function Transform() {} @@ -2120,17 +2120,17 @@ var JpxImage = (function JpxImageClosure() { u0, v0 ) { - var ll = subbands[0]; - for (var i = 1, ii = subbands.length; i < ii; i++) { + let ll = subbands[0]; + for (let i = 1, ii = subbands.length; i < ii; i++) { ll = this.iterate(ll, subbands[i], u0, v0); } return ll; }; Transform.prototype.extend = function extend(buffer, offset, size) { // Section F.3.7 extending... using max extension of 4 - var i1 = offset - 1, + let i1 = offset - 1, j1 = offset + 1; - var i2 = offset + size - 2, + let i2 = offset + size - 2, j2 = offset + size; buffer[i1--] = buffer[j1++]; buffer[j2++] = buffer[i2--]; @@ -2147,13 +2147,13 @@ var JpxImage = (function JpxImageClosure() { u0, v0 ) { - var llWidth = ll.width, + let llWidth = ll.width, llHeight = ll.height, llItems = ll.items; - var width = hl_lh_hh.width; - var height = hl_lh_hh.height; - var items = hl_lh_hh.items; - var i, j, k, l, u, v; + const width = hl_lh_hh.width; + const height = hl_lh_hh.height; + const items = hl_lh_hh.items; + let i, j, k, l, u, v; // Interleave LL according to Section F.3.3 for (k = 0, i = 0; i < llHeight; i++) { @@ -2165,8 +2165,8 @@ var JpxImage = (function JpxImageClosure() { // The LL band is not needed anymore. llItems = ll.items = null; - var bufferPadding = 4; - var rowBuffer = new Float32Array(width + 2 * bufferPadding); + const bufferPadding = 4; + const rowBuffer = new Float32Array(width + 2 * bufferPadding); // Section F.3.4 HOR_SR if (width === 1) { @@ -2196,12 +2196,12 @@ var JpxImage = (function JpxImageClosure() { // have a cache miss every time. To reduce cache misses, get up to // 'numBuffers' items at a time and store them into the individual // buffers. The colBuffers should be small enough to fit into CPU cache. - var numBuffers = 16; - var colBuffers = []; + let numBuffers = 16; + const colBuffers = []; for (i = 0; i < numBuffers; i++) { colBuffers.push(new Float32Array(height + 2 * bufferPadding)); } - var b, + let b, currentBuffer = 0; ll = bufferPadding + height; @@ -2227,7 +2227,7 @@ var JpxImage = (function JpxImageClosure() { } currentBuffer--; - var buffer = colBuffers[currentBuffer]; + const buffer = colBuffers[currentBuffer]; this.extend(buffer, bufferPadding, height); this.filter(buffer, bufferPadding, height); @@ -2265,16 +2265,16 @@ var JpxImage = (function JpxImageClosure() { offset, length ) { - var len = length >> 1; + const len = length >> 1; offset = offset | 0; - var j, n, current, next; + let j, n, current, next; - var alpha = -1.586134342059924; - var beta = -0.052980118572961; - var gamma = 0.882911075530934; - var delta = 0.443506852043971; - var K = 1.230174104914001; - var K_ = 1 / K; + const alpha = -1.586134342059924; + const beta = -0.052980118572961; + const gamma = 0.882911075530934; + const delta = 0.443506852043971; + const K = 1.230174104914001; + const K_ = 1 / K; // step 1 is combined with step 3 @@ -2363,9 +2363,9 @@ var JpxImage = (function JpxImageClosure() { offset, length ) { - var len = length >> 1; + const len = length >> 1; offset = offset | 0; - var j, n; + let j, n; for (j = offset, n = len + 1; n--; j += 2) { x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;