ColorFunctions: improved performance of mix(), tint() and shade() color functions

(used UIDefaultsDump to verify whether results are the same as before)
This commit is contained in:
Karl Tauber
2021-09-28 19:48:54 +02:00
parent 82df2ecfa9
commit 6baa583a28

View File

@@ -26,6 +26,17 @@ import java.awt.Color;
public class ColorFunctions
{
public static Color applyFunctions( Color color, ColorFunction... functions ) {
// if having only a single function of type Mix, then avoid four unnecessary conversions:
// 1. RGB to HSL in this method
// 2. HSL to RGB in Mix.apply()
// mix
// 3. RGB to HSL in Mix.apply()
// 4. HSL to RGB in this method
if( functions.length == 1 && functions[0] instanceof Mix ) {
Mix mixFunction = (Mix) functions[0];
return mix( color, mixFunction.color2, mixFunction.weight / 100 );
}
// convert RGB to HSL
float[] hsl = HSLColor.fromRGB( color );
float alpha = color.getAlpha() / 255f;