makew0rld/dither

Support images with alpha channel

makew0rld opened this issue · 3 comments

Thanks to @/Shrinks99

This will not do dithering in the alpha channel, but it will properly handle images with non-opaque pixels.

  • Leave fully transparent pixels as they are
  • Partially transparent pixels (example)
    • I have a premult color, a=0.5
    • I take the RGB and dither it, and end up with a palette color (with implicit a=1)
    • I multiply the palette color by 0.5
    • I store the multiplied color with a=0.5

DitherPaletted wouldn't support this, as this would require breaking the guarantee that the returned image has the same palette as the Ditherer.

I think the example is missing a step, right after the first one. Premultiplied colors need to be un-premultiplied before dithering, otherwise the dithering will treat the colors as if they're darker.

Support for this was added in 979ffde. This issue will be closed after some more testing.

Examples are in the repo tree now, here they are directly linked: