Convert src/core/arithmetic_decoder.js to ES6 syntax

This commit is contained in:
Tim van der Meij 2019-01-05 18:51:37 +01:00
parent c967eab8b1
commit 3b637e71d4
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -12,18 +12,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint no-var: error */
/* This class implements the QM Coder decoding as defined in
* JPEG 2000 Part I Final Committee Draft Version 1.0
* Annex C.3 Arithmetic decoding procedure
* available at http://www.jpeg.org/public/fcd15444-1.pdf
*
* The arithmetic decoder is used in conjunction with context models to decode
* JPEG2000 and JBIG2 streams.
*/
var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
// Table C-2
var QeTable = [
const QeTable = [
{ qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1, },
{ qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0, },
{ qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0, },
@ -70,11 +62,21 @@ var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
{ qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0, },
{ qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0, },
{ qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0, },
{ qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0, }
{ qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0, },
];
/**
* This class implements the QM Coder decoding as defined in
* JPEG 2000 Part I Final Committee Draft Version 1.0
* Annex C.3 Arithmetic decoding procedure
* available at http://www.jpeg.org/public/fcd15444-1.pdf
*
* The arithmetic decoder is used in conjunction with context models to decode
* JPEG2000 and JBIG2 streams.
*/
class ArithmeticDecoder {
// C.3.5 Initialisation of the decoder (INITDEC)
function ArithmeticDecoder(data, start, end) {
constructor(data, start, end) {
this.data = data;
this.bp = start;
this.dataEnd = end;
@ -90,14 +92,13 @@ var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
this.a = 0x8000;
}
ArithmeticDecoder.prototype = {
// C.3.4 Compressed data input (BYTEIN)
byteIn: function ArithmeticDecoder_byteIn() {
var data = this.data;
var bp = this.bp;
byteIn() {
const data = this.data;
let bp = this.bp;
if (data[bp] === 0xFF) {
var b1 = data[bp + 1];
if (b1 > 0x8F) {
if (data[bp + 1] > 0x8F) {
this.clow += 0xFF00;
this.ct = 8;
} else {
@ -116,16 +117,17 @@ var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
this.chigh += (this.clow >> 16);
this.clow &= 0xFFFF;
}
},
}
// C.3.2 Decoding a decision (DECODE)
readBit: function ArithmeticDecoder_readBit(contexts, pos) {
// contexts are packed into 1 byte:
readBit(contexts, pos) {
// Contexts are packed into 1 byte:
// highest 7 bits carry cx.index, lowest bit carries cx.mps
var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
var qeTableIcx = QeTable[cx_index];
var qeIcx = qeTableIcx.qe;
var d;
var a = this.a - qeIcx;
let cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
const qeTableIcx = QeTable[cx_index];
const qeIcx = qeTableIcx.qe;
let d;
let a = this.a - qeIcx;
if (this.chigh < qeIcx) {
// exchangeLps
@ -174,11 +176,8 @@ var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
contexts[pos] = cx_index << 1 | cx_mps;
return d;
},
};
return ArithmeticDecoder;
})();
}
}
export {
ArithmeticDecoder,