leds.cols=32
leds.rows=17
+
+gamma=1.5
public CakeLight(Configuration config, LedController ledController) {
this.config = config;
this.ledController = ledController;
+ Color.calculateGammaCorrection(config.gamma);
}
public void setMode(Mode mode) {
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) {
}
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) {
private List<Map.Entry<String, String>> settings = new ArrayList<>();
public VideoConfiguration video;
public LedConfiguration leds;
+ public double gamma;
private Configuration(Properties prop) {
video = new VideoConfiguration(prop);
leds = new LedConfiguration(prop);
+ gamma = Double.parseDouble(get(prop,"gamma", "1"));
}
public static Configuration from(String propertiesFile) {
}
public void fillColor(int r, int g, int b) {
- for (int i = 0; i < bytes.length; i += 3) {
- bytes[i + roff] = (byte)r;
- bytes[i + goff] = (byte)g;
- bytes[i + boff] = (byte)b;
- }
+ fillColor(Color.rgb(r, g, b));
}
public void fillColor(Color color) {
- fillColor(color.r(), color.g(), color.b());
+ byte r = (byte)color.r(), g = (byte)color.g(), b = (byte)color.b(); // Gamma corrected values
+ for (int i = 0; i < bytes.length; i += 3) {
+ bytes[i + roff] = r;
+ bytes[i + goff] = g;
+ bytes[i + boff] = b;
+ }
}
public void setLedColor(int led, Color color) {