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