@li0ard/wsq 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/bitmap.d.ts +11 -0
- package/dist/bitmap.js +30 -0
- package/dist/const.d.ts +114 -0
- package/dist/const.js +446 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +879 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Nikolai Konovalov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/bitmap.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class BitmapWithMetadata {
|
|
2
|
+
readonly pixels: Uint8Array;
|
|
3
|
+
readonly width: number;
|
|
4
|
+
readonly height: number;
|
|
5
|
+
readonly ppi: number;
|
|
6
|
+
readonly depth: number;
|
|
7
|
+
readonly lossyflag: number;
|
|
8
|
+
readonly metadata: Map<string, string>;
|
|
9
|
+
readonly comments: string[];
|
|
10
|
+
constructor(pixels: Uint8Array, width: number, height: number, ppi: number, depth: number, lossyflag: number, metadata?: Map<string, string> | null, ...comments: (string | null | undefined)[]);
|
|
11
|
+
}
|
package/dist/bitmap.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class BitmapWithMetadata {
|
|
2
|
+
pixels;
|
|
3
|
+
width;
|
|
4
|
+
height;
|
|
5
|
+
ppi;
|
|
6
|
+
depth;
|
|
7
|
+
lossyflag;
|
|
8
|
+
metadata;
|
|
9
|
+
comments;
|
|
10
|
+
constructor(pixels, width, height, ppi, depth, lossyflag, metadata, ...comments) {
|
|
11
|
+
this.pixels = pixels;
|
|
12
|
+
this.width = width;
|
|
13
|
+
this.height = height;
|
|
14
|
+
this.ppi = ppi;
|
|
15
|
+
this.depth = depth;
|
|
16
|
+
this.lossyflag = lossyflag;
|
|
17
|
+
this.metadata = new Map();
|
|
18
|
+
this.comments = [];
|
|
19
|
+
if (metadata) {
|
|
20
|
+
for (const [k, v] of metadata.entries())
|
|
21
|
+
this.metadata.set(k, v);
|
|
22
|
+
}
|
|
23
|
+
if (comments) {
|
|
24
|
+
for (const c of comments) {
|
|
25
|
+
if (c != null)
|
|
26
|
+
this.comments.push(c);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
package/dist/const.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export declare const NCM_HEADER = "NIST_COM";
|
|
2
|
+
export declare const NCM_PIX_WIDTH = "PIX_WIDTH";
|
|
3
|
+
export declare const NCM_PIX_HEIGHT = "PIX_HEIGHT";
|
|
4
|
+
export declare const NCM_PIX_DEPTH = "PIX_DEPTH";
|
|
5
|
+
export declare const NCM_PPI = "PPI";
|
|
6
|
+
export declare const NCM_COLORSPACE = "COLORSPACE";
|
|
7
|
+
export declare const NCM_COMPRESSION = "COMPRESSION";
|
|
8
|
+
export declare const NCM_LOSSY = "LOSSY";
|
|
9
|
+
export declare const BITMASK: Uint8Array;
|
|
10
|
+
export declare const MAX_HUFFBITS = 16;
|
|
11
|
+
export declare const MAX_HUFFCOUNTS_WSQ = 256;
|
|
12
|
+
export declare const W_TREELEN = 20;
|
|
13
|
+
export declare const Q_TREELEN = 64;
|
|
14
|
+
export declare const SOI_WSQ = 65440;
|
|
15
|
+
export declare const EOI_WSQ = 65441;
|
|
16
|
+
export declare const SOF_WSQ = 65442;
|
|
17
|
+
export declare const SOB_WSQ = 65443;
|
|
18
|
+
export declare const DTT_WSQ = 65444;
|
|
19
|
+
export declare const DQT_WSQ = 65445;
|
|
20
|
+
export declare const DHT_WSQ = 65446;
|
|
21
|
+
export declare const DRT_WSQ = 65447;
|
|
22
|
+
export declare const COM_WSQ = 65448;
|
|
23
|
+
export declare const MAX_SUBBANDS = 64;
|
|
24
|
+
export declare const NUM_SUBBANDS = 60;
|
|
25
|
+
export declare const ANY_WSQ = 65535;
|
|
26
|
+
export declare const TBLS_N_SOF = 2;
|
|
27
|
+
export declare const TBLS_N_SOB: number;
|
|
28
|
+
export declare class WavletTree {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
lenx: number;
|
|
32
|
+
leny: number;
|
|
33
|
+
invrw: number;
|
|
34
|
+
invcl: number;
|
|
35
|
+
}
|
|
36
|
+
export declare class TableDTT {
|
|
37
|
+
static HI_FILT_EVEN_8X8_1: Float32Array<ArrayBuffer>;
|
|
38
|
+
static LO_FILT_EVEN_8X8_1: Float32Array<ArrayBuffer>;
|
|
39
|
+
static HI_FILT_NOT_EVEN_8X8_1: Float32Array<ArrayBuffer>;
|
|
40
|
+
static LO_FILT_NOT_EVEN_8X8_1: Float32Array<ArrayBuffer>;
|
|
41
|
+
lofilt: Float32Array<ArrayBuffer>;
|
|
42
|
+
hifilt: Float32Array<ArrayBuffer>;
|
|
43
|
+
losz: number;
|
|
44
|
+
hisz: number;
|
|
45
|
+
lodef: number;
|
|
46
|
+
hidef: number;
|
|
47
|
+
}
|
|
48
|
+
export declare class HuffCode {
|
|
49
|
+
size: number;
|
|
50
|
+
code: number;
|
|
51
|
+
}
|
|
52
|
+
export declare class HeaderFrm {
|
|
53
|
+
black: number;
|
|
54
|
+
white: number;
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
mShift: number;
|
|
58
|
+
rScale: number;
|
|
59
|
+
wsqEncoder: number;
|
|
60
|
+
software: number;
|
|
61
|
+
}
|
|
62
|
+
export declare class HuffmanTable {
|
|
63
|
+
tableLen: number;
|
|
64
|
+
bytesLeft: number;
|
|
65
|
+
tableId: number;
|
|
66
|
+
huffbits: number[];
|
|
67
|
+
huffvalues: number[];
|
|
68
|
+
}
|
|
69
|
+
export declare class TableDHT {
|
|
70
|
+
private static readonly MAX_HUFFBITS;
|
|
71
|
+
private static readonly MAX_HUFFCOUNTS_WSQ;
|
|
72
|
+
tabdef: number;
|
|
73
|
+
huffbits: number[];
|
|
74
|
+
huffvalues: number[];
|
|
75
|
+
}
|
|
76
|
+
export declare class Table_DQT {
|
|
77
|
+
static readonly MAX_SUBBANDS = 64;
|
|
78
|
+
binCenter: number;
|
|
79
|
+
qBin: Float32Array<ArrayBuffer>;
|
|
80
|
+
zBin: Float32Array<ArrayBuffer>;
|
|
81
|
+
dqtDef: number;
|
|
82
|
+
}
|
|
83
|
+
export declare class QuantTree {
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
lenx: number;
|
|
87
|
+
leny: number;
|
|
88
|
+
}
|
|
89
|
+
export declare class Quantization {
|
|
90
|
+
static readonly MAX_SUBBANDS = 64;
|
|
91
|
+
q: number;
|
|
92
|
+
cr: number;
|
|
93
|
+
r: number;
|
|
94
|
+
qbss_t: Float32Array<ArrayBuffer>;
|
|
95
|
+
qbss: Float32Array<ArrayBuffer>;
|
|
96
|
+
qzbs: Float32Array<ArrayBuffer>;
|
|
97
|
+
var: Float32Array<ArrayBuffer>;
|
|
98
|
+
}
|
|
99
|
+
export declare class Ref<T> {
|
|
100
|
+
value: T | null;
|
|
101
|
+
constructor(value?: T | null);
|
|
102
|
+
}
|
|
103
|
+
export declare class Token {
|
|
104
|
+
static readonly MAX_DHT_TABLES = 8;
|
|
105
|
+
tableDHT: TableDHT[];
|
|
106
|
+
tableDTT: TableDTT;
|
|
107
|
+
tableDQT: Table_DQT;
|
|
108
|
+
wtree?: WavletTree[];
|
|
109
|
+
qtree?: QuantTree[];
|
|
110
|
+
quant_vals: Quantization;
|
|
111
|
+
comments: string[];
|
|
112
|
+
constructor();
|
|
113
|
+
}
|
|
114
|
+
export declare const buildWSQTrees: (token: Token, width: number, height: number) => void;
|
package/dist/const.js
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
export const NCM_HEADER = "NIST_COM"; /* mandatory */
|
|
2
|
+
export const NCM_PIX_WIDTH = "PIX_WIDTH"; /* mandatory */
|
|
3
|
+
export const NCM_PIX_HEIGHT = "PIX_HEIGHT"; /* mandatory */
|
|
4
|
+
export const NCM_PIX_DEPTH = "PIX_DEPTH"; /* 1,8,24 (mandatory)*/
|
|
5
|
+
export const NCM_PPI = "PPI"; /* -1 if unknown (mandatory)*/
|
|
6
|
+
export const NCM_COLORSPACE = "COLORSPACE"; /* RGB,YCbCr,GRAY */
|
|
7
|
+
export const NCM_COMPRESSION = "COMPRESSION"; /* NONE,JPEGB,JPEGL,WSQ */
|
|
8
|
+
export const NCM_LOSSY = "LOSSY"; /* 0,1 */
|
|
9
|
+
export const BITMASK = new Uint8Array([0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff]);
|
|
10
|
+
export const MAX_HUFFBITS = 16;
|
|
11
|
+
export const MAX_HUFFCOUNTS_WSQ = 256;
|
|
12
|
+
export const W_TREELEN = 20;
|
|
13
|
+
export const Q_TREELEN = 64;
|
|
14
|
+
/* WSQ Marker Definitions */
|
|
15
|
+
export const SOI_WSQ = 0xffa0;
|
|
16
|
+
export const EOI_WSQ = 0xffa1;
|
|
17
|
+
export const SOF_WSQ = 0xffa2;
|
|
18
|
+
export const SOB_WSQ = 0xffa3;
|
|
19
|
+
export const DTT_WSQ = 0xffa4;
|
|
20
|
+
export const DQT_WSQ = 0xffa5;
|
|
21
|
+
export const DHT_WSQ = 0xffa6;
|
|
22
|
+
export const DRT_WSQ = 0xffa7;
|
|
23
|
+
export const COM_WSQ = 0xffa8;
|
|
24
|
+
export const MAX_SUBBANDS = 64;
|
|
25
|
+
export const NUM_SUBBANDS = 60;
|
|
26
|
+
/* Case for getting ANY marker. */
|
|
27
|
+
export const ANY_WSQ = 0xffff;
|
|
28
|
+
export const TBLS_N_SOF = 2;
|
|
29
|
+
export const TBLS_N_SOB = TBLS_N_SOF + 2;
|
|
30
|
+
export class WavletTree {
|
|
31
|
+
x = 0;
|
|
32
|
+
y = 0;
|
|
33
|
+
lenx = 0;
|
|
34
|
+
leny = 0;
|
|
35
|
+
invrw = 0;
|
|
36
|
+
invcl = 0;
|
|
37
|
+
}
|
|
38
|
+
export class TableDTT {
|
|
39
|
+
static HI_FILT_EVEN_8X8_1 = new Float32Array([0.03226944131446922,
|
|
40
|
+
-0.05261415011924844,
|
|
41
|
+
-0.18870142780632693,
|
|
42
|
+
0.60328894481393847,
|
|
43
|
+
-0.60328894481393847,
|
|
44
|
+
0.18870142780632693,
|
|
45
|
+
0.05261415011924844,
|
|
46
|
+
-0.03226944131446922]);
|
|
47
|
+
static LO_FILT_EVEN_8X8_1 = new Float32Array([0.07565691101399093,
|
|
48
|
+
-0.12335584105275092,
|
|
49
|
+
-0.09789296778409587,
|
|
50
|
+
0.85269867900940344,
|
|
51
|
+
0.85269867900940344,
|
|
52
|
+
-0.09789296778409587,
|
|
53
|
+
-0.12335584105275092,
|
|
54
|
+
0.07565691101399093]);
|
|
55
|
+
static HI_FILT_NOT_EVEN_8X8_1 = new Float32Array([0.06453888262893845,
|
|
56
|
+
-0.04068941760955844,
|
|
57
|
+
-0.41809227322221221,
|
|
58
|
+
0.78848561640566439,
|
|
59
|
+
-0.41809227322221221,
|
|
60
|
+
-0.04068941760955844,
|
|
61
|
+
0.06453888262893845]);
|
|
62
|
+
static LO_FILT_NOT_EVEN_8X8_1 = new Float32Array([0.03782845550699546,
|
|
63
|
+
-0.02384946501938000,
|
|
64
|
+
-0.11062440441842342,
|
|
65
|
+
0.37740285561265380,
|
|
66
|
+
0.85269867900940344,
|
|
67
|
+
0.37740285561265380,
|
|
68
|
+
-0.11062440441842342,
|
|
69
|
+
-0.02384946501938000,
|
|
70
|
+
0.03782845550699546]);
|
|
71
|
+
lofilt = TableDTT.LO_FILT_NOT_EVEN_8X8_1;
|
|
72
|
+
hifilt = TableDTT.HI_FILT_NOT_EVEN_8X8_1;
|
|
73
|
+
losz = 0;
|
|
74
|
+
hisz = 0;
|
|
75
|
+
lodef = 0;
|
|
76
|
+
hidef = 0;
|
|
77
|
+
}
|
|
78
|
+
export class HuffCode {
|
|
79
|
+
size = 0;
|
|
80
|
+
code = 0;
|
|
81
|
+
}
|
|
82
|
+
export class HeaderFrm {
|
|
83
|
+
black = 0;
|
|
84
|
+
white = 0;
|
|
85
|
+
width = 0;
|
|
86
|
+
height = 0;
|
|
87
|
+
mShift = 0;
|
|
88
|
+
rScale = 0;
|
|
89
|
+
wsqEncoder = 0;
|
|
90
|
+
software = 0;
|
|
91
|
+
}
|
|
92
|
+
export class HuffmanTable {
|
|
93
|
+
tableLen = 0;
|
|
94
|
+
bytesLeft = 0;
|
|
95
|
+
tableId = 0;
|
|
96
|
+
huffbits = [];
|
|
97
|
+
huffvalues = [];
|
|
98
|
+
}
|
|
99
|
+
export class TableDHT {
|
|
100
|
+
static MAX_HUFFBITS = MAX_HUFFBITS;
|
|
101
|
+
static MAX_HUFFCOUNTS_WSQ = MAX_HUFFCOUNTS_WSQ;
|
|
102
|
+
tabdef = 0;
|
|
103
|
+
huffbits = new Array(TableDHT.MAX_HUFFBITS).fill(0);
|
|
104
|
+
huffvalues = new Array(TableDHT.MAX_HUFFCOUNTS_WSQ + 1).fill(0);
|
|
105
|
+
}
|
|
106
|
+
export class Table_DQT {
|
|
107
|
+
static MAX_SUBBANDS = 64;
|
|
108
|
+
binCenter = 0;
|
|
109
|
+
qBin = new Float32Array(Table_DQT.MAX_SUBBANDS);
|
|
110
|
+
zBin = new Float32Array(Table_DQT.MAX_SUBBANDS);
|
|
111
|
+
dqtDef = 0;
|
|
112
|
+
}
|
|
113
|
+
export class QuantTree {
|
|
114
|
+
x = 0;
|
|
115
|
+
y = 0;
|
|
116
|
+
lenx = 0;
|
|
117
|
+
leny = 0;
|
|
118
|
+
}
|
|
119
|
+
export class Quantization {
|
|
120
|
+
static MAX_SUBBANDS = 64;
|
|
121
|
+
q = 0;
|
|
122
|
+
cr = 0;
|
|
123
|
+
r = 0;
|
|
124
|
+
qbss_t = new Float32Array(Quantization.MAX_SUBBANDS);
|
|
125
|
+
qbss = new Float32Array(Quantization.MAX_SUBBANDS);
|
|
126
|
+
qzbs = new Float32Array(Quantization.MAX_SUBBANDS);
|
|
127
|
+
var = new Float32Array(Quantization.MAX_SUBBANDS);
|
|
128
|
+
}
|
|
129
|
+
export class Ref {
|
|
130
|
+
value;
|
|
131
|
+
constructor(value = null) {
|
|
132
|
+
this.value = value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export class Token {
|
|
136
|
+
static MAX_DHT_TABLES = 8;
|
|
137
|
+
tableDHT = new Array(Token.MAX_DHT_TABLES);
|
|
138
|
+
tableDTT = new TableDTT();
|
|
139
|
+
tableDQT = new Table_DQT();
|
|
140
|
+
wtree;
|
|
141
|
+
qtree;
|
|
142
|
+
quant_vals = new Quantization();
|
|
143
|
+
comments = [];
|
|
144
|
+
constructor() {
|
|
145
|
+
for (let i = 0; i < Token.MAX_DHT_TABLES; i++) {
|
|
146
|
+
this.tableDHT[i] = new TableDHT();
|
|
147
|
+
this.tableDHT[i].tabdef = 0;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
export const buildWSQTrees = (token, width, height) => {
|
|
152
|
+
buildWTree(token, W_TREELEN, width, height);
|
|
153
|
+
buildQTree(token, Q_TREELEN);
|
|
154
|
+
};
|
|
155
|
+
const buildWTree = (token, wtreelen, width, height) => {
|
|
156
|
+
let lenx, lenx2, leny, leny2;
|
|
157
|
+
token.wtree = new Array(wtreelen);
|
|
158
|
+
for (let i = 0; i < wtreelen; i++) {
|
|
159
|
+
token.wtree[i] = new WavletTree();
|
|
160
|
+
token.wtree[i].invrw = 0;
|
|
161
|
+
token.wtree[i].invcl = 0;
|
|
162
|
+
}
|
|
163
|
+
token.wtree[2].invrw = 1;
|
|
164
|
+
token.wtree[4].invrw = 1;
|
|
165
|
+
token.wtree[7].invrw = 1;
|
|
166
|
+
token.wtree[9].invrw = 1;
|
|
167
|
+
token.wtree[11].invrw = 1;
|
|
168
|
+
token.wtree[13].invrw = 1;
|
|
169
|
+
token.wtree[16].invrw = 1;
|
|
170
|
+
token.wtree[18].invrw = 1;
|
|
171
|
+
token.wtree[3].invcl = 1;
|
|
172
|
+
token.wtree[5].invcl = 1;
|
|
173
|
+
token.wtree[8].invcl = 1;
|
|
174
|
+
token.wtree[9].invcl = 1;
|
|
175
|
+
token.wtree[12].invcl = 1;
|
|
176
|
+
token.wtree[13].invcl = 1;
|
|
177
|
+
token.wtree[17].invcl = 1;
|
|
178
|
+
token.wtree[18].invcl = 1;
|
|
179
|
+
wtree4(token, 0, 1, width, height, 0, 0, 1);
|
|
180
|
+
if ((token.wtree[1].lenx % 2) == 0) {
|
|
181
|
+
lenx = token.wtree[1].lenx / 2;
|
|
182
|
+
lenx2 = lenx;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
lenx = (token.wtree[1].lenx + 1) / 2;
|
|
186
|
+
lenx2 = lenx - 1;
|
|
187
|
+
}
|
|
188
|
+
if ((token.wtree[1].leny % 2) == 0) {
|
|
189
|
+
leny = token.wtree[1].leny / 2;
|
|
190
|
+
leny2 = leny;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
leny = (token.wtree[1].leny + 1) / 2;
|
|
194
|
+
leny2 = leny - 1;
|
|
195
|
+
}
|
|
196
|
+
wtree4(token, 4, 6, lenx2, leny, lenx, 0, 0);
|
|
197
|
+
wtree4(token, 5, 10, lenx, leny2, 0, leny, 0);
|
|
198
|
+
wtree4(token, 14, 15, lenx, leny, 0, 0, 0);
|
|
199
|
+
token.wtree[19].x = 0;
|
|
200
|
+
token.wtree[19].y = 0;
|
|
201
|
+
if ((token.wtree[15].lenx % 2) == 0)
|
|
202
|
+
token.wtree[19].lenx = token.wtree[15].lenx / 2;
|
|
203
|
+
else
|
|
204
|
+
token.wtree[19].lenx = (token.wtree[15].lenx + 1) / 2;
|
|
205
|
+
if ((token.wtree[15].leny % 2) == 0)
|
|
206
|
+
token.wtree[19].leny = token.wtree[15].leny / 2;
|
|
207
|
+
else
|
|
208
|
+
token.wtree[19].leny = (token.wtree[15].leny + 1) / 2;
|
|
209
|
+
};
|
|
210
|
+
const wtree4 = (token, start1, start2, lenx, leny, x, y, stop1) => {
|
|
211
|
+
let p1 = start1, p2 = start2;
|
|
212
|
+
let evenx = lenx % 2, eveny = leny % 2;
|
|
213
|
+
if (!token.wtree)
|
|
214
|
+
return;
|
|
215
|
+
token.wtree[p1].x = x;
|
|
216
|
+
token.wtree[p1].y = y;
|
|
217
|
+
token.wtree[p1].lenx = lenx;
|
|
218
|
+
token.wtree[p1].leny = leny;
|
|
219
|
+
token.wtree[p2].x = x;
|
|
220
|
+
token.wtree[p2 + 2].x = x;
|
|
221
|
+
token.wtree[p2].y = y;
|
|
222
|
+
token.wtree[p2 + 1].y = y;
|
|
223
|
+
if (evenx == 0) {
|
|
224
|
+
token.wtree[p2].lenx = lenx / 2;
|
|
225
|
+
token.wtree[p2 + 1].lenx = token.wtree[p2].lenx;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
if (p1 == 4) {
|
|
229
|
+
token.wtree[p2].lenx = (lenx - 1) / 2;
|
|
230
|
+
token.wtree[p2 + 1].lenx = token.wtree[p2].lenx + 1;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
token.wtree[p2].lenx = (lenx + 1) / 2;
|
|
234
|
+
token.wtree[p2 + 1].lenx = token.wtree[p2].lenx - 1;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
token.wtree[p2 + 1].x = token.wtree[p2].lenx + x;
|
|
238
|
+
if (stop1 == 0) {
|
|
239
|
+
token.wtree[p2 + 3].lenx = token.wtree[p2 + 1].lenx;
|
|
240
|
+
token.wtree[p2 + 3].x = token.wtree[p2 + 1].x;
|
|
241
|
+
}
|
|
242
|
+
token.wtree[p2 + 2].lenx = token.wtree[p2].lenx;
|
|
243
|
+
if (eveny == 0) {
|
|
244
|
+
token.wtree[p2].leny = leny / 2;
|
|
245
|
+
token.wtree[p2 + 2].leny = token.wtree[p2].leny;
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
if (p1 == 5) {
|
|
249
|
+
token.wtree[p2].leny = (leny - 1) / 2;
|
|
250
|
+
token.wtree[p2 + 2].leny = token.wtree[p2].leny + 1;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
token.wtree[p2].leny = (leny + 1) / 2;
|
|
254
|
+
token.wtree[p2 + 2].leny = token.wtree[p2].leny - 1;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
token.wtree[p2 + 2].y = token.wtree[p2].leny + y;
|
|
258
|
+
if (stop1 == 0) {
|
|
259
|
+
token.wtree[p2 + 3].leny = token.wtree[p2 + 2].leny;
|
|
260
|
+
token.wtree[p2 + 3].y = token.wtree[p2 + 2].y;
|
|
261
|
+
}
|
|
262
|
+
token.wtree[p2 + 1].leny = token.wtree[p2].leny;
|
|
263
|
+
};
|
|
264
|
+
const buildQTree = (token, qtreelen) => {
|
|
265
|
+
token.qtree = new Array(qtreelen);
|
|
266
|
+
for (let i = 0; i < token.qtree.length; i++)
|
|
267
|
+
token.qtree[i] = new QuantTree();
|
|
268
|
+
if (!token.wtree)
|
|
269
|
+
return;
|
|
270
|
+
qtree16(token, 3, token.wtree[14].lenx, token.wtree[14].leny, token.wtree[14].x, token.wtree[14].y, 0, 0);
|
|
271
|
+
qtree16(token, 19, token.wtree[4].lenx, token.wtree[4].leny, token.wtree[4].x, token.wtree[4].y, 0, 1);
|
|
272
|
+
qtree16(token, 48, token.wtree[0].lenx, token.wtree[0].leny, token.wtree[0].x, token.wtree[0].y, 0, 0);
|
|
273
|
+
qtree16(token, 35, token.wtree[5].lenx, token.wtree[5].leny, token.wtree[5].x, token.wtree[5].y, 1, 0);
|
|
274
|
+
qtree4(token, 0, token.wtree[19].lenx, token.wtree[19].leny, token.wtree[19].x, token.wtree[19].y);
|
|
275
|
+
};
|
|
276
|
+
const qtree16 = (token, start, lenx, leny, x, y, rw, cl) => {
|
|
277
|
+
let tempx, temp2x, tempy, temp2y;
|
|
278
|
+
if (!token.qtree)
|
|
279
|
+
return;
|
|
280
|
+
let p = start, evenx = lenx % 2, eveny = leny % 2;
|
|
281
|
+
if (evenx == 0) {
|
|
282
|
+
tempx = lenx / 2;
|
|
283
|
+
temp2x = tempx;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
if (cl != 0) {
|
|
287
|
+
temp2x = (lenx + 1) / 2;
|
|
288
|
+
tempx = temp2x - 1;
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
tempx = (lenx + 1) / 2;
|
|
292
|
+
temp2x = tempx - 1;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (eveny == 0) {
|
|
296
|
+
tempy = leny / 2;
|
|
297
|
+
temp2y = tempy;
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
if (rw != 0) {
|
|
301
|
+
temp2y = (leny + 1) / 2;
|
|
302
|
+
tempy = temp2y - 1;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
tempy = (leny + 1) / 2;
|
|
306
|
+
temp2y = tempy - 1;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
evenx = tempx % 2;
|
|
310
|
+
eveny = tempy % 2;
|
|
311
|
+
token.qtree[p].x = x;
|
|
312
|
+
token.qtree[p + 2].x = x;
|
|
313
|
+
token.qtree[p].y = y;
|
|
314
|
+
token.qtree[p + 1].y = y;
|
|
315
|
+
if (evenx == 0) {
|
|
316
|
+
token.qtree[p].lenx = tempx / 2;
|
|
317
|
+
token.qtree[p + 1].lenx = token.qtree[p].lenx;
|
|
318
|
+
token.qtree[p + 2].lenx = token.qtree[p].lenx;
|
|
319
|
+
token.qtree[p + 3].lenx = token.qtree[p].lenx;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
token.qtree[p].lenx = (tempx + 1) / 2;
|
|
323
|
+
token.qtree[p + 1].lenx = token.qtree[p].lenx - 1;
|
|
324
|
+
token.qtree[p + 2].lenx = token.qtree[p].lenx;
|
|
325
|
+
token.qtree[p + 3].lenx = token.qtree[p + 1].lenx;
|
|
326
|
+
}
|
|
327
|
+
token.qtree[p + 1].x = x + token.qtree[p].lenx;
|
|
328
|
+
token.qtree[p + 3].x = token.qtree[p + 1].x;
|
|
329
|
+
if (eveny == 0) {
|
|
330
|
+
token.qtree[p].leny = tempy / 2;
|
|
331
|
+
token.qtree[p + 1].leny = token.qtree[p].leny;
|
|
332
|
+
token.qtree[p + 2].leny = token.qtree[p].leny;
|
|
333
|
+
token.qtree[p + 3].leny = token.qtree[p].leny;
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
token.qtree[p].leny = (tempy + 1) / 2;
|
|
337
|
+
token.qtree[p + 1].leny = token.qtree[p].leny;
|
|
338
|
+
token.qtree[p + 2].leny = token.qtree[p].leny - 1;
|
|
339
|
+
token.qtree[p + 3].leny = token.qtree[p + 2].leny;
|
|
340
|
+
}
|
|
341
|
+
token.qtree[p + 2].y = y + token.qtree[p].leny;
|
|
342
|
+
token.qtree[p + 3].y = token.qtree[p + 2].y;
|
|
343
|
+
evenx = temp2x % 2;
|
|
344
|
+
token.qtree[p + 4].x = x + tempx;
|
|
345
|
+
token.qtree[p + 6].x = token.qtree[p + 4].x;
|
|
346
|
+
token.qtree[p + 4].y = y;
|
|
347
|
+
token.qtree[p + 5].y = y;
|
|
348
|
+
token.qtree[p + 6].y = token.qtree[p + 2].y;
|
|
349
|
+
token.qtree[p + 7].y = token.qtree[p + 2].y;
|
|
350
|
+
token.qtree[p + 4].leny = token.qtree[p].leny;
|
|
351
|
+
token.qtree[p + 5].leny = token.qtree[p].leny;
|
|
352
|
+
token.qtree[p + 6].leny = token.qtree[p + 2].leny;
|
|
353
|
+
token.qtree[p + 7].leny = token.qtree[p + 2].leny;
|
|
354
|
+
if (evenx == 0) {
|
|
355
|
+
token.qtree[p + 4].lenx = temp2x / 2;
|
|
356
|
+
token.qtree[p + 5].lenx = token.qtree[p + 4].lenx;
|
|
357
|
+
token.qtree[p + 6].lenx = token.qtree[p + 4].lenx;
|
|
358
|
+
token.qtree[p + 7].lenx = token.qtree[p + 4].lenx;
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
token.qtree[p + 5].lenx = (temp2x + 1) / 2;
|
|
362
|
+
token.qtree[p + 4].lenx = token.qtree[p + 5].lenx - 1;
|
|
363
|
+
token.qtree[p + 6].lenx = token.qtree[p + 4].lenx;
|
|
364
|
+
token.qtree[p + 7].lenx = token.qtree[p + 5].lenx;
|
|
365
|
+
}
|
|
366
|
+
token.qtree[p + 5].x = token.qtree[p + 4].x + token.qtree[p + 4].lenx;
|
|
367
|
+
token.qtree[p + 7].x = token.qtree[p + 5].x;
|
|
368
|
+
eveny = temp2y % 2;
|
|
369
|
+
token.qtree[p + 8].x = x;
|
|
370
|
+
token.qtree[p + 9].x = token.qtree[p + 1].x;
|
|
371
|
+
token.qtree[p + 10].x = x;
|
|
372
|
+
token.qtree[p + 11].x = token.qtree[p + 1].x;
|
|
373
|
+
token.qtree[p + 8].y = y + tempy;
|
|
374
|
+
token.qtree[p + 9].y = token.qtree[p + 8].y;
|
|
375
|
+
token.qtree[p + 8].lenx = token.qtree[p].lenx;
|
|
376
|
+
token.qtree[p + 9].lenx = token.qtree[p + 1].lenx;
|
|
377
|
+
token.qtree[p + 10].lenx = token.qtree[p].lenx;
|
|
378
|
+
token.qtree[p + 11].lenx = token.qtree[p + 1].lenx;
|
|
379
|
+
if (eveny == 0) {
|
|
380
|
+
token.qtree[p + 8].leny = temp2y / 2;
|
|
381
|
+
token.qtree[p + 9].leny = token.qtree[p + 8].leny;
|
|
382
|
+
token.qtree[p + 10].leny = token.qtree[p + 8].leny;
|
|
383
|
+
token.qtree[p + 11].leny = token.qtree[p + 8].leny;
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
token.qtree[p + 10].leny = (temp2y + 1) / 2;
|
|
387
|
+
token.qtree[p + 11].leny = token.qtree[p + 10].leny;
|
|
388
|
+
token.qtree[p + 8].leny = token.qtree[p + 10].leny - 1;
|
|
389
|
+
token.qtree[p + 9].leny = token.qtree[p + 8].leny;
|
|
390
|
+
}
|
|
391
|
+
token.qtree[p + 10].y = token.qtree[p + 8].y + token.qtree[p + 8].leny;
|
|
392
|
+
token.qtree[p + 11].y = token.qtree[p + 10].y;
|
|
393
|
+
token.qtree[p + 12].x = token.qtree[p + 4].x;
|
|
394
|
+
token.qtree[p + 13].x = token.qtree[p + 5].x;
|
|
395
|
+
token.qtree[p + 14].x = token.qtree[p + 4].x;
|
|
396
|
+
token.qtree[p + 15].x = token.qtree[p + 5].x;
|
|
397
|
+
token.qtree[p + 12].y = token.qtree[p + 8].y;
|
|
398
|
+
token.qtree[p + 13].y = token.qtree[p + 8].y;
|
|
399
|
+
token.qtree[p + 14].y = token.qtree[p + 10].y;
|
|
400
|
+
token.qtree[p + 15].y = token.qtree[p + 10].y;
|
|
401
|
+
token.qtree[p + 12].lenx = token.qtree[p + 4].lenx;
|
|
402
|
+
token.qtree[p + 13].lenx = token.qtree[p + 5].lenx;
|
|
403
|
+
token.qtree[p + 14].lenx = token.qtree[p + 4].lenx;
|
|
404
|
+
token.qtree[p + 15].lenx = token.qtree[p + 5].lenx;
|
|
405
|
+
token.qtree[p + 12].leny = token.qtree[p + 8].leny;
|
|
406
|
+
token.qtree[p + 13].leny = token.qtree[p + 8].leny;
|
|
407
|
+
token.qtree[p + 14].leny = token.qtree[p + 10].leny;
|
|
408
|
+
token.qtree[p + 15].leny = token.qtree[p + 10].leny;
|
|
409
|
+
};
|
|
410
|
+
const qtree4 = (token, start, lenx, leny, x, y) => {
|
|
411
|
+
let p = start, evenx = lenx % 2, eveny = leny % 2;
|
|
412
|
+
if (!token.qtree)
|
|
413
|
+
return;
|
|
414
|
+
token.qtree[p].x = x;
|
|
415
|
+
token.qtree[p + 2].x = x;
|
|
416
|
+
token.qtree[p].y = y;
|
|
417
|
+
token.qtree[p + 1].y = y;
|
|
418
|
+
if (evenx == 0) {
|
|
419
|
+
token.qtree[p].lenx = lenx / 2;
|
|
420
|
+
token.qtree[p + 1].lenx = token.qtree[p].lenx;
|
|
421
|
+
token.qtree[p + 2].lenx = token.qtree[p].lenx;
|
|
422
|
+
token.qtree[p + 3].lenx = token.qtree[p].lenx;
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
token.qtree[p].lenx = (lenx + 1) / 2;
|
|
426
|
+
token.qtree[p + 1].lenx = token.qtree[p].lenx - 1;
|
|
427
|
+
token.qtree[p + 2].lenx = token.qtree[p].lenx;
|
|
428
|
+
token.qtree[p + 3].lenx = token.qtree[p + 1].lenx;
|
|
429
|
+
}
|
|
430
|
+
token.qtree[p + 1].x = x + token.qtree[p].lenx;
|
|
431
|
+
token.qtree[p + 3].x = token.qtree[p + 1].x;
|
|
432
|
+
if (eveny == 0) {
|
|
433
|
+
token.qtree[p].leny = leny / 2;
|
|
434
|
+
token.qtree[p + 1].leny = token.qtree[p].leny;
|
|
435
|
+
token.qtree[p + 2].leny = token.qtree[p].leny;
|
|
436
|
+
token.qtree[p + 3].leny = token.qtree[p].leny;
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
token.qtree[p].leny = (leny + 1) / 2;
|
|
440
|
+
token.qtree[p + 1].leny = token.qtree[p].leny;
|
|
441
|
+
token.qtree[p + 2].leny = token.qtree[p].leny - 1;
|
|
442
|
+
token.qtree[p + 3].leny = token.qtree[p + 2].leny;
|
|
443
|
+
}
|
|
444
|
+
token.qtree[p + 2].y = y + token.qtree[p].leny;
|
|
445
|
+
token.qtree[p + 3].y = token.qtree[p + 2].y;
|
|
446
|
+
};
|