diff --git a/Processing/Adalight/Adalight.pde b/Processing/Adalight/Adalight.pde index c9ff9be..cc0497b 100644 --- a/Processing/Adalight/Adalight.pde +++ b/Processing/Adalight/Adalight.pde @@ -32,6 +32,14 @@ static final short fade = 75; static final int pixelSize = 20; +// Depending on many factors, it may be faster either to capture full +// screens and process only the pixels needed, or to capture multiple +// smaller sub-blocks bounding each region to be processed. Try both, +// look at the reported frame rates in the Processing output console, +// and run with whichever works best for you. + +static final boolean useFullScreenCaps = true; + // Serial device timeout (in milliseconds), for locating Arduino device // running the corresponding LEDstream code. See notes later in the code... // in some situations you may want to entirely comment out that block. @@ -104,9 +112,10 @@ short[][] ledColor = new short[leds.length][3], byte[][] gamma = new byte[256][3]; int nDisplays = displays.length; Robot[] bot = new Robot[displays.length]; -Rectangle[] dispBounds = new Rectangle[displays.length]; -int[][] screenData = new int[displays.length][], - pixelOffset = new int[leds.length][256]; +Rectangle[] dispBounds = new Rectangle[displays.length], + ledBounds; // Alloc'd only if per-LED captures +int[][] pixelOffset = new int[leds.length][256], + screenData; // Alloc'd only if full-screen captures PImage[] preview = new PImage[displays.length]; Serial port; DisposeHandler dh; // For disabling LEDs on exit @@ -118,9 +127,10 @@ void setup() { GraphicsConfiguration[] gc; GraphicsDevice[] gd; int d, i, totalWidth, maxHeight, row, col, rowOffset; - float f, startX, curX, curY, incX, incY; + int[] x = new int[16], y = new int[16]; + float f, range, step, start; - dh = new DisposeHandler(this); // Init DisposeHandler ASAP + dh = new DisposeHandler(this); // Init DisposeHandler ASAP // Open serial port. As written here, this assumes the Arduino is the // first/only serial device on the system. If that's not the case, @@ -136,7 +146,15 @@ void setup() { // And finally, to test the software alone without an Arduino connected, // don't open a port...just comment out the serial lines above. - // Initialize screen capture code for each display's dimensions: + // Initialize screen capture code for each display's dimensions. + dispBounds = new Rectangle[displays.length]; + if(useFullScreenCaps == true) { + screenData = new int[displays.length][]; + // ledBounds[] not used + } else { + ledBounds = new Rectangle[leds.length]; + // screenData[][] not used + } ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); gd = ge.getScreenDevices(); if(nDisplays > gd.length) nDisplays = gd.length; @@ -160,26 +178,39 @@ void setup() { } // Precompute locations of every pixel to read when downsampling. - // Saves a bunch of math on each frame, at the expense of a chunk of RAM; - // but hey, it's not like the screen captures are petite either. + // Saves a bunch of math on each frame, at the expense of a chunk + // of RAM. Number of samples is now fixed at 256; this allows for + // some crazy optimizations in the downsampling code. for(i=0; i> 24) & 0xff) * weight + prevColor[i][0] * fade) >> 8); - ledColor[i][1] = (short)(((( g >> 16) & 0xff) * weight + prevColor[i][1] * fade) >> 8); - ledColor[i][2] = (short)((((rb >> 8) & 0xff) * weight + prevColor[i][2] * fade) >> 8); + ledColor[i][0] = (short)((((rb >> 24) & 0xff) * weight + + prevColor[i][0] * fade) >> 8); + ledColor[i][1] = (short)(((( g >> 16) & 0xff) * weight + + prevColor[i][1] * fade) >> 8); + ledColor[i][2] = (short)((((rb >> 8) & 0xff) * weight + + prevColor[i][2] * fade) >> 8); // Boost pixels that fall below the minimum brightness sum = ledColor[i][0] + ledColor[i][1] + ledColor[i][2];