emf-converter 4.5.0 → 4.5.2

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/dist/browser.js CHANGED
@@ -31152,6 +31152,29 @@ function halftoneAxis(start, srcLen, dstLen, reverse) {
31152
31152
  if (reverse) taps.reverse();
31153
31153
  return taps;
31154
31154
  }
31155
+ var SOFT_TENT_SIGMA = 0.25;
31156
+ var SOFT_TENT_STEPS = 31;
31157
+ var SOFT_TENT_SPAN = 3;
31158
+ var softTentCache = /* @__PURE__ */ new Map();
31159
+ function softTent(d) {
31160
+ const key = Math.round(d * 1024);
31161
+ const cached = softTentCache.get(key);
31162
+ if (cached !== void 0) {
31163
+ return cached;
31164
+ }
31165
+ let sum = 0;
31166
+ let total = 0;
31167
+ const half = (SOFT_TENT_STEPS - 1) / 2;
31168
+ for (let i = -half; i <= half; i++) {
31169
+ const x = i / half * SOFT_TENT_SPAN * SOFT_TENT_SIGMA;
31170
+ const g = Math.exp(-(x * x) / (2 * SOFT_TENT_SIGMA * SOFT_TENT_SIGMA));
31171
+ total += g;
31172
+ sum += g * Math.max(0, 1 - Math.abs(key / 1024 + x));
31173
+ }
31174
+ const value = sum / total;
31175
+ softTentCache.set(key, value);
31176
+ return value;
31177
+ }
31155
31178
  var SPECKLE_OVERSHOOT = 4;
31156
31179
  function halftoneDespeckle(px, w, h) {
31157
31180
  const src = px.slice();
@@ -31324,18 +31347,38 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust, adjustAfterSamplin
31324
31347
  }
31325
31348
  const source = out;
31326
31349
  out = new Int32Array(W * H * 3);
31350
+ const axisTaps = (src2, dst) => {
31351
+ const r = [];
31352
+ for (let i = 0; i < dst; i++) {
31353
+ if (src2 === dst) {
31354
+ r.push([[i, 1]]);
31355
+ continue;
31356
+ }
31357
+ const raw = (i + 0.5) * src2 / dst - 0.5;
31358
+ const pos = Math.max(0, Math.min(src2 - 1, raw));
31359
+ const i0 = Math.floor(pos);
31360
+ if (dst === 2 * src2) {
31361
+ r.push([[i0, 1 - (pos - i0)], [Math.min(src2 - 1, i0 + 1), pos - i0]]);
31362
+ continue;
31363
+ }
31364
+ const taps = [];
31365
+ let total = 0;
31366
+ for (let k = i0 - 2; k <= i0 + 3; k++) {
31367
+ const w = softTent(raw - k);
31368
+ taps.push([Math.max(0, Math.min(src2 - 1, k)), w]);
31369
+ total += w;
31370
+ }
31371
+ r.push(taps.map(([k, w]) => [k, w / total]));
31372
+ }
31373
+ return r;
31374
+ };
31375
+ const xt = axisTaps(sampleW, W), yt = axisTaps(sampleH, H);
31327
31376
  for (let y = 0; y < H; y++) {
31328
- const py = Math.max(0, Math.min(sampleH - 1, (y + 0.5) * sampleH / H - 0.5));
31329
- const y02 = Math.floor(py), fy = py - y02;
31330
31377
  for (let x = 0; x < W; x++) {
31331
- const px = Math.max(0, Math.min(sampleW - 1, (x + 0.5) * sampleW / W - 0.5));
31332
- const x02 = Math.floor(px), fx = px - x02;
31333
31378
  for (let c = 0; c < 3; c++) {
31334
- const at = (xx, yy) => source[(yy * sampleW + xx) * 3 + c];
31335
- const x1 = Math.min(sampleW - 1, x02 + 1), y1 = Math.min(sampleH - 1, y02 + 1);
31336
- const top = at(x02, y02) * (1 - fx) + at(x1, y02) * fx;
31337
- const bottom = at(x02, y1) * (1 - fx) + at(x1, y1) * fx;
31338
- out[(y * W + x) * 3 + c] = Math.floor(top * (1 - fy) + bottom * fy + 0.5);
31379
+ let v = 0;
31380
+ for (const [yy, wy] of yt[y]) for (const [xx, wx] of xt[x]) v += source[(yy * sampleW + xx) * 3 + c] * wy * wx;
31381
+ out[(y * W + x) * 3 + c] = Math.max(0, Math.min(255, Math.floor(v + 0.5)));
31339
31382
  }
31340
31383
  }
31341
31384
  }
