X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FColor.java;h=0756209004ace4f3acf15d41f95e0872cc69a11b;hb=38c759f87fc7de47d9dee60088f2dbc60e0a55fb;hp=da09127eff5c96a19bfcefa23beddaabe8732737;hpb=8aea44b5a5b9d56b600146ab305dfeef932772bd;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/Color.java b/src/kaka/cakelight/Color.java index da09127..0756209 100644 --- a/src/kaka/cakelight/Color.java +++ b/src/kaka/cakelight/Color.java @@ -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) { @@ -15,16 +23,35 @@ public class Color { 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) {