// retinex // // a demonstration of LW/SW image rendering, using Red/Gray // instead of the traditional Red/Green/Blue // // http://www.wendycarlos.com/colorvis/color.html // // 2003-11-05 // BImage imgs[]; int nimages = 30; int secondsPer = 1; float sz = 320.0/nimages; void setup() { size( 320, 240 ); // same size as our images imgs = new BImage[ nimages ]; for( int i = 0 ; i < nimages ; i++ ) { // use a little bit of Java to help us out in here... // I hate to do this, but it's the easiest way to load the images Integer ii = new Integer( i ); String filename = ii.toString( ); imgs[i] = loadImage( filename + ".jpg" ); } // for the image identifyer stroke( 255, 0, 0 ); } int currentImgNo = 0; boolean jerryAlt = false; void loop() { // select the image based on mouse position currentImgNo = (int) (mouseX/sz); // my alternate; on "gray" lines, drop the red component if( mouseY > height/2 ) jerryAlt = true; else jerryAlt = false; // BAH! Force it off jerryAlt = false; if( mousePressed ) { // mouse pressed, show the original image( imgs[currentImgNo], 0, 0 ); } else { // assume the image is the same size as the screen... int pno; // pixel number // render the longwave bit (Green as Grayscale) pno = width; for( int y = 1 ; y < height ; y+=2 ) { for( int x = 0 ; x < width ; x++ ) { int gg = ((imgs[currentImgNo].pixels[pno]) >> 8) & 0x000000ff; if( !jerryAlt ) pixels[pno] = (gg << 16) + (gg << 8) + gg; else pixels[pno] = (gg << 8) + gg; pno++; } pno += width; } // render the shortwave bit (Red as Red) pno = 0; for( int y = 0 ; y < height ; y+=2 ) { for( int x = 0 ; x < width ; x++ ) { int rr = ((imgs[currentImgNo].pixels[pno]) >> 16 ) & 0x000000ff; pixels[pno] = rr << 16; pno++; } pno += width; } } // draw a rectangle showing which picture is loaded. if( !jerryAlt ) { fill( 200 ); rect( currentImgNo*sz, 0, sz, sz ); } else { fill( 0, 200, 200 ); rect( currentImgNo*sz, height-sz-1, sz, sz ); } // save out a screengrab if( !online() && keyPressed && key == 'G' ) saveFrame(); }