PHP 7.4.33
Preview: blur.js Size: 3.99 KB
/var/www/sitesecurity.bitkit.dk/httpdocs/node_modules/d3-array/src/blur.js
export function blur(values, r) {
  if (!((r = +r) >= 0)) throw new RangeError("invalid r");
  let length = values.length;
  if (!((length = Math.floor(length)) >= 0)) throw new RangeError("invalid length");
  if (!length || !r) return values;
  const blur = blurf(r);
  const temp = values.slice();
  blur(values, temp, 0, length, 1);
  blur(temp, values, 0, length, 1);
  blur(values, temp, 0, length, 1);
  return values;
}

export const blur2 = Blur2(blurf);

export const blurImage = Blur2(blurfImage);

function Blur2(blur) {
  return function(data, rx, ry = rx) {
    if (!((rx = +rx) >= 0)) throw new RangeError("invalid rx");
    if (!((ry = +ry) >= 0)) throw new RangeError("invalid ry");
    let {data: values, width, height} = data;
    if (!((width = Math.floor(width)) >= 0)) throw new RangeError("invalid width");
    if (!((height = Math.floor(height !== undefined ? height : values.length / width)) >= 0)) throw new RangeError("invalid height");
    if (!width || !height || (!rx && !ry)) return data;
    const blurx = rx && blur(rx);
    const blury = ry && blur(ry);
    const temp = values.slice();
    if (blurx && blury) {
      blurh(blurx, temp, values, width, height);
      blurh(blurx, values, temp, width, height);
      blurh(blurx, temp, values, width, height);
      blurv(blury, values, temp, width, height);
      blurv(blury, temp, values, width, height);
      blurv(blury, values, temp, width, height);
    } else if (blurx) {
      blurh(blurx, values, temp, width, height);
      blurh(blurx, temp, values, width, height);
      blurh(blurx, values, temp, width, height);
    } else if (blury) {
      blurv(blury, values, temp, width, height);
      blurv(blury, temp, values, width, height);
      blurv(blury, values, temp, width, height);
    }
    return data;
  };
}

function blurh(blur, T, S, w, h) {
  for (let y = 0, n = w * h; y < n;) {
    blur(T, S, y, y += w, 1);
  }
}

function blurv(blur, T, S, w, h) {
  for (let x = 0, n = w * h; x < w; ++x) {
    blur(T, S, x, x + n, w);
  }
}

function blurfImage(radius) {
  const blur = blurf(radius);
  return (T, S, start, stop, step) => {
    start <<= 2, stop <<= 2, step <<= 2;
    blur(T, S, start + 0, stop + 0, step);
    blur(T, S, start + 1, stop + 1, step);
    blur(T, S, start + 2, stop + 2, step);
    blur(T, S, start + 3, stop + 3, step);
  };
}

// Given a target array T, a source array S, sets each value T[i] to the average
// of {S[i - r], …, S[i], …, S[i + r]}, where r = ⌊radius⌋, start <= i < stop,
// for each i, i + step, i + 2 * step, etc., and where S[j] is clamped between
// S[start] (inclusive) and S[stop] (exclusive). If the given radius is not an
// integer, S[i - r - 1] and S[i + r + 1] are added to the sum, each weighted
// according to r - ⌊radius⌋.
function blurf(radius) {
  const radius0 = Math.floor(radius);
  if (radius0 === radius) return bluri(radius);
  const t = radius - radius0;
  const w = 2 * radius + 1;
  return (T, S, start, stop, step) => { // stop must be aligned!
    if (!((stop -= step) >= start)) return; // inclusive stop
    let sum = radius0 * S[start];
    const s0 = step * radius0;
    const s1 = s0 + step;
    for (let i = start, j = start + s0; i < j; i += step) {
      sum += S[Math.min(stop, i)];
    }
    for (let i = start, j = stop; i <= j; i += step) {
      sum += S[Math.min(stop, i + s0)];
      T[i] = (sum + t * (S[Math.max(start, i - s1)] + S[Math.min(stop, i + s1)])) / w;
      sum -= S[Math.max(start, i - s0)];
    }
  };
}

// Like blurf, but optimized for integer radius.
function bluri(radius) {
  const w = 2 * radius + 1;
  return (T, S, start, stop, step) => { // stop must be aligned!
    if (!((stop -= step) >= start)) return; // inclusive stop
    let sum = radius * S[start];
    const s = step * radius;
    for (let i = start, j = start + s; i < j; i += step) {
      sum += S[Math.min(stop, i)];
    }
    for (let i = start, j = stop; i <= j; i += step) {
      sum += S[Math.min(stop, i + s)];
      T[i] = sum / w;
      sum -= S[Math.max(start, i - s)];
    }
  };
}

Directory Contents

Dirs: 1 × Files: 58
Name Size Perms Modified Actions
threshold DIR
- drwxr-xr-x 2026-04-28 09:11:40
Edit Download
90 B lrw-r--r-- 2026-04-28 09:11:39
Edit Download
127 B lrw-r--r-- 2026-04-28 09:11:39
Edit Download
3.96 KB lrw-r--r-- 2026-04-28 09:11:39
Edit Download
337 B lrw-r--r-- 2026-04-28 09:11:39
Edit Download
1.53 KB lrw-r--r-- 2026-04-28 09:11:39
Edit Download
3.99 KB lrw-r--r-- 2026-04-28 09:11:39
Edit Download
58 B lrw-r--r-- 2026-04-28 09:11:39
Edit Download
424 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
872 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
218 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
144 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
164 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
250 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
404 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
265 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
723 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
291 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.56 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
675 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
470 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.68 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
429 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
52 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.99 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
446 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
672 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
467 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
310 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
502 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
582 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
483 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
245 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
165 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
502 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
582 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
708 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
535 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
465 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
307 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
97 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.73 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.52 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
350 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
942 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
460 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
183 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
178 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
329 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
263 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.22 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
123 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
362 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
530 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.91 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
369 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
217 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
668 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
106 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).