Merge pull request #1837 from yurydelendik/jbig2-1
JBIG2 implementation
This commit is contained in:
commit
f90a05f5f8
@ -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.
|
||||
|
@ -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.
|
||||
|
1
make.js
1
make.js
@ -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
1051
src/jbig2.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -24,6 +24,7 @@ var files = [
|
||||
'stream.js',
|
||||
'worker.js',
|
||||
'jpx.js',
|
||||
'jbig2.js',
|
||||
'bidi.js',
|
||||
'../external/jpgjs/jpg.js'
|
||||
];
|
||||
|
1
test/pdfs/issue1810.pdf.link
Normal file
1
test/pdfs/issue1810.pdf.link
Normal file
@ -0,0 +1 @@
|
||||
http://www.freepatentsonline.com/pdf/documents/uspt/D661/USD661296/USD661296S1.pdf
|
@ -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",
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user