skarab42 / lw.canvas-filters

Canvas filters for LaserWeb
MIT License
1 stars 2 forks source link

[Feature request] Include dithering #1

Open jorgerobles opened 7 years ago

jorgerobles commented 7 years ago

Hi @lautr3k we have a crush on dithering on this thread https://plus.google.com/+ClaudioPrezzi/posts/2aVG4KuaESB?fscid=z13sct1itoz5sthsd22pdfbazufhenlio04.1491053867286977

Could you add https://github.com/noopkat/floyd-steinberg to the filters? It's just a couple of lines:

import floyd_steinberg from 'floyd-steinberg'

...L#133...
settings = Object.assign({}, {
        smoothing   : false,  // Smoothing [true|fale]
        brightness  : 0,      // Image brightness [-255 to +255]
        contrast    : 0,      // Image contrast [-255 to +255]
        gamma       : 0,      // Image gamma correction [0.01 to 7.99]
        grayscale   : 'none', // Graysale algorithm [average, luma, luma-601, luma-709, luma-240, desaturation, decomposition-[min|max], [red|green|blue]-chanel]
        shadesOfGray: 256,    // Number of shades of gray [2-256]
        invertColor : false,  // Invert color...
       dither: false,
}, settings || {})

...L#190...
if (settings.dither) {
        floyd_steinberg(imageData)
}
jorgerobles commented 7 years ago

Or extend lw.canvas-grid to accept custom key callables, this way could be extended without recompiling all the toolchain.

filters: {
   ... your filters
   dithering: (imageData) => { ...process ImageData... }
}

Or a simple hook for further imageData processing