package/dist/browser.mjs CHANGED
@@ -31150,6 +31150,29 @@ function halftoneAxis(start, srcLen, dstLen, reverse) {
31150
31150
  if (reverse) taps.reverse();
31151
31151
  return taps;
31152
31152
  }
31153
+ var SOFT_TENT_SIGMA = 0.25;
31154
+ var SOFT_TENT_STEPS = 31;
31155
+ var SOFT_TENT_SPAN = 3;
31156
+ var softTentCache = /* @__PURE__ */ new Map();
31157
+ function softTent(d) {
31158
+ const key = Math.round(d * 1024);
31159
+ const cached = softTentCache.get(key);
31160
+ if (cached !== void 0) {
31161
+ return cached;
31162
+ }
31163
+ let sum = 0;
31164
+ let total = 0;
31165
+ const half = (SOFT_TENT_STEPS - 1) / 2;
31166
+ for (let i = -half; i <= half; i++) {
31167
+ const x = i / half * SOFT_TENT_SPAN * SOFT_TENT_SIGMA;
31168
+ const g = Math.exp(-(x * x) / (2 * SOFT_TENT_SIGMA * SOFT_TENT_SIGMA));
31169
+ total += g;
31170
+ sum += g * Math.max(0, 1 - Math.abs(key / 1024 + x));
31171
+ }
31172
+ const value = sum / total;
31173
+ softTentCache.set(key, value);
31174
+ return value;
31175
+ }
31153
31176
  var SPECKLE_OVERSHOOT = 4;
31154
31177
  function halftoneDespeckle(px, w, h) {
31155
31178
  const src = px.slice();
@@ -31322,18 +31345,38 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust, adjustAfterSamplin
31322
31345
  }
31323
31346
  const source = out;
31324
31347
  out = new Int32Array(W * H * 3);
31348
+ const axisTaps = (src2, dst) => {
31349
+ const r = [];
31350
+ for (let i = 0; i < dst; i++) {
31351
+ if (src2 === dst) {
31352
+ r.push([[i, 1]]);
31353
+ continue;
31354
+ }
31355
+ const raw = (i + 0.5) * src2 / dst - 0.5;
31356
+ const pos = Math.max(0, Math.min(src2 - 1, raw));
31357
+ const i0 = Math.floor(pos);
31358
+ if (dst === 2 * src2) {
31359
+ r.push([[i0, 1 - (pos - i0)], [Math.min(src2 - 1, i0 + 1), pos - i0]]);
31360
+ continue;
31361
+ }
31362
+ const taps = [];
31363
+ let total = 0;
31364
+ for (let k = i0 - 2; k <= i0 + 3; k++) {
31365
+ const w = softTent(raw - k);
31366
+ taps.push([Math.max(0, Math.min(src2 - 1, k)), w]);
31367
+ total += w;
31368
+ }
31369
+ r.push(taps.map(([k, w]) => [k, w / total]));
31370
+ }
31371
+ return r;
31372
+ };
31373
+ const xt = axisTaps(sampleW, W), yt = axisTaps(sampleH, H);
31325
31374
  for (let y = 0; y < H; y++) {
31326
- const py = Math.max(0, Math.min(sampleH - 1, (y + 0.5) * sampleH / H - 0.5));
31327
- const y02 = Math.floor(py), fy = py - y02;
31328
31375
  for (let x = 0; x < W; x++) {
31329
- const px = Math.max(0, Math.min(sampleW - 1, (x + 0.5) * sampleW / W - 0.5));
31330
- const x02 = Math.floor(px), fx = px - x02;
31331
31376
  for (let c = 0; c < 3; c++) {
31332
- const at = (xx, yy) => source[(yy * sampleW + xx) * 3 + c];
31333
- const x1 = Math.min(sampleW - 1, x02 + 1), y1 = Math.min(sampleH - 1, y02 + 1);
31334
- const top = at(x02, y02) * (1 - fx) + at(x1, y02) * fx;
31335
- const bottom = at(x02, y1) * (1 - fx) + at(x1, y1) * fx;
31336
- out[(y * W + x) * 3 + c] = Math.floor(top * (1 - fy) + bottom * fy + 0.5);
31377
+ let v = 0;
31378
+ for (const [yy, wy] of yt[y]) for (const [xx, wx] of xt[x]) v += source[(yy * sampleW + xx) * 3 + c] * wy * wx;
31379
+ out[(y * W + x) * 3 + c] = Math.max(0, Math.min(255, Math.floor(v + 0.5)));
31337
31380
  }
31338
31381
  }
31339
31382
  }
