Here you can find the source of rgb2hsl(int colour)
public static double[] rgb2hsl(int colour)
//package com.java2s; //License from project: Open Source License public class Main { public static double[] rgb2hsl(int r, int g, int b) { double dr = r / 255.0; double dg = g / 255.0; double db = b / 255.0; double max = Math.max(dr, Math.max(dg, db)); double min = Math.min(dr, Math.min(dg, db)); double h, s; double l = (max + min) * 0.5; if (max == min) { h = 0;//www.j av a2 s . co m s = 0; } else { double d = max - min; s = l > 0.5 ? d / (2.0 - max - min) : d / (max + min); if (max == dr) { h = (dg - db) / d + (dg < db ? 6 : 0); } else if (max == dg) { h = (db - dr) / d + 2; } else { h = (dr - dg) / d + 4; } h /= 6.0; } return new double[] { h, s, l }; } public static double[] rgb2hsl(int colour) { return rgb2hsl(red(colour), green(colour), blue(colour)); } public static int red(int c) { return (c >> 16) & 0xFF; } public static int green(int c) { return (c >> 8) & 0xFF; } public static int blue(int c) { return (c) & 0xFF; } }