Merge pull request #3441 from brendandahl/less-cache
Remove caching of stream data and fix object loader for streams.
This commit is contained in:
commit
e67b9a7f17
@ -46,6 +46,10 @@ var ChunkedStream = (function ChunkedStreamClosure() {
|
||||
return chunks;
|
||||
},
|
||||
|
||||
getBaseStreams: function ChunkedStream_getBaseStreams() {
|
||||
return [this];
|
||||
},
|
||||
|
||||
allChunksLoaded: function ChunkedStream_allChunksLoaded() {
|
||||
return this.numChunksLoaded === this.numChunks;
|
||||
},
|
||||
|
32
src/obj.js
32
src/obj.js
@ -960,14 +960,7 @@ var XRef = (function XRefClosure() {
|
||||
} else {
|
||||
e = parser.getObj();
|
||||
}
|
||||
if (!isStream(e) || e instanceof JpegStream) {
|
||||
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);
|
||||
if (!isStream(e)) {
|
||||
this.cache[num] = e;
|
||||
}
|
||||
return e;
|
||||
@ -1296,13 +1289,22 @@ var ObjectLoader = (function() {
|
||||
pendingRequests.push({ begin: e.begin, end: e.end });
|
||||
}
|
||||
}
|
||||
if (currentNode instanceof ChunkedStream &&
|
||||
currentNode.getMissingChunks().length) {
|
||||
nodesToRevisit.push(currentNode);
|
||||
pendingRequests.push({
|
||||
begin: currentNode.start,
|
||||
end: currentNode.end
|
||||
});
|
||||
if (currentNode && currentNode.getBaseStreams) {
|
||||
var baseStreams = currentNode.getBaseStreams();
|
||||
var foundMissingData = false;
|
||||
for (var i = 0; i < baseStreams.length; i++) {
|
||||
var stream = baseStreams[i];
|
||||
if (stream.getMissingChunks && stream.getMissingChunks().length) {
|
||||
foundMissingData = true;
|
||||
pendingRequests.push({
|
||||
begin: stream.start,
|
||||
end: stream.end
|
||||
});
|
||||
}
|
||||
}
|
||||
if (foundMissingData) {
|
||||
nodesToRevisit.push(currentNode);
|
||||
}
|
||||
}
|
||||
|
||||
addChildren(currentNode, nodesToVisit);
|
||||
|
@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals bytesToString, ColorSpace, Dict, EOF, error, info, Jbig2Image,
|
||||
JpegImage, JpxImage, Lexer */
|
||||
JpegImage, JpxImage, Lexer, Util */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -202,6 +202,12 @@ var DecodeStream = (function DecodeStreamClosure() {
|
||||
},
|
||||
reset: function DecodeStream_reset() {
|
||||
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;
|
||||
};
|
||||
|
||||
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;
|
||||
})();
|
||||
|
||||
@ -618,11 +637,11 @@ var FlateStream = (function FlateStreamClosure() {
|
||||
})();
|
||||
|
||||
var PredictorStream = (function PredictorStreamClosure() {
|
||||
function PredictorStream(stream, params) {
|
||||
function PredictorStream(str, params) {
|
||||
var predictor = this.predictor = params.get('Predictor') || 1;
|
||||
|
||||
if (predictor <= 1)
|
||||
return stream; // no prediction
|
||||
return str; // no prediction
|
||||
if (predictor !== 2 && (predictor < 10 || predictor > 15))
|
||||
error('Unsupported predictor: ' + predictor);
|
||||
|
||||
@ -631,8 +650,8 @@ var PredictorStream = (function PredictorStreamClosure() {
|
||||
else
|
||||
this.readBlock = this.readBlockPng;
|
||||
|
||||
this.stream = stream;
|
||||
this.dict = stream.dict;
|
||||
this.str = str;
|
||||
this.dict = str.dict;
|
||||
|
||||
var colors = this.colors = params.get('Colors') || 1;
|
||||
var bits = this.bits = params.get('BitsPerComponent') || 8;
|
||||
@ -657,7 +676,7 @@ var PredictorStream = (function PredictorStreamClosure() {
|
||||
var bits = this.bits;
|
||||
var colors = this.colors;
|
||||
|
||||
var rawBytes = this.stream.getBytes(rowBytes);
|
||||
var rawBytes = this.str.getBytes(rowBytes);
|
||||
this.eof = !rawBytes.length;
|
||||
if (this.eof) {
|
||||
return;
|
||||
@ -720,8 +739,8 @@ var PredictorStream = (function PredictorStreamClosure() {
|
||||
var rowBytes = this.rowBytes;
|
||||
var pixBytes = this.pixBytes;
|
||||
|
||||
var predictor = this.stream.getByte();
|
||||
var rawBytes = this.stream.getBytes(rowBytes);
|
||||
var predictor = this.str.getByte();
|
||||
var rawBytes = this.str.getBytes(rowBytes);
|
||||
this.eof = !rawBytes.length;
|
||||
if (this.eof) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user