Fix coding style in src/core/stream.js
This commit is contained in:
parent
67b5c8868c
commit
6883362a84
@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
var Stream = (function StreamClosure() {
|
var Stream = (function StreamClosure() {
|
||||||
function Stream(arrayBuffer, start, length, dict) {
|
function Stream(arrayBuffer, start, length, dict) {
|
||||||
this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer :
|
this.bytes = (arrayBuffer instanceof Uint8Array ?
|
||||||
new Uint8Array(arrayBuffer);
|
arrayBuffer : new Uint8Array(arrayBuffer));
|
||||||
this.start = start || 0;
|
this.start = start || 0;
|
||||||
this.pos = this.start;
|
this.pos = this.start;
|
||||||
this.end = (start + length) || this.bytes.length;
|
this.end = (start + length) || this.bytes.length;
|
||||||
@ -36,8 +36,9 @@ var Stream = (function StreamClosure() {
|
|||||||
return this.end - this.start;
|
return this.end - this.start;
|
||||||
},
|
},
|
||||||
getByte: function Stream_getByte() {
|
getByte: function Stream_getByte() {
|
||||||
if (this.pos >= this.end)
|
if (this.pos >= this.end) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
return this.bytes[this.pos++];
|
return this.bytes[this.pos++];
|
||||||
},
|
},
|
||||||
getUint16: function Stream_getUint16() {
|
getUint16: function Stream_getUint16() {
|
||||||
@ -59,13 +60,13 @@ var Stream = (function StreamClosure() {
|
|||||||
var pos = this.pos;
|
var pos = this.pos;
|
||||||
var strEnd = this.end;
|
var strEnd = this.end;
|
||||||
|
|
||||||
if (!length)
|
if (!length) {
|
||||||
return bytes.subarray(pos, strEnd);
|
return bytes.subarray(pos, strEnd);
|
||||||
|
}
|
||||||
var end = pos + length;
|
var end = pos + length;
|
||||||
if (end > strEnd)
|
if (end > strEnd) {
|
||||||
end = strEnd;
|
end = strEnd;
|
||||||
|
}
|
||||||
this.pos = end;
|
this.pos = end;
|
||||||
return bytes.subarray(pos, end);
|
return bytes.subarray(pos, end);
|
||||||
},
|
},
|
||||||
@ -75,8 +76,9 @@ var Stream = (function StreamClosure() {
|
|||||||
return bytes;
|
return bytes;
|
||||||
},
|
},
|
||||||
skip: function Stream_skip(n) {
|
skip: function Stream_skip(n) {
|
||||||
if (!n)
|
if (!n) {
|
||||||
n = 1;
|
n = 1;
|
||||||
|
}
|
||||||
this.pos += n;
|
this.pos += n;
|
||||||
},
|
},
|
||||||
reset: function Stream_reset() {
|
reset: function Stream_reset() {
|
||||||
@ -98,8 +100,9 @@ var StringStream = (function StringStreamClosure() {
|
|||||||
function StringStream(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) {
|
||||||
bytes[n] = str.charCodeAt(n);
|
bytes[n] = str.charCodeAt(n);
|
||||||
|
}
|
||||||
Stream.call(this, bytes);
|
Stream.call(this, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,8 +152,9 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
getByte: function DecodeStream_getByte() {
|
getByte: function DecodeStream_getByte() {
|
||||||
var pos = this.pos;
|
var pos = this.pos;
|
||||||
while (this.bufferLength <= pos) {
|
while (this.bufferLength <= pos) {
|
||||||
if (this.eof)
|
if (this.eof) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
this.readBlock();
|
this.readBlock();
|
||||||
}
|
}
|
||||||
return this.buffer[this.pos++];
|
return this.buffer[this.pos++];
|
||||||
@ -174,22 +178,24 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
this.ensureBuffer(pos + length);
|
this.ensureBuffer(pos + length);
|
||||||
end = pos + length;
|
end = pos + length;
|
||||||
|
|
||||||
while (!this.eof && this.bufferLength < end)
|
while (!this.eof && this.bufferLength < end) {
|
||||||
this.readBlock();
|
this.readBlock();
|
||||||
|
}
|
||||||
var bufEnd = this.bufferLength;
|
var bufEnd = this.bufferLength;
|
||||||
if (end > bufEnd)
|
if (end > bufEnd) {
|
||||||
end = bufEnd;
|
end = bufEnd;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
while (!this.eof)
|
while (!this.eof) {
|
||||||
this.readBlock();
|
this.readBlock();
|
||||||
|
}
|
||||||
end = this.bufferLength;
|
end = this.bufferLength;
|
||||||
|
|
||||||
// checking if bufferLength is still 0 then
|
// checking if bufferLength is still 0 then
|
||||||
// the buffer has to be initialized
|
// the buffer has to be initialized
|
||||||
if (!end)
|
if (!end) {
|
||||||
this.buffer = new Uint8Array(0);
|
this.buffer = new Uint8Array(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pos = end;
|
this.pos = end;
|
||||||
@ -202,13 +208,15 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
},
|
},
|
||||||
makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
|
makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
|
||||||
var end = start + length;
|
var end = start + length;
|
||||||
while (this.bufferLength <= end && !this.eof)
|
while (this.bufferLength <= end && !this.eof) {
|
||||||
this.readBlock();
|
this.readBlock();
|
||||||
|
}
|
||||||
return new Stream(this.buffer, start, length, dict);
|
return new Stream(this.buffer, start, length, dict);
|
||||||
},
|
},
|
||||||
skip: function Stream_skip(n) {
|
skip: function Stream_skip(n) {
|
||||||
if (!n)
|
if (!n) {
|
||||||
n = 1;
|
n = 1;
|
||||||
|
}
|
||||||
this.pos += n;
|
this.pos += n;
|
||||||
},
|
},
|
||||||
reset: function DecodeStream_reset() {
|
reset: function DecodeStream_reset() {
|
||||||
@ -234,7 +242,7 @@ var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
|
|||||||
StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
|
StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
|
||||||
|
|
||||||
StreamsSequenceStream.prototype.readBlock =
|
StreamsSequenceStream.prototype.readBlock =
|
||||||
function streamSequenceStreamReadBlock() {
|
function streamSequenceStreamReadBlock() {
|
||||||
|
|
||||||
var streams = this.streams;
|
var streams = this.streams;
|
||||||
if (streams.length === 0) {
|
if (streams.length === 0) {
|
||||||
@ -365,14 +373,18 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
|
|
||||||
var cmf = str.getByte();
|
var cmf = str.getByte();
|
||||||
var flg = str.getByte();
|
var flg = str.getByte();
|
||||||
if (cmf == -1 || flg == -1)
|
if (cmf == -1 || flg == -1) {
|
||||||
error('Invalid header in flate stream: ' + cmf + ', ' + flg);
|
error('Invalid header in flate stream: ' + cmf + ', ' + flg);
|
||||||
if ((cmf & 0x0f) != 0x08)
|
}
|
||||||
|
if ((cmf & 0x0f) != 0x08) {
|
||||||
error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
|
error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
|
||||||
if ((((cmf << 8) + flg) % 31) !== 0)
|
}
|
||||||
|
if ((((cmf << 8) + flg) % 31) !== 0) {
|
||||||
error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
|
error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
|
||||||
if (flg & 0x20)
|
}
|
||||||
|
if (flg & 0x20) {
|
||||||
error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
|
error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
|
||||||
|
}
|
||||||
|
|
||||||
this.codeSize = 0;
|
this.codeSize = 0;
|
||||||
this.codeBuf = 0;
|
this.codeBuf = 0;
|
||||||
@ -420,8 +432,9 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
var code = codes[codeBuf & ((1 << maxLen) - 1)];
|
var code = codes[codeBuf & ((1 << maxLen) - 1)];
|
||||||
var codeLen = code >> 16;
|
var codeLen = code >> 16;
|
||||||
var codeVal = code & 0xffff;
|
var codeVal = code & 0xffff;
|
||||||
if (codeSize === 0 || codeSize < codeLen || codeLen === 0)
|
if (codeSize === 0 || codeSize < codeLen || codeLen === 0) {
|
||||||
error('Bad encoding in flate stream');
|
error('Bad encoding in flate stream');
|
||||||
|
}
|
||||||
this.codeBuf = (codeBuf >> codeLen);
|
this.codeBuf = (codeBuf >> codeLen);
|
||||||
this.codeSize = (codeSize - codeLen);
|
this.codeSize = (codeSize - codeLen);
|
||||||
return codeVal;
|
return codeVal;
|
||||||
@ -434,8 +447,9 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
// find max code length
|
// find max code length
|
||||||
var maxLen = 0;
|
var maxLen = 0;
|
||||||
for (var i = 0; i < n; ++i) {
|
for (var i = 0; i < n; ++i) {
|
||||||
if (lengths[i] > maxLen)
|
if (lengths[i] > maxLen) {
|
||||||
maxLen = lengths[i];
|
maxLen = lengths[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// build the table
|
// build the table
|
||||||
@ -455,9 +469,9 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fill the table entries
|
// fill the table entries
|
||||||
for (var i = code2; i < size; i += skip)
|
for (var i = code2; i < size; i += skip) {
|
||||||
codes[i] = (len << 16) | val;
|
codes[i] = (len << 16) | val;
|
||||||
|
}
|
||||||
++code;
|
++code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -470,8 +484,9 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
var str = this.str;
|
var str = this.str;
|
||||||
// read block header
|
// read block header
|
||||||
var hdr = this.getBits(3);
|
var hdr = this.getBits(3);
|
||||||
if (hdr & 1)
|
if (hdr & 1) {
|
||||||
this.eof = true;
|
this.eof = true;
|
||||||
|
}
|
||||||
hdr >>= 1;
|
hdr >>= 1;
|
||||||
|
|
||||||
if (hdr === 0) { // uncompressed block
|
if (hdr === 0) { // uncompressed block
|
||||||
@ -535,8 +550,9 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
// build the code lengths code table
|
// build the code lengths code table
|
||||||
var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
|
var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
|
||||||
|
|
||||||
for (var i = 0; i < numCodeLenCodes; ++i)
|
for (var i = 0; i < numCodeLenCodes; ++i) {
|
||||||
codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
|
codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
|
||||||
|
}
|
||||||
var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
|
var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
|
||||||
|
|
||||||
// build the literal and distance code tables
|
// build the literal and distance code tables
|
||||||
@ -558,8 +574,9 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var repeatLength = this.getBits(bitsLength) + bitsOffset;
|
var repeatLength = this.getBits(bitsLength) + bitsOffset;
|
||||||
while (repeatLength-- > 0)
|
while (repeatLength-- > 0) {
|
||||||
codeLengths[i++] = what;
|
codeLengths[i++] = what;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
litCodeTable =
|
litCodeTable =
|
||||||
@ -590,21 +607,24 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
code1 -= 257;
|
code1 -= 257;
|
||||||
code1 = lengthDecode[code1];
|
code1 = lengthDecode[code1];
|
||||||
var code2 = code1 >> 16;
|
var code2 = code1 >> 16;
|
||||||
if (code2 > 0)
|
if (code2 > 0) {
|
||||||
code2 = this.getBits(code2);
|
code2 = this.getBits(code2);
|
||||||
|
}
|
||||||
var len = (code1 & 0xffff) + code2;
|
var len = (code1 & 0xffff) + code2;
|
||||||
code1 = this.getCode(distCodeTable);
|
code1 = this.getCode(distCodeTable);
|
||||||
code1 = distDecode[code1];
|
code1 = distDecode[code1];
|
||||||
code2 = code1 >> 16;
|
code2 = code1 >> 16;
|
||||||
if (code2 > 0)
|
if (code2 > 0) {
|
||||||
code2 = this.getBits(code2);
|
code2 = this.getBits(code2);
|
||||||
|
}
|
||||||
var dist = (code1 & 0xffff) + code2;
|
var dist = (code1 & 0xffff) + code2;
|
||||||
if (pos + len >= limit) {
|
if (pos + len >= limit) {
|
||||||
buffer = this.ensureBuffer(pos + len);
|
buffer = this.ensureBuffer(pos + len);
|
||||||
limit = buffer.length;
|
limit = buffer.length;
|
||||||
}
|
}
|
||||||
for (var k = 0; k < len; ++k, ++pos)
|
for (var k = 0; k < len; ++k, ++pos) {
|
||||||
buffer[pos] = buffer[pos - dist];
|
buffer[pos] = buffer[pos - dist];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -615,15 +635,18 @@ var PredictorStream = (function PredictorStreamClosure() {
|
|||||||
function PredictorStream(str, maybeLength, params) {
|
function PredictorStream(str, maybeLength, params) {
|
||||||
var predictor = this.predictor = params.get('Predictor') || 1;
|
var predictor = this.predictor = params.get('Predictor') || 1;
|
||||||
|
|
||||||
if (predictor <= 1)
|
if (predictor <= 1) {
|
||||||
return str; // no prediction
|
return str; // no prediction
|
||||||
if (predictor !== 2 && (predictor < 10 || predictor > 15))
|
}
|
||||||
|
if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
|
||||||
error('Unsupported predictor: ' + predictor);
|
error('Unsupported predictor: ' + predictor);
|
||||||
|
}
|
||||||
|
|
||||||
if (predictor === 2)
|
if (predictor === 2) {
|
||||||
this.readBlock = this.readBlockTiff;
|
this.readBlock = this.readBlockTiff;
|
||||||
else
|
} else {
|
||||||
this.readBlock = this.readBlockPng;
|
this.readBlock = this.readBlockPng;
|
||||||
|
}
|
||||||
|
|
||||||
this.str = str;
|
this.str = str;
|
||||||
this.dict = str.dict;
|
this.dict = str.dict;
|
||||||
@ -642,7 +665,7 @@ var PredictorStream = (function PredictorStreamClosure() {
|
|||||||
PredictorStream.prototype = Object.create(DecodeStream.prototype);
|
PredictorStream.prototype = Object.create(DecodeStream.prototype);
|
||||||
|
|
||||||
PredictorStream.prototype.readBlockTiff =
|
PredictorStream.prototype.readBlockTiff =
|
||||||
function predictorStreamReadBlockTiff() {
|
function predictorStreamReadBlockTiff() {
|
||||||
var rowBytes = this.rowBytes;
|
var rowBytes = this.rowBytes;
|
||||||
|
|
||||||
var bufferLength = this.bufferLength;
|
var bufferLength = this.bufferLength;
|
||||||
@ -672,8 +695,9 @@ var PredictorStream = (function PredictorStreamClosure() {
|
|||||||
inbuf &= 0xFFFF;
|
inbuf &= 0xFFFF;
|
||||||
}
|
}
|
||||||
} else if (bits === 8) {
|
} else if (bits === 8) {
|
||||||
for (var i = 0; i < colors; ++i)
|
for (var i = 0; i < colors; ++i) {
|
||||||
buffer[pos++] = rawBytes[i];
|
buffer[pos++] = rawBytes[i];
|
||||||
|
}
|
||||||
for (; i < rowBytes; ++i) {
|
for (; i < rowBytes; ++i) {
|
||||||
buffer[pos] = buffer[pos - colors] + rawBytes[i];
|
buffer[pos] = buffer[pos - colors] + rawBytes[i];
|
||||||
pos++;
|
pos++;
|
||||||
@ -702,14 +726,14 @@ var PredictorStream = (function PredictorStreamClosure() {
|
|||||||
}
|
}
|
||||||
if (outbits > 0) {
|
if (outbits > 0) {
|
||||||
buffer[k++] = (outbuf << (8 - outbits)) +
|
buffer[k++] = (outbuf << (8 - outbits)) +
|
||||||
(inbuf & ((1 << (8 - outbits)) - 1));
|
(inbuf & ((1 << (8 - outbits)) - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.bufferLength += rowBytes;
|
this.bufferLength += rowBytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
PredictorStream.prototype.readBlockPng =
|
PredictorStream.prototype.readBlockPng =
|
||||||
function predictorStreamReadBlockPng() {
|
function predictorStreamReadBlockPng() {
|
||||||
|
|
||||||
var rowBytes = this.rowBytes;
|
var rowBytes = this.rowBytes;
|
||||||
var pixBytes = this.pixBytes;
|
var pixBytes = this.pixBytes;
|
||||||
@ -725,30 +749,35 @@ var PredictorStream = (function PredictorStreamClosure() {
|
|||||||
var buffer = this.ensureBuffer(bufferLength + rowBytes);
|
var buffer = this.ensureBuffer(bufferLength + rowBytes);
|
||||||
|
|
||||||
var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
|
var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
|
||||||
if (prevRow.length === 0)
|
if (prevRow.length === 0) {
|
||||||
prevRow = new Uint8Array(rowBytes);
|
prevRow = new Uint8Array(rowBytes);
|
||||||
|
}
|
||||||
|
|
||||||
var j = bufferLength;
|
var j = bufferLength;
|
||||||
switch (predictor) {
|
switch (predictor) {
|
||||||
case 0:
|
case 0:
|
||||||
for (var i = 0; i < rowBytes; ++i)
|
for (var i = 0; i < rowBytes; ++i) {
|
||||||
buffer[j++] = rawBytes[i];
|
buffer[j++] = rawBytes[i];
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
for (var i = 0; i < pixBytes; ++i)
|
for (var i = 0; i < pixBytes; ++i) {
|
||||||
buffer[j++] = rawBytes[i];
|
buffer[j++] = rawBytes[i];
|
||||||
|
}
|
||||||
for (; i < rowBytes; ++i) {
|
for (; i < rowBytes; ++i) {
|
||||||
buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
|
buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
for (var i = 0; i < rowBytes; ++i)
|
for (var i = 0; i < rowBytes; ++i) {
|
||||||
buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
|
buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
for (var i = 0; i < pixBytes; ++i)
|
for (var i = 0; i < pixBytes; ++i) {
|
||||||
buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
|
buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
|
||||||
|
}
|
||||||
for (; i < rowBytes; ++i) {
|
for (; i < rowBytes; ++i) {
|
||||||
buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
|
buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
|
||||||
rawBytes[i]) & 0xFF;
|
rawBytes[i]) & 0xFF;
|
||||||
@ -770,22 +799,26 @@ var PredictorStream = (function PredictorStreamClosure() {
|
|||||||
var p = left + up - upLeft;
|
var p = left + up - upLeft;
|
||||||
|
|
||||||
var pa = p - left;
|
var pa = p - left;
|
||||||
if (pa < 0)
|
if (pa < 0) {
|
||||||
pa = -pa;
|
pa = -pa;
|
||||||
|
}
|
||||||
var pb = p - up;
|
var pb = p - up;
|
||||||
if (pb < 0)
|
if (pb < 0) {
|
||||||
pb = -pb;
|
pb = -pb;
|
||||||
|
}
|
||||||
var pc = p - upLeft;
|
var pc = p - upLeft;
|
||||||
if (pc < 0)
|
if (pc < 0) {
|
||||||
pc = -pc;
|
pc = -pc;
|
||||||
|
}
|
||||||
|
|
||||||
var c = rawBytes[i];
|
var c = rawBytes[i];
|
||||||
if (pa <= pb && pa <= pc)
|
if (pa <= pb && pa <= pc) {
|
||||||
buffer[j++] = left + c;
|
buffer[j++] = left + c;
|
||||||
else if (pb <= pc)
|
} else if (pb <= pc) {
|
||||||
buffer[j++] = up + c;
|
buffer[j++] = up + c;
|
||||||
else
|
} else {
|
||||||
buffer[j++] = upLeft + c;
|
buffer[j++] = upLeft + c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -826,12 +859,14 @@ var JpegStream = (function JpegStreamClosure() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
|
JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
|
||||||
if (this.bufferLength)
|
if (this.bufferLength) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
var jpegImage = new JpegImage();
|
var jpegImage = new JpegImage();
|
||||||
if (this.colorTransform != -1)
|
if (this.colorTransform != -1) {
|
||||||
jpegImage.colorTransform = this.colorTransform;
|
jpegImage.colorTransform = this.colorTransform;
|
||||||
|
}
|
||||||
jpegImage.parse(this.bytes);
|
jpegImage.parse(this.bytes);
|
||||||
var width = jpegImage.width;
|
var width = jpegImage.width;
|
||||||
var height = jpegImage.height;
|
var height = jpegImage.height;
|
||||||
@ -851,7 +886,7 @@ var JpegStream = (function JpegStreamClosure() {
|
|||||||
* further processing such as color space conversions.
|
* further processing such as color space conversions.
|
||||||
*/
|
*/
|
||||||
JpegStream.prototype.isNativelySupported =
|
JpegStream.prototype.isNativelySupported =
|
||||||
function JpegStream_isNativelySupported(xref, res) {
|
function JpegStream_isNativelySupported(xref, res) {
|
||||||
var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
|
var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
|
||||||
return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
|
return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
|
||||||
};
|
};
|
||||||
@ -859,7 +894,7 @@ var JpegStream = (function JpegStreamClosure() {
|
|||||||
* Checks if the image can be decoded by the browser.
|
* Checks if the image can be decoded by the browser.
|
||||||
*/
|
*/
|
||||||
JpegStream.prototype.isNativelyDecodable =
|
JpegStream.prototype.isNativelyDecodable =
|
||||||
function JpegStream_isNativelyDecodable(xref, res) {
|
function JpegStream_isNativelyDecodable(xref, res) {
|
||||||
var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
|
var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
|
||||||
var numComps = cs.numComps;
|
var numComps = cs.numComps;
|
||||||
return numComps == 1 || numComps == 3;
|
return numComps == 1 || numComps == 3;
|
||||||
@ -892,8 +927,9 @@ var JpxStream = (function JpxStreamClosure() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
|
JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
|
||||||
if (this.bufferLength)
|
if (this.bufferLength) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var jpxImage = new JpxImage();
|
var jpxImage = new JpxImage();
|
||||||
jpxImage.parse(this.bytes);
|
jpxImage.parse(this.bytes);
|
||||||
@ -901,8 +937,9 @@ var JpxStream = (function JpxStreamClosure() {
|
|||||||
var width = jpxImage.width;
|
var width = jpxImage.width;
|
||||||
var height = jpxImage.height;
|
var height = jpxImage.height;
|
||||||
var componentsCount = jpxImage.componentsCount;
|
var componentsCount = jpxImage.componentsCount;
|
||||||
if (componentsCount != 1 && componentsCount != 3 && componentsCount != 4)
|
if (componentsCount != 1 && componentsCount != 3 && componentsCount != 4) {
|
||||||
error('JPX with ' + componentsCount + ' components is not supported');
|
error('JPX with ' + componentsCount + ' components is not supported');
|
||||||
|
}
|
||||||
|
|
||||||
var data = new Uint8Array(width * height * componentsCount);
|
var data = new Uint8Array(width * height * componentsCount);
|
||||||
|
|
||||||
@ -922,8 +959,9 @@ var JpxStream = (function JpxStreamClosure() {
|
|||||||
rowFeed = width - tileWidth;
|
rowFeed = width - tileWidth;
|
||||||
sourcePosition = 0;
|
sourcePosition = 0;
|
||||||
for (var j = 0; j < tileHeight; j++) {
|
for (var j = 0; j < tileHeight; j++) {
|
||||||
for (var i = 0; i < tileWidth; i++)
|
for (var i = 0; i < tileWidth; i++) {
|
||||||
data[dataPosition++] = data0[sourcePosition++];
|
data[dataPosition++] = data0[sourcePosition++];
|
||||||
|
}
|
||||||
dataPosition += rowFeed;
|
dataPosition += rowFeed;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1000,8 +1038,9 @@ var Jbig2Stream = (function Jbig2StreamClosure() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
|
Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
|
||||||
if (this.bufferLength)
|
if (this.bufferLength) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var jbig2Image = new Jbig2Image();
|
var jbig2Image = new Jbig2Image();
|
||||||
|
|
||||||
@ -1026,8 +1065,9 @@ var Jbig2Stream = (function Jbig2StreamClosure() {
|
|||||||
var dataLength = data.length;
|
var dataLength = data.length;
|
||||||
|
|
||||||
// JBIG2 had black as 1 and white as 0, inverting the colors
|
// JBIG2 had black as 1 and white as 0, inverting the colors
|
||||||
for (var i = 0; i < dataLength; i++)
|
for (var i = 0; i < dataLength; i++) {
|
||||||
data[i] ^= 0xFF;
|
data[i] ^= 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
this.buffer = data;
|
this.buffer = data;
|
||||||
this.bufferLength = dataLength;
|
this.bufferLength = dataLength;
|
||||||
@ -1073,8 +1113,9 @@ var DecryptStream = (function DecryptStreamClosure() {
|
|||||||
var bufferLength = this.bufferLength;
|
var bufferLength = this.bufferLength;
|
||||||
var i, n = chunk.length;
|
var i, n = chunk.length;
|
||||||
var buffer = this.ensureBuffer(bufferLength + n);
|
var buffer = this.ensureBuffer(bufferLength + n);
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++) {
|
||||||
buffer[bufferLength++] = chunk[i];
|
buffer[bufferLength++] = chunk[i];
|
||||||
|
}
|
||||||
this.bufferLength = bufferLength;
|
this.bufferLength = bufferLength;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1119,8 +1160,9 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
|
|||||||
// special code for z
|
// special code for z
|
||||||
if (c == Z_LOWER_CHAR) {
|
if (c == Z_LOWER_CHAR) {
|
||||||
buffer = this.ensureBuffer(bufferLength + 4);
|
buffer = this.ensureBuffer(bufferLength + 4);
|
||||||
for (var i = 0; i < 4; ++i)
|
for (var i = 0; i < 4; ++i) {
|
||||||
buffer[bufferLength + i] = 0;
|
buffer[bufferLength + i] = 0;
|
||||||
|
}
|
||||||
this.bufferLength += 4;
|
this.bufferLength += 4;
|
||||||
} else {
|
} else {
|
||||||
var input = this.input;
|
var input = this.input;
|
||||||
@ -1133,21 +1175,24 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
|
|||||||
|
|
||||||
input[i] = c;
|
input[i] = c;
|
||||||
|
|
||||||
if (c === EOF || c == TILDA_CHAR)
|
if (c === EOF || c == TILDA_CHAR) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buffer = this.ensureBuffer(bufferLength + i - 1);
|
buffer = this.ensureBuffer(bufferLength + i - 1);
|
||||||
this.bufferLength += i - 1;
|
this.bufferLength += i - 1;
|
||||||
|
|
||||||
// partial ending;
|
// partial ending;
|
||||||
if (i < 5) {
|
if (i < 5) {
|
||||||
for (; i < 5; ++i)
|
for (; i < 5; ++i) {
|
||||||
input[i] = 0x21 + 84;
|
input[i] = 0x21 + 84;
|
||||||
|
}
|
||||||
this.eof = true;
|
this.eof = true;
|
||||||
}
|
}
|
||||||
var t = 0;
|
var t = 0;
|
||||||
for (var i = 0; i < 5; ++i)
|
for (var i = 0; i < 5; ++i) {
|
||||||
t = t * 85 + (input[i] - 0x21);
|
t = t * 85 + (input[i] - 0x21);
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 3; i >= 0; --i) {
|
for (var i = 3; i >= 0; --i) {
|
||||||
buffer[bufferLength + i] = t & 0xFF;
|
buffer[bufferLength + i] = t & 0xFF;
|
||||||
@ -1257,8 +1302,9 @@ var RunLengthStream = (function RunLengthStreamClosure() {
|
|||||||
n = 257 - n;
|
n = 257 - n;
|
||||||
var b = repeatHeader[1];
|
var b = repeatHeader[1];
|
||||||
var buffer = this.ensureBuffer(bufferLength + n + 1);
|
var buffer = this.ensureBuffer(bufferLength + n + 1);
|
||||||
for (var i = 0; i < n; i++)
|
for (var i = 0; i < n; i++) {
|
||||||
buffer[bufferLength++] = b;
|
buffer[bufferLength++] = b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.bufferLength = bufferLength;
|
this.bufferLength = bufferLength;
|
||||||
};
|
};
|
||||||
@ -1706,8 +1752,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
this.columns = params.get('Columns') || 1728;
|
this.columns = params.get('Columns') || 1728;
|
||||||
this.rows = params.get('Rows') || 0;
|
this.rows = params.get('Rows') || 0;
|
||||||
var eoblock = params.get('EndOfBlock');
|
var eoblock = params.get('EndOfBlock');
|
||||||
if (eoblock === null || eoblock === undefined)
|
if (eoblock === null || eoblock === undefined) {
|
||||||
eoblock = true;
|
eoblock = true;
|
||||||
|
}
|
||||||
this.eoblock = eoblock;
|
this.eoblock = eoblock;
|
||||||
this.black = params.get('BlackIs1') || false;
|
this.black = params.get('BlackIs1') || false;
|
||||||
|
|
||||||
@ -1749,7 +1796,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CCITTFaxStream.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;
|
||||||
|
|
||||||
@ -1769,7 +1816,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CCITTFaxStream.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;
|
||||||
|
|
||||||
@ -1779,8 +1826,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
this.err = true;
|
this.err = true;
|
||||||
a1 = this.columns;
|
a1 = this.columns;
|
||||||
}
|
}
|
||||||
if ((codingPos & 1) ^ blackPixels)
|
if ((codingPos & 1) ^ blackPixels) {
|
||||||
++codingPos;
|
++codingPos;
|
||||||
|
}
|
||||||
|
|
||||||
codingLine[codingPos] = a1;
|
codingLine[codingPos] = a1;
|
||||||
} else if (a1 < codingLine[codingPos]) {
|
} else if (a1 < codingLine[codingPos]) {
|
||||||
@ -1789,8 +1837,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
this.err = true;
|
this.err = true;
|
||||||
a1 = 0;
|
a1 = 0;
|
||||||
}
|
}
|
||||||
while (codingPos > 0 && a1 < codingLine[codingPos - 1])
|
while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
|
||||||
--codingPos;
|
--codingPos;
|
||||||
|
}
|
||||||
codingLine[codingPos] = a1;
|
codingLine[codingPos] = a1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1805,16 +1854,16 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
var refPos, blackPixels, bits;
|
var refPos, blackPixels, bits;
|
||||||
|
|
||||||
if (this.outputBits === 0) {
|
if (this.outputBits === 0) {
|
||||||
if (this.eof)
|
if (this.eof) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
this.err = false;
|
this.err = false;
|
||||||
|
|
||||||
var code1, code2, code3;
|
var code1, code2, code3;
|
||||||
if (this.nextLine2D) {
|
if (this.nextLine2D) {
|
||||||
for (var i = 0; codingLine[i] < columns; ++i)
|
for (var i = 0; codingLine[i] < columns; ++i) {
|
||||||
refLine[i] = codingLine[i];
|
refLine[i] = codingLine[i];
|
||||||
|
}
|
||||||
refLine[i++] = columns;
|
refLine[i++] = columns;
|
||||||
refLine[i] = columns;
|
refLine[i] = columns;
|
||||||
codingLine[0] = 0;
|
codingLine[0] = 0;
|
||||||
@ -1827,8 +1876,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
switch (code1) {
|
switch (code1) {
|
||||||
case twoDimPass:
|
case twoDimPass:
|
||||||
this.addPixels(refLine[refPos + 1], blackPixels);
|
this.addPixels(refLine[refPos + 1], blackPixels);
|
||||||
if (refLine[refPos + 1] < columns)
|
if (refLine[refPos + 1] < columns) {
|
||||||
refPos += 2;
|
refPos += 2;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case twoDimHoriz:
|
case twoDimHoriz:
|
||||||
code1 = code2 = 0;
|
code1 = code2 = 0;
|
||||||
@ -1864,8 +1914,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
if (codingLine[this.codingPos] < columns) {
|
if (codingLine[this.codingPos] < columns) {
|
||||||
++refPos;
|
++refPos;
|
||||||
while (refLine[refPos] <= codingLine[this.codingPos] &&
|
while (refLine[refPos] <= codingLine[this.codingPos] &&
|
||||||
refLine[refPos] < columns)
|
refLine[refPos] < columns) {
|
||||||
refPos += 2;
|
refPos += 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case twoDimVertR2:
|
case twoDimVertR2:
|
||||||
@ -1885,8 +1936,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
if (codingLine[this.codingPos] < columns) {
|
if (codingLine[this.codingPos] < columns) {
|
||||||
++refPos;
|
++refPos;
|
||||||
while (refLine[refPos] <= codingLine[this.codingPos] &&
|
while (refLine[refPos] <= codingLine[this.codingPos] &&
|
||||||
refLine[refPos] < columns)
|
refLine[refPos] < columns) {
|
||||||
refPos += 2;
|
refPos += 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case twoDimVert0:
|
case twoDimVert0:
|
||||||
@ -1895,48 +1947,54 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
if (codingLine[this.codingPos] < columns) {
|
if (codingLine[this.codingPos] < columns) {
|
||||||
++refPos;
|
++refPos;
|
||||||
while (refLine[refPos] <= codingLine[this.codingPos] &&
|
while (refLine[refPos] <= codingLine[this.codingPos] &&
|
||||||
refLine[refPos] < columns)
|
refLine[refPos] < columns) {
|
||||||
refPos += 2;
|
refPos += 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case twoDimVertL3:
|
case twoDimVertL3:
|
||||||
this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
|
this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
|
||||||
blackPixels ^= 1;
|
blackPixels ^= 1;
|
||||||
if (codingLine[this.codingPos] < columns) {
|
if (codingLine[this.codingPos] < columns) {
|
||||||
if (refPos > 0)
|
if (refPos > 0) {
|
||||||
--refPos;
|
--refPos;
|
||||||
else
|
} else {
|
||||||
++refPos;
|
++refPos;
|
||||||
|
}
|
||||||
while (refLine[refPos] <= codingLine[this.codingPos] &&
|
while (refLine[refPos] <= codingLine[this.codingPos] &&
|
||||||
refLine[refPos] < columns)
|
refLine[refPos] < columns) {
|
||||||
refPos += 2;
|
refPos += 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case twoDimVertL2:
|
case twoDimVertL2:
|
||||||
this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
|
this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
|
||||||
blackPixels ^= 1;
|
blackPixels ^= 1;
|
||||||
if (codingLine[this.codingPos] < columns) {
|
if (codingLine[this.codingPos] < columns) {
|
||||||
if (refPos > 0)
|
if (refPos > 0) {
|
||||||
--refPos;
|
--refPos;
|
||||||
else
|
} else {
|
||||||
++refPos;
|
++refPos;
|
||||||
|
}
|
||||||
while (refLine[refPos] <= codingLine[this.codingPos] &&
|
while (refLine[refPos] <= codingLine[this.codingPos] &&
|
||||||
refLine[refPos] < columns)
|
refLine[refPos] < columns) {
|
||||||
refPos += 2;
|
refPos += 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case twoDimVertL1:
|
case twoDimVertL1:
|
||||||
this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
|
this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
|
||||||
blackPixels ^= 1;
|
blackPixels ^= 1;
|
||||||
if (codingLine[this.codingPos] < columns) {
|
if (codingLine[this.codingPos] < columns) {
|
||||||
if (refPos > 0)
|
if (refPos > 0) {
|
||||||
--refPos;
|
--refPos;
|
||||||
else
|
} else {
|
||||||
++refPos;
|
++refPos;
|
||||||
|
}
|
||||||
while (refLine[refPos] <= codingLine[this.codingPos] &&
|
while (refLine[refPos] <= codingLine[this.codingPos] &&
|
||||||
refLine[refPos] < columns)
|
refLine[refPos] < columns) {
|
||||||
refPos += 2;
|
refPos += 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EOF:
|
case EOF:
|
||||||
@ -1969,8 +2027,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.byteAlign)
|
if (this.byteAlign) {
|
||||||
this.inputBits &= ~7;
|
this.inputBits &= ~7;
|
||||||
|
}
|
||||||
|
|
||||||
var gotEOL = false;
|
var gotEOL = false;
|
||||||
|
|
||||||
@ -2006,8 +2065,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
if (this.encoding >= 0) {
|
if (this.encoding >= 0) {
|
||||||
for (var i = 0; i < 4; ++i) {
|
for (var i = 0; i < 4; ++i) {
|
||||||
code1 = this.lookBits(12);
|
code1 = this.lookBits(12);
|
||||||
if (code1 != 1)
|
if (code1 != 1) {
|
||||||
info('bad rtc code: ' + code1);
|
info('bad rtc code: ' + code1);
|
||||||
|
}
|
||||||
this.eatBits(12);
|
this.eatBits(12);
|
||||||
if (this.encoding > 0) {
|
if (this.encoding > 0) {
|
||||||
this.lookBits(1);
|
this.lookBits(1);
|
||||||
@ -2036,10 +2096,11 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codingLine[0] > 0)
|
if (codingLine[0] > 0) {
|
||||||
this.outputBits = codingLine[this.codingPos = 0];
|
this.outputBits = codingLine[this.codingPos = 0];
|
||||||
else
|
} else {
|
||||||
this.outputBits = codingLine[this.codingPos = 1];
|
this.outputBits = codingLine[this.codingPos = 1];
|
||||||
|
}
|
||||||
this.row++;
|
this.row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2094,15 +2155,17 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
// returned. The second array element is the actual code. The third array
|
// returned. The second array element is the actual code. The third array
|
||||||
// element indicates whether EOF was reached.
|
// element indicates whether EOF was reached.
|
||||||
CCITTFaxStream.prototype.findTableCode =
|
CCITTFaxStream.prototype.findTableCode =
|
||||||
function ccittFaxStreamFindTableCode(start, end, table, limit) {
|
function ccittFaxStreamFindTableCode(start, end, table, limit) {
|
||||||
|
|
||||||
var limitValue = limit || 0;
|
var limitValue = limit || 0;
|
||||||
for (var i = start; i <= end; ++i) {
|
for (var i = start; i <= end; ++i) {
|
||||||
var code = this.lookBits(i);
|
var code = this.lookBits(i);
|
||||||
if (code == EOF)
|
if (code == EOF) {
|
||||||
return [true, 1, false];
|
return [true, 1, false];
|
||||||
if (i < end)
|
}
|
||||||
|
if (i < end) {
|
||||||
code <<= end - i;
|
code <<= end - i;
|
||||||
|
}
|
||||||
if (!limitValue || code >= limitValue) {
|
if (!limitValue || code >= limitValue) {
|
||||||
var p = table[code - limitValue];
|
var p = table[code - limitValue];
|
||||||
if (p[0] == i) {
|
if (p[0] == i) {
|
||||||
@ -2115,7 +2178,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CCITTFaxStream.prototype.getTwoDimCode =
|
CCITTFaxStream.prototype.getTwoDimCode =
|
||||||
function ccittFaxStreamGetTwoDimCode() {
|
function ccittFaxStreamGetTwoDimCode() {
|
||||||
|
|
||||||
var code = 0;
|
var code = 0;
|
||||||
var p;
|
var p;
|
||||||
@ -2128,28 +2191,31 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var result = this.findTableCode(1, 7, twoDimTable);
|
var result = this.findTableCode(1, 7, twoDimTable);
|
||||||
if (result[0] && result[2])
|
if (result[0] && result[2]) {
|
||||||
return result[1];
|
return result[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
info('Bad two dim code');
|
info('Bad two dim code');
|
||||||
return EOF;
|
return EOF;
|
||||||
};
|
};
|
||||||
|
|
||||||
CCITTFaxStream.prototype.getWhiteCode =
|
CCITTFaxStream.prototype.getWhiteCode =
|
||||||
function ccittFaxStreamGetWhiteCode() {
|
function ccittFaxStreamGetWhiteCode() {
|
||||||
|
|
||||||
var code = 0;
|
var code = 0;
|
||||||
var p;
|
var p;
|
||||||
var n;
|
var n;
|
||||||
if (this.eoblock) {
|
if (this.eoblock) {
|
||||||
code = this.lookBits(12);
|
code = this.lookBits(12);
|
||||||
if (code == EOF)
|
if (code == EOF) {
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if ((code >> 5) === 0)
|
if ((code >> 5) === 0) {
|
||||||
p = whiteTable1[code];
|
p = whiteTable1[code];
|
||||||
else
|
} else {
|
||||||
p = whiteTable2[code >> 3];
|
p = whiteTable2[code >> 3];
|
||||||
|
}
|
||||||
|
|
||||||
if (p[0] > 0) {
|
if (p[0] > 0) {
|
||||||
this.eatBits(p[0]);
|
this.eatBits(p[0]);
|
||||||
@ -2157,12 +2223,14 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var result = this.findTableCode(1, 9, whiteTable2);
|
var result = this.findTableCode(1, 9, whiteTable2);
|
||||||
if (result[0])
|
if (result[0]) {
|
||||||
return result[1];
|
return result[1];
|
||||||
|
}
|
||||||
|
|
||||||
result = this.findTableCode(11, 12, whiteTable1);
|
result = this.findTableCode(11, 12, whiteTable1);
|
||||||
if (result[0])
|
if (result[0]) {
|
||||||
return result[1];
|
return result[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
info('bad white code');
|
info('bad white code');
|
||||||
this.eatBits(1);
|
this.eatBits(1);
|
||||||
@ -2170,19 +2238,21 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CCITTFaxStream.prototype.getBlackCode =
|
CCITTFaxStream.prototype.getBlackCode =
|
||||||
function ccittFaxStreamGetBlackCode() {
|
function ccittFaxStreamGetBlackCode() {
|
||||||
|
|
||||||
var code, p;
|
var code, p;
|
||||||
if (this.eoblock) {
|
if (this.eoblock) {
|
||||||
code = this.lookBits(13);
|
code = this.lookBits(13);
|
||||||
if (code == EOF)
|
if (code == EOF) {
|
||||||
return 1;
|
return 1;
|
||||||
if ((code >> 7) === 0)
|
}
|
||||||
|
if ((code >> 7) === 0) {
|
||||||
p = blackTable1[code];
|
p = blackTable1[code];
|
||||||
else if ((code >> 9) === 0 && (code >> 7) !== 0)
|
} else if ((code >> 9) === 0 && (code >> 7) !== 0) {
|
||||||
p = blackTable2[(code >> 1) - 64];
|
p = blackTable2[(code >> 1) - 64];
|
||||||
else
|
} else {
|
||||||
p = blackTable3[code >> 7];
|
p = blackTable3[code >> 7];
|
||||||
|
}
|
||||||
|
|
||||||
if (p[0] > 0) {
|
if (p[0] > 0) {
|
||||||
this.eatBits(p[0]);
|
this.eatBits(p[0]);
|
||||||
@ -2190,16 +2260,19 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var result = this.findTableCode(2, 6, blackTable3);
|
var result = this.findTableCode(2, 6, blackTable3);
|
||||||
if (result[0])
|
if (result[0]) {
|
||||||
return result[1];
|
return result[1];
|
||||||
|
}
|
||||||
|
|
||||||
result = this.findTableCode(7, 12, blackTable2, 64);
|
result = this.findTableCode(7, 12, blackTable2, 64);
|
||||||
if (result[0])
|
if (result[0]) {
|
||||||
return result[1];
|
return result[1];
|
||||||
|
}
|
||||||
|
|
||||||
result = this.findTableCode(10, 13, blackTable1);
|
result = this.findTableCode(10, 13, blackTable1);
|
||||||
if (result[0])
|
if (result[0]) {
|
||||||
return result[1];
|
return result[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
info('bad black code');
|
info('bad black code');
|
||||||
this.eatBits(1);
|
this.eatBits(1);
|
||||||
@ -2210,8 +2283,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
var c;
|
var c;
|
||||||
while (this.inputBits < n) {
|
while (this.inputBits < n) {
|
||||||
if ((c = this.str.getByte()) === -1) {
|
if ((c = this.str.getByte()) === -1) {
|
||||||
if (this.inputBits === 0)
|
if (this.inputBits === 0) {
|
||||||
return EOF;
|
return EOF;
|
||||||
|
}
|
||||||
return ((this.inputBuf << (n - this.inputBits)) &
|
return ((this.inputBuf << (n - this.inputBits)) &
|
||||||
(0xFFFF >> (16 - n)));
|
(0xFFFF >> (16 - n)));
|
||||||
}
|
}
|
||||||
@ -2222,8 +2296,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
|
CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
|
||||||
if ((this.inputBits -= n) < 0)
|
if ((this.inputBits -= n) < 0) {
|
||||||
this.inputBits = 0;
|
this.inputBits = 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return CCITTFaxStream;
|
return CCITTFaxStream;
|
||||||
@ -2282,8 +2357,9 @@ var LZWStream = (function LZWStreamClosure() {
|
|||||||
var i, j, q;
|
var i, j, q;
|
||||||
|
|
||||||
var lzwState = this.lzwState;
|
var lzwState = this.lzwState;
|
||||||
if (!lzwState)
|
if (!lzwState) {
|
||||||
return; // eof was found
|
return; // eof was found
|
||||||
|
}
|
||||||
|
|
||||||
var earlyChange = lzwState.earlyChange;
|
var earlyChange = lzwState.earlyChange;
|
||||||
var nextCode = lzwState.nextCode;
|
var nextCode = lzwState.nextCode;
|
||||||
@ -2344,8 +2420,9 @@ var LZWStream = (function LZWStreamClosure() {
|
|||||||
} while (estimatedDecodedSize < decodedLength);
|
} while (estimatedDecodedSize < decodedLength);
|
||||||
buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
|
buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
|
||||||
}
|
}
|
||||||
for (j = 0; j < currentSequenceLength; j++)
|
for (j = 0; j < currentSequenceLength; j++) {
|
||||||
buffer[currentBufferLength++] = currentSequence[j];
|
buffer[currentBufferLength++] = currentSequence[j];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lzwState.nextCode = nextCode;
|
lzwState.nextCode = nextCode;
|
||||||
lzwState.codeLength = codeLength;
|
lzwState.codeLength = codeLength;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user