X-Git-Url: http://dolda2000.com/gitweb/?p=kaka%2Fcakelight.git;a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FColor.java;h=fe010c7080fbe44c747d69b0d380513c10f24ac3;hp=0756209004ace4f3acf15d41f95e0872cc69a11b;hb=b3e103128bae11de70b5ca0bbf9255953d008eaf;hpb=38c759f87fc7de47d9dee60088f2dbc60e0a55fb diff --git a/src/kaka/cakelight/Color.java b/src/kaka/cakelight/Color.java index 0756209..fe010c7 100644 --- a/src/kaka/cakelight/Color.java +++ b/src/kaka/cakelight/Color.java @@ -23,6 +23,11 @@ public class Color { return c; } + /** + * @param hue 0.0 - 1.0 + * @param saturation 0.0 - 1.0 + * @param value 0.0 - 1.0 + */ public static Color hsv(double hue, double saturation, double value) { double normalizedHue = hue - Math.floor(hue); int h = (int)(normalizedHue * 6); @@ -42,6 +47,45 @@ public class Color { } } + public double[] toHSV() { + return toHSV(r / 255.0, g / 255.0, b / 255.0); + } + + /** + * @return an array with hsv values ranging from 0.0 to 1.0 + */ + public static double[] toHSV(double r, double g, double b) { + double h, s, v; + double min = Math.min(Math.min(r, g), b); + double max = Math.max(Math.max(r, g), b); + + if (max == 0) { + return new double[] {0, 0, 0}; + } + + // Value + v = max; + + // Saturation + double delta = max - min; + s = delta / max; + + // Hue + if (r == max) { + h = (g - b) / delta; // between yellow & magenta + } else if (g == max) { + h = 2 + (b - r) / delta; // between cyan & yellow + } else { + h = 4 + (r - g) / delta; // between magenta & cyan + } + + h /= 6.0; + if (h < 0) + h += 1; + + return new double[] {h, s, v}; + } + public int r() { return gammaCorrection[r]; }