Convert src/core/predictor_stream.js to use standard classes

This commit is contained in:
Jonas Jenwald 2021-04-27 13:46:11 +02:00
parent b08f9a8182
commit 40c342ec6c

View File

@ -17,13 +17,12 @@ import { DecodeStream } from "./stream.js";
import { FormatError } from "../shared/util.js"; import { FormatError } from "../shared/util.js";
import { isDict } from "./primitives.js"; import { isDict } from "./primitives.js";
const PredictorStream = (function PredictorStreamClosure() { class PredictorStream extends DecodeStream {
// eslint-disable-next-line no-shadow constructor(str, maybeLength, params) {
function PredictorStream(str, maybeLength, params) {
if (!isDict(params)) { if (!isDict(params)) {
return str; // no prediction return str; // no prediction
} }
const predictor = (this.predictor = params.get("Predictor") || 1); const predictor = params.get("Predictor") || 1;
if (predictor <= 1) { if (predictor <= 1) {
return str; // no prediction return str; // no prediction
@ -31,6 +30,8 @@ const PredictorStream = (function PredictorStreamClosure() {
if (predictor !== 2 && (predictor < 10 || predictor > 15)) { if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
throw new FormatError(`Unsupported predictor: ${predictor}`); throw new FormatError(`Unsupported predictor: ${predictor}`);
} }
super(maybeLength);
this.predictor = predictor;
if (predictor === 2) { if (predictor === 2) {
this.readBlock = this.readBlockTiff; this.readBlock = this.readBlockTiff;
@ -48,13 +49,10 @@ const PredictorStream = (function PredictorStreamClosure() {
this.pixBytes = (colors * bits + 7) >> 3; this.pixBytes = (colors * bits + 7) >> 3;
this.rowBytes = (columns * colors * bits + 7) >> 3; this.rowBytes = (columns * colors * bits + 7) >> 3;
DecodeStream.call(this, maybeLength);
return this; return this;
} }
PredictorStream.prototype = Object.create(DecodeStream.prototype); readBlockTiff() {
PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
const rowBytes = this.rowBytes; const rowBytes = this.rowBytes;
const bufferLength = this.bufferLength; const bufferLength = this.bufferLength;
@ -138,9 +136,9 @@ const PredictorStream = (function PredictorStreamClosure() {
} }
} }
this.bufferLength += rowBytes; this.bufferLength += rowBytes;
}; }
PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() { readBlockPng() {
const rowBytes = this.rowBytes; const rowBytes = this.rowBytes;
const pixBytes = this.pixBytes; const pixBytes = this.pixBytes;
@ -234,9 +232,7 @@ const PredictorStream = (function PredictorStreamClosure() {
throw new FormatError(`Unsupported predictor: ${predictor}`); throw new FormatError(`Unsupported predictor: ${predictor}`);
} }
this.bufferLength += rowBytes; this.bufferLength += rowBytes;
}; }
}
return PredictorStream;
})();
export { PredictorStream }; export { PredictorStream };