Merge pull request #13304 from Snuffleupagus/src-core-classes

Convert more code in `src/core/` to use standard classes
This commit is contained in:
Tim van der Meij 2021-04-27 19:37:09 +02:00 committed by GitHub
commit fae183b7cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 978 additions and 1015 deletions

File diff suppressed because it is too large Load Diff

View File

@ -17,9 +17,10 @@ import { Dict, isDict } from "./primitives.js";
import { CCITTFaxDecoder } from "./ccitt.js";
import { DecodeStream } from "./stream.js";
const CCITTFaxStream = (function CCITTFaxStreamClosure() {
// eslint-disable-next-line no-shadow
function CCITTFaxStream(str, maybeLength, params) {
class CCITTFaxStream extends DecodeStream {
constructor(str, maybeLength, params) {
super(maybeLength);
this.str = str;
this.dict = str.dict;
@ -41,13 +42,9 @@ const CCITTFaxStream = (function CCITTFaxStreamClosure() {
EndOfBlock: params.get("EndOfBlock"),
BlackIs1: params.get("BlackIs1"),
});
DecodeStream.call(this, maybeLength);
}
CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
CCITTFaxStream.prototype.readBlock = function () {
readBlock() {
while (!this.eof) {
const c = this.ccittFaxDecoder.readNextChar();
if (c === -1) {
@ -57,9 +54,7 @@ const CCITTFaxStream = (function CCITTFaxStreamClosure() {
this.ensureBuffer(this.bufferLength + 1);
this.buffer[this.bufferLength++] = c;
}
};
return CCITTFaxStream;
})();
}
}
export { CCITTFaxStream };

View File

@ -22,33 +22,27 @@ import { shadow } from "../shared/util.js";
* For JBIG2's we use a library to decode these images and
* the stream behaves like all the other DecodeStreams.
*/
const Jbig2Stream = (function Jbig2StreamClosure() {
// eslint-disable-next-line no-shadow
function Jbig2Stream(stream, maybeLength, dict, params) {
class Jbig2Stream extends DecodeStream {
constructor(stream, maybeLength, dict, params) {
super(maybeLength);
this.stream = stream;
this.maybeLength = maybeLength;
this.dict = dict;
this.params = params;
DecodeStream.call(this, maybeLength);
}
Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
get bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
}
Object.defineProperty(Jbig2Stream.prototype, "bytes", {
get() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
},
configurable: true,
});
Jbig2Stream.prototype.ensureBuffer = function (requested) {
ensureBuffer(requested) {
// No-op, since `this.readBlock` will always parse the entire image and
// directly insert all of its data into `this.buffer`.
};
}
Jbig2Stream.prototype.readBlock = function () {
readBlock() {
if (this.eof) {
return;
}
@ -73,9 +67,7 @@ const Jbig2Stream = (function Jbig2StreamClosure() {
this.buffer = data;
this.bufferLength = dataLength;
this.eof = true;
};
return Jbig2Stream;
})();
}
}
export { Jbig2Stream };

View File

@ -22,9 +22,8 @@ import { shadow } from "../shared/util.js";
* For JPEG's we use a library to decode these images and the stream behaves
* like all the other DecodeStreams.
*/
const JpegStream = (function JpegStreamClosure() {
// eslint-disable-next-line no-shadow
function JpegStream(stream, maybeLength, dict, params) {
class JpegStream extends DecodeStream {
constructor(stream, maybeLength, dict, params) {
// Some images may contain 'junk' before the SOI (start-of-image) marker.
// Note: this seems to mainly affect inline images.
let ch;
@ -35,30 +34,25 @@ const JpegStream = (function JpegStreamClosure() {
break;
}
}
super(maybeLength);
this.stream = stream;
this.maybeLength = maybeLength;
this.dict = dict;
this.params = params;
DecodeStream.call(this, maybeLength);
}
JpegStream.prototype = Object.create(DecodeStream.prototype);
get bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
}
Object.defineProperty(JpegStream.prototype, "bytes", {
get: function JpegStream_bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
},
configurable: true,
});
JpegStream.prototype.ensureBuffer = function (requested) {
ensureBuffer(requested) {
// No-op, since `this.readBlock` will always parse the entire image and
// directly insert all of its data into `this.buffer`.
};
}
JpegStream.prototype.readBlock = function () {
readBlock() {
if (this.eof) {
return;
}
@ -105,9 +99,7 @@ const JpegStream = (function JpegStreamClosure() {
this.buffer = data;
this.bufferLength = data.length;
this.eof = true;
};
return JpegStream;
})();
}
}
export { JpegStream };

View File

@ -21,33 +21,27 @@ import { shadow } from "../shared/util.js";
* For JPEG 2000's we use a library to decode these images and
* the stream behaves like all the other DecodeStreams.
*/
const JpxStream = (function JpxStreamClosure() {
// eslint-disable-next-line no-shadow
function JpxStream(stream, maybeLength, dict, params) {
class JpxStream extends DecodeStream {
constructor(stream, maybeLength, dict, params) {
super(maybeLength);
this.stream = stream;
this.maybeLength = maybeLength;
this.dict = dict;
this.params = params;
DecodeStream.call(this, maybeLength);
}
JpxStream.prototype = Object.create(DecodeStream.prototype);
get bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
}
Object.defineProperty(JpxStream.prototype, "bytes", {
get: function JpxStream_bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
},
configurable: true,
});
JpxStream.prototype.ensureBuffer = function (requested) {
ensureBuffer(requested) {
// No-op, since `this.readBlock` will always parse the entire image and
// directly insert all of its data into `this.buffer`.
};
}
JpxStream.prototype.readBlock = function () {
readBlock() {
if (this.eof) {
return;
}
@ -87,9 +81,7 @@ const JpxStream = (function JpxStreamClosure() {
}
this.bufferLength = this.buffer.length;
this.eof = true;
};
return JpxStream;
})();
}
}
export { JpxStream };