Here you can find the source of hslToHsb(float[] inputHsl)
Parameter | Description |
---|---|
inputHsl | HSL color in a array of three floats, 0 is Hue, 1 is Saturation and 2 is Lightness |
static float[] hslToHsb(float[] inputHsl)
//package com.java2s; /*//from w w w.j a va 2 s. c om * Copyright 2010 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** Index of Hue in HSB and HSL array. */ static final int H = 0; /** Index of Saturation in HSB and HSL array. */ static final int S = 1; /** Index of Lightness in HSL array. */ static final int L = 2; /** * Convert a color in HSL color space to one in HSB color space. * * @param inputHsl HSL color in a array of three floats, 0 is Hue, 1 is * Saturation and 2 is Lightness * @return HSB color in array of three floats, 0 is Hue, 1 is * Saturation and 2 is Brightness */ static float[] hslToHsb(float[] inputHsl) { float hHsl = inputHsl[H]; float sHsl = inputHsl[S]; float lHsl = inputHsl[L]; float hHsb = hHsl; float bHsb = (2 * lHsl + sHsl * (1 - Math.abs(2 * lHsl - 1))) / 2; float sHsb = 2 * (bHsb - lHsl) / bHsb; float[] hsb = { hHsb, sHsb, bHsb }; return hsb; } }