saucecontrol / PhotoSauce

MagicScaler high-performance, high-quality image processing pipeline for .NET
http://photosauce.net/
MIT License
589 stars 49 forks source link

ColorMatrixTransform does not unpremultiply/premultiply #131

Closed rickbrew closed 10 months ago

rickbrew commented 11 months ago

As per discussion on Discord. Color space conversions will not be correct for images that have alpha.

saucecontrol commented 10 months ago

I worked out the math on this again, and it doesn't make a difference whether you unpremultiply as long as you have enough precision (which we always do), because the proportions of the color values don't change with premultiplication, and that's all the color matrix does is blend the color channels based on their proportions.

I surely did this exercise when I first implemented it and came to the same conclusion, but at least now it's documented here, I won't forget again 😄