Merge pull request #4425 from timvandermeij/jpx-syntax
Making src/core/jpx.js adhere to the style guide
This commit is contained in:
commit
b05f05589b
177
src/core/jpx.js
177
src/core/jpx.js
@ -42,16 +42,18 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
// TODO catch parse error
|
// TODO catch parse error
|
||||||
var data = new Uint8Array(xhr.response || xhr.mozResponseArrayBuffer);
|
var data = new Uint8Array(xhr.response || xhr.mozResponseArrayBuffer);
|
||||||
this.parse(data);
|
this.parse(data);
|
||||||
if (this.onload)
|
if (this.onload) {
|
||||||
this.onload();
|
this.onload();
|
||||||
|
}
|
||||||
}).bind(this);
|
}).bind(this);
|
||||||
xhr.send(null);
|
xhr.send(null);
|
||||||
},
|
},
|
||||||
parse: function JpxImage_parse(data) {
|
parse: function JpxImage_parse(data) {
|
||||||
function readUint(data, offset, bytes) {
|
function readUint(data, offset, bytes) {
|
||||||
var n = 0;
|
var n = 0;
|
||||||
for (var i = 0; i < bytes; i++)
|
for (var i = 0; i < bytes; i++) {
|
||||||
n = n * 256 + (data[offset + i] & 0xFF);
|
n = n * 256 + (data[offset + i] & 0xFF);
|
||||||
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,10 +75,12 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
position += 8;
|
position += 8;
|
||||||
headerSize += 8;
|
headerSize += 8;
|
||||||
}
|
}
|
||||||
if (lbox === 0)
|
if (lbox === 0) {
|
||||||
lbox = length - position + headerSize;
|
lbox = length - position + headerSize;
|
||||||
if (lbox < headerSize)
|
}
|
||||||
|
if (lbox < headerSize) {
|
||||||
error('JPX error: Invalid box field size');
|
error('JPX error: Invalid box field size');
|
||||||
|
}
|
||||||
var dataLength = lbox - headerSize;
|
var dataLength = lbox - headerSize;
|
||||||
var jumpDataLength = true;
|
var jumpDataLength = true;
|
||||||
switch (tbox) {
|
switch (tbox) {
|
||||||
@ -93,8 +97,9 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
this.parseCodestream(data, position, position + dataLength);
|
this.parseCodestream(data, position, position + dataLength);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (jumpDataLength)
|
if (jumpDataLength) {
|
||||||
position += dataLength;
|
position += dataLength;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
parseCodestream: function JpxImage_parseCodestream(data, start, end) {
|
parseCodestream: function JpxImage_parseCodestream(data, start, end) {
|
||||||
@ -165,7 +170,7 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
default:
|
default:
|
||||||
throw 'Invalid SQcd value ' + sqcd;
|
throw 'Invalid SQcd value ' + sqcd;
|
||||||
}
|
}
|
||||||
qcd.noQuantization = spqcdSize == 8;
|
qcd.noQuantization = (spqcdSize == 8);
|
||||||
qcd.scalarExpounded = scalarExpounded;
|
qcd.scalarExpounded = scalarExpounded;
|
||||||
qcd.guardBits = sqcd >> 5;
|
qcd.guardBits = sqcd >> 5;
|
||||||
var spqcds = [];
|
var spqcds = [];
|
||||||
@ -182,9 +187,9 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
spqcds.push(spqcd);
|
spqcds.push(spqcd);
|
||||||
}
|
}
|
||||||
qcd.SPqcds = spqcds;
|
qcd.SPqcds = spqcds;
|
||||||
if (context.mainHeader)
|
if (context.mainHeader) {
|
||||||
context.QCD = qcd;
|
context.QCD = qcd;
|
||||||
else {
|
} else {
|
||||||
context.currentTile.QCD = qcd;
|
context.currentTile.QCD = qcd;
|
||||||
context.currentTile.QCC = [];
|
context.currentTile.QCC = [];
|
||||||
}
|
}
|
||||||
@ -194,9 +199,9 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
var qcc = {};
|
var qcc = {};
|
||||||
j = position + 2;
|
j = position + 2;
|
||||||
var cqcc;
|
var cqcc;
|
||||||
if (context.SIZ.Csiz < 257)
|
if (context.SIZ.Csiz < 257) {
|
||||||
cqcc = data[j++];
|
cqcc = data[j++];
|
||||||
else {
|
} else {
|
||||||
cqcc = readUint16(data, j);
|
cqcc = readUint16(data, j);
|
||||||
j += 2;
|
j += 2;
|
||||||
}
|
}
|
||||||
@ -218,11 +223,11 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
default:
|
default:
|
||||||
throw 'Invalid SQcd value ' + sqcd;
|
throw 'Invalid SQcd value ' + sqcd;
|
||||||
}
|
}
|
||||||
qcc.noQuantization = spqcdSize == 8;
|
qcc.noQuantization = (spqcdSize == 8);
|
||||||
qcc.scalarExpounded = scalarExpounded;
|
qcc.scalarExpounded = scalarExpounded;
|
||||||
qcc.guardBits = sqcd >> 5;
|
qcc.guardBits = sqcd >> 5;
|
||||||
var spqcds = [];
|
var spqcds = [];
|
||||||
while (j < length + position) {
|
while (j < (length + position)) {
|
||||||
var spqcd = {};
|
var spqcd = {};
|
||||||
if (spqcdSize == 8) {
|
if (spqcdSize == 8) {
|
||||||
spqcd.epsilon = data[j++] >> 3;
|
spqcd.epsilon = data[j++] >> 3;
|
||||||
@ -235,10 +240,11 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
spqcds.push(spqcd);
|
spqcds.push(spqcd);
|
||||||
}
|
}
|
||||||
qcc.SPqcds = spqcds;
|
qcc.SPqcds = spqcds;
|
||||||
if (context.mainHeader)
|
if (context.mainHeader) {
|
||||||
context.QCC[cqcc] = qcc;
|
context.QCC[cqcc] = qcc;
|
||||||
else
|
} else {
|
||||||
context.currentTile.QCC[cqcc] = qcc;
|
context.currentTile.QCC[cqcc] = qcc;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 0xFF52: // Coding style default (COD)
|
case 0xFF52: // Coding style default (COD)
|
||||||
length = readUint16(data, position);
|
length = readUint16(data, position);
|
||||||
@ -281,13 +287,14 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
cod.selectiveArithmeticCodingBypass ||
|
cod.selectiveArithmeticCodingBypass ||
|
||||||
cod.resetContextProbabilities ||
|
cod.resetContextProbabilities ||
|
||||||
cod.terminationOnEachCodingPass ||
|
cod.terminationOnEachCodingPass ||
|
||||||
cod.verticalyStripe || cod.predictableTermination)
|
cod.verticalyStripe || cod.predictableTermination) {
|
||||||
throw 'Unsupported COD options: ' +
|
throw 'Unsupported COD options: ' +
|
||||||
globalScope.JSON.stringify(cod);
|
globalScope.JSON.stringify(cod);
|
||||||
|
}
|
||||||
|
|
||||||
if (context.mainHeader)
|
if (context.mainHeader) {
|
||||||
context.COD = cod;
|
context.COD = cod;
|
||||||
else {
|
} else {
|
||||||
context.currentTile.COD = cod;
|
context.currentTile.COD = cod;
|
||||||
context.currentTile.COC = [];
|
context.currentTile.COC = [];
|
||||||
}
|
}
|
||||||
@ -320,7 +327,6 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
|
|
||||||
// moving to the end of the data
|
// moving to the end of the data
|
||||||
length = tile.dataEnd - position;
|
length = tile.dataEnd - position;
|
||||||
|
|
||||||
parseTilePackets(context, data, position, length);
|
parseTilePackets(context, data, position, length);
|
||||||
break;
|
break;
|
||||||
case 0xFF64: // Comment (COM)
|
case 0xFF64: // Comment (COM)
|
||||||
@ -333,10 +339,11 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
position += length;
|
position += length;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (this.failOnCorruptedImage)
|
if (this.failOnCorruptedImage) {
|
||||||
error('JPX error: ' + e);
|
error('JPX error: ' + e);
|
||||||
else
|
} else {
|
||||||
warn('JPX error: ' + e + '. Trying to recover');
|
warn('JPX error: ' + e + '. Trying to recover');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.tiles = transformComponents(context);
|
this.tiles = transformComponents(context);
|
||||||
this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
|
this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
|
||||||
@ -346,7 +353,7 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
};
|
};
|
||||||
function readUint32(data, offset) {
|
function readUint32(data, offset) {
|
||||||
return (data[offset] << 24) | (data[offset + 1] << 16) |
|
return (data[offset] << 24) | (data[offset + 1] << 16) |
|
||||||
(data[offset + 2] << 8) | data[offset + 3];
|
(data[offset + 2] << 8) | data[offset + 3];
|
||||||
}
|
}
|
||||||
function readUint16(data, offset) {
|
function readUint16(data, offset) {
|
||||||
return (data[offset] << 8) | data[offset + 1];
|
return (data[offset] << 8) | data[offset + 1];
|
||||||
@ -416,27 +423,27 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
result.PPy = codOrCoc.precinctsSizes[r].PPy;
|
result.PPy = codOrCoc.precinctsSizes[r].PPy;
|
||||||
}
|
}
|
||||||
// calculate codeblock size as described in section B.7
|
// calculate codeblock size as described in section B.7
|
||||||
result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
|
result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
|
||||||
Math.min(codOrCoc.xcb, result.PPx);
|
Math.min(codOrCoc.xcb, result.PPx));
|
||||||
result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
|
result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
|
||||||
Math.min(codOrCoc.ycb, result.PPy);
|
Math.min(codOrCoc.ycb, result.PPy));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
function buildPrecincts(context, resolution, dimensions) {
|
function buildPrecincts(context, resolution, dimensions) {
|
||||||
// Section B.6 Division resolution to precincts
|
// Section B.6 Division resolution to precincts
|
||||||
var precinctWidth = 1 << dimensions.PPx;
|
var precinctWidth = 1 << dimensions.PPx;
|
||||||
var precinctHeight = 1 << dimensions.PPy;
|
var precinctHeight = 1 << dimensions.PPy;
|
||||||
var numprecinctswide = resolution.trx1 > resolution.trx0 ?
|
var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
|
||||||
Math.ceil(resolution.trx1 / precinctWidth) -
|
Math.ceil(resolution.trx1 / precinctWidth) -
|
||||||
Math.floor(resolution.trx0 / precinctWidth) : 0;
|
Math.floor(resolution.trx0 / precinctWidth) : 0);
|
||||||
var numprecinctshigh = resolution.try1 > resolution.try0 ?
|
var numprecinctshigh = (resolution.try1 > resolution.try0 ?
|
||||||
Math.ceil(resolution.try1 / precinctHeight) -
|
Math.ceil(resolution.try1 / precinctHeight) -
|
||||||
Math.floor(resolution.try0 / precinctHeight) : 0;
|
Math.floor(resolution.try0 / precinctHeight) : 0);
|
||||||
var numprecincts = numprecinctswide * numprecinctshigh;
|
var numprecincts = numprecinctswide * numprecinctshigh;
|
||||||
var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
|
var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
|
||||||
precinctWidth;
|
precinctWidth;
|
||||||
var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
|
var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
|
||||||
precinctHeight;
|
precinctHeight;
|
||||||
resolution.precinctParameters = {
|
resolution.precinctParameters = {
|
||||||
precinctXOffset: precinctXOffset,
|
precinctXOffset: precinctXOffset,
|
||||||
precinctYOffset: precinctYOffset,
|
precinctYOffset: precinctYOffset,
|
||||||
@ -472,13 +479,13 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
};
|
};
|
||||||
// calculate precinct number
|
// calculate precinct number
|
||||||
var pi = Math.floor((codeblock.tbx0 -
|
var pi = Math.floor((codeblock.tbx0 -
|
||||||
precinctParameters.precinctXOffset) /
|
precinctParameters.precinctXOffset) /
|
||||||
precinctParameters.precinctWidth);
|
precinctParameters.precinctWidth);
|
||||||
var pj = Math.floor((codeblock.tby0 -
|
var pj = Math.floor((codeblock.tby0 -
|
||||||
precinctParameters.precinctYOffset) /
|
precinctParameters.precinctYOffset) /
|
||||||
precinctParameters.precinctHeight);
|
precinctParameters.precinctHeight);
|
||||||
var precinctNumber = pj +
|
var precinctNumber = pj +
|
||||||
pi * precinctParameters.numprecinctswide;
|
pi * precinctParameters.numprecinctswide;
|
||||||
codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
|
codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
|
||||||
codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
|
codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
|
||||||
codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
|
codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
|
||||||
@ -486,7 +493,7 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
codeblock.precinctNumber = precinctNumber;
|
codeblock.precinctNumber = precinctNumber;
|
||||||
codeblock.subbandType = subband.type;
|
codeblock.subbandType = subband.type;
|
||||||
var coefficientsLength = (codeblock.tbx1_ - codeblock.tbx0_) *
|
var coefficientsLength = (codeblock.tbx1_ - codeblock.tbx0_) *
|
||||||
(codeblock.tby1_ - codeblock.tby0_);
|
(codeblock.tby1_ - codeblock.tby0_);
|
||||||
codeblock.Lblock = 3;
|
codeblock.Lblock = 3;
|
||||||
codeblocks.push(codeblock);
|
codeblocks.push(codeblock);
|
||||||
// building precinct for the sub-band
|
// building precinct for the sub-band
|
||||||
@ -562,8 +569,9 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
for (; r <= maxDecompositionLevelsCount; r++) {
|
for (; r <= maxDecompositionLevelsCount; r++) {
|
||||||
for (; i < componentsCount; i++) {
|
for (; i < componentsCount; i++) {
|
||||||
var component = tile.components[i];
|
var component = tile.components[i];
|
||||||
if (r > component.codingStyleParameters.decompositionLevelsCount)
|
if (r > component.codingStyleParameters.decompositionLevelsCount) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var resolution = component.resolutions[r];
|
var resolution = component.resolutions[r];
|
||||||
var numprecincts = resolution.precinctParameters.numprecincts;
|
var numprecincts = resolution.precinctParameters.numprecincts;
|
||||||
@ -601,8 +609,9 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
for (; l < layersCount; l++) {
|
for (; l < layersCount; l++) {
|
||||||
for (; i < componentsCount; i++) {
|
for (; i < componentsCount; i++) {
|
||||||
var component = tile.components[i];
|
var component = tile.components[i];
|
||||||
if (r > component.codingStyleParameters.decompositionLevelsCount)
|
if (r > component.codingStyleParameters.decompositionLevelsCount) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var resolution = component.resolutions[r];
|
var resolution = component.resolutions[r];
|
||||||
var numprecincts = resolution.precinctParameters.numprecincts;
|
var numprecincts = resolution.precinctParameters.numprecincts;
|
||||||
@ -884,7 +893,7 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
|
|
||||||
var bitModel, currentCodingpassType;
|
var bitModel, currentCodingpassType;
|
||||||
bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
|
bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
|
||||||
codeblock.zeroBitPlanes);
|
codeblock.zeroBitPlanes);
|
||||||
currentCodingpassType = 2; // first bit plane starts from cleanup
|
currentCodingpassType = 2; // first bit plane starts from cleanup
|
||||||
|
|
||||||
// collect data
|
// collect data
|
||||||
@ -955,8 +964,8 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
var precision = context.components[c].precision;
|
var precision = context.components[c].precision;
|
||||||
|
|
||||||
var transformation = codingStyleParameters.transformation;
|
var transformation = codingStyleParameters.transformation;
|
||||||
var transform = transformation === TransformType.IRREVERSIBLE ?
|
var transform = (transformation === TransformType.IRREVERSIBLE ?
|
||||||
new IrreversibleTransform() : new ReversibleTransform();
|
new IrreversibleTransform() : new ReversibleTransform());
|
||||||
|
|
||||||
var subbandCoefficients = [];
|
var subbandCoefficients = [];
|
||||||
var k = 0, b = 0;
|
var k = 0, b = 0;
|
||||||
@ -980,8 +989,8 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
var gainLog2 = SubbandsGainLog2[subband.type];
|
var gainLog2 = SubbandsGainLog2[subband.type];
|
||||||
|
|
||||||
// calulate quantization coefficient (Section E.1.1.1)
|
// calulate quantization coefficient (Section E.1.1.1)
|
||||||
var delta = transformation === TransformType.IRREVERSIBLE ?
|
var delta = (transformation === TransformType.IRREVERSIBLE ?
|
||||||
Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048) : 1;
|
Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048) : 1);
|
||||||
var mb = (guardBits + epsilon - 1);
|
var mb = (guardBits + epsilon - 1);
|
||||||
|
|
||||||
var coefficients = new Float32Array(width * height);
|
var coefficients = new Float32Array(width * height);
|
||||||
@ -1000,7 +1009,7 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var result = transform.calculate(subbandCoefficients,
|
var result = transform.calculate(subbandCoefficients,
|
||||||
component.tcx0, component.tcy0);
|
component.tcx0, component.tcy0);
|
||||||
return {
|
return {
|
||||||
left: component.tcx0,
|
left: component.tcx0,
|
||||||
top: component.tcy0,
|
top: component.tcy0,
|
||||||
@ -1093,11 +1102,11 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
var resultTiles = [];
|
var resultTiles = [];
|
||||||
for (var c = 0; c < componentsCount; c++) {
|
for (var c = 0; c < componentsCount; c++) {
|
||||||
var component = tile.components[c];
|
var component = tile.components[c];
|
||||||
var qcdOrQcc = c in context.currentTile.QCC ?
|
var qcdOrQcc = (c in context.currentTile.QCC ?
|
||||||
context.currentTile.QCC[c] : context.currentTile.QCD;
|
context.currentTile.QCC[c] : context.currentTile.QCD);
|
||||||
component.quantizationParameters = qcdOrQcc;
|
component.quantizationParameters = qcdOrQcc;
|
||||||
var codOrCoc = c in context.currentTile.COC ?
|
var codOrCoc = (c in context.currentTile.COC ?
|
||||||
context.currentTile.COC[c] : context.currentTile.COD;
|
context.currentTile.COC[c] : context.currentTile.COD);
|
||||||
component.codingStyleParameters = codOrCoc;
|
component.codingStyleParameters = codOrCoc;
|
||||||
}
|
}
|
||||||
tile.codingStyleDefaultParameters = context.currentTile.COD;
|
tile.codingStyleDefaultParameters = context.currentTile.COD;
|
||||||
@ -1458,8 +1467,8 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
this.contextLabelTable = subband == 'HH' ? HHContextLabel :
|
this.contextLabelTable = (subband == 'HH' ? HHContextLabel :
|
||||||
subband == 'HL' ? HLContextLabel : LLAndLHContextsLabel;
|
(subband == 'HL' ? HLContextLabel : LLAndLHContextsLabel));
|
||||||
|
|
||||||
var coefficientCount = width * height;
|
var coefficientCount = width * height;
|
||||||
|
|
||||||
@ -1471,8 +1480,9 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
this.processingFlags = new Uint8Array(coefficientCount);
|
this.processingFlags = new Uint8Array(coefficientCount);
|
||||||
|
|
||||||
var bitsDecoded = new Uint8Array(this.width * this.height);
|
var bitsDecoded = new Uint8Array(this.width * this.height);
|
||||||
for (var i = 0, ii = bitsDecoded.length; i < ii; i++)
|
for (var i = 0, ii = bitsDecoded.length; i < ii; i++) {
|
||||||
bitsDecoded[i] = zeroBitPlanes;
|
bitsDecoded[i] = zeroBitPlanes;
|
||||||
|
}
|
||||||
this.bitsDecoded = bitsDecoded;
|
this.bitsDecoded = bitsDecoded;
|
||||||
|
|
||||||
this.reset();
|
this.reset();
|
||||||
@ -1551,8 +1561,10 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coefficentsMagnitude[index] || !neighborsSignificance[index])
|
if (coefficentsMagnitude[index] ||
|
||||||
|
!neighborsSignificance[index]) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var contextLabel = labels[neighborsSignificance[index]];
|
var contextLabel = labels[neighborsSignificance[index]];
|
||||||
var cx = contexts[contextLabel];
|
var cx = contexts[contextLabel];
|
||||||
@ -1620,8 +1632,7 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var contextLabel = 16;
|
var contextLabel = 16;
|
||||||
if ((processingFlags[index] &
|
if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
|
||||||
firstMagnitudeBitMask) !== 0) {
|
|
||||||
processingFlags[i * width + j] ^= firstMagnitudeBitMask;
|
processingFlags[i * width + j] ^= firstMagnitudeBitMask;
|
||||||
// first refinement
|
// first refinement
|
||||||
var significance = neighborsSignificance[index];
|
var significance = neighborsSignificance[index];
|
||||||
@ -1661,7 +1672,7 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
var index0 = i0 * width + j;
|
var index0 = i0 * width + j;
|
||||||
// using the property: labels[neighborsSignificance[index]] == 0
|
// using the property: labels[neighborsSignificance[index]] == 0
|
||||||
// when neighborsSignificance[index] == 0
|
// when neighborsSignificance[index] == 0
|
||||||
var allEmpty = i0 + 3 < height &&
|
var allEmpty = (i0 + 3 < height &&
|
||||||
processingFlags[index0] === 0 &&
|
processingFlags[index0] === 0 &&
|
||||||
processingFlags[index0 + oneRowDown] === 0 &&
|
processingFlags[index0 + oneRowDown] === 0 &&
|
||||||
processingFlags[index0 + twoRowsDown] === 0 &&
|
processingFlags[index0 + twoRowsDown] === 0 &&
|
||||||
@ -1669,7 +1680,7 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
neighborsSignificance[index0] === 0 &&
|
neighborsSignificance[index0] === 0 &&
|
||||||
neighborsSignificance[index0 + oneRowDown] === 0 &&
|
neighborsSignificance[index0 + oneRowDown] === 0 &&
|
||||||
neighborsSignificance[index0 + twoRowsDown] === 0 &&
|
neighborsSignificance[index0 + twoRowsDown] === 0 &&
|
||||||
neighborsSignificance[index0 + threeRowsDown] === 0;
|
neighborsSignificance[index0 + threeRowsDown] === 0);
|
||||||
var i1 = 0, index = index0;
|
var i1 = 0, index = index0;
|
||||||
var cx, i;
|
var cx, i;
|
||||||
if (allEmpty) {
|
if (allEmpty) {
|
||||||
@ -1740,10 +1751,10 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
return BitModel;
|
return BitModel;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Section F, Discrete wavelet transofrmation
|
// Section F, Discrete wavelet transformation
|
||||||
var Transform = (function TransformClosure() {
|
var Transform = (function TransformClosure() {
|
||||||
function Transform() {
|
function Transform() {}
|
||||||
}
|
|
||||||
Transform.prototype.calculate =
|
Transform.prototype.calculate =
|
||||||
function transformCalculate(subbands, u0, v0) {
|
function transformCalculate(subbands, u0, v0) {
|
||||||
var ll = subbands[0];
|
var ll = subbands[0];
|
||||||
@ -1754,17 +1765,17 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
return ll;
|
return ll;
|
||||||
};
|
};
|
||||||
Transform.prototype.extend = function extend(buffer, offset, size) {
|
Transform.prototype.extend = function extend(buffer, offset, size) {
|
||||||
// Section F.3.7 extending... using max extension of 4
|
// Section F.3.7 extending... using max extension of 4
|
||||||
var i1 = offset - 1, j1 = offset + 1;
|
var i1 = offset - 1, j1 = offset + 1;
|
||||||
var i2 = offset + size - 2, j2 = offset + size;
|
var i2 = offset + size - 2, j2 = offset + size;
|
||||||
buffer[i1--] = buffer[j1++];
|
buffer[i1--] = buffer[j1++];
|
||||||
buffer[j2++] = buffer[i2--];
|
buffer[j2++] = buffer[i2--];
|
||||||
buffer[i1--] = buffer[j1++];
|
buffer[i1--] = buffer[j1++];
|
||||||
buffer[j2++] = buffer[i2--];
|
buffer[j2++] = buffer[i2--];
|
||||||
buffer[i1--] = buffer[j1++];
|
buffer[i1--] = buffer[j1++];
|
||||||
buffer[j2++] = buffer[i2--];
|
buffer[j2++] = buffer[i2--];
|
||||||
buffer[i1] = buffer[j1];
|
buffer[i1] = buffer[j1];
|
||||||
buffer[j2] = buffer[i2];
|
buffer[j2] = buffer[i2];
|
||||||
};
|
};
|
||||||
Transform.prototype.iterate = function Transform_iterate(ll, hl, lh, hh,
|
Transform.prototype.iterate = function Transform_iterate(ll, hl, lh, hh,
|
||||||
u0, v0) {
|
u0, v0) {
|
||||||
@ -1906,33 +1917,39 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
|
|
||||||
// step 1
|
// step 1
|
||||||
var j = offset_ - 2;
|
var j = offset_ - 2;
|
||||||
for (var n = i0_ - 1, nn = i1_ + 2; n < nn; n++, j += 2)
|
for (var n = i0_ - 1, nn = i1_ + 2; n < nn; n++, j += 2) {
|
||||||
x[j] = K * y[j];
|
x[j] = K * y[j];
|
||||||
|
}
|
||||||
|
|
||||||
// step 2
|
// step 2
|
||||||
var j = offset_ - 3;
|
var j = offset_ - 3;
|
||||||
for (var n = i0_ - 2, nn = i1_ + 2; n < nn; n++, j += 2)
|
for (var n = i0_ - 2, nn = i1_ + 2; n < nn; n++, j += 2) {
|
||||||
x[j] = K_ * y[j];
|
x[j] = K_ * y[j];
|
||||||
|
}
|
||||||
|
|
||||||
// step 3
|
// step 3
|
||||||
var j = offset_ - 2;
|
var j = offset_ - 2;
|
||||||
for (var n = i0_ - 1, nn = i1_ + 2; n < nn; n++, j += 2)
|
for (var n = i0_ - 1, nn = i1_ + 2; n < nn; n++, j += 2) {
|
||||||
x[j] -= delta * (x[j - 1] + x[j + 1]);
|
x[j] -= delta * (x[j - 1] + x[j + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
// step 4
|
// step 4
|
||||||
var j = offset_ - 1;
|
var j = offset_ - 1;
|
||||||
for (var n = i0_ - 1, nn = i1_ + 1; n < nn; n++, j += 2)
|
for (var n = i0_ - 1, nn = i1_ + 1; n < nn; n++, j += 2) {
|
||||||
x[j] -= gamma * (x[j - 1] + x[j + 1]);
|
x[j] -= gamma * (x[j - 1] + x[j + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
// step 5
|
// step 5
|
||||||
var j = offset_;
|
var j = offset_;
|
||||||
for (var n = i0_, nn = i1_ + 1; n < nn; n++, j += 2)
|
for (var n = i0_, nn = i1_ + 1; n < nn; n++, j += 2) {
|
||||||
x[j] -= beta * (x[j - 1] + x[j + 1]);
|
x[j] -= beta * (x[j - 1] + x[j + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
// step 6
|
// step 6
|
||||||
var j = offset_ + 1;
|
var j = offset_ + 1;
|
||||||
for (var n = i0_, nn = i1_; n < nn; n++, j += 2)
|
for (var n = i0_, nn = i1_; n < nn; n++, j += 2) {
|
||||||
x[j] -= alpha * (x[j - 1] + x[j + 1]);
|
x[j] -= alpha * (x[j - 1] + x[j + 1]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return IrreversibleTransform;
|
return IrreversibleTransform;
|
||||||
@ -1951,11 +1968,13 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
var i1_ = Math.floor((i0 + length) / 2);
|
var i1_ = Math.floor((i0 + length) / 2);
|
||||||
var offset_ = offset - (i0 % 1);
|
var offset_ = offset - (i0 % 1);
|
||||||
|
|
||||||
for (var n = i0_, nn = i1_ + 1, j = offset_; n < nn; n++, j += 2)
|
for (var n = i0_, nn = i1_ + 1, j = offset_; n < nn; n++, j += 2) {
|
||||||
x[j] = y[j] - Math.floor((y[j - 1] + y[j + 1] + 2) / 4);
|
x[j] = y[j] - Math.floor((y[j - 1] + y[j + 1] + 2) / 4);
|
||||||
|
}
|
||||||
|
|
||||||
for (var n = i0_, nn = i1_, j = offset_ + 1; n < nn; n++, j += 2)
|
for (var n = i0_, nn = i1_, j = offset_ + 1; n < nn; n++, j += 2) {
|
||||||
x[j] = y[j] + Math.floor((x[j - 1] + x[j + 1]) / 2);
|
x[j] = y[j] + Math.floor((x[j - 1] + x[j + 1]) / 2);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return ReversibleTransform;
|
return ReversibleTransform;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user