-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTransmitter.pde
74 lines (61 loc) · 1.72 KB
/
Transmitter.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import hypermedia.net.*;
public class Transmitter {
private UDP udp;
private byte buffer[];
public Transmitter(PApplet parent) {
this.udp = new UDP(parent);
buffer = new byte[Config.STRIPS * Config.LEDS * 3 + 1];
buffer[0] = 1;
}
public void sendData(PGraphics pg, MapEntry[] map) {
int w = pg.width;
pg.loadPixels();
for (MapEntry entry : map) {
color c = pg.pixels[entry.y * w + entry.x];
int r = (c >> 16) & 0xff;
int g = (c >> 8) & 0xff;
int b = c & 0xff;
if (Config.ENABLE_GAMMA) {
r = gammaTable[r];
g = gammaTable[g];
b = gammaTable[b];
}
int idx = (entry.strip + entry.led * Config.STRIPS) * 3 + 1;
buffer[idx] = (byte)r;
if (Config.SWAP_LOOKUP[entry.strip]) {
buffer[idx + 2] = (byte)g;
buffer[idx + 1] = (byte)b;
} else {
buffer[idx + 1] = (byte)g;
buffer[idx + 2] = (byte)b;
}
}
udp.send(buffer, Config.HOST, Config.PORT);
}
public void sendData(PGraphics pg) {
pg.loadPixels();
int length = pg.width * pg.height;
for (int i = 0; i < length; i++) {
color c = pg.pixels[i];
int r = (c >> 16) & 0xff;
int g = (c >> 8) & 0xff;
int b = c & 0xff;
if (Config.ENABLE_GAMMA) {
r = gammaTable[r];
g = gammaTable[g];
b = gammaTable[b];
}
int idx = i * 3 + 1;
buffer[idx] = (byte)r;
// TODO: Double check the lookup index
if (Config.SWAP_LOOKUP[i / Config.LEDS]) {
buffer[idx + 2] = (byte)g;
buffer[idx + 1] = (byte)b;
} else {
buffer[idx + 1] = (byte)g;
buffer[idx + 2] = (byte)b;
}
}
udp.send(buffer, Config.HOST, Config.PORT);
}
}