From 6baa583a28e5e3ef15899d16552dfc507432b500 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 28 Sep 2021 19:48:54 +0200 Subject: [PATCH] ColorFunctions: improved performance of mix(), tint() and shade() color functions (used UIDefaultsDump to verify whether results are the same as before) --- .../java/com/formdev/flatlaf/util/ColorFunctions.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/ColorFunctions.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/ColorFunctions.java index fd223930..8ed13092 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/ColorFunctions.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/ColorFunctions.java @@ -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;