Move the RunLengthStream
from src/core/stream.js
and into its own file
This commit is contained in:
parent
1f0685cee6
commit
342b0c1bbc
@ -19,7 +19,6 @@ import {
|
||||
FlateStream,
|
||||
NullStream,
|
||||
PredictorStream,
|
||||
RunLengthStream,
|
||||
} from "./stream.js";
|
||||
import {
|
||||
assert,
|
||||
@ -47,6 +46,7 @@ import { Jbig2Stream } from "./jbig2_stream.js";
|
||||
import { JpegStream } from "./jpeg_stream.js";
|
||||
import { JpxStream } from "./jpx_stream.js";
|
||||
import { LZWStream } from "./lzw_stream.js";
|
||||
import { RunLengthStream } from "./run_length_stream.js";
|
||||
|
||||
const MAX_LENGTH_TO_CACHE = 1000;
|
||||
const MAX_ADLER32_LENGTH = 5552;
|
||||
|
67
src/core/run_length_stream.js
Normal file
67
src/core/run_length_stream.js
Normal file
@ -0,0 +1,67 @@
|
||||
/* Copyright 2012 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* eslint-disable no-var */
|
||||
|
||||
import { DecodeStream } from "./stream.js";
|
||||
|
||||
var RunLengthStream = (function RunLengthStreamClosure() {
|
||||
// eslint-disable-next-line no-shadow
|
||||
function RunLengthStream(str, maybeLength) {
|
||||
this.str = str;
|
||||
this.dict = str.dict;
|
||||
|
||||
DecodeStream.call(this, maybeLength);
|
||||
}
|
||||
|
||||
RunLengthStream.prototype = Object.create(DecodeStream.prototype);
|
||||
|
||||
RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
|
||||
// The repeatHeader has following format. The first byte defines type of run
|
||||
// and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
|
||||
// (in addition to the second byte from the header), n = 129 through 255 -
|
||||
// duplicate the second byte from the header (257 - n) times, n = 128 - end.
|
||||
var repeatHeader = this.str.getBytes(2);
|
||||
if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
|
||||
this.eof = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var buffer;
|
||||
var bufferLength = this.bufferLength;
|
||||
var n = repeatHeader[0];
|
||||
if (n < 128) {
|
||||
// copy n bytes
|
||||
buffer = this.ensureBuffer(bufferLength + n + 1);
|
||||
buffer[bufferLength++] = repeatHeader[1];
|
||||
if (n > 0) {
|
||||
var source = this.str.getBytes(n);
|
||||
buffer.set(source, bufferLength);
|
||||
bufferLength += n;
|
||||
}
|
||||
} else {
|
||||
n = 257 - n;
|
||||
var b = repeatHeader[1];
|
||||
buffer = this.ensureBuffer(bufferLength + n + 1);
|
||||
for (var i = 0; i < n; i++) {
|
||||
buffer[bufferLength++] = b;
|
||||
}
|
||||
}
|
||||
this.bufferLength = bufferLength;
|
||||
};
|
||||
|
||||
return RunLengthStream;
|
||||
})();
|
||||
|
||||
export { RunLengthStream };
|
@ -1148,54 +1148,6 @@ var AsciiHexStream = (function AsciiHexStreamClosure() {
|
||||
return AsciiHexStream;
|
||||
})();
|
||||
|
||||
var RunLengthStream = (function RunLengthStreamClosure() {
|
||||
// eslint-disable-next-line no-shadow
|
||||
function RunLengthStream(str, maybeLength) {
|
||||
this.str = str;
|
||||
this.dict = str.dict;
|
||||
|
||||
DecodeStream.call(this, maybeLength);
|
||||
}
|
||||
|
||||
RunLengthStream.prototype = Object.create(DecodeStream.prototype);
|
||||
|
||||
RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
|
||||
// The repeatHeader has following format. The first byte defines type of run
|
||||
// and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
|
||||
// (in addition to the second byte from the header), n = 129 through 255 -
|
||||
// duplicate the second byte from the header (257 - n) times, n = 128 - end.
|
||||
var repeatHeader = this.str.getBytes(2);
|
||||
if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
|
||||
this.eof = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var buffer;
|
||||
var bufferLength = this.bufferLength;
|
||||
var n = repeatHeader[0];
|
||||
if (n < 128) {
|
||||
// copy n bytes
|
||||
buffer = this.ensureBuffer(bufferLength + n + 1);
|
||||
buffer[bufferLength++] = repeatHeader[1];
|
||||
if (n > 0) {
|
||||
var source = this.str.getBytes(n);
|
||||
buffer.set(source, bufferLength);
|
||||
bufferLength += n;
|
||||
}
|
||||
} else {
|
||||
n = 257 - n;
|
||||
var b = repeatHeader[1];
|
||||
buffer = this.ensureBuffer(bufferLength + n + 1);
|
||||
for (var i = 0; i < n; i++) {
|
||||
buffer[bufferLength++] = b;
|
||||
}
|
||||
}
|
||||
this.bufferLength = bufferLength;
|
||||
};
|
||||
|
||||
return RunLengthStream;
|
||||
})();
|
||||
|
||||
var NullStream = (function NullStreamClosure() {
|
||||
// eslint-disable-next-line no-shadow
|
||||
function NullStream() {
|
||||
@ -1215,7 +1167,6 @@ export {
|
||||
FlateStream,
|
||||
NullStream,
|
||||
PredictorStream,
|
||||
RunLengthStream,
|
||||
Stream,
|
||||
StreamsSequenceStream,
|
||||
StringStream,
|
||||
|
Loading…
x
Reference in New Issue
Block a user