Java RGB Color Convert To rgb2hsl(int[] rgb)

Here you can find the source of rgb2hsl(int[] rgb)

Description

rgbhsl

License

Apache License

Declaration

static int[] rgb2hsl(int[] rgb) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    static int[] rgb2hsl(int[] rgb) {
        double max = Math.max(Math.max(rgb[0], rgb[1]), rgb[2]); // 0xdd = 221
        double delta = max - Math.min(Math.min(rgb[0], rgb[1]), rgb[2]); // 153
        double h = 0;
        int s = 0;
        int l = (int) Math.round(max * 100d / 255d); // 87 ok
        if (max != 0) {
            s = (int) Math.round(delta * 100d / max); // 69 ok
            if (max == rgb[0]) {
                h = (rgb[1] - rgb[2]) / delta;
            } else if (max == rgb[1]) {
                h = (rgb[2] - rgb[0]) / delta + 2d;
            } else {
                h = (rgb[0] - rgb[1]) / delta + 4d; // 4.8888888888
            }//from   w  ww. ja  v a 2  s  . c  om
            h = Math.min(Math.round(h * 60d), 360d); // 293
            if (h < 0d) {
                h += 360d;
            }
        }
        return new int[] { (int) Math.round(h), Math.round(s), l };
    }
}

Related

  1. rgb2grayscaleA(int[] rgb)
  2. rgb2Hex(int rgb)
  3. rgb2hex(int[] rgb)
  4. rgb2hsl(int colour)
  5. RGB2HSL(int red, int green, int blue, float[] hslvals)
  6. rgb2hsv(int r, int g, int b)
  7. rgb2int(final int[] color)
  8. rgb2intval(int r, int g, int b)
  9. rgb2lab(int R, int G, int B)