@xprite/pixelate 0.2.0 → 0.2.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/deskew.js +28 -15
- package/dist/fft-autocorr.d.ts +12 -0
- package/dist/fft-autocorr.js +116 -0
- package/dist/grid-arbitrate.d.ts +8 -0
- package/dist/grid-arbitrate.js +227 -66
- package/dist/grid-cut-snap.js +2 -38
- package/dist/grid-description-length.js +416 -111
- package/dist/grid-edge-coherence.js +4 -46
- package/dist/grid-edge-path.js +2 -33
- package/dist/grid-frame-lattice.js +109 -14
- package/dist/grid-period-comb.js +126 -22
- package/dist/grid-period-distance.js +59 -10
- package/dist/grid-phase-field.js +128 -48
- package/dist/grid-pitch-lattice.js +21 -9
- package/dist/grid-pitch-search.js +38 -18
- package/dist/grid-sampling.d.ts +6 -0
- package/dist/grid-sampling.js +111 -10
- package/dist/grid-step-profiles.d.ts +13 -0
- package/dist/grid-step-profiles.js +88 -0
- package/dist/grid-strip-shift.js +153 -35
- package/package.json +1 -1
package/dist/grid-cut-snap.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { imageStepProfiles } from "./grid-step-profiles.js";
|
|
1
2
|
/**
|
|
2
3
|
* A lattice whose cuts each moved to the strongest colour step within `radius` pixels: the cell
|
|
3
4
|
* count of a regular grid with the cut positions of the raster that rounded it. A cut with no
|
|
@@ -5,48 +6,11 @@
|
|
|
5
6
|
* where the cell before it stays within CELL_SPREAD of the pitch, so a strong edge inside a cell
|
|
6
7
|
* (a highlight, an outline) cannot squeeze one cell and stretch the next.
|
|
7
8
|
*/
|
|
8
|
-
const CHANNELS = 3;
|
|
9
|
-
const STRIDE = 4;
|
|
10
|
-
const ALPHA_CHANNEL = 3;
|
|
11
|
-
const ALPHA_SCALE = 255;
|
|
12
9
|
/** Share of a cell a cut may move. */
|
|
13
10
|
const SNAP_SHARE = 0.25;
|
|
14
11
|
/** Share of the pitch a snapped cell may differ from it. */
|
|
15
12
|
const CELL_SPREAD = 0.25;
|
|
16
13
|
const NO_STEP = -1;
|
|
17
|
-
/**
|
|
18
|
-
* Colour step between each pixel column (or row) and the one before it, summed along the line, on
|
|
19
|
-
* premultiplied colour and alpha: a clear pixel's hidden colour (a removed background) is no edge.
|
|
20
|
-
*/
|
|
21
|
-
function computeStepProfile(image, horizontal) {
|
|
22
|
-
const { width, height, data } = image;
|
|
23
|
-
const length = horizontal ? width : height;
|
|
24
|
-
const profile = new Float64Array(length);
|
|
25
|
-
for (let y = 0; y < height; y++)
|
|
26
|
-
for (let x = 0; x < width; x++) {
|
|
27
|
-
const along = horizontal ? x : y;
|
|
28
|
-
if (along === 0)
|
|
29
|
-
continue;
|
|
30
|
-
const o = (y * width + x) * STRIDE;
|
|
31
|
-
const p = horizontal ? o - STRIDE : o - width * STRIDE;
|
|
32
|
-
const a = data[o + ALPHA_CHANNEL] / ALPHA_SCALE, b = data[p + ALPHA_CHANNEL] / ALPHA_SCALE;
|
|
33
|
-
let step = Math.abs(data[o + ALPHA_CHANNEL] - data[p + ALPHA_CHANNEL]);
|
|
34
|
-
for (let c = 0; c < CHANNELS; c++)
|
|
35
|
-
step += Math.abs(data[o + c] * a - data[p + c] * b);
|
|
36
|
-
profile[along] += step;
|
|
37
|
-
}
|
|
38
|
-
return profile;
|
|
39
|
-
}
|
|
40
|
-
/** Every reading of one image snaps against the same profiles. */
|
|
41
|
-
const profiles = new WeakMap();
|
|
42
|
-
function stepProfiles(image) {
|
|
43
|
-
let cached = profiles.get(image);
|
|
44
|
-
if (!cached) {
|
|
45
|
-
cached = { x: computeStepProfile(image, true), y: computeStepProfile(image, false) };
|
|
46
|
-
profiles.set(image, cached);
|
|
47
|
-
}
|
|
48
|
-
return cached;
|
|
49
|
-
}
|
|
50
14
|
function snapAxis(profile, cuts, avoid) {
|
|
51
15
|
const cells = cuts.length - 1;
|
|
52
16
|
const pitch = (cuts[cells] - cuts[0]) / cells;
|
|
@@ -69,7 +33,7 @@ function snapAxis(profile, cuts, avoid) {
|
|
|
69
33
|
return { cuts: snapped, radius };
|
|
70
34
|
}
|
|
71
35
|
export function snapLatticeCuts(image, cutsX, cutsY, avoid = { x: [], y: [] }) {
|
|
72
|
-
const profile =
|
|
36
|
+
const profile = imageStepProfiles(image);
|
|
73
37
|
return {
|
|
74
38
|
x: snapAxis(profile.x, cutsX, avoid.x),
|
|
75
39
|
y: snapAxis(profile.y, cutsY, avoid.y),
|