diff --git a/dither4.js b/dither4.js index 9721a30..e487fdb 100644 --- a/dither4.js +++ b/dither4.js @@ -397,12 +397,6 @@ function decimate(input, palette, n) { for (let i = 0; i < palette.length; i++) { let diff = rgb.difference(palette[i]); let dist = diff.magnitude(); - /* - let darker = Math.min(diff.r, diff.g, diff.b) < 0; - if (darker) { - dist **= 2; - } - */ if (dist < shortest) { nextError = diff; shortest = dist; @@ -436,27 +430,28 @@ function decimate(input, palette, n) { error.blue[x] += nextError.b / 2; */ - error.right.r = nextError.r / 4; - error.right.g = nextError.g / 4; - error.right.b = nextError.b / 4; if (x == 159) { - error.red[0] = error.right.r; - error.green[0] = error.right.g; - error.blue[0] = error.right.b; + error.red[x] += error.right.r; + error.green[x] += error.right.g; + error.blue[x] += error.right.b; + } else { + error.right.r = nextError.r / 4; + error.right.g = nextError.g / 4; + error.right.b = nextError.b / 4; + + error.red[x - 1] += nextError.r / 4; + error.green[x - 1] += nextError.g / 4; + error.blue[x - 1] += nextError.b / 4; + + error.red[x] += nextError.r / 4; + error.green[x] += nextError.g / 4; + error.blue[x] += nextError.b / 4; + + error.red[x + 1] += nextError.r / 4; + error.green[x + 1] += nextError.g / 4; + error.blue[x + 1] += nextError.b / 4; } - error.red[x - 1] += nextError.r / 4; - error.green[x - 1] += nextError.g / 4; - error.blue[x - 1] += nextError.b / 4; - - error.red[x] += nextError.r / 4; - error.green[x] += nextError.g / 4; - error.blue[x] += nextError.b / 4; - - error.red[x + 1] += nextError.r / 4; - error.green[x + 1] += nextError.g / 4; - error.blue[x + 1] += nextError.b / 4; - /* error.right.r = nextError.r / 4; error.right.g = nextError.g / 4; @@ -538,16 +533,16 @@ function decimate(input, palette, n) { if (i == 0) { continue; // keep black always } - if (decimated[i].r == 255 && decimated[i].g == 255 && decimated[i].b == 255) { - //continue; // keep white always - } //let coolFactor = popularity[i]; let coolFactor = 0; - for (let x = 0; x < line.length; x++) { - if (output[x] == i) { - coolFactor += (fitness[x] ** 2); + if (popularity[i]) { + for (let x = 0; x < line.length; x++) { + if (output[x] == i) { + //coolFactor += (fitness[x] ** 2); + coolFactor += (fitness[x] ** 4); + } } }