mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 23:28:06 +02:00
Merge pull request #1837 from yurydelendik/jbig2-1
JBIG2 implementation
This commit is contained in:
commit
f90a05f5f8
11 changed files with 1112 additions and 1 deletions
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'
|
||||
];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue