@poe-platform/safe-bash 0.1.837 → 0.1.839

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.
@@ -875,9 +875,10 @@ function* warpPixelSteps(source, plan, background) {
875
875
  }
876
876
 
877
877
  // packages/safe-bash-command-imagemagick/src/morphology-kernel.ts
878
- function* morphologyPixelSteps(image, rx, ry, mode) {
878
+ function* morphologyPixelSteps(image, rows, mode) {
879
879
  const { width, height } = image, histogram = new Float64Array(4 * 256);
880
- const rank = Math.floor((rx * 2 + 1) * (ry * 2 + 1) / 2);
880
+ const ry = Math.floor(rows.length / 2);
881
+ const rank = Math.floor(rows.reduce((total, radius) => total + radius * 2 + 1, 0) / 2);
881
882
  let work = 0;
882
883
  for (let y = 0; y < height; y++) {
883
884
  yield;
@@ -887,14 +888,18 @@ function* morphologyPixelSteps(image, rx, ry, mode) {
887
888
  for (let local = 0; local < count; local++) {
888
889
  const x = left + local;
889
890
  for (let phase = 0; phase < (x === 0 ? 1 : 2); phase++) {
890
- const first = x === 0 ? -rx : phase === 0 ? x - rx - 1 : x + rx;
891
- const last = x === 0 ? rx : first, delta = x === 0 || phase === 1 ? 1 : -1;
892
- for (let dy = -ry; dy <= ry; dy++) for (let column = first; column <= last; column++) {
893
- if (++work % 4096 === 0) yield;
894
- const sx = Math.max(0, Math.min(width - 1, column)), sy = Math.max(0, Math.min(height - 1, y + dy));
895
- const bytes = yield { kind: "read", position: (sy * width + sx) * 4, length: 4 };
896
- if (!bytes || bytes.length !== 4) throw new Error("Truncated morphology pixels");
897
- for (let c = 0; c < 4; c++) histogram[c * 256 + bytes[c]] += delta;
891
+ const delta = x === 0 || phase === 1 ? 1 : -1;
892
+ for (let dy = -ry; dy <= ry; dy++) {
893
+ const rx = rows[dy + ry];
894
+ const first = x === 0 ? -rx : phase === 0 ? x - rx - 1 : x + rx;
895
+ const last = x === 0 ? rx : first;
896
+ for (let column = first; column <= last; column++) {
897
+ if (++work % 4096 === 0) yield;
898
+ const sx = Math.max(0, Math.min(width - 1, column)), sy = Math.max(0, Math.min(height - 1, y + dy));
899
+ const bytes = yield { kind: "read", position: (sy * width + sx) * 4, length: 4 };
900
+ if (!bytes || bytes.length !== 4) throw new Error("Truncated morphology pixels");
901
+ for (let c = 0; c < 4; c++) histogram[c * 256 + bytes[c]] += delta;
902
+ }
898
903
  }
899
904
  }
900
905
  for (let c = 0; c < 4; c++) {
@@ -2001,6 +2006,10 @@ function magickMorphologyPlan(methodRaw, kernelSpec) {
2001
2006
  rx = Math.max(1, Math.round(Number(sizePart)));
2002
2007
  ry = rx;
2003
2008
  }
2009
+ const disk = (colonIdx < 0 ? kernelSpec : kernelSpec.slice(0, colonIdx)).toLowerCase() === "disk";
2010
+ const radius = Number(sizePart) || 4.5;
2011
+ if (disk) ry = Math.max(0, Math.floor(radius));
2012
+ const rows = Array.from({ length: ry * 2 + 1 }, (_, row) => disk ? Math.floor(Math.sqrt(radius * radius - (row - ry) ** 2)) : rx);
2004
2013
  const filter = (source, mode) => ({ source, mode });
2005
2014
  const diff = (a, b) => ({ mode: "diff", a, b });
2006
2015
  let steps;
@@ -2037,7 +2046,7 @@ function magickMorphologyPlan(methodRaw, kernelSpec) {
2037
2046
  default:
2038
2047
  steps = [filter(0, "max")];
2039
2048
  }
2040
- return { rx, ry, steps };
2049
+ return { rows, steps };
2041
2050
  }
2042
2051
  function* subtractMagickPixelSteps(a, b) {
2043
2052
  const result = new Uint8Array(a.length);
@@ -2055,7 +2064,7 @@ function* applyMagickMorphology4ChSteps(img, methodRaw, kernelSpec, signal) {
2055
2064
  images.push({ ...a, data: yield* subtractMagickPixelSteps(a.data, b.data) });
2056
2065
  } else {
2057
2066
  const source = images[step.source];
2058
- images.push(yield* applyMagickRasterSteps(source, morphologyPixelSteps(source, plan.rx, plan.ry, step.mode), signal));
2067
+ images.push(yield* applyMagickRasterSteps(source, morphologyPixelSteps(source, plan.rows, step.mode), signal));
2059
2068
  }
2060
2069
  }
2061
2070
  return images.at(-1);
@@ -6227,7 +6236,7 @@ async function morphStoredMagickImage(image, backend, plan, signal) {
6227
6236
  images.push({ ...image, position });
6228
6237
  } else {
6229
6238
  const source = images[step.source];
6230
- images.push(await transformStoredMagickRaster(source, backend, morphologyPixelSteps(source, plan.rx, plan.ry, step.mode), signal));
6239
+ images.push(await transformStoredMagickRaster(source, backend, morphologyPixelSteps(source, plan.rows, step.mode), signal));
6231
6240
  }
6232
6241
  }
6233
6242
  return images.at(-1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poe-platform/safe-bash",
3
- "version": "0.1.837",
3
+ "version": "0.1.839",
4
4
  "description": "Extensible virtual shell with pluggable filesystems and streaming commands",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1415,7 +1415,7 @@
1415
1415
  "access": "public"
1416
1416
  },
1417
1417
  "dependencies": {
1418
- "@poe-platform/safe-fs": "0.1.837",
1418
+ "@poe-platform/safe-fs": "0.1.839",
1419
1419
  "pdf-lib": "1.17.1",
1420
1420
  "@types/node": "^25.2.2",
1421
1421
  "@formatjs/intl-numberformat": "9.4.0",