compat/src/main/java/androidx/core/graphics/ColorUtils.java
@ColorInt
    public static int HSLToColor(@NonNull float[] hsl) {
        final float h = hsl[0];
        final float s = hsl[1];
        final float l = hsl[2];

        final float c = (1f - Math.abs(2 * l - 1f)) * s;
        final float m = l - 0.5f * c;
        final float x = c * (1f - Math.abs((h / 60f % 2f) - 1f));

        final int hueSegment = (int) h / 60;

        int r = 0, g = 0, b = 0;

        switch (hueSegment) {
            case 0:
                r = Math.round(255 * (c + m));
                g = Math.round(255 * (x + m));
                b = Math.round(255 * m);
                break;
            case 1:
                r = Math.round(255 * (x + m));
                g = Math.round(255 * (c + m));
                b = Math.round(255 * m);
                break;
            case 2:
                r = Math.round(255 * m);
                g = Math.round(255 * (c + m));
                b = Math.round(255 * (x + m));
                break;
            case 3:
                r = Math.round(255 * m);
                g = Math.round(255 * (x + m));
                b = Math.round(255 * (c + m));
                break;
            case 4:
                r = Math.round(255 * (x + m));
                g = Math.round(255 * m);
                b = Math.round(255 * (c + m));
                break;
            case 5:
            case 6:
                r = Math.round(255 * (c + m));
                g = Math.round(255 * m);
                b = Math.round(255 * (x + m));
                break;
        }

        r = constrain(r, 0, 255);
        g = constrain(g, 0, 255);
        b = constrain(b, 0, 255);

        return Color.rgb(r, g, b);
    }
/**
     * Convert HSL (hue-saturation-lightness) components to a RGB color.
     * <ul>
     * <li>hsl[0] is Hue [0 .. 360)</li>
     * <li>hsl[1] is Saturation [0...1]</li>
     * <li>hsl[2] is Lightness [0...1]</li>
     * </ul>
     * If hsv values are out of range, they are pinned.
     *
     * @param hsl 3-element array which holds the input HSL components
     * @return the resulting RGB color
     */
Convert HSL (hue-saturation-lightness) components to a RGB color.

@param hsl 3-element array which holds the input HSL components
@return the resulting RGB color
Convert HSL ( hue - saturation - lightness ) components to a RGB color . @param hsl 3 - element array which holds the input HSL components @return the resulting RGB color
@ColorInt
    public static int HSLToColor(@NonNull float[] hsl) {
        final float h = hsl[0];
        final float s = hsl[1];
        final float l = hsl[2];
        final float c = (1f - Math.abs(2 * l - 1f)) * s;
        final float m = l - 0.5f * c;
        final float x = c * (1f - Math.abs((h / 60f % 2f) - 1f));
        final int hueSegment = (int) h / 60;
        int r = 0, g = 0, b = 0;
        switch (hueSegment) {
            case 0:
                r = Math.round(255 * (c + m));
                g = Math.round(255 * (x + m));
                b = Math.round(255 * m);
                break;
            case 1:
                r = Math.round(255 * (x + m));
                g = Math.round(255 * (c + m));
                b = Math.round(255 * m);
                break;
            case 2:
                r = Math.round(255 * m);
                g = Math.round(255 * (c + m));
                b = Math.round(255 * (x + m));
                break;
            case 3:
                r = Math.round(255 * m);
                g = Math.round(255 * (x + m));
                b = Math.round(255 * (c + m));
                break;
            case 4:
                r = Math.round(255 * (x + m));
                g = Math.round(255 * m);
                b = Math.round(255 * (c + m));
                break;
            case 5:
            case 6:
                r = Math.round(255 * (c + m));
                g = Math.round(255 * m);
                b = Math.round(255 * (x + m));
                break;
        }
        r = constrain(r, 0, 255);
        g = constrain(g, 0, 255);
        b = constrain(b, 0, 255);
        return Color.rgb(r, g, b);
    }
@ ColorInt public static int HSLToColor ( @ NonNull float [ ] hsl ) { final float h = hsl [ 0 ] ; final float s = hsl [ 1 ] ; final float l = hsl [ 2 ] ; final float c = ( 1f - Math . abs ( 2 * l - 1f ) ) * s ; final float m = l - 0.5f * c ; final float x = c * ( 1f - Math . abs ( ( h / 60f % 2f ) - 1f ) ) ; final int hueSegment = ( int ) h / 60 ; int r = 0 , g = 0 , b = 0 ; switch ( hueSegment ) { case 0 : r = Math . round ( 255 * ( c + m ) ) ; g = Math . round ( 255 * ( x + m ) ) ; b = Math . round ( 255 * m ) ; break ; case 1 : r = Math . round ( 255 * ( x + m ) ) ; g = Math . round ( 255 * ( c + m ) ) ; b = Math . round ( 255 * m ) ; break ; case 2 : r = Math . round ( 255 * m ) ; g = Math . round ( 255 * ( c + m ) ) ; b = Math . round ( 255 * ( x + m ) ) ; break ; case 3 : r = Math . round ( 255 * m ) ; g = Math . round ( 255 * ( x + m ) ) ; b = Math . round ( 255 * ( c + m ) ) ; break ; case 4 : r = Math . round ( 255 * ( x + m ) ) ; g = Math . round ( 255 * m ) ; b = Math . round ( 255 * ( c + m ) ) ; break ; case 5 : case 6 : r = Math . round ( 255 * ( c + m ) ) ; g = Math . round ( 255 * m ) ; b = Math . round ( 255 * ( x + m ) ) ; break ; } r = constrain ( r , 0 , 255 ) ; g = constrain ( g , 0 , 255 ) ; b = constrain ( b , 0 , 255 ) ; return Color . rgb ( r , g , b ) ; }
Convert HSL (hue-saturation-lightness) components to a RGB color.
Convert HSL ( hue - saturation - lightness ) components to a RGB color .