package kaka.cakelight;
public class Color {
+ private static int[] gammaCorrection = new int[256];
+
+ public static void calculateGammaCorrection(double gamma) {
+ for (int i = 0, max = 255; i <= max; i++) {
+ gammaCorrection[i] = (int)(Math.pow((double)i / max, gamma) * max);
+ }
+ }
+
private int r, g, b;
public static Color rgb(double r, double g, double b) {
return c;
}
+ public static Color hsv(double hue, double saturation, double value) {
+ double normalizedHue = hue - Math.floor(hue);
+ int h = (int)(normalizedHue * 6);
+ double f = normalizedHue * 6 - h;
+ double p = value * (1 - saturation);
+ double q = value * (1 - f * saturation);
+ double t = value * (1 - (1 - f) * saturation);
+
+ switch (h) {
+ case 0: return rgb(value, t, p);
+ case 1: return rgb(q, value, p);
+ case 2: return rgb(p, value, t);
+ case 3: return rgb(p, q, value);
+ case 4: return rgb(t, p, value);
+ case 5: return rgb(value, p, q);
+ default: throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + hue + ", " + saturation + ", " + value);
+ }
+ }
+
public int r() {
- return r;
+ return gammaCorrection[r];
}
public int g() {
- return g;
+ return gammaCorrection[g];
}
public int b() {
- return b;
+ return gammaCorrection[b];
}
public Color interpolate(Color other, double value) {