Fix coding style in src/core/stream.js

This commit is contained in:
Jonas Jenwald 2014-03-22 21:19:08 +01:00
parent 67b5c8868c
commit 6883362a84

View File

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