visualSound
Well-known member
Hey everyone. So I've been breaking my brain over a very small bit of code in the movie2serial PDE that comes with the octo library.
Let me start off with my original issue:
I have been using a for loop and .setPixel() and ints for red, green, and blue in my teensy's code and sending values ranging from 0-255 from my video application over serial. However I noticed that the videoDisplay sketch does things in a more optimal way, where it reads the incoming serial byte array directly into the drawingMemory array.
So, I tried replicated this in my own teensy serial receiver code, however I get strange results with the colors. The pattern is there... but the hue and saturation and brightness is jumbled.
So I dove into the movie2serial PDE and discovered that the bytes are ranging from -128 to 127, while the video application I use sends values from 0-255, which is using python by the way.
The values them selves even when I add 128, don't make sense to me, and on top of that I'm having a hard time understanding what the bit wise operators and stuff are doing to the data. I want to replicate what movie2serial is doing in python, but I just don't have a clue what I'm doing
1) so the video's pixel in processing (which up to this point I understand) is getting passed into "colorWiring", this converts the hex color value to 3 ints, applies gamma, then converts it back to hex but with a new order...
After that I'm confused as to how the values are going negative, and how they produce correct colors on the arduino side:
Why are the values not staying from 0-255?
Why does sending values of 0-255 from another application generate weird results?
Let me start off with my original issue:
I have been using a for loop and .setPixel() and ints for red, green, and blue in my teensy's code and sending values ranging from 0-255 from my video application over serial. However I noticed that the videoDisplay sketch does things in a more optimal way, where it reads the incoming serial byte array directly into the drawingMemory array.
So, I tried replicated this in my own teensy serial receiver code, however I get strange results with the colors. The pattern is there... but the hue and saturation and brightness is jumbled.
So I dove into the movie2serial PDE and discovered that the bytes are ranging from -128 to 127, while the video application I use sends values from 0-255, which is using python by the way.
The values them selves even when I add 128, don't make sense to me, and on top of that I'm having a hard time understanding what the bit wise operators and stuff are doing to the data. I want to replicate what movie2serial is doing in python, but I just don't have a clue what I'm doing
1) so the video's pixel in processing (which up to this point I understand) is getting passed into "colorWiring", this converts the hex color value to 3 ints, applies gamma, then converts it back to hex but with a new order...
After that I'm confused as to how the values are going negative, and how they produce correct colors on the arduino side:
Code:
for (x = xbegin; x != xend; x += xinc) {
for (int i=0; i < 8; i++) {
// fetch 8 pixels from the image, 1 for each pin
pixel[i] = image.pixels[x + (y + linesPerPin * i) * image.width];
pixel[i] = colorWiring(pixel[i]);
}
// convert 8 pixels to 24 bytes
for (mask = 0x800000; mask != 0; mask >>= 1) {
byte b = 0;
for (int i=0; i < 8; i++) {
if ((pixel[i] & mask) != 0) b |= (1 << i);
}
println(b);
data[offset++] = b;
//data[offset++] = 124;
}
}
Why are the values not staying from 0-255?
Why does sending values of 0-255 from another application generate weird results?