[HN Gopher] Show HN: An attempt to make a reduce-palette/dither ...
       ___________________________________________________________________
        
       Show HN: An attempt to make a reduce-palette/dither filter for 2d
       canvas images
        
       Author : rikroots
       Score  : 17 points
       Date   : 2022-08-20 11:25 UTC (11 hours ago)
        
 (HTM) web link (scrawl-v8.rikweb.org.uk)
 (TXT) w3m dump (scrawl-v8.rikweb.org.uk)
        
       | JKCalhoun wrote:
       | I remember when _blue noise_ was the shit back in the 90 's. And
       | wow, what a difference it makes when you enable it.
        
         | mistrial9 wrote:
         | can you say more about that?
        
       | hx2a wrote:
       | Nice work!
       | 
       | > Note that this is a resource-intensive filter. Memoization is
       | strongly advised!
       | 
       | Can you make this be the default for non Safari browsers? This
       | really made my CPU fan work hard. Also, why does this need to
       | recalculate the image so many times a second if it is the same
       | image each time? It really only needs to redraw when I change one
       | of the options.
        
         | rikroots wrote:
         | Thank you!
         | 
         | The demo is a part of the testing regime for my canvas library.
         | I set the default to "don't memoize" because it's the quickest
         | way to see how intense/computationally expensive the filter
         | gets using different parameters. For most scenarios the output
         | should be memoized (to stop unresponsive websites, device
         | damage, etc)
         | 
         | My ultimate goal would be to get the filter working more
         | efficiently on dynamic input eg a video media stream. So far
         | only the simplest settings (2 colours with dither) are
         | watchable: https://codepen.io/kaliedarik/pen/OJOaOZz
        
       | marginalia_nu wrote:
       | The performance is worse than I would expect with a correctly
       | implemented Floyd-Steinberg algorithm, I'd expect it to rasterize
       | well even with a 2 color palette (that's easier to get right than
       | RGB).
       | 
       | I don't at all mean to diminish the work, it's more a hunch that
       | it's under-performing. I was dicking around with dithering last
       | year, and had similar problems initially.
        
         | rikroots wrote:
         | Thanks for checking the demo out. The code[1] is very much a
         | work-in-progress - suggestions for algorithm improvements
         | (they're not based on Floyd-Steinberg) are always welcome!
         | 
         | [1] - https://github.com/KaliedaRik/Scrawl-
         | canvas/blob/master/sour...
        
           | dubiousconst281 wrote:
           | One fast way to do palette reduction is by using a 16-bit
           | RGB565 lookup table filled with all the closest colors
           | relative to each entry index, then you can replace each pixel
           | in the image using just a few bitwise ops and one array
           | access.
        
             | rikroots wrote:
             | That's an interesting approach!
             | 
             | I went a different way, converting each pixel to its LAB
             | color space values to find the optimal palette for the
             | image (based on preference arguments), then afterwards
             | measuring each pixel against the palette colors to find the
             | two closest colors before deciding which of those two
             | colors to pick based on a distance propensity weighting
             | against the semi-random number assigned to that pixel.
             | 
             | Coming up with highly efficient algorithms (for anything!)
             | is not my strongest skill. Neither is trying to explain
             | them.
        
       ___________________________________________________________________
       (page generated 2022-08-20 23:02 UTC)