package/dist/index.js CHANGED
@@ -31153,6 +31153,29 @@ function halftoneAxis(start, srcLen, dstLen, reverse) {
31153
31153
  if (reverse) taps.reverse();
31154
31154
  return taps;
31155
31155
  }
31156
+ var SOFT_TENT_SIGMA = 0.25;
31157
+ var SOFT_TENT_STEPS = 31;
31158
+ var SOFT_TENT_SPAN = 3;
31159
+ var softTentCache = /* @__PURE__ */ new Map();
31160
+ function softTent(d) {
31161
+ const key = Math.round(d * 1024);
31162
+ const cached = softTentCache.get(key);
31163
+ if (cached !== void 0) {
31164
+ return cached;
31165
+ }
31166
+ let sum = 0;
31167
+ let total = 0;
31168
+ const half = (SOFT_TENT_STEPS - 1) / 2;
31169
+ for (let i = -half; i <= half; i++) {
31170
+ const x = i / half * SOFT_TENT_SPAN * SOFT_TENT_SIGMA;
31171
+ const g = Math.exp(-(x * x) / (2 * SOFT_TENT_SIGMA * SOFT_TENT_SIGMA));
31172
+ total += g;
31173
+ sum += g * Math.max(0, 1 - Math.abs(key / 1024 + x));
31174
+ }
31175
+ const value = sum / total;
31176
+ softTentCache.set(key, value);
31177
+ return value;
31178
+ }
31156
31179
  var SPECKLE_OVERSHOOT = 4;
31157
31180
  function halftoneDespeckle(px, w, h) {
31158
31181
  const src = px.slice();
@@ -31325,18 +31348,38 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust, adjustAfterSamplin
31325
31348
  }
31326
31349
  const source = out;
31327
31350
  out = new Int32Array(W * H * 3);
31351
+ const axisTaps = (src2, dst) => {
31352
+ const r = [];
31353
+ for (let i = 0; i < dst; i++) {
31354
+ if (src2 === dst) {
31355
+ r.push([[i, 1]]);
31356
+ continue;
31357
+ }
31358
+ const raw = (i + 0.5) * src2 / dst - 0.5;
31359
+ const pos = Math.max(0, Math.min(src2 - 1, raw));
31360
+ const i0 = Math.floor(pos);
31361
+ if (dst === 2 * src2) {
31362
+ r.push([[i0, 1 - (pos - i0)], [Math.min(src2 - 1, i0 + 1), pos - i0]]);
31363
+ continue;
31364
+ }
31365
+ const taps = [];
31366
+ let total = 0;
31367
+ for (let k = i0 - 2; k <= i0 + 3; k++) {
31368
+ const w = softTent(raw - k);
31369
+ taps.push([Math.max(0, Math.min(src2 - 1, k)), w]);
31370
+ total += w;
31371
+ }
31372
+ r.push(taps.map(([k, w]) => [k, w / total]));
31373
+ }
31374
+ return r;
31375
+ };
31376
+ const xt = axisTaps(sampleW, W), yt = axisTaps(sampleH, H);
31328
31377
  for (let y = 0; y < H; y++) {
31329
- const py = Math.max(0, Math.min(sampleH - 1, (y + 0.5) * sampleH / H - 0.5));
31330
- const y02 = Math.floor(py), fy = py - y02;
31331
31378
  for (let x = 0; x < W; x++) {
31332
- const px = Math.max(0, Math.min(sampleW - 1, (x + 0.5) * sampleW / W - 0.5));
31333
- const x02 = Math.floor(px), fx = px - x02;
31334
31379
  for (let c = 0; c < 3; c++) {
31335
- const at = (xx, yy) => source[(yy * sampleW + xx) * 3 + c];
31336
- const x1 = Math.min(sampleW - 1, x02 + 1), y1 = Math.min(sampleH - 1, y02 + 1);
31337
- const top = at(x02, y02) * (1 - fx) + at(x1, y02) * fx;
31338
- const bottom = at(x02, y1) * (1 - fx) + at(x1, y1) * fx;
31339
- out[(y * W + x) * 3 + c] = Math.floor(top * (1 - fy) + bottom * fy + 0.5);
31380
+ let v = 0;
31381
+ for (const [yy, wy] of yt[y]) for (const [xx, wx] of xt[x]) v += source[(yy * sampleW + xx) * 3 + c] * wy * wx;
31382
+ out[(y * W + x) * 3 + c] = Math.max(0, Math.min(255, Math.floor(v + 0.5)));
31340
31383
  }
31341
31384
  }
31342
31385
  }
package/dist/index.mjs CHANGED
@@ -31151,6 +31151,29 @@ function halftoneAxis(start, srcLen, dstLen, reverse) {
31151
31151
  if (reverse) taps.reverse();
31152
31152
  return taps;
31153
31153
  }
