depixel 1.0.0 → 1.0.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/README.md +6 -2
- package/lib.js +21 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,10 +2,14 @@ Kopf-Lischinski "Depixelizing Pixel Art" for Node.js
|
|
|
2
2
|
====================================================
|
|
3
3
|
|
|
4
4
|
Based on the following paper:
|
|
5
|
-
* [Depixelizing Pixel Art](https://johanneskopf.de/publications/pixelart/)
|
|
5
|
+
* [Depixelizing Pixel Art](https://johanneskopf.de/publications/pixelart/) by Johannes Kopf & Dani Lischinski
|
|
6
6
|
|
|
7
7
|
And the [source code](https://github.com/falichs/Depixelizing-Pixel-Art-on-GPUs) included with this paper:
|
|
8
|
-
* [Depixelizing Pixel Art on GPUs](https://www.cg.tuwien.ac.at/research/publications/2014/KREUZER-2014-DPA/)
|
|
8
|
+
* [Depixelizing Pixel Art on GPUs](https://www.cg.tuwien.ac.at/research/publications/2014/KREUZER-2014-DPA/) by Felix Kreuzer
|
|
9
|
+
|
|
10
|
+
Improvements upon original
|
|
11
|
+
* Add a threshold parameter to adjust how close two colors need to be to be consider similar
|
|
12
|
+
* Better handle alpha channels (treat as dissimilar from non-transparent pixels)
|
|
9
13
|
|
|
10
14
|
Notes
|
|
11
15
|
* Original GPU code is MIT licensed, the same license may apply here, all original code in this project is additionally released under the MIT License
|
package/lib.js
CHANGED
|
@@ -88,10 +88,17 @@ function isSimilar(a, b, threshold) {
|
|
|
88
88
|
const uB = 0.493 * (b[2] - yB);
|
|
89
89
|
const vB = 0.877 * (b[0] - yB);
|
|
90
90
|
const t = Math.max(0, Math.min(255, threshold | 0)) / 255.0;
|
|
91
|
-
if (Math.abs(
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
if (Math.abs(a[3] - b[3]) <= (32.0/255) * t) {
|
|
92
|
+
if (a[3] + b[3] <= (32.0/255) * t) {
|
|
93
|
+
// treat all alpha=0 pixels as similar, regardless of color
|
|
94
|
+
// note: need an option for this if processing images with masks or premultiplied alpha
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (Math.abs(yA - yB) <= (48.0 / 255.0) * t) {
|
|
98
|
+
if (Math.abs(uA - uB) <= (7.0 / 255.0) * t) {
|
|
99
|
+
if (Math.abs(vA - vB) <= (6.0 / 255.0) * t) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
95
102
|
}
|
|
96
103
|
}
|
|
97
104
|
}
|
|
@@ -1813,17 +1820,23 @@ function scaleImage(src, opts) {
|
|
|
1813
1820
|
|
|
1814
1821
|
const borderPx = Math.max(0, Math.round(opts.borderPx || 0));
|
|
1815
1822
|
if (borderPx > 0) {
|
|
1823
|
+
const doInvisBorder = Math.min(
|
|
1824
|
+
src.data[3],
|
|
1825
|
+
src.data[(inW - 1) * 4 + 3],
|
|
1826
|
+
src.data[(inH - 1) * inW * 4 + 3],
|
|
1827
|
+
src.data[((inH - 1) * inW + (inW - 1)) * 4 + 3],
|
|
1828
|
+
) < 255;
|
|
1816
1829
|
const padW = inW + 2 * borderPx;
|
|
1817
1830
|
const padH = inH + 2 * borderPx;
|
|
1818
1831
|
const padData = new Uint8Array(padW * padH * 4);
|
|
1819
|
-
// fill magenta border
|
|
1832
|
+
// fill magenta border (invisible if original image appears to have invisible edges)
|
|
1820
1833
|
for (let y = 0; y < padH; y++) {
|
|
1821
1834
|
for (let x = 0; x < padW; x++) {
|
|
1822
1835
|
const idx = (y * padW + x) * 4;
|
|
1823
|
-
padData[idx] = 255;
|
|
1836
|
+
padData[idx] = doInvisBorder ? 0 : 255;
|
|
1824
1837
|
padData[idx + 1] = 0;
|
|
1825
|
-
padData[idx + 2] = 255;
|
|
1826
|
-
padData[idx + 3] = 255;
|
|
1838
|
+
padData[idx + 2] = doInvisBorder ? 0 : 255;
|
|
1839
|
+
padData[idx + 3] = doInvisBorder ? 0 : 255;
|
|
1827
1840
|
}
|
|
1828
1841
|
}
|
|
1829
1842
|
// copy src into center
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "depixel",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Depixelizing Pixel Art by Kopf-Lischinski and Felix Kreuzer for Node.js",
|
|
5
5
|
"main": "lib.js",
|
|
6
6
|
"keywords": [
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"upscale"
|
|
10
10
|
],
|
|
11
11
|
"author": "Jimb Esser (https://github.com/Jimbly)",
|
|
12
|
-
"homepage": "https://github.com/Jimbly/depixel-js",
|
|
12
|
+
"homepage": "https://github.com/Jimbly/depixel-js#readme",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git+https://github.com/Jimbly/npm-publish.git"
|