emf-converter 4.4.1 → 4.4.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
@@ -10332,6 +10332,16 @@ function decodeImageCodecFallback(bytes) {
10332
10332
  if (!f || !validSize(f.image.descriptor.width, f.image.descriptor.height)) return null;
10333
10333
  const frame2 = (0, import_gifuct_js.decompressFrame)(f, gif.gct, true);
10334
10334
  const data = new Uint8ClampedArray(width * height * 4);
10335
+ const transparent = frame2.transparentIndex !== void 0;
10336
+ const background = transparent ? frame2.colorTable[frame2.transparentIndex] : gif.gct?.[gif.lsd.backgroundColorIndex];
10337
+ if (background) {
10338
+ for (let i = 0; i < data.length; i += 4) {
10339
+ data[i] = background[0];
10340
+ data[i + 1] = background[1];
10341
+ data[i + 2] = background[2];
10342
+ data[i + 3] = transparent ? 0 : 255;
10343
+ }
10344
+ }
10335
10345
  const { top, left, width: fw, height: fh } = frame2.dims;
10336
10346
  for (let y = 0; y < fh && top + y < height; y++) {
10337
10347
  const n = Math.min(fw, width - left);
@@ -30409,6 +30419,7 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30409
30419
  }
30410
30420
  const enlarging = W >= SW && H >= SH && (W > SW || H > SH);
30411
30421
  const reducing = W < SW && H < SH;
30422
+ const mixed = W > SW && H < SH || W < SW && H > SH;
30412
30423
  if (enlarging) {
30413
30424
  halftoneDespeckle(rect, SW, SH);
30414
30425
  }
@@ -30417,6 +30428,19 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30417
30428
  }
30418
30429
  const cols = halftoneAxis(0, SW, W, flipX);
30419
30430
  const rows = halftoneAxis(0, SH, H, flipY);
30431
+ if (mixed) {
30432
+ const linear = (taps, src2, dst, reverse) => {
30433
+ if (dst <= src2) return;
30434
+ for (let i = 0; i < dst; i++) {
30435
+ const position = Math.max(0, Math.min(src2 - 1, (i + 0.5) * src2 / dst - 0.5));
30436
+ const left = Math.floor(position), fraction = position - left;
30437
+ const at = (k) => reverse ? src2 - 1 - k : k;
30438
+ taps[i] = [[at(left), 1 - fraction], [at(Math.min(src2 - 1, left + 1)), fraction]];
30439
+ }
30440
+ };
30441
+ linear(cols, SW, W, flipX);
30442
+ linear(rows, SH, H, flipY);
30443
+ }
30420
30444
  const out = new Int32Array(W * H * 3);
30421
30445
  for (let y = 0; y < H; y++) {
30422
30446
  const ys = rows[y];
@@ -30437,14 +30461,27 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30437
30461
  }
30438
30462
  }
30439
30463
  const o = (y * W + x) * 3;
30440
- out[o] = Math.floor((2 * r + total) / (2 * total));
30441
- out[o + 1] = Math.floor((2 * g + total) / (2 * total));
30442
- out[o + 2] = Math.floor((2 * b + total) / (2 * total));
30464
+ out[o] = mixed ? Math.ceil(r / total - 0.5) : Math.floor((2 * r + total) / (2 * total));
30465
+ out[o + 1] = mixed ? Math.ceil(g / total - 0.5) : Math.floor((2 * g + total) / (2 * total));
30466
+ out[o + 2] = mixed ? Math.ceil(b / total - 0.5) : Math.floor((2 * b + total) / (2 * total));
30443
30467
  }
30444
30468
  }
30445
30469
  if (reducing) {
30446
30470
  halftoneSharpen(out, W, H);
30447
30471
  }
