Remove the closure from BitModel
in the src/core/jpx.js
file
This commit is contained in:
parent
b0a1af306d
commit
88616f77ae
@ -1738,41 +1738,43 @@ class InclusionTree {
|
||||
}
|
||||
|
||||
// Section D. Coefficient bit modeling
|
||||
const BitModel = (function BitModelClosure() {
|
||||
const UNIFORM_CONTEXT = 17;
|
||||
const RUNLENGTH_CONTEXT = 18;
|
||||
class BitModel {
|
||||
static UNIFORM_CONTEXT = 17;
|
||||
|
||||
static RUNLENGTH_CONTEXT = 18;
|
||||
|
||||
// Table D-1
|
||||
// The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
|
||||
// vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
|
||||
const LLAndLHContextsLabel = new Uint8Array([
|
||||
static LLAndLHContextsLabel = new Uint8Array([
|
||||
0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4,
|
||||
7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6,
|
||||
8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8,
|
||||
]);
|
||||
const HLContextLabel = new Uint8Array([
|
||||
|
||||
static HLContextLabel = new Uint8Array([
|
||||
0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8,
|
||||
8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3,
|
||||
4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8,
|
||||
]);
|
||||
const HHContextLabel = new Uint8Array([
|
||||
|
||||
static HHContextLabel = new Uint8Array([
|
||||
0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5,
|
||||
5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8,
|
||||
8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8,
|
||||
]);
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
class BitModel {
|
||||
constructor(width, height, subband, zeroBitPlanes, mb) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
let contextLabelTable;
|
||||
if (subband === "HH") {
|
||||
contextLabelTable = HHContextLabel;
|
||||
contextLabelTable = BitModel.HHContextLabel;
|
||||
} else if (subband === "HL") {
|
||||
contextLabelTable = HLContextLabel;
|
||||
contextLabelTable = BitModel.HLContextLabel;
|
||||
} else {
|
||||
contextLabelTable = LLAndLHContextsLabel;
|
||||
contextLabelTable = BitModel.LLAndLHContextsLabel;
|
||||
}
|
||||
this.contextLabelTable = contextLabelTable;
|
||||
|
||||
@ -1816,8 +1818,8 @@ const BitModel = (function BitModelClosure() {
|
||||
// Contexts are packed into 1 byte:
|
||||
// highest 7 bits carry the index, lowest bit carries mps
|
||||
this.contexts[0] = (4 << 1) | 0;
|
||||
this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
|
||||
this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
|
||||
this.contexts[BitModel.UNIFORM_CONTEXT] = (46 << 1) | 0;
|
||||
this.contexts[BitModel.RUNLENGTH_CONTEXT] = (3 << 1) | 0;
|
||||
}
|
||||
|
||||
setNeighborsSignificance(row, column, index) {
|
||||
@ -2044,7 +2046,7 @@ const BitModel = (function BitModelClosure() {
|
||||
if (allEmpty) {
|
||||
const hasSignificantCoefficent = decoder.readBit(
|
||||
contexts,
|
||||
RUNLENGTH_CONTEXT
|
||||
BitModel.RUNLENGTH_CONTEXT
|
||||
);
|
||||
if (!hasSignificantCoefficent) {
|
||||
bitsDecoded[index0]++;
|
||||
@ -2054,8 +2056,8 @@ const BitModel = (function BitModelClosure() {
|
||||
continue; // next column
|
||||
}
|
||||
i1 =
|
||||
(decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
|
||||
decoder.readBit(contexts, UNIFORM_CONTEXT);
|
||||
(decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 1) |
|
||||
decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT);
|
||||
if (i1 !== 0) {
|
||||
i = i0 + i1;
|
||||
index += i1 * width;
|
||||
@ -2101,18 +2103,15 @@ const BitModel = (function BitModelClosure() {
|
||||
const decoder = this.decoder;
|
||||
const contexts = this.contexts;
|
||||
const symbol =
|
||||
(decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
|
||||
(decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
|
||||
(decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
|
||||
decoder.readBit(contexts, UNIFORM_CONTEXT);
|
||||
(decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 3) |
|
||||
(decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 2) |
|
||||
(decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 1) |
|
||||
decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT);
|
||||
if (symbol !== 0xa) {
|
||||
throw new JpxError("Invalid segmentation symbol");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BitModel;
|
||||
})();
|
||||
}
|
||||
|
||||
// Section F, Discrete wavelet transformation
|
||||
class Transform {
|
||||
|
Loading…
x
Reference in New Issue
Block a user