Dolda2000 GitWeb
/
kaka
/
cakelight.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
14d53f0
)
Added gamma correction
author
Tomas Wenström
<tomas.wenstrom@gmail.com>
Mon, 5 Jun 2017 20:04:03 +0000
(22:04 +0200)
committer
Tomas Wenström
<tomas.wenstrom@gmail.com>
Mon, 5 Jun 2017 20:04:03 +0000
(22:04 +0200)
config.properties
patch
|
blob
|
blame
|
history
src/kaka/cakelight/CakeLight.java
patch
|
blob
|
blame
|
history
src/kaka/cakelight/Color.java
patch
|
blob
|
blame
|
history
src/kaka/cakelight/Configuration.java
patch
|
blob
|
blame
|
history
src/kaka/cakelight/LedFrame.java
patch
|
blob
|
blame
|
history
diff --git
a/config.properties
b/config.properties
index
4fec08b
..
7e04ee2
100644
(file)
--- a/
config.properties
+++ b/
config.properties
@@
-14,3
+14,5
@@
video.crop.bottom=18
leds.cols=32
leds.rows=17
leds.cols=32
leds.rows=17
+
+gamma=1.5
diff --git
a/src/kaka/cakelight/CakeLight.java
b/src/kaka/cakelight/CakeLight.java
index
5401c0f
..
c51a534
100644
(file)
--- a/
src/kaka/cakelight/CakeLight.java
+++ b/
src/kaka/cakelight/CakeLight.java
@@
-8,6
+8,7
@@
public class CakeLight {
public CakeLight(Configuration config, LedController ledController) {
this.config = config;
this.ledController = ledController;
public CakeLight(Configuration config, LedController ledController) {
this.config = config;
this.ledController = ledController;
+ Color.calculateGammaCorrection(config.gamma);
}
public void setMode(Mode mode) {
}
public void setMode(Mode mode) {
diff --git
a/src/kaka/cakelight/Color.java
b/src/kaka/cakelight/Color.java
index
1e92da9
..
0756209
100644
(file)
--- a/
src/kaka/cakelight/Color.java
+++ b/
src/kaka/cakelight/Color.java
@@
-1,6
+1,14
@@
package kaka.cakelight;
public class Color {
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) {
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() {
}
public int r() {
- return
r
;
+ return
gammaCorrection[r]
;
}
public int g() {
}
public int g() {
- return g;
+ return g
ammaCorrection[g]
;
}
public int b() {
}
public int b() {
- return
b
;
+ return
gammaCorrection[b]
;
}
public Color interpolate(Color other, double value) {
}
public Color interpolate(Color other, double value) {
diff --git
a/src/kaka/cakelight/Configuration.java
b/src/kaka/cakelight/Configuration.java
index
2932c01
..
86ade8e
100644
(file)
--- a/
src/kaka/cakelight/Configuration.java
+++ b/
src/kaka/cakelight/Configuration.java
@@
-12,10
+12,12
@@
public class Configuration {
private List<Map.Entry<String, String>> settings = new ArrayList<>();
public VideoConfiguration video;
public LedConfiguration leds;
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);
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 static Configuration from(String propertiesFile) {
diff --git
a/src/kaka/cakelight/LedFrame.java
b/src/kaka/cakelight/LedFrame.java
index
9d95b0c
..
ab4ef5c
100644
(file)
--- a/
src/kaka/cakelight/LedFrame.java
+++ b/
src/kaka/cakelight/LedFrame.java
@@
-13,15
+13,16
@@
public class LedFrame {
}
public void fillColor(int r, int g, int b) {
}
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) {
}
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) {
}
public void setLedColor(int led, Color color) {