Java RGB Color Convert To rgbToHsl(byte red, byte green, byte blue)

Here you can find the source of rgbToHsl(byte red, byte green, byte blue)

Description

rgb To Hsl

License

Open Source License

Declaration

private static double[] rgbToHsl(byte red, byte green, byte blue) 

Method Source Code

//package com.java2s;

public class Main {
    private static double[] rgbToHsl(byte red, byte green, byte blue) {
        final double r = (red & 0xff) / 255d;
        final double g = (green & 0xff) / 255d;
        final double b = (blue & 0xff) / 255d;
        final double max = Math.max(Math.max(r, g), b);
        final double min = Math.min(Math.min(r, g), b);
        double h = 0d, s = 0d, l = (max + min) / 2d;
        if (max == min) {
            h = s = 0d; //gray scale
        } else {//from  ww w.  j  a  v  a  2 s. co m
            final double d = max - min;
            s = l > 0.5 ? d / (2d - max - min) : d / (max + min);
            if (max == r) {
                h = (g - b) / d + (g < b ? 6d : 0d);
            } else if (max == g) {
                h = (b - r) / d + 2d;
            } else if (max == b) {
                h = (r - g) / d + 4d;
            }
            h /= 6d;
        }
        return new double[] { h, s, l };
    }
}

Related

  1. RGBToHex(int[] rgb)
  2. rgbToHex(String color)
  3. RGBtoHSB(int r, int g, int b, float hsbvals[])
  4. RGBtoHSB(int r, int g, int b, float[] hsbvals)
  5. RGBtoHSB(int red, int green, int blue, float hsb[])
  6. RgbToHsl(float r, float g, float b, float a)
  7. rgbToHsl(float[] rgb)
  8. RGBtoHSL(int r, int g, int b)
  9. RGBtoHSL(int r, int g, int b)