Remove caching of stream data and fix object loader for streams.

This commit is contained in:
Brendan Dahl 2013-07-03 14:29:38 -07:00
parent 81fa4a0d93
commit 09aafa830b
3 changed files with 48 additions and 23 deletions

View File

@ -46,6 +46,10 @@ var ChunkedStream = (function ChunkedStreamClosure() {
return chunks; return chunks;
}, },
getBaseStreams: function ChunkedStream_getBaseStreams() {
return [this];
},
allChunksLoaded: function ChunkedStream_allChunksLoaded() { allChunksLoaded: function ChunkedStream_allChunksLoaded() {
return this.numChunksLoaded === this.numChunks; return this.numChunksLoaded === this.numChunks;
}, },

View File

@ -960,14 +960,7 @@ var XRef = (function XRefClosure() {
} else { } else {
e = parser.getObj(); e = parser.getObj();
} }
if (!isStream(e) || e instanceof JpegStream) { if (!isStream(e)) {
this.cache[num] = e;
} else if (e instanceof Stream) {
e = e.makeSubStream(e.start, e.length, e.dict);
this.cache[num] = e;
} else if ('readBlock' in e) {
e.getBytes();
e = e.makeSubStream(0, e.bufferLength, e.dict);
this.cache[num] = e; this.cache[num] = e;
} }
return e; return e;
@ -1296,13 +1289,22 @@ var ObjectLoader = (function() {
pendingRequests.push({ begin: e.begin, end: e.end }); pendingRequests.push({ begin: e.begin, end: e.end });
} }
} }
if (currentNode instanceof ChunkedStream && if (currentNode && currentNode.getBaseStreams) {
currentNode.getMissingChunks().length) { var baseStreams = currentNode.getBaseStreams();
nodesToRevisit.push(currentNode); var foundMissingData = false;
pendingRequests.push({ for (var i = 0; i < baseStreams.length; i++) {
begin: currentNode.start, var stream = baseStreams[i];
end: currentNode.end if (stream.getMissingChunks && stream.getMissingChunks().length) {
}); foundMissingData = true;
pendingRequests.push({
begin: stream.start,
end: stream.end
});
}
}
if (foundMissingData) {
nodesToRevisit.push(currentNode);
}
} }
addChildren(currentNode, nodesToVisit); addChildren(currentNode, nodesToVisit);

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/* globals bytesToString, ColorSpace, Dict, EOF, error, info, Jbig2Image, /* globals bytesToString, ColorSpace, Dict, EOF, error, info, Jbig2Image,
JpegImage, JpxImage, Lexer */ JpegImage, JpxImage, Lexer, Util */
'use strict'; 'use strict';
@ -202,6 +202,12 @@ var DecodeStream = (function DecodeStreamClosure() {
}, },
reset: function DecodeStream_reset() { reset: function DecodeStream_reset() {
this.pos = 0; this.pos = 0;
},
getBaseStreams: function DecodeStream_getBaseStreams() {
if (this.str && this.str.getBaseStreams) {
return this.str.getBaseStreams();
}
return [];
} }
}; };
@ -272,6 +278,19 @@ var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
this.bufferLength = newLength; this.bufferLength = newLength;
}; };
StreamsSequenceStream.prototype.getBaseStreams =
function StreamsSequenceStream_getBaseStreams() {
var baseStreams = [];
for (var i = 0, ii = this.streams.length; i < ii; i++) {
var stream = this.streams[i];
if (stream.getBaseStreams) {
Util.concatenateToArray(baseStreams, stream.getBaseStreams());
}
}
return baseStreams;
};
return StreamsSequenceStream; return StreamsSequenceStream;
})(); })();
@ -618,11 +637,11 @@ var FlateStream = (function FlateStreamClosure() {
})(); })();
var PredictorStream = (function PredictorStreamClosure() { var PredictorStream = (function PredictorStreamClosure() {
function PredictorStream(stream, params) { function PredictorStream(str, params) {
var predictor = this.predictor = params.get('Predictor') || 1; var predictor = this.predictor = params.get('Predictor') || 1;
if (predictor <= 1) if (predictor <= 1)
return stream; // 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);
@ -631,8 +650,8 @@ var PredictorStream = (function PredictorStreamClosure() {
else else
this.readBlock = this.readBlockPng; this.readBlock = this.readBlockPng;
this.stream = stream; this.str = str;
this.dict = stream.dict; this.dict = str.dict;
var colors = this.colors = params.get('Colors') || 1; var colors = this.colors = params.get('Colors') || 1;
var bits = this.bits = params.get('BitsPerComponent') || 8; var bits = this.bits = params.get('BitsPerComponent') || 8;
@ -657,7 +676,7 @@ var PredictorStream = (function PredictorStreamClosure() {
var bits = this.bits; var bits = this.bits;
var colors = this.colors; var colors = this.colors;
var rawBytes = this.stream.getBytes(rowBytes); var rawBytes = this.str.getBytes(rowBytes);
this.eof = !rawBytes.length; this.eof = !rawBytes.length;
if (this.eof) { if (this.eof) {
return; return;
@ -720,8 +739,8 @@ var PredictorStream = (function PredictorStreamClosure() {
var rowBytes = this.rowBytes; var rowBytes = this.rowBytes;
var pixBytes = this.pixBytes; var pixBytes = this.pixBytes;
var predictor = this.stream.getByte(); var predictor = this.str.getByte();
var rawBytes = this.stream.getBytes(rowBytes); var rawBytes = this.str.getBytes(rowBytes);
this.eof = !rawBytes.length; this.eof = !rawBytes.length;
if (this.eof) { if (this.eof) {
return; return;