Here you can find the source of getHSBfromRGB(final ByteBuffer pixels, final float[] result, int pixelSize)
public static float[] getHSBfromRGB(final ByteBuffer pixels, final float[] result, int pixelSize)
//package com.java2s; import java.nio.ByteBuffer; public class Main { public static float[] getHSBfromRGB(final ByteBuffer pixels, final float[] result, int pixelSize) { int idx = 0; for (int i = result.length / 3; --i >= 0;) { float hue; final float saturation; final float brightness; final int r = pixels.get() & 0xFF; final int g = pixels.get() & 0xFF; final int b = pixels.get() & 0xFF; int cmax = (r > g) ? r : g; if (b > cmax) cmax = b;/* w w w .ja v a 2 s . c o m*/ int cmin = (r < g) ? r : g; if (b < cmin) cmin = b; brightness = (cmax) / 255.0f; saturation = cmax != 0 ? ((float) (cmax - cmin)) / ((float) cmax) : 0f; if (saturation == 0) hue = 0; else { float redc = ((float) (cmax - r)) / ((float) (cmax - cmin)); float greenc = ((float) (cmax - g)) / ((float) (cmax - cmin)); float bluec = ((float) (cmax - b)) / ((float) (cmax - cmin)); if (r == cmax) hue = bluec - greenc; else if (g == cmax) hue = 2.0f + redc - bluec; else hue = 4.0f + greenc - redc; hue = hue / 6.0f; if (hue < 0) hue = hue + 1.0f; } result[idx++] = hue; result[idx++] = saturation; result[idx++] = brightness; if (pixelSize == 4) pixels.get(); } return result; } }