inlaytrace 0.4.0 → 0.5.0
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/CHANGELOG.md +13 -0
- package/README.md +1 -1
- package/bin/inlaytrace.mjs +3 -0
- package/dist/index.d.ts +56 -2
- package/dist/index.js +2361 -50
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# inlaytrace
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- New `deblur` option (and `--deblur` on the command line) for soft photos, screenshots and enlarged copies of flat-colour art. A blurred edge is a ramp, and its middle traced as a band of an in-between colour round every shape. `deblur` measures the blur place by place, finds the flat colours the image is made of, and works out the flat shapes that, blurred the same way, look like the image; those are traced instead, their straight edges drawn as true lines and their corners kept. It tells a lens's blur from a resize's, which decides where each edge sits, and takes out a colour fringe on the way. Images whose edges measure crisp are left as they are. `traceAsync` reports it as a `'deblur'` stage, pausing after each sweep of its search, so it can be cancelled. On a soft photo of a dump-truck logo the Logo SVG went from 411 KB with a halo round every shape to 71 KB without. Also exported: `deblur(rgba, width, height)` and `edgeBlur(rgba, width, height)`, which measures how soft an image's edges are, in px.
|
|
8
|
+
- Exact shapes are chosen by drawing them: a shape near the fit limits is kept only if it covers the region as well as the free fit, and a small regular polygon (a hexagon a few pixels across) is no longer drawn as a circle.
|
|
9
|
+
- New `traceAsync(image, { signal, onProgress, …options })`: the same trace as `trace`, but it pauses between stages to report progress, gives the thread time to do other work, and stops when its `AbortSignal` aborts.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Logo and Illustration keep a flat colour that sits close to another one, when there's room under the colour cap: a truck logo's neutral-grey grille bars and tyre treads, 0.057 from its blue-grey cab in OKLab, used to trace as the cab, smeared with navy. Only flat art gets this (four in five pixels flat), and gradients' in-between shades are left out, so photos and soft shading trace as before. A shade between two close colours (the truck's bumper) now takes one of them for its whole region, instead of blotches of both.
|
|
14
|
+
- A barely-there gradient in a background (a near-white vignette) no longer traces as ragged bands of close tints: Logo, Illustration and Outline art join them into one flat shape in their commonest colour. Only close colours the image passes between without an edge are joined, so a pale fill on white stays a shape, and your own palette keeps every colour. On a dump-truck logo the Logo SVG went from 107 to 63 KB.
|
|
15
|
+
|
|
3
16
|
## 0.4.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ PNGs need nothing else. For JPEG, WebP, GIF or TIFF, install
|
|
|
72
72
|
Any option overrides the preset: `colors`, `palette` (your own colours, as
|
|
73
73
|
`#rrggbb`), `merge` (`{ '#from': '#into' }`), `speckle`, `tolerance`,
|
|
74
74
|
`cornerAngle`, `layers`, `shapes`, `strokes`, `gradients`, `closeGaps`,
|
|
75
|
-
`threshold`, `invert`, `strokeWidth`, `smoothShading`, `keepOutlines`, `grayscale` and
|
|
75
|
+
`threshold`, `invert`, `strokeWidth`, `deblur`, `smoothShading`, `keepOutlines`, `grayscale` and
|
|
76
76
|
`scale`. [Options](https://github.com/mtblck/inlaytrace/blob/main/docs/package/options.md)
|
|
77
77
|
says what each does.
|
|
78
78
|
|
package/bin/inlaytrace.mjs
CHANGED
|
@@ -27,6 +27,7 @@ Writes to stdout without -o.
|
|
|
27
27
|
--exact-shapes draw circles and rectangles exactly (--no-exact-shapes)
|
|
28
28
|
--threshold <0-255> lineart and centerline: ink is darker than this
|
|
29
29
|
--invert lineart and centerline: light ink on a dark background
|
|
30
|
+
--deblur colour presets: take the blur out of a soft image first
|
|
30
31
|
--grayscale colour presets: greys only, --colors of them
|
|
31
32
|
--stroke-width <px> centerline: the stroke width
|
|
32
33
|
-h, --help
|
|
@@ -47,6 +48,7 @@ const { values, positionals } = parseArgs({
|
|
|
47
48
|
'exact-shapes': { type: 'boolean' },
|
|
48
49
|
threshold: { type: 'string' },
|
|
49
50
|
invert: { type: 'boolean' },
|
|
51
|
+
deblur: { type: 'boolean' },
|
|
50
52
|
grayscale: { type: 'boolean' },
|
|
51
53
|
'stroke-width': { type: 'string' },
|
|
52
54
|
help: { type: 'boolean', short: 'h' },
|
|
@@ -86,6 +88,7 @@ const options = {
|
|
|
86
88
|
shapes: values['exact-shapes'],
|
|
87
89
|
threshold: values.threshold === undefined ? undefined : values.threshold === 'auto' ? 'auto' : num('threshold', values.threshold),
|
|
88
90
|
invert: values.invert,
|
|
91
|
+
deblur: values.deblur,
|
|
89
92
|
grayscale: values.grayscale,
|
|
90
93
|
strokeWidth: num('stroke-width', values['stroke-width']),
|
|
91
94
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -89,7 +89,9 @@ export declare function pointAt(b: Cubic, t: number): Pt;
|
|
|
89
89
|
* share (a decal, lettering) is still a colour if it isn't a blend of two
|
|
90
90
|
* colours already accepted (an anti-aliased edge between them).
|
|
91
91
|
* 4. Stop at the requested count.
|
|
92
|
-
* 5. Given the image's `width`,
|
|
92
|
+
* 5. Given the image's `width`, add close fills: flat colours step 3 found
|
|
93
|
+
* too near a picked one (neutral-grey bars beside a blue-grey cab).
|
|
94
|
+
* 6. Then fill what's left of the count with pale tints:
|
|
93
95
|
* light flat colours (pixels that match their four neighbours) too close to a
|
|
94
96
|
* picked colour for step 3. A light-blue fill on white is 0.03 from it in
|
|
95
97
|
* OKLab and lies on the line from white to the blue ink, so step 3 calls
|
|
@@ -209,6 +211,14 @@ type InlayOptions = FitOptions & {
|
|
|
209
211
|
* pixel art. Off by default: a cutter or a plotter can't draw a gradient.
|
|
210
212
|
*/
|
|
211
213
|
gradients?: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Faint shading as one shape: neighbouring regions in close colours that
|
|
216
|
+
* the image passes between without an edge (a barely-there gradient in a
|
|
217
|
+
* background, banded by close tints) join, in their commonest colour.
|
|
218
|
+
* Palette mode, not photos or pixel art. On by default; the presets turn it
|
|
219
|
+
* off with your own palette, whose every colour you chose.
|
|
220
|
+
*/
|
|
221
|
+
faint?: boolean;
|
|
212
222
|
/**
|
|
213
223
|
* Painted lines (one entry per pixel, non-zero on a line), as `boostLines`
|
|
214
224
|
* marks them. A region mostly on them is a drawn line, not one ink's two
|
|
@@ -268,6 +278,13 @@ type InlayResult = {
|
|
|
268
278
|
};
|
|
269
279
|
/** The trace as an SVG document. */
|
|
270
280
|
export declare function toSvg(r: InlayResult): string;
|
|
281
|
+
/** What a trace is doing: take the blur out (only with `deblur`), pick the palette, label the pixels, clean up the labels, find the regions and their edges, fit the edges, build the shapes. */
|
|
282
|
+
type TraceStage = 'deblur' | 'palette' | 'label' | 'clean' | 'regions' | 'fit' | 'shapes';
|
|
283
|
+
/** A point a trace can pause at: the stage, and how far through it (0 to 1). */
|
|
284
|
+
type TraceStep = {
|
|
285
|
+
stage: TraceStage;
|
|
286
|
+
done: number;
|
|
287
|
+
};
|
|
271
288
|
type PresetName = 'logo' | 'illustration' | 'outline' | 'lineart' | 'centerline' | 'poster' | 'pixel';
|
|
272
289
|
/** Anything shaped like ImageData: RGBA bytes, row by row, and the size. sharp's `{ data, info }` gives `data` and `info.width`/`info.height`. */
|
|
273
290
|
type ImageLike = {
|
|
@@ -310,6 +327,8 @@ type TraceOptions = {
|
|
|
310
327
|
invert?: boolean;
|
|
311
328
|
/** Centerline: the stroke width in px; measured from the ink when left out. */
|
|
312
329
|
strokeWidth?: number;
|
|
330
|
+
/** Colour presets but pixel art: take the blur out of a soft image before picking colours, so it doesn't trace as a band round every shape. Does nothing to crisp images. */
|
|
331
|
+
deblur?: boolean;
|
|
313
332
|
/** Colour presets: even out painted shading (brush and JPEG noise) before picking colours. */
|
|
314
333
|
smoothShading?: boolean;
|
|
315
334
|
/** Colour presets: darken faint painted outlines first, so the shapes they part don't merge. */
|
|
@@ -338,6 +357,26 @@ export declare function trace(rgba: ArrayLike<number>, width: number, height: nu
|
|
|
338
357
|
export declare function traceInlay(image: ImageLike, options?: TraceOptions): string;
|
|
339
358
|
/** @deprecated Since 0.4: use `traceInlay({ data: rgba, width, height }, { preset, … })`. This form goes in 1.0. */
|
|
340
359
|
export declare function traceInlay(rgba: ArrayLike<number>, width: number, height: number, options: InlayOptions): string;
|
|
360
|
+
/** Anything shaped like an AbortSignal (an AbortController's `signal`). */
|
|
361
|
+
type AbortSignalLike = {
|
|
362
|
+
readonly aborted: boolean;
|
|
363
|
+
readonly reason?: unknown;
|
|
364
|
+
};
|
|
365
|
+
type TraceAsyncOptions = TraceOptions & {
|
|
366
|
+
/** Stops the trace at its next pause: the promise rejects with the signal's reason. */
|
|
367
|
+
signal?: AbortSignalLike;
|
|
368
|
+
/** Called at each pause with the stage under way and how far through it (0 to 1). */
|
|
369
|
+
onProgress?: (step: TraceStep) => void;
|
|
370
|
+
};
|
|
371
|
+
/**
|
|
372
|
+
* `trace`, but it pauses between its stages (and every few hundred edges
|
|
373
|
+
* while fitting) to report progress and let the thread get on with other
|
|
374
|
+
* work, and it stops when `signal` aborts. Same result as `trace`.
|
|
375
|
+
*
|
|
376
|
+
* const controller = new AbortController()
|
|
377
|
+
* const result = await traceAsync(image, { preset: 'poster', signal: controller.signal, onProgress: (s) => console.log(s.stage, s.done) })
|
|
378
|
+
*/
|
|
379
|
+
export declare function traceAsync(image: ImageLike, options?: TraceAsyncOptions): Promise<InlayResult>;
|
|
341
380
|
/**
|
|
342
381
|
* Edge-preserving smoothing for painted art, before its palette is picked.
|
|
343
382
|
*
|
|
@@ -381,6 +420,21 @@ export declare function smoothShading(rgba: ArrayLike<number>, width: number, he
|
|
|
381
420
|
* enough to the dark grey on either side to be folded in as a sliver.
|
|
382
421
|
*/
|
|
383
422
|
export declare function boostLines(rgba: ArrayLike<number>, width: number, height: number, radius?: number, lines?: Uint8Array): Uint8ClampedArray;
|
|
423
|
+
/**
|
|
424
|
+
* How soft the image's edges are, in px: the Gaussian blur a hard edge would
|
|
425
|
+
* need to look like the image's bold edges (their median). 0 when it has no
|
|
426
|
+
* bold edges. Crisp art reads under 1, anti-aliasing and all.
|
|
427
|
+
*/
|
|
428
|
+
export declare function edgeBlur(rgba: ArrayLike<number>, width: number, height: number): number;
|
|
429
|
+
/**
|
|
430
|
+
* A copy of `rgba` (`width` × `height`, RGBA) with its blur taken out: flat
|
|
431
|
+
* colours with clean, anti-aliased edges where the image had soft ramps.
|
|
432
|
+
* `blur` is how soft its edges are (`edgeBlur`, measured when left out);
|
|
433
|
+
* below `SOFT_EDGES` the image is only copied. `scale` is how many times the
|
|
434
|
+
* image was enlarged before this: enlarging softens edges by as much, so the
|
|
435
|
+
* threshold grows with it. Alpha is kept as it is.
|
|
436
|
+
*/
|
|
437
|
+
export declare function deblur(rgba: ArrayLike<number>, width: number, height: number, blurPx?: number, scale?: number): Uint8ClampedArray;
|
|
384
438
|
type CenterlineOptions = {
|
|
385
439
|
/** Ink is darker than this (0–255); 'auto' splits ink from paper by the image's histogram (Otsu); null compares each pixel with its neighbourhood instead. */
|
|
386
440
|
threshold: number | 'auto' | null;
|
|
@@ -462,4 +516,4 @@ type SymmetryOptions = {
|
|
|
462
516
|
* no foreground.
|
|
463
517
|
*/
|
|
464
518
|
export declare function detectSymmetry(rgba: ArrayLike<number>, w: number, h: number, options?: SymmetryOptions): Symmetry[];
|
|
465
|
-
export type { CenterlineOptions, CenterlineResult, Cubic, FitOptions, Gradient, GradientStop, ImageLike, InlayOptions, InlayPath, InlayResult, MirrorSymmetry, PathNode, PresetDefaults, PresetName, Pt, Rgb, RotationalSymmetry, Subpath, Symmetry, SymmetryOptions, TraceOptions };
|
|
519
|
+
export type { AbortSignalLike, CenterlineOptions, CenterlineResult, Cubic, FitOptions, Gradient, GradientStop, ImageLike, InlayOptions, InlayPath, InlayResult, MirrorSymmetry, PathNode, PresetDefaults, PresetName, Pt, Rgb, RotationalSymmetry, Subpath, Symmetry, SymmetryOptions, TraceAsyncOptions, TraceOptions, TraceStage, TraceStep };
|