30472
+ if (mixed) {
30473
+ const source = out.slice();
30474
+ const at = (x, y, c) => source[(Math.max(0, Math.min(H - 1, y)) * W + Math.max(0, Math.min(W - 1, x))) * 3 + c];
30475
+ for (let y = 0; y < H; y++) {
30476
+ for (let x = 0; x < W; x++) {
30477
+ for (let c = 0; c < 3; c++) {
30478
+ const v = at(x, y, c);
30479
+ const sum = W < SW ? at(x - 1, y, c) + at(x + 1, y, c) : at(x, y - 1, c) + at(x, y + 1, c);
30480
+ out[(y * W + x) * 3 + c] = Math.max(0, Math.min(255, v + Math.floor((2 * v - sum) / 4)));
30481
+ }
30482
+ }
30483
+ }
30484
+ }
30448
30485
  for (let i = 0, o = 0; i < W * H; i++, o += 3) {
30449
30486
  data[i * 4] = out[o];
30450
30487
  data[i * 4 + 1] = out[o + 1];
package/dist/browser.mjs CHANGED
@@ -10330,6 +10330,16 @@ function decodeImageCodecFallback(bytes) {
10330
10330
  if (!f || !validSize(f.image.descriptor.width, f.image.descriptor.height)) return null;
10331
10331
  const frame2 = (0, import_gifuct_js.decompressFrame)(f, gif.gct, true);
10332
10332
  const data = new Uint8ClampedArray(width * height * 4);
10333
+ const transparent = frame2.transparentIndex !== void 0;
10334
+ const background = transparent ? frame2.colorTable[frame2.transparentIndex] : gif.gct?.[gif.lsd.backgroundColorIndex];
10335
+ if (background) {
10336
+ for (let i = 0; i < data.length; i += 4) {
10337
+ data[i] = background[0];
10338
+ data[i + 1] = background[1];
10339
+ data[i + 2] = background[2];
10340
+ data[i + 3] = transparent ? 0 : 255;
10341
+ }
10342
+ }
10333
10343
  const { top, left, width: fw, height: fh } = frame2.dims;
10334
10344
  for (let y = 0; y < fh && top + y < height; y++) {
10335
10345
  const n = Math.min(fw, width - left);
@@ -30407,6 +30417,7 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30407
30417
  }
30408
30418
  const enlarging = W >= SW && H >= SH && (W > SW || H > SH);
30409
30419
  const reducing = W < SW && H < SH;
30420
+ const mixed = W > SW && H < SH || W < SW && H > SH;
30410
30421
  if (enlarging) {
30411
30422
  halftoneDespeckle(rect, SW, SH);
30412
30423
  }
@@ -30415,6 +30426,19 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30415
30426
  }
30416
30427
  const cols = halftoneAxis(0, SW, W, flipX);
30417
30428
  const rows = halftoneAxis(0, SH, H, flipY);
30429
+ if (mixed) {
30430
+ const linear = (taps, src2, dst, reverse) => {
30431
+ if (dst <= src2) return;
30432
+ for (let i = 0; i < dst; i++) {
30433
+ const position = Math.max(0, Math.min(src2 - 1, (i + 0.5) * src2 / dst - 0.5));
30434
+ const left = Math.floor(position), fraction = position - left;
30435
+ const at = (k) => reverse ? src2 - 1 - k : k;
30436
+ taps[i] = [[at(left), 1 - fraction], [at(Math.min(src2 - 1, left + 1)), fraction]];
30437
+ }
30438
+ };
30439
+ linear(cols, SW, W, flipX);
30440
+ linear(rows, SH, H, flipY);
30441
+ }
30418
30442
  const out = new Int32Array(W * H * 3);
30419
30443
  for (let y = 0; y < H; y++) {
30420
30444
  const ys = rows[y];
@@ -30435,14 +30459,27 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30435
30459
  }
30436
30460
  }
30437
30461
  const o = (y * W + x) * 3;
30438
- out[o] = Math.floor((2 * r + total) / (2 * total));
30439
- out[o + 1] = Math.floor((2 * g + total) / (2 * total));
30440
- out[o + 2] = Math.floor((2 * b + total) / (2 * total));
30462
+ out[o] = mixed ? Math.ceil(r / total - 0.5) : Math.floor((2 * r + total) / (2 * total));
30463
+ out[o + 1] = mixed ? Math.ceil(g / total - 0.5) : Math.floor((2 * g + total) / (2 * total));
30464
+ out[o + 2] = mixed ? Math.ceil(b / total - 0.5) : Math.floor((2 * b + total) / (2 * total));
30441
30465
  }
30442
30466
  }
30443
30467
  if (reducing) {
30444
30468
  halftoneSharpen(out, W, H);
30445
30469
  }
