Convert src/core/ccitt.js
to use standard classes
Given that we're using modules, meaning that only explicitly `export`ed things are visible to the outside, it's no longer necessary to wrap all of the code in a closure.
This commit is contained in:
parent
ca668587c6
commit
8ff213871b
@ -19,15 +19,14 @@
|
||||
* license.
|
||||
*/
|
||||
|
||||
import { info } from "../shared/util.js";
|
||||
|
||||
/**
|
||||
* @typedef {Object} CCITTFaxDecoderSource
|
||||
* @property {function} next - Method that return one byte of data for decoding,
|
||||
* or -1 when EOF is reached.
|
||||
*/
|
||||
|
||||
import { info } from "../shared/util.js";
|
||||
|
||||
const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
const ccittEOL = -2;
|
||||
const ccittEOF = -1;
|
||||
const twoDimPass = 0;
|
||||
@ -465,8 +464,8 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
* @param {CCITTFaxDecoderSource} source - The data which should be decoded.
|
||||
* @param {Object} [options] - Decoding options.
|
||||
*/
|
||||
// eslint-disable-next-line no-shadow
|
||||
function CCITTFaxDecoder(source, options = {}) {
|
||||
class CCITTFaxDecoder {
|
||||
constructor(source, options = {}) {
|
||||
if (!source || typeof source.next !== "function") {
|
||||
throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
|
||||
}
|
||||
@ -511,7 +510,6 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
}
|
||||
}
|
||||
|
||||
CCITTFaxDecoder.prototype = {
|
||||
readNextChar() {
|
||||
if (this.eof) {
|
||||
return -1;
|
||||
@ -569,10 +567,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
code2 += code3 = this._getBlackCode();
|
||||
} while (code3 >= 64);
|
||||
}
|
||||
this._addPixels(
|
||||
codingLine[this.codingPos] + code1,
|
||||
blackPixels
|
||||
);
|
||||
this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
|
||||
if (codingLine[this.codingPos] < columns) {
|
||||
this._addPixels(
|
||||
codingLine[this.codingPos] + code2,
|
||||
@ -845,7 +840,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
c ^= 0xff;
|
||||
}
|
||||
return c;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
@ -867,7 +862,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
codingLine[codingPos] = a1;
|
||||
}
|
||||
this.codingPos = codingPos;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
@ -900,7 +895,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
}
|
||||
|
||||
this.codingPos = codingPos;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns the code found from the table.
|
||||
@ -930,7 +925,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
}
|
||||
}
|
||||
return [false, 0, false];
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
@ -953,7 +948,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
}
|
||||
info("Bad two dim code");
|
||||
return ccittEOF;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
@ -991,7 +986,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
info("bad white code");
|
||||
this._eatBits(1);
|
||||
return 1;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
@ -1034,7 +1029,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
info("bad black code");
|
||||
this._eatBits(1);
|
||||
return 1;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
@ -1052,7 +1047,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
this.inputBits += 8;
|
||||
}
|
||||
return (this.inputBuf >> (this.inputBits - n)) & (0xffff >> (16 - n));
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
@ -1061,10 +1056,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
||||
if ((this.inputBits -= n) < 0) {
|
||||
this.inputBits = 0;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return CCITTFaxDecoder;
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
export { CCITTFaxDecoder };
|
||||
|
Loading…
x
Reference in New Issue
Block a user