return bytesToString(this.bytes);
};
JpegStream.prototype.getChar = function jpegStreamGetChar() {
- error('internal error: getChar is not valid on JpegStream');
+ error('internal error: getChar is not valid on JpegStream');
};
/**
* Checks if the image can be decoded and displayed by the browser without any
* For JPEG 2000's we use a library to decode these images and
* the stream behaves like all the other DecodeStreams.
*/
-var JpxStream = (function jpxStream() {
- function constructor(bytes, dict) {
+var JpxStream = (function JpxStreamClosure() {
+ function JpxStream(bytes, dict) {
this.dict = dict;
this.bytes = bytes;
DecodeStream.call(this);
}
- constructor.prototype = Object.create(DecodeStream.prototype);
+ JpxStream.prototype = Object.create(DecodeStream.prototype);
- constructor.prototype.ensureBuffer = function jpxStreamEnsureBuffer(req) {
+ JpxStream.prototype.ensureBuffer = function jpxStreamEnsureBuffer(req) {
if (this.bufferLength)
return;
var data = new Uint8Array(width * height * componentsCount);
for (var k = 0, kk = jpxImage.tiles.length; k < kk; k++) {
- var tile = jpxImage.tiles[k];
- var tileWidth = tile[0].width;
- var tileHeight = tile[0].height;
- var tileLeft = tile[0].left;
- var tileTop = tile[0].top;
-
- var data0 = tile[0].items;
- var data1 = componentsCount > 1 ? tile[1].items : null;
- var data2 = componentsCount > 1 ? tile[2].items : null;
- var data3 = componentsCount > 3 ? tile[3].items : null;
-
- var dataPosition = (width * tileTop + tileLeft) * componentsCount;
- var sourcePosition = 0;
- for (var j = 0; j < tileHeight; j++) {
- for (var i = 0; i < tileWidth; i++) {
- data[dataPosition++] = data0[sourcePosition];
- if (componentsCount > 1) {
- data[dataPosition++] = data1[sourcePosition];
- data[dataPosition++] = data2[sourcePosition];
- if (componentsCount > 3)
+ var tileCompoments = jpxImage.tiles[k];
+ var tileWidth = tileCompoments[0].width;
+ var tileHeight = tileCompoments[0].height;
+ var tileLeft = tileCompoments[0].left;
+ var tileTop = tileCompoments[0].top;
+
+ var dataPosition, sourcePosition, data0, data1, data2, data3, rowFeed;
+ switch (componentsCount) {
+ case 1:
+ data0 = tileCompoments[0].items;
+
+ dataPosition = width * tileTop + tileLeft;
+ rowFeed = width - tileWidth;
+ sourcePosition = 0;
+ for (var j = 0; j < tileHeight; j++) {
+ for (var i = 0; i < tileWidth; i++)
+ data[dataPosition++] = data0[sourcePosition++];
+ dataPosition += rowFeed;
+ }
+ break;
+ case 3:
+ data0 = tileCompoments[0].items;
+ data1 = tileCompoments[1].items;
+ data2 = tileCompoments[2].items;
+
+ dataPosition = (width * tileTop + tileLeft) * 3;
+ rowFeed = (width - tileWidth) * 3;
+ sourcePosition = 0;
+ for (var j = 0; j < tileHeight; j++) {
+ for (var i = 0; i < tileWidth; i++) {
+ data[dataPosition++] = data0[sourcePosition];
+ data[dataPosition++] = data1[sourcePosition];
+ data[dataPosition++] = data2[sourcePosition];
+ sourcePosition++;
+ }
+ dataPosition += rowFeed;
+ }
+ break;
+ case 4:
+ data0 = tileCompoments[0].items;
+ data1 = tileCompoments[1].items;
+ data2 = tileCompoments[2].items;
+ data3 = tileCompoments[3].items;
+
+ dataPosition = (width * tileTop + tileLeft) * 4;
+ rowFeed = (width - tileWidth) * 4;
+ sourcePosition = 0;
+ for (var j = 0; j < tileHeight; j++) {
+ for (var i = 0; i < tileWidth; i++) {
+ data[dataPosition++] = data0[sourcePosition];
+ data[dataPosition++] = data1[sourcePosition];
+ data[dataPosition++] = data2[sourcePosition];
data[dataPosition++] = data3[sourcePosition];
+ sourcePosition++;
+ }
+ dataPosition += rowFeed;
}
- sourcePosition++;
- }
- dataPosition += componentsCount * (width - tileWidth);
+ break;
}
}
this.buffer = data;
this.bufferLength = data.length;
};
- constructor.prototype.getIR = function jpxStreamGetIR() {
- return this.src;
- };
- constructor.prototype.getChar = function jpxStreamGetChar() {
- error('internal error: getChar is not valid on JpxStream');
+ JpxStream.prototype.getChar = function jpxStreamGetChar() {
+ error('internal error: getChar is not valid on JpxStream');
};
- return constructor;
+ return JpxStream;
})();
var DecryptStream = (function DecryptStreamClosure() {