emf-converter 4.19.0 → 4.20.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/README.md +33 -6
- package/dist/browser.js +803 -12
- package/dist/browser.mjs +803 -13
- package/dist/index.d.mts +39 -1
- package/dist/index.d.ts +39 -1
- package/dist/index.js +803 -12
- package/dist/index.mjs +803 -13
- package/package.json +4 -2
package/dist/browser.js
CHANGED
|
@@ -46,7 +46,7 @@ var require_encoder = __commonJS({
|
|
|
46
46
|
var YAC_HT;
|
|
47
47
|
var UVAC_HT;
|
|
48
48
|
var bitcode = new Array(65535);
|
|
49
|
-
var
|
|
49
|
+
var category2 = new Array(65535);
|
|
50
50
|
var outputfDCTQuant = new Array(64);
|
|
51
51
|
var DU = new Array(64);
|
|
52
52
|
var byteout = [];
|
|
@@ -655,13 +655,13 @@ var require_encoder = __commonJS({
|
|
|
655
655
|
var nrupper = 2;
|
|
656
656
|
for (var cat = 1; cat <= 15; cat++) {
|
|
657
657
|
for (var nr = nrlower; nr < nrupper; nr++) {
|
|
658
|
-
|
|
658
|
+
category2[32767 + nr] = cat;
|
|
659
659
|
bitcode[32767 + nr] = [];
|
|
660
660
|
bitcode[32767 + nr][1] = cat;
|
|
661
661
|
bitcode[32767 + nr][0] = nr;
|
|
662
662
|
}
|
|
663
663
|
for (var nrneg = -(nrupper - 1); nrneg <= -nrlower; nrneg++) {
|
|
664
|
-
|
|
664
|
+
category2[32767 + nrneg] = cat;
|
|
665
665
|
bitcode[32767 + nrneg] = [];
|
|
666
666
|
bitcode[32767 + nrneg][1] = cat;
|
|
667
667
|
bitcode[32767 + nrneg][0] = nrupper - 1 + nrneg;
|
|
@@ -943,7 +943,7 @@ var require_encoder = __commonJS({
|
|
|
943
943
|
writeBits(HTDC[0]);
|
|
944
944
|
} else {
|
|
945
945
|
pos = 32767 + Diff;
|
|
946
|
-
writeBits(HTDC[
|
|
946
|
+
writeBits(HTDC[category2[pos]]);
|
|
947
947
|
writeBits(bitcode[pos]);
|
|
948
948
|
}
|
|
949
949
|
var end0pos = 63;
|
|
@@ -967,7 +967,7 @@ var require_encoder = __commonJS({
|
|
|
967
967
|
nrzeroes = nrzeroes & 15;
|
|
968
968
|
}
|
|
969
969
|
pos = 32767 + DU[i];
|
|
970
|
-
writeBits(HTAC[(nrzeroes << 4) +
|
|
970
|
+
writeBits(HTAC[(nrzeroes << 4) + category2[pos]]);
|
|
971
971
|
writeBits(bitcode[pos]);
|
|
972
972
|
i++;
|
|
973
973
|
}
|
|
@@ -24936,6 +24936,752 @@ function drawEmfPlusImageNow(rCtx, img, draw, source, effect = null) {
|
|
|
24936
24936
|
return bitmap ? paintBitmapRaster(rCtx.ctx, bitmap, draw) : false;
|
|
24937
24937
|
}
|
|
24938
24938
|
|
|
24939
|
+
// src/jpeg-encoder.ts
|
|
24940
|
+
var DEFAULT_JPEG_QUALITY = 0.92;
|
|
24941
|
+
var ZIGZAG2 = [
|
|
24942
|
+
0,
|
|
24943
|
+
1,
|
|
24944
|
+
8,
|
|
24945
|
+
16,
|
|
24946
|
+
9,
|
|
24947
|
+
2,
|
|
24948
|
+
3,
|
|
24949
|
+
10,
|
|
24950
|
+
17,
|
|
24951
|
+
24,
|
|
24952
|
+
32,
|
|
24953
|
+
25,
|
|
24954
|
+
18,
|
|
24955
|
+
11,
|
|
24956
|
+
4,
|
|
24957
|
+
5,
|
|
24958
|
+
12,
|
|
24959
|
+
19,
|
|
24960
|
+
26,
|
|
24961
|
+
33,
|
|
24962
|
+
40,
|
|
24963
|
+
48,
|
|
24964
|
+
41,
|
|
24965
|
+
34,
|
|
24966
|
+
27,
|
|
24967
|
+
20,
|
|
24968
|
+
13,
|
|
24969
|
+
6,
|
|
24970
|
+
7,
|
|
24971
|
+
14,
|
|
24972
|
+
21,
|
|
24973
|
+
28,
|
|
24974
|
+
35,
|
|
24975
|
+
42,
|
|
24976
|
+
49,
|
|
24977
|
+
56,
|
|
24978
|
+
57,
|
|
24979
|
+
50,
|
|
24980
|
+
43,
|
|
24981
|
+
36,
|
|
24982
|
+
29,
|
|
24983
|
+
22,
|
|
24984
|
+
15,
|
|
24985
|
+
23,
|
|
24986
|
+
30,
|
|
24987
|
+
37,
|
|
24988
|
+
44,
|
|
24989
|
+
51,
|
|
24990
|
+
58,
|
|
24991
|
+
59,
|
|
24992
|
+
52,
|
|
24993
|
+
45,
|
|
24994
|
+
38,
|
|
24995
|
+
31,
|
|
24996
|
+
39,
|
|
24997
|
+
46,
|
|
24998
|
+
53,
|
|
24999
|
+
60,
|
|
25000
|
+
61,
|
|
25001
|
+
54,
|
|
25002
|
+
47,
|
|
25003
|
+
55,
|
|
25004
|
+
62,
|
|
25005
|
+
63
|
|
25006
|
+
];
|
|
25007
|
+
var LUMA_QUANT = [
|
|
25008
|
+
16,
|
|
25009
|
+
11,
|
|
25010
|
+
10,
|
|
25011
|
+
16,
|
|
25012
|
+
24,
|
|
25013
|
+
40,
|
|
25014
|
+
51,
|
|
25015
|
+
61,
|
|
25016
|
+
12,
|
|
25017
|
+
12,
|
|
25018
|
+
14,
|
|
25019
|
+
19,
|
|
25020
|
+
26,
|
|
25021
|
+
58,
|
|
25022
|
+
60,
|
|
25023
|
+
55,
|
|
25024
|
+
14,
|
|
25025
|
+
13,
|
|
25026
|
+
16,
|
|
25027
|
+
24,
|
|
25028
|
+
40,
|
|
25029
|
+
57,
|
|
25030
|
+
69,
|
|
25031
|
+
56,
|
|
25032
|
+
14,
|
|
25033
|
+
17,
|
|
25034
|
+
22,
|
|
25035
|
+
29,
|
|
25036
|
+
51,
|
|
25037
|
+
87,
|
|
25038
|
+
80,
|
|
25039
|
+
62,
|
|
25040
|
+
18,
|
|
25041
|
+
22,
|
|
25042
|
+
37,
|
|
25043
|
+
56,
|
|
25044
|
+
68,
|
|
25045
|
+
109,
|
|
25046
|
+
103,
|
|
25047
|
+
77,
|
|
25048
|
+
24,
|
|
25049
|
+
35,
|
|
25050
|
+
55,
|
|
25051
|
+
64,
|
|
25052
|
+
81,
|
|
25053
|
+
104,
|
|
25054
|
+
113,
|
|
25055
|
+
92,
|
|
25056
|
+
49,
|
|
25057
|
+
64,
|
|
25058
|
+
78,
|
|
25059
|
+
87,
|
|
25060
|
+
103,
|
|
25061
|
+
121,
|
|
25062
|
+
120,
|
|
25063
|
+
101,
|
|
25064
|
+
72,
|
|
25065
|
+
92,
|
|
25066
|
+
95,
|
|
25067
|
+
98,
|
|
25068
|
+
112,
|
|
25069
|
+
100,
|
|
25070
|
+
103,
|
|
25071
|
+
99
|
|
25072
|
+
];
|
|
25073
|
+
var CHROMA_QUANT = [
|
|
25074
|
+
17,
|
|
25075
|
+
18,
|
|
25076
|
+
24,
|
|
25077
|
+
47,
|
|
25078
|
+
99,
|
|
25079
|
+
99,
|
|
25080
|
+
99,
|
|
25081
|
+
99,
|
|
25082
|
+
18,
|
|
25083
|
+
21,
|
|
25084
|
+
26,
|
|
25085
|
+
66,
|
|
25086
|
+
99,
|
|
25087
|
+
99,
|
|
25088
|
+
99,
|
|
25089
|
+
99,
|
|
25090
|
+
24,
|
|
25091
|
+
26,
|
|
25092
|
+
56,
|
|
25093
|
+
99,
|
|
25094
|
+
99,
|
|
25095
|
+
99,
|
|
25096
|
+
99,
|
|
25097
|
+
99,
|
|
25098
|
+
47,
|
|
25099
|
+
66,
|
|
25100
|
+
99,
|
|
25101
|
+
99,
|
|
25102
|
+
99,
|
|
25103
|
+
99,
|
|
25104
|
+
99,
|
|
25105
|
+
99,
|
|
25106
|
+
99,
|
|
25107
|
+
99,
|
|
25108
|
+
99,
|
|
25109
|
+
99,
|
|
25110
|
+
99,
|
|
25111
|
+
99,
|
|
25112
|
+
99,
|
|
25113
|
+
99,
|
|
25114
|
+
99,
|
|
25115
|
+
99,
|
|
25116
|
+
99,
|
|
25117
|
+
99,
|
|
25118
|
+
99,
|
|
25119
|
+
99,
|
|
25120
|
+
99,
|
|
25121
|
+
99,
|
|
25122
|
+
99,
|
|
25123
|
+
99,
|
|
25124
|
+
99,
|
|
25125
|
+
99,
|
|
25126
|
+
99,
|
|
25127
|
+
99,
|
|
25128
|
+
99,
|
|
25129
|
+
99,
|
|
25130
|
+
99,
|
|
25131
|
+
99,
|
|
25132
|
+
99,
|
|
25133
|
+
99,
|
|
25134
|
+
99,
|
|
25135
|
+
99,
|
|
25136
|
+
99,
|
|
25137
|
+
99
|
|
25138
|
+
];
|
|
25139
|
+
var DC_LUMA = { bits: [0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] };
|
|
25140
|
+
var DC_CHROMA = { bits: [0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] };
|
|
25141
|
+
var AC_LUMA = {
|
|
25142
|
+
bits: [0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125],
|
|
25143
|
+
values: [
|
|
25144
|
+
1,
|
|
25145
|
+
2,
|
|
25146
|
+
3,
|
|
25147
|
+
0,
|
|
25148
|
+
4,
|
|
25149
|
+
17,
|
|
25150
|
+
5,
|
|
25151
|
+
18,
|
|
25152
|
+
33,
|
|
25153
|
+
49,
|
|
25154
|
+
65,
|
|
25155
|
+
6,
|
|
25156
|
+
19,
|
|
25157
|
+
81,
|
|
25158
|
+
97,
|
|
25159
|
+
7,
|
|
25160
|
+
34,
|
|
25161
|
+
113,
|
|
25162
|
+
20,
|
|
25163
|
+
50,
|
|
25164
|
+
129,
|
|
25165
|
+
145,
|
|
25166
|
+
161,
|
|
25167
|
+
8,
|
|
25168
|
+
35,
|
|
25169
|
+
66,
|
|
25170
|
+
177,
|
|
25171
|
+
193,
|
|
25172
|
+
21,
|
|
25173
|
+
82,
|
|
25174
|
+
209,
|
|
25175
|
+
240,
|
|
25176
|
+
36,
|
|
25177
|
+
51,
|
|
25178
|
+
98,
|
|
25179
|
+
114,
|
|
25180
|
+
130,
|
|
25181
|
+
9,
|
|
25182
|
+
10,
|
|
25183
|
+
22,
|
|
25184
|
+
23,
|
|
25185
|
+
24,
|
|
25186
|
+
25,
|
|
25187
|
+
26,
|
|
25188
|
+
37,
|
|
25189
|
+
38,
|
|
25190
|
+
39,
|
|
25191
|
+
40,
|
|
25192
|
+
41,
|
|
25193
|
+
42,
|
|
25194
|
+
52,
|
|
25195
|
+
53,
|
|
25196
|
+
54,
|
|
25197
|
+
55,
|
|
25198
|
+
56,
|
|
25199
|
+
57,
|
|
25200
|
+
58,
|
|
25201
|
+
67,
|
|
25202
|
+
68,
|
|
25203
|
+
69,
|
|
25204
|
+
70,
|
|
25205
|
+
71,
|
|
25206
|
+
72,
|
|
25207
|
+
73,
|
|
25208
|
+
74,
|
|
25209
|
+
83,
|
|
25210
|
+
84,
|
|
25211
|
+
85,
|
|
25212
|
+
86,
|
|
25213
|
+
87,
|
|
25214
|
+
88,
|
|
25215
|
+
89,
|
|
25216
|
+
90,
|
|
25217
|
+
99,
|
|
25218
|
+
100,
|
|
25219
|
+
101,
|
|
25220
|
+
102,
|
|
25221
|
+
103,
|
|
25222
|
+
104,
|
|
25223
|
+
105,
|
|
25224
|
+
106,
|
|
25225
|
+
115,
|
|
25226
|
+
116,
|
|
25227
|
+
117,
|
|
25228
|
+
118,
|
|
25229
|
+
119,
|
|
25230
|
+
120,
|
|
25231
|
+
121,
|
|
25232
|
+
122,
|
|
25233
|
+
131,
|
|
25234
|
+
132,
|
|
25235
|
+
133,
|
|
25236
|
+
134,
|
|
25237
|
+
135,
|
|
25238
|
+
136,
|
|
25239
|
+
137,
|
|
25240
|
+
138,
|
|
25241
|
+
146,
|
|
25242
|
+
147,
|
|
25243
|
+
148,
|
|
25244
|
+
149,
|
|
25245
|
+
150,
|
|
25246
|
+
151,
|
|
25247
|
+
152,
|
|
25248
|
+
153,
|
|
25249
|
+
154,
|
|
25250
|
+
162,
|
|
25251
|
+
163,
|
|
25252
|
+
164,
|
|
25253
|
+
165,
|
|
25254
|
+
166,
|
|
25255
|
+
167,
|
|
25256
|
+
168,
|
|
25257
|
+
169,
|
|
25258
|
+
170,
|
|
25259
|
+
178,
|
|
25260
|
+
179,
|
|
25261
|
+
180,
|
|
25262
|
+
181,
|
|
25263
|
+
182,
|
|
25264
|
+
183,
|
|
25265
|
+
184,
|
|
25266
|
+
185,
|
|
25267
|
+
186,
|
|
25268
|
+
194,
|
|
25269
|
+
195,
|
|
25270
|
+
196,
|
|
25271
|
+
197,
|
|
25272
|
+
198,
|
|
25273
|
+
199,
|
|
25274
|
+
200,
|
|
25275
|
+
201,
|
|
25276
|
+
202,
|
|
25277
|
+
210,
|
|
25278
|
+
211,
|
|
25279
|
+
212,
|
|
25280
|
+
213,
|
|
25281
|
+
214,
|
|
25282
|
+
215,
|
|
25283
|
+
216,
|
|
25284
|
+
217,
|
|
25285
|
+
218,
|
|
25286
|
+
225,
|
|
25287
|
+
226,
|
|
25288
|
+
227,
|
|
25289
|
+
228,
|
|
25290
|
+
229,
|
|
25291
|
+
230,
|
|
25292
|
+
231,
|
|
25293
|
+
232,
|
|
25294
|
+
233,
|
|
25295
|
+
234,
|
|
25296
|
+
241,
|
|
25297
|
+
242,
|
|
25298
|
+
243,
|
|
25299
|
+
244,
|
|
25300
|
+
245,
|
|
25301
|
+
246,
|
|
25302
|
+
247,
|
|
25303
|
+
248,
|
|
25304
|
+
249,
|
|
25305
|
+
250
|
|
25306
|
+
]
|
|
25307
|
+
};
|
|
25308
|
+
var AC_CHROMA = {
|
|
25309
|
+
bits: [0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119],
|
|
25310
|
+
values: [
|
|
25311
|
+
0,
|
|
25312
|
+
1,
|
|
25313
|
+
2,
|
|
25314
|
+
3,
|
|
25315
|
+
17,
|
|
25316
|
+
4,
|
|
25317
|
+
5,
|
|
25318
|
+
33,
|
|
25319
|
+
49,
|
|
25320
|
+
6,
|
|
25321
|
+
18,
|
|
25322
|
+
65,
|
|
25323
|
+
81,
|
|
25324
|
+
7,
|
|
25325
|
+
97,
|
|
25326
|
+
113,
|
|
25327
|
+
19,
|
|
25328
|
+
34,
|
|
25329
|
+
50,
|
|
25330
|
+
129,
|
|
25331
|
+
8,
|
|
25332
|
+
20,
|
|
25333
|
+
66,
|
|
25334
|
+
145,
|
|
25335
|
+
161,
|
|
25336
|
+
177,
|
|
25337
|
+
193,
|
|
25338
|
+
9,
|
|
25339
|
+
35,
|
|
25340
|
+
51,
|
|
25341
|
+
82,
|
|
25342
|
+
240,
|
|
25343
|
+
21,
|
|
25344
|
+
98,
|
|
25345
|
+
114,
|
|
25346
|
+
209,
|
|
25347
|
+
10,
|
|
25348
|
+
22,
|
|
25349
|
+
36,
|
|
25350
|
+
52,
|
|
25351
|
+
225,
|
|
25352
|
+
37,
|
|
25353
|
+
241,
|
|
25354
|
+
23,
|
|
25355
|
+
24,
|
|
25356
|
+
25,
|
|
25357
|
+
26,
|
|
25358
|
+
38,
|
|
25359
|
+
39,
|
|
25360
|
+
40,
|
|
25361
|
+
41,
|
|
25362
|
+
42,
|
|
25363
|
+
53,
|
|
25364
|
+
54,
|
|
25365
|
+
55,
|
|
25366
|
+
56,
|
|
25367
|
+
57,
|
|
25368
|
+
58,
|
|
25369
|
+
67,
|
|
25370
|
+
68,
|
|
25371
|
+
69,
|
|
25372
|
+
70,
|
|
25373
|
+
71,
|
|
25374
|
+
72,
|
|
25375
|
+
73,
|
|
25376
|
+
74,
|
|
25377
|
+
83,
|
|
25378
|
+
84,
|
|
25379
|
+
85,
|
|
25380
|
+
86,
|
|
25381
|
+
87,
|
|
25382
|
+
88,
|
|
25383
|
+
89,
|
|
25384
|
+
90,
|
|
25385
|
+
99,
|
|
25386
|
+
100,
|
|
25387
|
+
101,
|
|
25388
|
+
102,
|
|
25389
|
+
103,
|
|
25390
|
+
104,
|
|
25391
|
+
105,
|
|
25392
|
+
106,
|
|
25393
|
+
115,
|
|
25394
|
+
116,
|
|
25395
|
+
117,
|
|
25396
|
+
118,
|
|
25397
|
+
119,
|
|
25398
|
+
120,
|
|
25399
|
+
121,
|
|
25400
|
+
122,
|
|
25401
|
+
130,
|
|
25402
|
+
131,
|
|
25403
|
+
132,
|
|
25404
|
+
133,
|
|
25405
|
+
134,
|
|
25406
|
+
135,
|
|
25407
|
+
136,
|
|
25408
|
+
137,
|
|
25409
|
+
138,
|
|
25410
|
+
146,
|
|
25411
|
+
147,
|
|
25412
|
+
148,
|
|
25413
|
+
149,
|
|
25414
|
+
150,
|
|
25415
|
+
151,
|
|
25416
|
+
152,
|
|
25417
|
+
153,
|
|
25418
|
+
154,
|
|
25419
|
+
162,
|
|
25420
|
+
163,
|
|
25421
|
+
164,
|
|
25422
|
+
165,
|
|
25423
|
+
166,
|
|
25424
|
+
167,
|
|
25425
|
+
168,
|
|
25426
|
+
169,
|
|
25427
|
+
170,
|
|
25428
|
+
178,
|
|
25429
|
+
179,
|
|
25430
|
+
180,
|
|
25431
|
+
181,
|
|
25432
|
+
182,
|
|
25433
|
+
183,
|
|
25434
|
+
184,
|
|
25435
|
+
185,
|
|
25436
|
+
186,
|
|
25437
|
+
194,
|
|
25438
|
+
195,
|
|
25439
|
+
196,
|
|
25440
|
+
197,
|
|
25441
|
+
198,
|
|
25442
|
+
199,
|
|
25443
|
+
200,
|
|
25444
|
+
201,
|
|
25445
|
+
202,
|
|
25446
|
+
210,
|
|
25447
|
+
211,
|
|
25448
|
+
212,
|
|
25449
|
+
213,
|
|
25450
|
+
214,
|
|
25451
|
+
215,
|
|
25452
|
+
216,
|
|
25453
|
+
217,
|
|
25454
|
+
218,
|
|
25455
|
+
226,
|
|
25456
|
+
227,
|
|
25457
|
+
228,
|
|
25458
|
+
229,
|
|
25459
|
+
230,
|
|
25460
|
+
231,
|
|
25461
|
+
232,
|
|
25462
|
+
233,
|
|
25463
|
+
234,
|
|
25464
|
+
242,
|
|
25465
|
+
243,
|
|
25466
|
+
244,
|
|
25467
|
+
245,
|
|
25468
|
+
246,
|
|
25469
|
+
247,
|
|
25470
|
+
248,
|
|
25471
|
+
249,
|
|
25472
|
+
250
|
|
25473
|
+
]
|
|
25474
|
+
};
|
|
25475
|
+
function buildCodes(spec) {
|
|
25476
|
+
const code = new Uint16Array(256);
|
|
25477
|
+
const size = new Uint8Array(256);
|
|
25478
|
+
let next = 0;
|
|
25479
|
+
let k = 0;
|
|
25480
|
+
for (let len = 1; len <= 16; len++) {
|
|
25481
|
+
for (let i = 0; i < spec.bits[len - 1]; i++) {
|
|
25482
|
+
const symbol = spec.values[k++];
|
|
25483
|
+
code[symbol] = next++;
|
|
25484
|
+
size[symbol] = len;
|
|
25485
|
+
}
|
|
25486
|
+
next <<= 1;
|
|
25487
|
+
}
|
|
25488
|
+
return { code, size };
|
|
25489
|
+
}
|
|
25490
|
+
function scaleQuant(base, quality) {
|
|
25491
|
+
const q = Math.min(100, Math.max(1, Math.round(quality * 100)));
|
|
25492
|
+
const scale = q < 50 ? Math.floor(5e3 / q) : 200 - q * 2;
|
|
25493
|
+
return Uint8Array.from(base, (v) => Math.min(255, Math.max(1, Math.floor((v * scale + 50) / 100))));
|
|
25494
|
+
}
|
|
25495
|
+
var COS = (() => {
|
|
25496
|
+
const t = new Float64Array(64);
|
|
25497
|
+
for (let u = 0; u < 8; u++) {
|
|
25498
|
+
const c = u === 0 ? Math.SQRT1_2 : 1;
|
|
25499
|
+
for (let x = 0; x < 8; x++) {
|
|
25500
|
+
t[u * 8 + x] = c / 2 * Math.cos((2 * x + 1) * u * Math.PI / 16);
|
|
25501
|
+
}
|
|
25502
|
+
}
|
|
25503
|
+
return t;
|
|
25504
|
+
})();
|
|
25505
|
+
function fdctQuantize(block, quant, out, tmp) {
|
|
25506
|
+
for (let y = 0; y < 8; y++) {
|
|
25507
|
+
for (let u = 0; u < 8; u++) {
|
|
25508
|
+
let s = 0;
|
|
25509
|
+
for (let x = 0; x < 8; x++) s += COS[u * 8 + x] * block[y * 8 + x];
|
|
25510
|
+
tmp[y * 8 + u] = s;
|
|
25511
|
+
}
|
|
25512
|
+
}
|
|
25513
|
+
for (let k = 0; k < 64; k++) {
|
|
25514
|
+
const n = ZIGZAG2[k];
|
|
25515
|
+
const v = n >> 3;
|
|
25516
|
+
const u = n & 7;
|
|
25517
|
+
let s = 0;
|
|
25518
|
+
for (let y = 0; y < 8; y++) s += COS[v * 8 + y] * tmp[y * 8 + u];
|
|
25519
|
+
out[k] = Math.round(s / quant[n]);
|
|
25520
|
+
}
|
|
25521
|
+
}
|
|
25522
|
+
var BitWriter = class {
|
|
25523
|
+
constructor() {
|
|
25524
|
+
this.buf = new Uint8Array(4096);
|
|
25525
|
+
this.length = 0;
|
|
25526
|
+
this.acc = 0;
|
|
25527
|
+
this.count = 0;
|
|
25528
|
+
}
|
|
25529
|
+
byte(b) {
|
|
25530
|
+
if (this.length === this.buf.length) {
|
|
25531
|
+
const grown = new Uint8Array(this.buf.length * 2);
|
|
25532
|
+
grown.set(this.buf);
|
|
25533
|
+
this.buf = grown;
|
|
25534
|
+
}
|
|
25535
|
+
this.buf[this.length++] = b;
|
|
25536
|
+
}
|
|
25537
|
+
bits(value, size) {
|
|
25538
|
+
for (let i = size - 1; i >= 0; i--) {
|
|
25539
|
+
this.acc = this.acc << 1 | value >> i & 1;
|
|
25540
|
+
if (++this.count === 8) {
|
|
25541
|
+
this.byte(this.acc);
|
|
25542
|
+
if (this.acc === 255) this.byte(0);
|
|
25543
|
+
this.acc = 0;
|
|
25544
|
+
this.count = 0;
|
|
25545
|
+
}
|
|
25546
|
+
}
|
|
25547
|
+
}
|
|
25548
|
+
/** Pads the last byte with 1 bits and returns the segment. */
|
|
25549
|
+
finish() {
|
|
25550
|
+
if (this.count > 0) this.bits((1 << 8 - this.count) - 1, 8 - this.count);
|
|
25551
|
+
return this.buf.subarray(0, this.length);
|
|
25552
|
+
}
|
|
25553
|
+
};
|
|
25554
|
+
function category(v) {
|
|
25555
|
+
let a = v < 0 ? -v : v;
|
|
25556
|
+
let n = 0;
|
|
25557
|
+
while (a) {
|
|
25558
|
+
n++;
|
|
25559
|
+
a >>= 1;
|
|
25560
|
+
}
|
|
25561
|
+
return n;
|
|
25562
|
+
}
|
|
25563
|
+
function writeBlock(w, coef, prevDc, dc, ac) {
|
|
25564
|
+
const diff = coef[0] - prevDc;
|
|
25565
|
+
const dcSize = category(diff);
|
|
25566
|
+
w.bits(dc.code[dcSize], dc.size[dcSize]);
|
|
25567
|
+
if (dcSize) w.bits(diff < 0 ? diff - 1 : diff, dcSize);
|
|
25568
|
+
let run = 0;
|
|
25569
|
+
for (let k = 1; k < 64; k++) {
|
|
25570
|
+
const v = coef[k];
|
|
25571
|
+
if (v === 0) {
|
|
25572
|
+
run++;
|
|
25573
|
+
continue;
|
|
25574
|
+
}
|
|
25575
|
+
while (run > 15) {
|
|
25576
|
+
w.bits(ac.code[240], ac.size[240]);
|
|
25577
|
+
run -= 16;
|
|
25578
|
+
}
|
|
25579
|
+
const size = category(v);
|
|
25580
|
+
const symbol = run << 4 | size;
|
|
25581
|
+
w.bits(ac.code[symbol], ac.size[symbol]);
|
|
25582
|
+
w.bits(v < 0 ? v - 1 : v, size);
|
|
25583
|
+
run = 0;
|
|
25584
|
+
}
|
|
25585
|
+
if (run > 0) w.bits(ac.code[0], ac.size[0]);
|
|
25586
|
+
return coef[0];
|
|
25587
|
+
}
|
|
25588
|
+
function segment(marker, payload) {
|
|
25589
|
+
const len = payload.length + 2;
|
|
25590
|
+
return [255, marker, len >> 8, len & 255, ...payload];
|
|
25591
|
+
}
|
|
25592
|
+
function dhtPayload(tableClass, id, spec) {
|
|
25593
|
+
return [tableClass << 4 | id, ...spec.bits, ...spec.values];
|
|
25594
|
+
}
|
|
25595
|
+
function encodeJpeg(data, width, height, options2 = {}) {
|
|
25596
|
+
if (!(width >= 1 && height >= 1 && width <= 65535 && height <= 65535)) {
|
|
25597
|
+
throw new RangeError(`JPEG dimensions out of range: ${width}x${height}`);
|
|
25598
|
+
}
|
|
25599
|
+
const quality = Number.isFinite(options2.quality) ? Math.min(1, Math.max(0, options2.quality)) : DEFAULT_JPEG_QUALITY;
|
|
25600
|
+
const [bgR, bgG, bgB] = options2.background ?? [255, 255, 255];
|
|
25601
|
+
const sub = options2.chromaSubsampling ?? false;
|
|
25602
|
+
const lumaQuant = scaleQuant(LUMA_QUANT, quality);
|
|
25603
|
+
const chromaQuant = scaleQuant(CHROMA_QUANT, quality);
|
|
25604
|
+
const n = width * height;
|
|
25605
|
+
const Y = new Float64Array(n);
|
|
25606
|
+
const Cb = new Float64Array(n);
|
|
25607
|
+
const Cr = new Float64Array(n);
|
|
25608
|
+
for (let i = 0; i < n; i++) {
|
|
25609
|
+
const a = data[i * 4 + 3] / 255;
|
|
25610
|
+
const r = data[i * 4] * a + bgR * (1 - a);
|
|
25611
|
+
const g = data[i * 4 + 1] * a + bgG * (1 - a);
|
|
25612
|
+
const b = data[i * 4 + 2] * a + bgB * (1 - a);
|
|
25613
|
+
Y[i] = 0.299 * r + 0.587 * g + 0.114 * b;
|
|
25614
|
+
Cb[i] = -0.168736 * r - 0.331264 * g + 0.5 * b + 128;
|
|
25615
|
+
Cr[i] = 0.5 * r - 0.418688 * g - 0.081312 * b + 128;
|
|
25616
|
+
}
|
|
25617
|
+
const dcL = buildCodes(DC_LUMA);
|
|
25618
|
+
const acL = buildCodes(AC_LUMA);
|
|
25619
|
+
const dcC = buildCodes(DC_CHROMA);
|
|
25620
|
+
const acC = buildCodes(AC_CHROMA);
|
|
25621
|
+
const factor = sub ? 2 : 1;
|
|
25622
|
+
const mcu = 8 * factor;
|
|
25623
|
+
const block = new Float64Array(64);
|
|
25624
|
+
const tmp = new Float64Array(64);
|
|
25625
|
+
const coef = new Int32Array(64);
|
|
25626
|
+
const w = new BitWriter();
|
|
25627
|
+
let dcY = 0;
|
|
25628
|
+
let dcCb = 0;
|
|
25629
|
+
let dcCr = 0;
|
|
25630
|
+
const lumaBlock = (x0, y0) => {
|
|
25631
|
+
for (let y = 0; y < 8; y++) {
|
|
25632
|
+
const row2 = Math.min(height - 1, y0 + y) * width;
|
|
25633
|
+
for (let x = 0; x < 8; x++) block[y * 8 + x] = Y[row2 + Math.min(width - 1, x0 + x)] - 128;
|
|
25634
|
+
}
|
|
25635
|
+
};
|
|
25636
|
+
const chromaBlock = (plane, x0, y0) => {
|
|
25637
|
+
for (let y = 0; y < 8; y++) {
|
|
25638
|
+
for (let x = 0; x < 8; x++) {
|
|
25639
|
+
let s = 0;
|
|
25640
|
+
for (let dy = 0; dy < factor; dy++) {
|
|
25641
|
+
const row2 = Math.min(height - 1, y0 + y * factor + dy) * width;
|
|
25642
|
+
for (let dx = 0; dx < factor; dx++) s += plane[row2 + Math.min(width - 1, x0 + x * factor + dx)];
|
|
25643
|
+
}
|
|
25644
|
+
block[y * 8 + x] = s / (factor * factor) - 128;
|
|
25645
|
+
}
|
|
25646
|
+
}
|
|
25647
|
+
};
|
|
25648
|
+
for (let my = 0; my < height; my += mcu) {
|
|
25649
|
+
for (let mx = 0; mx < width; mx += mcu) {
|
|
25650
|
+
for (let by = 0; by < factor; by++) {
|
|
25651
|
+
for (let bx = 0; bx < factor; bx++) {
|
|
25652
|
+
lumaBlock(mx + bx * 8, my + by * 8);
|
|
25653
|
+
fdctQuantize(block, lumaQuant, coef, tmp);
|
|
25654
|
+
dcY = writeBlock(w, coef, dcY, dcL, acL);
|
|
25655
|
+
}
|
|
25656
|
+
}
|
|
25657
|
+
chromaBlock(Cb, mx, my);
|
|
25658
|
+
fdctQuantize(block, chromaQuant, coef, tmp);
|
|
25659
|
+
dcCb = writeBlock(w, coef, dcCb, dcC, acC);
|
|
25660
|
+
chromaBlock(Cr, mx, my);
|
|
25661
|
+
fdctQuantize(block, chromaQuant, coef, tmp);
|
|
25662
|
+
dcCr = writeBlock(w, coef, dcCr, dcC, acC);
|
|
25663
|
+
}
|
|
25664
|
+
}
|
|
25665
|
+
const scan = w.finish();
|
|
25666
|
+
const sampling = factor << 4 | factor;
|
|
25667
|
+
const header = [
|
|
25668
|
+
255,
|
|
25669
|
+
216,
|
|
25670
|
+
// APP0 JFIF 1.01, no density (aspect ratio 1:1), no thumbnail.
|
|
25671
|
+
...segment(224, [74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0]),
|
|
25672
|
+
...segment(219, [0, ...ZIGZAG2.map((i) => lumaQuant[i]), 1, ...ZIGZAG2.map((i) => chromaQuant[i])]),
|
|
25673
|
+
...segment(192, [8, height >> 8, height & 255, width >> 8, width & 255, 3, 1, sampling, 0, 2, 17, 1, 3, 17, 1]),
|
|
25674
|
+
...segment(196, [...dhtPayload(0, 0, DC_LUMA), ...dhtPayload(1, 0, AC_LUMA), ...dhtPayload(0, 1, DC_CHROMA), ...dhtPayload(1, 1, AC_CHROMA)]),
|
|
25675
|
+
...segment(218, [3, 1, 0, 2, 17, 3, 17, 0, 63, 0])
|
|
25676
|
+
];
|
|
25677
|
+
const out = new Uint8Array(header.length + scan.length + 2);
|
|
25678
|
+
out.set(header, 0);
|
|
25679
|
+
out.set(scan, header.length);
|
|
25680
|
+
out[out.length - 2] = 255;
|
|
25681
|
+
out[out.length - 1] = 217;
|
|
25682
|
+
return out;
|
|
25683
|
+
}
|
|
25684
|
+
|
|
24939
25685
|
// src/fnt-font.ts
|
|
24940
25686
|
function parseFnt(view, base, end) {
|
|
24941
25687
|
if (base + 118 > end) {
|
|
@@ -43381,6 +44127,54 @@ async function processDeferredImages(ctx, deferredImages, recursionDepth) {
|
|
|
43381
44127
|
return complete;
|
|
43382
44128
|
}
|
|
43383
44129
|
async function convertMetafileToDataUrl(buffer, options2, recursionDepth = 0) {
|
|
44130
|
+
const raster = await renderRaster(buffer, options2, recursionDepth, "convertMetafileToDataUrl");
|
|
44131
|
+
if (!raster) {
|
|
44132
|
+
return null;
|
|
44133
|
+
}
|
|
44134
|
+
try {
|
|
44135
|
+
const url = await exportCanvasToPngDataUrl(raster.canvas);
|
|
44136
|
+
if (!url) {
|
|
44137
|
+
emfWarn("convertMetafileToDataUrl: exportCanvasToPngDataUrl returned null");
|
|
44138
|
+
}
|
|
44139
|
+
return url;
|
|
44140
|
+
} catch (err) {
|
|
44141
|
+
emfWarn("convertMetafileToDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
|
|
44142
|
+
console.warn("[emf-converter] Conversion failed:", err instanceof Error ? err.message : err);
|
|
44143
|
+
return null;
|
|
44144
|
+
}
|
|
44145
|
+
}
|
|
44146
|
+
async function convertMetafileToJpegDataUrl(buffer, options2) {
|
|
44147
|
+
const raster = await renderRaster(buffer, options2, 0, "convertMetafileToJpegDataUrl");
|
|
44148
|
+
if (!raster) {
|
|
44149
|
+
return null;
|
|
44150
|
+
}
|
|
44151
|
+
try {
|
|
44152
|
+
const { canvas, ctx } = raster;
|
|
44153
|
+
const pixels = canvas instanceof SoftwareRasterCanvas ? canvas.pixels : canvasGetImageData(ctx, 0, 0, canvas.width, canvas.height).data;
|
|
44154
|
+
const jpeg = encodeJpeg(pixels, canvas.width, canvas.height, {
|
|
44155
|
+
quality: options2?.quality,
|
|
44156
|
+
background: parseBackground(options2?.background),
|
|
44157
|
+
chromaSubsampling: options2?.chromaSubsampling
|
|
44158
|
+
});
|
|
44159
|
+
return `data:image/jpeg;base64,${bytesToBase64(jpeg)}`;
|
|
44160
|
+
} catch (err) {
|
|
44161
|
+
emfWarn("convertMetafileToJpegDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
|
|
44162
|
+
console.warn("[emf-converter] Conversion failed:", err instanceof Error ? err.message : err);
|
|
44163
|
+
return null;
|
|
44164
|
+
}
|
|
44165
|
+
}
|
|
44166
|
+
function parseBackground(color) {
|
|
44167
|
+
if (color === void 0) {
|
|
44168
|
+
return [255, 255, 255];
|
|
44169
|
+
}
|
|
44170
|
+
const hex5 = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(color.trim())?.[1];
|
|
44171
|
+
if (!hex5) {
|
|
44172
|
+
return [255, 255, 255];
|
|
44173
|
+
}
|
|
44174
|
+
const full = hex5.length === 3 ? [...hex5].map((c) => c + c).join("") : hex5;
|
|
44175
|
+
return [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16));
|
|
44176
|
+
}
|
|
44177
|
+
async function renderRaster(buffer, options2, recursionDepth, caller) {
|
|
43384
44178
|
await ensureNodeCanvasModule();
|
|
43385
44179
|
if (recursionDepth > MAX_METAFILE_RECURSION) {
|
|
43386
44180
|
return null;
|
|
@@ -43410,17 +44204,13 @@ async function convertMetafileToDataUrl(buffer, options2, recursionDepth = 0) {
|
|
|
43410
44204
|
const soft = canvas instanceof SoftwareRasterCanvas ? canvas : null;
|
|
43411
44205
|
if (soft && (soft.textDraws > 0 || !complete)) {
|
|
43412
44206
|
emfWarn(
|
|
43413
|
-
|
|
44207
|
+
`${caller}: no canvas backend and the drawing ${soft.textDraws > 0 ? `contains text (${soft.textDraws} runs)` : "contains an image only a canvas can decode"}; install @napi-rs/canvas for raster output, or use SVG output`
|
|
43414
44208
|
);
|
|
43415
44209
|
return null;
|
|
43416
44210
|
}
|
|
43417
|
-
|
|
43418
|
-
if (!url) {
|
|
43419
|
-
emfWarn("convertMetafileToDataUrl: exportCanvasToPngDataUrl returned null");
|
|
43420
|
-
}
|
|
43421
|
-
return url;
|
|
44211
|
+
return { canvas, ctx: result.surface.ctx };
|
|
43422
44212
|
} catch (err) {
|
|
43423
|
-
emfWarn(
|
|
44213
|
+
emfWarn(`${caller}: EXCEPTION:`, err instanceof Error ? err.message : err);
|
|
43424
44214
|
console.warn("[emf-converter] Conversion failed:", err instanceof Error ? err.message : err);
|
|
43425
44215
|
return null;
|
|
43426
44216
|
}
|
|
@@ -43571,6 +44361,7 @@ async function convertMetafileToSvgDataUrl(buffer, options2) {
|
|
|
43571
44361
|
|
|
43572
44362
|
exports.DEFAULT_DPI_SCALE = DEFAULT_DPI_SCALE;
|
|
43573
44363
|
exports.convertMetafileToDataUrl = convertMetafileToDataUrl;
|
|
44364
|
+
exports.convertMetafileToJpegDataUrl = convertMetafileToJpegDataUrl;
|
|
43574
44365
|
exports.convertMetafileToSvg = convertMetafileToSvg;
|
|
43575
44366
|
exports.convertMetafileToSvgDataUrl = convertMetafileToSvgDataUrl;
|
|
43576
44367
|
exports.convertMetafileToSvgTree = convertMetafileToSvgTree;
|