Here you can find the source of rgbToHsl(byte red, byte green, byte blue)
private static double[] rgbToHsl(byte red, byte green, byte blue)
//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 }; } }