getLuminosityColor static method
Implementation
static Color getLuminosityColor(Color tintColor, double? luminosityOpacity) {
// If luminosity opacity is specified, just use the values as is
if (luminosityOpacity != null) {
return Color.fromRGBO(
tintColor.red,
tintColor.green,
tintColor.blue,
luminosityOpacity.clamp(0.0, 1.0),
);
} else {
// To create the Luminosity blend input color without luminosity opacity,
// we're taking the TintColor input, converting to HSV, and clamping the V between these values
const minHsvV = 0.125;
const maxHsvV = 0.965;
var hsvTintColor = HSVColor.fromColor(tintColor);
var clampedHsvV = hsvTintColor.value.clamp(minHsvV, maxHsvV);
var hsvLuminosityColor = hsvTintColor.withValue(clampedHsvV);
var rgbLuminosityColor = hsvLuminosityColor.toColor();
// Now figure out luminosity opacity
// Map original *tint* opacity to this range
const minLuminosityOpacity = 0.15;
const maxLuminosityOpacity = 1.03;
const luminosityOpacityRangeMax =
maxLuminosityOpacity - minLuminosityOpacity;
var mappedTintOpacity =
((tintColor.alpha / 255.0) * luminosityOpacityRangeMax) +
minLuminosityOpacity;
// Finally, combine the luminosity opacity and the HsvV-clamped tint color
return Color.fromRGBO(
rgbLuminosityColor.red,
rgbLuminosityColor.green,
rgbLuminosityColor.blue,
math.min(mappedTintOpacity, 1.0),
);
}
}