FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Tools
(Moderator: REAS)
   RealTime blur (well on my computer attleast)
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: RealTime blur (well on my computer attleast)  (Read 2198 times)
Mathatan

WWW
RealTime blur (well on my computer attleast)
« on: Jun 19th, 2003, 2:12pm »

Hiya!
 
I was practising the use of Proce55ing and made a quite fast blurring method.  
 
Because I wanted to get the method work as fast as it could (for realtime purposes) I left the masking and filters out. Alltough I did make another method, which is a bit more thorough.
 
Anyway heres the method:
 

void blurFast(int startX, int startY, int sizeX, int sizeY, int sampleSize, int sampleDensity, int iteration, boolean borders)
{
  
  int stopX=startX+sizeX;
  int stopY=startY+sizeY;
  int[] colors = new int[4];
  color fcolor;
  int locationX=0, locationY=0, foo=0;
  int[] npixels= new int[screenX*screenY];
  System.arraycopy(pixels, 0, npixels, 0, screenX*screenY);
 
  if(sampleSize/sampleDensity>1) sampleSize/=sampleDensity;
 
  while(iteration-->0) {
  for(int pixX=startX; pixX<stopX; pixX++)
  for(int pixY=startY; pixY<stopY; pixY++)
    {
    if(pixX>screenX) foo=screenX*(pixY-1)+(pixX-iteration);
    else foo=screenX*(pixY)+(pixX-iteration);
    colors[0]=0; colors[1]=0; colors[2]=0; colors[3]=0;
    for(int i=-(sampleSize+1/2)*sampleDensity; i<(sampleSize+1/2)*sampleDensity; i+=sampleDensity)
      for(int j=-(sampleSize+1/2)*sampleDensity; j<(sampleSize+1/2)*sampleDensity; j+=sampleDensity)
        {  
          locationX=pixX+i;
          locationY=pixY+j;
          if(locationX>=screenX) locationX-=screenX;
          if(locationY>=screenY) locationY-=screenY;
          fcolor=getPixel(locationX, locationY);
          colors[0]+=red(fcolor); colors[1]+=green(fcolor); colors[2]+=blue(fcolor); colors[3]++;
        }
    npixels[foo]=color(colors[0]/colors[3], colors[1]/colors[3], colors[2]/colors[3]);
    }
  System.arraycopy(npixels, 0, pixels, 0, screenX*screenY);
  }
  if(borders) {
    drawLine(startX, startY+1, 0, sizeX+1);
    drawLine(startX, startY+1+sizeY, 0, sizeX+1);
    drawLine(startX+1, startY, 90, sizeY+1);
    drawLine(startX+1+sizeX, startY, 90, sizeY+1);
  }
}
 
void drawLine(int startX, int startY, float rotation, int length)
{
  int endX=1, endY=1;
  float rotX=1*cos(radians(rotation)), rotY=1*sin(radians(rotation));
 
  for(int i=1; i<=length; i++) {
    endX=int(startX+(rotX*i))%screenX;
    endY=int(startY+(rotY*i))%screenY;
    if(endX<0) endX+=screenX;
    if(endY<0) endY+=screenY;
    point(endX, endY);
  }
}

 
If you're interested to see it on action (with some other stuff also) check http://koti.mbnet.fi/mathatan/temp/WIP/Java/RealTimeBlur/
 
If you have got any suggestions or improvement (as I'm just a beginner) please let me know..
« Last Edit: Jun 19th, 2003, 3:50pm by Mathatan »  
Mathatan

WWW
New version
« Reply #1 on: Jun 21st, 2003, 10:40am »

Made a new version of the blur method. It now has support for masks, alltough it generates them by it self - but the maskIte function is quite simple to bypass.. It's also a bit faster (mainly because you can use smaller sampleSizes and compensate with iteration)
 
Anyways to see it on action check:  
http://koti.mbnet.fi/mathatan/temp/WIP/Java/RealTimeBlur2/
 
Source can be found here:
http://koti.mbnet.fi/mathatan/temp/WIP/Java/RealTimeBlur2/blur.java
 
Pages: 1 

« Previous topic | Next topic »