30470
+ if (mixed) {
30471
+ const source = out.slice();
30472
+ const at = (x, y, c) => source[(Math.max(0, Math.min(H - 1, y)) * W + Math.max(0, Math.min(W - 1, x))) * 3 + c];
30473
+ for (let y = 0; y < H; y++) {
30474
+ for (let x = 0; x < W; x++) {
30475
+ for (let c = 0; c < 3; c++) {
30476
+ const v = at(x, y, c);
30477
+ const sum = W < SW ? at(x - 1, y, c) + at(x + 1, y, c) : at(x, y - 1, c) + at(x, y + 1, c);
30478
+ out[(y * W + x) * 3 + c] = Math.max(0, Math.min(255, v + Math.floor((2 * v - sum) / 4)));
30479
+ }
30480
+ }
30481
+ }
30482
+ }
30446
30483
  for (let i = 0, o = 0; i < W * H; i++, o += 3) {
30447
30484
  data[i * 4] = out[o];
30448
30485
  data[i * 4 + 1] = out[o + 1];
package/dist/index.js CHANGED
@@ -10332,6 +10332,16 @@ function decodeImageCodecFallback(bytes) {
10332
10332
  if (!f || !validSize(f.image.descriptor.width, f.image.descriptor.height)) return null;
10333
10333
  const frame2 = (0, import_gifuct_js.decompressFrame)(f, gif.gct, true);
10334
10334
  const data = new Uint8ClampedArray(width * height * 4);
10335
+ const transparent = frame2.transparentIndex !== void 0;
10336
+ const background = transparent ? frame2.colorTable[frame2.transparentIndex] : gif.gct?.[gif.lsd.backgroundColorIndex];
10337
+ if (background) {
10338
+ for (let i = 0; i < data.length; i += 4) {
10339
+ data[i] = background[0];
10340
+ data[i + 1] = background[1];
10341
+ data[i + 2] = background[2];
10342
+ data[i + 3] = transparent ? 0 : 255;
10343
+ }
10344
+ }
10335
10345
  const { top, left, width: fw, height: fh } = frame2.dims;
10336
10346
  for (let y = 0; y < fh && top + y < height; y++) {
10337
10347
  const n = Math.min(fw, width - left);
@@ -30410,6 +30420,7 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30410
30420
  }
30411
30421
  const enlarging = W >= SW && H >= SH && (W > SW || H > SH);
30412
30422
  const reducing = W < SW && H < SH;
30423
+ const mixed = W > SW && H < SH || W < SW && H > SH;
30413
30424
  if (enlarging) {
30414
30425
  halftoneDespeckle(rect, SW, SH);
30415
30426
  }
@@ -30418,6 +30429,19 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30418
30429
  }
30419
30430
  const cols = halftoneAxis(0, SW, W, flipX);
30420
30431
  const rows = halftoneAxis(0, SH, H, flipY);
30432
+ if (mixed) {
30433
+ const linear = (taps, src2, dst, reverse) => {
30434
+ if (dst <= src2) return;
30435
+ for (let i = 0; i < dst; i++) {
30436
+ const position = Math.max(0, Math.min(src2 - 1, (i + 0.5) * src2 / dst - 0.5));
30437
+ const left = Math.floor(position), fraction = position - left;
30438
+ const at = (k) => reverse ? src2 - 1 - k : k;
30439
+ taps[i] = [[at(left), 1 - fraction], [at(Math.min(src2 - 1, left + 1)), fraction]];
30440
+ }
30441
+ };
30442
+ linear(cols, SW, W, flipX);
30443
+ linear(rows, SH, H, flipY);
30444
+ }
30421
30445
  const out = new Int32Array(W * H * 3);
30422
30446
  for (let y = 0; y < H; y++) {
30423
30447
  const ys = rows[y];
@@ -30438,14 +30462,27 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30438
30462
  }
30439
30463
  }
30440
30464
  const o = (y * W + x) * 3;
30441
- out[o] = Math.floor((2 * r + total) / (2 * total));
30442
- out[o + 1] = Math.floor((2 * g + total) / (2 * total));
30443
- out[o + 2] = Math.floor((2 * b + total) / (2 * total));
30465
+ out[o] = mixed ? Math.ceil(r / total - 0.5) : Math.floor((2 * r + total) / (2 * total));
30466
+ out[o + 1] = mixed ? Math.ceil(g / total - 0.5) : Math.floor((2 * g + total) / (2 * total));
30467
+ out[o + 2] = mixed ? Math.ceil(b / total - 0.5) : Math.floor((2 * b + total) / (2 * total));
30444
30468
  }
30445
30469
  }
30446
30470
  if (reducing) {
30447
30471
  halftoneSharpen(out, W, H);
30448
30472
  }
