AngusJohnson / Image32

An extensive 2D graphics library written in Delphi Pascal
Boost Software License 1.0
137 stars 31 forks source link

Improve TImage32.CopyToDc performance #76

Closed ahausladen closed 3 months ago

ahausladen commented 3 months ago

This PR optimizes the TImage32.CopyToDc method by using a much faster PremultiplyAlpha function and using it to copy and pre-multiply the alpha channel of the pixels in one step into the bitmap's memory.

The old code first copied the image scanlines and then called PremultiplyAlpha on them, reading and writing every pixels twice. The new code only reads and writes the pixels once.

It also fixes the double pre-multiplying of the alpha channel of the image in TImage32.CopyToDc, if it is called with Transparent=True and the image was already pre-multiplied by a call to TImage32.PremultiplyAlpha.