Comparing version 1.1.0 to 1.2.0
@@ -1,2 +0,2 @@ | ||
// https://github.com/fil/array-blur v1.1.0 Copyright 2020 Fil | ||
// https://github.com/fil/array-blur v1.2.0 Copyright 2021 Fil | ||
(function (global, factory) { | ||
@@ -14,2 +14,6 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
function arrayify(values) { | ||
return typeof values !== "object" || "length" in values ? values : Array.from(values); | ||
} | ||
function blurTransfer(V, r, n, vertical) { | ||
@@ -73,13 +77,13 @@ if (!r) return; // radius 0 is a noop | ||
function blur(data) { | ||
const n = width || data.length; | ||
const m = Math.round(data.length / n); | ||
// reuse the V arrays if possible | ||
if (!value && V[0] && V[0].length === data.length) { | ||
V[0].set(data); | ||
if (value || !V[0] || V[0].length !== data.length) { | ||
V[0] = value ? Float32Array.from(data, value) : Float32Array.from(data); | ||
V[1] = new Float32Array(V[0].length); | ||
} else { | ||
V[0] = value ? Float32Array.from(data, value) : Float32Array.from(data); | ||
V[1] = new Float32Array(data.length); | ||
V[0].set(arrayify(data)); | ||
} | ||
const n = width || V[0].length; | ||
const m = Math.round(V[0].length / n); | ||
blurTransfer(V, rx, n, false); | ||
@@ -86,0 +90,0 @@ blurTransfer(V, ry, m, true); |
@@ -1,2 +0,2 @@ | ||
// https://github.com/fil/array-blur v1.1.0 Copyright 2020 Fil | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).d3=t.d3||{})}(this,(function(t){"use strict";const e=Math.floor,o=Math.max,n=Math.min;function r(t,e,o,n){if(!e)return;const r=Math.floor(e);if(e===r)for(let r=0;r<3;r++)f(t,e,o,n);else{const i=e-r,l=1-i,s=t[0].slice();for(let e=0;e<3;e++)f(t,r+1,o,n);const d=t[0];if(t[0]=s,r>0)for(let e=0;e<3;e++)f(t,r,o,n);for(let e=0;e<s.length;e++)t[0][e]=t[0][e]*l+d[e]*i}}function f(t,r,f,i){const[l,s]=t,d=e(l.length/f),u=2*r+1,a=1/u,c=i?d:1,h=i?1:f,g=u*c,p=r*c;for(let t=0;t<d;++t){const e=h*t,i=e+c*(f-1);for(let d=0,y=u*l[e];d<f+r;++d){const r=c*d+h*t;y+=l[n(r,i)]-l[o(r-g,e)],s[o(r-p,e)]=y*a}}t.reverse()}t.blur=function(){let t,e,o=5,n=o;const f=[];function i(i){const l=e||i.length,s=Math.round(i.length/l);return!t&&f[0]&&f[0].length===i.length?f[0].set(i):(f[0]=t?Float32Array.from(i,t):Float32Array.from(i),f[1]=new Float32Array(i.length)),r(f,o,l,!1),r(f,n,s,!0),f[0].width=l,f[0].height=s,f[0]}return i.radius=t=>void 0===t?(o+n)/2:(o=n=+t,i),i.radiusX=t=>void 0===t?o:(o=+t,i),i.radiusY=t=>void 0===t?n:(n=+t,i),i.width=t=>void 0===t?e:(e=Math.round(+t),i),i.value=e=>"function"==typeof e?(t=e,i):t,i},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
// https://github.com/fil/array-blur v1.2.0 Copyright 2021 Fil | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).d3=t.d3||{})}(this,(function(t){"use strict";const e=Math.floor,o=Math.max,n=Math.min;function r(t,e,o,n){if(!e)return;const r=Math.floor(e);if(e===r)for(let r=0;r<3;r++)f(t,e,o,n);else{const i=e-r,l=1-i,s=t[0].slice();for(let e=0;e<3;e++)f(t,r+1,o,n);const d=t[0];if(t[0]=s,r>0)for(let e=0;e<3;e++)f(t,r,o,n);for(let e=0;e<s.length;e++)t[0][e]=t[0][e]*l+d[e]*i}}function f(t,r,f,i){const[l,s]=t,d=e(l.length/f),u=2*r+1,a=1/u,c=i?d:1,h=i?1:f,g=u*c,y=r*c;for(let t=0;t<d;++t){const e=h*t,i=e+c*(f-1);for(let d=0,p=u*l[e];d<f+r;++d){const r=c*d+h*t;p+=l[n(r,i)]-l[o(r-g,e)],s[o(r-y,e)]=p*a}}t.reverse()}t.blur=function(){let t,e,o=5,n=o;const f=[];function i(i){var l;t||!f[0]||f[0].length!==i.length?(f[0]=t?Float32Array.from(i,t):Float32Array.from(i),f[1]=new Float32Array(f[0].length)):f[0].set("object"!=typeof(l=i)||"length"in l?l:Array.from(l));const s=e||f[0].length,d=Math.round(f[0].length/s);return r(f,o,s,!1),r(f,n,d,!0),f[0].width=s,f[0].height=d,f[0]}return i.radius=t=>void 0===t?(o+n)/2:(o=n=+t,i),i.radiusX=t=>void 0===t?o:(o=+t,i),i.radiusY=t=>void 0===t?n:(n=+t,i),i.width=t=>void 0===t?e:(e=Math.round(+t),i),i.value=e=>"function"==typeof e?(t=e,i):t,i},Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "array-blur", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Array & image blurring.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -20,11 +20,11 @@ # array-blur | ||
Creates a blur transformer, which can blur (or smooth) an *array* of values by three iterations of a moving average transform. | ||
Creates a blur transformer, which can blur (or smooth) an *iterable* by three iterations of a moving average transform. | ||
<a name="blur_radius" href="#blur_radius">#</a> *blur*.<b>radius</b>([*radius*]) | ||
If *radius* is specified, sets the radius of the transformation: on each iteration, the value of a point is transformed into the mean value of itself and the *radius* points of data surrounding it on the left and on the right (taking into account the edges). If *radius* is not specified, return the current radius (if horizontal and vertical radii have been set separately, returns their average value). If *radius* is not an integer value, the blurring is applied partially. Defaults to 5. | ||
If *radius* is specified, sets the radius of the transformation: on each iteration, the value of a point is transformed into the mean value of itself and the *radius* points of data surrounding it on the left and on the right (taking into account the edges). If *radius* is not specified, returns the current radius (if horizontal and vertical radii have been set separately, returns their average value). If *radius* is not an integer value, the blurring is applied partially. Defaults to 5. | ||
<a name="blur_value" href="#blur_value">#</a> *blur*.<b>value</b>([*value*]) | ||
If *value* is specified, sets the *value* accessor, which will read the *array*. If not specified, return the current number. Defaults to the special *null* accessor, which copies the values directly (faster than an identity function). | ||
If *value* is specified, sets the *value* accessor, which will read the values of the *iterator*. If not specified, returns the current number. Defaults to the special *null* accessor, which copies the values directly (faster than an identity function). | ||
@@ -31,0 +31,0 @@ Example: |
import {floor, max, min} from "./math.js"; | ||
import {arrayify} from "./utils.js"; | ||
@@ -61,13 +62,13 @@ function blurTransfer(V, r, n, vertical) { | ||
function blur(data) { | ||
const n = width || data.length; | ||
const m = Math.round(data.length / n); | ||
// reuse the V arrays if possible | ||
if (!value && V[0] && V[0].length === data.length) { | ||
V[0].set(data); | ||
if (value || !V[0] || V[0].length !== data.length) { | ||
V[0] = value ? Float32Array.from(data, value) : Float32Array.from(data); | ||
V[1] = new Float32Array(V[0].length); | ||
} else { | ||
V[0] = value ? Float32Array.from(data, value) : Float32Array.from(data); | ||
V[1] = new Float32Array(data.length); | ||
V[0].set(arrayify(data)); | ||
} | ||
const n = width || V[0].length; | ||
const m = Math.round(V[0].length / n); | ||
blurTransfer(V, rx, n, false); | ||
@@ -74,0 +75,0 @@ blurTransfer(V, ry, m, true); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12448
9
193