Try using only the hue in video mode, with max saturation and value
authorTomas Wenström <tomas.wenstrom@gmail.com>
Wed, 7 Jun 2017 19:15:53 +0000 (21:15 +0200)
committerTomas Wenström <tomas.wenstrom@gmail.com>
Wed, 7 Jun 2017 19:15:53 +0000 (21:15 +0200)
src/kaka/cakelight/Color.java
src/kaka/cakelight/Frame.java

index 0756209..fe010c7 100644 (file)
@@ -23,6 +23,11 @@ public class Color {
         return c;
     }
 
         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);
     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];
     }
     public int r() {
         return gammaCorrection[r];
     }
index 0ae0d41..053b713 100644 (file)
@@ -101,6 +101,12 @@ public class Frame {
 //        Imgproc.resize(src, rowImage, new Size(16, config.leds.rows), 0, 0, interpolation);
     }
 
 //        Imgproc.resize(src, rowImage, new Size(16, config.leds.rows), 0, 0, interpolation);
     }
 
+    private Color wrappedGetLedColor(ListPosition listPosition, int xy) {
+        Color c = getLedColor(listPosition, xy);
+        double[] hsv = c.toHSV();
+        return Color.hsv(hsv[0], 1, 1);
+    }
+
     private Color getLedColor(ListPosition listPosition, int xy) {
         // TODO: maybe use highest value from pixels? 100 % from 1st, 66 % from 2nd, 33 % from 3rd. colors might be strange.
         switch (listPosition) {
     private Color getLedColor(ListPosition listPosition, int xy) {
         // TODO: maybe use highest value from pixels? 100 % from 1st, 66 % from 2nd, 33 % from 3rd. colors might be strange.
         switch (listPosition) {
@@ -166,10 +172,10 @@ public class Frame {
     public LedFrame getLedFrame() {
         LedFrame frame = LedFrame.from(config);
         int led = 0;
     public LedFrame getLedFrame() {
         LedFrame frame = LedFrame.from(config);
         int led = 0;
-        for (int i = 0; i < config.leds.cols; i++)      frame.setLedColor(led++, getLedColor(ListPosition.BOTTOM, i));
-        for (int i = config.leds.rows - 1; i >= 0; i--) frame.setLedColor(led++, getLedColor(ListPosition.RIGHT, i));
-        for (int i = config.leds.cols - 1; i >= 0; i--) frame.setLedColor(led++, getLedColor(ListPosition.TOP, i));
-        for (int i = 0; i < config.leds.rows; i++)      frame.setLedColor(led++, getLedColor(ListPosition.LEFT, i));
+        for (int i = 0; i < config.leds.cols; i++)      frame.setLedColor(led++, wrappedGetLedColor(ListPosition.BOTTOM, i));
+        for (int i = config.leds.rows - 1; i >= 0; i--) frame.setLedColor(led++, wrappedGetLedColor(ListPosition.RIGHT, i));
+        for (int i = config.leds.cols - 1; i >= 0; i--) frame.setLedColor(led++, wrappedGetLedColor(ListPosition.TOP, i));
+        for (int i = 0; i < config.leds.rows; i++)      frame.setLedColor(led++, wrappedGetLedColor(ListPosition.LEFT, i));
         return frame;
     }
 }
         return frame;
     }
 }