Merge pull request #1837 from yurydelendik/jbig2-1

JBIG2 implementation
This commit is contained in:
Brendan Dahl 2012-06-26 16:00:32 -07:00
commit f90a05f5f8
11 changed files with 1112 additions and 1 deletions

View File

@ -25,6 +25,7 @@
<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="../../src/jbig2.js"></script>
<script type="text/javascript">
// Specify the main script used to create a new PDF.JS web worker.

View File

@ -25,6 +25,7 @@
<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="../../src/jbig2.js"></script>
<script type="text/javascript">
// Specify the main script used to create a new PDF.JS web worker.

View File

@ -166,6 +166,7 @@ target.bundle = function() {
'worker.js',
'../external/jpgjs/jpg.js',
'jpx.js',
'jbig2.js',
'bidi.js',
'metadata.js'];

1051
src/jbig2.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -253,7 +253,8 @@ var Parser = (function ParserClosure() {
return new RunLengthStream(stream);
}
if (name == 'JBIG2Decode') {
error('JBIG2 image format is not currently supprted.');
var bytes = stream.getBytes(length);
return new Jbig2Stream(bytes, stream.dict);
}
warn('filter "' + name + '" not supported yet');
return stream;

View File

@ -979,6 +979,50 @@ var JpxStream = (function JpxStreamClosure() {
return JpxStream;
})();
/**
* For JBIG2's we use a library to decode these images and
* the stream behaves like all the other DecodeStreams.
*/
var Jbig2Stream = (function Jbig2StreamClosure() {
function Jbig2Stream(bytes, dict) {
this.dict = dict;
this.bytes = bytes;
DecodeStream.call(this);
}
Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
if (this.bufferLength)
return;
var jbig2Image = new Jbig2Image();
var chunks = [], decodeParams = this.dict.get('DecodeParms');
if (decodeParams && decodeParams.has('JBIG2Globals')) {
var globalsStream = decodeParams.get('JBIG2Globals');
var globals = globalsStream.getBytes();
chunks.push({data: globals, start: 0, end: globals.length});
}
chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
var data = jbig2Image.parseChunks(chunks);
var dataLength = data.length;
// JBIG2 had black as 1 and white as 0, inverting the colors
for (var i = 0; i < dataLength; i++)
data[i] ^= 0xFF;
this.buffer = data;
this.bufferLength = dataLength;
};
Jbig2Stream.prototype.getChar = function Jbig2Stream_getChar() {
error('internal error: getChar is not valid on Jbig2Stream');
};
return Jbig2Stream;
})();
var DecryptStream = (function DecryptStreamClosure() {
function DecryptStream(str, decrypt) {
this.str = str;

View File

@ -24,6 +24,7 @@ var files = [
'stream.js',
'worker.js',
'jpx.js',
'jbig2.js',
'bidi.js',
'../external/jpgjs/jpg.js'
];

View File

@ -0,0 +1 @@
http://www.freepatentsonline.com/pdf/documents/uspt/D661/USD661296/USD661296S1.pdf

View File

@ -589,6 +589,14 @@
"link": true,
"type": "eq"
},
{ "id": "issue1810",
"file": "pdfs/issue1810.pdf",
"md5": "b173a9dfb7bf00e1a298c6e8cb95c03e",
"rounds": 1,
"pageLimit": 3,
"link": true,
"type": "eq"
},
{ "id": "issue1597",
"file": "pdfs/issue1597.pdf",
"md5": "a5ebef467fd6e2fc0aeb56c9eb725ae3",

View File

@ -24,6 +24,7 @@
<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="/src/jbig2.js"></script>
<script type="text/javascript" src="/src/bidi.js"></script>
<script type="text/javascript" src="driver.js"></script>

View File

@ -35,6 +35,7 @@
<script type="text/javascript" src="../src/worker.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../external/jpgjs/jpg.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/jpx.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/jbig2.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/bidi.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript">PDFJS.workerSrc = '../src/worker_loader.js';</script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="debugger.js"></script>