Added gamma correction
[kaka/cakelight.git] / src / kaka / cakelight / Color.java
index 1e92da9..0756209 100644 (file)
@@ -1,6 +1,14 @@
 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) {
@@ -35,15 +43,15 @@ public class Color {
     }
 
     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) {