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 double minHsvV = 0.125;
const double maxHsvV = 0.965;
HSVColor hsvTintColor = HSVColor.fromColor(tintColor);
double clampedHsvV = hsvTintColor.value.clamp(minHsvV, maxHsvV);
HSVColor hsvLuminosityColor = hsvTintColor.withValue(clampedHsvV);
Color rgbLuminosityColor = hsvLuminosityColor.toColor();
// Now figure out luminosity opacity
// Map original *tint* opacity to this range
const double minLuminosityOpacity = 0.15;
const double maxLuminosityOpacity = 1.03;
const double luminosityOpacityRangeMax =
maxLuminosityOpacity - minLuminosityOpacity;
double 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),
);
}
}