diff --git a/dither-image.js b/dither-image.js index 1b6ca30..58cb9bf 100644 --- a/dither-image.js +++ b/dither-image.js @@ -651,13 +651,23 @@ function decimate(input, palette, n) { rgb = rgb.multiply(brightest / avg_luma).clamp(); } + // this also works pretty ok + // but i think keeping luma is better + // /* // 1) take the brightest luma // 2) take the most saturated chroma // 3) profit! let lumas = bucket.map((rgb) => rgb.luma()); - let luma = Math.max(...lumas); - let rgb = bucket[lumas.indexOf(luma)]; + let brightest = Math.max(...lumas); + let saturations = bucket.map((rgb) => Math.max(rgb.r, rgb.g, rgb.b) - Math.min(rgb.r, rgb.g, rgb.b)); + let saturation = Math.max(...saturations); + let saturatedIndex = saturations.indexOf(saturation); + let rgb = bucket[saturatedIndex]; + let luma = rgb.luma(); + if (luma > 0) { + rgb = rgb.multiply(brightest / luma).clamp(); + } */ // pick the luma-brightest color in the bucket