@xprite/pixelate 0.1.3 → 0.2.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/README.md +14 -0
- package/README.zh-CN.md +14 -0
- package/dist/base.d.ts +4 -0
- package/dist/base.js +33 -0
- package/dist/deskew.js +28 -15
- package/dist/fft-autocorr.d.ts +12 -0
- package/dist/fft-autocorr.js +116 -0
- package/dist/float-image.d.ts +25 -0
- package/dist/float-image.js +184 -0
- package/dist/grid-arbitrate.d.ts +8 -0
- package/dist/grid-arbitrate.js +219 -65
- 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-pitch-lattice.js +21 -9
- package/dist/grid-pitch-search.js +38 -18
- package/dist/grid-sample.js +2 -2
- 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/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/kuwahara.d.ts +9 -0
- package/dist/kuwahara.js +287 -0
- package/dist/line-guided/pixeloe-entry.d.ts +2 -2
- package/dist/line-guided/pixeloe-entry.js +6 -35
- package/dist/orphan-pixels.d.ts +7 -0
- package/dist/orphan-pixels.js +133 -0
- package/dist/palette-snap.d.ts +1 -1
- package/dist/palette-snap.js +127 -58
- package/dist/pixelate.d.ts +4 -7
- package/dist/pixelate.js +133 -98
- package/dist/quantization.d.ts +4 -0
- package/dist/quantization.js +23 -16
- package/dist/resize-crisp.d.ts +11 -0
- package/dist/resize-crisp.js +213 -0
- package/dist/resize-lanczos.d.ts +7 -0
- package/dist/resize-lanczos.js +205 -0
- package/dist/sampling.d.ts +2 -1
- package/dist/sampling.js +1 -1
- package/dist/settings.d.ts +6 -3
- package/dist/settings.js +26 -12
- package/dist/types.d.ts +14 -2
- package/dist/types.js +2 -2
- package/package.json +1 -1
- package/dist/contours.d.ts +0 -4
- package/dist/contours.js +0 -66
- package/dist/most-frequent.d.ts +0 -3
- package/dist/most-frequent.js +0 -56
package/dist/types.d.ts
CHANGED
|
@@ -50,10 +50,10 @@ export interface PixelArtAnalysis {
|
|
|
50
50
|
export declare enum PixelationMethod {
|
|
51
51
|
Nearest = "nearest",
|
|
52
52
|
Box = "box",
|
|
53
|
-
MostFrequent = "most-frequent",
|
|
54
53
|
Dominant = "dominant",
|
|
55
54
|
Structure = "structure",
|
|
56
|
-
|
|
55
|
+
Lanczos = "lanczos",
|
|
56
|
+
Crisp = "crisp"
|
|
57
57
|
}
|
|
58
58
|
export declare enum PixelationMode {
|
|
59
59
|
Convert = "convert",
|
|
@@ -171,6 +171,11 @@ export interface PaletteSnapOptions {
|
|
|
171
171
|
palette?: readonly Rgba[];
|
|
172
172
|
/** Ordered / Floyd–Steinberg while snapping; None (nearest) when omitted. */
|
|
173
173
|
dither?: PixelationDither;
|
|
174
|
+
/**
|
|
175
|
+
* Weight clustering by local OKLab brightness/chroma contrast so small focal accents
|
|
176
|
+
* (eyes, lips, highlights, seals) keep dedicated palette slots. Defaults to true.
|
|
177
|
+
*/
|
|
178
|
+
saliency?: boolean;
|
|
174
179
|
}
|
|
175
180
|
export interface PixelateOptions {
|
|
176
181
|
mode?: PixelationMode;
|
|
@@ -179,6 +184,11 @@ export interface PixelateOptions {
|
|
|
179
184
|
colorPicker?: CellColorPicker;
|
|
180
185
|
grid?: PixelGridGeometry;
|
|
181
186
|
outlineStrength?: number;
|
|
187
|
+
/**
|
|
188
|
+
* Cel-shading simplification pre-pass (Anisotropic Kuwahara + highlight-safe OKLab clarity)
|
|
189
|
+
* ahead of sampling and outline expansion. Off when omitted.
|
|
190
|
+
*/
|
|
191
|
+
kuwahara?: boolean;
|
|
182
192
|
/**
|
|
183
193
|
* Outline pre-pass; None when omitted. With the Contrast picker and no grid recovered from the
|
|
184
194
|
* source (a plain convert or Custom size), a PixelOE pre-pass runs stock PixelOE end to end
|
|
@@ -229,6 +239,8 @@ export interface PixelationSettings {
|
|
|
229
239
|
*/
|
|
230
240
|
reduceColors: boolean;
|
|
231
241
|
outlineStrength: number;
|
|
242
|
+
/** Cel-shading simplification pre-pass ahead of conversion (see `PixelateOptions.kuwahara`). */
|
|
243
|
+
kuwahara: boolean;
|
|
232
244
|
/** Outline pre-pass ahead of the colour rule (see `PixelateOptions.prepass`). */
|
|
233
245
|
prepass: OutlinePrepass;
|
|
234
246
|
/** Line guide of the PixelOE + lines pre-pass. */
|
package/dist/types.js
CHANGED
|
@@ -9,10 +9,10 @@ export var PixelationMethod;
|
|
|
9
9
|
(function (PixelationMethod) {
|
|
10
10
|
PixelationMethod["Nearest"] = "nearest";
|
|
11
11
|
PixelationMethod["Box"] = "box";
|
|
12
|
-
PixelationMethod["MostFrequent"] = "most-frequent";
|
|
13
12
|
PixelationMethod["Dominant"] = "dominant";
|
|
14
13
|
PixelationMethod["Structure"] = "structure";
|
|
15
|
-
PixelationMethod["
|
|
14
|
+
PixelationMethod["Lanczos"] = "lanczos";
|
|
15
|
+
PixelationMethod["Crisp"] = "crisp";
|
|
16
16
|
})(PixelationMethod || (PixelationMethod = {}));
|
|
17
17
|
export var PixelationMode;
|
|
18
18
|
(function (PixelationMode) {
|
package/package.json
CHANGED
package/dist/contours.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { PixelBuffer } from "./base.ts";
|
|
2
|
-
/** Independent thin-ridge filter: opposite neighbors identify narrow light/dark features.
|
|
3
|
-
* Only RGB is blended into existing visible pixels; the alpha footprint never grows. */
|
|
4
|
-
export declare function protectPixelationContours(image: PixelBuffer, strength: number): PixelBuffer;
|
package/dist/contours.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { UINT8_MAX } from "./base.js";
|
|
2
|
-
const CHANNELS = 4;
|
|
3
|
-
const COLOR_CHANNELS = 3;
|
|
4
|
-
const LUMA = [0.2126, 0.7152, 0.0722];
|
|
5
|
-
const MIN_CONTRAST = 0.14;
|
|
6
|
-
const BACKGROUND_TOLERANCE = 0.12;
|
|
7
|
-
const MAX_BLEND = 0.65;
|
|
8
|
-
const PERCENT = 100;
|
|
9
|
-
/** Independent thin-ridge filter: opposite neighbors identify narrow light/dark features.
|
|
10
|
-
* Only RGB is blended into existing visible pixels; the alpha footprint never grows. */
|
|
11
|
-
export function protectPixelationContours(image, strength) {
|
|
12
|
-
if (!strength)
|
|
13
|
-
return image;
|
|
14
|
-
const count = image.width * image.height;
|
|
15
|
-
const luminance = new Float32Array(count);
|
|
16
|
-
const features = new Float32Array(count);
|
|
17
|
-
const source = image.data;
|
|
18
|
-
for (let i = 0; i < count; i++) {
|
|
19
|
-
const offset = i * CHANNELS;
|
|
20
|
-
luminance[i] =
|
|
21
|
-
(source[offset] * LUMA[0] + source[offset + 1] * LUMA[1] + source[offset + 2] * LUMA[2]) /
|
|
22
|
-
UINT8_MAX;
|
|
23
|
-
}
|
|
24
|
-
const ridge = (center, first, second) => {
|
|
25
|
-
if (!source[first * CHANNELS + COLOR_CHANNELS] || !source[second * CHANNELS + COLOR_CHANNELS])
|
|
26
|
-
return 0;
|
|
27
|
-
const left = luminance[center] - luminance[first], right = luminance[center] - luminance[second];
|
|
28
|
-
if (left * right <= 0 || Math.abs(luminance[first] - luminance[second]) > BACKGROUND_TOLERANCE)
|
|
29
|
-
return 0;
|
|
30
|
-
return Math.min(Math.abs(left), Math.abs(right));
|
|
31
|
-
};
|
|
32
|
-
for (let y = 1; y < image.height - 1; y++)
|
|
33
|
-
for (let x = 1; x < image.width - 1; x++) {
|
|
34
|
-
const i = y * image.width + x;
|
|
35
|
-
if (!source[i * CHANNELS + COLOR_CHANNELS])
|
|
36
|
-
continue;
|
|
37
|
-
features[i] = Math.max(ridge(i, i - 1, i + 1), ridge(i, i - image.width, i + image.width));
|
|
38
|
-
}
|
|
39
|
-
const data = new Uint8ClampedArray(source);
|
|
40
|
-
for (let y = 0; y < image.height; y++)
|
|
41
|
-
for (let x = 0; x < image.width; x++) {
|
|
42
|
-
const i = y * image.width + x, offset = i * CHANNELS;
|
|
43
|
-
if (!source[offset + COLOR_CHANNELS] || features[i] >= MIN_CONTRAST)
|
|
44
|
-
continue;
|
|
45
|
-
let best = i, score = MIN_CONTRAST;
|
|
46
|
-
for (let dy = -1; dy <= 1; dy++)
|
|
47
|
-
for (let dx = -1; dx <= 1; dx++) {
|
|
48
|
-
const nx = x + dx, ny = y + dy;
|
|
49
|
-
if ((!dx && !dy) || nx < 0 || ny < 0 || nx >= image.width || ny >= image.height)
|
|
50
|
-
continue;
|
|
51
|
-
const neighbor = ny * image.width + nx;
|
|
52
|
-
const coverage = source[neighbor * CHANNELS + COLOR_CHANNELS] / UINT8_MAX;
|
|
53
|
-
const candidate = (features[neighbor] * coverage) / Math.max(1, Math.abs(dx) + Math.abs(dy));
|
|
54
|
-
if (candidate > score) {
|
|
55
|
-
score = candidate;
|
|
56
|
-
best = neighbor;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (best === i)
|
|
60
|
-
continue;
|
|
61
|
-
const amount = (strength / PERCENT) * MAX_BLEND;
|
|
62
|
-
for (let c = 0; c < COLOR_CHANNELS; c++)
|
|
63
|
-
data[offset + c] = Math.round(source[offset + c] * (1 - amount) + source[best * CHANNELS + c] * amount);
|
|
64
|
-
}
|
|
65
|
-
return { width: image.width, height: image.height, data };
|
|
66
|
-
}
|
package/dist/most-frequent.d.ts
DELETED
package/dist/most-frequent.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { UINT8_MAX } from "./base.js";
|
|
2
|
-
import { assertDimension, assertPixelCount } from "./base.js";
|
|
3
|
-
const CHANNELS = 4;
|
|
4
|
-
const RGB_BASE = 256;
|
|
5
|
-
const EMPTY_SAMPLE = -1;
|
|
6
|
-
const MAX_SAMPLES_PER_AXIS = 64;
|
|
7
|
-
/** Choose a cell's most frequent RGB, counting transparent pixels as empty samples. */
|
|
8
|
-
export function resizeMostFrequent(source, width, height) {
|
|
9
|
-
assertDimension(source.width, "source width");
|
|
10
|
-
assertDimension(source.height, "source height");
|
|
11
|
-
assertDimension(width, "width");
|
|
12
|
-
assertDimension(height, "height");
|
|
13
|
-
assertPixelCount(width, height);
|
|
14
|
-
if (source.data.length !== source.width * source.height * CHANNELS)
|
|
15
|
-
throw new Error("Invalid pixel buffer.");
|
|
16
|
-
const data = new Uint8ClampedArray(width * height * CHANNELS);
|
|
17
|
-
for (let row = 0; row < height; row++) {
|
|
18
|
-
const top = Math.floor((row * source.height) / height);
|
|
19
|
-
const bottom = Math.min(source.height, Math.max(top + 1, Math.floor(((row + 1) * source.height) / height)));
|
|
20
|
-
const yStep = Math.ceil((bottom - top) / MAX_SAMPLES_PER_AXIS);
|
|
21
|
-
for (let column = 0; column < width; column++) {
|
|
22
|
-
const left = Math.floor((column * source.width) / width);
|
|
23
|
-
const right = Math.min(source.width, Math.max(left + 1, Math.floor(((column + 1) * source.width) / width)));
|
|
24
|
-
const xStep = Math.ceil((right - left) / MAX_SAMPLES_PER_AXIS);
|
|
25
|
-
const counts = new Map();
|
|
26
|
-
let alphaSum = 0;
|
|
27
|
-
let samples = 0;
|
|
28
|
-
for (let y = top; y < bottom; y += yStep)
|
|
29
|
-
for (let x = left; x < right; x += xStep) {
|
|
30
|
-
const offset = (y * source.width + x) * CHANNELS;
|
|
31
|
-
alphaSum += source.data[offset + 3];
|
|
32
|
-
samples++;
|
|
33
|
-
const key = source.data[offset + 3] === 0
|
|
34
|
-
? EMPTY_SAMPLE
|
|
35
|
-
: (source.data[offset] * RGB_BASE + source.data[offset + 1]) * RGB_BASE +
|
|
36
|
-
source.data[offset + 2];
|
|
37
|
-
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
38
|
-
}
|
|
39
|
-
let selected = EMPTY_SAMPLE;
|
|
40
|
-
let largest = 0;
|
|
41
|
-
for (const [color, count] of counts)
|
|
42
|
-
if (count > largest) {
|
|
43
|
-
selected = color;
|
|
44
|
-
largest = count;
|
|
45
|
-
}
|
|
46
|
-
if (selected === EMPTY_SAMPLE)
|
|
47
|
-
continue;
|
|
48
|
-
const offset = (row * width + column) * CHANNELS;
|
|
49
|
-
data[offset] = Math.floor(selected / (RGB_BASE * RGB_BASE));
|
|
50
|
-
data[offset + 1] = Math.floor(selected / RGB_BASE) % RGB_BASE;
|
|
51
|
-
data[offset + 2] = selected % RGB_BASE;
|
|
52
|
-
data[offset + 3] = Math.min(UINT8_MAX, Math.round(alphaSum / samples));
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return { width, height, data };
|
|
56
|
-
}
|