good morning dear Processing community, i'm looking for some way to use blur in real time, and have stumbled on this example:
Code:incubator.quasimondo.com/processing/superfast_blur.php
Looks nice enough and fast, i've tried to modify it so it runs in Processing 1.05, but it doesn't:
Quote:// Super Fast Blur v1.1
// by Mario Klingemann
//
// Tip: Multiple invovations of this filter with a small
// radius will approximate a gaussian blur quite well.
//
PImage a;
PImage b;
void setup()
{
a=loadImage("dog.jpg");
size(a.width, a.height);
b=new PImage(a.width, a.height);
fill(255);
noStroke();
}
void draw()
{
System.arraycopy(a.pixels,0,b.pixels,0,a.pixels.length);
fastblur(b,mouseY/8);
image(b, 0, 0);
}
void fastblur(PImage img,int radius){
if (radius<1){
return;
}
int w=img.width;
int h=img.height;
int wm=w-1;
int hm=h-1;
int wh=w*h;
int div=radius+radius+1;
int r[]=new int[wh];
int g[]=new int[wh];
int b[]=new int[wh];
int rsum,gsum,bsum,x,y,i,p,p1,p2,yp,yi,yw;
int vmin[] = new int[max(w,h)];
int vmax[] = new int[max(w,h)];
int[] pix=img.pixels;
int dv[]=new int[256*div];
for (i=0;i<256*div;i++){
dv[i]=(i/div);
}
yw=yi=0;
for (y=0;y<h;y++){
rsum=gsum=bsum=0;
for(i=-radius;i<=radius;i++){
p=pix[yi+min(wm,max(i,0))];
rsum+=(p & 0xff0000)>>16;
gsum+=(p & 0x00ff00)>>8;
bsum+= p & 0x0000ff;
}
for (x=0;x<w;x++){
r[yi]=dv[rsum];
g[yi]=dv[gsum];
b[yi]=dv[bsum];
if(y==0){
vmin[x]=min(x+radius+1,wm);
vmax[x]=max(x-radius,0);
}
p1=pix[yw+vmin[x]];
p2=pix[yw+vmax[x]];
rsum+=((p1 & 0xff0000)-(p2 & 0xff0000))>>16;
gsum+=((p1 & 0x00ff00)-(p2 & 0x00ff00))>>8;
bsum+= (p1 & 0x0000ff)-(p2 & 0x0000ff);
yi++;
}
yw+=w;
}
for (x=0;x<w;x++){
rsum=gsum=bsum=0;
yp=-radius*w;
for(i=-radius;i<=radius;i++){
yi=max(0,yp)+x;
rsum+=r[yi];
gsum+=g[yi];
bsum+=b[yi];
yp+=w;
}
yi=x;
for (y=0;y<h;y++){
pix[yi]=0xff000000 | (dv[rsum]<<16) | (dv[gsum]<<8) | dv[bsum];
if(x==0){
vmin[y]=min(y+radius+1,hm)*w;
vmax[y]=max(y-radius,0)*w;
}
p1=x+vmin[y];
p2=x+vmax[y];
rsum+=r[p1]-r[p2];
gsum+=g[p1]-g[p2];
bsum+=b[p1]-b[p2];
yi+=w;
}
}
}
Something with that System.arraycopy line? Sorry i'm a bit noobish.
So once this works, if i want to use the blur just like filter(BLUR), i'd go about pixels[] etc., right?
Also, do you think it's possible to use a blur function like this as a method for some class? i.e. isolate the pixels one object draws, and blur only these, without affecting anything else on the screen. I suppose this to be a bit more complicated, with transparent blurry borders et al...
thanks