// all values are in the range of 0 to 1.0 RGBA32 makeRGBAFromHSLA(double h, double s, double l, double a) { double temp2 = l < 0.5 ? l * (1.0 + s) : l + s - l * s; double temp1 = 2.0 * l - temp2; return makeRGBA(static_cast<int>(calcHue(temp1, temp2, h + 1.0 / 3.0) * 255), static_cast<int>(calcHue(temp1, temp2, h) * 255), static_cast<int>(calcHue(temp1, temp2, h - 1.0 / 3.0) * 255), static_cast<int>(a * 255)); }
// all values are in the range of 0 to 1.0 RGBA32 makeRGBAFromHSLA(double hue, double saturation, double lightness, double alpha) { const double scaleFactor = nextafter(256.0, 0.0); if (!saturation) { int greyValue = static_cast<int>(lightness * scaleFactor); return makeRGBA(greyValue, greyValue, greyValue, static_cast<int>(alpha * scaleFactor)); } double temp2 = lightness < 0.5 ? lightness * (1.0 + saturation) : lightness + saturation - lightness * saturation; double temp1 = 2.0 * lightness - temp2; return makeRGBA(static_cast<int>(calcHue(temp1, temp2, hue + 1.0 / 3.0) * scaleFactor), static_cast<int>(calcHue(temp1, temp2, hue) * scaleFactor), static_cast<int>(calcHue(temp1, temp2, hue - 1.0 / 3.0) * scaleFactor), static_cast<int>(alpha * scaleFactor)); }