Merge pull request #1242 from notmasteryet/bad-jpx-1
Recovering from the bad JPX images (#1145)
This commit is contained in:
commit
f45f87b70b
22
src/jpx.js
22
src/jpx.js
@ -1052,7 +1052,7 @@ var JpxImage = (function JpxImageClosure() {
|
||||
}
|
||||
r = 0;
|
||||
}
|
||||
error('JPX error: Out of packets');
|
||||
throw 'Out of packets';
|
||||
};
|
||||
}
|
||||
function ResolutionLayerComponentPositionIterator(context) {
|
||||
@ -1091,7 +1091,7 @@ var JpxImage = (function JpxImageClosure() {
|
||||
}
|
||||
l = 0;
|
||||
}
|
||||
error('JPX error: Out of packets');
|
||||
throw 'Out of packets';
|
||||
};
|
||||
}
|
||||
function buildPackets(context) {
|
||||
@ -1187,7 +1187,7 @@ var JpxImage = (function JpxImageClosure() {
|
||||
new ResolutionLayerComponentPositionIterator(context);
|
||||
break;
|
||||
default:
|
||||
error('JPX error: Unsupported progression order ' + progressionOrder);
|
||||
throw 'Unsupported progression order ' + progressionOrder;
|
||||
}
|
||||
}
|
||||
function parseTilePackets(context, data, offset, dataLength) {
|
||||
@ -1553,6 +1553,7 @@ var JpxImage = (function JpxImageClosure() {
|
||||
}
|
||||
|
||||
function JpxImage() {
|
||||
this.failOnCorruptedImage = false;
|
||||
}
|
||||
JpxImage.prototype = {
|
||||
load: function jpxImageLoad(url) {
|
||||
@ -1612,6 +1613,7 @@ var JpxImage = (function JpxImageClosure() {
|
||||
},
|
||||
parseCodestream: function jpxImageParseCodestream(data, start, end) {
|
||||
var context = {};
|
||||
try {
|
||||
var position = start;
|
||||
while (position < end) {
|
||||
var code = readUint16(data, position);
|
||||
@ -1675,7 +1677,7 @@ var JpxImage = (function JpxImageClosure() {
|
||||
scalarExpounded = true;
|
||||
break;
|
||||
default:
|
||||
error('JPX error: Invalid SQcd value ' + sqcd);
|
||||
throw 'Invalid SQcd value ' + sqcd;
|
||||
}
|
||||
qcd.noQuantization = spqcdSize == 8;
|
||||
qcd.scalarExpounded = scalarExpounded;
|
||||
@ -1728,7 +1730,7 @@ var JpxImage = (function JpxImageClosure() {
|
||||
scalarExpounded = true;
|
||||
break;
|
||||
default:
|
||||
error('JPX error: Invalid SQcd value ' + sqcd);
|
||||
throw 'Invalid SQcd value ' + sqcd;
|
||||
}
|
||||
qcc.noQuantization = spqcdSize == 8;
|
||||
qcc.scalarExpounded = scalarExpounded;
|
||||
@ -1795,7 +1797,7 @@ var JpxImage = (function JpxImageClosure() {
|
||||
cod.terminationOnEachCodingPass ||
|
||||
cod.verticalyStripe || cod.predictableTermination ||
|
||||
cod.segmentationSymbolUsed)
|
||||
error('JPX error: Unsupported COD options: ' + uneval(cod));
|
||||
throw 'Unsupported COD options: ' + uneval(cod);
|
||||
|
||||
if (context.mainHeader)
|
||||
context.COD = cod;
|
||||
@ -1840,10 +1842,16 @@ var JpxImage = (function JpxImageClosure() {
|
||||
// skipping content
|
||||
break;
|
||||
default:
|
||||
error('JPX error: Unknown codestream code: ' + code.toString(16));
|
||||
throw 'Unknown codestream code: ' + code.toString(16);
|
||||
}
|
||||
position += length;
|
||||
}
|
||||
} catch (e) {
|
||||
if (this.failOnCorruptedImage)
|
||||
error('JPX error: ' + e);
|
||||
else
|
||||
warn('JPX error: ' + e + '. Trying to recover');
|
||||
}
|
||||
this.tiles = transformComponents(context);
|
||||
this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
|
||||
this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
|
||||
|
Loading…
Reference in New Issue
Block a user