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.
|
* license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { info } from "../shared/util.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} CCITTFaxDecoderSource
|
* @typedef {Object} CCITTFaxDecoderSource
|
||||||
* @property {function} next - Method that return one byte of data for decoding,
|
* @property {function} next - Method that return one byte of data for decoding,
|
||||||
* or -1 when EOF is reached.
|
* or -1 when EOF is reached.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { info } from "../shared/util.js";
|
|
||||||
|
|
||||||
const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|
||||||
const ccittEOL = -2;
|
const ccittEOL = -2;
|
||||||
const ccittEOF = -1;
|
const ccittEOF = -1;
|
||||||
const twoDimPass = 0;
|
const twoDimPass = 0;
|
||||||
@ -465,8 +464,8 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|||||||
* @param {CCITTFaxDecoderSource} source - The data which should be decoded.
|
* @param {CCITTFaxDecoderSource} source - The data which should be decoded.
|
||||||
* @param {Object} [options] - Decoding options.
|
* @param {Object} [options] - Decoding options.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line no-shadow
|
class CCITTFaxDecoder {
|
||||||
function CCITTFaxDecoder(source, options = {}) {
|
constructor(source, options = {}) {
|
||||||
if (!source || typeof source.next !== "function") {
|
if (!source || typeof source.next !== "function") {
|
||||||
throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
|
throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
|
||||||
}
|
}
|
||||||
@ -511,7 +510,6 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CCITTFaxDecoder.prototype = {
|
|
||||||
readNextChar() {
|
readNextChar() {
|
||||||
if (this.eof) {
|
if (this.eof) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -569,10 +567,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|||||||
code2 += code3 = this._getBlackCode();
|
code2 += code3 = this._getBlackCode();
|
||||||
} while (code3 >= 64);
|
} while (code3 >= 64);
|
||||||
}
|
}
|
||||||
this._addPixels(
|
this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
|
||||||
codingLine[this.codingPos] + code1,
|
|
||||||
blackPixels
|
|
||||||
);
|
|
||||||
if (codingLine[this.codingPos] < columns) {
|
if (codingLine[this.codingPos] < columns) {
|
||||||
this._addPixels(
|
this._addPixels(
|
||||||
codingLine[this.codingPos] + code2,
|
codingLine[this.codingPos] + code2,
|
||||||
@ -845,7 +840,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|||||||
c ^= 0xff;
|
c ^= 0xff;
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@ -867,7 +862,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|||||||
codingLine[codingPos] = a1;
|
codingLine[codingPos] = a1;
|
||||||
}
|
}
|
||||||
this.codingPos = codingPos;
|
this.codingPos = codingPos;
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@ -900,7 +895,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.codingPos = codingPos;
|
this.codingPos = codingPos;
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function returns the code found from the table.
|
* This function returns the code found from the table.
|
||||||
@ -930,7 +925,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [false, 0, false];
|
return [false, 0, false];
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@ -953,7 +948,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|||||||
}
|
}
|
||||||
info("Bad two dim code");
|
info("Bad two dim code");
|
||||||
return ccittEOF;
|
return ccittEOF;
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@ -991,7 +986,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|||||||
info("bad white code");
|
info("bad white code");
|
||||||
this._eatBits(1);
|
this._eatBits(1);
|
||||||
return 1;
|
return 1;
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@ -1034,7 +1029,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|||||||
info("bad black code");
|
info("bad black code");
|
||||||
this._eatBits(1);
|
this._eatBits(1);
|
||||||
return 1;
|
return 1;
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@ -1052,7 +1047,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|||||||
this.inputBits += 8;
|
this.inputBits += 8;
|
||||||
}
|
}
|
||||||
return (this.inputBuf >> (this.inputBits - n)) & (0xffff >> (16 - n));
|
return (this.inputBuf >> (this.inputBits - n)) & (0xffff >> (16 - n));
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@ -1061,10 +1056,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
|
|||||||
if ((this.inputBits -= n) < 0) {
|
if ((this.inputBits -= n) < 0) {
|
||||||
this.inputBits = 0;
|
this.inputBits = 0;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
return CCITTFaxDecoder;
|
|
||||||
})();
|
|
||||||
|
|
||||||
export { CCITTFaxDecoder };
|
export { CCITTFaxDecoder };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user