30473
+ if (mixed) {
30474
+ const source = out.slice();
30475
+ const at = (x, y, c) => source[(Math.max(0, Math.min(H - 1, y)) * W + Math.max(0, Math.min(W - 1, x))) * 3 + c];
30476
+ for (let y = 0; y < H; y++) {
30477
+ for (let x = 0; x < W; x++) {
30478
+ for (let c = 0; c < 3; c++) {
30479
+ const v = at(x, y, c);
30480
+ const sum = W < SW ? at(x - 1, y, c) + at(x + 1, y, c) : at(x, y - 1, c) + at(x, y + 1, c);
30481
+ out[(y * W + x) * 3 + c] = Math.max(0, Math.min(255, v + Math.floor((2 * v - sum) / 4)));
30482
+ }
30483
+ }
30484
+ }
30485
+ }
30449
30486
  for (let i = 0, o = 0; i < W * H; i++, o += 3) {
30450
30487
  data[i * 4] = out[o];
30451
30488
  data[i * 4 + 1] = out[o + 1];
package/dist/index.mjs CHANGED
@@ -10330,6 +10330,16 @@ function decodeImageCodecFallback(bytes) {
10330
10330
  if (!f || !validSize(f.image.descriptor.width, f.image.descriptor.height)) return null;
10331
10331
  const frame2 = (0, import_gifuct_js.decompressFrame)(f, gif.gct, true);
10332
10332
  const data = new Uint8ClampedArray(width * height * 4);
10333
+ const transparent = frame2.transparentIndex !== void 0;
10334
+ const background = transparent ? frame2.colorTable[frame2.transparentIndex] : gif.gct?.[gif.lsd.backgroundColorIndex];
10335
+ if (background) {
10336
+ for (let i = 0; i < data.length; i += 4) {
10337
+ data[i] = background[0];
10338
+ data[i + 1] = background[1];
10339
+ data[i + 2] = background[2];
10340
+ data[i + 3] = transparent ? 0 : 255;
10341
+ }
10342
+ }
10333
10343
  const { top, left, width: fw, height: fh } = frame2.dims;
10334
10344
  for (let y = 0; y < fh && top + y < height; y++) {
10335
10345
  const n = Math.min(fw, width - left);
@@ -30408,6 +30418,7 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30408
30418
  }
30409
30419
  const enlarging = W >= SW && H >= SH && (W > SW || H > SH);
30410
30420
  const reducing = W < SW && H < SH;
30421
+ const mixed = W > SW && H < SH || W < SW && H > SH;
30411
30422
  if (enlarging) {
30412
30423
  halftoneDespeckle(rect, SW, SH);
30413
30424
  }
@@ -30416,6 +30427,19 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30416
30427
  }
30417
30428
  const cols = halftoneAxis(0, SW, W, flipX);
30418
30429
  const rows = halftoneAxis(0, SH, H, flipY);
30430
+ if (mixed) {
30431
+ const linear = (taps, src2, dst, reverse) => {
30432
+ if (dst <= src2) return;
30433
+ for (let i = 0; i < dst; i++) {
30434
+ const position = Math.max(0, Math.min(src2 - 1, (i + 0.5) * src2 / dst - 0.5));
30435
+ const left = Math.floor(position), fraction = position - left;
30436
+ const at = (k) => reverse ? src2 - 1 - k : k;
30437
+ taps[i] = [[at(left), 1 - fraction], [at(Math.min(src2 - 1, left + 1)), fraction]];
30438
+ }
30439
+ };
30440
+ linear(cols, SW, W, flipX);
30441
+ linear(rows, SH, H, flipY);
30442
+ }
30419
30443
  const out = new Int32Array(W * H * 3);
30420
30444
  for (let y = 0; y < H; y++) {
30421
30445
  const ys = rows[y];
@@ -30436,14 +30460,27 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30436
30460
  }
30437
30461
  }
30438
30462
  const o = (y * W + x) * 3;
30439
- out[o] = Math.floor((2 * r + total) / (2 * total));
30440
- out[o + 1] = Math.floor((2 * g + total) / (2 * total));
30441
- out[o + 2] = Math.floor((2 * b + total) / (2 * total));
30463
+ out[o] = mixed ? Math.ceil(r / total - 0.5) : Math.floor((2 * r + total) / (2 * total));
30464
+ out[o + 1] = mixed ? Math.ceil(g / total - 0.5) : Math.floor((2 * g + total) / (2 * total));
30465
+ out[o + 2] = mixed ? Math.ceil(b / total - 0.5) : Math.floor((2 * b + total) / (2 * total));
30442
30466
  }
30443
30467
  }
30444
30468
  if (reducing) {
30445
30469
  halftoneSharpen(out, W, H);
30446
30470
  }
30471
+ if (mixed) {
30472
+ const source = out.slice();
30473
+ const at = (x, y, c) => source[(Math.max(0, Math.min(H - 1, y)) * W + Math.max(0, Math.min(W - 1, x))) * 3 + c];
30474
+ for (let y = 0; y < H; y++) {
30475
+ for (let x = 0; x < W; x++) {
30476
+ for (let c = 0; c < 3; c++) {
30477
+ const v = at(x, y, c);
30478
+ const sum = W < SW ? at(x - 1, y, c) + at(x + 1, y, c) : at(x, y - 1, c) + at(x, y + 1, c);
30479
+ out[(y * W + x) * 3 + c] = Math.max(0, Math.min(255, v + Math.floor((2 * v - sum) / 4)));
30480
+ }
30481
+ }
30482
+ }
30483
+ }
30447
30484
  for (let i = 0, o = 0; i < W * H; i++, o += 3) {
30448
30485
  data[i * 4] = out[o];
30449
30486
  data[i * 4 + 1] = out[o + 1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emf-converter",
3
- "version": "4.4.1",
3
+ "version": "4.4.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",