Here you can find the source of RGB2HSL(int red, int green, int blue, float[] hslvals)
public static void RGB2HSL(int red, int green, int blue, float[] hslvals)
//package com.java2s; /*/*from w ww .j a v a 2 s . c o m*/ * Copyright (C) 2007, 2008 Quadduc <quadduc@gmail.com> * Copyright (C) 2007, 2011 IsmAvatar <IsmAvatar@gmail.com> * Copyright (C) 2007 Clam <clamisgood@gmail.com> * Copyright (C) 2013, 2014 Robert B. Colton * * This file is part of LateralGM. * LateralGM is free software and comes with ABSOLUTELY NO WARRANTY. * See LICENSE for details. */ public class Main { public static void RGB2HSL(int red, int green, int blue, float[] hslvals) { float r = red / 255.f; float g = green / 255.f; float b = blue / 255.f; float max = Math.max(Math.max(r, g), b); float min = Math.min(Math.min(r, g), b); float c = max - min; float h_ = 0.f; if (c == 0) { h_ = 0; } else if (max == r) { h_ = (float) (g - b) / c; if (h_ < 0) h_ += 6.f; } else if (max == g) { h_ = (float) (b - r) / c + 2.f; } else if (max == b) { h_ = (float) (r - g) / c + 4.f; } float h = 60.f * h_; float l = (max + min) * 0.5f; float s; if (c == 0) { s = 0.f; } else { s = c / (1 - Math.abs(2.f * l - 1.f)); } hslvals[0] = h; hslvals[1] = s; hslvals[2] = l; } }