31154
+ var SOFT_TENT_SIGMA = 0.25;
31155
+ var SOFT_TENT_STEPS = 31;
31156
+ var SOFT_TENT_SPAN = 3;
31157
+ var softTentCache = /* @__PURE__ */ new Map();
31158
+ function softTent(d) {
31159
+ const key = Math.round(d * 1024);
31160
+ const cached = softTentCache.get(key);
31161
+ if (cached !== void 0) {
31162
+ return cached;
31163
+ }
31164
+ let sum = 0;
31165
+ let total = 0;
31166
+ const half = (SOFT_TENT_STEPS - 1) / 2;
31167
+ for (let i = -half; i <= half; i++) {
31168
+ const x = i / half * SOFT_TENT_SPAN * SOFT_TENT_SIGMA;
31169
+ const g = Math.exp(-(x * x) / (2 * SOFT_TENT_SIGMA * SOFT_TENT_SIGMA));
31170
+ total += g;
31171
+ sum += g * Math.max(0, 1 - Math.abs(key / 1024 + x));
31172
+ }
31173
+ const value = sum / total;
31174
+ softTentCache.set(key, value);
31175
+ return value;
31176
+ }
31154
31177
  var SPECKLE_OVERSHOOT = 4;
31155
31178
  function halftoneDespeckle(px, w, h) {
31156
31179
  const src = px.slice();
@@ -31323,18 +31346,38 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust, adjustAfterSamplin
31323
31346
  }
31324
31347
  const source = out;
31325
31348
  out = new Int32Array(W * H * 3);
31349
+ const axisTaps = (src2, dst) => {
31350
+ const r = [];
31351
+ for (let i = 0; i < dst; i++) {
31352
+ if (src2 === dst) {
31353
+ r.push([[i, 1]]);
31354
+ continue;
31355
+ }
31356
+ const raw = (i + 0.5) * src2 / dst - 0.5;
31357
+ const pos = Math.max(0, Math.min(src2 - 1, raw));
31358
+ const i0 = Math.floor(pos);
31359
+ if (dst === 2 * src2) {
31360
+ r.push([[i0, 1 - (pos - i0)], [Math.min(src2 - 1, i0 + 1), pos - i0]]);
31361
+ continue;
31362
+ }
31363
+ const taps = [];
31364
+ let total = 0;
31365
+ for (let k = i0 - 2; k <= i0 + 3; k++) {
31366
+ const w = softTent(raw - k);
31367
+ taps.push([Math.max(0, Math.min(src2 - 1, k)), w]);
31368
+ total += w;
31369
+ }
31370
+ r.push(taps.map(([k, w]) => [k, w / total]));
31371
+ }
31372
+ return r;
31373
+ };
31374
+ const xt = axisTaps(sampleW, W), yt = axisTaps(sampleH, H);
31326
31375
  for (let y = 0; y < H; y++) {
31327
- const py = Math.max(0, Math.min(sampleH - 1, (y + 0.5) * sampleH / H - 0.5));
31328
- const y02 = Math.floor(py), fy = py - y02;
31329
31376
  for (let x = 0; x < W; x++) {
31330
- const px = Math.max(0, Math.min(sampleW - 1, (x + 0.5) * sampleW / W - 0.5));
31331
- const x02 = Math.floor(px), fx = px - x02;
31332
31377
  for (let c = 0; c < 3; c++) {
31333
- const at = (xx, yy) => source[(yy * sampleW + xx) * 3 + c];
31334
- const x1 = Math.min(sampleW - 1, x02 + 1), y1 = Math.min(sampleH - 1, y02 + 1);
31335
- const top = at(x02, y02) * (1 - fx) + at(x1, y02) * fx;
31336
- const bottom = at(x02, y1) * (1 - fx) + at(x1, y1) * fx;
31337
- out[(y * W + x) * 3 + c] = Math.floor(top * (1 - fy) + bottom * fy + 0.5);
31378
+ let v = 0;
31379
+ for (const [yy, wy] of yt[y]) for (const [xx, wx] of xt[x]) v += source[(yy * sampleW + xx) * 3 + c] * wy * wx;
31380
+ out[(y * W + x) * 3 + c] = Math.max(0, Math.min(255, Math.floor(v + 0.5)));
31338
31381
  }
31339
31382
  }
31340
31383
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emf-converter",
3
- "version": "4.5.0",
3
+ "version": "4.5.2",
4
4
  "description": "Convert EMF/WMF metafile binaries to PNG data URLs or SVG (markup, data URL, React/JSX)",
5
5
  "keywords": [
6
6
  "canvas",