|
|
@ -3,8 +3,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
'use strict'; |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
var Stream = (function streamStream() { |
|
|
|
var Stream = (function StreamClosure() { |
|
|
|
function constructor(arrayBuffer, start, length, dict) { |
|
|
|
function Stream(arrayBuffer, start, length, dict) { |
|
|
|
this.bytes = new Uint8Array(arrayBuffer); |
|
|
|
this.bytes = new Uint8Array(arrayBuffer); |
|
|
|
this.start = start || 0; |
|
|
|
this.start = start || 0; |
|
|
|
this.pos = this.start; |
|
|
|
this.pos = this.start; |
|
|
@ -14,7 +14,7 @@ var Stream = (function streamStream() { |
|
|
|
|
|
|
|
|
|
|
|
// required methods for a stream. if a particular stream does not
|
|
|
|
// required methods for a stream. if a particular stream does not
|
|
|
|
// implement these, an error should be thrown
|
|
|
|
// implement these, an error should be thrown
|
|
|
|
constructor.prototype = { |
|
|
|
Stream.prototype = { |
|
|
|
get length() { |
|
|
|
get length() { |
|
|
|
return this.end - this.start; |
|
|
|
return this.end - this.start; |
|
|
|
}, |
|
|
|
}, |
|
|
@ -67,11 +67,11 @@ var Stream = (function streamStream() { |
|
|
|
isStream: true |
|
|
|
isStream: true |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return Stream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
var StringStream = (function stringStream() { |
|
|
|
var StringStream = (function StringStreamClosure() { |
|
|
|
function constructor(str) { |
|
|
|
function StringStream(str) { |
|
|
|
var length = str.length; |
|
|
|
var length = str.length; |
|
|
|
var bytes = new Uint8Array(length); |
|
|
|
var bytes = new Uint8Array(length); |
|
|
|
for (var n = 0; n < length; ++n) |
|
|
|
for (var n = 0; n < length; ++n) |
|
|
@ -79,21 +79,21 @@ var StringStream = (function stringStream() { |
|
|
|
Stream.call(this, bytes); |
|
|
|
Stream.call(this, bytes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = Stream.prototype; |
|
|
|
StringStream.prototype = Stream.prototype; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return StringStream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
// super class for the decoding streams
|
|
|
|
// super class for the decoding streams
|
|
|
|
var DecodeStream = (function decodeStream() { |
|
|
|
var DecodeStream = (function DecodeStreamClosure() { |
|
|
|
function constructor() { |
|
|
|
function DecodeStream() { |
|
|
|
this.pos = 0; |
|
|
|
this.pos = 0; |
|
|
|
this.bufferLength = 0; |
|
|
|
this.bufferLength = 0; |
|
|
|
this.eof = false; |
|
|
|
this.eof = false; |
|
|
|
this.buffer = null; |
|
|
|
this.buffer = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = { |
|
|
|
DecodeStream.prototype = { |
|
|
|
ensureBuffer: function decodestream_ensureBuffer(requested) { |
|
|
|
ensureBuffer: function decodestream_ensureBuffer(requested) { |
|
|
|
var buffer = this.buffer; |
|
|
|
var buffer = this.buffer; |
|
|
|
var current = buffer ? buffer.byteLength : 0; |
|
|
|
var current = buffer ? buffer.byteLength : 0; |
|
|
@ -178,24 +178,24 @@ var DecodeStream = (function decodeStream() { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return DecodeStream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
var FakeStream = (function fakeStream() { |
|
|
|
var FakeStream = (function FakeStreamClosure() { |
|
|
|
function constructor(stream) { |
|
|
|
function FakeStream(stream) { |
|
|
|
this.dict = stream.dict; |
|
|
|
this.dict = stream.dict; |
|
|
|
DecodeStream.call(this); |
|
|
|
DecodeStream.call(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = Object.create(DecodeStream.prototype); |
|
|
|
FakeStream.prototype = Object.create(DecodeStream.prototype); |
|
|
|
constructor.prototype.readBlock = function fakeStreamReadBlock() { |
|
|
|
FakeStream.prototype.readBlock = function fakeStreamReadBlock() { |
|
|
|
var bufferLength = this.bufferLength; |
|
|
|
var bufferLength = this.bufferLength; |
|
|
|
bufferLength += 1024; |
|
|
|
bufferLength += 1024; |
|
|
|
var buffer = this.ensureBuffer(bufferLength); |
|
|
|
var buffer = this.ensureBuffer(bufferLength); |
|
|
|
this.bufferLength = bufferLength; |
|
|
|
this.bufferLength = bufferLength; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.getBytes = function fakeStreamGetBytes(length) { |
|
|
|
FakeStream.prototype.getBytes = function fakeStreamGetBytes(length) { |
|
|
|
var end, pos = this.pos; |
|
|
|
var end, pos = this.pos; |
|
|
|
|
|
|
|
|
|
|
|
if (length) { |
|
|
|
if (length) { |
|
|
@ -217,18 +217,20 @@ var FakeStream = (function fakeStream() { |
|
|
|
return this.buffer.subarray(pos, end); |
|
|
|
return this.buffer.subarray(pos, end); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return FakeStream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
var StreamsSequenceStream = (function streamSequenceStream() { |
|
|
|
var StreamsSequenceStream = (function StreamsSequenceStreamClosure() { |
|
|
|
function constructor(streams) { |
|
|
|
function StreamsSequenceStream(streams) { |
|
|
|
this.streams = streams; |
|
|
|
this.streams = streams; |
|
|
|
DecodeStream.call(this); |
|
|
|
DecodeStream.call(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = Object.create(DecodeStream.prototype); |
|
|
|
StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StreamsSequenceStream.prototype.readBlock = |
|
|
|
|
|
|
|
function streamSequenceStreamReadBlock() { |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.readBlock = function streamSequenceStreamReadBlock() { |
|
|
|
|
|
|
|
var streams = this.streams; |
|
|
|
var streams = this.streams; |
|
|
|
if (streams.length == 0) { |
|
|
|
if (streams.length == 0) { |
|
|
|
this.eof = true; |
|
|
|
this.eof = true; |
|
|
@ -243,10 +245,10 @@ var StreamsSequenceStream = (function streamSequenceStream() { |
|
|
|
this.bufferLength = newLength; |
|
|
|
this.bufferLength = newLength; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return StreamsSequenceStream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
var FlateStream = (function flateStream() { |
|
|
|
var FlateStream = (function FlateStreamClosure() { |
|
|
|
var codeLenCodeMap = new Uint32Array([ |
|
|
|
var codeLenCodeMap = new Uint32Array([ |
|
|
|
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
|
|
|
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
|
|
|
]); |
|
|
|
]); |
|
|
@ -339,7 +341,7 @@ var FlateStream = (function flateStream() { |
|
|
|
0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000 |
|
|
|
0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000 |
|
|
|
]), 5]; |
|
|
|
]), 5]; |
|
|
|
|
|
|
|
|
|
|
|
function constructor(stream) { |
|
|
|
function FlateStream(stream) { |
|
|
|
var bytes = stream.getBytes(); |
|
|
|
var bytes = stream.getBytes(); |
|
|
|
var bytesPos = 0; |
|
|
|
var bytesPos = 0; |
|
|
|
|
|
|
|
|
|
|
@ -364,9 +366,9 @@ var FlateStream = (function flateStream() { |
|
|
|
DecodeStream.call(this); |
|
|
|
DecodeStream.call(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = Object.create(DecodeStream.prototype); |
|
|
|
FlateStream.prototype = Object.create(DecodeStream.prototype); |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.getBits = function flateStreamGetBits(bits) { |
|
|
|
FlateStream.prototype.getBits = function flateStreamGetBits(bits) { |
|
|
|
var codeSize = this.codeSize; |
|
|
|
var codeSize = this.codeSize; |
|
|
|
var codeBuf = this.codeBuf; |
|
|
|
var codeBuf = this.codeBuf; |
|
|
|
var bytes = this.bytes; |
|
|
|
var bytes = this.bytes; |
|
|
@ -386,7 +388,7 @@ var FlateStream = (function flateStream() { |
|
|
|
return b; |
|
|
|
return b; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.getCode = function flateStreamGetCode(table) { |
|
|
|
FlateStream.prototype.getCode = function flateStreamGetCode(table) { |
|
|
|
var codes = table[0]; |
|
|
|
var codes = table[0]; |
|
|
|
var maxLen = table[1]; |
|
|
|
var maxLen = table[1]; |
|
|
|
var codeSize = this.codeSize; |
|
|
|
var codeSize = this.codeSize; |
|
|
@ -412,7 +414,7 @@ var FlateStream = (function flateStream() { |
|
|
|
return codeVal; |
|
|
|
return codeVal; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.generateHuffmanTable = |
|
|
|
FlateStream.prototype.generateHuffmanTable = |
|
|
|
function flateStreamGenerateHuffmanTable(lengths) { |
|
|
|
function flateStreamGenerateHuffmanTable(lengths) { |
|
|
|
var n = lengths.length; |
|
|
|
var n = lengths.length; |
|
|
|
|
|
|
|
|
|
|
@ -451,7 +453,7 @@ var FlateStream = (function flateStream() { |
|
|
|
return [codes, maxLen]; |
|
|
|
return [codes, maxLen]; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.readBlock = function flateStreamReadBlock() { |
|
|
|
FlateStream.prototype.readBlock = function flateStreamReadBlock() { |
|
|
|
// read block header
|
|
|
|
// read block header
|
|
|
|
var hdr = this.getBits(3); |
|
|
|
var hdr = this.getBits(3); |
|
|
|
if (hdr & 1) |
|
|
|
if (hdr & 1) |
|
|
@ -582,11 +584,11 @@ var FlateStream = (function flateStream() { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return FlateStream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
var PredictorStream = (function predictorStream() { |
|
|
|
var PredictorStream = (function PredictorStreamClosure() { |
|
|
|
function constructor(stream, params) { |
|
|
|
function PredictorStream(stream, params) { |
|
|
|
var predictor = this.predictor = params.get('Predictor') || 1; |
|
|
|
var predictor = this.predictor = params.get('Predictor') || 1; |
|
|
|
|
|
|
|
|
|
|
|
if (predictor <= 1) |
|
|
|
if (predictor <= 1) |
|
|
@ -613,9 +615,9 @@ var PredictorStream = (function predictorStream() { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = Object.create(DecodeStream.prototype); |
|
|
|
PredictorStream.prototype = Object.create(DecodeStream.prototype); |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.readBlockTiff = |
|
|
|
PredictorStream.prototype.readBlockTiff = |
|
|
|
function predictorStreamReadBlockTiff() { |
|
|
|
function predictorStreamReadBlockTiff() { |
|
|
|
var rowBytes = this.rowBytes; |
|
|
|
var rowBytes = this.rowBytes; |
|
|
|
|
|
|
|
|
|
|
@ -676,7 +678,9 @@ var PredictorStream = (function predictorStream() { |
|
|
|
this.bufferLength += rowBytes; |
|
|
|
this.bufferLength += rowBytes; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.readBlockPng = function predictorStreamReadBlockPng() { |
|
|
|
PredictorStream.prototype.readBlockPng = |
|
|
|
|
|
|
|
function predictorStreamReadBlockPng() { |
|
|
|
|
|
|
|
|
|
|
|
var rowBytes = this.rowBytes; |
|
|
|
var rowBytes = this.rowBytes; |
|
|
|
var pixBytes = this.pixBytes; |
|
|
|
var pixBytes = this.pixBytes; |
|
|
|
|
|
|
|
|
|
|
@ -753,7 +757,7 @@ var PredictorStream = (function predictorStream() { |
|
|
|
this.bufferLength += rowBytes; |
|
|
|
this.bufferLength += rowBytes; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return PredictorStream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -763,7 +767,7 @@ var PredictorStream = (function predictorStream() { |
|
|
|
* a library to decode these images and the stream behaves like all the other |
|
|
|
* a library to decode these images and the stream behaves like all the other |
|
|
|
* DecodeStreams. |
|
|
|
* DecodeStreams. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
var JpegStream = (function jpegStream() { |
|
|
|
var JpegStream = (function JpegStreamClosure() { |
|
|
|
function isAdobeImage(bytes) { |
|
|
|
function isAdobeImage(bytes) { |
|
|
|
var maxBytesScanned = Math.max(bytes.length - 16, 1024); |
|
|
|
var maxBytesScanned = Math.max(bytes.length - 16, 1024); |
|
|
|
// Looking for APP14, 'Adobe'
|
|
|
|
// Looking for APP14, 'Adobe'
|
|
|
@ -794,7 +798,7 @@ var JpegStream = (function jpegStream() { |
|
|
|
return newBytes; |
|
|
|
return newBytes; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function constructor(bytes, dict, xref) { |
|
|
|
function JpegStream(bytes, dict, xref) { |
|
|
|
// TODO: per poppler, some images may have 'junk' before that
|
|
|
|
// TODO: per poppler, some images may have 'junk' before that
|
|
|
|
// need to be removed
|
|
|
|
// need to be removed
|
|
|
|
this.dict = dict; |
|
|
|
this.dict = dict; |
|
|
@ -825,9 +829,9 @@ var JpegStream = (function jpegStream() { |
|
|
|
DecodeStream.call(this); |
|
|
|
DecodeStream.call(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = Object.create(DecodeStream.prototype); |
|
|
|
JpegStream.prototype = Object.create(DecodeStream.prototype); |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.ensureBuffer = function jpegStreamEnsureBuffer(req) { |
|
|
|
JpegStream.prototype.ensureBuffer = function jpegStreamEnsureBuffer(req) { |
|
|
|
if (this.bufferLength) |
|
|
|
if (this.bufferLength) |
|
|
|
return; |
|
|
|
return; |
|
|
|
var jpegImage = new JpegImage(); |
|
|
|
var jpegImage = new JpegImage(); |
|
|
@ -839,18 +843,18 @@ var JpegStream = (function jpegStream() { |
|
|
|
this.buffer = data; |
|
|
|
this.buffer = data; |
|
|
|
this.bufferLength = data.length; |
|
|
|
this.bufferLength = data.length; |
|
|
|
}; |
|
|
|
}; |
|
|
|
constructor.prototype.getIR = function jpegStreamGetIR() { |
|
|
|
JpegStream.prototype.getIR = function jpegStreamGetIR() { |
|
|
|
return this.src; |
|
|
|
return this.src; |
|
|
|
}; |
|
|
|
}; |
|
|
|
constructor.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'); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return JpegStream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
var DecryptStream = (function decryptStream() { |
|
|
|
var DecryptStream = (function DecryptStreamClosure() { |
|
|
|
function constructor(str, decrypt) { |
|
|
|
function DecryptStream(str, decrypt) { |
|
|
|
this.str = str; |
|
|
|
this.str = str; |
|
|
|
this.dict = str.dict; |
|
|
|
this.dict = str.dict; |
|
|
|
this.decrypt = decrypt; |
|
|
|
this.decrypt = decrypt; |
|
|
@ -860,9 +864,9 @@ var DecryptStream = (function decryptStream() { |
|
|
|
|
|
|
|
|
|
|
|
var chunkSize = 512; |
|
|
|
var chunkSize = 512; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = Object.create(DecodeStream.prototype); |
|
|
|
DecryptStream.prototype = Object.create(DecodeStream.prototype); |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.readBlock = function decryptStreamReadBlock() { |
|
|
|
DecryptStream.prototype.readBlock = function decryptStreamReadBlock() { |
|
|
|
var chunk = this.str.getBytes(chunkSize); |
|
|
|
var chunk = this.str.getBytes(chunkSize); |
|
|
|
if (!chunk || chunk.length == 0) { |
|
|
|
if (!chunk || chunk.length == 0) { |
|
|
|
this.eof = true; |
|
|
|
this.eof = true; |
|
|
@ -879,11 +883,11 @@ var DecryptStream = (function decryptStream() { |
|
|
|
this.bufferLength = bufferLength; |
|
|
|
this.bufferLength = bufferLength; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return DecryptStream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
var Ascii85Stream = (function ascii85Stream() { |
|
|
|
var Ascii85Stream = (function Ascii85StreamClosure() { |
|
|
|
function constructor(str) { |
|
|
|
function Ascii85Stream(str) { |
|
|
|
this.str = str; |
|
|
|
this.str = str; |
|
|
|
this.dict = str.dict; |
|
|
|
this.dict = str.dict; |
|
|
|
this.input = new Uint8Array(5); |
|
|
|
this.input = new Uint8Array(5); |
|
|
@ -891,9 +895,9 @@ var Ascii85Stream = (function ascii85Stream() { |
|
|
|
DecodeStream.call(this); |
|
|
|
DecodeStream.call(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = Object.create(DecodeStream.prototype); |
|
|
|
Ascii85Stream.prototype = Object.create(DecodeStream.prototype); |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.readBlock = function ascii85StreamReadBlock() { |
|
|
|
Ascii85Stream.prototype.readBlock = function ascii85StreamReadBlock() { |
|
|
|
var tildaCode = '~'.charCodeAt(0); |
|
|
|
var tildaCode = '~'.charCodeAt(0); |
|
|
|
var zCode = 'z'.charCodeAt(0); |
|
|
|
var zCode = 'z'.charCodeAt(0); |
|
|
|
var str = this.str; |
|
|
|
var str = this.str; |
|
|
@ -948,11 +952,11 @@ var Ascii85Stream = (function ascii85Stream() { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return Ascii85Stream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
var AsciiHexStream = (function asciiHexStream() { |
|
|
|
var AsciiHexStream = (function AsciiHexStreamClosure() { |
|
|
|
function constructor(str) { |
|
|
|
function AsciiHexStream(str) { |
|
|
|
this.str = str; |
|
|
|
this.str = str; |
|
|
|
this.dict = str.dict; |
|
|
|
this.dict = str.dict; |
|
|
|
|
|
|
|
|
|
|
@ -986,9 +990,9 @@ var AsciiHexStream = (function asciiHexStream() { |
|
|
|
102: 15 |
|
|
|
102: 15 |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = Object.create(DecodeStream.prototype); |
|
|
|
AsciiHexStream.prototype = Object.create(DecodeStream.prototype); |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.readBlock = function asciiHexStreamReadBlock() { |
|
|
|
AsciiHexStream.prototype.readBlock = function asciiHexStreamReadBlock() { |
|
|
|
var gtCode = '>'.charCodeAt(0), bytes = this.str.getBytes(), c, n, |
|
|
|
var gtCode = '>'.charCodeAt(0), bytes = this.str.getBytes(), c, n, |
|
|
|
decodeLength, buffer, bufferLength, i, length; |
|
|
|
decodeLength, buffer, bufferLength, i, length; |
|
|
|
|
|
|
|
|
|
|
@ -1018,10 +1022,10 @@ var AsciiHexStream = (function asciiHexStream() { |
|
|
|
this.eof = true; |
|
|
|
this.eof = true; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return AsciiHexStream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
var CCITTFaxStream = (function ccittFaxStream() { |
|
|
|
var CCITTFaxStream = (function CCITTFaxStreamClosure() { |
|
|
|
|
|
|
|
|
|
|
|
var ccittEOL = -2; |
|
|
|
var ccittEOL = -2; |
|
|
|
var twoDimPass = 0; |
|
|
|
var twoDimPass = 0; |
|
|
@ -1449,7 +1453,7 @@ var CCITTFaxStream = (function ccittFaxStream() { |
|
|
|
[2, 2], [2, 2], [2, 2], [2, 2] |
|
|
|
[2, 2], [2, 2], [2, 2], [2, 2] |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
function constructor(str, params) { |
|
|
|
function CCITTFaxStream(str, params) { |
|
|
|
this.str = str; |
|
|
|
this.str = str; |
|
|
|
this.dict = str.dict; |
|
|
|
this.dict = str.dict; |
|
|
|
|
|
|
|
|
|
|
@ -1494,9 +1498,9 @@ var CCITTFaxStream = (function ccittFaxStream() { |
|
|
|
DecodeStream.call(this); |
|
|
|
DecodeStream.call(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = Object.create(DecodeStream.prototype); |
|
|
|
CCITTFaxStream.prototype = Object.create(DecodeStream.prototype); |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.readBlock = function ccittFaxStreamReadBlock() { |
|
|
|
CCITTFaxStream.prototype.readBlock = function ccittFaxStreamReadBlock() { |
|
|
|
while (!this.eof) { |
|
|
|
while (!this.eof) { |
|
|
|
var c = this.lookChar(); |
|
|
|
var c = this.lookChar(); |
|
|
|
this.buf = EOF; |
|
|
|
this.buf = EOF; |
|
|
@ -1505,7 +1509,7 @@ var CCITTFaxStream = (function ccittFaxStream() { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.addPixels = |
|
|
|
CCITTFaxStream.prototype.addPixels = |
|
|
|
function ccittFaxStreamAddPixels(a1, blackPixels) { |
|
|
|
function ccittFaxStreamAddPixels(a1, blackPixels) { |
|
|
|
var codingLine = this.codingLine; |
|
|
|
var codingLine = this.codingLine; |
|
|
|
var codingPos = this.codingPos; |
|
|
|
var codingPos = this.codingPos; |
|
|
@ -1525,7 +1529,7 @@ var CCITTFaxStream = (function ccittFaxStream() { |
|
|
|
this.codingPos = codingPos; |
|
|
|
this.codingPos = codingPos; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.addPixelsNeg = |
|
|
|
CCITTFaxStream.prototype.addPixelsNeg = |
|
|
|
function ccittFaxStreamAddPixelsNeg(a1, blackPixels) { |
|
|
|
function ccittFaxStreamAddPixelsNeg(a1, blackPixels) { |
|
|
|
var codingLine = this.codingLine; |
|
|
|
var codingLine = this.codingLine; |
|
|
|
var codingPos = this.codingPos; |
|
|
|
var codingPos = this.codingPos; |
|
|
@ -1554,7 +1558,7 @@ var CCITTFaxStream = (function ccittFaxStream() { |
|
|
|
this.codingPos = codingPos; |
|
|
|
this.codingPos = codingPos; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.lookChar = function ccittFaxStreamLookChar() { |
|
|
|
CCITTFaxStream.prototype.lookChar = function ccittFaxStreamLookChar() { |
|
|
|
if (this.buf != EOF) |
|
|
|
if (this.buf != EOF) |
|
|
|
return this.buf; |
|
|
|
return this.buf; |
|
|
|
|
|
|
|
|
|
|
@ -1873,7 +1877,9 @@ var CCITTFaxStream = (function ccittFaxStream() { |
|
|
|
return [false, 0, false]; |
|
|
|
return [false, 0, false]; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.getTwoDimCode = function ccittFaxStreamGetTwoDimCode() { |
|
|
|
CCITTFaxStream.prototype.getTwoDimCode = |
|
|
|
|
|
|
|
function ccittFaxStreamGetTwoDimCode() { |
|
|
|
|
|
|
|
|
|
|
|
var code = 0; |
|
|
|
var code = 0; |
|
|
|
var p; |
|
|
|
var p; |
|
|
|
if (this.eoblock) { |
|
|
|
if (this.eoblock) { |
|
|
@ -1892,7 +1898,9 @@ var CCITTFaxStream = (function ccittFaxStream() { |
|
|
|
return EOF; |
|
|
|
return EOF; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.getWhiteCode = function ccittFaxStreamGetWhiteCode() { |
|
|
|
CCITTFaxStream.prototype.getWhiteCode = |
|
|
|
|
|
|
|
function ccittFaxStreamGetWhiteCode() { |
|
|
|
|
|
|
|
|
|
|
|
var code = 0; |
|
|
|
var code = 0; |
|
|
|
var p; |
|
|
|
var p; |
|
|
|
var n; |
|
|
|
var n; |
|
|
@ -1924,7 +1932,9 @@ var CCITTFaxStream = (function ccittFaxStream() { |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.getBlackCode = function ccittFaxStreamGetBlackCode() { |
|
|
|
CCITTFaxStream.prototype.getBlackCode = |
|
|
|
|
|
|
|
function ccittFaxStreamGetBlackCode() { |
|
|
|
|
|
|
|
|
|
|
|
var code, p; |
|
|
|
var code, p; |
|
|
|
if (this.eoblock) { |
|
|
|
if (this.eoblock) { |
|
|
|
code = this.lookBits(13); |
|
|
|
code = this.lookBits(13); |
|
|
@ -1959,7 +1969,7 @@ var CCITTFaxStream = (function ccittFaxStream() { |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.lookBits = function ccittFaxStreamLookBits(n) { |
|
|
|
CCITTFaxStream.prototype.lookBits = function ccittFaxStreamLookBits(n) { |
|
|
|
var c; |
|
|
|
var c; |
|
|
|
while (this.inputBits < n) { |
|
|
|
while (this.inputBits < n) { |
|
|
|
if ((c = this.str.getByte()) == null) { |
|
|
|
if ((c = this.str.getByte()) == null) { |
|
|
@ -1974,16 +1984,16 @@ var CCITTFaxStream = (function ccittFaxStream() { |
|
|
|
return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n)); |
|
|
|
return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n)); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.eatBits = function ccittFaxStreamEatBits(n) { |
|
|
|
CCITTFaxStream.prototype.eatBits = function ccittFaxStreamEatBits(n) { |
|
|
|
if ((this.inputBits -= n) < 0) |
|
|
|
if ((this.inputBits -= n) < 0) |
|
|
|
this.inputBits = 0; |
|
|
|
this.inputBits = 0; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return CCITTFaxStream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
var LZWStream = (function lzwStream() { |
|
|
|
var LZWStream = (function LZWStreamClosure() { |
|
|
|
function constructor(str, earlyChange) { |
|
|
|
function LZWStream(str, earlyChange) { |
|
|
|
this.str = str; |
|
|
|
this.str = str; |
|
|
|
this.dict = str.dict; |
|
|
|
this.dict = str.dict; |
|
|
|
this.cachedData = 0; |
|
|
|
this.cachedData = 0; |
|
|
@ -2009,9 +2019,9 @@ var LZWStream = (function lzwStream() { |
|
|
|
DecodeStream.call(this); |
|
|
|
DecodeStream.call(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = Object.create(DecodeStream.prototype); |
|
|
|
LZWStream.prototype = Object.create(DecodeStream.prototype); |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.readBits = function lzwStreamReadBits(n) { |
|
|
|
LZWStream.prototype.readBits = function lzwStreamReadBits(n) { |
|
|
|
var bitsCached = this.bitsCached; |
|
|
|
var bitsCached = this.bitsCached; |
|
|
|
var cachedData = this.cachedData; |
|
|
|
var cachedData = this.cachedData; |
|
|
|
while (bitsCached < n) { |
|
|
|
while (bitsCached < n) { |
|
|
@ -2029,7 +2039,7 @@ var LZWStream = (function lzwStream() { |
|
|
|
return (cachedData >>> bitsCached) & ((1 << n) - 1); |
|
|
|
return (cachedData >>> bitsCached) & ((1 << n) - 1); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype.readBlock = function lzwStreamReadBlock() { |
|
|
|
LZWStream.prototype.readBlock = function lzwStreamReadBlock() { |
|
|
|
var blockSize = 512; |
|
|
|
var blockSize = 512; |
|
|
|
var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize; |
|
|
|
var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize; |
|
|
|
var i, j, q; |
|
|
|
var i, j, q; |
|
|
@ -2108,6 +2118,6 @@ var LZWStream = (function lzwStream() { |
|
|
|
this.bufferLength = currentBufferLength; |
|
|
|
this.bufferLength = currentBufferLength; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return LZWStream; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|