Skip to content

Commit

Permalink
InvertColorsEffect does not work correct for alpha values != 255
Browse files Browse the repository at this point in the history
reason is that cairo images use premultiplied alpha values
  • Loading branch information
codeprof committed Dec 2, 2015
1 parent 481f6fa commit b4b013b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Pinta.Core/Effects/UnaryPixelOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ public class Invert
{
public override ColorBgra Apply(ColorBgra color)
{
return ColorBgra.FromBgra((byte)(255 - color.B), (byte)(255 - color.G), (byte)(255 - color.R), color.A);
//Note: Cairo images use premultiplied alpha values
//The formula for changing B would be: (255 - B * 255 / A) * A / 255
//This can be simplified to: A - B
return ColorBgra.FromBgra((byte)(color.A - color.B), (byte)(color.A - color.G), (byte)(color.A - color.R), color.A);
}
}

Expand Down

0 comments on commit b4b013b

Please sign in to comment.