depixel 0.0.4 → 1.0.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.
Files changed (3) hide show
  1. package/README.md +6 -2
  2. package/lib.js +16 -8
  3. 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,12 @@ 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(yA - yB) <= (48.0 / 255.0) * t) {
92
- if (Math.abs(uA - uB) <= (7.0 / 255.0) * t) {
93
- if (Math.abs(vA - vB) <= (6.0 / 255.0) * t) {
94
- return true;
91
+ if (Math.abs(a[3] - b[3]) <= (32.0/255) * t) {
92
+ if (Math.abs(yA - yB) <= (48.0 / 255.0) * t) {
93
+ if (Math.abs(uA - uB) <= (7.0 / 255.0) * t) {
94
+ if (Math.abs(vA - vB) <= (6.0 / 255.0) * t) {
95
+ return true;
96
+ }
95
97
  }
96
98
  }
97
99
  }
@@ -1813,17 +1815,23 @@ function scaleImage(src, opts) {
1813
1815
 
1814
1816
  const borderPx = Math.max(0, Math.round(opts.borderPx || 0));
1815
1817
  if (borderPx > 0) {
1818
+ const doInvisBorder = Math.min(
1819
+ src.data[3],
1820
+ src.data[(inW - 1) * 4 + 3],
1821
+ src.data[(inH - 1) * inW * 4 + 3],
1822
+ src.data[((inH - 1) * inW + (inW - 1)) * 4 + 3],
1823
+ ) < 255;
1816
1824
  const padW = inW + 2 * borderPx;
1817
1825
  const padH = inH + 2 * borderPx;
1818
1826
  const padData = new Uint8Array(padW * padH * 4);
1819
- // fill magenta border
1827
+ // fill magenta border (invisible if original image appears to have invisible edges)
1820
1828
  for (let y = 0; y < padH; y++) {
1821
1829
  for (let x = 0; x < padW; x++) {
1822
1830
  const idx = (y * padW + x) * 4;
1823
- padData[idx] = 255;
1831
+ padData[idx] = doInvisBorder ? 0 : 255;
1824
1832
  padData[idx + 1] = 0;
1825
- padData[idx + 2] = 255;
1826
- padData[idx + 3] = 255;
1833
+ padData[idx + 2] = doInvisBorder ? 0 : 255;
1834
+ padData[idx + 3] = doInvisBorder ? 0 : 255;
1827
1835
  }
1828
1836
  }
1829
1837
  // copy src into center
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "depixel",
3
- "version": "0.0.4",
3
+ "version": "1.0.1",
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"