Address review comments

This commit is contained in:
notmasteryet 2012-01-13 18:24:02 -06:00
parent 8af527919a
commit 5b6c06d5c6

View File

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