Why Xojo premultiply on Alpha channel will not work for most image processing


Premultiply gives great results for drawing on screen and is very fast, so is good for all sorts of effects and media. However original RGB values cannot be retrieved back from it accuratly.

Here is why:

If we consider the colour: (125,125,125,120) where the alpha channel is 120.

Then that can be premultiplied which would give: (59,59,59,120)

If reverse calculating back to un-premultiplied color then precision is lost and we get: (124,124,124,120)

This can and will at times vary by more than just the one tone as shown above.

If considering the color (125,125,125,0) then premultiplied version of that is (0,0,0,0), where all data of the original color is lost. Calculating this one back to the original one gives (0,0,0,0)

The new style Alpha channels in Xojo work as follows:

  • MacOS X Cocoa (GUI application)
    • Premultiplied
  • MacOS X Carbon (GUI application)
    • Not supported at all
  • Windows (GUI application)
    • Not premultiplied
  • Linux (GUI application)
    • Premultiplied
  • MacOS X and Windows (Console application)
    • Not premultiplied
  • Linux (Console application)
    • Not premultiplied but the alpha channel is only 7 bits (so looses slightly precision on alpha channel)

Old style Xojo image masks of course preserve full precision.

Most image processing algorithms need to work on the actual RGB values, for this reason then most effects in the PictureEffects plugin will not be supporting the new style alpha channel. Exception from that might be distortion algorithms where whole pixels are only moved around, such as in Flip, and maybe rotation and other such.

PictureEffects will continue to support masking where it applies and normal Xojo Pictures. And we plan to add our own Picture class type that is more suitable for image processing without loosing precision with alpha channels.