@richardmcquiston01/core-image 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +30 -2
- package/dist/filters/dither.d.ts +35 -0
- package/dist/filters/dither.d.ts.map +1 -0
- package/dist/filters/dither.js +228 -0
- package/dist/filters/dither.js.map +1 -0
- package/dist/filters/edge-morphology.d.ts +61 -0
- package/dist/filters/edge-morphology.d.ts.map +1 -0
- package/dist/filters/edge-morphology.js +368 -0
- package/dist/filters/edge-morphology.js.map +1 -0
- package/dist/filters/index.d.ts +31 -0
- package/dist/filters/index.d.ts.map +1 -0
- package/dist/filters/index.js +131 -0
- package/dist/filters/index.js.map +1 -0
- package/dist/filters/testgrid.d.ts +20 -0
- package/dist/filters/testgrid.d.ts.map +1 -0
- package/dist/filters/testgrid.js +91 -0
- package/dist/filters/testgrid.js.map +1 -0
- package/dist/filters/tone.d.ts +32 -0
- package/dist/filters/tone.d.ts.map +1 -0
- package/dist/filters/tone.js +134 -0
- package/dist/filters/tone.js.map +1 -0
- package/dist/filters/transform.d.ts +20 -0
- package/dist/filters/transform.d.ts.map +1 -0
- package/dist/filters/transform.js +117 -0
- package/dist/filters/transform.js.map +1 -0
- package/dist/heightmap.d.ts +29 -0
- package/dist/heightmap.d.ts.map +1 -0
- package/dist/heightmap.js +146 -0
- package/dist/heightmap.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/io.d.ts +6 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +43 -0
- package/dist/io.js.map +1 -0
- package/dist/pixel.d.ts +6 -0
- package/dist/pixel.d.ts.map +1 -0
- package/dist/pixel.js +31 -0
- package/dist/pixel.js.map +1 -0
- package/dist/registry.d.ts +16 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +34 -0
- package/dist/registry.js.map +1 -0
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Richard McQuiston
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @richardmcquiston01/core-image
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Image processing core for laser, CNC and other maker-machine workflows: a filter registry (dithering, tone, edge/morphology, transforms, test grids), image I/O helpers, and grayscale heightmap-to-STL conversion.
|
|
4
|
+
|
|
5
|
+
Part of [maker-image-tools](https://github.com/RichardMcQuiston01/maker-image-tools).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i @richardmcquiston01/core-image
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
createFilterRegistry,
|
|
18
|
+
imageToHeightmapStl,
|
|
19
|
+
loadImageData,
|
|
20
|
+
} from "@richardmcquiston01/core-image";
|
|
21
|
+
|
|
22
|
+
const image: ImageData = await loadImageData(blob);
|
|
23
|
+
const registry = createFilterRegistry();
|
|
24
|
+
const stl: string = imageToHeightmapStl(image);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Requires an environment with `ImageData` (browser, or a polyfill in Node). ESM only.
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
MIT
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Filter, FilterOptions } from "../types.js";
|
|
2
|
+
/** Options shared by every error-diffusion dithering filter. */
|
|
3
|
+
export interface DitherOptions extends FilterOptions {
|
|
4
|
+
/** Grayscale cutoff (0-255) above which a pixel is quantized to white. Defaults to 128. */
|
|
5
|
+
threshold?: number;
|
|
6
|
+
}
|
|
7
|
+
/** Options for Bayer (ordered) dithering. */
|
|
8
|
+
export interface BayerDitherOptions extends FilterOptions {
|
|
9
|
+
/** Size of the (square) Bayer matrix. Defaults to 4. */
|
|
10
|
+
matrixSize?: 2 | 4 | 8;
|
|
11
|
+
}
|
|
12
|
+
/** Options for blue-noise (ordered) dithering. Currently no tunable fields. */
|
|
13
|
+
export type BlueNoiseDitherOptions = FilterOptions;
|
|
14
|
+
/** Floyd-Steinberg error-diffusion dithering (Floyd & Steinberg, 1976). */
|
|
15
|
+
export declare const ditherFloydSteinberg: Filter<DitherOptions>;
|
|
16
|
+
/** Atkinson dithering (Bill Atkinson, Apple). Only diffuses 6/8 of the error,
|
|
17
|
+
* which intentionally clips instead of fully spreading it, giving higher local contrast. */
|
|
18
|
+
export declare const ditherAtkinson: Filter<DitherOptions>;
|
|
19
|
+
/** Jarvis, Judice & Ninke error-diffusion dithering (1976). */
|
|
20
|
+
export declare const ditherJarvisJudiceNinke: Filter<DitherOptions>;
|
|
21
|
+
/** Stucki error-diffusion dithering (1981). */
|
|
22
|
+
export declare const ditherStucki: Filter<DitherOptions>;
|
|
23
|
+
/** Sierra error-diffusion dithering (Frankie Sierra). */
|
|
24
|
+
export declare const ditherSierra: Filter<DitherOptions>;
|
|
25
|
+
/** Burkes error-diffusion dithering (Daniel Burkes, 1988). */
|
|
26
|
+
export declare const ditherBurkes: Filter<DitherOptions>;
|
|
27
|
+
/** Bayer ordered dithering: compares each pixel against a tiled NxN threshold matrix. */
|
|
28
|
+
export declare const ditherBayer: Filter<BayerDitherOptions>;
|
|
29
|
+
/**
|
|
30
|
+
* Blue-noise ordered dithering using Interleaved Gradient Noise (IGN) as a
|
|
31
|
+
* cheap, real-time-graphics approximation of a true blue-noise texture --
|
|
32
|
+
* this is not a void-and-cluster blue-noise dither, just visually similar.
|
|
33
|
+
*/
|
|
34
|
+
export declare const ditherBlueNoise: Filter<BlueNoiseDitherOptions>;
|
|
35
|
+
//# sourceMappingURL=dither.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dither.d.ts","sourceRoot":"","sources":["../../src/filters/dither.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGzD,gEAAgE;AAChE,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD,2FAA2F;IAC3F,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,6CAA6C;AAC7C,MAAM,WAAW,kBAAmB,SAAQ,aAAa;IACvD,wDAAwD;IACxD,UAAU,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACxB;AAED,+EAA+E;AAC/E,MAAM,MAAM,sBAAsB,GAAG,aAAa,CAAC;AAgGnD,2EAA2E;AAC3E,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,aAAa,CAGtD,CAAC;AAWF;4FAC4F;AAC5F,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,aAAa,CAGhD,CAAC;AAiBF,+DAA+D;AAC/D,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,aAAa,CAGzD,CAAC;AAiBF,+CAA+C;AAC/C,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,aAAa,CAG9C,CAAC;AAeF,yDAAyD;AACzD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,aAAa,CAG9C,CAAC;AAYF,8DAA8D;AAC9D,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,aAAa,CAG9C,CAAC;AAoCF,yFAAyF;AACzF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,kBAAkB,CAmBlD,CAAC;AAMF;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,sBAAsB,CAiB1D,CAAC"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { createImageData, getPixel } from "../pixel.js";
|
|
2
|
+
const DEFAULT_THRESHOLD = 128;
|
|
3
|
+
/** Builds a kernel of normalized weights from integer numerators and a shared divisor. */
|
|
4
|
+
function buildKernel(divisor, taps) {
|
|
5
|
+
return taps.map(([dx, dy, numerator]) => ({ dx, dy, weight: numerator / divisor }));
|
|
6
|
+
}
|
|
7
|
+
function luma(r, g, b) {
|
|
8
|
+
return r * 0.299 + g * 0.587 + b * 0.114;
|
|
9
|
+
}
|
|
10
|
+
/** Converts image to a working grayscale buffer (one float per pixel, 0-255 range). */
|
|
11
|
+
function toGrayscaleBuffer(image) {
|
|
12
|
+
const { width, height, data } = image;
|
|
13
|
+
const gray = new Float32Array(width * height);
|
|
14
|
+
for (let y = 0; y < height; y++) {
|
|
15
|
+
for (let x = 0; x < width; x++) {
|
|
16
|
+
const i = (y * width + x) * 4;
|
|
17
|
+
const p = i;
|
|
18
|
+
gray[y * width + x] = luma(data[p] ?? 0, data[p + 1] ?? 0, data[p + 2] ?? 0);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return gray;
|
|
22
|
+
}
|
|
23
|
+
/** Writes a pure black/white pixel into `output` at `idx`, carrying over `image`'s alpha at (x, y). */
|
|
24
|
+
function writeBinaryPixel(output, image, x, y, idx, value) {
|
|
25
|
+
const [, , , a] = getPixel(image, x, y);
|
|
26
|
+
const oi = idx * 4;
|
|
27
|
+
output.data[oi] = value;
|
|
28
|
+
output.data[oi + 1] = value;
|
|
29
|
+
output.data[oi + 2] = value;
|
|
30
|
+
output.data[oi + 3] = a;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Shared error-diffusion engine. Walks the grayscale buffer left-to-right,
|
|
34
|
+
* top-to-bottom, quantizing each pixel to 0/255 and pushing the resulting
|
|
35
|
+
* error onto not-yet-visited neighbors per `kernel`. Out-of-bounds neighbors
|
|
36
|
+
* are simply skipped (their share of the error is dropped at image edges).
|
|
37
|
+
*/
|
|
38
|
+
function diffuseErrorDither(image, threshold, kernel) {
|
|
39
|
+
const { width, height } = image;
|
|
40
|
+
const gray = toGrayscaleBuffer(image);
|
|
41
|
+
const output = createImageData(width, height);
|
|
42
|
+
for (let y = 0; y < height; y++) {
|
|
43
|
+
for (let x = 0; x < width; x++) {
|
|
44
|
+
const idx = y * width + x;
|
|
45
|
+
const oldValue = gray[idx] ?? 0;
|
|
46
|
+
const newValue = oldValue > threshold ? 255 : 0;
|
|
47
|
+
const error = oldValue - newValue;
|
|
48
|
+
writeBinaryPixel(output, image, x, y, idx, newValue);
|
|
49
|
+
for (const tap of kernel) {
|
|
50
|
+
const nx = x + tap.dx;
|
|
51
|
+
const ny = y + tap.dy;
|
|
52
|
+
if (nx < 0 || nx >= width || ny < 0 || ny >= height)
|
|
53
|
+
continue;
|
|
54
|
+
const nIdx = ny * width + nx;
|
|
55
|
+
gray[nIdx] = (gray[nIdx] ?? 0) + error * tap.weight;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return output;
|
|
60
|
+
}
|
|
61
|
+
const FLOYD_STEINBERG_KERNEL = buildKernel(16, [
|
|
62
|
+
[1, 0, 7],
|
|
63
|
+
[-1, 1, 3],
|
|
64
|
+
[0, 1, 5],
|
|
65
|
+
[1, 1, 1],
|
|
66
|
+
]);
|
|
67
|
+
/** Floyd-Steinberg error-diffusion dithering (Floyd & Steinberg, 1976). */
|
|
68
|
+
export const ditherFloydSteinberg = (image, options) => {
|
|
69
|
+
const threshold = options.threshold ?? DEFAULT_THRESHOLD;
|
|
70
|
+
return diffuseErrorDither(image, threshold, FLOYD_STEINBERG_KERNEL);
|
|
71
|
+
};
|
|
72
|
+
const ATKINSON_KERNEL = buildKernel(8, [
|
|
73
|
+
[1, 0, 1],
|
|
74
|
+
[2, 0, 1],
|
|
75
|
+
[-1, 1, 1],
|
|
76
|
+
[0, 1, 1],
|
|
77
|
+
[1, 1, 1],
|
|
78
|
+
[0, 2, 1],
|
|
79
|
+
]);
|
|
80
|
+
/** Atkinson dithering (Bill Atkinson, Apple). Only diffuses 6/8 of the error,
|
|
81
|
+
* which intentionally clips instead of fully spreading it, giving higher local contrast. */
|
|
82
|
+
export const ditherAtkinson = (image, options) => {
|
|
83
|
+
const threshold = options.threshold ?? DEFAULT_THRESHOLD;
|
|
84
|
+
return diffuseErrorDither(image, threshold, ATKINSON_KERNEL);
|
|
85
|
+
};
|
|
86
|
+
const JARVIS_JUDICE_NINKE_KERNEL = buildKernel(48, [
|
|
87
|
+
[1, 0, 7],
|
|
88
|
+
[2, 0, 5],
|
|
89
|
+
[-2, 1, 3],
|
|
90
|
+
[-1, 1, 5],
|
|
91
|
+
[0, 1, 7],
|
|
92
|
+
[1, 1, 5],
|
|
93
|
+
[2, 1, 3],
|
|
94
|
+
[-2, 2, 1],
|
|
95
|
+
[-1, 2, 3],
|
|
96
|
+
[0, 2, 5],
|
|
97
|
+
[1, 2, 3],
|
|
98
|
+
[2, 2, 1],
|
|
99
|
+
]);
|
|
100
|
+
/** Jarvis, Judice & Ninke error-diffusion dithering (1976). */
|
|
101
|
+
export const ditherJarvisJudiceNinke = (image, options) => {
|
|
102
|
+
const threshold = options.threshold ?? DEFAULT_THRESHOLD;
|
|
103
|
+
return diffuseErrorDither(image, threshold, JARVIS_JUDICE_NINKE_KERNEL);
|
|
104
|
+
};
|
|
105
|
+
const STUCKI_KERNEL = buildKernel(42, [
|
|
106
|
+
[1, 0, 8],
|
|
107
|
+
[2, 0, 4],
|
|
108
|
+
[-2, 1, 2],
|
|
109
|
+
[-1, 1, 4],
|
|
110
|
+
[0, 1, 8],
|
|
111
|
+
[1, 1, 4],
|
|
112
|
+
[2, 1, 2],
|
|
113
|
+
[-2, 2, 1],
|
|
114
|
+
[-1, 2, 2],
|
|
115
|
+
[0, 2, 4],
|
|
116
|
+
[1, 2, 2],
|
|
117
|
+
[2, 2, 1],
|
|
118
|
+
]);
|
|
119
|
+
/** Stucki error-diffusion dithering (1981). */
|
|
120
|
+
export const ditherStucki = (image, options) => {
|
|
121
|
+
const threshold = options.threshold ?? DEFAULT_THRESHOLD;
|
|
122
|
+
return diffuseErrorDither(image, threshold, STUCKI_KERNEL);
|
|
123
|
+
};
|
|
124
|
+
const SIERRA_KERNEL = buildKernel(32, [
|
|
125
|
+
[1, 0, 5],
|
|
126
|
+
[2, 0, 3],
|
|
127
|
+
[-2, 1, 2],
|
|
128
|
+
[-1, 1, 4],
|
|
129
|
+
[0, 1, 5],
|
|
130
|
+
[1, 1, 4],
|
|
131
|
+
[2, 1, 2],
|
|
132
|
+
[-1, 2, 2],
|
|
133
|
+
[0, 2, 3],
|
|
134
|
+
[1, 2, 2],
|
|
135
|
+
]);
|
|
136
|
+
/** Sierra error-diffusion dithering (Frankie Sierra). */
|
|
137
|
+
export const ditherSierra = (image, options) => {
|
|
138
|
+
const threshold = options.threshold ?? DEFAULT_THRESHOLD;
|
|
139
|
+
return diffuseErrorDither(image, threshold, SIERRA_KERNEL);
|
|
140
|
+
};
|
|
141
|
+
const BURKES_KERNEL = buildKernel(32, [
|
|
142
|
+
[1, 0, 8],
|
|
143
|
+
[2, 0, 4],
|
|
144
|
+
[-2, 1, 2],
|
|
145
|
+
[-1, 1, 4],
|
|
146
|
+
[0, 1, 8],
|
|
147
|
+
[1, 1, 4],
|
|
148
|
+
[2, 1, 2],
|
|
149
|
+
]);
|
|
150
|
+
/** Burkes error-diffusion dithering (Daniel Burkes, 1988). */
|
|
151
|
+
export const ditherBurkes = (image, options) => {
|
|
152
|
+
const threshold = options.threshold ?? DEFAULT_THRESHOLD;
|
|
153
|
+
return diffuseErrorDither(image, threshold, BURKES_KERNEL);
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Recursively builds the NxN Bayer matrix (N a power of two) with entries
|
|
157
|
+
* 0..N^2-1, using the standard blockwise construction:
|
|
158
|
+
* M(2n) = [[4*M(n), 4*M(n)+2], [4*M(n)+3, 4*M(n)+1]]
|
|
159
|
+
*/
|
|
160
|
+
function buildBayerMatrix(size) {
|
|
161
|
+
if (size === 2) {
|
|
162
|
+
return [
|
|
163
|
+
[0, 2],
|
|
164
|
+
[3, 1],
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
const half = size / 2;
|
|
168
|
+
const base = buildBayerMatrix(half);
|
|
169
|
+
const matrix = Array.from({ length: size }, () => new Array(size).fill(0));
|
|
170
|
+
for (let y = 0; y < half; y++) {
|
|
171
|
+
for (let x = 0; x < half; x++) {
|
|
172
|
+
const v = base[y]?.[x] ?? 0;
|
|
173
|
+
matrix[y][x] = 4 * v;
|
|
174
|
+
matrix[y][x + half] = 4 * v + 2;
|
|
175
|
+
matrix[y + half][x] = 4 * v + 3;
|
|
176
|
+
matrix[y + half][x + half] = 4 * v + 1;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return matrix;
|
|
180
|
+
}
|
|
181
|
+
/** Builds an NxN matrix of 0-255 dithering thresholds from the raw Bayer matrix. */
|
|
182
|
+
function buildBayerThresholdMatrix(size) {
|
|
183
|
+
const raw = buildBayerMatrix(size);
|
|
184
|
+
const n2 = size * size;
|
|
185
|
+
return raw.map((row) => row.map((value) => ((value + 0.5) / n2) * 255));
|
|
186
|
+
}
|
|
187
|
+
/** Bayer ordered dithering: compares each pixel against a tiled NxN threshold matrix. */
|
|
188
|
+
export const ditherBayer = (image, options) => {
|
|
189
|
+
const size = options.matrixSize ?? 4;
|
|
190
|
+
const thresholds = buildBayerThresholdMatrix(size);
|
|
191
|
+
const { width, height } = image;
|
|
192
|
+
const gray = toGrayscaleBuffer(image);
|
|
193
|
+
const output = createImageData(width, height);
|
|
194
|
+
for (let y = 0; y < height; y++) {
|
|
195
|
+
for (let x = 0; x < width; x++) {
|
|
196
|
+
const idx = y * width + x;
|
|
197
|
+
const value = gray[idx] ?? 0;
|
|
198
|
+
const threshold = thresholds[y % size]?.[x % size] ?? 0;
|
|
199
|
+
const newValue = value > threshold ? 255 : 0;
|
|
200
|
+
writeBinaryPixel(output, image, x, y, idx, newValue);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return output;
|
|
204
|
+
};
|
|
205
|
+
function fractional(v) {
|
|
206
|
+
return v - Math.floor(v);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Blue-noise ordered dithering using Interleaved Gradient Noise (IGN) as a
|
|
210
|
+
* cheap, real-time-graphics approximation of a true blue-noise texture --
|
|
211
|
+
* this is not a void-and-cluster blue-noise dither, just visually similar.
|
|
212
|
+
*/
|
|
213
|
+
export const ditherBlueNoise = (image) => {
|
|
214
|
+
const { width, height } = image;
|
|
215
|
+
const gray = toGrayscaleBuffer(image);
|
|
216
|
+
const output = createImageData(width, height);
|
|
217
|
+
for (let y = 0; y < height; y++) {
|
|
218
|
+
for (let x = 0; x < width; x++) {
|
|
219
|
+
const idx = y * width + x;
|
|
220
|
+
const value = gray[idx] ?? 0;
|
|
221
|
+
const threshold = 255 * fractional(52.9829189 * fractional(0.06711056 * x + 0.00583715 * y));
|
|
222
|
+
const newValue = value > threshold ? 255 : 0;
|
|
223
|
+
writeBinaryPixel(output, image, x, y, idx, newValue);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return output;
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=dither.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dither.js","sourceRoot":"","sources":["../../src/filters/dither.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAiBxD,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAU9B,0FAA0F;AAC1F,SAAS,WAAW,CAAC,OAAe,EAAE,IAAqC;IACzE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC;AACtF,CAAC;AAED,SAAS,IAAI,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;IAC3C,OAAO,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC;AAC3C,CAAC;AAED,uFAAuF;AACvF,SAAS,iBAAiB,CAAC,KAAgB;IACzC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IACtC,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;IAC9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,KAAK,IAAI,CAAC,GAAG,CAAC,E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GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YAC/B,MAAM,GAAG,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;YAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC7B,MAAM,SAAS,GAAG,GAAG,GAAG,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,GAAG,CAAC,GAAG,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC;YAC7F,MAAM,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAE7C,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Filter, FilterOptions } from "../types.js";
|
|
2
|
+
export interface HalftoneOptions extends FilterOptions {
|
|
3
|
+
/** Grid cell size in pixels. Default 8. */
|
|
4
|
+
cellSize?: number;
|
|
5
|
+
/** Screen rotation in degrees, applied around the image center. Default 0. */
|
|
6
|
+
angle?: number;
|
|
7
|
+
/** Dot shape used to render darkness within each cell. Default "circle". */
|
|
8
|
+
shape?: "circle" | "line";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Classic halftone screen: grayscales the image, then renders each grid cell
|
|
12
|
+
* as a black dot/line sized proportionally to how dark that cell's source
|
|
13
|
+
* pixels were on average. Output alpha is copied from the input and plays no
|
|
14
|
+
* part in the darkness computation.
|
|
15
|
+
*/
|
|
16
|
+
export declare const halftone: Filter<HalftoneOptions>;
|
|
17
|
+
export interface MorphologyOptions extends FilterOptions {
|
|
18
|
+
/** Neighborhood radius; the structuring element is a (2r+1)x(2r+1) square. Default 1. */
|
|
19
|
+
radius?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Binary erosion at threshold 128: a dark pixel survives only if every pixel
|
|
23
|
+
* in its square neighborhood is also dark (out-of-bounds counts as
|
|
24
|
+
* background). Output is pure black/white; alpha is copied from the input.
|
|
25
|
+
*/
|
|
26
|
+
export declare const erode: Filter<MorphologyOptions>;
|
|
27
|
+
/**
|
|
28
|
+
* Binary dilation at threshold 128: a background pixel becomes foreground if
|
|
29
|
+
* any pixel in its square neighborhood is dark. Output is pure black/white;
|
|
30
|
+
* alpha is copied from the input.
|
|
31
|
+
*/
|
|
32
|
+
export declare const dilate: Filter<MorphologyOptions>;
|
|
33
|
+
/** Opening: erode then dilate, removing small isolated foreground specks. */
|
|
34
|
+
export declare const morphOpen: Filter<MorphologyOptions>;
|
|
35
|
+
/** Closing: dilate then erode, filling small isolated background gaps. */
|
|
36
|
+
export declare const morphClose: Filter<MorphologyOptions>;
|
|
37
|
+
export interface SobelEdgeOptions extends FilterOptions {
|
|
38
|
+
/**
|
|
39
|
+
* When provided, output is binarized: white where the gradient magnitude
|
|
40
|
+
* is >= threshold, black otherwise. When omitted, output is the raw
|
|
41
|
+
* grayscale magnitude map (clamped to 0-255).
|
|
42
|
+
*/
|
|
43
|
+
threshold?: number;
|
|
44
|
+
}
|
|
45
|
+
/** Standard 3x3 Sobel edge detector on the grayscale image; alpha is copied from the input. */
|
|
46
|
+
export declare const sobelEdgeDetect: Filter<SobelEdgeOptions>;
|
|
47
|
+
export interface CannyEdgeOptions extends FilterOptions {
|
|
48
|
+
/** Magnitude (0-255 scale) below which a pixel is never an edge. Default 50. */
|
|
49
|
+
lowThreshold?: number;
|
|
50
|
+
/** Magnitude (0-255 scale) above which a pixel is always a strong edge. Default 100. */
|
|
51
|
+
highThreshold?: number;
|
|
52
|
+
/** Standard deviation of the Gaussian pre-blur. Default 1.4. */
|
|
53
|
+
gaussianSigma?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Classic Canny pipeline: grayscale -> Gaussian blur -> Sobel gradients ->
|
|
57
|
+
* non-maximum suppression -> double threshold + 8-connected hysteresis.
|
|
58
|
+
* Output is pure black/white; alpha is copied from the input.
|
|
59
|
+
*/
|
|
60
|
+
export declare const cannyEdgeDetect: Filter<CannyEdgeOptions>;
|
|
61
|
+
//# sourceMappingURL=edge-morphology.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edge-morphology.d.ts","sourceRoot":"","sources":["../../src/filters/edge-morphology.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA4IzD,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACpD,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;CAC3B;AAOD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,eAAe,CA6E5C,CAAC;AAEF,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD,yFAAyF;IACzF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,iBAAiB,CAwB3C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,iBAAiB,CAwB5C,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,iBAAiB,CACR,CAAC;AAEzC,0EAA0E;AAC1E,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,iBAAiB,CACT,CAAC;AAEzC,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,+FAA+F;AA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