Migration of the JPX code (from jpx5)

This commit is contained in:
notmasteryet 2012-01-11 20:08:46 -06:00
parent 93bb2cf0d3
commit 93ca387d1b
6 changed files with 1905 additions and 1 deletions

1826
src/jpx.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -240,6 +240,10 @@ var Parser = (function ParserClosure() {
var bytes = stream.getBytes(length);
return new JpegStream(bytes, stream.dict, this.xref);
}
if (name == 'JPXDecode' || name == 'JPX') {
var bytes = stream.getBytes(length);
return new JpxStream(bytes, stream.dict);
}
if (name == 'ASCII85Decode' || name == 'A85') {
return new Ascii85Stream(stream);
}

View File

@ -869,6 +869,77 @@ var JpegStream = (function JpegStreamClosure() {
return JpegStream;
})();
/**
* 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) {
this.dict = dict;
this.bytes = bytes;
DecodeStream.call(this);
}
constructor.prototype = Object.create(DecodeStream.prototype);
constructor.prototype.ensureBuffer = function jpxStreamEnsureBuffer(req) {
if (this.bufferLength)
return;
var jpxImage = new JpxImage();
jpxImage.parse(this.bytes);
var width = jpxImage.width;
var height = jpxImage.height;
var componentsCount = jpxImage.componentsCount;
if (componentsCount != 1 && componentsCount != 3 && componentsCount != 4)
error('JPX with ' + componentsCount + ' components is not supported');
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)
data[dataPosition++] = data3[sourcePosition];
}
sourcePosition++;
}
dataPosition += componentsCount * (width - tileWidth);
}
}
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');
};
return constructor;
})();
var DecryptStream = (function DecryptStreamClosure() {
function DecryptStream(str, decrypt) {
this.str = str;

View File

@ -23,7 +23,8 @@ var files = [
'pattern.js',
'stream.js',
'worker.js',
'../external/jpgjs/jpg.js'
'../external/jpgjs/jpg.js',
'jpx.js'
];
// Load all the files.

View File

@ -22,6 +22,7 @@
<script type="text/javascript" src="/src/stream.js"></script>
<script type="text/javascript" src="/src/worker.js"></script>
<script type="text/javascript" src="/external/jpgjs/jpg.js"></script>
<script type="text/javascript" src="/src/jpx.js"></script>
<script type="text/javascript" src="driver.js"></script>
<script type="text/javascript">

View File

@ -26,6 +26,7 @@
<script type="text/javascript" src="../src/stream.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
<script type="text/javascript" src="../src/worker.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
<script type="text/javascript" src="../external/jpgjs/jpg.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
<script type="text/javascript" src="../src/jpx.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
<script type="text/javascript">PDFJS.workerSrc = '../src/worker_loader.js';</script> <!-- PDFJSSCRIPT_REMOVE -->
<script type="text/javascript" src="viewer.js"></script>