Fix #3591 / list unsupported options
This commit is contained in:
parent
a45e10337c
commit
894d9fe085
@ -14,7 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals ArithmeticDecoder, error, globalScope, log2, readUint16, readUint32,
|
/* globals ArithmeticDecoder, globalScope, log2, readUint16, readUint32,
|
||||||
warn */
|
warn */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -58,7 +58,7 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
lbox = length - position + headerSize;
|
lbox = length - position + headerSize;
|
||||||
}
|
}
|
||||||
if (lbox < headerSize) {
|
if (lbox < headerSize) {
|
||||||
error('JPX error: Invalid box field size');
|
throw 'JPX error: Invalid box field size';
|
||||||
}
|
}
|
||||||
var dataLength = lbox - headerSize;
|
var dataLength = lbox - headerSize;
|
||||||
var jumpDataLength = true;
|
var jumpDataLength = true;
|
||||||
@ -82,41 +82,34 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
parseImageProperties: function JpxImage_parseImageProperties(stream) {
|
parseImageProperties: function JpxImage_parseImageProperties(stream) {
|
||||||
try {
|
var newByte = stream.getByte();
|
||||||
var newByte = stream.getByte();
|
while (newByte >= 0) {
|
||||||
while (newByte >= 0) {
|
var oldByte = newByte;
|
||||||
var oldByte = newByte;
|
newByte = stream.getByte();
|
||||||
newByte = stream.getByte();
|
var code = (oldByte << 8) | newByte;
|
||||||
var code = (oldByte << 8) | newByte;
|
// Image and tile size (SIZ)
|
||||||
// Image and tile size (SIZ)
|
if (code == 0xFF51) {
|
||||||
if (code == 0xFF51) {
|
stream.skip(4);
|
||||||
stream.skip(4);
|
var Xsiz = stream.getInt32() >>> 0; // Byte 4
|
||||||
var Xsiz = stream.getInt32() >>> 0; // Byte 4
|
var Ysiz = stream.getInt32() >>> 0; // Byte 8
|
||||||
var Ysiz = stream.getInt32() >>> 0; // Byte 8
|
var XOsiz = stream.getInt32() >>> 0; // Byte 12
|
||||||
var XOsiz = stream.getInt32() >>> 0; // Byte 12
|
var YOsiz = stream.getInt32() >>> 0; // Byte 16
|
||||||
var YOsiz = stream.getInt32() >>> 0; // Byte 16
|
stream.skip(16);
|
||||||
stream.skip(16);
|
var Csiz = stream.getUint16(); // Byte 36
|
||||||
var Csiz = stream.getUint16(); // Byte 36
|
this.width = Xsiz - XOsiz;
|
||||||
this.width = Xsiz - XOsiz;
|
this.height = Ysiz - YOsiz;
|
||||||
this.height = Ysiz - YOsiz;
|
this.componentsCount = Csiz;
|
||||||
this.componentsCount = Csiz;
|
// Results are always returned as Uint8Arrays
|
||||||
// Results are always returned as Uint8Arrays
|
this.bitsPerComponent = 8;
|
||||||
this.bitsPerComponent = 8;
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw 'No size marker found in JPX stream';
|
|
||||||
} catch (e) {
|
|
||||||
if (this.failOnCorruptedImage) {
|
|
||||||
error('JPX error: ' + e);
|
|
||||||
} else {
|
|
||||||
warn('JPX error: ' + e + '. Trying to recover');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
throw 'JPX error: No size marker found in JPX stream';
|
||||||
},
|
},
|
||||||
parseCodestream: function JpxImage_parseCodestream(data, start, end) {
|
parseCodestream: function JpxImage_parseCodestream(data, start, end) {
|
||||||
var context = {};
|
var context = {};
|
||||||
try {
|
try {
|
||||||
|
var doNotRecover = false;
|
||||||
var position = start;
|
var position = start;
|
||||||
while (position + 1 < end) {
|
while (position + 1 < end) {
|
||||||
var code = readUint16(data, position);
|
var code = readUint16(data, position);
|
||||||
@ -160,6 +153,11 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
context.QCC = [];
|
context.QCC = [];
|
||||||
context.COC = [];
|
context.COC = [];
|
||||||
break;
|
break;
|
||||||
|
case 0xFF55: // Tile-part lengths, main header (TLM)
|
||||||
|
var Ltlm = readUint16(data, position); // Marker segment length
|
||||||
|
// Skip tile length markers
|
||||||
|
position += Ltlm;
|
||||||
|
break;
|
||||||
case 0xFF5C: // Quantization default (QCD)
|
case 0xFF5C: // Quantization default (QCD)
|
||||||
length = readUint16(data, position);
|
length = readUint16(data, position);
|
||||||
var qcd = {};
|
var qcd = {};
|
||||||
@ -291,16 +289,33 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
}
|
}
|
||||||
cod.precinctsSizes = precinctsSizes;
|
cod.precinctsSizes = precinctsSizes;
|
||||||
}
|
}
|
||||||
|
var unsupported = [];
|
||||||
if (cod.sopMarkerUsed || cod.ephMarkerUsed ||
|
if (cod.sopMarkerUsed) {
|
||||||
cod.selectiveArithmeticCodingBypass ||
|
unsupported.push('sopMarkerUsed');
|
||||||
cod.resetContextProbabilities ||
|
}
|
||||||
cod.terminationOnEachCodingPass ||
|
if (cod.ephMarkerUsed) {
|
||||||
cod.verticalyStripe || cod.predictableTermination) {
|
unsupported.push('ephMarkerUsed');
|
||||||
throw 'Unsupported COD options: ' +
|
}
|
||||||
globalScope.JSON.stringify(cod);
|
if (cod.selectiveArithmeticCodingBypass) {
|
||||||
|
unsupported.push('selectiveArithmeticCodingBypass');
|
||||||
|
}
|
||||||
|
if (cod.resetContextProbabilities) {
|
||||||
|
unsupported.push('resetContextProbabilities');
|
||||||
|
}
|
||||||
|
if (cod.terminationOnEachCodingPass) {
|
||||||
|
unsupported.push('terminationOnEachCodingPass');
|
||||||
|
}
|
||||||
|
if (cod.verticalyStripe) {
|
||||||
|
unsupported.push('verticalyStripe');
|
||||||
|
}
|
||||||
|
if (cod.predictableTermination) {
|
||||||
|
unsupported.push('predictableTermination');
|
||||||
|
}
|
||||||
|
if (unsupported.length > 0) {
|
||||||
|
doNotRecover = true;
|
||||||
|
throw 'Unsupported COD options (' + unsupported.join(', ') +
|
||||||
|
')';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.mainHeader) {
|
if (context.mainHeader) {
|
||||||
context.COD = cod;
|
context.COD = cod;
|
||||||
} else {
|
} else {
|
||||||
@ -350,8 +365,8 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
position += length;
|
position += length;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (this.failOnCorruptedImage) {
|
if (doNotRecover || this.failOnCorruptedImage) {
|
||||||
error('JPX error: ' + e);
|
throw 'JPX error: ' + e;
|
||||||
} else {
|
} else {
|
||||||
warn('JPX error: ' + e + '. Trying to recover');
|
warn('JPX error: ' + e + '. Trying to recover');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user