@xprite/pixelate 0.1.1 → 0.1.3
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 +48 -46
- package/README.zh-CN.md +48 -43
- package/dist/grid-sample.js +1 -76
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/orphan-pixels.d.ts +11 -0
- package/dist/orphan-pixels.js +74 -0
- package/dist/palette-snap.js +84 -44
- package/dist/pixel-alpha.d.ts +10 -0
- package/dist/pixel-alpha.js +108 -0
- package/dist/pixelate.js +34 -24
- package/dist/quantization.d.ts +6 -1
- package/dist/quantization.js +50 -8
- package/dist/types.d.ts +4 -4
- package/dist/types.js +1 -1
- package/package.json +21 -21
package/README.md
CHANGED
|
@@ -15,19 +15,20 @@ A real generated image (887×887, cells 15 to 21 px wide), recovered by each too
|
|
|
15
15
|
settings. Xprite puts each cut on a colour edge, so it does not cut through the eye, the boots or
|
|
16
16
|
the sword.
|
|
17
17
|
|
|
18
|
-
| Recovered grid | Xprite, 48×49 | [pixel-art-fixer](https://github.com/Retro-Diffusion/pixel-art-fixer), 47×48 | [perfectPixel](https://github.com/theamusing/perfectPixel), 50×50 | [proper-pixel-art](https://github.com/KennethJAllen/proper-pixel-art), 53×54 |
|
|
19
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
20
|
-
|  |  |  |  |  |
|
|
18
|
+
| Recovered grid | Xprite, 48×49 | [pixel-art-fixer](https://github.com/Retro-Diffusion/pixel-art-fixer), 47×48 | [perfectPixel](https://github.com/theamusing/perfectPixel), 50×50 | [proper-pixel-art](https://github.com/KennethJAllen/proper-pixel-art), 53×54 | [Sprite Fusion Pixel Snapper](https://github.com/Hugo-Dz/spritefusion-pixel-snapper), 56×53 |
|
|
19
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
20
|
+
|  |  |  |  |  |  |
|
|
21
21
|
|
|
22
22
|
On the AI suite of [our benchmark](#benchmark) (1746 cases), Xprite gets the exact size most
|
|
23
23
|
often:
|
|
24
24
|
|
|
25
|
-
| Method | Exact size | Within 1 cell | Pixel match |
|
|
25
|
+
| Method | Exact size | Within 1 cell | Pixel match | Fringe (alpha 1–254) | Median time |
|
|
26
26
|
| --- | --- | --- | --- | --- | --- |
|
|
27
|
-
| Xprite Auto | **83.6%** | **90.0%** | **99.
|
|
27
|
+
| Xprite Auto | **83.6%** | **90.0%** | **99.7%** | 0.1% | 2.80 s |
|
|
28
28
|
| pixel-art-fixer | 49.7% | 80.9% | 98.3% | 0.0% | 0.18 s |
|
|
29
29
|
| perfectPixel | 53.3% | 68.0% | 96.7% | - | 0.03 s |
|
|
30
30
|
| proper-pixel-art | 72.2% | 80.4% | 99.7% | 0.0% | 0.49 s |
|
|
31
|
+
| Sprite Fusion Pixel Snapper | 56.8% | 77.9% | 98.5% | 91.0% | — |
|
|
31
32
|
|
|
32
33
|
## Contents
|
|
33
34
|
|
|
@@ -41,56 +42,56 @@ often:
|
|
|
41
42
|
## Examples
|
|
42
43
|
|
|
43
44
|
Each example is one case from a category of the benchmark's AI suite: CC0 pixel art rendered the
|
|
44
|
-
way generators fake it, with a known native size. The sizes are the visible art in cells;
|
|
45
|
+
way generators fake it, with a known native size. The sizes are the visible art in cells; ✅ marks
|
|
45
46
|
the exact native size. Every tool runs with its default settings.
|
|
46
47
|
|
|
47
48
|
### Two sprites on one canvas
|
|
48
49
|
|
|
49
50
|
- [Goblins by LuizMelo](https://luizmelo.itch.io/monsters-creatures-fantasy), CC0. Category `gen_pair`. Native art: 78×36.
|
|
50
51
|
|
|
51
|
-
| Input, 1800×845 | Xprite, 78×36
|
|
52
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
53
|
-
|  |  |  |  |  |
|
|
52
|
+
| Input, 1800×845 | Xprite, 78×36 ✅ | pixel-art-fixer, 78×35 ❌ | perfectPixel, 80×36 ❌ | proper-pixel-art, 79×36 ❌ | Sprite Fusion, 78×36 ✅ |
|
|
53
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
54
|
+
|  |  |  |  |  |  |
|
|
54
55
|
|
|
55
56
|
### Cells that drift and jitter
|
|
56
57
|
|
|
57
58
|
- [Boss dragon by ansimuz](https://opengameart.org/content/sideview-fantasy-patreon-collection), CC0. Category `gen_wobble`. Native art: 71×39.
|
|
58
59
|
|
|
59
|
-
| Input, 1226×664 | Xprite, 71×39
|
|
60
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
61
|
-
|  |  |  |  |  |
|
|
60
|
+
| Input, 1226×664 | Xprite, 71×39 ✅ | pixel-art-fixer, 69×38 ❌ | perfectPixel, 74×39 ❌ | proper-pixel-art, 69×38 ❌ | Sprite Fusion, 71×38 ❌ |
|
|
61
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
62
|
+
|  |  |  |  |  |  |
|
|
62
63
|
|
|
63
64
|
### Small cells and WebP damage
|
|
64
65
|
|
|
65
66
|
- [Monster by Denzi](https://opengameart.org/content/denzis-public-domain-art), CC0. Category `gen_small_pitch`. Native art: 32×48.
|
|
66
67
|
|
|
67
|
-
| Input, 218×339 | Xprite, 32×48
|
|
68
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
69
|
-
|  |  |  |  |  |
|
|
68
|
+
| Input, 218×339 | Xprite, 32×48 ✅ | pixel-art-fixer, 32×47 ❌ | perfectPixel, 32×49 ❌ | proper-pixel-art, 34×49 ❌ | Sprite Fusion, 32×48 ✅ |
|
|
69
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
70
|
+
|  |  |  |  |  |  |
|
|
70
71
|
|
|
71
72
|
### A small sprite on a large clear canvas
|
|
72
73
|
|
|
73
74
|
- [Nekomimi girl by cawfeecrow](https://opengameart.org/content/nekomimi-girl-portrait), CC0. Category `gen_sparse`. Native art: 123×136.
|
|
74
75
|
|
|
75
|
-
| Input, 1797×1800 | Xprite, 123×136
|
|
76
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
77
|
-
|  |  |  |  |  |
|
|
76
|
+
| Input, 1797×1800 | Xprite, 123×136 ✅ | pixel-art-fixer, 122×136 ❌ | perfectPixel, 124×136 ❌ | proper-pixel-art, 127×142 ❌ | Sprite Fusion, 118×133 ❌ |
|
|
77
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
78
|
+
|  |  |  |  |  |  |
|
|
78
79
|
|
|
79
80
|
### An off-white background
|
|
80
81
|
|
|
81
82
|
- [Dragon by ansimuz](https://opengameart.org/content/sideview-fantasy-patreon-collection), CC0. Category `gen_white`. Native art: 162×106.
|
|
82
83
|
|
|
83
|
-
| Input, 1800×1210 | Xprite, 162×106
|
|
84
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
85
|
-
|  |  |  |  |  |
|
|
84
|
+
| Input, 1800×1210 | Xprite, 162×106 ✅ | pixel-art-fixer, 325×208 ❌ | perfectPixel, 161×105 ❌ | proper-pixel-art, 168×106 ❌ | Sprite Fusion, 162×106 ✅ |
|
|
85
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
86
|
+
|  |  |  |  |  |  |
|
|
86
87
|
|
|
87
88
|
### Painterly shading inside cells
|
|
88
89
|
|
|
89
90
|
- [Naga mage, Dungeon Crawl Stone Soup](https://github.com/crawl/tiles), CC0. Category `gen_painterly`. Native art: 31×32.
|
|
90
91
|
|
|
91
|
-
| Input, 411×425 | Xprite, 31×32
|
|
92
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
93
|
-
|  |  |  |  |  |
|
|
92
|
+
| Input, 411×425 | Xprite, 31×32 ✅ | pixel-art-fixer, 30×33 ❌ | perfectPixel, 31×32 ✅ | proper-pixel-art, 31×34 ❌ | Sprite Fusion, 31×32 ✅ |
|
|
93
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
94
|
+
|  |  |  |  |  |  |
|
|
94
95
|
|
|
95
96
|
## Install
|
|
96
97
|
|
|
@@ -219,50 +220,51 @@ Each source file in [`src/`](src) describes its step.
|
|
|
219
220
|
|
|
220
221
|
## Benchmark
|
|
221
222
|
|
|
222
|
-
[`bench/`](bench) compares this package with
|
|
223
|
+
[`bench/`](bench) compares this package with four other tools on mostly CC0 native pixel art (plus one CC-BY source). The
|
|
223
224
|
benchmark damages the art in known ways and scores each result against the original. Every tool
|
|
224
225
|
runs with its default settings.
|
|
225
226
|
|
|
226
227
|
AI suite (1746 cases in 12 categories, rendered the way generators fake pixel art):
|
|
227
228
|
|
|
228
|
-
| Method | Exact size | Within 1 cell | Pixel match | ΔE |
|
|
229
|
+
| Method | Exact size | Within 1 cell | Pixel match | ΔE | Fringe (alpha 1–254) | Median time |
|
|
229
230
|
| --- | --- | --- | --- | --- | --- | --- |
|
|
230
|
-
| Xprite Auto | **83.6%** | **90.0%** | **99.
|
|
231
|
+
| Xprite Auto | **83.6%** | **90.0%** | **99.7%** | 0.85 | 0.1% | 2.80 s |
|
|
231
232
|
| pixel-art-fixer | 49.7% | 80.9% | 98.3% | 1.74 | 0.0% | 0.18 s |
|
|
232
233
|
| perfectPixel | 53.3% | 68.0% | 96.7% | 2.42 | - | 0.03 s |
|
|
233
234
|
| proper-pixel-art | 72.2% | 80.4% | 99.7% | **0.64** | 0.0% | 0.49 s |
|
|
235
|
+
| Sprite Fusion Pixel Snapper | 56.8% | 77.9% | 98.5% | 1.93 | 91.0% | — |
|
|
234
236
|
|
|
235
237
|
Exact size per category:
|
|
236
238
|
|
|
237
|
-
| Category | Xprite | pixel-art-fixer | perfectPixel | proper-pixel-art |
|
|
238
|
-
| --- | --- | --- | --- | --- |
|
|
239
|
-
| Clean (`gen_clean`) | **93.6%** | 71.7% | 58.4% | 74.6% |
|
|
240
|
-
| Sparse canvas (`gen_sparse`) | **99.0%** | 63.5% | 71.9% | 88.5% |
|
|
241
|
-
| Off-white background (`gen_white`) | 77.7% | 65.2% | 66.1% | **82.1%** |
|
|
242
|
-
| Soft outline (`gen_soft_edge`) | **95.8%** | 61.9% | 67.8% | 82.2% |
|
|
243
|
-
| Drift and WebP (`gen_webp`) | **80.9%** | 40.5% | 57.8% | 71.1% |
|
|
244
|
-
| Halos and JPEG (`gen_halo_jpeg`) | **82.7%** | 52.6% | 60.1% | 72.8% |
|
|
245
|
-
| Painterly shading (`gen_painterly`) | **84.5%** | 39.1% | 67.8% | 79.3% |
|
|
246
|
-
| Small cells (4-8 px) (`gen_small_pitch`) | **72.2%** | 47.9% | 40.2% | 43.8% |
|
|
247
|
-
| Large cells (24-48 px) (`gen_large_pitch`) | 68.2% | 22.0% | 68.2% | **78.0%** |
|
|
248
|
-
| Strong drift (`gen_wobble`) | **73.3%** | 30.8% | 30.8% | 54.1% |
|
|
249
|
-
| Two sprites (`gen_pair`) | **97.1%** | 62.7% | 45.1% | 72.5% |
|
|
250
|
-
| Drop shadow (`gen_shadow`) | **97.3%** | 64.0% | 0.0% | 84.7% |
|
|
239
|
+
| Category | Xprite | pixel-art-fixer | perfectPixel | proper-pixel-art | Sprite Fusion |
|
|
240
|
+
| --- | --- | --- | --- | --- | --- |
|
|
241
|
+
| Clean (`gen_clean`) | **93.6%** | 71.7% | 58.4% | 74.6% | 56.6% |
|
|
242
|
+
| Sparse canvas (`gen_sparse`) | **99.0%** | 63.5% | 71.9% | 88.5% | 69.8% |
|
|
243
|
+
| Off-white background (`gen_white`) | 77.7% | 65.2% | 66.1% | **82.1%** | 78.6% |
|
|
244
|
+
| Soft outline (`gen_soft_edge`) | **95.8%** | 61.9% | 67.8% | 82.2% | 59.3% |
|
|
245
|
+
| Drift and WebP (`gen_webp`) | **80.9%** | 40.5% | 57.8% | 71.1% | 48.6% |
|
|
246
|
+
| Halos and JPEG (`gen_halo_jpeg`) | **82.7%** | 52.6% | 60.1% | 72.8% | 59.0% |
|
|
247
|
+
| Painterly shading (`gen_painterly`) | **84.5%** | 39.1% | 67.8% | 79.3% | 50.0% |
|
|
248
|
+
| Small cells (4-8 px) (`gen_small_pitch`) | **72.2%** | 47.9% | 40.2% | 43.8% | 42.6% |
|
|
249
|
+
| Large cells (24-48 px) (`gen_large_pitch`) | 68.2% | 22.0% | 68.2% | **78.0%** | 57.8% |
|
|
250
|
+
| Strong drift (`gen_wobble`) | **73.3%** | 30.8% | 30.8% | 54.1% | 49.4% |
|
|
251
|
+
| Two sprites (`gen_pair`) | **97.1%** | 62.7% | 45.1% | 72.5% | 60.8% |
|
|
252
|
+
| Drop shadow (`gen_shadow`) | **97.3%** | 64.0% | 0.0% | 84.7% | 68.5% |
|
|
251
253
|
|
|
252
254
|
[pixel-bench](https://github.com/Retro-Diffusion/pixel-bench) suite v1 (7651 cases of upscales and
|
|
253
255
|
lossy pipelines):
|
|
254
256
|
|
|
255
257
|
| Method | Exact size | Within 1 cell | Pixel match | ΔE | Median time |
|
|
256
258
|
| --- | --- | --- | --- | --- | --- |
|
|
257
|
-
| Xprite Auto | **87.1%** | **90.1%** | 94.
|
|
259
|
+
| Xprite Auto | **87.1%** | **90.1%** | 94.4% | **2.76** | 0.27 s |
|
|
258
260
|
| pixel-art-fixer | 77.8% | 83.5% | **94.4%** | 2.83 | 0.04 s |
|
|
259
261
|
| perfectPixel | 24.2% | 32.9% | 89.7% | 4.31 | 0.002 s |
|
|
260
262
|
| proper-pixel-art | 16.5% | 28.6% | 93.0% | 3.85 | 0.05 s |
|
|
263
|
+
| Sprite Fusion Pixel Snapper | 6.6% | 26.8% | 91.0% | 4.42 | — |
|
|
264
|
+
|
|
265
|
+
Pixel match, ΔE and fringe are measured only on each method's exact-size cases. The sample sets can differ, so these values are not directly comparable across methods. Fringe counts alpha values from 1 to 254, including nearly opaque pixels.
|
|
261
266
|
|
|
262
|
-
|
|
263
|
-
the four tools. The damage is synthetic, so the scores show how the tools rank on these features,
|
|
264
|
-
not how often they succeed on real images. [bench/README.md](bench/README.md) gives the method,
|
|
265
|
-
the categories and the steps to run it.
|
|
267
|
+
Each method uses its default color processing, so these are end-to-end results with different palettes. Timing methods also differ; measurements that include process startup and PNG I/O are omitted from the table. Results use the same cases and scoring code; some were recorded in an earlier run. Synthetic damage does not establish real-world success rates. See [bench/README.md](bench/README.md) for method versions, timing and reproduction.
|
|
266
268
|
|
|
267
269
|
## License
|
|
268
270
|
|
package/README.zh-CN.md
CHANGED
|
@@ -11,18 +11,19 @@
|
|
|
11
11
|
|
|
12
12
|
一张真实的 AI 生成图(887×887,格宽 15 到 21 像素不等),各工具用默认设置还原的结果。Xprite 把每一刀都切在颜色边缘上,所以不会切开眼睛、靴子和剑。
|
|
13
13
|
|
|
14
|
-
| 找到的网格 | Xprite,48×49 | [pixel-art-fixer](https://github.com/Retro-Diffusion/pixel-art-fixer),47×48 | [perfectPixel](https://github.com/theamusing/perfectPixel),50×50 | [proper-pixel-art](https://github.com/KennethJAllen/proper-pixel-art),53×54 |
|
|
15
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
16
|
-
|  |  |  |  |  |
|
|
14
|
+
| 找到的网格 | Xprite,48×49 | [pixel-art-fixer](https://github.com/Retro-Diffusion/pixel-art-fixer),47×48 | [perfectPixel](https://github.com/theamusing/perfectPixel),50×50 | [proper-pixel-art](https://github.com/KennethJAllen/proper-pixel-art),53×54 | [Sprite Fusion Pixel Snapper](https://github.com/Hugo-Dz/spritefusion-pixel-snapper),56×53 |
|
|
15
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
16
|
+
|  |  |  |  |  |  |
|
|
17
17
|
|
|
18
18
|
在[我们的基准测试](#基准测试)的 AI 套件(1746 个用例)上,Xprite 得到正确尺寸的次数最多:
|
|
19
19
|
|
|
20
|
-
| 方法 | 尺寸完全正确 | 差 1 格以内 | 像素一致率 |
|
|
20
|
+
| 方法 | 尺寸完全正确 | 差 1 格以内 | 像素一致率 | 毛边(alpha 1–254) | 中位耗时 |
|
|
21
21
|
| --- | --- | --- | --- | --- | --- |
|
|
22
|
-
| Xprite Auto | **83.6%** | **90.0%** | **99.
|
|
22
|
+
| Xprite Auto | **83.6%** | **90.0%** | **99.7%** | 0.1% | 2.80 s |
|
|
23
23
|
| pixel-art-fixer | 49.7% | 80.9% | 98.3% | 0.0% | 0.18 s |
|
|
24
24
|
| perfectPixel | 53.3% | 68.0% | 96.7% | - | 0.03 s |
|
|
25
25
|
| proper-pixel-art | 72.2% | 80.4% | 99.7% | 0.0% | 0.49 s |
|
|
26
|
+
| Sprite Fusion Pixel Snapper | 56.8% | 77.9% | 98.5% | 91.0% | — |
|
|
26
27
|
|
|
27
28
|
## 目录
|
|
28
29
|
|
|
@@ -35,55 +36,55 @@
|
|
|
35
36
|
|
|
36
37
|
## 示例
|
|
37
38
|
|
|
38
|
-
每个示例取自基准测试 AI 套件的一个类别:把 CC0
|
|
39
|
+
每个示例取自基准测试 AI 套件的一个类别:把 CC0 像素画按生成模型的方式渲染,原画尺寸已知。尺寸是可见画面的格数,✅ 表示与原画尺寸完全一致。每个工具都使用默认设置。
|
|
39
40
|
|
|
40
41
|
### 一张画布上的两个角色
|
|
41
42
|
|
|
42
43
|
- [哥布林,作者 LuizMelo](https://luizmelo.itch.io/monsters-creatures-fantasy),CC0。类别 `gen_pair`。原画:78×36。
|
|
43
44
|
|
|
44
|
-
| 输入,1800×845 | Xprite,78×36
|
|
45
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
46
|
-
|  |  |  |  |  |
|
|
45
|
+
| 输入,1800×845 | Xprite,78×36 ✅ | pixel-art-fixer,78×35 ❌ | perfectPixel,80×36 ❌ | proper-pixel-art,79×36 ❌ | Sprite Fusion,78×36 ✅ |
|
|
46
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
47
|
+
|  |  |  |  |  |  |
|
|
47
48
|
|
|
48
49
|
### 格子漂移和抖动
|
|
49
50
|
|
|
50
51
|
- [巨龙,作者 ansimuz](https://opengameart.org/content/sideview-fantasy-patreon-collection),CC0。类别 `gen_wobble`。原画:71×39。
|
|
51
52
|
|
|
52
|
-
| 输入,1226×664 | Xprite,71×39
|
|
53
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
54
|
-
|  |  |  |  |  |
|
|
53
|
+
| 输入,1226×664 | Xprite,71×39 ✅ | pixel-art-fixer,69×38 ❌ | perfectPixel,74×39 ❌ | proper-pixel-art,69×38 ❌ | Sprite Fusion,71×38 ❌ |
|
|
54
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
55
|
+
|  |  |  |  |  |  |
|
|
55
56
|
|
|
56
57
|
### 小格子和 WebP 压缩损伤
|
|
57
58
|
|
|
58
59
|
- [怪物,作者 Denzi](https://opengameart.org/content/denzis-public-domain-art),CC0。类别 `gen_small_pitch`。原画:32×48。
|
|
59
60
|
|
|
60
|
-
| 输入,218×339 | Xprite,32×48
|
|
61
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
62
|
-
|  |  |  |  |  |
|
|
61
|
+
| 输入,218×339 | Xprite,32×48 ✅ | pixel-art-fixer,32×47 ❌ | perfectPixel,32×49 ❌ | proper-pixel-art,34×49 ❌ | Sprite Fusion,32×48 ✅ |
|
|
62
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
63
|
+
|  |  |  |  |  |  |
|
|
63
64
|
|
|
64
65
|
### 大块透明画布上的小角色
|
|
65
66
|
|
|
66
67
|
- [猫耳少女,作者 cawfeecrow](https://opengameart.org/content/nekomimi-girl-portrait),CC0。类别 `gen_sparse`。原画:123×136。
|
|
67
68
|
|
|
68
|
-
| 输入,1797×1800 | Xprite,123×136
|
|
69
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
70
|
-
|  |  |  |  |  |
|
|
69
|
+
| 输入,1797×1800 | Xprite,123×136 ✅ | pixel-art-fixer,122×136 ❌ | perfectPixel,124×136 ❌ | proper-pixel-art,127×142 ❌ | Sprite Fusion,118×133 ❌ |
|
|
70
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
71
|
+
|  |  |  |  |  |  |
|
|
71
72
|
|
|
72
73
|
### 近白色背景
|
|
73
74
|
|
|
74
75
|
- [飞龙,作者 ansimuz](https://opengameart.org/content/sideview-fantasy-patreon-collection),CC0。类别 `gen_white`。原画:162×106。
|
|
75
76
|
|
|
76
|
-
| 输入,1800×1210 | Xprite,162×106
|
|
77
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
78
|
-
|  |  |  |  |  |
|
|
77
|
+
| 输入,1800×1210 | Xprite,162×106 ✅ | pixel-art-fixer,325×208 ❌ | perfectPixel,161×105 ❌ | proper-pixel-art,168×106 ❌ | Sprite Fusion,162×106 ✅ |
|
|
78
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
79
|
+
|  |  |  |  |  |  |
|
|
79
80
|
|
|
80
81
|
### 格内有绘画式明暗
|
|
81
82
|
|
|
82
83
|
- [娜迦法师,Dungeon Crawl Stone Soup](https://github.com/crawl/tiles),CC0。类别 `gen_painterly`。原画:31×32。
|
|
83
84
|
|
|
84
|
-
| 输入,411×425 | Xprite,31×32
|
|
85
|
-
| :---: | :---: | :---: | :---: | :---: |
|
|
86
|
-
|  |  |  |  |  |
|
|
85
|
+
| 输入,411×425 | Xprite,31×32 ✅ | pixel-art-fixer,30×33 ❌ | perfectPixel,31×32 ✅ | proper-pixel-art,31×34 ❌ | Sprite Fusion,31×32 ✅ |
|
|
86
|
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
87
|
+
|  |  |  |  |  |  |
|
|
87
88
|
|
|
88
89
|
## 安装
|
|
89
90
|
|
|
@@ -196,44 +197,48 @@ const grid = await detectWithAlgorithmAsync(image);
|
|
|
196
197
|
|
|
197
198
|
## 基准测试
|
|
198
199
|
|
|
199
|
-
[`bench/`](bench)
|
|
200
|
+
[`bench/`](bench) 在以 CC0 为主(另有一个 CC-BY 来源)的原生像素画上比较本包和另外四个工具。基准测试以已知方式损伤原画,再把每个结果和原画对比打分。每个工具都使用默认设置。
|
|
200
201
|
|
|
201
202
|
AI 套件(12 个类别共 1746 个用例,按生成模型伪造像素画的方式渲染):
|
|
202
203
|
|
|
203
|
-
| 方法 | 尺寸完全正确 | 差 1 格以内 | 像素一致率 | ΔE |
|
|
204
|
+
| 方法 | 尺寸完全正确 | 差 1 格以内 | 像素一致率 | ΔE | 毛边(alpha 1–254) | 中位耗时 |
|
|
204
205
|
| --- | --- | --- | --- | --- | --- | --- |
|
|
205
|
-
| Xprite Auto | **83.6%** | **90.0%** | **99.
|
|
206
|
+
| Xprite Auto | **83.6%** | **90.0%** | **99.7%** | 0.85 | 0.1% | 2.80 s |
|
|
206
207
|
| pixel-art-fixer | 49.7% | 80.9% | 98.3% | 1.74 | 0.0% | 0.18 s |
|
|
207
208
|
| perfectPixel | 53.3% | 68.0% | 96.7% | 2.42 | - | 0.03 s |
|
|
208
209
|
| proper-pixel-art | 72.2% | 80.4% | 99.7% | **0.64** | 0.0% | 0.49 s |
|
|
210
|
+
| Sprite Fusion Pixel Snapper | 56.8% | 77.9% | 98.5% | 1.93 | 91.0% | — |
|
|
209
211
|
|
|
210
212
|
各类别的尺寸完全正确率:
|
|
211
213
|
|
|
212
|
-
| 类别 | Xprite | pixel-art-fixer | perfectPixel | proper-pixel-art |
|
|
213
|
-
| --- | --- | --- | --- | --- |
|
|
214
|
-
| 干净 (`gen_clean`) | **93.6%** | 71.7% | 58.4% | 74.6% |
|
|
215
|
-
| 稀疏画布 (`gen_sparse`) | **99.0%** | 63.5% | 71.9% | 88.5% |
|
|
216
|
-
| 近白色背景 (`gen_white`) | 77.7% | 65.2% | 66.1% | **82.1%** |
|
|
217
|
-
| 柔和轮廓 (`gen_soft_edge`) | **95.8%** | 61.9% | 67.8% | 82.2% |
|
|
218
|
-
| 漂移和 WebP (`gen_webp`) | **80.9%** | 40.5% | 57.8% | 71.1% |
|
|
219
|
-
| 光晕和 JPEG (`gen_halo_jpeg`) | **82.7%** | 52.6% | 60.1% | 72.8% |
|
|
220
|
-
| 绘画式明暗 (`gen_painterly`) | **84.5%** | 39.1% | 67.8% | 79.3% |
|
|
221
|
-
| 小格子(4-8 px) (`gen_small_pitch`) | **72.2%** | 47.9% | 40.2% | 43.8% |
|
|
222
|
-
| 大格子(24-48 px) (`gen_large_pitch`) | 68.2% | 22.0% | 68.2% | **78.0%** |
|
|
223
|
-
| 强漂移 (`gen_wobble`) | **73.3%** | 30.8% | 30.8% | 54.1% |
|
|
224
|
-
| 两个角色 (`gen_pair`) | **97.1%** | 62.7% | 45.1% | 72.5% |
|
|
225
|
-
| 投影 (`gen_shadow`) | **97.3%** | 64.0% | 0.0% | 84.7% |
|
|
214
|
+
| 类别 | Xprite | pixel-art-fixer | perfectPixel | proper-pixel-art | Sprite Fusion |
|
|
215
|
+
| --- | --- | --- | --- | --- | --- |
|
|
216
|
+
| 干净 (`gen_clean`) | **93.6%** | 71.7% | 58.4% | 74.6% | 56.6% |
|
|
217
|
+
| 稀疏画布 (`gen_sparse`) | **99.0%** | 63.5% | 71.9% | 88.5% | 69.8% |
|
|
218
|
+
| 近白色背景 (`gen_white`) | 77.7% | 65.2% | 66.1% | **82.1%** | 78.6% |
|
|
219
|
+
| 柔和轮廓 (`gen_soft_edge`) | **95.8%** | 61.9% | 67.8% | 82.2% | 59.3% |
|
|
220
|
+
| 漂移和 WebP (`gen_webp`) | **80.9%** | 40.5% | 57.8% | 71.1% | 48.6% |
|
|
221
|
+
| 光晕和 JPEG (`gen_halo_jpeg`) | **82.7%** | 52.6% | 60.1% | 72.8% | 59.0% |
|
|
222
|
+
| 绘画式明暗 (`gen_painterly`) | **84.5%** | 39.1% | 67.8% | 79.3% | 50.0% |
|
|
223
|
+
| 小格子(4-8 px) (`gen_small_pitch`) | **72.2%** | 47.9% | 40.2% | 43.8% | 42.6% |
|
|
224
|
+
| 大格子(24-48 px) (`gen_large_pitch`) | 68.2% | 22.0% | 68.2% | **78.0%** | 57.8% |
|
|
225
|
+
| 强漂移 (`gen_wobble`) | **73.3%** | 30.8% | 30.8% | 54.1% | 49.4% |
|
|
226
|
+
| 两个角色 (`gen_pair`) | **97.1%** | 62.7% | 45.1% | 72.5% | 60.8% |
|
|
227
|
+
| 投影 (`gen_shadow`) | **97.3%** | 64.0% | 0.0% | 84.7% | 68.5% |
|
|
226
228
|
|
|
227
229
|
[pixel-bench](https://github.com/Retro-Diffusion/pixel-bench) v1 套件(7651 个放大和有损处理用例):
|
|
228
230
|
|
|
229
231
|
| 方法 | 尺寸完全正确 | 差 1 格以内 | 像素一致率 | ΔE | 中位耗时 |
|
|
230
232
|
| --- | --- | --- | --- | --- | --- |
|
|
231
|
-
| Xprite Auto | **87.1%** | **90.1%** | 94.
|
|
233
|
+
| Xprite Auto | **87.1%** | **90.1%** | 94.4% | **2.76** | 0.27 s |
|
|
232
234
|
| pixel-art-fixer | 77.8% | 83.5% | **94.4%** | 2.83 | 0.04 s |
|
|
233
235
|
| perfectPixel | 24.2% | 32.9% | 89.7% | 4.31 | 0.002 s |
|
|
234
236
|
| proper-pixel-art | 16.5% | 28.6% | 93.0% | 3.85 | 0.05 s |
|
|
237
|
+
| Sprite Fusion Pixel Snapper | 6.6% | 26.8% | 91.0% | 4.42 | — |
|
|
238
|
+
|
|
239
|
+
像素一致率、ΔE 和毛边只在各方法尺寸完全正确的用例上统计。样本集合可能不同,这些数值不能在方法之间直接比较。毛边统计包含 alpha 为 1 至 254 的像素,包括接近不透明的像素。
|
|
235
240
|
|
|
236
|
-
|
|
241
|
+
各方法使用默认颜色处理方式,调色板可能不同;表中是端到端结果。计时方式也有差异,包含进程启动和 PNG 读写的计时未列入表格。所有结果使用相同的用例和评分代码,部分结果来自先前的运行。损伤是合成的,不能代表真实图片的成功率。各方法的版本、计时口径和复现方法见 [bench/README.md](bench/README.md)。
|
|
237
242
|
|
|
238
243
|
## 许可证
|
|
239
244
|
|
package/dist/grid-sample.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getColorPickerEntry } from "./cell-color-picker.js";
|
|
2
2
|
import { MAX_RECOVERED_GRID_SIZE, pixelGridCuts } from "./grid.js";
|
|
3
|
+
import { settleEdgeAlpha } from "./pixel-alpha.js";
|
|
3
4
|
import { samplePixelation } from "./sampling.js";
|
|
4
5
|
import { CellColorPicker, PixelationMethod, } from "./types.js";
|
|
5
6
|
const CHANNELS = 4;
|
|
@@ -43,82 +44,6 @@ function roundTripError(input, candidate, cells) {
|
|
|
43
44
|
}
|
|
44
45
|
return pixelCount > 0 ? errorSum / pixelCount : 0;
|
|
45
46
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Pixel art is drawn with whole pixels: a cell is either covered or clear. A generated or resampled
|
|
48
|
-
* sprite carries a soft edge instead: the pixels along its outline are partly transparent, and its
|
|
49
|
-
* covered pixels often sit a little below full opacity. Averaged into cells, that leaves a
|
|
50
|
-
* half-transparent ring around the recovered sprite and an almost-opaque inside.
|
|
51
|
-
*
|
|
52
|
-
* A cell that holds both covered pixels (alpha of at least HALF_ALPHA) and uncovered ones lies on
|
|
53
|
-
* the outline. In translucent art, a cell with no covered pixel takes the median alpha of its
|
|
54
|
-
* pixels: a shadow keeps its level, a soft outline (mostly clear) is cleared. It is in the art when its covered pixels fill at least half of it, and clear
|
|
55
|
-
* otherwise; in opaque art, so is a cell with no covered pixel. A covered cell takes the mean alpha of its covered pixels, raised to OPAQUE when the
|
|
56
|
-
* source's art is opaque: at most TRANSLUCENT_SHARE of its visible pixels between TRANSLUCENT_LOW
|
|
57
|
-
* and TRANSLUCENT_HIGH. Art drawn translucent (glass, shadows, glow) keeps its alpha, except that a
|
|
58
|
-
* covered cell above TRANSLUCENT_HIGH is still raised to OPAQUE.
|
|
59
|
-
*/
|
|
60
|
-
const HALF_ALPHA = 128;
|
|
61
|
-
const HALF = 0.5;
|
|
62
|
-
const OPAQUE = 255;
|
|
63
|
-
const TRANSLUCENT_LOW = 16;
|
|
64
|
-
const TRANSLUCENT_HIGH = 224;
|
|
65
|
-
/** Share of the visible pixels a soft outline around opaque art stays below. */
|
|
66
|
-
const TRANSLUCENT_SHARE = 0.2;
|
|
67
|
-
/** Whether the image's visible pixels are opaque but for a soft edge. */
|
|
68
|
-
function opaqueArt(image) {
|
|
69
|
-
let visible = 0, translucent = 0;
|
|
70
|
-
for (let o = COLOR_CHANNELS; o < image.data.length; o += CHANNELS) {
|
|
71
|
-
const alpha = image.data[o];
|
|
72
|
-
if (!alpha)
|
|
73
|
-
continue;
|
|
74
|
-
visible++;
|
|
75
|
-
if (alpha >= TRANSLUCENT_LOW && alpha <= TRANSLUCENT_HIGH)
|
|
76
|
-
translucent++;
|
|
77
|
-
}
|
|
78
|
-
return visible > 0 && translucent <= TRANSLUCENT_SHARE * visible;
|
|
79
|
-
}
|
|
80
|
-
function settleEdgeAlpha(image, x, y, out) {
|
|
81
|
-
const opaque = opaqueArt(image);
|
|
82
|
-
for (let row = 0; row < out.height; row++)
|
|
83
|
-
for (let column = 0; column < out.width; column++) {
|
|
84
|
-
const offset = (row * out.width + column) * CHANNELS;
|
|
85
|
-
if (!out.data[offset + COLOR_CHANNELS])
|
|
86
|
-
continue;
|
|
87
|
-
const left = Math.max(0, Math.ceil(x[column])), right = Math.min(image.width, Math.ceil(x[column + 1])), top = Math.max(0, Math.ceil(y[row])), bottom = Math.min(image.height, Math.ceil(y[row + 1]));
|
|
88
|
-
let covered = 0, coveredAlpha = 0;
|
|
89
|
-
const alphas = [];
|
|
90
|
-
for (let py = top; py < bottom; py++)
|
|
91
|
-
for (let px = left; px < right; px++) {
|
|
92
|
-
const alpha = image.data[(py * image.width + px) * CHANNELS + COLOR_CHANNELS];
|
|
93
|
-
alphas.push(alpha);
|
|
94
|
-
if (alpha < HALF_ALPHA)
|
|
95
|
-
continue;
|
|
96
|
-
covered++;
|
|
97
|
-
coveredAlpha += alpha;
|
|
98
|
-
}
|
|
99
|
-
const area = (right - left) * (bottom - top);
|
|
100
|
-
if (!covered && !opaque) {
|
|
101
|
-
// Translucent art fills its cell evenly; a soft outline leaves most of the cell clear.
|
|
102
|
-
alphas.sort((a, b) => a - b);
|
|
103
|
-
const median = alphas[alphas.length >> 1] ?? 0;
|
|
104
|
-
if (median < TRANSLUCENT_LOW)
|
|
105
|
-
out.data.fill(0, offset, offset + CHANNELS);
|
|
106
|
-
else
|
|
107
|
-
out.data[offset + COLOR_CHANNELS] = median;
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
if (covered < HALF * area)
|
|
111
|
-
out.data.fill(0, offset, offset + CHANNELS);
|
|
112
|
-
else if (opaque)
|
|
113
|
-
out.data[offset + COLOR_CHANNELS] = OPAQUE;
|
|
114
|
-
else {
|
|
115
|
-
// Translucent art (a shadow, a glow) keeps its alpha, but a covered cell above
|
|
116
|
-
// TRANSLUCENT_HIGH is opaque art drawn a little below 255, as everywhere else.
|
|
117
|
-
const alpha = covered < area ? coveredAlpha / covered : out.data[offset + COLOR_CHANNELS];
|
|
118
|
-
out.data[offset + COLOR_CHANNELS] = alpha > TRANSLUCENT_HIGH ? OPAQUE : Math.round(alpha);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
47
|
/** One RGBA pixel per grid cell: explicit cuts when the grid carries them, else one regular lattice. */
|
|
123
48
|
export function recoverGrid(image, grid, picker = CellColorPicker.MostCommon) {
|
|
124
49
|
const x = grid.cutsX ?? pixelGridCuts(image.width, grid.cellWidth, grid.offsetX), y = grid.cutsY ?? pixelGridCuts(image.height, grid.cellHeight, grid.offsetY);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { analyzePixelArt, analyzePixelArtAsync } from "./analyze.ts";
|
|
2
2
|
export { extractPalette, extractPixelationPalette, countDistinctColors, reduceToPalette, } from "./palette.ts";
|
|
3
3
|
export { snapPalette } from "./palette-snap.ts";
|
|
4
|
+
export { removeOrphanPixels, type RemoveOrphanPixelsOptions } from "./orphan-pixels.ts";
|
|
5
|
+
export { settlePixelAlpha } from "./pixel-alpha.ts";
|
|
4
6
|
export { estimateTilt, straighten, MAX_TILT_DEGREES } from "./deskew.ts";
|
|
5
7
|
export { resizeNearest } from "./resize.ts";
|
|
6
8
|
export { pixelateImage, pixelateImageAsync } from "./pixelate.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { analyzePixelArt, analyzePixelArtAsync } from "./analyze.js";
|
|
2
2
|
export { extractPalette, extractPixelationPalette, countDistinctColors, reduceToPalette, } from "./palette.js";
|
|
3
3
|
export { snapPalette } from "./palette-snap.js";
|
|
4
|
+
export { removeOrphanPixels } from "./orphan-pixels.js";
|
|
5
|
+
export { settlePixelAlpha } from "./pixel-alpha.js";
|
|
4
6
|
export { estimateTilt, straighten, MAX_TILT_DEGREES } from "./deskew.js";
|
|
5
7
|
export { resizeNearest } from "./resize.js";
|
|
6
8
|
export { pixelateImage, pixelateImageAsync } from "./pixelate.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type PixelBuffer } from "./base.ts";
|
|
2
|
+
export interface RemoveOrphanPixelsOptions {
|
|
3
|
+
/** Replace isolated interior colors. Disable this for dithered art. Defaults to true. */
|
|
4
|
+
absorbInterior?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Clear fully opaque pixels separated from visible art on all four sides. In an opaque interior,
|
|
8
|
+
* replace a color unsupported by all eight neighbors only if those neighbors have a strict
|
|
9
|
+
* majority color. Decisions use the original pixels and never change the input buffer.
|
|
10
|
+
*/
|
|
11
|
+
export declare function removeOrphanPixels(image: PixelBuffer, { absorbInterior }?: RemoveOrphanPixelsOptions): PixelBuffer;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { assertPixelBuffer, UINT8_MAX } from "./base.js";
|
|
2
|
+
const CHANNELS = 4;
|
|
3
|
+
const ALPHA = 3;
|
|
4
|
+
function rgbAt(data, offset) {
|
|
5
|
+
return (data[offset] << 16) | (data[offset + 1] << 8) | data[offset + 2];
|
|
6
|
+
}
|
|
7
|
+
function majorityNeighborColor(data, offset, neighbors, colors) {
|
|
8
|
+
const center = rgbAt(data, offset);
|
|
9
|
+
let candidate = 0;
|
|
10
|
+
let votes = 0;
|
|
11
|
+
for (let i = 0; i < neighbors.length; i++) {
|
|
12
|
+
const neighbor = offset + neighbors[i];
|
|
13
|
+
if (data[neighbor + ALPHA] !== UINT8_MAX)
|
|
14
|
+
return;
|
|
15
|
+
const color = rgbAt(data, neighbor);
|
|
16
|
+
if (color === center)
|
|
17
|
+
return;
|
|
18
|
+
colors[i] = color;
|
|
19
|
+
// Cancel opposing votes, then verify the candidate has a strict majority.
|
|
20
|
+
if (votes === 0)
|
|
21
|
+
candidate = color;
|
|
22
|
+
votes += color === candidate ? 1 : -1;
|
|
23
|
+
}
|
|
24
|
+
if (votes === 0)
|
|
25
|
+
return;
|
|
26
|
+
let count = 0;
|
|
27
|
+
for (const color of colors)
|
|
28
|
+
if (color === candidate)
|
|
29
|
+
count++;
|
|
30
|
+
if (count > neighbors.length / 2)
|
|
31
|
+
return candidate;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Clear fully opaque pixels separated from visible art on all four sides. In an opaque interior,
|
|
35
|
+
* replace a color unsupported by all eight neighbors only if those neighbors have a strict
|
|
36
|
+
* majority color. Decisions use the original pixels and never change the input buffer.
|
|
37
|
+
*/
|
|
38
|
+
export function removeOrphanPixels(image, { absorbInterior = true } = {}) {
|
|
39
|
+
assertPixelBuffer(image);
|
|
40
|
+
const { width, height, data } = image;
|
|
41
|
+
if (width === 1 && height === 1)
|
|
42
|
+
return image;
|
|
43
|
+
const stride = width * CHANNELS;
|
|
44
|
+
const neighbors = [
|
|
45
|
+
-CHANNELS, CHANNELS, -stride, stride,
|
|
46
|
+
-stride - CHANNELS, -stride + CHANNELS, stride - CHANNELS, stride + CHANNELS,
|
|
47
|
+
];
|
|
48
|
+
const colors = new Uint32Array(neighbors.length);
|
|
49
|
+
let output;
|
|
50
|
+
for (let y = 0; y < height; y++)
|
|
51
|
+
for (let x = 0; x < width; x++) {
|
|
52
|
+
const offset = y * stride + x * CHANNELS;
|
|
53
|
+
const alpha = offset + ALPHA;
|
|
54
|
+
if (data[alpha] !== UINT8_MAX)
|
|
55
|
+
continue;
|
|
56
|
+
if ((x === 0 || data[alpha - CHANNELS] === 0) &&
|
|
57
|
+
(x === width - 1 || data[alpha + CHANNELS] === 0) &&
|
|
58
|
+
(y === 0 || data[alpha - stride] === 0) &&
|
|
59
|
+
(y === height - 1 || data[alpha + stride] === 0)) {
|
|
60
|
+
(output ??= data.slice()).fill(0, offset, offset + CHANNELS);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!absorbInterior || x === 0 || y === 0 || x === width - 1 || y === height - 1)
|
|
64
|
+
continue;
|
|
65
|
+
const replacement = majorityNeighborColor(data, offset, neighbors, colors);
|
|
66
|
+
if (replacement === undefined)
|
|
67
|
+
continue;
|
|
68
|
+
output ??= data.slice();
|
|
69
|
+
output[offset] = replacement >> 16;
|
|
70
|
+
output[offset + 1] = (replacement >> 8) & 255;
|
|
71
|
+
output[offset + 2] = replacement & 255;
|
|
72
|
+
}
|
|
73
|
+
return output ? { ...image, data: output } : image;
|
|
74
|
+
}
|