public float[] convertToHsl() {

        float H, S, L;

        // first normalize [0,1]
        float R = r / 255f;
        float G = g / 255f;
        float B = b / 255f;

        // compute min and max
        float M = max(R, G, B);
        float m = min(R, G, B);

        L = (M + m) / 2f;

        if (M == m) {
            // grey
            H = S = 0;
        }
        else {
            float diff = M - m;
            S = (L < 0.5) ? diff / (2f * L) : diff / (2f - 2f * L);

            if (M == R) {
                H = (G - B) / diff;
            }
            else if (M == G) {
                H = (B - R) / diff + 2f;
            }
            else {
                H = (R - G) / diff + 4f;
            }
            H *= 60;
        }

        H = hueCheck(H);
        S = slCheck(S * 100f);
        L = slCheck(L * 100f);

        return new float[] { H, S, L };
    }
public float [ ] convertToHsl ( ) { float H , S , L ; float R = r / 255f ; float G = g / 255f ; float B = b / 255f ; float M = max ( R , G , B ) ; float m = min ( R , G , B ) ; L = ( M + m ) / 2f ; if ( M == m ) { H = S = 0 ; } else { float diff = M - m ; S = ( L < 0.5 ) ? diff / ( 2f * L ) : diff / ( 2f - 2f * L ) ; if ( M == R ) { H = ( G - B ) / diff ; } else if ( M == G ) { H = ( B - R ) / diff + 2f ; } else { H = ( R - G ) / diff + 4f ; } H *= 60 ; } H = hueCheck ( H ) ; S = slCheck ( S * 100f ) ; L = slCheck ( L * 100f ) ; return new float [ ] { H , S , L } ; }
Returns a triple of hue [0-360), saturation [0-100], and
lightness [0-100]. These are kept as float[] so that for any
RgbaColor color,
color.equals(RgbaColor.fromHsl(color.convertToHsl())) is true.

<p>
<i>Implementation based on <a
href="http://en.wikipedia.org/wiki/HSL_and_HSV"
>wikipedia</a></i>