X-Git-Url: http://dolda2000.com/gitweb/?p=kaka%2Fcakelight.git;a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FLedFrame.java;h=4d6b68add12d99313bfaaedcf0d407434fea0d57;hp=f739e388935daa81b3553cf70a76418a98658bab;hb=ed56b145bc04170b4129f4ff92b9eab0e6e4dc74;hpb=f722ee0d05ade1f90b7bc5e51d68b3aed4d65652 diff --git a/src/kaka/cakelight/LedFrame.java b/src/kaka/cakelight/LedFrame.java index f739e38..4d6b68a 100644 --- a/src/kaka/cakelight/LedFrame.java +++ b/src/kaka/cakelight/LedFrame.java @@ -1,19 +1,44 @@ package kaka.cakelight; public class LedFrame { - private Color[] leds; + private byte[] bytes; + private int roff = 0, goff = 2, boff = 1; // Color values are stored as RBG, which is what the LED list takes. public static LedFrame from(Configuration config) { LedFrame frame = new LedFrame(); - frame.leds = new Color[config.leds.cols * 2 + config.leds.rows * 2]; + frame.bytes = new byte[config.leds.getCount() * 3]; return frame; } + 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; + } + } + + public void fillColor(Color color) { + fillColor(color.r(), color.g(), color.b()); + } + public void setLedColor(int led, Color color) { - leds[led] = color; + int offset = led * 3; + bytes[offset + roff] = (byte)color.r(); + bytes[offset + goff] = (byte)color.g(); + bytes[offset + boff] = (byte)color.b(); } public Color getLedColor(int led) { - return leds[led]; + int offset = led * 3; + return Color.rgb( + bytes[offset + roff] & 0xff, + bytes[offset + goff] & 0xff, + bytes[offset + boff] & 0xff + ); + } + + public byte[] getBytes() { + return bytes; } }